Project version
0.7.2
Project
compiler
What happened?
compile_blk recursively processes every statement in a block, making stack usage proportional to statement count rather than syntactic nesting depth
At src/compile/mod.rs:227, compile_blk constructs the block's pair chain recursively. The recursive calls at lines 244 and 249 introduce approximately one stack frame per statement so a block containing N sequential statements produces O(N) call-stack depth, even though the source itself has no nesting.
This is specific to the code-generation phase. Parsing and type-checking process the same flat statement list iteratively and do not exhibit the same stack growth. As a result, an otherwise ordinary function containing many sequential statements can cause the compiler to exhaust its 8 MB stack and abort with a stack overflow.
It is not fixed by #401 as well and
Minimal reproduction steps
The code stack overflow's at around 3000~4000 let statements and compiles fine for 2000.
try using the python script below to generate a file for it and run it using simc
# python script
NUM_LETS = 5000
OUTPUT_FILE = "bug.simf"
with open(OUTPUT_FILE, "w", encoding="utf-8") as f:
f.write("fn main() {\n")
for i in range(NUM_LETS):
f.write(f" let x{i}: u32 = {i};\n")
f.write(" assert!(jet::eq_32(x0, 0));\n")
f.write("}\n")
print(f"Generated {NUM_LETS} sequential let bindings in {OUTPUT_FILE}")
The above script generates the bug.simf file with 5000 let statements which produces the following error on compilation.
error
thread 'main' (7347361) has overflowed its stack
fatal runtime error: stack overflow, aborting
[1] 38741 abort ./target/debug/simc ./bug.simf
Project version
0.7.2
Project
compiler
What happened?
compile_blkrecursively processes every statement in a block, making stack usage proportional to statement count rather than syntactic nesting depthAt
src/compile/mod.rs:227,compile_blkconstructs the block's pair chain recursively. The recursive calls at lines 244 and 249 introduce approximately one stack frame per statement so a block containing N sequential statements produces O(N) call-stack depth, even though the source itself has no nesting.This is specific to the code-generation phase. Parsing and type-checking process the same flat statement list iteratively and do not exhibit the same stack growth. As a result, an otherwise ordinary function containing many sequential statements can cause the compiler to exhaust its 8 MB stack and abort with a stack overflow.
It is not fixed by #401 as well and
Minimal reproduction steps
The code stack overflow's at around 3000~4000 let statements and compiles fine for 2000.
try using the python script below to generate a file for it and run it using
simcThe above script generates the bug.simf file with 5000 let statements which produces the following error on compilation.
error