diff --git a/src/mir/builder/builder_calls.rs b/src/mir/builder/builder_calls.rs index 5e5203b7..2d8a4441 100644 --- a/src/mir/builder/builder_calls.rs +++ b/src/mir/builder/builder_calls.rs @@ -160,6 +160,9 @@ impl super::MirBuilder { .filter(|(_, &vid)| vid == r) .map(|(k, _)| k.clone()) .collect(); + // CRITICAL DEBUG: Show type information sources + let origin = self.value_origin_newbox.get(&r).cloned(); + let vtype = self.value_types.get(&r).cloned(); eprintln!( "[builder/recv-trace] fn={} bb={:?} method={}.{} recv=%{} aliases={:?}", current_fn, @@ -169,6 +172,10 @@ impl super::MirBuilder { r.0, names ); + eprintln!( + "[builder/recv-trace] value_origin_newbox: {:?}, value_types: {:?}", + origin, vtype + ); } // Prefer pinning to a slot so start_new_block can propagate it across entries. let r_pinned = self.pin_to_slot(r, "@recv").unwrap_or(r); diff --git a/src/mir/builder/decls.rs b/src/mir/builder/decls.rs index 19b61672..73912190 100644 --- a/src/mir/builder/decls.rs +++ b/src/mir/builder/decls.rs @@ -33,12 +33,18 @@ impl super::MirBuilder { let func_name = format!("{}.{}", box_name, "main"); eprintln!("[DEBUG] build_static_main_box: Before lower_static_method_as_function"); eprintln!("[DEBUG] variable_map = {:?}", self.variable_map); + // ✅ CRITICAL FIX: Clear metadata maps BEFORE Phase 1 compilation + // This prevents pollution from using statement resolution during Phase 1 + // from leaking into Phase 2 (inline main execution). + // Root cause: Using statements create boxes (ParserBox, etc.) and their metadata + // (variable_map, value_origin_newbox, value_types) gets saved/restored incorrectly. + // This caused parameters like "args" to be incorrectly typed as "ParserBox". + self.variable_map.clear(); + self.value_origin_newbox.clear(); + self.value_types.clear(); let _ = self.lower_static_method_as_function(func_name, params.clone(), body.clone()); eprintln!("[DEBUG] build_static_main_box: After lower_static_method_as_function"); eprintln!("[DEBUG] variable_map = {:?}", self.variable_map); - // ✅ PHI UseBeforeDef修正: 関数生成後、変数マップをクリア - // 理由: cf_block()で同じbodyを再処理する際、前の関数の変数(PHI ID等)が混入するのを防ぐ - self.variable_map.clear(); // Convert the method body to a Program AST node and lower it let program_ast = ASTNode::Program { statements: body.clone(), diff --git a/src/mir/builder/exprs.rs b/src/mir/builder/exprs.rs index feebec2d..c9c4469b 100644 --- a/src/mir/builder/exprs.rs +++ b/src/mir/builder/exprs.rs @@ -162,6 +162,19 @@ impl super::MirBuilder { } else if is_static { // Generic static box: lower all static methods into standalone MIR functions (BoxName.method/N) self.user_defined_boxes.insert(name.clone()); + // ✅ CRITICAL FIX: Clear metadata maps BEFORE compiling each static box + // This prevents pollution from using statement resolution from leaking between boxes. + // Root cause: Using statements create boxes (ParserBox, etc.) and their metadata + // (variable_map, value_origin_newbox, value_types) leaks into subsequent box compilations. + // This caused parameters like "args" to be incorrectly typed as "ParserBox". + eprintln!("[DEBUG/static-box] Processing static box: {}", name); + eprintln!("[DEBUG/static-box] BEFORE clear: value_origin_newbox size={}, value_types size={}", + self.value_origin_newbox.len(), self.value_types.len()); + self.variable_map.clear(); + self.value_origin_newbox.clear(); + self.value_types.clear(); + eprintln!("[DEBUG/static-box] AFTER clear: value_origin_newbox size={}, value_types size={}", + self.value_origin_newbox.len(), self.value_types.len()); for (method_name, method_ast) in methods.clone() { if let ASTNode::FunctionDeclaration { params, body, .. } = method_ast { let func_name = format!( diff --git a/src/mir/builder/lifecycle.rs b/src/mir/builder/lifecycle.rs index 9e172c28..b36a1375 100644 --- a/src/mir/builder/lifecycle.rs +++ b/src/mir/builder/lifecycle.rs @@ -87,6 +87,14 @@ impl super::MirBuilder { if name == "Main" { main_static = Some((name.clone(), methods.clone())); } else { + // ✅ CRITICAL FIX: Clear metadata maps BEFORE compiling each static box + // This prevents pollution from using statement resolution and previous boxes + // from leaking into this box's method compilations. + // Root cause: Using statements and previous box compilations create metadata + // (variable_map, value_origin_newbox, value_types) that leaks into subsequent compilations. + self.variable_map.clear(); + self.value_origin_newbox.clear(); + self.value_types.clear(); // Lower all static methods into standalone functions: BoxName.method/Arity for (mname, mast) in methods.iter() { if let N::FunctionDeclaration { params, body, .. } = mast {