Skip to content

Commit

Permalink
Merge branch 'master' into aztec-packages
Browse files Browse the repository at this point in the history
* master: (30 commits)
  chore: add regression tests for #4372 (#6401)
  chore: add regression tests for #6314 (#6381)
  chore: use array instead of Vec in keccak256 (#6395)
  fix: make keccak256 work with input lengths greater than 136 bytes (#6393)
  feat: support specifying generics on a struct when calling an associated function (#6306)
  fix: Display every bit in integer tokens (#6360)
  feat: better LSP hover for functions (#6376)
  feat: Add capacities to brillig vectors and use them in slice ops (#6332)
  feat: suggest removing `!` from macro call that doesn't return Quoted (#6384)
  fix: (formatter) correctly format quote delimiters (#6377)
  fix: allow globals in format strings (#6382)
  feat: do not increment reference counts on arrays through references (#6375)
  fix: (LSP) check visibility of module that re-exports item, if any (#6371)
  feat: let LSP suggest traits in trait bounds (#6370)
  fix: LSP auto-import would import public item inside private module (#6366)
  fix: remove assumed parent traits (#6365)
  fix: slightly better formatting of empty blocks with comments (#6367)
  fix: Fix panic in comptime code (#6361)
  feat: let the LSP import code action insert into existing use statements (#6358)
  chore: minor tweaks to comptime doc (#6357)
  ...
  • Loading branch information
TomAFrench committed Oct 30, 2024
2 parents fb5cb0f + 4e44e1f commit bc7d722
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 15 deletions.
8 changes: 1 addition & 7 deletions compiler/noirc_evaluator/src/ssa/function_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,7 @@ impl FunctionBuilder {
match self.type_of_value(value) {
Type::Numeric(_) => (),
Type::Function => (),
Type::Reference(element) => {
if element.contains_an_array() {
let reference = value;
let value = self.insert_load(reference, element.as_ref().clone());
self.update_array_reference_count(value, increment);
}
}
Type::Reference(_) => (),
Type::Array(..) | Type::Slice(..) => {
// If there are nested arrays or slices, we wait until ArrayGet
// is issued to increment the count of that array.
Expand Down
26 changes: 18 additions & 8 deletions compiler/noirc_frontend/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3548,17 +3548,27 @@ fn uses_self_in_import() {
}

#[test]
fn alias_in_let_pattern() {
fn does_not_error_on_return_values_after_block_expression() {
// Regression test for https://github.com/noir-lang/noir/issues/4372
let src = r#"
struct Foo<T> { x: T }
type Bar<U> = Foo<U>;
fn case1() -> [Field] {
if true {
}
&[1]
}
fn main() {
let Bar { x } = Foo { x: [0] };
// This is just to show the compiler knows this is an array.
let _: [Field; 1] = x;
fn case2() -> [u8] {
let mut var: u8 = 1;
{
var += 1;
}
&[var]
}
fn main() {
let _ = case1();
let _ = case2();
}
"#;
assert_no_errors(src);
}
16 changes: 16 additions & 0 deletions compiler/noirc_frontend/src/tests/aliases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,19 @@ fn allows_usage_of_type_alias_as_return_type() {
"#;
assert_no_errors(src);
}

#[test]
fn alias_in_let_pattern() {
let src = r#"
struct Foo<T> { x: T }
type Bar<U> = Foo<U>;
fn main() {
let Bar { x } = Foo { x: [0] };
// This is just to show the compiler knows this is an array.
let _: [Field; 1] = x;
}
"#;
assert_no_errors(src);
}
58 changes: 58 additions & 0 deletions compiler/noirc_frontend/src/tests/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,64 @@ fn errors_if_impl_trait_constraint_is_not_satisfied() {
assert_eq!(impl_trait, "Foo");
}

#[test]
// Regression test for https://github.com/noir-lang/noir/issues/6314
// Baz inherits from a single trait: Foo
fn regression_6314_single_inheritance() {
let src = r#"
trait Foo {
fn foo(self) -> Self;
}
trait Baz: Foo {}
impl<T> Baz for T where T: Foo {}
fn main() { }
"#;
assert_no_errors(src);
}

#[test]
// Regression test for https://github.com/noir-lang/noir/issues/6314
// Baz inherits from two traits: Foo and Bar
fn regression_6314_double_inheritance() {
let src = r#"
trait Foo {
fn foo(self) -> Self;
}
trait Bar {
fn bar(self) -> Self;
}
trait Baz: Foo + Bar {}
impl<T> Baz for T where T: Foo + Bar {}
fn baz<T>(x: T) -> T where T: Baz {
x.foo().bar()
}
impl Foo for Field {
fn foo(self) -> Self {
self + 1
}
}
impl Bar for Field {
fn bar(self) -> Self {
self + 2
}
}
fn main() {
assert(0.foo().bar() == baz(0));
}"#;

assert_no_errors(src);
}

#[test]
fn removes_assumed_parent_traits_after_function_ends() {
let src = r#"
Expand Down

0 comments on commit bc7d722

Please sign in to comment.