-
Notifications
You must be signed in to change notification settings - Fork 219
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
Compiler panic when you make a recursive call which does not terminate #4828
Comments
This function isn't doing what the comment is suggesting. The if statement doesn't cause the function We should have a nicer error for this than a panic however. |
I had omitted the fact that functions only return the last instruction. I assumed it worked like in Rust, where an instruction not followed by a semicolon is treated as a return. Sorry for the misunderstanding. |
It does work the same as in Rust. In Rust and Noir an instruction not followed by a semicolon is not a return from the function, it just yields the value of that expression. The same code in Rust does however issue an error that the result of an if with no else is expected to be a unit value though and suggests maybe a |
Since this error applies to any recursive function and doesn't require a return call, I'm going to treat this issue as the general issue for improving the "Attempted to recur more than 1000 times during function inlining" error and am closing #4843. Minimal repro for this issue is fn main() {
main();
} |
…#6291) # Description ## Problem\* Resolves #4828 ## Summary\* Given a program like this: ``` fn main() { main(); } ``` Changed this panic message: ``` Attempted to recur more than 1000 times during function inlining. ``` Into this: ``` Attempted to recur more than 1000 times during inlining function 'main': acir(inline) fn main f0 { b0(): call f0() return } ``` I included the ACIR to help figure out which function is the culprit, in case the name is not enough. ## Additional Context I added a test to show that there is no compilation error or warning for the example program. It would be nice to issue a warning about unconditional recursion like Rust does. I'll try to do that in a followup PR. ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [ ] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
# Description ## Problem\* Related to #4828 Followup to #6291 ## Summary\* Added a new `ResolutionError::UnconditionalRecursion` which should result in a warning or compilation error where the function body recurses into the defining function with no alternative way to return. ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [ ] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
Aim
We (https://github.com/FuzzingLabs) found that the compiler panics when you make a recursive call without condition, even if a return call makes you go out of the loop.a
Expected Behavior
No panic should occur.
Bug
When a function makes a recursive call after a return statement, the compiler considers the recursive call, which can lead to a panic crash as it treats it as an infinite loop. As you can see in the code example, the
rec1
function has a return statement before the recursive call, preventing any potential looping. However, the compiler still perceives it as an infinite recursive function.rec2
is another function that might exhibit the same behavior, but in this case, the compiler doesn’t panic. This seems to be because the compiler never enters the else block. The same phenomenon occurs withrec3
.The issue occurs with the latest compiler version on the master branch. The error message is as follows:
To Reproduce
Project Impact
None
Impact Context
No response
Workaround
None
Workaround Description
No response
Additional Context
No response
Installation Method
None
Nargo Version
No response
NoirJS Version
No response
Would you like to submit a PR for this Issue?
None
Support Needs
No response
The text was updated successfully, but these errors were encountered: