Skip to content

Be more explicit in generated case alternatives

This came up during the GHC call while discussing #13397 (closed) and I thought it would be good to record.

Often in the compiler we end up with a case analysis with a number of alternatives and a DEFAULT case in place of the remaining alternative,

data T = Con1 | Con2 | Con3

...
  case x of
    Con1 -> a
    Con2 -> b
    DEFAULT -> c

Arguably we should instead generate,

case x of
  Con1 -> a
  Con2 -> b
  Con3 -> c

instead as this may allow the code generator may be able to emit better code when it knows the finite bounds of the switch (e.g. using a jump table).

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