Embrace -XTypeInType, add -XStarIsType
[ghc.git] / libraries / base / GHC / Err.hs
1 {-# LANGUAGE Trustworthy #-}
2 {-# LANGUAGE NoImplicitPrelude, MagicHash, ImplicitParams #-}
3 {-# LANGUAGE RankNTypes, PolyKinds, DataKinds #-}
4 {-# OPTIONS_HADDOCK hide #-}
5
6 -----------------------------------------------------------------------------
7 -- |
8 -- Module : GHC.Err
9 -- Copyright : (c) The University of Glasgow, 1994-2002
10 -- License : see libraries/base/LICENSE
11 --
12 -- Maintainer : cvs-ghc@haskell.org
13 -- Stability : internal
14 -- Portability : non-portable (GHC extensions)
15 --
16 -- The "GHC.Err" module defines the code for the wired-in error functions,
17 -- which have a special type in the compiler (with \"open tyvars\").
18 --
19 -- We cannot define these functions in a module where they might be used
20 -- (e.g., "GHC.Base"), because the magical wired-in type will get confused
21 -- with what the typechecker figures out.
22 --
23 -----------------------------------------------------------------------------
24
25 module GHC.Err( absentErr, error, errorWithoutStackTrace, undefined ) where
26 import GHC.CString ()
27 import GHC.Types (Char, RuntimeRep)
28 import GHC.Stack.Types
29 import GHC.Prim
30 import GHC.Integer () -- Make sure Integer is compiled first
31 -- because GHC depends on it in a wired-in way
32 -- so the build system doesn't see the dependency
33 import {-# SOURCE #-} GHC.Exception
34 ( errorCallWithCallStackException
35 , errorCallException )
36
37 -- | 'error' stops execution and displays an error message.
38 error :: forall (r :: RuntimeRep). forall (a :: TYPE r).
39 HasCallStack => [Char] -> a
40 error s = raise# (errorCallWithCallStackException s ?callStack)
41 -- Bleh, we should be using 'GHC.Stack.callStack' instead of
42 -- '?callStack' here, but 'GHC.Stack.callStack' depends on
43 -- 'GHC.Stack.popCallStack', which is partial and depends on
44 -- 'error'.. Do as I say, not as I do.
45
46 -- | A variant of 'error' that does not produce a stack trace.
47 --
48 -- @since 4.9.0.0
49 errorWithoutStackTrace :: forall (r :: RuntimeRep). forall (a :: TYPE r).
50 [Char] -> a
51 errorWithoutStackTrace s = raise# (errorCallException s)
52
53
54 -- Note [Errors in base]
55 -- ~~~~~~~~~~~~~~~~~~~~~
56 -- As of base-4.9.0.0, `error` produces a stack trace alongside the
57 -- error message using the HasCallStack machinery. This provides
58 -- a partial stack trace, containing the call-site of each function
59 -- with a HasCallStack constraint.
60 --
61 -- In base, however, the only functions that have such constraints are
62 -- error and undefined, so the stack traces from partial functions in
63 -- base will never contain a call-site in user code. Instead we'll
64 -- usually just get the actual call to error. Base functions already
65 -- have a good habit of providing detailed error messages, including the
66 -- name of the offending partial function, so the partial stack-trace
67 -- does not provide any extra information, just noise. Thus, we export
68 -- the callstack-aware error, but within base we use the
69 -- errorWithoutStackTrace variant for more hygienic error messages.
70
71
72 -- | A special case of 'error'.
73 -- It is expected that compilers will recognize this and insert error
74 -- messages which are more appropriate to the context in which 'undefined'
75 -- appears.
76 undefined :: forall (r :: RuntimeRep). forall (a :: TYPE r).
77 HasCallStack => a
78 undefined = error "Prelude.undefined"
79
80 -- | Used for compiler-generated error message;
81 -- encoding saves bytes of string junk.
82 absentErr :: a
83 absentErr = errorWithoutStackTrace "Oops! The program has entered an `absent' argument!\n"