refactor(builder): route debug logs via trace
This commit is contained in:
@ -427,19 +427,38 @@ impl MirBuilder {
|
||||
|
||||
// Debug trace
|
||||
if std::env::var("NYASH_STATIC_CALL_TRACE").ok().as_deref() == Some("1") {
|
||||
eprintln!(
|
||||
"[DEBUG] try_build_static_method_call: obj_name={}, method={}",
|
||||
obj_name, method
|
||||
let trace = crate::mir::builder::control_flow::joinir::trace::trace();
|
||||
trace.stderr_if(
|
||||
&format!(
|
||||
"[DEBUG] try_build_static_method_call: obj_name={}, method={}",
|
||||
obj_name, method
|
||||
),
|
||||
true,
|
||||
);
|
||||
eprintln!("[DEBUG] is_local_var={}", is_local_var);
|
||||
trace.stderr_if(&format!("[DEBUG] is_local_var={}", is_local_var), true);
|
||||
if is_local_var {
|
||||
eprintln!("[DEBUG] variable_map contains '{}' - treating as local variable, will use method call", obj_name);
|
||||
eprintln!(
|
||||
"[DEBUG] variable_map keys: {:?}",
|
||||
self.variable_ctx.variable_map.keys().collect::<Vec<_>>()
|
||||
trace.stderr_if(
|
||||
&format!(
|
||||
"[DEBUG] variable_map contains '{}' - treating as local variable, will use method call",
|
||||
obj_name
|
||||
),
|
||||
true,
|
||||
);
|
||||
trace.stderr_if(
|
||||
&format!(
|
||||
"[DEBUG] variable_map keys: {:?}",
|
||||
self.variable_ctx.variable_map.keys().collect::<Vec<_>>()
|
||||
),
|
||||
true,
|
||||
);
|
||||
} else {
|
||||
eprintln!("[DEBUG] '{}' not in variable_map - treating as static box, will use global call", obj_name);
|
||||
trace.stderr_if(
|
||||
&format!(
|
||||
"[DEBUG] '{}' not in variable_map - treating as static box, will use global call",
|
||||
obj_name
|
||||
),
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -565,30 +584,43 @@ impl MirBuilder {
|
||||
fn trace_receiver_if_enabled(&self, object: &ASTNode, object_value: ValueId) {
|
||||
if std::env::var("NYASH_DEBUG_PARAM_RECEIVER").ok().as_deref() == Some("1") {
|
||||
if let ASTNode::Variable { name, .. } = object {
|
||||
eprintln!(
|
||||
"[DEBUG/param-recv] build_method_call receiver '{}' → ValueId({})",
|
||||
name, object_value.0
|
||||
let trace = crate::mir::builder::control_flow::joinir::trace::trace();
|
||||
trace.stderr_if(
|
||||
&format!(
|
||||
"[DEBUG/param-recv] build_method_call receiver '{}' → ValueId({})",
|
||||
name, object_value.0
|
||||
),
|
||||
true,
|
||||
);
|
||||
if let Some(origin) = self.type_ctx.value_origin_newbox.get(&object_value) {
|
||||
eprintln!("[DEBUG/param-recv] origin: {}", origin);
|
||||
trace.stderr_if(&format!("[DEBUG/param-recv] origin: {}", origin), true);
|
||||
}
|
||||
if let Some(&mapped_id) = self.variable_ctx.variable_map.get(name) {
|
||||
eprintln!(
|
||||
"[DEBUG/param-recv] variable_map['{}'] = ValueId({})",
|
||||
name, mapped_id.0
|
||||
trace.stderr_if(
|
||||
&format!(
|
||||
"[DEBUG/param-recv] variable_map['{}'] = ValueId({})",
|
||||
name, mapped_id.0
|
||||
),
|
||||
true,
|
||||
);
|
||||
if mapped_id != object_value {
|
||||
eprintln!("[DEBUG/param-recv] ⚠️ MISMATCH! build_expression returned different ValueId!");
|
||||
trace.stderr_if(
|
||||
"[DEBUG/param-recv] ⚠️ MISMATCH! build_expression returned different ValueId!",
|
||||
true,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
eprintln!(
|
||||
"[DEBUG/param-recv] ⚠️ '{}' NOT FOUND in variable_map!",
|
||||
name
|
||||
trace.stderr_if(
|
||||
&format!(
|
||||
"[DEBUG/param-recv] ⚠️ '{}' NOT FOUND in variable_map!",
|
||||
name
|
||||
),
|
||||
true,
|
||||
);
|
||||
}
|
||||
eprintln!(
|
||||
"[DEBUG/param-recv] current_block: {:?}",
|
||||
self.current_block
|
||||
trace.stderr_if(
|
||||
&format!("[DEBUG/param-recv] current_block: {:?}", self.current_block),
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,11 +83,19 @@ impl MirBuilder {
|
||||
ctx.saved_function = self.scope_ctx.current_function.take();
|
||||
ctx.saved_block = self.current_block.take();
|
||||
|
||||
eprintln!(
|
||||
"[DEBUG/create_function_skeleton] Creating function: {}",
|
||||
func_name
|
||||
let trace = crate::mir::builder::control_flow::joinir::trace::trace();
|
||||
trace.emit_if(
|
||||
"debug",
|
||||
"create_function_skeleton",
|
||||
&format!("Creating function: {}", func_name),
|
||||
trace.is_enabled(),
|
||||
);
|
||||
trace.emit_if(
|
||||
"debug",
|
||||
"create_function_skeleton",
|
||||
&format!("Entry block: {:?}", entry),
|
||||
trace.is_enabled(),
|
||||
);
|
||||
eprintln!("[DEBUG/create_function_skeleton] Entry block: {:?}", entry);
|
||||
|
||||
// Phase 136 Step 3/7: Use scope_ctx as SSOT
|
||||
self.scope_ctx.current_function = Some(function);
|
||||
@ -166,17 +174,33 @@ impl MirBuilder {
|
||||
|
||||
/// 🎯 箱理論: Step 4 - 本体lowering
|
||||
fn lower_function_body(&mut self, body: Vec<ASTNode>) -> Result<(), String> {
|
||||
let trace = crate::mir::builder::control_flow::joinir::trace::trace();
|
||||
|
||||
if crate::config::env::joinir_dev_enabled() {
|
||||
let tree = crate::mir::control_tree::StepTreeBuilderBox::build_from_block(&body);
|
||||
crate::mir::builder::control_flow::joinir::trace::trace()
|
||||
.dev("control_tree/step_tree", &tree.to_compact_string());
|
||||
trace.dev("control_tree/step_tree", &tree.to_compact_string());
|
||||
}
|
||||
|
||||
eprintln!("[DEBUG/lower_function_body] body.len() = {}", body.len());
|
||||
trace.emit_if(
|
||||
"debug",
|
||||
"lower_function_body",
|
||||
&format!("body.len() = {}", body.len()),
|
||||
trace.is_enabled(),
|
||||
);
|
||||
let program_ast = function_lowering::wrap_in_program(body);
|
||||
eprintln!("[DEBUG/lower_function_body] About to call build_expression");
|
||||
trace.emit_if(
|
||||
"debug",
|
||||
"lower_function_body",
|
||||
"About to call build_expression",
|
||||
trace.is_enabled(),
|
||||
);
|
||||
let _last = self.build_expression(program_ast)?;
|
||||
eprintln!("[DEBUG/lower_function_body] build_expression completed");
|
||||
trace.emit_if(
|
||||
"debug",
|
||||
"lower_function_body",
|
||||
"build_expression completed",
|
||||
trace.is_enabled(),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user