StgTopLifted is misleadingly named
Consider the type:
type Foo :: Type -> UnliftedType
data Foo a where
Bar :: Foo Int
The Core of this will contain a wrapper:
Mod.$WBar [InlPrag=INLINE[final] CONLIKE] :: Foo Int
[GblId[DataConWrapper], Unf=OtherCon []]
Mod.$WBar
= Mod.Bar @Int @~(<Int>_N :: Int ~# Int)
Which will be lowered to STG of the form:
Mod.$WBar [InlPrag=INLINE[final] CONLIKE]
:: Mod.Foo GHC.Types.Int
[GblId[DataConWrapper], Unf=OtherCon []] =
Mod.Bar! [GHC.Prim.coercionToken#];
The RHS of this binding is represented by StgTopLifted
constructor despite the fact that the binding is clearly not lifted.
This is admittedly a bit of a corner case as we do not allow top-level unlifted bindings in Haskell; I believe this sort of wrapper is the only case in which this will arise. However, the name is nevertheless confusing.
I originally noticed this while looking at #25636, where this naming contributed to the confusion that lead to the bug.
Edited by Ben Gamari