Skip to content

Commit

Permalink
chore: Move templated code for assert_message into the stdlib (#4475)
Browse files Browse the repository at this point in the history
# 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 <15848336+TomAFrench@users.noreply.github.com>
Co-authored-by: Tom French <tom@tomfren.ch>
  • Loading branch information
3 people committed Mar 6, 2024
1 parent 18e1fe2 commit ea9a834
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 106 deletions.
9 changes: 0 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
[workspace]

members = [
# Macros crates for metaprogramming
# Aztec Macro crate for metaprogramming
"aztec_macros",
"noirc_macros",
# Compiler crates
"compiler/noirc_evaluator",
"compiler/noirc_frontend",
Expand Down
1 change: 0 additions & 1 deletion compiler/noirc_driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,3 @@ tracing.workspace = true
thiserror.workspace = true

aztec_macros = { path = "../../aztec_macros" }
noirc_macros = { path = "../../noirc_macros" }
7 changes: 2 additions & 5 deletions compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,9 @@ pub fn check_crate(
disable_macros: bool,
) -> CompilationResult<()> {
let macros: Vec<&dyn MacroProcessor> = if disable_macros {
vec![&noirc_macros::AssertMessageMacro as &dyn MacroProcessor]
vec![]
} else {
vec![
&aztec_macros::AztecMacro as &dyn MacroProcessor,
&noirc_macros::AssertMessageMacro as &dyn MacroProcessor,
]
vec![&aztec_macros::AztecMacro as &dyn MacroProcessor]
};

let mut errors = vec![];
Expand Down
8 changes: 6 additions & 2 deletions compiler/noirc_frontend/src/hir/resolution/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1256,13 +1256,17 @@ impl<'a> Resolver<'a> {
let is_in_stdlib = self.path_resolver.module_id().krate.is_stdlib();
let assert_msg_call_path = if is_in_stdlib {
ExpressionKind::Variable(Path {
segments: vec![Ident::from("resolve_assert_message")],
segments: vec![Ident::from("internal"), Ident::from("resolve_assert_message")],
kind: PathKind::Crate,
span,
})
} else {
ExpressionKind::Variable(Path {
segments: vec![Ident::from("std"), Ident::from("resolve_assert_message")],
segments: vec![
Ident::from("std"),
Ident::from("internal"),
Ident::from("resolve_assert_message"),
],
kind: PathKind::Dep,
span,
})
Expand Down
12 changes: 12 additions & 0 deletions noir_stdlib/src/internal.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This file contains functions which should only be used in calls injected by the Noir compiler.
// These functions should not be called manually in user code.
//
// Changes to this file will not be considered breaking.

#[oracle(assert_message)]
unconstrained fn assert_message_oracle<T>(_input: T) {}
unconstrained pub fn resolve_assert_message<T>(input: T, condition: bool) {
if !condition {
assert_message_oracle(input);
}
}
1 change: 1 addition & 0 deletions noir_stdlib/src/lib.nr
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod default;
mod prelude;
mod uint128;
mod bigint;
mod internal;

// Oracle calls are required to be wrapped in an unconstrained function
// Thus, the only argument to the `println` oracle is expected to always be an ident
Expand Down
14 changes: 0 additions & 14 deletions noirc_macros/Cargo.toml

This file was deleted.

73 changes: 0 additions & 73 deletions noirc_macros/src/lib.rs

This file was deleted.

0 comments on commit ea9a834

Please sign in to comment.