gibbon-0.3: A compiler for operating on serialized data
Safe HaskellSafe-Inferred
LanguageHaskell2010

Gibbon.Passes.Unariser

Synopsis

Documentation

unariser :: Prog3 -> PassM Prog3 Source #

This pass gets ready for Lower by converting most uses of projection and tuple-construction into finer-grained bindings.

OUTPUT INVARIANTS:

  1. only flat tuples as function arguments (no nesting), all arguments immediately present, e.g. `AppE "f" (MkProd [x,y,z])` rather than `AppE "f" (MkProdE [x,MkProdE[y,z]])`
  2. The only MkProdE allowed outside of function operands is within return/tail position (of a function or If branch).
  3. Primitives are allowed to return tuples, but are let-bound (these will turn into LetPrimCall). The references to these tuples are all of the form `ProjE i (VarE v)` and they are then transformed to varrefs in lower.
Aditya Gupta, Oct 2021
NOTE: I am limiting flattening to only intermediate expressions. i.e. the tail value of main expression is a terminal expression and shouldn't be flattened. We can recursively propagate terminality based on expression type. This way all intermediate expressions will enjoy benefit from flattening, but we still retain same output for terminal expressions. We can have a separate function to recover after unarising but that won't have the env2/ddefs values and we won't be able to fuse it into unariser cases. But on the other hands, defining a separate function can eliminate missed cases, but there are only few, so combining recovering terminal expressions in unariser seems best.

unariserExp :: Bool -> DDefs Ty3 -> ProjStack -> Env2 Ty3 -> Exp3 -> PassM Exp3 Source #