-
Notifications
You must be signed in to change notification settings - Fork 0
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
[DMS-48] motoko-san: ADT encoding for tuples #28
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, but I am pondering about perspectives and alternative implementation of "tuple arity analysis":
So now you have spread everywhere ctxt
and mostly into tr_typ
function. Later (DMS-52) we will need also gather all instances of tuple type e.g. collect { Tup2[Int, Bool], Tup1[Int] }
to add field: tup$2$int$bool; field tup$1$int;
into prelude. So I think we can reuse you changes e.g. change IntSet
into str Set.t
.
(Indeed, we need to support arrays of tuples.)
However I am thinking can we decouple this somehow via using visitor pattern and traverse.ml
? Namely, make a function that visit all expressions and types seeking Tuples and gather all instantiations into set. Then via this set we can generate necessary prelude piece.
WDYT?
b53c6c0
to
c4e9eb0
Compare
Yes, that's the plan, except I think we'll need a
It's not enough to collect that
If we wanted to decouple, that'd be a reasonable solution, but I think coupling makes sense here. The principle I used in
When we emit If we decouple computing |
Yes, of course you're right.
Yeah, I agree that it makes sense to keep things sync. However I don't see here any corner case: we modify Also I have thought that probably decoupled version could be easier reused for other types encoded as polymorphic domain/adt e.g. Synchronization between prelude and unit translation will be ensured by invariant that type of any subexpression should be visited and presented in the type collection. Does it make sense? I am not insisting, just trying to find best design to avoid refactoring work in future. |
Alright, so just for the sake of a comparison, I implemented a separate traversal in bd74790. An interesting discovery is that it generates more declarations than required. I guess it happens because in Motoko, function arguments are packed in tuples, whereas in Viper we use multi-argument functions. Based on this I am now more confident in proceeding with the current solution, i.e. doing translation and collecting tuple arities in one integrated pass. It is more precise this way. |
c4e9eb0
to
1cd0906
Compare
Okay, then let's stay with current solution. |
1cd0906
to
d4f38d7
Compare
The new encoding is more suitable for storing tuple in arrays, which will be implemented in a follow-up patch.