Skip to content

Commit 7ea4709

Browse files
AztecBotTomAFrench
andauthored
feat: Sync from noir (#8543)
Automated pull of development from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec. BEGIN_COMMIT_OVERRIDE feat: add `Expr::as_for` and `Expr::as_for_range` (noir-lang/noir#6039) fix: Fix canonicalization bug (noir-lang/noir#6033) fix: Parse a statement as an expression (noir-lang/noir#6040) chore: rename CustomAtrribute to CustomAttribute (noir-lang/noir#6038) fix: error on `&mut x` when `x` is not mutable (noir-lang/noir#6037) feat: add `Expr::as_constructor` (noir-lang/noir#5980) chore: Fix docs (noir-lang/noir#6035) chore: document array methods (noir-lang/noir#6034) END_COMMIT_OVERRIDE --------- Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
1 parent ae26474 commit 7ea4709

91 files changed

Lines changed: 1802 additions & 500 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.noir-sync-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
fc74c55ffed892962413c6fe15af62e1d2e7b785
1+
5bbd9ba9a6d6494fd16813b44036b78c871f6613

noir-projects/aztec-nr/aztec/src/keys/getters/test.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn setup() -> (TestEnvironment, PrivateContext, TestAccount) {
1818

1919
#[test(should_fail_with="Invalid public keys hint for address")]
2020
fn test_get_current_keys_unknown_unregistered() {
21-
let (_, context, account) = setup();
21+
let (_, mut context, account) = setup();
2222

2323
let _ = OracleMock::mock("getPublicKeysAndPartialAddress").returns([0; KEY_ORACLE_RESPONSE_LENGTH]).times(1);
2424
let _ = get_current_public_keys(&mut context, account.address);

noir-projects/noir-contracts/contracts/nft_contract/src/main.nr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ contract NFT {
233233
let from_ovpk_m = get_current_public_keys(&mut context, from).ovpk_m;
234234
let to_keys = get_current_public_keys(&mut context, to);
235235

236-
let new_note = NFTNote::new(token_id, to_keys.npk_m.hash());
236+
let mut new_note = NFTNote::new(token_id, to_keys.npk_m.hash());
237237
nfts.at(to).insert(&mut new_note).emit(encode_and_encrypt_note_with_keys(&mut context, from_ovpk_m, to_keys.ivpk_m, to));
238238
}
239239

noir/noir-repo/aztec_macros/src/transforms/storage.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,11 @@ pub fn generate_storage_implementation(
222222
})
223223
.collect();
224224

225-
let storage_constructor_statement = make_statement(StatementKind::Expression(expression(
226-
ExpressionKind::constructor((chained_path!(storage_struct_name), field_constructors)),
227-
)));
225+
let storage_constructor_statement =
226+
make_statement(StatementKind::Expression(expression(ExpressionKind::constructor((
227+
UnresolvedType::from_path(chained_path!(storage_struct_name)),
228+
field_constructors,
229+
)))));
228230

229231
// This is the type over which the impl is generic.
230232
let generic_context_ident = ident("Context");

noir/noir-repo/aztec_macros/src/utils/parse_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ fn empty_expression(expression: &mut Expression) {
299299
ExpressionKind::Quote(..)
300300
| ExpressionKind::Resolved(_)
301301
| ExpressionKind::Interned(_)
302+
| ExpressionKind::InternedStatement(_)
302303
| ExpressionKind::Error => (),
303304
}
304305
}
@@ -505,7 +506,7 @@ fn empty_method_call_expression(method_call_expression: &mut MethodCallExpressio
505506
}
506507

507508
fn empty_constructor_expression(constructor_expression: &mut ConstructorExpression) {
508-
empty_path(&mut constructor_expression.type_name);
509+
empty_unresolved_type(&mut constructor_expression.typ);
509510
for (name, expression) in constructor_expression.fields.iter_mut() {
510511
empty_ident(name);
511512
empty_expression(expression);

noir/noir-repo/compiler/noirc_frontend/src/ast/expression.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::ast::{
77
};
88
use crate::hir::def_collector::errors::DefCollectorErrorKind;
99
use crate::macros_api::StructId;
10-
use crate::node_interner::{ExprId, InternedExpressionKind, QuotedTypeId};
10+
use crate::node_interner::{ExprId, InternedExpressionKind, InternedStatementKind, QuotedTypeId};
1111
use crate::token::{Attributes, FunctionAttribute, Token, Tokens};
1212
use crate::{Kind, Type};
1313
use acvm::{acir::AcirField, FieldElement};
@@ -48,6 +48,10 @@ pub enum ExpressionKind {
4848
// The actual ExpressionKind can be retrieved with a NodeInterner.
4949
Interned(InternedExpressionKind),
5050

51+
/// Interned statements are allowed to be parsed as expressions in case they resolve
52+
/// to an StatementKind::Expression or StatementKind::Semi.
53+
InternedStatement(InternedStatementKind),
54+
5155
Error,
5256
}
5357

@@ -200,9 +204,11 @@ impl ExpressionKind {
200204
ExpressionKind::Literal(Literal::FmtStr(contents))
201205
}
202206

203-
pub fn constructor((type_name, fields): (Path, Vec<(Ident, Expression)>)) -> ExpressionKind {
207+
pub fn constructor(
208+
(typ, fields): (UnresolvedType, Vec<(Ident, Expression)>),
209+
) -> ExpressionKind {
204210
ExpressionKind::Constructor(Box::new(ConstructorExpression {
205-
type_name,
211+
typ,
206212
fields,
207213
struct_type: None,
208214
}))
@@ -536,7 +542,7 @@ pub struct MethodCallExpression {
536542

537543
#[derive(Debug, PartialEq, Eq, Clone)]
538544
pub struct ConstructorExpression {
539-
pub type_name: Path,
545+
pub typ: UnresolvedType,
540546
pub fields: Vec<(Ident, Expression)>,
541547

542548
/// This may be filled out during macro expansion
@@ -615,6 +621,7 @@ impl Display for ExpressionKind {
615621
write!(f, "quote {{ {} }}", tokens.join(" "))
616622
}
617623
AsTraitPath(path) => write!(f, "{path}"),
624+
InternedStatement(_) => write!(f, "?InternedStatement"),
618625
}
619626
}
620627
}
@@ -717,7 +724,7 @@ impl Display for ConstructorExpression {
717724
let fields =
718725
self.fields.iter().map(|(ident, expr)| format!("{ident}: {expr}")).collect::<Vec<_>>();
719726

720-
write!(f, "({} {{ {} }})", self.type_name, fields.join(", "))
727+
write!(f, "({} {{ {} }})", self.typ, fields.join(", "))
721728
}
722729
}
723730

noir/noir-repo/compiler/noirc_frontend/src/ast/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,19 @@ impl UnresolvedType {
344344
pub(crate) fn is_type_expression(&self) -> bool {
345345
matches!(&self.typ, UnresolvedTypeData::Expression(_))
346346
}
347+
348+
pub fn from_path(mut path: Path) -> Self {
349+
let span = path.span;
350+
let last_segment = path.segments.last_mut().unwrap();
351+
let generics = last_segment.generics.take();
352+
let generic_type_args = if let Some(generics) = generics {
353+
GenericTypeArgs { ordered_args: generics, named_args: Vec::new() }
354+
} else {
355+
GenericTypeArgs::default()
356+
};
357+
let typ = UnresolvedTypeData::Named(path, generic_type_args, true);
358+
UnresolvedType { typ, span }
359+
}
347360
}
348361

349362
impl UnresolvedTypeData {

noir/noir-repo/compiler/noirc_frontend/src/ast/statement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ impl Pattern {
620620
}
621621
Some(Expression {
622622
kind: ExpressionKind::Constructor(Box::new(ConstructorExpression {
623-
type_name: path.clone(),
623+
typ: UnresolvedType::from_path(path.clone()),
624624
fields,
625625
struct_type: None,
626626
})),

noir/noir-repo/compiler/noirc_frontend/src/ast/structure.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ use crate::token::SecondaryAttribute;
66
use iter_extended::vecmap;
77
use noirc_errors::Span;
88

9-
use super::Documented;
9+
use super::{Documented, ItemVisibility};
1010

1111
/// Ast node for a struct
1212
#[derive(Clone, Debug, PartialEq, Eq)]
1313
pub struct NoirStruct {
1414
pub name: Ident,
1515
pub attributes: Vec<SecondaryAttribute>,
16+
pub visibility: ItemVisibility,
1617
pub generics: UnresolvedGenerics,
1718
pub fields: Vec<Documented<StructField>>,
1819
pub span: Span,

noir/noir-repo/compiler/noirc_frontend/src/ast/traits.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct NoirTrait {
2222
pub span: Span,
2323
pub items: Vec<Documented<TraitItem>>,
2424
pub attributes: Vec<SecondaryAttribute>,
25+
pub visibility: ItemVisibility,
2526
}
2627

2728
/// Any declaration inside the body of a trait that a user is required to

0 commit comments

Comments
 (0)