-
Notifications
You must be signed in to change notification settings - Fork 108
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
[ocaml-gen] issue with re-declaring custom types #172
Comments
@imeckler proposed to maybe track the different declaration of a custom type by using the different concrete types used. I think this might be a good idea. For this to work, I think we'd only have to return a different value for decl_module!(w, env, "FieldVectors", {
decl_module!(w, env, "Fp", {
- decl_type!(w, env, CamlPointer<T1> => "t");
+ decl_type!(w, env, CamlPointer<Vec<Fp>> => "t");
decl_type_alias!(w, env, "elt" => CamlFp); but I might be missing some edge-cases... What if several modules want to use the same more-generic |
Actually, it's a bigger problem than what I originally thought. If you have a function that takes different arguments that are all essentially the same generic custom type: fn thing(g1: CamlPointer<T1>, g2: Camlpointer<T2>, g3: CamlPointer<T3>) The current solution will produce wrong bindings: all arguments will be of the type of the latest instance of decl_type!(w, env, CamlPointer<T1> => "t"); Imagine that it is within the module external thing : T1.t -> T1.t -> T1.t -> unit = "thing" This will likely not work. For example, the type What to do?Solution 1: Prevent re-declaring custom typesThe first solution now is to backtrack and prevent multiple usage of Solution 2: Distinguish the same custom types when it is instantiated with different concrete parametersGoing with @imeckler 's idea, maybe instead of declaring custom types like so: decl_type!(w, env, CamlPointer<T1> => "t"); where decl_type!(w, env, CamlPointer<SomeConcreteType> => "t"); or even like so: decl_type!(w, env, CamlPointer<SomeConcreteType<T1>> => "t"); Even so, it is not a perfect solution. You might have situation where you want to split a non-generic custom type, or a generic custom type with the same concrete type (so really the same type), in different types on the OCaml side. I would argue that if you really want to do this, this distinction should also exist in Rust via wrapper types or something. In the rest of this post I'll talk about solution 2. Implementing solution 2To make solution 2 work, we'd need to return a different What's unique_id?It's a unique id derived from the filename and line of code where a struct is defined. This means that a generic struct will always have the same It is used in two places:
The change to unique_idA custom type needs to return a CamlPointer<SomeType<This>> and CamlPointer<SomeType<AndThat>> two considerations:
This won't workActually, this won't work, because when we generate that code (in the So instead... we might want to just generate a BacktrackingWait. This is something that we might actually want to distinguish in Rust as well. Damn it this sounds like a fine solution. |
re-reading this, I'm not convinced that it won't work... working on this in https://github.com/o1-labs/proof-systems/tree/mimoo/ocaml_custom |
OK so trying to find a solution, I hit one dead end that's also not really a dead end but hear me out. If I want to distinguish different instantiations of the same generic custom type in Rust, I can either:
So I propose that we go with the previous solution I proposed, which is to just not have this feature and force people to write distinct types in Rust. If someone is interested to take a stab at it, we'd need some tests to make sure that solution 2 (which seems to be the right solution to pursue) doesn't have weird edge-cases. |
Stale issue message |
moved to o1-labs/ocaml-gen#5 |
Sometimes in OCaml, we can use the same custom type in different context.
For example, we use the
CamlPointer
custom type in different modules:converts to
Redeclaring a type is usually not allowed in ocaml-gen, but it is permitted for custom types. The problem is that, the next time a type or a function from another module uses the
CamlPointer
type, it will be renamed asFieldVectors.Fq.t
which is the last place it was declared. While not technically true, it is not great.Ideally, we would want the generation code to panic when this happens.
It is not clear to me that there's a solution though, because I don't see how to differentiate a legitimate use-case from a non-legitimate use-case.
We could, technically, track all the declarations of the same custom type and give them a different nickname, but I don't think this it is less error-prone.
The text was updated successfully, but these errors were encountered: