Skip to content

Commit

Permalink
[1 changes] chore: remove usage of slices in pedersen hash (noir-lang…
Browse files Browse the repository at this point in the history
…/noir#6295)

chore: remove dead function (noir-lang/noir#6308)
feat: new formatter (noir-lang/noir#6300)
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 23, 2024
1 parent ab0c80d commit 06768d9
Show file tree
Hide file tree
Showing 368 changed files with 17,578 additions and 5,448 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ae87d287ab1fae0f999dfd0d1166fbddb927ba97
8dec84793d200dcb524aa5c397d0a84d38974e7e
2 changes: 1 addition & 1 deletion noir/noir-repo/.github/workflows/docs-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:

- name: Build docs
env:
MATOMO_ENV: staging # not really a secret, it will show in the footer anyway
ENV: staging # not really a secret, it will show in the footer anyway
run: yarn workspaces foreach -Rpt --from docs run build

- name: Upload artifact
Expand Down
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.

2 changes: 1 addition & 1 deletion noir/noir-repo/acvm-repo/acvm_js/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function run_if_available {
require_command jq
require_command cargo
require_command wasm-bindgen
#require_command wasm-opt
require_command wasm-opt

self_path=$(dirname "$(readlink -f "$0")")
pname=$(cargo read-manifest | jq -r '.name')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::{
};
use acvm::acir::{brillig::MemoryAddress, AcirField};

pub(crate) const MAX_STACK_SIZE: usize = 32768;
pub(crate) const MAX_STACK_SIZE: usize = 16 * MAX_STACK_FRAME_SIZE;
pub(crate) const MAX_STACK_FRAME_SIZE: usize = 2048;
pub(crate) const MAX_SCRATCH_SPACE: usize = 64;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ pub(super) fn simplify_call(
} else {
unreachable!("ICE: Intrinsic::ToRadix return type must be array")
};
let result_array = constant_to_radix(endian, field, 2, limb_count, dfg);

SimplifyResult::SimplifiedTo(result_array)
constant_to_radix(endian, field, 2, limb_count, dfg)
} else {
SimplifyResult::None
}
Expand All @@ -79,10 +77,7 @@ pub(super) fn simplify_call(
} else {
unreachable!("ICE: Intrinsic::ToRadix return type must be array")
};

let result_array = constant_to_radix(endian, field, radix, limb_count, dfg);

SimplifyResult::SimplifiedTo(result_array)
constant_to_radix(endian, field, radix, limb_count, dfg)
} else {
SimplifyResult::None
}
Expand Down Expand Up @@ -606,22 +601,29 @@ fn constant_to_radix(
radix: u32,
limb_count: u32,
dfg: &mut DataFlowGraph,
) -> ValueId {
) -> SimplifyResult {
let bit_size = u32::BITS - (radix - 1).leading_zeros();
let radix_big = BigUint::from(radix);
assert_eq!(BigUint::from(2u128).pow(bit_size), radix_big, "ICE: Radix must be a power of 2");
let big_integer = BigUint::from_bytes_be(&field.to_be_bytes());

// Decompose the integer into its radix digits in little endian form.
let decomposed_integer = big_integer.to_radix_le(radix);
let mut limbs = vecmap(0..limb_count, |i| match decomposed_integer.get(i as usize) {
Some(digit) => FieldElement::from_be_bytes_reduce(&[*digit]),
None => FieldElement::zero(),
});
if endian == Endian::Big {
limbs.reverse();
if limb_count < decomposed_integer.len() as u32 {
// `field` cannot be represented as `limb_count` bits.
// defer error to acir_gen.
SimplifyResult::None
} else {
let mut limbs = vecmap(0..limb_count, |i| match decomposed_integer.get(i as usize) {
Some(digit) => FieldElement::from_be_bytes_reduce(&[*digit]),
None => FieldElement::zero(),
});
if endian == Endian::Big {
limbs.reverse();
}
let result_array = make_constant_array(dfg, limbs, Type::unsigned(bit_size));
SimplifyResult::SimplifiedTo(result_array)
}
make_constant_array(dfg, limbs, Type::unsigned(bit_size))
}

fn to_u8_vec(dfg: &DataFlowGraph, values: im::Vector<Id<Value>>) -> Vec<u8> {
Expand Down
29 changes: 27 additions & 2 deletions noir/noir-repo/compiler/noirc_evaluator/src/ssa/opt/inlining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,14 @@ impl InlineContext {
) -> Vec<ValueId> {
self.recursion_level += 1;

let source_function = &ssa.functions[&id];

if self.recursion_level > RECURSION_LIMIT {
panic!(
"Attempted to recur more than {RECURSION_LIMIT} times during function inlining."
"Attempted to recur more than {RECURSION_LIMIT} times during inlining function '{}': {}", source_function.name(), source_function
);
}

let source_function = &ssa.functions[&id];
let mut context = PerFunctionContext::new(self, source_function);

let parameters = source_function.parameters();
Expand Down Expand Up @@ -1091,6 +1092,30 @@ mod test {
assert_eq!(main.reachable_blocks().len(), 4);
}

#[test]
#[should_panic(
expected = "Attempted to recur more than 1000 times during inlining function 'main': acir(inline) fn main f0 {"
)]
fn unconditional_recursion() {
// fn main f1 {
// b0():
// call f1()
// return
// }
let main_id = Id::test_new(0);
let mut builder = FunctionBuilder::new("main".into(), main_id);

let main = builder.import_function(main_id);
let results = builder.insert_call(main, Vec::new(), vec![]).to_vec();
builder.terminate_with_return(results);

let ssa = builder.finish();
assert_eq!(ssa.functions.len(), 1);

let inlined = ssa.inline_functions(i64::MAX);
assert_eq!(inlined.functions.len(), 0);
}

#[test]
fn inliner_disabled() {
// brillig fn foo {
Expand Down
29 changes: 0 additions & 29 deletions noir/noir-repo/compiler/noirc_evaluator/src/ssa/opt/unrolling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,35 +81,6 @@ impl Ssa {
}

impl Function {
// TODO(https://github.com/noir-lang/noir/issues/6192): are both this and
// TODO: Ssa::unroll_loops_iteratively needed? Likely able to be combined
pub(crate) fn unroll_loops_iteratively(&mut self) -> Result<(), RuntimeError> {
// Try to unroll loops first:
let mut unroll_errors = vec![];
self.try_to_unroll_loops(&mut unroll_errors);

// Keep unrolling until no more errors are found
while !unroll_errors.is_empty() {
let prev_unroll_err_count = unroll_errors.len();

// Simplify the SSA before retrying

// Do a mem2reg after the last unroll to aid simplify_cfg
self.mem2reg();
self.simplify_function();
// Do another mem2reg after simplify_cfg to aid the next unroll
self.mem2reg();

// Unroll again
self.try_to_unroll_loops(&mut unroll_errors);
// If we didn't manage to unroll any more loops, exit
if unroll_errors.len() >= prev_unroll_err_count {
return Err(unroll_errors.swap_remove(0));
}
}
Ok(())
}

pub(crate) fn try_to_unroll_loops(&mut self, errors: &mut Vec<RuntimeError>) {
// Loop unrolling in brillig can lead to a code explosion currently. This can
// also be true for ACIR, but we have no alternative to unrolling in ACIR.
Expand Down
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
Loading

0 comments on commit 06768d9

Please sign in to comment.