📦 Hotfix 3: NewBox ValueId(0) Bug Fix - Module-Level Generator Elimination
**根本原因**: 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 <noreply@anthropic.com>
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user