Skip to content

Commit b82f3d1

Browse files
AztecBotsirasistantTomAFrench
authored
feat: Sync from noir (#9569)
Automated pull of development from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec. BEGIN_COMMIT_OVERRIDE chore: use array instead of Vec in keccak256 (noir-lang/noir#6395) fix: make keccak256 work with input lengths greater than 136 bytes (noir-lang/noir#6393) feat: support specifying generics on a struct when calling an associated function (noir-lang/noir#6306) fix: Display every bit in integer tokens (noir-lang/noir#6360) feat: better LSP hover for functions (noir-lang/noir#6376) feat: Add capacities to brillig vectors and use them in slice ops (noir-lang/noir#6332) feat: suggest removing `!` from macro call that doesn't return Quoted (noir-lang/noir#6384) fix: (formatter) correctly format quote delimiters (noir-lang/noir#6377) fix: allow globals in format strings (noir-lang/noir#6382) END_COMMIT_OVERRIDE --------- Co-authored-by: sirasistant <[email protected]> Co-authored-by: Tom French <[email protected]>
1 parent 9a5dce3 commit b82f3d1

File tree

46 files changed

+1711
-655
lines changed

Some content is hidden

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

46 files changed

+1711
-655
lines changed

.noir-sync-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
60c770f5f2594eea31ac75c852980edefa40d9eb
1+
075c3d32481314d900cbdea0d277de83444747ab

noir/noir-repo/acvm-repo/acir_field/src/field_element.rs

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::ops::{Add, AddAssign, Div, Mul, Neg, Sub, SubAssign};
88
use crate::AcirField;
99

1010
// XXX: Switch out for a trait and proper implementations
11-
// This implementation is in-efficient, can definitely remove hex usage and Iterator instances for trivial functionality
11+
// This implementation is inefficient, can definitely remove hex usage and Iterator instances for trivial functionality
1212
#[derive(Default, Clone, Copy, Eq, PartialOrd, Ord)]
1313
pub struct FieldElement<F: PrimeField>(F);
1414

@@ -33,46 +33,6 @@ impl<F: PrimeField> std::fmt::Display for FieldElement<F> {
3333
write!(f, "-")?;
3434
}
3535

36-
// Number of bits needed to represent the smaller representation
37-
let num_bits = smaller_repr.bits();
38-
39-
// Check if the number represents a power of 2
40-
if smaller_repr.count_ones() == 1 {
41-
let mut bit_index = 0;
42-
for i in 0..num_bits {
43-
if smaller_repr.bit(i) {
44-
bit_index = i;
45-
break;
46-
}
47-
}
48-
return match bit_index {
49-
0 => write!(f, "1"),
50-
1 => write!(f, "2"),
51-
2 => write!(f, "4"),
52-
3 => write!(f, "8"),
53-
_ => write!(f, "2{}", superscript(bit_index)),
54-
};
55-
}
56-
57-
// Check if number is a multiple of a power of 2.
58-
// This is used because when computing the quotient
59-
// we usually have numbers in the form 2^t * q + r
60-
// We focus on 2^64, 2^32, 2^16, 2^8, 2^4 because
61-
// they are common. We could extend this to a more
62-
// general factorization strategy, but we pay in terms of CPU time
63-
let mul_sign = "×";
64-
for power in [64, 32, 16, 8, 4] {
65-
let power_of_two = BigUint::from(2_u128).pow(power);
66-
if &smaller_repr % &power_of_two == BigUint::zero() {
67-
return write!(
68-
f,
69-
"2{}{}{}",
70-
superscript(power as u64),
71-
mul_sign,
72-
smaller_repr / &power_of_two,
73-
);
74-
}
75-
}
7636
write!(f, "{smaller_repr}")
7737
}
7838
}
@@ -409,35 +369,6 @@ impl<F: PrimeField> SubAssign for FieldElement<F> {
409369
}
410370
}
411371

