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

chore: remove aztec compile time feature flag #3596

Merged
merged 45 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6f6217f
create a namespaced API for macros
kevaundray Nov 26, 2023
1212b44
remove aztec specific error variants
kevaundray Nov 26, 2023
8373541
remove aztec feature flag from frontend by allowing arbitrary macro p…
kevaundray Nov 26, 2023
f2b128e
fix test
kevaundray Nov 26, 2023
413260c
add aztec_macro crate
kevaundray Nov 26, 2023
8282ffe
remove aztec feature flag and code from noirc_frontend
kevaundray Nov 26, 2023
927a2a3
add aztec feature flag to noirc_driver
kevaundray Nov 26, 2023
b2fb79a
modify yml feature flags
kevaundray Nov 26, 2023
f3fa65f
clippy fix
kevaundray Nov 26, 2023
7afdc45
use slice of trait objects when there are no macro processors
kevaundray Nov 26, 2023
7df00c7
replace opaque type with trait object in function signature
kevaundray Nov 26, 2023
7c9198f
fmt
kevaundray Nov 26, 2023
e6b4b89
temporarily coerce the type system -- a clone here would likely not b…
kevaundray Nov 26, 2023
89b4678
fmt
kevaundray Nov 26, 2023
00136a1
use vec instead of slice and clone the pointers to vtable (references…
kevaundray Nov 26, 2023
cf11ad9
fmt
kevaundray Nov 26, 2023
a925d8d
remove extraneous & in test
kevaundray Nov 26, 2023
546020d
remove aztec feature flag
kevaundray Nov 27, 2023
958e11f
remove aztec builds from CI workflow
kevaundray Nov 27, 2023
0684bf4
Update compiler/noirc_driver/Cargo.toml
TomAFrench Nov 27, 2023
26559c3
remove duplicated code
kevaundray Nov 28, 2023
c7dd9b9
Merge branch 'master' into kw/create-api-for-macros
kevaundray Nov 28, 2023
7d3f0e1
Merge branch 'kw/create-api-for-macros' into kw/remove-aztec-feature-…
kevaundray Nov 28, 2023
4b64a69
Merge remote-tracking branch 'origin/master' into kw/remove-aztec-fea…
kevaundray Nov 28, 2023
d6ebf4f
add aztec macros flag for compiling in typescript
kevaundray Nov 28, 2023
8c7a7c4
cargo fmt --all
kevaundray Nov 29, 2023
8beb276
default to enabling the macro on lsp run
kevaundray Nov 29, 2023
79f9afc
Merge remote-tracking branch 'origin/master' into kw/remove-aztec-fea…
kevaundray Nov 30, 2023
2c4e84b
fix test
kevaundray Nov 30, 2023
f5060a2
fmt
kevaundray Nov 30, 2023
a849a11
Merge branch 'master' into kw/remove-aztec-feature-flag
kevaundray Nov 30, 2023
5746d40
enable aztec macro via an environment variable
kevaundray Nov 30, 2023
1aa2206
set the aztec macro based on environment variable for lsp
kevaundray Nov 30, 2023
58fe17b
add missing args
kevaundray Dec 1, 2023
14d846b
lint fix
kevaundray Dec 1, 2023
43a8561
Merge branch 'master' into kw/remove-aztec-feature-flag
kevaundray Dec 5, 2023
d436b0d
Merge branch 'master' into kw/remove-aztec-feature-flag
TomAFrench Dec 11, 2023
f7a8f9f
chore: fix missing arg
TomAFrench Dec 12, 2023
8f99af1
Empty commit to signal me making changes
kevaundray Dec 12, 2023
7f4a1f9
remove threading of aztec macros flag
kevaundray Dec 12, 2023
cb69179
clippy
kevaundray Dec 12, 2023
97ed2fb
revert changes
kevaundray Dec 12, 2023
9d0e9fd
compile no longer needs extra parameter
kevaundray Dec 12, 2023
6c266dc
add disable_macros flag
kevaundray Dec 12, 2023
3bb1c2e
add code to handle disabling macros
kevaundray Dec 12, 2023
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
45 changes: 0 additions & 45 deletions .github/workflows/build-aztec-feature-flag.yml

This file was deleted.

5 changes: 0 additions & 5 deletions .github/workflows/publish-es-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ jobs:
nix-cache-name: "noir"
cachix-auth-token: ${{ secrets.CACHIXAUTHTOKEN }}

- name: Enable aztec features
if: ${{ inputs.npm-tag == 'aztec' }}
run: |
echo $'\n'"default = [\"aztec\"]"$'\n' >> compiler/noirc_frontend/Cargo.toml

- name: Build wasm package
run: |
nix build -L .#noir_wasm
Expand Down
9 changes: 9 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]

