From bcd43eadae560e9e72f30cf33590598214c365f5 Mon Sep 17 00:00:00 2001 From: Alex Hubers Date: Thu, 19 May 2022 10:15:30 -0500 Subject: [PATCH] Add CPP shenanigans back to Array.hs --- Data/HashMap/Internal/Array.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Data/HashMap/Internal/Array.hs b/Data/HashMap/Internal/Array.hs index 2cb5e003..1a1c5892 100644 --- a/Data/HashMap/Internal/Array.hs +++ b/Data/HashMap/Internal/Array.hs @@ -109,6 +109,26 @@ import qualified Prelude import GHC.Types (Total, type(@)) +#if defined(ASSERTS) +-- This fugly hack is brought by GHC's apparent reluctance to deal +-- with MagicHash and UnboxedTuples when inferring types. Eek! +# define CHECK_BOUNDS(_func_,_len_,_k_) \ +if (_k_) < 0 || (_k_) >= (_len_) then error ("Data.HashMap.Internal.Array." ++ (_func_) ++ ": bounds error, offset " ++ show (_k_) ++ ", length " ++ show (_len_)) else +# define CHECK_OP(_func_,_op_,_lhs_,_rhs_) \ +if not ((_lhs_) _op_ (_rhs_)) then error ("Data.HashMap.Internal.Array." ++ (_func_) ++ ": Check failed: _lhs_ _op_ _rhs_ (" ++ show (_lhs_) ++ " vs. " ++ show (_rhs_) ++ ")") else +# define CHECK_GT(_func_,_lhs_,_rhs_) CHECK_OP(_func_,>,_lhs_,_rhs_) +# define CHECK_LE(_func_,_lhs_,_rhs_) CHECK_OP(_func_,<=,_lhs_,_rhs_) +# define CHECK_EQ(_func_,_lhs_,_rhs_) CHECK_OP(_func_,==,_lhs_,_rhs_) +#else +# define CHECK_BOUNDS(_func_,_len_,_k_) +# define CHECK_OP(_func_,_op_,_lhs_,_rhs_) +# define CHECK_GT(_func_,_lhs_,_rhs_) +# define CHECK_LE(_func_,_lhs_,_rhs_) +# define CHECK_EQ(_func_,_lhs_,_rhs_) +#endif + + + data Array a = Array { unArray :: !(SmallArray# a) }