summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÖmer Sinan Ağacan <omeragacan@gmail.com>2019-08-09 14:05:13 +0300
committerÖmer Sinan Ağacan <omeragacan@gmail.com>2019-08-27 10:45:02 +0300
commit10763ce0fbf2ec88b16902cb9ba6c717bf400c13 (patch)
treee1b383c3f34d19b2cc7360fbdf7871b109799149
parentcff44d8686c1539ee77d34756d6b7908e120b96a (diff)
downloadhaskell-10763ce0fbf2ec88b16902cb9ba6c717bf400c13.tar.gz
Some more documentation for typePrimRep1 stuff
[skip ci]
-rw-r--r--compiler/codeGen/StgCmmClosure.hs11
-rw-r--r--compiler/simplStg/RepType.hs4
-rw-r--r--compiler/simplStg/UnariseStg.hs2
3 files changed, 14 insertions, 3 deletions
diff --git a/compiler/codeGen/StgCmmClosure.hs b/compiler/codeGen/StgCmmClosure.hs
index 437219bf45..ac8db1268f 100644
--- a/compiler/codeGen/StgCmmClosure.hs
+++ b/compiler/codeGen/StgCmmClosure.hs
@@ -166,20 +166,27 @@ assertNonVoidStgArgs args = ASSERT(not (any (isVoidTy . stgArgType) args))
-- Why are these here?
+-- | Assumes that there is precisely one 'PrimRep' of the type. This assumption
+-- holds after unarise.
+-- See Note [Post-unarisation invariants]
idPrimRep :: Id -> PrimRep
idPrimRep id = typePrimRep1 (idType id)
- -- NB: typePrimRep1 fails on unboxed tuples,
- -- but by StgCmm no Ids have unboxed tuple type
-- See also Note [VoidRep] in RepType
+-- | Assumes that Ids have one PrimRep, which holds after unarisation.
+-- See Note [Post-unarisation invariants]
addIdReps :: [NonVoid Id] -> [NonVoid (PrimRep, Id)]
addIdReps = map (\id -> let id' = fromNonVoid id
in NonVoid (idPrimRep id', id'))
+-- | Assumes that arguments have one PrimRep, which holds after unarisation.
+-- See Note [Post-unarisation invariants]
addArgReps :: [NonVoid StgArg] -> [NonVoid (PrimRep, StgArg)]
addArgReps = map (\arg -> let arg' = fromNonVoid arg
in NonVoid (argPrimRep arg', arg'))
+-- | Assumes that the argument has one PrimRep, which holds after unarisation.
+-- See Note [Post-unarisation invariants]
argPrimRep :: StgArg -> PrimRep
argPrimRep arg = typePrimRep1 (stgArgType arg)
diff --git a/compiler/simplStg/RepType.hs b/compiler/simplStg/RepType.hs
index f235344848..75fde79d87 100644
--- a/compiler/simplStg/RepType.hs
+++ b/compiler/simplStg/RepType.hs
@@ -472,7 +472,9 @@ typePrimRep ty = kindPrimRep (text "typePrimRep" <+>
(typeKind ty)
-- | Like 'typePrimRep', but assumes that there is precisely one 'PrimRep' output;
--- an empty list of PrimReps becomes a VoidRep
+-- an empty list of PrimReps becomes a VoidRep.
+-- This assumption holds after unarise, see Note [Post-unarisation invariants].
+-- Before unarise it may or may not hold.
-- See also Note [RuntimeRep and PrimRep] and Note [VoidRep]
typePrimRep1 :: HasDebugCallStack => UnaryType -> PrimRep
typePrimRep1 ty = case typePrimRep ty of
diff --git a/compiler/simplStg/UnariseStg.hs b/compiler/simplStg/UnariseStg.hs
index c908580f2f..57e9f3351a 100644
--- a/compiler/simplStg/UnariseStg.hs
+++ b/compiler/simplStg/UnariseStg.hs
@@ -188,6 +188,8 @@ STG programs after unarisation have these invariants:
`StgCmmEnv.NonVoid`, for example.
* Alt binders (binders in patterns) are always non-void.
+
+ * Binders always have zero (for void arguments) or one PrimRep.
-}
{-# LANGUAGE CPP, TupleSections #-}