{-# LANGUAGE NondecreasingIndentation #-}
{-# LANGUAGE GADTs #-}
module Agda.TypeChecking.MetaVars where
import Prelude hiding (null)
import Control.Monad ( foldM, forM, forM_, liftM2, void )
import Control.Monad.Except ( MonadError(..), ExceptT, runExceptT )
import Control.Monad.Trans ( lift )
import Data.Function
import qualified Data.IntSet as IntSet
import qualified Data.List as List
import qualified Data.Map.Strict as MapS
import qualified Data.Set as Set
import qualified Data.Foldable as Fold
import qualified Data.Traversable as Trav
import Agda.Interaction.Options
import Agda.Syntax.Abstract.Name as A
import Agda.Syntax.Common
import Agda.Syntax.Internal
import Agda.Syntax.Internal.Generic
import Agda.Syntax.Internal.MetaVars
import Agda.Syntax.Position (getRange, killRange)
import Agda.TypeChecking.Monad
import Agda.TypeChecking.Reduce
import Agda.TypeChecking.Sort
import Agda.TypeChecking.Substitute
import qualified Agda.TypeChecking.SyntacticEquality as SynEq
import Agda.TypeChecking.Telescope
import Agda.TypeChecking.Constraints
import Agda.TypeChecking.Free
import Agda.TypeChecking.Lock
import Agda.TypeChecking.Level (levelType)
import Agda.TypeChecking.Records
import Agda.TypeChecking.Pretty
import Agda.TypeChecking.Irrelevance
import Agda.TypeChecking.EtaContract
import Agda.TypeChecking.SizedTypes (boundedSizeMetaHook, isSizeProblem)
import {-# SOURCE #-} Agda.TypeChecking.CheckInternal
import {-# SOURCE #-} Agda.TypeChecking.Conversion
import Agda.TypeChecking.MetaVars.Occurs
import Agda.Utils.Function
import Agda.Utils.Lens
import Agda.Utils.List
import Agda.Utils.Maybe
import Agda.Utils.Monad
import Agda.Utils.Size
import Agda.Utils.Tuple
import Agda.Utils.Permutation
import Agda.Utils.Pretty (Pretty, prettyShow, render)
import qualified Agda.Utils.ProfileOptions as Profile
import Agda.Utils.Singleton
import qualified Agda.Utils.Graph.TopSort as Graph
import Agda.Utils.VarSet (VarSet)
import qualified Agda.Utils.VarSet as VarSet
import Agda.Utils.WithDefault
import Agda.Utils.Impossible
instance MonadMetaSolver TCM where
newMeta' :: forall a.
MetaInstantiation
-> Frozen
-> MetaInfo
-> MetaPriority
-> Permutation
-> Judgement a
-> TCM MetaId
newMeta' = forall a.
MetaInstantiation
-> Frozen
-> MetaInfo
-> MetaPriority
-> Permutation
-> Judgement a
-> TCM MetaId
newMetaTCM'
assignV :: CompareDirection -> MetaId -> Args -> Term -> CompareAs -> TCM ()
assignV CompareDirection
dir MetaId
x Args
args Term
v CompareAs
t = forall (m :: * -> *).
(MonadMetaSolver m, MonadConstraint m, MonadError TCErr m,
MonadDebug m, HasOptions m) =>
CompareDirection -> MetaId -> Elims -> Term -> m () -> m ()
assignWrapper CompareDirection
dir MetaId
x (forall a b. (a -> b) -> [a] -> [b]
map forall a. Arg a -> Elim' a
Apply Args
args) Term
v forall a b. (a -> b) -> a -> b
$ CompareDirection -> MetaId -> Args -> Term -> CompareAs -> TCM ()
assign CompareDirection
dir MetaId
x Args
args Term
v CompareAs
t
assignTerm' :: MonadMetaSolver (TCMT IO) =>
MetaId -> [Arg [Char]] -> Term -> TCM ()
assignTerm' = MetaId -> [Arg [Char]] -> Term -> TCM ()
assignTermTCM'
etaExpandMeta :: [MetaKind] -> MetaId -> TCM ()
etaExpandMeta = [MetaKind] -> MetaId -> TCM ()
etaExpandMetaTCM
updateMetaVar :: MetaId -> (MetaVariable -> MetaVariable) -> TCM ()
updateMetaVar = HasCallStack => MetaId -> (MetaVariable -> MetaVariable) -> TCM ()
updateMetaVarTCM
speculateMetas :: TCM () -> TCM KeepMetas -> TCM ()
speculateMetas TCM ()
fallback TCM KeepMetas
m = do
(KeepMetas
a, TCState
s) <- forall a. TCM a -> TCM (a, TCState)
localTCStateSaving TCM KeepMetas
m
case KeepMetas
a of
KeepMetas
KeepMetas -> forall (m :: * -> *). MonadTCState m => TCState -> m ()
putTC TCState
s
KeepMetas
RollBackMetas -> TCM ()
fallback
findIdx :: Eq a => [a] -> a -> Maybe Int
findIdx :: forall a. Eq a => [a] -> a -> Maybe Nat
findIdx [a]
vs a
v = forall a. Eq a => a -> [a] -> Maybe Nat
List.elemIndex a
v (forall a. [a] -> [a]
reverse [a]
vs)
hasTwinMeta :: MetaId -> TCM Bool
hasTwinMeta :: MetaId -> TCM Bool
hasTwinMeta MetaId
x = do
MetaVariable
m <- forall (m :: * -> *).
(HasCallStack, MonadDebug m, ReadTCState m) =>
MetaId -> m MetaVariable
lookupLocalMeta MetaId
x
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. Maybe a -> Bool
isJust forall a b. (a -> b) -> a -> b
$ MetaVariable -> Maybe MetaId
mvTwin MetaVariable
m
isBlockedTerm :: MetaId -> TCM Bool
isBlockedTerm :: MetaId -> TCM Bool
isBlockedTerm MetaId
x = do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> [Char] -> m ()
reportSLn [Char]
"tc.meta.blocked" Nat
12 forall a b. (a -> b) -> a -> b
$ [Char]
"is " forall a. [a] -> [a] -> [a]
++ forall a. Pretty a => a -> [Char]
prettyShow MetaId
x forall a. [a] -> [a] -> [a]
++ [Char]
" a blocked term? "
MetaInstantiation
i <- forall (m :: * -> *).
ReadTCState m =>
MetaId -> m MetaInstantiation
lookupMetaInstantiation MetaId
x
let r :: Bool
r = case MetaInstantiation
i of
BlockedConst{} -> Bool
True
PostponedTypeCheckingProblem{} -> Bool
True
InstV{} -> Bool
False
Open{} -> Bool
False
OpenInstance{} -> Bool
False
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> [Char] -> m ()
reportSLn [Char]
"tc.meta.blocked" Nat
12 forall a b. (a -> b) -> a -> b
$
if Bool
r then [Char]
" yes, because " forall a. [a] -> [a] -> [a]
++ forall a. Pretty a => a -> [Char]
prettyShow MetaInstantiation
i else [Char]
" no"
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
r
isEtaExpandable :: [MetaKind] -> MetaId -> TCM Bool
isEtaExpandable :: [MetaKind] -> MetaId -> TCM Bool
isEtaExpandable [MetaKind]
kinds MetaId
x = do
MetaInstantiation
i <- forall (m :: * -> *).
ReadTCState m =>
MetaId -> m MetaInstantiation
lookupMetaInstantiation MetaId
x
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ case MetaInstantiation
i of
Open{} -> Bool
True
OpenInstance{} -> MetaKind
Records forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [MetaKind]
kinds
InstV{} -> Bool
False
BlockedConst{} -> Bool
False
PostponedTypeCheckingProblem{} -> Bool
False
assignTerm :: MonadMetaSolver m => MetaId -> [Arg ArgName] -> Term -> m ()
assignTerm :: forall (m :: * -> *).
MonadMetaSolver m =>
MetaId -> [Arg [Char]] -> Term -> m ()
assignTerm MetaId
x [Arg [Char]]
tel Term
v = do
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM (forall (m :: * -> *).
(HasCallStack, MonadDebug m, ReadTCState m) =>
MetaId -> m Bool
isFrozen MetaId
x) forall a. HasCallStack => a
__IMPOSSIBLE__
forall (m :: * -> *).
(MonadMetaSolver m, MonadMetaSolver m) =>
MetaId -> [Arg [Char]] -> Term -> m ()
assignTerm' MetaId
x [Arg [Char]]
tel Term
v
assignTermTCM' :: MetaId -> [Arg ArgName] -> Term -> TCM ()
assignTermTCM' :: MetaId -> [Arg [Char]] -> Term -> TCM ()
assignTermTCM' MetaId
x [Arg [Char]]
tel Term
v = do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign" Nat
70 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"assignTerm" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM MetaId
x forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
" := " forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Term
v
, forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"tel =" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *) (t :: * -> *).
(Applicative m, Semigroup (m Doc), Foldable t) =>
t (m Doc) -> m Doc
prettyList_ (forall a b. (a -> b) -> [a] -> [b]
map (forall (m :: * -> *). Applicative m => [Char] -> m Doc
text forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e. Arg e -> e
unArg) [Arg [Char]]
tel)
]
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM (Bool -> Bool
not forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC TCEnv -> Bool
envAssignMetas) forall a. HasCallStack => a
__IMPOSSIBLE__
forall (m :: * -> *). MonadDebug m => ProfileOption -> m () -> m ()
whenProfile ProfileOption
Profile.Metas forall a b. (a -> b) -> a -> b
$ forall (tcm :: * -> *) a. MonadTCM tcm => TCM a -> tcm a
liftTCM forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return ()
HasCallStack => MetaId -> (MetaVariable -> MetaVariable) -> TCM ()
updateMetaVarTCM MetaId
x forall a b. (a -> b) -> a -> b
$ \ MetaVariable
mv ->
MetaVariable
mv { mvInstantiation :: MetaInstantiation
mvInstantiation = Instantiation -> MetaInstantiation
InstV forall a b. (a -> b) -> a -> b
$ Instantiation
{ instTel :: [Arg [Char]]
instTel = [Arg [Char]]
tel
, instBody :: Term
instBody = Term
v
}
}
forall (m :: * -> *). MonadMetaSolver m => MetaId -> m ()
etaExpandListeners MetaId
x
forall (m :: * -> *). MonadMetaSolver m => MetaId -> m ()
wakeupConstraints MetaId
x
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> [Char] -> m ()
reportSLn [Char]
"tc.meta.assign" Nat
20 forall a b. (a -> b) -> a -> b
$ [Char]
"completed assignment of " forall a. [a] -> [a] -> [a]
++ forall a. Pretty a => a -> [Char]
prettyShow MetaId
x
newSortMetaBelowInf :: TCM Sort
newSortMetaBelowInf :: TCM (Sort' Term)
newSortMetaBelowInf = do
Sort' Term
x <- forall (m :: * -> *). MonadMetaSolver m => m (Sort' Term)
newSortMeta
Sort' Term -> TCM ()
hasBiggerSort Sort' Term
x
forall (m :: * -> *) a. Monad m => a -> m a
return Sort' Term
x
newSortMeta :: MonadMetaSolver m => m Sort
newSortMeta :: forall (m :: * -> *). MonadMetaSolver m => m (Sort' Term)
newSortMeta =
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
ifM forall (m :: * -> *). HasOptions m => m Bool
hasUniversePolymorphism (forall (m :: * -> *). MonadMetaSolver m => Args -> m (Sort' Term)
newSortMetaCtx forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m Args
getContextArgs)
forall a b. (a -> b) -> a -> b
$ do MetaInfo
i <- forall (m :: * -> *). (MonadTCEnv m, ReadTCState m) => m MetaInfo
createMetaInfo
let j :: Judgement ()
j = forall a. a -> Type -> Judgement a
IsSort () HasCallStack => Type
__DUMMY_TYPE__
MetaId
x <- forall (m :: * -> *) a.
MonadMetaSolver m =>
Frozen
-> MetaInfo
-> MetaPriority
-> Permutation
-> Judgement a
-> m MetaId
newMeta Frozen
Instantiable MetaInfo
i MetaPriority
normalMetaPriority (Nat -> Permutation
idP Nat
0) Judgement ()
j
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.new" Nat
50 forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"new sort meta" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM MetaId
x
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall t. MetaId -> [Elim' t] -> Sort' t
MetaS MetaId
x []
newSortMetaCtx :: MonadMetaSolver m => Args -> m Sort
newSortMetaCtx :: forall (m :: * -> *). MonadMetaSolver m => Args -> m (Sort' Term)
newSortMetaCtx Args
vs = do
MetaInfo
i <- forall (m :: * -> *). (MonadTCEnv m, ReadTCState m) => m MetaInfo
createMetaInfo
Tele (Dom Type)
tel <- forall (m :: * -> *).
(Applicative m, MonadTCEnv m) =>
m (Tele (Dom Type))
getContextTelescope
let t :: Type
t = Tele (Dom Type) -> Type -> Type
telePi_ Tele (Dom Type)
tel HasCallStack => Type
__DUMMY_TYPE__
MetaId
x <- forall (m :: * -> *) a.
MonadMetaSolver m =>
Frozen
-> MetaInfo
-> MetaPriority
-> Permutation
-> Judgement a
-> m MetaId
newMeta Frozen
Instantiable MetaInfo
i MetaPriority
normalMetaPriority (Nat -> Permutation
idP forall a b. (a -> b) -> a -> b
$ forall a. Sized a => a -> Nat
size Tele (Dom Type)
tel) forall a b. (a -> b) -> a -> b
$ forall a. a -> Type -> Judgement a
IsSort () Type
t
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.new" Nat
50 forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"new sort meta" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM MetaId
x forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
":" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
t
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall t. MetaId -> [Elim' t] -> Sort' t
MetaS MetaId
x forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall a. Arg a -> Elim' a
Apply Args
vs
newTypeMeta' :: Comparison -> Sort -> TCM Type
newTypeMeta' :: Comparison -> Sort' Term -> TCM Type
newTypeMeta' Comparison
cmp Sort' Term
s = forall t a. Sort' t -> a -> Type'' t a
El Sort' Term
s forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
MonadMetaSolver m =>
RunMetaOccursCheck -> Comparison -> Type -> m (MetaId, Term)
newValueMeta RunMetaOccursCheck
RunMetaOccursCheck Comparison
cmp (Sort' Term -> Type
sort Sort' Term
s)
newTypeMeta :: Sort -> TCM Type
newTypeMeta :: Sort' Term -> TCM Type
newTypeMeta = Comparison -> Sort' Term -> TCM Type
newTypeMeta' Comparison
CmpLeq
newTypeMeta_ :: TCM Type
newTypeMeta_ :: TCM Type
newTypeMeta_ = Comparison -> Sort' Term -> TCM Type
newTypeMeta' Comparison
CmpEq forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (forall (m :: * -> *) a.
(MonadTCEnv m, HasOptions m, MonadDebug m) =>
m a -> m a
workOnTypes forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). MonadMetaSolver m => m (Sort' Term)
newSortMeta)
newLevelMeta :: MonadMetaSolver m => m Level
newLevelMeta :: forall (m :: * -> *). MonadMetaSolver m => m Level
newLevelMeta = do
(MetaId
x, Term
v) <- forall (m :: * -> *).
MonadMetaSolver m =>
RunMetaOccursCheck -> Comparison -> Type -> m (MetaId, Term)
newValueMeta RunMetaOccursCheck
RunMetaOccursCheck Comparison
CmpEq forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *). (HasBuiltins m, MonadTCError m) => m Type
levelType
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ case Term
v of
Level Level
l -> Level
l
Term
_ -> forall t. t -> Level' t
atomicLevel Term
v
newInstanceMeta
:: MonadMetaSolver m
=> MetaNameSuggestion -> Type -> m (MetaId, Term)
newInstanceMeta :: forall (m :: * -> *).
MonadMetaSolver m =>
[Char] -> Type -> m (MetaId, Term)
newInstanceMeta [Char]
s Type
t = do
Args
vs <- forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m Args
getContextArgs
Tele (Dom Type)
ctx <- forall (m :: * -> *).
(Applicative m, MonadTCEnv m) =>
m (Tele (Dom Type))
getContextTelescope
forall (m :: * -> *).
MonadMetaSolver m =>
[Char] -> Type -> Args -> m (MetaId, Term)
newInstanceMetaCtx [Char]
s (Tele (Dom Type) -> Type -> Type
telePi_ Tele (Dom Type)
ctx Type
t) Args
vs
newInstanceMetaCtx
:: MonadMetaSolver m
=> MetaNameSuggestion -> Type -> Args -> m (MetaId, Term)
newInstanceMetaCtx :: forall (m :: * -> *).
MonadMetaSolver m =>
[Char] -> Type -> Args -> m (MetaId, Term)
newInstanceMetaCtx [Char]
s Type
t Args
vs = do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.new" Nat
50 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
fsep
[ TCMT IO Doc
"new instance meta:"
, forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Args
vs forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
"|-"
]
MetaInfo
i0 <- forall (m :: * -> *).
(MonadTCEnv m, ReadTCState m) =>
RunMetaOccursCheck -> m MetaInfo
createMetaInfo' RunMetaOccursCheck
DontRunMetaOccursCheck
let i :: MetaInfo
i = MetaInfo
i0 { miNameSuggestion :: [Char]
miNameSuggestion = [Char]
s }
TelV Tele (Dom Type)
tel Type
_ <- forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Type -> m (TelV Type)
telView Type
t
let perm :: Permutation
perm = Nat -> Permutation
idP (forall a. Sized a => a -> Nat
size Tele (Dom Type)
tel)
MetaId
x <- forall (m :: * -> *) a.
MonadMetaSolver m =>
MetaInstantiation
-> Frozen
-> MetaInfo
-> MetaPriority
-> Permutation
-> Judgement a
-> m MetaId
newMeta' MetaInstantiation
OpenInstance Frozen
Instantiable MetaInfo
i MetaPriority
normalMetaPriority Permutation
perm (forall a. a -> Comparison -> Type -> Judgement a
HasType () Comparison
CmpLeq Type
t)
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.new" Nat
50 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
fsep
[ forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty MetaId
x forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
":" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
t
]
let c :: Constraint
c = MetaId -> Maybe [Candidate] -> Constraint
FindInstance MetaId
x forall a. Maybe a
Nothing
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
ifM forall (m :: * -> *). MonadTCEnv m => m Bool
isSolvingConstraints (forall (m :: * -> *).
MonadConstraint m =>
Blocker -> Constraint -> m ()
addConstraint Blocker
alwaysUnblock Constraint
c) (forall (m :: * -> *).
MonadConstraint m =>
Blocker -> Constraint -> m ()
addAwakeConstraint Blocker
alwaysUnblock Constraint
c)
forall (m :: * -> *). MonadMetaSolver m => MetaId -> m ()
etaExpandMetaSafe MetaId
x
forall (m :: * -> *) a. Monad m => a -> m a
return (MetaId
x, MetaId -> Elims -> Term
MetaV MetaId
x forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall a. Arg a -> Elim' a
Apply Args
vs)
newNamedValueMeta :: MonadMetaSolver m => RunMetaOccursCheck -> MetaNameSuggestion -> Comparison -> Type -> m (MetaId, Term)
newNamedValueMeta :: forall (m :: * -> *).
MonadMetaSolver m =>
RunMetaOccursCheck
-> [Char] -> Comparison -> Type -> m (MetaId, Term)
newNamedValueMeta RunMetaOccursCheck
b [Char]
s Comparison
cmp Type
t = do
(MetaId
x, Term
v) <- forall (m :: * -> *).
MonadMetaSolver m =>
RunMetaOccursCheck -> Comparison -> Type -> m (MetaId, Term)
newValueMeta RunMetaOccursCheck
b Comparison
cmp Type
t
forall (m :: * -> *). MonadMetaSolver m => MetaId -> [Char] -> m ()
setMetaNameSuggestion MetaId
x [Char]
s
forall (m :: * -> *) a. Monad m => a -> m a
return (MetaId
x, Term
v)
newNamedValueMeta' :: MonadMetaSolver m => RunMetaOccursCheck -> MetaNameSuggestion -> Comparison -> Type -> m (MetaId, Term)
newNamedValueMeta' :: forall (m :: * -> *).
MonadMetaSolver m =>
RunMetaOccursCheck
-> [Char] -> Comparison -> Type -> m (MetaId, Term)
newNamedValueMeta' RunMetaOccursCheck
b [Char]
s Comparison
cmp Type
t = do
(MetaId
x, Term
v) <- forall (m :: * -> *).
MonadMetaSolver m =>
RunMetaOccursCheck -> Comparison -> Type -> m (MetaId, Term)
newValueMeta' RunMetaOccursCheck
b Comparison
cmp Type
t
forall (m :: * -> *). MonadMetaSolver m => MetaId -> [Char] -> m ()
setMetaNameSuggestion MetaId
x [Char]
s
forall (m :: * -> *) a. Monad m => a -> m a
return (MetaId
x, Term
v)
newValueMeta :: MonadMetaSolver m => RunMetaOccursCheck -> Comparison -> Type -> m (MetaId, Term)
newValueMeta :: forall (m :: * -> *).
MonadMetaSolver m =>
RunMetaOccursCheck -> Comparison -> Type -> m (MetaId, Term)
newValueMeta RunMetaOccursCheck
b Comparison
cmp Type
t = do
Args
vs <- forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m Args
getContextArgs
Tele (Dom Type)
tel <- forall (m :: * -> *).
(Applicative m, MonadTCEnv m) =>
m (Tele (Dom Type))
getContextTelescope
forall (m :: * -> *).
MonadMetaSolver m =>
Frozen
-> RunMetaOccursCheck
-> Comparison
-> Type
-> Tele (Dom Type)
-> Permutation
-> Args
-> m (MetaId, Term)
newValueMetaCtx Frozen
Instantiable RunMetaOccursCheck
b Comparison
cmp Type
t Tele (Dom Type)
tel (Nat -> Permutation
idP forall a b. (a -> b) -> a -> b
$ forall a. Sized a => a -> Nat
size Tele (Dom Type)
tel) Args
vs
newValueMetaCtx
:: MonadMetaSolver m
=> Frozen -> RunMetaOccursCheck -> Comparison -> Type -> Telescope -> Permutation -> Args -> m (MetaId, Term)
newValueMetaCtx :: forall (m :: * -> *).
MonadMetaSolver m =>
Frozen
-> RunMetaOccursCheck
-> Comparison
-> Type
-> Tele (Dom Type)
-> Permutation
-> Args
-> m (MetaId, Term)
newValueMetaCtx Frozen
frozen RunMetaOccursCheck
b Comparison
cmp Type
t Tele (Dom Type)
tel Permutation
perm Args
ctx =
forall (m :: * -> *) b d a.
Applicative m =>
(b -> m d) -> (a, b) -> m (a, d)
mapSndM forall a (m :: * -> *).
(InstantiateFull a, MonadReduce m) =>
a -> m a
instantiateFull forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *).
MonadMetaSolver m =>
Frozen
-> RunMetaOccursCheck
-> Comparison
-> Type
-> Tele (Dom Type)
-> Permutation
-> Args
-> m (MetaId, Term)
newValueMetaCtx' Frozen
frozen RunMetaOccursCheck
b Comparison
cmp Type
t Tele (Dom Type)
tel Permutation
perm Args
ctx
newValueMeta'
:: MonadMetaSolver m
=> RunMetaOccursCheck -> Comparison -> Type -> m (MetaId, Term)
newValueMeta' :: forall (m :: * -> *).
MonadMetaSolver m =>
RunMetaOccursCheck -> Comparison -> Type -> m (MetaId, Term)
newValueMeta' RunMetaOccursCheck
b Comparison
cmp Type
t = do
Args
vs <- forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m Args
getContextArgs
Tele (Dom Type)
tel <- forall (m :: * -> *).
(Applicative m, MonadTCEnv m) =>
m (Tele (Dom Type))
getContextTelescope
forall (m :: * -> *).
MonadMetaSolver m =>
Frozen
-> RunMetaOccursCheck
-> Comparison
-> Type
-> Tele (Dom Type)
-> Permutation
-> Args
-> m (MetaId, Term)
newValueMetaCtx' Frozen
Instantiable RunMetaOccursCheck
b Comparison
cmp Type
t Tele (Dom Type)
tel (Nat -> Permutation
idP forall a b. (a -> b) -> a -> b
$ forall a. Sized a => a -> Nat
size Tele (Dom Type)
tel) Args
vs
newValueMetaCtx'
:: MonadMetaSolver m
=> Frozen -> RunMetaOccursCheck -> Comparison -> Type -> Telescope -> Permutation -> Args -> m (MetaId, Term)
newValueMetaCtx' :: forall (m :: * -> *).
MonadMetaSolver m =>
Frozen
-> RunMetaOccursCheck
-> Comparison
-> Type
-> Tele (Dom Type)
-> Permutation
-> Args
-> m (MetaId, Term)
newValueMetaCtx' Frozen
frozen RunMetaOccursCheck
b Comparison
cmp Type
a Tele (Dom Type)
tel Permutation
perm Args
vs = do
MetaInfo
i <- forall (m :: * -> *).
(MonadTCEnv m, ReadTCState m) =>
RunMetaOccursCheck -> m MetaInfo
createMetaInfo' RunMetaOccursCheck
b
let t :: Type
t = Tele (Dom Type) -> Type -> Type
telePi_ Tele (Dom Type)
tel Type
a
MetaId
x <- forall (m :: * -> *) a.
MonadMetaSolver m =>
Frozen
-> MetaInfo
-> MetaPriority
-> Permutation
-> Judgement a
-> m MetaId
newMeta Frozen
frozen MetaInfo
i MetaPriority
normalMetaPriority Permutation
perm (forall a. a -> Comparison -> Type -> Judgement a
HasType () Comparison
cmp Type
t)
Modality
modality <- forall (m :: * -> *) a. MonadTCEnv m => Lens' a TCEnv -> m a
viewTC Lens' Modality TCEnv
eModality
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.new" Nat
50 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
fsep
[ forall (m :: * -> *). Applicative m => [Char] -> m Doc
text forall a b. (a -> b) -> a -> b
$ [Char]
"new meta (" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show (MetaInfo
i forall o i. o -> Lens' i o -> i
^. forall a. LensIsAbstract a => Lens' IsAbstract a
lensIsAbstract) forall a. [a] -> [a] -> [a]
++ [Char]
"):"
, forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Args
vs forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
"|-"
, forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty MetaId
x forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
":" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty Modality
modality forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
t
]
forall (m :: * -> *). MonadMetaSolver m => MetaId -> m ()
etaExpandMetaSafe MetaId
x
let u :: Term
u = MetaId -> Elims -> Term
MetaV MetaId
x forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall a. Arg a -> Elim' a
Apply Args
vs
forall (m :: * -> *).
(MonadConstraint m, MonadTCEnv m, ReadTCState m, MonadAddContext m,
HasOptions m, HasBuiltins m) =>
Term -> Tele (Dom Type) -> Type -> m ()
boundedSizeMetaHook Term
u Tele (Dom Type)
tel Type
a
forall (m :: * -> *) a. Monad m => a -> m a
return (MetaId
x, Term
u)
newTelMeta :: MonadMetaSolver m => Telescope -> m Args
newTelMeta :: forall (m :: * -> *).
MonadMetaSolver m =>
Tele (Dom Type) -> m Args
newTelMeta Tele (Dom Type)
tel = forall (m :: * -> *). MonadMetaSolver m => Type -> m Args
newArgsMeta (forall t. Abstract t => Tele (Dom Type) -> t -> t
abstract Tele (Dom Type)
tel forall a b. (a -> b) -> a -> b
$ HasCallStack => Type
__DUMMY_TYPE__)
type Condition = Dom Type -> Abs Type -> Bool
trueCondition :: Condition
trueCondition :: Condition
trueCondition Dom Type
_ Abs Type
_ = Bool
True
newArgsMeta :: MonadMetaSolver m => Type -> m Args
newArgsMeta :: forall (m :: * -> *). MonadMetaSolver m => Type -> m Args
newArgsMeta = forall (m :: * -> *).
MonadMetaSolver m =>
Condition -> Type -> m Args
newArgsMeta' Condition
trueCondition
newArgsMeta' :: MonadMetaSolver m => Condition -> Type -> m Args
newArgsMeta' :: forall (m :: * -> *).
MonadMetaSolver m =>
Condition -> Type -> m Args
newArgsMeta' Condition
condition Type
t = do
Args
args <- forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m Args
getContextArgs
Tele (Dom Type)
tel <- forall (m :: * -> *).
(Applicative m, MonadTCEnv m) =>
m (Tele (Dom Type))
getContextTelescope
forall (m :: * -> *).
MonadMetaSolver m =>
Frozen
-> Condition
-> Type
-> Tele (Dom Type)
-> Permutation
-> Args
-> m Args
newArgsMetaCtx' Frozen
Instantiable Condition
condition Type
t Tele (Dom Type)
tel (Nat -> Permutation
idP forall a b. (a -> b) -> a -> b
$ forall a. Sized a => a -> Nat
size Tele (Dom Type)
tel) Args
args
newArgsMetaCtx :: Type -> Telescope -> Permutation -> Args -> TCM Args
newArgsMetaCtx :: Type -> Tele (Dom Type) -> Permutation -> Args -> TCM Args
newArgsMetaCtx = forall (m :: * -> *).
MonadMetaSolver m =>
Frozen
-> Condition
-> Type
-> Tele (Dom Type)
-> Permutation
-> Args
-> m Args
newArgsMetaCtx' Frozen
Instantiable Condition
trueCondition
newArgsMetaCtx'
:: MonadMetaSolver m
=> Frozen -> Condition -> Type -> Telescope -> Permutation -> Args -> m Args
newArgsMetaCtx' :: forall (m :: * -> *).
MonadMetaSolver m =>
Frozen
-> Condition
-> Type
-> Tele (Dom Type)
-> Permutation
-> Args
-> m Args
newArgsMetaCtx' Frozen
frozen Condition
condition (El Sort' Term
s Term
tm) Tele (Dom Type)
tel Permutation
perm Args
ctx = do
Term
tm <- forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce Term
tm
case Term
tm of
Pi dom :: Dom Type
dom@(Dom{domInfo :: forall t e. Dom' t e -> ArgInfo
domInfo = ArgInfo
info, unDom :: forall t e. Dom' t e -> e
unDom = Type
a}) Abs Type
codom | Condition
condition Dom Type
dom Abs Type
codom -> do
let mod :: Modality
mod = forall a. LensModality a => a -> Modality
getModality ArgInfo
info
tel' :: Tele (Dom Type)
tel' = ListTel -> Tele (Dom Type)
telFromList forall a b. (a -> b) -> a -> b
$
forall a b. (a -> b) -> [a] -> [b]
map (Modality
mod forall a. LensModality a => Modality -> a -> a
`inverseApplyModalityButNotQuantity`) forall a b. (a -> b) -> a -> b
$
forall t. Tele (Dom t) -> [Dom ([Char], t)]
telToList Tele (Dom Type)
tel
ctx' :: Args
ctx' = forall a b. (a -> b) -> [a] -> [b]
map (Modality
mod forall a. LensModality a => Modality -> a -> a
`inverseApplyModalityButNotQuantity`) Args
ctx
(MetaId
m, Term
u) <- forall (tcm :: * -> *) m a.
(MonadTCEnv tcm, LensModality m) =>
m -> tcm a -> tcm a
applyModalityToContext ArgInfo
info forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *).
MonadMetaSolver m =>
Frozen
-> RunMetaOccursCheck
-> Comparison
-> Type
-> Tele (Dom Type)
-> Permutation
-> Args
-> m (MetaId, Term)
newValueMetaCtx Frozen
frozen RunMetaOccursCheck
RunMetaOccursCheck Comparison
CmpLeq Type
a Tele (Dom Type)
tel' Permutation
perm Args
ctx'
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM ((forall a. Eq a => a -> a -> Bool
== DoGeneralize
YesGeneralizeVar) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. MonadTCEnv m => Lens' a TCEnv -> m a
viewTC Lens' DoGeneralize TCEnv
eGeneralizeMetas) forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *).
MonadMetaSolver m =>
MetaId -> ArgInfo -> m ()
setMetaGeneralizableArgInfo MetaId
m forall a b. (a -> b) -> a -> b
$ forall a. LensHiding a => a -> a
hideOrKeepInstance ArgInfo
info
forall (m :: * -> *). MonadMetaSolver m => MetaId -> [Char] -> m ()
setMetaNameSuggestion MetaId
m (forall a. Abs a -> [Char]
absName Abs Type
codom)
Args
args <- forall (m :: * -> *).
MonadMetaSolver m =>
Frozen
-> Condition
-> Type
-> Tele (Dom Type)
-> Permutation
-> Args
-> m Args
newArgsMetaCtx' Frozen
frozen Condition
condition (Abs Type
codom forall a. Subst a => Abs a -> SubstArg a -> a
`absApp` Term
u) Tele (Dom Type)
tel Permutation
perm Args
ctx
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
info Term
u forall a. a -> [a] -> [a]
: Args
args
Term
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return []
newRecordMeta :: QName -> Args -> TCM Term
newRecordMeta :: QName -> Args -> TCM Term
newRecordMeta QName
r Args
pars = do
Args
args <- forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m Args
getContextArgs
Tele (Dom Type)
tel <- forall (m :: * -> *).
(Applicative m, MonadTCEnv m) =>
m (Tele (Dom Type))
getContextTelescope
Frozen
-> QName
-> Args
-> Tele (Dom Type)
-> Permutation
-> Args
-> TCM Term
newRecordMetaCtx Frozen
Instantiable QName
r Args
pars Tele (Dom Type)
tel (Nat -> Permutation
idP forall a b. (a -> b) -> a -> b
$ forall a. Sized a => a -> Nat
size Tele (Dom Type)
tel) Args
args
newRecordMetaCtx
:: Frozen
-> QName
-> Args
-> Telescope -> Permutation -> Args -> TCM Term
newRecordMetaCtx :: Frozen
-> QName
-> Args
-> Tele (Dom Type)
-> Permutation
-> Args
-> TCM Term
newRecordMetaCtx Frozen
frozen QName
r Args
pars Tele (Dom Type)
tel Permutation
perm Args
ctx = do
Tele (Dom Type)
ftel <- forall a b c. (a -> b -> c) -> b -> a -> c
flip forall t. Apply t => t -> Args -> t
apply Args
pars forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> QName -> TCMT IO (Tele (Dom Type))
getRecordFieldTypes QName
r
Args
fields <- forall (m :: * -> *).
MonadMetaSolver m =>
Frozen
-> Condition
-> Type
-> Tele (Dom Type)
-> Permutation
-> Args
-> m Args
newArgsMetaCtx' Frozen
frozen Condition
trueCondition
(Tele (Dom Type) -> Type -> Type
telePi_ Tele (Dom Type)
ftel HasCallStack => Type
__DUMMY_TYPE__) Tele (Dom Type)
tel Permutation
perm Args
ctx
ConHead
con <- forall (m :: * -> *).
(HasConstInfo m, ReadTCState m, MonadError TCErr m) =>
QName -> m ConHead
getRecordConstructor QName
r
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ConHead -> ConInfo -> Elims -> Term
Con ConHead
con ConInfo
ConOSystem (forall a b. (a -> b) -> [a] -> [b]
map forall a. Arg a -> Elim' a
Apply Args
fields)
newQuestionMark :: InteractionId -> Comparison -> Type -> TCM (MetaId, Term)
newQuestionMark :: InteractionId -> Comparison -> Type -> TCM (MetaId, Term)
newQuestionMark InteractionId
ii Comparison
cmp = (Comparison -> Type -> TCM (MetaId, Term))
-> InteractionId -> Comparison -> Type -> TCM (MetaId, Term)
newQuestionMark' (forall (m :: * -> *).
MonadMetaSolver m =>
RunMetaOccursCheck -> Comparison -> Type -> m (MetaId, Term)
newValueMeta' RunMetaOccursCheck
RunMetaOccursCheck) InteractionId
ii Comparison
cmp
newQuestionMark'
:: (Comparison -> Type -> TCM (MetaId, Term))
-> InteractionId -> Comparison -> Type -> TCM (MetaId, Term)
newQuestionMark' :: (Comparison -> Type -> TCM (MetaId, Term))
-> InteractionId -> Comparison -> Type -> TCM (MetaId, Term)
newQuestionMark' Comparison -> Type -> TCM (MetaId, Term)
new InteractionId
ii Comparison
cmp Type
t = forall (m :: * -> *).
ReadTCState m =>
InteractionId -> m (Maybe MetaId)
lookupInteractionMeta InteractionId
ii forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Maybe MetaId
Nothing -> do
(MetaId
x, Term
m) <- Comparison -> Type -> TCM (MetaId, Term)
new Comparison
cmp Type
t
forall (m :: * -> *).
MonadInteractionPoints m =>
InteractionId -> MetaId -> m ()
connectInteractionPoint InteractionId
ii MetaId
x
forall (m :: * -> *) a. Monad m => a -> m a
return (MetaId
x, Term
m)
Just MetaId
x -> do
MetaVar
{ mvInfo :: MetaVariable -> MetaInfo
mvInfo = MetaInfo{ miClosRange :: MetaInfo -> Closure Range
miClosRange = Closure{ clEnv :: forall a. Closure a -> TCEnv
clEnv = TCEnv{ envContext :: TCEnv -> Context
envContext = Context
gamma }}}
, mvPermutation :: MetaVariable -> Permutation
mvPermutation = Permutation
p
} <- forall a. a -> Maybe a -> a
fromMaybe forall a. HasCallStack => a
__IMPOSSIBLE__ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
ReadTCState m =>
MetaId -> m (Maybe MetaVariable)
lookupLocalMeta' MetaId
x
Context
delta <- forall (m :: * -> *). MonadTCEnv m => m Context
getContext
let glen :: Nat
glen = forall (t :: * -> *) a. Foldable t => t a -> Nat
length Context
gamma
let dlen :: Nat
dlen = forall (t :: * -> *) a. Foldable t => t a -> Nat
length Context
delta
let gxs :: [Name]
gxs = forall a b. (a -> b) -> [a] -> [b]
map (forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t e. Dom' t e -> e
unDom) Context
gamma
let dxs :: [Name]
dxs = forall a b. (a -> b) -> [a] -> [b]
map (forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t e. Dom' t e -> e
unDom) Context
delta
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.interaction" Nat
20 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"reusing meta"
, forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"creation context:" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty [Name]
gxs
, forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"reusage context:" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty [Name]
dxs
]
[Term]
rev_args <- case forall a. (a -> Bool) -> [a] -> Maybe Nat
List.findIndex Name -> Bool
nameIsRecordName [Name]
dxs of
Maybe Nat
Nothing -> do
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ([Name]
gxs forall a. Eq a => [a] -> [a] -> Bool
`List.isSuffixOf` [Name]
dxs) forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"impossible" Nat
10 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"expecting meta-creation context"
, forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty [Name]
gxs
, TCMT IO Doc
"to be a suffix of the meta-reuse context"
, forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty [Name]
dxs
]
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"impossible" Nat
70 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"expecting meta-creation context"
, forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ (forall (m :: * -> *). Applicative m => [Char] -> m Doc
text forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> [Char]
show) [Name]
gxs
, TCMT IO Doc
"to be a suffix of the meta-reuse context"
, forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ (forall (m :: * -> *). Applicative m => [Char] -> m Doc
text forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> [Char]
show) [Name]
dxs
]
forall a. HasCallStack => a
__IMPOSSIBLE__
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map Nat -> Term
var [Nat
dlen forall a. Num a => a -> a -> a
- Nat
glen .. Nat
dlen forall a. Num a => a -> a -> a
- Nat
1]
Just Nat
k -> do
let g0len :: Nat
g0len = forall (t :: * -> *) a. Foldable t => t a -> Nat
length [Name]
dxs forall a. Num a => a -> a -> a
- Nat
k forall a. Num a => a -> a -> a
- Nat
1
let gys :: [Name]
gys = forall a b. (a -> b) -> [a] -> [b]
map Name -> Name
nameCanonical [Name]
gxs
let dys :: [Name]
dys = forall a b. (a -> b) -> [a] -> [b]
map Name -> Name
nameCanonical [Name]
dxs
let (Nat
d2len, Nat
g1len) = forall a. Eq a => [a] -> [a] -> (Nat, Nat)
findOverlap (forall a. Nat -> [a] -> [a]
take Nat
k [Name]
dys) [Name]
gys
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.interaction" Nat
30 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2)
[ TCMT IO Doc
"glen =" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty Nat
glen
, TCMT IO Doc
"g0len =" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty Nat
g0len
, TCMT IO Doc
"g1len =" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty Nat
g1len
, TCMT IO Doc
"d2len =" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty Nat
d2len
]
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (forall a. Nat -> [a] -> [a]
drop (Nat
glen forall a. Num a => a -> a -> a
- Nat
g0len) [Name]
gxs forall a. Eq a => a -> a -> Bool
== forall a. Nat -> [a] -> [a]
drop (Nat
k forall a. Num a => a -> a -> a
+ Nat
1) [Name]
dxs) forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"impossible" Nat
10 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"expecting meta-creation context (with fields instead of record var)"
, forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty [Name]
gxs
, TCMT IO Doc
"to share ancestry (suffix) with the meta-reuse context (with record var)"
, forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty [Name]
dxs
]
forall a. HasCallStack => a
__IMPOSSIBLE__
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ( (forall a. Eq a => a -> a -> Bool
(==) forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` forall a. Nat -> [a] -> [a]
take Nat
g1len) [Name]
gys (forall a. Nat -> [a] -> [a]
drop Nat
d2len [Name]
dys) ) forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"impossible" Nat
10 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"expecting meta-creation context (with fields instead of record var)"
, forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty [Name]
gxs
, TCMT IO Doc
"to be an expansion of the meta-reuse context (with record var)"
, forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty [Name]
dxs
]
forall a. HasCallStack => a
__IMPOSSIBLE__
let ([Term]
vs1, Term
v : [Term]
vs0) = forall a. Nat -> [a] -> ([a], [a])
splitAt Nat
g1len forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map Nat -> Term
var [Nat
d2len..Nat
dlenforall a. Num a => a -> a -> a
-Nat
1]
let numFields :: Nat
numFields = Nat
glen forall a. Num a => a -> a -> a
- Nat
g1len forall a. Num a => a -> a -> a
- Nat
g0len
if Nat
numFields forall a. Ord a => a -> a -> Bool
<= Nat
0 then forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [Term]
vs1 forall a. [a] -> [a] -> [a]
++ [Term]
vs0 else do
let t :: Type
t = forall a b. (a, b) -> b
snd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t e. Dom' t e -> e
unDom forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a -> a
fromMaybe forall a. HasCallStack => a
__IMPOSSIBLE__ forall a b. (a -> b) -> a -> b
$ Context
delta forall a. [a] -> Nat -> Maybe a
!!! Nat
k
[Dom QName]
fs <- Type -> TCM [Dom QName]
getRecordTypeFields Type
t
let vfs :: [Term]
vfs = forall a b. (a -> b) -> [a] -> [b]
map ((\ QName
x -> Term
v forall t. Apply t => t -> Elims -> t
`applyE` [forall a. ProjOrigin -> QName -> Elim' a
Proj ProjOrigin
ProjSystem QName
x]) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t e. Dom' t e -> e
unDom) [Dom QName]
fs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [Term]
vs1 forall a. [a] -> [a] -> [a]
++ forall a. [a] -> [a]
reverse (forall a. Nat -> [a] -> [a]
take Nat
numFields [Term]
vfs) forall a. [a] -> [a] -> [a]
++ [Term]
vs0
let args :: Args
args = forall a. [a] -> [a]
reverse forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith forall (f :: * -> *) a b. Functor f => a -> f b -> f a
(<$) [Term]
rev_args forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall t a. Dom' t a -> Arg a
argFromDom Context
gamma
let vs :: Args
vs = forall a. Permutation -> [a] -> [a]
permute (Nat -> Permutation -> Permutation
takeP (forall (t :: * -> *) a. Foldable t => t a -> Nat
length Args
args) Permutation
p) Args
args
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.interaction" Nat
20 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"meta reuse arguments:" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Args
vs ]
forall (m :: * -> *) a. Monad m => a -> m a
return (MetaId
x, MetaId -> Elims -> Term
MetaV MetaId
x forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall a. Arg a -> Elim' a
Apply Args
vs)
blockTerm
:: (MonadMetaSolver m, MonadConstraint m, MonadFresh Nat m, MonadFresh ProblemId m)
=> Type -> m Term -> m Term
blockTerm :: forall (m :: * -> *).
(MonadMetaSolver m, MonadConstraint m, MonadFresh Nat m,
MonadFresh ProblemId m) =>
Type -> m Term -> m Term
blockTerm Type
t m Term
blocker = do
(ProblemId
pid, Term
v) <- forall (m :: * -> *) a.
(MonadFresh ProblemId m, MonadConstraint m) =>
m a -> m (ProblemId, a)
newProblem m Term
blocker
forall (m :: * -> *).
(MonadMetaSolver m, MonadFresh Nat m) =>
Type -> Term -> ProblemId -> m Term
blockTermOnProblem Type
t Term
v ProblemId
pid
blockTermOnProblem
:: (MonadMetaSolver m, MonadFresh Nat m)
=> Type -> Term -> ProblemId -> m Term
blockTermOnProblem :: forall (m :: * -> *).
(MonadMetaSolver m, MonadFresh Nat m) =>
Type -> Term -> ProblemId -> m Term
blockTermOnProblem Type
t Term
v ProblemId
pid = do
Bool
solved <- forall (m :: * -> *).
(MonadTCEnv m, ReadTCState m) =>
ProblemId -> m Bool
isProblemSolved ProblemId
pid
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
ifM (forall (m :: * -> *) a. Monad m => a -> m a
return Bool
solved forall (m :: * -> *). Monad m => m Bool -> m Bool -> m Bool
`or2M` forall (m :: * -> *).
(ReadTCState m, HasOptions m, HasBuiltins m) =>
ProblemId -> m Bool
isSizeProblem ProblemId
pid)
(Term
v forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> [Char] -> m ()
reportSLn [Char]
"tc.meta.blocked" Nat
20 ([Char]
"Not blocking because " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show ProblemId
pid forall a. [a] -> [a] -> [a]
++ [Char]
" is " forall a. [a] -> [a] -> [a]
++
if Bool
solved then [Char]
"solved" else [Char]
"a size problem")) forall a b. (a -> b) -> a -> b
$ do
MetaInfo
i <- forall (m :: * -> *). (MonadTCEnv m, ReadTCState m) => m MetaInfo
createMetaInfo
Elims
es <- forall a b. (a -> b) -> [a] -> [b]
map forall a. Arg a -> Elim' a
Apply forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m Args
getContextArgs
Tele (Dom Type)
tel <- forall (m :: * -> *).
(Applicative m, MonadTCEnv m) =>
m (Tele (Dom Type))
getContextTelescope
MetaId
x <- forall (m :: * -> *) a.
MonadMetaSolver m =>
MetaInstantiation
-> Frozen
-> MetaInfo
-> MetaPriority
-> Permutation
-> Judgement a
-> m MetaId
newMeta' (Term -> MetaInstantiation
BlockedConst forall a b. (a -> b) -> a -> b
$ forall t. Abstract t => Tele (Dom Type) -> t -> t
abstract Tele (Dom Type)
tel Term
v)
Frozen
Instantiable
MetaInfo
i
MetaPriority
lowMetaPriority
(Nat -> Permutation
idP forall a b. (a -> b) -> a -> b
$ forall a. Sized a => a -> Nat
size Tele (Dom Type)
tel)
(forall a. a -> Comparison -> Type -> Judgement a
HasType () Comparison
CmpLeq forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> Type -> Type
telePi_ Tele (Dom Type)
tel Type
t)
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
MonadConstraint m =>
Blocker -> Constraint -> m ()
addConstraint (ProblemId -> Blocker
unblockOnProblem ProblemId
pid) (MetaId -> Constraint
UnBlock MetaId
x)
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.blocked" Nat
20 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"blocked" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM MetaId
x forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
":=" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext
(forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM forall a b. (a -> b) -> a -> b
$ forall t. Abstract t => Tele (Dom Type) -> t -> t
abstract Tele (Dom Type)
tel Term
v)
, TCMT IO Doc
" by" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> (forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *). ReadTCState m => ProblemId -> m Constraints
getConstraintsForProblem ProblemId
pid)
]
Bool
inst <- forall a (m :: * -> *).
(IsInstantiatedMeta a, MonadFail m, ReadTCState m) =>
a -> m Bool
isInstantiatedMeta MetaId
x
if Bool
inst
then forall a (m :: * -> *). (Instantiate a, MonadReduce m) => a -> m a
instantiate (MetaId -> Elims -> Term
MetaV MetaId
x Elims
es)
else do
(MetaId
m', Term
v) <- forall (m :: * -> *).
MonadMetaSolver m =>
RunMetaOccursCheck -> Comparison -> Type -> m (MetaId, Term)
newValueMeta RunMetaOccursCheck
DontRunMetaOccursCheck Comparison
CmpLeq Type
t
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.blocked" Nat
30
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"setting twin of"
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM MetaId
m'
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
"to be"
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM MetaId
x
forall (m :: * -> *).
MonadMetaSolver m =>
MetaId -> (MetaVariable -> MetaVariable) -> m ()
updateMetaVar MetaId
m' (\MetaVariable
mv -> MetaVariable
mv { mvTwin :: Maybe MetaId
mvTwin = forall a. a -> Maybe a
Just MetaId
x })
Nat
i <- forall i (m :: * -> *). MonadFresh i m => m i
fresh
ProblemConstraint
cmp <- forall (m :: * -> *).
(MonadTCEnv m, ReadTCState m) =>
Blocker -> Constraint -> m ProblemConstraint
buildProblemConstraint_ (MetaId -> Blocker
unblockOnMeta MetaId
x) (Comparison -> CompareAs -> Term -> Term -> Constraint
ValueCmp Comparison
CmpEq (Type -> CompareAs
AsTermsOf Type
t) Term
v (MetaId -> Elims -> Term
MetaV MetaId
x Elims
es))
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.constr.add" Nat
20 forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"adding constraint" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM ProblemConstraint
cmp
forall (m :: * -> *).
MonadMetaSolver m =>
Listener -> MetaId -> m ()
listenToMeta (Nat -> ProblemConstraint -> Listener
CheckConstraint Nat
i ProblemConstraint
cmp) MetaId
x
forall (m :: * -> *) a. Monad m => a -> m a
return Term
v
blockTypeOnProblem
:: (MonadMetaSolver m, MonadFresh Nat m)
=> Type -> ProblemId -> m Type
blockTypeOnProblem :: forall (m :: * -> *).
(MonadMetaSolver m, MonadFresh Nat m) =>
Type -> ProblemId -> m Type
blockTypeOnProblem (El Sort' Term
s Term
a) ProblemId
pid = forall t a. Sort' t -> a -> Type'' t a
El Sort' Term
s forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
(MonadMetaSolver m, MonadFresh Nat m) =>
Type -> Term -> ProblemId -> m Term
blockTermOnProblem (Sort' Term -> Type
sort Sort' Term
s) Term
a ProblemId
pid
unblockedTester :: Type -> TCM Blocker
unblockedTester :: Type -> TCM Blocker
unblockedTester Type
t = forall t (m :: * -> *) a.
(Reduce t, IsMeta t, MonadReduce m) =>
t -> (Blocker -> t -> m a) -> (NotBlocked -> t -> m a) -> m a
ifBlocked Type
t (\ Blocker
b Type
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return Blocker
b) (\ NotBlocked
_ Type
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return Blocker
alwaysUnblock)
postponeTypeCheckingProblem_ :: TypeCheckingProblem -> TCM Term
postponeTypeCheckingProblem_ :: TypeCheckingProblem -> TCM Term
postponeTypeCheckingProblem_ TypeCheckingProblem
p = do
TypeCheckingProblem -> Blocker -> TCM Term
postponeTypeCheckingProblem TypeCheckingProblem
p forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TypeCheckingProblem -> TCM Blocker
unblock TypeCheckingProblem
p
where
unblock :: TypeCheckingProblem -> TCM Blocker
unblock (CheckExpr Comparison
_ Expr
_ Type
t) = Type -> TCM Blocker
unblockedTester Type
t
unblock (CheckArgs Comparison
_ ExpandHidden
_ Range
_ [NamedArg Expr]
_ Type
t Type
_ ArgsCheckState CheckedTarget -> TCM Term
_) = Type -> TCM Blocker
unblockedTester Type
t
unblock (CheckProjAppToKnownPrincipalArg Comparison
_ Expr
_ ProjOrigin
_ List1 QName
_ [NamedArg Expr]
_ Type
_ Nat
_ Term
_ Type
t PrincipalArgTypeMetas
_) = Type -> TCM Blocker
unblockedTester Type
t
unblock (CheckLambda Comparison
_ Arg (List1 (WithHiding Name), Maybe Type)
_ Expr
_ Type
t) = Type -> TCM Blocker
unblockedTester Type
t
unblock (DoQuoteTerm Comparison
_ Term
_ Type
_) = forall a. HasCallStack => a
__IMPOSSIBLE__
postponeTypeCheckingProblem :: TypeCheckingProblem -> Blocker -> TCM Term
postponeTypeCheckingProblem :: TypeCheckingProblem -> Blocker -> TCM Term
postponeTypeCheckingProblem TypeCheckingProblem
p Blocker
unblock | Blocker
unblock forall a. Eq a => a -> a -> Bool
== Blocker
alwaysUnblock = do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"impossible" Nat
2 forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"Postponed without blocker:" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<?> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM TypeCheckingProblem
p
forall a. HasCallStack => a
__IMPOSSIBLE__
postponeTypeCheckingProblem TypeCheckingProblem
p Blocker
unblock = do
MetaInfo
i <- forall (m :: * -> *).
(MonadTCEnv m, ReadTCState m) =>
RunMetaOccursCheck -> m MetaInfo
createMetaInfo' RunMetaOccursCheck
DontRunMetaOccursCheck
Tele (Dom Type)
tel <- forall (m :: * -> *).
(Applicative m, MonadTCEnv m) =>
m (Tele (Dom Type))
getContextTelescope
Closure TypeCheckingProblem
cl <- forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m) =>
a -> m (Closure a)
buildClosure TypeCheckingProblem
p
let t :: Type
t = TypeCheckingProblem -> Type
problemType TypeCheckingProblem
p
MetaId
m <- forall (m :: * -> *) a.
MonadMetaSolver m =>
MetaInstantiation
-> Frozen
-> MetaInfo
-> MetaPriority
-> Permutation
-> Judgement a
-> m MetaId
newMeta' (Closure TypeCheckingProblem -> MetaInstantiation
PostponedTypeCheckingProblem Closure TypeCheckingProblem
cl)
Frozen
Instantiable MetaInfo
i MetaPriority
normalMetaPriority (Nat -> Permutation
idP (forall a. Sized a => a -> Nat
size Tele (Dom Type)
tel))
forall a b. (a -> b) -> a -> b
$ forall a. a -> Comparison -> Type -> Judgement a
HasType () Comparison
CmpLeq forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> Type -> Type
telePi_ Tele (Dom Type)
tel Type
t
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.postponed" Nat
20 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"new meta" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM MetaId
m forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
":" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM (Tele (Dom Type) -> Type -> Type
telePi_ Tele (Dom Type)
tel Type
t)
, TCMT IO Doc
"for postponed typechecking problem" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM TypeCheckingProblem
p
]
Elims
es <- forall a b. (a -> b) -> [a] -> [b]
map forall a. Arg a -> Elim' a
Apply forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m Args
getContextArgs
(MetaId
_, Term
v) <- forall (m :: * -> *).
MonadMetaSolver m =>
RunMetaOccursCheck -> Comparison -> Type -> m (MetaId, Term)
newValueMeta RunMetaOccursCheck
DontRunMetaOccursCheck Comparison
CmpLeq Type
t
ProblemConstraint
cmp <- forall (m :: * -> *).
(MonadTCEnv m, ReadTCState m) =>
Blocker -> Constraint -> m ProblemConstraint
buildProblemConstraint_ (MetaId -> Blocker
unblockOnMeta MetaId
m) (Comparison -> CompareAs -> Term -> Term -> Constraint
ValueCmp Comparison
CmpEq (Type -> CompareAs
AsTermsOf Type
t) Term
v (MetaId -> Elims -> Term
MetaV MetaId
m Elims
es))
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.constr.add" Nat
20 forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"adding constraint" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM ProblemConstraint
cmp
Nat
i <- forall (tcm :: * -> *) a. MonadTCM tcm => TCM a -> tcm a
liftTCM forall i (m :: * -> *). MonadFresh i m => m i
fresh
forall (m :: * -> *).
MonadMetaSolver m =>
Listener -> MetaId -> m ()
listenToMeta (Nat -> ProblemConstraint -> Listener
CheckConstraint Nat
i ProblemConstraint
cmp) MetaId
m
forall (m :: * -> *).
MonadConstraint m =>
Blocker -> Constraint -> m ()
addConstraint Blocker
unblock (MetaId -> Constraint
UnBlock MetaId
m)
forall (m :: * -> *) a. Monad m => a -> m a
return Term
v
problemType :: TypeCheckingProblem -> Type
problemType :: TypeCheckingProblem -> Type
problemType (CheckExpr Comparison
_ Expr
_ Type
t ) = Type
t
problemType (CheckArgs Comparison
_ ExpandHidden
_ Range
_ [NamedArg Expr]
_ Type
_ Type
t ArgsCheckState CheckedTarget -> TCM Term
_ ) = Type
t
problemType (CheckProjAppToKnownPrincipalArg Comparison
_ Expr
_ ProjOrigin
_ List1 QName
_ [NamedArg Expr]
_ Type
t Nat
_ Term
_ Type
_ PrincipalArgTypeMetas
_) = Type
t
problemType (CheckLambda Comparison
_ Arg (List1 (WithHiding Name), Maybe Type)
_ Expr
_ Type
t ) = Type
t
problemType (DoQuoteTerm Comparison
_ Term
_ Type
t) = Type
t
etaExpandMetaTCM :: [MetaKind] -> MetaId -> TCM ()
etaExpandMetaTCM :: [MetaKind] -> MetaId -> TCM ()
etaExpandMetaTCM [MetaKind]
kinds MetaId
m = forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM ((Bool -> Bool
not forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
(HasCallStack, MonadDebug m, ReadTCState m) =>
MetaId -> m Bool
isFrozen MetaId
m) forall (m :: * -> *). Monad m => m Bool -> m Bool -> m Bool
`and2M` forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC TCEnv -> Bool
envAssignMetas forall (m :: * -> *). Monad m => m Bool -> m Bool -> m Bool
`and2M` [MetaKind] -> MetaId -> TCM Bool
isEtaExpandable [MetaKind]
kinds MetaId
m) forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *) a.
MonadDebug m =>
[Char] -> Nat -> [Char] -> m a -> m a
verboseBracket [Char]
"tc.meta.eta" Nat
20 ([Char]
"etaExpandMeta " forall a. [a] -> [a] -> [a]
++ forall a. Pretty a => a -> [Char]
prettyShow MetaId
m) forall a b. (a -> b) -> a -> b
$ do
let waitFor :: Blocker -> TCM ()
waitFor Blocker
b = do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.eta" Nat
20 forall a b. (a -> b) -> a -> b
$ do
TCMT IO Doc
"postponing eta-expansion of meta variable" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+>
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM MetaId
m forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+>
TCMT IO Doc
"which is blocked by" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Blocker
b
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (forall (m :: * -> *).
MonadMetaSolver m =>
Listener -> MetaId -> m ()
listenToMeta (MetaId -> Listener
EtaExpand MetaId
m)) forall a b. (a -> b) -> a -> b
$ forall a. Set a -> [a]
Set.toList forall a b. (a -> b) -> a -> b
$ Blocker -> Set MetaId
allBlockingMetas Blocker
b
dontExpand :: TCM ()
dontExpand = do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.eta" Nat
20 forall a b. (a -> b) -> a -> b
$ do
TCMT IO Doc
"we do not expand meta variable" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM MetaId
m forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+>
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char]
"(requested was expansion of " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show [MetaKind]
kinds forall a. [a] -> [a] -> [a]
++ [Char]
")")
MetaVariable
meta <- forall (m :: * -> *).
(HasCallStack, MonadDebug m, ReadTCState m) =>
MetaId -> m MetaVariable
lookupLocalMeta MetaId
m
case MetaVariable -> Judgement MetaId
mvJudgement MetaVariable
meta of
IsSort{} -> TCM ()
dontExpand
HasType MetaId
_ Comparison
cmp Type
a -> do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.eta" Nat
40 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
sep
[ forall (m :: * -> *). Applicative m => [Char] -> m Doc
text [Char]
"considering eta-expansion at type "
, forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
a
, forall (m :: * -> *). Applicative m => [Char] -> m Doc
text [Char]
" raw: "
, forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty Type
a
]
TelV Tele (Dom Type)
tel Type
b <- forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Type -> m (TelV Type)
telView Type
a
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.eta" Nat
40 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
sep
[ forall (m :: * -> *). Applicative m => [Char] -> m Doc
text [Char]
"considering eta-expansion at type"
, forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Tele (Dom Type)
tel (forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
b)
, forall (m :: * -> *). Applicative m => [Char] -> m Doc
text [Char]
"under telescope"
, forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Tele (Dom Type)
tel
]
if forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any forall t e. Dom' t e -> Bool
domIsFinite (forall a. TermSubst a => Tele (Dom a) -> [Dom a]
flattenTel Tele (Dom Type)
tel) then TCM ()
dontExpand else do
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Tele (Dom Type)
tel forall a b. (a -> b) -> a -> b
$ do
forall t (m :: * -> *) a.
(Reduce t, IsMeta t, MonadReduce m) =>
t -> (Blocker -> t -> m a) -> (NotBlocked -> t -> m a) -> m a
ifBlocked (forall t a. Type'' t a -> a
unEl Type
b) (\ Blocker
x Term
_ -> Blocker -> TCM ()
waitFor Blocker
x) forall a b. (a -> b) -> a -> b
$ \ NotBlocked
_ Term
t -> case Term
t of
lvl :: Term
lvl@(Def QName
r Elims
es) ->
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
ifM (forall (m :: * -> *). HasConstInfo m => QName -> m Bool
isEtaRecord QName
r) (do
let ps :: Args
ps = forall a. a -> Maybe a -> a
fromMaybe forall a. HasCallStack => a
__IMPOSSIBLE__ forall a b. (a -> b) -> a -> b
$ forall a. [Elim' a] -> Maybe [Arg a]
allApplyElims Elims
es
let expand :: TCM ()
expand = do
Term
u <- forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadTrace m) =>
MetaVariable -> m a -> m a
withMetaInfo' MetaVariable
meta forall a b. (a -> b) -> a -> b
$
Frozen
-> QName
-> Args
-> Tele (Dom Type)
-> Permutation
-> Args
-> TCM Term
newRecordMetaCtx (MetaVariable -> Frozen
mvFrozen MetaVariable
meta) QName
r Args
ps Tele (Dom Type)
tel (Nat -> Permutation
idP forall a b. (a -> b) -> a -> b
$ forall a. Sized a => a -> Nat
size Tele (Dom Type)
tel) forall a b. (a -> b) -> a -> b
$ forall a t. DeBruijn a => Tele (Dom t) -> [Arg a]
teleArgs Tele (Dom Type)
tel
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.eta" Nat
15 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
sep
[ TCMT IO Doc
"eta expanding: " forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty MetaId
m forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
" --> "
, forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Term
u
]
forall (m :: * -> *) a.
(MonadConstraint m, MonadWarning m, MonadError TCErr m,
MonadFresh ProblemId m) =>
m a -> m a
noConstraints forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
(MonadMetaSolver m, MonadMetaSolver m) =>
MetaId -> [Arg [Char]] -> Term -> m ()
assignTerm' MetaId
m (forall a. TelToArgs a => a -> [Arg [Char]]
telToArgs Tele (Dom Type)
tel) Term
u
if MetaKind
Records forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [MetaKind]
kinds then
TCM ()
expand
else if (MetaKind
SingletonRecords forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [MetaKind]
kinds) then
forall (m :: * -> *) a.
MonadBlock m =>
(Blocker -> m a) -> m a -> m a
catchPatternErr (\Blocker
x -> Blocker -> TCM ()
waitFor Blocker
x) forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
ifM (forall (m :: * -> *).
(PureTCM m, MonadBlock m) =>
QName -> Args -> m Bool
isSingletonRecord QName
r Args
ps) TCM ()
expand TCM ()
dontExpand
else TCM ()
dontExpand
) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
ifM (forall (f :: * -> *) (m :: * -> *).
(Foldable f, Monad m) =>
f (m Bool) -> m Bool
andM [ forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ MetaKind
Levels forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [MetaKind]
kinds
, forall (m :: * -> *). HasOptions m => m Bool
typeInType
, (forall a. a -> Maybe a
Just Term
lvl forall a. Eq a => a -> a -> Bool
==) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). HasBuiltins m => [Char] -> m (Maybe Term)
getBuiltin' [Char]
builtinLevel
]) (do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> [Char] -> m ()
reportSLn [Char]
"tc.meta.eta" Nat
20 forall a b. (a -> b) -> a -> b
$ [Char]
"Expanding level meta to 0 (type-in-type)"
forall (m :: * -> *) a.
(MonadConstraint m, MonadWarning m, MonadError TCErr m,
MonadFresh ProblemId m) =>
m a -> m a
noConstraints forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
MonadMetaSolver m =>
MetaId -> [Arg [Char]] -> Term -> m ()
assignTerm MetaId
m (forall a. TelToArgs a => a -> [Arg [Char]]
telToArgs Tele (Dom Type)
tel) forall a b. (a -> b) -> a -> b
$ Level -> Term
Level forall a b. (a -> b) -> a -> b
$ Integer -> Level
ClosedLevel Integer
0
) forall a b. (a -> b) -> a -> b
$ TCM ()
dontExpand
Term
_ -> TCM ()
dontExpand
etaExpandBlocked :: (MonadReduce m, MonadMetaSolver m, IsMeta t, Reduce t)
=> Blocked t -> m (Blocked t)
etaExpandBlocked :: forall (m :: * -> *) t.
(MonadReduce m, MonadMetaSolver m, IsMeta t, Reduce t) =>
Blocked t -> m (Blocked t)
etaExpandBlocked t :: Blocked t
t@NotBlocked{} = forall (m :: * -> *) a. Monad m => a -> m a
return Blocked t
t
etaExpandBlocked t :: Blocked t
t@(Blocked Blocker
_ t
v) | Just{} <- forall a. IsMeta a => a -> Maybe MetaId
isMeta t
v = forall (m :: * -> *) a. Monad m => a -> m a
return Blocked t
t
etaExpandBlocked (Blocked Blocker
b t
t) = do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.eta" Nat
30 forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"Eta expanding blockers" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty Blocker
b
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (forall (m :: * -> *).
MonadMetaSolver m =>
[MetaKind] -> MetaId -> m ()
etaExpandMeta [MetaKind
Records]) forall a b. (a -> b) -> a -> b
$ forall a. Set a -> [a]
Set.toList forall a b. (a -> b) -> a -> b
$ Blocker -> Set MetaId
allBlockingMetas Blocker
b
Blocked t
t <- forall a (m :: * -> *).
(Reduce a, MonadReduce m) =>
a -> m (Blocked a)
reduceB t
t
case Blocked t
t of
Blocked Blocker
b' t
_ | Blocker
b forall a. Eq a => a -> a -> Bool
/= Blocker
b' -> forall (m :: * -> *) t.
(MonadReduce m, MonadMetaSolver m, IsMeta t, Reduce t) =>
Blocked t -> m (Blocked t)
etaExpandBlocked Blocked t
t
Blocked t
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return Blocked t
t
assignWrapper :: (MonadMetaSolver m, MonadConstraint m, MonadError TCErr m, MonadDebug m, HasOptions m)
=> CompareDirection -> MetaId -> Elims -> Term -> m () -> m ()
assignWrapper :: forall (m :: * -> *).
(MonadMetaSolver m, MonadConstraint m, MonadError TCErr m,
MonadDebug m, HasOptions m) =>
CompareDirection -> MetaId -> Elims -> Term -> m () -> m ()
assignWrapper CompareDirection
dir MetaId
x Elims
es Term
v m ()
doAssign = do
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
ifNotM (forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC TCEnv -> Bool
envAssignMetas) forall {b}. m b
dontAssign forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign" Nat
10 forall a b. (a -> b) -> a -> b
$ do
TCMT IO Doc
"term" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM (MetaId -> Elims -> Term
MetaV MetaId
x Elims
es) forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char]
":" forall a. [a] -> [a] -> [a]
++ forall a. Pretty a => a -> [Char]
prettyShow CompareDirection
dir) forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Term
v
forall (m :: * -> *) a. MonadTCEnv m => m a -> m a
nowSolvingConstraints m ()
doAssign forall e (m :: * -> *) a. MonadError e m => m a -> m () -> m a
`finally` forall (m :: * -> *). MonadConstraint m => m ()
solveAwakeConstraints
where dontAssign :: m b
dontAssign = do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> [Char] -> m ()
reportSLn [Char]
"tc.meta.assign" Nat
10 [Char]
"don't assign metas"
forall (m :: * -> *) a. MonadBlock m => Blocker -> m a
patternViolation Blocker
alwaysUnblock
assign :: CompareDirection -> MetaId -> Args -> Term -> CompareAs -> TCM ()
assign :: CompareDirection -> MetaId -> Args -> Term -> CompareAs -> TCM ()
assign CompareDirection
dir MetaId
x Args
args Term
v CompareAs
target = forall (m :: * -> *) a. MonadBlock m => Blocker -> m a -> m a
addOrUnblocker (MetaId -> Blocker
unblockOnMeta MetaId
x) forall a b. (a -> b) -> a -> b
$ do
MetaVariable
mvar <- forall (m :: * -> *).
(HasCallStack, MonadDebug m, ReadTCState m) =>
MetaId -> m MetaVariable
lookupLocalMeta MetaId
x
let t :: Type
t = forall a. Judgement a -> Type
jMetaType forall a b. (a -> b) -> a -> b
$ MetaVariable -> Judgement MetaId
mvJudgement MetaVariable
mvar
Term
v <- forall a (m :: * -> *). (Instantiate a, MonadReduce m) => a -> m a
instantiate Term
v
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign" Nat
45 forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"MetaVars.assign: assigning meta " forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM (MetaId -> Elims -> Term
MetaV MetaId
x []) forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+>
TCMT IO Doc
" with args " forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *) (t :: * -> *).
(Applicative m, Semigroup (m Doc), Foldable t) =>
t (m Doc) -> m Doc
prettyList_ (forall a b. (a -> b) -> [a] -> [b]
map (forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e. Arg e -> e
unArg) Args
args) forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+>
TCMT IO Doc
" to " forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Term
v
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign" Nat
45 forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"MetaVars.assign: type of meta: " forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
t
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign" Nat
75 forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text [Char]
"MetaVars.assign: assigning meta " forall a. Semigroup a => a -> a -> a
<> forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty MetaId
x forall a. Semigroup a => a -> a -> a
<> forall (m :: * -> *). Applicative m => [Char] -> m Doc
text [Char]
" with args " forall a. Semigroup a => a -> a -> a
<> forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty Args
args forall a. Semigroup a => a -> a -> a
<> forall (m :: * -> *). Applicative m => [Char] -> m Doc
text [Char]
" to " forall a. Semigroup a => a -> a -> a
<> forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty Term
v
case (Term
v, MetaVariable -> Judgement MetaId
mvJudgement MetaVariable
mvar) of
(Sort Sort' Term
s, HasType{}) -> Sort' Term -> TCM ()
hasBiggerSort Sort' Term
s
(Term, Judgement MetaId)
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
Bool
cumulativity <- PragmaOptions -> Bool
optCumulativity forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). HasOptions m => m PragmaOptions
pragmaOptions
let checkSolutionSort :: Comparison -> Sort' Term -> Term -> TCM ()
checkSolutionSort Comparison
cmp Sort' Term
s Term
v = do
Sort' Term
s' <- forall (m :: * -> *).
(PureTCM m, MonadBlock m) =>
Term -> m (Sort' Term)
sortOf Term
v
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign" Nat
40 forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"Instantiating sort" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Sort' Term
s forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+>
TCMT IO Doc
"to sort" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Sort' Term
s' forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
"of solution" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Term
v
forall (m :: * -> *) a. MonadTrace m => Call -> m a -> m a
traceCall (Range -> MetaId -> Type -> Term -> Call
CheckMetaSolution (forall a. HasRange a => a -> Range
getRange MetaVariable
mvar) MetaId
x (Sort' Term -> Type
sort Sort' Term
s) Term
v) forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *).
MonadConversion m =>
Comparison -> Sort' Term -> Sort' Term -> m ()
compareSort Comparison
cmp Sort' Term
s' Sort' Term
s
case (CompareAs
target , MetaVariable -> Judgement MetaId
mvJudgement MetaVariable
mvar) of
(AsTypes{} , HasType MetaId
_ Comparison
cmp0 Type
t) -> do
let cmp :: Comparison
cmp = if Bool
cumulativity then Comparison
cmp0 else Comparison
CmpEq
abort :: TCMT IO Empty
abort = forall (m :: * -> *) a. MonadBlock m => Blocker -> m a
patternViolation forall a b. (a -> b) -> a -> b
$ forall t. AllMetas t => t -> Blocker
unblockOnAnyMetaIn Type
t
Type
t' <- forall a (m :: * -> *).
(PiApplyM a, MonadReduce m, HasBuiltins m) =>
m Empty -> Type -> a -> m Type
piApplyM' TCMT IO Empty
abort Type
t Args
args
Sort' Term
s <- forall (m :: * -> *).
(PureTCM m, MonadBlock m, MonadError TCErr m) =>
Type -> m (Sort' Term)
shouldBeSort Type
t'
Comparison -> Sort' Term -> Term -> TCM ()
checkSolutionSort Comparison
cmp Sort' Term
s Term
v
(AsTermsOf{} , HasType MetaId
_ Comparison
cmp Type
t)
| Bool
cumulativity -> do
let abort :: TCMT IO Empty
abort = forall (m :: * -> *) a. MonadBlock m => Blocker -> m a
patternViolation forall a b. (a -> b) -> a -> b
$ forall t. AllMetas t => t -> Blocker
unblockOnAnyMetaIn Type
t
Type
t' <- forall a (m :: * -> *).
(PiApplyM a, MonadReduce m, HasBuiltins m) =>
m Empty -> Type -> a -> m Type
piApplyM' TCMT IO Empty
abort Type
t Args
args
TelV Tele (Dom Type)
tel Type
t'' <- forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Type -> m (TelV Type)
telView Type
t'
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Tele (Dom Type)
tel forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a.
(MonadReduce m, MonadBlock m) =>
Type -> m a -> (Sort' Term -> m a) -> m a
ifNotSort Type
t'' (forall (m :: * -> *) a. Monad m => a -> m a
return ()) forall a b. (a -> b) -> a -> b
$ \Sort' Term
s -> do
let v' :: Term
v' = forall a. Subst a => Nat -> a -> a
raise (forall a. Sized a => a -> Nat
size Tele (Dom Type)
tel) Term
v forall t. Apply t => t -> Args -> t
`apply` forall a t. DeBruijn a => Tele (Dom t) -> [Arg a]
teleArgs Tele (Dom Type)
tel
Comparison -> Sort' Term -> Term -> TCM ()
checkSolutionSort Comparison
cmp Sort' Term
s Term
v'
(AsTypes{} , IsSort{} ) -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
(AsTermsOf{} , Judgement MetaId
_ ) -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
(AsSizes{} , Judgement MetaId
_ ) -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (MetaVariable -> Frozen
mvFrozen MetaVariable
mvar forall a. Eq a => a -> a -> Bool
== Frozen
Frozen) forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> [Char] -> m ()
reportSLn [Char]
"tc.meta.assign" Nat
25 forall a b. (a -> b) -> a -> b
$ [Char]
"aborting: meta is frozen!"
forall (m :: * -> *) a. MonadBlock m => Blocker -> m a
patternViolation Blocker
neverUnblock
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM (MetaId -> TCM Bool
isBlockedTerm MetaId
x) forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> [Char] -> m ()
reportSLn [Char]
"tc.meta.assign" Nat
25 forall a b. (a -> b) -> a -> b
$ [Char]
"aborting: meta is a blocked term!"
forall (m :: * -> *) a. MonadBlock m => Blocker -> m a
patternViolation (MetaId -> Blocker
unblockOnMeta MetaId
x)
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> [Char] -> m ()
reportSLn [Char]
"tc.meta.assign" Nat
50 forall a b. (a -> b) -> a -> b
$ [Char]
"MetaVars.assign: I want to see whether rhs is blocked"
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign" Nat
25 forall a b. (a -> b) -> a -> b
$ do
Blocked Term
v0 <- forall a (m :: * -> *).
(Reduce a, MonadReduce m) =>
a -> m (Blocked a)
reduceB Term
v
case Blocked Term
v0 of
Blocked Blocker
m0 Term
_ -> TCMT IO Doc
"r.h.s. blocked on:" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Blocker
m0
NotBlocked{} -> TCMT IO Doc
"r.h.s. not blocked"
CompareDirection
-> MetaId
-> MetaVariable
-> Type
-> Args
-> Term
-> (Term -> TCM ())
-> TCM ()
subtypingForSizeLt CompareDirection
dir MetaId
x MetaVariable
mvar Type
t Args
args Term
v forall a b. (a -> b) -> a -> b
$ \ Term
v -> do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign.proj" Nat
45 forall a b. (a -> b) -> a -> b
$ do
Tele (Dom Type)
cxt <- forall (m :: * -> *).
(Applicative m, MonadTCEnv m) =>
m (Tele (Dom Type))
getContextTelescope
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"context before projection expansion"
, forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext forall a b. (a -> b) -> a -> b
$ forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Tele (Dom Type)
cxt
]
forall a b c.
(Pretty a, PrettyTCM a, NoProjectedVar a, ReduceAndEtaContract a,
PrettyTCM b, TermSubst b) =>
a -> b -> (a -> b -> TCM c) -> TCM c
expandProjectedVars Args
args (Term
v, CompareAs
target) forall a b. (a -> b) -> a -> b
$ \ Args
args (Term
v, CompareAs
target) -> do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign.proj" Nat
45 forall a b. (a -> b) -> a -> b
$ do
Tele (Dom Type)
cxt <- forall (m :: * -> *).
(Applicative m, MonadTCEnv m) =>
m (Tele (Dom Type))
getContextTelescope
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"context after projection expansion"
, forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext forall a b. (a -> b) -> a -> b
$ forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Tele (Dom Type)
cxt
]
let
vars :: VarMap
vars = forall a c t. (IsVarSet a c, Singleton Nat c, Free t) => t -> c
freeVars Args
args
relVL :: [Nat]
relVL = (VarOcc -> Bool) -> VarMap -> [Nat]
filterVarMapToList forall a. LensRelevance a => a -> Bool
isRelevant VarMap
vars
nonstrictVL :: [Nat]
nonstrictVL = (VarOcc -> Bool) -> VarMap -> [Nat]
filterVarMapToList forall a. LensRelevance a => a -> Bool
isNonStrict VarMap
vars
irrVL :: [Nat]
irrVL = (VarOcc -> Bool) -> VarMap -> [Nat]
filterVarMapToList (forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 Bool -> Bool -> Bool
(&&) forall a. LensRelevance a => a -> Bool
isIrrelevant forall a o. LensFlexRig a o => o -> Bool
isUnguarded) VarMap
vars
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign" Nat
20 forall a b. (a -> b) -> a -> b
$
let pr :: Term -> m Doc
pr (Var Nat
n []) = forall (m :: * -> *). Applicative m => [Char] -> m Doc
text (forall a. Show a => a -> [Char]
show Nat
n)
pr (Def QName
c []) = forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM QName
c
pr Term
_ = m Doc
".."
in forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"mvar args:" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
sep (forall a b. (a -> b) -> [a] -> [b]
map (forall {m :: * -> *}.
(MonadFresh NameId m, MonadInteractionPoints m,
MonadStConcreteNames m, PureTCM m, IsString (m Doc), Null (m Doc),
Semigroup (m Doc)) =>
Term -> m Doc
pr forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e. Arg e -> e
unArg) Args
args)
, TCMT IO Doc
"fvars lhs (rel):" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
sep (forall a b. (a -> b) -> [a] -> [b]
map (forall (m :: * -> *). Applicative m => [Char] -> m Doc
text forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> [Char]
show) [Nat]
relVL)
, TCMT IO Doc
"fvars lhs (nonstrict):" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
sep (forall a b. (a -> b) -> [a] -> [b]
map (forall (m :: * -> *). Applicative m => [Char] -> m Doc
text forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> [Char]
show) [Nat]
nonstrictVL)
, TCMT IO Doc
"fvars lhs (irr):" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
sep (forall a b. (a -> b) -> [a] -> [b]
map (forall (m :: * -> *). Applicative m => [Char] -> m Doc
text forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> [Char]
show) [Nat]
irrVL)
]
Term
v <- forall (tcm :: * -> *) a. MonadTCM tcm => TCM a -> tcm a
liftTCM forall a b. (a -> b) -> a -> b
$ forall a.
(Occurs a, InstantiateFull a, PrettyTCM a) =>
MetaId -> VarMap -> a -> TCM a
occursCheck MetaId
x VarMap
vars Term
v
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> [Char] -> m ()
reportSLn [Char]
"tc.meta.assign" Nat
15 [Char]
"passed occursCheck"
forall (m :: * -> *). MonadDebug m => [Char] -> Nat -> m () -> m ()
verboseS [Char]
"tc.meta.assign" Nat
30 forall a b. (a -> b) -> a -> b
$ do
let n :: Nat
n = forall a. TermSize a => a -> Nat
termSize Term
v
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Nat
n forall a. Ord a => a -> a -> Bool
> Nat
200) forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign" Nat
30 forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
sep [ TCMT IO Doc
"size" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *). Applicative m => [Char] -> m Doc
text (forall a. Show a => a -> [Char]
show Nat
n)
, forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"term" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Term
v
]
let fvs :: VarSet
fvs = forall t. Free t => t -> VarSet
allFreeVars Term
v
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign" Nat
20 forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"fvars rhs:" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
sep (forall a b. (a -> b) -> [a] -> [b]
map (forall (m :: * -> *). Applicative m => [Char] -> m Doc
text forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> [Char]
show) forall a b. (a -> b) -> a -> b
$ VarSet -> [Nat]
VarSet.toList VarSet
fvs)
Maybe SubstCand
mids <- do
Either InvertExcept SubstCand
res <- forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT forall a b. (a -> b) -> a -> b
$ Args -> ExceptT InvertExcept (TCMT IO) SubstCand
inverseSubst Args
args
case Either InvertExcept SubstCand
res of
Right SubstCand
ids -> do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign" Nat
60 forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"inverseSubst returns:" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
sep (forall a b. (a -> b) -> [a] -> [b]
map forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty SubstCand
ids)
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign" Nat
50 forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"inverseSubst returns:" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
sep (forall a b. (a -> b) -> [a] -> [b]
map forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM SubstCand
ids)
let boundVars :: VarSet
boundVars = [Nat] -> VarSet
VarSet.fromList forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst SubstCand
ids
if VarSet
fvs VarSet -> VarSet -> Bool
`VarSet.isSubsetOf` VarSet
boundVars
then forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just SubstCand
ids
else forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
Left InvertExcept
CantInvert -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
Left InvertExcept
NeutralArg -> forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. MetaId -> Args -> VarSet -> TCM a
attemptPruning MetaId
x Args
args VarSet
fvs
Left ProjVar{} -> forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. MetaId -> Args -> VarSet -> TCM a
attemptPruning MetaId
x Args
args VarSet
fvs
case Maybe SubstCand
mids of
Maybe SubstCand
Nothing -> forall (m :: * -> *) a. MonadBlock m => Blocker -> m a
patternViolation (forall t. AllMetas t => t -> Blocker
unblockOnAnyMetaIn Term
v)
Just SubstCand
ids -> do
SubstCand
ids <- do
Either () SubstCand
res <- forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT forall a b. (a -> b) -> a -> b
$ SubstCand -> ExceptT () (TCMT IO) SubstCand
checkLinearity SubstCand
ids
case Either () SubstCand
res of
Right SubstCand
ids -> forall (m :: * -> *) a. Monad m => a -> m a
return SubstCand
ids
Left () -> forall (m :: * -> *) a. MonadBlock m => Blocker -> m a -> m a
addOrUnblocker (forall t. AllMetas t => t -> Blocker
unblockOnAnyMetaIn Term
v) forall a b. (a -> b) -> a -> b
$ forall a. MetaId -> Args -> VarSet -> TCM a
attemptPruning MetaId
x Args
args VarSet
fvs
() <- do
let idvars :: [(Nat, VarSet)]
idvars = forall a b. (a -> b) -> [a] -> [b]
map (forall b d a. (b -> d) -> (a, b) -> (a, d)
mapSnd forall t. Free t => t -> VarSet
allFreeVars) SubstCand
ids
let earlierThan :: a -> a -> Bool
earlierThan a
l a
j = a
j forall a. Ord a => a -> a -> Bool
> a
l
TelV Tele (Dom Type)
tel' Type
_ <- forall (m :: * -> *). PureTCM m => Nat -> Type -> m (TelV Type)
telViewUpToPath (forall (t :: * -> *) a. Foldable t => t a -> Nat
length Args
args) Type
t
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ SubstCand
ids forall a b. (a -> b) -> a -> b
$ \(Nat
i,Term
u) -> do
Dom (Name, Type)
d <- forall (m :: * -> *).
(MonadFail m, MonadTCEnv m) =>
Nat -> m (Dom (Name, Type))
lookupBV Nat
i
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (forall a. LensLock a => a -> Lock
getLock (forall a. LensArgInfo a => a -> ArgInfo
getArgInfo Dom (Name, Type)
d) forall a. Eq a => a -> a -> Bool
== Lock
IsLock) forall a b. (a -> b) -> a -> b
$ do
let us :: VarSet
us = forall (f :: * -> *). Foldable f => f VarSet -> VarSet
IntSet.unions forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> b
snd forall a b. (a -> b) -> a -> b
$ forall a. (a -> Bool) -> [a] -> [a]
filter (forall a. Ord a => a -> a -> Bool
earlierThan Nat
i forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst) [(Nat, VarSet)]
idvars
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Tele (Dom Type)
tel' forall a b. (a -> b) -> a -> b
$ Term -> VarSet -> TCM ()
checkEarlierThan Term
u VarSet
us
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError` \case
TypeError{} -> forall (m :: * -> *) a. MonadBlock m => Blocker -> m a
patternViolation (MetaId -> Blocker
unblockOnMeta MetaId
x)
TCErr
err -> forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError TCErr
err
let n :: Nat
n = forall (t :: * -> *) a. Foldable t => t a -> Nat
length Args
args
TelV Tele (Dom Type)
tel' Type
_ <- forall (m :: * -> *). PureTCM m => Nat -> Type -> m (TelV Type)
telViewUpToPath Nat
n Type
t
let sigma :: Substitution' Term
sigma = forall a. DeBruijn a => [a] -> Substitution' a
parallelS forall a b. (a -> b) -> a -> b
$ forall a. [a] -> [a]
reverse forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall e. Arg e -> e
unArg Args
args
Bool
hasSubtyping <- PragmaOptions -> Bool
optCumulativity forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). HasOptions m => m PragmaOptions
pragmaOptions
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
hasSubtyping forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ SubstCand
ids forall a b. (a -> b) -> a -> b
$ \(Nat
i , Term
u) -> do
Type
a <- forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst Substitution' Term
sigma forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Tele (Dom Type)
tel' (forall (m :: * -> *). MonadCheckInternal m => Term -> m Type
infer Term
u)
Type
a' <- forall (m :: * -> *).
(Applicative m, MonadFail m, MonadTCEnv m) =>
Nat -> m Type
typeOfBV Nat
i
Type -> Type -> TCM ()
checkSubtypeIsEqual Type
a' Type
a
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError` \case
TypeError{} -> forall (m :: * -> *) a. MonadBlock m => Blocker -> m a
patternViolation (MetaId -> Blocker
unblockOnMeta MetaId
x)
TCErr
err -> forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError TCErr
err
Nat
m <- forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m Nat
getContextSize
Nat -> MetaId -> Type -> Nat -> SubstCand -> Term -> TCM ()
assignMeta' Nat
m MetaId
x Type
t Nat
n SubstCand
ids Term
v
where
attemptPruning
:: MetaId
-> Args
-> FVs
-> TCM a
attemptPruning :: forall a. MetaId -> Args -> VarSet -> TCM a
attemptPruning MetaId
x Args
args VarSet
fvs = do
PruneResult
killResult <- forall (m :: * -> *).
(PureTCM m, MonadMetaSolver m) =>
MetaId -> Args -> (Nat -> Bool) -> m PruneResult
prune MetaId
x Args
args forall a b. (a -> b) -> a -> b
$ (Nat -> VarSet -> Bool
`VarSet.member` VarSet
fvs)
let success :: Bool
success = PruneResult
killResult forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [PruneResult
PrunedSomething,PruneResult
PrunedEverything]
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign" Nat
10 forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"pruning" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM MetaId
x forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> do forall (m :: * -> *). Applicative m => [Char] -> m Doc
text forall a b. (a -> b) -> a -> b
$ if Bool
success then [Char]
"succeeded" else [Char]
"failed"
Blocker
blocker <- if
| Bool
success -> forall (m :: * -> *) a. Monad m => a -> m a
return Blocker
alwaysUnblock
| Bool
otherwise -> forall t. AllMetas t => t -> Blocker
unblockOnAnyMetaIn forall b c a. (b -> c) -> (a -> b) -> a -> c
. MetaId -> Elims -> Term
MetaV MetaId
x forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall a. Arg a -> Elim' a
Apply forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a (m :: * -> *).
(InstantiateFull a, MonadReduce m) =>
a -> m a
instantiateFull Args
args
forall (m :: * -> *) a. MonadBlock m => Blocker -> m a
patternViolation Blocker
blocker
assignMeta :: Int -> MetaId -> Type -> [Int] -> Term -> TCM ()
assignMeta :: Nat -> MetaId -> Type -> [Nat] -> Term -> TCM ()
assignMeta Nat
m MetaId
x Type
t [Nat]
ids Term
v = do
let n :: Nat
n = forall (t :: * -> *) a. Foldable t => t a -> Nat
length [Nat]
ids
cand :: SubstCand
cand = forall a. Ord a => [a] -> [a]
List.sort forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip [Nat]
ids forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map Nat -> Term
var forall a b. (a -> b) -> a -> b
$ forall a. Integral a => a -> [a]
downFrom Nat
n
Nat -> MetaId -> Type -> Nat -> SubstCand -> Term -> TCM ()
assignMeta' Nat
m MetaId
x Type
t Nat
n SubstCand
cand Term
v
assignMeta' :: Int -> MetaId -> Type -> Int -> SubstCand -> Term -> TCM ()
assignMeta' :: Nat -> MetaId -> Type -> Nat -> SubstCand -> Term -> TCM ()
assignMeta' Nat
m MetaId
x Type
t Nat
n SubstCand
ids Term
v = do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign" Nat
25 forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"preparing to instantiate: " forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Term
v
let assocToList :: Nat -> SubstCand -> [Maybe Term]
assocToList Nat
i = \case
SubstCand
_ | Nat
i forall a. Ord a => a -> a -> Bool
>= Nat
m -> []
((Nat
j,Term
u) : SubstCand
l) | Nat
i forall a. Eq a => a -> a -> Bool
== Nat
j -> forall a. a -> Maybe a
Just Term
u forall a. a -> [a] -> [a]
: Nat -> SubstCand -> [Maybe Term]
assocToList (Nat
iforall a. Num a => a -> a -> a
+Nat
1) SubstCand
l
SubstCand
l -> forall a. Maybe a
Nothing forall a. a -> [a] -> [a]
: Nat -> SubstCand -> [Maybe Term]
assocToList (Nat
iforall a. Num a => a -> a -> a
+Nat
1) SubstCand
l
ivs :: [Maybe Term]
ivs = Nat -> SubstCand -> [Maybe Term]
assocToList Nat
0 SubstCand
ids
rho :: Substitution' Term
rho = forall a.
DeBruijn a =>
Impossible -> [Maybe a] -> Substitution' a -> Substitution' a
prependS HasCallStack => Impossible
impossible [Maybe Term]
ivs forall a b. (a -> b) -> a -> b
$ forall a. Nat -> Substitution' a
raiseS Nat
n
v' :: Term
v' = forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst Substitution' Term
rho Term
v
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign" Nat
15 forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"type of meta =" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
t
(telv :: TelV Type
telv@(TelV Tele (Dom Type)
tel' Type
a), Boundary
bs) <- forall (m :: * -> *).
PureTCM m =>
Nat -> Type -> m (TelV Type, Boundary)
telViewUpToPathBoundary Nat
n Type
t
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign" Nat
30 forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"tel' =" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Tele (Dom Type)
tel'
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign" Nat
30 forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"#args =" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *). Applicative m => [Char] -> m Doc
text (forall a. Show a => a -> [Char]
show Nat
n)
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (forall a. Sized a => a -> Nat
size Tele (Dom Type)
tel' forall a. Ord a => a -> a -> Bool
< Nat
n) forall a b. (a -> b) -> a -> b
$ do
Type
a <- forall (m :: * -> *) t.
(MonadReduce m, MonadBlock m, IsMeta t, Reduce t) =>
t -> m t
abortIfBlocked Type
a
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"impossible" Nat
10 forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"not enough pis, but not blocked?" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<?> forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty Type
a
forall a. HasCallStack => a
__IMPOSSIBLE__
let vsol :: Term
vsol = forall t. Abstract t => Tele (Dom Type) -> t -> t
abstract Tele (Dom Type)
tel' Term
v'
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM (PragmaOptions -> Bool
optDoubleCheck forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). HasOptions m => m PragmaOptions
pragmaOptions) forall a b. (a -> b) -> a -> b
$ do
MetaVariable
m <- forall (m :: * -> *).
(HasCallStack, MonadDebug m, ReadTCState m) =>
MetaId -> m MetaVariable
lookupLocalMeta MetaId
x
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.check" Nat
30 forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"double checking solution"
forall (m :: * -> *).
MonadConstraint m =>
Constraint -> m () -> m ()
catchConstraint (MetaId -> Constraint
CheckMetaInst MetaId
x) forall a b. (a -> b) -> a -> b
$
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Tele (Dom Type)
tel' forall a b. (a -> b) -> a -> b
$ MetaId -> MetaVariable -> Term -> Type -> TCM ()
checkSolutionForMeta MetaId
x MetaVariable
m Term
v' Type
a
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign" Nat
10 forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"solving" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM MetaId
x forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
":=" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Term
vsol
Term
v' <- TelV Type -> Boundary -> Term -> TCM Term
blockOnBoundary TelV Type
telv Boundary
bs Term
v'
forall (m :: * -> *).
MonadMetaSolver m =>
MetaId -> [Arg [Char]] -> Term -> m ()
assignTerm MetaId
x (forall a. TelToArgs a => a -> [Arg [Char]]
telToArgs Tele (Dom Type)
tel') Term
v'
where
blockOnBoundary :: TelView -> Boundary -> Term -> TCM Term
blockOnBoundary :: TelV Type -> Boundary -> Term -> TCM Term
blockOnBoundary TelV Type
telv [] Term
v = forall (m :: * -> *) a. Monad m => a -> m a
return Term
v
blockOnBoundary (TelV Tele (Dom Type)
tel Type
t) Boundary
bs Term
v = forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Tele (Dom Type)
tel forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *).
(MonadMetaSolver m, MonadConstraint m, MonadFresh Nat m,
MonadFresh ProblemId m) =>
Type -> m Term -> m Term
blockTerm Type
t forall a b. (a -> b) -> a -> b
$ do
Term
neg <- forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primINeg
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Boundary
bs forall a b. (a -> b) -> a -> b
$ \ (Term
r,(Term
x,Term
y)) -> do
forall (m :: * -> *).
MonadConversion m =>
Term -> Type -> Term -> Term -> m ()
equalTermOnFace (Term
neg forall t. Apply t => t -> Term -> t
`apply1` Term
r) Type
t Term
x Term
v
forall (m :: * -> *).
MonadConversion m =>
Term -> Type -> Term -> Term -> m ()
equalTermOnFace Term
r Type
t Term
y Term
v
forall (m :: * -> *) a. Monad m => a -> m a
return Term
v
checkMetaInst :: MetaId -> TCM ()
checkMetaInst :: MetaId -> TCM ()
checkMetaInst MetaId
x = do
MetaVariable
m <- forall (m :: * -> *).
(HasCallStack, MonadDebug m, ReadTCState m) =>
MetaId -> m MetaVariable
lookupLocalMeta MetaId
x
let postpone :: TCM ()
postpone = forall (m :: * -> *).
MonadConstraint m =>
Blocker -> Constraint -> m ()
addConstraint (MetaId -> Blocker
unblockOnMeta MetaId
x) forall a b. (a -> b) -> a -> b
$ MetaId -> Constraint
CheckMetaInst MetaId
x
case MetaVariable -> MetaInstantiation
mvInstantiation MetaVariable
m of
BlockedConst{} -> TCM ()
postpone
PostponedTypeCheckingProblem{} -> TCM ()
postpone
Open{} -> TCM ()
postpone
OpenInstance{} -> TCM ()
postpone
InstV Instantiation
inst -> do
let n :: Nat
n = forall a. Sized a => a -> Nat
size (Instantiation -> [Arg [Char]]
instTel Instantiation
inst)
t :: Type
t = forall a. Judgement a -> Type
jMetaType forall a b. (a -> b) -> a -> b
$ MetaVariable -> Judgement MetaId
mvJudgement MetaVariable
m
(telv :: TelV Type
telv@(TelV Tele (Dom Type)
tel Type
a),Boundary
bs) <- forall (m :: * -> *).
PureTCM m =>
Nat -> Type -> m (TelV Type, Boundary)
telViewUpToPathBoundary Nat
n Type
t
forall (m :: * -> *).
MonadConstraint m =>
Constraint -> m () -> m ()
catchConstraint (MetaId -> Constraint
CheckMetaInst MetaId
x) forall a b. (a -> b) -> a -> b
$ forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Tele (Dom Type)
tel forall a b. (a -> b) -> a -> b
$
MetaId -> MetaVariable -> Term -> Type -> TCM ()
checkSolutionForMeta MetaId
x MetaVariable
m (Instantiation -> Term
instBody Instantiation
inst) Type
a
checkSolutionForMeta :: MetaId -> MetaVariable -> Term -> Type -> TCM ()
checkSolutionForMeta :: MetaId -> MetaVariable -> Term -> Type -> TCM ()
checkSolutionForMeta MetaId
x MetaVariable
m Term
v Type
a = do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.check" Nat
30 forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"checking solution for meta" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM MetaId
x
case MetaVariable -> Judgement MetaId
mvJudgement MetaVariable
m of
HasType{ jComparison :: forall a. Judgement a -> Comparison
jComparison = Comparison
cmp } -> do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.check" Nat
30 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM MetaId
x forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
" : " forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
a forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
":=" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Term
v
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.check" Nat
50 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ do
Context
ctx <- forall (m :: * -> *). MonadTCEnv m => m Context
getContext
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"in context: " forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM (Context -> PrettyContext
PrettyContext Context
ctx)
forall (m :: * -> *) a. MonadTrace m => Call -> m a -> m a
traceCall (Range -> MetaId -> Type -> Term -> Call
CheckMetaSolution (forall a. HasRange a => a -> Range
getRange MetaVariable
m) MetaId
x Type
a Term
v) forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *).
MonadCheckInternal m =>
Term -> Comparison -> Type -> m ()
checkInternal Term
v Comparison
cmp Type
a
IsSort{} -> forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.check" Nat
30 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM MetaId
x forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
":=" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Term
v forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
" is a sort"
Sort' Term
s <- forall (m :: * -> *).
(PureTCM m, MonadBlock m, MonadError TCErr m) =>
Type -> m (Sort' Term)
shouldBeSort (forall t a. Sort' t -> a -> Type'' t a
El HasCallStack => Sort' Term
__DUMMY_SORT__ Term
v)
forall (m :: * -> *) a. MonadTrace m => Call -> m a -> m a
traceCall (Range -> MetaId -> Type -> Term -> Call
CheckMetaSolution (forall a. HasRange a => a -> Range
getRange MetaVariable
m) MetaId
x (Sort' Term -> Type
sort (Sort' Term -> Sort' Term
univSort Sort' Term
s)) (Sort' Term -> Term
Sort Sort' Term
s)) forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *).
MonadCheckInternal m =>
Action m -> Sort' Term -> m (Sort' Term)
checkSort forall (m :: * -> *). PureTCM m => Action m
defaultAction Sort' Term
s
checkSubtypeIsEqual :: Type -> Type -> TCM ()
checkSubtypeIsEqual :: Type -> Type -> TCM ()
checkSubtypeIsEqual Type
a Type
b = do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.subtype" Nat
30 forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"checking that subtype" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
a forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+>
TCMT IO Doc
"of" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
b forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
"is actually equal."
forall a (m :: * -> *) b.
(Instantiate a, SynEq a, MonadReduce m) =>
a -> a -> (a -> a -> m b) -> (a -> a -> m b) -> m b
SynEq.checkSyntacticEquality Type
a Type
b (\Type
_ Type
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return ()) forall a b. (a -> b) -> a -> b
$ \Type
a Type
b -> do
Bool
cumulativity <- PragmaOptions -> Bool
optCumulativity forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). HasOptions m => m PragmaOptions
pragmaOptions
forall (m :: * -> *) t.
(MonadReduce m, MonadBlock m, IsMeta t, Reduce t) =>
t -> m t
abortIfBlocked (forall t a. Type'' t a -> a
unEl Type
b) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Sort Sort' Term
sb -> forall (m :: * -> *) t.
(MonadReduce m, MonadBlock m, IsMeta t, Reduce t) =>
t -> m t
abortIfBlocked (forall t a. Type'' t a -> a
unEl Type
a) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Sort Sort' Term
sa | Bool
cumulativity -> forall (m :: * -> *).
MonadConversion m =>
Sort' Term -> Sort' Term -> m ()
equalSort Sort' Term
sa Sort' Term
sb
| Bool
otherwise -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
Dummy{} -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
Term
a -> forall (m :: * -> *) a. MonadBlock m => Blocker -> m a
patternViolation (forall t. AllMetas t => t -> Blocker
unblockOnAnyMetaIn Term
a)
Pi Dom Type
b1 Abs Type
b2 -> forall (m :: * -> *) t.
(MonadReduce m, MonadBlock m, IsMeta t, Reduce t) =>
t -> m t
abortIfBlocked (forall t a. Type'' t a -> a
unEl Type
a) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Pi Dom Type
a1 Abs Type
a2
| forall a. LensRelevance a => a -> Relevance
getRelevance Dom Type
a1 forall a. Eq a => a -> a -> Bool
/= forall a. LensRelevance a => a -> Relevance
getRelevance Dom Type
b1 -> forall (m :: * -> *) a. MonadBlock m => Blocker -> m a
patternViolation Blocker
neverUnblock
| forall a. LensQuantity a => a -> Quantity
getQuantity Dom Type
a1 forall a. Eq a => a -> a -> Bool
/= forall a. LensQuantity a => a -> Quantity
getQuantity Dom Type
b1 -> forall (m :: * -> *) a. MonadBlock m => Blocker -> m a
patternViolation Blocker
neverUnblock
| forall a. LensCohesion a => a -> Cohesion
getCohesion Dom Type
a1 forall a. Eq a => a -> a -> Bool
/= forall a. LensCohesion a => a -> Cohesion
getCohesion Dom Type
b1 -> forall (m :: * -> *) a. MonadBlock m => Blocker -> m a
patternViolation Blocker
neverUnblock
| Bool
otherwise -> do
Type -> Type -> TCM ()
checkSubtypeIsEqual (forall t e. Dom' t e -> e
unDom Dom Type
b1) (forall t e. Dom' t e -> e
unDom Dom Type
a1)
forall a (m :: * -> *) b.
(Subst a, MonadAddContext m) =>
Dom Type -> Abs a -> (a -> m b) -> m b
underAbstractionAbs Dom Type
a1 Abs Type
a2 forall a b. (a -> b) -> a -> b
$ \Type
a2' -> Type -> Type -> TCM ()
checkSubtypeIsEqual Type
a2' (forall a. Subst a => Abs a -> a
absBody Abs Type
b2)
Dummy{} -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
Term
a -> forall (m :: * -> *) a. MonadBlock m => Blocker -> m a
patternViolation (forall t. AllMetas t => t -> Blocker
unblockOnAnyMetaIn Term
a)
Term
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
subtypingForSizeLt
:: CompareDirection
-> MetaId
-> MetaVariable
-> Type
-> Args
-> Term
-> (Term -> TCM ())
-> TCM ()
subtypingForSizeLt :: CompareDirection
-> MetaId
-> MetaVariable
-> Type
-> Args
-> Term
-> (Term -> TCM ())
-> TCM ()
subtypingForSizeLt CompareDirection
DirEq MetaId
x MetaVariable
mvar Type
t Args
args Term
v Term -> TCM ()
cont = Term -> TCM ()
cont Term
v
subtypingForSizeLt CompareDirection
dir MetaId
x MetaVariable
mvar Type
t Args
args Term
v Term -> TCM ()
cont = do
let fallback :: TCM ()
fallback = Term -> TCM ()
cont Term
v
(Maybe QName
mSize, Maybe QName
mSizeLt) <- forall (m :: * -> *). HasBuiltins m => m (Maybe QName, Maybe QName)
getBuiltinSize
forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe Maybe QName
mSize TCM ()
fallback forall a b. (a -> b) -> a -> b
$ \ QName
qSize -> do
forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe Maybe QName
mSizeLt TCM ()
fallback forall a b. (a -> b) -> a -> b
$ \ QName
qSizeLt -> do
Term
v <- forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce Term
v
case Term
v of
Def QName
q [Apply (Arg ArgInfo
ai Term
u)] | QName
q forall a. Eq a => a -> a -> Bool
== QName
qSizeLt -> do
TelV Tele (Dom Type)
tel Type
_ <- forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Type -> m (TelV Type)
telView Type
t
let size :: Type
size = QName -> Type
sizeType_ QName
qSize
t' :: Type
t' = Tele (Dom Type) -> Type -> Type
telePi Tele (Dom Type)
tel Type
size
MetaId
y <- forall (m :: * -> *) a.
MonadMetaSolver m =>
Frozen
-> MetaInfo
-> MetaPriority
-> Permutation
-> Judgement a
-> m MetaId
newMeta Frozen
Instantiable (MetaVariable -> MetaInfo
mvInfo MetaVariable
mvar) (MetaVariable -> MetaPriority
mvPriority MetaVariable
mvar) (MetaVariable -> Permutation
mvPermutation MetaVariable
mvar)
(forall a. a -> Comparison -> Type -> Judgement a
HasType forall a. HasCallStack => a
__IMPOSSIBLE__ Comparison
CmpLeq Type
t')
let yArgs :: Term
yArgs = MetaId -> Elims -> Term
MetaV MetaId
y forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall a. Arg a -> Elim' a
Apply Args
args
forall (m :: * -> *).
MonadConstraint m =>
Blocker -> Constraint -> m ()
addConstraint (MetaId -> Blocker
unblockOnMeta MetaId
y) forall a b. (a -> b) -> a -> b
$ forall a c.
(Comparison -> a -> a -> c) -> CompareDirection -> a -> a -> c
dirToCmp (Comparison -> CompareAs -> Term -> Term -> Constraint
`ValueCmp` CompareAs
AsSizes) CompareDirection
dir Term
yArgs Term
u
let xArgs :: Term
xArgs = MetaId -> Elims -> Term
MetaV MetaId
x forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall a. Arg a -> Elim' a
Apply Args
args
v' :: Term
v' = QName -> Elims -> Term
Def QName
qSizeLt [forall a. Arg a -> Elim' a
Apply forall a b. (a -> b) -> a -> b
$ forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
ai Term
yArgs]
c :: Constraint
c = forall a c.
(Comparison -> a -> a -> c) -> CompareDirection -> a -> a -> c
dirToCmp (Comparison -> CompareAs -> Term -> Term -> Constraint
`ValueCmp` (Type -> CompareAs
AsTermsOf Type
sizeUniv)) CompareDirection
dir Term
xArgs Term
v'
forall (m :: * -> *).
MonadConstraint m =>
Constraint -> m () -> m ()
catchConstraint Constraint
c forall a b. (a -> b) -> a -> b
$ Term -> TCM ()
cont Term
v'
Term
_ -> TCM ()
fallback
expandProjectedVars
:: ( Pretty a, PrettyTCM a, NoProjectedVar a
, ReduceAndEtaContract a
, PrettyTCM b, TermSubst b
)
=> a
-> b
-> (a -> b -> TCM c)
-> TCM c
expandProjectedVars :: forall a b c.
(Pretty a, PrettyTCM a, NoProjectedVar a, ReduceAndEtaContract a,
PrettyTCM b, TermSubst b) =>
a -> b -> (a -> b -> TCM c) -> TCM c
expandProjectedVars a
args b
v a -> b -> TCM c
ret = (a, b) -> TCM c
loop (a
args, b
v) where
loop :: (a, b) -> TCM c
loop (a
args, b
v) = do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign.proj" Nat
45 forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"meta args: " forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM a
args
a
args <- forall a. TCM a -> TCM a
callByName forall a b. (a -> b) -> a -> b
$ forall a. ReduceAndEtaContract a => a -> TCM a
reduceAndEtaContract a
args
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign.proj" Nat
45 forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"norm args: " forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM a
args
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign.proj" Nat
85 forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"norm args: " forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty a
args
let done :: TCM c
done = a -> b -> TCM c
ret a
args b
v
case forall a. NoProjectedVar a => a -> Either ProjectedVar ()
noProjectedVar a
args of
Right () -> do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign.proj" Nat
40 forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"no projected var found in args: " forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM a
args
TCM c
done
Left (ProjectedVar Nat
i [(ProjOrigin, QName)]
_) -> forall a c.
(PrettyTCM a, TermSubst a) =>
Nat -> a -> TCM c -> (a -> TCM c) -> TCM c
etaExpandProjectedVar Nat
i (a
args, b
v) TCM c
done (a, b) -> TCM c
loop
etaExpandProjectedVar :: (PrettyTCM a, TermSubst a) => Int -> a -> TCM c -> (a -> TCM c) -> TCM c
etaExpandProjectedVar :: forall a c.
(PrettyTCM a, TermSubst a) =>
Nat -> a -> TCM c -> (a -> TCM c) -> TCM c
etaExpandProjectedVar Nat
i a
v TCM c
fail a -> TCM c
succeed = do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign.proj" Nat
40 forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"trying to expand projected variable" forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM (Nat -> Term
var Nat
i)
forall (m :: * -> *) a b.
Monad m =>
m (Maybe a) -> m b -> (a -> m b) -> m b
caseMaybeM (Nat
-> TCM
(Maybe (Tele (Dom Type), Substitution' Term, Substitution' Term))
etaExpandBoundVar Nat
i) TCM c
fail forall a b. (a -> b) -> a -> b
$ \ (Tele (Dom Type)
delta, Substitution' Term
sigma, Substitution' Term
tau) -> do
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign.proj" Nat
25 forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"eta-expanding var " forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM (Nat -> Term
var Nat
i) forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+>
TCMT IO Doc
" in terms " forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM a
v
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
unsafeInTopContext forall a b. (a -> b) -> a -> b
$ forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Tele (Dom Type)
delta forall a b. (a -> b) -> a -> b
$
a -> TCM c
succeed forall a b. (a -> b) -> a -> b
$ forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst Substitution' Term
tau a
v
class NoProjectedVar a where
noProjectedVar :: a -> Either ProjectedVar ()
default noProjectedVar
:: (NoProjectedVar b, Foldable t, t b ~ a)
=> a -> Either ProjectedVar ()
noProjectedVar = forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
Fold.mapM_ forall a. NoProjectedVar a => a -> Either ProjectedVar ()
noProjectedVar
instance NoProjectedVar a => NoProjectedVar (Arg a)
instance NoProjectedVar a => NoProjectedVar [a]
instance NoProjectedVar Term where
noProjectedVar :: Term -> Either ProjectedVar ()
noProjectedVar = \case
Var Nat
i Elims
es
| qs :: [(ProjOrigin, QName)]
qs@((ProjOrigin, QName)
_:[(ProjOrigin, QName)]
_) <- forall a b. (a -> Maybe b) -> [a] -> Prefix b
takeWhileJust forall a. a -> a
id forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall e. IsProjElim e => e -> Maybe (ProjOrigin, QName)
isProjElim Elims
es
-> forall a b. a -> Either a b
Left forall a b. (a -> b) -> a -> b
$ Nat -> [(ProjOrigin, QName)] -> ProjectedVar
ProjectedVar Nat
i [(ProjOrigin, QName)]
qs
Con (ConHead QName
_ IsRecord{} Induction
Inductive [Arg QName]
_) ConInfo
_ Elims
es
| Just Args
vs <- forall a. [Elim' a] -> Maybe [Arg a]
allApplyElims Elims
es
-> forall a. NoProjectedVar a => a -> Either ProjectedVar ()
noProjectedVar Args
vs
Term
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
class (TermLike a, TermSubst a, Reduce a) => ReduceAndEtaContract a where
reduceAndEtaContract :: a -> TCM a
default reduceAndEtaContract
:: (Traversable f, TermLike b, Subst b, Reduce b, ReduceAndEtaContract b, f b ~ a)
=> a -> TCM a
reduceAndEtaContract = forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
Trav.mapM forall a. ReduceAndEtaContract a => a -> TCM a
reduceAndEtaContract
instance ReduceAndEtaContract a => ReduceAndEtaContract [a]
instance ReduceAndEtaContract a => ReduceAndEtaContract (Arg a)
instance ReduceAndEtaContract Term where
reduceAndEtaContract :: Term -> TCM Term
reduceAndEtaContract Term
u = do
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce Term
u forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Lam ArgInfo
ai (Abs [Char]
x Term
b) -> forall (m :: * -> *).
(MonadTCEnv m, HasConstInfo m, HasOptions m) =>
ArgInfo -> [Char] -> Term -> m Term
etaLam ArgInfo
ai [Char]
x forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall a. ReduceAndEtaContract a => a -> TCM a
reduceAndEtaContract Term
b
Con ConHead
c ConInfo
ci Elims
es -> forall (m :: * -> *).
(MonadTCEnv m, HasConstInfo m, HasOptions m) =>
ConHead
-> ConInfo
-> Elims
-> (QName -> ConHead -> ConInfo -> Args -> m Term)
-> m Term
etaCon ConHead
c ConInfo
ci Elims
es forall a b. (a -> b) -> a -> b
$ \ QName
r ConHead
c ConInfo
ci Args
args -> do
Args
args <- forall a. ReduceAndEtaContract a => a -> TCM a
reduceAndEtaContract Args
args
forall (m :: * -> *).
HasConstInfo m =>
QName -> ConHead -> ConInfo -> Args -> m Term
etaContractRecord QName
r ConHead
c ConInfo
ci Args
args
Term
v -> forall (m :: * -> *) a. Monad m => a -> m a
return Term
v
type FVs = VarSet
type SubstCand = [(Int,Term)]
checkLinearity :: SubstCand -> ExceptT () TCM SubstCand
checkLinearity :: SubstCand -> ExceptT () (TCMT IO) SubstCand
checkLinearity SubstCand
ids0 = do
let ids :: SubstCand
ids = forall a. (a -> a -> Ordering) -> [a] -> [a]
List.sortBy (forall a. Ord a => a -> a -> Ordering
compare forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` forall a b. (a, b) -> a
fst) SubstCand
ids0
let grps :: [SubstCand]
grps = forall b a. Ord b => (a -> b) -> [a] -> [[a]]
groupOn forall a b. (a, b) -> a
fst SubstCand
ids
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM SubstCand -> ExceptT () (TCMT IO) SubstCand
makeLinear [SubstCand]
grps
where
makeLinear :: SubstCand -> ExceptT () TCM SubstCand
makeLinear :: SubstCand -> ExceptT () (TCMT IO) SubstCand
makeLinear [] = forall a. HasCallStack => a
__IMPOSSIBLE__
makeLinear grp :: SubstCand
grp@[(Nat, Term)
_] = forall (m :: * -> *) a. Monad m => a -> m a
return SubstCand
grp
makeLinear (p :: (Nat, Term)
p@(Nat
i,Term
t) : SubstCand
_) =
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
ifM ((forall a b. b -> Either a b
Right Bool
True forall a. Eq a => a -> a -> Bool
==) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *) a.
Monad m =>
BlockT m a -> m (Either Blocker a)
runBlocked forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (m :: * -> *). (PureTCM m, MonadBlock m) => Type -> m Bool
isSingletonTypeModuloRelevance forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (m :: * -> *).
(Applicative m, MonadFail m, MonadTCEnv m) =>
Nat -> m Type
typeOfBV Nat
i)
(forall (m :: * -> *) a. Monad m => a -> m a
return [(Nat, Term)
p])
(forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError ())
type Res = [(Arg Nat, Term)]
data InvertExcept
= CantInvert
| NeutralArg
| ProjVar ProjectedVar
inverseSubst :: Args -> ExceptT InvertExcept TCM SubstCand
inverseSubst :: Args -> ExceptT InvertExcept (TCMT IO) SubstCand
inverseSubst Args
args = forall a b. (a -> b) -> [a] -> [b]
map (forall a c b. (a -> c) -> (a, b) -> (c, b)
mapFst forall e. Arg e -> e
unArg) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Arg Term, Term)] -> ExceptT InvertExcept (TCMT IO) Res
loop (forall a b. [a] -> [b] -> [(a, b)]
zip Args
args [Term]
terms)
where
loop :: [(Arg Term, Term)] -> ExceptT InvertExcept (TCMT IO) Res
loop = forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM Res -> (Arg Term, Term) -> ExceptT InvertExcept (TCMT IO) Res
isVarOrIrrelevant []
terms :: [Term]
terms = forall a b. (a -> b) -> [a] -> [b]
map Nat -> Term
var (forall a. Integral a => a -> [a]
downFrom (forall a. Sized a => a -> Nat
size Args
args))
failure :: ExceptT InvertExcept (TCMT IO) Res
failure = do
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.meta.assign" Nat
15 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"not all arguments are variables: " forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Args
args
, TCMT IO Doc
" aborting assignment" ]
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError InvertExcept
CantInvert
neutralArg :: ExceptT InvertExcept (TCMT IO) a
neutralArg = forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError InvertExcept
NeutralArg
isVarOrIrrelevant :: Res -> (Arg Term, Term) -> ExceptT InvertExcept TCM Res
isVarOrIrrelevant :: Res -> (Arg Term, Term) -> ExceptT InvertExcept (TCMT IO) Res
isVarOrIrrelevant Res
vars (Arg ArgInfo
info Term
v, Term
t) = do
let irr :: Bool
irr | forall a. LensRelevance a => a -> Bool
isIrrelevant ArgInfo
info = Bool
True
| DontCare{} <- Term
v = Bool
True
| Bool
otherwise = Bool
False
case Term -> Term
stripDontCare Term
v of
Var Nat
i [] -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ (forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
info Nat
i, Term
t) (Arg Nat, Term) -> Res -> Res
`cons` Res
vars
Var Nat
i Elims
es | Just [(ProjOrigin, QName)]
qs <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM forall e. IsProjElim e => e -> Maybe (ProjOrigin, QName)
isProjElim Elims
es ->
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError forall a b. (a -> b) -> a -> b
$ ProjectedVar -> InvertExcept
ProjVar forall a b. (a -> b) -> a -> b
$ Nat -> [(ProjOrigin, QName)] -> ProjectedVar
ProjectedVar Nat
i [(ProjOrigin, QName)]
qs
Con ConHead
c ConInfo
ci Elims
es -> do
let fallback :: ExceptT InvertExcept (TCMT IO) Res
fallback
| forall a. LensRelevance a => a -> Bool
isIrrelevant ArgInfo
info = forall (m :: * -> *) a. Monad m => a -> m a
return Res
vars
| Bool
otherwise = ExceptT InvertExcept (TCMT IO) Res
failure
Bool
irrProj <- PragmaOptions -> Bool
optIrrelevantProjections forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *). HasOptions m => m PragmaOptions
pragmaOptions
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (forall (m :: * -> *).
HasConstInfo m =>
QName -> m (Maybe (QName, Defn))
isRecordConstructor forall a b. (a -> b) -> a -> b
$ ConHead -> QName
conName ConHead
c) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Just (QName
_, r :: Defn
r@Record{ recFields :: Defn -> [Dom QName]
recFields = [Dom QName]
fs })
| HasEta' PatternOrCopattern
YesEta <- Defn -> HasEta' PatternOrCopattern
recEtaEquality Defn
r
, forall (t :: * -> *) a. Foldable t => t a -> Nat
length [Dom QName]
fs forall a. Eq a => a -> a -> Bool
== forall (t :: * -> *) a. Foldable t => t a -> Nat
length Elims
es
, forall a. LensQuantity a => a -> Bool
hasQuantity0 ArgInfo
info Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all forall a. LensQuantity a => a -> Bool
usableQuantity [Dom QName]
fs
, Bool
irrProj Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all forall a. LensRelevance a => a -> Bool
isRelevant [Dom QName]
fs -> do
let aux :: Arg Term -> Dom QName -> (Arg Term, Term)
aux (Arg ArgInfo
_ Term
v) Dom{domInfo :: forall t e. Dom' t e -> ArgInfo
domInfo = ArgInfo
info', unDom :: forall t e. Dom' t e -> e
unDom = QName
f} =
(forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
ai Term
v,) forall a b. (a -> b) -> a -> b
$ Term
t forall t. Apply t => t -> Elims -> t
`applyE` [forall a. ProjOrigin -> QName -> Elim' a
Proj ProjOrigin
ProjSystem QName
f]
where
ai :: ArgInfo
ai = ArgInfo
{ argInfoHiding :: Hiding
argInfoHiding = forall a. Ord a => a -> a -> a
min (forall a. LensHiding a => a -> Hiding
getHiding ArgInfo
info) (forall a. LensHiding a => a -> Hiding
getHiding ArgInfo
info')
, argInfoModality :: Modality
argInfoModality = Modality
{ modRelevance :: Relevance
modRelevance = forall a. Ord a => a -> a -> a
max (forall a. LensRelevance a => a -> Relevance
getRelevance ArgInfo
info) (forall a. LensRelevance a => a -> Relevance
getRelevance ArgInfo
info')
, modQuantity :: Quantity
modQuantity = forall a. Ord a => a -> a -> a
max (forall a. LensQuantity a => a -> Quantity
getQuantity ArgInfo
info) (forall a. LensQuantity a => a -> Quantity
getQuantity ArgInfo
info')
, modCohesion :: Cohesion
modCohesion = forall a. Ord a => a -> a -> a
max (forall a. LensCohesion a => a -> Cohesion
getCohesion ArgInfo
info) (forall a. LensCohesion a => a -> Cohesion
getCohesion ArgInfo
info')
}
, argInfoOrigin :: Origin
argInfoOrigin = forall a. Ord a => a -> a -> a
min (forall a. LensOrigin a => a -> Origin
getOrigin ArgInfo
info) (forall a. LensOrigin a => a -> Origin
getOrigin ArgInfo
info')
, argInfoFreeVariables :: FreeVariables
argInfoFreeVariables = FreeVariables
unknownFreeVariables
, argInfoAnnotation :: Annotation
argInfoAnnotation = ArgInfo -> Annotation
argInfoAnnotation ArgInfo
info'
}
vs :: Args
vs = forall a. a -> Maybe a -> a
fromMaybe forall a. HasCallStack => a
__IMPOSSIBLE__ forall a b. (a -> b) -> a -> b
$ forall a. [Elim' a] -> Maybe [Arg a]
allApplyElims Elims
es
Res
res <- [(Arg Term, Term)] -> ExceptT InvertExcept (TCMT IO) Res
loop forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Arg Term -> Dom QName -> (Arg Term, Term)
aux Args
vs [Dom QName]
fs
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Res
res Res -> Res -> Res
`append` Res
vars
| Bool
otherwise -> ExceptT InvertExcept (TCMT IO) Res
fallback
Maybe (QName, Defn)
_ -> ExceptT InvertExcept (TCMT IO) Res
fallback
Term
_ | Bool
irr -> forall (m :: * -> *) a. Monad m => a -> m a
return Res
vars
Var{} -> forall {a}. ExceptT InvertExcept (TCMT IO) a
neutralArg
Def{} -> forall {a}. ExceptT InvertExcept (TCMT IO) a
neutralArg
Lam{} -> ExceptT InvertExcept (TCMT IO) Res
failure
Lit{} -> ExceptT InvertExcept (TCMT IO) Res
failure
MetaV{} -> ExceptT InvertExcept (TCMT IO) Res
failure
Pi{} -> forall {a}. ExceptT InvertExcept (TCMT IO) a
neutralArg
Sort{} -> forall {a}. ExceptT InvertExcept (TCMT IO) a
neutralArg
Level{} -> forall {a}. ExceptT InvertExcept (TCMT IO) a
neutralArg
DontCare{} -> forall a. HasCallStack => a
__IMPOSSIBLE__
Dummy [Char]
s Elims
_ -> forall (m :: * -> *) a.
(HasCallStack, MonadDebug m) =>
[Char] -> m a
__IMPOSSIBLE_VERBOSE__ [Char]
s
append :: Res -> Res -> Res
append :: Res -> Res -> Res
append Res
res Res
vars = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Arg Nat, Term) -> Res -> Res
cons Res
vars Res
res
cons :: (Arg Nat, Term) -> Res -> Res
cons :: (Arg Nat, Term) -> Res -> Res
cons a :: (Arg Nat, Term)
a@(Arg ArgInfo
ai Nat
i, Term
t) Res
vars
| forall a. LensRelevance a => a -> Bool
isIrrelevant ArgInfo
ai = forall a. Bool -> (a -> a) -> a -> a
applyUnless (forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any ((Nat
iforall a. Eq a => a -> a -> Bool
==) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e. Arg e -> e
unArg forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst) Res
vars) ((Arg Nat, Term)
a forall a. a -> [a] -> [a]
:) Res
vars
| Bool
otherwise = (Arg Nat, Term)
a forall a. a -> [a] -> [a]
:
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\ a :: (Arg Nat, Term)
a@(Arg ArgInfo
info Nat
j, Term
t) -> forall a. LensRelevance a => a -> Bool
isIrrelevant ArgInfo
info Bool -> Bool -> Bool
&& Nat
i forall a. Eq a => a -> a -> Bool
== Nat
j)) Res
vars
openMetasToPostulates :: TCM ()
openMetasToPostulates :: TCM ()
openMetasToPostulates = do
ModuleName
m <- forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC TCEnv -> ModuleName
envCurrentModule
[(MetaId, MetaVariable)]
ms <- forall k a. Map k a -> [(k, a)]
MapS.assocs forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' LocalMetaStore TCState
stOpenMetaStore
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [(MetaId, MetaVariable)]
ms forall a b. (a -> b) -> a -> b
$ \ (MetaId
x, MetaVariable
mv) -> do
let t :: Type
t = Type -> Type
dummyTypeToOmega forall a b. (a -> b) -> a -> b
$ forall a. Judgement a -> Type
jMetaType forall a b. (a -> b) -> a -> b
$ MetaVariable -> Judgement MetaId
mvJudgement MetaVariable
mv
let r :: Range
r = forall a. Closure a -> a
clValue forall a b. (a -> b) -> a -> b
$ MetaInfo -> Closure Range
miClosRange forall a b. (a -> b) -> a -> b
$ MetaVariable -> MetaInfo
mvInfo MetaVariable
mv
[Char]
s' <- Doc -> [Char]
render forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM MetaId
x
let s :: [Char]
s = [Char]
"unsolved#meta." forall a. [a] -> [a] -> [a]
++ forall a. (a -> Bool) -> [a] -> [a]
filter (forall a. Eq a => a -> a -> Bool
/= Char
'_') [Char]
s'
Name
n <- forall (m :: * -> *).
MonadFresh NameId m =>
Range -> [Char] -> m Name
freshName Range
r [Char]
s
let q :: QName
q = ModuleName -> Name -> QName
A.QName ModuleName
m Name
n
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Nat -> TCMT IO Doc -> m ()
reportSDoc [Char]
"meta.postulate" Nat
20 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char]
"Turning " forall a. [a] -> [a] -> [a]
++ if MetaVariable -> Bool
isSortMeta_ MetaVariable
mv then [Char]
"sort" else [Char]
"value" forall a. [a] -> [a] -> [a]
++ [Char]
" meta ")
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM MetaId
x forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
" into postulate."
, forall (m :: * -> *). Functor m => Nat -> m Doc -> m Doc
nest Nat
2 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"Name: " forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM QName
q
, TCMT IO Doc
"Type: " forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
t
]
]
QName -> ArgInfo -> QName -> Type -> Defn -> TCM ()
addConstant' QName
q ArgInfo
defaultArgInfo QName
q Type
t Defn
defaultAxiom
let inst :: MetaInstantiation
inst = Instantiation -> MetaInstantiation
InstV forall a b. (a -> b) -> a -> b
$ Instantiation
{ instTel :: [Arg [Char]]
instTel = [], instBody :: Term
instBody = QName -> Elims -> Term
Def QName
q [] }
forall (m :: * -> *).
MonadMetaSolver m =>
MetaId -> (MetaVariable -> MetaVariable) -> m ()
updateMetaVar MetaId
x forall a b. (a -> b) -> a -> b
$ \ MetaVariable
mv0 -> MetaVariable
mv0 { mvInstantiation :: MetaInstantiation
mvInstantiation = MetaInstantiation
inst }
forall (m :: * -> *) a. Monad m => a -> m a
return ()
where
dummyTypeToOmega :: Type -> Type
dummyTypeToOmega Type
t =
case Type -> TelV Type
telView' Type
t of
TelV Tele (Dom Type)
tel (El Sort' Term
_ Dummy{}) -> forall t. Abstract t => Tele (Dom Type) -> t -> t
abstract Tele (Dom Type)
tel (Sort' Term -> Type
sort forall a b. (a -> b) -> a -> b
$ forall t. IsFibrant -> Integer -> Sort' t
Inf IsFibrant
IsFibrant Integer
0)
TelV Type
_ -> Type
t
dependencySortMetas :: [MetaId] -> TCM (Maybe [MetaId])
dependencySortMetas :: [MetaId] -> TCM (Maybe [MetaId])
dependencySortMetas [MetaId]
metas = do
[(MetaId, MetaId)]
metaGraph <- forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [MetaId]
metas forall a b. (a -> b) -> a -> b
$ \ MetaId
m -> do
Set MetaId
deps <- forall t m. (AllMetas t, Monoid m) => (MetaId -> m) -> t -> m
allMetas (\MetaId
m' -> if MetaId
m' forall a. Ord a => a -> Set a -> Bool
`Set.member` Set MetaId
metas'
then forall el coll. Singleton el coll => el -> coll
singleton MetaId
m'
else forall a. Monoid a => a
mempty) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
forall {m :: * -> *}. MonadReduce m => MetaId -> m (Maybe Type)
getType MetaId
m
forall (m :: * -> *) a. Monad m => a -> m a
return [ (MetaId
m, MetaId
m') | MetaId
m' <- forall a. Set a -> [a]
Set.toList Set MetaId
deps ]
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall n. Ord n => Set n -> [(n, n)] -> Maybe [n]
Graph.topSort Set MetaId
metas' [(MetaId, MetaId)]
metaGraph
where
metas' :: Set MetaId
metas' = forall a. Ord a => [a] -> Set a
Set.fromList [MetaId]
metas
getType :: MetaId -> m (Maybe Type)
getType MetaId
m = do
Judgement MetaId
j <- forall (m :: * -> *).
ReadTCState m =>
MetaId -> m (Judgement MetaId)
lookupMetaJudgement MetaId
m
case Judgement MetaId
j of
IsSort{} -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
HasType{ jMetaType :: forall a. Judgement a -> Type
jMetaType = Type
t } -> forall a. a -> Maybe a
Just forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a (m :: * -> *).
(InstantiateFull a, MonadReduce m) =>
a -> m a
instantiateFull Type
t