plutus icon indicating copy to clipboard operation
plutus copied to clipboard

UPLC case-of-case improvements

Open effectfully opened this issue 1 year ago • 5 comments

After #5960 we have some left-overs:

  1. this example is incorrect and needs to be updated:
{- | A special case of case-of-case optimisation: transforms

@
    case ((force ifThenElse) b (constr t) (constr f)) alts
@

into

@
    force ifThenElse b (case (constr t) alts) (case (constr f) alts)
@

This is always an improvement.
-}

Plus, there's no explanation of what we do and why we do it.

  1. the PR added generation of extra force-delay pairs, why don't we see them in the existing golden tests? Those that were affected by the original PR introducing case-of-case? UPD: @ana-pantilie figured it out: it's because we know how case-of-case in PIR and so no suitable expression survives compilation of PIR to be transformed at the UPLC level. Thanks Ana!

  2. should we avoid generating force-delay pairs when branches are pure?

  3. what about PIR, do we have the same issue there that was fixed for UPLC?

  4. UPLC case-of-case is exponential in the same way as PIR case-of-case (see this and below).

effectfully avatar May 08 '24 23:05 effectfully

Plus, there's no explanation of what we do and why we do it.

The name of the transformation is self-explanatory: this is basically case-of-case transformation. The reason it is useful is because it can trigger case-of-known-constructor transformation on case (constr t) and case (constr f).

zliu41 avatar May 09 '24 17:05 zliu41

should we avoid generating force-delay pairs when branches are pure?

Yes, I think we already do that when compiling cases. Forces and delays are only added if at least one of the branches isn't pure.

zliu41 avatar May 09 '24 17:05 zliu41

The name of the transformation is self-explanatory: this is basically case-of-case transformation. The reason it is useful is because it can trigger case-of-known-constructor transformation on case (constr t) and case (constr f).

The name is self-explanatory, but the force-delay caveat was so obscure that if went through the review process without anybody noticing. This must be documented.

Yes, I think we already do that when compiling cases.

In the UPLC case-of-case transformation? Where?

effectfully avatar May 09 '24 20:05 effectfully

In the UPLC case-of-case transformation? Where?

I think it's in the compilation of Case in GHC Core into PIR, but it's the same idea.

zliu41 avatar May 09 '24 23:05 zliu41

Ah, I misunderstood, I thought you were saying it was already implemented for UPLC case-of-case.

effectfully avatar May 10 '24 00:05 effectfully