Skip to content

Commit

Permalink
feat: Add unquote function (#5497)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Resolves #5478

## Summary\*

## 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.

---------

Co-authored-by: Michael J Klein <[email protected]>
  • Loading branch information
jfecher and michaeljklein authored Jul 11, 2024
1 parent a33cafc commit 2947aba
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
10 changes: 1 addition & 9 deletions compiler/noirc_frontend/src/parser/parser/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,7 @@ pub(super) fn parenthesized_type(
}

pub(super) fn maybe_comp_time() -> impl NoirParser<bool> {
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<UnresolvedType> {
Expand Down
7 changes: 7 additions & 0 deletions noir_stdlib/src/meta/mod.nr
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 7 additions & 0 deletions test_programs/compile_success_empty/unquote/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "unquote"
type = "bin"
authors = [""]
compiler_version = ">=0.31.0"

[dependencies]
4 changes: 4 additions & 0 deletions test_programs/compile_success_empty/unquote/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
std::meta::unquote!(quote { assert(true); });
assert(std::meta::unquote!(quote { true }));
}
3 changes: 2 additions & 1 deletion tooling/nargo_cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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(
Expand Down

0 comments on commit 2947aba

Please sign in to comment.