HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

datadata SwitchTargets

A value of type SwitchTargets contains the alternatives for a CmmSwitch value, and knows whether the value is signed, the possible range, an optional default value and a map from values to jump labels.

Instances2Eq, Show

switchTargetsToTable creates a dense jump table, usable for code generation.

Also returns an offset to add to the value; the list is 0-based on the result of that addition.

The conversion from Integer to Int is a bit of a wart, as the actual scrutinee might be an unsigned word, but it just works, due to wrap-around arithmetic (as verified by the CmmSwitchTest test case).

The back end targets a technology that implements switch natively. (For example, LLVM or C.) Therefore it is not necessary for GHC to ccompile a Cmm Switch form into a decision tree with jump tables at the leaves.