-
Notifications
You must be signed in to change notification settings - Fork 18
Sub-expansion pass #195
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
Sub-expansion pass #195
Conversation
|
Nice!
What would be an example for a binding that can be removed that was not already in the domain of the generated substitution? |
In the previous implementation, I made it so that the case expressions generated from the subtype would also generate the binds as well if necessary. So take this example (as above): However, to make it simple, I would collect all the binds of all of the case expressions and apply it to all of them. So I would have I didn't like this approach, so I have changed it so that the case expressions actually carry the binds with them as well. This means I only filter at the end now to remove the subst ids (in the case above it would be x) |
…fted subst generation to own function
|
Should be complete now! Though will need the uncase PR (#191) to be merged first. |
|
This is looking good, for example I get ;; ../../../../specification/wasm-3.0/1.2-syntax.types.spectec
def $zsize(storagetype : storagetype) : nat
;; ../../../../specification/wasm-3.0/1.2-syntax.types.spectec
- def $zsize{numtype : numtype}((numtype : numtype <: storagetype)) = $size(numtype)
+ def $zsize(I32_storagetype) = $size(I32_numtype)
+ ;; ../../../../specification/wasm-3.0/1.2-syntax.types.spectec
+ def $zsize(I64_storagetype) = $size(I64_numtype)
+ ;; ../../../../specification/wasm-3.0/1.2-syntax.types.spectec
+ def $zsize(F32_storagetype) = $size(F32_numtype)
;; ../../../../specification/wasm-3.0/1.2-syntax.types.spectec
- def $zsize{vectype : vectype}((vectype : vectype <: storagetype)) = $vsize(vectype)
+ def $zsize(F64_storagetype) = $size(F64_numtype)
;; ../../../../specification/wasm-3.0/1.2-syntax.types.spectec
- def $zsize{packtype : packtype}((packtype : packtype <: storagetype)) = $psize(packtype)
+ def $zsize(V128_storagetype) = $vsize(V128_vectype)
+ ;; ../../../../specification/wasm-3.0/1.2-syntax.types.spectec
+ def $zsize(I8_storagetype) = $psize(I8_packtype)
+ ;; ../../../../specification/wasm-3.0/1.2-syntax.types.spectec
+ def $zsize(I16_storagetype) = $psize(I16_packtype)but with this is now partial… ah, but it seems this was already the case in the source, which has Is that just a case of a missing |
|
For |
That seems to be the case I would say.
I do not handle overlapping patterns, since it might not be necessary to remove them for some targets. I could remove them easily if necessary though |
At least the lean4 backend will need that. But that doesn’t mean you have to do that right away, I can also do it at some point. |
Rocq will also need it so will probably do it after this gets merged, either as part of this pass or a new pass. |
Actually Lean has |
| let rec collect_sube_exp e = | ||
| let c_func = collect_sube_exp in | ||
| match e.it with | ||
| (* Assumption - nested sub expressions do not exist. Must also be a varE. *) |
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.
You used the Iter module in #191, any reason to not use it here?
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.
No real reason, probably was trying to get a more functional approach instead of using Iter.
Also since its only traversing through exp I maybe thought it was overkill.
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.
Ah, good point. No issue, was just curious.
I wish we didn't have to duplicate the traversal logic in every pass, but 🤷🏻
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.
Yeah... I really wish there was an easier way to make a generic traversal pass that didn't involve side effects 😅 . I'll look into it more to see if something can be done
This pass expands the subtyping patterns that appear in the LHS of
function clauses and type family arguments.
It achieves this through the following steps:
possible in the subtype. If the specific case additionally carries
values, then we generate binds to add in the function scope.
the cartesian product in order to absolutely grab all the possible cases.
See $cvtop to see how this might be done.
and proceed to generate the clause/type instance.
For example, take the following types and function:
Would be transformed as such:
To give a slightly more involved example:
Would be transformed as such:
Currently it has a similar limitation as the sub pass: if you expand type families, then the evaluator (which the validator uses) cannot show that types are in fact equivalent.
Currently a draft pull request until the rework of middlend testing goes through.