module Futhark.Error
( CompilerError (..),
prettyCompilerError,
ErrorClass (..),
externalError,
externalErrorS,
InternalError (..),
compilerBug,
compilerBugS,
compilerLimitation,
compilerLimitationS,
internalErrorS,
)
where
import Control.Exception
import Control.Monad.Error.Class
import Data.Text qualified as T
import Futhark.Util.Pretty
import Prettyprinter.Render.Text (renderStrict)
data ErrorClass
= CompilerBug
| CompilerLimitation
deriving (ErrorClass -> ErrorClass -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ErrorClass -> ErrorClass -> Bool
$c/= :: ErrorClass -> ErrorClass -> Bool
== :: ErrorClass -> ErrorClass -> Bool
$c== :: ErrorClass -> ErrorClass -> Bool
Eq, Eq ErrorClass
ErrorClass -> ErrorClass -> Bool
ErrorClass -> ErrorClass -> Ordering
ErrorClass -> ErrorClass -> ErrorClass
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: ErrorClass -> ErrorClass -> ErrorClass
$cmin :: ErrorClass -> ErrorClass -> ErrorClass
max :: ErrorClass -> ErrorClass -> ErrorClass
$cmax :: ErrorClass -> ErrorClass -> ErrorClass
>= :: ErrorClass -> ErrorClass -> Bool
$c>= :: ErrorClass -> ErrorClass -> Bool
> :: ErrorClass -> ErrorClass -> Bool
$c> :: ErrorClass -> ErrorClass -> Bool
<= :: ErrorClass -> ErrorClass -> Bool
$c<= :: ErrorClass -> ErrorClass -> Bool
< :: ErrorClass -> ErrorClass -> Bool
$c< :: ErrorClass -> ErrorClass -> Bool
compare :: ErrorClass -> ErrorClass -> Ordering
$ccompare :: ErrorClass -> ErrorClass -> Ordering
Ord, Int -> ErrorClass -> ShowS
[ErrorClass] -> ShowS
ErrorClass -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ErrorClass] -> ShowS
$cshowList :: [ErrorClass] -> ShowS
show :: ErrorClass -> String
$cshow :: ErrorClass -> String
showsPrec :: Int -> ErrorClass -> ShowS
$cshowsPrec :: Int -> ErrorClass -> ShowS
Show)
data CompilerError
=
ExternalError (Doc AnsiStyle)
|
InternalError T.Text T.Text ErrorClass
prettyCompilerError :: CompilerError -> Doc AnsiStyle
prettyCompilerError :: CompilerError -> Doc AnsiStyle
prettyCompilerError (ExternalError Doc AnsiStyle
e) = Doc AnsiStyle
e
prettyCompilerError (InternalError Text
s Text
_ ErrorClass
_) = forall a ann. Pretty a => a -> Doc ann
pretty Text
s
externalError :: MonadError CompilerError m => Doc AnsiStyle -> m a
externalError :: forall (m :: * -> *) a.
MonadError CompilerError m =>
Doc AnsiStyle -> m a
externalError = forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc AnsiStyle -> CompilerError
ExternalError
externalErrorS :: MonadError CompilerError m => String -> m a
externalErrorS :: forall (m :: * -> *) a. MonadError CompilerError m => String -> m a
externalErrorS = forall (m :: * -> *) a.
MonadError CompilerError m =>
Doc AnsiStyle -> m a
externalError forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a ann. Pretty a => a -> Doc ann
pretty
internalErrorS :: MonadError CompilerError m => String -> Doc AnsiStyle -> m a
internalErrorS :: forall (m :: * -> *) a.
MonadError CompilerError m =>
String -> Doc AnsiStyle -> m a
internalErrorS String
s Doc AnsiStyle
d =
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall a b. (a -> b) -> a -> b
$ Text -> Text -> ErrorClass -> CompilerError
InternalError (String -> Text
T.pack String
s) (forall {ann}. Doc ann -> Text
p Doc AnsiStyle
d) ErrorClass
CompilerBug
where
p :: Doc ann -> Text
p = forall ann. SimpleDocStream ann -> Text
renderStrict forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall ann. LayoutOptions -> Doc ann -> SimpleDocStream ann
layoutSmart LayoutOptions
defaultLayoutOptions
data InternalError = Error ErrorClass T.Text
deriving (Int -> InternalError -> ShowS
[InternalError] -> ShowS
InternalError -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InternalError] -> ShowS
$cshowList :: [InternalError] -> ShowS
show :: InternalError -> String
$cshow :: InternalError -> String
showsPrec :: Int -> InternalError -> ShowS
$cshowsPrec :: Int -> InternalError -> ShowS
Show)
instance Exception InternalError
compilerBug :: T.Text -> a
compilerBug :: forall a. Text -> a
compilerBug = forall a e. Exception e => e -> a
throw forall b c a. (b -> c) -> (a -> b) -> a -> c
. ErrorClass -> Text -> InternalError
Error ErrorClass
CompilerBug
compilerLimitation :: T.Text -> a
compilerLimitation :: forall a. Text -> a
compilerLimitation = forall a e. Exception e => e -> a
throw forall b c a. (b -> c) -> (a -> b) -> a -> c
. ErrorClass -> Text -> InternalError
Error ErrorClass
CompilerLimitation
compilerBugS :: String -> a
compilerBugS :: forall a. String -> a
compilerBugS = forall a. Text -> a
compilerBug forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
compilerLimitationS :: String -> a
compilerLimitationS :: forall a. String -> a
compilerLimitationS = forall a. Text -> a
compilerLimitation forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack