Skip to content
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

fix(frontend): Call trait method with mut self from generic definition #5041

Merged
merged 63 commits into from
May 21, 2024

Conversation

vezenovm
Copy link
Contributor

@vezenovm vezenovm commented May 16, 2024

Description

Problem*

Resolves

Not sure if there is another issue for this I will have to look again, but I found this bug when trying to implement #4514

Summary*

When type checking a MethodCall from the HIR now we also add a mutable reference to the object type when we have a HirMethodReference::TraitMethodId. We were previously only doing this for a HirMethodReference::FuncId.

For example that meant this program would fail with the following errors laid out in the comments:

fn hash_simple_array<H>(input: [Field; 2]) -> Field where H: Hasher + Default {
    // Check that we can a trait method to instead a trait implementation
    let mut hasher: H = H::default();
    // Regression that the object is converted to a mutable reference type `&mut _`.
    // Otherwise will see `Expected type &mut _, found type H`.
    // Then we need to make sure to also auto dereference later in the type checking process
    // when searching for a matching impl or else we will get `No matching impl found for `&mut H: Hasher`
    hasher.write(input[0]);
    hasher.write(input[1]);
    hasher.finish()
}

I also had to add auto dereferencing when verifying the trait constraints later inside of type_check_func. So first we add a mutable reference to the method call's object type to avoid a mismatched type error, and then we later dereference it to find the appropriate trait implementation.

Additional Context

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.

