Skip to content

Commit

Permalink
feat: new formatter (noir-lang/noir#6300)
Browse files Browse the repository at this point in the history
feat: Sync from aztec-packages (noir-lang/noir#6301)
fix: Allow array map on empty arrays (noir-lang/noir#6305)
fix: Display function name and body when inlining recursion limit hit (noir-lang/noir#6291)
feat(interpreter): Comptime derive generators (noir-lang/noir#6303)
fix: enforce correctness of decompositions performed at compile time (noir-lang/noir#6278)
feat: Warn about private types leaking in public functions and struct fields (noir-lang/noir#6296)
chore(docs): refactoring guides and some other nits (noir-lang/noir#6175)
fix: Do not warn on unused self in traits (noir-lang/noir#6298)
fix: Reject invalid expression with in CLI parser (noir-lang/noir#6287)
  • Loading branch information
AztecBot committed Oct 22, 2024
2 parents 697b72c + 1fe1516 commit e0ead20
Show file tree
Hide file tree
Showing 316 changed files with 14,621 additions and 4,713 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
70dcf4a25dcad10daeb427f0887d3a0bf10c9916
62404d7ff349ddf7551f2efd865adafc5213a742
8 changes: 0 additions & 8 deletions noir/noir-repo/Cargo.lock

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

15 changes: 14 additions & 1 deletion noir/noir-repo/compiler/noirc_frontend/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ pub enum GenericTypeArg {
Named(Ident, UnresolvedType),
}

#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub enum GenericTypeArgKind {
Ordered,
Named,
}

#[derive(Debug, Default, PartialEq, Eq, Clone, Hash)]
pub struct GenericTypeArgs {
/// Each ordered argument, e.g. `<A, B, C>`
Expand All @@ -181,6 +187,9 @@ pub struct GenericTypeArgs {
/// All named arguments, e.g. `<A = B, C = D, E = F>`.
/// Used for associated types.
pub named_args: Vec<(Ident, UnresolvedType)>,

/// The kind of each argument, in order (in case traversing the generics in order is needed)
pub kinds: Vec<GenericTypeArgKind>,
}

impl GenericTypeArgs {
Expand Down Expand Up @@ -351,7 +360,11 @@ impl UnresolvedType {
let last_segment = path.segments.last_mut().unwrap();
let generics = last_segment.generics.take();
let generic_type_args = if let Some(generics) = generics {
GenericTypeArgs { ordered_args: generics, named_args: Vec::new() }
let mut kinds = Vec::with_capacity(generics.len());
for _ in 0..generics.len() {
kinds.push(GenericTypeArgKind::Ordered);
}
GenericTypeArgs { ordered_args: generics, named_args: Vec::new(), kinds }
} else {
GenericTypeArgs::default()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ fn remove_interned_in_generic_type_args(
named_args: vecmap(args.named_args, |(name, typ)| {
(name, remove_interned_in_unresolved_type(interner, typ))
}),
kinds: args.kinds,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ impl Type {
Type::Struct(def, generics) => {
let struct_def = def.borrow();
let ordered_args = vecmap(generics, |generic| generic.to_display_ast());
let generics = GenericTypeArgs { ordered_args, named_args: Vec::new() };
let generics =
GenericTypeArgs { ordered_args, named_args: Vec::new(), kinds: Vec::new() };
let name = Path::from_ident(struct_def.name.clone());
UnresolvedTypeData::Named(name, generics, false)
}
Expand All @@ -312,7 +313,8 @@ impl Type {
// alias' definition was changed
let type_def = type_def.borrow();
let ordered_args = vecmap(generics, |generic| generic.to_display_ast());
let generics = GenericTypeArgs { ordered_args, named_args: Vec::new() };
let generics =
GenericTypeArgs { ordered_args, named_args: Vec::new(), kinds: Vec::new() };
let name = Path::from_ident(type_def.name.clone());
UnresolvedTypeData::Named(name, generics, false)
}
Expand All @@ -330,7 +332,7 @@ impl Type {
let named_args = vecmap(&generics.named, |named_type| {
(named_type.name.clone(), named_type.typ.to_display_ast())
});
let generics = GenericTypeArgs { ordered_args, named_args };
let generics = GenericTypeArgs { ordered_args, named_args, kinds: Vec::new() };
let name = Path::from_single(name.as_ref().clone(), Span::default());
UnresolvedTypeData::TraitAsType(name, generics)
}
Expand Down
6 changes: 5 additions & 1 deletion noir/noir-repo/compiler/noirc_frontend/src/lexer/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,11 @@ impl<'a> Lexer<'a> {
return self.lookup_word_token(word, start, end);
}

let delimiter = self.next_token()?;
let mut delimiter = self.next_token()?;
while let Token::Whitespace(_) = delimiter.token() {
delimiter = self.next_token()?;
}

let (start_delim, end_delim) = match delimiter.token() {
Token::LeftBrace => (Token::LeftBrace, Token::RightBrace),
Token::LeftBracket => (Token::LeftBracket, Token::RightBracket),
Expand Down
34 changes: 19 additions & 15 deletions noir/noir-repo/compiler/noirc_frontend/src/lexer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ impl fmt::Display for Token {
}
Token::Keyword(k) => write!(f, "{k}"),
Token::Attribute(ref a) => write!(f, "{a}"),
Token::InnerAttribute(ref a) => write!(f, "#![{a}]"),
Token::InnerAttribute(ref a) => write!(f, "#![{}]", a.contents()),
Token::LineComment(ref s, style) => match style {
Some(DocStyle::Inner) => write!(f, "//!{s}"),
Some(DocStyle::Outer) => write!(f, "///{s}"),
Expand Down Expand Up @@ -1010,28 +1010,32 @@ impl SecondaryAttribute {
pub(crate) fn is_abi(&self) -> bool {
matches!(self, SecondaryAttribute::Abi(_))
}
}

impl fmt::Display for SecondaryAttribute {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
pub(crate) fn contents(&self) -> String {
match self {
SecondaryAttribute::Deprecated(None) => write!(f, "#[deprecated]"),
SecondaryAttribute::Deprecated(None) => "deprecated".to_string(),
SecondaryAttribute::Deprecated(Some(ref note)) => {
write!(f, r#"#[deprecated({note:?})]"#)
format!("deprecated({note:?})")
}
SecondaryAttribute::Tag(ref attribute) => write!(f, "#['{}]", attribute.contents),
SecondaryAttribute::Meta(ref attribute) => write!(f, "#[{}]", attribute.contents),
SecondaryAttribute::ContractLibraryMethod => write!(f, "#[contract_library_method]"),
SecondaryAttribute::Export => write!(f, "#[export]"),
SecondaryAttribute::Field(ref k) => write!(f, "#[field({k})]"),
SecondaryAttribute::Abi(ref k) => write!(f, "#[abi({k})]"),
SecondaryAttribute::Varargs => write!(f, "#[varargs]"),
SecondaryAttribute::UseCallersScope => write!(f, "#[use_callers_scope]"),
SecondaryAttribute::Allow(ref k) => write!(f, "#[allow(#{k})]"),
SecondaryAttribute::Tag(ref attribute) => format!("'{}", attribute.contents),
SecondaryAttribute::Meta(ref attribute) => attribute.contents.to_string(),
SecondaryAttribute::ContractLibraryMethod => "contract_library_method".to_string(),
SecondaryAttribute::Export => "export".to_string(),
SecondaryAttribute::Field(ref k) => format!("field({k})"),
SecondaryAttribute::Abi(ref k) => format!("abi({k})"),
SecondaryAttribute::Varargs => "varargs".to_string(),
SecondaryAttribute::UseCallersScope => "use_callers_scope".to_string(),
SecondaryAttribute::Allow(ref k) => format!("allow({k})"),
}
}
}

impl fmt::Display for SecondaryAttribute {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "#[{}]", self.contents())
}
}

#[derive(PartialEq, Eq, Hash, Debug, Clone, PartialOrd, Ord)]
pub struct CustomAttribute {
pub contents: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,11 @@ impl<'a> Parser<'a> {
match generic {
GenericTypeArg::Ordered(typ) => {
generic_type_args.ordered_args.push(typ);
generic_type_args.kinds.push(crate::ast::GenericTypeArgKind::Ordered);
}
GenericTypeArg::Named(name, typ) => {
generic_type_args.named_args.push((name, typ));
generic_type_args.kinds.push(crate::ast::GenericTypeArgKind::Named);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions noir/noir-repo/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
"plonkc",
"PLONKish",
"pprof",
"precomputes",
"preimage",
"preprocess",
"prettytable",
Expand All @@ -178,6 +179,7 @@
"reqwest",
"rfind",
"rustc",
"rustfmt",
"rustup",
"sboxed",
"schnorr",
Expand Down Expand Up @@ -229,6 +231,8 @@
"wasi",
"wasmer",
"Weierstraß",
"whitespace",
"whitespaces",
"zkhash",
"zshell"
],
Expand Down
18 changes: 12 additions & 6 deletions noir/noir-repo/noir_stdlib/src/array/check_shuffle.nr
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::cmp::Eq;

unconstrained fn __get_shuffle_indices<T, let N: u32>(lhs: [T; N], rhs: [T; N]) -> [Field; N] where T: Eq {
let mut shuffle_indices: [Field;N ] = [0; N];
unconstrained fn __get_shuffle_indices<T, let N: u32>(lhs: [T; N], rhs: [T; N]) -> [Field; N]
where
T: Eq,
{
let mut shuffle_indices: [Field; N] = [0; N];

let mut shuffle_mask: [bool; N] = [false; N];
for i in 0..N {
Expand Down Expand Up @@ -35,7 +38,10 @@ unconstrained fn __get_index<let N: u32>(indices: [Field; N], idx: Field) -> Fie
result
}

pub(crate) fn check_shuffle<T, let N: u32>(lhs: [T; N], rhs: [T; N]) where T: Eq {
pub(crate) fn check_shuffle<T, let N: u32>(lhs: [T; N], rhs: [T; N])
where
T: Eq,
{
unsafe {
let shuffle_indices = __get_shuffle_indices(lhs, rhs);

Expand All @@ -59,7 +65,7 @@ mod test {
struct CompoundStruct {
a: bool,
b: Field,
c: u64
c: u64,
}
impl Eq for CompoundStruct {
fn eq(self, other: Self) -> bool {
Expand Down Expand Up @@ -102,14 +108,14 @@ mod test {
CompoundStruct { a: false, b: -100, c: 54321 },
CompoundStruct { a: true, b: 5, c: 0xffffffffffffffff },
CompoundStruct { a: true, b: 9814, c: 0xeeffee0011001133 },
CompoundStruct { a: false, b: 0x155, c: 0 }
CompoundStruct { a: false, b: 0x155, c: 0 },
];
let rhs: [CompoundStruct; 5] = [
CompoundStruct { a: false, b: 0x155, c: 0 },
CompoundStruct { a: false, b: 0, c: 12345 },
CompoundStruct { a: false, b: -100, c: 54321 },
CompoundStruct { a: true, b: 9814, c: 0xeeffee0011001133 },
CompoundStruct { a: true, b: 5, c: 0xffffffffffffffff }
CompoundStruct { a: true, b: 5, c: 0xffffffffffffffff },
];
check_shuffle(lhs, rhs);
}
Expand Down
Loading

0 comments on commit e0ead20

Please sign in to comment.