From be52064765202ccfb28011fcfde0b164bdfb13d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=88=B1=E7=89=B9=E6=AF=8F=E7=BE=8A=E9=98=9F?= Date: Thu, 6 Aug 2026 12:16:51 +0800 Subject: [PATCH] =?UTF-8?q?test(compiler):=20compile=5Fmultiple=5Fstmts=20?= =?UTF-8?q?=E9=94=9A=E6=8C=89=20D-11=20=E6=94=BE=E5=AE=BD=E4=B8=BA?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E6=80=A7=E6=96=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DCE 默认开启删除死 '1; 2' 链的 LOAD_CONST,仅剩顶层值 '3'。 精确计数断言 load_count >= 3 实测失败,放宽为 any(LOAD_CONST)。 --- crates/oxide_compiler/tests/compile_expr_tests.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/crates/oxide_compiler/tests/compile_expr_tests.rs b/crates/oxide_compiler/tests/compile_expr_tests.rs index 16f2919..5bbcab6 100644 --- a/crates/oxide_compiler/tests/compile_expr_tests.rs +++ b/crates/oxide_compiler/tests/compile_expr_tests.rs @@ -85,12 +85,10 @@ fn compile_negation() { fn compile_multiple_stmts() { let module = compile_source("1; 2; 3;"); - let load_count = module - .bytecode - .iter() - .filter(|&&i| opcode::opcode(i) == OpCode::LOAD_CONST) - .count(); - assert!(load_count >= 3); + // D-11 放宽:Compiler 默认 DCE 开启,死 `1; 2` 链的 LOAD_CONST 被删除, + // 仅剩顶层值 `3` 的 LOAD_CONST(HALT 经 reg0 返回)。精确计数断言放宽为存在性断言。 + let has_load = module.bytecode.iter().any(|&i| opcode::opcode(i) == OpCode::LOAD_CONST); + assert!(has_load, "expected at least one LOAD_CONST for the final value"); } #[test]