erg-lang / erg

A statically typed language compatible with Python
http://erg-lang.org
Apache License 2.0
2.69k stars 55 forks source link

Stack overflow occurs when running parser on Windows with debug build #115

Closed mtshiba closed 2 years ago

mtshiba commented 2 years ago

Reproducible code

$ cargo run --features debug examples/class.er

Result A stack overflow occurs.

OS Windows 11

First-aid treatment

$ editbin /STACK:0x350000 target/debug/erg.exe

If you run the above command, a stack overflow will not happen.

mtshiba commented 2 years ago

This issue was not reproduced in release builds or on Unix-family OSs. Apparently Windows allocates a small stack size to executables by default.

mtshiba commented 2 years ago

Or perhaps the current parser process should be renovated to be more efficient.

GreasySlug commented 2 years ago

I have researched this issue a bit.

The following files cause overflow.

Looking at where the overflow is occurring, it occurs in braces.

ex)

Point = Class {x = Int|-> overflow
Point2D = Class {x|-> overflow
LitExpr = Class {.i = Int|-> overflow
Nil T = Class Impl := Phantom(|-> overflow

So I tried to see how far nesting would cause overflow, and it occurs at 25 times or more.

At the 25th time, it takes almost 1-2 minutes before the result is displayed.

r = (1, (2, (3, (4, (5, (6, (7, (8, (9, (10, (11, (12, (13, (14, (15, (16, (17, (18, (19, (20, (21, (22, (23, (24, 25))))))))))))))))))))))))
print! r

Or perhaps the current parser process should be renovated to be more efficient.

I agree with this opinion.