Skip to content
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
f55d717
Start #7897
aakoshh Apr 2, 2025
e1c966f
FunctionContext::gen_expr
aakoshh Apr 2, 2025
290542d
Add Scope with type producers
aakoshh Apr 2, 2025
08cc1e2
Produce a type from available variables
aakoshh Apr 2, 2025
97c719a
Produce the array index from random expressions
aakoshh Apr 2, 2025
2e413a4
Produce a target from a tuple
aakoshh Apr 2, 2025
7ae8e34
Supress unused warnings
aakoshh Apr 2, 2025
0c85c82
Separate locals and global scope
aakoshh Apr 2, 2025
39eda06
Compose objects from expressions
aakoshh Apr 2, 2025
eb440dc
Try improve readability with shorter names
aakoshh Apr 2, 2025
774faf6
Deref references
aakoshh Apr 3, 2025
e51391a
Generate unary
aakoshh Apr 3, 2025
12580d1
Generate binary
aakoshh Apr 3, 2025
94f3385
Refactor freq
aakoshh Apr 3, 2025
dbcc6f1
Block and Let
aakoshh Apr 3, 2025
42228a3
If expr
aakoshh Apr 3, 2025
1ab57ba
Register locals
aakoshh Apr 3, 2025
3910f1c
If as statement
aakoshh Apr 3, 2025
12adf63
Semi
aakoshh Apr 3, 2025
248003d
Drop
aakoshh Apr 3, 2025
3b1e6fb
Factor out frequencies into the config
aakoshh Apr 3, 2025
44a4f0b
Show mutability in AST print
aakoshh Apr 3, 2025
9e6baec
Assign
aakoshh Apr 3, 2025
2dd4b68
push/pop scopes for if-then-else
aakoshh Apr 3, 2025
89edf54
Reduce function size
aakoshh Apr 3, 2025
1d19a5f
Separate freq module
aakoshh Apr 4, 2025
c8af28a
Separate scope module
aakoshh Apr 4, 2025
0dca936
Test scope cloning and types produced
aakoshh Apr 4, 2025
7a5316f
Add ScopeStack
aakoshh Apr 4, 2025
5eab799
Redistribute frequencies
aakoshh Apr 4, 2025
6545dd6
Tweaks to weights, fix blocks in condition
aakoshh Apr 4, 2025
3736ac0
Rename if_then to if
aakoshh Apr 4, 2025
8ea40ff
For loop
aakoshh Apr 4, 2025
028d2ab
Remove unused
aakoshh Apr 4, 2025
d6e7e52
TODO ticket numbers
aakoshh Apr 4, 2025
27f6551
Tweak budgets to try to avoid trivial unit ifs
aakoshh Apr 4, 2025
027027b
Merge remote-tracking branch 'origin/master' into af/7879-ast-fuzz-fn…
aakoshh Apr 4, 2025
cf3b3ec
Merge branch 'master' into af/7879-ast-fuzz-fn-body
rkarabut Apr 6, 2025
c702d81
Fix name
aakoshh Apr 7, 2025
46546c8
Merge branch 'af/7879-ast-fuzz-fn-body' of github.com:noir-lang/noir …
aakoshh Apr 7, 2025
1337539
Comments about ordering freq.enabled_when
aakoshh Apr 7, 2025
c3bf260
Better test case for redistribution
aakoshh Apr 7, 2025
6944621
Print the AST, inputs, ACIR and Brillig upon failure
aakoshh Apr 7, 2025
e013d53
Don't fail if the assertion payload is the same
aakoshh Apr 7, 2025
85ac778
Fix clippy
aakoshh Apr 7, 2025
5d59aca
Add name and type to globals so we can see what the AST is
aakoshh Apr 7, 2025
c8fdb82
Merge branch 'master' into af/7879-ast-fuzz-fn-body
aakoshh Apr 7, 2025
87c2cb9
Fix the failing monomorphization test
aakoshh Apr 7, 2025
3a9b8d1
Print the SSA during compilation if the debug flag is on
aakoshh Apr 7, 2025
1ddece1
Stop using i128 in unary and binary ops
aakoshh Apr 7, 2025
4c9f8a7
Only consider binary op inputs which are compatible with the output
aakoshh Apr 7, 2025
434635a
Merge remote-tracking branch 'origin/master' into af/7879-ast-fuzz-fn…
aakoshh Apr 7, 2025
c633d2a
Binary ops only work on numeric types
aakoshh Apr 7, 2025
d99e0c9
Merge branch 'master' into af/7879-ast-fuzz-fn-body
rkarabut Apr 8, 2025
9229d8b
Cast binary result to target if needed
aakoshh Apr 8, 2025
cdd4da8
Merge branch 'af/7879-ast-fuzz-fn-body' of github.com:noir-lang/noir …
aakoshh Apr 8, 2025
fe84562
Consider division by zero and unsatisified constrain equal
aakoshh Apr 8, 2025
56991a3
Don't generate negative i128 literals
aakoshh Apr 8, 2025
a1f125d
Add GITHUB_TOKEN for downloading prost_prebuilt
aakoshh Apr 8, 2025
9244871
Add GITHUB_TOKEN for downloading prost_prebuilt
aakoshh Apr 8, 2025
31a3d3c
Print the error in debug format when one of them failed
aakoshh Apr 8, 2025
54d7cf1
Separate env vars for printing AST and SSA. Budget limited by data
aakoshh Apr 8, 2025
9a084c7
Don't generate i1 for globals
aakoshh Apr 8, 2025
697b0f5
More types that don't work in global
aakoshh Apr 8, 2025
2bfb47f
Treat modulo as arithmetic
aakoshh Apr 8, 2025
4545562
No need to cast to bool
aakoshh Apr 8, 2025
d1b3bf1
Merge branch 'master' into af/7879-ast-fuzz-fn-body
aakoshh Apr 9, 2025
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
21 changes: 19 additions & 2 deletions compiler/noirc_frontend/src/ast/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,7 @@ impl Expression {

pub type BinaryOp = Located<BinaryOpKind>;

#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Debug, Copy, Clone)]
#[cfg_attr(test, derive(strum_macros::EnumIter))]
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Debug, Copy, Clone, strum_macros::EnumIter)]
pub enum BinaryOpKind {
Add,
Subtract,
Expand Down Expand Up @@ -339,6 +338,24 @@ impl BinaryOpKind {
)
}

