{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Rzk.TypeCheck.Monad where
import Control.Monad (unless, when)
import Control.Monad.Except (ExceptT,
MonadError (catchError, throwError),
runExceptT)
import Control.Monad.Reader (ReaderT (..), ask, asks, local)
import Control.Monad.Trans (lift)
import Control.Monad.Trans.State.Strict (State, get, modify', put,
runState)
import qualified Data.IntMap.Strict as IntMap
import qualified Data.IntSet as IntSet
import Debug.Trace (trace)
import Control.Monad.Foil (Distinct)
import qualified Control.Monad.Foil as Foil
import Language.Rzk.Foil.Names (TModality, VarIdent)
import Language.Rzk.Foil.Syntax (positionOfTerm)
import Rzk.TypeCheck.Context
import Rzk.TypeCheck.Display
import Rzk.TypeCheck.Error
data HoleEntry = HoleEntry
{ HoleEntry -> VarIdent
holeEntryName :: VarIdent
, HoleEntry -> Rendered
holeEntryType :: Rendered
, HoleEntry -> HoleModalInfo
holeEntryMode :: HoleModalInfo
} deriving (HoleEntry -> HoleEntry -> Bool
(HoleEntry -> HoleEntry -> Bool)
-> (HoleEntry -> HoleEntry -> Bool) -> Eq HoleEntry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HoleEntry -> HoleEntry -> Bool
== :: HoleEntry -> HoleEntry -> Bool
$c/= :: HoleEntry -> HoleEntry -> Bool
/= :: HoleEntry -> HoleEntry -> Bool
Eq, Int -> HoleEntry -> ShowS
[HoleEntry] -> ShowS
HoleEntry -> String
(Int -> HoleEntry -> ShowS)
-> (HoleEntry -> String)
-> ([HoleEntry] -> ShowS)
-> Show HoleEntry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HoleEntry -> ShowS
showsPrec :: Int -> HoleEntry -> ShowS
$cshow :: HoleEntry -> String
show :: HoleEntry -> String
$cshowList :: [HoleEntry] -> ShowS
showList :: [HoleEntry] -> ShowS
Show)
data HoleModalInfo = HoleModalInfo
{ HoleModalInfo -> TModality
holeItemModality :: TModality
, HoleModalInfo -> TModality
holeItemLocks :: TModality
, HoleModalInfo -> Bool
holeItemAccessible :: Bool
} deriving (HoleModalInfo -> HoleModalInfo -> Bool
(HoleModalInfo -> HoleModalInfo -> Bool)
-> (HoleModalInfo -> HoleModalInfo -> Bool) -> Eq HoleModalInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HoleModalInfo -> HoleModalInfo -> Bool
== :: HoleModalInfo -> HoleModalInfo -> Bool
$c/= :: HoleModalInfo -> HoleModalInfo -> Bool
/= :: HoleModalInfo -> HoleModalInfo -> Bool
Eq, Int -> HoleModalInfo -> ShowS
[HoleModalInfo] -> ShowS
HoleModalInfo -> String
(Int -> HoleModalInfo -> ShowS)
-> (HoleModalInfo -> String)
-> ([HoleModalInfo] -> ShowS)
-> Show HoleModalInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HoleModalInfo -> ShowS
showsPrec :: Int -> HoleModalInfo -> ShowS
$cshow :: HoleModalInfo -> String
show :: HoleModalInfo -> String
$cshowList :: [HoleModalInfo] -> ShowS
showList :: [HoleModalInfo] -> ShowS
Show)
data HoleTopeEntry = HoleTopeEntry
{ HoleTopeEntry -> Rendered
holeTopeValue :: Rendered
, HoleTopeEntry -> HoleModalInfo
holeTopeMode :: HoleModalInfo
} deriving (HoleTopeEntry -> HoleTopeEntry -> Bool
(HoleTopeEntry -> HoleTopeEntry -> Bool)
-> (HoleTopeEntry -> HoleTopeEntry -> Bool) -> Eq HoleTopeEntry
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HoleTopeEntry -> HoleTopeEntry -> Bool
== :: HoleTopeEntry -> HoleTopeEntry -> Bool
$c/= :: HoleTopeEntry -> HoleTopeEntry -> Bool
/= :: HoleTopeEntry -> HoleTopeEntry -> Bool
Eq, Int -> HoleTopeEntry -> ShowS
[HoleTopeEntry] -> ShowS
HoleTopeEntry -> String
(Int -> HoleTopeEntry -> ShowS)
-> (HoleTopeEntry -> String)
-> ([HoleTopeEntry] -> ShowS)
-> Show HoleTopeEntry
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HoleTopeEntry -> ShowS
showsPrec :: Int -> HoleTopeEntry -> ShowS
$cshow :: HoleTopeEntry -> String
show :: HoleTopeEntry -> String
$cshowList :: [HoleTopeEntry] -> ShowS
showList :: [HoleTopeEntry] -> ShowS
Show)
data HoleInfo = HoleInfo
{ HoleInfo -> Maybe VarIdent
holeName :: Maybe VarIdent
, HoleInfo -> Rendered
holeGoal :: Rendered
, HoleInfo -> Maybe (VarIdent, Rendered)
holeGoalShape :: Maybe (VarIdent, Rendered)
, HoleInfo -> [HoleEntry]
holeTermVars :: [HoleEntry]
, HoleInfo -> [HoleEntry]
holeCubeVars :: [HoleEntry]
, HoleInfo -> [HoleTopeEntry]
holeTopes :: [HoleTopeEntry]
, HoleInfo -> [Rendered]
holeCandidates :: [Rendered]
, HoleInfo -> [Rendered]
holeIntroductions :: [Rendered]
, HoleInfo -> Maybe String
holeDiagram :: Maybe String
, HoleInfo -> Maybe LocationInfo
holeLocation :: Maybe LocationInfo
} deriving (HoleInfo -> HoleInfo -> Bool
(HoleInfo -> HoleInfo -> Bool)
-> (HoleInfo -> HoleInfo -> Bool) -> Eq HoleInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HoleInfo -> HoleInfo -> Bool
== :: HoleInfo -> HoleInfo -> Bool
$c/= :: HoleInfo -> HoleInfo -> Bool
/= :: HoleInfo -> HoleInfo -> Bool
Eq, Int -> HoleInfo -> ShowS
[HoleInfo] -> ShowS
HoleInfo -> String
(Int -> HoleInfo -> ShowS)
-> (HoleInfo -> String) -> ([HoleInfo] -> ShowS) -> Show HoleInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HoleInfo -> ShowS
showsPrec :: Int -> HoleInfo -> ShowS
$cshow :: HoleInfo -> String
show :: HoleInfo -> String
$cshowList :: [HoleInfo] -> ShowS
showList :: [HoleInfo] -> ShowS
Show)
data CheckWarning
= LargeInductiveTypeWarning
VarIdent
VarIdent
(Maybe LocationInfo)
| MetaPrefixWarning
VarIdent
VarIdent
Int
Int
MetaPrefixRule
(Maybe LocationInfo)
| RSTTScopeWarning RSTTExtension String (Maybe LocationInfo)
| RSTTHoleWarning (Maybe LocationInfo)
| RSTTIncompleteWarning String (Maybe LocationInfo)
| OverhangWarning
String
String
[String]
(Maybe LocationInfo)
| TopeFamilyDomainWarning
String
String
(Maybe LocationInfo)
| FreeStandingRestrictionWarning
VarIdent
String
FragmentUse
(Maybe LocationInfo)
| MetaBinderWarning
VarIdent
VarIdent
String
(Maybe LocationInfo)
deriving (CheckWarning -> CheckWarning -> Bool
(CheckWarning -> CheckWarning -> Bool)
-> (CheckWarning -> CheckWarning -> Bool) -> Eq CheckWarning
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CheckWarning -> CheckWarning -> Bool
== :: CheckWarning -> CheckWarning -> Bool
$c/= :: CheckWarning -> CheckWarning -> Bool
/= :: CheckWarning -> CheckWarning -> Bool
Eq, Int -> CheckWarning -> ShowS
[CheckWarning] -> ShowS
CheckWarning -> String
(Int -> CheckWarning -> ShowS)
-> (CheckWarning -> String)
-> ([CheckWarning] -> ShowS)
-> Show CheckWarning
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CheckWarning -> ShowS
showsPrec :: Int -> CheckWarning -> ShowS
$cshow :: CheckWarning -> String
show :: CheckWarning -> String
$cshowList :: [CheckWarning] -> ShowS
showList :: [CheckWarning] -> ShowS
Show)
data RSTTExtension = RSTTModal | RSTTInterval | RSTTInductive | RSTTShapeDependency | RSTTUnsupported | RSTTSchematic
deriving (RSTTExtension -> RSTTExtension -> Bool
(RSTTExtension -> RSTTExtension -> Bool)
-> (RSTTExtension -> RSTTExtension -> Bool) -> Eq RSTTExtension
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RSTTExtension -> RSTTExtension -> Bool
== :: RSTTExtension -> RSTTExtension -> Bool
$c/= :: RSTTExtension -> RSTTExtension -> Bool
/= :: RSTTExtension -> RSTTExtension -> Bool
Eq, Int -> RSTTExtension -> ShowS
[RSTTExtension] -> ShowS
RSTTExtension -> String
(Int -> RSTTExtension -> ShowS)
-> (RSTTExtension -> String)
-> ([RSTTExtension] -> ShowS)
-> Show RSTTExtension
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RSTTExtension -> ShowS
showsPrec :: Int -> RSTTExtension -> ShowS
$cshow :: RSTTExtension -> String
show :: RSTTExtension -> String
$cshowList :: [RSTTExtension] -> ShowS
showList :: [RSTTExtension] -> ShowS
Show)
data FragmentUse
= UseBinder
| UseMotive
| UseData
| UseIdentity
| UseConcluded
deriving (FragmentUse -> FragmentUse -> Bool
(FragmentUse -> FragmentUse -> Bool)
-> (FragmentUse -> FragmentUse -> Bool) -> Eq FragmentUse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FragmentUse -> FragmentUse -> Bool
== :: FragmentUse -> FragmentUse -> Bool
$c/= :: FragmentUse -> FragmentUse -> Bool
/= :: FragmentUse -> FragmentUse -> Bool
Eq, Int -> FragmentUse -> ShowS
[FragmentUse] -> ShowS
FragmentUse -> String
(Int -> FragmentUse -> ShowS)
-> (FragmentUse -> String)
-> ([FragmentUse] -> ShowS)
-> Show FragmentUse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FragmentUse -> ShowS
showsPrec :: Int -> FragmentUse -> ShowS
$cshow :: FragmentUse -> String
show :: FragmentUse -> String
$cshowList :: [FragmentUse] -> ShowS
showList :: [FragmentUse] -> ShowS
Show)
warningLocation :: CheckWarning -> Maybe LocationInfo
warningLocation :: CheckWarning -> Maybe LocationInfo
warningLocation (LargeInductiveTypeWarning VarIdent
_ VarIdent
_ Maybe LocationInfo
loc) = Maybe LocationInfo
loc
warningLocation (MetaPrefixWarning VarIdent
_ VarIdent
_ Int
_ Int
_ MetaPrefixRule
_ Maybe LocationInfo
loc) = Maybe LocationInfo
loc
warningLocation (RSTTScopeWarning RSTTExtension
_ String
_ Maybe LocationInfo
loc) = Maybe LocationInfo
loc
warningLocation (RSTTIncompleteWarning String
_ Maybe LocationInfo
loc) = Maybe LocationInfo
loc
warningLocation (RSTTHoleWarning Maybe LocationInfo
loc) = Maybe LocationInfo
loc
warningLocation (OverhangWarning String
_ String
_ [String]
_ Maybe LocationInfo
loc) = Maybe LocationInfo
loc
warningLocation (TopeFamilyDomainWarning String
_ String
_ Maybe LocationInfo
loc) = Maybe LocationInfo
loc
warningLocation (FreeStandingRestrictionWarning VarIdent
_ String
_ FragmentUse
_ Maybe LocationInfo
loc) = Maybe LocationInfo
loc
warningLocation (MetaBinderWarning VarIdent
_ VarIdent
_ String
_ Maybe LocationInfo
loc) = Maybe LocationInfo
loc
data MetaPrefixRule
= MetaPrefixBoth
| MetaPrefixStrictOnly
deriving (MetaPrefixRule -> MetaPrefixRule -> Bool
(MetaPrefixRule -> MetaPrefixRule -> Bool)
-> (MetaPrefixRule -> MetaPrefixRule -> Bool) -> Eq MetaPrefixRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MetaPrefixRule -> MetaPrefixRule -> Bool
== :: MetaPrefixRule -> MetaPrefixRule -> Bool
$c/= :: MetaPrefixRule -> MetaPrefixRule -> Bool
/= :: MetaPrefixRule -> MetaPrefixRule -> Bool
Eq, Int -> MetaPrefixRule -> ShowS
[MetaPrefixRule] -> ShowS
MetaPrefixRule -> String
(Int -> MetaPrefixRule -> ShowS)
-> (MetaPrefixRule -> String)
-> ([MetaPrefixRule] -> ShowS)
-> Show MetaPrefixRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MetaPrefixRule -> ShowS
showsPrec :: Int -> MetaPrefixRule -> ShowS
$cshow :: MetaPrefixRule -> String
show :: MetaPrefixRule -> String
$cshowList :: [MetaPrefixRule] -> ShowS
showList :: [MetaPrefixRule] -> ShowS
Show)
data CheckLog = CheckLog
{ CheckLog -> [HoleInfo]
logHolesRev :: [HoleInfo]
, CheckLog -> [CheckWarning]
logWarningsRev :: [CheckWarning]
, CheckLog -> IntSet
logSchematicCache :: IntSet.IntSet
, CheckLog -> IntMap (Maybe Int)
logSchematicObjectFamilies :: IntMap.IntMap (Maybe Int)
}
emptyCheckLog :: CheckLog
emptyCheckLog :: CheckLog
emptyCheckLog = [HoleInfo]
-> [CheckWarning] -> IntSet -> IntMap (Maybe Int) -> CheckLog
CheckLog [] [] IntSet
IntSet.empty IntMap (Maybe Int)
forall a. IntMap a
IntMap.empty
checkLog :: CheckLog -> ([HoleInfo], [CheckWarning])
checkLog :: CheckLog -> ([HoleInfo], [CheckWarning])
checkLog (CheckLog [HoleInfo]
holes [CheckWarning]
warnings IntSet
_ IntMap (Maybe Int)
_) = ([HoleInfo] -> [HoleInfo]
forall a. [a] -> [a]
reverse [HoleInfo]
holes, [CheckWarning] -> [CheckWarning]
forall a. [a] -> [a]
reverse [CheckWarning]
warnings)
type TypeCheck n =
ReaderT (Context n)
(ExceptT TypeErrorInScopedContext (State CheckLog))
runTypeCheckWith
:: Context n -> TypeCheck n a
-> (Either TypeErrorInScopedContext a, ([HoleInfo], [CheckWarning]))
runTypeCheckWith :: forall (n :: S) a.
Context n
-> TypeCheck n a
-> (Either TypeErrorInScopedContext a,
([HoleInfo], [CheckWarning]))
runTypeCheckWith Context n
ctx TypeCheck n a
tc =
case State CheckLog (Either TypeErrorInScopedContext a)
-> CheckLog -> (Either TypeErrorInScopedContext a, CheckLog)
forall s a. State s a -> s -> (a, s)
runState (ExceptT TypeErrorInScopedContext (StateT CheckLog Identity) a
-> State CheckLog (Either TypeErrorInScopedContext a)
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT (TypeCheck n a
-> Context n
-> ExceptT TypeErrorInScopedContext (StateT CheckLog Identity) a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT TypeCheck n a
tc Context n
ctx)) CheckLog
emptyCheckLog of
(Either TypeErrorInScopedContext a
result, CheckLog
logged) -> (Either TypeErrorInScopedContext a
result, CheckLog -> ([HoleInfo], [CheckWarning])
checkLog CheckLog
logged)
runTypeCheck :: TypeCheck Foil.VoidS a -> Either TypeErrorInScopedContext a
runTypeCheck :: forall a. TypeCheck 'VoidS a -> Either TypeErrorInScopedContext a
runTypeCheck = Context 'VoidS
-> TypeCheck 'VoidS a -> Either TypeErrorInScopedContext a
forall (n :: S) a.
Context n -> TypeCheck n a -> Either TypeErrorInScopedContext a
runTypeCheckIn Context 'VoidS
emptyContext
runTypeCheckIn :: Context n -> TypeCheck n a -> Either TypeErrorInScopedContext a
runTypeCheckIn :: forall (n :: S) a.
Context n -> TypeCheck n a -> Either TypeErrorInScopedContext a
runTypeCheckIn Context n
ctx TypeCheck n a
tc = (Either TypeErrorInScopedContext a, ([HoleInfo], [CheckWarning]))
-> Either TypeErrorInScopedContext a
forall a b. (a, b) -> a
fst (Context n
-> TypeCheck n a
-> (Either TypeErrorInScopedContext a,
([HoleInfo], [CheckWarning]))
forall (n :: S) a.
Context n
-> TypeCheck n a
-> (Either TypeErrorInScopedContext a,
([HoleInfo], [CheckWarning]))
runTypeCheckWith Context n
ctx TypeCheck n a
tc)
inContext :: Context l -> TypeCheck l a -> TypeCheck n a
inContext :: forall (l :: S) a (n :: S).
Context l -> TypeCheck l a -> TypeCheck n a
inContext Context l
ctx = ExceptT TypeErrorInScopedContext (StateT CheckLog Identity) a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall (m :: * -> *) a. Monad m => m a -> ReaderT (Context n) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (ExceptT TypeErrorInScopedContext (StateT CheckLog Identity) a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a)
-> (TypeCheck l a
-> ExceptT TypeErrorInScopedContext (StateT CheckLog Identity) a)
-> TypeCheck l a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TypeCheck l a
-> Context l
-> ExceptT TypeErrorInScopedContext (StateT CheckLog Identity) a)
-> Context l
-> TypeCheck l a
-> ExceptT TypeErrorInScopedContext (StateT CheckLog Identity) a
forall a b c. (a -> b -> c) -> b -> a -> c
flip TypeCheck l a
-> Context l
-> ExceptT TypeErrorInScopedContext (StateT CheckLog Identity) a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT Context l
ctx
issueTypeError :: Distinct n => TypeError n -> TypeCheck n a
issueTypeError :: forall (n :: S) a. Distinct n => TypeError n -> TypeCheck n a
issueTypeError TypeError n
err = do
ctx <- ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
(Context n)
forall r (m :: * -> *). MonadReader r m => m r
ask
throwError (TypeErrorInScopedContext ctx err)
issueWarning :: String -> TypeCheck n ()
issueWarning :: forall (n :: S). String -> TypeCheck n ()
issueWarning String
message = String -> TypeCheck n () -> TypeCheck n ()
forall a. String -> a -> a
trace (String
"Warning: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
message) (() -> TypeCheck n ()
forall a.
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall (m :: * -> *) a. Monad m => a -> m a
return ())
trace' :: Verbosity -> Verbosity -> String -> a -> a
trace' :: forall a. Verbosity -> Verbosity -> String -> a -> a
trace' Verbosity
Silent Verbosity
_ String
_ = a -> a
forall a. a -> a
id
trace' Verbosity
Normal Verbosity
Debug String
_ = a -> a
forall a. a -> a
id
trace' Verbosity
_ Verbosity
_ String
msg = String -> a -> a
forall a. String -> a -> a
trace String
msg
traceTypeCheck :: Verbosity -> String -> TypeCheck n a -> TypeCheck n a
traceTypeCheck :: forall (n :: S) a.
Verbosity -> String -> TypeCheck n a -> TypeCheck n a
traceTypeCheck Verbosity
verbosity String
msg TypeCheck n a
action = do
configuredVerbosity <- (Context n -> Verbosity)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
Verbosity
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Context n -> Verbosity
forall (n :: S). Context n -> Verbosity
ctxVerbosity
trace' configuredVerbosity verbosity msg action
localVerbosity :: Verbosity -> TypeCheck n a -> TypeCheck n a
localVerbosity :: forall (n :: S) a. Verbosity -> TypeCheck n a -> TypeCheck n a
localVerbosity Verbosity
verbosity = (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a.
(Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local ((Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a)
-> (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a b. (a -> b) -> a -> b
$ \Context n
ctx -> Context n
ctx { ctxVerbosity = verbosity }
localRenderBackend :: Maybe RenderBackend -> TypeCheck n a -> TypeCheck n a
localRenderBackend :: forall (n :: S) a.
Maybe RenderBackend -> TypeCheck n a -> TypeCheck n a
localRenderBackend Maybe RenderBackend
backend = (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a.
(Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local ((Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a)
-> (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a b. (a -> b) -> a -> b
$ \Context n
ctx -> Context n
ctx { ctxRenderBackend = backend }
localHideTerm :: Bool -> TypeCheck n a -> TypeCheck n a
localHideTerm :: forall (n :: S) a. Bool -> TypeCheck n a -> TypeCheck n a
localHideTerm Bool
hide = (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a.
(Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local ((Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a)
-> (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a b. (a -> b) -> a -> b
$ \Context n
ctx -> Context n
ctx { ctxRenderHideTerm = hide }
localWarnOverhang :: Bool -> TypeCheck n a -> TypeCheck n a
localWarnOverhang :: forall (n :: S) a. Bool -> TypeCheck n a -> TypeCheck n a
localWarnOverhang Bool
warn = (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a.
(Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local ((Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a)
-> (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a b. (a -> b) -> a -> b
$ \Context n
ctx -> Context n
ctx { ctxWarnOverhang = warn }
localWarnTopeFamilyDomain :: Bool -> TypeCheck n a -> TypeCheck n a
localWarnTopeFamilyDomain :: forall (n :: S) a. Bool -> TypeCheck n a -> TypeCheck n a
localWarnTopeFamilyDomain Bool
warn = (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a.
(Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local ((Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a)
-> (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a b. (a -> b) -> a -> b
$ \Context n
ctx -> Context n
ctx { ctxWarnTopeFamilyDomain = warn }
localWarnFreeStandingRestriction :: Bool -> TypeCheck n a -> TypeCheck n a
localWarnFreeStandingRestriction :: forall (n :: S) a. Bool -> TypeCheck n a -> TypeCheck n a
localWarnFreeStandingRestriction Bool
warn =
(Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a.
(Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local ((Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a)
-> (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a b. (a -> b) -> a -> b
$ \Context n
ctx -> Context n
ctx { ctxStandaloneWarnFreeStandingRestriction = warn }
localWarnShapeDependency :: Bool -> TypeCheck n a -> TypeCheck n a
localWarnShapeDependency :: forall (n :: S) a. Bool -> TypeCheck n a -> TypeCheck n a
localWarnShapeDependency Bool
warn = (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a.
(Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local ((Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a)
-> (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a b. (a -> b) -> a -> b
$ \Context n
ctx -> Context n
ctx { ctxStandaloneWarnShapeDependency = warn }
localWarnMetaBinder :: Bool -> TypeCheck n a -> TypeCheck n a
localWarnMetaBinder :: forall (n :: S) a. Bool -> TypeCheck n a -> TypeCheck n a
localWarnMetaBinder Bool
warn = (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a.
(Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local ((Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a)
-> (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a b. (a -> b) -> a -> b
$ \Context n
ctx -> Context n
ctx { ctxStandaloneWarnMetaBinder = warn }
localMetaPrefixSensitivity :: MetaPrefixSensitivity -> TypeCheck n a -> TypeCheck n a
localMetaPrefixSensitivity :: forall (n :: S) a.
MetaPrefixSensitivity -> TypeCheck n a -> TypeCheck n a
localMetaPrefixSensitivity MetaPrefixSensitivity
sensitivity =
(Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a.
(Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local ((Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a)
-> (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a b. (a -> b) -> a -> b
$ \Context n
ctx -> Context n
ctx { ctxMetaPrefixSensitivity = sensitivity }
hidingTerm :: TypeCheck n a -> TypeCheck n a
hidingTerm :: forall (n :: S) a. TypeCheck n a -> TypeCheck n a
hidingTerm = Bool -> TypeCheck n a -> TypeCheck n a
forall (n :: S) a. Bool -> TypeCheck n a -> TypeCheck n a
localHideTerm Bool
True
switchVariance :: TypeCheck n a -> TypeCheck n a
switchVariance :: forall (n :: S) a. TypeCheck n a -> TypeCheck n a
switchVariance = (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a.
(Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local ((Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a)
-> (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a b. (a -> b) -> a -> b
$ \Context n
ctx -> Context n
ctx { ctxCovariance = switch (ctxCovariance ctx) }
where
switch :: Covariance -> Covariance
switch Covariance
Covariant = Covariance
Contravariant
switch Covariance
Contravariant = Covariance
Covariant
switch Covariance
Invariant = Covariance
Invariant
setVariance :: Covariance -> TypeCheck n a -> TypeCheck n a
setVariance :: forall (n :: S) a. Covariance -> TypeCheck n a -> TypeCheck n a
setVariance Covariance
variance = (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a.
(Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local ((Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a)
-> (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a b. (a -> b) -> a -> b
$ \Context n
ctx -> Context n
ctx { ctxCovariance = variance }
maxActionStackDepth :: Int
maxActionStackDepth :: Int
maxActionStackDepth = Int
1000
performing :: Distinct n => Action n -> TypeCheck n a -> TypeCheck n a
performing :: forall (n :: S) a.
Distinct n =>
Action n -> TypeCheck n a -> TypeCheck n a
performing Action n
action TypeCheck n a
tc = do
ctx@Context{..} <- ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
(Context n)
forall r (m :: * -> *). MonadReader r m => m r
ask
unless (ctxActionStackDepth < maxActionStackDepth) $
issueTypeError $ TypeErrorOther "maximum depth reached"
let ctx' = Context n
ctx
{ ctxActionStack = action : ctxActionStack
, ctxActionStackDepth = ctxActionStackDepth + 1
, ctxLocation = narrowLocation action ctxLocation
}
if ctxVerbosity <= Debug
then trace (ppAction (namingOfContext ctx) ctxActionStackDepth action) $
local (const ctx') tc
else local (const ctx') tc
narrowLocation :: Action n -> Maybe LocationInfo -> Maybe LocationInfo
narrowLocation :: forall (n :: S).
Action n -> Maybe LocationInfo -> Maybe LocationInfo
narrowLocation Action n
action Maybe LocationInfo
loc = case Action n -> Maybe (Term n)
forall {n :: S}. Action n -> Maybe (Term n)
termOf Action n
action of
Just Term n
term | Just RzkPosition
pos <- Term n -> Maybe RzkPosition
forall (n :: S). Term n -> Maybe RzkPosition
positionOfTerm Term n
term -> RzkPosition -> LocationInfo -> LocationInfo
atPosition RzkPosition
pos (LocationInfo -> LocationInfo)
-> Maybe LocationInfo -> Maybe LocationInfo
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe LocationInfo
loc
Maybe (Term n)
_ -> Maybe LocationInfo
loc
where
termOf :: Action n -> Maybe (Term n)
termOf (ActionTypeCheck Term n
term TermT n
_) = Term n -> Maybe (Term n)
forall a. a -> Maybe a
Just Term n
term
termOf (ActionInfer Term n
term) = Term n -> Maybe (Term n)
forall a. a -> Maybe a
Just Term n
term
termOf Action n
_ = Maybe (Term n)
forall a. Maybe a
Nothing
modifyLog :: (CheckLog -> CheckLog) -> TypeCheck n ()
modifyLog :: forall (n :: S). (CheckLog -> CheckLog) -> TypeCheck n ()
modifyLog CheckLog -> CheckLog
f = ExceptT TypeErrorInScopedContext (StateT CheckLog Identity) ()
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
()
forall (m :: * -> *) a. Monad m => m a -> ReaderT (Context n) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (State CheckLog ()
-> ExceptT TypeErrorInScopedContext (StateT CheckLog Identity) ()
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT TypeErrorInScopedContext m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift ((CheckLog -> CheckLog) -> State CheckLog ()
forall (m :: * -> *) s. Monad m => (s -> s) -> StateT s m ()
modify' CheckLog -> CheckLog
f))
suppressing :: TypeCheck n a -> TypeCheck n a
suppressing :: forall (n :: S) a. TypeCheck n a -> TypeCheck n a
suppressing TypeCheck n a
action = do
saved <- ExceptT
TypeErrorInScopedContext (StateT CheckLog Identity) CheckLog
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
CheckLog
forall (m :: * -> *) a. Monad m => m a -> ReaderT (Context n) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (State CheckLog CheckLog
-> ExceptT
TypeErrorInScopedContext (StateT CheckLog Identity) CheckLog
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT TypeErrorInScopedContext m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift State CheckLog CheckLog
forall (m :: * -> *) s. Monad m => StateT s m s
get)
let restore = ExceptT TypeErrorInScopedContext (StateT CheckLog Identity) ()
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
()
forall (m :: * -> *) a. Monad m => m a -> ReaderT (Context n) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (State CheckLog ()
-> ExceptT TypeErrorInScopedContext (StateT CheckLog Identity) ()
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT TypeErrorInScopedContext m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (CheckLog -> State CheckLog ()
forall (m :: * -> *) s. Monad m => s -> StateT s m ()
put CheckLog
saved))
result <- action `catchError` \TypeErrorInScopedContext
err -> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
()
restore ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
()
-> TypeCheck n a -> TypeCheck n a
forall a b.
ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
b
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> TypeErrorInScopedContext -> TypeCheck n a
forall a.
TypeErrorInScopedContext
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError TypeErrorInScopedContext
err
restore
return result
recordHoleInfo :: Distinct n => HoleInfo -> TypeCheck n ()
recordHoleInfo :: forall (n :: S). Distinct n => HoleInfo -> TypeCheck n ()
recordHoleInfo HoleInfo
info = do
(CheckLog -> CheckLog) -> TypeCheck n ()
forall (n :: S). (CheckLog -> CheckLog) -> TypeCheck n ()
modifyLog ((CheckLog -> CheckLog) -> TypeCheck n ())
-> (CheckLog -> CheckLog) -> TypeCheck n ()
forall a b. (a -> b) -> a -> b
$ \CheckLog
l -> CheckLog
l { logHolesRev = info : logHolesRev l }
enabled <- (Context n -> Bool)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
Bool
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Context n -> Bool
forall (n :: S). Context n -> Bool
rsttSafeEnabled
when enabled $ recordCheckWarning (RSTTHoleWarning (holeLocation info))
recordCheckWarning :: Distinct n => CheckWarning -> TypeCheck n ()
recordCheckWarning :: forall (n :: S). Distinct n => CheckWarning -> TypeCheck n ()
recordCheckWarning CheckWarning
warning = do
(CheckLog -> CheckLog) -> TypeCheck n ()
forall (n :: S). (CheckLog -> CheckLog) -> TypeCheck n ()
modifyLog ((CheckLog -> CheckLog) -> TypeCheck n ())
-> (CheckLog -> CheckLog) -> TypeCheck n ()
forall a b. (a -> b) -> a -> b
$ \CheckLog
l ->
if CheckWarning
warning CheckWarning -> [CheckWarning] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` CheckLog -> [CheckWarning]
logWarningsRev CheckLog
l then CheckLog
l
else CheckLog
l { logWarningsRev = warning : logWarningsRev l }
mode <- (Context n -> RSTTSafeMode)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
RSTTSafeMode
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Context n -> RSTTSafeMode
forall (n :: S). Context n -> RSTTSafeMode
rsttSafeMode
when (mode == RSTTSafeError) $
mapM_ (issueTypeError . TypeErrorRSTT) (rsttViolation warning)
rsttViolation :: CheckWarning -> Maybe String
rsttViolation :: CheckWarning -> Maybe String
rsttViolation = \case
MetaPrefixWarning VarIdent
_ VarIdent
_ Int
_ Int
_ MetaPrefixRule
_ Maybe LocationInfo
_ -> String -> Maybe String
forall a. a -> Maybe a
Just String
"unsaturated schematic parameters"
FreeStandingRestrictionWarning VarIdent
_ String
_ FragmentUse
_ Maybe LocationInfo
_ -> String -> Maybe String
forall a. a -> Maybe a
Just String
"free-standing restriction in an assumed position"
MetaBinderWarning VarIdent
_ VarIdent
_ String
_ Maybe LocationInfo
_ -> String -> Maybe String
forall a. a -> Maybe a
Just String
"schematic binder inside a term"
RSTTScopeWarning RSTTExtension
_ String
feature Maybe LocationInfo
_ -> String -> Maybe String
forall a. a -> Maybe a
Just (String
feature String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" is outside RSTT")
RSTTHoleWarning Maybe LocationInfo
_ -> String -> Maybe String
forall a. a -> Maybe a
Just String
"unfinished obligation"
RSTTIncompleteWarning String
reason Maybe LocationInfo
_ -> String -> Maybe String
forall a. a -> Maybe a
Just String
reason
CheckWarning
_ -> Maybe String
forall a. Maybe a
Nothing
reportIncompleteRSTTCheck :: Distinct n => String -> TypeErrorInScopedContext -> TypeCheck n ()
reportIncompleteRSTTCheck :: forall (n :: S).
Distinct n =>
String -> TypeErrorInScopedContext -> TypeCheck n ()
reportIncompleteRSTTCheck String
_ err :: TypeErrorInScopedContext
err@(TypeErrorInScopedContext Context n
_ TypeErrorRSTT{}) = TypeErrorInScopedContext
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
()
forall a.
TypeErrorInScopedContext
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError TypeErrorInScopedContext
err
reportIncompleteRSTTCheck String
what (TypeErrorInScopedContext Context n
_ TypeError n
err) = do
loc <- (Context n -> Maybe LocationInfo)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
(Maybe LocationInfo)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Context n -> Maybe LocationInfo
forall (n :: S). Context n -> Maybe LocationInfo
ctxLocation
let reason = case TypeError n
err of
TypeErrorOther String
message -> String
message
TypeError n
_ -> String
"could not inspect a type"
recordCheckWarning $ RSTTIncompleteWarning (what <> ": " <> reason) loc
withLocation :: LocationInfo -> TypeCheck n a -> TypeCheck n a
withLocation :: forall (n :: S) a. LocationInfo -> TypeCheck n a -> TypeCheck n a
withLocation LocationInfo
loc = (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a.
(Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local ((Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a)
-> (Context n -> Context n)
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
-> ReaderT
(Context n)
(ExceptT TypeErrorInScopedContext (StateT CheckLog Identity))
a
forall a b. (a -> b) -> a -> b
$ \Context n
ctx -> Context n
ctx { ctxLocation = Just loc }