forked from noir-lang/noir
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement trait dispatch in the comptime interpreter (noir-lang…
…#5376) # Description ## Problem\* Resolves noir-lang#4925 ## Summary\* Implements trait dispatch in the interpreter - which includes operator overloading. ## Additional Context I've tried to share as much code as I can between the interpreter and monomorphization. Most of this PR is rather straightforward adapting code in the monomorphizer to use in the interpreter. The main new bit of code is a stack of `FunctionContext`s in the elaborator. I found at that when having a comptime block in the middle of a function, even a known trait would panic that it had no impl. This was because we previously delayed solving impls to the very end of a function when types were known. I've had to change this into a stack instead so that we can solve impls that were done within a comptime block at the end of that comptime block, just before interpreting so that they'd be defined. Similarly, the `type_variables` list also needed to be placed here since defaulting types can cause some trait constraints to succeed/fail without it. I settled on `function_context` for the name of this stack but am not sure if it fits the case where we have a stack of comptime contexts instead. Similarly, `ComptimeContext` also didn't make sense for the more common case of only having one of them for a function with no comptime blocks. ## 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
15 changed files
with
419 additions
and
219 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
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.