-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow globals to refer to any expression (#4293)
# Description ## Problem\* Resolves #1734 ## Summary\* Allows globals to be defined as any expression using the dependency graph to ensure there are no cycles. Note that globals defined via a function call are allowed: `global FOO = bar();`, although the function will be re-called each time the global is used since globals are just substituted for their definitions where they are used. Example program: ```rs global A = B; global B = foo(); fn foo() -> Field { A } ``` Example error: ``` error: Dependency cycle found ┌─ /Users/user/Code/Noir/noir/short/src/main.nr:2:8 │ 2 │ global B = foo(); │ - 'B' recursively depends on itself: B -> foo -> A -> B │ ``` ## Additional Context This is a somewhat longer PR because it also includes a refactoring to use a new `GlobalId` over `StmtId`. I found this necessary to allow referring to globals in cycles where another global may not be resolved yet. WIP because I still need to: - ~~Track dependencies within functions~~ - ~~Update documentation~~ ## Documentation\* Check one: - [ ] No documentation needed. - [x] Documentation included in this PR. - [ ] **[Exceptional Case]** 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. --------- Co-authored-by: José Pedro Sousa <[email protected]>
- Loading branch information
1 parent
d86ff1a
commit 479330e
Showing
13 changed files
with
286 additions
and
184 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
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
Oops, something went wrong.