fix: guard unified BoxCall recursion and document Stage-B stack overflow status
This commit is contained in:
@ -188,6 +188,10 @@ pub struct MirBuilder {
|
||||
/// infinite recursion (emit_unified_call → emit_box_or_plugin_call →
|
||||
/// emit_unified_call …) can occur when routing decisions disagree.
|
||||
pub(super) in_unified_boxcall_fallback: bool,
|
||||
|
||||
/// Recursion depth counter for debugging stack overflow
|
||||
/// Tracks the depth of build_expression calls to detect infinite loops
|
||||
pub(super) recursion_depth: usize,
|
||||
}
|
||||
|
||||
impl MirBuilder {
|
||||
@ -242,6 +246,7 @@ impl MirBuilder {
|
||||
schedule_mat_map: HashMap::new(),
|
||||
|
||||
in_unified_boxcall_fallback: false,
|
||||
recursion_depth: 0,
|
||||
}
|
||||
}
|
||||
|
||||
@ -371,7 +376,21 @@ impl MirBuilder {
|
||||
/// Build an expression and return its value ID
|
||||
pub(super) fn build_expression(&mut self, ast: ASTNode) -> Result<ValueId, String> {
|
||||
// Delegated to exprs.rs to keep this file lean
|
||||
self.build_expression_impl(ast)
|
||||
// Debug: Track recursion depth to detect infinite loops
|
||||
const MAX_RECURSION_DEPTH: usize = 200;
|
||||
self.recursion_depth += 1;
|
||||
if self.recursion_depth > MAX_RECURSION_DEPTH {
|
||||
eprintln!("\n[FATAL] ============================================");
|
||||
eprintln!("[FATAL] Recursion depth exceeded {} in build_expression", MAX_RECURSION_DEPTH);
|
||||
eprintln!("[FATAL] Current depth: {}", self.recursion_depth);
|
||||
eprintln!("[FATAL] AST node type: {:?}", std::mem::discriminant(&ast));
|
||||
eprintln!("[FATAL] ============================================\n");
|
||||
return Err(format!("Recursion depth exceeded: {} (possible infinite loop)", self.recursion_depth));
|
||||
}
|
||||
|
||||
let result = self.build_expression_impl(ast);
|
||||
self.recursion_depth -= 1;
|
||||
result
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user