-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent
no_predicates
from removing predicates in calling func…
…tion (#5452) # Description ## Problem\* Resolves #5435 ## Summary\* This PR caches the current `side_effects_enabled` value on the `PerFunctionContext` and restores it after inlining another function. This ensures that any `EnableSideEffects` instructions from the inlined function do not leak out into the calling function. ## 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. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
- Loading branch information
1 parent
fa9b444
commit 66244b6
Showing
4 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "regression_5435" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.31.0" | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
input = "0" | ||
enable = false |
18 changes: 18 additions & 0 deletions
18
test_programs/execution_success/regression_5435/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
fn main(input: Field, enable: bool) { | ||
if enable { | ||
let hash = no_predicate_function(input); | ||
// `EnableSideEffects` instruction from above instruction leaks out and removes the predicate from this call, | ||
// resulting in execution failure. | ||
fail(hash); | ||
} | ||
} | ||
|
||
#[no_predicates] | ||
fn no_predicate_function(enable: Field) -> Field { | ||
// if-statement ensures that an `EnableSideEffects` instruction is emitted. | ||
if enable == 0 { 1 } else { 0 } | ||
} | ||
|
||
unconstrained fn fail(_: Field) { | ||
assert(false); | ||
} |