summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Klebinger <klebinger.andreas@gmx.at>2021-03-31 15:31:19 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-04-09 03:31:02 -0400
commitc02ac1bbd2d882d58307fa3009aa2d9665399703 (patch)
tree0c5a038ca509a36e4b24ceca3643d65e63a7e533
parent0bdb867e37bcfe4ae2c5c4f5f7e54b41acfe6116 (diff)
downloadhaskell-c02ac1bbd2d882d58307fa3009aa2d9665399703.tar.gz
Re-export GHC.Bits from GHC.Prelude with custom shift implementation.
This allows us to use the unsafe shifts in non-debug builds for performance. For older versions of base we instead export Data.Bits See also #19618
-rw-r--r--compiler/GHC/Builtin/Uniques.hs1
-rw-r--r--compiler/GHC/ByteCode/Asm.hs2
-rw-r--r--compiler/GHC/Cmm/CommonBlockElim.hs1
-rw-r--r--compiler/GHC/Cmm/Info.hs1
-rw-r--r--compiler/GHC/Cmm/LayoutStack.hs1
-rw-r--r--compiler/GHC/Cmm/Opt.hs1
-rw-r--r--compiler/GHC/Cmm/Utils.hs1
-rw-r--r--compiler/GHC/CmmToAsm/Dwarf/Types.hs1
-rw-r--r--compiler/GHC/CmmToAsm/PPC/CodeGen.hs1
-rw-r--r--compiler/GHC/CmmToAsm/PPC/Ppr.hs1
-rw-r--r--compiler/GHC/CmmToAsm/Ppr.hs1
-rw-r--r--compiler/GHC/CmmToAsm/Reg/Linear/PPC.hs1
-rw-r--r--compiler/GHC/CmmToAsm/Reg/Linear/SPARC.hs1
-rw-r--r--compiler/GHC/CmmToAsm/Reg/Linear/X86.hs1
-rw-r--r--compiler/GHC/CmmToAsm/Reg/Linear/X86_64.hs1
-rw-r--r--compiler/GHC/CmmToAsm/X86/CodeGen.hs1
-rw-r--r--compiler/GHC/CmmToAsm/X86/Ppr.hs1
-rw-r--r--compiler/GHC/CmmToC.hs1
-rw-r--r--compiler/GHC/Core/Opt/ConstantFold.hs25
-rw-r--r--compiler/GHC/CoreToStg/Prep.hs1
-rw-r--r--compiler/GHC/Data/Bitmap.hs1
-rw-r--r--compiler/GHC/Data/FastMutInt.hs1
-rw-r--r--compiler/GHC/Iface/Binary.hs1
-rw-r--r--compiler/GHC/Parser/CharClass.hs1
-rw-r--r--compiler/GHC/Parser/Lexer.x1
-rw-r--r--compiler/GHC/Prelude.hs63
-rw-r--r--compiler/GHC/Runtime/Heap/Inspect.hs2
-rw-r--r--compiler/GHC/Runtime/Heap/Layout.hs1
-rw-r--r--compiler/GHC/StgToByteCode.hs2
-rw-r--r--compiler/GHC/StgToCmm/Prim.hs1
-rw-r--r--compiler/GHC/SysTools/Terminal.hs2
-rw-r--r--compiler/GHC/Types/Basic.hs1
-rw-r--r--compiler/GHC/Types/Id/Info.hs1
-rw-r--r--compiler/GHC/Types/SrcLoc.hs1
-rw-r--r--compiler/GHC/Types/Unique.hs1
-rw-r--r--compiler/GHC/Types/Unique/Supply.hs1
-rw-r--r--compiler/GHC/Utils/Binary.hs2
-rw-r--r--compiler/GHC/Utils/Misc.hs1
38 files changed, 76 insertions, 53 deletions
diff --git a/compiler/GHC/Builtin/Uniques.hs b/compiler/GHC/Builtin/Uniques.hs
index 4b3f3e00b6..317670bb37 100644
--- a/compiler/GHC/Builtin/Uniques.hs
+++ b/compiler/GHC/Builtin/Uniques.hs
@@ -68,7 +68,6 @@ import GHC.Utils.Outputable
import GHC.Utils.Misc
import GHC.Utils.Panic
-import Data.Bits
import Data.Maybe
-- | Get the 'Name' associated with a known-key 'Unique'.
diff --git a/compiler/GHC/ByteCode/Asm.hs b/compiler/GHC/ByteCode/Asm.hs
index 30f2c2b633..1f11938517 100644
--- a/compiler/GHC/ByteCode/Asm.hs
+++ b/compiler/GHC/ByteCode/Asm.hs
@@ -56,7 +56,7 @@ import Data.Array.Base ( UArray(..) )
import Data.Array.Unsafe( castSTUArray )
-import Foreign
+import Foreign hiding (shiftL, shiftR)
import Data.Char ( ord )
import Data.List ( genericLength )
import Data.Map.Strict (Map)
diff --git a/compiler/GHC/Cmm/CommonBlockElim.hs b/compiler/GHC/Cmm/CommonBlockElim.hs
index ffb4562c40..9ed08a2d12 100644
--- a/compiler/GHC/Cmm/CommonBlockElim.hs
+++ b/compiler/GHC/Cmm/CommonBlockElim.hs
@@ -18,7 +18,6 @@ import GHC.Cmm.Dataflow.Block
import GHC.Cmm.Dataflow.Graph
import GHC.Cmm.Dataflow.Label
import GHC.Cmm.Dataflow.Collections
-import Data.Bits
import Data.Maybe (mapMaybe)
import qualified Data.List as List
import Data.Word
diff --git a/compiler/GHC/Cmm/Info.hs b/compiler/GHC/Cmm/Info.hs
index eaa3c2a923..996821ab3b 100644
--- a/compiler/GHC/Cmm/Info.hs
+++ b/compiler/GHC/Cmm/Info.hs
@@ -58,7 +58,6 @@ import GHC.Utils.Misc
import GHC.Utils.Outputable
import Data.ByteString (ByteString)
-import Data.Bits
-- When we split at proc points, we need an empty info table.
mkEmptyContInfoTable :: CLabel -> CmmInfoTable
diff --git a/compiler/GHC/Cmm/LayoutStack.hs b/compiler/GHC/Cmm/LayoutStack.hs
index ac46f23f1f..2fdbb1fe5a 100644
--- a/compiler/GHC/Cmm/LayoutStack.hs
+++ b/compiler/GHC/Cmm/LayoutStack.hs
@@ -40,7 +40,6 @@ import GHC.Utils.Panic
import qualified Data.Set as Set
import Control.Monad.Fix
import Data.Array as Array
-import Data.Bits
import Data.List (nub)
{- Note [Stack Layout]
diff --git a/compiler/GHC/Cmm/Opt.hs b/compiler/GHC/Cmm/Opt.hs
index f4be9520ee..6a2945c4f8 100644
--- a/compiler/GHC/Cmm/Opt.hs
+++ b/compiler/GHC/Cmm/Opt.hs
@@ -22,7 +22,6 @@ import GHC.Utils.Misc
import GHC.Utils.Panic
import GHC.Platform
-import Data.Bits
import Data.Maybe
diff --git a/compiler/GHC/Cmm/Utils.hs b/compiler/GHC/Cmm/Utils.hs
index 3ac8b3c3ac..b42cd691f5 100644
--- a/compiler/GHC/Cmm/Utils.hs
+++ b/compiler/GHC/Cmm/Utils.hs
@@ -85,7 +85,6 @@ import GHC.Platform.Regs
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
-import Data.Bits
import GHC.Cmm.Dataflow.Graph
import GHC.Cmm.Dataflow.Label
import GHC.Cmm.Dataflow.Block
diff --git a/compiler/GHC/CmmToAsm/Dwarf/Types.hs b/compiler/GHC/CmmToAsm/Dwarf/Types.hs
index cad6a63515..43d902d106 100644
--- a/compiler/GHC/CmmToAsm/Dwarf/Types.hs
+++ b/compiler/GHC/CmmToAsm/Dwarf/Types.hs
@@ -46,7 +46,6 @@ import GHC.CmmToAsm.Dwarf.Constants
import qualified Data.ByteString as BS
import qualified Control.Monad.Trans.State.Strict as S
import Control.Monad (zipWithM, join)
-import Data.Bits
import qualified Data.Map as Map
import Data.Word
import Data.Char
diff --git a/compiler/GHC/CmmToAsm/PPC/CodeGen.hs b/compiler/GHC/CmmToAsm/PPC/CodeGen.hs
index 0a78722c85..f1a411ab27 100644
--- a/compiler/GHC/CmmToAsm/PPC/CodeGen.hs
+++ b/compiler/GHC/CmmToAsm/PPC/CodeGen.hs
@@ -66,7 +66,6 @@ import GHC.Utils.Outputable
import GHC.Utils.Panic
import Control.Monad ( mapAndUnzipM, when )
-import Data.Bits
import Data.Word
import GHC.Types.Basic
diff --git a/compiler/GHC/CmmToAsm/PPC/Ppr.hs b/compiler/GHC/CmmToAsm/PPC/Ppr.hs
index 5f8ab214cb..7ed13b298f 100644
--- a/compiler/GHC/CmmToAsm/PPC/Ppr.hs
+++ b/compiler/GHC/CmmToAsm/PPC/Ppr.hs
@@ -44,7 +44,6 @@ import GHC.Utils.Panic
import Data.Word
import Data.Int
-import Data.Bits
-- -----------------------------------------------------------------------------
-- Printing this stuff out
diff --git a/compiler/GHC/CmmToAsm/Ppr.hs b/compiler/GHC/CmmToAsm/Ppr.hs
index 8fba238cd1..dd656a9906 100644
--- a/compiler/GHC/CmmToAsm/Ppr.hs
+++ b/compiler/GHC/CmmToAsm/Ppr.hs
@@ -35,7 +35,6 @@ import Data.Array.ST
import Control.Monad.ST
import Data.Word
-import Data.Bits
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import GHC.Exts
diff --git a/compiler/GHC/CmmToAsm/Reg/Linear/PPC.hs b/compiler/GHC/CmmToAsm/Reg/Linear/PPC.hs
index fc9f9c0f89..e6c6015540 100644
--- a/compiler/GHC/CmmToAsm/Reg/Linear/PPC.hs
+++ b/compiler/GHC/CmmToAsm/Reg/Linear/PPC.hs
@@ -12,7 +12,6 @@ import GHC.Utils.Panic
import GHC.Platform
import Data.Word
-import Data.Bits
-- The PowerPC has 32 integer and 32 floating point registers.
-- This is 32bit PowerPC, so Word64 is inefficient - two Word32s are much
diff --git a/compiler/GHC/CmmToAsm/Reg/Linear/SPARC.hs b/compiler/GHC/CmmToAsm/Reg/Linear/SPARC.hs
index a2a0ee73f9..31e9a9dca0 100644
--- a/compiler/GHC/CmmToAsm/Reg/Linear/SPARC.hs
+++ b/compiler/GHC/CmmToAsm/Reg/Linear/SPARC.hs
@@ -15,7 +15,6 @@ import GHC.Utils.Panic
import GHC.Platform
import Data.Word
-import Data.Bits
--------------------------------------------------------------------------------
diff --git a/compiler/GHC/CmmToAsm/Reg/Linear/X86.hs b/compiler/GHC/CmmToAsm/Reg/Linear/X86.hs
index 42f63b5752..ba9b9cc966 100644
--- a/compiler/GHC/CmmToAsm/Reg/Linear/X86.hs
+++ b/compiler/GHC/CmmToAsm/Reg/Linear/X86.hs
@@ -13,7 +13,6 @@ import GHC.Platform
import GHC.Utils.Outputable
import Data.Word
-import Data.Bits
newtype FreeRegs = FreeRegs Word32
deriving (Show,Outputable)
diff --git a/compiler/GHC/CmmToAsm/Reg/Linear/X86_64.hs b/compiler/GHC/CmmToAsm/Reg/Linear/X86_64.hs
index 44eea342a4..801b7be146 100644
--- a/compiler/GHC/CmmToAsm/Reg/Linear/X86_64.hs
+++ b/compiler/GHC/CmmToAsm/Reg/Linear/X86_64.hs
@@ -13,7 +13,6 @@ import GHC.Platform
import GHC.Utils.Outputable
import Data.Word
-import Data.Bits
newtype FreeRegs = FreeRegs Word64
deriving (Show,Outputable)
diff --git a/compiler/GHC/CmmToAsm/X86/CodeGen.hs b/compiler/GHC/CmmToAsm/X86/CodeGen.hs
index 878f3387fb..7b803b2708 100644
--- a/compiler/GHC/CmmToAsm/X86/CodeGen.hs
+++ b/compiler/GHC/CmmToAsm/X86/CodeGen.hs
@@ -86,7 +86,6 @@ import GHC.Utils.Misc
import GHC.Types.Unique.Supply ( getUniqueM )
import Control.Monad
-import Data.Bits
import Data.Foldable (fold)
import Data.Int
import Data.Maybe
diff --git a/compiler/GHC/CmmToAsm/X86/Ppr.hs b/compiler/GHC/CmmToAsm/X86/Ppr.hs
index 97abf78006..2d12e90443 100644
--- a/compiler/GHC/CmmToAsm/X86/Ppr.hs
+++ b/compiler/GHC/CmmToAsm/X86/Ppr.hs
@@ -50,7 +50,6 @@ import GHC.Utils.Outputable
import GHC.Utils.Panic
import Data.Word
-import Data.Bits
-- -----------------------------------------------------------------------------
-- Printing this stuff out
diff --git a/compiler/GHC/CmmToC.hs b/compiler/GHC/CmmToC.hs
index 49f0567a81..5f6c0486bc 100644
--- a/compiler/GHC/CmmToC.hs
+++ b/compiler/GHC/CmmToC.hs
@@ -59,7 +59,6 @@ import GHC.Utils.Misc
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import Control.Monad.ST
-import Data.Bits
import Data.Char
import Data.List (intersperse)
import Data.Map (Map)
diff --git a/compiler/GHC/Core/Opt/ConstantFold.hs b/compiler/GHC/Core/Opt/ConstantFold.hs
index 3a397330d7..237a87d6c4 100644
--- a/compiler/GHC/Core/Opt/ConstantFold.hs
+++ b/compiler/GHC/Core/Opt/ConstantFold.hs
@@ -76,7 +76,6 @@ import Control.Applicative ( Alternative(..) )
import Control.Monad
import Data.Functor (($>))
-import Data.Bits as Bits
import qualified Data.ByteString as BS
import Data.Ratio
import Data.Word
@@ -129,9 +128,9 @@ primOpRules nm = \case
, equalArgs $> Lit zeroI8 ]
Int8NegOp -> mkPrimOpRule nm 1 [ unaryLit negOp
, semiInversePrimOp Int8NegOp ]
- Int8SllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt8 (const Bits.shiftL)
+ Int8SllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt8 (const shiftL)
, rightIdentity zeroI8 ]
- Int8SraOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt8 (const Bits.shiftR)
+ Int8SraOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt8 (const shiftR)
, rightIdentity zeroI8 ]
Int8SrlOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt8 $ const $ shiftRightLogical @Word8
, rightIdentity zeroI8 ]
@@ -167,7 +166,7 @@ primOpRules nm = \case
, equalArgs $> Lit zeroW8 ]
Word8NotOp -> mkPrimOpRule nm 1 [ unaryLit complementOp
, semiInversePrimOp Word8NotOp ]
- Word8SllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord (const Bits.shiftL) ]
+ Word8SllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord (const shiftL) ]
Word8SrlOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord $ const $ shiftRightLogical @Word8 ]
@@ -196,9 +195,9 @@ primOpRules nm = \case
, equalArgs $> Lit zeroI16 ]
Int16NegOp -> mkPrimOpRule nm 1 [ unaryLit negOp
, semiInversePrimOp Int16NegOp ]
- Int16SllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt16 (const Bits.shiftL)
+ Int16SllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt16 (const shiftL)
, rightIdentity zeroI16 ]
- Int16SraOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt16 (const Bits.shiftR)
+ Int16SraOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt16 (const shiftR)
, rightIdentity zeroI16 ]
Int16SrlOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt16 $ const $ shiftRightLogical @Word16
, rightIdentity zeroI16 ]
@@ -234,7 +233,7 @@ primOpRules nm = \case
, equalArgs $> Lit zeroW16 ]
Word16NotOp -> mkPrimOpRule nm 1 [ unaryLit complementOp
, semiInversePrimOp Word16NotOp ]
- Word16SllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord (const Bits.shiftL) ]
+ Word16SllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord (const shiftL) ]
Word16SrlOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord $ const $ shiftRightLogical @Word16 ]
@@ -263,9 +262,9 @@ primOpRules nm = \case
, equalArgs $> Lit zeroI32 ]
Int32NegOp -> mkPrimOpRule nm 1 [ unaryLit negOp
, semiInversePrimOp Int32NegOp ]
- Int32SllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt32 (const Bits.shiftL)
+ Int32SllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt32 (const shiftL)
, rightIdentity zeroI32 ]
- Int32SraOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt32 (const Bits.shiftR)
+ Int32SraOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt32 (const shiftR)
, rightIdentity zeroI32 ]
Int32SrlOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt32 $ const $ shiftRightLogical @Word32
, rightIdentity zeroI32 ]
@@ -301,7 +300,7 @@ primOpRules nm = \case
, equalArgs $> Lit zeroW32 ]
Word32NotOp -> mkPrimOpRule nm 1 [ unaryLit complementOp
, semiInversePrimOp Word32NotOp ]
- Word32SllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord (const Bits.shiftL) ]
+ Word32SllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord (const shiftL) ]
Word32SrlOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord $ const $ shiftRightLogical @Word32 ]
@@ -346,9 +345,9 @@ primOpRules nm = \case
, semiInversePrimOp IntNotOp ]
IntNegOp -> mkPrimOpRule nm 1 [ unaryLit negOp
, semiInversePrimOp IntNegOp ]
- IntSllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt (const Bits.shiftL)
+ IntSllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt (const shiftL)
, rightIdentityPlatform zeroi ]
- IntSraOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt (const Bits.shiftR)
+ IntSraOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt (const shiftR)
, rightIdentityPlatform zeroi ]
IntSrlOp -> mkPrimOpRule nm 2 [ shiftRule LitNumInt shiftRightLogicalNative
, rightIdentityPlatform zeroi ]
@@ -389,7 +388,7 @@ primOpRules nm = \case
, equalArgs >> retLit zerow ]
WordNotOp -> mkPrimOpRule nm 1 [ unaryLit complementOp
, semiInversePrimOp WordNotOp ]
- WordSllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord (const Bits.shiftL) ]
+ WordSllOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord (const shiftL) ]
WordSrlOp -> mkPrimOpRule nm 2 [ shiftRule LitNumWord shiftRightLogicalNative ]
-- coercions
diff --git a/compiler/GHC/CoreToStg/Prep.hs b/compiler/GHC/CoreToStg/Prep.hs
index 2e2c4d84af..74616683e3 100644
--- a/compiler/GHC/CoreToStg/Prep.hs
+++ b/compiler/GHC/CoreToStg/Prep.hs
@@ -77,7 +77,6 @@ import GHC.Types.TyThing
import GHC.Types.CostCentre ( CostCentre, ccFromThisModule )
import GHC.Types.Unique.Supply
-import Data.Bits
import Data.List ( unfoldr )
import Control.Monad
import qualified Data.Set as S
diff --git a/compiler/GHC/Data/Bitmap.hs b/compiler/GHC/Data/Bitmap.hs
index 5f6444ddc0..533dc725cd 100644
--- a/compiler/GHC/Data/Bitmap.hs
+++ b/compiler/GHC/Data/Bitmap.hs
@@ -19,7 +19,6 @@ import GHC.Prelude
import GHC.Platform
import GHC.Runtime.Heap.Layout
-import Data.Bits
{-|
A bitmap represented by a sequence of 'StgWord's on the /target/
diff --git a/compiler/GHC/Data/FastMutInt.hs b/compiler/GHC/Data/FastMutInt.hs
index e2e3a50601..3b78966577 100644
--- a/compiler/GHC/Data/FastMutInt.hs
+++ b/compiler/GHC/Data/FastMutInt.hs
@@ -15,7 +15,6 @@ module GHC.Data.FastMutInt(
import GHC.Prelude
-import Data.Bits
import GHC.Base
data FastMutInt = FastMutInt !(MutableByteArray# RealWorld)
diff --git a/compiler/GHC/Iface/Binary.hs b/compiler/GHC/Iface/Binary.hs
index a662ebb84b..293058f0ca 100644
--- a/compiler/GHC/Iface/Binary.hs
+++ b/compiler/GHC/Iface/Binary.hs
@@ -56,7 +56,6 @@ import GHC.Utils.Misc
import Data.Array
import Data.Array.IO
import Data.Array.Unsafe
-import Data.Bits
import Data.Char
import Data.Word
import Data.IORef
diff --git a/compiler/GHC/Parser/CharClass.hs b/compiler/GHC/Parser/CharClass.hs
index 6d09de764c..7834109e8c 100644
--- a/compiler/GHC/Parser/CharClass.hs
+++ b/compiler/GHC/Parser/CharClass.hs
@@ -18,7 +18,6 @@ module GHC.Parser.CharClass
import GHC.Prelude
-import Data.Bits ( Bits((.&.),(.|.)) )
import Data.Char ( ord, chr )
import Data.Word
import GHC.Utils.Panic
diff --git a/compiler/GHC/Parser/Lexer.x b/compiler/GHC/Parser/Lexer.x
index 9fa6d05cf0..fef3b8b8c3 100644
--- a/compiler/GHC/Parser/Lexer.x
+++ b/compiler/GHC/Parser/Lexer.x
@@ -77,7 +77,6 @@ import GHC.Prelude
-- base
import Control.Monad
-import Data.Bits
import Data.Char
import Data.List (stripPrefix, isInfixOf, partition)
import Data.Maybe
diff --git a/compiler/GHC/Prelude.hs b/compiler/GHC/Prelude.hs
index 95c2d4b190..d538adfefb 100644
--- a/compiler/GHC/Prelude.hs
+++ b/compiler/GHC/Prelude.hs
@@ -10,15 +10,17 @@
-- * Is compiled with -XNoImplicitPrelude
-- * Explicitly imports GHC.Prelude
-module GHC.Prelude (module X) where
+module GHC.Prelude
+ (module X
+ ,module Bits
+ ,shiftL, shiftR
+ ) where
+
-- We export the 'Semigroup' class but w/o the (<>) operator to avoid
-- clashing with the (Outputable.<>) operator which is heavily used
-- through GHC's code-base.
-import Prelude as X hiding ((<>))
-import Data.Foldable as X (foldl')
-
{-
Note [Why do we import Prelude here?]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -31,3 +33,56 @@ NoImplicitPrelude. There are two motivations for this:
giving a smoother development experience when adding new
extensions.
-}
+
+import Prelude as X hiding ((<>))
+import Data.Foldable as X (foldl')
+
+#if MIN_VERSION_base(4,15,0)
+import GHC.Bits as Bits hiding (shiftL, shiftR)
+# if defined(DEBUG)
+import qualified GHC.Bits as Bits (shiftL, shiftR)
+# endif
+
+#else
+--base <4.15
+import Data.Bits as Bits hiding (shiftL, shiftR)
+# if defined(DEBUG)
+import qualified Data.Bits as Bits (shiftL, shiftR)
+# endif
+#endif
+
+{- Note [Default to unsafe shifts inside GHC]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The safe shifts can introduce branches which come
+at the cost of performance. We still want the additional
+debugability for debug builds. So we define it as one or the
+other depending on the DEBUG setting.
+
+Why do we then continue on to re-export the rest of Data.Bits?
+If we would not what is likely to happen is:
+* Someone imports Data.Bits, uses xor. Things are fine.
+* They add a shift and get an ambigious definition error.
+* The are puzzled for a bit.
+* They either:
+ + Remove the import of Data.Bits and get an error because xor is not in scope.
+ + Add the hiding clause to the Data.Bits import for the shifts.
+
+Either is quite annoying. Simply re-exporting all of Data.Bits avoids this
+making for a smoother developer experience. At the cost of having a few more
+names in scope at all time. But that seems like a fair tradeoff.
+
+See also #19618
+-}
+
+-- We always want the Data.Bits method to show up for rules etc.
+{-# INLINE shiftL #-}
+{-# INLINE shiftR #-}
+shiftL, shiftR :: Bits.Bits a => a -> Int -> a
+#if defined(DEBUG)
+shiftL = Bits.shiftL
+shiftR = Bits.shiftR
+#else
+shiftL = Bits.unsafeShiftL
+shiftR = Bits.unsafeShiftR
+#endif
+
diff --git a/compiler/GHC/Runtime/Heap/Inspect.hs b/compiler/GHC/Runtime/Heap/Inspect.hs
index d6619e0e2f..d3acf5ffed 100644
--- a/compiler/GHC/Runtime/Heap/Inspect.hs
+++ b/compiler/GHC/Runtime/Heap/Inspect.hs
@@ -71,7 +71,7 @@ import Data.List ((\\))
import GHC.Exts
import qualified Data.Sequence as Seq
import Data.Sequence (viewl, ViewL(..))
-import Foreign
+import Foreign hiding (shiftL, shiftR)
import System.IO.Unsafe
---------------------------------------------
diff --git a/compiler/GHC/Runtime/Heap/Layout.hs b/compiler/GHC/Runtime/Heap/Layout.hs
index 7e4d5af136..2d402ae27a 100644
--- a/compiler/GHC/Runtime/Heap/Layout.hs
+++ b/compiler/GHC/Runtime/Heap/Layout.hs
@@ -57,7 +57,6 @@ import GHC.Utils.Outputable
import GHC.Utils.Panic
import Data.Word
-import Data.Bits
import Data.ByteString (ByteString)
{-
diff --git a/compiler/GHC/StgToByteCode.hs b/compiler/GHC/StgToByteCode.hs
index 4d9dc0b4e1..cf4f9c7f3c 100644
--- a/compiler/GHC/StgToByteCode.hs
+++ b/compiler/GHC/StgToByteCode.hs
@@ -71,7 +71,7 @@ import GHC.Types.Tickish
import Data.List ( genericReplicate, genericLength, intersperse
, partition, scanl', sort, sortBy, zip4, zip6, nub )
-import Foreign
+import Foreign hiding (shiftL, shiftR)
import Control.Monad
import Data.Char
diff --git a/compiler/GHC/StgToCmm/Prim.hs b/compiler/GHC/StgToCmm/Prim.hs
index fbd08b55a9..38cbd965b2 100644
--- a/compiler/GHC/StgToCmm/Prim.hs
+++ b/compiler/GHC/StgToCmm/Prim.hs
@@ -50,7 +50,6 @@ import GHC.Utils.Misc
import GHC.Utils.Panic
import Data.Maybe
-import Data.Bits ((.&.), bit)
import Control.Monad (liftM, when, unless)
------------------------------------------------------------------------
diff --git a/compiler/GHC/SysTools/Terminal.hs b/compiler/GHC/SysTools/Terminal.hs
index c7951e0b43..fb122865f0 100644
--- a/compiler/GHC/SysTools/Terminal.hs
+++ b/compiler/GHC/SysTools/Terminal.hs
@@ -12,7 +12,7 @@ import System.Console.Terminfo (SetupTermError, Terminal, getCapability,
import System.Posix (queryTerminal, stdError)
#elif defined(mingw32_HOST_OS)
import Control.Exception (catch, try)
-import Data.Bits ((.|.), (.&.))
+-- import Data.Bits ((.|.), (.&.))
import Foreign (Ptr, peek, with)
import qualified Graphics.Win32 as Win32
import qualified System.Win32 as Win32
diff --git a/compiler/GHC/Types/Basic.hs b/compiler/GHC/Types/Basic.hs
index f8725bf8fc..04fb58324f 100644
--- a/compiler/GHC/Types/Basic.hs
+++ b/compiler/GHC/Types/Basic.hs
@@ -110,7 +110,6 @@ import GHC.Utils.Panic
import GHC.Utils.Binary
import GHC.Types.SourceText
import Data.Data
-import Data.Bits
import qualified Data.Semigroup as Semi
{-
diff --git a/compiler/GHC/Types/Id/Info.hs b/compiler/GHC/Types/Id/Info.hs
index f9a7cacba8..399937265c 100644
--- a/compiler/GHC/Types/Id/Info.hs
+++ b/compiler/GHC/Types/Id/Info.hs
@@ -113,7 +113,6 @@ import GHC.Utils.Outputable
import GHC.Utils.Panic
import Data.Word
-import Data.Bits
import GHC.StgToCmm.Types (LambdaFormInfo (..))
diff --git a/compiler/GHC/Types/SrcLoc.hs b/compiler/GHC/Types/SrcLoc.hs
index 1ec91017ca..f90f6df109 100644
--- a/compiler/GHC/Types/SrcLoc.hs
+++ b/compiler/GHC/Types/SrcLoc.hs
@@ -123,7 +123,6 @@ import GHC.Data.FastString
import Control.DeepSeq
import Control.Applicative (liftA2)
-import Data.Bits
import Data.Data
import Data.List (sortBy, intercalate)
import Data.Function (on)
diff --git a/compiler/GHC/Types/Unique.hs b/compiler/GHC/Types/Unique.hs
index 4d19ba7f66..0735539910 100644
--- a/compiler/GHC/Types/Unique.hs
+++ b/compiler/GHC/Types/Unique.hs
@@ -59,7 +59,6 @@ import GHC.Utils.Panic
import GHC.Exts (indexCharOffAddr#, Char(..), Int(..))
import Data.Char ( chr, ord )
-import Data.Bits
{-
************************************************************************
diff --git a/compiler/GHC/Types/Unique/Supply.hs b/compiler/GHC/Types/Unique/Supply.hs
index 0d27bb6ceb..f3e2b4b353 100644
--- a/compiler/GHC/Types/Unique/Supply.hs
+++ b/compiler/GHC/Types/Unique/Supply.hs
@@ -39,7 +39,6 @@ import GHC.IO
import GHC.Utils.Monad
import Control.Monad
-import Data.Bits
import Data.Char
import GHC.Exts( Ptr(..), noDuplicate#, oneShot )
#if MIN_VERSION_GLASGOW_HASKELL(9,1,0,0)
diff --git a/compiler/GHC/Utils/Binary.hs b/compiler/GHC/Utils/Binary.hs
index daddd0ce0f..37b303a3cd 100644
--- a/compiler/GHC/Utils/Binary.hs
+++ b/compiler/GHC/Utils/Binary.hs
@@ -85,7 +85,7 @@ import GHC.Utils.Fingerprint
import GHC.Types.SrcLoc
import Control.DeepSeq
-import Foreign
+import Foreign hiding (shiftL, shiftR)
import Data.Array
import Data.Array.IO
import Data.Array.Unsafe
diff --git a/compiler/GHC/Utils/Misc.hs b/compiler/GHC/Utils/Misc.hs
index 3c31f32d42..c977f89078 100644
--- a/compiler/GHC/Utils/Misc.hs
+++ b/compiler/GHC/Utils/Misc.hs
@@ -160,7 +160,6 @@ import Data.Char ( isUpper, isAlphaNum, isSpace, chr, ord, isDigit, toUpp
import Data.Int
import Data.Ratio ( (%) )
import Data.Ord ( comparing )
-import Data.Bits
import Data.Word
import qualified Data.IntMap as IM
import qualified Data.Set as Set