2 % (c) The GRASP Project, Glasgow University, 1992-2000
4 \section{Panic error messages}
6 Defines basic funtions for printing error messages.
8 It's hard to put these functions anywhere else without causing
9 some unnecessary loops in the module dependency graph.
14 GhcException(..), ghcError, progName,
15 panic, panic#, assertPanic, trace,
19 #include "HsVersions.h"
26 import TRACE ( trace )
27 import UNSAFE_IO ( unsafePerformIO )
32 GHC's own exception type.
35 ghcError :: GhcException -> a
36 ghcError e = throwDyn e
38 -- error messages all take the form
40 -- <location>: <error>
42 -- If the location is on the command line, or in GHC itself, then
43 -- <location>="ghc". All of the error types below correspond to
44 -- a <location> of "ghc", except for ProgramError (where the string is
45 -- assumed to contain a location already, so we don't print one).
48 = PhaseFailed String -- name of phase
49 ExitCode -- an external phase (eg. cpp) failed
50 | Interrupted -- someone pressed ^C
51 | UsageError String -- prints the short usage msg after the error
52 | CmdLineError String -- cmdline prob, but doesn't print usage
53 | Panic String -- the `impossible' happened
54 | InstallationError String -- an installation problem
55 | ProgramError String -- error in the user's code, probably
58 progName = unsafePerformIO (getProgName)
59 {-# NOINLINE progName #-}
61 short_usage = "Usage: For basic information, try the `--help' option."
63 instance Show GhcException where
64 showsPrec _ e@(ProgramError _) = showGhcException e
65 showsPrec _ e = showString progName . showString ": " . showGhcException e
67 showGhcException (UsageError str)
68 = showString str . showChar '\n' . showString short_usage
69 showGhcException (PhaseFailed phase code)
70 = showString "phase `" . showString phase .
71 showString "' failed (exitcode = " . shows int_code .
76 ExitSuccess -> (0::Int)
78 showGhcException (CmdLineError str)
80 showGhcException (ProgramError str)
82 showGhcException (InstallationError str)
84 showGhcException (Interrupted)
85 = showString "interrupted"
86 showGhcException (Panic s)
87 = showString ("panic! (the `impossible' happened, GHC version "
88 ++ cProjectVersion ++ "):\n\t"
90 ++ "Please report it as a compiler bug "
91 ++ "to glasgow-haskell-bugs@haskell.org,\n"
92 ++ "or http://sourceforge.net/projects/ghc/.\n\n")
94 ghcExceptionTc = mkTyCon "GhcException"
95 {-# NOINLINE ghcExceptionTc #-}
96 instance Typeable GhcException where
97 typeOf _ = mkAppTy ghcExceptionTc []
104 panic x = throwDyn (Panic x)
106 -- #-versions because panic can't return an unboxed int, and that's
107 -- what TAG_ is with GHC at the moment. Ugh. (Simon)
108 -- No, man -- Too Beautiful! (Will)
110 panic# :: String -> FastInt
111 panic# s = case (panic s) of () -> _ILIT 0
113 assertPanic :: String -> Int -> a
114 assertPanic file line =
115 throw (AssertionFailed
116 ("ASSERT failed! file " ++ file ++ ", line " ++ show line))