-
Notifications
You must be signed in to change notification settings - Fork 15
Type family removal pass #186
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
base: main
Are you sure you want to change the base?
Conversation
…roved equality check through type alias reduction. Added some more cases for conversion checks. Made a wrapper function for the new type family constructors to aid validation.
…ons after traversal, making it possible to not write specific cases for conversions. Removed boolean parameter indicating that it is a match expression.
… arguments. Some small changes also done to make wasm 3.0 validate.
…one before applying conversions. Fixed an issue with getting the real type of CaseE and also added some more cases to get_real_typ_from_exp.
…ptional removal operation. Removed function that makes the family constructor since not necessary.
…tion functions so that they don't get conversions applied to them.
…se number of the type family instead of mangling all of the bind names.
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.
This looks good!
Yes, the validation failure is due to a limitation in the current definition of expression equivalence, which simply reduces both terms (including contained types) and the compares syntactically. But syntactic equivalence is not enough when considering type names that are not just alias names. (Two possible solutions: either we define a separate equivalence relation on expressions (feels a bit redundant), or we eliminate the somewhat odd separation between types and type definitions, such that type reduction goes all the way (may be annoying in practice, due to much larger types in IL error messages, unless significant work is done to track abbreviations as well).)
So for now I suggest we just tweak the definitions of Pnn and Inn.
That sounds reasonable to me! It is also easier for the mechanization backend when these syntactical equivalences don't exist (i.e. Pnn and Packtype). Should I change it in this branch? |
Co-authored-by: Andreas Rossberg <rossberg@mpi-sws.org>
27776de
to
730503d
Compare
Yes, feel free to fix here! (Side note: With GitHub, please never force-push to a branch under review. That destroys the review history and makes the reviewer's life much harder.) |
My bad! I realized that a little too late when I saw my comments disappearing! Will not do that again. |
It seems like the small change to Inn breaks the interpreter tests, not exactly sure why. |
I'm not sure either. I suspect this is due to some special handling of types like Inn in pattern position. @f52985, can you please triage to somebody who can have a look? |
This transformation transforms type families into a single variant user-defined
type.
This is achieved through the following steps:
user-defined type, using the binds as their respective dependent type arguments.
were instances before, encoding the pattern matching as equality premises.
sub type.
explicit through the use of the constructor and projections made before. This is achieved
by inspecting the expression and generating its "real type", and match that to the type
given by elaboration.
As an example,
given the following type family:
where p is a parameter type, a, b and c are arguments that match their respective parameter type,
v is a bind that appears in a, b, and c with type t.
This is transformed into:
An example of the projection function is as follows:
Names were specifically chosen here for simplicity.
An interesting case is for iteration types.
When a real type is an iter type of a sub type and it is expected for it to be an iter type of the type family, then special handling is required.
The specific expression that has this mismatch will become an iteration with that expression specifically being the entity that is being iterated on. With the new variable made, that specific conversion is then applied.
For example, take an expression e with real type
t_alias(a)*
and expected typefoo(a)*
. It is transformed into:Limitations to this pass are as follows:
comparisons, since they only allow expressions.
Things to do later/watch out for:
This pass also introduces a quick fix to totalize which just ensures that the extra clause added does indeed add the bind for type parameters.
For Wasm 2.0 to pass (and also 3.0), this validation error needs to be fixed:
This is due to the sub typing expressions, when checking for equivalence in typing, does not account for equivalence in the sub types. This can be either be fixed in validation or just making
Pnn
an alias ofpacktype
. Similar issue with 3.0, but withInn
andaddrtype
.