refactor: 清理 dead abstraction(oxide_api 空壳/空钩子/PersistentHeap/空目录)

This commit is contained in:
2026-08-10 11:54:44 +08:00
parent 7942269be8
commit 020989a348
9 changed files with 18 additions and 94 deletions
-15
View File
@@ -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
-1
View File
@@ -1 +0,0 @@
#![doc = "OxideJS - Public API surface"]
-1
View File
@@ -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
-6
View File
@@ -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 槽不进入临时寄存器池。
+7 -33
View File
@@ -1,9 +1,8 @@
//! 内存管理抽象:跨 epoch 持久存储与每次调用(agent call)内的 arena 分配。
//!
//! `P<T>` 是基于 `Arc` 的持久指针,持有者跨 `Epoch::reset()` 存活;
//! `PersistentHeap` 负责把对象"提升"到持久堆;`Epoch` 则是对
//! `bumpalo::Bump` 的封装,用于每次调用内的高频分配与 O(1) 整体回收,
//! 并通过 epoch ID 辅助悬挂指针检测。
//! `P<T>` 是 `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<T>` 用于跨 epoch 对象存储。`Clone` 递增引用计数,`Drop` 递减;
/// `P<T>` 包裹的对象在 `Epoch::reset()` 后仍存活——它们位于全局堆上。
/// `P<T>` 是 `Arc<T>` 的透明包装(`repr(transparent)`),语义等价于 `Arc`:
/// `Clone` 递增引用计数,`Drop` 递减。对象位于全局堆上,跨 `Epoch::reset()`
/// 存活。
#[repr(transparent)]
pub struct P<T>(Arc<T>);
@@ -60,31 +60,6 @@ impl<T: fmt::Display> fmt::Display for P<T> {
}
}
/// 跨 epoch 对象存储的持久堆。
///
/// 提供最小 API:`promote(value)` 把 `value` 以 `Arc` 移到全局堆并返回 `P<T>`。
/// shape、code、IC 模板与字符串的类型化存储位于 OxideKernel。
pub struct PersistentHeap;
impl PersistentHeap {
/// 创建空持久堆(无内部状态,仅提供 `promote`)。
pub fn new() -> Self {
Self
}
/// 把 `value` 移到持久堆并返回引用计数指针。
/// 返回的 `P<T>` 跨 epoch 重置存活——它以 `Arc` 存在全局堆上。
pub fn promote<T>(&self, value: T) -> P<T> {
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::<u8>()));
+1 -1
View File
@@ -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,
+10 -23
View File
@@ -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();