diff --git a/Cargo.lock b/Cargo.lock index dd39fca3..8837f744 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1093,18 +1093,6 @@ dependencies = [ "unicode-id-start", ] -[[package]] -name = "oxide_api" -version = "0.1.0" -dependencies = [ - "oxide_compiler", - "oxide_kernel", - "oxide_parser", - "oxide_vm", - "rayon", - "serde_json", -] - [[package]] name = "oxide_builtins" version = "0.1.0" @@ -1147,7 +1135,6 @@ version = "0.1.0" dependencies = [ "ansi_term", "clap", - "oxide_api", "oxide_bytecode", "oxide_code_cache", "oxide_compiler", diff --git a/Cargo.toml b/Cargo.toml index c56d5675..6b3391a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,6 @@ members = [ "crates/oxide_kernel", "crates/oxide_runtime_api", "crates/oxide_builtins", - "crates/oxide_api", "crates/oxide_cli", "crates/oxide_test262", ] diff --git a/crates/oxide_api/Cargo.toml b/crates/oxide_api/Cargo.toml deleted file mode 100644 index 2473c17b..00000000 --- a/crates/oxide_api/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "oxide_api" -version.workspace = true -edition.workspace = true -license.workspace = true -rust-version.workspace = true -description = "OxideJS - Public API surface" - -[dependencies] -oxide_parser = { path = "../oxide_parser" } -oxide_compiler = { path = "../oxide_compiler" } -oxide_vm = { path = "../oxide_vm" } -oxide_kernel = { path = "../oxide_kernel" } -serde_json.workspace = true -rayon.workspace = true diff --git a/crates/oxide_api/src/lib.rs b/crates/oxide_api/src/lib.rs deleted file mode 100644 index 2714e267..00000000 --- a/crates/oxide_api/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -#![doc = "OxideJS - Public API surface"] diff --git a/crates/oxide_cli/Cargo.toml b/crates/oxide_cli/Cargo.toml index d4e35c4f..c0b67e55 100644 --- a/crates/oxide_cli/Cargo.toml +++ b/crates/oxide_cli/Cargo.toml @@ -18,7 +18,6 @@ oxide_types = { path = "../oxide_types" } oxide_compiler = { path = "../oxide_compiler" } oxide_vm = { path = "../oxide_vm" } oxide_kernel = { path = "../oxide_kernel" } -oxide_api = { path = "../oxide_api" } oxide_log = { path = "../oxide_log" } clap.workspace = true rustyline.workspace = true diff --git a/crates/oxide_emit/src/emit.rs b/crates/oxide_emit/src/emit.rs index b6f39b5f..4fb172be 100644 --- a/crates/oxide_emit/src/emit.rs +++ b/crates/oxide_emit/src/emit.rs @@ -587,11 +587,6 @@ impl CompileCtx { .unwrap_or(0) } - pub(crate) fn pre_register_builtins(&mut self) { - // builtin 全局由 lookup_or_builtin() 惰性解析。保留此钩子维持编译管线形态, - // 避免在每个模块预留约 60 个寄存器槽。 - } - /// 组装 IRFunction(两出口共用),take 走编译产物状态。 /// `parent_ctx` 用于补全 upvalue_captures 的 enclosing_reg(父符号表在父 emit 完成后完整)。 fn assemble_ir(&mut self, param_layout: oxide_ir::ParamLayout, parent_ctx: Option<&CompileCtx>) -> IRFunction { @@ -1278,7 +1273,6 @@ impl Emitter { let mut ctx = CompileCtx::new(); // 脚本顶层:var/function 声明需落到全局对象,let/const/class 不进全局。 ctx.is_global_scope = true; - ctx.pre_register_builtins(); self.predeclare_function_declarations(&program.body, &mut ctx); // 预注册 builtin 引用(先于任何临时寄存器),builtin 槽不进入临时寄存器池。 diff --git a/crates/oxide_types/src/mem.rs b/crates/oxide_types/src/mem.rs index 70923102..56b1be0e 100644 --- a/crates/oxide_types/src/mem.rs +++ b/crates/oxide_types/src/mem.rs @@ -1,9 +1,8 @@ //! 内存管理抽象:跨 epoch 持久存储与每次调用(agent call)内的 arena 分配。 //! -//! `P` 是基于 `Arc` 的持久指针,持有者跨 `Epoch::reset()` 存活; -//! `PersistentHeap` 负责把对象"提升"到持久堆;`Epoch` 则是对 -//! `bumpalo::Bump` 的封装,用于每次调用内的高频分配与 O(1) 整体回收, -//! 并通过 epoch ID 辅助悬挂指针检测。 +//! `P` 是 `Arc` 的透明包装,持有者跨 `Epoch::reset()` 存活; +//! `Epoch` 则是对 `bumpalo::Bump` 的封装,用于每次调用内的高频分配与 +//! O(1) 整体回收,并通过 epoch ID 辅助悬挂指针检测。 use std::fmt; use std::ops::Deref; @@ -11,8 +10,9 @@ use std::sync::Arc; /// 引用计数持久指针。 /// -/// 包装 `Arc` 用于跨 epoch 对象存储。`Clone` 递增引用计数,`Drop` 递减; -/// `P` 包裹的对象在 `Epoch::reset()` 后仍存活——它们位于全局堆上。 +/// `P` 是 `Arc` 的透明包装(`repr(transparent)`),语义等价于 `Arc`: +/// `Clone` 递增引用计数,`Drop` 递减。对象位于全局堆上,跨 `Epoch::reset()` +/// 存活。 #[repr(transparent)] pub struct P(Arc); @@ -60,31 +60,6 @@ impl fmt::Display for P { } } -/// 跨 epoch 对象存储的持久堆。 -/// -/// 提供最小 API:`promote(value)` 把 `value` 以 `Arc` 移到全局堆并返回 `P`。 -/// shape、code、IC 模板与字符串的类型化存储位于 OxideKernel。 -pub struct PersistentHeap; - -impl PersistentHeap { - /// 创建空持久堆(无内部状态,仅提供 `promote`)。 - pub fn new() -> Self { - Self - } - - /// 把 `value` 移到持久堆并返回引用计数指针。 - /// 返回的 `P` 跨 epoch 重置存活——它以 `Arc` 存在全局堆上。 - pub fn promote(&self, value: T) -> P { - P::new(value) - } -} - -impl Default for PersistentHeap { - fn default() -> Self { - Self::new() - } -} -/// /// 包装 `bumpalo::Bump` 并携带 epoch ID 计数器用于悬挂指针检测。 /// 所有 Agent 调用级对象分配于此;`reset()` 在每次调用结束时 O(1) 清空。 pub struct Epoch { @@ -186,8 +161,7 @@ mod tests { #[test] fn is_epoch_ptr_returns_false_for_heap_and_stack_pointers() { let epoch = Epoch::new(); - let heap = PersistentHeap::new(); - let persistent = heap.promote(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())); + let persistent = P::new(JsObject::new_empty(EMPTY_SHAPE_ID, JsValue::null())); let stack_value = 7i32; assert!(!epoch.is_epoch_ptr(persistent.as_ptr().cast::())); diff --git a/crates/oxide_types/src/object.rs b/crates/oxide_types/src/object.rs index 1908b965..a9af74f1 100644 --- a/crates/oxide_types/src/object.rs +++ b/crates/oxide_types/src/object.rs @@ -353,7 +353,7 @@ impl Cell { /// 内联字段:`header`(shape_id + 一组标志位)、`type_tag`(外来对象种类)、 /// `proto`、`generation` 等;dense 属性向量、属性元数据、native payload 与 /// upvalue cell 列表以裸指针挂在堆上,由 VM / GC 维护。对象可分配在 -/// session arena(`Epoch`)或持久堆(`PersistentHeap`),通过 +/// session arena(`Epoch`)或全局堆(`Arc`),通过 /// `is_session_epoch` 位区分。 pub struct JsObject { header: u32, diff --git a/crates/oxide_vm/tests/mem_tests.rs b/crates/oxide_vm/tests/mem_tests.rs index ae7eedcd..06312554 100644 --- a/crates/oxide_vm/tests/mem_tests.rs +++ b/crates/oxide_vm/tests/mem_tests.rs @@ -1,6 +1,6 @@ use std::time::Instant; -use oxide_types::mem::{Epoch, PersistentHeap}; +use oxide_types::mem::{Epoch, P}; #[test] fn epoch_alloc_and_read() { @@ -54,17 +54,15 @@ fn epoch_benchmark_1m_allocations() { } #[test] -fn persistent_promote_and_deref() { - let heap = PersistentHeap::new(); - let p = heap.promote(42i32); +fn persistent_new_and_deref() { + let p = P::new(42i32); assert_eq!(*p, 42); } #[test] -fn persistent_promote_survives_epoch_reset() { - let heap = PersistentHeap::new(); +fn persistent_survives_epoch_reset() { let mut epoch = Epoch::new(); - let p = heap.promote(100i32); + let p = P::new(100i32); epoch.reset(); @@ -73,8 +71,7 @@ fn persistent_promote_survives_epoch_reset() { #[test] fn persistent_clone_shares_data() { - let heap = PersistentHeap::new(); - let a = heap.promote(42i32); + let a = P::new(42i32); let b = a.clone(); assert_eq!(*a, 42); @@ -86,15 +83,14 @@ fn persistent_clone_shares_data() { } #[test] -fn persistent_promote_custom_type() { +fn persistent_custom_type() { #[derive(Debug, PartialEq)] struct Data { name: String, value: i32, } - let heap = PersistentHeap::new(); - let p = heap.promote(Data { + let p = P::new(Data { name: "test".to_string(), value: 42, }); @@ -105,15 +101,13 @@ fn persistent_promote_custom_type() { #[test] fn persistent_debug_format() { - let heap = PersistentHeap::new(); - let p = heap.promote(42i32); + let p = P::new(42i32); assert_eq!(format!("{:?}", p), "P(42)"); } #[test] fn persistent_display_format() { - let heap = PersistentHeap::new(); - let p = heap.promote(42i32); + let p = P::new(42i32); assert_eq!(format!("{}", p), "42"); } @@ -125,13 +119,6 @@ fn epoch_default_creates_valid() { assert_eq!(unsafe { *ptr }, 7); } -#[test] -fn persistent_heap_default() { - let heap = PersistentHeap; - let p = heap.promote("hello"); - assert_eq!(*p, "hello"); -} - #[test] fn epoch_alloc_with_closure() { let epoch = Epoch::new();