{-# OPTIONS_GHC -fno-warn-name-shadowing -fno-warn-redundant-constraints #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Rzk.TypeCheck.Context where
import Control.Monad.Foil (DExt, Distinct, NameBinder,
NameMap, Scope)
import qualified Control.Monad.Foil as Foil
import Control.Monad.Foil.Internal (NameMap (..))
import qualified Data.IntMap as IntMap
import Data.Map (Map)
import qualified Data.Map as Map
import Unsafe.Coerce (unsafeCoerce)
import Language.Rzk.Foil.Syntax
import Language.Rzk.Foil.Names (Binder (..), RzkPosition (..),
TModality (..), VarIdent,
binderName)
import qualified Language.Rzk.Syntax as Rzk
data Covariance
= Covariant
| Contravariant
| Invariant
data RenderBackend
= RenderSVG
| RenderLaTeX
data Verbosity
= Debug
| Normal
| Silent
deriving (Verbosity -> Verbosity -> Bool
(Verbosity -> Verbosity -> Bool)
-> (Verbosity -> Verbosity -> Bool) -> Eq Verbosity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Verbosity -> Verbosity -> Bool
== :: Verbosity -> Verbosity -> Bool
$c/= :: Verbosity -> Verbosity -> Bool
/= :: Verbosity -> Verbosity -> Bool
Eq, Eq Verbosity
Eq Verbosity =>
(Verbosity -> Verbosity -> Ordering)
-> (Verbosity -> Verbosity -> Bool)
-> (Verbosity -> Verbosity -> Bool)
-> (Verbosity -> Verbosity -> Bool)
-> (Verbosity -> Verbosity -> Bool)
-> (Verbosity -> Verbosity -> Verbosity)
-> (Verbosity -> Verbosity -> Verbosity)
-> Ord Verbosity
Verbosity -> Verbosity -> Bool
Verbosity -> Verbosity -> Ordering
Verbosity -> Verbosity -> Verbosity
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
$ccompare :: Verbosity -> Verbosity -> Ordering
compare :: Verbosity -> Verbosity -> Ordering
$c< :: Verbosity -> Verbosity -> Bool
< :: Verbosity -> Verbosity -> Bool
$c<= :: Verbosity -> Verbosity -> Bool
<= :: Verbosity -> Verbosity -> Bool
$c> :: Verbosity -> Verbosity -> Bool
> :: Verbosity -> Verbosity -> Bool
$c>= :: Verbosity -> Verbosity -> Bool
>= :: Verbosity -> Verbosity -> Bool
$cmax :: Verbosity -> Verbosity -> Verbosity
max :: Verbosity -> Verbosity -> Verbosity
$cmin :: Verbosity -> Verbosity -> Verbosity
min :: Verbosity -> Verbosity -> Verbosity
Ord)
data LocationInfo = LocationInfo
{ LocationInfo -> Maybe FilePath
locationFilePath :: Maybe FilePath
, LocationInfo -> Maybe Int
locationLine :: Maybe Int
, LocationInfo -> Maybe Int
locationColumn :: Maybe Int
} deriving (LocationInfo -> LocationInfo -> Bool
(LocationInfo -> LocationInfo -> Bool)
-> (LocationInfo -> LocationInfo -> Bool) -> Eq LocationInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LocationInfo -> LocationInfo -> Bool
== :: LocationInfo -> LocationInfo -> Bool
$c/= :: LocationInfo -> LocationInfo -> Bool
/= :: LocationInfo -> LocationInfo -> Bool
Eq, Int -> LocationInfo -> ShowS
[LocationInfo] -> ShowS
LocationInfo -> FilePath
(Int -> LocationInfo -> ShowS)
-> (LocationInfo -> FilePath)
-> ([LocationInfo] -> ShowS)
-> Show LocationInfo
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LocationInfo -> ShowS
showsPrec :: Int -> LocationInfo -> ShowS
$cshow :: LocationInfo -> FilePath
show :: LocationInfo -> FilePath
$cshowList :: [LocationInfo] -> ShowS
showList :: [LocationInfo] -> ShowS
Show)
atPosition :: RzkPosition -> LocationInfo -> LocationInfo
atPosition :: RzkPosition -> LocationInfo -> LocationInfo
atPosition RzkPosition
pos LocationInfo
loc = case RzkPosition -> BNFC'Position
rzkLineCol RzkPosition
pos of
BNFC'Position
Nothing -> LocationInfo
loc
Just (Int
line, Int
col) -> LocationInfo
loc { locationLine = Just line, locationColumn = Just col }
data VarInfo n = VarInfo
{ forall (n :: S). VarInfo n -> TermT n
varType :: TermT n
, forall (n :: S). VarInfo n -> Maybe (TermT n)
varValue :: Maybe (TermT n)
, forall (n :: S). VarInfo n -> TModality
varModality :: TModality
, forall (n :: S). VarInfo n -> TModality
varModAccum :: TModality
, forall (n :: S). VarInfo n -> Binder
varOrig :: Binder
, forall (n :: S). VarInfo n -> Bool
varIsAssumption :: Bool
, forall (n :: S). VarInfo n -> Bool
varIsTopLevel :: Bool
, forall (n :: S). VarInfo n -> [Name n]
varDeclaredAssumptions :: [Foil.Name n]
, forall (n :: S). VarInfo n -> Maybe LocationInfo
varLocation :: Maybe LocationInfo
, forall (n :: S). VarInfo n -> Maybe (DataRole n)
varDataRole :: Maybe (DataRole n)
, forall (n :: S). VarInfo n -> Int
varMetaPrefix :: Int
}
data DataRole n = DataRole
{ forall (n :: S). DataRole n -> Name n
dataRoleDataType :: Foil.Name n
, forall (n :: S). DataRole n -> Int
dataRoleNumParams :: Int
, forall (n :: S). DataRole n -> DataRoleKind
dataRoleKind :: DataRoleKind
}
data DataRoleKind
= DataConKind ConSort Int Int [Int]
| DataElimKind Int Int ElimKind
data ConSort = PointCon | PathCon
deriving (ConSort -> ConSort -> Bool
(ConSort -> ConSort -> Bool)
-> (ConSort -> ConSort -> Bool) -> Eq ConSort
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ConSort -> ConSort -> Bool
== :: ConSort -> ConSort -> Bool
$c/= :: ConSort -> ConSort -> Bool
/= :: ConSort -> ConSort -> Bool
Eq)
data ElimKind = ElimInd | ElimRec
deriving (ElimKind -> ElimKind -> Bool
(ElimKind -> ElimKind -> Bool)
-> (ElimKind -> ElimKind -> Bool) -> Eq ElimKind
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ElimKind -> ElimKind -> Bool
== :: ElimKind -> ElimKind -> Bool
$c/= :: ElimKind -> ElimKind -> Bool
/= :: ElimKind -> ElimKind -> Bool
Eq)
bumpDataRoleParams :: DataRole n -> DataRole n
bumpDataRoleParams :: forall (n :: S). DataRole n -> DataRole n
bumpDataRoleParams DataRole n
role = DataRole n
role { dataRoleNumParams = dataRoleNumParams role + 1 }
data ModalTope n = ModalTope
{ forall (n :: S). ModalTope n -> TModality
tModAccum :: TModality
, forall (n :: S). ModalTope n -> TModality
tModVar :: TModality
, forall (n :: S). ModalTope n -> TermT n
tTope :: TermT n
}
data Action n
= ActionTypeCheck (Term n) (TermT n)
| ActionUnify (TermT n) (TermT n) (TermT n)
| ActionUnifyTerms (TermT n) (TermT n)
| ActionInfer (Term n)
| ActionContextEntailedBy [TermT n] (TermT n)
| ActionContextEntails [TermT n] (TermT n)
| ActionContextEntailsUnion [TermT n] [TermT n]
| ActionWHNF (TermT n)
| ActionNF (TermT n)
| ActionCheckCoherence (TermT n, TermT n) (TermT n, TermT n)
| ActionCloseSection (Maybe Rzk.SectionName)
| ActionCheckLetValue (Maybe VarIdent)
data CachedSaturation n
= SaturationUncached
| SaturationCached (Maybe [[ModalTope n]])
data Context n = Context
{ forall (n :: S). Context n -> Scope n
ctxScope :: Scope n
, forall (n :: S). Context n -> NameMap n (VarInfo n)
ctxVars :: NameMap n (VarInfo n)
, forall (n :: S). Context n -> Map VarIdent (Name n)
ctxNamed :: Map VarIdent (Foil.Name n)
, forall (n :: S). Context n -> [Name n]
ctxBound :: [Foil.Name n]
, forall (n :: S). Context n -> [SectionInfo n]
ctxSections :: [SectionInfo n]
, forall (n :: S). Context n -> [ModalTope n]
ctxDiscreteTopes :: [ModalTope n]
, forall (n :: S). Context n -> [ModalTope n]
ctxTopes :: [ModalTope n]
, forall (n :: S). Context n -> [ModalTope n]
ctxTopesNF :: [ModalTope n]
, forall (n :: S). Context n -> [[ModalTope n]]
ctxTopesNFUnion :: [[ModalTope n]]
, forall (n :: S). Context n -> Maybe Bool
ctxTopesEntailBottom :: Maybe Bool
, forall (n :: S). Context n -> CachedSaturation n
ctxTopesSaturated :: CachedSaturation n
, forall (n :: S). Context n -> Map VarIdent [VarIdent]
ctxShadow :: Map VarIdent [VarIdent]
, forall (n :: S). Context n -> [Action n]
ctxActionStack :: [Action n]
, forall (n :: S). Context n -> Int
ctxActionStackDepth :: Int
, forall (n :: S). Context n -> Maybe Command
ctxCurrentCommand :: Maybe Rzk.Command
, forall (n :: S). Context n -> Maybe LocationInfo
ctxLocation :: Maybe LocationInfo
, forall (n :: S). Context n -> Verbosity
ctxVerbosity :: Verbosity
, forall (n :: S). Context n -> Covariance
ctxCovariance :: Covariance
, forall (n :: S). Context n -> Maybe RenderBackend
ctxRenderBackend :: Maybe RenderBackend
, forall (n :: S). Context n -> Bool
ctxRenderHideTerm :: Bool
, forall (n :: S). Context n -> Bool
ctxHolesAreErrors :: Bool
, forall (n :: S). Context n -> Bool
ctxDeferHoleMismatches :: Bool
, forall (n :: S). Context n -> [VarIdent]
ctxHintLemmas :: [VarIdent]
, forall (n :: S). Context n -> Bool
ctxWarnOverhang :: Bool
, forall (n :: S). Context n -> MetaPrefixSensitivity
ctxMetaPrefixSensitivity :: MetaPrefixSensitivity
}
data MetaPrefixSensitivity
= MetaPrefixOff
| MetaPrefixStructural
| MetaPrefixStrict
deriving (MetaPrefixSensitivity -> MetaPrefixSensitivity -> Bool
(MetaPrefixSensitivity -> MetaPrefixSensitivity -> Bool)
-> (MetaPrefixSensitivity -> MetaPrefixSensitivity -> Bool)
-> Eq MetaPrefixSensitivity
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MetaPrefixSensitivity -> MetaPrefixSensitivity -> Bool
== :: MetaPrefixSensitivity -> MetaPrefixSensitivity -> Bool
$c/= :: MetaPrefixSensitivity -> MetaPrefixSensitivity -> Bool
/= :: MetaPrefixSensitivity -> MetaPrefixSensitivity -> Bool
Eq, Int -> MetaPrefixSensitivity -> ShowS
[MetaPrefixSensitivity] -> ShowS
MetaPrefixSensitivity -> FilePath
(Int -> MetaPrefixSensitivity -> ShowS)
-> (MetaPrefixSensitivity -> FilePath)
-> ([MetaPrefixSensitivity] -> ShowS)
-> Show MetaPrefixSensitivity
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MetaPrefixSensitivity -> ShowS
showsPrec :: Int -> MetaPrefixSensitivity -> ShowS
$cshow :: MetaPrefixSensitivity -> FilePath
show :: MetaPrefixSensitivity -> FilePath
$cshowList :: [MetaPrefixSensitivity] -> ShowS
showList :: [MetaPrefixSensitivity] -> ShowS
Show)
data SectionInfo n = SectionInfo
{ forall (n :: S). SectionInfo n -> Maybe SectionName
sectionName :: Maybe Rzk.SectionName
, forall (n :: S). SectionInfo n -> [Name n]
sectionEntries :: [Foil.Name n]
}
emptyContext :: Context Foil.VoidS
emptyContext :: Context 'VoidS
emptyContext = Context
{ ctxScope :: Scope 'VoidS
ctxScope = Scope 'VoidS
Foil.emptyScope
, ctxVars :: NameMap 'VoidS (VarInfo 'VoidS)
ctxVars = NameMap 'VoidS (VarInfo 'VoidS)
forall a. NameMap 'VoidS a
Foil.emptyNameMap
, ctxNamed :: Map VarIdent (Name 'VoidS)
ctxNamed = Map VarIdent (Name 'VoidS)
forall k a. Map k a
Map.empty
, ctxBound :: [Name 'VoidS]
ctxBound = []
, ctxSections :: [SectionInfo 'VoidS]
ctxSections = [Maybe SectionName -> [Name 'VoidS] -> SectionInfo 'VoidS
forall (n :: S). Maybe SectionName -> [Name n] -> SectionInfo n
SectionInfo Maybe SectionName
forall a. Maybe a
Nothing []]
, ctxDiscreteTopes :: [ModalTope 'VoidS]
ctxDiscreteTopes = []
, ctxTopes :: [ModalTope 'VoidS]
ctxTopes = [ModalTope 'VoidS]
forall (n :: S). [ModalTope n]
emptyTopeContext
, ctxTopesNF :: [ModalTope 'VoidS]
ctxTopesNF = [ModalTope 'VoidS]
forall (n :: S). [ModalTope n]
emptyTopeContext
, ctxTopesNFUnion :: [[ModalTope 'VoidS]]
ctxTopesNFUnion = [[ModalTope 'VoidS]
forall (n :: S). [ModalTope n]
emptyTopeContext]
, ctxTopesEntailBottom :: Maybe Bool
ctxTopesEntailBottom = Bool -> Maybe Bool
forall a. a -> Maybe a
Just Bool
False
, ctxTopesSaturated :: CachedSaturation 'VoidS
ctxTopesSaturated = CachedSaturation 'VoidS
forall (n :: S). CachedSaturation n
SaturationUncached
, ctxShadow :: Map VarIdent [VarIdent]
ctxShadow = Map VarIdent [VarIdent]
forall k a. Map k a
Map.empty
, ctxActionStack :: [Action 'VoidS]
ctxActionStack = []
, ctxActionStackDepth :: Int
ctxActionStackDepth = Int
0
, ctxCurrentCommand :: Maybe Command
ctxCurrentCommand = Maybe Command
forall a. Maybe a
Nothing
, ctxLocation :: Maybe LocationInfo
ctxLocation = Maybe LocationInfo
forall a. Maybe a
Nothing
, ctxVerbosity :: Verbosity
ctxVerbosity = Verbosity
Normal
, ctxCovariance :: Covariance
ctxCovariance = Covariance
Covariant
, ctxRenderBackend :: Maybe RenderBackend
ctxRenderBackend = Maybe RenderBackend
forall a. Maybe a
Nothing
, ctxRenderHideTerm :: Bool
ctxRenderHideTerm = Bool
False
, ctxHolesAreErrors :: Bool
ctxHolesAreErrors = Bool
True
, ctxDeferHoleMismatches :: Bool
ctxDeferHoleMismatches = Bool
True
, ctxHintLemmas :: [VarIdent]
ctxHintLemmas = []
, ctxWarnOverhang :: Bool
ctxWarnOverhang = Bool
False
, ctxMetaPrefixSensitivity :: MetaPrefixSensitivity
ctxMetaPrefixSensitivity = MetaPrefixSensitivity
MetaPrefixStrict
}
emptyTopeContext :: [ModalTope n]
emptyTopeContext :: forall (n :: S). [ModalTope n]
emptyTopeContext =
[ TModality -> TModality -> TermT n -> ModalTope n
forall (n :: S). TModality -> TModality -> TermT n -> ModalTope n
ModalTope TModality
Id TModality
Id TermT n
forall (n :: S). TermT n
topeTopT
, TModality -> TModality -> TermT n -> ModalTope n
forall (n :: S). TModality -> TModality -> TermT n -> ModalTope n
ModalTope TModality
Id TModality
Flat TermT n
forall (n :: S). TermT n
topeTopT
, TModality -> TModality -> TermT n -> ModalTope n
forall (n :: S). TModality -> TModality -> TermT n -> ModalTope n
ModalTope TModality
Id TModality
Op TermT n
forall (n :: S). TermT n
topeTopT
, TModality -> TModality -> TermT n -> ModalTope n
forall (n :: S). TModality -> TModality -> TermT n -> ModalTope n
ModalTope TModality
Id TModality
Sharp TermT n
forall (n :: S). TermT n
topeTopT
]
sinkContextUnchecked :: DExt n l => Context n -> Context l
sinkContextUnchecked :: forall (n :: S) (l :: S). DExt n l => Context n -> Context l
sinkContextUnchecked = Context n -> Context l
forall a b. a -> b
unsafeCoerce
enterBinder
:: DExt n l
=> NameBinder n l
-> VarInfo n
-> [ModalTope l]
-> Context n
-> Context l
enterBinder :: forall (n :: S) (l :: S).
DExt n l =>
NameBinder n l
-> VarInfo n -> [ModalTope l] -> Context n -> Context l
enterBinder NameBinder n l
binder VarInfo n
info [ModalTope l]
discrete Context n
ctx = (Context n -> Context l
forall (n :: S) (l :: S). DExt n l => Context n -> Context l
sinkContextUnchecked Context n
ctx)
{ ctxScope = Foil.extendScope binder (ctxScope ctx)
, ctxVars = Foil.addNameBinder binder (Foil.sink info) (sinkVars (ctxVars ctx))
, ctxBound = Foil.nameOf binder : sinkNames (ctxBound ctx)
, ctxNamed = case binderName (varOrig info) of
Maybe VarIdent
Nothing -> Map VarIdent (Name n) -> Map VarIdent (Name l)
forall (n :: S) (l :: S).
DExt n l =>
Map VarIdent (Name n) -> Map VarIdent (Name l)
sinkNamed (Context n -> Map VarIdent (Name n)
forall (n :: S). Context n -> Map VarIdent (Name n)
ctxNamed Context n
ctx)
Just VarIdent
name -> VarIdent
-> Name l -> Map VarIdent (Name l) -> Map VarIdent (Name l)
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert VarIdent
name (NameBinder n l -> Name l
forall (n :: S) (l :: S). NameBinder n l -> Name l
Foil.nameOf NameBinder n l
binder) (Map VarIdent (Name n) -> Map VarIdent (Name l)
forall (n :: S) (l :: S).
DExt n l =>
Map VarIdent (Name n) -> Map VarIdent (Name l)
sinkNamed (Context n -> Map VarIdent (Name n)
forall (n :: S). Context n -> Map VarIdent (Name n)
ctxNamed Context n
ctx))
, ctxDiscreteTopes = discrete <> sinkTopes (ctxDiscreteTopes ctx)
, ctxShadow = addBinderNames (varOrig info) (ctxShadow ctx)
}
withFreshBinder
:: Distinct n
=> Context n
-> VarInfo n
-> (forall l. DExt n l => NameBinder n l -> Context l -> r)
-> r
withFreshBinder :: forall (n :: S) r.
Distinct n =>
Context n
-> VarInfo n
-> (forall (l :: S). DExt n l => NameBinder n l -> Context l -> r)
-> r
withFreshBinder Context n
ctx VarInfo n
info forall (l :: S). DExt n l => NameBinder n l -> Context l -> r
k =
Scope n -> (forall (l :: S). DExt n l => NameBinder n l -> r) -> r
forall (n :: S) r.
Distinct n =>
Scope n -> (forall (l :: S). DExt n l => NameBinder n l -> r) -> r
Foil.withFresh (Context n -> Scope n
forall (n :: S). Context n -> Scope n
ctxScope Context n
ctx) ((forall (l :: S). DExt n l => NameBinder n l -> r) -> r)
-> (forall (l :: S). DExt n l => NameBinder n l -> r) -> r
forall a b. (a -> b) -> a -> b
$ \NameBinder n l
binder ->
NameBinder n l -> Context l -> r
forall (l :: S). DExt n l => NameBinder n l -> Context l -> r
k NameBinder n l
binder (NameBinder n l
-> VarInfo n -> [ModalTope l] -> Context n -> Context l
forall (n :: S) (l :: S).
DExt n l =>
NameBinder n l
-> VarInfo n -> [ModalTope l] -> Context n -> Context l
enterBinder NameBinder n l
binder VarInfo n
info [] Context n
ctx)
addBinderNames :: Binder -> Map VarIdent [VarIdent] -> Map VarIdent [VarIdent]
addBinderNames :: Binder -> Map VarIdent [VarIdent] -> Map VarIdent [VarIdent]
addBinderNames Binder
orig Map VarIdent [VarIdent]
names =
case Binder -> Maybe VarIdent
binderName Binder
orig of
Maybe VarIdent
Nothing -> Map VarIdent [VarIdent]
names
Just VarIdent
name -> ([VarIdent] -> [VarIdent] -> [VarIdent])
-> VarIdent
-> [VarIdent]
-> Map VarIdent [VarIdent]
-> Map VarIdent [VarIdent]
forall k a. Ord k => (a -> a -> a) -> k -> a -> Map k a -> Map k a
Map.insertWith [VarIdent] -> [VarIdent] -> [VarIdent]
forall a. Semigroup a => a -> a -> a
(<>) VarIdent
name [VarIdent
name] Map VarIdent [VarIdent]
names
shadowedBy :: VarIdent -> Context n -> [VarIdent]
shadowedBy :: forall (n :: S). VarIdent -> Context n -> [VarIdent]
shadowedBy VarIdent
name Context n
ctx = [VarIdent] -> VarIdent -> Map VarIdent [VarIdent] -> [VarIdent]
forall k a. Ord k => a -> k -> Map k a -> a
Map.findWithDefault [] VarIdent
name (Context n -> Map VarIdent [VarIdent]
forall (n :: S). Context n -> Map VarIdent [VarIdent]
ctxShadow Context n
ctx)
instance Foil.Sinkable VarInfo where
sinkabilityProof :: forall (n :: S) (l :: S).
(Name n -> Name l) -> VarInfo n -> VarInfo l
sinkabilityProof Name n -> Name l
rename VarInfo n
info = VarInfo n
info
{ varType = Foil.sinkabilityProof rename (varType info)
, varValue = Foil.sinkabilityProof rename <$> varValue info
, varDeclaredAssumptions = rename <$> varDeclaredAssumptions info
, varDataRole = renameRole <$> varDataRole info
}
where
renameRole :: DataRole n -> DataRole l
renameRole DataRole n
role = DataRole n
role { dataRoleDataType = rename (dataRoleDataType role) }
instance Foil.Sinkable ModalTope where
sinkabilityProof :: forall (n :: S) (l :: S).
(Name n -> Name l) -> ModalTope n -> ModalTope l
sinkabilityProof Name n -> Name l
rename ModalTope n
tope =
ModalTope n
tope { tTope = Foil.sinkabilityProof rename (tTope tope) }
sinkVars :: DExt n l => NameMap n (VarInfo n) -> NameMap n (VarInfo l)
sinkVars :: forall (n :: S) (l :: S).
DExt n l =>
NameMap n (VarInfo n) -> NameMap n (VarInfo l)
sinkVars = NameMap n (VarInfo n) -> NameMap n (VarInfo l)
forall (f :: * -> *) (e :: S -> *) (n :: S) (l :: S).
(Functor f, Sinkable e, DExt n l) =>
f (e n) -> f (e l)
Foil.sink1
sinkTopes :: DExt n l => [ModalTope n] -> [ModalTope l]
sinkTopes :: forall (n :: S) (l :: S).
DExt n l =>
[ModalTope n] -> [ModalTope l]
sinkTopes = [ModalTope n] -> [ModalTope l]
forall (f :: * -> *) (e :: S -> *) (n :: S) (l :: S).
(Functor f, Sinkable e, DExt n l) =>
f (e n) -> f (e l)
Foil.sink1
sinkNamed :: DExt n l => Map VarIdent (Foil.Name n) -> Map VarIdent (Foil.Name l)
sinkNamed :: forall (n :: S) (l :: S).
DExt n l =>
Map VarIdent (Name n) -> Map VarIdent (Name l)
sinkNamed = Map VarIdent (Name n) -> Map VarIdent (Name l)
forall (f :: * -> *) (e :: S -> *) (n :: S) (l :: S).
(Functor f, Sinkable e, DExt n l) =>
f (e n) -> f (e l)
Foil.sink1
sinkNames :: DExt n l => [Foil.Name n] -> [Foil.Name l]
sinkNames :: forall (n :: S) (l :: S). DExt n l => [Name n] -> [Name l]
sinkNames = [Name n] -> [Name l]
forall (f :: * -> *) (e :: S -> *) (n :: S) (l :: S).
(Functor f, Sinkable e, DExt n l) =>
f (e n) -> f (e l)
Foil.sink1
lookupVarInfo :: Foil.Name n -> Context n -> VarInfo n
lookupVarInfo :: forall (n :: S). Name n -> Context n -> VarInfo n
lookupVarInfo Name n
name Context n
ctx = Name n -> NameMap n (VarInfo n) -> VarInfo n
forall (n :: S) a. Name n -> NameMap n a -> a
Foil.lookupName Name n
name (Context n -> NameMap n (VarInfo n)
forall (n :: S). Context n -> NameMap n (VarInfo n)
ctxVars Context n
ctx)
varInfos :: Context n -> [VarInfo n]
varInfos :: forall (n :: S). Context n -> [VarInfo n]
varInfos Context n
ctx = IntMap (VarInfo n) -> [VarInfo n]
forall a. IntMap a -> [a]
IntMap.elems IntMap (VarInfo n)
m
where
NameMap IntMap (VarInfo n)
m = Context n -> NameMap n (VarInfo n)
forall (n :: S). Context n -> NameMap n (VarInfo n)
ctxVars Context n
ctx
varsInScope :: Context n -> [(Foil.Name n, VarInfo n)]
varsInScope :: forall (n :: S). Context n -> [(Name n, VarInfo n)]
varsInScope Context n
ctx =
[ (Name n
name, Name n -> Context n -> VarInfo n
forall (n :: S). Name n -> Context n -> VarInfo n
lookupVarInfo Name n
name Context n
ctx) | Name n
name <- [Name n] -> [Name n]
forall a. [a] -> [a]
reverse (Context n -> [Name n]
forall (n :: S). Context n -> [Name n]
ctxBound Context n
ctx) ]
lookupNamed :: VarIdent -> Context n -> Maybe (Foil.Name n)
lookupNamed :: forall (n :: S). VarIdent -> Context n -> Maybe (Name n)
lookupNamed VarIdent
name Context n
ctx = VarIdent -> Map VarIdent (Name n) -> Maybe (Name n)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup VarIdent
name (Context n -> Map VarIdent (Name n)
forall (n :: S). Context n -> Map VarIdent (Name n)
ctxNamed Context n
ctx)
binderOfName :: Foil.Name n -> Context n -> Binder
binderOfName :: forall (n :: S). Name n -> Context n -> Binder
binderOfName Name n
name = VarInfo n -> Binder
forall (n :: S). VarInfo n -> Binder
varOrig (VarInfo n -> Binder)
-> (Context n -> VarInfo n) -> Context n -> Binder
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Name n -> Context n -> VarInfo n
forall (n :: S). Name n -> Context n -> VarInfo n
lookupVarInfo Name n
name
class ModeTheory m where
iden :: m
comp :: m -> m -> m
coe :: m -> m -> Bool
isRA :: m -> Bool
instance ModeTheory TModality where
iden :: TModality
iden = TModality
Id
comp :: TModality -> TModality -> TModality
comp TModality
Flat TModality
Flat = TModality
Flat
comp TModality
Flat TModality
Sharp = TModality
Flat
comp TModality
Flat TModality
Op = TModality
Flat
comp TModality
Op TModality
Flat = TModality
Flat
comp TModality
Sharp TModality
Sharp = TModality
Sharp
comp TModality
Sharp TModality
Flat = TModality
Sharp
comp TModality
Sharp TModality
Op = TModality
Sharp
comp TModality
Op TModality
Sharp = TModality
Sharp
comp TModality
Op TModality
Op = TModality
Id
comp TModality
Id TModality
m = TModality
m
comp TModality
m TModality
Id = TModality
m
coe :: TModality -> TModality -> Bool
coe TModality
Flat TModality
Id = Bool
True
coe TModality
Flat TModality
Op = Bool
True
coe TModality
Id TModality
Sharp = Bool
True
coe TModality
Flat TModality
Sharp = Bool
True
coe TModality
Op TModality
Sharp = Bool
True
coe TModality
a TModality
b = TModality
a TModality -> TModality -> Bool
forall a. Eq a => a -> a -> Bool
== TModality
b
isRA :: TModality -> Bool
isRA TModality
Sharp = Bool
True
isRA TModality
Op = Bool
True
isRA TModality
Id = Bool
True
isRA TModality
_ = Bool
False
applyModality :: TModality -> Context n -> Context n
applyModality :: forall (n :: S). TModality -> Context n -> Context n
applyModality TModality
md Context n
ctx = Context n
ctx
{ ctxVars = mapNameMap addToVar (ctxVars ctx)
, ctxTopes = map addToTope (ctxTopes ctx)
, ctxTopesNF = map addToTope (ctxTopesNF ctx)
, ctxTopesNFUnion = map (map addToTope) (ctxTopesNFUnion ctx)
, ctxTopesSaturated = SaturationUncached
}
where
addToVar :: VarInfo n -> VarInfo n
addToVar VarInfo n
info
| VarInfo n -> Bool
forall (n :: S). VarInfo n -> Bool
varIsTopLevel VarInfo n
info = VarInfo n
info
| Bool
otherwise = VarInfo n
info { varModAccum = comp (varModAccum info) md }
addToTope :: ModalTope n -> ModalTope n
addToTope ModalTope n
tope = ModalTope n
tope { tModAccum = comp (tModAccum tope) md }
mapNameMap :: (a -> b) -> NameMap n a -> NameMap n b
mapNameMap :: forall a b (n :: S). (a -> b) -> NameMap n a -> NameMap n b
mapNameMap a -> b
f (NameMap IntMap a
m) = IntMap b -> NameMap n b
forall (n :: S) a. IntMap a -> NameMap n a
NameMap ((a -> b) -> IntMap a -> IntMap b
forall a b. (a -> b) -> IntMap a -> IntMap b
IntMap.map a -> b
f IntMap a
m)
insertVarInfo :: Foil.Name n -> VarInfo n -> Context n -> Context n
insertVarInfo :: forall (n :: S). Name n -> VarInfo n -> Context n -> Context n
insertVarInfo Name n
name VarInfo n
info Context n
ctx = Context n
ctx { ctxVars = replace (ctxVars ctx) }
where
replace :: NameMap n (VarInfo n) -> NameMap n (VarInfo n)
replace (NameMap IntMap (VarInfo n)
m) = IntMap (VarInfo n) -> NameMap n (VarInfo n)
forall (n :: S) a. IntMap a -> NameMap n a
NameMap (Int -> VarInfo n -> IntMap (VarInfo n) -> IntMap (VarInfo n)
forall a. Int -> a -> IntMap a -> IntMap a
IntMap.insert (Name n -> Int
forall (l :: S). Name l -> Int
Foil.nameId Name n
name) VarInfo n
info IntMap (VarInfo n)
m)
isAccessible :: ModalTope n -> Bool
isAccessible :: forall (n :: S). ModalTope n -> Bool
isAccessible ModalTope n
mt = TModality -> TModality -> Bool
forall m. ModeTheory m => m -> m -> Bool
coe (ModalTope n -> TModality
forall (n :: S). ModalTope n -> TModality
tModVar ModalTope n
mt) (ModalTope n -> TModality
forall (n :: S). ModalTope n -> TModality
tModAccum ModalTope n
mt)
filterAccessible :: [ModalTope n] -> [ModalTope n]
filterAccessible :: forall (n :: S). [ModalTope n] -> [ModalTope n]
filterAccessible = (ModalTope n -> Bool) -> [ModalTope n] -> [ModalTope n]
forall a. (a -> Bool) -> [a] -> [a]
filter ModalTope n -> Bool
forall (n :: S). ModalTope n -> Bool
isAccessible
accessibleTopes :: [ModalTope n] -> [TermT n]
accessibleTopes :: forall (n :: S). [ModalTope n] -> [TermT n]
accessibleTopes = (ModalTope n -> TermT n) -> [ModalTope n] -> [TermT n]
forall a b. (a -> b) -> [a] -> [b]
map ModalTope n -> TermT n
forall (n :: S). ModalTope n -> TermT n
tTope ([ModalTope n] -> [TermT n])
-> ([ModalTope n] -> [ModalTope n]) -> [ModalTope n] -> [TermT n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [ModalTope n] -> [ModalTope n]
forall (n :: S). [ModalTope n] -> [ModalTope n]
filterAccessible
plainTope :: TermT n -> ModalTope n
plainTope :: forall (n :: S). TermT n -> ModalTope n
plainTope = TModality -> TModality -> TermT n -> ModalTope n
forall (n :: S). TModality -> TModality -> TermT n -> ModalTope n
ModalTope TModality
Id TModality
Id
availableTopes :: Context n -> [TermT n]
availableTopes :: forall (n :: S). Context n -> [TermT n]
availableTopes = [ModalTope n] -> [TermT n]
forall (n :: S). [ModalTope n] -> [TermT n]
accessibleTopes ([ModalTope n] -> [TermT n])
-> (Context n -> [ModalTope n]) -> Context n -> [TermT n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Context n -> [ModalTope n]
forall (n :: S). Context n -> [ModalTope n]
ctxTopes
availableTopesNF :: Context n -> [TermT n]
availableTopesNF :: forall (n :: S). Context n -> [TermT n]
availableTopesNF = [ModalTope n] -> [TermT n]
forall (n :: S). [ModalTope n] -> [TermT n]
accessibleTopes ([ModalTope n] -> [TermT n])
-> (Context n -> [ModalTope n]) -> Context n -> [TermT n]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Context n -> [ModalTope n]
forall (n :: S). Context n -> [ModalTope n]
ctxTopesNF
allowHoles :: Context n -> Context n
allowHoles :: forall (n :: S). Context n -> Context n
allowHoles Context n
ctx = Context n
ctx { ctxHolesAreErrors = False }
withHintLemmas :: [VarIdent] -> Context n -> Context n
withHintLemmas :: forall (n :: S). [VarIdent] -> Context n -> Context n
withHintLemmas [VarIdent]
lemmas Context n
ctx = Context n
ctx { ctxHintLemmas = lemmas }
structuralHoleUnify :: Context n -> Context n
structuralHoleUnify :: forall (n :: S). Context n -> Context n
structuralHoleUnify Context n
ctx = Context n
ctx { ctxDeferHoleMismatches = False }