Skip to content
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

feat: Add unquote function #5497

Merged
merged 4 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading