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
26 #include "HsVersions.h"
29 GHC's own exception type.
32 ghcError :: GhcException -> a
33 ghcError e = throwDyn e
35 -- error messages all take the form
37 -- <location>: <error>
39 -- If the location is on the command line, or in GHC itself, then
40 -- <location>="ghc". All of the error types below correspond to
41 -- a <location> of "ghc", except for ProgramError (where the string is
42 -- assumed to contain a location already, so we don't print one).
45 = PhaseFailed String -- name of phase
46 ExitCode -- an external phase (eg. cpp) failed
47 | Interrupted -- someone pressed ^C
48 | UsageError String -- prints the short usage msg after the error
49 | CmdLineError String -- cmdline prob, but doesn't print usage
50 | Panic String -- the `impossible' happened
51 | InstallationError String -- an installation problem
52 | ProgramError String -- error in the user's code, probably
55 progName = unsafePerformIO (getProgName)
56 {-# NOINLINE progName #-}
58 short_usage = "Usage: For basic information, try the `--help' option."
60 instance Show GhcException where
61 showsPrec _ e@(ProgramError _) = showGhcException e
62 showsPrec _ e = showString progName . showString ": " . showGhcException e
64 showGhcException (UsageError str)
65 = showString str . showChar '\n' . showString short_usage
66 showGhcException (PhaseFailed phase code)
67 = showString "phase `" . showString phase .
68 showString "' failed (exitcode = " . shows int_code .
73 ExitSuccess -> (0::Int)
75 showGhcException (CmdLineError str)
77 showGhcException (ProgramError str)
79 showGhcException (InstallationError str)
81 showGhcException (Interrupted)
82 = showString "interrupted"
83 showGhcException (Panic s)
84 = showString ("panic! (the `impossible' happened, GHC version "
85 ++ cProjectVersion ++ "):\n\t"
87 ++ "Please report it as a compiler bug "
88 ++ "to glasgow-haskell-bugs@haskell.org,\n"
89 ++ "or http://sourceforge.net/projects/ghc/.\n\n")
91 ghcExceptionTc = mkTyCon "GhcException"
92 {-# NOINLINE ghcExceptionTc #-}
93 instance Typeable GhcException where
94 typeOf _ = mkAppTy ghcExceptionTc []
101 panic x = throwDyn (Panic x)
103 -- #-versions because panic can't return an unboxed int, and that's
104 -- what TAG_ is with GHC at the moment. Ugh. (Simon)
105 -- No, man -- Too Beautiful! (Will)
107 panic# :: String -> FastInt
108 panic# s = case (panic s) of () -> _ILIT 0
110 assertPanic :: String -> Int -> a
111 assertPanic file line =
112 throw (AssertionFailed
113 ("ASSERT failed! file " ++ file ++ ", line " ++ show line))