diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2021-05-06 14:52:53 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-05-12 21:41:43 -0400 |
commit | bfabf94f63b6644bd32982fd13ea0c8bca9aeae4 (patch) | |
tree | b185749a9676a57c226dab9681fa3c4ba0415dd3 /compiler/GHC/Tc/Module.hs | |
parent | da56ed41b62ab132db6d62637c11076985410b24 (diff) | |
download | haskell-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/Tc/Module.hs')
-rw-r--r-- | compiler/GHC/Tc/Module.hs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/compiler/GHC/Tc/Module.hs b/compiler/GHC/Tc/Module.hs index fc330061e8..72b588a921 100644 --- a/compiler/GHC/Tc/Module.hs +++ b/compiler/GHC/Tc/Module.hs @@ -131,6 +131,7 @@ import GHC.Runtime.Context import GHC.Utils.Error import GHC.Utils.Outputable as Outputable import GHC.Utils.Panic +import GHC.Utils.Panic.Plain import GHC.Utils.Misc import GHC.Utils.Logger @@ -977,7 +978,7 @@ checkBootDeclM is_boot boot_thing real_thing checkBootDecl :: Bool -> TyThing -> TyThing -> Maybe SDoc checkBootDecl _ (AnId id1) (AnId id2) - = ASSERT(id1 == id2) + = assert (id1 == id2) $ check (idType id1 `eqType` idType id2) (text "The two types are different") @@ -1117,7 +1118,7 @@ checkBootTyCon is_boot tc1 tc2 | Just syn_rhs1 <- synTyConRhs_maybe tc1 , Just syn_rhs2 <- synTyConRhs_maybe tc2 , Just env <- eqVarBndrs emptyRnEnv2 (tyConTyVars tc1) (tyConTyVars tc2) - = ASSERT(tc1 == tc2) + = assert (tc1 == tc2) $ checkRoles roles1 roles2 `andThenCheck` check (eqTypeX env syn_rhs1 syn_rhs2) empty -- nothing interesting to say -- This allows abstract 'data T a' to be implemented using 'type T = ...' @@ -1147,7 +1148,7 @@ checkBootTyCon is_boot tc1 tc2 | Just fam_flav1 <- famTyConFlav_maybe tc1 , Just fam_flav2 <- famTyConFlav_maybe tc2 - = ASSERT(tc1 == tc2) + = assert (tc1 == tc2) $ let eqFamFlav OpenSynFamilyTyCon OpenSynFamilyTyCon = True eqFamFlav (DataFamilyTyCon {}) (DataFamilyTyCon {}) = True -- This case only happens for hsig merging: @@ -1173,7 +1174,7 @@ checkBootTyCon is_boot tc1 tc2 | isAlgTyCon tc1 && isAlgTyCon tc2 , Just env <- eqVarBndrs emptyRnEnv2 (tyConTyVars tc1) (tyConTyVars tc2) - = ASSERT(tc1 == tc2) + = assert (tc1 == tc2) $ checkRoles roles1 roles2 `andThenCheck` check (eqListBy (eqTypeX env) (tyConStupidTheta tc1) (tyConStupidTheta tc2)) @@ -1282,7 +1283,7 @@ checkBootTyCon is_boot tc1 tc2 `andThenCheck` -- Don't report roles errors unless the type synonym is nullary checkUnless (not (null tvs)) $ - ASSERT( null roles2 ) + assert (null roles2) $ -- If we have something like: -- -- signature H where @@ -1825,7 +1826,7 @@ checkMain explicit_mod_hdr export_ies generateMainBinding tcg_env main_name | otherwise - -> ASSERT( null exported_mains ) + -> assert (null exported_mains) $ -- A fully-checked export list can't contain more -- than one function with the same OccName do { complain_no_main dflags main_mod main_occ @@ -2651,7 +2652,7 @@ tcRnType hsc_env flexi normalise rdr_type -- Since all the wanteds are equalities, the returned bindings will be empty ; empty_binds <- simplifyTop wanted - ; MASSERT2( isEmptyBag empty_binds, ppr empty_binds ) + ; massertPpr (isEmptyBag empty_binds) (ppr empty_binds) -- Do kind generalisation; see Note [Kind-generalise in tcRnType] ; kvs <- kindGeneralizeAll kind |