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

chore: pull across macro ordering changes #10466

Merged
merged 7 commits into from
Dec 9, 2024
Merged

Conversation

TomAFrench
Copy link
Member

This PR pulls across the changes from noir-lang/noir#6326 so we can see how it affects the aztec-nr macros.

@Thunkar
Copy link
Contributor

Thunkar commented Dec 9, 2024

Seems like a simple reordering of annotations makes this work (waiting for CI). One thing that I found curious:

    #[event]
    #[derive(Serialize)]
    struct ContractInstanceDeployed {

^^^ that fails, while this works:

    #[derive(Serialize)]
    #[event]
    struct ContractInstanceDeployed {

Makes sense, since #[event] injects a trait that expects the attached struct to implement Serialize. I tried to do this inside the #[event] macro:

    let any = fresh_type_variable();
    let maybe_serialize_impl = typ.get_trait_impl(quote { protocol_types::traits::Serialize<$any> }.as_trait_constraint());

    assert(maybe_serialize_impl.is_some(), "A nice error message to convey #[derive(Serialize)] must come before #[event]");

And to my surprise, maybe_serialize_impl always has a value (even with the incorrect annotation order). How come?

maramihali and others added 2 commits December 9, 2024 09:53
#10460)

Skip computation of numerator and denominator of z_perm at indexes that
are not part of the active ranges, and refine the threshold in
commit_structured for `z_perm`. New benchmarks:
**Now: 5.6 s difference**
We still see a difference between committing to z_perm between an
ambient trace of 2^19 and 2^20, caused by the fact that the active
ranges complement are larger (i.e. the ranges in the trace blocks where
z_perm is constant) because the blocks themselves are larger. We 
make sure to at least avoid computing and committing to z_perm after the
final active wire index.
@TomAFrench
Copy link
Member Author

Ah excellent! Much easier than I feared.

@TomAFrench
Copy link
Member Author

Hmm, I'm not entirely sure why there would be an impl in that case. @jfecher can you shed light here?

@TomAFrench TomAFrench changed the base branch from master to sync-noir December 9, 2024 15:14
@TomAFrench TomAFrench merged commit 2445f7a into sync-noir Dec 9, 2024
9 checks passed
@TomAFrench TomAFrench deleted the tf/macro-ordering branch December 9, 2024 15:15
@jfecher
Copy link
Contributor

jfecher commented Dec 9, 2024

@Thunkar

#[derive_via(derive_serialize)]
trait Serialize<let N: u32> {}

comptime fn derive_serialize(s: StructDefinition) -> Quoted {
    let t = s.as_type();
    quote[impl Serialize<0> for $t {}]
}

#[find_serialize]
#[derive(Serialize)]
struct Foo {}

comptime fn find_serialize(s: StructDefinition) {
    let any = std::meta::typ::fresh_type_variable();

    let serialize = quote { Serialize<$any> }.as_trait_constraint();
    let serialize_impl = s.as_type().get_trait_impl(serialize);

    assert(serialize_impl.is_some(), "#[derive(Serialize)] must come before #[find_serialize]");
}

Errors as expected for me

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.

4 participants