Kindelia icon indicating copy to clipboard operation
Kindelia copied to clipboard

stack overflow when dropping big nested term

Open racs4 opened this issue 2 years ago • 1 comments

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: Captura de Tela 2022-06-24 às 13 10 59

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

racs4 avatar Jun 24 '22 16:06 racs4

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

racs4 avatar Jun 24 '22 18:06 racs4