From ff4c4b84c558ba0f7998daa36cfb0d9da816d9f6 Mon Sep 17 00:00:00 2001 From: nyash-codex Date: Tue, 18 Nov 2025 06:46:22 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20Hotfix=203:=20NewBox=20ValueId(0?= =?UTF-8?q?)=20Bug=20Fix=20-=20Module-Level=20Generator=20Elimination?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **根本原因**: build_new_expression が value_gen.next() を使用(module-level, starts from 0) **修正内容**: - src/mir/builder.rs:738 - Core-13 pure mode NewBox - src/mir/builder.rs:760 - IntegerBox optimization path - src/mir/builder.rs:779 - General NewBox emission path **Before**: ```rust let dst = self.value_gen.next(); // ❌ Starts from ValueId(0), overwrites param! ``` **After**: ```rust let dst = self.next_value_id(); // ✅ Respects function param reservation ``` **Impact**: - ✅ `new ArrayBox()` now gets correct ValueId (e.g., %4 instead of %0) - ✅ No more parameter ValueId collision - ✅ SSA form integrity preserved **Test Result**: ``` Before: %0 = new ArrayBox() // ❌ Overwrites param %0 After: %4 = new ArrayBox() // ✅ Correct allocation ``` **業界標準準拠**: - ✅ Single Source of Truth: next_value_id() is the only allocator - ✅ Context-aware allocation (function vs module level) **Next Issue Discovered**: - Static box methods need receiver ValueId reservation - `collect_entries/1` signature shows 1 param, but needs 2 ValueIds (receiver + param) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/mir/builder.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/mir/builder.rs b/src/mir/builder.rs index b45d988d..f4c1fe6a 100644 --- a/src/mir/builder.rs +++ b/src/mir/builder.rs @@ -734,7 +734,8 @@ impl MirBuilder { args.push(ty_id); args.extend(arg_vals); // Call env.box.new - let dst = self.value_gen.next(); + // 📦 Hotfix 3: Use next_value_id() to respect function parameter reservation + let dst = self.next_value_id(); self.emit_instruction(MirInstruction::ExternCall { dst: Some(dst), iface_name: "env.box".to_string(), @@ -755,7 +756,8 @@ impl MirBuilder { .. } = arguments[0].clone() { - let dst = self.value_gen.next(); + // 📦 Hotfix 3: Use next_value_id() to respect function parameter reservation + let dst = self.next_value_id(); self.emit_instruction(MirInstruction::Const { dst, value: ConstValue::Integer(n), @@ -773,7 +775,8 @@ impl MirBuilder { } // Generate the destination ValueId - let dst = self.value_gen.next(); + // 📦 Hotfix 3: Use next_value_id() to respect function parameter reservation + let dst = self.next_value_id(); // Emit NewBox instruction for all Box types // VM will handle optimization for basic types internally