Skip to content

fix!: better error message when cannot infer generic numeric type #7843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

asterite
Copy link
Collaborator

@asterite asterite commented Mar 28, 2025

Blocked on noir-bignum getting a new release, then updating dependencies to use this new release.

Blocked on noir-bignum dependencies (and Aztec-Packages, I think) updating to bignum 0.7.0.

Description

Problem

Resolves #7617

Summary

Now this code:

pub fn foo<let N: u32>() -> BoundedVec<Field, N> {
    BoundedVec::new()
}

fn main() {
    let _ = foo();
}

Gives this error:

error: Type annotation needed
  ┌─ src/main.nr:6:13
  │
6 │     let _ = foo();
  │             --- Could not determine the value of the generic argument `N` declared on the function `foo`

I think it's fine that the error shows up there because, for example, one can specify the type of the let variable to fix this (the issue suggested showing the error on BoundedVec::new() instead).

This PR improves a bit how unbound numeric generics are shown in inlay hints.

Before:

image

After:

image

Additional Context

I know there's #7889 but this also solves the issue of default_type being wrong for Numeric, and also the fix for #7889 will be a bit different.

Also marked as a breaking change because previously unused numeric generics didn't trigger the error if they were completely unused.

Documentation

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 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: bf0834e Previous: 4ee2d12 Ratio
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_rollup-lib 223 s 179 s 1.25

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

@asterite asterite changed the title fix: better error message when cannot infer generic numeric type fix!: better error message when cannot infer generic numeric type Mar 28, 2025
@asterite
Copy link
Collaborator Author

It seems we'd need to merge #6388 first.

asterite added 5 commits April 2, 2025 17:07
…ic-type' of github.com:noir-lang/noir into ab/better-error-message-when-cannot-infer-generic-numeric-type
@asterite asterite added the Blocked PR is blocked on an issue label Apr 3, 2025
github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Apr 3, 2025
…pl (#13283)

This was discussed a bit over slack, but here's some context.

In Rust this gives an error:

```rust
pub struct Foo<T> {
    x: T,
}

impl<T> Foo<T> {
    fn one(x: T) {
        Bar::two(x); // Cannot infer the value of const parameter U
    }
}

struct Bar<T, const U: usize> {
    x: T,
}

impl<T, const U: usize> Bar<T, U> {
    fn two(x: T) -> Foo<T> {
        Foo { x }
    }
}

fn main() {
    Foo::<i32>::one(1);
}
```

In the call `Bar::two` Rust needs to know what is the value of `U`. It
can be solved by doing `Bar::<T, 1234>::two(x)` or using any numeric
value... because the numeric value isn't used in that impl function...
which probably means that it doesn't need to "belong" to `Bar`.

In this [Noir PR](noir-lang/noir#7843) gets
merged that's what will happen. We have a similar case in this codebase
where `SharedMutableValues` has two methods:
- `unpack_value_change`: doesn't refer to `INITIAL_DELAY`
- `unpack_delay_change`: doesn't refer to `T`

So, this PR moves those two methods outside of the impl, only specifying
the generics that are needed.
github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Apr 3, 2025
…pl (#13283)

This was discussed a bit over slack, but here's some context.

In Rust this gives an error:

```rust
pub struct Foo<T> {
    x: T,
}

impl<T> Foo<T> {
    fn one(x: T) {
        Bar::two(x); // Cannot infer the value of const parameter U
    }
}

struct Bar<T, const U: usize> {
    x: T,
}

impl<T, const U: usize> Bar<T, U> {
    fn two(x: T) -> Foo<T> {
        Foo { x }
    }
}

fn main() {
    Foo::<i32>::one(1);
}
```

In the call `Bar::two` Rust needs to know what is the value of `U`. It
can be solved by doing `Bar::<T, 1234>::two(x)` or using any numeric
value... because the numeric value isn't used in that impl function...
which probably means that it doesn't need to "belong" to `Bar`.

In this [Noir PR](noir-lang/noir#7843) gets
merged that's what will happen. We have a similar case in this codebase
where `SharedMutableValues` has two methods:
- `unpack_value_change`: doesn't refer to `INITIAL_DELAY`
- `unpack_delay_change`: doesn't refer to `T`

So, this PR moves those two methods outside of the impl, only specifying
the generics that are needed.
AztecBot pushed a commit to AztecProtocol/aztec-nr that referenced this pull request Apr 4, 2025
…pl (#13283)

This was discussed a bit over slack, but here's some context.

In Rust this gives an error:

```rust
pub struct Foo<T> {
    x: T,
}

impl<T> Foo<T> {
    fn one(x: T) {
        Bar::two(x); // Cannot infer the value of const parameter U
    }
}

struct Bar<T, const U: usize> {
    x: T,
}

impl<T, const U: usize> Bar<T, U> {
    fn two(x: T) -> Foo<T> {
        Foo { x }
    }
}

fn main() {
    Foo::<i32>::one(1);
}
```

In the call `Bar::two` Rust needs to know what is the value of `U`. It
can be solved by doing `Bar::<T, 1234>::two(x)` or using any numeric
value... because the numeric value isn't used in that impl function...
which probably means that it doesn't need to "belong" to `Bar`.

In this [Noir PR](noir-lang/noir#7843) gets
merged that's what will happen. We have a similar case in this codebase
where `SharedMutableValues` has two methods:
- `unpack_value_change`: doesn't refer to `INITIAL_DELAY`
- `unpack_delay_change`: doesn't refer to `T`

So, this PR moves those two methods outside of the impl, only specifying
the generics that are needed.
@asterite asterite added the Blocked PR is blocked on an issue label Apr 7, 2025
@asterite
Copy link
Collaborator Author

Update:

I think the path forward would be:

  1. Merge the above two PRs
  2. Release a new version of bignum
  3. Update noir_bigcurve, noir_rsa, noir-jwt and noir_rsa to use the latest version of bignum, and release new versions

Then this PR can be merged.

github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request May 13, 2025
…4277)

Towards noir-lang/noir#7843

The added zeroes happen in test so it should be harmless. The zero is
for the `INITIAL_DELAY` which is likely unused in tests (otherwise it
would have failed to compile when needing that value).
github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request May 13, 2025
…4277)

Towards noir-lang/noir#7843

The added zeroes happen in test so it should be harmless. The zero is
for the `INITIAL_DELAY` which is likely unused in tests (otherwise it
would have failed to compile when needing that value).
@asterite
Copy link
Collaborator Author

@TomAFrench I'll also merge this PR if it's okay with you. The libraries that fail to compile with this change are noir-jwt and the two noir-rsa.

@TomAFrench
Copy link
Member

LGTM

@TomAFrench TomAFrench enabled auto-merge May 21, 2025 18:20
@TomAFrench TomAFrench added this pull request to the merge queue May 21, 2025
Merged via the queue into master with commit 72ce94b May 21, 2025
116 of 118 checks passed
@TomAFrench TomAFrench deleted the ab/better-error-message-when-cannot-infer-generic-numeric-type branch May 21, 2025 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocked PR is blocked on an issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unclear error when calling BoundedVec::new()
3 participants