refactor: string_forge 与命名空间绑定常量迁入 oxide_types 中立层

This commit is contained in:
2026-10-08 05:03:05 +00:00
parent dbe7779d36
commit 66735f802f
15 changed files with 52 additions and 45 deletions
Generated
+20 -19
View File
@@ -1160,7 +1160,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_builtins" name = "oxide_builtins"
version = "0.8.67" version = "0.8.68"
dependencies = [ dependencies = [
"chrono", "chrono",
"fast-float", "fast-float",
@@ -1185,7 +1185,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_bytecode" name = "oxide_bytecode"
version = "0.8.67" version = "0.8.68"
dependencies = [ dependencies = [
"num-bigint", "num-bigint",
"oxide_log", "oxide_log",
@@ -1193,7 +1193,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_cfg" name = "oxide_cfg"
version = "0.8.67" version = "0.8.68"
dependencies = [ dependencies = [
"oxide_bytecode", "oxide_bytecode",
"oxide_emit", "oxide_emit",
@@ -1204,7 +1204,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_cli" name = "oxide_cli"
version = "0.8.67" version = "0.8.68"
dependencies = [ dependencies = [
"ansi_term", "ansi_term",
"bumpalo", "bumpalo",
@@ -1225,7 +1225,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_code_cache" name = "oxide_code_cache"
version = "0.8.67" version = "0.8.68"
dependencies = [ dependencies = [
"lru", "lru",
"oxide_bytecode", "oxide_bytecode",
@@ -1234,7 +1234,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_compiler" name = "oxide_compiler"
version = "0.8.67" version = "0.8.68"
dependencies = [ dependencies = [
"oxide_bytecode", "oxide_bytecode",
"oxide_cfg", "oxide_cfg",
@@ -1253,7 +1253,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_dce" name = "oxide_dce"
version = "0.8.67" version = "0.8.68"
dependencies = [ dependencies = [
"oxide_bytecode", "oxide_bytecode",
"oxide_cfg", "oxide_cfg",
@@ -1267,22 +1267,22 @@ dependencies = [
[[package]] [[package]]
name = "oxide_emit" name = "oxide_emit"
version = "0.8.67" version = "0.8.68"
dependencies = [ dependencies = [
"num-bigint", "num-bigint",
"oxc_allocator", "oxc_allocator",
"oxide_bytecode", "oxide_bytecode",
"oxide_ir", "oxide_ir",
"oxide_kernel",
"oxide_log", "oxide_log",
"oxide_parser", "oxide_parser",
"oxide_types",
"regex", "regex",
"regress", "regress",
] ]
[[package]] [[package]]
name = "oxide_ir" name = "oxide_ir"
version = "0.8.67" version = "0.8.68"
dependencies = [ dependencies = [
"oxide_bytecode", "oxide_bytecode",
"oxide_log", "oxide_log",
@@ -1291,7 +1291,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_kernel" name = "oxide_kernel"
version = "0.8.67" version = "0.8.68"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"dashmap", "dashmap",
@@ -1305,7 +1305,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_liveness" name = "oxide_liveness"
version = "0.8.67" version = "0.8.68"
dependencies = [ dependencies = [
"oxide_bytecode", "oxide_bytecode",
"oxide_cfg", "oxide_cfg",
@@ -1317,7 +1317,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_log" name = "oxide_log"
version = "0.8.67" version = "0.8.68"
dependencies = [ dependencies = [
"tracing", "tracing",
"tracing-appender", "tracing-appender",
@@ -1326,7 +1326,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_parser" name = "oxide_parser"
version = "0.8.67" version = "0.8.68"
dependencies = [ dependencies = [
"oxc_allocator", "oxc_allocator",
"oxc_ast", "oxc_ast",
@@ -1341,7 +1341,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_regalloc" name = "oxide_regalloc"
version = "0.8.67" version = "0.8.68"
dependencies = [ dependencies = [
"oxide_bytecode", "oxide_bytecode",
"oxide_cfg", "oxide_cfg",
@@ -1357,7 +1357,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_runtime_api" name = "oxide_runtime_api"
version = "0.8.67" version = "0.8.68"
dependencies = [ dependencies = [
"num-bigint", "num-bigint",
"num-traits", "num-traits",
@@ -1369,7 +1369,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_test262" name = "oxide_test262"
version = "0.8.67" version = "0.8.68"
dependencies = [ dependencies = [
"oxide_bytecode", "oxide_bytecode",
"oxide_compiler", "oxide_compiler",
@@ -1386,9 +1386,10 @@ dependencies = [
[[package]] [[package]]
name = "oxide_types" name = "oxide_types"
version = "0.8.67" version = "0.8.68"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"dashmap",
"hashbrown 0.14.5", "hashbrown 0.14.5",
"num-bigint", "num-bigint",
"oxide_log", "oxide_log",
@@ -1398,7 +1399,7 @@ dependencies = [
[[package]] [[package]]
name = "oxide_vm" name = "oxide_vm"
version = "0.8.67" version = "0.8.68"
dependencies = [ dependencies = [
"bumpalo", "bumpalo",
"chrono", "chrono",
+1 -1
View File
@@ -22,7 +22,7 @@ members = [
] ]
[workspace.package] [workspace.package]
version = "0.8.67" version = "0.8.68"
edition = "2021" edition = "2021"
license = "MIT" license = "MIT"
rust-version = "1.80" rust-version = "1.80"
+1 -1
View File
@@ -8,7 +8,7 @@ description = "OxideJS - AST to IR emit pass"
[dependencies] [dependencies]
oxide_parser = { path = "../oxide_parser" } oxide_parser = { path = "../oxide_parser" }
oxide_kernel = { path = "../oxide_kernel" } oxide_types = { path = "../oxide_types" }
oxc_allocator.workspace = true oxc_allocator.workspace = true
oxide_bytecode = { path = "../oxide_bytecode" } oxide_bytecode = { path = "../oxide_bytecode" }
oxide_ir = { path = "../oxide_ir" } oxide_ir = { path = "../oxide_ir" }
+1 -1
View File
@@ -176,7 +176,7 @@ pub struct CompileCtx {
/// 依赖模块规范路径(按 import/export source 字符串索引):再导出来源身份用。 /// 依赖模块规范路径(按 import/export source 字符串索引):再导出来源身份用。
pub(crate) module_dep_paths: HashMap<String, String>, pub(crate) module_dep_paths: HashMap<String, String>,
/// 非自导入的导入局部名 → (依赖模块规范路径, 导入名)。命名空间导入的导入名为 /// 非自导入的导入局部名 → (依赖模块规范路径, 导入名)。命名空间导入的导入名为
/// `oxide_kernel::MODULE_NAMESPACE_BINDING`;再导出据此重分类为间接导出。 /// `oxide_types::MODULE_NAMESPACE_BINDING`;再导出据此重分类为间接导出。
pub(crate) module_import_origins: HashMap<String, (String, String)>, pub(crate) module_import_origins: HashMap<String, (String, String)>,
/// 依赖 source 字符串 → 依赖模块是否含可重赋导出(`compile_js_dep` 回传; /// 依赖 source 字符串 → 依赖模块是否含可重赋导出(`compile_js_dep` 回传;
/// Json/Text 数据模块恒 false)。导入方据此把命名/默认导入登记为活读。 /// Json/Text 数据模块恒 false)。导入方据此把命名/默认导入登记为活读。
+1 -1
View File
@@ -24,7 +24,7 @@ pub use oxide_parser::{AssignmentOperator, BinaryOperator, Expression, Statement
/// 编译入口。方法按语法域组织在 `impl Emitter` 中。 /// 编译入口。方法按语法域组织在 `impl Emitter` 中。
pub struct Emitter { pub struct Emitter {
/// 源码是否为 `oxide_kernel::string_forge::source_escape` 产物 /// 源码是否为 `oxide_types::string_forge::source_escape` 产物
/// (eval/Function 动态编译):源文本内的孤立 surrogate 单元 / FFFD 以 /// (eval/Function 动态编译):源文本内的孤立 surrogate 单元 / FFFD 以
/// `\uXXXX` 转义文本承载(oxc 不可见裸单元——Rust str 无孤立 surrogate, /// `\uXXXX` 转义文本承载(oxc 不可见裸单元——Rust str 无孤立 surrogate,
/// 转义文本是唯一注入形态),反斜杠原样透传。正则字面量的源文本切片据此 /// 转义文本是唯一注入形态),反斜杠原样透传。正则字面量的源文本切片据此
+1 -1
View File
@@ -96,7 +96,7 @@ impl Emitter {
// 转义文本还原为池键 marker 形态(物化还原原始单元, // 转义文本还原为池键 marker 形态(物化还原原始单元,
// `.source` 按原始源返回),用户转义文本逐字透传。 // `.source` 按原始源返回),用户转义文本逐字透传。
let pattern_key = if ctx.source_encoded { let pattern_key = if ctx.source_encoded {
oxide_kernel::string_forge::source_escape_to_key(&pattern) oxide_types::string_forge::source_escape_to_key(&pattern)
} else { } else {
crate::shared::string_pool::pool_key_plain(&pattern) crate::shared::string_pool::pool_key_plain(&pattern)
}; };
@@ -33,7 +33,7 @@ impl Emitter {
.collect(); .collect();
// 容量提示按单元数口径(键文本经物化解码还原单元序列)。 // 容量提示按单元数口径(键文本经物化解码还原单元序列)。
let total_len_hint: usize = quasi_keys.iter().map(|k| oxide_kernel::string_forge::decode_key(k).len()).sum(); let total_len_hint: usize = quasi_keys.iter().map(|k| oxide_types::string_forge::decode_key(k).len()).sum();
let mut parts = Vec::with_capacity(quasi_const_idxs.len() * 2); let mut parts = Vec::with_capacity(quasi_const_idxs.len() * 2);
let mut expr_iter = expr_regs.iter(); let mut expr_iter = expr_regs.iter();
+1 -1
View File
@@ -19,7 +19,7 @@ use oxide_bytecode::opcode::OpCode;
use oxide_ir::inst::Inst; use oxide_ir::inst::Inst;
use oxide_ir::operand::Operand; use oxide_ir::operand::Operand;
use oxide_ir::{IRFunction, ParamLayout}; use oxide_ir::{IRFunction, ParamLayout};
use oxide_kernel::MODULE_NAMESPACE_BINDING; use oxide_types::MODULE_NAMESPACE_BINDING;
use oxide_parser::{ use oxide_parser::{
BindingPattern, Declaration, ExportDefaultDeclarationKind, Expression, ImportAttributeKey, BindingPattern, Declaration, ExportDefaultDeclarationKind, Expression, ImportAttributeKey,
ImportDeclarationSpecifier, ModuleExportName, Statement, VariableDeclarationKind, WithClause, ImportDeclarationSpecifier, ModuleExportName, Statement, VariableDeclarationKind, WithClause,
+2 -2
View File
@@ -1,4 +1,4 @@
//! 常量池字符串键编码:池统一存无标志键编码(`oxide_kernel::string_forge::encode_key` //! 常量池字符串键编码:池统一存无标志键编码(`oxide_types::string_forge::encode_key`
//! 语义),物化侧(perm_string → `decode_key`)是其精确逆变换。 //! 语义),物化侧(perm_string → `decode_key`)是其精确逆变换。
//! //!
//! 两类来源文本: //! 两类来源文本:
@@ -8,8 +8,8 @@
//! 须逃逸编码防裸 FFFD 与 surrogate marker 碰撞; //! 须逃逸编码防裸 FFFD 与 surrogate marker 碰撞;
//! - 普通文本(标识符 / 数字 / 源文本):非 FFFD 恒等,真实 FFFD 逃逸为 FFFD+"fffd"。 //! - 普通文本(标识符 / 数字 / 源文本):非 FFFD 恒等,真实 FFFD 逃逸为 FFFD+"fffd"。
use oxide_kernel::string_forge::encode_key;
use oxide_parser::PropertyKey; use oxide_parser::PropertyKey;
use oxide_types::string_forge::encode_key;
/// 普通文本 → 池键:真实 FFFD 逃逸为 FFFD+"fffd",其余逐单元恒等。 /// 普通文本 → 池键:真实 FFFD 逃逸为 FFFD+"fffd",其余逐单元恒等。
pub(crate) fn pool_key_plain(text: &str) -> String { pub(crate) fn pool_key_plain(text: &str) -> String {
+4 -9
View File
@@ -17,15 +17,10 @@ pub mod kernel_log;
pub mod prop_forge; pub mod prop_forge;
/// hidden class(shape)共享存储:把对象结构映射为整数 id。 /// hidden class(shape)共享存储:把对象结构映射为整数 id。
pub mod shape_forge; pub mod shape_forge;
/// 永久字符串 intern 表:属性名/方法名稳定 id 化。
pub mod string_forge;
/// kernel 对外的三个核心类型:配置、共享核心、会话。 /// kernel 对外的三个核心类型:配置、共享核心、会话。
pub use kernel::{KernelConfig, KernelCore, KernelSession}; pub use kernel::{KernelConfig, KernelCore, KernelSession};
/// 永久字符串 intern 表与键编码(本体在 `oxide_types`,此处再导出保持既有路径有效)。
/// 模块命名空间再导出的绑定身份哨兵。 pub use oxide_types::string_forge;
/// /// 模块命名空间再导出的绑定身份哨兵(本体在 `oxide_types`,此处再导出)。
/// `export * as ns from mod` 与 `import * as ns from mod; export { ns }` 两路 pub use oxide_types::MODULE_NAMESPACE_BINDING;
/// 转发的是同一个命名空间对象,来源身份须用同一绑定名才能判为同一绑定;该字面量
/// 含 NUL,不可能与任何静态导出名相同。编译器与运行时共享此常量,禁止另写字面量。
pub const MODULE_NAMESPACE_BINDING: &str = "\u{0}namespace";
+2 -2
View File
@@ -81,7 +81,7 @@ pub trait VmHost {
/// 本次 `&self` 借用(返回值即时消费即可)。 /// 本次 `&self` 借用(返回值即时消费即可)。
fn single_char(&self, ch: char) -> Option<JsValue> { fn single_char(&self, ch: char) -> Option<JsValue> {
if ch.is_ascii() { if ch.is_ascii() {
Some(JsValue::string(oxide_kernel::string_forge::single_char_ptr(ch as u8))) Some(JsValue::string(oxide_types::string_forge::single_char_ptr(ch as u8)))
} else { } else {
None None
} }
@@ -94,7 +94,7 @@ pub trait VmHost {
/// 短路),非 ASCII 返回 `None` 由调用方回落单元创建。 /// 短路),非 ASCII 返回 `None` 由调用方回落单元创建。
fn single_unit(&self, u: u16) -> Option<JsValue> { fn single_unit(&self, u: u16) -> Option<JsValue> {
if u < 0x80 { if u < 0x80 {
Some(JsValue::string(oxide_kernel::string_forge::single_char_ptr(u as u8))) Some(JsValue::string(oxide_types::string_forge::single_char_ptr(u as u8)))
} else { } else {
None None
} }
+1
View File
@@ -8,6 +8,7 @@ description = "OxideJS - Shared core types (JsValue, JsObject, Shape, P, Epoch)"
[dependencies] [dependencies]
bumpalo.workspace = true bumpalo.workspace = true
dashmap.workspace = true
hashbrown.workspace = true hashbrown.workspace = true
oxide_log = { path = "../oxide_log" } oxide_log = { path = "../oxide_log" }
rustc-hash.workspace = true rustc-hash.workspace = true
+10
View File
@@ -10,6 +10,9 @@ pub mod object;
pub mod private_key; pub mod private_key;
/// 形状(hidden class)存储。 /// 形状(hidden class)存储。
pub mod shape; pub mod shape;
/// 永久字符串 intern 表与键编码:属性名/方法名稳定 id 化、interner 键
/// 编码、动态编译源编码与有界永久 `JsString` 指针表。
pub mod string_forge;
/// ECMAScript 值(NaN-boxing 的 `JsValue`)。 /// ECMAScript 值(NaN-boxing 的 `JsValue`)。
pub mod value; pub mod value;
@@ -18,3 +21,10 @@ mod types_log;
/// 重导出 [`error`] 模块的运行时错误类型。 /// 重导出 [`error`] 模块的运行时错误类型。
pub use error::{JsError, JsErrorKind}; pub use error::{JsError, JsErrorKind};
/// 模块命名空间再导出的绑定身份哨兵。
///
/// `export * as ns from mod` 与 `import * as ns from mod; export { ns }` 两路
/// 转发的是同一个命名空间对象,来源身份须用同一绑定名才能判为同一绑定;该字面量
/// 含 NUL,不可能与任何静态导出名相同。编译器与运行时共享此常量,禁止另写字面量。
pub const MODULE_NAMESPACE_BINDING: &str = "\u{0}namespace";
@@ -2,10 +2,10 @@ use std::hash::{Hash, Hasher};
use std::sync::{OnceLock, RwLock}; use std::sync::{OnceLock, RwLock};
use dashmap::DashMap; use dashmap::DashMap;
use oxide_types::object::JsString;
use rustc_hash::FxHasher; use rustc_hash::FxHasher;
use crate::{kernel_debug, kernel_trace}; use crate::object::JsString;
use crate::{types_debug, types_trace};
/// 完整 64 位内容哈希。interner 的 hash→候选表碰撞风险可忽略。 /// 完整 64 位内容哈希。interner 的 hash→候选表碰撞风险可忽略。
fn hash64(s: &str) -> u64 { fn hash64(s: &str) -> u64 {
@@ -289,7 +289,7 @@ impl PermInterner {
let entries = self.entries.read().unwrap(); let entries = self.entries.read().unwrap();
for &id in candidates.iter() { for &id in candidates.iter() {
if entries[id as usize].data == s { if entries[id as usize].data == s {
kernel_trace!("PermInterner intern hit id={}", id); types_trace!("PermInterner intern hit id={}", id);
return (id, hash); return (id, hash);
} }
} }
@@ -310,9 +310,9 @@ impl PermInterner {
let entry_count = entries.len(); let entry_count = entries.len();
drop(entries); drop(entries);
self.hash_map.entry(hash).or_default().push(id); self.hash_map.entry(hash).or_default().push(id);
kernel_debug!("PermInterner intern new id={} len={}", id, s.len()); types_debug!("PermInterner intern new id={} len={}", id, s.len());
if entry_count % 1000 == 0 { if entry_count % 1000 == 0 {
kernel_debug!("PermInterner stats: {} strings", entry_count); types_debug!("PermInterner stats: {} strings", entry_count);
} }
(id, hash) (id, hash)
} }
@@ -1,4 +1,4 @@
use oxide_kernel::string_forge::{ use oxide_types::string_forge::{
decode_key, encode_key, single_char_ptr, small_int_ptr, source_escape, source_escape_to_key, typeof_string_ptr, decode_key, encode_key, single_char_ptr, small_int_ptr, source_escape, source_escape_to_key, typeof_string_ptr,
PermInterner, PermInterner,
}; };