Deftorel pass#206
Conversation
|
I’m trying to merge this into the lean4 branch, but trying to update the |
|
Just ran the tests locally again to make sure, it all seems fine to me. I haven't changed either of them, so thats very weird. |
|
Also, for visibility (I put this in #207 but not here). After some testing on the rocq output, it seems like some recursive functions turning into relations do not pass as it doesn't pass the strictly positive condition. Lean will likely exhibit a similar error on the function utf8. |
That function definition is in |
Fair enough, but did some more quick testing and it happens to most recursive functions (subst_typevar and subst_typeuse for example) |
|
Maybe we need to push harder to make them translate as functions. At least when the premises are on identical patterns like in and they are all booleans or otherwise, it should be possible to translate that as if-then-else, shouldn’t it? |
Yes, that was one of the things I was thinking of doing as well, for premises that are boolean conditions. I wanted a more general approach first though to see if it worked. In some functions by the way, you can also transform some of the if premises into let premises (look at growmem for example) and any iterpr with boolean conditions could be List.all |
|
With the new changes, the fallthrough premises no longer cause a (big) problem. Wasm 3.0 was compiled in Rocq (with some spec changes for partial funcs). |
|
Changed this to only do fallthrough whenever it spots an otherwise premise, instead of all the time. This is in line with what the actual semantics is supposed to be. Other than maybe fixing names and reordering premises, this should be good to start being reviewed. It is a pretty complicated one to review though. |
Yeah, I’m not sure if I can do a meaningful review :-/ |
Fair enough! I will probably just keep it as a draft until we make use of this pass in the mechanization backends. Will also try to make it more readable! |
661e6e4 to
e5d20ef
Compare
…he recursive functions themselves.
…that removes ones that have reference to the return expression.
…ng new traversal method
…xp params) into relations.
|
Just to understand this better: I'm a bit surprised that every function with premises is turned into a relation. That seems rather brittle, since a small source-level change to a definition might consist of adding a condition, but that would totally change the translation outcome. Naively, I would have expected that Boolean premises are fine for functions (as long as they don't involve free variables, which is already ruled out by the third condition). Is that because you want to translate Boolean expressions into something in prop? |
It is very restricting, I agree. However with boolean premises, the only way to translate it for ITPs would be to have if-then-else expressions. It should then be the case that the if-then-else-introduction pass should resolve this issue. But if it cannot, then we don't exactly have a good way to convert these functions into executable functions in ITPs. Hopefully if we keep improving the ITE pass to cover all cases for boolean premises then it should never hit the case for functions that only have boolean premises. But it is still good to have that safety net in deftorel to ensure we can always compile in the mechanization side. I would be fine with reporting some warning if this does happen though, as these functions are supposed to stay as functions. (Also, I forgot a condition: if the function is recursive then it does get turned into a relation always as we cannot prove termination automatically in general! Will edit this) |
|
I see, makes sense! |
This pull request is made to introduce the pass "deftorel". This pass does as the name suggests: convert specific function definitions to relations.
To first explain what this pass exactly does, we must first understand what specific functions we are converting to inductive relation:
If a function fulfills any of these criterias, then it get transformed.
The transformation is done as such:
The only other portion left is transforming the function calls. This portion is much trickier as we need to ensure the scope of the function call is preserved (i.e. when it is in an iterE). So the solution is as follows for each function call:
To give a small example illustrating this, say we have:
This gets transformed into:
Notice how the new relational premises have preserved the iteration, and the if premise now has new iteration ids!
As you can probably see, this is a very complex pass.
Old Example:
to