From b0ba874844e1c1644d2eb5b136912d7765798882 Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Thu, 6 Aug 2026 11:27:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=BB=BA=20oxide=5Fdce=20crat?= =?UTF-8?q?e=20=E9=AA=A8=E6=9E=B6=E5=B9=B6=E6=8E=A5=E5=85=A5=20workspace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - workspace.members 在 oxide_cfg 后追加 crates/oxide_dce - Cargo.toml 骨架照抄 oxide_cfg(oxide_ir + oxide_cfg 依赖,dev-deps parser/emit/vm) - lib.rs 中文文档头 + pub fn dce 入口(空函数退化先例,非空路径 Task 2/3 骨架) --- Cargo.toml | 1 + crates/oxide_dce/Cargo.toml | 16 ++++++++++++++++ crates/oxide_dce/src/lib.rs | 20 ++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 crates/oxide_dce/Cargo.toml create mode 100644 crates/oxide_dce/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 3b611b4d..15fc2cea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ members = [ "crates/oxide_emit", "crates/oxide_ir", "crates/oxide_cfg", + "crates/oxide_dce", "crates/oxide_types", "crates/oxide_vm", "crates/oxide_kernel", diff --git a/crates/oxide_dce/Cargo.toml b/crates/oxide_dce/Cargo.toml new file mode 100644 index 00000000..37f1f8be --- /dev/null +++ b/crates/oxide_dce/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "oxide_dce" +version.workspace = true +edition.workspace = true +license.workspace = true +rust-version.workspace = true +description = "OxideJS - dead code elimination pass over IR (reachability + use-count iteration + mark-sweep)" + +[dependencies] +oxide_ir = { path = "../oxide_ir" } +oxide_cfg = { path = "../oxide_cfg" } + +[dev-dependencies] +oxide_parser = { path = "../oxide_parser" } +oxide_emit = { path = "../oxide_emit" } +oxide_vm = { path = "../oxide_vm" } diff --git a/crates/oxide_dce/src/lib.rs b/crates/oxide_dce/src/lib.rs new file mode 100644 index 00000000..ac5bcbe5 --- /dev/null +++ b/crates/oxide_dce/src/lib.rs @@ -0,0 +1,20 @@ +//! DCE 改写 pass:IRFunction → 死代码消除后 compact 重建。 +//! +//! 改写 pass(D-09):`&mut IRFunction` 就地 compact(D-06 方案 A 索引关联保证无借用冲突), +//! 三 Pass——Pass A 块级可达性(消费 `oxide_cfg::build_cfg`,Exception 边保守,D-07/Pitfall 4)、 +//! Pass B 全函数 use 计数迭代删除死指令到不动点(D-01/D-02 连锁语义)、 +//! Pass C mark-sweep 一次性重建 insts + label_pos 重映射(D-13,不用就地逐删平移)。 +//! 本 pass 不碰 nested(D-03 不递归)、常量池(D-14 不清理)、n_registers(D-04 不收缩)、 +//! label_count(D-13 不读不改)。中间产物(keep/use_count)用局部 Vec 显式传参, +//! 不做 struct 状态持有(无共享可变状态约定)。零 unsafe。 + +use oxide_ir::IRFunction; + +/// 死代码消除:块级不可达删除 + 全函数 use 计数迭代删除到不动点 + mark-sweep 重建。 +pub fn dce(f: &mut IRFunction) { + // 空 IRFunction 退化形态:无指令可删(照 oxide_cfg empty_function 先例)。 + // 非空路径为 Task 2/3 骨架占位:Pass A 可达性 + Pass B use 计数迭代 + Pass C mark-sweep。 + if !f.insts.is_empty() { + // TODO(Task 2/3):Pass A/B/C 实现(当前骨架 no-op,等价于不改写)。 + } +}