From bfabf94f63b6644bd32982fd13ea0c8bca9aeae4 Mon Sep 17 00:00:00 2001 From: Sylvain Henry Date: Thu, 6 May 2021 14:52:53 +0200 Subject: 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 () --- compiler/GHC/Utils/Constants.hs | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 compiler/GHC/Utils/Constants.hs (limited to 'compiler/GHC/Utils/Constants.hs') diff --git a/compiler/GHC/Utils/Constants.hs b/compiler/GHC/Utils/Constants.hs new file mode 100644 index 0000000000..518c5f31be --- /dev/null +++ b/compiler/GHC/Utils/Constants.hs @@ -0,0 +1,51 @@ +{-# LANGUAGE CPP #-} + +module GHC.Utils.Constants + ( debugIsOn + , ghciSupported + , isWindowsHost + , isDarwinHost + ) +where + +import GHC.Prelude + +{- + +These booleans are global constants, set by CPP flags. They allow us to +recompile a single module (this one) to change whether or not debug output +appears. They sometimes let us avoid even running CPP elsewhere. + +It's important that the flags are literal constants (True/False). Then, +with -0, tests of the flags in other modules will simplify to the correct +branch of the conditional, thereby dropping debug code altogether when +the flags are off. +-} + +ghciSupported :: Bool +#if defined(HAVE_INTERNAL_INTERPRETER) +ghciSupported = True +#else +ghciSupported = False +#endif + +debugIsOn :: Bool +#if defined(DEBUG) +debugIsOn = True +#else +debugIsOn = False +#endif + +isWindowsHost :: Bool +#if defined(mingw32_HOST_OS) +isWindowsHost = True +#else +isWindowsHost = False +#endif + +isDarwinHost :: Bool +#if defined(darwin_HOST_OS) +isDarwinHost = True +#else +isDarwinHost = False +#endif -- cgit v1.2.1