-
Notifications
You must be signed in to change notification settings - Fork 174
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
Epic: Metaprogramming #4594
Labels
aztec.nr
Helpful for development of Aztec.nr the smart contract framework
enhancement
New feature or request
Milestone
Comments
5 tasks
github-merge-queue bot
pushed a commit
that referenced
this issue
Mar 20, 2024
# Description ## Problem\* Resolves #4586 Part of #4594 ## Summary\* Adds a `quote { ... }` expression to the parser along with a new builtin `Code` type which it is the only method of creating. ## Additional Context The quote expression can only currently quote expressions and statements. It cannot yet quote top-level statements - we'd need more parser changes for this. In particular the top level statement parser would now need to be recursive and passed down all the way to the expression level... Trying to use `quote` in a program gives you an `experimental feature` warning. Indeed, the only thing you can do with it currently is panic once it gets to monomorphization without being removed from the runtime program yet. ## Documentation\* Check one: - [x] No documentation needed. - I'm following the pattern with other experimental features and waiting to document them until they're stable. For this, it means quote won't be documented until the base for metaprogramming is completed. - [ ] 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.
TomAFrench
pushed a commit
that referenced
this issue
Apr 3, 2024
# Description ## Problem\* Resolves #4586 Part of #4594 ## Summary\* Adds a `quote { ... }` expression to the parser along with a new builtin `Code` type which it is the only method of creating. ## Additional Context The quote expression can only currently quote expressions and statements. It cannot yet quote top-level statements - we'd need more parser changes for this. In particular the top level statement parser would now need to be recursive and passed down all the way to the expression level... Trying to use `quote` in a program gives you an `experimental feature` warning. Indeed, the only thing you can do with it currently is panic once it gets to monomorphization without being removed from the runtime program yet. ## Documentation\* Check one: - [x] No documentation needed. - I'm following the pattern with other experimental features and waiting to document them until they're stable. For this, it means quote won't be documented until the base for metaprogramming is completed. - [ ] 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.
This was referenced May 8, 2024
github-merge-queue bot
pushed a commit
that referenced
this issue
May 9, 2024
) # Description ## Problem\* Working towards #4594 ## Summary\* Adds a hidden compiler option `--use-elaborator` to enable the experimental elaborator code to be run on a codebase. This also connects the elaborator with `dc_crate` (and thus the cli flag above) by filling in the stub for elaborating functions. Filling in the stub required quite a bit of code but it was as usual just copied from name resolution and type checking. ## Additional Context Originally I wanted to connect the elaborator to more of the frontend (e.g. resolve globals, types, traits, etc) but this already ballooned to a large line count. To review I'd recommend reviewing the non-elaborator portions first then just skimming through the elaborator portions since they are copied from `Resolver::resolve_function`, `Resolver::extract_meta`, `Resolver::intern_function`, and `type_check_func`. ## 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.
github-merge-queue bot
pushed a commit
that referenced
this issue
May 21, 2024
# Description ## Problem\* Working towards #4594 ## Summary\* Adds support for impls and trait impls to the elaborator. This was somewhat satisfying to add since the existing code for this in `dc_crate.rs` is very messy & long winded due to our current design of creating a new `NameResolver` for every resolution. Keeping everything in the same elaborator and not needing to keep setting the interner, def maps, current crate, module, generics, append errors, etc saved many lines. I think this implementation is roughly half the size as a result. ## Additional Context Still need types, type aliases, and globals after this. The pass is testable after that but is expected to fail the comptime tests at least. So I'll need to inline the comptime scanning pass in the elaborator as well. After that the pass is theoretically done but realistically there will be bugs to fix before we can make it the default. ## 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.
5 tasks
github-merge-queue bot
pushed a commit
that referenced
this issue
May 22, 2024
# Description ## Problem\* Working towards #4594 ## Summary\* Adds support for resolving top-level traits and type definitions to the elaborator. ## Additional Context After this PR only globals will need to be resolved in the elaborator. ## 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.
5 tasks
github-merge-queue bot
pushed a commit
that referenced
this issue
May 28, 2024
# Description ## Problem\* Working towards #4594 ## Summary\* When run on a program the elaborator would always panic previously due to `FuncMeta`s not yet being set for other functions while one function was being elaborated. This is because we used to set them during name resolution and only check them during type checking, but now that these two passes are merged we'll need to set them all before elaboration instead. This PR creates a new `define_function_metas` function to create the `FuncMeta`s beforehand. I imagine there are more changes required here related to scoping / generics / parameters but this at least stops the panic. ## Additional Context This is the first of the elaborator PRs to feature only new changes rather than largely copied code, so feel free to critique as usual if you think a different approach would be better, notice an issue, etc. After this PR the elaborator will run on a small example program, only producing 1052 errors in the standard library 🙂. Most of these errors appear to be variants of "no method named '...' found for ..." and "no matching impl found for ..." ## 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. --------- Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com> Co-authored-by: Maxim Vezenov <mvezenov@gmail.com>
Current goal is to get a vertical slice of metaprogramming working to support deriving a trait impl of a simple type on a simple trait like Default: comptime fn derive_default(typ: TypeDefinition) -> Quoted {
let generics: [Quoted] = typ.generics();
assert(generics.is_empty(), "derive_default: Deriving Default on generic types is currently unimplemented");
let type_name: Type = typ.as_type();
let fields: [(Quoted, Type)] = typ.fields();
let fields: Quoted = fields.map(|(name, _)| quote { $name : Default::default(), })
.join();
quote {
impl Default for $type_name {
fn default() -> Self {
Self { $fields }
}
}
}
}
#[derive_default]
struct Foo {
x: Field
}
// Expected output:
//
// impl Default for Foo {
// fn default(this: Self) -> Self {
// Foo {
// x: Default::default(),
// }
// }
// } Required unimplemented features:
fn join(slice: [Quoted]) -> Quoted {
let mut ret = quote {};
for element in slice {
// Since quoted values are token streams, we do not need (or want) a `;` separator.
ret = quote { $ret $element };
}
ret
}
Edit: We used to have a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
aztec.nr
Helpful for development of Aztec.nr the smart contract framework
enhancement
New feature or request
Proposal: https://hackmd.io/Tkzo_ryvTsWMPESmWHPiZw?view
Core Tasks for Noir 1.0
quote
expressions for metaprogramming #4586comptime
modifier for variables/functions which only exist at compile-time #4588Hir -> Ast
conversion #4796comptime
globals #4916comptime
globals #4917comptime
context #4924comptime
expressions have been evaluated #5168comptime
code when a type definition is annotated with acomptime
function #5255TypeDefinition
#5285quote
token streams #5284Bugs for Noir 1.0
Nice-to-haves for Noir 1.0+
derive
attribute with support for (de)serialize macros on existing complex types #3379The text was updated successfully, but these errors were encountered: