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 ExitCode -- an external phase (eg. cpp) failed
46 | Interrupted -- someone pressed ^C
47 | UsageError String -- prints the short usage msg after the error
48 | CmdLineError String -- cmdline prob, but doesn't print usage
49 | Panic String -- the `impossible' happened
50 | InstallationError String -- an installation problem
51 | ProgramError String -- error in the user's code, probably
54 progName = unsafePerformIO (getProgName)
55 {-# NOINLINE progName #-}
57 short_usage = "Usage: For basic information, try the `--help' option."
59 instance Show GhcException where
60 showsPrec _ e@(ProgramError _) = showGhcException e
61 showsPrec _ e = showString progName . showString ": " . showGhcException e
63 showGhcException (UsageError str)
64 = showString str . showChar '\n' . showString short_usage
65 showGhcException (PhaseFailed phase code)
66 = showString phase . showString " failed, code = " . shows code
67 showGhcException (CmdLineError str)
69 showGhcException (ProgramError str)
71 showGhcException (InstallationError str)
73 showGhcException (Interrupted)
74 = showString "interrupted"
75 showGhcException (Panic s)
76 = showString ("panic! (the `impossible' happened, GHC version "
77 ++ cProjectVersion ++ "):\n\t"
79 ++ "Please report it as a compiler bug "
80 ++ "to glasgow-haskell-bugs@haskell.org,\n"
81 ++ "or http://sourceforge.net/projects/ghc/.\n\n")
83 ghcExceptionTc = mkTyCon "GhcException"
84 {-# NOINLINE ghcExceptionTc #-}
85 instance Typeable GhcException where
86 typeOf _ = mkAppTy ghcExceptionTc []
93 panic x = throwDyn (Panic x)
95 -- #-versions because panic can't return an unboxed int, and that's
96 -- what TAG_ is with GHC at the moment. Ugh. (Simon)
97 -- No, man -- Too Beautiful! (Will)
99 panic# :: String -> FastInt
100 panic# s = case (panic s) of () -> _ILIT 0
102 assertPanic :: String -> Int -> a
103 assertPanic file line =
104 throw (AssertionFailed
105 ("ASSERT failed! file " ++ file ++ ", line " ++ show line))