Skip to content

CorePrep: `cpeRhsE Case{}` uses cpeBody for scrutinee, but Note [CorePrep invariants] suggests cpeApp

This is the grammar in Note [CorePrep invariants]:

Here is the syntax of the Core produced by CorePrep:

    Trivial expressions
       arg ::= lit |  var
              | arg ty  |  /\a. arg
              | truv co  |  /\c. arg  |  arg |> co

    Applications
       app ::= lit  |  var  |  app arg  |  app ty  | app co | app |> co

    Expressions
       body ::= app
              | let(rec) x = rhs in body     -- Boxed only
              | case app of pat -> body
              | /\a. body | /\c. body
              | body |> co

    Right hand sides (only place where value lambdas can occur)
       rhs ::= /\a.rhs  |  \x.rhs  |  body

(Side note: What is truv in truv co? I think it should be app co.)

This is the main case of cpeRhsE Case{}, the case that prep's Case expressions in GHC.CoreToStg.Prep:

cpeRhsE env (Case scrut bndr ty alts)
  = do { (floats, scrut') <- cpeBody env scrut
       ... Case scrut' ...

But it uses cpeBody, suggesting that a prep'd Case accepts a body non-terminal. Which is it? At the least I'd expect an assertion.

But realistically, I think our pipeline can in fact cope with entire bodys in the scrutinee, not just app (although that would feel cleaner to me).

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information