-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix using lazily elaborated comptime globals (#5995)
# Description ## Problem\* Resolves #5991 ## Summary\* Fixes two issues: 1. The original linked issue where elaborating a function early would cause any globals to be "locked in" in a sense. 2. The fact that we were never actually mutating underlying values in the interpreter. ## 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
Showing
6 changed files
with
62 additions
and
15 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
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
7 changes: 7 additions & 0 deletions
7
test_programs/compile_success_empty/comptime_globals_regression/Nargo.toml
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 = "comptime_globals_regression" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.33.0" | ||
|
||
[dependencies] |
23 changes: 23 additions & 0 deletions
23
test_programs/compile_success_empty/comptime_globals_regression/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,23 @@ | ||
comptime mut global COUNTER = 0; | ||
|
||
fn main() { | ||
comptime | ||
{ | ||
increment() | ||
}; | ||
comptime | ||
{ | ||
increment() | ||
}; | ||
|
||
assert_eq(get_counter(), 2); | ||
} | ||
|
||
fn get_counter() -> Field { | ||
COUNTER | ||
} | ||
|
||
comptime fn increment() { | ||
COUNTER += 1; | ||
assert_eq(get_counter(), COUNTER); | ||
} |