summaryrefslogtreecommitdiff
path: root/libraries/base/GHC
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2013-06-05 18:01:54 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2013-06-06 14:38:35 +0100
commit8d87b5bf45082f29eefc911df1378fad327bf6fa (patch)
tree909bcb62f16d957cb14fbc65236db6e13f6c4e06 /libraries/base/GHC
parentf3c261bcc9dfec69abf0eff08758b4f0b126943e (diff)
downloadhaskell-8d87b5bf45082f29eefc911df1378fad327bf6fa.tar.gz
Re-jig SOURCE imports
* Do not have have an hs-boot file for Data.Typeable * Instead make all the loops go through GHC.Err (just a couple of magic functions) GHC.Exception (some non-exceptional functions) The main idea is a) don't involve classes in the hs-boot world b) loop through error cases where performance doesn't matter c) be careful not to SOURCE import things that are bottom, unless MkCore knows about them in eRROR_IDS, so that we see their strictness
Diffstat (limited to 'libraries/base/GHC')
-rw-r--r--libraries/base/GHC/Arr.lhs4
-rw-r--r--libraries/base/GHC/Base.lhs6
-rw-r--r--libraries/base/GHC/Err.lhs39
-rw-r--r--libraries/base/GHC/Err.lhs-boot14
-rw-r--r--libraries/base/GHC/Event/Array.hs1
-rw-r--r--libraries/base/GHC/Event/EPoll.hsc1
-rw-r--r--libraries/base/GHC/Event/Poll.hsc1
-rw-r--r--libraries/base/GHC/Exception.lhs19
-rw-r--r--libraries/base/GHC/Exception.lhs-boot19
-rw-r--r--libraries/base/GHC/ForeignPtr.hs1
-rw-r--r--libraries/base/GHC/IOArray.hs5
-rw-r--r--libraries/base/GHC/IORef.hs5
-rw-r--r--libraries/base/GHC/Int.hs14
-rw-r--r--libraries/base/GHC/MVar.hs5
-rw-r--r--libraries/base/GHC/Read.lhs1
-rw-r--r--libraries/base/GHC/Real.lhs25
-rw-r--r--libraries/base/GHC/Stable.lhs4
-rw-r--r--libraries/base/GHC/Word.hs2
18 files changed, 96 insertions, 70 deletions
diff --git a/libraries/base/GHC/Arr.lhs b/libraries/base/GHC/Arr.lhs
index 48bb41430d..acae5a8a3a 100644
--- a/libraries/base/GHC/Arr.lhs
+++ b/libraries/base/GHC/Arr.lhs
@@ -47,7 +47,7 @@ import GHC.Num
import GHC.ST
import GHC.Base
import GHC.List
-import GHC.Real
+import GHC.Real( fromIntegral )
import GHC.Show
infixl 9 !, //
@@ -185,7 +185,7 @@ can do better, so we override the default method for index.
-- Abstract these errors from the relevant index functions so that
-- the guts of the function will be small enough to inline.
-{-# NOINLINE indexError #-}
+{- # NOINLINE indexError #-}
indexError :: Show a => (a,a) -> a -> String -> b
indexError rng i tp
= error (showString "Ix{" . showString tp . showString "}.index: Index " .
diff --git a/libraries/base/GHC/Base.lhs b/libraries/base/GHC/Base.lhs
index 075f21d6ec..ec162efd90 100644
--- a/libraries/base/GHC/Base.lhs
+++ b/libraries/base/GHC/Base.lhs
@@ -101,8 +101,8 @@ module GHC.Base
module GHC.CString,
module GHC.Magic,
module GHC.Types,
- module GHC.Prim, -- Re-export GHC.Prim and GHC.Err, to avoid lots
- module GHC.Err -- of people having to import it explicitly
+ module GHC.Prim, -- Re-export GHC.Prim and [boot] GHC.Err, to avoid lots
+ module GHC.Err -- of people having to import it explicitly
)
where
@@ -111,7 +111,7 @@ import GHC.Classes
import GHC.CString
import GHC.Magic
import GHC.Prim
-import {-# SOURCE #-} GHC.Err
+import GHC.Err
import {-# SOURCE #-} GHC.IO (failIO)
-- This is not strictly speaking required by this module, but is an
diff --git a/libraries/base/GHC/Err.lhs b/libraries/base/GHC/Err.lhs
index 964bc0cda9..0837f2e627 100644
--- a/libraries/base/GHC/Err.lhs
+++ b/libraries/base/GHC/Err.lhs
@@ -1,6 +1,6 @@
\begin{code}
{-# LANGUAGE Trustworthy #-}
-{-# LANGUAGE CPP, NoImplicitPrelude #-}
+{-# LANGUAGE CPP, NoImplicitPrelude, MagicHash #-}
{-# OPTIONS_HADDOCK hide #-}
-----------------------------------------------------------------------------
@@ -23,20 +23,10 @@
-----------------------------------------------------------------------------
-- #hide
-module GHC.Err
- (
- absentErr
- , divZeroError
- , ratioZeroDenominatorError
- , overflowError
-
- , error
-
- , undefined
- ) where
-
+module GHC.Err( absentErr, error, undefined ) where
import GHC.Types
-import GHC.Exception
+import GHC.Prim
+import {-# SOURCE #-} GHC.Exception( errorCallException )
\end{code}
%*********************************************************
@@ -48,7 +38,7 @@ import GHC.Exception
\begin{code}
-- | 'error' stops execution and displays an error message.
error :: [Char] -> a
-error s = throw (ErrorCall s)
+error s = raise# (errorCallException s)
-- | A special case of 'error'.
-- It is expected that compilers will recognize this and insert error
@@ -70,25 +60,6 @@ encoding saves bytes of string junk.
\begin{code}
absentErr :: a
-
absentErr = error "Oops! The program has entered an `absent' argument!\n"
\end{code}
-Divide by zero and arithmetic overflow.
-We put them here because they are needed relatively early
-in the libraries before the Exception type has been defined yet.
-
-\begin{code}
-{-# NOINLINE divZeroError #-}
-divZeroError :: a
-divZeroError = throw DivideByZero
-
-{-# NOINLINE ratioZeroDenominatorError #-}
-ratioZeroDenominatorError :: a
-ratioZeroDenominatorError = throw RatioZeroDenominator
-
-{-# NOINLINE overflowError #-}
-overflowError :: a
-overflowError = throw Overflow
-\end{code}
-
diff --git a/libraries/base/GHC/Err.lhs-boot b/libraries/base/GHC/Err.lhs-boot
index cc39bc8e0a..1b9467e3ab 100644
--- a/libraries/base/GHC/Err.lhs-boot
+++ b/libraries/base/GHC/Err.lhs-boot
@@ -6,17 +6,17 @@
-- Ghc.Err.hs-boot
---------------------------------------------------------------------------
-module GHC.Err( error ) where
+module GHC.Err ( error, undefined ) where
+import GHC.Types( Char )
--- The type signature for 'error' is a gross hack.
--- First, we can't give an accurate type for error, because it mentions
+-- The type signature for 'error'/'undefined' is a gross hack:
+-- we can't give an accurate type for error, because it mentions
-- an open type variable.
--- Second, we can't even say error :: [Char] -> a, because Char is defined
--- in GHC.Base, and that would make Err.lhs-boot mutually recursive
--- with GHC.Base.
-- Fortunately it doesn't matter what type we give here because the
-- compiler will use its wired-in version. But we have
-- to mention 'error' so that it gets exported from this .hi-boot
-- file.
-error :: a
+
+error :: [Char] -> a
+undefined :: a
\end{code}
diff --git a/libraries/base/GHC/Event/Array.hs b/libraries/base/GHC/Event/Array.hs
index 5b811ef7a9..fbc2a971e6 100644
--- a/libraries/base/GHC/Event/Array.hs
+++ b/libraries/base/GHC/Event/Array.hs
@@ -33,7 +33,6 @@ import Foreign.ForeignPtr (ForeignPtr, withForeignPtr)
import Foreign.Ptr (Ptr, nullPtr, plusPtr)
import Foreign.Storable (Storable(..))
import GHC.Base
-import GHC.Err (undefined)
import GHC.ForeignPtr (mallocPlainForeignPtrBytes, newForeignPtr_)
import GHC.Num (Num(..))
import GHC.Real (fromIntegral)
diff --git a/libraries/base/GHC/Event/EPoll.hsc b/libraries/base/GHC/Event/EPoll.hsc
index 44c8bd9750..e253671ac1 100644
--- a/libraries/base/GHC/Event/EPoll.hsc
+++ b/libraries/base/GHC/Event/EPoll.hsc
@@ -52,7 +52,6 @@ import Foreign.Marshal.Utils (with)
import Foreign.Ptr (Ptr)
import Foreign.Storable (Storable(..))
import GHC.Base
-import GHC.Err (undefined)
import GHC.Num (Num(..))
import GHC.Real (ceiling, fromIntegral)
import GHC.Show (Show)
diff --git a/libraries/base/GHC/Event/Poll.hsc b/libraries/base/GHC/Event/Poll.hsc
index c5003ff24f..fc4b011d4d 100644
--- a/libraries/base/GHC/Event/Poll.hsc
+++ b/libraries/base/GHC/Event/Poll.hsc
@@ -37,7 +37,6 @@ import Foreign.Ptr (Ptr)
import Foreign.Storable (Storable(..))
import GHC.Base
import GHC.Conc.Sync (withMVar)
-import GHC.Err (undefined)
import GHC.Num (Num(..))
import GHC.Real (ceiling, fromIntegral)
import GHC.Show (Show)
diff --git a/libraries/base/GHC/Exception.lhs b/libraries/base/GHC/Exception.lhs
index ba40a89a91..7d40a94332 100644
--- a/libraries/base/GHC/Exception.lhs
+++ b/libraries/base/GHC/Exception.lhs
@@ -22,10 +22,16 @@
-----------------------------------------------------------------------------
-- #hide
-module GHC.Exception where
+module GHC.Exception
+ ( Exception(..) -- Class
+ , throw
+ , SomeException(..), ErrorCall(..), ArithException(..)
+ , divZeroException, overflowException, ratioZeroDenomException
+ , errorCallException
+ ) where
import Data.Maybe
-import {-# SOURCE #-} Data.Typeable (Typeable, cast)
+import Data.Typeable (Typeable, cast)
-- loop: Data.Typeable -> GHC.Err -> GHC.Exception
import GHC.Base
import GHC.Show
@@ -173,6 +179,9 @@ instance Exception ErrorCall
instance Show ErrorCall where
showsPrec _ (ErrorCall err) = showString err
+errorCallException :: String -> SomeException
+errorCallException s = toException (ErrorCall s)
+
-----
-- |Arithmetic exceptions.
@@ -185,6 +194,11 @@ data ArithException
| RatioZeroDenominator
deriving (Eq, Ord, Typeable)
+divZeroException, overflowException, ratioZeroDenomException :: SomeException
+divZeroException = toException DivideByZero
+overflowException = toException Overflow
+ratioZeroDenomException = toException RatioZeroDenominator
+
instance Exception ArithException
instance Show ArithException where
@@ -194,5 +208,4 @@ instance Show ArithException where
showsPrec _ DivideByZero = showString "divide by zero"
showsPrec _ Denormal = showString "denormal"
showsPrec _ RatioZeroDenominator = showString "Ratio has zero denominator"
-
\end{code}
diff --git a/libraries/base/GHC/Exception.lhs-boot b/libraries/base/GHC/Exception.lhs-boot
new file mode 100644
index 0000000000..9c3b0bf4f6
--- /dev/null
+++ b/libraries/base/GHC/Exception.lhs-boot
@@ -0,0 +1,19 @@
+\begin{code}
+{-# LANGUAGE Trustworthy #-}
+{-# LANGUAGE NoImplicitPrelude #-}
+
+---------------------------------------------------------------------------
+-- Ghc.Exception.hs-boot
+---------------------------------------------------------------------------
+
+module GHC.Exception ( SomeException, errorCallException,
+ divZeroException, overflowException, ratioZeroDenomException
+ ) where
+import GHC.Types( Char )
+
+-- These exports are nice, well-behaved, non-bottom values
+
+data SomeException
+divZeroException, overflowException, ratioZeroDenomException :: SomeException
+errorCallException :: [Char] -> SomeException
+\end{code}
diff --git a/libraries/base/GHC/ForeignPtr.hs b/libraries/base/GHC/ForeignPtr.hs
index a9c859a1ff..e8e23e5ca4 100644
--- a/libraries/base/GHC/ForeignPtr.hs
+++ b/libraries/base/GHC/ForeignPtr.hs
@@ -56,7 +56,6 @@ import GHC.Base
import GHC.IORef
import GHC.STRef ( STRef(..) )
import GHC.Ptr ( Ptr(..), FunPtr(..) )
-import GHC.Err
#include "Typeable.h"
diff --git a/libraries/base/GHC/IOArray.hs b/libraries/base/GHC/IOArray.hs
index 800b596923..8594e2ada5 100644
--- a/libraries/base/GHC/IOArray.hs
+++ b/libraries/base/GHC/IOArray.hs
@@ -1,5 +1,5 @@
{-# LANGUAGE Unsafe #-}
-{-# LANGUAGE NoImplicitPrelude #-}
+{-# LANGUAGE NoImplicitPrelude, DeriveDataTypeable #-}
{-# OPTIONS_GHC -funbox-strict-fields #-}
{-# OPTIONS_HADDOCK hide #-}
@@ -27,6 +27,7 @@ module GHC.IOArray (
import GHC.Base
import GHC.IO
import GHC.Arr
+import Data.Typeable.Internal
-- ---------------------------------------------------------------------------
-- | An 'IOArray' is a mutable, boxed, non-strict array in the 'IO' monad.
@@ -38,7 +39,7 @@ import GHC.Arr
--
--
-newtype IOArray i e = IOArray (STArray RealWorld i e)
+newtype IOArray i e = IOArray (STArray RealWorld i e) deriving( Typeable )
-- explicit instance because Haddock can't figure out a derived one
instance Eq (IOArray i e) where
diff --git a/libraries/base/GHC/IORef.hs b/libraries/base/GHC/IORef.hs
index a0ed0823ed..bb618341b4 100644
--- a/libraries/base/GHC/IORef.hs
+++ b/libraries/base/GHC/IORef.hs
@@ -1,5 +1,5 @@
{-# LANGUAGE Unsafe #-}
-{-# LANGUAGE NoImplicitPrelude, MagicHash #-}
+{-# LANGUAGE NoImplicitPrelude, MagicHash, DeriveDataTypeable #-}
{-# OPTIONS_GHC -funbox-strict-fields #-}
{-# OPTIONS_HADDOCK hide #-}
@@ -25,12 +25,13 @@ module GHC.IORef (
import GHC.Base
import GHC.STRef
import GHC.IO
+import Data.Typeable.Internal( Typeable )
-- ---------------------------------------------------------------------------
-- IORefs
-- |A mutable variable in the 'IO' monad
-newtype IORef a = IORef (STRef RealWorld a)
+newtype IORef a = IORef (STRef RealWorld a) deriving( Typeable )
-- explicit instance because Haddock can't figure out a derived one
instance Eq (IORef a) where
diff --git a/libraries/base/GHC/Int.hs b/libraries/base/GHC/Int.hs
index cad798152f..206a25b56e 100644
--- a/libraries/base/GHC/Int.hs
+++ b/libraries/base/GHC/Int.hs
@@ -1,6 +1,6 @@
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE CPP, NoImplicitPrelude, BangPatterns, MagicHash, UnboxedTuples,
- StandaloneDeriving #-}
+ StandaloneDeriving, DeriveDataTypeable #-}
{-# OPTIONS_HADDOCK hide #-}
-----------------------------------------------------------------------------
@@ -38,10 +38,10 @@ import GHC.Num
import GHC.Real
import GHC.Read
import GHC.Arr
-import GHC.Err
import GHC.Word hiding (uncheckedShiftL64#, uncheckedShiftRL64#)
import GHC.Show
import GHC.Float () -- for RealFrac methods
+import Data.Typeable
------------------------------------------------------------------------
@@ -51,7 +51,7 @@ import GHC.Float () -- for RealFrac methods
-- Int8 is represented in the same way as Int. Operations may assume
-- and must ensure that it holds only values from its logical range.
-data {-# CTYPE "HsInt8" #-} Int8 = I8# Int# deriving (Eq, Ord)
+data {-# CTYPE "HsInt8" #-} Int8 = I8# Int# deriving (Eq, Ord, Typeable)
-- ^ 8-bit signed integer type
instance Show Int8 where
@@ -210,7 +210,7 @@ instance FiniteBits Int8 where
-- Int16 is represented in the same way as Int. Operations may assume
-- and must ensure that it holds only values from its logical range.
-data {-# CTYPE "HsInt16" #-} Int16 = I16# Int# deriving (Eq, Ord)
+data {-# CTYPE "HsInt16" #-} Int16 = I16# Int# deriving (Eq, Ord, Typeable)
-- ^ 16-bit signed integer type
instance Show Int16 where
@@ -374,7 +374,7 @@ instance FiniteBits Int16 where
-- from its logical range.
#endif
-data {-# CTYPE "HsInt32" #-} Int32 = I32# Int# deriving (Eq, Ord)
+data {-# CTYPE "HsInt32" #-} Int32 = I32# Int# deriving (Eq, Ord, Typeable)
-- ^ 32-bit signed integer type
instance Show Int32 where
@@ -549,7 +549,7 @@ instance Ix Int32 where
#if WORD_SIZE_IN_BITS < 64
-data {-# CTYPE "HsInt64" #-} Int64 = I64# Int64#
+data {-# CTYPE "HsInt64" #-} Int64 = I64# Int64# deriving( Typeable )
-- ^ 64-bit signed integer type
instance Eq Int64 where
@@ -724,7 +724,7 @@ a `iShiftRA64#` b | b >=# 64# = if a `ltInt64#` (intToInt64# 0#)
-- Operations may assume and must ensure that it holds only values
-- from its logical range.
-data {-# CTYPE "HsInt64" #-} Int64 = I64# Int# deriving (Eq, Ord)
+data {-# CTYPE "HsInt64" #-} Int64 = I64# Int# deriving (Eq, Ord, Typeable)
-- ^ 64-bit signed integer type
instance Show Int64 where
diff --git a/libraries/base/GHC/MVar.hs b/libraries/base/GHC/MVar.hs
index cd2ca33dd8..b256c592f9 100644
--- a/libraries/base/GHC/MVar.hs
+++ b/libraries/base/GHC/MVar.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE Unsafe #-}
+{-# LANGUAGE Unsafe, DeriveDataTypeable #-}
{-# LANGUAGE NoImplicitPrelude, MagicHash, UnboxedTuples #-}
{-# OPTIONS_GHC -funbox-strict-fields #-}
{-# OPTIONS_HADDOCK hide #-}
@@ -32,8 +32,9 @@ module GHC.MVar (
import GHC.Base
import Data.Maybe
+import Data.Typeable
-data MVar a = MVar (MVar# RealWorld a)
+data MVar a = MVar (MVar# RealWorld a) deriving( Typeable )
{- ^
An 'MVar' (pronounced \"em-var\") is a synchronising variable, used
for communication between concurrent threads. It can be thought of
diff --git a/libraries/base/GHC/Read.lhs b/libraries/base/GHC/Read.lhs
index 5ad9527361..0729ff2145 100644
--- a/libraries/base/GHC/Read.lhs
+++ b/libraries/base/GHC/Read.lhs
@@ -68,7 +68,6 @@ import GHC.Real
import GHC.Float
import GHC.Show
import GHC.Base
-import GHC.Err
import GHC.Arr
\end{code}
diff --git a/libraries/base/GHC/Real.lhs b/libraries/base/GHC/Real.lhs
index d380c4aa38..87e78450d5 100644
--- a/libraries/base/GHC/Real.lhs
+++ b/libraries/base/GHC/Real.lhs
@@ -26,7 +26,7 @@ import GHC.Num
import GHC.List
import GHC.Enum
import GHC.Show
-import GHC.Err
+import {-# SOURCE #-} GHC.Exception( divZeroException, overflowException, ratioZeroDenomException )
#ifdef OPTIMISE_INTEGER_GCD_LCM
import GHC.Integer.GMP.Internals
@@ -43,6 +43,29 @@ default () -- Double isn't available yet,
%*********************************************************
%* *
+ Divide by zero and arithmetic overflow
+%* *
+%*********************************************************
+
+We put them here because they are needed relatively early
+in the libraries before the Exception type has been defined yet.
+
+\begin{code}
+{-# NOINLINE divZeroError #-}
+divZeroError :: a
+divZeroError = raise# divZeroException
+
+{-# NOINLINE ratioZeroDenominatorError #-}
+ratioZeroDenominatorError :: a
+ratioZeroDenominatorError = raise# ratioZeroDenomException
+
+{-# NOINLINE overflowError #-}
+overflowError :: a
+overflowError = raise# overflowException
+\end{code}
+
+%*********************************************************
+%* *
\subsection{The @Ratio@ and @Rational@ types}
%* *
%*********************************************************
diff --git a/libraries/base/GHC/Stable.lhs b/libraries/base/GHC/Stable.lhs
index 439689583b..ba7205415e 100644
--- a/libraries/base/GHC/Stable.lhs
+++ b/libraries/base/GHC/Stable.lhs
@@ -1,5 +1,5 @@
\begin{code}
-{-# LANGUAGE Unsafe #-}
+{-# LANGUAGE Unsafe, DeriveDataTypeable #-}
{-# LANGUAGE NoImplicitPrelude
, MagicHash
, UnboxedTuples
@@ -33,6 +33,7 @@ module GHC.Stable (
import GHC.Ptr
import GHC.Base
+import Data.Typeable.Internal
-----------------------------------------------------------------------------
-- Stable Pointers
@@ -49,6 +50,7 @@ A value of type @StablePtr a@ is a stable pointer to a Haskell
expression of type @a@.
-}
data {-# CTYPE "HsStablePtr" #-} StablePtr a = StablePtr (StablePtr# a)
+ deriving( Typeable )
-- |
-- Create a stable pointer referring to the given Haskell value.
diff --git a/libraries/base/GHC/Word.hs b/libraries/base/GHC/Word.hs
index d319333e56..75957df704 100644
--- a/libraries/base/GHC/Word.hs
+++ b/libraries/base/GHC/Word.hs
@@ -33,6 +33,7 @@ import Data.Maybe
import GHC.IntWord64
#endif
+-- import {-# SOURCE #-} GHC.Exception
import GHC.Base
import GHC.Enum
import GHC.Num
@@ -40,7 +41,6 @@ import GHC.Real
import GHC.Read
import GHC.Arr
import GHC.Show
-import GHC.Err
import GHC.Float () -- for RealFrac methods
------------------------------------------------------------------------