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