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

Serialization Derive Macro does not support Tuples #125

Closed
gakonst opened this issue Mar 4, 2020 · 4 comments
Closed

Serialization Derive Macro does not support Tuples #125

gakonst opened this issue Mar 4, 2020 · 4 comments

Comments

@gakonst
Copy link
Contributor

gakonst commented Mar 4, 2020

As title, ref #104. Example:

#[derive(Debug, CanonicalSerialize)]
struct TestCase<E: PairingEngine> {
    a: (E::G1Affine, E::G1Affine), // this makes the macro fail
    b: E::G1Affine, // this works
    c: Vec<E::G2Affine>, // this works
}

It'd be nice if it would just serialize a.0 followed by a.1

Sidenote: In order to use the macro, I had to explicitly import algebra-core to my package. It'd be nice if the macro were usable via importing just algebra as well.

i.e. go from:

zexe_algebra = { package = "algebra", git = "https://github.com/scipr-lab/zexe", version = "0.1.0" }
zexe_algebra_core_derive = { package = "algebra-core-derive", git = "https://github.com/scipr-lab/zexe", version = "0.1.0" }
algebra_core = { package = "algebra-core", git = "https://github.com/scipr-lab/zexe", version = "0.1.0" }

to
zexe_algebra = { package = "algebra", git = "https://github.com/scipr-lab/zexe", version = "0.1.0", features = ["derive"] }

cc @paberr

@paberr
Copy link
Contributor

paberr commented Mar 4, 2020

I'll take a look into it. :)

@paberr
Copy link
Contributor

paberr commented Mar 4, 2020

I opened a PR with the functionality you were looking for.
Ok, I just noticed that re-exporting it in both algebra and algebra-core results in problems when compiling the tests.

@paberr
Copy link
Contributor

paberr commented Mar 4, 2020

So, the problem with not having algebra-core as a dependency is:

  • The derive macro generates code that refers to types like ::algebra_core::SerializationError.
  • Since algebra also re-exports these types, I tried choosing between algebra_core and algebra using a feature flag at compile time.
  • However, since feature flags are active within the whole workspace/project, the following will happen:
    1. Let's suppose you write your own crate that only depends on algebra and gm17.
    2. You want to use the derive macro using algebra only. Then, the feature will be set for the whole workspace. The derive macros will thus use ::algebra::<...> as a path.
    3. However, gm17/groth16 only depend on algebra-core. This will cause gm17 to not compile anymore.

To avoid this mess, I guess the best way is to still require algebra-core as a dependency.
You don't need to explicitly depend on the algebra-core-derive anymore, but can use a feature flag in algebra-core.

If someone has another idea how to realise this, I'm open for suggestions.

@gakonst
Copy link
Contributor Author

gakonst commented Mar 9, 2020

Closing, thank you so much @paberr !

@gakonst gakonst closed this as completed Mar 9, 2020
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

No branches or pull requests

2 participants