diff options
-rw-r--r-- | compiler/simplStg/UnariseStg.hs | 16 | ||||
-rw-r--r-- | compiler/stgSyn/CoreToStg.hs | 2 | ||||
-rw-r--r-- | compiler/types/Type.hs | 24 |
3 files changed, 18 insertions, 24 deletions
diff --git a/compiler/simplStg/UnariseStg.hs b/compiler/simplStg/UnariseStg.hs index d5809428dd..1b94cbcbc6 100644 --- a/compiler/simplStg/UnariseStg.hs +++ b/compiler/simplStg/UnariseStg.hs @@ -50,6 +50,22 @@ Of course all this applies recursively, so that we flatten out nested tuples. Note [Unarisation and nullary tuples] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The above scheme has a special cases for nullary unboxed tuples, x :: (# #) +To see why, consider + f2 :: (# Int, Int #) -> Int + f1 :: (# Int #) -> Int + f0 :: (# #) -> Int + +When we "unarise" to eliminate unboxed tuples (this is done at the STG level), +we'll transform to + f2 :: Int -> Int -> Int + f1 :: Int -> Int + f0 :: ?? + +We do not want to give f0 zero arguments, otherwise a lambda will +turn into a thunk! So we want to get + f0 :: Void# -> Int + +So here is what we do for nullary tuples * Extend the UnariseEnv with x :-> [voidPrimId] diff --git a/compiler/stgSyn/CoreToStg.hs b/compiler/stgSyn/CoreToStg.hs index d2010a83d4..273cbdb9c1 100644 --- a/compiler/stgSyn/CoreToStg.hs +++ b/compiler/stgSyn/CoreToStg.hs @@ -451,7 +451,7 @@ mkStgAltType bndr alts = case repType (idType bndr) of PolyAlt Nothing -> PolyAlt UbxTupleRep rep_tys -> UbxTupAlt (length rep_tys) - -- NB Nullary unboxed tuples have UnaryRep, and generate a PrimAlt + -- UbxTupAlt includes nullary and and singleton unboxed tuples where _is_poly_alt_tycon tc = isFunTyCon tc diff --git a/compiler/types/Type.hs b/compiler/types/Type.hs index 9aaf3de645..724a9a40d2 100644 --- a/compiler/types/Type.hs +++ b/compiler/types/Type.hs @@ -1714,33 +1714,11 @@ typeSize (CoercionTy co) = coercionSize co * * ********************************************************************** -} -{- Note [Nullary unboxed tuple] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -At runtime we represent the nullary unboxed tuple as the type Void#. -To see why, consider - f2 :: (# Int, Int #) -> Int - f1 :: (# Int #) -> Int - f0 :: (# #) -> Int - -When we "unarise" to eliminate unboxed tuples (this is done at the STG level), -we'll transform to - f2 :: Int -> Int -> Int - f1 :: Int -> Int - f0 :: ?? - -We do not want to give f0 zero arguments, otherwise a lambda will -turn into a thunk! So we want to get - f0 :: Void# -> Int - -See Note [Unarisation and nullary tuples] in UnariseStg for more detail. --} - type UnaryType = Type data RepType = UbxTupleRep [UnaryType] -- Represented by multiple values - -- INVARIANT: never an empty list - -- (see Note [Nullary unboxed tuple]) + -- Can be zero, one, or more | UnaryRep UnaryType -- Represented by a single value instance Outputable RepType where |