412-
// For pretty printing powers
413-
fn superscript(n: u64) -> String {
414-
if n == 0 {
415-
"⁰".to_owned()
416-
} else if n == 1 {
417-
"¹".to_owned()
418-
} else if n == 2 {
419-
"²".to_owned()
420-
} else if n == 3 {
421-
"³".to_owned()
422-
} else if n == 4 {
423-
"⁴".to_owned()
424-
} else if n == 5 {
425-
"⁵".to_owned()
426-
} else if n == 6 {
427-
"⁶".to_owned()
428-
} else if n == 7 {
429-
"⁷".to_owned()
430-
} else if n == 8 {
431-
"⁸".to_owned()
432-
} else if n == 9 {
433-
"⁹".to_owned()
434-
} else if n >= 10 {
435-
superscript(n / 10) + &superscript(n % 10)
436-
} else {
437-
panic!("{}", n.to_string() + " can't be converted to superscript.");
438-
}
439-
}
440-
441372
#[cfg(test)]
442373
mod tests {
443374
use super::{AcirField, FieldElement};

noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_black_box.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use acvm::{
88

99
use crate::brillig::brillig_ir::{
1010
brillig_variable::BrilligVariable, debug_show::DebugToString, registers::RegisterAllocator,
11-
BrilligBinaryOp, BrilligContext,
11+
BrilligContext,
1212
};
1313

1414
/// Transforms SSA's black box function calls into the corresponding brillig instructions
@@ -395,19 +395,8 @@ pub(crate) fn convert_black_box_call<F: AcirField + DebugToString, Registers: Re
395395

396396
brillig_context.mov_instruction(out_len.address, outputs_vector.size);
397397
// Returns slice, so we need to allocate memory for it after the fact
398-
brillig_context.codegen_usize_op_in_place(
399-
outputs_vector.size,
400-
BrilligBinaryOp::Add,
401-
2_usize,
402-
);
403-
brillig_context.increase_free_memory_pointer_instruction(outputs_vector.size);
404-
// We also need to write the size of the vector to the memory
405-
brillig_context.codegen_usize_op_in_place(
406-
outputs_vector.pointer,
407-
BrilligBinaryOp::Sub,
408-
1_usize,
409-
);
410-
brillig_context.store_instruction(outputs_vector.pointer, out_len.address);
398+
399+
brillig_context.initialize_externally_returned_vector(*outputs, outputs_vector);
411400

412401
brillig_context.deallocate_heap_vector(inputs);
413402
brillig_context.deallocate_heap_vector(outputs_vector);

noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -374,34 +374,10 @@ impl<'block> BrilligBlock<'block> {
374374
match output_register {
375375
// Returned vectors need to emit some bytecode to format the result as a BrilligVector
376376
ValueOrArray::HeapVector(heap_vector) => {
377-
// Update the stack pointer so that we do not overwrite
378-
// dynamic memory returned from other external calls
379-
// Single values and allocation of fixed sized arrays has already been handled
380-
// inside of `allocate_external_call_result`
381-
let total_size = self.brillig_context.allocate_register();
382-
self.brillig_context.codegen_usize_op(
383-
heap_vector.size,
384-
total_size,
385-
BrilligBinaryOp::Add,
386-
2, // RC and Length
377+
self.brillig_context.initialize_externally_returned_vector(
378+
output_variable.extract_vector(),
379+
*heap_vector,
387380
);
388-
389-
self.brillig_context
390-
.increase_free_memory_pointer_instruction(total_size);
391-
let brillig_vector = output_variable.extract_vector();
392-
let size_pointer = self.brillig_context.allocate_register();
393-
394-
self.brillig_context.codegen_usize_op(
395-
brillig_vector.pointer,
396-
size_pointer,
397-
BrilligBinaryOp::Add,
398-
1_usize, // Slices are [RC, Size, ...items]
399-
);
400-
self.brillig_context
401-
.store_instruction(size_pointer, heap_vector.size);
402-
self.brillig_context.deallocate_register(size_pointer);
403-
self.brillig_context.deallocate_register(total_size);
404-
405381
// Update the dynamic slice length maintained in SSA
406382
if let ValueOrArray::MemoryAddress(len_index) = output_values[i - 1]
407383
{
@@ -515,8 +491,11 @@ impl<'block> BrilligBlock<'block> {
515491
element_size,
516492
);
517493

518-
self.brillig_context
519-
.codegen_initialize_vector(destination_vector, source_size_register);
494+
self.brillig_context.codegen_initialize_vector(
495+
destination_vector,
496+
source_size_register,
497+
None,
498+
);
520499

521500
// Items
522501
let vector_items_pointer =
@@ -1575,7 +1554,7 @@ impl<'block> BrilligBlock<'block> {
15751554
let size = self
15761555
.brillig_context
15771556
.make_usize_constant_instruction(array.len().into());
1578-
self.brillig_context.codegen_initialize_vector(vector, size);
1557+
self.brillig_context.codegen_initialize_vector(vector, size, None);
15791558
self.brillig_context.deallocate_single_addr(size);
15801559
}
15811560
_ => unreachable!(
@@ -1821,11 +1800,6 @@ impl<'block> BrilligBlock<'block> {
18211800
// The stack pointer will then be updated by the caller of this method
18221801
// once the external call is resolved and the array size is known
18231802
self.brillig_context.load_free_memory_pointer_instruction(vector.pointer);
1824-
self.brillig_context.indirect_const_instruction(
1825-
vector.pointer,
1826-
BRILLIG_MEMORY_ADDRESSING_BIT_SIZE,
1827-
1_usize.into(),
1828-
);
18291803

18301804
variable
18311805
}

0 commit comments

Comments
 (0)