From d47944b2fd74db8da80e8965273df2fabcf2ec36 Mon Sep 17 00:00:00 2001 From: Ashwin Naren Date: Tue, 15 Apr 2025 10:02:32 -0700 Subject: [PATCH] error handling --- compiler/codegen/src/ir.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/codegen/src/ir.rs b/compiler/codegen/src/ir.rs index 9106d3fdf..662ba81db 100644 --- a/compiler/codegen/src/ir.rs +++ b/compiler/codegen/src/ir.rs @@ -244,8 +244,10 @@ impl CodeInfo { let instr_display = instr.display(display_arg, self); eprint!("{instr_display}: {depth} {effect:+} => "); } - // Either it's less than 0 or more than u32. Option 1 is far more likely unless something is seriously wrong. - let new_depth = depth.checked_add_signed(effect).expect("The stack is detected to have likely been reduced to less than 0 elements, this is a bug."); + if effect < 0 && depth < effect.abs() as u32 { + panic!("The stack will underflow at {depth} with {effect} effect on {instr:?}"); + } + let new_depth = depth.checked_add_signed(effect).unwrap(); if DEBUG { eprintln!("{new_depth}"); }