members = [
"aztec_macros",
"compiler/noirc_evaluator",
"compiler/noirc_frontend",
"compiler/noirc_errors",
Expand Down
14 changes: 14 additions & 0 deletions aztec_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "aztec_macros"
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
repository.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
noirc_frontend.workspace = true
iter-extended.workspace = true
Original file line number Diff line number Diff line change
@@ -1,28 +1,59 @@
use acvm::FieldElement;
use iter_extended::vecmap;
use noirc_errors::Span;

use crate::graph::CrateId;
use crate::hir::def_collector::errors::DefCollectorErrorKind;
use crate::hir_def::expr::{HirExpression, HirLiteral};
use crate::hir_def::stmt::HirStatement;
use crate::node_interner::{NodeInterner, StructId};
use crate::parser::SortedModule;
use crate::token::SecondaryAttribute;
use crate::{
hir::Context, BlockExpression, CallExpression, CastExpression, Distinctness, Expression,
ExpressionKind, FunctionReturnType, Ident, IndexExpression, LetStatement, Literal,
MemberAccessExpression, MethodCallExpression, NoirFunction, Path, PathKind, Pattern, Statement,
UnresolvedType, UnresolvedTypeData, Visibility,
};
use crate::{
ForLoopStatement, ForRange, FunctionDefinition, FunctionVisibility, ImportStatement,
NoirStruct, Param, PrefixExpression, Signedness, StatementKind, StructType, Type, TypeImpl,
UnaryOp,

use noirc_frontend::macros_api::FieldElement;
use noirc_frontend::macros_api::{
BlockExpression, CallExpression, CastExpression, Distinctness, Expression, ExpressionKind,
ForLoopStatement, ForRange, FunctionDefinition, FunctionReturnType, FunctionVisibility,
HirContext, HirExpression, HirLiteral, HirStatement, Ident, ImportStatement, IndexExpression,
LetStatement, Literal, MemberAccessExpression, MethodCallExpression, NoirFunction, NoirStruct,
Param, Path, PathKind, Pattern, PrefixExpression, SecondaryAttribute, Signedness, Span,
Statement, StatementKind, StructType, Type, TypeImpl, UnaryOp, UnresolvedType,
UnresolvedTypeData, Visibility,
};
use fm::FileId;
use noirc_frontend::macros_api::{CrateId, FileId};
use noirc_frontend::macros_api::{MacroError, MacroProcessor};
use noirc_frontend::macros_api::{ModuleDefId, NodeInterner, SortedModule, StructId};

pub struct AztecMacro;

impl MacroProcessor for AztecMacro {
fn process_untyped_ast(
&self,
ast: SortedModule,
crate_id: &CrateId,
context: &HirContext,
) -> Result<SortedModule, (MacroError, FileId)> {
transform(ast, crate_id, context)
}

fn process_typed_ast(&self, crate_id: &CrateId, context: &mut HirContext) {
transform_hir(crate_id, context)
}
}

use super::def_map::ModuleDefId;
#[derive(Debug, Clone)]
pub enum AztecMacroError {
// TODO(benesjan): https://github.com/AztecProtocol/aztec-packages/issues/2905

Check warning on line 36 in aztec_macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (benesjan)
AztecNotFound,
AztecComputeNoteHashAndNullifierNotFound { span: Span },
}

impl From<AztecMacroError> for MacroError {
fn from(err: AztecMacroError) -> Self {
match err {
AztecMacroError::AztecNotFound {} => MacroError {
primary_message: "Aztec dependency not found. Please add aztec as a dependency in your Cargo.toml".to_owned(),
secondary_message: None,
span: None,
},
AztecMacroError::AztecComputeNoteHashAndNullifierNotFound { span } => MacroError {
primary_message: "compute_note_hash_and_nullifier function not found. Define it in your contract.".to_owned(),
secondary_message: None,
span: Some(span),
},
}
}
}

//
// Helper macros for creating noir ast nodes
Expand Down Expand Up @@ -162,11 +193,11 @@

/// Traverses every function in the ast, calling `transform_function` which
/// determines if further processing is required
pub(crate) fn transform(
fn transform(
mut ast: SortedModule,
crate_id: &CrateId,
context: &Context,
) -> Result<SortedModule, (DefCollectorErrorKind, FileId)> {
context: &HirContext,
) -> Result<SortedModule, (MacroError, FileId)> {
// Usage -> mut ast -> aztec_library::transform(&mut ast)

// Covers all functions in the ast
Expand All @@ -184,7 +215,7 @@
//

/// Completes the Hir with data gathered from type resolution
pub(crate) fn transform_hir(crate_id: &CrateId, context: &mut Context) {
fn transform_hir(crate_id: &CrateId, context: &mut HirContext) {
transform_events(crate_id, context);
}

Expand All @@ -206,14 +237,14 @@
/// Creates an error alerting the user that they have not downloaded the Aztec-noir library
fn check_for_aztec_dependency(
crate_id: &CrateId,
context: &Context,
) -> Result<(), (DefCollectorErrorKind, FileId)> {
context: &HirContext,
) -> Result<(), (MacroError, FileId)> {
let crate_graph = &context.crate_graph[crate_id];
let has_aztec_dependency = crate_graph.dependencies.iter().any(|dep| dep.as_name() == "aztec");
if has_aztec_dependency {
Ok(())
} else {
Err((DefCollectorErrorKind::AztecNotFound {}, crate_graph.root_file_id))
Err((MacroError { primary_message: "Aztec dependency not found. Please add aztec as a dependency in your Cargo.toml".to_owned(), secondary_message: None, span: None }, crate_graph.root_file_id))
}
}

Expand All @@ -234,10 +265,7 @@
// Array(Option<UnresolvedTypeExpression>, Box<UnresolvedType>) contains only fields
&& match &func.def.parameters[3].typ.typ {
UnresolvedTypeData::Array(_, inner_type) => {
match inner_type.typ {
UnresolvedTypeData::FieldElement => true,
_ => false,
}
matches!(inner_type.typ, UnresolvedTypeData::FieldElement)
},
_ => false,
}
Expand All @@ -247,10 +275,7 @@
FunctionReturnType::Ty(unresolved_type) => {
match &unresolved_type.typ {
UnresolvedTypeData::Array(_, inner_type) => {
match inner_type.typ {
UnresolvedTypeData::FieldElement => true,
_ => false,
}
matches!(inner_type.typ, UnresolvedTypeData::FieldElement)
},
_ => false,
}
Expand All @@ -274,18 +299,20 @@
fn transform_module(
module: &mut SortedModule,
crate_id: &CrateId,
context: &Context,
) -> Result<bool, (DefCollectorErrorKind, FileId)> {
context: &HirContext,
) -> Result<bool, (MacroError, FileId)> {
let mut has_transformed_module = false;

// Check for a user defined storage struct
let storage_defined = check_for_storage_definition(&module);
let storage_defined = check_for_storage_definition(module);

if storage_defined && !check_for_compute_note_hash_and_nullifier_definition(&module) {
if storage_defined && !check_for_compute_note_hash_and_nullifier_definition(module) {
let crate_graph = &context.crate_graph[crate_id];
return Err((
DefCollectorErrorKind::AztecComputeNoteHashAndNullifierNotFound {
span: Span::default(), // Add a default span so we know which contract file the error originates from
MacroError {
span: Some(Span::default()), // Add a default span so we know which contract file the error originates from
primary_message: "compute_note_hash_and_nullifier function not found. Define it in your contract.".to_owned(),
secondary_message: None,
},
crate_graph.root_file_id,
));
Expand Down Expand Up @@ -374,7 +401,7 @@
func.def.body.0.insert(0, abstract_storage("Unconstrained", true));
}

fn collect_crate_structs(crate_id: &CrateId, context: &Context) -> Vec<StructId> {
fn collect_crate_structs(crate_id: &CrateId, context: &HirContext) -> Vec<StructId> {
context
.def_map(crate_id)
.expect("ICE: Missing crate in def_map")
Expand Down Expand Up @@ -444,7 +471,7 @@
}
}

fn transform_events(crate_id: &CrateId, context: &mut Context) {
fn transform_events(crate_id: &CrateId, context: &mut HirContext) {
for struct_id in collect_crate_structs(crate_id, context) {
let attributes = context.def_interner.struct_attributes(&struct_id);
if attributes.iter().any(|attr| matches!(attr, SecondaryAttribute::Event)) {
Expand Down Expand Up @@ -514,7 +541,7 @@
/// fn foo() {
/// // ...
/// }
pub(crate) fn create_inputs(ty: &str) -> Param {
fn create_inputs(ty: &str) -> Param {
let context_ident = ident("inputs");
let context_pattern = Pattern::Identifier(context_ident);
let type_path = chained_path!("aztec", "abi", ty);
Expand Down Expand Up @@ -574,7 +601,7 @@
// `hasher.add_multiple({ident}.serialize())`
UnresolvedTypeData::Named(..) => add_struct_to_hasher(identifier),
UnresolvedTypeData::Array(_, arr_type) => {
add_array_to_hasher(identifier, &arr_type)
add_array_to_hasher(identifier, arr_type)
}
// `hasher.add({ident})`
UnresolvedTypeData::FieldElement => add_field_to_hasher(identifier),
Expand Down Expand Up @@ -819,7 +846,7 @@
/// fn foo() {
/// // ...
/// }
pub(crate) fn create_return_type(ty: &str) -> FunctionReturnType {
fn create_return_type(ty: &str) -> FunctionReturnType {
let return_path = chained_path!("aztec", "abi", ty);

let ty = make_type(UnresolvedTypeData::Named(return_path, vec![]));
Expand All @@ -844,7 +871,7 @@
/// fn foo() {
/// // ...
/// }
pub(crate) fn create_context_finish() -> Statement {
fn create_context_finish() -> Statement {
let method_call = method_call(
variable("context"), // variable
"finish", // method name
Expand Down Expand Up @@ -875,7 +902,7 @@
fn create_loop_over(var: Expression, loop_body: Vec<Statement>) -> Statement {
// If this is an array of primitive types (integers / fields) we can add them each to the hasher
// casted to a field
let span = var.span.clone();
let span = var.span;

// `array.len()`
let end_range_expression = method_call(
Expand Down Expand Up @@ -914,7 +941,7 @@
UnresolvedTypeData::Named(..) => {
let hasher_method_name = "add_multiple".to_owned();
let call = method_call(
// All serialise on each element

Check warning on line 944 in aztec_macros/src/lib.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (serialise)
arr_index, // variable
"serialize", // method name
vec![], // args
Expand Down
2 changes: 2 additions & 0 deletions compiler/noirc_driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ iter-extended.workspace = true
fm.workspace = true
serde.workspace = true
fxhash.workspace = true

aztec_macros ={path = "../../aztec_macros"}
TomAFrench marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading