Potentially turn MachOp into a GADT?
MachOps are quite delicate since there is nothing tying the arity of the operation (not to mention its expected argument types) to its expression. Consequently, we have a variety of wildcard pattern matches in the C-- optimiser and NCG which mask incomplete matches which periodically blow-up (e.g. #18141 (closed)). It seems like we could easily make
MachOp a GADT which would encode the (at least) arity of the operation. I can think of a number of ways to slice this. For instance, we might have,
data MachOp (arity :: Nat) where MO_Add :: Width -> MachOp 2 MO_SF_Conv :: Width -> Width -> MachOp 1 -- ... type family OpArgs :: Nat -> Type type instance OpArgs 0 = () type instance OpArgs 1 = CmmExpr type instance OpArgs 2 = (CmmExpr, CmmExpr) data CmmExpr where CmmMachOp :: forall arity. MachOp arity -> OpArgs arity -> CmmExpr -- ...
This would allow us to eliminate a partial matches associated with arity (and slightly the representation size in some cases, since we the arguments are a product rather than a cons list).