Commit cc536288 authored by Ben Gamari's avatar Ben Gamari 🐢 Committed by Marge Bot

compiler/ByteCode: Allow 2^32 local labels

This widens LocalLabel to 2^16, avoiding the crash observed in #14334.

Closes #14334.
parent ae146b53
Pipeline #26387 passed with stages
in 336 minutes and 32 seconds
......@@ -179,7 +179,9 @@ assembleBCO platform (ProtoBCO { protoBCOName = nm
-- this BCO to be long.
(n_insns0, lbl_map0) = inspectAsm platform False initial_offset asm
((n_insns, lbl_map), long_jumps)
| isLarge n_insns0 = (inspectAsm platform True initial_offset asm, True)
| isLarge (fromIntegral $ Map.size lbl_map0)
|| isLarge n_insns0
= (inspectAsm platform True initial_offset asm, True)
| otherwise = ((n_insns0, lbl_map0), False)
env :: LocalLabel -> Word
......
......@@ -50,7 +50,8 @@ data ProtoBCO a
protoBCOFFIs :: [FFIInfo]
}
newtype LocalLabel = LocalLabel { getLocalLabel :: Word16 }
-- | A local block label (e.g. identifying a case alternative).
newtype LocalLabel = LocalLabel { getLocalLabel :: Word32 }
deriving (Eq, Ord)
instance Outputable LocalLabel where
......
......@@ -1968,7 +1968,7 @@ data BcM_State
{ bcm_hsc_env :: HscEnv
, uniqSupply :: UniqSupply -- for generating fresh variable names
, thisModule :: Module -- current module (for breakpoints)
, nextlabel :: Word16 -- for generating local labels
, nextlabel :: Word32 -- for generating local labels
, ffis :: [FFIInfo] -- ffi info blocks, to free later
-- Should be free()d when it is GCd
, modBreaks :: Maybe ModBreaks -- info about breakpoints
......@@ -2040,7 +2040,7 @@ getLabelBc
panic "getLabelBc: Ran out of labels"
return (st{nextlabel = nl + 1}, LocalLabel nl)
getLabelsBc :: Word16 -> BcM [LocalLabel]
getLabelsBc :: Word32 -> BcM [LocalLabel]
getLabelsBc n
= BcM $ \st -> let ctr = nextlabel st
in return (st{nextlabel = ctr+n}, coerce [ctr .. ctr+n-1])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment