Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Common.Compiler
Description
Data types and helpers used to compose the compiler pipeline.
Synopsis
- data ErrorMsg
- data Error
- data Warning
- newtype Pass a = Pass (PassMonad a)
- class Monad m => MonadError e (m :: Type -> Type) | m -> e where
- throwError :: e -> m a
- catchError :: m a -> (e -> m a) -> m a
- runPass :: Pass a -> Either Error (a, [Warning])
- dump :: Pretty a => a -> Pass x
- unexpected :: MonadError Error m => String -> m a
- warn :: MonadWriter [Warning] m => Warning -> m ()
- todo :: MonadError Error m => String -> m a
- passIO :: Pass a -> IO (a, [Warning])
- liftEither :: MonadError e m => Either e a -> m a
- typeError :: MonadError Error m => String -> m a
Documentation
Type for error messages.
Types of compiler errors that can be thrown during compilation.
Constructors
Dump String | Halt compiler to dump output (not an error) |
UnexpectedError ErrorMsg | Internal error; should be unreachable |
UnimplementedError ErrorMsg | "It's a research artifact" |
TypeError ErrorMsg | Round peg in square hole |
ScopeError ErrorMsg | Identifier is out of scope |
NameError ErrorMsg | Invalid naming convention at binding |
PatternError ErrorMsg | Malformed pattern |
LexError ErrorMsg | Error encountered by scanner |
ParseError ErrorMsg | Error encountered by parser |
Instances
Eq Error Source # | |
Show Error Source # | |
MonadError Error Pass Source # | |
Defined in Common.Compiler | |
MonadError Error AnomalyFn Source # | |
Defined in IR.Pattern.Anomaly Methods throwError :: Error -> AnomalyFn a # catchError :: AnomalyFn a -> (Error -> AnomalyFn a) -> AnomalyFn a # | |
MonadError Error GenFn Source # | |
Defined in Codegen.Codegen |
Types of compiler warnings that can be logged during compilation.
Constructors
TypeWarning ErrorMsg | Warning about type |
NameWarning ErrorMsg | Warning related to identifier names |
PatternWarning ErrorMsg | Warning related to patterns |
The compiler pipeline monad; supports throwing errors, logging, etc.
Constructors
Pass (PassMonad a) |
class Monad m => MonadError e (m :: Type -> Type) | m -> e where #
The strategy of combining computations that can throw exceptions by bypassing bound functions from the point an exception is thrown to the point that it is handled.
Is parameterized over the type of error information and
the monad type constructor.
It is common to use
as the monad type constructor
for an error monad in which error descriptions take the form of strings.
In that case and many other common cases the resulting monad is already defined
as an instance of the Either
StringMonadError
class.
You can also define your own error type and/or use a monad type constructor
other than
or Either
String
.
In these cases you will have to explicitly define instances of the Either
IOError
MonadError
class.
(If you are using the deprecated Control.Monad.Error or
Control.Monad.Trans.Error, you may also have to define an Error
instance.)
Methods
throwError :: e -> m a #
Is used within a monadic computation to begin exception processing.
catchError :: m a -> (e -> m a) -> m a #
A handler function to handle previous errors and return to normal execution. A common idiom is:
do { action1; action2; action3 } `catchError` handler
where the action
functions can call throwError
.
Note that handler
and the do-block must have the same return type.
Instances
unexpected :: MonadError Error m => String -> m a Source #
Report unexpected compiler error and halt pipeline.
todo :: MonadError Error m => String -> m a Source #
Report unexpected compiler error and halt pipeline.
passIO :: Pass a -> IO (a, [Warning]) Source #
Execute compiler pass in I/O monad, exiting upon exception.
liftEither :: MonadError e m => Either e a -> m a #
Lifts an
into any Either
e
.MonadError
e
do { val <- liftEither =<< action1; action2 }
where action1
returns an Either
to represent errors.
Since: mtl-2.2.2