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

errors using the latest beta #115

Open
mimoo opened this issue Mar 1, 2023 · 4 comments
Open

errors using the latest beta #115

mimoo opened this issue Mar 1, 2023 · 4 comments

Comments

@mimoo
Copy link
Contributor

mimoo commented Mar 1, 2023

Using the latest beta (4) I get the following errors:

warning: suffixes on a tuple index are invalid
   --> poseidon/src/sponge.rs:297:28
    |
297 |     #[derive(Debug, Clone, ocaml::ToValue, ocaml::FromValue, ocaml_gen::Struct)]
    |                            ^^^^^^^^^^^^^^ invalid suffix `usize`
    |
    = help: `usize` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
    = help: on proc macros, you'll want to use `syn::Index::from` or `proc_macro::Literal::*_unsuffixed` for code that will desugar to tuple field access
    = help: see issue #60210 <https://github.com/rust-lang/rust/issues/60210> for more information
    = note: this warning originates in the derive macro `ocaml::ToValue` (in Nightly builds, run with -Z macro-backtrace for more info)

this one seems to be internal to ocaml-rs? Not sure

I'm also now getting errors that looks like the bounds are not added by the deriver:

error[E0277]: the trait bound `CamlF: ToValue` is not satisfied
   --> poseidon/src/sponge.rs:297:28
    |
297 |     #[derive(Debug, Clone, ocaml::ToValue, ocaml::FromValue, ocaml_gen::Struct)]
    |                            ^^^^^^^^^^^^^^ the trait `ToValue` is not implemented for `CamlF`
    |
    = note: required for `&CamlF` to implement `ToValue`
note: required by a bound in `Value::store_field`
   --> /Users/david/.cargo/registry/src/github.com-1ecc6299db9ec823/ocaml-1.0.0-beta.5/src/value.rs:420:34
    |
420 |     pub unsafe fn store_field<V: ToValue>(&mut self, rt: &Runtime, i: Size, val: V) {
    |                                  ^^^^^^^ required by this bound in `Value::store_field`
    = note: this error originates in the derive macro `ocaml::ToValue` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `CamlF`
    |
298 |     pub struct CamlScalarChallenge<CamlF: ocaml::ToValue>(pub CamlF);
    |                                         ++++++++++++++++

the code it points to, that used to work:

    #[derive(Debug, Clone, ocaml::ToValue, ocaml::FromValue, ocaml_gen::Struct)]
    pub struct CamlScalarChallenge<CamlF>(pub CamlF);
@zshipko
Copy link
Owner

zshipko commented Mar 1, 2023

Thanks! The first issue is an easy fix (I just pushed a commit for that one), but the bounds issue is a little more complicated. The ToValue macro is a little stricter and doesn't add any bounds for you. I can look for some solutions on my side but in the meantime you can add the bounds yourself:

#[derive(Debug, Clone, ocaml::ToValue, ocaml::FromValue, ocaml_gen::Struct)]
pub struct CamlScalarChallenge<CamlF>(pub CamlF)
where 
  CamlF: ocaml::ToValue + ocaml::FromValue;

@mimoo
Copy link
Contributor Author

mimoo commented Mar 1, 2023

Yeah I wanted to avoid that if possible so I reverted back to latest stable. I'm wondering why it's a complicated issue to fix now :o (as it was successfully matching serde/debug/display/etc. behavior before)

@zshipko
Copy link
Owner

zshipko commented Mar 1, 2023

It's likely not too hard of problem to solve, but macros in Rust are hard to debug. I think I'll be able to get it to match the expected behavior but am pretty low on time at the moment!

@mimoo
Copy link
Contributor Author

mimoo commented Mar 13, 2023

I just implemented this for another project here: https://github.com/o1-labs/proof-systems/blob/mimoo/snarky2/kimchi/snarky-deriver/src/lib.rs#L509 if this can help.

Basically the strategy was to look at all the fields of the struct, collect their types in a hashset, and add the bounds on them.

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