Skip to content

Commit

Permalink
Merge branch 'master' into michaeljklein/pedantic-flag
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljklein authored Jan 7, 2025
2 parents 75f912e + dcdccfc commit b013d23
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/reports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ jobs:
fail-fast: false
matrix:
include:
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-contracts, is_library: true }
# - project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-contracts, is_library: true }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/private-kernel-inner, take_average: true }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/private-kernel-tail, take_average: true }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/private-kernel-reset, take_average: true }
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/acir/acir_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1421,7 +1421,7 @@ impl<F: AcirField, B: BlackBoxFunctionSolver<F>> AcirContext<F, B> {
}
}?;
output_count = input_size + (16 - input_size % 16);
(vec![], vec![F::from(output_count as u128)])
(vec![], vec![])
}
BlackBoxFunc::RecursiveAggregation => {
let proof_type_var = match inputs.pop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,14 @@ pub(crate) fn convert_black_box_call<F: AcirField + DebugToString, Registers: Re
BlackBoxFunc::AES128Encrypt => {
if let (
[inputs, BrilligVariable::BrilligArray(iv), BrilligVariable::BrilligArray(key)],
[BrilligVariable::SingleAddr(out_len), BrilligVariable::BrilligVector(outputs)],
[outputs],
) = (function_arguments, function_results)
{
let inputs = convert_array_or_vector(brillig_context, *inputs, bb_func);
let iv = brillig_context.codegen_brillig_array_to_heap_array(*iv);
let key = brillig_context.codegen_brillig_array_to_heap_array(*key);

let outputs_vector =
brillig_context.codegen_brillig_vector_to_heap_vector(*outputs);
let outputs_vector = convert_array_or_vector(brillig_context, *outputs, bb_func);

brillig_context.black_box_op_instruction(BlackBoxOp::AES128Encrypt {
inputs,
Expand All @@ -372,11 +371,6 @@ pub(crate) fn convert_black_box_call<F: AcirField + DebugToString, Registers: Re
outputs: outputs_vector,
});

brillig_context.mov_instruction(out_len.address, outputs_vector.size);
// Returns slice, so we need to allocate memory for it after the fact

brillig_context.initialize_externally_returned_vector(*outputs, outputs_vector);

brillig_context.deallocate_heap_vector(inputs);
brillig_context.deallocate_heap_vector(outputs_vector);
brillig_context.deallocate_heap_array(iv);
Expand Down
11 changes: 6 additions & 5 deletions compiler/noirc_frontend/src/elaborator/path_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ impl<'context> Elaborator<'context> {

// Check if namespace
let found_ns = if current_module_id_is_struct {
match self.resolve_struct_function(starting_module, current_module, current_ident) {
match self.resolve_struct_function(importing_module, current_module, current_ident)
{
StructMethodLookupResult::NotFound(vec) => {
if vec.is_empty() {
return Err(PathResolutionError::Unresolved(current_ident.clone()));
Expand All @@ -306,7 +307,7 @@ impl<'context> Elaborator<'context> {
StructMethodLookupResult::FoundStructMethod(per_ns) => per_ns,
StructMethodLookupResult::FoundTraitMethod(per_ns, trait_id) => {
let trait_ = self.interner.get_trait(trait_id);
self.usage_tracker.mark_as_used(starting_module, &trait_.name);
self.usage_tracker.mark_as_used(importing_module, &trait_.name);
per_ns
}
StructMethodLookupResult::FoundOneTraitMethodButNotInScope(
Expand All @@ -324,7 +325,7 @@ impl<'context> Elaborator<'context> {
StructMethodLookupResult::FoundMultipleTraitMethods(vec) => {
let traits = vecmap(vec, |trait_id| {
let trait_ = self.interner.get_trait(trait_id);
self.usage_tracker.mark_as_used(starting_module, &trait_.name);
self.usage_tracker.mark_as_used(importing_module, &trait_.name);
self.fully_qualified_trait_path(trait_)
});
return Err(PathResolutionError::MultipleTraitsInScope {
Expand Down Expand Up @@ -382,7 +383,7 @@ impl<'context> Elaborator<'context> {

fn resolve_struct_function(
&self,
starting_module_id: ModuleId,
importing_module_id: ModuleId,
current_module: &ModuleData,
ident: &Ident,
) -> StructMethodLookupResult {
Expand All @@ -402,7 +403,7 @@ impl<'context> Elaborator<'context> {
}

// Otherwise, the function could be defined in zero, one or more traits.
let starting_module = self.get_module(starting_module_id);
let starting_module = self.get_module(importing_module_id);

// Gather a list of items for which their trait is in scope.
let mut results = Vec::new();
Expand Down
32 changes: 31 additions & 1 deletion compiler/noirc_frontend/src/tests/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ fn calls_trait_function_if_it_is_in_scope() {
}

#[test]
fn calls_trait_function_it_is_only_candidate_in_scope() {
fn calls_trait_function_if_it_is_only_candidate_in_scope() {
let src = r#"
use private_mod::Foo;
Expand Down Expand Up @@ -753,6 +753,36 @@ fn calls_trait_function_it_is_only_candidate_in_scope() {
assert_no_errors(src);
}

#[test]
fn calls_trait_function_if_it_is_only_candidate_in_scope_in_nested_module_using_super() {
let src = r#"
mod moo {
use super::public_mod::Foo;
pub fn method() {
let _ = super::Bar::foo();
}
}
fn main() {}
pub struct Bar {}
pub mod public_mod {
pub trait Foo {
fn foo() -> i32;
}
impl Foo for super::Bar {
fn foo() -> i32 {
42
}
}
}
"#;
assert_no_errors(src);
}

#[test]
fn errors_if_trait_is_not_in_scope_for_function_call_and_there_are_multiple_candidates() {
let src = r#"
Expand Down
6 changes: 5 additions & 1 deletion noir_stdlib/src/aes128.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#[foreign(aes128_encrypt)]
// docs:start:aes128
pub fn aes128_encrypt<let N: u32>(input: [u8; N], iv: [u8; 16], key: [u8; 16]) -> [u8] {}
pub fn aes128_encrypt<let N: u32>(
input: [u8; N],
iv: [u8; 16],
key: [u8; 16],
) -> [u8; N + 16 - N % 16] {}
// docs:end:aes128
4 changes: 2 additions & 2 deletions test_programs/execution_success/aes128_encrypt/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ unconstrained fn decode_hex<let N: u32, let M: u32>(s: str<N>) -> [u8; M] {

unconstrained fn cipher(plaintext: [u8; 12], iv: [u8; 16], key: [u8; 16]) -> [u8; 16] {
let result = std::aes128::aes128_encrypt(plaintext, iv, key);
result.as_array()
result
}

fn main(inputs: str<12>, iv: str<16>, key: str<16>, output: str<32>) {
let result: [u8; 16] =
std::aes128::aes128_encrypt(inputs.as_bytes(), iv.as_bytes(), key.as_bytes()).as_array();
std::aes128::aes128_encrypt(inputs.as_bytes(), iv.as_bytes(), key.as_bytes());

let output_bytes: [u8; 16] = unsafe {
//@safety: testing context
Expand Down

0 comments on commit b013d23

Please sign in to comment.