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/HsVersions.h | |
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/HsVersions.h')
-rw-r--r-- | compiler/HsVersions.h | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/compiler/HsVersions.h b/compiler/HsVersions.h index b71613de97..10cc152ea1 100644 --- a/compiler/HsVersions.h +++ b/compiler/HsVersions.h @@ -10,8 +10,8 @@ you will screw up the layout where they are used in case expressions! #endif #define ASSERT(e) if debugIsOn && not (e) then (assertPanic __FILE__ __LINE__) else -#define ASSERT2(e,msg) if debugIsOn && not (e) then (assertPprPanic __FILE__ __LINE__ (msg)) else -#define WARN( e, msg ) (warnPprTrace (e) __FILE__ __LINE__ (msg)) $ +#define ASSERT2(e,msg) if debugIsOn && not (e) then (assertPprPanic (msg)) else +#define WARN( e, msg ) (warnPprTrace (e) (msg)) $ -- Examples: Assuming flagSet :: String -> m Bool -- @@ -19,9 +19,7 @@ you will screw up the layout where they are used in case expressions! -- do { c <- getChar; MASSERT2( isUpper c, text "Bad" ); ... } -- do { str <- getStr; ASSERTM( flagSet str ); .. } -- do { str <- getStr; ASSERTM2( flagSet str, text "Bad" ); .. } --- do { str <- getStr; WARNM2( flagSet str, text "Flag is set" ); .. } #define MASSERT(e) ASSERT(e) return () #define MASSERT2(e,msg) ASSERT2(e,msg) return () #define ASSERTM(e) do { bool <- e; MASSERT(bool) } #define ASSERTM2(e,msg) do { bool <- e; MASSERT2(bool,msg) } -#define WARNM2(e,msg) do { bool <- e; WARN(bool, msg) return () } |