Skip to content

Commit ea9a834

Browse files
chore: Move templated code for assert_message into the stdlib (#4475)
# Description ## Problem\* We currently have a noirc_macros crate which checks for the stdlib and inserts two functions into the stdlib. The motivation being that we did not want users to be able to see these functions. Introducing a new crate for this reason, does not seem to be worth it since its ~7 lines of noir code. ## Solution\* This PR removes the noirc_macros crate and copies the noir code that was being pasted into the stdlib, directly into the stdlib ## Additional Context ## Documentation\* Check one: - [ ] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** Documentation to be submitted in a separate PR. # PR Checklist\* - [ ] I have tested the changes locally. - [ ] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --------- Co-authored-by: Tom French <[email protected]> Co-authored-by: Tom French <[email protected]>
1 parent 18e1fe2 commit ea9a834

File tree

9 files changed

+22
-106
lines changed

9 files changed

+22
-106
lines changed

Cargo.lock

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
[workspace]
22

33
members = [
4-
# Macros crates for metaprogramming
4+
# Aztec Macro crate for metaprogramming
55
"aztec_macros",
6-
"noirc_macros",
76
# Compiler crates
87
"compiler/noirc_evaluator",
98
"compiler/noirc_frontend",

compiler/noirc_driver/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,3 @@ tracing.workspace = true
2626
thiserror.workspace = true
2727

2828
aztec_macros = { path = "../../aztec_macros" }
29-
noirc_macros = { path = "../../noirc_macros" }

compiler/noirc_driver/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,9 @@ pub fn check_crate(
238238
disable_macros: bool,
239239
) -> CompilationResult<()> {
240240
let macros: Vec<&dyn MacroProcessor> = if disable_macros {
241-
vec![&noirc_macros::AssertMessageMacro as &dyn MacroProcessor]
241+
vec![]
242242
} else {
243-
vec![
244-
&aztec_macros::AztecMacro as &dyn MacroProcessor,
245-
&noirc_macros::AssertMessageMacro as &dyn MacroProcessor,
246-
]
243+
vec![&aztec_macros::AztecMacro as &dyn MacroProcessor]
247244
};
248245

249246
let mut errors = vec![];

compiler/noirc_frontend/src/hir/resolution/resolver.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,13 +1256,17 @@ impl<'a> Resolver<'a> {
12561256
let is_in_stdlib = self.path_resolver.module_id().krate.is_stdlib();
12571257
let assert_msg_call_path = if is_in_stdlib {
12581258
ExpressionKind::Variable(Path {
1259-
segments: vec![Ident::from("resolve_assert_message")],
1259+
segments: vec![Ident::from("internal"), Ident::from("resolve_assert_message")],
12601260
kind: PathKind::Crate,
12611261
span,
12621262
})
12631263
} else {
12641264
ExpressionKind::Variable(Path {
1265-
segments: vec![Ident::from("std"), Ident::from("resolve_assert_message")],
1265+
segments: vec![
1266+
Ident::from("std"),
1267+
Ident::from("internal"),
1268+
Ident::from("resolve_assert_message"),
1269+
],
12661270
kind: PathKind::Dep,
12671271
span,
12681272
})

noir_stdlib/src/internal.nr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// This file contains functions which should only be used in calls injected by the Noir compiler.
2+
// These functions should not be called manually in user code.
3+
//
4+
// Changes to this file will not be considered breaking.
5+
6+
#[oracle(assert_message)]
7+
unconstrained fn assert_message_oracle<T>(_input: T) {}
8+
unconstrained pub fn resolve_assert_message<T>(input: T, condition: bool) {
9+
if !condition {
10+
assert_message_oracle(input);
11+
}
12+
}

noir_stdlib/src/lib.nr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ mod default;
2626
mod prelude;
2727
mod uint128;
2828
mod bigint;
29+
mod internal;
2930

3031
// Oracle calls are required to be wrapped in an unconstrained function
3132
// Thus, the only argument to the `println` oracle is expected to always be an ident

noirc_macros/Cargo.toml

Lines changed: 0 additions & 14 deletions
This file was deleted.

noirc_macros/src/lib.rs

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)