pub fn is_arithmetic(self) -> bool {
matches!(
self,
BinaryOpKind::Add
| BinaryOpKind::Subtract
| BinaryOpKind::Multiply
| BinaryOpKind::Divide
)
}

pub fn is_bitwise(self) -> bool {
matches!(self, BinaryOpKind::And | BinaryOpKind::Or | BinaryOpKind::Xor)
}

pub fn is_bitshift(self) -> bool {
matches!(self, BinaryOpKind::ShiftLeft | BinaryOpKind::ShiftRight)
}

pub fn is_valid_for_field_type(self) -> bool {
matches!(
self,
Expand Down
1 change: 1 addition & 0 deletions compiler/noirc_frontend/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ impl From<IntegerBitSize> for u32 {
}
}

#[derive(Debug)]
pub struct InvalidIntegerBitSizeError(pub u32);

impl TryFrom<u32> for IntegerBitSize {
Expand Down
16 changes: 13 additions & 3 deletions compiler/noirc_frontend/src/monomorphization/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ impl AstPrinter {

write!(
f,
"fn {}$f{}({}) -> {} {{",
function.name, function.id, params, function.return_type
"{}fn {}$f{}({}) -> {} {{",
if function.unconstrained { "unconstrained " } else { "" },
function.name,
function.id,
params,
function.return_type
)?;
self.indent_level += 1;
self.print_expr_expect_block(&function.body, f)?;
Expand Down Expand Up @@ -75,7 +79,13 @@ impl AstPrinter {
}
Expression::Call(call) => self.print_call(call, f),
Expression::Let(let_expr) => {
write!(f, "let {}${} = ", let_expr.name, let_expr.id.0)?;
write!(
f,
"let {}{}${} = ",
if let_expr.mutable { "mut " } else { "" },
let_expr.name,
let_expr.id.0
)?;
self.print_expr(&let_expr.expression, f)
}
Expression::Constrain(expr, ..) => {
Expand Down
2 changes: 2 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"bindgen",
"bitand",
"bitmask",
"bitshift",
"bitsize",
"blackbox",
"boilerplate",
Expand Down Expand Up @@ -108,6 +109,7 @@
"foralls",
"formatcp",
"fpath",
"freqs",
"frontends",
"fuzzer",
"fxhash",
Expand Down
9 changes: 9 additions & 0 deletions test_programs/execution_success/loop/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ fn main(six_as_u32: u32) {
assert_eq(loop_excl(4), six_as_u32);
assert_eq(loop_incl(3), six_as_u32);
assert(plain_loop() == six_as_u32);
assert(never_loop() == 0);
}

fn loop_excl(x: u32) -> u32 {
Expand All @@ -30,3 +31,11 @@ fn plain_loop() -> u32 {
}
sum
}

fn never_loop() -> u32 {
let mut sum = 0;
for i in 4..0 {
sum = sum + i;
}
sum
}
30 changes: 28 additions & 2 deletions tooling/ast_fuzzer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod program;
pub use abi::program_abi;
pub use input::arb_inputs;
pub use program::arb_program;
use program::freq::Freqs;

/// AST generation configuration.
#[derive(Debug, Clone)]
Expand All @@ -16,23 +17,48 @@ pub struct Config {
pub max_functions: usize,
/// Maximum number of arguments a function can have.
pub max_function_args: usize,
/// Maximum number of statements to aim for in a function body.
pub max_function_size: usize,
/// Maximum number of statements in a block.
pub max_block_size: usize,
/// Maximum nesting depth for complex expressions.
pub max_depth: usize,
/// Maximum number of fields for tuples.
pub max_tuple_size: usize,
/// Maximum size for arrays.
pub max_array_size: usize,
/// Maximum size of for loop ranges, which affects unrolling in ACIR.
pub max_range_size: usize,
/// Frequency of expressions that produce a value.
pub expr_freqs: Freqs,
/// Frequency of statements that don't produce a value.
pub stmt_freqs: Freqs,
}

impl Default for Config {
fn default() -> Self {
let expr_freqs = Freqs::new(&[
("unary", 5),
("binary", 20),
("if", 15),
("block", 30),
("vars", 20),
("literal", 5),
]);
let stmt_freqs =
Freqs::new(&[("drop", 5), ("assign", 30), ("if", 10), ("for", 20), ("let", 20)]);
Self {
max_globals: 3,
max_functions: 5,
max_function_args: 3,
max_function_size: 25,
max_block_size: 5,
max_depth: 2,
max_tuple_size: 4,
max_array_size: 8,
max_tuple_size: 5,
max_array_size: 4,
max_range_size: 10,
expr_freqs,
stmt_freqs,
}
}
}
Loading
Loading