-
Notifications
You must be signed in to change notification settings - Fork 2
recursion depth leakage #10
Description
Hi,
as I was testing around with cyan. I ran into a leakage ( Segmentation fault (core dumped) ).
Consider this cyan code:
fun fac(n) {
if n == 1 then 1 else n * fac(n-1)
}
out(fac(2000))
This code is giving me: Runtime Error: Maximum recursion depth exceeded which is okay.
But if I go into interpreter.py and do this:
import sys
sys.setrecursionlimit(30000)
As there may not be a way to do this from cyan itself - this was one of the ways to do it.
Now, when I run the code - I get:
Segmentation fault (core dumped)
To further examine what's going, you could use valgrind:
valgrind --leak-check=full -v ./python ../__main__.py ../fac.cyan
From what I've seen, I can say this is due to the fact that there is a double layer of recursion that you have to go through since this language is written in Python. So each time you run the factorial fun, we have O(n^2) - thus n^2 memory is used as well. This is when Python gets knotted and exhausted. hence: Segmentation fault (core dumped)
I will try debugging this on my other machine just to make sure. However, my assumption may be incorrect.
I understand that Cyan might not be designed to handle heavy stuff like this but this is interesting to point out.
This is a great project!
Kind regards.