summaryrefslogtreecommitdiff
path: root/compiler/codeGen/StgCmmClosure.hs
diff options
context:
space:
mode:
authorÖmer Sinan Ağacan <omeragacan@gmail.com>2016-09-20 00:19:15 -0400
committerÖmer Sinan Ağacan <omeragacan@gmail.com>2016-09-20 00:19:27 -0400
commit14c2e8e0c11bb2b95f81303284d1460bb80a9a98 (patch)
treeb9c67117f0e2f7f79037e9a07c20a0256800f5cc /compiler/codeGen/StgCmmClosure.hs
parentea310f9956179f91ca973bc747b0bc7b061bc174 (diff)
downloadhaskell-14c2e8e0c11bb2b95f81303284d1460bb80a9a98.tar.gz
Codegen for case: Remove redundant void id checks
New unarise (714bebf) eliminates void binders in patterns already, so no need to eliminate them here. I leave assertions to make sure this is the case. Assertion failure -> bug in unarise Reviewers: bgamari, simonpj, austin, simonmar, hvr Reviewed By: simonpj Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2416
Diffstat (limited to 'compiler/codeGen/StgCmmClosure.hs')
-rw-r--r--compiler/codeGen/StgCmmClosure.hs51
1 files changed, 47 insertions, 4 deletions
diff --git a/compiler/codeGen/StgCmmClosure.hs b/compiler/codeGen/StgCmmClosure.hs
index f831789454..23b803cc56 100644
--- a/compiler/codeGen/StgCmmClosure.hs
+++ b/compiler/codeGen/StgCmmClosure.hs
@@ -18,6 +18,9 @@ module StgCmmClosure (
idPrimRep, isVoidRep, isGcPtrRep, addIdReps, addArgReps,
argPrimRep,
+ NonVoid(..), fromNonVoid, nonVoidIds, nonVoidStgArgs,
+ assertNonVoidIds, assertNonVoidStgArgs,
+
-- * LambdaFormInfo
LambdaFormInfo, -- Abstract
StandardFormInfo, -- ...ditto...
@@ -84,6 +87,8 @@ import Outputable
import DynFlags
import Util
+import Data.Coerce (coerce)
+
-----------------------------------------------------------------------------
-- Data types and synonyms
-----------------------------------------------------------------------------
@@ -115,6 +120,42 @@ isKnownFun LFLetNoEscape = True
isKnownFun _ = False
+-------------------------------------
+-- Non-void types
+-------------------------------------
+-- We frequently need the invariant that an Id or a an argument
+-- is of a non-void type. This type is a witness to the invariant.
+
+newtype NonVoid a = NonVoid a
+ deriving (Eq, Show)
+
+fromNonVoid :: NonVoid a -> a
+fromNonVoid (NonVoid a) = a
+
+instance (Outputable a) => Outputable (NonVoid a) where
+ ppr (NonVoid a) = ppr a
+
+nonVoidIds :: [Id] -> [NonVoid Id]
+nonVoidIds ids = [NonVoid id | id <- ids, not (isVoidTy (idType id))]
+
+-- | Used in places where some invariant ensures that all these Ids are
+-- non-void; e.g. constructor field binders in case expressions.
+-- See Note [Post-unarisation invariants] in UnariseStg.
+assertNonVoidIds :: [Id] -> [NonVoid Id]
+assertNonVoidIds ids = ASSERT(not (any (isVoidTy . idType) ids))
+ coerce ids
+
+nonVoidStgArgs :: [StgArg] -> [NonVoid StgArg]
+nonVoidStgArgs args = [NonVoid arg | arg <- args, not (isVoidTy (stgArgType arg))]
+
+-- | Used in places where some invariant ensures that all these arguments are
+-- non-void; e.g. constructor arguments.
+-- See Note [Post-unarisation invariants] in UnariseStg.
+assertNonVoidStgArgs :: [StgArg] -> [NonVoid StgArg]
+assertNonVoidStgArgs args = ASSERT(not (any (isVoidTy . stgArgType) args))
+ coerce args
+
+
-----------------------------------------------------------------------------
-- Representations
-----------------------------------------------------------------------------
@@ -126,11 +167,13 @@ idPrimRep id = typePrimRep (idType id)
-- NB: typePrimRep fails on unboxed tuples,
-- but by StgCmm no Ids have unboxed tuple type
-addIdReps :: [Id] -> [(PrimRep, Id)]
-addIdReps ids = [(idPrimRep id, id) | id <- ids]
+addIdReps :: [NonVoid Id] -> [NonVoid (PrimRep, Id)]
+addIdReps = map (\id -> let id' = fromNonVoid id
+ in NonVoid (idPrimRep id', id'))
-addArgReps :: [StgArg] -> [(PrimRep, StgArg)]
-addArgReps args = [(argPrimRep arg, arg) | arg <- args]
+addArgReps :: [NonVoid StgArg] -> [NonVoid (PrimRep, StgArg)]
+addArgReps = map (\arg -> let arg' = fromNonVoid arg
+ in NonVoid (argPrimRep arg', arg'))
argPrimRep :: StgArg -> PrimRep
argPrimRep arg = typePrimRep (stgArgType arg)