{-# LANGUAGE NondecreasingIndentation #-}
module Agda.TypeChecking.Rules.Application
( checkArguments
, checkArguments_
, checkApplication
, inferApplication
, checkProjAppToKnownPrincipalArg
, univChecks
, suffixToLevel
) where
import Prelude hiding ( null )
import Control.Applicative ( (<|>) )
import Control.Monad ( filterM, forM, forM_, guard, liftM2 )
import Control.Monad.Except ( ExceptT, runExceptT, MonadError, catchError, throwError )
import Control.Monad.Trans
import Control.Monad.Trans.Maybe
import Data.Bifunctor
import Data.Maybe
import Data.Void
import qualified Data.Foldable as Fold
import qualified Data.IntSet as IntSet
import Agda.Interaction.Highlighting.Generate
( storeDisambiguatedConstructor, storeDisambiguatedProjection )
import qualified Agda.Syntax.Abstract as A
import Agda.Syntax.Abstract.Views as A
import qualified Agda.Syntax.Info as A
import Agda.Syntax.Concrete.Pretty ()
import Agda.Syntax.Common
import Agda.Syntax.Internal as I
import Agda.Syntax.Position
import Agda.TypeChecking.Conversion
import Agda.TypeChecking.Constraints
import Agda.TypeChecking.Datatypes
import Agda.TypeChecking.Free
import Agda.TypeChecking.Implicit
import Agda.TypeChecking.Injectivity
import Agda.TypeChecking.InstanceArguments (postponeInstanceConstraints)
import Agda.TypeChecking.Level
import Agda.TypeChecking.MetaVars
import Agda.TypeChecking.Modalities
import Agda.TypeChecking.Names
import Agda.TypeChecking.Pretty
import Agda.TypeChecking.Primitive hiding (Nat)
import Agda.TypeChecking.Monad
import Agda.TypeChecking.Records
import Agda.TypeChecking.Reduce
import Agda.TypeChecking.Rules.Def
import Agda.TypeChecking.Rules.Term
import Agda.TypeChecking.Substitute
import Agda.TypeChecking.Telescope
import Agda.Utils.Either
import Agda.Utils.Functor
import Agda.Utils.Lens
import Agda.Utils.List ( (!!!), groupOn, initWithDefault )
import qualified Agda.Utils.List as List
import Agda.Utils.List1 ( List1, pattern (:|) )
import qualified Agda.Utils.List1 as List1
import Agda.Utils.Maybe
import Agda.Utils.Monad
import Agda.Utils.Null
import Agda.Syntax.Common.Pretty ( prettyShow )
import Agda.Utils.Size
import Agda.Utils.Tuple
import Agda.Utils.Impossible
type MaybeRanges = [Maybe Range]
acHeadConstraints :: (Elims -> Term) -> ArgsCheckState a -> [Constraint]
acHeadConstraints :: forall a. (Elims -> Term) -> ArgsCheckState a -> [Constraint]
acHeadConstraints Elims -> Term
hd ACState{acElims :: forall a. ArgsCheckState a -> Elims
acElims = Elims
es, acConstraints :: forall a. ArgsCheckState a -> [Maybe (Abs Constraint)]
acConstraints = [Maybe (Abs Constraint)]
cs} = (Elims -> SubstArg Constraint)
-> Elims -> [Maybe (Abs Constraint)] -> [Constraint]
forall {a} {a}.
Subst a =>
([a] -> SubstArg a) -> [a] -> [Maybe (Abs a)] -> [a]
go Elims -> Term
Elims -> SubstArg Constraint
hd Elims
es [Maybe (Abs Constraint)]
cs
where
go :: ([a] -> SubstArg a) -> [a] -> [Maybe (Abs a)] -> [a]
go [a] -> SubstArg a
hd [] [] = []
go [a] -> SubstArg a
hd (a
e : [a]
es) (Maybe (Abs a)
c : [Maybe (Abs a)]
cs) = ([a] -> [a])
-> (Abs a -> [a] -> [a]) -> Maybe (Abs a) -> [a] -> [a]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [a] -> [a]
forall a. a -> a
id (\ Abs a
c -> (Abs a -> SubstArg a -> a
forall a. Subst a => Abs a -> SubstArg a -> a
lazyAbsApp Abs a
c ([a] -> SubstArg a
hd []) a -> [a] -> [a]
forall a. a -> [a] -> [a]
:)) Maybe (Abs a)
c ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$ ([a] -> SubstArg a) -> [a] -> [Maybe (Abs a)] -> [a]
go ([a] -> SubstArg a
hd ([a] -> SubstArg a) -> ([a] -> [a]) -> [a] -> SubstArg a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a
e a -> [a] -> [a]
forall a. a -> [a] -> [a]
:)) [a]
es [Maybe (Abs a)]
cs
go [a] -> SubstArg a
_ [] (Maybe (Abs a)
_:[Maybe (Abs a)]
_) = [a]
forall a. HasCallStack => a
__IMPOSSIBLE__
go [a] -> SubstArg a
_ (a
_:[a]
_) [] = [a]
forall a. HasCallStack => a
__IMPOSSIBLE__
checkHeadConstraints :: (Elims -> Term) -> ArgsCheckState a -> TCM Term
checkHeadConstraints :: forall a. (Elims -> Term) -> ArgsCheckState a -> TCM Term
checkHeadConstraints Elims -> Term
hd ArgsCheckState a
st = do
(Constraint -> TCMT IO ()) -> [Constraint] -> TCMT IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ Constraint -> TCMT IO ()
solveConstraint_ ((Elims -> Term) -> ArgsCheckState a -> [Constraint]
forall a. (Elims -> Term) -> ArgsCheckState a -> [Constraint]
acHeadConstraints Elims -> Term
hd ArgsCheckState a
st)
Term -> TCM Term
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Term -> TCM Term) -> Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ Elims -> Term
hd (ArgsCheckState a -> Elims
forall a. ArgsCheckState a -> Elims
acElims ArgsCheckState a
st)
checkApplication :: Comparison -> A.Expr -> A.Args -> A.Expr -> Type -> TCM Term
checkApplication :: Comparison -> Expr -> [NamedArg Expr] -> Expr -> Type -> TCM Term
checkApplication Comparison
cmp Expr
hd [NamedArg Expr]
args Expr
e Type
t =
Expr -> TCM Term -> TCM Term
forall a. Expr -> TCM a -> TCM a
turnOffExpandLastIfExistingMeta Expr
hd (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$
TCM Term -> TCM Term
forall a. TCM a -> TCM a
postponeInstanceConstraints (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ do
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.check.app" Int
20 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"checkApplication"
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"hd = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Expr -> TCMT IO Doc
forall a (m :: * -> *).
(ToConcrete a, Pretty (ConOfAbs a), MonadAbsToCon m) =>
a -> m Doc
prettyA Expr
hd
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"args = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
sep ((NamedArg Expr -> TCMT IO Doc) -> [NamedArg Expr] -> [TCMT IO Doc]
forall a b. (a -> b) -> [a] -> [b]
map NamedArg Expr -> TCMT IO Doc
forall a (m :: * -> *).
(ToConcrete a, Pretty (ConOfAbs a), MonadAbsToCon m) =>
a -> m Doc
prettyA [NamedArg Expr]
args)
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"e = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Expr -> TCMT IO Doc
forall a (m :: * -> *).
(ToConcrete a, Pretty (ConOfAbs a), MonadAbsToCon m) =>
a -> m Doc
prettyA Expr
e
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"t = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
t
]
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.check.app" Int
70 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"checkApplication (raw)"
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char] -> TCMT IO Doc) -> [Char] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char]
"hd = " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Expr -> [Char]
forall a. Show a => a -> [Char]
show Expr
hd
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char] -> TCMT IO Doc) -> [Char] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char]
"args = " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [NamedArg Expr] -> [Char]
forall a. Show a => a -> [Char]
show ([NamedArg Expr] -> [NamedArg Expr]
forall a. ExprLike a => a -> a
deepUnscope [NamedArg Expr]
args)
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char] -> TCMT IO Doc) -> [Char] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char]
"e = " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Expr -> [Char]
forall a. Show a => a -> [Char]
show (Expr -> Expr
forall a. ExprLike a => a -> a
deepUnscope Expr
e)
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char] -> TCMT IO Doc) -> [Char] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char]
"t = " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Type -> [Char]
forall a. Show a => a -> [Char]
show Type
t
]
case Expr -> Expr
unScope Expr
hd of
A.Proj ProjOrigin
o AmbiguousQName
p | Just QName
x <- AmbiguousQName -> Maybe QName
getUnambiguous AmbiguousQName
p -> do
Comparison
-> Expr
-> Type
-> QName
-> ProjOrigin
-> Expr
-> [NamedArg Expr]
-> TCM Term
checkUnambiguousProjectionApplication Comparison
cmp Expr
e Type
t QName
x ProjOrigin
o Expr
hd [NamedArg Expr]
args
A.Proj ProjOrigin
o AmbiguousQName
p -> do
Comparison
-> Expr
-> ProjOrigin
-> List1 QName
-> [NamedArg Expr]
-> Type
-> TCM Term
checkProjApp Comparison
cmp Expr
e ProjOrigin
o (AmbiguousQName -> List1 QName
unAmbQ AmbiguousQName
p) [NamedArg Expr]
args Type
t
A.Con AmbiguousQName
ambC | Just QName
c <- AmbiguousQName -> Maybe QName
getUnambiguous AmbiguousQName
ambC -> do
ConHead
con <-
(SigError -> TCMT IO ConHead)
-> TCMT IO (Either SigError ConHead) -> TCMT IO ConHead
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> m (Either a b) -> m b
fromRightM
(TCMT IO ConHead -> SigError -> TCMT IO ConHead
forall (m :: * -> *) a.
(HasCallStack, MonadDebug m) =>
m a -> SigError -> m a
sigError (TypeError -> TCMT IO ConHead
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO ConHead) -> TypeError -> TCMT IO ConHead
forall a b. (a -> b) -> a -> b
$ QName -> TypeError
AbstractConstructorNotInScope QName
c)) (TCMT IO (Either SigError ConHead) -> TCMT IO ConHead)
-> TCMT IO (Either SigError ConHead) -> TCMT IO ConHead
forall a b. (a -> b) -> a -> b
$
QName -> TCMT IO (Either SigError ConHead)
getOrigConHead QName
c
Comparison
-> Expr -> Type -> ConHead -> [NamedArg Expr] -> TCM Term
checkConstructorApplication Comparison
cmp Expr
e Type
t ConHead
con [NamedArg Expr]
args
A.Con (AmbQ List1 QName
cs0) -> List1 QName -> [NamedArg Expr] -> Type -> DisambiguateConstructor
disambiguateConstructor List1 QName
cs0 [NamedArg Expr]
args Type
t DisambiguateConstructor
-> (Either Blocker ConHead -> TCM Term) -> TCM Term
forall a b. TCMT IO a -> (a -> TCMT IO b) -> TCMT IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ case
Left Blocker
unblock -> TypeCheckingProblem -> Blocker -> TCM Term
postponeTypeCheckingProblem (Comparison -> Expr -> Type -> TypeCheckingProblem
CheckExpr Comparison
cmp Expr
e Type
t) Blocker
unblock
Right ConHead
c -> Comparison
-> Expr -> Type -> ConHead -> [NamedArg Expr] -> TCM Term
checkConstructorApplication Comparison
cmp Expr
e Type
t ConHead
c [NamedArg Expr]
args
A.PatternSyn AmbiguousQName
n -> do
([Arg Name]
ns, Pattern' Void
p) <- AmbiguousQName -> TCM ([Arg Name], Pattern' Void)
lookupPatternSyn AmbiguousQName
n
Pattern' Expr
p <- Pattern' Expr -> TCMT IO (Pattern' Expr)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Pattern' Expr -> TCMT IO (Pattern' Expr))
-> Pattern' Expr -> TCMT IO (Pattern' Expr)
forall a b. (a -> b) -> a -> b
$ Range -> Pattern' Expr -> Pattern' Expr
forall a. SetRange a => Range -> a -> a
setRange (AmbiguousQName -> Range
forall a. HasRange a => a -> Range
getRange AmbiguousQName
n) (Pattern' Expr -> Pattern' Expr) -> Pattern' Expr -> Pattern' Expr
forall a b. (a -> b) -> a -> b
$ Pattern' Expr -> Pattern' Expr
forall a. KillRange a => KillRangeT a
killRange (Pattern' Expr -> Pattern' Expr) -> Pattern' Expr -> Pattern' Expr
forall a b. (a -> b) -> a -> b
$ Pattern' Void -> Pattern' Expr
forall (f :: * -> *) a. Functor f => f Void -> f a
vacuous Pattern' Void
p
let meta :: Range -> Expr
meta Range
r = MetaInfo -> Expr
A.Underscore (MetaInfo -> Expr) -> MetaInfo -> Expr
forall a b. (a -> b) -> a -> b
$ MetaInfo
A.emptyMetaInfo{ A.metaRange = r }
case (Range -> Expr)
-> Range
-> [Arg Name]
-> [NamedArg Expr]
-> Maybe ([(Name, Expr)], [Arg Name])
forall a.
HasRange a =>
(Range -> a)
-> Range
-> [Arg Name]
-> [NamedArg a]
-> Maybe ([(Name, a)], [Arg Name])
A.insertImplicitPatSynArgs Range -> Expr
meta (AmbiguousQName -> Range
forall a. HasRange a => a -> Range
getRange AmbiguousQName
n) [Arg Name]
ns [NamedArg Expr]
args of
Maybe ([(Name, Expr)], [Arg Name])
Nothing -> TypeError -> TCM Term
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCM Term) -> TypeError -> TCM Term
forall a b. (a -> b) -> a -> b
$ AmbiguousQName -> TypeError
BadArgumentsToPatternSynonym AmbiguousQName
n
Just ([(Name, Expr)]
s, [Arg Name]
ns) -> do
let p' :: Expr
p' = Pattern' Expr -> Expr
A.patternToExpr Pattern' Expr
p
e' :: Expr
e' = [Name] -> Expr -> Expr
A.lambdaLiftExpr ((Arg Name -> Name) -> [Arg Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map Arg Name -> Name
forall e. Arg e -> e
unArg [Arg Name]
ns) ([(Name, Expr)] -> Expr -> Expr
forall a. SubstExpr a => [(Name, Expr)] -> a -> a
A.substExpr [(Name, Expr)]
s Expr
p')
Comparison -> Expr -> Type -> TCM Term
checkExpr' Comparison
cmp Expr
e' Type
t
A.Macro QName
x -> do
TelV Tele (Dom Type)
tel Type
_ <- Type -> TCMT IO (TelV Type)
forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Type -> m (TelV Type)
telView (Type -> TCMT IO (TelV Type))
-> (Definition -> Type) -> Definition -> TCMT IO (TelV Type)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Definition -> Type
defType (Definition -> TCMT IO (TelV Type))
-> TCMT IO Definition -> TCMT IO (TelV Type)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Definition -> TCMT IO Definition
forall (m :: * -> *).
(Functor m, HasConstInfo m, HasOptions m, ReadTCState m,
MonadTCEnv m, MonadDebug m) =>
Definition -> m Definition
instantiateDef (Definition -> TCMT IO Definition)
-> TCMT IO Definition -> TCMT IO Definition
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< QName -> TCMT IO Definition
forall (m :: * -> *). HasConstInfo m => QName -> m Definition
getConstInfo QName
x
Term
tTerm <- TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primAgdaTerm
Term
tName <- TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primQName
let argTel :: [Dom' Term ([Char], Type)]
argTel = [Dom' Term ([Char], Type)] -> [Dom' Term ([Char], Type)]
forall a. HasCallStack => [a] -> [a]
init ([Dom' Term ([Char], Type)] -> [Dom' Term ([Char], Type)])
-> [Dom' Term ([Char], Type)] -> [Dom' Term ([Char], Type)]
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Dom' Term ([Char], Type)]
forall t. Tele (Dom t) -> [Dom ([Char], t)]
telToList Tele (Dom Type)
tel
mkArg :: Type -> NamedArg A.Expr -> NamedArg A.Expr
mkArg :: Type -> NamedArg Expr -> NamedArg Expr
mkArg Type
t NamedArg Expr
a | Type -> Term
forall t a. Type'' t a -> a
unEl Type
t Term -> Term -> Bool
forall a. Eq a => a -> a -> Bool
== Term
tTerm =
((Named_ Expr -> Named_ Expr) -> NamedArg Expr -> NamedArg Expr
forall a b. (a -> b) -> Arg a -> Arg b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Named_ Expr -> Named_ Expr) -> NamedArg Expr -> NamedArg Expr)
-> ((Expr -> Expr) -> Named_ Expr -> Named_ Expr)
-> (Expr -> Expr)
-> NamedArg Expr
-> NamedArg Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Expr -> Expr) -> Named_ Expr -> Named_ Expr
forall a b. (a -> b) -> Named NamedName a -> Named NamedName b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap)
(AppInfo -> Expr -> NamedArg Expr -> Expr
A.App (Range -> AppInfo
A.defaultAppInfo (NamedArg Expr -> Range
forall a. HasRange a => a -> Range
getRange NamedArg Expr
a)) (ExprInfo -> Expr
A.QuoteTerm ExprInfo
A.exprNoRange) (NamedArg Expr -> Expr) -> (Expr -> NamedArg Expr) -> Expr -> Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expr -> NamedArg Expr
forall a. a -> NamedArg a
defaultNamedArg) NamedArg Expr
a
mkArg Type
t NamedArg Expr
a | Type -> Term
forall t a. Type'' t a -> a
unEl Type
t Term -> Term -> Bool
forall a. Eq a => a -> a -> Bool
== Term
tName =
((Named_ Expr -> Named_ Expr) -> NamedArg Expr -> NamedArg Expr
forall a b. (a -> b) -> Arg a -> Arg b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Named_ Expr -> Named_ Expr) -> NamedArg Expr -> NamedArg Expr)
-> ((Expr -> Expr) -> Named_ Expr -> Named_ Expr)
-> (Expr -> Expr)
-> NamedArg Expr
-> NamedArg Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Expr -> Expr) -> Named_ Expr -> Named_ Expr
forall a b. (a -> b) -> Named NamedName a -> Named NamedName b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap)
(AppInfo -> Expr -> NamedArg Expr -> Expr
A.App (Range -> AppInfo
A.defaultAppInfo (NamedArg Expr -> Range
forall a. HasRange a => a -> Range
getRange NamedArg Expr
a)) (ExprInfo -> Expr
A.Quote ExprInfo
A.exprNoRange) (NamedArg Expr -> Expr) -> (Expr -> NamedArg Expr) -> Expr -> Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expr -> NamedArg Expr
forall a. a -> NamedArg a
defaultNamedArg) NamedArg Expr
a
mkArg Type
t NamedArg Expr
a | Bool
otherwise = NamedArg Expr
a
makeArgs :: [Dom (String, Type)] -> [NamedArg A.Expr] -> ([NamedArg A.Expr], [NamedArg A.Expr])
makeArgs :: [Dom' Term ([Char], Type)]
-> [NamedArg Expr] -> ([NamedArg Expr], [NamedArg Expr])
makeArgs [] [NamedArg Expr]
args = ([], [NamedArg Expr]
args)
makeArgs [Dom' Term ([Char], Type)]
_ [] = ([], [])
makeArgs tel :: [Dom' Term ([Char], Type)]
tel@(Dom' Term ([Char], Type)
d : [Dom' Term ([Char], Type)]
tel1) (NamedArg Expr
arg : [NamedArg Expr]
args) =
case NamedArg Expr -> [Dom' Term ([Char], Type)] -> ImplicitInsertion
forall e a. NamedArg e -> [Dom a] -> ImplicitInsertion
insertImplicit NamedArg Expr
arg [Dom' Term ([Char], Type)]
tel of
ImplicitInsertion
NoInsertNeeded -> ([NamedArg Expr] -> [NamedArg Expr])
-> ([NamedArg Expr], [NamedArg Expr])
-> ([NamedArg Expr], [NamedArg Expr])
forall a b c. (a -> b) -> (a, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first (Type -> NamedArg Expr -> NamedArg Expr
mkArg (([Char], Type) -> Type
forall a b. (a, b) -> b
snd (([Char], Type) -> Type) -> ([Char], Type) -> Type
forall a b. (a -> b) -> a -> b
$ Dom' Term ([Char], Type) -> ([Char], Type)
forall t e. Dom' t e -> e
unDom Dom' Term ([Char], Type)
d) NamedArg Expr
arg NamedArg Expr -> [NamedArg Expr] -> [NamedArg Expr]
forall a. a -> [a] -> [a]
:) (([NamedArg Expr], [NamedArg Expr])
-> ([NamedArg Expr], [NamedArg Expr]))
-> ([NamedArg Expr], [NamedArg Expr])
-> ([NamedArg Expr], [NamedArg Expr])
forall a b. (a -> b) -> a -> b
$ [Dom' Term ([Char], Type)]
-> [NamedArg Expr] -> ([NamedArg Expr], [NamedArg Expr])
makeArgs [Dom' Term ([Char], Type)]
tel1 [NamedArg Expr]
args
ImpInsert [Dom ()]
is -> [Dom' Term ([Char], Type)]
-> [NamedArg Expr] -> ([NamedArg Expr], [NamedArg Expr])
makeArgs (Int -> [Dom' Term ([Char], Type)] -> [Dom' Term ([Char], Type)]
forall a. Int -> [a] -> [a]
drop ([Dom ()] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Dom ()]
is) [Dom' Term ([Char], Type)]
tel) (NamedArg Expr
arg NamedArg Expr -> [NamedArg Expr] -> [NamedArg Expr]
forall a. a -> [a] -> [a]
: [NamedArg Expr]
args)
ImplicitInsertion
BadImplicits -> (NamedArg Expr
arg NamedArg Expr -> [NamedArg Expr] -> [NamedArg Expr]
forall a. a -> [a] -> [a]
: [NamedArg Expr]
args, [])
NoSuchName{} -> (NamedArg Expr
arg NamedArg Expr -> [NamedArg Expr] -> [NamedArg Expr]
forall a. a -> [a] -> [a]
: [NamedArg Expr]
args, [])
([NamedArg Expr]
macroArgs, [NamedArg Expr]
otherArgs) = [Dom' Term ([Char], Type)]
-> [NamedArg Expr] -> ([NamedArg Expr], [NamedArg Expr])
makeArgs [Dom' Term ([Char], Type)]
argTel [NamedArg Expr]
args
unq :: Expr -> Expr
unq = AppInfo -> Expr -> NamedArg Expr -> Expr
A.App (Range -> AppInfo
A.defaultAppInfo (Range -> AppInfo) -> Range -> AppInfo
forall a b. (a -> b) -> a -> b
$ QName -> [NamedArg Expr] -> Range
forall u t. (HasRange u, HasRange t) => u -> t -> Range
fuseRange QName
x [NamedArg Expr]
args) (ExprInfo -> Expr
A.Unquote ExprInfo
A.exprNoRange) (NamedArg Expr -> Expr) -> (Expr -> NamedArg Expr) -> Expr -> Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expr -> NamedArg Expr
forall a. a -> NamedArg a
defaultNamedArg
desugared :: Expr
desugared = Expr -> [NamedArg Expr] -> Expr
A.app (Expr -> Expr
unq (Expr -> Expr) -> Expr -> Expr
forall a b. (a -> b) -> a -> b
$ AppView -> Expr
unAppView (AppView -> Expr) -> AppView -> Expr
forall a b. (a -> b) -> a -> b
$ Expr -> [NamedArg Expr] -> AppView
forall arg. Expr -> [NamedArg arg] -> AppView' arg
Application (QName -> Expr
A.Def QName
x) ([NamedArg Expr] -> AppView) -> [NamedArg Expr] -> AppView
forall a b. (a -> b) -> a -> b
$ [NamedArg Expr]
macroArgs) [NamedArg Expr]
otherArgs
Comparison -> Expr -> Type -> TCM Term
checkExpr' Comparison
cmp Expr
desugared Type
t
A.Unquote ExprInfo
_
| [NamedArg Expr
arg] <- [NamedArg Expr]
args -> do
(MetaId
_, Term
hole) <- RunMetaOccursCheck -> Comparison -> Type -> TCMT IO (MetaId, Term)
forall (m :: * -> *).
MonadMetaSolver m =>
RunMetaOccursCheck -> Comparison -> Type -> m (MetaId, Term)
newValueMeta RunMetaOccursCheck
RunMetaOccursCheck Comparison
CmpLeq Type
t
Expr -> Term -> Type -> TCMT IO ()
unquoteM (NamedArg Expr -> Expr
forall a. NamedArg a -> a
namedArg NamedArg Expr
arg) Term
hole Type
t
Term -> TCM Term
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Term
hole
| NamedArg Expr
arg : [NamedArg Expr]
args <- [NamedArg Expr]
args -> do
Tele (Dom Type)
tel <- [NamedArg Expr] -> TCM (Tele (Dom Type))
forall a. [Arg a] -> TCM (Tele (Dom Type))
metaTel [NamedArg Expr]
args
Type
target <- Tele (Dom Type) -> TCMT IO Type -> TCMT IO Type
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
forall (m :: * -> *) a.
MonadAddContext m =>
Tele (Dom Type) -> m a -> m a
addContext Tele (Dom Type)
tel TCMT IO Type
newTypeMeta_
let holeType :: Type
holeType = Tele (Dom Type) -> Type -> Type
telePi_ Tele (Dom Type)
tel Type
target
(Just [Arg Term]
vs, Tele (Dom Type)
EmptyTel) <- (Elims -> Maybe [Arg Term])
-> (Elims, Tele (Dom Type)) -> (Maybe [Arg Term], Tele (Dom Type))
forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFst Elims -> Maybe [Arg Term]
forall a. [Elim' a] -> Maybe [Arg a]
allApplyElims ((Elims, Tele (Dom Type)) -> (Maybe [Arg Term], Tele (Dom Type)))
-> TCMT IO (Elims, Tele (Dom Type))
-> TCMT IO (Maybe [Arg Term], Tele (Dom Type))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Comparison
-> ExpandHidden
-> Range
-> [NamedArg Expr]
-> Tele (Dom Type)
-> TCMT IO (Elims, Tele (Dom Type))
checkArguments_ Comparison
CmpLeq ExpandHidden
ExpandLast ([NamedArg Expr] -> Range
forall a. HasRange a => a -> Range
getRange [NamedArg Expr]
args) [NamedArg Expr]
args Tele (Dom Type)
tel
let rho :: Substitution' Term
rho = [Term] -> [Term]
forall a. [a] -> [a]
reverse ((Arg Term -> Term) -> [Arg Term] -> [Term]
forall a b. (a -> b) -> [a] -> [b]
map Arg Term -> Term
forall e. Arg e -> e
unArg [Arg Term]
vs) [Term] -> Substitution' Term -> Substitution' Term
forall a. DeBruijn a => [a] -> Substitution' a -> Substitution' a
++# Substitution' Term
forall a. Substitution' a
IdS
Type -> Type -> TCMT IO ()
forall (m :: * -> *). MonadConversion m => Type -> Type -> m ()
equalType (Substitution' (SubstArg Type) -> Type -> Type
forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst Substitution' Term
Substitution' (SubstArg Type)
rho Type
target) Type
t
(MetaId
_, Term
hole) <- RunMetaOccursCheck -> Comparison -> Type -> TCMT IO (MetaId, Term)
forall (m :: * -> *).
MonadMetaSolver m =>
RunMetaOccursCheck -> Comparison -> Type -> m (MetaId, Term)
newValueMeta RunMetaOccursCheck
RunMetaOccursCheck Comparison
CmpLeq Type
holeType
Expr -> Term -> Type -> TCMT IO ()
unquoteM (NamedArg Expr -> Expr
forall a. NamedArg a -> a
namedArg NamedArg Expr
arg) Term
hole Type
holeType
Term -> TCM Term
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Term -> TCM Term) -> Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
apply Term
hole [Arg Term]
vs
where
metaTel :: [Arg a] -> TCM Telescope
metaTel :: forall a. [Arg a] -> TCM (Tele (Dom Type))
metaTel [] = Tele (Dom Type) -> TCM (Tele (Dom Type))
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Tele (Dom Type)
forall a. Tele a
EmptyTel
metaTel (Arg a
arg : [Arg a]
args) = do
Type
a <- TCMT IO Type
newTypeMeta_
let dom :: Dom Type
dom = Type
a Type -> Dom' Term a -> Dom Type
forall a b. a -> Dom' Term b -> Dom' Term a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Arg a -> Dom' Term a
forall a. Arg a -> Dom a
domFromArg Arg a
arg
Dom Type -> Abs (Tele (Dom Type)) -> Tele (Dom Type)
forall a. a -> Abs (Tele a) -> Tele a
ExtendTel Dom Type
dom (Abs (Tele (Dom Type)) -> Tele (Dom Type))
-> (Tele (Dom Type) -> Abs (Tele (Dom Type)))
-> Tele (Dom Type)
-> Tele (Dom Type)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Tele (Dom Type) -> Abs (Tele (Dom Type))
forall a. [Char] -> a -> Abs a
Abs [Char]
"x" (Tele (Dom Type) -> Tele (Dom Type))
-> TCM (Tele (Dom Type)) -> TCM (Tele (Dom Type))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
([Char], Dom Type)
-> TCM (Tele (Dom Type)) -> TCM (Tele (Dom Type))
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
forall (m :: * -> *) a.
MonadAddContext m =>
([Char], Dom Type) -> m a -> m a
addContext ([Char]
"x" :: String, Dom Type
dom) ([Arg a] -> TCM (Tele (Dom Type))
forall a. [Arg a] -> TCM (Tele (Dom Type))
metaTel [Arg a]
args)
Expr
_ -> do
Term
v <- Comparison -> Expr -> Type -> Expr -> [NamedArg Expr] -> TCM Term
checkHeadApplication Comparison
cmp Expr
e Type
t Expr
hd [NamedArg Expr]
args
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.app" Int
30 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"checkApplication: checkHeadApplication returned"
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"v = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Term -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Term -> m Doc
prettyTCM Term
v
]
Term -> TCM Term
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Term
v
inferApplication :: ExpandHidden -> A.Expr -> A.Args -> A.Expr -> TCM (Term, Type)
inferApplication :: ExpandHidden -> Expr -> [NamedArg Expr] -> Expr -> TCM (Term, Type)
inferApplication ExpandHidden
exh Expr
hd [NamedArg Expr]
args Expr
e | Bool -> Bool
not (Expr -> Bool
defOrVar Expr
hd) = do
Type
t <- TCMT IO Type -> TCMT IO Type
forall (m :: * -> *) a.
(MonadTCEnv m, HasOptions m, MonadDebug m) =>
m a -> m a
workOnTypes (TCMT IO Type -> TCMT IO Type) -> TCMT IO Type -> TCMT IO Type
forall a b. (a -> b) -> a -> b
$ TCMT IO Type
newTypeMeta_
Term
v <- Comparison -> Expr -> Type -> TCM Term
checkExpr' Comparison
CmpEq Expr
e Type
t
(Term, Type) -> TCM (Term, Type)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Term
v, Type
t)
inferApplication ExpandHidden
exh Expr
hd [NamedArg Expr]
args Expr
e = TCM (Term, Type) -> TCM (Term, Type)
forall a. TCM a -> TCM a
postponeInstanceConstraints (TCM (Term, Type) -> TCM (Term, Type))
-> TCM (Term, Type) -> TCM (Term, Type)
forall a b. (a -> b) -> a -> b
$ do
SortKit{QName -> Maybe (UnivSize, Univ)
UnivSize -> Univ -> QName
nameOfUniv :: UnivSize -> Univ -> QName
isNameOfUniv :: QName -> Maybe (UnivSize, Univ)
nameOfUniv :: SortKit -> UnivSize -> Univ -> QName
isNameOfUniv :: SortKit -> QName -> Maybe (UnivSize, Univ)
..} <- TCMT IO SortKit
forall (m :: * -> *).
(HasBuiltins m, MonadTCError m, HasOptions m) =>
m SortKit
sortKit
case Expr -> Expr
unScope Expr
hd of
A.Proj ProjOrigin
o AmbiguousQName
p | AmbiguousQName -> Bool
isAmbiguous AmbiguousQName
p -> Expr
-> ProjOrigin -> List1 QName -> [NamedArg Expr] -> TCM (Term, Type)
inferProjApp Expr
e ProjOrigin
o (AmbiguousQName -> List1 QName
unAmbQ AmbiguousQName
p) [NamedArg Expr]
args
A.Def' QName
x Suffix
s | Just (UnivSize
sz, Univ
u) <- QName -> Maybe (UnivSize, Univ)
isNameOfUniv QName
x -> UnivSize
-> Univ
-> Expr
-> QName
-> Suffix
-> [NamedArg Expr]
-> TCM (Term, Type)
inferUniv UnivSize
sz Univ
u Expr
e QName
x Suffix
s [NamedArg Expr]
args
Expr
_ -> do
(Elims -> Term
f, Type
t0) <- Expr -> TCM (Elims -> Term, Type)
inferHead Expr
hd
let r :: Range
r = Expr -> Range
forall a. HasRange a => a -> Range
getRange Expr
hd
Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget)
res <- ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> TCM
(Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget))
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT (ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> TCM
(Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget)))
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> TCM
(Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget))
forall a b. (a -> b) -> a -> b
$ Comparison
-> ExpandHidden
-> Range
-> [NamedArg Expr]
-> Type
-> Maybe Type
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
checkArgumentsE Comparison
CmpEq ExpandHidden
exh (Expr -> Range
forall a. HasRange a => a -> Range
getRange Expr
hd) [NamedArg Expr]
args Type
t0 Maybe Type
forall a. Maybe a
Nothing
case Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget)
res of
Right st :: ArgsCheckState CheckedTarget
st@(ACState{acType :: forall a. ArgsCheckState a -> Type
acType = Type
t1}) -> (Term -> (Term, Type)) -> TCM Term -> TCM (Term, Type)
forall a b. (a -> b) -> TCMT IO a -> TCMT IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (,Type
t1) (TCM Term -> TCM (Term, Type)) -> TCM Term -> TCM (Term, Type)
forall a b. (a -> b) -> a -> b
$ Term -> TCM Term
forall (m :: * -> *). PureTCM m => Term -> m Term
unfoldInlined (Term -> TCM Term) -> TCM Term -> TCM Term
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (Elims -> Term) -> ArgsCheckState CheckedTarget -> TCM Term
forall a. (Elims -> Term) -> ArgsCheckState a -> TCM Term
checkHeadConstraints Elims -> Term
f ArgsCheckState CheckedTarget
st
Left ArgsCheckState [NamedArg Expr]
problem -> do
Type
t <- TCMT IO Type -> TCMT IO Type
forall (m :: * -> *) a.
(MonadTCEnv m, HasOptions m, MonadDebug m) =>
m a -> m a
workOnTypes (TCMT IO Type -> TCMT IO Type) -> TCMT IO Type -> TCMT IO Type
forall a b. (a -> b) -> a -> b
$ TCMT IO Type
newTypeMeta_
Term
v <- ArgsCheckState [NamedArg Expr]
-> Comparison
-> ExpandHidden
-> Range
-> [NamedArg Expr]
-> Type
-> (ArgsCheckState CheckedTarget -> TCM Term)
-> TCM Term
postponeArgs ArgsCheckState [NamedArg Expr]
problem Comparison
CmpEq ExpandHidden
exh Range
r [NamedArg Expr]
args Type
t ((ArgsCheckState CheckedTarget -> TCM Term) -> TCM Term)
-> (ArgsCheckState CheckedTarget -> TCM Term) -> TCM Term
forall a b. (a -> b) -> a -> b
$ \ ArgsCheckState CheckedTarget
st -> Term -> TCM Term
forall (m :: * -> *). PureTCM m => Term -> m Term
unfoldInlined (Term -> TCM Term) -> TCM Term -> TCM Term
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (Elims -> Term) -> ArgsCheckState CheckedTarget -> TCM Term
forall a. (Elims -> Term) -> ArgsCheckState a -> TCM Term
checkHeadConstraints Elims -> Term
f ArgsCheckState CheckedTarget
st
(Term, Type) -> TCM (Term, Type)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Term
v, Type
t)
inferHeadDef :: ProjOrigin -> QName -> TCM (Elims -> Term, Type)
inferHeadDef :: ProjOrigin -> QName -> TCM (Elims -> Term, Type)
inferHeadDef ProjOrigin
o QName
x = do
Maybe Projection
proj <- QName -> TCMT IO (Maybe Projection)
forall (m :: * -> *).
HasConstInfo m =>
QName -> m (Maybe Projection)
isRelevantProjection QName
x
Relevance
rel <- ArgInfo -> Relevance
forall a. LensRelevance a => a -> Relevance
getRelevance (ArgInfo -> Relevance)
-> (Definition -> ArgInfo) -> Definition -> Relevance
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Definition -> ArgInfo
defArgInfo (Definition -> Relevance)
-> TCMT IO Definition -> TCMT IO Relevance
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> QName -> TCMT IO Definition
forall (m :: * -> *). HasConstInfo m => QName -> m Definition
getConstInfo QName
x
let app :: [Arg Term] -> Term
app =
case Maybe Projection
proj of
Maybe Projection
Nothing -> \ [Arg Term]
args -> QName -> Elims -> Term
Def QName
x (Elims -> Term) -> Elims -> Term
forall a b. (a -> b) -> a -> b
$ (Arg Term -> Elim) -> [Arg Term] -> Elims
forall a b. (a -> b) -> [a] -> [b]
map Arg Term -> Elim
forall a. Arg a -> Elim' a
Apply [Arg Term]
args
Just Projection
p -> \ [Arg Term]
args -> Projection -> ProjOrigin -> Relevance -> [Arg Term] -> Term
projDropParsApply Projection
p ProjOrigin
o Relevance
rel [Arg Term]
args
(Term -> Elims -> Term) -> (Term, Type) -> (Elims -> Term, Type)
forall a b c. (a -> b) -> (a, c) -> (b, c)
mapFst Term -> Elims -> Term
forall t. Apply t => t -> Elims -> t
applyE ((Term, Type) -> (Elims -> Term, Type))
-> TCM (Term, Type) -> TCM (Elims -> Term, Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([Arg Term] -> Term) -> QName -> TCM (Term, Type)
inferDef [Arg Term] -> Term
app QName
x
inferHead :: A.Expr -> TCM (Elims -> Term, Type)
inferHead :: Expr -> TCM (Elims -> Term, Type)
inferHead Expr
e = do
case Expr
e of
A.Var Name
x -> do
(Term
u, Dom Type
a) <- Name -> TCMT IO (Term, Dom Type)
forall (m :: * -> *).
(MonadFail m, MonadTCEnv m) =>
Name -> m (Term, Dom Type)
getVarInfo Name
x
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.var" Int
20 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
hsep
[ TCMT IO Doc
"variable" , Name -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Name -> m Doc
prettyTCM Name
x
, TCMT IO Doc
"(" , [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text (Term -> [Char]
forall a. Show a => a -> [Char]
show Term
u) , TCMT IO Doc
")"
, TCMT IO Doc
"has type:" , Dom Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Dom Type -> m Doc
prettyTCM Dom Type
a
]
Bool -> TCMT IO () -> TCMT IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Dom Type -> Bool
forall a. LensRelevance a => a -> Bool
usableRelevance Dom Type
a) (TCMT IO () -> TCMT IO ()) -> TCMT IO () -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$
TypeError -> TCMT IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO ()) -> TypeError -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ Name -> TypeError
VariableIsIrrelevant Name
x
TCMT IO Bool -> TCMT IO () -> TCMT IO ()
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
unlessM ((Dom Type -> Quantity
forall a. LensQuantity a => a -> Quantity
getQuantity Dom Type
a Quantity -> Quantity -> Bool
`moreQuantity`) (Quantity -> Bool) -> TCMT IO Quantity -> TCMT IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Lens' TCEnv Quantity -> TCMT IO Quantity
forall (m :: * -> *) a. MonadTCEnv m => Lens' TCEnv a -> m a
viewTC (Quantity -> f Quantity) -> TCEnv -> f TCEnv
Lens' TCEnv Quantity
eQuantity) (TCMT IO () -> TCMT IO ()) -> TCMT IO () -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$
TypeError -> TCMT IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO ()) -> TypeError -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ Name -> TypeError
VariableIsErased Name
x
Bool -> TCMT IO () -> TCMT IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Dom Type -> Bool
forall a. LensCohesion a => a -> Bool
usableCohesion Dom Type
a) (TCMT IO () -> TCMT IO ()) -> TCMT IO () -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$
TypeError -> TCMT IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO ()) -> TypeError -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ Name -> Cohesion -> TypeError
VariableIsOfUnusableCohesion Name
x (Dom Type -> Cohesion
forall a. LensCohesion a => a -> Cohesion
getCohesion Dom Type
a)
(Elims -> Term, Type) -> TCM (Elims -> Term, Type)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Term -> Elims -> Term
forall t. Apply t => t -> Elims -> t
applyE Term
u, Dom Type -> Type
forall t e. Dom' t e -> e
unDom Dom Type
a)
A.Def QName
x -> ProjOrigin -> QName -> TCM (Elims -> Term, Type)
inferHeadDef ProjOrigin
ProjPrefix QName
x
A.Def'{} -> TCM (Elims -> Term, Type)
forall a. HasCallStack => a
__IMPOSSIBLE__
A.Proj ProjOrigin
o AmbiguousQName
ambP | Just QName
d <- AmbiguousQName -> Maybe QName
getUnambiguous AmbiguousQName
ambP -> ProjOrigin -> QName -> TCM (Elims -> Term, Type)
inferHeadDef ProjOrigin
o QName
d
A.Proj{} -> TCM (Elims -> Term, Type)
forall a. HasCallStack => a
__IMPOSSIBLE__
A.Con AmbiguousQName
ambC | Just QName
c <- AmbiguousQName -> Maybe QName
getUnambiguous AmbiguousQName
ambC -> do
ConHead
con <-
(SigError -> TCMT IO ConHead)
-> TCMT IO (Either SigError ConHead) -> TCMT IO ConHead
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> m (Either a b) -> m b
fromRightM
(TCMT IO ConHead -> SigError -> TCMT IO ConHead
forall (m :: * -> *) a.
(HasCallStack, MonadDebug m) =>
m a -> SigError -> m a
sigError (TypeError -> TCMT IO ConHead
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO ConHead) -> TypeError -> TCMT IO ConHead
forall a b. (a -> b) -> a -> b
$ QName -> TypeError
AbstractConstructorNotInScope QName
c)) (TCMT IO (Either SigError ConHead) -> TCMT IO ConHead)
-> TCMT IO (Either SigError ConHead) -> TCMT IO ConHead
forall a b. (a -> b) -> a -> b
$
QName -> TCMT IO (Either SigError ConHead)
getOrigConHead QName
c
(Term
u, Type
a) <- ([Arg Term] -> Term) -> QName -> TCM (Term, Type)
inferDef (\ [Arg Term]
_ -> ConHead -> ConInfo -> Elims -> Term
Con ConHead
con ConInfo
ConOCon []) QName
c
Constructor{conPars :: Defn -> Int
conPars = Int
n} <- Definition -> Defn
theDef (Definition -> Defn) -> TCMT IO Definition -> TCMT IO Defn
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Definition -> TCMT IO Definition
forall (m :: * -> *).
(Functor m, HasConstInfo m, HasOptions m, ReadTCState m,
MonadTCEnv m, MonadDebug m) =>
Definition -> m Definition
instantiateDef (Definition -> TCMT IO Definition)
-> TCMT IO Definition -> TCMT IO Definition
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< QName -> TCMT IO Definition
forall (m :: * -> *). HasConstInfo m => QName -> m Definition
getConstInfo QName
c)
[Char] -> Int -> [Char] -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"tc.term.con" Int
7 ([Char] -> TCMT IO ()) -> [Char] -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [[Char]] -> [Char]
unwords [QName -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow QName
c, [Char]
"has", Int -> [Char]
forall a. Show a => a -> [Char]
show Int
n, [Char]
"parameters."]
(Elims -> Term, Type) -> TCM (Elims -> Term, Type)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Term -> Elims -> Term
forall t. Apply t => t -> Elims -> t
applyE Term
u (Elims -> Term) -> (Elims -> Elims) -> Elims -> Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Elims -> Elims
forall a. Int -> [a] -> [a]
drop Int
n, Type
a)
A.Con{} -> TCM (Elims -> Term, Type)
forall a. HasCallStack => a
__IMPOSSIBLE__
A.QuestionMark MetaInfo
i InteractionId
ii -> (Comparison -> Type -> TCMT IO (MetaId, Term))
-> MetaInfo -> TCM (Elims -> Term, Type)
inferMeta (InteractionId -> Comparison -> Type -> TCMT IO (MetaId, Term)
newQuestionMark InteractionId
ii) MetaInfo
i
A.Underscore MetaInfo
i -> (Comparison -> Type -> TCMT IO (MetaId, Term))
-> MetaInfo -> TCM (Elims -> Term, Type)
inferMeta (RunMetaOccursCheck -> Comparison -> Type -> TCMT IO (MetaId, Term)
forall (m :: * -> *).
MonadMetaSolver m =>
RunMetaOccursCheck -> Comparison -> Type -> m (MetaId, Term)
newValueMeta RunMetaOccursCheck
RunMetaOccursCheck) MetaInfo
i
Expr
e -> do
(Term
term, Type
t) <- Expr -> TCM (Term, Type)
inferExpr Expr
e
(Elims -> Term, Type) -> TCM (Elims -> Term, Type)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Term -> Elims -> Term
forall t. Apply t => t -> Elims -> t
applyE Term
term, Type
t)
inferDef :: (Args -> Term) -> QName -> TCM (Term, Type)
inferDef :: ([Arg Term] -> Term) -> QName -> TCM (Term, Type)
inferDef [Arg Term] -> Term
mkTerm QName
x =
Call -> TCM (Term, Type) -> TCM (Term, Type)
forall a. Call -> TCMT IO a -> TCMT IO a
forall (m :: * -> *) a. MonadTrace m => Call -> m a -> m a
traceCall (QName -> Call
InferDef QName
x) (TCM (Term, Type) -> TCM (Term, Type))
-> TCM (Term, Type) -> TCM (Term, Type)
forall a b. (a -> b) -> a -> b
$ do
Definition
d0 <- QName -> TCMT IO Definition
forall (m :: * -> *). HasConstInfo m => QName -> m Definition
getConstInfo QName
x
Definition
d <- Definition -> TCMT IO Definition
forall (m :: * -> *).
(Functor m, HasConstInfo m, HasOptions m, ReadTCState m,
MonadTCEnv m, MonadDebug m) =>
Definition -> m Definition
instantiateDef Definition
d0
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.def" Int
10 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"inferDef" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => QName -> m Doc
prettyTCM QName
x
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.def" Int
30 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
" absolute type: " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc -> TCMT IO Doc
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext (Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM (Type -> TCMT IO Doc) -> Type -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Definition -> Type
defType Definition
d0)
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.def" Int
30 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
" instantiated type:" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM (Definition -> Type
defType Definition
d)
QName -> Definition -> TCMT IO ()
forall (m :: * -> *).
MonadConversion m =>
QName -> Definition -> m ()
checkModality QName
x Definition
d
case Definition -> Defn
theDef Definition
d of
GeneralizableVar{} -> do
GeneralizedValue
val <- GeneralizedValue -> Maybe GeneralizedValue -> GeneralizedValue
forall a. a -> Maybe a -> a
fromMaybe GeneralizedValue
forall a. HasCallStack => a
__IMPOSSIBLE__ (Maybe GeneralizedValue -> GeneralizedValue)
-> TCMT IO (Maybe GeneralizedValue) -> TCMT IO GeneralizedValue
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Lens' TCEnv (Maybe GeneralizedValue)
-> TCMT IO (Maybe GeneralizedValue)
forall (m :: * -> *) a. MonadTCEnv m => Lens' TCEnv a -> m a
viewTC ((Map QName GeneralizedValue -> f (Map QName GeneralizedValue))
-> TCEnv -> f TCEnv
Lens' TCEnv (Map QName GeneralizedValue)
eGeneralizedVars ((Map QName GeneralizedValue -> f (Map QName GeneralizedValue))
-> TCEnv -> f TCEnv)
-> ((Maybe GeneralizedValue -> f (Maybe GeneralizedValue))
-> Map QName GeneralizedValue -> f (Map QName GeneralizedValue))
-> (Maybe GeneralizedValue -> f (Maybe GeneralizedValue))
-> TCEnv
-> f TCEnv
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QName
-> Lens' (Map QName GeneralizedValue) (Maybe GeneralizedValue)
forall k v. Ord k => k -> Lens' (Map k v) (Maybe v)
key QName
x)
Substitution' Term
sub <- CheckpointId -> TCMT IO (Substitution' Term)
forall (tcm :: * -> *).
MonadTCEnv tcm =>
CheckpointId -> tcm (Substitution' Term)
checkpointSubstitution (GeneralizedValue -> CheckpointId
genvalCheckpoint GeneralizedValue
val)
let (Term
v, Type
t) = Substitution' (SubstArg (Term, Type))
-> (Term, Type) -> (Term, Type)
forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst Substitution' Term
Substitution' (SubstArg (Term, Type))
sub (GeneralizedValue -> Term
genvalTerm GeneralizedValue
val, GeneralizedValue -> Type
genvalType GeneralizedValue
val)
[Arg Term] -> Type -> Term -> TCMT IO ()
debug [] Type
t Term
v
(Term, Type) -> TCM (Term, Type)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Term
v, Type
t)
Defn
_ -> do
[Arg Term]
vs <- QName -> TCMT IO [Arg Term]
forall (m :: * -> *).
(Functor m, HasConstInfo m, HasOptions m, ReadTCState m,
MonadTCEnv m, MonadDebug m) =>
QName -> m [Arg Term]
freeVarsToApply QName
x
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.def" Int
30 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
" free vars:" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Semigroup (m Doc), Foldable t) =>
t (m Doc) -> m Doc
prettyList_ ((Arg Term -> TCMT IO Doc) -> [Arg Term] -> [TCMT IO Doc]
forall a b. (a -> b) -> [a] -> [b]
map Arg Term -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Arg Term -> m Doc
prettyTCM [Arg Term]
vs)
let t :: Type
t = Definition -> Type
defType Definition
d
v :: Term
v = [Arg Term] -> Term
mkTerm [Arg Term]
vs
Definition -> [Arg Term] -> TCMT IO ()
forall (m :: * -> *).
MonadConversion m =>
Definition -> [Arg Term] -> m ()
checkModalityArgs Definition
d0 [Arg Term]
vs
[Arg Term] -> Type -> Term -> TCMT IO ()
debug [Arg Term]
vs Type
t Term
v
(Term, Type) -> TCM (Term, Type)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Term
v, Type
t)
where
debug :: Args -> Type -> Term -> TCM ()
debug :: [Arg Term] -> Type -> Term -> TCMT IO ()
debug [Arg Term]
vs Type
t Term
v = do
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.def" Int
60 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"freeVarsToApply to def " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
hsep ((Arg Term -> TCMT IO Doc) -> [Arg Term] -> [TCMT IO Doc]
forall a b. (a -> b) -> [a] -> [b]
map ([Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char] -> TCMT IO Doc)
-> (Arg Term -> [Char]) -> Arg Term -> TCMT IO Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Arg Term -> [Char]
forall a. Show a => a -> [Char]
show) [Arg Term]
vs)
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.def" Int
10 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"inferred def " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => QName -> m Doc
prettyTCM QName
x TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
hsep ((Arg Term -> TCMT IO Doc) -> [Arg Term] -> [TCMT IO Doc]
forall a b. (a -> b) -> [a] -> [b]
map Arg Term -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Arg Term -> m Doc
prettyTCM [Arg Term]
vs)
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
":" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
t
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"-->" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Term -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Term -> m Doc
prettyTCM Term
v ]
checkHeadApplication :: Comparison -> A.Expr -> Type -> A.Expr -> [NamedArg A.Expr] -> TCM Term
checkHeadApplication :: Comparison -> Expr -> Type -> Expr -> [NamedArg Expr] -> TCM Term
checkHeadApplication Comparison
cmp Expr
e Type
t Expr
hd [NamedArg Expr]
args = do
SortKit{QName -> Maybe (UnivSize, Univ)
UnivSize -> Univ -> QName
nameOfUniv :: SortKit -> UnivSize -> Univ -> QName
isNameOfUniv :: SortKit -> QName -> Maybe (UnivSize, Univ)
nameOfUniv :: UnivSize -> Univ -> QName
isNameOfUniv :: QName -> Maybe (UnivSize, Univ)
..} <- TCMT IO SortKit
forall (m :: * -> *).
(HasBuiltins m, MonadTCError m, HasOptions m) =>
m SortKit
sortKit
Maybe QName
sharp <- (CoinductionKit -> QName) -> Maybe CoinductionKit -> Maybe QName
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap CoinductionKit -> QName
nameOfSharp (Maybe CoinductionKit -> Maybe QName)
-> TCMT IO (Maybe CoinductionKit) -> TCMT IO (Maybe QName)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TCMT IO (Maybe CoinductionKit)
coinductionKit
Maybe QName
conId <- PrimitiveId -> TCMT IO (Maybe QName)
forall (m :: * -> *).
HasBuiltins m =>
PrimitiveId -> m (Maybe QName)
getNameOfConstrained PrimitiveId
builtinConId
Maybe QName
pOr <- PrimitiveId -> TCMT IO (Maybe QName)
forall (m :: * -> *).
HasBuiltins m =>
PrimitiveId -> m (Maybe QName)
getNameOfConstrained PrimitiveId
builtinPOr
Maybe QName
pComp <- PrimitiveId -> TCMT IO (Maybe QName)
forall (m :: * -> *).
HasBuiltins m =>
PrimitiveId -> m (Maybe QName)
getNameOfConstrained PrimitiveId
builtinComp
Maybe QName
pHComp <- PrimitiveId -> TCMT IO (Maybe QName)
forall (m :: * -> *).
HasBuiltins m =>
PrimitiveId -> m (Maybe QName)
getNameOfConstrained PrimitiveId
builtinHComp
Maybe QName
pTrans <- PrimitiveId -> TCMT IO (Maybe QName)
forall (m :: * -> *).
HasBuiltins m =>
PrimitiveId -> m (Maybe QName)
getNameOfConstrained PrimitiveId
builtinTrans
Maybe QName
mglue <- PrimitiveId -> TCMT IO (Maybe QName)
forall (m :: * -> *).
HasBuiltins m =>
PrimitiveId -> m (Maybe QName)
getNameOfConstrained PrimitiveId
builtin_glue
Maybe QName
mglueU <- PrimitiveId -> TCMT IO (Maybe QName)
forall (m :: * -> *).
HasBuiltins m =>
PrimitiveId -> m (Maybe QName)
getNameOfConstrained PrimitiveId
builtin_glueU
case Expr
hd of
A.Def' QName
c Suffix
s | Just (UnivSize
sz, Univ
u) <- QName -> Maybe (UnivSize, Univ)
isNameOfUniv QName
c -> UnivSize
-> Univ
-> Comparison
-> Expr
-> Type
-> QName
-> Suffix
-> [NamedArg Expr]
-> TCM Term
checkUniv UnivSize
sz Univ
u Comparison
cmp Expr
e Type
t QName
c Suffix
s [NamedArg Expr]
args
A.Def QName
c | QName -> Maybe QName
forall a. a -> Maybe a
Just QName
c Maybe QName -> Maybe QName -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe QName
sharp -> Expr -> Type -> QName -> [NamedArg Expr] -> TCM Term
checkSharpApplication Expr
e Type
t QName
c [NamedArg Expr]
args
A.Def QName
c | QName -> Maybe QName
forall a. a -> Maybe a
Just QName
c Maybe QName -> Maybe QName -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe QName
pComp -> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term
defaultResult' (Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term)
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term
forall a b. (a -> b) -> a -> b
$ (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
forall a. a -> Maybe a
Just ((MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]))
-> (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
forall a b. (a -> b) -> a -> b
$ QName -> MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]
checkPrimComp QName
c
A.Def QName
c | QName -> Maybe QName
forall a. a -> Maybe a
Just QName
c Maybe QName -> Maybe QName -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe QName
pHComp -> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term
defaultResult' (Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term)
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term
forall a b. (a -> b) -> a -> b
$ (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
forall a. a -> Maybe a
Just ((MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]))
-> (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
forall a b. (a -> b) -> a -> b
$ QName -> MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]
checkPrimHComp QName
c
A.Def QName
c | QName -> Maybe QName
forall a. a -> Maybe a
Just QName
c Maybe QName -> Maybe QName -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe QName
pTrans -> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term
defaultResult' (Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term)
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term
forall a b. (a -> b) -> a -> b
$ (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
forall a. a -> Maybe a
Just ((MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]))
-> (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
forall a b. (a -> b) -> a -> b
$ QName -> MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]
checkPrimTrans QName
c
A.Def QName
c | QName -> Maybe QName
forall a. a -> Maybe a
Just QName
c Maybe QName -> Maybe QName -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe QName
conId -> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term
defaultResult' (Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term)
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term
forall a b. (a -> b) -> a -> b
$ (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
forall a. a -> Maybe a
Just ((MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]))
-> (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
forall a b. (a -> b) -> a -> b
$ QName -> MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]
checkConId QName
c
A.Def QName
c | QName -> Maybe QName
forall a. a -> Maybe a
Just QName
c Maybe QName -> Maybe QName -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe QName
pOr -> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term
defaultResult' (Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term)
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term
forall a b. (a -> b) -> a -> b
$ (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
forall a. a -> Maybe a
Just ((MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]))
-> (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
forall a b. (a -> b) -> a -> b
$ QName -> MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]
checkPOr QName
c
A.Def QName
c | QName -> Maybe QName
forall a. a -> Maybe a
Just QName
c Maybe QName -> Maybe QName -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe QName
mglue -> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term
defaultResult' (Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term)
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term
forall a b. (a -> b) -> a -> b
$ (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
forall a. a -> Maybe a
Just ((MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]))
-> (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
forall a b. (a -> b) -> a -> b
$ QName -> MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]
check_glue QName
c
A.Def QName
c | QName -> Maybe QName
forall a. a -> Maybe a
Just QName
c Maybe QName -> Maybe QName -> Bool
forall a. Eq a => a -> a -> Bool
== Maybe QName
mglueU -> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term
defaultResult' (Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term)
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term
forall a b. (a -> b) -> a -> b
$ (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
forall a. a -> Maybe a
Just ((MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]))
-> (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
forall a b. (a -> b) -> a -> b
$ QName -> MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]
check_glueU QName
c
Expr
_ -> TCM Term
defaultResult
where
defaultResult :: TCM Term
defaultResult :: TCM Term
defaultResult = Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term
defaultResult' Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
forall a. Maybe a
Nothing
defaultResult' :: Maybe (MaybeRanges -> Args -> Type -> TCM Args) -> TCM Term
defaultResult' :: Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
-> TCM Term
defaultResult' Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
mk = do
(Elims -> Term
f, Type
t0) <- Expr -> TCM (Elims -> Term, Type)
inferHead Expr
hd
ExpandHidden
expandLast <- (TCEnv -> ExpandHidden) -> TCMT IO ExpandHidden
forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC TCEnv -> ExpandHidden
envExpandLast
Comparison
-> ExpandHidden
-> Range
-> [NamedArg Expr]
-> Type
-> Type
-> (ArgsCheckState CheckedTarget -> TCM Term)
-> TCM Term
checkArguments Comparison
cmp ExpandHidden
expandLast (Expr -> Range
forall a. HasRange a => a -> Range
getRange Expr
hd) [NamedArg Expr]
args Type
t0 Type
t ((ArgsCheckState CheckedTarget -> TCM Term) -> TCM Term)
-> (ArgsCheckState CheckedTarget -> TCM Term) -> TCM Term
forall a b. (a -> b) -> a -> b
$ \ st :: ArgsCheckState CheckedTarget
st@(ACState MaybeRanges
rs Elims
vs [Maybe (Abs Constraint)]
_ Type
t1 CheckedTarget
checkedTarget) -> do
let check :: Maybe (TCMT IO [Arg Term])
check = do
MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]
k <- Maybe (MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term])
mk
[Arg Term]
as <- Elims -> Maybe [Arg Term]
forall a. [Elim' a] -> Maybe [Arg a]
allApplyElims Elims
vs
TCMT IO [Arg Term] -> Maybe (TCMT IO [Arg Term])
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TCMT IO [Arg Term] -> Maybe (TCMT IO [Arg Term]))
-> TCMT IO [Arg Term] -> Maybe (TCMT IO [Arg Term])
forall a b. (a -> b) -> a -> b
$ MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]
k MaybeRanges
rs [Arg Term]
as Type
t1
Elims
vs <- case Maybe (TCMT IO [Arg Term])
check of
Just TCMT IO [Arg Term]
ck -> do
(Arg Term -> Elim) -> [Arg Term] -> Elims
forall a b. (a -> b) -> [a] -> [b]
map Arg Term -> Elim
forall a. Arg a -> Elim' a
Apply ([Arg Term] -> Elims) -> TCMT IO [Arg Term] -> TCMT IO Elims
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TCMT IO [Arg Term]
ck
Maybe (TCMT IO [Arg Term])
Nothing -> do
Elims -> TCMT IO Elims
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Elims
vs
Term
v <- Term -> TCM Term
forall (m :: * -> *). PureTCM m => Term -> m Term
unfoldInlined (Term -> TCM Term) -> TCM Term -> TCM Term
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (Elims -> Term) -> ArgsCheckState CheckedTarget -> TCM Term
forall a. (Elims -> Term) -> ArgsCheckState a -> TCM Term
checkHeadConstraints Elims -> Term
f (ArgsCheckState CheckedTarget
st { acElims = vs })
Comparison -> CheckedTarget -> Term -> Type -> Type -> TCM Term
coerce' Comparison
cmp CheckedTarget
checkedTarget Term
v Type
t1 Type
t
turnOffExpandLastIfExistingMeta :: A.Expr -> TCM a -> TCM a
turnOffExpandLastIfExistingMeta :: forall a. Expr -> TCM a -> TCM a
turnOffExpandLastIfExistingMeta Expr
hd
| Bool
isExistingMeta = TCM a -> TCM a
forall a. TCM a -> TCM a
reallyDontExpandLast
| Bool
otherwise = TCM a -> TCM a
forall a. a -> a
id
where
isExistingMeta :: Bool
isExistingMeta = Maybe MetaId -> Bool
forall a. Maybe a -> Bool
isJust (Maybe MetaId -> Bool) -> Maybe MetaId -> Bool
forall a b. (a -> b) -> a -> b
$ MetaInfo -> Maybe MetaId
A.metaNumber (MetaInfo -> Maybe MetaId) -> Maybe MetaInfo -> Maybe MetaId
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Expr -> Maybe MetaInfo
metaInfo Expr
hd
metaInfo :: Expr -> Maybe MetaInfo
metaInfo (A.QuestionMark MetaInfo
i InteractionId
_) = MetaInfo -> Maybe MetaInfo
forall a. a -> Maybe a
Just MetaInfo
i
metaInfo (A.Underscore MetaInfo
i) = MetaInfo -> Maybe MetaInfo
forall a. a -> Maybe a
Just MetaInfo
i
metaInfo (A.ScopedExpr ScopeInfo
_ Expr
e) = Expr -> Maybe MetaInfo
metaInfo Expr
e
metaInfo Expr
_ = Maybe MetaInfo
forall a. Maybe a
Nothing
traceCallE :: Call -> ExceptT e TCM r -> ExceptT e TCM r
traceCallE :: forall e r. Call -> ExceptT e (TCMT IO) r -> ExceptT e (TCMT IO) r
traceCallE Call
call ExceptT e (TCMT IO) r
m = do
Either e r
z <- TCM (Either e r) -> ExceptT e (TCMT IO) (Either e r)
forall (m :: * -> *) a. Monad m => m a -> ExceptT e m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM (Either e r) -> ExceptT e (TCMT IO) (Either e r))
-> TCM (Either e r) -> ExceptT e (TCMT IO) (Either e r)
forall a b. (a -> b) -> a -> b
$ Call -> TCM (Either e r) -> TCM (Either e r)
forall a. Call -> TCMT IO a -> TCMT IO a
forall (m :: * -> *) a. MonadTrace m => Call -> m a -> m a
traceCall Call
call (TCM (Either e r) -> TCM (Either e r))
-> TCM (Either e r) -> TCM (Either e r)
forall a b. (a -> b) -> a -> b
$ ExceptT e (TCMT IO) r -> TCM (Either e r)
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT ExceptT e (TCMT IO) r
m
case Either e r
z of
Right r
e -> r -> ExceptT e (TCMT IO) r
forall a. a -> ExceptT e (TCMT IO) a
forall (m :: * -> *) a. Monad m => a -> m a
return r
e
Left e
err -> e -> ExceptT e (TCMT IO) r
forall a. e -> ExceptT e (TCMT IO) a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError e
err
coerce' :: Comparison -> CheckedTarget -> Term -> Type -> Type -> TCM Term
coerce' :: Comparison -> CheckedTarget -> Term -> Type -> Type -> TCM Term
coerce' Comparison
cmp CheckedTarget
NotCheckedTarget Term
v Type
inferred Type
expected = Comparison -> Term -> Type -> Type -> TCM Term
forall (m :: * -> *).
(MonadConversion m, MonadTCM m) =>
Comparison -> Term -> Type -> Type -> m Term
coerce Comparison
cmp Term
v Type
inferred Type
expected
coerce' Comparison
cmp (CheckedTarget Maybe ProblemId
Nothing) Term
v Type
_ Type
_ = Term -> TCM Term
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Term
v
coerce' Comparison
cmp (CheckedTarget (Just ProblemId
pid)) Term
v Type
_ Type
expected = Type -> Term -> ProblemId -> TCM Term
forall (m :: * -> *).
(MonadMetaSolver m, MonadFresh Int m) =>
Type -> Term -> ProblemId -> m Term
blockTermOnProblem Type
expected Term
v ProblemId
pid
checkArgumentsE :: Comparison -> ExpandHidden -> Range -> [NamedArg A.Expr] -> Type -> Maybe Type ->
ExceptT (ArgsCheckState [NamedArg A.Expr]) TCM (ArgsCheckState CheckedTarget)
checkArgumentsE :: Comparison
-> ExpandHidden
-> Range
-> [NamedArg Expr]
-> Type
-> Maybe Type
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
checkArgumentsE Comparison
sComp ExpandHidden
sExpand Range
sRange [NamedArg Expr]
sArgs Type
sFun Maybe Type
sApp = do
Type -> PathView
sPathView <- ExceptT
(ArgsCheckState [NamedArg Expr]) (TCMT IO) (Type -> PathView)
forall (m :: * -> *). HasBuiltins m => m (Type -> PathView)
pathView'
CheckArgumentsE'State
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
checkArgumentsE'
S{ sChecked :: CheckedTarget
sChecked = CheckedTarget
NotCheckedTarget
, sArgs :: [(NamedArg Expr, Bool)]
sArgs = [NamedArg Expr] -> [Bool] -> [(NamedArg Expr, Bool)]
forall a b. [a] -> [b] -> [(a, b)]
zip [NamedArg Expr]
sArgs ([Bool] -> [(NamedArg Expr, Bool)])
-> [Bool] -> [(NamedArg Expr, Bool)]
forall a b. (a -> b) -> a -> b
$
(NamedArg Expr -> Bool) -> [NamedArg Expr] -> [Bool]
forall a. (a -> Bool) -> [a] -> [Bool]
List.suffixesSatisfying NamedArg Expr -> Bool
forall a. LensHiding a => a -> Bool
visible [NamedArg Expr]
sArgs
, sArgsLen :: Int
sArgsLen = [NamedArg Expr] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [NamedArg Expr]
sArgs
, sSizeLtChecked :: Bool
sSizeLtChecked = Bool
False
, sSkipCheck :: SkipCheck
sSkipCheck = SkipCheck
DontSkip
, Maybe Type
Range
Type
Comparison
ExpandHidden
Type -> PathView
sComp :: Comparison
sExpand :: ExpandHidden
sRange :: Range
sFun :: Type
sApp :: Maybe Type
sPathView :: Type -> PathView
sComp :: Comparison
sExpand :: ExpandHidden
sRange :: Range
sFun :: Type
sApp :: Maybe Type
sPathView :: Type -> PathView
..
}
data CheckArgumentsE'State = S
{ CheckArgumentsE'State -> CheckedTarget
sChecked :: CheckedTarget
, CheckArgumentsE'State -> Comparison
sComp :: Comparison
, CheckArgumentsE'State -> ExpandHidden
sExpand :: ExpandHidden
, CheckArgumentsE'State -> Range
sRange :: Range
, CheckArgumentsE'State -> [(NamedArg Expr, Bool)]
sArgs :: [(NamedArg A.Expr, Bool)]
, CheckArgumentsE'State -> Int
sArgsLen :: !Nat
, CheckArgumentsE'State -> Type
sFun :: Type
, CheckArgumentsE'State -> Maybe Type
sApp :: Maybe Type
, CheckArgumentsE'State -> Bool
sSizeLtChecked :: !Bool
, CheckArgumentsE'State -> SkipCheck
sSkipCheck :: !SkipCheck
, CheckArgumentsE'State -> Type -> PathView
sPathView :: Type -> PathView
}
data SkipCheck
= Skip
| SkipNext !Nat
| DontSkip
checkArgumentsE'
:: CheckArgumentsE'State
-> ExceptT (ArgsCheckState [NamedArg A.Expr]) TCM (ArgsCheckState CheckedTarget)
checkArgumentsE' :: CheckArgumentsE'State
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
checkArgumentsE' S{ sArgs :: CheckArgumentsE'State -> [(NamedArg Expr, Bool)]
sArgs = [], Bool
Int
Maybe Type
Range
Type
Comparison
ExpandHidden
CheckedTarget
SkipCheck
Type -> PathView
sChecked :: CheckArgumentsE'State -> CheckedTarget
sArgsLen :: CheckArgumentsE'State -> Int
sSizeLtChecked :: CheckArgumentsE'State -> Bool
sSkipCheck :: CheckArgumentsE'State -> SkipCheck
sComp :: CheckArgumentsE'State -> Comparison
sExpand :: CheckArgumentsE'State -> ExpandHidden
sRange :: CheckArgumentsE'State -> Range
sFun :: CheckArgumentsE'State -> Type
sApp :: CheckArgumentsE'State -> Maybe Type
sPathView :: CheckArgumentsE'State -> Type -> PathView
sChecked :: CheckedTarget
sComp :: Comparison
sExpand :: ExpandHidden
sRange :: Range
sArgsLen :: Int
sFun :: Type
sApp :: Maybe Type
sSizeLtChecked :: Bool
sSkipCheck :: SkipCheck
sPathView :: Type -> PathView
.. }
| ExpandHidden -> Bool
isDontExpandLast ExpandHidden
sExpand =
ArgsCheckState CheckedTarget
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall a. a -> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) a
forall (m :: * -> *) a. Monad m => a -> m a
return (ArgsCheckState CheckedTarget
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget))
-> ArgsCheckState CheckedTarget
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall a b. (a -> b) -> a -> b
$ ACState
{ acRanges :: MaybeRanges
acRanges = []
, acElims :: Elims
acElims = []
, acConstraints :: [Maybe (Abs Constraint)]
acConstraints = []
, acType :: Type
acType = Type
sFun
, acData :: CheckedTarget
acData = CheckedTarget
sChecked
}
checkArgumentsE' S{ sArgs :: CheckArgumentsE'State -> [(NamedArg Expr, Bool)]
sArgs = [], Bool
Int
Maybe Type
Range
Type
Comparison
ExpandHidden
CheckedTarget
SkipCheck
Type -> PathView
sChecked :: CheckArgumentsE'State -> CheckedTarget
sArgsLen :: CheckArgumentsE'State -> Int
sSizeLtChecked :: CheckArgumentsE'State -> Bool
sSkipCheck :: CheckArgumentsE'State -> SkipCheck
sComp :: CheckArgumentsE'State -> Comparison
sExpand :: CheckArgumentsE'State -> ExpandHidden
sRange :: CheckArgumentsE'State -> Range
sFun :: CheckArgumentsE'State -> Type
sApp :: CheckArgumentsE'State -> Maybe Type
sPathView :: CheckArgumentsE'State -> Type -> PathView
sChecked :: CheckedTarget
sComp :: Comparison
sExpand :: ExpandHidden
sRange :: Range
sArgsLen :: Int
sFun :: Type
sApp :: Maybe Type
sSizeLtChecked :: Bool
sSkipCheck :: SkipCheck
sPathView :: Type -> PathView
.. } =
Call
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall e r. Call -> ExceptT e (TCMT IO) r -> ExceptT e (TCMT IO) r
traceCallE (Range -> [NamedArg Expr] -> Type -> Maybe Type -> Call
CheckArguments Range
sRange [] Type
sFun Maybe Type
sApp) (ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget))
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall a b. (a -> b) -> a -> b
$ TCM (ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (ArgsCheckState [NamedArg Expr]) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM (ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget))
-> TCM (ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall a b. (a -> b) -> a -> b
$ do
Maybe Term
sApp <- (Type -> TCM Term) -> Maybe Type -> TCMT IO (Maybe Term)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse (Type -> Term
forall t a. Type'' t a -> a
unEl (Type -> Term) -> (Type -> TCMT IO Type) -> Type -> TCM Term
forall (m :: * -> *) b c a.
Functor m =>
(b -> c) -> (a -> m b) -> a -> m c
<.> Type -> TCMT IO Type
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce) Maybe Type
sApp
([Arg Term]
us, Type
t) <- Int -> (Hiding -> Bool) -> Type -> TCMT IO ([Arg Term], Type)
forall (m :: * -> *).
(PureTCM m, MonadMetaSolver m, MonadTCM m) =>
Int -> (Hiding -> Bool) -> Type -> m ([Arg Term], Type)
implicitArgs (-Int
1) (Maybe Term -> Hiding -> Bool
expand Maybe Term
sApp) Type
sFun
ArgsCheckState CheckedTarget -> TCM (ArgsCheckState CheckedTarget)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ArgsCheckState CheckedTarget
-> TCM (ArgsCheckState CheckedTarget))
-> ArgsCheckState CheckedTarget
-> TCM (ArgsCheckState CheckedTarget)
forall a b. (a -> b) -> a -> b
$ ACState
{ acRanges :: MaybeRanges
acRanges = Int -> Maybe Range -> MaybeRanges
forall a. Int -> a -> [a]
replicate ([Arg Term] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Arg Term]
us) Maybe Range
forall a. Maybe a
Nothing
, acElims :: Elims
acElims = (Arg Term -> Elim) -> [Arg Term] -> Elims
forall a b. (a -> b) -> [a] -> [b]
map Arg Term -> Elim
forall a. Arg a -> Elim' a
Apply [Arg Term]
us
, acConstraints :: [Maybe (Abs Constraint)]
acConstraints = Int -> Maybe (Abs Constraint) -> [Maybe (Abs Constraint)]
forall a. Int -> a -> [a]
replicate ([Arg Term] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Arg Term]
us) Maybe (Abs Constraint)
forall a. Maybe a
Nothing
, acType :: Type
acType = Type
t
, acData :: CheckedTarget
acData = CheckedTarget
sChecked
}
where
expand :: Maybe Term -> Hiding -> Bool
expand (Just (Pi Dom Type
dom Abs Type
_)) Hiding
Hidden = Bool -> Bool
not (Dom Type -> Bool
forall a. LensHiding a => a -> Bool
hidden Dom Type
dom)
expand Maybe Term
_ Hiding
Hidden = Bool
True
expand (Just (Pi Dom Type
dom Abs Type
_)) Instance{} = Bool -> Bool
not (Dom Type -> Bool
forall a. LensHiding a => a -> Bool
isInstance Dom Type
dom)
expand Maybe Term
_ Instance{} = Bool
True
expand Maybe Term
_ Hiding
NotHidden = Bool
False
checkArgumentsE'
s :: CheckArgumentsE'State
s@S{ sArgs :: CheckArgumentsE'State -> [(NamedArg Expr, Bool)]
sArgs = sArgs :: [(NamedArg Expr, Bool)]
sArgs@((arg :: NamedArg Expr
arg@(Arg ArgInfo
info Named_ Expr
e), Bool
sArgsVisible) : [(NamedArg Expr, Bool)]
args), Bool
Int
Maybe Type
Range
Type
Comparison
ExpandHidden
CheckedTarget
SkipCheck
Type -> PathView
sChecked :: CheckArgumentsE'State -> CheckedTarget
sArgsLen :: CheckArgumentsE'State -> Int
sSizeLtChecked :: CheckArgumentsE'State -> Bool
sSkipCheck :: CheckArgumentsE'State -> SkipCheck
sComp :: CheckArgumentsE'State -> Comparison
sExpand :: CheckArgumentsE'State -> ExpandHidden
sRange :: CheckArgumentsE'State -> Range
sFun :: CheckArgumentsE'State -> Type
sApp :: CheckArgumentsE'State -> Maybe Type
sPathView :: CheckArgumentsE'State -> Type -> PathView
sChecked :: CheckedTarget
sComp :: Comparison
sExpand :: ExpandHidden
sRange :: Range
sArgsLen :: Int
sFun :: Type
sApp :: Maybe Type
sSizeLtChecked :: Bool
sSkipCheck :: SkipCheck
sPathView :: Type -> PathView
.. } =
Call
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall e r. Call -> ExceptT e (TCMT IO) r -> ExceptT e (TCMT IO) r
traceCallE (Range -> [NamedArg Expr] -> Type -> Maybe Type -> Call
CheckArguments Range
sRange (((NamedArg Expr, Bool) -> NamedArg Expr)
-> [(NamedArg Expr, Bool)] -> [NamedArg Expr]
forall a b. (a -> b) -> [a] -> [b]
map (NamedArg Expr, Bool) -> NamedArg Expr
forall a b. (a, b) -> a
fst [(NamedArg Expr, Bool)]
sArgs) Type
sFun Maybe Type
sApp) (ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget))
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall a b. (a -> b) -> a -> b
$ do
TCMT IO () -> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) ()
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (ArgsCheckState [NamedArg Expr]) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO ()
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) ())
-> TCMT IO ()
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) ()
forall a b. (a -> b) -> a -> b
$ [Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.args" Int
30 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
sep
[ TCMT IO Doc
"checkArgumentsE"
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"e =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Named_ Expr -> TCMT IO Doc
forall a (m :: * -> *).
(ToConcrete a, Pretty (ConOfAbs a), MonadAbsToCon m) =>
a -> m Doc
prettyA Named_ Expr
e
, TCMT IO Doc
"sFun =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
sFun
, TCMT IO Doc
"sApp =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc -> (Type -> TCMT IO Doc) -> Maybe Type -> TCMT IO Doc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe TCMT IO Doc
"Nothing" Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Maybe Type
sApp
]
]
let hx :: Hiding
hx = ArgInfo -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding ArgInfo
info
mx :: Maybe ArgName
mx :: Maybe [Char]
mx = Named_ Expr -> Maybe [Char]
forall a. (LensNamed a, NameOf a ~ NamedName) => a -> Maybe [Char]
bareNameOf Named_ Expr
e
expand :: Hiding -> [Char] -> Bool
expand Hiding
NotHidden [Char]
y = Bool
False
expand Hiding
hy [Char]
y = Bool -> Bool
not (Hiding -> Hiding -> Bool
forall a b. (LensHiding a, LensHiding b) => a -> b -> Bool
sameHiding Hiding
hy Hiding
hx) Bool -> Bool -> Bool
|| Bool -> ([Char] -> Bool) -> Maybe [Char] -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False ([Char]
y [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
/=) Maybe [Char]
mx
[Char]
-> Int
-> TCMT IO Doc
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.args" Int
30 (TCMT IO Doc
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) ())
-> TCMT IO Doc
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"calling implicitNamedArgs"
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"sFun = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
sFun
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"hx = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text (Hiding -> [Char]
forall a. Show a => a -> [Char]
show Hiding
hx)
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"mx = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
-> ([Char] -> TCMT IO Doc) -> Maybe [Char] -> TCMT IO Doc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe TCMT IO Doc
"nothing" [Char] -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => [Char] -> m Doc
prettyTCM Maybe [Char]
mx
]
(NamedArgs
nargs, Type
sFun) <- TCM (NamedArgs, Type)
-> ExceptT
(ArgsCheckState [NamedArg Expr]) (TCMT IO) (NamedArgs, Type)
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (ArgsCheckState [NamedArg Expr]) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM (NamedArgs, Type)
-> ExceptT
(ArgsCheckState [NamedArg Expr]) (TCMT IO) (NamedArgs, Type))
-> TCM (NamedArgs, Type)
-> ExceptT
(ArgsCheckState [NamedArg Expr]) (TCMT IO) (NamedArgs, Type)
forall a b. (a -> b) -> a -> b
$ Int -> (Hiding -> [Char] -> Bool) -> Type -> TCM (NamedArgs, Type)
forall (m :: * -> *).
(PureTCM m, MonadMetaSolver m, MonadTCM m) =>
Int -> (Hiding -> [Char] -> Bool) -> Type -> m (NamedArgs, Type)
implicitNamedArgs (-Int
1) Hiding -> [Char] -> Bool
expand Type
sFun
let ([Maybe NamedName]
mxs, Elims
us) = [(Maybe NamedName, Elim)] -> ([Maybe NamedName], Elims)
forall a b. [(a, b)] -> ([a], [b])
unzip ([(Maybe NamedName, Elim)] -> ([Maybe NamedName], Elims))
-> [(Maybe NamedName, Elim)] -> ([Maybe NamedName], Elims)
forall a b. (a -> b) -> a -> b
$ (Arg (Named NamedName Term) -> (Maybe NamedName, Elim))
-> NamedArgs -> [(Maybe NamedName, Elim)]
forall a b. (a -> b) -> [a] -> [b]
map (\ (Arg ArgInfo
ai (Named Maybe NamedName
mx Term
u)) -> (Maybe NamedName
mx, Arg Term -> Elim
forall a. Arg a -> Elim' a
Apply (Arg Term -> Elim) -> Arg Term -> Elim
forall a b. (a -> b) -> a -> b
$ ArgInfo -> Term -> Arg Term
forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
ai Term
u)) NamedArgs
nargs
xs :: [NamedName]
xs = [Maybe NamedName] -> [NamedName]
forall a. [Maybe a] -> [a]
catMaybes [Maybe NamedName]
mxs
Type
sFun <- TCMT IO Type
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) Type
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (ArgsCheckState [NamedArg Expr]) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO Type
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) Type)
-> TCMT IO Type
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) Type
forall a b. (a -> b) -> a -> b
$ Type -> TCMT IO Type
forcePiUsingInjectivity Type
sFun
Type
-> (Blocker
-> Type
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget))
-> (NotBlocked
-> Type
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget))
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall t (m :: * -> *) a.
(Reduce t, IsMeta t, MonadReduce m) =>
t -> (Blocker -> t -> m a) -> (NotBlocked -> t -> m a) -> m a
ifBlocked Type
sFun
(\Blocker
_ Type
sFun -> ArgsCheckState [NamedArg Expr]
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall a.
ArgsCheckState [NamedArg Expr]
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (ArgsCheckState [NamedArg Expr]
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget))
-> ArgsCheckState [NamedArg Expr]
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall a b. (a -> b) -> a -> b
$ ACState
{ acRanges :: MaybeRanges
acRanges = Int -> Maybe Range -> MaybeRanges
forall a. Int -> a -> [a]
replicate (Elims -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length Elims
us) Maybe Range
forall a. Maybe a
Nothing
, acElims :: Elims
acElims = Elims
us
, acConstraints :: [Maybe (Abs Constraint)]
acConstraints = Int -> Maybe (Abs Constraint) -> [Maybe (Abs Constraint)]
forall a. Int -> a -> [a]
replicate (Elims -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length Elims
us) Maybe (Abs Constraint)
forall a. Maybe a
Nothing
, acType :: Type
acType = Type
sFun
, acData :: [NamedArg Expr]
acData = ((NamedArg Expr, Bool) -> NamedArg Expr)
-> [(NamedArg Expr, Bool)] -> [NamedArg Expr]
forall a b. (a -> b) -> [a] -> [b]
map (NamedArg Expr, Bool) -> NamedArg Expr
forall a b. (a, b) -> a
fst [(NamedArg Expr, Bool)]
sArgs
}) ((NotBlocked
-> Type
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget))
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget))
-> (NotBlocked
-> Type
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget))
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall a b. (a -> b) -> a -> b
$ \NotBlocked
_ Type
sFun -> do
let shouldBePi :: ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
shouldBePi
| ArgInfo -> Bool
forall a. LensHiding a => a -> Bool
visible ArgInfo
info = TCM (ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (ArgsCheckState [NamedArg Expr]) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM (ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget))
-> TCM (ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall a b. (a -> b) -> a -> b
$ TypeError -> TCM (ArgsCheckState CheckedTarget)
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCM (ArgsCheckState CheckedTarget))
-> TypeError -> TCM (ArgsCheckState CheckedTarget)
forall a b. (a -> b) -> a -> b
$ Type -> TypeError
ShouldBePi Type
sFun
| [NamedName] -> Bool
forall a. Null a => a -> Bool
null [NamedName]
xs = TCM (ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (ArgsCheckState [NamedArg Expr]) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM (ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget))
-> TCM (ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall a b. (a -> b) -> a -> b
$ TypeError -> TCM (ArgsCheckState CheckedTarget)
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCM (ArgsCheckState CheckedTarget))
-> TypeError -> TCM (ArgsCheckState CheckedTarget)
forall a b. (a -> b) -> a -> b
$ Type -> TypeError
ShouldBePi Type
sFun
| Bool
otherwise = TCM (ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (ArgsCheckState [NamedArg Expr]) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM (ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget))
-> TCM (ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall a b. (a -> b) -> a -> b
$ TypeError -> TCM (ArgsCheckState CheckedTarget)
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCM (ArgsCheckState CheckedTarget))
-> TypeError -> TCM (ArgsCheckState CheckedTarget)
forall a b. (a -> b) -> a -> b
$ NamedArg Expr -> [NamedName] -> TypeError
WrongNamedArgument NamedArg Expr
arg [NamedName]
xs
let wrongPi :: ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
wrongPi
| [NamedName] -> Bool
forall a. Null a => a -> Bool
null [NamedName]
xs = TCM (ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (ArgsCheckState [NamedArg Expr]) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM (ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget))
-> TCM (ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall a b. (a -> b) -> a -> b
$ TypeError -> TCM (ArgsCheckState CheckedTarget)
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCM (ArgsCheckState CheckedTarget))
-> TypeError -> TCM (ArgsCheckState CheckedTarget)
forall a b. (a -> b) -> a -> b
$
Type -> TypeError
WrongHidingInApplication Type
sFun
| Bool
otherwise = TCM (ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (ArgsCheckState [NamedArg Expr]) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM (ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget))
-> TCM (ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall a b. (a -> b) -> a -> b
$ TypeError -> TCM (ArgsCheckState CheckedTarget)
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCM (ArgsCheckState CheckedTarget))
-> TypeError -> TCM (ArgsCheckState CheckedTarget)
forall a b. (a -> b) -> a -> b
$ NamedArg Expr -> [NamedName] -> TypeError
WrongNamedArgument NamedArg Expr
arg [NamedName]
xs
let (Bool
skip, SkipCheck
next) = case SkipCheck
sSkipCheck of
SkipCheck
Skip -> (Bool
True, SkipCheck
Skip)
SkipCheck
DontSkip -> (Bool
False, SkipCheck
DontSkip)
SkipNext Int
n -> case Int -> Int -> Ordering
forall a. Ord a => a -> a -> Ordering
compare Int
n Int
1 of
Ordering
LT -> (Bool
False, SkipCheck
DontSkip)
Ordering
EQ -> (Bool
True, SkipCheck
DontSkip)
Ordering
GT -> (Bool
True, Int -> SkipCheck
SkipNext (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1))
CheckArgumentsE'State
s <- CheckArgumentsE'State
-> ExceptT
(ArgsCheckState [NamedArg Expr]) (TCMT IO) CheckArgumentsE'State
forall a. a -> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) a
forall (m :: * -> *) a. Monad m => a -> m a
return CheckArgumentsE'State
s
{ sRange = fuseRange sRange e
, sArgs = args
, sArgsLen = sArgsLen - 1
, sFun = sFun
, sSkipCheck = next
}
CheckArgumentsE'State
s <- TCM CheckArgumentsE'State
-> ExceptT
(ArgsCheckState [NamedArg Expr]) (TCMT IO) CheckArgumentsE'State
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (ArgsCheckState [NamedArg Expr]) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM CheckArgumentsE'State
-> ExceptT
(ArgsCheckState [NamedArg Expr]) (TCMT IO) CheckArgumentsE'State)
-> TCM CheckArgumentsE'State
-> ExceptT
(ArgsCheckState [NamedArg Expr]) (TCMT IO) CheckArgumentsE'State
forall a b. (a -> b) -> a -> b
$
case (CheckedTarget
sChecked, Bool
skip, Maybe Type
sApp) of
(CheckedTarget
NotCheckedTarget, Bool
False, Just Type
sApp) | Bool
sArgsVisible -> do
TelV Tele (Dom Type)
tel Type
tgt <- Int -> (Dom Type -> Bool) -> Type -> TCMT IO (TelV Type)
forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Int -> (Dom Type -> Bool) -> Type -> m (TelV Type)
telViewUpTo' Int
sArgsLen Dom Type -> Bool
forall a. LensHiding a => a -> Bool
visible Type
sFun
let visiblePis :: Int
visiblePis = Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
tel
freeInTgt :: IntSet
freeInTgt =
(IntSet, IntSet) -> IntSet
forall a b. (a, b) -> a
fst ((IntSet, IntSet) -> IntSet) -> (IntSet, IntSet) -> IntSet
forall a b. (a -> b) -> a -> b
$ Int -> IntSet -> (IntSet, IntSet)
IntSet.split Int
visiblePis (IntSet -> (IntSet, IntSet)) -> IntSet -> (IntSet, IntSet)
forall a b. (a -> b) -> a -> b
$ Type -> IntSet
forall a c t. (IsVarSet a c, Singleton Int c, Free t) => t -> c
freeVars Type
tgt
IsRigid
rigid <- CheckArgumentsE'State -> Type -> TCM IsRigid
isRigid CheckArgumentsE'State
s Type
tgt
case IsRigid
rigid of
IsNotRigid IsPermanent
reason ->
let skip :: Int -> CheckArgumentsE'State
skip Int
k = CheckArgumentsE'State
s{ sSkipCheck =
SkipNext $ visiblePis - 1 - k
}
dontSkip :: CheckArgumentsE'State
dontSkip = CheckArgumentsE'State
s
in CheckArgumentsE'State -> TCM CheckArgumentsE'State
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (CheckArgumentsE'State -> TCM CheckArgumentsE'State)
-> CheckArgumentsE'State -> TCM CheckArgumentsE'State
forall a b. (a -> b) -> a -> b
$ case IsPermanent
reason of
IsPermanent
Permanent -> Int -> CheckArgumentsE'State
skip Int
0
IsPermanent
Unspecified -> CheckArgumentsE'State
dontSkip
AVar Int
x ->
if Int
x Int -> IntSet -> Bool
`IntSet.member` IntSet
freeInTgt
then Int -> CheckArgumentsE'State
skip Int
x
else Int -> CheckArgumentsE'State
skip Int
0
IsRigid
IsRigid -> do
let dep :: Bool
dep = Bool -> Bool
not (IntSet -> Bool
IntSet.null IntSet
freeInTgt)
if Bool
dep then CheckArgumentsE'State -> TCM CheckArgumentsE'State
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return CheckArgumentsE'State
s else do
(Bool
isSizeLt, Type
sApp, CheckArgumentsE'State
s) <-
if Bool
sSizeLtChecked
then (Bool, Type, CheckArgumentsE'State)
-> TCMT IO (Bool, Type, CheckArgumentsE'State)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool
False, Type
sApp, CheckArgumentsE'State
s)
else do
Type
sApp <- Type -> TCMT IO Type
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce Type
sApp
Bool
isSizeLt <- Type -> TCMT IO (Maybe BoundedSize)
forall a (m :: * -> *).
(IsSizeType a, HasOptions m, HasBuiltins m) =>
a -> m (Maybe BoundedSize)
forall (m :: * -> *).
(HasOptions m, HasBuiltins m) =>
Type -> m (Maybe BoundedSize)
isSizeType Type
sApp TCMT IO (Maybe BoundedSize)
-> (Maybe BoundedSize -> Bool) -> TCMT IO Bool
forall (m :: * -> *) a b. Functor m => m a -> (a -> b) -> m b
<&> \case
Just (BoundedLt Term
_) -> Bool
True
Maybe BoundedSize
_ -> Bool
False
(Bool, Type, CheckArgumentsE'State)
-> TCMT IO (Bool, Type, CheckArgumentsE'State)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ( Bool
isSizeLt
, Type
sApp
, CheckArgumentsE'State
s{ sApp = Just sApp
, sSizeLtChecked = True
, sSkipCheck =
if isSizeLt then Skip else DontSkip
}
)
if Bool
isSizeLt then CheckArgumentsE'State -> TCM CheckArgumentsE'State
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return CheckArgumentsE'State
s else do
let tgt1 :: Type
tgt1 = Substitution' (SubstArg Type) -> Type -> Type
forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst
(Impossible -> Int -> Substitution' Term
forall a. Impossible -> Int -> Substitution' a
strengthenS Impossible
HasCallStack => Impossible
impossible Int
visiblePis)
Type
tgt
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.args.target" Int
30 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"Checking target types first"
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"inferred =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
tgt1
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"expected =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
sApp ]
CheckedTarget
chk <-
Call -> TCMT IO CheckedTarget -> TCMT IO CheckedTarget
forall a. Call -> TCMT IO a -> TCMT IO a
forall (m :: * -> *) a. MonadTrace m => Call -> m a -> m a
traceCall
(Range -> Type -> Type -> Call
CheckTargetType
(Range -> [(NamedArg Expr, Bool)] -> Range
forall u t. (HasRange u, HasRange t) => u -> t -> Range
fuseRange Range
sRange [(NamedArg Expr, Bool)]
sArgs) Type
tgt1 Type
sApp) (TCMT IO CheckedTarget -> TCMT IO CheckedTarget)
-> TCMT IO CheckedTarget -> TCMT IO CheckedTarget
forall a b. (a -> b) -> a -> b
$
Maybe ProblemId -> CheckedTarget
CheckedTarget (Maybe ProblemId -> CheckedTarget)
-> TCMT IO (Maybe ProblemId) -> TCMT IO CheckedTarget
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
TCMT IO ()
-> TCMT IO (Maybe ProblemId)
-> (ProblemId -> TCMT IO (Maybe ProblemId))
-> TCMT IO (Maybe ProblemId)
forall a. TCMT IO () -> TCM a -> (ProblemId -> TCM a) -> TCM a
ifNoConstraints_ (Comparison -> Type -> Type -> TCMT IO ()
forall (m :: * -> *).
MonadConversion m =>
Comparison -> Type -> Type -> m ()
compareType Comparison
sComp Type
tgt1 Type
sApp)
(Maybe ProblemId -> TCMT IO (Maybe ProblemId)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe ProblemId
forall a. Maybe a
Nothing) (Maybe ProblemId -> TCMT IO (Maybe ProblemId)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe ProblemId -> TCMT IO (Maybe ProblemId))
-> (ProblemId -> Maybe ProblemId)
-> ProblemId
-> TCMT IO (Maybe ProblemId)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProblemId -> Maybe ProblemId
forall a. a -> Maybe a
Just)
CheckArgumentsE'State -> TCM CheckArgumentsE'State
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return CheckArgumentsE'State
s{ sChecked = chk }
(CheckedTarget, Bool, Maybe Type)
_ -> CheckArgumentsE'State -> TCM CheckArgumentsE'State
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return CheckArgumentsE'State
s
case Type -> Term
forall t a. Type'' t a -> a
unEl Type
sFun of
Pi (Dom{domInfo :: forall t e. Dom' t e -> ArgInfo
domInfo = ArgInfo
info', domName :: forall t e. Dom' t e -> Maybe NamedName
domName = Maybe NamedName
dname, unDom :: forall t e. Dom' t e -> e
unDom = Type
a}) Abs Type
b
| let name :: [Char]
name = [Char] -> Maybe NamedName -> [Char]
forall a.
(LensNamed a, NameOf a ~ NamedName) =>
[Char] -> a -> [Char]
bareNameWithDefault [Char]
"_" Maybe NamedName
dname,
ArgInfo -> ArgInfo -> Bool
forall a b. (LensHiding a, LensHiding b) => a -> b -> Bool
sameHiding ArgInfo
info ArgInfo
info'
Bool -> Bool -> Bool
&& (ArgInfo -> Bool
forall a. LensHiding a => a -> Bool
visible ArgInfo
info Bool -> Bool -> Bool
|| Bool -> ([Char] -> Bool) -> Maybe [Char] -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
True ([Char]
name [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
==) Maybe [Char]
mx) -> do
Term
u <- TCM Term -> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) Term
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (ArgsCheckState [NamedArg Expr]) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM Term
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) Term)
-> TCM Term
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) Term
forall a b. (a -> b) -> a -> b
$ ArgInfo -> TCM Term -> TCM Term
forall (tcm :: * -> *) m a.
(MonadTCEnv tcm, LensModality m) =>
m -> tcm a -> tcm a
applyModalityToContext ArgInfo
info' (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ do
let e' :: Named_ Expr
e' = Named_ Expr
e { nameOf = (nameOf e) <|> dname }
NamedArg Expr -> Type -> TCM Term
checkNamedArg (ArgInfo -> Named_ Expr -> NamedArg Expr
forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
info' Named_ Expr
e') Type
a
let
c :: Maybe (Abs Constraint)
c = case ArgInfo -> Lock
forall a. LensLock a => a -> Lock
getLock ArgInfo
info' of
IsLock{} -> Abs Constraint -> Maybe (Abs Constraint)
forall a. a -> Maybe a
Just (Abs Constraint -> Maybe (Abs Constraint))
-> Abs Constraint -> Maybe (Abs Constraint)
forall a b. (a -> b) -> a -> b
$ [Char] -> Constraint -> Abs Constraint
forall a. [Char] -> a -> Abs a
Abs [Char]
"t" (Constraint -> Abs Constraint) -> Constraint -> Abs Constraint
forall a b. (a -> b) -> a -> b
$
Term -> Type -> Arg Term -> Type -> Constraint
CheckLockedVars (Int -> Elims -> Term
Var Int
0 []) (Int -> Type -> Type
forall a. Subst a => Int -> a -> a
raise Int
1 Type
sFun)
(Int -> Arg Term -> Arg Term
forall a. Subst a => Int -> a -> a
raise Int
1 (Arg Term -> Arg Term) -> Arg Term -> Arg Term
forall a b. (a -> b) -> a -> b
$ ArgInfo -> Term -> Arg Term
forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
info' Term
u) (Int -> Type -> Type
forall a. Subst a => Int -> a -> a
raise Int
1 Type
a)
Lock
_ -> Maybe (Abs Constraint)
forall a. Maybe a
Nothing
TCMT IO () -> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) ()
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (ArgsCheckState [NamedArg Expr]) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO ()
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) ())
-> TCMT IO ()
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) ()
forall a b. (a -> b) -> a -> b
$ [Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.lock" Int
40 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text [Char]
"lock =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text (Lock -> [Char]
forall a. Show a => a -> [Char]
show (Lock -> [Char]) -> Lock -> [Char]
forall a b. (a -> b) -> a -> b
$ ArgInfo -> Lock
forall a. LensLock a => a -> Lock
getLock ArgInfo
info')
TCMT IO () -> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) ()
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (ArgsCheckState [NamedArg Expr]) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO ()
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) ())
-> TCMT IO ()
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) ()
forall a b. (a -> b) -> a -> b
$ [Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.lock" Int
40 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$
Dom Type -> TCMT IO Doc -> TCMT IO Doc
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
forall (m :: * -> *) a. MonadAddContext m => Dom Type -> m a -> m a
addContext (Type -> Dom Type
forall a. a -> Dom a
defaultDom (Type -> Dom Type) -> Type -> Dom Type
forall a b. (a -> b) -> a -> b
$ Type
sFun) (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
-> (Abs Constraint -> TCMT IO Doc)
-> Maybe (Abs Constraint)
-> TCMT IO Doc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ([Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text [Char]
"nothing") (Constraint -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Constraint -> m Doc
prettyTCM (Constraint -> TCMT IO Doc)
-> (Abs Constraint -> Constraint) -> Abs Constraint -> TCMT IO Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Abs Constraint -> Constraint
forall a. Subst a => Abs a -> a
absBody) Maybe (Abs Constraint)
c
Elims
-> Range
-> Elim
-> Maybe (Abs Constraint)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall {a} {m :: * -> *} {a}.
MonadError (ArgsCheckState a) m =>
Elims
-> Range
-> Elim
-> Maybe (Abs Constraint)
-> m (ArgsCheckState a)
-> m (ArgsCheckState a)
addCheckedArgs Elims
us (Named_ Expr -> Range
forall a. HasRange a => a -> Range
getRange Named_ Expr
e) (Arg Term -> Elim
forall a. Arg a -> Elim' a
Apply (Arg Term -> Elim) -> Arg Term -> Elim
forall a b. (a -> b) -> a -> b
$ ArgInfo -> Term -> Arg Term
forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
info' Term
u) Maybe (Abs Constraint)
c (ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget))
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall a b. (a -> b) -> a -> b
$
CheckArgumentsE'State
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
checkArgumentsE' CheckArgumentsE'State
s{ sFun = absApp b u }
| Bool
otherwise -> do
[Char]
-> Int
-> TCMT IO Doc
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"error" Int
10 (TCMT IO Doc
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) ())
-> TCMT IO Doc
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) ()
forall a b. (a -> b) -> a -> b
$ Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char] -> TCMT IO Doc) -> [Char] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char]
"info = " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ ArgInfo -> [Char]
forall a. Show a => a -> [Char]
show ArgInfo
info
, [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char] -> TCMT IO Doc) -> [Char] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char]
"info' = " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ ArgInfo -> [Char]
forall a. Show a => a -> [Char]
show ArgInfo
info'
, [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char] -> TCMT IO Doc) -> [Char] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char]
"absName b = " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Abs Type -> [Char]
forall a. Abs a -> [Char]
absName Abs Type
b
, [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char] -> TCMT IO Doc) -> [Char] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char]
"nameOf e = " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Maybe NamedName -> [Char]
forall a. Show a => a -> [Char]
show (Named_ Expr -> Maybe NamedName
forall name a. Named name a -> Maybe name
nameOf Named_ Expr
e)
]
ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
wrongPi
Term
_
| ArgInfo -> Bool
forall a. LensHiding a => a -> Bool
visible ArgInfo
info
, PathType Sort
sort QName
_ Arg Term
_ Arg Term
bA Arg Term
x Arg Term
y <- Type -> PathView
sPathView Type
sFun -> do
TCMT IO () -> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) ()
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (ArgsCheckState [NamedArg Expr]) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO ()
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) ())
-> TCMT IO ()
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) ()
forall a b. (a -> b) -> a -> b
$ [Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.args" Int
30 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char] -> TCMT IO Doc) -> [Char] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Arg Term -> [Char]
forall a. Show a => a -> [Char]
show Arg Term
bA
Term
u <- TCM Term -> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) Term
forall (m :: * -> *) a.
Monad m =>
m a -> ExceptT (ArgsCheckState [NamedArg Expr]) m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCM Term
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) Term)
-> TCM Term
-> ExceptT (ArgsCheckState [NamedArg Expr]) (TCMT IO) Term
forall a b. (a -> b) -> a -> b
$ Expr -> Type -> TCM Term
checkExpr (Named_ Expr -> Expr
forall name a. Named name a -> a
namedThing Named_ Expr
e) (Type -> TCM Term) -> TCMT IO Type -> TCM Term
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCMT IO Type
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Type
primIntervalType
Elims
-> Range
-> Elim
-> Maybe (Abs Constraint)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall {a} {m :: * -> *} {a}.
MonadError (ArgsCheckState a) m =>
Elims
-> Range
-> Elim
-> Maybe (Abs Constraint)
-> m (ArgsCheckState a)
-> m (ArgsCheckState a)
addCheckedArgs Elims
us (Named_ Expr -> Range
forall a. HasRange a => a -> Range
getRange Named_ Expr
e) (Term -> Term -> Term -> Elim
forall a. a -> a -> a -> Elim' a
IApply (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
x) (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
y) Term
u) Maybe (Abs Constraint)
forall a. Maybe a
Nothing (ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget))
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
forall a b. (a -> b) -> a -> b
$
CheckArgumentsE'State
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
checkArgumentsE'
CheckArgumentsE'State
s{ sChecked = NotCheckedTarget
, sFun = El sort $ unArg bA `apply` [argN u]
}
Term
_ -> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
shouldBePi
where
addCheckedArgs :: Elims
-> Range
-> Elim
-> Maybe (Abs Constraint)
-> m (ArgsCheckState a)
-> m (ArgsCheckState a)
addCheckedArgs Elims
us Range
r Elim
u Maybe (Abs Constraint)
c m (ArgsCheckState a)
rec = do
st :: ArgsCheckState a
st@ACState{acRanges :: forall a. ArgsCheckState a -> MaybeRanges
acRanges = MaybeRanges
rs, acElims :: forall a. ArgsCheckState a -> Elims
acElims = Elims
vs} <- m (ArgsCheckState a)
rec
let rs' :: MaybeRanges
rs' = Int -> Maybe Range -> MaybeRanges
forall a. Int -> a -> [a]
replicate (Elims -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length Elims
us) Maybe Range
forall a. Maybe a
Nothing MaybeRanges -> MaybeRanges -> MaybeRanges
forall a. [a] -> [a] -> [a]
++ Range -> Maybe Range
forall a. a -> Maybe a
Just Range
r Maybe Range -> MaybeRanges -> MaybeRanges
forall a. a -> [a] -> [a]
: MaybeRanges
rs
cs' :: [Maybe (Abs Constraint)]
cs' = Int -> Maybe (Abs Constraint) -> [Maybe (Abs Constraint)]
forall a. Int -> a -> [a]
replicate (Elims -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length Elims
us) Maybe (Abs Constraint)
forall a. Maybe a
Nothing [Maybe (Abs Constraint)]
-> [Maybe (Abs Constraint)] -> [Maybe (Abs Constraint)]
forall a. [a] -> [a] -> [a]
++ Maybe (Abs Constraint)
c Maybe (Abs Constraint)
-> [Maybe (Abs Constraint)] -> [Maybe (Abs Constraint)]
forall a. a -> [a] -> [a]
: ArgsCheckState a -> [Maybe (Abs Constraint)]
forall a. ArgsCheckState a -> [Maybe (Abs Constraint)]
acConstraints ArgsCheckState a
st
ArgsCheckState a -> m (ArgsCheckState a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (ArgsCheckState a -> m (ArgsCheckState a))
-> ArgsCheckState a -> m (ArgsCheckState a)
forall a b. (a -> b) -> a -> b
$ ArgsCheckState a
st { acRanges = rs', acElims = us ++ u : vs, acConstraints = cs' }
m (ArgsCheckState a)
-> (ArgsCheckState a -> m (ArgsCheckState a))
-> m (ArgsCheckState a)
forall a. m a -> (ArgsCheckState a -> m a) -> m a
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError` \ st :: ArgsCheckState a
st@ACState{acRanges :: forall a. ArgsCheckState a -> MaybeRanges
acRanges = MaybeRanges
rs, acElims :: forall a. ArgsCheckState a -> Elims
acElims = Elims
vs} -> do
let rs' :: MaybeRanges
rs' = Int -> Maybe Range -> MaybeRanges
forall a. Int -> a -> [a]
replicate (Elims -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length Elims
us) Maybe Range
forall a. Maybe a
Nothing MaybeRanges -> MaybeRanges -> MaybeRanges
forall a. [a] -> [a] -> [a]
++ Range -> Maybe Range
forall a. a -> Maybe a
Just Range
r Maybe Range -> MaybeRanges -> MaybeRanges
forall a. a -> [a] -> [a]
: MaybeRanges
rs
cs' :: [Maybe (Abs Constraint)]
cs' = Int -> Maybe (Abs Constraint) -> [Maybe (Abs Constraint)]
forall a. Int -> a -> [a]
replicate (Elims -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length Elims
us) Maybe (Abs Constraint)
forall a. Maybe a
Nothing [Maybe (Abs Constraint)]
-> [Maybe (Abs Constraint)] -> [Maybe (Abs Constraint)]
forall a. [a] -> [a] -> [a]
++ Maybe (Abs Constraint)
c Maybe (Abs Constraint)
-> [Maybe (Abs Constraint)] -> [Maybe (Abs Constraint)]
forall a. a -> [a] -> [a]
: ArgsCheckState a -> [Maybe (Abs Constraint)]
forall a. ArgsCheckState a -> [Maybe (Abs Constraint)]
acConstraints ArgsCheckState a
st
ArgsCheckState a -> m (ArgsCheckState a)
forall a. ArgsCheckState a -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (ArgsCheckState a -> m (ArgsCheckState a))
-> ArgsCheckState a -> m (ArgsCheckState a)
forall a b. (a -> b) -> a -> b
$ ArgsCheckState a
st { acRanges = rs', acElims = us ++ u : vs, acConstraints = cs' }
data IsRigid
= IsRigid
| IsNotRigid !IsPermanent
data IsPermanent
= Permanent
| AVar !Nat
| Unspecified
isRigid :: CheckArgumentsE'State -> Type -> TCM IsRigid
isRigid :: CheckArgumentsE'State -> Type -> TCM IsRigid
isRigid CheckArgumentsE'State
s Type
t | PathType{} <- CheckArgumentsE'State -> Type -> PathView
sPathView CheckArgumentsE'State
s Type
t =
IsRigid -> TCM IsRigid
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (IsRigid -> TCM IsRigid) -> IsRigid -> TCM IsRigid
forall a b. (a -> b) -> a -> b
$ IsPermanent -> IsRigid
IsNotRigid IsPermanent
Permanent
isRigid CheckArgumentsE'State
_ (El Sort
_ Term
t) = case Term
t of
Var Int
x Elims
_ -> IsRigid -> TCM IsRigid
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (IsRigid -> TCM IsRigid) -> IsRigid -> TCM IsRigid
forall a b. (a -> b) -> a -> b
$ IsPermanent -> IsRigid
IsNotRigid (Int -> IsPermanent
AVar Int
x)
Lam{} -> IsRigid -> TCM IsRigid
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (IsRigid -> TCM IsRigid) -> IsRigid -> TCM IsRigid
forall a b. (a -> b) -> a -> b
$ IsPermanent -> IsRigid
IsNotRigid IsPermanent
Permanent
Lit{} -> IsRigid -> TCM IsRigid
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (IsRigid -> TCM IsRigid) -> IsRigid -> TCM IsRigid
forall a b. (a -> b) -> a -> b
$ IsPermanent -> IsRigid
IsNotRigid IsPermanent
Permanent
Con{} -> IsRigid -> TCM IsRigid
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (IsRigid -> TCM IsRigid) -> IsRigid -> TCM IsRigid
forall a b. (a -> b) -> a -> b
$ IsPermanent -> IsRigid
IsNotRigid IsPermanent
Permanent
Pi Dom Type
dom Abs Type
_ -> IsRigid -> TCM IsRigid
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (IsRigid -> TCM IsRigid) -> IsRigid -> TCM IsRigid
forall a b. (a -> b) -> a -> b
$
if Dom Type -> Bool
forall a. LensHiding a => a -> Bool
visible Dom Type
dom then IsRigid
IsRigid else IsPermanent -> IsRigid
IsNotRigid IsPermanent
Permanent
Sort{} -> IsRigid -> TCM IsRigid
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (IsRigid -> TCM IsRigid) -> IsRigid -> TCM IsRigid
forall a b. (a -> b) -> a -> b
$ IsPermanent -> IsRigid
IsNotRigid IsPermanent
Permanent
Level{} -> IsRigid -> TCM IsRigid
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (IsRigid -> TCM IsRigid) -> IsRigid -> TCM IsRigid
forall a b. (a -> b) -> a -> b
$ IsPermanent -> IsRigid
IsNotRigid IsPermanent
Permanent
MetaV{} -> IsRigid -> TCM IsRigid
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (IsRigid -> TCM IsRigid) -> IsRigid -> TCM IsRigid
forall a b. (a -> b) -> a -> b
$ IsPermanent -> IsRigid
IsNotRigid IsPermanent
Unspecified
DontCare{} -> IsRigid -> TCM IsRigid
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (IsRigid -> TCM IsRigid) -> IsRigid -> TCM IsRigid
forall a b. (a -> b) -> a -> b
$ IsPermanent -> IsRigid
IsNotRigid IsPermanent
Permanent
Dummy{} -> IsRigid -> TCM IsRigid
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (IsRigid -> TCM IsRigid) -> IsRigid -> TCM IsRigid
forall a b. (a -> b) -> a -> b
$ IsPermanent -> IsRigid
IsNotRigid IsPermanent
Permanent
Def QName
d Elims
_ -> QName -> TCMT IO Definition
forall (m :: * -> *). HasConstInfo m => QName -> m Definition
getConstInfo QName
d TCMT IO Definition -> (Definition -> Defn) -> TCMT IO Defn
forall (m :: * -> *) a b. Functor m => m a -> (a -> b) -> m b
<&> Definition -> Defn
theDef TCMT IO Defn -> (Defn -> IsRigid) -> TCM IsRigid
forall (m :: * -> *) a b. Functor m => m a -> (a -> b) -> m b
<&> \case
Axiom{} -> IsRigid
IsRigid
DataOrRecSig{} -> IsRigid
IsRigid
AbstractDefn{} -> IsRigid
IsRigid
Function{funClauses :: Defn -> [Clause]
funClauses = [Clause]
cs} -> if [Clause] -> Bool
forall a. Null a => a -> Bool
null [Clause]
cs
then IsRigid
IsRigid
else IsPermanent -> IsRigid
IsNotRigid IsPermanent
Unspecified
Datatype{} -> IsRigid
IsRigid
Record{} -> IsRigid
IsRigid
Constructor{} -> IsRigid
forall a. HasCallStack => a
__IMPOSSIBLE__
GeneralizableVar{} -> IsRigid
forall a. HasCallStack => a
__IMPOSSIBLE__
Primitive{} -> IsPermanent -> IsRigid
IsNotRigid IsPermanent
Unspecified
PrimitiveSort{} -> IsPermanent -> IsRigid
IsNotRigid IsPermanent
Unspecified
checkArguments_
:: Comparison
-> ExpandHidden
-> Range
-> [NamedArg A.Expr]
-> Telescope
-> TCM (Elims, Telescope)
checkArguments_ :: Comparison
-> ExpandHidden
-> Range
-> [NamedArg Expr]
-> Tele (Dom Type)
-> TCMT IO (Elims, Tele (Dom Type))
checkArguments_ Comparison
cmp ExpandHidden
exh Range
r [NamedArg Expr]
args Tele (Dom Type)
tel = TCMT IO (Elims, Tele (Dom Type))
-> TCMT IO (Elims, Tele (Dom Type))
forall a. TCM a -> TCM a
postponeInstanceConstraints (TCMT IO (Elims, Tele (Dom Type))
-> TCMT IO (Elims, Tele (Dom Type)))
-> TCMT IO (Elims, Tele (Dom Type))
-> TCMT IO (Elims, Tele (Dom Type))
forall a b. (a -> b) -> a -> b
$ do
Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget)
z <- ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> TCM
(Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget))
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT (ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> TCM
(Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget)))
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> TCM
(Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget))
forall a b. (a -> b) -> a -> b
$
Comparison
-> ExpandHidden
-> Range
-> [NamedArg Expr]
-> Type
-> Maybe Type
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
checkArgumentsE Comparison
cmp ExpandHidden
exh Range
r [NamedArg Expr]
args (Tele (Dom Type) -> Type -> Type
telePi Tele (Dom Type)
tel Type
HasCallStack => Type
__DUMMY_TYPE__) Maybe Type
forall a. Maybe a
Nothing
case Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget)
z of
Right (ACState MaybeRanges
_ Elims
args [Maybe (Abs Constraint)]
cs Type
t CheckedTarget
_) | (Maybe (Abs Constraint) -> Bool)
-> [Maybe (Abs Constraint)] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Maybe (Abs Constraint) -> Bool
forall a. Maybe a -> Bool
isNothing [Maybe (Abs Constraint)]
cs -> do
let TelV Tele (Dom Type)
tel' Type
_ = Type -> TelV Type
telView' Type
t
(Elims, Tele (Dom Type)) -> TCMT IO (Elims, Tele (Dom Type))
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Elims
args, Tele (Dom Type)
tel')
| Bool
otherwise -> do
TypeError -> TCMT IO (Elims, Tele (Dom Type))
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO (Elims, Tele (Dom Type)))
-> TypeError -> TCMT IO (Elims, Tele (Dom Type))
forall a b. (a -> b) -> a -> b
$ [Char] -> TypeError
GenericError ([Char] -> TypeError) -> [Char] -> TypeError
forall a b. (a -> b) -> a -> b
$ [Char]
"Head constraints are not (yet) supported in this position."
Left ArgsCheckState [NamedArg Expr]
_ -> TCMT IO (Elims, Tele (Dom Type))
forall a. HasCallStack => a
__IMPOSSIBLE__
checkArguments ::
Comparison -> ExpandHidden -> Range -> [NamedArg A.Expr] -> Type -> Type ->
(ArgsCheckState CheckedTarget -> TCM Term) -> TCM Term
checkArguments :: Comparison
-> ExpandHidden
-> Range
-> [NamedArg Expr]
-> Type
-> Type
-> (ArgsCheckState CheckedTarget -> TCM Term)
-> TCM Term
checkArguments Comparison
cmp ExpandHidden
exph Range
r [NamedArg Expr]
args Type
t0 Type
t ArgsCheckState CheckedTarget -> TCM Term
k = TCM Term -> TCM Term
forall a. TCM a -> TCM a
postponeInstanceConstraints (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ do
Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget)
z <- ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> TCM
(Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget))
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT (ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> TCM
(Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget)))
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> TCM
(Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget))
forall a b. (a -> b) -> a -> b
$ Comparison
-> ExpandHidden
-> Range
-> [NamedArg Expr]
-> Type
-> Maybe Type
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
checkArgumentsE Comparison
cmp ExpandHidden
exph Range
r [NamedArg Expr]
args Type
t0 (Type -> Maybe Type
forall a. a -> Maybe a
Just Type
t)
case Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget)
z of
Right ArgsCheckState CheckedTarget
st -> ArgsCheckState CheckedTarget -> TCM Term
k ArgsCheckState CheckedTarget
st
Left ArgsCheckState [NamedArg Expr]
problem -> ArgsCheckState [NamedArg Expr]
-> Comparison
-> ExpandHidden
-> Range
-> [NamedArg Expr]
-> Type
-> (ArgsCheckState CheckedTarget -> TCM Term)
-> TCM Term
postponeArgs ArgsCheckState [NamedArg Expr]
problem Comparison
cmp ExpandHidden
exph Range
r [NamedArg Expr]
args Type
t ArgsCheckState CheckedTarget -> TCM Term
k
postponeArgs :: (ArgsCheckState [NamedArg A.Expr]) -> Comparison -> ExpandHidden -> Range -> [NamedArg A.Expr] -> Type ->
(ArgsCheckState CheckedTarget -> TCM Term) -> TCM Term
postponeArgs :: ArgsCheckState [NamedArg Expr]
-> Comparison
-> ExpandHidden
-> Range
-> [NamedArg Expr]
-> Type
-> (ArgsCheckState CheckedTarget -> TCM Term)
-> TCM Term
postponeArgs (ACState MaybeRanges
rs Elims
us [Maybe (Abs Constraint)]
cs Type
t0 [NamedArg Expr]
es) Comparison
cmp ExpandHidden
exph Range
r [NamedArg Expr]
args Type
t ArgsCheckState CheckedTarget -> TCM Term
k = do
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.expr.args" Int
80 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$
[TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
sep [ TCMT IO Doc
"postponed checking arguments"
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
4 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Semigroup (m Doc), Foldable t) =>
t (m Doc) -> m Doc
prettyList ((NamedArg Expr -> TCMT IO Doc) -> [NamedArg Expr] -> [TCMT IO Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Expr -> TCMT IO Doc
forall a (m :: * -> *).
(ToConcrete a, Pretty (ConOfAbs a), MonadAbsToCon m) =>
a -> m Doc
prettyA (Expr -> TCMT IO Doc)
-> (NamedArg Expr -> Expr) -> NamedArg Expr -> TCMT IO Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Named_ Expr -> Expr
forall name a. Named name a -> a
namedThing (Named_ Expr -> Expr)
-> (NamedArg Expr -> Named_ Expr) -> NamedArg Expr -> Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NamedArg Expr -> Named_ Expr
forall e. Arg e -> e
unArg) [NamedArg Expr]
args)
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"against"
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
4 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
t0 ] TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
$$
[TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
sep [ TCMT IO Doc
"progress:"
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"checked" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Semigroup (m Doc), Foldable t) =>
t (m Doc) -> m Doc
prettyList ((Elim -> TCMT IO Doc) -> Elims -> [TCMT IO Doc]
forall a b. (a -> b) -> [a] -> [b]
map Elim -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Elim -> m Doc
prettyTCM Elims
us)
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"remaining" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
sep [ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Semigroup (m Doc), Foldable t) =>
t (m Doc) -> m Doc
prettyList ((NamedArg Expr -> TCMT IO Doc) -> [NamedArg Expr] -> [TCMT IO Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Expr -> TCMT IO Doc
forall a (m :: * -> *).
(ToConcrete a, Pretty (ConOfAbs a), MonadAbsToCon m) =>
a -> m Doc
prettyA (Expr -> TCMT IO Doc)
-> (NamedArg Expr -> Expr) -> NamedArg Expr -> TCMT IO Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Named_ Expr -> Expr
forall name a. Named name a -> a
namedThing (Named_ Expr -> Expr)
-> (NamedArg Expr -> Named_ Expr) -> NamedArg Expr -> Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NamedArg Expr -> Named_ Expr
forall e. Arg e -> e
unArg) [NamedArg Expr]
es)
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
":" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
t0 ] ]
TypeCheckingProblem -> TCM Term
postponeTypeCheckingProblem_ (Comparison
-> ExpandHidden
-> Range
-> [NamedArg Expr]
-> Type
-> Type
-> (ArgsCheckState CheckedTarget -> TCM Term)
-> TypeCheckingProblem
CheckArgs Comparison
cmp ExpandHidden
exph Range
r [NamedArg Expr]
es Type
t0 Type
t ((ArgsCheckState CheckedTarget -> TCM Term) -> TypeCheckingProblem)
-> (ArgsCheckState CheckedTarget -> TCM Term)
-> TypeCheckingProblem
forall a b. (a -> b) -> a -> b
$ \ (ACState MaybeRanges
rs' Elims
vs [Maybe (Abs Constraint)]
cs' Type
t CheckedTarget
pid) -> ArgsCheckState CheckedTarget -> TCM Term
k (ArgsCheckState CheckedTarget -> TCM Term)
-> ArgsCheckState CheckedTarget -> TCM Term
forall a b. (a -> b) -> a -> b
$ MaybeRanges
-> Elims
-> [Maybe (Abs Constraint)]
-> Type
-> CheckedTarget
-> ArgsCheckState CheckedTarget
forall a.
MaybeRanges
-> Elims
-> [Maybe (Abs Constraint)]
-> Type
-> a
-> ArgsCheckState a
ACState (MaybeRanges
rs MaybeRanges -> MaybeRanges -> MaybeRanges
forall a. [a] -> [a] -> [a]
++ MaybeRanges
rs') (Elims
us Elims -> Elims -> Elims
forall a. [a] -> [a] -> [a]
++ Elims
vs) ([Maybe (Abs Constraint)]
cs [Maybe (Abs Constraint)]
-> [Maybe (Abs Constraint)] -> [Maybe (Abs Constraint)]
forall a. [a] -> [a] -> [a]
++ [Maybe (Abs Constraint)]
cs') Type
t CheckedTarget
pid)
checkConstructorApplication :: Comparison -> A.Expr -> Type -> ConHead -> [NamedArg A.Expr] -> TCM Term
checkConstructorApplication :: Comparison
-> Expr -> Type -> ConHead -> [NamedArg Expr] -> TCM Term
checkConstructorApplication Comparison
cmp Expr
org Type
t ConHead
c [NamedArg Expr]
args = do
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.con" Int
50 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"entering checkConstructorApplication"
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"org =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Expr -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Expr -> m Doc
prettyTCM Expr
org
, TCMT IO Doc
"t =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
t
, TCMT IO Doc
"c =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> ConHead -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => ConHead -> m Doc
prettyTCM ConHead
c
, TCMT IO Doc
"args =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> [NamedArg Expr] -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => [NamedArg Expr] -> m Doc
prettyTCM [NamedArg Expr]
args
] ]
Definition
cdef <- ConHead -> TCMT IO Definition
forall (m :: * -> *). HasConstInfo m => ConHead -> m Definition
getConInfo ConHead
c
QName -> Definition -> TCMT IO ()
forall (m :: * -> *).
MonadConversion m =>
QName -> Definition -> m ()
checkModality (ConHead -> QName
conName ConHead
c) Definition
cdef
let paramsGiven :: Bool
paramsGiven = [NamedArg Expr] -> Bool
checkForParams [NamedArg Expr]
args
if Bool
paramsGiven then TCM Term
fallback else do
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.con" Int
50 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"checkConstructorApplication: no parameters explicitly supplied, continuing..."
let Constructor{conData :: Defn -> QName
conData = QName
d, conPars :: Defn -> Int
conPars = Int
npars} = Definition -> Defn
theDef Definition
cdef
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.con" Int
50 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"d =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => QName -> m Doc
prettyTCM QName
d
Term
t0 <- Term -> TCM Term
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce (QName -> Elims -> Term
Def QName
d [])
Type
tReduced <- Type -> TCMT IO Type
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce Type
t
case (Term
t0, Type -> Term
forall t a. Type'' t a -> a
unEl Type
tReduced) of
(Def QName
d0 Elims
_, Def QName
d' Elims
es) -> do
let ~(Just [Arg Term]
vs) = Elims -> Maybe [Arg Term]
forall a. [Elim' a] -> Maybe [Arg a]
allApplyElims Elims
es
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.con" Int
50 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"d0 =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => QName -> m Doc
prettyTCM QName
d0
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.con" Int
50 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"d' =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => QName -> m Doc
prettyTCM QName
d'
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.con" Int
50 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"vs =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> [Arg Term] -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => [Arg Term] -> m Doc
prettyTCM [Arg Term]
vs
if QName
d' QName -> QName -> Bool
forall a. Eq a => a -> a -> Bool
/= QName
d0 then TCM Term
fallback else do
Maybe Int
npars' <- QName -> TCMT IO (Maybe Int)
forall (m :: * -> *). HasConstInfo m => QName -> m (Maybe Int)
getNumberOfParameters QName
d'
Maybe (Pair Int) -> TCM Term -> (Pair Int -> TCM Term) -> TCM Term
forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe (Pair (Maybe Int) -> Maybe (Pair Int)
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
forall (f :: * -> *) a. Applicative f => Pair (f a) -> f (Pair a)
sequenceA (Pair (Maybe Int) -> Maybe (Pair Int))
-> Pair (Maybe Int) -> Maybe (Pair Int)
forall a b. (a -> b) -> a -> b
$ Maybe Int -> Maybe Int -> Pair (Maybe Int)
forall a. a -> a -> Pair a
Pair (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
npars) Maybe Int
npars') TCM Term
fallback ((Pair Int -> TCM Term) -> TCM Term)
-> (Pair Int -> TCM Term) -> TCM Term
forall a b. (a -> b) -> a -> b
$ \ (Pair Int
n Int
n') -> do
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.con" Int
50 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char] -> TCMT IO Doc) -> [Char] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char]
"n = " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show Int
n
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.con" Int
50 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char] -> TCMT IO Doc) -> [Char] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char]
"n' = " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show Int
n'
Bool -> TCMT IO () -> TCMT IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
n')
TCMT IO ()
forall a. HasCallStack => a
__IMPOSSIBLE__
let ps :: [Arg Term]
ps = Int -> [Arg Term] -> [Arg Term]
forall a. Int -> [a] -> [a]
take Int
n ([Arg Term] -> [Arg Term]) -> [Arg Term] -> [Arg Term]
forall a b. (a -> b) -> a -> b
$ Int -> [Arg Term] -> [Arg Term]
forall a. Int -> [a] -> [a]
drop (Int
n' Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
n) [Arg Term]
vs
ctype :: Type
ctype = Definition -> Type
defType Definition
cdef
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.con" Int
20 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"special checking of constructor application of" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> ConHead -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => ConHead -> m Doc
prettyTCM ConHead
c
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat [ TCMT IO Doc
"ps =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> [Arg Term] -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => [Arg Term] -> m Doc
prettyTCM [Arg Term]
ps
, TCMT IO Doc
"ctype =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
ctype ] ]
let ctype' :: Type
ctype' = Type
ctype Type -> [Arg Term] -> Type
`piApply` [Arg Term]
ps
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.con" Int
20 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"ctype' =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
ctype'
let TelV Tele (Dom Type)
ptel Type
_ = Int -> Type -> TelV Type
telView'UpTo Int
n Type
ctype
let pnames :: [Dom' Term [Char]]
pnames = (Dom' Term ([Char], Type) -> Dom' Term [Char])
-> [Dom' Term ([Char], Type)] -> [Dom' Term [Char]]
forall a b. (a -> b) -> [a] -> [b]
map ((([Char], Type) -> [Char])
-> Dom' Term ([Char], Type) -> Dom' Term [Char]
forall a b. (a -> b) -> Dom' Term a -> Dom' Term b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ([Char], Type) -> [Char]
forall a b. (a, b) -> a
fst) ([Dom' Term ([Char], Type)] -> [Dom' Term [Char]])
-> [Dom' Term ([Char], Type)] -> [Dom' Term [Char]]
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Dom' Term ([Char], Type)]
forall t. Tele (Dom t) -> [Dom ([Char], t)]
telToList Tele (Dom Type)
ptel
args' :: [NamedArg Expr]
args' = [Dom' Term [Char]] -> [NamedArg Expr] -> [NamedArg Expr]
dropArgs [Dom' Term [Char]]
pnames [NamedArg Expr]
args
ExpandHidden
expandLast <- (TCEnv -> ExpandHidden) -> TCMT IO ExpandHidden
forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC TCEnv -> ExpandHidden
envExpandLast
Comparison
-> ExpandHidden
-> Range
-> [NamedArg Expr]
-> Type
-> Type
-> (ArgsCheckState CheckedTarget -> TCM Term)
-> TCM Term
checkArguments Comparison
cmp ExpandHidden
expandLast (ConHead -> Range
forall a. HasRange a => a -> Range
getRange ConHead
c) [NamedArg Expr]
args' Type
ctype' Type
t ((ArgsCheckState CheckedTarget -> TCM Term) -> TCM Term)
-> (ArgsCheckState CheckedTarget -> TCM Term) -> TCM Term
forall a b. (a -> b) -> a -> b
$ \ st :: ArgsCheckState CheckedTarget
st@(ACState MaybeRanges
_ Elims
_ [Maybe (Abs Constraint)]
_ Type
t' CheckedTarget
targetCheck) -> do
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.con" Int
20 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text [Char]
"es =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Elims -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Elims -> m Doc
prettyTCM Elims
es
, [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text [Char]
"t' =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
t' ]
Term
v <- (Elims -> Term) -> ArgsCheckState CheckedTarget -> TCM Term
forall a. (Elims -> Term) -> ArgsCheckState a -> TCM Term
checkHeadConstraints (ConHead -> ConInfo -> Elims -> Term
Con ConHead
c ConInfo
ConOCon) ArgsCheckState CheckedTarget
st
Comparison -> CheckedTarget -> Term -> Type -> Type -> TCM Term
coerce' Comparison
cmp CheckedTarget
targetCheck Term
v Type
t' Type
t
(Term, Term)
_ -> do
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.con" Int
50 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"we are not at a datatype, falling back"
TCM Term
fallback
where
fallback :: TCM Term
fallback = Comparison -> Expr -> Type -> Expr -> [NamedArg Expr] -> TCM Term
checkHeadApplication Comparison
cmp Expr
org Type
t (AmbiguousQName -> Expr
A.Con (QName -> AmbiguousQName
unambiguous (QName -> AmbiguousQName) -> QName -> AmbiguousQName
forall a b. (a -> b) -> a -> b
$ ConHead -> QName
conName ConHead
c)) [NamedArg Expr]
args
checkForParams :: [NamedArg Expr] -> Bool
checkForParams [NamedArg Expr]
args =
let ([NamedArg Expr]
hargs, [NamedArg Expr]
rest) = (NamedArg Expr -> Bool)
-> [NamedArg Expr] -> ([NamedArg Expr], [NamedArg Expr])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break NamedArg Expr -> Bool
forall a. LensHiding a => a -> Bool
visible [NamedArg Expr]
args
notUnderscore :: Expr -> Bool
notUnderscore A.Underscore{} = Bool
False
notUnderscore Expr
_ = Bool
True
in (NamedArg Expr -> Bool) -> [NamedArg Expr] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Expr -> Bool
notUnderscore (Expr -> Bool) -> (NamedArg Expr -> Expr) -> NamedArg Expr -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expr -> Expr
unScope (Expr -> Expr) -> (NamedArg Expr -> Expr) -> NamedArg Expr -> Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NamedArg Expr -> Expr
forall a. NamedArg a -> a
namedArg) [NamedArg Expr]
hargs
dropArgs :: [Dom' Term [Char]] -> [NamedArg Expr] -> [NamedArg Expr]
dropArgs [] [NamedArg Expr]
args = [NamedArg Expr]
args
dropArgs [Dom' Term [Char]]
ps [] = [NamedArg Expr]
args
dropArgs [Dom' Term [Char]]
ps args :: [NamedArg Expr]
args@(NamedArg Expr
arg : [NamedArg Expr]
args')
| Just [Char]
p <- Maybe [Char]
name,
Just [Dom' Term [Char]]
ps' <- [Char] -> [Dom' Term [Char]] -> Maybe [Dom' Term [Char]]
forall {b} {t}. Eq b => b -> [Dom' t b] -> Maybe [Dom' t b]
namedPar [Char]
p [Dom' Term [Char]]
ps = [Dom' Term [Char]] -> [NamedArg Expr] -> [NamedArg Expr]
dropArgs [Dom' Term [Char]]
ps' [NamedArg Expr]
args'
| Maybe [Char]
Nothing <- Maybe [Char]
name,
Just [Dom' Term [Char]]
ps' <- Hiding -> [Dom' Term [Char]] -> Maybe [Dom' Term [Char]]
forall {a} {t}.
(LensHiding a, LensHiding t) =>
a -> [t] -> Maybe [t]
unnamedPar Hiding
h [Dom' Term [Char]]
ps = [Dom' Term [Char]] -> [NamedArg Expr] -> [NamedArg Expr]
dropArgs [Dom' Term [Char]]
ps' [NamedArg Expr]
args'
| Bool
otherwise = [NamedArg Expr]
args
where
name :: Maybe [Char]
name = NamedArg Expr -> Maybe [Char]
forall a. (LensNamed a, NameOf a ~ NamedName) => a -> Maybe [Char]
bareNameOf NamedArg Expr
arg
h :: Hiding
h = NamedArg Expr -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding NamedArg Expr
arg
namedPar :: b -> [Dom' t b] -> Maybe [Dom' t b]
namedPar b
x = (Dom' t b -> Bool) -> [Dom' t b] -> Maybe [Dom' t b]
forall {t}. (t -> Bool) -> [t] -> Maybe [t]
dropPar ((b
x b -> b -> Bool
forall a. Eq a => a -> a -> Bool
==) (b -> Bool) -> (Dom' t b -> b) -> Dom' t b -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dom' t b -> b
forall t e. Dom' t e -> e
unDom)
unnamedPar :: a -> [t] -> Maybe [t]
unnamedPar a
h = (t -> Bool) -> [t] -> Maybe [t]
forall {t}. (t -> Bool) -> [t] -> Maybe [t]
dropPar (a -> t -> Bool
forall a b. (LensHiding a, LensHiding b) => a -> b -> Bool
sameHiding a
h)
dropPar :: (t -> Bool) -> [t] -> Maybe [t]
dropPar t -> Bool
this (t
p : [t]
ps) | t -> Bool
this t
p = [t] -> Maybe [t]
forall a. a -> Maybe a
Just [t]
ps
| Bool
otherwise = (t -> Bool) -> [t] -> Maybe [t]
dropPar t -> Bool
this [t]
ps
dropPar t -> Bool
_ [] = Maybe [t]
forall a. Maybe a
Nothing
type DisambiguateConstructor = TCM (Either Blocker ConHead)
disambiguateConstructor :: List1 QName -> A.Args -> Type -> DisambiguateConstructor
disambiguateConstructor :: List1 QName -> [NamedArg Expr] -> Type -> DisambiguateConstructor
disambiguateConstructor List1 QName
cs0 [NamedArg Expr]
args Type
t = do
[Char] -> Int -> [Char] -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"tc.check.term.con" Int
40 ([Char] -> TCMT IO ()) -> [Char] -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [Char]
"Ambiguous constructor: " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ List1 QName -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow List1 QName
cs0
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.check.term.con" Int
40 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat ([TCMT IO Doc] -> TCMT IO Doc) -> [TCMT IO Doc] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"Arguments:" TCMT IO Doc -> [TCMT IO Doc] -> [TCMT IO Doc]
forall a. a -> [a] -> [a]
: (NamedArg Expr -> TCMT IO Doc) -> [NamedArg Expr] -> [TCMT IO Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc)
-> (NamedArg Expr -> TCMT IO Doc) -> NamedArg Expr -> TCMT IO Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NamedArg Expr -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => NamedArg Expr -> m Doc
prettyTCM) [NamedArg Expr]
args
let getData :: Defn -> QName
getData Constructor{conData :: Defn -> QName
conData = QName
d} = QName
d
getData Defn
_ = QName
forall a. HasCallStack => a
__IMPOSSIBLE__
[Char] -> Int -> [Char] -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"tc.check.term.con" Int
40 ([Char] -> TCMT IO ()) -> [Char] -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [Char]
" ranges before: " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Range -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow (List1 QName -> Range
forall a. HasRange a => a -> Range
getRange List1 QName
cs0)
[(QName, ConHead)]
ccons <- List1 (Either SigError (QName, ConHead)) -> [(QName, ConHead)]
forall a b. List1 (Either a b) -> [b]
List1.rights (List1 (Either SigError (QName, ConHead)) -> [(QName, ConHead)])
-> TCMT IO (List1 (Either SigError (QName, ConHead)))
-> TCMT IO [(QName, ConHead)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
List1 QName
-> (QName -> TCMT IO (Either SigError (QName, ConHead)))
-> TCMT IO (List1 (Either SigError (QName, ConHead)))
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM List1 QName
cs0 ((QName -> TCMT IO (Either SigError (QName, ConHead)))
-> TCMT IO (List1 (Either SigError (QName, ConHead))))
-> (QName -> TCMT IO (Either SigError (QName, ConHead)))
-> TCMT IO (List1 (Either SigError (QName, ConHead)))
forall a b. (a -> b) -> a -> b
$ \ QName
c -> (ConHead -> (QName, ConHead))
-> Either SigError ConHead -> Either SigError (QName, ConHead)
forall b d a. (b -> d) -> Either a b -> Either a d
mapRight (QName
c,) (Either SigError ConHead -> Either SigError (QName, ConHead))
-> TCMT IO (Either SigError ConHead)
-> TCMT IO (Either SigError (QName, ConHead))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> QName -> TCMT IO (Either SigError ConHead)
getConForm QName
c
[Char] -> Int -> [Char] -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"tc.check.term.con" Int
40 ([Char] -> TCMT IO ()) -> [Char] -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [Char]
" reduced: " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [ConHead] -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow (((QName, ConHead) -> ConHead) -> [(QName, ConHead)] -> [ConHead]
forall a b. (a -> b) -> [a] -> [b]
map (QName, ConHead) -> ConHead
forall a b. (a, b) -> b
snd [(QName, ConHead)]
ccons)
case [(QName, ConHead)]
ccons of
[] -> TypeError -> DisambiguateConstructor
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> DisambiguateConstructor)
-> TypeError -> DisambiguateConstructor
forall a b. (a -> b) -> a -> b
$ QName -> TypeError
AbstractConstructorNotInScope (QName -> TypeError) -> QName -> TypeError
forall a b. (a -> b) -> a -> b
$ List1 QName -> QName
forall a. NonEmpty a -> a
List1.head List1 QName
cs0
[(QName
c0,ConHead
con)] -> do
let c :: ConHead
c = QName -> ConHead -> ConHead
forall a. LensConName a => QName -> a -> a
setConName QName
c0 ConHead
con
[Char] -> Int -> [Char] -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"tc.check.term.con" Int
40 ([Char] -> TCMT IO ()) -> [Char] -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [Char]
" only one non-abstract constructor: " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ ConHead -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow ConHead
c
ConHead -> DisambiguateConstructor
decideOn ConHead
c
(QName
c0,ConHead
_):[(QName, ConHead)]
_ -> do
[(QName, Type, ConHead)]
dcs :: [(QName, Type, ConHead)] <- [(QName, ConHead)]
-> ((QName, ConHead) -> TCMT IO (QName, Type, ConHead))
-> TCMT IO [(QName, Type, ConHead)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [(QName, ConHead)]
ccons (((QName, ConHead) -> TCMT IO (QName, Type, ConHead))
-> TCMT IO [(QName, Type, ConHead)])
-> ((QName, ConHead) -> TCMT IO (QName, Type, ConHead))
-> TCMT IO [(QName, Type, ConHead)]
forall a b. (a -> b) -> a -> b
$ \ (QName
c, ConHead
con) -> do
Type
t <- Definition -> Type
defType (Definition -> Type) -> TCMT IO Definition -> TCMT IO Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> QName -> TCMT IO Definition
forall (m :: * -> *). HasConstInfo m => QName -> m Definition
getConstInfo QName
c
Definition
def <- ConHead -> TCMT IO Definition
forall (m :: * -> *). HasConstInfo m => ConHead -> m Definition
getConInfo ConHead
con
(QName, Type, ConHead) -> TCMT IO (QName, Type, ConHead)
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Defn -> QName
getData (Definition -> Defn
theDef Definition
def), Type
t, QName -> ConHead -> ConHead
forall a. LensConName a => QName -> a -> a
setConName QName
c ConHead
con)
let badCon :: Type -> DisambiguateConstructor
badCon Type
t = TypeError -> DisambiguateConstructor
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> DisambiguateConstructor)
-> TypeError -> DisambiguateConstructor
forall a b. (a -> b) -> a -> b
$ QName -> Type -> TypeError
DoesNotConstructAnElementOf QName
c0 Type
t
TelV Tele (Dom Type)
tel Type
t1 <- Type -> TCMT IO (TelV Type)
forall (m :: * -> *). PureTCM m => Type -> m (TelV Type)
telViewPath Type
t
Tele (Dom Type)
-> DisambiguateConstructor -> DisambiguateConstructor
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
forall (m :: * -> *) a.
MonadAddContext m =>
Tele (Dom Type) -> m a -> m a
addContext Tele (Dom Type)
tel (DisambiguateConstructor -> DisambiguateConstructor)
-> DisambiguateConstructor -> DisambiguateConstructor
forall a b. (a -> b) -> a -> b
$ do
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.check.term.con" Int
40 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"target type: " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
t1
Type
-> (Blocker -> Type -> DisambiguateConstructor)
-> (NotBlocked -> Type -> DisambiguateConstructor)
-> DisambiguateConstructor
forall t (m :: * -> *) a.
(Reduce t, IsMeta t, MonadReduce m) =>
t -> (Blocker -> t -> m a) -> (NotBlocked -> t -> m a) -> m a
ifBlocked Type
t1 (\ Blocker
b Type
_ -> [(QName, Type, ConHead)]
-> DisambiguateConstructor -> DisambiguateConstructor
disambiguateByArgs [(QName, Type, ConHead)]
dcs (DisambiguateConstructor -> DisambiguateConstructor)
-> DisambiguateConstructor -> DisambiguateConstructor
forall a b. (a -> b) -> a -> b
$ Either Blocker ConHead -> DisambiguateConstructor
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Either Blocker ConHead -> DisambiguateConstructor)
-> Either Blocker ConHead -> DisambiguateConstructor
forall a b. (a -> b) -> a -> b
$ Blocker -> Either Blocker ConHead
forall a b. a -> Either a b
Left Blocker
b) ((NotBlocked -> Type -> DisambiguateConstructor)
-> DisambiguateConstructor)
-> (NotBlocked -> Type -> DisambiguateConstructor)
-> DisambiguateConstructor
forall a b. (a -> b) -> a -> b
$ \ NotBlocked
_ Type
t' ->
TCMT IO (Maybe QName)
-> DisambiguateConstructor
-> (QName -> DisambiguateConstructor)
-> DisambiguateConstructor
forall (m :: * -> *) a b.
Monad m =>
m (Maybe a) -> m b -> (a -> m b) -> m b
caseMaybeM (Term -> TCMT IO (Maybe QName)
isDataOrRecord (Term -> TCMT IO (Maybe QName)) -> Term -> TCMT IO (Maybe QName)
forall a b. (a -> b) -> a -> b
$ Type -> Term
forall t a. Type'' t a -> a
unEl Type
t') (Type -> DisambiguateConstructor
badCon Type
t') ((QName -> DisambiguateConstructor) -> DisambiguateConstructor)
-> (QName -> DisambiguateConstructor) -> DisambiguateConstructor
forall a b. (a -> b) -> a -> b
$ \ QName
d -> do
let dcs' :: [(QName, Type, ConHead)]
dcs' = ((QName, Type, ConHead) -> Bool)
-> [(QName, Type, ConHead)] -> [(QName, Type, ConHead)]
forall a. (a -> Bool) -> [a] -> [a]
filter ((QName
d QName -> QName -> Bool
forall a. Eq a => a -> a -> Bool
==) (QName -> Bool)
-> ((QName, Type, ConHead) -> QName)
-> (QName, Type, ConHead)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (QName, Type, ConHead) -> QName
forall a b c. (a, b, c) -> a
fst3) [(QName, Type, ConHead)]
dcs
case ((QName, Type, ConHead) -> ConHead)
-> [(QName, Type, ConHead)] -> [ConHead]
forall a b. (a -> b) -> [a] -> [b]
map (QName, Type, ConHead) -> ConHead
forall a b c. (a, b, c) -> c
thd3 [(QName, Type, ConHead)]
dcs' of
[ConHead
c] -> ConHead -> DisambiguateConstructor
decideOn ConHead
c
[] -> Type -> DisambiguateConstructor
badCon (Type -> DisambiguateConstructor)
-> Type -> DisambiguateConstructor
forall a b. (a -> b) -> a -> b
$ Type
t' Type -> Term -> Type
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> QName -> Elims -> Term
Def QName
d []
ConHead
c:[ConHead]
cs-> [(QName, Type, ConHead)]
-> DisambiguateConstructor -> DisambiguateConstructor
disambiguateByArgs [(QName, Type, ConHead)]
dcs' (DisambiguateConstructor -> DisambiguateConstructor)
-> DisambiguateConstructor -> DisambiguateConstructor
forall a b. (a -> b) -> a -> b
$
TypeError -> DisambiguateConstructor
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> DisambiguateConstructor)
-> TypeError -> DisambiguateConstructor
forall a b. (a -> b) -> a -> b
$ QName -> List1 QName -> TypeError
CantResolveOverloadedConstructorsTargetingSameDatatype QName
d (List1 QName -> TypeError) -> List1 QName -> TypeError
forall a b. (a -> b) -> a -> b
$
(ConHead -> QName) -> NonEmpty ConHead -> List1 QName
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ConHead -> QName
conName (NonEmpty ConHead -> List1 QName)
-> NonEmpty ConHead -> List1 QName
forall a b. (a -> b) -> a -> b
$ ConHead
c ConHead -> [ConHead] -> NonEmpty ConHead
forall a. a -> [a] -> NonEmpty a
:| [ConHead]
cs
where
decideOn :: ConHead -> DisambiguateConstructor
decideOn :: ConHead -> DisambiguateConstructor
decideOn ConHead
c = do
[Char] -> Int -> [Char] -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> [Char] -> m ()
reportSLn [Char]
"tc.check.term.con" Int
40 ([Char] -> TCMT IO ()) -> [Char] -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [Char]
" decided on: " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ ConHead -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow ConHead
c
Induction -> QName -> TCMT IO ()
storeDisambiguatedConstructor (ConHead -> Induction
conInductive ConHead
c) (ConHead -> QName
conName ConHead
c)
Either Blocker ConHead -> DisambiguateConstructor
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Either Blocker ConHead -> DisambiguateConstructor)
-> Either Blocker ConHead -> DisambiguateConstructor
forall a b. (a -> b) -> a -> b
$ ConHead -> Either Blocker ConHead
forall a b. b -> Either a b
Right ConHead
c
disambiguateByArgs :: [(QName, Type, ConHead)] -> DisambiguateConstructor -> DisambiguateConstructor
disambiguateByArgs :: [(QName, Type, ConHead)]
-> DisambiguateConstructor -> DisambiguateConstructor
disambiguateByArgs [(QName, Type, ConHead)]
dcs DisambiguateConstructor
fallback = do
[Maybe QName]
askel <- TCM [Maybe QName]
visibleVarArgs
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.check.term.con" Int
40 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
hsep ([TCMT IO Doc] -> TCMT IO Doc) -> [TCMT IO Doc] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"trying disambiguation by arguments" TCMT IO Doc -> [TCMT IO Doc] -> [TCMT IO Doc]
forall a. a -> [a] -> [a]
: (Maybe QName -> TCMT IO Doc) -> [Maybe QName] -> [TCMT IO Doc]
forall a b. (a -> b) -> [a] -> [b]
map Maybe QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Maybe QName -> m Doc
prettyTCM [Maybe QName]
askel
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.check.term.con" Int
80 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
hsep ([TCMT IO Doc] -> TCMT IO Doc) -> [TCMT IO Doc] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"trying disambiguation by arguments" TCMT IO Doc -> [TCMT IO Doc] -> [TCMT IO Doc]
forall a. a -> [a] -> [a]
: (Maybe QName -> TCMT IO Doc) -> [Maybe QName] -> [TCMT IO Doc]
forall a b. (a -> b) -> [a] -> [b]
map Maybe QName -> TCMT IO Doc
forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty [Maybe QName]
askel
[(QName, Type, ConHead)]
cands <- ((QName, Type, ConHead) -> TCMT IO Bool)
-> [(QName, Type, ConHead)] -> TCMT IO [(QName, Type, ConHead)]
forall (m :: * -> *) a.
Applicative m =>
(a -> m Bool) -> [a] -> m [a]
filterM (\ (QName
_d, Type
t, ConHead
_c) -> [Maybe QName] -> [Maybe QName] -> TCMT IO Bool
matchSkel [Maybe QName]
askel ([Maybe QName] -> TCMT IO Bool)
-> TCM [Maybe QName] -> TCMT IO Bool
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Type -> TCM [Maybe QName]
visibleConDoms Type
t) [(QName, Type, ConHead)]
dcs
case [(QName, Type, ConHead)]
cands of
[(QName
_d, Type
_t, ConHead
c)] -> ConHead -> DisambiguateConstructor
decideOn ConHead
c
[(QName, Type, ConHead)]
_ -> DisambiguateConstructor
fallback
where
match ::
[Maybe QName]
-> [Maybe QName]
-> Bool
match :: [Maybe QName] -> [Maybe QName] -> Bool
match = (([Maybe QName], [Maybe QName]) -> Bool)
-> [Maybe QName] -> [Maybe QName] -> Bool
forall a b c. ((a, b) -> c) -> a -> b -> c
curry ((([Maybe QName], [Maybe QName]) -> Bool)
-> [Maybe QName] -> [Maybe QName] -> Bool)
-> (([Maybe QName], [Maybe QName]) -> Bool)
-> [Maybe QName]
-> [Maybe QName]
-> Bool
forall a b. (a -> b) -> a -> b
$ \case
([], [Maybe QName]
_ ) -> Bool
True
([Maybe QName]
_ , []) -> Bool
False
(Just QName
q : [Maybe QName]
ms, Just QName
q' : [Maybe QName]
ms') -> QName
q QName -> QName -> Bool
forall a. Eq a => a -> a -> Bool
== QName
q' Bool -> Bool -> Bool
&& [Maybe QName] -> [Maybe QName] -> Bool
match [Maybe QName]
ms [Maybe QName]
ms'
(Maybe QName
_ : [Maybe QName]
ms, Maybe QName
_ : [Maybe QName]
ms') -> [Maybe QName] -> [Maybe QName] -> Bool
match [Maybe QName]
ms [Maybe QName]
ms'
matchSkel :: [Maybe QName] -> [Maybe QName] -> TCM Bool
matchSkel :: [Maybe QName] -> [Maybe QName] -> TCMT IO Bool
matchSkel [Maybe QName]
argsSkel [Maybe QName]
conSkel = do
let res :: Bool
res = [Maybe QName] -> [Maybe QName] -> Bool
match [Maybe QName]
argsSkel [Maybe QName]
conSkel
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.check.term.con" Int
40 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"matchSkel returns" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Bool -> TCMT IO Doc
forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty Bool
res TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
"on:"
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Maybe QName] -> TCMT IO Doc
forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty [Maybe QName]
argsSkel
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Maybe QName] -> TCMT IO Doc
forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty [Maybe QName]
conSkel
]
Bool -> TCMT IO Bool
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
res
visibleVarArgs :: TCM [Maybe QName]
visibleVarArgs :: TCM [Maybe QName]
visibleVarArgs = [NamedArg Expr]
-> (NamedArg Expr -> TCMT IO (Maybe QName)) -> TCM [Maybe QName]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM ((NamedArg Expr -> Bool) -> [NamedArg Expr] -> [NamedArg Expr]
forall a. (a -> Bool) -> [a] -> [a]
filter NamedArg Expr -> Bool
forall a. LensHiding a => a -> Bool
visible [NamedArg Expr]
args) ((NamedArg Expr -> TCMT IO (Maybe QName)) -> TCM [Maybe QName])
-> (NamedArg Expr -> TCMT IO (Maybe QName)) -> TCM [Maybe QName]
forall a b. (a -> b) -> a -> b
$ \ (NamedArg Expr
arg :: NamedArg A.Expr) -> do
let v :: Expr
v = Expr -> Expr
unScope (Expr -> Expr) -> Expr -> Expr
forall a b. (a -> b) -> a -> b
$ NamedArg Expr -> Expr
forall a. NamedArg a -> a
namedArg NamedArg Expr
arg
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.check.term.con" Int
40 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"is this a variable? :" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Expr -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Expr -> m Doc
prettyTCM Expr
v
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.check.term.con" Int
90 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"is this a variable? :" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> ([Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char] -> TCMT IO Doc) -> (Expr -> [Char]) -> Expr -> TCMT IO Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expr -> [Char]
forall a. Show a => a -> [Char]
show) Expr
v
case Expr
v of
A.Var Name
x -> do
Type
t <- Dom Type -> Type
forall t e. Dom' t e -> e
unDom (Dom Type -> Type)
-> ((Term, Dom Type) -> Dom Type) -> (Term, Dom Type) -> Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Term, Dom Type) -> Dom Type
forall a b. (a, b) -> b
snd ((Term, Dom Type) -> Type)
-> TCMT IO (Term, Dom Type) -> TCMT IO Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> TCMT IO (Term, Dom Type)
forall (m :: * -> *).
(MonadFail m, MonadTCEnv m) =>
Name -> m (Term, Dom Type)
getVarInfo Name
x
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.check.term.con" Int
40 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"type of variable:" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
t
Type -> TCMT IO (Maybe QName)
getTypeHead Type
t
A.Def QName
x -> do
QName -> TCMT IO (Either SigError Definition)
forall (m :: * -> *).
HasConstInfo m =>
QName -> m (Either SigError Definition)
getConstInfo' QName
x TCMT IO (Either SigError Definition)
-> (Either SigError Definition -> TCMT IO (Maybe QName))
-> TCMT IO (Maybe QName)
forall a b. TCMT IO a -> (a -> TCMT IO b) -> TCMT IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Right Definition
def -> Type -> TCMT IO (Maybe QName)
getTypeHead (Type -> TCMT IO (Maybe QName)) -> Type -> TCMT IO (Maybe QName)
forall a b. (a -> b) -> a -> b
$ Definition -> Type
defType Definition
def
Left{} -> Maybe QName -> TCMT IO (Maybe QName)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe QName
forall a. Maybe a
Nothing
Expr
_ -> Maybe QName -> TCMT IO (Maybe QName)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe QName
forall a. Maybe a
Nothing
visibleConDoms :: Type -> TCM [Maybe QName]
visibleConDoms :: Type -> TCM [Maybe QName]
visibleConDoms Type
t = do
TelV Tele (Dom Type)
tel Type
_ <- Type -> TCMT IO (TelV Type)
forall (m :: * -> *). PureTCM m => Type -> m (TelV Type)
telViewPath Type
t
(Dom' Term ([Char], Type) -> TCMT IO (Maybe QName))
-> [Dom' Term ([Char], Type)] -> TCM [Maybe QName]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Type -> TCMT IO (Maybe QName)
getTypeHead (Type -> TCMT IO (Maybe QName))
-> (Dom' Term ([Char], Type) -> Type)
-> Dom' Term ([Char], Type)
-> TCMT IO (Maybe QName)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Char], Type) -> Type
forall a b. (a, b) -> b
snd (([Char], Type) -> Type)
-> (Dom' Term ([Char], Type) -> ([Char], Type))
-> Dom' Term ([Char], Type)
-> Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dom' Term ([Char], Type) -> ([Char], Type)
forall t e. Dom' t e -> e
unDom) ([Dom' Term ([Char], Type)] -> TCM [Maybe QName])
-> [Dom' Term ([Char], Type)] -> TCM [Maybe QName]
forall a b. (a -> b) -> a -> b
$ (Dom' Term ([Char], Type) -> Bool)
-> [Dom' Term ([Char], Type)] -> [Dom' Term ([Char], Type)]
forall a. (a -> Bool) -> [a] -> [a]
filter Dom' Term ([Char], Type) -> Bool
forall a. LensHiding a => a -> Bool
visible ([Dom' Term ([Char], Type)] -> [Dom' Term ([Char], Type)])
-> [Dom' Term ([Char], Type)] -> [Dom' Term ([Char], Type)]
forall a b. (a -> b) -> a -> b
$ Tele (Dom Type) -> [Dom' Term ([Char], Type)]
forall t. Tele (Dom t) -> [Dom ([Char], t)]
telToList Tele (Dom Type)
tel
getTypeHead :: Type -> TCM (Maybe QName)
getTypeHead :: Type -> TCMT IO (Maybe QName)
getTypeHead Type
t = do
Maybe QName
res <- Type
-> (Blocker -> Type -> TCMT IO (Maybe QName))
-> (NotBlocked -> Type -> TCMT IO (Maybe QName))
-> TCMT IO (Maybe QName)
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
_ Type
_ -> Maybe QName -> TCMT IO (Maybe QName)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe QName
forall a. Maybe a
Nothing) ((NotBlocked -> Type -> TCMT IO (Maybe QName))
-> TCMT IO (Maybe QName))
-> (NotBlocked -> Type -> TCMT IO (Maybe QName))
-> TCMT IO (Maybe QName)
forall a b. (a -> b) -> a -> b
$ \ NotBlocked
nb Type
t -> do
case NotBlocked
nb of
NotBlocked
ReallyNotBlocked -> do
TelV Tele (Dom Type)
_ Type
core <- Int -> (Dom Type -> Bool) -> Type -> TCMT IO (TelV Type)
forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Int -> (Dom Type -> Bool) -> Type -> m (TelV Type)
telViewUpTo' (Int
0Int -> Int -> Int
forall a. Num a => a -> a -> a
-Int
1) (Bool -> Bool
not (Bool -> Bool) -> (Dom Type -> Bool) -> Dom Type -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dom Type -> Bool
forall a. LensHiding a => a -> Bool
visible) Type
t
case Type -> Term
forall t a. Type'' t a -> a
unEl Type
core of
Def QName
q Elims
_ -> Maybe QName -> TCMT IO (Maybe QName)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe QName -> TCMT IO (Maybe QName))
-> Maybe QName -> TCMT IO (Maybe QName)
forall a b. (a -> b) -> a -> b
$ QName -> Maybe QName
forall a. a -> Maybe a
Just QName
q
Term
_ -> Maybe QName -> TCMT IO (Maybe QName)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe QName
forall a. Maybe a
Nothing
NotBlocked
_ -> Maybe QName -> TCMT IO (Maybe QName)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe QName
forall a. Maybe a
Nothing
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.check.term.con" Int
80 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
hcat ([TCMT IO Doc] -> TCMT IO Doc) -> [TCMT IO Doc] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"getTypeHead(" TCMT IO Doc -> [TCMT IO Doc] -> [TCMT IO Doc]
forall a. a -> [a] -> [a]
: Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
t TCMT IO Doc -> [TCMT IO Doc] -> [TCMT IO Doc]
forall a. a -> [a] -> [a]
: TCMT IO Doc
") = " TCMT IO Doc -> [TCMT IO Doc] -> [TCMT IO Doc]
forall a. a -> [a] -> [a]
: Maybe QName -> TCMT IO Doc
forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty Maybe QName
res TCMT IO Doc -> [TCMT IO Doc] -> [TCMT IO Doc]
forall a. a -> [a] -> [a]
: []
Maybe QName -> TCMT IO (Maybe QName)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe QName
res
checkUnambiguousProjectionApplication :: Comparison -> A.Expr -> Type -> QName -> ProjOrigin -> A.Expr -> [NamedArg A.Expr] -> TCM Term
checkUnambiguousProjectionApplication :: Comparison
-> Expr
-> Type
-> QName
-> ProjOrigin
-> Expr
-> [NamedArg Expr]
-> TCM Term
checkUnambiguousProjectionApplication Comparison
cmp Expr
e Type
t QName
x ProjOrigin
o Expr
hd [NamedArg Expr]
args = do
let fallback :: TCM Term
fallback = Comparison -> Expr -> Type -> Expr -> [NamedArg Expr] -> TCM Term
checkHeadApplication Comparison
cmp Expr
e Type
t Expr
hd [NamedArg Expr]
args
case (ProjOrigin
o, [NamedArg Expr]
args) of
(ProjOrigin
ProjPostfix, NamedArg Expr
arg : [NamedArg Expr]
rest) -> do
TCMT IO (Maybe Projection)
-> TCM Term -> (Projection -> TCM Term) -> TCM Term
forall (m :: * -> *) a b.
Monad m =>
m (Maybe a) -> m b -> (a -> m b) -> m b
caseMaybeM (QName -> TCMT IO (Maybe Projection)
forall (m :: * -> *).
HasConstInfo m =>
QName -> m (Maybe Projection)
isProjection QName
x) TCM Term
fallback ((Projection -> TCM Term) -> TCM Term)
-> (Projection -> TCM Term) -> TCM Term
forall a b. (a -> b) -> a -> b
$ \ Projection
pr -> do
Comparison -> Expr -> Type -> Expr -> [NamedArg Expr] -> TCM Term
checkHeadApplication Comparison
cmp Expr
e Type
t Expr
hd (ArgInfo -> NamedArg Expr -> NamedArg Expr
forall a. LensArgInfo a => ArgInfo -> a -> a
setArgInfo (Projection -> ArgInfo
projArgInfo Projection
pr) NamedArg Expr
arg NamedArg Expr -> [NamedArg Expr] -> [NamedArg Expr]
forall a. a -> [a] -> [a]
: [NamedArg Expr]
rest)
(ProjOrigin, [NamedArg Expr])
_ -> TCM Term
fallback
inferProjApp :: A.Expr -> ProjOrigin -> List1 QName -> A.Args -> TCM (Term, Type)
inferProjApp :: Expr
-> ProjOrigin -> List1 QName -> [NamedArg Expr] -> TCM (Term, Type)
inferProjApp Expr
e ProjOrigin
o List1 QName
ds [NamedArg Expr]
args0 = do
(Term
v, Type
t, CheckedTarget
_) <- Expr
-> ProjOrigin
-> List1 QName
-> [NamedArg Expr]
-> Maybe (Comparison, Type)
-> TCM (Term, Type, CheckedTarget)
inferOrCheckProjApp Expr
e ProjOrigin
o List1 QName
ds [NamedArg Expr]
args0 Maybe (Comparison, Type)
forall a. Maybe a
Nothing
(Term, Type) -> TCM (Term, Type)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Term
v, Type
t)
checkProjApp :: Comparison -> A.Expr -> ProjOrigin -> List1 QName -> A.Args -> Type -> TCM Term
checkProjApp :: Comparison
-> Expr
-> ProjOrigin
-> List1 QName
-> [NamedArg Expr]
-> Type
-> TCM Term
checkProjApp Comparison
cmp Expr
e ProjOrigin
o List1 QName
ds [NamedArg Expr]
args0 Type
t = do
(Term
v, Type
ti, CheckedTarget
targetCheck) <- Expr
-> ProjOrigin
-> List1 QName
-> [NamedArg Expr]
-> Maybe (Comparison, Type)
-> TCM (Term, Type, CheckedTarget)
inferOrCheckProjApp Expr
e ProjOrigin
o List1 QName
ds [NamedArg Expr]
args0 ((Comparison, Type) -> Maybe (Comparison, Type)
forall a. a -> Maybe a
Just (Comparison
cmp, Type
t))
Comparison -> CheckedTarget -> Term -> Type -> Type -> TCM Term
coerce' Comparison
cmp CheckedTarget
targetCheck Term
v Type
ti Type
t
checkProjAppToKnownPrincipalArg :: Comparison -> A.Expr -> ProjOrigin -> List1 QName -> A.Args -> Type -> Int -> Term -> Type -> PrincipalArgTypeMetas -> TCM Term
checkProjAppToKnownPrincipalArg :: Comparison
-> Expr
-> ProjOrigin
-> List1 QName
-> [NamedArg Expr]
-> Type
-> Int
-> Term
-> Type
-> PrincipalArgTypeMetas
-> TCM Term
checkProjAppToKnownPrincipalArg Comparison
cmp Expr
e ProjOrigin
o List1 QName
ds [NamedArg Expr]
args0 Type
t Int
k Term
v0 Type
pt PrincipalArgTypeMetas
patm = do
(Term
v, Type
ti, CheckedTarget
targetCheck) <- Expr
-> ProjOrigin
-> List1 QName
-> [NamedArg Expr]
-> Maybe (Comparison, Type)
-> Int
-> Term
-> Type
-> Maybe PrincipalArgTypeMetas
-> TCM (Term, Type, CheckedTarget)
inferOrCheckProjAppToKnownPrincipalArg Expr
e ProjOrigin
o List1 QName
ds [NamedArg Expr]
args0 ((Comparison, Type) -> Maybe (Comparison, Type)
forall a. a -> Maybe a
Just (Comparison
cmp, Type
t)) Int
k Term
v0 Type
pt (PrincipalArgTypeMetas -> Maybe PrincipalArgTypeMetas
forall a. a -> Maybe a
Just PrincipalArgTypeMetas
patm)
Comparison -> CheckedTarget -> Term -> Type -> Type -> TCM Term
coerce' Comparison
cmp CheckedTarget
targetCheck Term
v Type
ti Type
t
inferOrCheckProjApp
:: A.Expr
-> ProjOrigin
-> List1 QName
-> A.Args
-> Maybe (Comparison, Type)
-> TCM (Term, Type, CheckedTarget)
inferOrCheckProjApp :: Expr
-> ProjOrigin
-> List1 QName
-> [NamedArg Expr]
-> Maybe (Comparison, Type)
-> TCM (Term, Type, CheckedTarget)
inferOrCheckProjApp Expr
e ProjOrigin
o List1 QName
ds [NamedArg Expr]
args Maybe (Comparison, Type)
mt = do
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.proj.amb" Int
20 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"checking ambiguous projection"
, [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char] -> TCMT IO Doc) -> [Char] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char]
" ds = " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ List1 QName -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow List1 QName
ds
, [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text [Char]
" args = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
sep ((NamedArg Expr -> TCMT IO Doc) -> [NamedArg Expr] -> [TCMT IO Doc]
forall a b. (a -> b) -> [a] -> [b]
map NamedArg Expr -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => NamedArg Expr -> m Doc
prettyTCM [NamedArg Expr]
args)
, [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text [Char]
" t = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Maybe (Comparison, Type)
-> TCMT IO Doc
-> ((Comparison, Type) -> TCMT IO Doc)
-> TCMT IO Doc
forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe Maybe (Comparison, Type)
mt TCMT IO Doc
"Nothing" (Comparison, Type) -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => (Comparison, Type) -> m Doc
prettyTCM
]
let cmp :: Comparison
cmp = Maybe (Comparison, Type)
-> Comparison -> ((Comparison, Type) -> Comparison) -> Comparison
forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe Maybe (Comparison, Type)
mt Comparison
CmpEq (Comparison, Type) -> Comparison
forall a b. (a, b) -> a
fst
postpone :: Blocker -> TCM (Term, Type, CheckedTarget)
postpone Blocker
b = do
Type
tc <- Maybe (Comparison, Type)
-> TCMT IO Type
-> ((Comparison, Type) -> TCMT IO Type)
-> TCMT IO Type
forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe Maybe (Comparison, Type)
mt TCMT IO Type
newTypeMeta_ (Type -> TCMT IO Type
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Type -> TCMT IO Type)
-> ((Comparison, Type) -> Type)
-> (Comparison, Type)
-> TCMT IO Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Comparison, Type) -> Type
forall a b. (a, b) -> b
snd)
Term
v <- TypeCheckingProblem -> Blocker -> TCM Term
postponeTypeCheckingProblem (Comparison -> Expr -> Type -> TypeCheckingProblem
CheckExpr Comparison
cmp Expr
e Type
tc) Blocker
b
(Term, Type, CheckedTarget) -> TCM (Term, Type, CheckedTarget)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Term
v, Type
tc, CheckedTarget
NotCheckedTarget)
case ((Int, NamedArg Expr) -> Bool)
-> [(Int, NamedArg Expr)] -> [(Int, NamedArg Expr)]
forall a. (a -> Bool) -> [a] -> [a]
filter (NamedArg Expr -> Bool
forall a. LensHiding a => a -> Bool
visible (NamedArg Expr -> Bool)
-> ((Int, NamedArg Expr) -> NamedArg Expr)
-> (Int, NamedArg Expr)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, NamedArg Expr) -> NamedArg Expr
forall a b. (a, b) -> b
snd) ([(Int, NamedArg Expr)] -> [(Int, NamedArg Expr)])
-> [(Int, NamedArg Expr)] -> [(Int, NamedArg Expr)]
forall a b. (a -> b) -> a -> b
$ [Int] -> [NamedArg Expr] -> [(Int, NamedArg Expr)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0..] [NamedArg Expr]
args of
[] -> Maybe (Comparison, Type)
-> TCM (Term, Type, CheckedTarget)
-> ((Comparison, Type) -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget)
forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe Maybe (Comparison, Type)
mt (List1 QName -> TCM (Term, Type, CheckedTarget)
forall a. List1 QName -> TCM a
refuseProjNotApplied List1 QName
ds) (((Comparison, Type) -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget))
-> ((Comparison, Type) -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget)
forall a b. (a -> b) -> a -> b
$ \ (Comparison
cmp , Type
t) -> do
TelV Tele (Dom Type)
_ptel Type
core <- Int -> (Dom Type -> Bool) -> Type -> TCMT IO (TelV Type)
forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Int -> (Dom Type -> Bool) -> Type -> m (TelV Type)
telViewUpTo' (-Int
1) (Bool -> Bool
not (Bool -> Bool) -> (Dom Type -> Bool) -> Dom Type -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dom Type -> Bool
forall a. LensHiding a => a -> Bool
visible) Type
t
Type
-> (Blocker -> Type -> TCM (Term, Type, CheckedTarget))
-> (NotBlocked -> Type -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget)
forall t (m :: * -> *) a.
(Reduce t, IsMeta t, MonadReduce m) =>
t -> (Blocker -> t -> m a) -> (NotBlocked -> t -> m a) -> m a
ifBlocked Type
core (\ Blocker
m Type
_ -> Blocker -> TCM (Term, Type, CheckedTarget)
postpone Blocker
m) ((NotBlocked -> Type -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget))
-> (NotBlocked -> Type -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget)
forall a b. (a -> b) -> a -> b
$ \ NotBlocked
_ Type
core -> do
Type
-> (Type -> TCM (Term, Type, CheckedTarget))
-> (Dom Type -> Abs Type -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget)
forall (m :: * -> *) a.
MonadReduce m =>
Type -> (Type -> m a) -> (Dom Type -> Abs Type -> m a) -> m a
ifNotPiType Type
core (\ Type
_ -> List1 QName -> TCM (Term, Type, CheckedTarget)
forall a. List1 QName -> TCM a
refuseProjNotApplied List1 QName
ds) ((Dom Type -> Abs Type -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget))
-> (Dom Type -> Abs Type -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget)
forall a b. (a -> b) -> a -> b
$ \ Dom Type
dom Abs Type
_b -> do
Type
-> (Blocker -> Type -> TCM (Term, Type, CheckedTarget))
-> (NotBlocked -> Type -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget)
forall t (m :: * -> *) a.
(Reduce t, IsMeta t, MonadReduce m) =>
t -> (Blocker -> t -> m a) -> (NotBlocked -> t -> m a) -> m a
ifBlocked (Dom Type -> Type
forall t e. Dom' t e -> e
unDom Dom Type
dom) (\ Blocker
m Type
_ -> Blocker -> TCM (Term, Type, CheckedTarget)
postpone Blocker
m) ((NotBlocked -> Type -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget))
-> (NotBlocked -> Type -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget)
forall a b. (a -> b) -> a -> b
$ \ NotBlocked
_ Type
ta -> do
TCMT IO (Maybe (QName, [Arg Term], Defn))
-> TCM (Term, Type, CheckedTarget)
-> ((QName, [Arg Term], Defn) -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget)
forall (m :: * -> *) a b.
Monad m =>
m (Maybe a) -> m b -> (a -> m b) -> m b
caseMaybeM (Type -> TCMT IO (Maybe (QName, [Arg Term], Defn))
forall (m :: * -> *).
PureTCM m =>
Type -> m (Maybe (QName, [Arg Term], Defn))
isRecordType Type
ta) (List1 QName
-> Maybe Term -> Type -> TCM (Term, Type, CheckedTarget)
forall a. List1 QName -> Maybe Term -> Type -> TCM a
refuseProjNotRecordType List1 QName
ds Maybe Term
forall a. Maybe a
Nothing Type
ta) (((QName, [Arg Term], Defn) -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget))
-> ((QName, [Arg Term], Defn) -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget)
forall a b. (a -> b) -> a -> b
$ \ (QName
_q, [Arg Term]
_pars, Defn
defn) -> do
case Defn
defn of
Record { recFields :: Defn -> [Dom QName]
recFields = [Dom QName]
fs } -> do
case [Dom QName] -> (Dom QName -> Maybe QName) -> [QName]
forall a b. [a] -> (a -> Maybe b) -> [b]
forMaybe [Dom QName]
fs ((Dom QName -> Maybe QName) -> [QName])
-> (Dom QName -> Maybe QName) -> [QName]
forall a b. (a -> b) -> a -> b
$ \ Dom QName
f -> (QName -> Bool) -> List1 QName -> Maybe QName
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
Fold.find (Dom QName -> QName
forall t e. Dom' t e -> e
unDom Dom QName
f QName -> QName -> Bool
forall a. Eq a => a -> a -> Bool
==) List1 QName
ds of
[] -> List1 QName -> TCM (Term, Type, CheckedTarget)
forall a. List1 QName -> TCM a
refuseProjNoMatching List1 QName
ds
[QName
d] -> do
QName -> TCMT IO ()
storeDisambiguatedProjection QName
d
(, Type
t, Maybe ProblemId -> CheckedTarget
CheckedTarget Maybe ProblemId
forall a. Maybe a
Nothing) (Term -> (Term, Type, CheckedTarget))
-> TCM Term -> TCM (Term, Type, CheckedTarget)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
Comparison -> Expr -> Type -> Expr -> [NamedArg Expr] -> TCM Term
checkHeadApplication Comparison
cmp Expr
e Type
t (ProjOrigin -> AmbiguousQName -> Expr
A.Proj ProjOrigin
o (AmbiguousQName -> Expr) -> AmbiguousQName -> Expr
forall a b. (a -> b) -> a -> b
$ QName -> AmbiguousQName
unambiguous QName
d) [NamedArg Expr]
args
[QName]
_ -> TCM (Term, Type, CheckedTarget)
forall a. HasCallStack => a
__IMPOSSIBLE__
Defn
_ -> TCM (Term, Type, CheckedTarget)
forall a. HasCallStack => a
__IMPOSSIBLE__
((Int
k, NamedArg Expr
arg) : [(Int, NamedArg Expr)]
_) -> do
(Term
v0, Type
ta) <- Expr -> TCM (Term, Type)
inferExpr (Expr -> TCM (Term, Type)) -> Expr -> TCM (Term, Type)
forall a b. (a -> b) -> a -> b
$ NamedArg Expr -> Expr
forall a. NamedArg a -> a
namedArg NamedArg Expr
arg
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.proj.amb" Int
25 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
" principal arg " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> NamedArg Expr -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => NamedArg Expr -> m Doc
prettyTCM NamedArg Expr
arg
, TCMT IO Doc
" has type " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
ta
]
Expr
-> ProjOrigin
-> List1 QName
-> [NamedArg Expr]
-> Maybe (Comparison, Type)
-> Int
-> Term
-> Type
-> Maybe PrincipalArgTypeMetas
-> TCM (Term, Type, CheckedTarget)
inferOrCheckProjAppToKnownPrincipalArg Expr
e ProjOrigin
o List1 QName
ds [NamedArg Expr]
args Maybe (Comparison, Type)
mt Int
k Term
v0 Type
ta Maybe PrincipalArgTypeMetas
forall a. Maybe a
Nothing
inferOrCheckProjAppToKnownPrincipalArg
:: A.Expr
-> ProjOrigin
-> List1 QName
-> A.Args
-> Maybe (Comparison, Type)
-> Int
-> Term
-> Type
-> Maybe PrincipalArgTypeMetas
-> TCM (Term, Type, CheckedTarget)
inferOrCheckProjAppToKnownPrincipalArg :: Expr
-> ProjOrigin
-> List1 QName
-> [NamedArg Expr]
-> Maybe (Comparison, Type)
-> Int
-> Term
-> Type
-> Maybe PrincipalArgTypeMetas
-> TCM (Term, Type, CheckedTarget)
inferOrCheckProjAppToKnownPrincipalArg Expr
e ProjOrigin
o List1 QName
ds [NamedArg Expr]
args Maybe (Comparison, Type)
mt Int
k Term
v0 Type
ta Maybe PrincipalArgTypeMetas
mpatm = do
let cmp :: Comparison
cmp = Maybe (Comparison, Type)
-> Comparison -> ((Comparison, Type) -> Comparison) -> Comparison
forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe Maybe (Comparison, Type)
mt Comparison
CmpEq (Comparison, Type) -> Comparison
forall a b. (a, b) -> a
fst
postpone :: Blocker -> PrincipalArgTypeMetas -> TCM (Term, Type, CheckedTarget)
postpone Blocker
b PrincipalArgTypeMetas
patm = do
Type
tc <- Maybe (Comparison, Type)
-> TCMT IO Type
-> ((Comparison, Type) -> TCMT IO Type)
-> TCMT IO Type
forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe Maybe (Comparison, Type)
mt TCMT IO Type
newTypeMeta_ (Type -> TCMT IO Type
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Type -> TCMT IO Type)
-> ((Comparison, Type) -> Type)
-> (Comparison, Type)
-> TCMT IO Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Comparison, Type) -> Type
forall a b. (a, b) -> b
snd)
Term
v <- TypeCheckingProblem -> Blocker -> TCM Term
postponeTypeCheckingProblem (Comparison
-> Expr
-> ProjOrigin
-> List1 QName
-> [NamedArg Expr]
-> Type
-> Int
-> Term
-> Type
-> PrincipalArgTypeMetas
-> TypeCheckingProblem
CheckProjAppToKnownPrincipalArg Comparison
cmp Expr
e ProjOrigin
o List1 QName
ds [NamedArg Expr]
args Type
tc Int
k Term
v0 Type
ta PrincipalArgTypeMetas
patm) Blocker
b
(Term, Type, CheckedTarget) -> TCM (Term, Type, CheckedTarget)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Term
v, Type
tc, CheckedTarget
NotCheckedTarget)
patm :: PrincipalArgTypeMetas
patm@(PrincipalArgTypeMetas [Arg Term]
vargs Type
ta) <- case Maybe PrincipalArgTypeMetas
mpatm of
Just PrincipalArgTypeMetas
patm -> PrincipalArgTypeMetas -> TCMT IO PrincipalArgTypeMetas
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return PrincipalArgTypeMetas
patm
Maybe PrincipalArgTypeMetas
Nothing -> ([Arg Term] -> Type -> PrincipalArgTypeMetas)
-> ([Arg Term], Type) -> PrincipalArgTypeMetas
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry [Arg Term] -> Type -> PrincipalArgTypeMetas
PrincipalArgTypeMetas (([Arg Term], Type) -> PrincipalArgTypeMetas)
-> TCMT IO ([Arg Term], Type) -> TCMT IO PrincipalArgTypeMetas
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> (Hiding -> Bool) -> Type -> TCMT IO ([Arg Term], Type)
forall (m :: * -> *).
(PureTCM m, MonadMetaSolver m, MonadTCM m) =>
Int -> (Hiding -> Bool) -> Type -> m ([Arg Term], Type)
implicitArgs (-Int
1) (Bool -> Bool
not (Bool -> Bool) -> (Hiding -> Bool) -> Hiding -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hiding -> Bool
forall a. LensHiding a => a -> Bool
visible) Type
ta
let v :: Term
v = Term
v0 Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
`apply` [Arg Term]
vargs
Type
-> (Blocker -> Type -> TCM (Term, Type, CheckedTarget))
-> (NotBlocked -> Type -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget)
forall t (m :: * -> *) a.
(Reduce t, IsMeta t, MonadReduce m) =>
t -> (Blocker -> t -> m a) -> (NotBlocked -> t -> m a) -> m a
ifBlocked Type
ta (\ Blocker
m Type
_ -> Blocker -> PrincipalArgTypeMetas -> TCM (Term, Type, CheckedTarget)
postpone Blocker
m PrincipalArgTypeMetas
patm) ((NotBlocked -> Type -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget))
-> (NotBlocked -> Type -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget)
forall a b. (a -> b) -> a -> b
$ \ NotBlocked
_ Type
ta -> do
TCMT IO (Maybe (QName, [Arg Term], Defn))
-> TCM (Term, Type, CheckedTarget)
-> ((QName, [Arg Term], Defn) -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget)
forall (m :: * -> *) a b.
Monad m =>
m (Maybe a) -> m b -> (a -> m b) -> m b
caseMaybeM (Type -> TCMT IO (Maybe (QName, [Arg Term], Defn))
forall (m :: * -> *).
PureTCM m =>
Type -> m (Maybe (QName, [Arg Term], Defn))
isRecordType Type
ta) (List1 QName
-> Maybe Term -> Type -> TCM (Term, Type, CheckedTarget)
forall a. List1 QName -> Maybe Term -> Type -> TCM a
refuseProjNotRecordType List1 QName
ds (Term -> Maybe Term
forall a. a -> Maybe a
Just Term
v0) Type
ta) (((QName, [Arg Term], Defn) -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget))
-> ((QName, [Arg Term], Defn) -> TCM (Term, Type, CheckedTarget))
-> TCM (Term, Type, CheckedTarget)
forall a b. (a -> b) -> a -> b
$ \ (QName
q, [Arg Term]
_pars0, Defn
_) -> do
let try :: QName
-> MaybeT
(TCMT IO) (QName, (QName, ([Arg Term], (Dom Type, Term, Type))))
try QName
d = do
[Char] -> Int -> TCMT IO Doc -> MaybeT (TCMT IO) ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.proj.amb" Int
30 (TCMT IO Doc -> MaybeT (TCMT IO) ())
-> TCMT IO Doc -> MaybeT (TCMT IO) ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char] -> TCMT IO Doc) -> [Char] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char]
"trying projection " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ QName -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow QName
d
, TCMT IO Doc
" td = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO (Maybe Type)
-> TCMT IO Doc -> (Type -> TCMT IO Doc) -> TCMT IO Doc
forall (m :: * -> *) a b.
Monad m =>
m (Maybe a) -> m b -> (a -> m b) -> m b
caseMaybeM (QName -> Type -> TCMT IO (Maybe Type)
forall (m :: * -> *). PureTCM m => QName -> Type -> m (Maybe Type)
getDefType QName
d Type
ta) TCMT IO Doc
"Nothing" Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM
]
Definition
def <- TCMT IO Definition -> MaybeT (TCMT IO) Definition
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO Definition -> MaybeT (TCMT IO) Definition)
-> TCMT IO Definition -> MaybeT (TCMT IO) Definition
forall a b. (a -> b) -> a -> b
$ QName -> TCMT IO Definition
forall (m :: * -> *). HasConstInfo m => QName -> m Definition
getConstInfo QName
d
let isP :: Maybe Projection
isP = Defn -> Maybe Projection
isProjection_ (Defn -> Maybe Projection) -> Defn -> Maybe Projection
forall a b. (a -> b) -> a -> b
$ Definition -> Defn
theDef Definition
def
[Char] -> Int -> TCMT IO Doc -> MaybeT (TCMT IO) ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.proj.amb" Int
40 (TCMT IO Doc -> MaybeT (TCMT IO) ())
-> TCMT IO Doc -> MaybeT (TCMT IO) ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat ([TCMT IO Doc] -> TCMT IO Doc) -> [TCMT IO Doc] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$
[Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ( [Char]
" isProjection = " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Maybe Projection -> [Char] -> (Projection -> [Char]) -> [Char]
forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe Maybe Projection
isP [Char]
"no" ([Char] -> Projection -> [Char]
forall a b. a -> b -> a
const [Char]
"yes")
) TCMT IO Doc -> [TCMT IO Doc] -> [TCMT IO Doc]
forall a. a -> [a] -> [a]
: Maybe Projection
-> [TCMT IO Doc] -> (Projection -> [TCMT IO Doc]) -> [TCMT IO Doc]
forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe Maybe Projection
isP [] (\ Projection{ projProper :: Projection -> Maybe QName
projProper = Maybe QName
proper, projOrig :: Projection -> QName
projOrig = QName
orig } ->
[ [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char] -> TCMT IO Doc) -> [Char] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char]
" proper = " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Maybe QName -> [Char]
forall a. Show a => a -> [Char]
show Maybe QName
proper
, [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char] -> TCMT IO Doc) -> [Char] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char]
" orig = " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ QName -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow QName
orig
])
let orig :: QName
orig = Maybe Projection -> QName -> (Projection -> QName) -> QName
forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe Maybe Projection
isP QName
d Projection -> QName
projOrig
(Dom Type
dom, Term
u, Type
tb) <- TCMT IO (Maybe (Dom Type, Term, Type))
-> MaybeT (TCMT IO) (Dom Type, Term, Type)
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (Term
-> Type
-> ProjOrigin
-> QName
-> TCMT IO (Maybe (Dom Type, Term, Type))
forall (m :: * -> *).
PureTCM m =>
Term
-> Type -> ProjOrigin -> QName -> m (Maybe (Dom Type, Term, Type))
projectTyped Term
v Type
ta ProjOrigin
o QName
d TCMT IO (Maybe (Dom Type, Term, Type))
-> (TCErr -> TCMT IO (Maybe (Dom Type, Term, Type)))
-> TCMT IO (Maybe (Dom Type, Term, Type))
forall a. TCMT IO a -> (TCErr -> TCMT IO a) -> TCMT IO a
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError` \ TCErr
_ -> Maybe (Dom Type, Term, Type)
-> TCMT IO (Maybe (Dom Type, Term, Type))
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Dom Type, Term, Type)
forall a. Maybe a
Nothing)
[Char] -> Int -> TCMT IO Doc -> MaybeT (TCMT IO) ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.proj.amb" Int
30 (TCMT IO Doc -> MaybeT (TCMT IO) ())
-> TCMT IO Doc -> MaybeT (TCMT IO) ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
" dom = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Dom Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Dom Type -> m Doc
prettyTCM Dom Type
dom
, TCMT IO Doc
" u = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Term -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Term -> m Doc
prettyTCM Term
u
, TCMT IO Doc
" tb = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
tb
]
(QName
q', [Arg Term]
pars, Defn
_) <- TCMT IO (Maybe (QName, [Arg Term], Defn))
-> MaybeT (TCMT IO) (QName, [Arg Term], Defn)
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (TCMT IO (Maybe (QName, [Arg Term], Defn))
-> MaybeT (TCMT IO) (QName, [Arg Term], Defn))
-> TCMT IO (Maybe (QName, [Arg Term], Defn))
-> MaybeT (TCMT IO) (QName, [Arg Term], Defn)
forall a b. (a -> b) -> a -> b
$ Type -> TCMT IO (Maybe (QName, [Arg Term], Defn))
forall (m :: * -> *).
PureTCM m =>
Type -> m (Maybe (QName, [Arg Term], Defn))
isRecordType (Type -> TCMT IO (Maybe (QName, [Arg Term], Defn)))
-> Type -> TCMT IO (Maybe (QName, [Arg Term], Defn))
forall a b. (a -> b) -> a -> b
$ Dom Type -> Type
forall t e. Dom' t e -> e
unDom Dom Type
dom
[Char] -> Int -> TCMT IO Doc -> MaybeT (TCMT IO) ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.proj.amb" Int
30 (TCMT IO Doc -> MaybeT (TCMT IO) ())
-> TCMT IO Doc -> MaybeT (TCMT IO) ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
" q = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => QName -> m Doc
prettyTCM QName
q
, TCMT IO Doc
" q' = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => QName -> m Doc
prettyTCM QName
q'
]
Bool -> MaybeT (TCMT IO) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (QName
q QName -> QName -> Bool
forall a. Eq a => a -> a -> Bool
== QName
q')
let tfull :: Type
tfull = Definition -> Type
defType Definition
def
TelV Tele (Dom Type)
tel Type
_ <- TCMT IO (TelV Type) -> MaybeT (TCMT IO) (TelV Type)
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO (TelV Type) -> MaybeT (TCMT IO) (TelV Type))
-> TCMT IO (TelV Type) -> MaybeT (TCMT IO) (TelV Type)
forall a b. (a -> b) -> a -> b
$ Int -> (Dom Type -> Bool) -> Type -> TCMT IO (TelV Type)
forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Int -> (Dom Type -> Bool) -> Type -> m (TelV Type)
telViewUpTo' (-Int
1) (Bool -> Bool
not (Bool -> Bool) -> (Dom Type -> Bool) -> Dom Type -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dom Type -> Bool
forall a. LensHiding a => a -> Bool
visible) Type
tfull
[Char] -> Int -> TCMT IO Doc -> MaybeT (TCMT IO) ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.proj.amb" Int
30 (TCMT IO Doc -> MaybeT (TCMT IO) ())
-> TCMT IO Doc -> MaybeT (TCMT IO) ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char] -> TCMT IO Doc) -> [Char] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char]
" size tel = " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show (Tele (Dom Type) -> Int
forall a. Sized a => a -> Int
size Tele (Dom Type)
tel)
, [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text ([Char] -> TCMT IO Doc) -> [Char] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Char]
" size pars = " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show ([Arg Term] -> Int
forall a. Sized a => a -> Int
size [Arg Term]
pars)
]
Bool -> MaybeT (TCMT IO) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> MaybeT (TCMT IO) ())
-> MaybeT (TCMT IO) Bool -> MaybeT (TCMT IO) ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< do Maybe TypeError -> Bool
forall a. Maybe a -> Bool
isNothing (Maybe TypeError -> Bool)
-> MaybeT (TCMT IO) (Maybe TypeError) -> MaybeT (TCMT IO) Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do TCMT IO (Maybe TypeError) -> MaybeT (TCMT IO) (Maybe TypeError)
forall (m :: * -> *) a. Monad m => m a -> MaybeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (TCMT IO (Maybe TypeError) -> MaybeT (TCMT IO) (Maybe TypeError))
-> TCMT IO (Maybe TypeError) -> MaybeT (TCMT IO) (Maybe TypeError)
forall a b. (a -> b) -> a -> b
$ QName -> Definition -> TCMT IO (Maybe TypeError)
forall (m :: * -> *).
MonadConversion m =>
QName -> Definition -> m (Maybe TypeError)
checkModality' QName
d Definition
def
(QName, (QName, ([Arg Term], (Dom Type, Term, Type))))
-> MaybeT
(TCMT IO) (QName, (QName, ([Arg Term], (Dom Type, Term, Type))))
forall a. a -> MaybeT (TCMT IO) a
forall (m :: * -> *) a. Monad m => a -> m a
return (QName
orig, (QName
d, ([Arg Term]
pars, (Dom Type
dom, Term
u, Type
tb))))
[[(QName, (QName, ([Arg Term], (Dom Type, Term, Type))))]]
cands <- ((QName, (QName, ([Arg Term], (Dom Type, Term, Type)))) -> QName)
-> [(QName, (QName, ([Arg Term], (Dom Type, Term, Type))))]
-> [[(QName, (QName, ([Arg Term], (Dom Type, Term, Type))))]]
forall b a. Ord b => (a -> b) -> [a] -> [[a]]
groupOn (QName, (QName, ([Arg Term], (Dom Type, Term, Type)))) -> QName
forall a b. (a, b) -> a
fst ([(QName, (QName, ([Arg Term], (Dom Type, Term, Type))))]
-> [[(QName, (QName, ([Arg Term], (Dom Type, Term, Type))))]])
-> (List1
(Maybe (QName, (QName, ([Arg Term], (Dom Type, Term, Type)))))
-> [(QName, (QName, ([Arg Term], (Dom Type, Term, Type))))])
-> List1
(Maybe (QName, (QName, ([Arg Term], (Dom Type, Term, Type)))))
-> [[(QName, (QName, ([Arg Term], (Dom Type, Term, Type))))]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. List1
(Maybe (QName, (QName, ([Arg Term], (Dom Type, Term, Type)))))
-> [(QName, (QName, ([Arg Term], (Dom Type, Term, Type))))]
forall a. List1 (Maybe a) -> [a]
List1.catMaybes (List1
(Maybe (QName, (QName, ([Arg Term], (Dom Type, Term, Type)))))
-> [[(QName, (QName, ([Arg Term], (Dom Type, Term, Type))))]])
-> TCMT
IO
(List1
(Maybe (QName, (QName, ([Arg Term], (Dom Type, Term, Type))))))
-> TCMT
IO [[(QName, (QName, ([Arg Term], (Dom Type, Term, Type))))]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (QName
-> TCMT
IO (Maybe (QName, (QName, ([Arg Term], (Dom Type, Term, Type))))))
-> List1 QName
-> TCMT
IO
(List1
(Maybe (QName, (QName, ([Arg Term], (Dom Type, Term, Type))))))
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> NonEmpty a -> m (NonEmpty b)
mapM (MaybeT
(TCMT IO) (QName, (QName, ([Arg Term], (Dom Type, Term, Type))))
-> TCMT
IO (Maybe (QName, (QName, ([Arg Term], (Dom Type, Term, Type)))))
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT
(TCMT IO) (QName, (QName, ([Arg Term], (Dom Type, Term, Type))))
-> TCMT
IO (Maybe (QName, (QName, ([Arg Term], (Dom Type, Term, Type))))))
-> (QName
-> MaybeT
(TCMT IO) (QName, (QName, ([Arg Term], (Dom Type, Term, Type)))))
-> QName
-> TCMT
IO (Maybe (QName, (QName, ([Arg Term], (Dom Type, Term, Type)))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QName
-> MaybeT
(TCMT IO) (QName, (QName, ([Arg Term], (Dom Type, Term, Type))))
try) List1 QName
ds
case [[(QName, (QName, ([Arg Term], (Dom Type, Term, Type))))]]
cands of
[] -> List1 QName -> TCM (Term, Type, CheckedTarget)
forall a. List1 QName -> TCM a
refuseProjNoMatching List1 QName
ds
[[]] -> List1 QName -> TCM (Term, Type, CheckedTarget)
forall a. List1 QName -> TCM a
refuseProjNoMatching List1 QName
ds
([(QName, (QName, ([Arg Term], (Dom Type, Term, Type))))]
_:[(QName, (QName, ([Arg Term], (Dom Type, Term, Type))))]
_:[[(QName, (QName, ([Arg Term], (Dom Type, Term, Type))))]]
_) -> List1 QName -> TCMT IO Doc -> TCM (Term, Type, CheckedTarget)
forall a. List1 QName -> TCMT IO Doc -> TCM a
refuseProj List1 QName
ds (TCMT IO Doc -> TCM (Term, Type, CheckedTarget))
-> TCMT IO Doc -> TCM (Term, Type, CheckedTarget)
forall a b. (a -> b) -> a -> b
$ [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
fwords [Char]
"several matching candidates can be applied."
[ (QName
_orig, (QName
d, ([Arg Term]
pars, (Dom Type
_dom,Term
u,Type
tb)))) : [(QName, (QName, ([Arg Term], (Dom Type, Term, Type))))]
_ ] -> do
QName -> TCMT IO ()
storeDisambiguatedProjection QName
d
Type
tfull <- QName -> TCMT IO Type
forall (m :: * -> *).
(HasConstInfo m, ReadTCState m) =>
QName -> m Type
typeOfConst QName
d
([Arg Term]
_,Type
_) <- [NamedArg Expr] -> [Arg Term] -> Type -> TCMT IO ([Arg Term], Type)
checkKnownArguments (Int -> [NamedArg Expr] -> [NamedArg Expr]
forall a. Int -> [a] -> [a]
take Int
k [NamedArg Expr]
args) [Arg Term]
pars Type
tfull
let r :: Range
r = Expr -> Range
forall a. HasRange a => a -> Range
getRange Expr
e
args' :: [NamedArg Expr]
args' = Int -> [NamedArg Expr] -> [NamedArg Expr]
forall a. Int -> [a] -> [a]
drop (Int
k Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) [NamedArg Expr]
args
Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget)
z <- ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> TCM
(Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget))
forall e (m :: * -> *) a. ExceptT e m a -> m (Either e a)
runExceptT (ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> TCM
(Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget)))
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
-> TCM
(Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget))
forall a b. (a -> b) -> a -> b
$ Comparison
-> ExpandHidden
-> Range
-> [NamedArg Expr]
-> Type
-> Maybe Type
-> ExceptT
(ArgsCheckState [NamedArg Expr])
(TCMT IO)
(ArgsCheckState CheckedTarget)
checkArgumentsE Comparison
cmp ExpandHidden
ExpandLast Range
r [NamedArg Expr]
args' Type
tb ((Comparison, Type) -> Type
forall a b. (a, b) -> b
snd ((Comparison, Type) -> Type)
-> Maybe (Comparison, Type) -> Maybe Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (Comparison, Type)
mt)
case Either
(ArgsCheckState [NamedArg Expr]) (ArgsCheckState CheckedTarget)
z of
Right st :: ArgsCheckState CheckedTarget
st@(ACState MaybeRanges
_ Elims
_ [Maybe (Abs Constraint)]
_ Type
trest CheckedTarget
targetCheck) -> do
Term
v <- (Elims -> Term) -> ArgsCheckState CheckedTarget -> TCM Term
forall a. (Elims -> Term) -> ArgsCheckState a -> TCM Term
checkHeadConstraints (Term
u Term -> Elims -> Term
forall t. Apply t => t -> Elims -> t
`applyE`) ArgsCheckState CheckedTarget
st
(Term, Type, CheckedTarget) -> TCM (Term, Type, CheckedTarget)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Term
v, Type
trest, CheckedTarget
targetCheck)
Left ArgsCheckState [NamedArg Expr]
problem -> do
Type
tc <- Maybe (Comparison, Type)
-> TCMT IO Type
-> ((Comparison, Type) -> TCMT IO Type)
-> TCMT IO Type
forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe Maybe (Comparison, Type)
mt TCMT IO Type
newTypeMeta_ (Type -> TCMT IO Type
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Type -> TCMT IO Type)
-> ((Comparison, Type) -> Type)
-> (Comparison, Type)
-> TCMT IO Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Comparison, Type) -> Type
forall a b. (a, b) -> b
snd)
Term
v <- ArgsCheckState [NamedArg Expr]
-> Comparison
-> ExpandHidden
-> Range
-> [NamedArg Expr]
-> Type
-> (ArgsCheckState CheckedTarget -> TCM Term)
-> TCM Term
postponeArgs ArgsCheckState [NamedArg Expr]
problem Comparison
cmp ExpandHidden
ExpandLast Range
r [NamedArg Expr]
args' Type
tc ((ArgsCheckState CheckedTarget -> TCM Term) -> TCM Term)
-> (ArgsCheckState CheckedTarget -> TCM Term) -> TCM Term
forall a b. (a -> b) -> a -> b
$ \ st :: ArgsCheckState CheckedTarget
st@(ACState MaybeRanges
_ Elims
_ [Maybe (Abs Constraint)]
_ Type
trest CheckedTarget
targetCheck) -> do
Term
v <- (Elims -> Term) -> ArgsCheckState CheckedTarget -> TCM Term
forall a. (Elims -> Term) -> ArgsCheckState a -> TCM Term
checkHeadConstraints (Term
u Term -> Elims -> Term
forall t. Apply t => t -> Elims -> t
`applyE`) ArgsCheckState CheckedTarget
st
Comparison -> CheckedTarget -> Term -> Type -> Type -> TCM Term
coerce' Comparison
cmp CheckedTarget
targetCheck Term
v Type
trest Type
tc
(Term, Type, CheckedTarget) -> TCM (Term, Type, CheckedTarget)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Term
v, Type
tc, CheckedTarget
NotCheckedTarget)
refuseProj :: List1 QName -> TCM Doc -> TCM a
refuseProj :: forall a. List1 QName -> TCMT IO Doc -> TCM a
refuseProj List1 QName
ds TCMT IO Doc
reason = TypeError -> TCMT IO a
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO a) -> (Doc -> TypeError) -> Doc -> TCMT IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. List1 QName -> Doc -> TypeError
AmbiguousProjectionError List1 QName
ds (Doc -> TCMT IO a) -> TCMT IO Doc -> TCMT IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCMT IO Doc
reason
refuseProjNotApplied, refuseProjNoMatching :: List1 QName -> TCM a
refuseProjNotApplied :: forall a. List1 QName -> TCM a
refuseProjNotApplied List1 QName
ds = List1 QName -> TCMT IO Doc -> TCM a
forall a. List1 QName -> TCMT IO Doc -> TCM a
refuseProj List1 QName
ds (TCMT IO Doc -> TCM a) -> TCMT IO Doc -> TCM a
forall a b. (a -> b) -> a -> b
$ [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
fwords [Char]
"it is not applied to a visible argument"
refuseProjNoMatching :: forall a. List1 QName -> TCM a
refuseProjNoMatching List1 QName
ds = List1 QName -> TCMT IO Doc -> TCM a
forall a. List1 QName -> TCMT IO Doc -> TCM a
refuseProj List1 QName
ds (TCMT IO Doc -> TCM a) -> TCMT IO Doc -> TCM a
forall a b. (a -> b) -> a -> b
$ [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
fwords [Char]
"no matching candidate found"
refuseProjNotRecordType :: List1 QName -> Maybe Term -> Type -> TCM a
refuseProjNotRecordType :: forall a. List1 QName -> Maybe Term -> Type -> TCM a
refuseProjNotRecordType List1 QName
ds Maybe Term
pValue Type
pType = do
let dType :: TCMT IO Doc
dType = Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
pType
let dValue :: TCMT IO Doc
dValue = Maybe Term -> TCMT IO Doc -> (Term -> TCMT IO Doc) -> TCMT IO Doc
forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe Maybe Term
pValue (Doc -> TCMT IO Doc
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Doc
forall a. Null a => a
empty) Term -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Term -> m Doc
prettyTCM
List1 QName -> TCMT IO Doc -> TCM a
forall a. List1 QName -> TCMT IO Doc -> TCM a
refuseProj List1 QName
ds (TCMT IO Doc -> TCM a) -> TCMT IO Doc -> TCM a
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
fsep ([TCMT IO Doc] -> TCMT IO Doc) -> [TCMT IO Doc] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$
[TCMT IO Doc
"principal argument", TCMT IO Doc
dValue, TCMT IO Doc
"has type", TCMT IO Doc
dType, TCMT IO Doc
"while it should be of record type"]
checkUniv
:: UnivSize -> Univ -> Comparison -> A.Expr -> Type
-> QName -> Suffix -> [NamedArg A.Expr] -> TCM Term
checkUniv :: UnivSize
-> Univ
-> Comparison
-> Expr
-> Type
-> QName
-> Suffix
-> [NamedArg Expr]
-> TCM Term
checkUniv UnivSize
sz Univ
u Comparison
cmp Expr
e Type
t QName
q Suffix
suffix [NamedArg Expr]
args = do
(Term
v, Type
t0) <- UnivSize
-> Univ
-> Expr
-> QName
-> Suffix
-> [NamedArg Expr]
-> TCM (Term, Type)
inferUniv UnivSize
sz Univ
u Expr
e QName
q Suffix
suffix [NamedArg Expr]
args
Comparison -> Term -> Type -> Type -> TCM Term
forall (m :: * -> *).
(MonadConversion m, MonadTCM m) =>
Comparison -> Term -> Type -> Type -> m Term
coerce Comparison
cmp Term
v Type
t0 Type
t
inferUniv :: UnivSize -> Univ -> A.Expr -> QName -> Suffix -> [NamedArg A.Expr] -> TCM (Term, Type)
inferUniv :: UnivSize
-> Univ
-> Expr
-> QName
-> Suffix
-> [NamedArg Expr]
-> TCM (Term, Type)
inferUniv UnivSize
sz Univ
u Expr
e QName
q Suffix
s [NamedArg Expr]
args = do
Univ -> TCMT IO ()
univChecks Univ
u
case UnivSize
sz of
UnivSize
USmall -> Univ -> QName -> Suffix -> [NamedArg Expr] -> TCM (Term, Type)
inferLeveledSort Univ
u QName
q Suffix
s [NamedArg Expr]
args
UnivSize
ULarge -> Univ -> QName -> Suffix -> [NamedArg Expr] -> TCM (Term, Type)
inferUnivOmega Univ
u QName
q Suffix
s [NamedArg Expr]
args
univChecks :: Univ -> TCM ()
univChecks :: Univ -> TCMT IO ()
univChecks = \case
Univ
UProp -> TCMT IO Bool -> TCMT IO () -> TCMT IO ()
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
unlessM TCMT IO Bool
forall (m :: * -> *). HasOptions m => m Bool
isPropEnabled (TCMT IO () -> TCMT IO ()) -> TCMT IO () -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ TypeError -> TCMT IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError TypeError
NeedOptionProp
Univ
UType -> () -> TCMT IO ()
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
Univ
USSet -> TCMT IO Bool -> TCMT IO () -> TCMT IO ()
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
unlessM TCMT IO Bool
forall (m :: * -> *). HasOptions m => m Bool
isTwoLevelEnabled (TCMT IO () -> TCMT IO ()) -> TCMT IO () -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ TypeError -> TCMT IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError TypeError
NeedOptionTwoLevel
suffixToLevel :: Suffix -> Integer
suffixToLevel :: Suffix -> Integer
suffixToLevel = \case
Suffix
NoSuffix -> Integer
0
Suffix Integer
n -> Integer
n
inferLeveledSort ::
Univ
-> QName
-> Suffix
-> [NamedArg A.Expr]
-> TCM (Term, Type)
inferLeveledSort :: Univ -> QName -> Suffix -> [NamedArg Expr] -> TCM (Term, Type)
inferLeveledSort Univ
u QName
q Suffix
suffix = \case
[] -> do
let n :: Integer
n = Suffix -> Integer
suffixToLevel Suffix
suffix
(Term, Type) -> TCM (Term, Type)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Sort -> Term
Sort (Univ -> Level' Term -> Sort
forall t. Univ -> Level' t -> Sort' t
Univ Univ
u (Level' Term -> Sort) -> Level' Term -> Sort
forall a b. (a -> b) -> a -> b
$ Integer -> Level' Term
ClosedLevel Integer
n) , Sort -> Type
sort (Univ -> Level' Term -> Sort
forall t. Univ -> Level' t -> Sort' t
Univ (Univ -> Univ
univUniv Univ
u) (Level' Term -> Sort) -> Level' Term -> Sort
forall a b. (a -> b) -> a -> b
$ Integer -> Level' Term
ClosedLevel (Integer -> Level' Term) -> Integer -> Level' Term
forall a b. (a -> b) -> a -> b
$ Integer
n Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
1))
[NamedArg Expr
arg] -> do
Bool -> TCMT IO () -> TCMT IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (NamedArg Expr -> Bool
forall a. LensHiding a => a -> Bool
visible NamedArg Expr
arg) (TCMT IO () -> TCMT IO ()) -> TCMT IO () -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ TypeError -> TCMT IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO ()) -> TypeError -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ Type -> TypeError
WrongHidingInApplication (Type -> TypeError) -> Type -> TypeError
forall a b. (a -> b) -> a -> b
$ Sort -> Type
sort (Sort -> Type) -> Sort -> Type
forall a b. (a -> b) -> a -> b
$ Univ -> Level' Term -> Sort
forall t. Univ -> Level' t -> Sort' t
Univ Univ
u (Level' Term -> Sort) -> Level' Term -> Sort
forall a b. (a -> b) -> a -> b
$ Integer -> Level' Term
ClosedLevel Integer
0
TCMT IO Bool -> TCMT IO () -> TCMT IO ()
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
unlessM TCMT IO Bool
forall (m :: * -> *). HasOptions m => m Bool
hasUniversePolymorphism (TCMT IO () -> TCMT IO ()) -> TCMT IO () -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [Char] -> TCMT IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
[Char] -> m a
genericError
[Char]
"Use --universe-polymorphism to enable level arguments to Set"
Level' Term
l <- Relevance -> TCMT IO (Level' Term) -> TCMT IO (Level' Term)
forall (tcm :: * -> *) r a.
(MonadTCEnv tcm, LensRelevance r) =>
r -> tcm a -> tcm a
applyRelevanceToContext Relevance
NonStrict (TCMT IO (Level' Term) -> TCMT IO (Level' Term))
-> TCMT IO (Level' Term) -> TCMT IO (Level' Term)
forall a b. (a -> b) -> a -> b
$ NamedArg Expr -> TCMT IO (Level' Term)
checkLevel NamedArg Expr
arg
(Term, Type) -> TCM (Term, Type)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Sort -> Term
Sort (Sort -> Term) -> Sort -> Term
forall a b. (a -> b) -> a -> b
$ Univ -> Level' Term -> Sort
forall t. Univ -> Level' t -> Sort' t
Univ Univ
u Level' Term
l , Sort -> Type
sort (Univ -> Level' Term -> Sort
forall t. Univ -> Level' t -> Sort' t
Univ (Univ -> Univ
univUniv Univ
u) (Level' Term -> Sort) -> Level' Term -> Sort
forall a b. (a -> b) -> a -> b
$ Level' Term -> Level' Term
levelSuc Level' Term
l))
NamedArg Expr
arg : [NamedArg Expr]
_ -> TypeError -> TCM (Term, Type)
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCM (Term, Type))
-> (Doc -> TypeError) -> Doc -> TCM (Term, Type)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> TypeError
GenericDocError (Doc -> TCM (Term, Type)) -> TCMT IO Doc -> TCM (Term, Type)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
fsep
[ QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => QName -> m Doc
prettyTCM QName
q , TCMT IO Doc
"cannot be applied to more than one argument" ]
inferUnivOmega ::
Univ
-> QName
-> Suffix
-> [NamedArg A.Expr]
-> TCM (Term, Type)
inferUnivOmega :: Univ -> QName -> Suffix -> [NamedArg Expr] -> TCM (Term, Type)
inferUnivOmega Univ
u QName
q Suffix
suffix = \case
[] -> do
let n :: Integer
n = Suffix -> Integer
suffixToLevel Suffix
suffix
(Term, Type) -> TCM (Term, Type)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Sort -> Term
Sort (Univ -> Integer -> Sort
forall t. Univ -> Integer -> Sort' t
Inf Univ
u Integer
n) , Sort -> Type
sort (Univ -> Integer -> Sort
forall t. Univ -> Integer -> Sort' t
Inf (Univ -> Univ
univUniv Univ
u) (Integer -> Sort) -> Integer -> Sort
forall a b. (a -> b) -> a -> b
$ Integer
1 Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
n))
NamedArg Expr
arg : [NamedArg Expr]
_ -> TypeError -> TCM (Term, Type)
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCM (Term, Type))
-> (Doc -> TypeError) -> Doc -> TCM (Term, Type)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> TypeError
GenericDocError (Doc -> TCM (Term, Type)) -> TCMT IO Doc -> TCM (Term, Type)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
fsep
[ QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => QName -> m Doc
prettyTCM QName
q , TCMT IO Doc
"cannot be applied to an argument" ]
checkSharpApplication :: A.Expr -> Type -> QName -> [NamedArg A.Expr] -> TCM Term
checkSharpApplication :: Expr -> Type -> QName -> [NamedArg Expr] -> TCM Term
checkSharpApplication Expr
e Type
t QName
c [NamedArg Expr]
args = do
Expr
arg <- case [NamedArg Expr]
args of
[NamedArg Expr
a] | NamedArg Expr -> Bool
forall a. LensHiding a => a -> Bool
visible NamedArg Expr
a -> Expr -> TCMT IO Expr
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Expr -> TCMT IO Expr) -> Expr -> TCMT IO Expr
forall a b. (a -> b) -> a -> b
$ NamedArg Expr -> Expr
forall a. NamedArg a -> a
namedArg NamedArg Expr
a
[NamedArg Expr]
_ -> TypeError -> TCMT IO Expr
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO Expr) -> TypeError -> TCMT IO Expr
forall a b. (a -> b) -> a -> b
$ [Char] -> TypeError
GenericError ([Char] -> TypeError) -> [Char] -> TypeError
forall a b. (a -> b) -> a -> b
$ QName -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow QName
c [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" must be applied to exactly one argument."
Int
i <- TCMT IO Int
forall i (m :: * -> *). MonadFresh i m => m i
fresh :: TCM Int
let name :: [Char]
name = (Char -> Bool) -> [Char] -> [Char]
forall a. (a -> Bool) -> [a] -> [a]
filter (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'_') (Name -> [Char]
forall a. Pretty a => a -> [Char]
prettyShow (Name -> [Char]) -> Name -> [Char]
forall a b. (a -> b) -> a -> b
$ Name -> Name
A.nameConcrete (Name -> Name) -> Name -> Name
forall a b. (a -> b) -> a -> b
$ QName -> Name
A.qnameName QName
c) [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"-" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Int -> [Char]
forall a. Show a => a -> [Char]
show Int
i
CoinductionKit
kit <- TCM CoinductionKit
coinductionKit'
let flat :: QName
flat = CoinductionKit -> QName
nameOfFlat CoinductionKit
kit
inf :: QName
inf = CoinductionKit -> QName
nameOfInf CoinductionKit
kit
Type
forcedType <- do
Type
lvl <- TCMT IO Type
forall (m :: * -> *). (HasBuiltins m, MonadTCError m) => m Type
levelType
(MetaId
_, Term
l) <- RunMetaOccursCheck -> Comparison -> Type -> TCMT IO (MetaId, Term)
forall (m :: * -> *).
MonadMetaSolver m =>
RunMetaOccursCheck -> Comparison -> Type -> m (MetaId, Term)
newValueMeta RunMetaOccursCheck
RunMetaOccursCheck Comparison
CmpLeq Type
lvl
Level' Term
lv <- Term -> TCMT IO (Level' Term)
forall (m :: * -> *). PureTCM m => Term -> m (Level' Term)
levelView Term
l
(MetaId
_, Term
a) <- RunMetaOccursCheck -> Comparison -> Type -> TCMT IO (MetaId, Term)
forall (m :: * -> *).
MonadMetaSolver m =>
RunMetaOccursCheck -> Comparison -> Type -> m (MetaId, Term)
newValueMeta RunMetaOccursCheck
RunMetaOccursCheck Comparison
CmpEq (Sort -> Type
sort (Sort -> Type) -> Sort -> Type
forall a b. (a -> b) -> a -> b
$ Level' Term -> Sort
forall t. Level' t -> Sort' t
Type Level' Term
lv)
Type -> TCMT IO Type
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Type -> TCMT IO Type) -> Type -> TCMT IO Type
forall a b. (a -> b) -> a -> b
$ Sort -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El (Level' Term -> Sort
forall t. Level' t -> Sort' t
Type Level' Term
lv) (Term -> Type) -> Term -> Type
forall a b. (a -> b) -> a -> b
$ QName -> Elims -> Term
Def QName
inf [Arg Term -> Elim
forall a. Arg a -> Elim' a
Apply (Arg Term -> Elim) -> Arg Term -> Elim
forall a b. (a -> b) -> a -> b
$ Hiding -> Arg Term -> Arg Term
forall a. LensHiding a => Hiding -> a -> a
setHiding Hiding
Hidden (Arg Term -> Arg Term) -> Arg Term -> Arg Term
forall a b. (a -> b) -> a -> b
$ Term -> Arg Term
forall e. e -> Arg e
defaultArg Term
l, Arg Term -> Elim
forall a. Arg a -> Elim' a
Apply (Arg Term -> Elim) -> Arg Term -> Elim
forall a b. (a -> b) -> a -> b
$ Term -> Arg Term
forall e. e -> Arg e
defaultArg Term
a]
QName
wrapper <- TCM QName -> TCM QName
forall a. TCM a -> TCM a
inFreshModuleIfFreeParams (TCM QName -> TCM QName) -> TCM QName -> TCM QName
forall a b. (a -> b) -> a -> b
$
TCM QName -> TCM QName
forall a. TCM a -> TCM a
setRunTimeModeUnlessInHardCompileTimeMode (TCM QName -> TCM QName) -> TCM QName -> TCM QName
forall a b. (a -> b) -> a -> b
$ do
QName
c' <- Range -> QName -> QName
forall a. SetRange a => Range -> a -> a
setRange (QName -> Range
forall a. HasRange a => a -> Range
getRange QName
c) (QName -> QName) -> TCM QName -> TCM QName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
(ModuleName -> Name -> QName)
-> TCMT IO ModuleName -> TCMT IO Name -> TCM QName
forall (m :: * -> *) a1 a2 r.
Monad m =>
(a1 -> a2 -> r) -> m a1 -> m a2 -> m r
liftM2 ModuleName -> Name -> QName
qualify (KillRangeT ModuleName
forall a. KillRange a => KillRangeT a
killRange KillRangeT ModuleName -> TCMT IO ModuleName -> TCMT IO ModuleName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TCMT IO ModuleName
forall (m :: * -> *). MonadTCEnv m => m ModuleName
currentModule)
([Char] -> TCMT IO Name
forall a (m :: * -> *).
(FreshName a, MonadFresh NameId m) =>
a -> m Name
forall (m :: * -> *). MonadFresh NameId m => [Char] -> m Name
freshName_ [Char]
name)
Modality
mod <- TCMT IO Modality
forall (m :: * -> *). MonadTCEnv m => m Modality
currentModality
IsAbstract
abs <- (TCEnv -> IsAbstract) -> TCMT IO IsAbstract
forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC (TCEnv -> Lens' TCEnv IsAbstract -> IsAbstract
forall o i. o -> Lens' o i -> i
^. (IsAbstract -> f IsAbstract) -> TCEnv -> f TCEnv
forall a. LensIsAbstract a => Lens' a IsAbstract
Lens' TCEnv IsAbstract
lensIsAbstract)
let info :: DefInfo' Expr
info = Name -> Fixity' -> Access -> IsAbstract -> Range -> DefInfo' Expr
forall t.
Name -> Fixity' -> Access -> IsAbstract -> Range -> DefInfo' t
A.mkDefInfo (Name -> Name
A.nameConcrete (Name -> Name) -> Name -> Name
forall a b. (a -> b) -> a -> b
$ QName -> Name
A.qnameName QName
c') Fixity'
noFixity'
Access
PublicAccess IsAbstract
abs Range
forall a. Range' a
noRange
core :: LHSCore' Expr
core = A.LHSProj { lhsDestructor :: AmbiguousQName
A.lhsDestructor = QName -> AmbiguousQName
unambiguous QName
flat
, lhsFocus :: NamedArg (LHSCore' Expr)
A.lhsFocus = LHSCore' Expr -> NamedArg (LHSCore' Expr)
forall a. a -> NamedArg a
defaultNamedArg (LHSCore' Expr -> NamedArg (LHSCore' Expr))
-> LHSCore' Expr -> NamedArg (LHSCore' Expr)
forall a b. (a -> b) -> a -> b
$ QName -> [NamedArg (Pattern' Expr)] -> LHSCore' Expr
forall e. QName -> [NamedArg (Pattern' e)] -> LHSCore' e
A.LHSHead QName
c' []
, lhsPats :: [NamedArg (Pattern' Expr)]
A.lhsPats = [] }
clause :: Clause' LHS
clause = LHS
-> [ProblemEq] -> RHS -> WhereDeclarations -> Bool -> Clause' LHS
forall lhs.
lhs
-> [ProblemEq] -> RHS -> WhereDeclarations -> Bool -> Clause' lhs
A.Clause (LHSInfo -> LHSCore' Expr -> LHS
A.LHS LHSInfo
forall a. Null a => a
empty LHSCore' Expr
core) []
(Expr -> Maybe Expr -> RHS
A.RHS Expr
arg Maybe Expr
forall a. Maybe a
Nothing)
WhereDeclarations
A.noWhereDecls Bool
False
MutualId
i <- TCM MutualId
currentOrFreshMutualBlock
QName -> Definition -> TCMT IO ()
addConstant QName
c' (Definition -> TCMT IO ()) -> TCMT IO Definition -> TCMT IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< do
let ai :: ArgInfo
ai = Modality -> ArgInfo -> ArgInfo
forall a. LensModality a => Modality -> a -> a
setModality Modality
mod ArgInfo
defaultArgInfo
Language
lang <- TCMT IO Language
forall (m :: * -> *). HasOptions m => m Language
getLanguage
Defn
fun <- TCMT IO Defn
forall (m :: * -> *). HasOptions m => m Defn
emptyFunction
Definition -> TCMT IO Definition
useTerPragma (Definition -> TCMT IO Definition)
-> Definition -> TCMT IO Definition
forall a b. (a -> b) -> a -> b
$
(ArgInfo -> QName -> Type -> Language -> Defn -> Definition
defaultDefn ArgInfo
ai QName
c' Type
forcedType Language
lang Defn
fun)
{ defMutual = i }
DefInfo' Expr -> QName -> [Clause' LHS] -> TCMT IO ()
checkFunDef DefInfo' Expr
info QName
c' [Clause' LHS
clause]
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.expr.coind" Int
15 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ do
Defn
def <- Definition -> Defn
theDef (Definition -> Defn) -> TCMT IO Definition -> TCMT IO Defn
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> QName -> TCMT IO Definition
forall (m :: * -> *). HasConstInfo m => QName -> m Definition
getConstInfo QName
c'
[TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat ([TCMT IO Doc] -> TCMT IO Doc) -> [TCMT IO Doc] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$
[ TCMT IO Doc
"The coinductive wrapper"
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Modality -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Modality -> m Doc
prettyTCM Modality
mod TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall a. Semigroup a => a -> a -> a
<> (QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => QName -> m Doc
prettyTCM QName
c' TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
":")
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
4 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
t
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Clause' LHS -> TCMT IO Doc
forall a (m :: * -> *).
(ToConcrete a, Pretty (ConOfAbs a), MonadAbsToCon m) =>
a -> m Doc
prettyA Clause' LHS
clause
]
QName -> TCM QName
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return QName
c'
Term
e' <- QName -> Elims -> Term
Def QName
wrapper (Elims -> Term) -> ([Arg Term] -> Elims) -> [Arg Term] -> Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Arg Term -> Elim) -> [Arg Term] -> Elims
forall a b. (a -> b) -> [a] -> [b]
map Arg Term -> Elim
forall a. Arg a -> Elim' a
Apply ([Arg Term] -> Term) -> TCMT IO [Arg Term] -> TCM Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TCMT IO [Arg Term]
forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m [Arg Term]
getContextArgs
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.expr.coind" Int
15 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat ([TCMT IO Doc] -> TCMT IO Doc) -> [TCMT IO Doc] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$
[ TCMT IO Doc
"The coinductive constructor application"
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Expr -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Expr -> m Doc
prettyTCM Expr
e
, TCMT IO Doc
"was translated into the application"
, Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Term -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Term -> m Doc
prettyTCM Term
e'
]
Type -> TCM Term -> TCM Term
forall (m :: * -> *).
(MonadMetaSolver m, MonadConstraint m, MonadFresh Int m,
MonadFresh ProblemId m) =>
Type -> m Term -> m Term
blockTerm Type
t (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ Term
e' Term -> TCMT IO () -> TCM Term
forall a b. a -> TCMT IO b -> TCMT IO a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ TCMT IO () -> TCMT IO ()
forall (m :: * -> *) a.
(MonadTCEnv m, HasOptions m, MonadDebug m) =>
m a -> m a
workOnTypes (Type -> Type -> TCMT IO ()
forall (m :: * -> *). MonadConversion m => Type -> Type -> m ()
leqType Type
forcedType Type
t)
pathAbs :: PathView -> Abs Term -> TCM Term
pathAbs :: PathView -> Abs Term -> TCM Term
pathAbs (OType Type
_) Abs Term
t = TCM Term
forall a. HasCallStack => a
__IMPOSSIBLE__
pathAbs (PathType Sort
s QName
path Arg Term
l Arg Term
a Arg Term
x Arg Term
y) Abs Term
t = do
Term -> TCM Term
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Term -> TCM Term) -> Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ ArgInfo -> Abs Term -> Term
Lam ArgInfo
defaultArgInfo Abs Term
t
checkPrimComp :: QName -> MaybeRanges -> Args -> Type -> TCM Args
checkPrimComp :: QName -> MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]
checkPrimComp QName
c MaybeRanges
rs [Arg Term]
vs Type
_ = do
case [Arg Term]
vs of
Arg Term
l : Arg Term
a : Arg Term
phi : Arg Term
u : Arg Term
a0 : [Arg Term]
rest -> do
Arg Term
iz <- ArgInfo -> Term -> Arg Term
forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
defaultArgInfo (Term -> Arg Term) -> TCM Term -> TCMT IO (Arg Term)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IntervalView -> TCM Term
forall (m :: * -> *). HasBuiltins m => IntervalView -> m Term
intervalUnview IntervalView
IZero
let lz :: Term
lz = Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
l Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
`apply` [Arg Term
iz]
az :: Term
az = Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
a Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
`apply` [Arg Term
iz]
Type
ty <- TCM Term -> TCM Term -> TCMT IO Type
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Type
el's (Term -> TCM Term
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
l Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
`apply` [Arg Term
iz])) (TCM Term -> TCMT IO Type) -> TCM Term -> TCMT IO Type
forall a b. (a -> b) -> a -> b
$ TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primPartial TCM Term -> TCM Term -> TCM Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<#> Term -> TCM Term
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
l Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
`apply` [Arg Term
iz]) TCM Term -> TCM Term -> TCM Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> Term -> TCM Term
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
phi) TCM Term -> TCM Term -> TCM Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> Term -> TCM Term
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
a Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
`apply` [Arg Term
iz])
Type
bAz <- TCM Term -> TCM Term -> TCMT IO Type
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Type
el' (Term -> TCM Term
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Term -> TCM Term) -> Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ Term
lz) (Term -> TCM Term
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Term -> TCM Term) -> Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ Term
az)
Arg Term
a0 <- Type
-> Maybe (Maybe Range)
-> Arg Term
-> TCMT IO ()
-> TCMT IO (Arg Term)
forall r.
HasRange r =>
Type -> r -> Arg Term -> TCMT IO () -> TCMT IO (Arg Term)
blockArg Type
bAz (MaybeRanges
rs MaybeRanges -> Int -> Maybe (Maybe Range)
forall a. [a] -> Int -> Maybe a
!!! Int
4) Arg Term
a0 (TCMT IO () -> TCMT IO (Arg Term))
-> TCMT IO () -> TCMT IO (Arg Term)
forall a b. (a -> b) -> a -> b
$ do
Type -> Term -> Term -> TCMT IO ()
forall (m :: * -> *).
MonadConversion m =>
Type -> Term -> Term -> m ()
equalTerm Type
ty
(ArgInfo -> Abs Term -> Term
Lam ArgInfo
defaultArgInfo (Abs Term -> Term) -> Abs Term -> Term
forall a b. (a -> b) -> a -> b
$ [Char] -> Term -> Abs Term
forall a. [Char] -> a -> Abs a
NoAbs [Char]
"_" (Term -> Abs Term) -> Term -> Abs Term
forall a b. (a -> b) -> a -> b
$ Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
a0)
(Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
apply (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
u) [Arg Term
iz])
[Arg Term] -> TCMT IO [Arg Term]
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Arg Term] -> TCMT IO [Arg Term])
-> [Arg Term] -> TCMT IO [Arg Term]
forall a b. (a -> b) -> a -> b
$ Arg Term
l Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
a Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
phi Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
u Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
a0 Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: [Arg Term]
rest
[Arg Term]
_ -> TypeError -> TCMT IO [Arg Term]
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO [Arg Term])
-> (Doc -> TypeError) -> Doc -> TCMT IO [Arg Term]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> TypeError
GenericDocError (Doc -> TCMT IO [Arg Term]) -> TCMT IO Doc -> TCMT IO [Arg Term]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => QName -> m Doc
prettyTCM QName
c TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
"must be fully applied"
checkPrimHComp :: QName -> MaybeRanges -> Args -> Type -> TCM Args
checkPrimHComp :: QName -> MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]
checkPrimHComp QName
c MaybeRanges
rs [Arg Term]
vs Type
_ = do
case [Arg Term]
vs of
Arg Term
l : Arg Term
a : Arg Term
phi : Arg Term
u : Arg Term
a0 : [Arg Term]
rest -> do
Arg Term
iz <- ArgInfo -> Term -> Arg Term
forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
defaultArgInfo (Term -> Arg Term) -> TCM Term -> TCMT IO (Arg Term)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IntervalView -> TCM Term
forall (m :: * -> *). HasBuiltins m => IntervalView -> m Term
intervalUnview IntervalView
IZero
Type
ty <- TCM Term -> TCM Term -> TCMT IO Type
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Type
el's (Term -> TCM Term
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
l)) (TCM Term -> TCMT IO Type) -> TCM Term -> TCMT IO Type
forall a b. (a -> b) -> a -> b
$ TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primPartial TCM Term -> TCM Term -> TCM Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<#> Term -> TCM Term
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
l) TCM Term -> TCM Term -> TCM Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> Term -> TCM Term
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
phi) TCM Term -> TCM Term -> TCM Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> Term -> TCM Term
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
a)
Type
bA <- TCM Term -> TCM Term -> TCMT IO Type
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Type
el' (Term -> TCM Term
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Term -> TCM Term) -> Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
l) (Term -> TCM Term
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Term -> TCM Term) -> Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
a)
Arg Term
a0 <- Type
-> Maybe (Maybe Range)
-> Arg Term
-> TCMT IO ()
-> TCMT IO (Arg Term)
forall r.
HasRange r =>
Type -> r -> Arg Term -> TCMT IO () -> TCMT IO (Arg Term)
blockArg Type
bA (MaybeRanges
rs MaybeRanges -> Int -> Maybe (Maybe Range)
forall a. [a] -> Int -> Maybe a
!!! Int
4) Arg Term
a0 (TCMT IO () -> TCMT IO (Arg Term))
-> TCMT IO () -> TCMT IO (Arg Term)
forall a b. (a -> b) -> a -> b
$ do
Type -> Term -> Term -> TCMT IO ()
forall (m :: * -> *).
MonadConversion m =>
Type -> Term -> Term -> m ()
equalTerm Type
ty
(ArgInfo -> Abs Term -> Term
Lam ArgInfo
defaultArgInfo (Abs Term -> Term) -> Abs Term -> Term
forall a b. (a -> b) -> a -> b
$ [Char] -> Term -> Abs Term
forall a. [Char] -> a -> Abs a
NoAbs [Char]
"_" (Term -> Abs Term) -> Term -> Abs Term
forall a b. (a -> b) -> a -> b
$ Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
a0)
(Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
apply (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
u) [Arg Term
iz])
[Arg Term] -> TCMT IO [Arg Term]
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Arg Term] -> TCMT IO [Arg Term])
-> [Arg Term] -> TCMT IO [Arg Term]
forall a b. (a -> b) -> a -> b
$ Arg Term
l Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
a Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
phi Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
u Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
a0 Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: [Arg Term]
rest
[Arg Term]
_ -> TypeError -> TCMT IO [Arg Term]
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO [Arg Term])
-> (Doc -> TypeError) -> Doc -> TCMT IO [Arg Term]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> TypeError
GenericDocError (Doc -> TCMT IO [Arg Term]) -> TCMT IO Doc -> TCMT IO [Arg Term]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => QName -> m Doc
prettyTCM QName
c TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
"must be fully applied"
checkPrimTrans :: QName -> MaybeRanges -> Args -> Type -> TCM Args
checkPrimTrans :: QName -> MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]
checkPrimTrans QName
c MaybeRanges
rs [Arg Term]
vs Type
_ = do
case [Arg Term]
vs of
Arg Term
l : Arg Term
a : Arg Term
phi : [Arg Term]
rest -> do
Arg Term
iz <- ArgInfo -> Term -> Arg Term
forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
defaultArgInfo (Term -> Arg Term) -> TCM Term -> TCMT IO (Arg Term)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IntervalView -> TCM Term
forall (m :: * -> *). HasBuiltins m => IntervalView -> m Term
intervalUnview IntervalView
IZero
Type
ty <- [[Char]] -> NamesT (TCMT IO) Type -> TCMT IO Type
forall (m :: * -> *) a. [[Char]] -> NamesT m a -> m a
runNamesT [] (NamesT (TCMT IO) Type -> TCMT IO Type)
-> NamesT (TCMT IO) Type -> TCMT IO Type
forall a b. (a -> b) -> a -> b
$ do
NamesT (TCMT IO) Term
l <- Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall (m :: * -> *) a.
(MonadFail m, Subst a) =>
a -> NamesT m (NamesT m a)
open (Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term))
-> Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall a b. (a -> b) -> a -> b
$ Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
l
[Char]
-> NamesT (TCMT IO) Type
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type
forall (m :: * -> *).
(MonadFail m, MonadAddContext m, MonadDebug m) =>
[Char]
-> NamesT m Type
-> (NamesT m Term -> NamesT m Type)
-> NamesT m Type
nPi' [Char]
"i" NamesT (TCMT IO) Type
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Type
primIntervalType ((NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type)
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type
forall a b. (a -> b) -> a -> b
$ \ NamesT (TCMT IO) Term
i -> (Sort -> Type
sort (Sort -> Type) -> (Term -> Sort) -> Term -> Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term -> Sort
tmSort (Term -> Type) -> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (NamesT (TCMT IO) Term
l NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> NamesT (TCMT IO) Term
i))
Arg Term
a <- Type
-> Maybe (Maybe Range)
-> Arg Term
-> TCMT IO ()
-> TCMT IO (Arg Term)
forall r.
HasRange r =>
Type -> r -> Arg Term -> TCMT IO () -> TCMT IO (Arg Term)
blockArg Type
ty (MaybeRanges
rs MaybeRanges -> Int -> Maybe (Maybe Range)
forall a. [a] -> Int -> Maybe a
!!! Int
1) Arg Term
a (TCMT IO () -> TCMT IO (Arg Term))
-> TCMT IO () -> TCMT IO (Arg Term)
forall a b. (a -> b) -> a -> b
$ do
Term -> Type -> Term -> Term -> TCMT IO ()
forall (m :: * -> *).
MonadConversion m =>
Term -> Type -> Term -> Term -> m ()
equalTermOnFace (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
phi) Type
ty
(Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
a)
(ArgInfo -> Abs Term -> Term
Lam ArgInfo
defaultArgInfo (Abs Term -> Term) -> Abs Term -> Term
forall a b. (a -> b) -> a -> b
$ [Char] -> Term -> Abs Term
forall a. [Char] -> a -> Abs a
NoAbs [Char]
"_" (Term -> Abs Term) -> Term -> Abs Term
forall a b. (a -> b) -> a -> b
$ Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
apply (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
a) [Arg Term
iz])
[Arg Term] -> TCMT IO [Arg Term]
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Arg Term] -> TCMT IO [Arg Term])
-> [Arg Term] -> TCMT IO [Arg Term]
forall a b. (a -> b) -> a -> b
$ Arg Term
l Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
a Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
phi Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: [Arg Term]
rest
[Arg Term]
_ -> TypeError -> TCMT IO [Arg Term]
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO [Arg Term])
-> (Doc -> TypeError) -> Doc -> TCMT IO [Arg Term]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> TypeError
GenericDocError (Doc -> TCMT IO [Arg Term]) -> TCMT IO Doc -> TCMT IO [Arg Term]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => QName -> m Doc
prettyTCM QName
c TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
"must be fully applied"
blockArg :: HasRange r => Type -> r -> Arg Term -> TCM () -> TCM (Arg Term)
blockArg :: forall r.
HasRange r =>
Type -> r -> Arg Term -> TCMT IO () -> TCMT IO (Arg Term)
blockArg Type
t r
r Arg Term
a TCMT IO ()
m =
Range -> TCMT IO (Arg Term) -> TCMT IO (Arg Term)
forall (m :: * -> *) x a.
(MonadTrace m, HasRange x) =>
x -> m a -> m a
setCurrentRange (r -> Range
forall a. HasRange a => a -> Range
getRange (r -> Range) -> r -> Range
forall a b. (a -> b) -> a -> b
$ r
r) (TCMT IO (Arg Term) -> TCMT IO (Arg Term))
-> TCMT IO (Arg Term) -> TCMT IO (Arg Term)
forall a b. (a -> b) -> a -> b
$ (Term -> Arg Term) -> TCM Term -> TCMT IO (Arg Term)
forall a b. (a -> b) -> TCMT IO a -> TCMT IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Arg Term
a Arg Term -> Term -> Arg Term
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$>) (TCM Term -> TCMT IO (Arg Term)) -> TCM Term -> TCMT IO (Arg Term)
forall a b. (a -> b) -> a -> b
$ Type -> TCM Term -> TCM Term
forall (m :: * -> *).
(MonadMetaSolver m, MonadConstraint m, MonadFresh Int m,
MonadFresh ProblemId m) =>
Type -> m Term -> m Term
blockTerm Type
t (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ TCMT IO ()
m TCMT IO () -> TCM Term -> TCM Term
forall a b. TCMT IO a -> TCMT IO b -> TCMT IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Term -> TCM Term
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
a)
checkConId :: QName -> MaybeRanges -> Args -> Type -> TCM Args
checkConId :: QName -> MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]
checkConId QName
c MaybeRanges
rs [Arg Term]
vs Type
t1 = do
case [Arg Term]
vs of
args :: [Arg Term]
args@[Arg Term
_, Arg Term
_, Arg Term
_, Arg Term
_, Arg Term
phi, Arg Term
p] -> do
iv :: PathView
iv@(PathType Sort
s QName
_ Arg Term
l Arg Term
a Arg Term
x Arg Term
y) <- Type -> TCMT IO PathView
forall (m :: * -> *). HasBuiltins m => Type -> m PathView
idViewAsPath Type
t1
let ty :: Type
ty = PathView -> Type
pathUnview PathView
iv
Term
const_x <- Type -> TCM Term -> TCM Term
forall (m :: * -> *).
(MonadMetaSolver m, MonadConstraint m, MonadFresh Int m,
MonadFresh ProblemId m) =>
Type -> m Term -> m Term
blockTerm Type
ty (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ do
Term -> Type -> Term -> Term -> TCMT IO ()
forall (m :: * -> *).
MonadConversion m =>
Term -> Type -> Term -> Term -> m ()
equalTermOnFace (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
phi) (Sort -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El Sort
s (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
a)) (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
x) (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
y)
PathView -> Abs Term -> TCM Term
pathAbs PathView
iv ([Char] -> Term -> Abs Term
forall a. [Char] -> a -> Abs a
NoAbs ([Char] -> [Char]
stringToArgName [Char]
"_") (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
x))
Arg Term
p <- Type
-> Maybe (Maybe Range)
-> Arg Term
-> TCMT IO ()
-> TCMT IO (Arg Term)
forall r.
HasRange r =>
Type -> r -> Arg Term -> TCMT IO () -> TCMT IO (Arg Term)
blockArg Type
ty (MaybeRanges
rs MaybeRanges -> Int -> Maybe (Maybe Range)
forall a. [a] -> Int -> Maybe a
!!! Int
5) Arg Term
p (TCMT IO () -> TCMT IO (Arg Term))
-> TCMT IO () -> TCMT IO (Arg Term)
forall a b. (a -> b) -> a -> b
$ do
Term -> Type -> Term -> Term -> TCMT IO ()
forall (m :: * -> *).
MonadConversion m =>
Term -> Type -> Term -> Term -> m ()
equalTermOnFace (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
phi) Type
ty (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
p) Term
const_x
[Arg Term] -> TCMT IO [Arg Term]
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Arg Term] -> TCMT IO [Arg Term])
-> [Arg Term] -> TCMT IO [Arg Term]
forall a b. (a -> b) -> a -> b
$ [Arg Term] -> [Arg Term] -> [Arg Term]
forall a. [a] -> [a] -> [a]
initWithDefault [Arg Term]
forall a. HasCallStack => a
__IMPOSSIBLE__ [Arg Term]
args [Arg Term] -> [Arg Term] -> [Arg Term]
forall a. [a] -> [a] -> [a]
++ [Arg Term
p]
[Arg Term]
_ -> TypeError -> TCMT IO [Arg Term]
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO [Arg Term])
-> (Doc -> TypeError) -> Doc -> TCMT IO [Arg Term]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> TypeError
GenericDocError (Doc -> TCMT IO [Arg Term]) -> TCMT IO Doc -> TCMT IO [Arg Term]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => QName -> m Doc
prettyTCM QName
c TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
"must be fully applied"
checkPOr :: QName -> MaybeRanges -> Args -> Type -> TCM Args
checkPOr :: QName -> MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]
checkPOr QName
c MaybeRanges
rs [Arg Term]
vs Type
_ = do
case [Arg Term]
vs of
Arg Term
l : Arg Term
phi1 : Arg Term
phi2 : Arg Term
a : Arg Term
u : Arg Term
v : [Arg Term]
rest -> do
Term
phi <- IntervalView -> TCM Term
forall (m :: * -> *). HasBuiltins m => IntervalView -> m Term
intervalUnview (Arg Term -> Arg Term -> IntervalView
IMin Arg Term
phi1 Arg Term
phi2)
[Char] -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
[Char] -> Int -> TCMT IO Doc -> m ()
reportSDoc [Char]
"tc.term.por" Int
10 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [Char] -> TCMT IO Doc
forall (m :: * -> *). Applicative m => [Char] -> m Doc
text (Term -> [Char]
forall a. Show a => a -> [Char]
show Term
phi)
Type
t1 <- [[Char]] -> NamesT (TCMT IO) Type -> TCMT IO Type
forall (m :: * -> *) a. [[Char]] -> NamesT m a -> m a
runNamesT [] (NamesT (TCMT IO) Type -> TCMT IO Type)
-> NamesT (TCMT IO) Type -> TCMT IO Type
forall a b. (a -> b) -> a -> b
$ do
[NamesT (TCMT IO) Term
l,NamesT (TCMT IO) Term
a] <- (Arg Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term))
-> [Arg Term] -> NamesT (TCMT IO) [NamesT (TCMT IO) Term]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall (m :: * -> *) a.
(MonadFail m, Subst a) =>
a -> NamesT m (NamesT m a)
open (Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term))
-> (Arg Term -> Term)
-> Arg Term
-> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Arg Term -> Term
forall e. Arg e -> e
unArg) [Arg Term
l,Arg Term
a]
NamesT (TCMT IO) Term
psi <- Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall (m :: * -> *) a.
(MonadFail m, Subst a) =>
a -> NamesT m (NamesT m a)
open (Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term))
-> NamesT (TCMT IO) Term
-> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< IntervalView -> NamesT (TCMT IO) Term
forall (m :: * -> *). HasBuiltins m => IntervalView -> m Term
intervalUnview (Arg Term -> Arg Term -> IntervalView
IMax Arg Term
phi1 Arg Term
phi2)
[Char]
-> NamesT (TCMT IO) Term
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type
forall (m :: * -> *).
(MonadAddContext m, HasBuiltins m, MonadDebug m) =>
[Char]
-> NamesT m Term
-> (NamesT m Term -> NamesT m Type)
-> NamesT m Type
pPi' [Char]
"o" NamesT (TCMT IO) Term
psi ((NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type)
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type
forall a b. (a -> b) -> a -> b
$ \ NamesT (TCMT IO) Term
o -> NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Type
el' NamesT (TCMT IO) Term
l (NamesT (TCMT IO) Term
a NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<..> NamesT (TCMT IO) Term
o)
Type
tv <- [[Char]] -> NamesT (TCMT IO) Type -> TCMT IO Type
forall (m :: * -> *) a. [[Char]] -> NamesT m a -> m a
runNamesT [] (NamesT (TCMT IO) Type -> TCMT IO Type)
-> NamesT (TCMT IO) Type -> TCMT IO Type
forall a b. (a -> b) -> a -> b
$ do
[NamesT (TCMT IO) Term
l,NamesT (TCMT IO) Term
a,NamesT (TCMT IO) Term
phi1,NamesT (TCMT IO) Term
phi2] <- (Arg Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term))
-> [Arg Term] -> NamesT (TCMT IO) [NamesT (TCMT IO) Term]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall (m :: * -> *) a.
(MonadFail m, Subst a) =>
a -> NamesT m (NamesT m a)
open (Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term))
-> (Arg Term -> Term)
-> Arg Term
-> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Arg Term -> Term
forall e. Arg e -> e
unArg) [Arg Term
l,Arg Term
a,Arg Term
phi1,Arg Term
phi2]
[Char]
-> NamesT (TCMT IO) Term
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type
forall (m :: * -> *).
(MonadAddContext m, HasBuiltins m, MonadDebug m) =>
[Char]
-> NamesT m Term
-> (NamesT m Term -> NamesT m Type)
-> NamesT m Type
pPi' [Char]
"o" NamesT (TCMT IO) Term
phi2 ((NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type)
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type
forall a b. (a -> b) -> a -> b
$ \ NamesT (TCMT IO) Term
o -> NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Type
el' NamesT (TCMT IO) Term
l (NamesT (TCMT IO) Term
a NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<..> (TCM Term -> NamesT (TCMT IO) Term
forall (m :: * -> *) a. Monad m => m a -> NamesT m a
cl TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primIsOne2 NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> NamesT (TCMT IO) Term
phi1 NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> NamesT (TCMT IO) Term
phi2 NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> NamesT (TCMT IO) Term
o))
Arg Term
v <- Type
-> Maybe (Maybe Range)
-> Arg Term
-> TCMT IO ()
-> TCMT IO (Arg Term)
forall r.
HasRange r =>
Type -> r -> Arg Term -> TCMT IO () -> TCMT IO (Arg Term)
blockArg Type
tv (MaybeRanges
rs MaybeRanges -> Int -> Maybe (Maybe Range)
forall a. [a] -> Int -> Maybe a
!!! Int
5) Arg Term
v (TCMT IO () -> TCMT IO (Arg Term))
-> TCMT IO () -> TCMT IO (Arg Term)
forall a b. (a -> b) -> a -> b
$ do
Term -> Type -> Term -> Term -> TCMT IO ()
forall (m :: * -> *).
MonadConversion m =>
Term -> Type -> Term -> Term -> m ()
equalTermOnFace Term
phi Type
t1 (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
u) (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
v)
[Arg Term] -> TCMT IO [Arg Term]
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Arg Term] -> TCMT IO [Arg Term])
-> [Arg Term] -> TCMT IO [Arg Term]
forall a b. (a -> b) -> a -> b
$ Arg Term
l Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
phi1 Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
phi2 Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
a Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
u Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
v Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: [Arg Term]
rest
[Arg Term]
_ -> TypeError -> TCMT IO [Arg Term]
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO [Arg Term])
-> (Doc -> TypeError) -> Doc -> TCMT IO [Arg Term]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> TypeError
GenericDocError (Doc -> TCMT IO [Arg Term]) -> TCMT IO Doc -> TCMT IO [Arg Term]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => QName -> m Doc
prettyTCM QName
c TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
"must be fully applied"
check_glue :: QName -> MaybeRanges -> Args -> Type -> TCM Args
check_glue :: QName -> MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]
check_glue QName
c MaybeRanges
rs [Arg Term]
vs Type
_ = do
case [Arg Term]
vs of
Arg Term
la : Arg Term
lb : Arg Term
bA : Arg Term
phi : Arg Term
bT : Arg Term
e : Arg Term
t : Arg Term
a : [Arg Term]
rest -> do
let iinfo :: ArgInfo
iinfo = Relevance -> ArgInfo -> ArgInfo
forall a. LensRelevance a => Relevance -> a -> a
setRelevance Relevance
Irrelevant ArgInfo
defaultArgInfo
Term
v <- [[Char]] -> NamesT (TCMT IO) Term -> TCM Term
forall (m :: * -> *) a. [[Char]] -> NamesT m a -> m a
runNamesT [] (NamesT (TCMT IO) Term -> TCM Term)
-> NamesT (TCMT IO) Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ do
[NamesT (TCMT IO) Term
lb, NamesT (TCMT IO) Term
la, NamesT (TCMT IO) Term
bA, NamesT (TCMT IO) Term
phi, NamesT (TCMT IO) Term
bT, NamesT (TCMT IO) Term
e, NamesT (TCMT IO) Term
t] <- (Arg Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term))
-> [Arg Term] -> NamesT (TCMT IO) [NamesT (TCMT IO) Term]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall (m :: * -> *) a.
(MonadFail m, Subst a) =>
a -> NamesT m (NamesT m a)
open (Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term))
-> (Arg Term -> Term)
-> Arg Term
-> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Arg Term -> Term
forall e. Arg e -> e
unArg) [Arg Term
lb, Arg Term
la, Arg Term
bA, Arg Term
phi, Arg Term
bT, Arg Term
e, Arg Term
t]
let f :: NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
f NamesT (TCMT IO) Term
o = TCM Term -> NamesT (TCMT IO) Term
forall (m :: * -> *) a. Monad m => m a -> NamesT m a
cl TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primEquivFun NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<#> NamesT (TCMT IO) Term
lb NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<#> NamesT (TCMT IO) Term
la NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<#> (NamesT (TCMT IO) Term
bT NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<..> NamesT (TCMT IO) Term
o) NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<#> NamesT (TCMT IO) Term
bA NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> (NamesT (TCMT IO) Term
e NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<..> NamesT (TCMT IO) Term
o)
ArgInfo
-> [Char]
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term)
-> NamesT (TCMT IO) Term
forall (m :: * -> *).
MonadFail m =>
ArgInfo
-> [Char] -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
glam ArgInfo
iinfo [Char]
"o" ((NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term)
-> NamesT (TCMT IO) Term)
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term)
-> NamesT (TCMT IO) Term
forall a b. (a -> b) -> a -> b
$ \ NamesT (TCMT IO) Term
o -> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
f NamesT (TCMT IO) Term
o NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> (NamesT (TCMT IO) Term
t NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<..> NamesT (TCMT IO) Term
o)
Type
ty <- [[Char]] -> NamesT (TCMT IO) Type -> TCMT IO Type
forall (m :: * -> *) a. [[Char]] -> NamesT m a -> m a
runNamesT [] (NamesT (TCMT IO) Type -> TCMT IO Type)
-> NamesT (TCMT IO) Type -> TCMT IO Type
forall a b. (a -> b) -> a -> b
$ do
[NamesT (TCMT IO) Term
lb, NamesT (TCMT IO) Term
phi, NamesT (TCMT IO) Term
bA] <- (Arg Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term))
-> [Arg Term] -> NamesT (TCMT IO) [NamesT (TCMT IO) Term]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall (m :: * -> *) a.
(MonadFail m, Subst a) =>
a -> NamesT m (NamesT m a)
open (Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term))
-> (Arg Term -> Term)
-> Arg Term
-> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Arg Term -> Term
forall e. Arg e -> e
unArg) [Arg Term
lb, Arg Term
phi, Arg Term
bA]
NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Type
el's NamesT (TCMT IO) Term
lb (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type
forall a b. (a -> b) -> a -> b
$ TCM Term -> NamesT (TCMT IO) Term
forall (m :: * -> *) a. Monad m => m a -> NamesT m a
cl TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primPartialP NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<#> NamesT (TCMT IO) Term
lb NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> NamesT (TCMT IO) Term
phi NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> ArgInfo
-> [Char]
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term)
-> NamesT (TCMT IO) Term
forall (m :: * -> *).
MonadFail m =>
ArgInfo
-> [Char] -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
glam ArgInfo
iinfo [Char]
"o" (\ NamesT (TCMT IO) Term
_ -> NamesT (TCMT IO) Term
bA)
let a' :: Term
a' = ArgInfo -> Abs Term -> Term
Lam ArgInfo
iinfo ([Char] -> Term -> Abs Term
forall a. [Char] -> a -> Abs a
NoAbs [Char]
"o" (Term -> Abs Term) -> Term -> Abs Term
forall a b. (a -> b) -> a -> b
$ Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
a)
Type
ta <- TCM Term -> TCM Term -> TCMT IO Type
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Type
el' (Term -> TCM Term
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Term -> TCM Term) -> Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
la) (Term -> TCM Term
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Term -> TCM Term) -> Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
bA)
Arg Term
a <- Type
-> Maybe (Maybe Range)
-> Arg Term
-> TCMT IO ()
-> TCMT IO (Arg Term)
forall r.
HasRange r =>
Type -> r -> Arg Term -> TCMT IO () -> TCMT IO (Arg Term)
blockArg Type
ta (MaybeRanges
rs MaybeRanges -> Int -> Maybe (Maybe Range)
forall a. [a] -> Int -> Maybe a
!!! Int
7) Arg Term
a (TCMT IO () -> TCMT IO (Arg Term))
-> TCMT IO () -> TCMT IO (Arg Term)
forall a b. (a -> b) -> a -> b
$ Type -> Term -> Term -> TCMT IO ()
forall (m :: * -> *).
MonadConversion m =>
Type -> Term -> Term -> m ()
equalTerm Type
ty Term
a' Term
v
[Arg Term] -> TCMT IO [Arg Term]
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Arg Term] -> TCMT IO [Arg Term])
-> [Arg Term] -> TCMT IO [Arg Term]
forall a b. (a -> b) -> a -> b
$ Arg Term
la Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
lb Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
bA Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
phi Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
bT Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
e Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
t Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
a Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: [Arg Term]
rest
[Arg Term]
_ -> TypeError -> TCMT IO [Arg Term]
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO [Arg Term])
-> (Doc -> TypeError) -> Doc -> TCMT IO [Arg Term]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> TypeError
GenericDocError (Doc -> TCMT IO [Arg Term]) -> TCMT IO Doc -> TCMT IO [Arg Term]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => QName -> m Doc
prettyTCM QName
c TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
"must be fully applied"
check_glueU :: QName -> MaybeRanges -> Args -> Type -> TCM Args
check_glueU :: QName -> MaybeRanges -> [Arg Term] -> Type -> TCMT IO [Arg Term]
check_glueU QName
c MaybeRanges
rs [Arg Term]
vs Type
_ = do
case [Arg Term]
vs of
Arg Term
la : Arg Term
phi : Arg Term
bT : Arg Term
bA : Arg Term
t : Arg Term
a : [Arg Term]
rest -> do
let iinfo :: ArgInfo
iinfo = Relevance -> ArgInfo -> ArgInfo
forall a. LensRelevance a => Relevance -> a -> a
setRelevance Relevance
Irrelevant ArgInfo
defaultArgInfo
Term
v <- [[Char]] -> NamesT (TCMT IO) Term -> TCM Term
forall (m :: * -> *) a. [[Char]] -> NamesT m a -> m a
runNamesT [] (NamesT (TCMT IO) Term -> TCM Term)
-> NamesT (TCMT IO) Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ do
[NamesT (TCMT IO) Term
la, NamesT (TCMT IO) Term
phi, NamesT (TCMT IO) Term
bT, NamesT (TCMT IO) Term
bA, NamesT (TCMT IO) Term
t] <- (Arg Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term))
-> [Arg Term] -> NamesT (TCMT IO) [NamesT (TCMT IO) Term]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall (m :: * -> *) a.
(MonadFail m, Subst a) =>
a -> NamesT m (NamesT m a)
open (Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term))
-> (Arg Term -> Term)
-> Arg Term
-> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Arg Term -> Term
forall e. Arg e -> e
unArg) [Arg Term
la, Arg Term
phi, Arg Term
bT, Arg Term
bA, Arg Term
t]
let f :: NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
f NamesT (TCMT IO) Term
o = TCM Term -> NamesT (TCMT IO) Term
forall (m :: * -> *) a. Monad m => m a -> NamesT m a
cl TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primTrans NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<#> [Char]
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term)
-> NamesT (TCMT IO) Term
forall (m :: * -> *).
MonadFail m =>
[Char] -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
lam [Char]
"i" (NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall a b. a -> b -> a
const NamesT (TCMT IO) Term
la) NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> [Char]
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term)
-> NamesT (TCMT IO) Term
forall (m :: * -> *).
MonadFail m =>
[Char] -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
lam [Char]
"i" (\ NamesT (TCMT IO) Term
i -> NamesT (TCMT IO) Term
bT NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> (TCM Term -> NamesT (TCMT IO) Term
forall (m :: * -> *) a. Monad m => m a -> NamesT m a
cl TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primINeg NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> NamesT (TCMT IO) Term
i) NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<..> NamesT (TCMT IO) Term
o) NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> TCM Term -> NamesT (TCMT IO) Term
forall (m :: * -> *) a. Monad m => m a -> NamesT m a
cl TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primIZero
ArgInfo
-> [Char]
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term)
-> NamesT (TCMT IO) Term
forall (m :: * -> *).
MonadFail m =>
ArgInfo
-> [Char] -> (NamesT m Term -> NamesT m Term) -> NamesT m Term
glam ArgInfo
iinfo [Char]
"o" ((NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term)
-> NamesT (TCMT IO) Term)
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term)
-> NamesT (TCMT IO) Term
forall a b. (a -> b) -> a -> b
$ \ NamesT (TCMT IO) Term
o -> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
f NamesT (TCMT IO) Term
o NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> (NamesT (TCMT IO) Term
t NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<..> NamesT (TCMT IO) Term
o)
Type
ty <- [[Char]] -> NamesT (TCMT IO) Type -> TCMT IO Type
forall (m :: * -> *) a. [[Char]] -> NamesT m a -> m a
runNamesT [] (NamesT (TCMT IO) Type -> TCMT IO Type)
-> NamesT (TCMT IO) Type -> TCMT IO Type
forall a b. (a -> b) -> a -> b
$ do
[NamesT (TCMT IO) Term
la, NamesT (TCMT IO) Term
phi, NamesT (TCMT IO) Term
bT] <- (Arg Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term))
-> [Arg Term] -> NamesT (TCMT IO) [NamesT (TCMT IO) Term]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall (m :: * -> *) a.
(MonadFail m, Subst a) =>
a -> NamesT m (NamesT m a)
open (Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term))
-> (Arg Term -> Term)
-> Arg Term
-> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Arg Term -> Term
forall e. Arg e -> e
unArg) [Arg Term
la, Arg Term
phi, Arg Term
bT]
[Char]
-> NamesT (TCMT IO) Term
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type
forall (m :: * -> *).
(MonadAddContext m, HasBuiltins m, MonadDebug m) =>
[Char]
-> NamesT m Term
-> (NamesT m Term -> NamesT m Type)
-> NamesT m Type
pPi' [Char]
"o" NamesT (TCMT IO) Term
phi ((NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type)
-> (NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type)
-> NamesT (TCMT IO) Type
forall a b. (a -> b) -> a -> b
$ \ NamesT (TCMT IO) Term
o -> NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Type
el' NamesT (TCMT IO) Term
la (NamesT (TCMT IO) Term
bT NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> TCM Term -> NamesT (TCMT IO) Term
forall (m :: * -> *) a. Monad m => m a -> NamesT m a
cl TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primIZero NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<..> NamesT (TCMT IO) Term
o)
let a' :: Term
a' = ArgInfo -> Abs Term -> Term
Lam ArgInfo
iinfo ([Char] -> Term -> Abs Term
forall a. [Char] -> a -> Abs a
NoAbs [Char]
"o" (Term -> Abs Term) -> Term -> Abs Term
forall a b. (a -> b) -> a -> b
$ Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
a)
Type
ta <- [[Char]] -> NamesT (TCMT IO) Type -> TCMT IO Type
forall (m :: * -> *) a. [[Char]] -> NamesT m a -> m a
runNamesT [] (NamesT (TCMT IO) Type -> TCMT IO Type)
-> NamesT (TCMT IO) Type -> TCMT IO Type
forall a b. (a -> b) -> a -> b
$ do
[NamesT (TCMT IO) Term
la, NamesT (TCMT IO) Term
phi, NamesT (TCMT IO) Term
bT, NamesT (TCMT IO) Term
bA] <- (Arg Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term))
-> [Arg Term] -> NamesT (TCMT IO) [NamesT (TCMT IO) Term]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall (m :: * -> *) a.
(MonadFail m, Subst a) =>
a -> NamesT m (NamesT m a)
open (Term -> NamesT (TCMT IO) (NamesT (TCMT IO) Term))
-> (Arg Term -> Term)
-> Arg Term
-> NamesT (TCMT IO) (NamesT (TCMT IO) Term)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Arg Term -> Term
forall e. Arg e -> e
unArg) [Arg Term
la, Arg Term
phi, Arg Term
bT, Arg Term
bA]
NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Type
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Type
el' NamesT (TCMT IO) Term
la (TCM Term -> NamesT (TCMT IO) Term
forall (m :: * -> *) a. Monad m => m a -> NamesT m a
cl TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primSubOut NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<#> (TCM Term -> NamesT (TCMT IO) Term
forall (m :: * -> *) a. Monad m => m a -> NamesT m a
cl TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primLevelSuc NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> NamesT (TCMT IO) Term
la) NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<#> (Sort -> Term
Sort (Sort -> Term) -> (Term -> Sort) -> Term -> Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term -> Sort
tmSort (Term -> Term) -> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NamesT (TCMT IO) Term
la) NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<#> NamesT (TCMT IO) Term
phi NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<#> (NamesT (TCMT IO) Term
bT NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> TCM Term -> NamesT (TCMT IO) Term
forall (m :: * -> *) a. Monad m => m a -> NamesT m a
cl TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primIZero) NamesT (TCMT IO) Term
-> NamesT (TCMT IO) Term -> NamesT (TCMT IO) Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> NamesT (TCMT IO) Term
bA)
Arg Term
a <- Type
-> Maybe (Maybe Range)
-> Arg Term
-> TCMT IO ()
-> TCMT IO (Arg Term)
forall r.
HasRange r =>
Type -> r -> Arg Term -> TCMT IO () -> TCMT IO (Arg Term)
blockArg Type
ta (MaybeRanges
rs MaybeRanges -> Int -> Maybe (Maybe Range)
forall a. [a] -> Int -> Maybe a
!!! Int
5) Arg Term
a (TCMT IO () -> TCMT IO (Arg Term))
-> TCMT IO () -> TCMT IO (Arg Term)
forall a b. (a -> b) -> a -> b
$ Type -> Term -> Term -> TCMT IO ()
forall (m :: * -> *).
MonadConversion m =>
Type -> Term -> Term -> m ()
equalTerm Type
ty Term
a' Term
v
[Arg Term] -> TCMT IO [Arg Term]
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Arg Term] -> TCMT IO [Arg Term])
-> [Arg Term] -> TCMT IO [Arg Term]
forall a b. (a -> b) -> a -> b
$ Arg Term
la Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
phi Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
bT Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
bA Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
t Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: Arg Term
a Arg Term -> [Arg Term] -> [Arg Term]
forall a. a -> [a] -> [a]
: [Arg Term]
rest
[Arg Term]
_ -> TypeError -> TCMT IO [Arg Term]
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO [Arg Term])
-> (Doc -> TypeError) -> Doc -> TCMT IO [Arg Term]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> TypeError
GenericDocError (Doc -> TCMT IO [Arg Term]) -> TCMT IO Doc -> TCMT IO [Arg Term]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< QName -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => QName -> m Doc
prettyTCM QName
c TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TCMT IO Doc
"must be fully applied"