pure-c / purec

C backend for PureScript
232 stars 8 forks source link

RangeError: Maximum call stack size exceeded #44

Closed Lupino closed 3 years ago

Lupino commented 5 years ago

when I compile https://github.com/pure-c/purescript-arrays/pull/1 test file cause an RangeError

https://github.com/pure-c/purescript-arrays/blob/master/test/Test/Data/Array.purs

felixSchl commented 5 years ago

Likely lack of tco which i am battling through atm

felixSchl commented 5 years ago

Sorry I responded a bit to hastely from my phone this morning. Upon second reading it would seem you are experiencing the issue during compilation, meaning that we overflow stack while compiling. If you have pure-c checked out, you mind trying running the AST.everywhereM and AST.everythingM traversal functions through runTrampoline? That would be the easiest win, otherwise maybe time has come to invest time to make these functions tail recursive.

Lupino commented 5 years ago

more then 200 line will raise an RangeError

Lupino commented 5 years ago
screen shot 2018-10-20 at 6 37 31 pm

also raise a RangeError on compile Test/Data/Array.purs

felixSchl commented 5 years ago

Hm I can successfully compile it over here and run the purescript-arrays test suite. Are you able to identify whereabouts the problem is occurring?

felixSchl commented 5 years ago

Have you tried using latest master?

Lupino commented 5 years ago

It is my mistake, now I can success compile the source。 I only update my macos version,and reinstall nodejs

Lupino commented 5 years ago

Now it raise a range error, when I commit line

screenshot 2018-10-21 at 8 32 09 am

and recompile (just run make)

Lupino commented 5 years ago

I find RangeError will occur on recompile

make clean
make         # this compile will fine.

#  edit the test/Test/Data/Array.purs 
make         # this time raise an RangeError
felixSchl commented 5 years ago

I can reproduce this but cannot explain why this is happening. It appears the stack overflow occurs trying to parse the corefn for these large modules. It's a riddle to me, however, why it would work after make clean and only fail subsequently.

felixSchl commented 5 years ago

So, running the corefn parsing through trampoline solves the issue. However, it's currently not possible to evaluate F to any other monad than Identity. I've submitted a pull request to purescript-foreign that recovers this ability: https://github.com/purescript/purescript-foreign/pull/74. We'll have to see if it gets merged or not. For now, I simply changed the definition of ExceptT to use Trampoline in my local bower_components.... pretty messy.