fix: catch unbound type variables during frontend compilation#8686
fix: catch unbound type variables during frontend compilation#8686
Conversation
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'Compilation Time'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.
| Benchmark suite | Current: 5ba8bd7 | Previous: 2a79d90 | Ratio |
|---|---|---|---|
private-kernel-reset |
8.3 s |
6.842 s |
1.21 |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @TomAFrench
The My idea of this change was that we'd have |
The main issue is that we also need to track how that type variable related to things in the source code to be able to give an error that's understandable. Essentially saying "Cannot deduce the type of generic parameter T of function That said, I'm still not sure tracking every type variable is needed. I think this error can only happen when generics aren't specified, and this can only happen in identifiers, constructors, and array/slice literals. |
|
@asterite you could store the source location in that type variable list. E.g. you could have an enumeration or similar which gets passed to the error message |
|
@jfecher I feel like the current implementation is correct so I'm a bit hesitant to try a different approach where I'm not sure it'll improve things. I'm just wondering if there's some code (some type variables) that aren't caught in this PR. If so, I can work on fixing those with this approach and, if that doesn't work, I can try the other approach. |
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.
| Benchmark suite | Current: fa40da3 | Previous: b09073a | Ratio |
|---|---|---|---|
test_report_zkpassport_noir-ecdsa_ |
126 s |
92 s |
1.37 |
test_report_zkpassport_noir_rsa_ |
2 s |
1 s |
2 |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @TomAFrench
|
This is ready for review again, and all external libraries in our control compile file. |
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'Execution Time'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.
| Benchmark suite | Current: 1edf754 | Previous: 9580a12 | Ratio |
|---|---|---|---|
rollup-merge |
0.004 s |
0.003 s |
1.33 |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @TomAFrench
TomAFrench
left a comment
There was a problem hiding this comment.
Looks like there's some test failures now. Not sure how many are flakes but the noir-contracts issue is real.
Right, it seems a bunch of types were introduced with a generic |
|
I think I got it to compile... I'll create a PR. |
For noir-lang/noir#8686 When returning `dep::aztec::context::call_interfaces::PrivateStaticCallInterface` (and others) from some functions, the generic `N` argument wasn't specified. This will soon cause a compile error (like in Rust). I assumed the `N` argument is the size of the return type (I tried with zero first and it said it didn't find a `Deserialize<0>` impl for some types, so I figured the size in fields of the type was needed), but let me know if that's not how it should be done. Given that `size_in_fields` is now used in a couple of places, I decided to move it to its own file/module.
For noir-lang/noir#8686 When returning `dep::aztec::context::call_interfaces::PrivateStaticCallInterface` (and others) from some functions, the generic `N` argument wasn't specified. This will soon cause a compile error (like in Rust). I assumed the `N` argument is the size of the return type (I tried with zero first and it said it didn't find a `Deserialize<0>` impl for some types, so I figured the size in fields of the type was needed), but let me know if that's not how it should be done. Given that `size_in_fields` is now used in a couple of places, I decided to move it to its own file/module.
|
This is ready for review again. |
Automated pull of nightly from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec. BEGIN_COMMIT_OVERRIDE fix(LSP): suggest generic type methods (noir-lang/noir#8948) fix: Fix if/match tracking in last uses pass (noir-lang/noir#8935) fix(ssa): Swap Brillig index shift and DIE in minimal pipeline (noir-lang/noir#8946) fix: when macro parse error happens, discard warnings; also preserve unquoted token locations (noir-lang/noir#8944) chore: disable noncritical workflow steps which fail on external prs (noir-lang/noir#8939) chore(test): Add `--minimal-ssa` to integration tests (noir-lang/noir#8938) fix(noirc_evaluator): U128 Binary::And simplification (noir-lang/noir#8940) chore: Improve access to data required to extract Noir (noir-lang/noir#8793) chore: bump external pinned commits (noir-lang/noir#8920) chore(fuzz): Compare print output on failed programs (noir-lang/noir#8921) chore(fuzz): Display nightly fuzz status badge (noir-lang/noir#8932) fix(fuzz): Consider values returned from Brillig to ACIR as dynamic (noir-lang/noir#8931) fix(fuzz): Fix env var name in fuzzing workflow (noir-lang/noir#8929) chore(fuzz): Add nightly fuzz workflow with 5 minute budget (noir-lang/noir#8925) fix(mem2reg): Keep last store for a used nested array (noir-lang/noir#8917) chore(fuzz): Increase the number of deterministic test cases (noir-lang/noir#8872) fix: Create calls to `apply` before function values are changed to fields in defunctionalize (noir-lang/noir#8916) chore: Add various regression tests for mutable references (noir-lang/noir#8915) fix: handle return_data in the interpreter SSA CLI (noir-lang/noir#8914) feat(fuzz): Generate references in the AST fuzzer (noir-lang/noir#8728) fix(fuzz): Use an inline block to circumvent negation with overflow (noir-lang/noir#8911) fix: Inline global arrays with functions at their call site (noir-lang/noir#8905) chore: Casting ACIR vs Brillig regression tests (noir-lang/noir#8903) fix(mem2reg): Keep last store for reference in array used only in an array get (noir-lang/noir#8877) fix: more SSA interpreter fixes (noir-lang/noir#8904) chore: Ban dynamic array indices with reference elements (noir-lang/noir#8888) chore(ssa_fuzzer): Add SSA validation to the SSA fuzzer (noir-lang/noir#8901) chore(fuzz): More metamorphic rules (noir-lang/noir#8857) fix: catch unbound type variables during frontend compilation (noir-lang/noir#8686) fix: preserve functions which are used in `array_set` instructions (noir-lang/noir#8891) fix: assorted SSA interpreter fixes (noir-lang/noir#8893) fix(ssa): Signed cast simplification (noir-lang/noir#8862) feat: simplify apply function cfg immediately (noir-lang/noir#8895) fix: do not hoist control dependent cast (noir-lang/noir#8886) fix(licm): Account for negative bounds when checking whether a loop executes (noir-lang/noir#8889) chore: Release Noir(1.0.0-beta.7) (noir-lang/noir#8520) chore: test noir-ecdsa library in CI (noir-lang/noir#8859) chore: Incorrect clippy warning blocking PRs (noir-lang/noir#8861) END_COMMIT_OVERRIDE --------- Co-authored-by: AztecBot <tech@aztecprotocol.com> Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
For noir-lang/noir#8686 When returning `dep::aztec::context::call_interfaces::PrivateStaticCallInterface` (and others) from some functions, the generic `N` argument wasn't specified. This will soon cause a compile error (like in Rust). I assumed the `N` argument is the size of the return type (I tried with zero first and it said it didn't find a `Deserialize<0>` impl for some types, so I figured the size in fields of the type was needed), but let me know if that's not how it should be done. Given that `size_in_fields` is now used in a couple of places, I decided to move it to its own file/module.
Automated pull of nightly from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec. BEGIN_COMMIT_OVERRIDE fix(LSP): suggest generic type methods (noir-lang/noir#8948) fix: Fix if/match tracking in last uses pass (noir-lang/noir#8935) fix(ssa): Swap Brillig index shift and DIE in minimal pipeline (noir-lang/noir#8946) fix: when macro parse error happens, discard warnings; also preserve unquoted token locations (noir-lang/noir#8944) chore: disable noncritical workflow steps which fail on external prs (noir-lang/noir#8939) chore(test): Add `--minimal-ssa` to integration tests (noir-lang/noir#8938) fix(noirc_evaluator): U128 Binary::And simplification (noir-lang/noir#8940) chore: Improve access to data required to extract Noir (noir-lang/noir#8793) chore: bump external pinned commits (noir-lang/noir#8920) chore(fuzz): Compare print output on failed programs (noir-lang/noir#8921) chore(fuzz): Display nightly fuzz status badge (noir-lang/noir#8932) fix(fuzz): Consider values returned from Brillig to ACIR as dynamic (noir-lang/noir#8931) fix(fuzz): Fix env var name in fuzzing workflow (noir-lang/noir#8929) chore(fuzz): Add nightly fuzz workflow with 5 minute budget (noir-lang/noir#8925) fix(mem2reg): Keep last store for a used nested array (noir-lang/noir#8917) chore(fuzz): Increase the number of deterministic test cases (noir-lang/noir#8872) fix: Create calls to `apply` before function values are changed to fields in defunctionalize (noir-lang/noir#8916) chore: Add various regression tests for mutable references (noir-lang/noir#8915) fix: handle return_data in the interpreter SSA CLI (noir-lang/noir#8914) feat(fuzz): Generate references in the AST fuzzer (noir-lang/noir#8728) fix(fuzz): Use an inline block to circumvent negation with overflow (noir-lang/noir#8911) fix: Inline global arrays with functions at their call site (noir-lang/noir#8905) chore: Casting ACIR vs Brillig regression tests (noir-lang/noir#8903) fix(mem2reg): Keep last store for reference in array used only in an array get (noir-lang/noir#8877) fix: more SSA interpreter fixes (noir-lang/noir#8904) chore: Ban dynamic array indices with reference elements (noir-lang/noir#8888) chore(ssa_fuzzer): Add SSA validation to the SSA fuzzer (noir-lang/noir#8901) chore(fuzz): More metamorphic rules (noir-lang/noir#8857) fix: catch unbound type variables during frontend compilation (noir-lang/noir#8686) fix: preserve functions which are used in `array_set` instructions (noir-lang/noir#8891) fix: assorted SSA interpreter fixes (noir-lang/noir#8893) fix(ssa): Signed cast simplification (noir-lang/noir#8862) feat: simplify apply function cfg immediately (noir-lang/noir#8895) fix: do not hoist control dependent cast (noir-lang/noir#8886) fix(licm): Account for negative bounds when checking whether a loop executes (noir-lang/noir#8889) chore: Release Noir(1.0.0-beta.7) (noir-lang/noir#8520) chore: test noir-ecdsa library in CI (noir-lang/noir#8859) chore: Incorrect clippy warning blocking PRs (noir-lang/noir#8861) END_COMMIT_OVERRIDE --------- Co-authored-by: AztecBot <tech@aztecprotocol.com> Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Description
Problem
Resolves #7889
Resolves #8464
Summary
I started implementing this a few times until I landed with the current implementation. At first I thought we'd need to track all type variables, but for example when you have
fn foo<T>() { ... }, thatTin that function will remain unbound. It's only when it's called that it will become bound. This is why we can't track all type variables.Then, I noticed that, maybe, the places where we need to track them are:
But let me know if this isn't right.
Then, many errors started to show up. The reason is that we'd previously error during monomorphization. That means that if there was such error in a function that wasn't reached from
main, that error never showed up. Now it does! And this is why tests will have a few more errors now. And, for example, there was a#[test]on top of a function were generics couldn't be deduced. That was previously only erroring when that test function was monomorphized. Now it always errors, which makes the test impossible to write, so I removed it.Finally, when type-checking
FunctionDefinition::as_typed_exprthe type variables aren't checked because they are later checked when the value is interpolated somewhere else. In reality I'm not sureas_typed_exprshould be usingtype_check_variable_with_bindings, so let me know if it should be done in a different way.Additional Context
I'm unsure about the name
RequiredTypeVariable, happy to rename it!Documentation
Check one:
PR Checklist
cargo fmton default settings.