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

Support generic traits #3471

Closed
Tracked by #2568
jfecher opened this issue Nov 10, 2023 · 1 comment · Fixed by #4000
Closed
Tracked by #2568

Support generic traits #3471

jfecher opened this issue Nov 10, 2023 · 1 comment · Fixed by #4000
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@jfecher
Copy link
Contributor

jfecher commented Nov 10, 2023

Problem

While generics on trait methods and trait impls on generic types are working, generics on traits directly are not supported yet.

Happy Case

The following should execute successfully:

trait Into<Result> {
    fn into(self) -> Result;
}

impl Into<u32> for Field {
    fn into(self) -> u32 {
        self as u32
    }
}

impl Into<u64> for Field {
    fn into(self) -> u64 {
        self as u64
    }
}

Alternatives Considered

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@jfecher jfecher added the enhancement New feature or request label Nov 10, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Nov 10, 2023
@sirasistant
Copy link
Contributor

sirasistant commented Jan 4, 2024

This would be especially useful to create a serialize trait:

trait Serialize<N> {
    fn serialize() -> [Field; N];
}

Which we have in many data structures

kevaundray pushed a commit to AztecProtocol/aztec-packages that referenced this issue Jan 4, 2024
Simple use of traits in `noir-protocol-circuits` and `aztec-nr` when
possible.

Missing: Serialize/Deserialize due to:
noir-lang/noir#3471

Renamed ::default() to ::empty(), since it better conveys meaning for
our use cases (open to discussion).
AztecBot pushed a commit to AztecProtocol/aztec-nr that referenced this issue Jan 7, 2024
Simple use of traits in `noir-protocol-circuits` and `aztec-nr` when
possible.

Missing: Serialize/Deserialize due to:
noir-lang/noir#3471

Renamed ::default() to ::empty(), since it better conveys meaning for
our use cases (open to discussion).
@Savio-Sou Savio-Sou mentioned this issue Jan 8, 2024
46 tasks
Maddiaa0 pushed a commit to AztecProtocol/aztec-packages that referenced this issue Jan 8, 2024
Simple use of traits in `noir-protocol-circuits` and `aztec-nr` when
possible.

Missing: Serialize/Deserialize due to:
noir-lang/noir#3471

Renamed ::default() to ::empty(), since it better conveys meaning for
our use cases (open to discussion).
@jfecher jfecher self-assigned this Jan 8, 2024
@kevaundray kevaundray added this to the 1.0 milestone Jan 15, 2024
github-merge-queue bot pushed a commit that referenced this issue Jan 16, 2024
# Description

## Problem\*

Resolves #3471
Resolves #3474

## Summary\*

Implements support for generics on the trait directly. E.g. `trait
Into<T> { ... }`

## Additional Context

The old `trait_generics` test has been renamed to `trait_impl_generics`
- I think this is more accurate. There is a new test in `trait_generics`
now which tests the generic traits added by this PR.

I've discovered two new bugs in writing this PR, which are commented in
the `trait_generics` test. I'll make issues for them now.

## Documentation\*

Check one:
- [ ] No documentation needed.
- [x] Documentation included in this PR.
- [ ] **[Exceptional Case]** 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.
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Jan 16, 2024
michaelelliot pushed a commit to Swoir/noir_rs that referenced this issue Feb 28, 2024
Simple use of traits in `noir-protocol-circuits` and `aztec-nr` when
possible.

Missing: Serialize/Deserialize due to:
noir-lang/noir#3471

Renamed ::default() to ::empty(), since it better conveys meaning for
our use cases (open to discussion).
superstar0402 added a commit to superstar0402/aztec-nr that referenced this issue Aug 16, 2024
Simple use of traits in `noir-protocol-circuits` and `aztec-nr` when
possible.

Missing: Serialize/Deserialize due to:
noir-lang/noir#3471

Renamed ::default() to ::empty(), since it better conveys meaning for
our use cases (open to discussion).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants