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: Allow arguments to attribute functions (noir-lang#5494)
# Description ## Problem\* Resolves noir-lang#5473 Resolves noir-lang#5476 ## Summary\* Allows arguments to attribute functions. - These arguments are all quoted by default. This is to replicate something like Rust's `#[derive(Foo, Bar)]` where `Foo` and `Bar` are meant to be traits rather than values in scope. - Varargs is also possible if the attribute accepts a slice of Quoted values rather than individual Quoted arguments. ## Additional Context ## Documentation\* Check one: - [ ] No documentation needed. - [ ] Documentation included in this PR. - [x] **[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
5 changed files
with
94 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,6 +206,8 @@ | |
"unoptimized", | ||
"urem", | ||
"USERPROFILE", | ||
"vararg", | ||
"varargs", | ||
"vecmap", | ||
"vitkov", | ||
"wasi", | ||
|
7 changes: 7 additions & 0 deletions
7
test_programs/compile_success_empty/attribute_args/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 = "attribute_args" | ||
type = "bin" | ||
authors = [""] | ||
compiler_version = ">=0.31.0" | ||
|
||
[dependencies] |
20 changes: 20 additions & 0 deletions
20
test_programs/compile_success_empty/attribute_args/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,20 @@ | ||
#[attr_with_args(a b, c d)] | ||
#[varargs(one, two)] | ||
#[varargs(one, two, three, four)] | ||
struct Foo {} | ||
|
||
comptime fn attr_with_args(s: StructDefinition, a: Quoted, b: Quoted) { | ||
// Ensure all variables are in scope. | ||
// We can't print them since that breaks the test runner. | ||
let _ = s; | ||
let _ = a; | ||
let _ = b; | ||
} | ||
|
||
comptime fn varargs(s: StructDefinition, t: [Quoted]) { | ||
let _ = s; | ||
for _ in t {} | ||
assert(t.len() < 5); | ||
} | ||
|
||
fn main() {} |