jfecher and others added 27 commits November 21, 2023 15:26
* master: (120 commits)
  feat: allow passing custom foreign call handlers when creating proofs in NoirJS (#3764)
  fix: add missing assertion to test (#3765)
  chore: re-export the items needed for the lsp from the fm crate instead of importing codespan_reporting (#3757)
  chore: remove special casing for `pedersen_hash` black box function (#3744)
  chore: remove extraneous dbg statement (#3761)
  chore: fix un-needed fully qualified path (#3755)
  feat: aztec-packages (#3754)
  feat: allow underscores in integer literals (#3746)
  fix: deserialize odd length hex literals (#3747)
  feat: optimize out unnecessary truncation instructions (#3717)
  chore: use `tsx` instead of `ts-node` for `noir_js` (#3750)
  chore(ci): fail `tests-end` job if any dependants failed (#3737)
  chore: allow common ascii punctuation in attributes (#3733)
  chore: fix broken onboarding link in README (#3732)
  feat: Dockerfile to test cargo and JS packages (#3684)
  feat(lsp): add goto definition for locals (#3705)
  feat: docs landing page with a playground (#3667)
  fix: `try_unify` no longer binds types on failure (#3697)
  fix: parse negative integer literals (#3698)
  fix: unsigned integers cannot be negated (#3688)
  ...
@vezenovm vezenovm marked this pull request as ready for review May 16, 2024 22:43
@vezenovm vezenovm dismissed michaeljklein’s stale review May 21, 2024 17:35

Comments were resolved but was not approved again

Base automatically changed from jf/turbofish to master May 21, 2024 17:41
@vezenovm vezenovm enabled auto-merge May 21, 2024 17:46
@vezenovm vezenovm added this pull request to the merge queue May 21, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 21, 2024
@vezenovm vezenovm added this pull request to the merge queue May 21, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 21, 2024
@vezenovm vezenovm added this pull request to the merge queue May 21, 2024
@vezenovm vezenovm removed this pull request from the merge queue due to a manual request May 21, 2024
@vezenovm vezenovm enabled auto-merge May 21, 2024 17:58
@vezenovm vezenovm added this pull request to the merge queue May 21, 2024
Merged via the queue into master with commit 89846cf May 21, 2024
41 checks passed
@vezenovm vezenovm deleted the mv/trait-method-reference branch May 21, 2024 18:40
AztecBot added a commit to AztecProtocol/aztec-packages that referenced this pull request May 21, 2024
…ic definition (noir-lang/noir#5041)

feat: Implement turbofish operator (noir-lang/noir#3542)
feat: add `as_witness` builtin function in order to constrain a witness to be equal to a variable  (noir-lang/noir#4641)
chore(experimental): Elaborate impls & non-trait impls (noir-lang/noir#5007)
feat: add native rust implementation of schnorr signature verification (noir-lang/noir#5053)
chore: Release Noir(0.30.0) (noir-lang/noir#4981)
github-merge-queue bot pushed a commit that referenced this pull request May 21, 2024
# Description

## Problem\*

Resolves #4514 

## Summary\*

This updates `eddsa_verify_with_hasher` to have the following signature
now that we support the turbofish operator:
```rust
pub fn eddsa_verify_with_hasher<H>(
    pub_key_x: Field,
    pub_key_y: Field,
    signature_s: Field,
    signature_r8_x: Field,
    signature_r8_y: Field,
    message: Field
) -> bool 
where H: Hasher + Default {
  [function body ...]
}
``` 
This re-work was only possible with further bug fixes from
#5049 and
#5041. The original turbofish PR
can be found here (#3542).

## Additional Context

This PR can most likely be merged into its parent #5049 but I just made
this separate PR to separate the bug fix and the stdlib library breaking
change.

## Documentation\*

Check one:
- [ ] No documentation needed.
- [x] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.

---------

Co-authored-by: Jake Fecher <jake@aztecprotocol.com>
Co-authored-by: Jake Fecher <jfecher11@gmail.com>
Co-authored-by: Tom French <tom@tomfren.ch>
TomAFrench added a commit to AztecProtocol/aztec-packages that referenced this pull request May 21, 2024
Automated pull of development from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix(frontend): Call trait method with mut self from generic definition
(noir-lang/noir#5041)
feat: Implement turbofish operator
(noir-lang/noir#3542)
feat: add `as_witness` builtin function in order to constrain a witness
to be equal to a variable (noir-lang/noir#4641)
chore(experimental): Elaborate impls & non-trait impls
(noir-lang/noir#5007)
feat: add native rust implementation of schnorr signature verification
(noir-lang/noir#5053)
chore: Release Noir(0.30.0)
(noir-lang/noir#4981)
END_COMMIT_OVERRIDE

---------

Co-authored-by: TomAFrench <tom@tomfren.ch>
AztecBot added a commit that referenced this pull request May 21, 2024
Automated pull of development from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix(frontend): Call trait method with mut self from generic definition
(#5041)
feat: Implement turbofish operator
(#3542)
feat: add `as_witness` builtin function in order to constrain a witness
to be equal to a variable (#4641)
chore(experimental): Elaborate impls & non-trait impls
(#5007)
feat: add native rust implementation of schnorr signature verification
(#5053)
chore: Release Noir(0.30.0)
(#4981)
END_COMMIT_OVERRIDE

---------

Co-authored-by: TomAFrench <tom@tomfren.ch>
github-merge-queue bot pushed a commit that referenced this pull request May 23, 2024
# Description

## Problem\*

Resolves <!-- Link to GitHub Issue -->

## Summary\*

Moving #3542,
#5041, and
#5087 to the elaborator

## Additional Context



## 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](https://prettier.io/)
and/or `cargo fmt` on default settings.

---------

Co-authored-by: jfecher <jake@aztecprotocol.com>
github-merge-queue bot pushed a commit that referenced this pull request May 28, 2024
…rait methods (#5108)

# Description

## Problem\*

Resolves the single "Duplicate definitions of <generic> found" error.

## Summary\*

Since `resolve_trait_function` already calls `add_generics` indirectly
via `define_function_meta`, we were adding generics on trait methods
twice before. I've removed the first of the two to fix this.

## Additional Context

After this the only errors that remain are the 5 on these lines of the
stdlib:
https://github.com/noir-lang/noir/blob/master/noir_stdlib/src/eddsa.nr#L49-L53.
I believe these are the result of something from the turbofish changes
being missed (likely #5041) since
they were recently modified from
#5050.

## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants