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

feat: new formatter #6300

Merged
merged 222 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
222 commits
Select commit Hold shift + click to select a range
770a1ad
The beginnings of a new formatter
asterite Oct 12, 2024
21fdfbe
Function modifiers
asterite Oct 14, 2024
aba5220
Format function generics
asterite Oct 14, 2024
f3a377a
Format function return type
asterite Oct 14, 2024
a1d856c
Got modules right
asterite Oct 14, 2024
e5dc373
Preserve newlines (at most 2)
asterite Oct 14, 2024
f6cbe26
Small rename/refactor
asterite Oct 14, 2024
6ad8636
Param and return visibility
asterite Oct 14, 2024
4680271
Format type aliases
asterite Oct 14, 2024
52c29d4
Format globals
asterite Oct 14, 2024
c159683
A few types and path
asterite Oct 14, 2024
7042f29
Format where clause
asterite Oct 14, 2024
7b7037c
Handle empty where clause
asterite Oct 14, 2024
51f2313
Format array type
asterite Oct 14, 2024
aaefaff
Format mutable reference type
asterite Oct 14, 2024
b01487c
Format generic type args
asterite Oct 14, 2024
b1d536d
Format parenthesized type
asterite Oct 14, 2024
937a188
Format function types
asterite Oct 14, 2024
782067e
Format tuple types
asterite Oct 14, 2024
ea9deba
Some fixes to functions
asterite Oct 14, 2024
d234d9c
More functions
asterite Oct 14, 2024
fc6c738
More fixes
asterite Oct 14, 2024
8e66bd5
Improved fn formatting
asterite Oct 14, 2024
c04b093
Start formatting statements
asterite Oct 14, 2024
1d74184
Handle comments a bit better
asterite Oct 14, 2024
05cea5d
Some literals
asterite Oct 14, 2024
da7977e
Some arrays
asterite Oct 14, 2024
92437ac
Format arrays
asterite Oct 14, 2024
effa043
Correct formatting of comments inside chunks
asterite Oct 15, 2024
09a5080
Better way to format function body
asterite Oct 15, 2024
ddab02c
More comments fixes
asterite Oct 15, 2024
49081c8
Remove dbg
asterite Oct 15, 2024
2c59e9e
No need to have ForceLine
asterite Oct 15, 2024
31d9df0
Write two lines if two or more exist in the source code
asterite Oct 15, 2024
ab4be16
Use new array formatting
asterite Oct 15, 2024
6fab2b1
Contract
asterite Oct 15, 2024
379d5d3
Format cast
asterite Oct 15, 2024
9218a3d
Rename Chunk::Chunks to Chunk::Group
asterite Oct 15, 2024
77b072e
Vars, and don't use two lines at beginning or end of group
asterite Oct 15, 2024
64f9447
Add a comment
asterite Oct 15, 2024
b91dd09
Include newlinw when formatting empty file
asterite Oct 15, 2024
47ccea4
Trait as type
asterite Oct 15, 2024
66546ae
Format hex integers
asterite Oct 15, 2024
ab6aa5d
Don't add extra space before initial comment
asterite Oct 15, 2024
92f2d9c
Format patterns
asterite Oct 15, 2024
806b664
Format impl
asterite Oct 15, 2024
242174a
self parameter
asterite Oct 15, 2024
a33dff2
More impl
asterite Oct 15, 2024
3336741
More comments
asterite Oct 15, 2024
687eb70
Small enhancement formatting impls
asterite Oct 15, 2024
2b74f71
Format traits
asterite Oct 15, 2024
3fedd3f
Format slice type
asterite Oct 15, 2024
a1eac74
Format string type
asterite Oct 15, 2024
e629f74
Format fmtstr type
asterite Oct 15, 2024
0e715a6
Format quoted type
asterite Oct 15, 2024
a5e880a
Format AsTraitPath
asterite Oct 15, 2024
00780d4
A few simple statements
asterite Oct 15, 2024
b20b5e6
Format let statement
asterite Oct 15, 2024
b3fc75a
Format assign
asterite Oct 15, 2024
79f852d
Format op assign
asterite Oct 15, 2024
f7ea1ca
Format LValues
asterite Oct 15, 2024
549888a
Format tuple expression
asterite Oct 15, 2024
c853eff
Format as trait path expr
asterite Oct 15, 2024
21ce453
Index and prefix
asterite Oct 15, 2024
cd9fe5c
Better formatting of index expression
asterite Oct 15, 2024
3fa421e
Focus on getting everything done, let's perfect it at the end
asterite Oct 16, 2024
91083d7
Format type expressions
asterite Oct 16, 2024
6424b90
Format parenthesized lvalues
asterite Oct 16, 2024
99048f2
Format comptime statement
asterite Oct 16, 2024
49d5a1c
Refactor
asterite Oct 16, 2024
b456bb2
Format blocks in statements
asterite Oct 16, 2024
50e1e37
Format comptime block
asterite Oct 16, 2024
7e1799b
Blocks
asterite Oct 16, 2024
45772b7
Add a test for something that's not ideal
asterite Oct 16, 2024
fe53160
Format for loop
asterite Oct 16, 2024
1283298
Format assert and assert_eq
asterite Oct 16, 2024
e810fb4
Format call
asterite Oct 16, 2024
47f4d5d
Format method call
asterite Oct 16, 2024
493f224
Format member access
asterite Oct 16, 2024
64b1457
Format path turbofish
asterite Oct 16, 2024
04b1d16
Some fixes
asterite Oct 16, 2024
0353dcc
Refactor
asterite Oct 16, 2024
cab9d68
Format parenthesized expression
asterite Oct 16, 2024
444ba8b
Format unsafe expression
asterite Oct 16, 2024
0400e88
Format unsafe statement
asterite Oct 16, 2024
4e279c4
Add something for later
asterite Oct 16, 2024
45390c8
Another case not to forget
asterite Oct 16, 2024
400c78c
Format constructor
asterite Oct 16, 2024
c1dc482
Format negative integers
asterite Oct 16, 2024
b6075c5
Mutable reference fix
asterite Oct 16, 2024
b70996e
Format comptime statement and expression
asterite Oct 16, 2024
6133a26
Format type path
asterite Oct 16, 2024
e7d82a6
Format if expression
asterite Oct 16, 2024
2e44128
Format if
asterite Oct 16, 2024
041868e
Allow whitespace between `quote` and `{`
asterite Oct 16, 2024
6573c17
Format quote
asterite Oct 16, 2024
7a59c9a
Format lambda
asterite Oct 16, 2024
0946752
Format trait impls
asterite Oct 16, 2024
7945291
Format imports
asterite Oct 16, 2024
9c2ac62
Fix empty blocks when they just have newlines
asterite Oct 16, 2024
fe61d89
Apply new format to turbofish_call
asterite Oct 16, 2024
8cf054f
Fix method call with turbofish
asterite Oct 16, 2024
34a021a
Write line afte use
asterite Oct 16, 2024
b24e23c
Refactor: extract `format_let_or_global`
asterite Oct 16, 2024
fd343d6
Simplify use tree list with just one item
asterite Oct 16, 2024
44d4ce4
Format constructor field without value
asterite Oct 16, 2024
8e98598
Don't indent+ let/global after `=`
asterite Oct 16, 2024
f1f2fac
Transform TextIfMultiline to Text
asterite Oct 16, 2024
34b243c
Simplify
asterite Oct 16, 2024
2eec35c
Correct format for vec example (remove trailing spaces)
asterite Oct 16, 2024
6508f8b
Correct format for module sample
asterite Oct 16, 2024
c412f7e
Fix issue with comment
asterite Oct 16, 2024
ef585d4
New format for impl
asterite Oct 16, 2024
fa11b43
Honor `config.tab_spaces`
asterite Oct 17, 2024
fe75b4e
Remove some TODOs
asterite Oct 17, 2024
3f28068
Honor single_line_if_else_max_width
asterite Oct 17, 2024
7cab276
Handle comments after if condition and else keyword
asterite Oct 17, 2024
99f98b0
Honor fn_call_width
asterite Oct 17, 2024
cd88246
Fix formatting of struct patterns
asterite Oct 17, 2024
4f3aa93
Don't break lambda parameters
asterite Oct 17, 2024
f9baa42
Preserve multiple lines between fors
asterite Oct 17, 2024
5c1961c
Glue trailing comma to last text
asterite Oct 17, 2024
ca3bf71
Extract `comments_and_whitespace` module
asterite Oct 17, 2024
8b6d678
Better chunk tags
asterite Oct 17, 2024
328f5b4
Better way to format infix expressions
asterite Oct 17, 2024
86a98d9
Better formatting of MemberAccess chains
asterite Oct 17, 2024
c28f806
More chains
asterite Oct 17, 2024
6fbb4c4
A bit more member access and method calls
asterite Oct 17, 2024
ce7cce5
A bit more infix
asterite Oct 17, 2024
fc298a4
Add a failing test
asterite Oct 17, 2024
47a4840
No need to force chain children to be multiline
asterite Oct 17, 2024
81d9c09
Fix use trees
asterite Oct 17, 2024
739b17c
Trait impl impl generics
asterite Oct 17, 2024
b62feb7
comptime mut globals
asterite Oct 17, 2024
33ffecb
Format tuple member access
asterite Oct 17, 2024
cd3ad71
Format trait function with where clause but not body
asterite Oct 17, 2024
ea4fdbe
Write line after trait
asterite Oct 17, 2024
1fe9d4a
Write line after item
asterite Oct 17, 2024
815d347
Format trait where clause
asterite Oct 17, 2024
97da905
Trait bound generics
asterite Oct 17, 2024
cd39bae
Remove TODO
asterite Oct 17, 2024
28c76bc
Fix unintended token bump when formatting chunks
asterite Oct 17, 2024
0042f3f
Obey indentation chunks even when formatting in one line
asterite Oct 17, 2024
5131f43
Fix contract test
asterite Oct 17, 2024
6b55f9c
Put comments tests in its own module
asterite Oct 17, 2024
a1a9f8c
Format `{ /* comment */ }`
asterite Oct 17, 2024
eaf7727
More comments handling
asterite Oct 17, 2024
370b48b
More comments
asterite Oct 17, 2024
56630ea
Finally expr test file formats fine
asterite Oct 17, 2024
265ed7a
Handle comment inside index
asterite Oct 17, 2024
c6e417a
Spaces around infix operands
asterite Oct 17, 2024
40568f0
More comments and whitespaces
asterite Oct 17, 2024
84b8b62
Remove nested parents, and more comments and whitespace
asterite Oct 17, 2024
e2d3fc6
Tuples
asterite Oct 17, 2024
eecba23
Hopefully no need for ignore anymore
asterite Oct 17, 2024
ca1d5d3
Fix empty arguments list when multiple lines are needed
asterite Oct 17, 2024
6ef4c78
Attach comma to last group
asterite Oct 17, 2024
7817923
Fix constructor with turbofish
asterite Oct 17, 2024
b044cc8
Assign to tuple member
asterite Oct 17, 2024
4872371
Format lambda as last argument in a special (nice) way
asterite Oct 18, 2024
173dcea
A bit more lambda
asterite Oct 18, 2024
1b91c8f
More lambdas :-)
asterite Oct 18, 2024
55df85e
Fix some comments indentation
asterite Oct 18, 2024
a7b09f6
Clippy
asterite Oct 18, 2024
675a5d3
Fix issue with long use list
asterite Oct 18, 2024
2f71cd2
Honor the short_array_element_width_threshold config
asterite Oct 18, 2024
6283127
Comments and renames
asterite Oct 18, 2024
40f23ba
More comments
asterite Oct 18, 2024
41cd590
Clippy
asterite Oct 18, 2024
926af37
Format the standard library and test programs
asterite Oct 18, 2024
c3570a2
Handle comments after struct field
asterite Oct 18, 2024
6bbb36c
Format the stdlib again
asterite Oct 18, 2024
5367c51
Remove "error on lost comment" as this formatter never loses comments
asterite Oct 18, 2024
fe80ff2
Handle comments after function signature
asterite Oct 18, 2024
3a17152
Fix for long function signatures without parameters
asterite Oct 18, 2024
b56c3c8
Implement noir-fmt:ignore
asterite Oct 18, 2024
102f802
Don't indent in assign after `=`
asterite Oct 18, 2024
5cbe1b7
Document
asterite Oct 18, 2024
e331266
Remove lines before anything, preserve lines after comment and item
asterite Oct 18, 2024
77860e6
Move test
asterite Oct 18, 2024
d3c3b71
Reformat
asterite Oct 18, 2024
d198d69
Better way to see if we wrote comments
asterite Oct 18, 2024
8686b40
Format let statement attributes
asterite Oct 19, 2024
fe48c2f
No need to skip idempotency anymore
asterite Oct 19, 2024
b76ea4b
Fix regarding cspell
asterite Oct 19, 2024
435e9d8
Attach semicolon to last group text
asterite Oct 19, 2024
b28b9b3
Better way to format let statements and assignments
asterite Oct 19, 2024
5092e12
Better way to format method calls and chains in general
asterite Oct 19, 2024
451d174
Reformat the standard library and test programs
asterite Oct 19, 2024
ada28f0
Make sure to always attach semicolons to parent groups
asterite Oct 19, 2024
cb299e5
Introduce ChunkGroup::semicolon
asterite Oct 19, 2024
89a5a7e
Introduce ChunkGroup::space
asterite Oct 19, 2024
2229d40
Document a bit more
asterite Oct 19, 2024
1f714c2
Merge branch 'master' into ab/formatter
asterite Oct 19, 2024
fb5be0f
os-dependent newlines
asterite Oct 20, 2024
6d9d375
Fix quote contents getting wrong format
asterite Oct 21, 2024
e87bb19
Better (shorter) way to format nested calls and nested expression lis…
asterite Oct 21, 2024
1c6256f
Clippy
asterite Oct 21, 2024
f224bec
Reformat
asterite Oct 21, 2024
c07d540
Better way to avoid indenting twice
asterite Oct 21, 2024
9e1f811
Update tooling/nargo_fmt/src/formatter.rs
asterite Oct 21, 2024
9d58753
Update tooling/nargo_fmt/src/formatter/chunks.rs
asterite Oct 21, 2024
743d524
Update tooling/nargo_fmt/src/formatter/chunks.rs
asterite Oct 21, 2024
9f7636c
Update tooling/nargo_fmt/src/formatter/chunks.rs
asterite Oct 21, 2024
51a0006
Update tooling/nargo_fmt/src/formatter/chunks.rs
asterite Oct 21, 2024
76ab4ef
Format and use text snippet instead of rust
asterite Oct 21, 2024
aec8fda
Reuse `add_trailing_comma_to_last_text`
asterite Oct 21, 2024
3f2e724
Remove unneeded code
asterite Oct 21, 2024
7abc31e
Introduce a Buffer object to avoid writing to it in unintended ways
asterite Oct 21, 2024
593ad00
Merge branch 'master' into ab/formatter
asterite Oct 21, 2024
d7cc3c1
Format after merge
asterite Oct 21, 2024
ba0ac2c
Derive Debug for Buffer
asterite Oct 21, 2024
e5e062a
Better way to format lambdas that don't have a block as a body
asterite Oct 21, 2024
f6b0ffa
Always name a ChunkGroup as group, never as chunks
asterite Oct 21, 2024
e6a1088
Fix an issue introduced in the new lambda formatting
asterite Oct 21, 2024
54ad8b7
Merge branch 'master' into ab/formatter
asterite Oct 21, 2024
bc841e5
Update tooling/nargo_fmt/tests/expected/tuple.nr
asterite Oct 22, 2024
33a288f
Move chunks outside of the formatter directory
asterite Oct 22, 2024
b88c4ed
Merge branch 'ab/formatter' of github.com:noir-lang/noir into ab/form…
asterite Oct 22, 2024
768560d
Merge branch 'master' into ab/formatter
asterite Oct 22, 2024
a386434
Remove FIXME from tuple sample
asterite Oct 22, 2024
fb27136
Introduce ChunkFormatter to avoid mixing formatting modes (thank you …
asterite Oct 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 0 additions & 8 deletions 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 compiler/noirc_frontend/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@
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 @@
/// 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 @@
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 Expand Up @@ -517,7 +530,7 @@
Self::Public => write!(f, "pub"),
Self::Private => write!(f, "priv"),
Self::CallData(id) => write!(f, "calldata{id}"),
Self::ReturnData => write!(f, "returndata"),

Check warning on line 533 in compiler/noirc_frontend/src/ast/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (returndata)
}
}
}
1 change: 1 addition & 0 deletions compiler/noirc_frontend/src/hir/comptime/display.rs
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 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 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
2 changes: 2 additions & 0 deletions compiler/noirc_frontend/src/parser/parser/generics.rs
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 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_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
Loading