fix(mir/builder): clear metadata maps to prevent type pollution between static boxes
Root cause: When compiling multiple static boxes, metadata from using statements and previous box compilations (variable_map, value_origin_newbox, value_types) leaked into subsequent compilations, causing parameters to be incorrectly typed. For example, "args" parameter was incorrectly inferred as "ParserBox" instead of its actual type. Changes: 1. lifecycle.rs:95-97: Clear metadata before compiling each non-Main static box 2. decls.rs:42-44: Clear metadata before Phase 1 compilation in build_static_main_box 3. exprs.rs:170-172: Clear metadata before processing static box methods 4. builder_calls.rs:164-178: Add debug traces for value_origin_newbox/value_types Impact: - Fixes StageBArgsBox.resolve_src ValueId(21) undefined error - Prevents "ParserBox" type contamination of parameters - Ensures clean compilation context for each static box Note: Revealed new bug in StageBBodyExtractorBox (Copy from undefined ValueId(114)) which needs separate investigation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -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);
|
||||
|
||||
@ -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(),
|
||||
|
||||
@ -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!(
|
||||
|
||||
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user