Kindelia
Kindelia copied to clipboard
stack overflow when dropping big nested term
When evaluating a big term (term with too many nested terms) like this one
ctr {Succ p}
ctr {Zero}
fun (ToSucc n) {
(ToSucc #0) = {Zero}
(ToSucc n) = {Succ (ToSucc (- n #1))}
}
run {
!done (ToSucc #8000) // = {Succ {Succ {Succ {Succ ... {Zero}}}}}
}
a stack overflow error happens.
Debugging this I found out that the error occurs when the term is dropped (the term dropped is created with readback
in run_statement
function and is dropped when the function ends), as is shown in this call stack:
Recursive structures are recursively dropped in rust causing stack overflow in big nested structures, as explained here. A simple(?) workaround would be implement the trait Drop for the Term struct in the same way as shown here and here. I tried implementing a solution following the example shown in the first link but found myself stuck on compiler errors
I forgot to mention that a test with the name stack_overlfow2
can be used to debug, test and reproduce this. It is located in test.rs
and can be executed with cargo test test::stack_overflow2 -- --include-ignored