summaryrefslogtreecommitdiff
path: root/compiler/GHC/Stg/Unarise.hs
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-05-06 14:52:53 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-05-12 21:41:43 -0400
commitbfabf94f63b6644bd32982fd13ea0c8bca9aeae4 (patch)
treeb185749a9676a57c226dab9681fa3c4ba0415dd3 /compiler/GHC/Stg/Unarise.hs
parentda56ed41b62ab132db6d62637c11076985410b24 (diff)
downloadhaskell-bfabf94f63b6644bd32982fd13ea0c8bca9aeae4.tar.gz
Replace CPP assertions with Haskell functions
There is no reason to use CPP. __LINE__ and __FILE__ macros are now better replaced with GHC's CallStack. As a bonus, assert error messages now contain more information (function name, column). Here is the mapping table (HasCallStack omitted): * ASSERT: assert :: Bool -> a -> a * MASSERT: massert :: Bool -> m () * ASSERTM: assertM :: m Bool -> m () * ASSERT2: assertPpr :: Bool -> SDoc -> a -> a * MASSERT2: massertPpr :: Bool -> SDoc -> m () * ASSERTM2: assertPprM :: m Bool -> SDoc -> m ()
Diffstat (limited to 'compiler/GHC/Stg/Unarise.hs')
-rw-r--r--compiler/GHC/Stg/Unarise.hs25
1 files changed, 13 insertions, 12 deletions
diff --git a/compiler/GHC/Stg/Unarise.hs b/compiler/GHC/Stg/Unarise.hs
index 7790bc382d..4a4fef1402 100644
--- a/compiler/GHC/Stg/Unarise.hs
+++ b/compiler/GHC/Stg/Unarise.hs
@@ -257,6 +257,7 @@ import GHC.Types.Id.Make (voidPrimId, voidArgId)
import GHC.Utils.Monad (mapAccumLM)
import GHC.Utils.Outputable
import GHC.Utils.Panic
+import GHC.Utils.Panic.Plain
import GHC.Types.RepType
import GHC.Stg.Syntax
import GHC.Core.Type
@@ -307,10 +308,10 @@ instance Outputable UnariseVal where
-- | Extend the environment, checking the UnariseEnv invariant.
extendRho :: UnariseEnv -> Id -> UnariseVal -> UnariseEnv
extendRho rho x (MultiVal args)
- = ASSERT(all (isNvUnaryType . stgArgType) args)
+ = assert (all (isNvUnaryType . stgArgType) args)
extendVarEnv rho x (MultiVal args)
extendRho rho x (UnaryVal val)
- = ASSERT(isNvUnaryType (stgArgType val))
+ = assert (isNvUnaryType (stgArgType val))
extendVarEnv rho x (UnaryVal val)
--------------------------------------------------------------------------------
@@ -336,7 +337,7 @@ unariseRhs rho (StgRhsClosure ext ccs update_flag args expr)
return (StgRhsClosure ext ccs update_flag args1 expr')
unariseRhs rho (StgRhsCon ccs con mu ts args)
- = ASSERT(not (isUnboxedTupleDataCon con || isUnboxedSumDataCon con))
+ = assert (not (isUnboxedTupleDataCon con || isUnboxedSumDataCon con))
return (StgRhsCon ccs con mu ts (unariseConArgs rho args))
--------------------------------------------------------------------------------
@@ -420,7 +421,7 @@ unariseMulti_maybe rho dc args ty_args
= Just (unariseConArgs rho args)
| isUnboxedSumDataCon dc
- , let args1 = ASSERT(isSingleton args) (unariseConArgs rho args)
+ , let args1 = assert (isSingleton args) (unariseConArgs rho args)
= Just (mkUbxSum dc ty_args args1)
| otherwise
@@ -454,7 +455,7 @@ elimCase rho args bndr (MultiValAlt _) [(_, bndrs, rhs)]
| isUnboxedTupleBndr bndr
= mapTupleIdBinders bndrs args rho1
| otherwise
- = ASSERT(isUnboxedSumBndr bndr)
+ = assert (isUnboxedSumBndr bndr) $
if null bndrs then rho1
else mapSumIdBinders bndrs args rho1
@@ -489,7 +490,7 @@ unariseAlts rho (MultiValAlt n) bndr [(DEFAULT, [], e)]
unariseAlts rho (MultiValAlt n) bndr [(DataAlt _, ys, e)]
| isUnboxedTupleBndr bndr
= do (rho', ys1) <- unariseConArgBinders rho ys
- MASSERT(ys1 `lengthIs` n)
+ massert (ys1 `lengthIs` n)
let rho'' = extendRho rho' bndr (MultiVal (map StgVarArg ys1))
e' <- unariseExpr rho'' e
return [(DataAlt (tupleDataCon Unboxed n), ys1, e')]
@@ -559,7 +560,7 @@ mapTupleIdBinders
-> UnariseEnv
-> UnariseEnv
mapTupleIdBinders ids args0 rho0
- = ASSERT(not (any (isVoidTy . stgArgType) args0))
+ = assert (not (any (isVoidTy . stgArgType) args0)) $
let
ids_unarised :: [(Id, [PrimRep])]
ids_unarised = map (\id -> (id, typePrimRep (idType id))) ids
@@ -570,12 +571,12 @@ mapTupleIdBinders ids args0 rho0
let
x_arity = length x_reps
(x_args, args') =
- ASSERT(args `lengthAtLeast` x_arity)
+ assert (args `lengthAtLeast` x_arity)
splitAt x_arity args
rho'
| x_arity == 1
- = ASSERT(x_args `lengthIs` 1)
+ = assert (x_args `lengthIs` 1)
extendRho rho x (UnaryVal (head x_args))
| otherwise
= extendRho rho x (MultiVal x_args)
@@ -593,7 +594,7 @@ mapSumIdBinders
-> UnariseEnv
mapSumIdBinders [id] args rho0
- = ASSERT(not (any (isVoidTy . stgArgType) args))
+ = assert (not (any (isVoidTy . stgArgType) args)) $
let
arg_slots = map primRepSlot $ concatMap (typePrimRep . stgArgType) args
id_slots = map primRepSlot $ typePrimRep (idType id)
@@ -601,7 +602,7 @@ mapSumIdBinders [id] args rho0
in
if isMultiValBndr id
then extendRho rho0 id (MultiVal [ args !! i | i <- layout1 ])
- else ASSERT(layout1 `lengthIs` 1)
+ else assert (layout1 `lengthIs` 1)
extendRho rho0 id (UnaryVal (args !! head layout1))
mapSumIdBinders ids sum_args _
@@ -787,7 +788,7 @@ unariseConArg _ arg@(StgLitArg lit)
| Just as <- unariseRubbish_maybe lit
= as
| otherwise
- = ASSERT(not (isVoidTy (literalType lit))) -- We have no non-rubbish void literals
+ = assert (not (isVoidTy (literalType lit))) -- We have no non-rubbish void literals
[arg]
unariseConArgs :: UnariseEnv -> [InStgArg] -> [OutStgArg]