From 66735f802f5e6f3f50986c466ea342dfd0bf00f9 Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Thu, 8 Oct 2026 05:03:05 +0000 Subject: [PATCH] =?UTF-8?q?refactor:=20string=5Fforge=20=E4=B8=8E=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E7=A9=BA=E9=97=B4=E7=BB=91=E5=AE=9A=E5=B8=B8=E9=87=8F?= =?UTF-8?q?=E8=BF=81=E5=85=A5=20oxide=5Ftypes=20=E4=B8=AD=E7=AB=8B?= =?UTF-8?q?=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 39 ++++++++++--------- Cargo.toml | 2 +- crates/oxide_emit/Cargo.toml | 2 +- crates/oxide_emit/src/compile_ctx.rs | 2 +- crates/oxide_emit/src/emit.rs | 2 +- crates/oxide_emit/src/expr/literal.rs | 2 +- .../src/expr/template/template_literal.rs | 2 +- crates/oxide_emit/src/module.rs | 2 +- crates/oxide_emit/src/shared/string_pool.rs | 4 +- crates/oxide_kernel/src/lib.rs | 13 ++----- crates/oxide_runtime_api/src/host.rs | 4 +- crates/oxide_types/Cargo.toml | 1 + crates/oxide_types/src/lib.rs | 10 +++++ .../src/string_forge.rs | 10 ++--- .../tests/string_forge_tests.rs | 2 +- 15 files changed, 52 insertions(+), 45 deletions(-) rename crates/{oxide_kernel => oxide_types}/src/string_forge.rs (98%) rename crates/{oxide_kernel => oxide_types}/tests/string_forge_tests.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index 6a6d26c2..490a1a78 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1160,7 +1160,7 @@ dependencies = [ [[package]] name = "oxide_builtins" -version = "0.8.67" +version = "0.8.68" dependencies = [ "chrono", "fast-float", @@ -1185,7 +1185,7 @@ dependencies = [ [[package]] name = "oxide_bytecode" -version = "0.8.67" +version = "0.8.68" dependencies = [ "num-bigint", "oxide_log", @@ -1193,7 +1193,7 @@ dependencies = [ [[package]] name = "oxide_cfg" -version = "0.8.67" +version = "0.8.68" dependencies = [ "oxide_bytecode", "oxide_emit", @@ -1204,7 +1204,7 @@ dependencies = [ [[package]] name = "oxide_cli" -version = "0.8.67" +version = "0.8.68" dependencies = [ "ansi_term", "bumpalo", @@ -1225,7 +1225,7 @@ dependencies = [ [[package]] name = "oxide_code_cache" -version = "0.8.67" +version = "0.8.68" dependencies = [ "lru", "oxide_bytecode", @@ -1234,7 +1234,7 @@ dependencies = [ [[package]] name = "oxide_compiler" -version = "0.8.67" +version = "0.8.68" dependencies = [ "oxide_bytecode", "oxide_cfg", @@ -1253,7 +1253,7 @@ dependencies = [ [[package]] name = "oxide_dce" -version = "0.8.67" +version = "0.8.68" dependencies = [ "oxide_bytecode", "oxide_cfg", @@ -1267,22 +1267,22 @@ dependencies = [ [[package]] name = "oxide_emit" -version = "0.8.67" +version = "0.8.68" dependencies = [ "num-bigint", "oxc_allocator", "oxide_bytecode", "oxide_ir", - "oxide_kernel", "oxide_log", "oxide_parser", + "oxide_types", "regex", "regress", ] [[package]] name = "oxide_ir" -version = "0.8.67" +version = "0.8.68" dependencies = [ "oxide_bytecode", "oxide_log", @@ -1291,7 +1291,7 @@ dependencies = [ [[package]] name = "oxide_kernel" -version = "0.8.67" +version = "0.8.68" dependencies = [ "bumpalo", "dashmap", @@ -1305,7 +1305,7 @@ dependencies = [ [[package]] name = "oxide_liveness" -version = "0.8.67" +version = "0.8.68" dependencies = [ "oxide_bytecode", "oxide_cfg", @@ -1317,7 +1317,7 @@ dependencies = [ [[package]] name = "oxide_log" -version = "0.8.67" +version = "0.8.68" dependencies = [ "tracing", "tracing-appender", @@ -1326,7 +1326,7 @@ dependencies = [ [[package]] name = "oxide_parser" -version = "0.8.67" +version = "0.8.68" dependencies = [ "oxc_allocator", "oxc_ast", @@ -1341,7 +1341,7 @@ dependencies = [ [[package]] name = "oxide_regalloc" -version = "0.8.67" +version = "0.8.68" dependencies = [ "oxide_bytecode", "oxide_cfg", @@ -1357,7 +1357,7 @@ dependencies = [ [[package]] name = "oxide_runtime_api" -version = "0.8.67" +version = "0.8.68" dependencies = [ "num-bigint", "num-traits", @@ -1369,7 +1369,7 @@ dependencies = [ [[package]] name = "oxide_test262" -version = "0.8.67" +version = "0.8.68" dependencies = [ "oxide_bytecode", "oxide_compiler", @@ -1386,9 +1386,10 @@ dependencies = [ [[package]] name = "oxide_types" -version = "0.8.67" +version = "0.8.68" dependencies = [ "bumpalo", + "dashmap", "hashbrown 0.14.5", "num-bigint", "oxide_log", @@ -1398,7 +1399,7 @@ dependencies = [ [[package]] name = "oxide_vm" -version = "0.8.67" +version = "0.8.68" dependencies = [ "bumpalo", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 9bc7f237..24b9491f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ members = [ ] [workspace.package] -version = "0.8.67" +version = "0.8.68" edition = "2021" license = "MIT" rust-version = "1.80" diff --git a/crates/oxide_emit/Cargo.toml b/crates/oxide_emit/Cargo.toml index c4561fa6..9a3f98f1 100644 --- a/crates/oxide_emit/Cargo.toml +++ b/crates/oxide_emit/Cargo.toml @@ -8,7 +8,7 @@ description = "OxideJS - AST to IR emit pass" [dependencies] oxide_parser = { path = "../oxide_parser" } -oxide_kernel = { path = "../oxide_kernel" } +oxide_types = { path = "../oxide_types" } oxc_allocator.workspace = true oxide_bytecode = { path = "../oxide_bytecode" } oxide_ir = { path = "../oxide_ir" } diff --git a/crates/oxide_emit/src/compile_ctx.rs b/crates/oxide_emit/src/compile_ctx.rs index f27fdbf3..044f8c1d 100644 --- a/crates/oxide_emit/src/compile_ctx.rs +++ b/crates/oxide_emit/src/compile_ctx.rs @@ -176,7 +176,7 @@ pub struct CompileCtx { /// 依赖模块规范路径(按 import/export source 字符串索引):再导出来源身份用。 pub(crate) module_dep_paths: HashMap, /// 非自导入的导入局部名 → (依赖模块规范路径, 导入名)。命名空间导入的导入名为 - /// `oxide_kernel::MODULE_NAMESPACE_BINDING`;再导出据此重分类为间接导出。 + /// `oxide_types::MODULE_NAMESPACE_BINDING`;再导出据此重分类为间接导出。 pub(crate) module_import_origins: HashMap, /// 依赖 source 字符串 → 依赖模块是否含可重赋导出(`compile_js_dep` 回传; /// Json/Text 数据模块恒 false)。导入方据此把命名/默认导入登记为活读。 diff --git a/crates/oxide_emit/src/emit.rs b/crates/oxide_emit/src/emit.rs index 17db1254..54dfd55e 100644 --- a/crates/oxide_emit/src/emit.rs +++ b/crates/oxide_emit/src/emit.rs @@ -24,7 +24,7 @@ pub use oxide_parser::{AssignmentOperator, BinaryOperator, Expression, Statement /// 编译入口。方法按语法域组织在 `impl Emitter` 中。 pub struct Emitter { - /// 源码是否为 `oxide_kernel::string_forge::source_escape` 产物 + /// 源码是否为 `oxide_types::string_forge::source_escape` 产物 /// (eval/Function 动态编译):源文本内的孤立 surrogate 单元 / FFFD 以 /// `\uXXXX` 转义文本承载(oxc 不可见裸单元——Rust str 无孤立 surrogate, /// 转义文本是唯一注入形态),反斜杠原样透传。正则字面量的源文本切片据此 diff --git a/crates/oxide_emit/src/expr/literal.rs b/crates/oxide_emit/src/expr/literal.rs index bc0927de..ffd00d72 100644 --- a/crates/oxide_emit/src/expr/literal.rs +++ b/crates/oxide_emit/src/expr/literal.rs @@ -96,7 +96,7 @@ impl Emitter { // 转义文本还原为池键 marker 形态(物化还原原始单元, // `.source` 按原始源返回),用户转义文本逐字透传。 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 { crate::shared::string_pool::pool_key_plain(&pattern) }; diff --git a/crates/oxide_emit/src/expr/template/template_literal.rs b/crates/oxide_emit/src/expr/template/template_literal.rs index 3fb1d421..d1e76f80 100644 --- a/crates/oxide_emit/src/expr/template/template_literal.rs +++ b/crates/oxide_emit/src/expr/template/template_literal.rs @@ -33,7 +33,7 @@ impl Emitter { .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 expr_iter = expr_regs.iter(); diff --git a/crates/oxide_emit/src/module.rs b/crates/oxide_emit/src/module.rs index 39db5521..c449e5f2 100644 --- a/crates/oxide_emit/src/module.rs +++ b/crates/oxide_emit/src/module.rs @@ -19,7 +19,7 @@ use oxide_bytecode::opcode::OpCode; use oxide_ir::inst::Inst; use oxide_ir::operand::Operand; use oxide_ir::{IRFunction, ParamLayout}; -use oxide_kernel::MODULE_NAMESPACE_BINDING; +use oxide_types::MODULE_NAMESPACE_BINDING; use oxide_parser::{ BindingPattern, Declaration, ExportDefaultDeclarationKind, Expression, ImportAttributeKey, ImportDeclarationSpecifier, ModuleExportName, Statement, VariableDeclarationKind, WithClause, diff --git a/crates/oxide_emit/src/shared/string_pool.rs b/crates/oxide_emit/src/shared/string_pool.rs index 0d93e0d9..80cbd5d4 100644 --- a/crates/oxide_emit/src/shared/string_pool.rs +++ b/crates/oxide_emit/src/shared/string_pool.rs @@ -1,4 +1,4 @@ -//! 常量池字符串键编码:池统一存无标志键编码(`oxide_kernel::string_forge::encode_key` +//! 常量池字符串键编码:池统一存无标志键编码(`oxide_types::string_forge::encode_key` //! 语义),物化侧(perm_string → `decode_key`)是其精确逆变换。 //! //! 两类来源文本: @@ -8,8 +8,8 @@ //! 须逃逸编码防裸 FFFD 与 surrogate marker 碰撞; //! - 普通文本(标识符 / 数字 / 源文本):非 FFFD 恒等,真实 FFFD 逃逸为 FFFD+"fffd"。 -use oxide_kernel::string_forge::encode_key; use oxide_parser::PropertyKey; +use oxide_types::string_forge::encode_key; /// 普通文本 → 池键:真实 FFFD 逃逸为 FFFD+"fffd",其余逐单元恒等。 pub(crate) fn pool_key_plain(text: &str) -> String { diff --git a/crates/oxide_kernel/src/lib.rs b/crates/oxide_kernel/src/lib.rs index f57c3e6d..3a2a274a 100644 --- a/crates/oxide_kernel/src/lib.rs +++ b/crates/oxide_kernel/src/lib.rs @@ -17,15 +17,10 @@ pub mod kernel_log; pub mod prop_forge; /// hidden class(shape)共享存储:把对象结构映射为整数 id。 pub mod shape_forge; -/// 永久字符串 intern 表:属性名/方法名稳定 id 化。 -pub mod string_forge; /// kernel 对外的三个核心类型:配置、共享核心、会话。 pub use kernel::{KernelConfig, KernelCore, KernelSession}; - -/// 模块命名空间再导出的绑定身份哨兵。 -/// -/// `export * as ns from mod` 与 `import * as ns from mod; export { ns }` 两路 -/// 转发的是同一个命名空间对象,来源身份须用同一绑定名才能判为同一绑定;该字面量 -/// 含 NUL,不可能与任何静态导出名相同。编译器与运行时共享此常量,禁止另写字面量。 -pub const MODULE_NAMESPACE_BINDING: &str = "\u{0}namespace"; +/// 永久字符串 intern 表与键编码(本体在 `oxide_types`,此处再导出保持既有路径有效)。 +pub use oxide_types::string_forge; +/// 模块命名空间再导出的绑定身份哨兵(本体在 `oxide_types`,此处再导出)。 +pub use oxide_types::MODULE_NAMESPACE_BINDING; diff --git a/crates/oxide_runtime_api/src/host.rs b/crates/oxide_runtime_api/src/host.rs index 669533d9..d77326a1 100644 --- a/crates/oxide_runtime_api/src/host.rs +++ b/crates/oxide_runtime_api/src/host.rs @@ -81,7 +81,7 @@ pub trait VmHost { /// 本次 `&self` 借用(返回值即时消费即可)。 fn single_char(&self, ch: char) -> Option { 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 { None } @@ -94,7 +94,7 @@ pub trait VmHost { /// 短路),非 ASCII 返回 `None` 由调用方回落单元创建。 fn single_unit(&self, u: u16) -> Option { 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 { None } diff --git a/crates/oxide_types/Cargo.toml b/crates/oxide_types/Cargo.toml index e315736a..46026ef3 100644 --- a/crates/oxide_types/Cargo.toml +++ b/crates/oxide_types/Cargo.toml @@ -8,6 +8,7 @@ description = "OxideJS - Shared core types (JsValue, JsObject, Shape, P, Epoch)" [dependencies] bumpalo.workspace = true +dashmap.workspace = true hashbrown.workspace = true oxide_log = { path = "../oxide_log" } rustc-hash.workspace = true diff --git a/crates/oxide_types/src/lib.rs b/crates/oxide_types/src/lib.rs index 30b6df23..8be6c032 100644 --- a/crates/oxide_types/src/lib.rs +++ b/crates/oxide_types/src/lib.rs @@ -10,6 +10,9 @@ pub mod object; pub mod private_key; /// 形状(hidden class)存储。 pub mod shape; +/// 永久字符串 intern 表与键编码:属性名/方法名稳定 id 化、interner 键 +/// 编码、动态编译源编码与有界永久 `JsString` 指针表。 +pub mod string_forge; /// ECMAScript 值(NaN-boxing 的 `JsValue`)。 pub mod value; @@ -18,3 +21,10 @@ mod types_log; /// 重导出 [`error`] 模块的运行时错误类型。 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"; diff --git a/crates/oxide_kernel/src/string_forge.rs b/crates/oxide_types/src/string_forge.rs similarity index 98% rename from crates/oxide_kernel/src/string_forge.rs rename to crates/oxide_types/src/string_forge.rs index 0989e2e0..eb5c3404 100644 --- a/crates/oxide_kernel/src/string_forge.rs +++ b/crates/oxide_types/src/string_forge.rs @@ -2,10 +2,10 @@ use std::hash::{Hash, Hasher}; use std::sync::{OnceLock, RwLock}; use dashmap::DashMap; -use oxide_types::object::JsString; use rustc_hash::FxHasher; -use crate::{kernel_debug, kernel_trace}; +use crate::object::JsString; +use crate::{types_debug, types_trace}; /// 完整 64 位内容哈希。interner 的 hash→候选表碰撞风险可忽略。 fn hash64(s: &str) -> u64 { @@ -289,7 +289,7 @@ impl PermInterner { let entries = self.entries.read().unwrap(); for &id in candidates.iter() { if entries[id as usize].data == s { - kernel_trace!("PermInterner intern hit id={}", id); + types_trace!("PermInterner intern hit id={}", id); return (id, hash); } } @@ -310,9 +310,9 @@ impl PermInterner { let entry_count = entries.len(); drop(entries); 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 { - kernel_debug!("PermInterner stats: {} strings", entry_count); + types_debug!("PermInterner stats: {} strings", entry_count); } (id, hash) } diff --git a/crates/oxide_kernel/tests/string_forge_tests.rs b/crates/oxide_types/tests/string_forge_tests.rs similarity index 99% rename from crates/oxide_kernel/tests/string_forge_tests.rs rename to crates/oxide_types/tests/string_forge_tests.rs index 8d50bf66..ff35efe1 100644 --- a/crates/oxide_kernel/tests/string_forge_tests.rs +++ b/crates/oxide_types/tests/string_forge_tests.rs @@ -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, PermInterner, };