Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack overflow in parser #6975

Open
vezenovm opened this issue Jan 7, 2025 · 1 comment
Open

Stack overflow in parser #6975

vezenovm opened this issue Jan 7, 2025 · 1 comment
Labels
bug Something isn't working parser issues primarily related to the parser

Comments

@vezenovm
Copy link
Contributor

vezenovm commented Jan 7, 2025

Aim

I want the user to be able to repeat the same token many times (essentially unlimited times as it should be up to the user), without triggering a stack overflow.

Expected Behavior

The compiler should not stack overflow.

Bug

For our example we are just going to comment out EXPONENTIATE in regression_4709. You could even comment out the entire file. This will result in a stack overflow:

thread '<unknown>' has overflowed its stack
fatal runtime error: stack overflow

This overflow looks to be due to recursion being utilized for parsing a list of items

pub(super) fn parse_many<T, F>(

For comments parse_many is used here.

This is an edge case and seems unlikely to be hit but I did not test under what circumstances we hit the stack limit. It would be good to know under what circumstances we may hit the stack limit as parse_many is utilized in many locations. I could see this stack overflow being hit by a use tree in larger programs with many imports.

To Reproduce

  1. Comment out src/main.nr in regression_4709
  2. nargo compile
  3. See stack overflow

Workaround

Yes

Workaround Description

The workaround is to not have so many repeated tokens.

Additional Context

No response

Project Impact

Nice-to-have

Blocker Context

I would be surprised this would block any user and that they could not work around by manually splitting up their large token list.

Nargo Version

nargo version = 1.0.0-beta.1 noirc version = 1.0.0-beta.1+2e5d91f3d69ce629d07eb6041736b5a8e8ed2013 (git version hash: 2e5d91f, is dirty: false)

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@vezenovm vezenovm added bug Something isn't working parser issues primarily related to the parser labels Jan 7, 2025
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jan 7, 2025
@vezenovm
Copy link
Contributor Author

vezenovm commented Jan 7, 2025

I just noticed that the first line in regression_4709 is // Regression test for issue #4709. Commenting out the whole file makes this line // // Regression test for issue #4709, which gives me a stack overflow. Deleting the extra // I get

error: cannot compile crate into a program as it does not contain a `main` function

as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser issues primarily related to the parser
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant