From 283771bebbef780712ca47927ed9ab3dcdb8318b Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Thu, 11 Jul 2024 14:41:22 -0500 Subject: [PATCH 1/3] Add unquote function --- compiler/noirc_frontend/src/parser/parser/types.rs | 10 +--------- noir_stdlib/src/meta/mod.nr | 7 +++++++ test_programs/compile_success_empty/unquote/Nargo.toml | 7 +++++++ .../compile_success_empty/unquote/src/main.nr | 3 +++ 4 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 test_programs/compile_success_empty/unquote/Nargo.toml create mode 100644 test_programs/compile_success_empty/unquote/src/main.nr diff --git a/compiler/noirc_frontend/src/parser/parser/types.rs b/compiler/noirc_frontend/src/parser/parser/types.rs index 32929312d54..6e8064c6423 100644 --- a/compiler/noirc_frontend/src/parser/parser/types.rs +++ b/compiler/noirc_frontend/src/parser/parser/types.rs @@ -54,15 +54,7 @@ pub(super) fn parenthesized_type( } pub(super) fn maybe_comp_time() -> impl NoirParser { - keyword(Keyword::Comptime).or_not().validate(|opt, span, emit| { - if opt.is_some() { - emit(ParserError::with_reason( - ParserErrorReason::ExperimentalFeature("Comptime values"), - span, - )); - } - opt.is_some() - }) + keyword(Keyword::Comptime).or_not().map(|opt| opt.is_some()) } pub(super) fn field_type() -> impl NoirParser { diff --git a/noir_stdlib/src/meta/mod.nr b/noir_stdlib/src/meta/mod.nr index 1825888130b..ad8ee4f8586 100644 --- a/noir_stdlib/src/meta/mod.nr +++ b/noir_stdlib/src/meta/mod.nr @@ -1 +1,8 @@ mod type_def; + +/// Calling unquote as a macro (via `unquote!(arg)`) will unquote +/// its argument. Since this is the effect `!` already does, `unquote` +/// itself does not need to do anything besides return its argument. +pub comptime fn unquote(code: Quoted) -> Quoted { + code +} diff --git a/test_programs/compile_success_empty/unquote/Nargo.toml b/test_programs/compile_success_empty/unquote/Nargo.toml new file mode 100644 index 00000000000..68b2890e37a --- /dev/null +++ b/test_programs/compile_success_empty/unquote/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "unquote" +type = "bin" +authors = [""] +compiler_version = ">=0.31.0" + +[dependencies] \ No newline at end of file diff --git a/test_programs/compile_success_empty/unquote/src/main.nr b/test_programs/compile_success_empty/unquote/src/main.nr new file mode 100644 index 00000000000..857974dc213 --- /dev/null +++ b/test_programs/compile_success_empty/unquote/src/main.nr @@ -0,0 +1,3 @@ +fn main() { + std::meta::unquote!(quote { assert(true); }); +} From 546670f5820698c837e24385ff7628369bfc005e Mon Sep 17 00:00:00 2001 From: jfecher Date: Thu, 11 Jul 2024 15:06:58 -0500 Subject: [PATCH 2/3] Update test_programs/compile_success_empty/unquote/src/main.nr Co-authored-by: Michael J Klein --- test_programs/compile_success_empty/unquote/src/main.nr | 1 + 1 file changed, 1 insertion(+) diff --git a/test_programs/compile_success_empty/unquote/src/main.nr b/test_programs/compile_success_empty/unquote/src/main.nr index 857974dc213..2717286b810 100644 --- a/test_programs/compile_success_empty/unquote/src/main.nr +++ b/test_programs/compile_success_empty/unquote/src/main.nr @@ -1,3 +1,4 @@ fn main() { std::meta::unquote!(quote { assert(true); }); + assert(std::meta::unquote!(quote { true })); } From 40b09ac8904d02bb72b0f3dde4dacfef65dd356c Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Thu, 11 Jul 2024 15:51:47 -0500 Subject: [PATCH 3/3] Exempt unquote from legacy tests --- tooling/nargo_cli/build.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tooling/nargo_cli/build.rs b/tooling/nargo_cli/build.rs index 9dfa0dfe861..2681f2501cd 100644 --- a/tooling/nargo_cli/build.rs +++ b/tooling/nargo_cli/build.rs @@ -61,7 +61,7 @@ const IGNORED_BRILLIG_TESTS: [&str; 11] = [ /// Certain features are only available in the elaborator. /// We skip these tests for non-elaborator code since they are not /// expected to work there. This can be removed once the old code is removed. -const IGNORED_NEW_FEATURE_TESTS: [&str; 9] = [ +const IGNORED_NEW_FEATURE_TESTS: [&str; 10] = [ "macros", "wildcard_type", "type_definition_annotation", @@ -71,6 +71,7 @@ const IGNORED_NEW_FEATURE_TESTS: [&str; 9] = [ "comptime_slice_methods", "unary_operator_overloading", "unquote_multiple_items_from_annotation", + "unquote", ]; fn read_test_cases(