Certifier: add force-case-delay translation relation#7594
Certifier: add force-case-delay translation relation#7594ana-pantilie wants to merge 2 commits intomasterfrom
Conversation
88d9ba0 to
3d80c91
Compare
8238d2e to
c795e79
Compare
c795e79 to
86ec713
Compare
zliu41
left a comment
There was a problem hiding this comment.
Looks reasonable - could you share benchmarking results from cabal bench plutus-benchmark:certifier-bench?
|
|
||
| The Force-Case-Delay compiler optimization phase transforms terms of the form: `force (case scrut [\x1... -> delay term_1, ..., \x1... -> delay term_m])` into `case scrut [\x1... -> term_1, ..., \x1... -> term_m]`. Note that the delay must appear in all the branches of the case, under any number (including zero) of lambda abstractions. | ||
|
|
||
| An important remark is that this transformation is not semantics-preserving in general, but it is semantics preserving when the program is "well-formed". We do not have a formal definition of well-formedness, this is left as future work. For more information about the intuitive notion of well-formedness, see `Note [Applying force to delays in case branches]` in the Untyped Plutus Core implementation of the Force-Case-Delay optimization phase. |
There was a problem hiding this comment.
well-formedness
Is that not the same as "the UPLC program is typeable in TPLC"? Or similarly (though not equivalently), "evaluating the UPLC program does not lead to MachineError"? If you are talking about formalizing it in Agda, I don't think that's possible - I think it is undecidable.
There was a problem hiding this comment.
the UPLC program is typeable in TPLC
I think this is more restrictive than what we mean by "well-defined".
evaluating the UPLC program does not lead to MachineError
That's probably the best definition, and if I'm not mistaken it appears in the note.
If you are talking about formalizing it in Agda, I don't think that's possible - I think it is undecidable.
It might not be, but I'm not entirely convinced we can't find a formalization which, although not complete, is enough for our purposes.
There was a problem hiding this comment.
If you are talking about formalizing it in Agda, I don't think that's possible - I think it is undecidable.
It is certainly possible to formalize such a property, it's just undecidable in general. However, it (or a weaker property that suffices) may follow from typeability in TPLC and if it is preserved by the translation relations, we could prove it for what Ana describes.
There was a problem hiding this comment.
I imagine it's only possible to formalize it in very special cases, unless I'm missing something
There was a problem hiding this comment.
It's terms like
force
case (constr 0 [true, false])
[ \x y z -> delay x
]that make it unsound in general (note the amount of parameters in the branch does not line up), because it's optimised to
case (constr 0 [true, false])
[ \x y z -> x
]I don't expect you could ever obtain the first term from the optimiser when starting out with a TPLC-typable term. Or can we?
In any case, it's unclear what that property would be exactly.
|
|
||
| variable | ||
| n : ℕ | ||
| M N : n ⊢ |
There was a problem hiding this comment.
I think we use X ⊢ in most other places
There was a problem hiding this comment.
I know, but I don't like that notation. It gives me the impression that X can be any type, when it's just a natural number.
There was a problem hiding this comment.
X is a left-over from when terms used to be indexes by X : Set which was instantiated to nested Maybe. I'm in favor of n, and we should eventually change that in other places too.
There was a problem hiding this comment.
Or Γ, which is commonly used for context?
There was a problem hiding this comment.
That works too, although I'd associate it more with a typing context, rather than scoping.
|
|
||
| isForceCaseDelay? : MatchOrCE (ForceCaseDelay {n}) | ||
|
|
||
| {-# TERMINATING #-} |
There was a problem hiding this comment.
Do you know which recursive call upsets the termination checker?
|
@zliu41 The benchmarking results: The numbers are quite similar to the ones from your PR which improved the certifier performance. Note that we're running them on different machines, so it's possible my machine is faster and that explains why the numbers are lower. |
Could you comment out the other passes in |
Fixes https://github.com/IntersectMBO/plutus-private/issues/2053