{-# LANGUAGE NondecreasingIndentation #-}
module Mikan.TypeChecking.Rules.Term where
import Prelude hiding ( null )
import Control.Monad.Except ( MonadError(..) )
import Data.Maybe
import Data.DList qualified as DL
import Data.Either (partitionEithers, lefts)
import Data.List qualified as List
import Data.IntMap qualified as IntMap
import Data.Map qualified as Map
import Data.Set qualified as Set
import Data.Text.Short qualified as TS
import Mikan.Interaction.Options
import Mikan.Interaction.Highlighting.Generate (disambiguateRecordFields)
import Mikan.Syntax.Abstract (Binder, TypedBindingInfo (tbTacticAttr), unBind, binderName)
import Mikan.Syntax.Abstract qualified as A
import Mikan.Syntax.Abstract.Views as A
import Mikan.Syntax.Info qualified as A
import Mikan.Syntax.Concrete.Pretty ()
import Mikan.Syntax.Concrete (FieldAssignment'(..), nameFieldA, TacticAttribute'(..))
import Mikan.Syntax.Concrete.Name qualified as C
import Mikan.Syntax.Common
import Mikan.Syntax.Common.Pretty ( prettyShow )
import Mikan.Syntax.Common.Pretty qualified as P
import Mikan.Syntax.Internal as I
import Mikan.Syntax.Internal.MetaVars
import Mikan.Syntax.Position
import Mikan.Syntax.Literal
import Mikan.Syntax.Scope.Base ( ThingsInScope
, emptyScopeInfo
, exportedNamesInScope)
import Mikan.Syntax.Scope.Monad (getNamedScope)
import Mikan.TypeChecking.CompiledClause
import Mikan.TypeChecking.Constraints
import Mikan.TypeChecking.Conversion
import Mikan.TypeChecking.Coverage.SplitTree
import Mikan.TypeChecking.Coverage.Errors
import Mikan.TypeChecking.Datatypes
import Mikan.TypeChecking.EtaContract
import Mikan.TypeChecking.Generalize
import Mikan.TypeChecking.Implicit
import Mikan.TypeChecking.InstanceArguments
import Mikan.TypeChecking.Irrelevance
import Mikan.TypeChecking.IApplyConfluence
import Mikan.TypeChecking.Level
import Mikan.TypeChecking.MetaVars
import Mikan.TypeChecking.Monad
import Mikan.TypeChecking.Patterns.Abstract
import Mikan.TypeChecking.Positivity.Occurrence
import Mikan.TypeChecking.Pretty
import Mikan.TypeChecking.Primitive
import Mikan.TypeChecking.Quote
import Mikan.TypeChecking.RecordPatterns
import Mikan.TypeChecking.Records
import Mikan.TypeChecking.Reduce
import Mikan.TypeChecking.Rules.LHS
import Mikan.TypeChecking.Sort
import Mikan.TypeChecking.Substitute
import Mikan.TypeChecking.Telescope
import Mikan.TypeChecking.Unquote.Errors
import Mikan.TypeChecking.Unquote
import Mikan.TypeChecking.Warnings
import Mikan.TypeChecking.Errors.Deferred
import {-# SOURCE #-} Mikan.TypeChecking.Empty ( ensureEmptyType )
import {-# SOURCE #-} Mikan.TypeChecking.Rules.Def (checkFunDef', useTerPragma)
import {-# SOURCE #-} Mikan.TypeChecking.Rules.Decl (checkSectionApplication)
import {-# SOURCE #-} Mikan.TypeChecking.Rules.Application
import Mikan.TypeChecking.Rules.WithApp
import Mikan.Utils.Function
import Mikan.Utils.Functor
import Mikan.Utils.List
import Mikan.Utils.List1 ( List1, pattern (:|) )
import Mikan.Utils.List2 ( pattern List2 )
import Mikan.Utils.List1 qualified as List1
import Mikan.Utils.Maybe
import Mikan.Utils.Monad
import Mikan.Utils.Null
import Mikan.Utils.Set1 qualified as Set1
import Mikan.Utils.Singleton
import Mikan.Utils.Size
import Mikan.Utils.Tuple
import Mikan.Utils.Impossible
import Mikan.Utils.Boolean (implies)
import Mikan.Utils.CallStack
isType :: A.Expr -> Sort -> TCM Type
isType :: Expr -> Sort' Term -> TCM Type
isType = Comparison -> Expr -> Sort' Term -> TCM Type
isType' Comparison
CmpLeq
isType' :: Comparison -> A.Expr -> Sort -> TCM Type
isType' :: Comparison -> Expr -> Sort' Term -> TCM Type
isType' Comparison
c Expr
e Sort' Term
s =
Call -> TCM Type -> TCM Type
forall a. Call -> TCMT IO a -> TCMT IO a
forall (m :: * -> *) a. MonadTrace m => Call -> m a -> m a
traceCall (Comparison -> Expr -> Sort' Term -> Call
IsTypeCall Comparison
c Expr
e Sort' Term
s) (TCM Type -> TCM Type) -> TCM Type -> TCM Type
forall a b. (a -> b) -> a -> b
$ do
v <- Comparison -> Expr -> Type -> TCM Term
checkExpr' Comparison
c Expr
e (Sort' Term -> Type
sort Sort' Term
s)
return $ El s v
isType_ :: A.Expr -> TCM Type
isType_ :: Expr -> TCM Type
isType_ Expr
e = Call -> TCM Type -> TCM Type
forall a. Call -> TCMT IO a -> TCMT IO a
forall (m :: * -> *) a. MonadTrace m => Call -> m a -> m a
traceCall (Expr -> Call
IsType_ Expr
e) (TCM Type -> TCM Type) -> TCM Type -> TCM Type
forall a b. (a -> b) -> a -> b
$ do
String -> Int -> (Type -> TCMT IO Doc) -> TCM Type -> TCM Type
forall (m :: * -> *) a.
MonadDebug m =>
String -> Int -> (a -> TCMT IO Doc) -> m a -> m a
reportResult String
"tc.term.istype" Int
15 (\Type
a -> [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"isType_" 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
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
"returns" 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
a
]) (TCM Type -> TCM Type) -> TCM Type -> TCM Type
forall a b. (a -> b) -> a -> b
$ do
let fallback :: TCM Type
fallback = Comparison -> Expr -> Sort' Term -> TCM Type
isType' Comparison
CmpEq Expr
e (Sort' Term -> TCM Type) -> TCMT IO (Sort' Term) -> TCM Type
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< do TCMT IO (Sort' Term) -> TCMT IO (Sort' Term)
forall (m :: * -> *) a. (MonadTCEnv m, MonadDebug m) => m a -> m a
workOnTypes (TCMT IO (Sort' Term) -> TCMT IO (Sort' Term))
-> TCMT IO (Sort' Term) -> TCMT IO (Sort' Term)
forall a b. (a -> b) -> a -> b
$ TCMT IO (Sort' Term)
newSortMeta
SortKit{ isNameOfUniv } <- TCMT IO SortKit
forall (m :: * -> *). (HasBuiltins m, MonadTCError m) => m SortKit
sortKit
case unScope e of
A.Fun ExprInfo
i (Arg ArgInfo
info Expr
t) Expr
b -> do
a <- ArgInfo -> Type -> Dom Type
forall a t. ArgInfo -> a -> Dom' t a
defaultArgDom ArgInfo
info (Type -> Dom Type) -> TCM Type -> TCMT IO (Dom Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Name -> List1 ArgInfo -> Expr -> TCM Type
forall a. Maybe Name -> List1 a -> Expr -> TCM Type
checkPiDomain Maybe Name
forall a. Maybe a
Nothing (ArgInfo
info ArgInfo -> [ArgInfo] -> List1 ArgInfo
forall a. a -> [a] -> NonEmpty a
:| []) Expr
t
b <- isType_ b
s <- inferFunSort a b
let t' = Sort' Term -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El Sort' Term
s (Term -> Type) -> Term -> Type
forall a b. (a -> b) -> a -> b
$ Dom Type -> Abs Type -> Term
Pi Dom Type
a (Abs Type -> Term) -> Abs Type -> Term
forall a b. (a -> b) -> a -> b
$ ArgName -> Type -> Abs Type
forall a. ArgName -> a -> Abs a
NoAbs ArgName
forall a. Underscore a => a
underscore Type
b
hasPTSRule a (NoAbs underscore $ getSort b)
return t'
A.Pi ExprInfo
_ Telescope1
tel Expr
e -> do
(t0, t') <- Telescope -> (Telescope -> TCM (Type, Type)) -> TCM (Type, Type)
forall a. Telescope -> (Telescope -> TCM a) -> TCM a
checkPiTelescope (Telescope1 -> [Item Telescope1]
forall l. IsList l => l -> [Item l]
List1.toList Telescope1
tel) ((Telescope -> TCM (Type, Type)) -> TCM (Type, Type))
-> (Telescope -> TCM (Type, Type)) -> TCM (Type, Type)
forall a b. (a -> b) -> a -> b
$ \ Telescope
tel -> do
t0 <- Type -> TCM Type
forall a (m :: * -> *).
(InstantiateFull a, MonadReduce m) =>
a -> m a
instantiateFull (Type -> TCM Type) -> TCM Type -> TCM Type
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Expr -> TCM Type
isType_ Expr
e
tel <- instantiateFull tel
checkTelePiSort tel (getSort t0)
return (t0, telePi tel t0)
return t'
A.Generalized Set1 QName
s Expr
e -> do
(_, t') <- Set QName -> TCM Type -> TCM ([Maybe QName], Type)
generalizeType (Set1 QName -> Set QName
forall a. NESet a -> Set a
Set1.toSet Set1 QName
s) (TCM Type -> TCM ([Maybe QName], Type))
-> TCM Type -> TCM ([Maybe QName], Type)
forall a b. (a -> b) -> a -> b
$ Expr -> TCM Type
isType_ Expr
e
return t'
A.Def' QName
x Suffix
suffix
| Just (UnivSize
sz, Univ
u) <- QName -> Maybe (UnivSize, Univ)
isNameOfUniv QName
x
, let n :: Integer
n = Suffix -> Integer
suffixToLevel Suffix
suffix
-> do
Univ -> TCM ()
univChecks Univ
u
Type -> TCM Type
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Type -> TCM Type)
-> (Sort' Term -> Type) -> Sort' Term -> TCM Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sort' Term -> Type
sort (Sort' Term -> TCM Type) -> Sort' Term -> TCM Type
forall a b. (a -> b) -> a -> b
$ case UnivSize
sz of
UnivSize
USmall -> Univ -> Level' Term -> Sort' Term
forall t. Univ -> Level' t -> Sort' t
Univ Univ
u (Level' Term -> Sort' Term) -> Level' Term -> Sort' Term
forall a b. (a -> b) -> a -> b
$ Integer -> Level' Term
ClosedLevel Integer
n
UnivSize
ULarge -> Univ -> Integer -> Sort' Term
forall t. Univ -> Integer -> Sort' t
Inf Univ
u Integer
n
A.App AppInfo
i Expr
s NamedArg Expr
arg
| NamedArg Expr -> Bool
forall a. LensHiding a => a -> Bool
visible NamedArg Expr
arg,
A.Def QName
x <- Expr -> Expr
unScope Expr
s,
Just (UnivSize
USmall, Univ
u) <- QName -> Maybe (UnivSize, Univ)
isNameOfUniv QName
x -> do
Univ -> TCM ()
univChecks Univ
u
Sort' Term -> Type
sort (Sort' Term -> Type)
-> (Level' Term -> Sort' Term) -> Level' Term -> Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Univ -> Level' Term -> Sort' Term
forall t. Univ -> Level' t -> Sort' t
Univ Univ
u (Level' Term -> Type) -> TCMT IO (Level' Term) -> TCM Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NamedArg Expr -> TCMT IO (Level' Term)
checkLevel NamedArg Expr
arg
A.QuestionMark MetaInfo
minfo InteractionId
ii -> TCMT IO (Maybe MetaId)
-> TCM Type -> (MetaId -> TCM Type) -> TCM Type
forall (m :: * -> *) a b.
Monad m =>
m (Maybe a) -> m b -> (a -> m b) -> m b
caseMaybeM (InteractionId -> TCMT IO (Maybe MetaId)
forall (m :: * -> *).
ReadTCState m =>
InteractionId -> m (Maybe MetaId)
lookupInteractionMeta InteractionId
ii) TCM Type
fallback ((MetaId -> TCM Type) -> TCM Type)
-> (MetaId -> TCM Type) -> TCM Type
forall a b. (a -> b) -> a -> b
$ \ MetaId
x -> do
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.ip" Int
20 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
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
"Rechecking meta "
, MetaId -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => MetaId -> m Doc
prettyTCM MetaId
x
, String -> TCMT IO Doc
forall (m :: * -> *). Applicative m => String -> m Doc
text (String -> TCMT IO Doc) -> String -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ String
" for interaction point " String -> String -> String
forall a. [a] -> [a] -> [a]
++! InteractionId -> String
forall a. Show a => a -> String
show InteractionId
ii
]
mv <- MetaId -> TCMT IO MetaVariable
forall (m :: * -> *).
(HasCallStack, MonadDebug m, ReadTCState m) =>
MetaId -> m MetaVariable
lookupLocalMeta MetaId
x
let s0 = Judgement MetaId -> Teletype
forall a. Judgement a -> Teletype
jMetaType (Judgement MetaId -> Teletype)
-> (MetaVariable -> Judgement MetaId) -> MetaVariable -> Teletype
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MetaVariable -> Judgement MetaId
mvJudgement (MetaVariable -> Teletype) -> MetaVariable -> Teletype
forall a b. (a -> b) -> a -> b
$ MetaVariable
mv
let n = Context -> Int
forall a. Context' a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (Context -> Int)
-> (MetaVariable -> Context) -> MetaVariable -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Getting Context TCEnv Context -> TCEnv -> Context
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting Context TCEnv Context
Lens' TCEnv Context
eContext (TCEnv -> Context)
-> (MetaVariable -> TCEnv) -> MetaVariable -> Context
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Closure Range -> TCEnv
forall a. Closure a -> TCEnv
clEnv (Closure Range -> TCEnv)
-> (MetaVariable -> Closure Range) -> MetaVariable -> TCEnv
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MetaInfo -> Closure Range
miClosRange (MetaInfo -> Closure Range)
-> (MetaVariable -> MetaInfo) -> MetaVariable -> Closure Range
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MetaVariable -> MetaInfo
mvInfo (MetaVariable -> Int) -> MetaVariable -> Int
forall a b. (a -> b) -> a -> b
$ MetaVariable
mv
(vs, rest) <- splitAt' n <$> getContextArgs
let oldCxtNames = (Name -> Name) -> [Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map' Name -> Name
nameCanonical ([Name] -> [Name]) -> [Name] -> [Name]
forall a b. (a -> b) -> a -> b
$ Context -> [Name]
contextNames' (Context -> [Name]) -> Context -> [Name]
forall a b. (a -> b) -> a -> b
$ Getting Context TCEnv Context -> TCEnv -> Context
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting Context TCEnv Context
Lens' TCEnv Context
eContext
(TCEnv -> Context) -> TCEnv -> Context
forall a b. (a -> b) -> a -> b
$ Closure Range -> TCEnv
forall a. Closure a -> TCEnv
clEnv (Closure Range -> TCEnv) -> Closure Range -> TCEnv
forall a b. (a -> b) -> a -> b
$ MetaInfo -> Closure Range
miClosRange (MetaInfo -> Closure Range) -> MetaInfo -> Closure Range
forall a b. (a -> b) -> a -> b
$ MetaVariable -> MetaInfo
mvInfo (MetaVariable -> MetaInfo) -> MetaVariable -> MetaInfo
forall a b. (a -> b) -> a -> b
$ MetaVariable
mv
newCxtNames <- map' nameCanonical <$> getContextNames'
reportSDoc "tc.ip" 20 $ vcat
[ " s0 = " <+> prettyTCM s0
, " vs = " <+> prettyTCM vs
, " rest = " <+> prettyTCM rest
, " oldCxtNames = " <+> prettyTCM oldCxtNames
, " newCxtNames = " <+> prettyTCM newCxtNames
]
if (not $ List.isPrefixOf oldCxtNames newCxtNames) then fallback else do
s1 <- reduce $ teleApply s0 vs
reportSDoc "tc.ip" 20 $ vcat
[ " s1 = " <+> prettyTCM s1
]
reportSDoc "tc.ip" 70 $ vcat
[ " s1 = " <+> text (show s1)
]
case unEl s1 of
Sort Sort' Term
s -> Type -> TCM Type
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Type -> TCM Type) -> Type -> TCM Type
forall a b. (a -> b) -> a -> b
$! Sort' Term -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El Sort' Term
s (Term -> Type) -> Term -> Type
forall a b. (a -> b) -> a -> b
$! MetaId -> Elims -> Term
MetaV MetaId
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]
vs
Term
_ -> TCM Type
forall a. HasCallStack => a
__IMPOSSIBLE__
Expr
_ -> TCM Type
fallback
checkLevel :: NamedArg A.Expr -> TCM Level
checkLevel :: NamedArg Expr -> TCMT IO (Level' Term)
checkLevel NamedArg Expr
arg = do
lvl <- TCM Type
forall (m :: * -> *). (HasBuiltins m, MonadTCError m) => m Type
levelType
levelView =<< checkNamedArg arg lvl
isTypeEqualTo :: A.Expr -> Type -> TCM Type
isTypeEqualTo :: Expr -> Type -> TCM Type
isTypeEqualTo Expr
e0 Type
t = Expr -> TCM Expr
scopedExpr Expr
e0 TCM Expr -> (Expr -> TCM Type) -> TCM Type
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
A.ScopedExpr{} -> TCM Type
forall a. HasCallStack => a
__IMPOSSIBLE__
A.Underscore MetaInfo
i | Maybe MetaId -> Bool
forall a. Maybe a -> Bool
isNothing (MetaInfo -> Maybe MetaId
A.metaNumber MetaInfo
i) -> Type -> TCM Type
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Type
t
Expr
e -> TCM Type -> TCM Type
forall (m :: * -> *) a. (MonadTCEnv m, MonadDebug m) => m a -> m a
workOnTypes (TCM Type -> TCM Type) -> TCM Type -> TCM Type
forall a b. (a -> b) -> a -> b
$ do
t' <- Expr -> Sort' Term -> TCM Type
isType Expr
e (Type -> Sort' Term
forall a. LensSort a => a -> Sort' Term
getSort Type
t)
t' <$ leqType t t'
leqType_ :: Type -> Type -> TCM ()
leqType_ :: Type -> Type -> TCM ()
leqType_ Type
t Type
t' = TCM () -> TCM ()
forall (m :: * -> *) a. (MonadTCEnv m, MonadDebug m) => m a -> m a
workOnTypes (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$ Type -> Type -> TCM ()
leqType Type
t Type
t'
data ModTelOrigin = ModTelData | ModTelNotData
deriving (ModTelOrigin -> ModTelOrigin -> Bool
(ModTelOrigin -> ModTelOrigin -> Bool)
-> (ModTelOrigin -> ModTelOrigin -> Bool) -> Eq ModTelOrigin
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ModTelOrigin -> ModTelOrigin -> Bool
== :: ModTelOrigin -> ModTelOrigin -> Bool
$c/= :: ModTelOrigin -> ModTelOrigin -> Bool
/= :: ModTelOrigin -> ModTelOrigin -> Bool
Eq, Int -> ModTelOrigin -> String -> String
[ModTelOrigin] -> String -> String
ModTelOrigin -> String
(Int -> ModTelOrigin -> String -> String)
-> (ModTelOrigin -> String)
-> ([ModTelOrigin] -> String -> String)
-> Show ModTelOrigin
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> ModTelOrigin -> String -> String
showsPrec :: Int -> ModTelOrigin -> String -> String
$cshow :: ModTelOrigin -> String
show :: ModTelOrigin -> String
$cshowList :: [ModTelOrigin] -> String -> String
showList :: [ModTelOrigin] -> String -> String
Show)
checkGeneralizeTelescope ::
ModTelOrigin
-> Maybe ModuleName
-> A.GeneralizeTelescope
-> ([Maybe Name] -> Telescope -> TCM a)
-> TCM a
checkGeneralizeTelescope :: forall a.
ModTelOrigin
-> Maybe ModuleName
-> GeneralizeTelescope
-> ([Maybe Name] -> Telescope -> TCM a)
-> TCM a
checkGeneralizeTelescope ModTelOrigin
o Maybe ModuleName
mm (A.GeneralizeTel Map QName Name
vars Telescope
tel) =
((([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> (([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a
tr (Map QName Name
-> (forall a1. (Telescope -> TCM a1) -> TCM a1)
-> ([Maybe Name] -> Telescope -> TCMT IO a)
-> TCMT IO a
forall a.
Map QName Name
-> (forall a1. (Telescope -> TCM a1) -> TCM a1)
-> ([Maybe Name] -> Telescope -> TCM a)
-> TCM a
generalizeTelescope Map QName Name
vars (ModTelOrigin -> Telescope -> (Telescope -> TCM a1) -> TCM a1
forall a.
ModTelOrigin -> Telescope -> (Telescope -> TCM a) -> TCM a
checkTelescope ModTelOrigin
o Telescope
tel) (([Maybe Name] -> Telescope -> TCMT IO a) -> TCMT IO a)
-> ((([Maybe Name], Telescope) -> TCMT IO a)
-> [Maybe Name] -> Telescope -> TCMT IO a)
-> (([Maybe Name], Telescope) -> TCMT IO a)
-> TCMT IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (([Maybe Name], Telescope) -> TCMT IO a)
-> [Maybe Name] -> Telescope -> TCMT IO a
forall a b c. ((a, b) -> c) -> a -> b -> c
curry) ((([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> (([Maybe Name] -> Telescope -> TCMT IO a)
-> ([Maybe Name], Telescope) -> TCMT IO a)
-> ([Maybe Name] -> Telescope -> TCMT IO a)
-> TCMT IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Maybe Name] -> Telescope -> TCMT IO a)
-> ([Maybe Name], Telescope) -> TCMT IO a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry
where
tr :: ((([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> (([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a
tr = Bool
-> (((([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> (([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> ((([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> (([Maybe Name], Telescope) -> TCMT IO a)
-> TCMT IO a
forall b a. IsBool b => b -> (a -> a) -> a -> a
applyUnless (Telescope -> Bool
forall a. Null a => a -> Bool
null Telescope
tel) ((((([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> (([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> ((([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> (([Maybe Name], Telescope) -> TCMT IO a)
-> TCMT IO a)
-> (((([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> (([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> ((([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> (([Maybe Name], Telescope) -> TCMT IO a)
-> TCMT IO a
forall a b. (a -> b) -> a -> b
$ Maybe ModuleName
-> (ModuleName
-> ((([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> (([Maybe Name], Telescope) -> TCMT IO a)
-> TCMT IO a)
-> ((([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> (([Maybe Name], Telescope) -> TCMT IO a)
-> TCMT IO a
forall b a. Maybe b -> (b -> a -> a) -> a -> a
applyWhenJust Maybe ModuleName
mm ((ModuleName
-> ((([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> (([Maybe Name], Telescope) -> TCMT IO a)
-> TCMT IO a)
-> ((([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> (([Maybe Name], Telescope) -> TCMT IO a)
-> TCMT IO a)
-> (ModuleName
-> ((([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> (([Maybe Name], Telescope) -> TCMT IO a)
-> TCMT IO a)
-> ((([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> (([Maybe Name], Telescope) -> TCMT IO a)
-> TCMT IO a
forall a b. (a -> b) -> a -> b
$ \ ModuleName
m ->
Call
-> ((([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> (([Maybe Name], Telescope) -> TCMT IO a)
-> TCMT IO a
forall a b.
Call
-> ((a -> TCMT IO b) -> TCMT IO b) -> (a -> TCMT IO b) -> TCMT IO b
forall (m :: * -> *) a b.
MonadTrace m =>
Call -> ((a -> m b) -> m b) -> (a -> m b) -> m b
traceCallCPS (Call
-> ((([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> (([Maybe Name], Telescope) -> TCMT IO a)
-> TCMT IO a)
-> Call
-> ((([Maybe Name], Telescope) -> TCMT IO a) -> TCMT IO a)
-> (([Maybe Name], Telescope) -> TCMT IO a)
-> TCMT IO a
forall a b. (a -> b) -> a -> b
$ ModuleName -> Telescope -> Call
CheckModuleParameters ModuleName
m Telescope
tel
checkTelescope :: ModTelOrigin -> A.Telescope -> (Telescope -> TCM a) -> TCM a
checkTelescope :: forall a.
ModTelOrigin -> Telescope -> (Telescope -> TCM a) -> TCM a
checkTelescope ModTelOrigin
o = LamOrPi -> Telescope -> (Telescope -> TCM a) -> TCM a
forall a. LamOrPi -> Telescope -> (Telescope -> TCM a) -> TCM a
checkTelescope' (ModTelOrigin -> LamOrPi
LamNotPi ModTelOrigin
o)
checkPiTelescope :: A.Telescope -> (Telescope -> TCM a) -> TCM a
checkPiTelescope :: forall a. Telescope -> (Telescope -> TCM a) -> TCM a
checkPiTelescope = LamOrPi -> Telescope -> (Telescope -> TCM a) -> TCM a
forall a. LamOrPi -> Telescope -> (Telescope -> TCM a) -> TCM a
checkTelescope' LamOrPi
PiNotLam
data LamOrPi
= LamNotPi ModTelOrigin
| PiNotLam
deriving (LamOrPi -> LamOrPi -> Bool
(LamOrPi -> LamOrPi -> Bool)
-> (LamOrPi -> LamOrPi -> Bool) -> Eq LamOrPi
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LamOrPi -> LamOrPi -> Bool
== :: LamOrPi -> LamOrPi -> Bool
$c/= :: LamOrPi -> LamOrPi -> Bool
/= :: LamOrPi -> LamOrPi -> Bool
Eq, Int -> LamOrPi -> String -> String
[LamOrPi] -> String -> String
LamOrPi -> String
(Int -> LamOrPi -> String -> String)
-> (LamOrPi -> String)
-> ([LamOrPi] -> String -> String)
-> Show LamOrPi
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> LamOrPi -> String -> String
showsPrec :: Int -> LamOrPi -> String -> String
$cshow :: LamOrPi -> String
show :: LamOrPi -> String
$cshowList :: [LamOrPi] -> String -> String
showList :: [LamOrPi] -> String -> String
Show)
checkTelescope' :: LamOrPi -> A.Telescope -> (Telescope -> TCM a) -> TCM a
checkTelescope' :: forall a. LamOrPi -> Telescope -> (Telescope -> TCM a) -> TCM a
checkTelescope' LamOrPi
lamOrPi [] Telescope -> TCM a
ret = Telescope -> TCM a
ret Telescope
forall a. Tele a
EmptyTel
checkTelescope' LamOrPi
lamOrPi (TypedBinding
b : Telescope
tel) Telescope -> TCM a
ret =
LamOrPi -> TypedBinding -> (Telescope -> TCM a) -> TCM a
forall a. LamOrPi -> TypedBinding -> (Telescope -> TCM a) -> TCM a
checkTypedBindings LamOrPi
lamOrPi TypedBinding
b ((Telescope -> TCM a) -> TCM a) -> (Telescope -> TCM a) -> TCM a
forall a b. (a -> b) -> a -> b
$ \Telescope
tel1 ->
LamOrPi -> Telescope -> (Telescope -> TCM a) -> TCM a
forall a. LamOrPi -> Telescope -> (Telescope -> TCM a) -> TCM a
checkTelescope' LamOrPi
lamOrPi Telescope
tel ((Telescope -> TCM a) -> TCM a) -> (Telescope -> TCM a) -> TCM a
forall a b. (a -> b) -> a -> b
$ \Telescope
tel2 ->
Telescope -> TCM a
ret (Telescope -> TCM a) -> Telescope -> TCM a
forall a b. (a -> b) -> a -> b
$ Telescope -> Telescope -> Telescope
forall t. Abstract t => Telescope -> t -> t
abstract Telescope
tel1 Telescope
tel2
checkDomain ::
LamOrPi -> Maybe Name -> List1 a -> A.Expr -> TCM Type
checkDomain :: forall a. LamOrPi -> Maybe Name -> List1 a -> Expr -> TCM Type
checkDomain LamOrPi
lamOrPi Maybe Name
n List1 a
xs Expr
e = LamOrPi -> TCM Type -> TCM Type
forall {m :: * -> *} {a}.
(MonadTCEnv m, MonadDebug m) =>
LamOrPi -> m a -> m a
modEnv LamOrPi
lamOrPi (TCM Type -> TCM Type) -> TCM Type -> TCM Type
forall a b. (a -> b) -> a -> b
$ Expr -> TCM Type
isType_ Expr
e
where
modEnv :: LamOrPi -> m a -> m a
modEnv (LamNotPi ModTelOrigin
_) = m a -> m a
forall (m :: * -> *) a. (MonadTCEnv m, MonadDebug m) => m a -> m a
workOnTypes
modEnv LamOrPi
PiNotLam = m a -> m a
forall a. a -> a
id
checkPiDomain :: Maybe Name -> List1 a -> A.Expr -> TCM Type
checkPiDomain :: forall a. Maybe Name -> List1 a -> Expr -> TCM Type
checkPiDomain = LamOrPi -> Maybe Name -> List1 a -> Expr -> TCM Type
forall a. LamOrPi -> Maybe Name -> List1 a -> Expr -> TCM Type
checkDomain LamOrPi
PiNotLam
checkTypedBindings :: LamOrPi -> A.TypedBinding -> (Telescope -> TCM a) -> TCM a
checkTypedBindings :: forall a. LamOrPi -> TypedBinding -> (Telescope -> TCM a) -> TCM a
checkTypedBindings LamOrPi
lamOrPi (A.TBind Range
r TypedBindingInfo
tac List1 (NamedArg (Binder' BindName))
xps Expr
e) Telescope -> TCM a
ret = do
let xs :: List1 (NamedArg Name)
xs = (NamedArg (Binder' BindName) -> NamedArg Name)
-> List1 (NamedArg (Binder' BindName)) -> List1 (NamedArg Name)
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Binder' BindName -> Name)
-> NamedArg (Binder' BindName) -> NamedArg Name
forall a b. (a -> b) -> NamedArg a -> NamedArg b
updateNamedArg ((Binder' BindName -> Name)
-> NamedArg (Binder' BindName) -> NamedArg Name)
-> (Binder' BindName -> Name)
-> NamedArg (Binder' BindName)
-> NamedArg Name
forall a b. (a -> b) -> a -> b
$ BindName -> Name
A.unBind (BindName -> Name)
-> (Binder' BindName -> BindName) -> Binder' BindName -> Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Binder' BindName -> BindName
forall a. Binder' a -> a
A.binderName) List1 (NamedArg (Binder' BindName))
xps
tac <- (Ranged Expr -> TCM Term)
-> Maybe (Ranged Expr) -> 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 (LamOrPi -> Ranged Expr -> TCM Term
checkTacticAttribute LamOrPi
lamOrPi) (Maybe (Ranged Expr) -> TCMT IO (Maybe Term))
-> Maybe (Ranged Expr) -> TCMT IO (Maybe Term)
forall a b. (a -> b) -> a -> b
$
TacticAttribute -> Maybe (Ranged Expr)
forall a. TacticAttribute' a -> Maybe (Ranged a)
theTacticAttribute (TacticAttribute -> Maybe (Ranged Expr))
-> TacticAttribute -> Maybe (Ranged Expr)
forall a b. (a -> b) -> a -> b
$ TypedBindingInfo -> TacticAttribute
tbTacticAttr TypedBindingInfo
tac
whenJust tac $ \ Term
t -> String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.term.tactic" Int
30 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"Checked tactic attribute:" 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
t
let x = BindName -> Name
unBind (BindName -> Name) -> BindName -> Name
forall a b. (a -> b) -> a -> b
$ Binder' BindName -> BindName
forall a. Binder' a -> a
binderName (Binder' BindName -> BindName) -> Binder' BindName -> BindName
forall a b. (a -> b) -> a -> b
$ NamedArg (Binder' BindName) -> Binder' BindName
forall a. NamedArg a -> a
namedArg (NamedArg (Binder' BindName) -> Binder' BindName)
-> NamedArg (Binder' BindName) -> Binder' BindName
forall a b. (a -> b) -> a -> b
$ List1 (NamedArg (Binder' BindName)) -> NamedArg (Binder' BindName)
forall a. NonEmpty a -> a
List1.head List1 (NamedArg (Binder' BindName))
xps
t <- checkDomain lamOrPi (Just x) xps e
List1.unlessNull (List1.filter isInstance xps) $ \ List1 (NamedArg (Binder' BindName))
ixs -> do
(tel, _, target) <- Type -> TCM (Telescope, Term, OutputTypeName)
getOutputTypeName Type
t
case target of
OutputTypeName{} -> () -> TCM ()
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
OutputTypeVar{} -> () -> TCM ()
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
OutputTypeNameNotYetKnown{} -> () -> TCM ()
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
OutputTypeVisiblePi{} -> Expr -> TCM () -> TCM ()
forall (m :: * -> *) x a.
(MonadTrace m, HasRange x) =>
x -> m a -> m a
setCurrentRange Expr
e (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$
Warning -> TCM ()
forall (m :: * -> *) e.
(HasCallStack, MonadWarning m, Diagnostic e) =>
e -> m ()
warning (Warning -> TCM ()) -> (Doc -> Warning) -> Doc -> TCM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Warning
InstanceArgWithExplicitArg (Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TypedBinding -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => TypedBinding -> m Doc
prettyTCM (Range
-> List1 (NamedArg (Binder' BindName)) -> Expr -> TypedBinding
A.mkTBind Range
r List1 (NamedArg (Binder' BindName))
ixs Expr
e)
OutputTypeName
NoOutputTypeName -> Expr -> TCM () -> TCM ()
forall (m :: * -> *) x a.
(MonadTrace m, HasRange x) =>
x -> m a -> m a
setCurrentRange Expr
e (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$
Warning -> TCM ()
forall (m :: * -> *) e.
(HasCallStack, MonadWarning m, Diagnostic e) =>
e -> m ()
warning (Warning -> TCM ()) -> (Doc -> Warning) -> Doc -> TCM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> Warning
InstanceNoOutputTypeName (Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TypedBinding -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => TypedBinding -> m Doc
prettyTCM (Range
-> List1 (NamedArg (Binder' BindName)) -> Expr -> TypedBinding
A.mkTBind Range
r List1 (NamedArg (Binder' BindName))
ixs Expr
e)
let setTac Maybe t
tac Dom' t e
dom = Dom' t e
dom Dom' t e -> (Dom' t e -> Dom' t e) -> Dom' t e
forall a b. a -> (a -> b) -> b
& (Maybe t -> Identity (Maybe t)) -> Dom' t e -> Identity (Dom' t e)
forall t e (f :: * -> *).
Functor f =>
(Maybe t -> f (Maybe t)) -> Dom' t e -> f (Dom' t e)
dTactic ((Maybe t -> Identity (Maybe t))
-> Dom' t e -> Identity (Dom' t e))
-> Maybe t -> Dom' t e -> Dom' t e
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Maybe t
tac
setTacTel Maybe t
tac Tele (Dom' t e)
EmptyTel = Tele (Dom' t e)
forall a. Tele a
EmptyTel
setTacTel Maybe t
tac (ExtendTel Dom' t e
dom Abs (Tele (Dom' t e))
tel) =
Dom' t e -> Abs (Tele (Dom' t e)) -> Tele (Dom' t e)
forall a. a -> Abs (Tele a) -> Tele a
ExtendTel (Maybe t -> Dom' t e -> Dom' t e
forall {t} {e}. Maybe t -> Dom' t e -> Dom' t e
setTac Maybe t
tac Dom' t e
dom) (Abs (Tele (Dom' t e)) -> Tele (Dom' t e))
-> Abs (Tele (Dom' t e)) -> Tele (Dom' t e)
forall a b. (a -> b) -> a -> b
$
Maybe t -> Tele (Dom' t e) -> Tele (Dom' t e)
setTacTel (Int -> Maybe t -> Maybe t
forall a. Subst a => Int -> a -> a
raise Int
1 Maybe t
tac) (Tele (Dom' t e) -> Tele (Dom' t e))
-> Abs (Tele (Dom' t e)) -> Abs (Tele (Dom' t e))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Abs (Tele (Dom' t e))
tel
xs' = Maybe Term -> Dom' Term Name -> Dom' Term Name
forall {t} {e}. Maybe t -> Dom' t e -> Dom' t e
setTac Maybe Term
tac
(Dom' Term Name -> Dom' Term Name)
-> (NamedArg Name -> Dom' Term Name)
-> NamedArg Name
-> Dom' Term Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NamedArg Name -> Dom' Term Name
domNameFromNamedArgName
(NamedArg Name -> Dom' Term Name)
-> List1 (NamedArg Name) -> NonEmpty (Dom' Term Name)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> List1 (NamedArg Name)
xs
let tel = Maybe Term -> Telescope -> Telescope
forall {t} {e}.
Subst t =>
Maybe t -> Tele (Dom' t e) -> Tele (Dom' t e)
setTacTel Maybe Term
tac (Telescope -> Telescope) -> Telescope -> Telescope
forall a b. (a -> b) -> a -> b
$ List1 (NamedArg Name) -> Type -> Telescope
namedBindsToTel1 List1 (NamedArg Name)
xs Type
t
addContext (xs', t) $ addTypedPatterns xps (ret tel)
checkTypedBindings LamOrPi
lamOrPi (A.TLet Range
_ List1 LetBinding
lbs) Telescope -> TCM a
ret = do
List1 LetBinding -> TCM a -> TCM a
forall (t :: * -> *) a.
Foldable t =>
t LetBinding -> TCM a -> TCM a
checkLetBindings List1 LetBinding
lbs (Telescope -> TCM a
ret Telescope
forall a. Tele a
EmptyTel)
addTypedPatterns :: List1 (NamedArg A.Binder) -> TCM a -> TCM a
addTypedPatterns :: forall a. List1 (NamedArg (Binder' BindName)) -> TCM a -> TCM a
addTypedPatterns List1 (NamedArg (Binder' BindName))
xps TCM a
ret = do
let
ps :: [(Pattern, BindName)]
ps = (NamedArg (Binder' BindName) -> Maybe (Pattern, BindName))
-> List1 (NamedArg (Binder' BindName)) -> [(Pattern, BindName)]
forall a b. (a -> Maybe b) -> List1 a -> [b]
List1.mapMaybe (Binder' BindName -> Maybe (Pattern, BindName)
forall a. Binder' a -> Maybe (Pattern, a)
A.extractPattern (Binder' BindName -> Maybe (Pattern, BindName))
-> (NamedArg (Binder' BindName) -> Binder' BindName)
-> NamedArg (Binder' BindName)
-> Maybe (Pattern, BindName)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NamedArg (Binder' BindName) -> Binder' BindName
forall a. NamedArg a -> a
namedArg) List1 (NamedArg (Binder' BindName))
xps
lbs :: [LetBinding]
lbs = ((Pattern, BindName) -> LetBinding)
-> [(Pattern, BindName)] -> [LetBinding]
forall a b. (a -> b) -> [a] -> [b]
map' (Pattern, BindName) -> LetBinding
letBinding [(Pattern, BindName)]
ps
letBinding :: (A.Pattern, A.BindName) -> A.LetBinding
letBinding :: (Pattern, BindName) -> LetBinding
letBinding (Pattern
p, BindName
n) = LetInfo -> Pattern -> Expr -> LetBinding
A.LetPatBind (Range -> LetInfo
A.LetRange Range
r) Pattern
p (Name -> Expr
A.Var (Name -> Expr) -> Name -> Expr
forall a b. (a -> b) -> a -> b
$ BindName -> Name
A.unBind BindName
n)
where r :: Range
r = Pattern -> BindName -> Range
forall u t. (HasRange u, HasRange t) => u -> t -> Range
fuseRange Pattern
p BindName
n
[LetBinding] -> TCM a -> TCM a
forall (t :: * -> *) a.
Foldable t =>
t LetBinding -> TCM a -> TCM a
checkLetBindings' [LetBinding]
lbs TCM a
ret
checkTacticAttribute :: LamOrPi -> Ranged A.Expr -> TCM Term
checkTacticAttribute :: LamOrPi -> Ranged Expr -> TCM Term
checkTacticAttribute (LamNotPi ModTelOrigin
ModTelData) (Ranged Range
r Expr
e) = Range -> TCM Term -> TCM Term
forall (m :: * -> *) x a.
(MonadTrace m, HasRange x) =>
x -> m a -> m a
setCurrentRange Range
r (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$
TypeError -> TCM Term
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> TCM Term) -> TypeError -> TCM Term
forall a b. (a -> b) -> a -> b
$ TypeError
TacticAttributeNotAllowed
checkTacticAttribute LamOrPi
_ (Ranged Range
r Expr
e) = do
expectedType <- TCM Term -> TCM Type
forall (m :: * -> *). Functor m => m Term -> m Type
el TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primAgdaTerm TCM Type -> TCM Type -> TCM Type
forall (m :: * -> *). HasOptions m => m Type -> m Type -> m Type
--> TCM Term -> TCM Type
forall (m :: * -> *). Functor m => m Term -> m Type
el (TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primAgdaTCM TCM Term -> TCM Term -> TCM Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<#> TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primLevelZero TCM Term -> TCM Term -> TCM Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primUnit)
checkExpr e expectedType
checkPath :: NamedArg Binder -> A.Type -> A.Expr -> Type -> TCM Term
checkPath :: NamedArg (Binder' BindName) -> Expr -> Expr -> Type -> TCM Term
checkPath NamedArg (Binder' BindName)
xp Expr
typ Expr
body Type
ty = do
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.term.lambda" Int
30 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
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
"checking path lambda", NamedArg (Binder' BindName) -> TCMT IO Doc
forall a (m :: * -> *).
(ToConcrete a, Pretty (ConOfAbs a), MonadAbsToCon m) =>
a -> m Doc
prettyA NamedArg (Binder' BindName)
xp ]
case (Binder' BindName -> Maybe (Pattern, BindName)
forall a. Binder' a -> Maybe (Pattern, a)
A.extractPattern (Binder' BindName -> Maybe (Pattern, BindName))
-> Binder' BindName -> Maybe (Pattern, BindName)
forall a b. (a -> b) -> a -> b
$ NamedArg (Binder' BindName) -> Binder' BindName
forall a. NamedArg a -> a
namedArg NamedArg (Binder' BindName)
xp) of
Just{} -> NamedArg (Binder' BindName) -> TCM Term -> TCM Term
forall (m :: * -> *) x a.
(MonadTrace m, HasRange x) =>
x -> m a -> m a
setCurrentRange NamedArg (Binder' BindName)
xp (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ TypeError -> TCM Term
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError TypeError
PatternInPathLambda
Maybe (Pattern, BindName)
Nothing -> do
let x :: NamedArg Name
x = (Binder' BindName -> Name)
-> NamedArg (Binder' BindName) -> NamedArg Name
forall a b. (a -> b) -> NamedArg a -> NamedArg b
updateNamedArg (BindName -> Name
A.unBind (BindName -> Name)
-> (Binder' BindName -> BindName) -> Binder' BindName -> Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Binder' BindName -> BindName
forall a. Binder' a -> a
A.binderName) NamedArg (Binder' BindName)
xp
info :: ArgInfo
info = NamedArg Name -> ArgInfo
forall a. LensArgInfo a => a -> ArgInfo
getArgInfo NamedArg Name
x
PathType s path level typ lhs rhs <- Type -> TCMT IO PathView
forall (m :: * -> *). HasBuiltins m => Type -> m PathView
pathView Type
ty
interval <- primIntervalType
v <- addContext ([x], interval) $
checkExpr body (El (raise 1 s) (raise 1 (unArg typ) `apply` [argN $ var 0]))
iZero <- primIZero
iOne <- primIOne
let lhs' = Int -> SubstArg Term -> Term -> Term
forall a. Subst a => Int -> SubstArg a -> a -> a
subst Int
0 Term
SubstArg Term
iZero Term
v
rhs' = Int -> SubstArg Term -> Term -> Term
forall a. Subst a => Int -> SubstArg a -> a -> a
subst Int
0 Term
SubstArg Term
iOne Term
v
let t = ArgInfo -> Abs Term -> Term
Lam ArgInfo
info (Abs Term -> Term) -> Abs Term -> Term
forall a b. (a -> b) -> a -> b
$ ArgName -> Term -> Abs Term
forall a. ArgName -> a -> Abs a
Abs (NamedArg Name -> ArgName
namedArgName NamedArg Name
x) Term
v
let btyp Term
i = Sort' Term -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El Sort' Term
s (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
typ Term -> [Arg Term] -> Term
forall t. Apply t => t -> [Arg Term] -> t
`apply` [Term -> Arg Term
forall e. e -> Arg e
argN Term
i])
locallyTC eRange (const noRange) $ blockTerm ty $ setCurrentRange body $ do
equalTerm (btyp iZero) lhs' (unArg lhs)
equalTerm (btyp iOne) rhs' (unArg rhs)
return t
checkLambda :: Comparison -> A.TypedBinding -> A.Expr -> Type -> TCM Term
checkLambda :: Comparison -> TypedBinding -> Expr -> Type -> TCM Term
checkLambda Comparison
cmp (A.TLet Range
_ List1 LetBinding
lbs) Expr
body Type
target =
List1 LetBinding -> TCM Term -> TCM Term
forall (t :: * -> *) a.
Foldable t =>
t LetBinding -> TCM a -> TCM a
checkLetBindings List1 LetBinding
lbs (Expr -> Type -> TCM Term
checkExpr Expr
body Type
target)
checkLambda Comparison
cmp b :: TypedBinding
b@(A.TBind Range
r TypedBindingInfo
tac List1 (NamedArg (Binder' BindName))
xps0 Expr
typ) Expr
body Type
target = do
(tel, tgt0) <- NamedArg (Binder' BindName) -> Type -> TCM (Telescope, Type)
forall a. HasRange a => NamedArg a -> Type -> TCM (Telescope, Type)
splitImplicitBinderT (List1 (NamedArg (Binder' BindName)) -> NamedArg (Binder' BindName)
forall a. NonEmpty a -> a
List1.head List1 (NamedArg (Binder' BindName))
xps0) Type
target
abstract tel <$> addContext tel do
checkLambda' cmp r tac xps0 typ body tgt0
checkLambda' ::
Comparison
-> Range
-> A.TypedBindingInfo
-> List1 (NamedArg Binder)
-> A.Type
-> A.Expr
-> Type
-> TCM Term
checkLambda' :: Comparison
-> Range
-> TypedBindingInfo
-> List1 (NamedArg (Binder' BindName))
-> Expr
-> Expr
-> Type
-> TCM Term
checkLambda' Comparison
cmp Range
r TypedBindingInfo
tac List1 (NamedArg (Binder' BindName))
xps Expr
typ Expr
body Type
target = do
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.term.lambda" Int
30 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
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
"checkLambda xs =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> List1 (NamedArg (Binder' BindName)) -> TCMT IO Doc
forall a (m :: * -> *).
(ToConcrete a, Pretty (ConOfAbs a), MonadAbsToCon m) =>
a -> m Doc
prettyA List1 (NamedArg (Binder' BindName))
xps
, TCMT IO Doc
"possiblePath =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Bool -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Bool -> m Doc
prettyTCM Bool
possiblePath
, TCMT IO Doc
"numbinds =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Int -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Int -> m Doc
prettyTCM Int
numbinds
, TCMT IO Doc
"typ =" 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 -> Expr
unScope Expr
typ)
, TCMT IO Doc
"target =" 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
target
, TCMT IO Doc
"tactic =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> TacticAttribute -> TCMT IO Doc
forall a (m :: * -> *).
(ToConcrete a, Pretty (ConOfAbs a), MonadAbsToCon m) =>
a -> m Doc
prettyA (TypedBindingInfo -> TacticAttribute
tbTacticAttr TypedBindingInfo
tac)
]
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.term.lambda" Int
60 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
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
"info =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> (String -> TCMT IO Doc
forall (m :: * -> *). Applicative m => String -> m Doc
text (String -> TCMT IO Doc)
-> (ArgInfo -> String) -> ArgInfo -> TCMT IO Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArgInfo -> String
forall a. Show a => a -> String
show) ArgInfo
info
]
case TypedBindingInfo
tac of
TypedBindingInfo
_ | TypedBindingInfo -> Bool
forall a. Null a => a -> Bool
null TypedBindingInfo
tac -> () -> TCM ()
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
A.TypedBindingInfo{ tbTacticAttr :: TypedBindingInfo -> TacticAttribute
tbTacticAttr = TacticAttribute (Just (Ranged Range
r Expr
e)) } -> do
Range -> TCM () -> TCM ()
forall (m :: * -> *) x a.
(MonadTrace m, HasRange x) =>
x -> m a -> m a
setCurrentRange Range
r (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$ TypeError -> TCM ()
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> TCM ()) -> TypeError -> TCM ()
forall a b. (a -> b) -> a -> b
$ TypeError
TacticAttributeNotAllowed
TypedBindingInfo
_ -> TCM ()
forall a. HasCallStack => a
__IMPOSSIBLE__
TelV tel btyp <- Int -> Type -> TCMT IO (TelV Type)
forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Int -> Type -> m (TelV Type)
telViewUpTo Int
numbinds Type
target
reportSDoc "tc.term.lambda" 30 $ vcat
[ "tel =" <+> prettyTCM tel
, "btyp =" <+> prettyTCM btyp
, "blocked =" <+> (pretty =<< isBlocked btyp)
]
if numbinds == 1 && not (null tel) then useTargetType tel btyp
else if possiblePath then trySeeingIfPath
else dontUseTargetType
where
b :: TypedBinding
b = Range
-> TypedBindingInfo
-> List1 (NamedArg (Binder' BindName))
-> Expr
-> TypedBinding
A.TBind Range
r TypedBindingInfo
tac List1 (NamedArg (Binder' BindName))
xps Expr
typ
xs :: List1 (NamedArg Name)
xs :: List1 (NamedArg Name)
xs = (NamedArg (Binder' BindName) -> NamedArg Name)
-> List1 (NamedArg (Binder' BindName)) -> List1 (NamedArg Name)
forall a b. (a -> b) -> NonEmpty a -> NonEmpty b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Binder' BindName -> Name)
-> NamedArg (Binder' BindName) -> NamedArg Name
forall a b. (a -> b) -> NamedArg a -> NamedArg b
updateNamedArg (BindName -> Name
A.unBind (BindName -> Name)
-> (Binder' BindName -> BindName) -> Binder' BindName -> Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Binder' BindName -> BindName
forall a. Binder' a -> a
A.binderName)) List1 (NamedArg (Binder' BindName))
xps
numbinds :: Int
numbinds = List1 (NamedArg (Binder' BindName)) -> Int
forall a. NonEmpty a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length List1 (NamedArg (Binder' BindName))
xps
possiblePath :: Bool
possiblePath = Int
numbinds Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1 Bool -> Bool -> Bool
&& Expr -> Bool
forall a. Underscore a => a -> Bool
isUnderscore (Expr -> Expr
unScope Expr
typ)
Bool -> Bool -> Bool
&& ArgInfo -> Bool
forall a. LensHiding a => a -> Bool
visible ArgInfo
info
info :: ArgInfo
info = NamedArg Name -> ArgInfo
forall a. LensArgInfo a => a -> ArgInfo
getArgInfo (NamedArg Name -> ArgInfo) -> NamedArg Name -> ArgInfo
forall a b. (a -> b) -> a -> b
$ List1 (NamedArg Name) -> NamedArg Name
forall a. NonEmpty a -> a
List1.head List1 (NamedArg Name)
xs
trySeeingIfPath :: TCM Term
trySeeingIfPath = Type
-> (Blocker -> Type -> TCM Term)
-> (NotBlocked -> Type -> TCM Term)
-> TCM Term
forall t (m :: * -> *) a.
(Reduce t, IsMeta t, MonadReduce m) =>
t -> (Blocker -> t -> m a) -> (NotBlocked -> t -> m a) -> m a
ifBlocked Type
target Blocker -> Type -> TCM Term
postpone ((NotBlocked -> Type -> TCM Term) -> TCM Term)
-> (NotBlocked -> Type -> TCM Term) -> TCM Term
forall a b. (a -> b) -> a -> b
$ \ NotBlocked
_ Type
t -> do
TCMT IO Bool -> TCM Term -> TCM Term -> TCM Term
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
ifNotM (PathView -> Bool
isPathType (PathView -> Bool) -> TCMT IO PathView -> TCMT IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type -> TCMT IO PathView
forall (m :: * -> *). HasBuiltins m => Type -> m PathView
pathView Type
t) TCM Term
dontUseTargetType do
NamedArg (Binder' BindName) -> Expr -> Expr -> Type -> TCM Term
checkPath (List1 (NamedArg (Binder' BindName)) -> NamedArg (Binder' BindName)
forall a. NonEmpty a -> a
List1.head List1 (NamedArg (Binder' BindName))
xps) Expr
typ Expr
body Type
t
postpone_ :: TCM Term
postpone_ = TypeCheckingProblem -> TCM Term
postponeTypeCheckingProblem_ (TypeCheckingProblem -> TCM Term)
-> TypeCheckingProblem -> TCM Term
forall a b. (a -> b) -> a -> b
$
Comparison -> Expr -> Type -> TypeCheckingProblem
CheckExpr Comparison
cmp (ExprInfo -> LamBinding -> Expr -> Expr
A.Lam ExprInfo
A.exprNoRange (TypedBinding -> LamBinding
A.DomainFull TypedBinding
b) Expr
body) Type
target
postpone :: Blocker -> Type -> TCM Term
postpone Blocker
blocker Type
tgt = (TypeCheckingProblem -> Blocker -> TCM Term)
-> Blocker -> TypeCheckingProblem -> TCM Term
forall a b c. (a -> b -> c) -> b -> a -> c
flip TypeCheckingProblem -> Blocker -> TCM Term
postponeTypeCheckingProblem Blocker
blocker (TypeCheckingProblem -> TCM Term)
-> TypeCheckingProblem -> TCM Term
forall a b. (a -> b) -> a -> b
$
Comparison -> Expr -> Type -> TypeCheckingProblem
CheckExpr Comparison
cmp (ExprInfo -> LamBinding -> Expr -> Expr
A.Lam ExprInfo
A.exprNoRange (TypedBinding -> LamBinding
A.DomainFull TypedBinding
b) Expr
body) Type
tgt
dontUseTargetType :: TCM Term
dontUseTargetType = do
String -> Int -> TCM () -> TCM ()
forall (m :: * -> *). MonadDebug m => String -> Int -> m () -> m ()
verboseS String
"tc.term.lambda" Int
5 (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$ String -> TCM ()
forall (m :: * -> *). MonadStatistics m => String -> m ()
tick String
"lambda-no-target-type"
argsT <- TCM Type -> TCM Type
forall (m :: * -> *) a. (MonadTCEnv m, MonadDebug m) => m a -> m a
workOnTypes (TCM Type -> TCM Type) -> TCM Type -> TCM Type
forall a b. (a -> b) -> a -> b
$ Expr -> TCM Type
isType_ Expr
typ
let tel = List1 (NamedArg Name) -> Type -> Telescope
namedBindsToTel1 List1 (NamedArg Name)
xs Type
argsT
reportSDoc "tc.term.lambda" 30 $ "dontUseTargetType tel =" <+> pretty tel
let postponeOnBlockedPattern TCM (Type, Term)
m = TCM (Type, Term)
m TCM (Type, Term)
-> ((TCErr, Blocker) -> TCM (Type, Term)) -> TCM (Type, Term)
forall a. TCM a -> ((TCErr, Blocker) -> TCM a) -> TCM a
`catchIlltypedPatternBlockedOnMeta` \(TCErr
err , Blocker
x) -> do
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.term" Int
50 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
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
"checking record pattern stuck on meta: " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> String -> TCMT IO Doc
forall (m :: * -> *). Applicative m => String -> m Doc
text (Blocker -> String
forall a. Show a => a -> String
show Blocker
x) ]
t1 <- (List1 (NamedArg Name), Type) -> TCM Type -> TCM Type
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
forall (m :: * -> *) a.
MonadAddContext m =>
(List1 (NamedArg Name), Type) -> m a -> m a
addContext (List1 (NamedArg Name)
xs, Type
argsT) (TCM Type -> TCM Type) -> TCM Type -> TCM Type
forall a b. (a -> b) -> a -> b
$ TCM Type -> TCM Type
forall (m :: * -> *) a. (MonadTCEnv m, MonadDebug m) => m a -> m a
workOnTypes TCM Type
newTypeMeta_
let e = ExprInfo -> LamBinding -> Expr -> Expr
A.Lam ExprInfo
A.exprNoRange (TypedBinding -> LamBinding
A.DomainFull TypedBinding
b) Expr
body
tgt' = Telescope -> Type -> Type
telePi Telescope
tel Type
t1
w <- postponeTypeCheckingProblem (CheckExpr cmp e tgt') x
return (tgt' , w)
(target0 , w) <- postponeOnBlockedPattern $
addContext (xs, argsT) $ addTypedPatterns xps $ do
t1 <- workOnTypes newTypeMeta_
v <- checkExpr' cmp body t1
return (abstract tel t1 , abstract tel v)
if notVisible info || any notVisible xs then do
pid <- newProblem_ $ leqType target0 target
blockTermOnProblem target w pid
else do
coerce cmp w target0 target
useTargetType :: Telescope -> Type -> TCM Term
useTargetType tel :: Telescope
tel@(ExtendTel Dom Type
dom (Abs ArgName
y Telescope
EmptyTel)) Type
btyp = do
String -> Int -> TCM () -> TCM ()
forall (m :: * -> *). MonadDebug m => String -> Int -> m () -> m ()
verboseS String
"tc.term.lambda" Int
5 (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$ String -> TCM ()
forall (m :: * -> *). MonadStatistics m => String -> m ()
tick String
"lambda-with-target-type"
String -> Int -> String -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> String -> m ()
reportSLn String
"tc.term.lambda" Int
30 (String -> TCM ()) -> String -> TCM ()
forall a b. (a -> b) -> a -> b
$ String
"useTargetType y = " String -> String -> String
forall a. [a] -> [a] -> [a]
++! ArgName -> String
TS.unpack ArgName
y
let (NamedArg Name
x :| []) = List1 (NamedArg Name)
xs
Bool -> TCM () -> TCM ()
forall b (m :: * -> *). (IsBool b, Monad m) => b -> m () -> m ()
unless (Dom Type -> ArgInfo -> Bool
forall a b. (LensHiding a, LensHiding b) => a -> b -> Bool
sameHiding Dom Type
dom ArgInfo
info) (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$ TypeError -> TCM ()
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> TCM ()) -> TypeError -> TCM ()
forall a b. (a -> b) -> a -> b
$ Hiding -> Type -> TypeError
WrongHidingInLambda (ArgInfo -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding ArgInfo
info) Type
target
Bool -> TCM () -> TCM ()
forall b (m :: * -> *). (IsBool b, Monad m) => b -> m () -> m ()
when (Maybe (WithOrigin (Ranged ArgName)) -> Bool
forall a. Maybe a -> Bool
isJust (Maybe (WithOrigin (Ranged ArgName)) -> Bool)
-> Maybe (WithOrigin (Ranged ArgName)) -> Bool
forall a b. (a -> b) -> a -> b
$ NamedArg Name -> Maybe (NameOf (NamedArg Name))
forall a. LensNamed a => a -> Maybe (NameOf a)
getNameOf NamedArg Name
x) (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$
Bool -> TCM () -> TCM ()
forall b (m :: * -> *). (IsBool b, Monad m) => b -> m () -> m ()
unless (Dom Type -> NamedArg Name -> Bool
forall a b.
(LensNamed a, LensNamed b, NameOf a ~ WithOrigin (Ranged ArgName),
NameOf b ~ WithOrigin (Ranged ArgName)) =>
a -> b -> Bool
namedSame Dom Type
dom NamedArg Name
x) (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$
NamedArg Name -> TCM () -> TCM ()
forall (m :: * -> *) x a.
(MonadTrace m, HasRange x) =>
x -> m a -> m a
setCurrentRange NamedArg Name
x (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$ TypeError -> TCM ()
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> TCM ()) -> TypeError -> TCM ()
forall a b. (a -> b) -> a -> b
$ Hiding -> TypeError
WrongHidingInLHS (Hiding -> TypeError) -> Hiding -> TypeError
forall a b. (a -> b) -> a -> b
$ NamedArg Name -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding NamedArg Name
x
let a :: Type
a = Dom Type -> Type
forall t e. Dom' t e -> e
unDom Dom Type
dom
(pid, argT) <- TCM Type -> TCMT IO (ProblemId, Type)
forall (m :: * -> *) a.
(MonadFresh ProblemId m, MonadConstraint m) =>
m a -> m (ProblemId, a)
newProblem (TCM Type -> TCMT IO (ProblemId, Type))
-> TCM Type -> TCMT IO (ProblemId, Type)
forall a b. (a -> b) -> a -> b
$ Expr -> Type -> TCM Type
isTypeEqualTo Expr
typ Type
a
v <- lambdaAddContext (namedArg x) y (defaultArgDom info argT) $
addTypedPatterns xps $ checkExpr' cmp body btyp
blockTermOnProblem target (Lam info $ Abs (namedArgName x) v) pid
useTargetType Telescope
_ Type
_ = TCM Term
forall a. HasCallStack => a
__IMPOSSIBLE__
lambdaAddContext :: MonadAddContext m => Name -> ArgName -> Dom Type -> m a -> m a
lambdaAddContext :: forall (m :: * -> *) a.
MonadAddContext m =>
Name -> ArgName -> Dom Type -> m a -> m a
lambdaAddContext Name
x ArgName
y Dom Type
dom
| Name -> Bool
forall a. IsNoName a => a -> Bool
isNoName Name
x = (ArgName, Dom Type) -> m a -> m a
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
forall (m :: * -> *) a.
MonadAddContext m =>
(ArgName, Dom Type) -> m a -> m a
addContext (ArgName
y, Dom Type
dom)
| Bool
otherwise = (Name, Dom Type) -> m a -> m a
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
forall (m :: * -> *) a.
MonadAddContext m =>
(Name, Dom Type) -> m a -> m a
addContext (Name
x, Dom Type
dom)
checkAbsurdLambda :: Comparison -> A.ExprInfo -> Hiding -> A.Expr -> Type -> TCM Term
checkAbsurdLambda :: Comparison -> ExprInfo -> Hiding -> Expr -> Type -> TCM Term
checkAbsurdLambda Comparison
cmp ExprInfo
i Hiding
h Expr
e Type
t = do
t <- Type -> TCM Type
forall a (m :: * -> *).
(InstantiateFull a, MonadReduce m) =>
a -> m a
instantiateFull Type
t
ifBlocked t (\ Blocker
blocker Type
t' -> TypeCheckingProblem -> Blocker -> TCM Term
postponeTypeCheckingProblem (Comparison -> Expr -> Type -> TypeCheckingProblem
CheckExpr Comparison
cmp Expr
e Type
t') Blocker
blocker) $ \ NotBlocked
_ Type
t' -> do
case Type -> Term
forall t a. Type'' t a -> a
unEl Type
t' of
Pi dom :: Dom Type
dom@(Dom Type -> Type
forall t e. Dom' t e -> e
unDom -> Type
a) Abs Type
b -> do
let info' :: ArgInfo
info' = Dom Type
dom Dom Type -> Getting ArgInfo (Dom Type) ArgInfo -> ArgInfo
forall s a. s -> Getting a s a -> a
^. Getting ArgInfo (Dom Type) ArgInfo
forall t e (f :: * -> *).
Functor f =>
(ArgInfo -> f ArgInfo) -> Dom' t e -> f (Dom' t e)
dInfo
if Bool -> Bool
not (Hiding -> ArgInfo -> Bool
forall a b. (LensHiding a, LensHiding b) => a -> b -> Bool
sameHiding Hiding
h ArgInfo
info') then
TypeError -> TCM Term
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> TCM Term) -> TypeError -> TCM Term
forall a b. (a -> b) -> a -> b
$ Hiding -> Type -> TypeError
WrongHidingInLambda (ArgInfo -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding ArgInfo
info') Type
t'
else Type -> TCM Term -> TCM Term
blockTerm Type
t' (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ do
Range -> Type -> TCM ()
ensureEmptyType (ExprInfo -> Range
forall a. HasRange a => a -> Range
getRange ExprInfo
i) Type
a
aux <- Range -> Dom Type -> Abs Type -> TCM QName
makeAbsurdLambda (ExprInfo -> Range
forall a. HasRange a => a -> Range
getRange ExprInfo
i) Dom Type
dom Abs Type
b
Def aux . map' Apply . teleArgs <$> getContextTelescope
Term
_ -> TypeError -> TCM Term
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> TCM Term) -> TypeError -> TCM Term
forall a b. (a -> b) -> a -> b
$ Type -> TypeError
ShouldBePi Type
t'
makeAbsurdLambda :: Range -> Dom Type -> Abs Type -> TCM QName
makeAbsurdLambda :: Range -> Dom Type -> Abs Type -> TCM QName
makeAbsurdLambda Range
r Dom Type
a Abs Type
b = do
let t :: Term
t = Dom Type -> Abs Type -> Term
Pi Dom Type
a Abs Type
b
s :: Sort' Term
s = Dom Type -> Abs Type -> Sort' Term
mkPiSort Dom Type
a Abs Type
b
info :: ArgInfo
info = Dom Type -> ArgInfo
forall t e. Dom' t e -> ArgInfo
domInfo Dom Type
a
top <- TCMT IO ModuleName
forall (m :: * -> *). MonadTCEnv m => m ModuleName
currentModule
aux <- qualify top <$> freshName_ (r, absurdLambdaName)
reportSDoc "tc.term.absurd" 10 $ vcat
[ "Adding absurd function" <+> prettyTCM aux
, nest 2 $ "of type" <+> prettyTCM t
]
let fun = FunctionData
emptyFunctionData
addConstant aux $
(\ Defn
d -> (ArgInfo -> QName -> Type -> Defn -> Definition
defaultDefn ArgInfo
info QName
aux (Sort' Term -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El Sort' Term
s Term
t) Defn
d)
{ defPolarity = [Nonvariant]
, defArgOccurrences = [Unused] })
$ FunctionDefn fun
{ _funClauses =
[ Clause
{ clauseLHSRange = r
, clauseFullRange = r
, clauseTel = telFromList [fmap (absurdPatternName,) a]
, namedClausePats = [Arg info $ Named (Just $ WithOrigin Inserted $ unranged $ absName b) $ absurdP 0]
, clauseBody = Nothing
, clauseType = Just $ defaultArg $ absBody b
, clauseCatchall = YesCatchall empty
, clauseRecursive = NotRecursive
, clauseUnreachable = Just True
, clauseEllipsis = NoEllipsis
, clauseWhereModule = Nothing
}
]
, _funCompiled = Just $ Fail [Arg info "()"]
, _funSplitTree = Just $ SplittingDone 0
, _funMutual = Just []
, _funTerminates = Just True
, _funExtLam = Just $ ExtLamInfo top True empty
}
return aux
checkExtendedLambda ::
Comparison -> A.ExprInfo -> A.DefInfo -> QName ->
List1 A.Clause -> A.Expr -> Type -> TCM Term
checkExtendedLambda :: Comparison
-> ExprInfo
-> DefInfo
-> QName
-> List1 Clause
-> Expr
-> Type
-> TCM Term
checkExtendedLambda Comparison
cmp ExprInfo
i DefInfo
di QName
qname List1 Clause
cs Expr
e Type
t = do
do
lamMod <- TCMT IO ModuleName -> TCMT IO ModuleName
forall a. TCM a -> TCM a
inFreshModuleIfFreeParams TCMT IO ModuleName
forall (m :: * -> *). MonadTCEnv m => m ModuleName
currentModule
t <- instantiateFull t
ifBlocked t (\ Blocker
m Type
t' -> TypeCheckingProblem -> TCM Term
postponeTypeCheckingProblem_ (TypeCheckingProblem -> TCM Term)
-> TypeCheckingProblem -> TCM Term
forall a b. (a -> b) -> a -> b
$ Comparison -> Expr -> Type -> TypeCheckingProblem
CheckExpr Comparison
cmp Expr
e Type
t') \ NotBlocked
_ Type
t -> do
j <- TCM MutualId
currentOrFreshMutualBlock
reportSDoc "tc.term.exlam" 20 $ vcat
[ hsep
[ text $ show $ A.defAbstract di
, "extended lambda's implementation"
, doubleQuotes $ prettyTCM qname
, "has type:"
]
, prettyTCM t
]
args <- getContextArgs
abstract (A.defAbstract di) do
addConstant qname =<< do
let fun = Defn
emptyFunction
useTerPragma $
(defaultDefn defaultArgInfo qname t fun)
{ defMutual = j }
checkFunDef' t defaultArgInfo (Just $ ExtLamInfo lamMod False empty) NotWithFunction di qname $
List1.toList cs
whenNothingM (viewTC eMutualBlock) $
checkIApplyConfluence_ qname
return $! Def qname $! map' Apply args
where
abstract :: IsAbstract -> m a -> m a
abstract IsAbstract
ConcreteDef = m a -> m a
forall (m :: * -> *) a. MonadTCEnv m => m a -> m a
inConcreteMode
abstract IsAbstract
AbstractDef = m a -> m a
forall (m :: * -> *) a. MonadTCEnv m => m a -> m a
inAbstractMode
catchIlltypedPatternBlockedOnMeta :: TCM a -> ((TCErr, Blocker) -> TCM a) -> TCM a
catchIlltypedPatternBlockedOnMeta :: forall a. TCM a -> ((TCErr, Blocker) -> TCM a) -> TCM a
catchIlltypedPatternBlockedOnMeta TCM a
m (TCErr, Blocker) -> TCM a
handle = do
st <- TCMT IO TCState
forall (m :: * -> *). MonadTCState m => m TCState
getTC
m `catchError` \ TCErr
err -> do
let reraise :: MonadError TCErr m => m a
reraise :: forall (m :: * -> *) a. MonadError TCErr m => m a
reraise = TCErr -> m a
forall a. TCErr -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError TCErr
err
blocker <- TCMT IO Blocker
-> (Blocker -> TCMT IO Blocker) -> Maybe Blocker -> TCMT IO Blocker
forall b a. b -> (a -> b) -> Maybe a -> b
maybe TCMT IO Blocker
forall (m :: * -> *) a. MonadError TCErr m => m a
reraise Blocker -> TCMT IO Blocker
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Blocker -> TCMT IO Blocker)
-> Maybe Blocker -> TCMT IO Blocker
forall a b. (a -> b) -> a -> b
$! case TCErr
err of
TypeError CallStack
_ TCState
s Closure SomeDiagnostic
cl -> SomeDiagnostic -> Maybe SplitError
forall a. Diagnostic a => SomeDiagnostic -> Maybe a
fromSomeDiagnostic (Closure SomeDiagnostic -> SomeDiagnostic
forall a. Closure a -> a
clValue Closure SomeDiagnostic
cl) Maybe SplitError -> (SplitError -> Maybe Blocker) -> Maybe Blocker
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
SortOfSplitVarError Maybe Blocker
b Doc
_ -> Maybe Blocker
b
UnificationStuck Maybe Blocker
b QName
c Telescope
tel [Arg Term]
us [Arg Term]
vs [UnificationFailure]
_ -> Maybe Blocker
b
BlockedType Blocker
b Closure Type
aClosure -> Blocker -> Maybe Blocker
forall a. a -> Maybe a
Just Blocker
b
CannotEliminateWithPattern Maybe Blocker
b NamedArg Pattern
p Type
a -> Maybe Blocker
b
CannotEliminateWithProjection Maybe Blocker
b Type
_ WhyWrongProj
_ WrongProjectionName
_ -> Maybe Blocker
b
SplitError
_ -> Maybe Blocker
forall a. Maybe a
Nothing
TCErr
_ -> Maybe Blocker
forall a. Maybe a
Nothing
reportSDoc "tc.postpone" 20 $ vcat $
[ "checking definition blocked on: " <+> prettyTCM blocker ]
putTC st
blocker <- (`onBlockingMetasM` blocker) $ \ MetaId
x ->
MetaId -> TCMT IO (Maybe (Either RemoteMetaVariable MetaVariable))
forall (m :: * -> *).
ReadTCState m =>
MetaId -> m (Maybe (Either RemoteMetaVariable MetaVariable))
lookupMeta MetaId
x TCMT IO (Maybe (Either RemoteMetaVariable MetaVariable))
-> (Maybe (Either RemoteMetaVariable MetaVariable)
-> TCMT IO Blocker)
-> TCMT IO Blocker
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
Maybe (Either RemoteMetaVariable MetaVariable)
Nothing -> Blocker -> TCMT IO Blocker
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Blocker
neverUnblock
Just Left{} -> Blocker -> TCMT IO Blocker
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Blocker
alwaysUnblock
Just (Right MetaVariable
m)
| InstV{} <- MetaVariable -> MetaInstantiation
mvInstantiation MetaVariable
m -> Blocker -> TCMT IO Blocker
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Blocker
alwaysUnblock
| Bool
otherwise -> Blocker -> TCMT IO Blocker
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Blocker -> TCMT IO Blocker) -> Blocker -> TCMT IO Blocker
forall a b. (a -> b) -> a -> b
$! MetaId -> Blocker
unblockOnMeta MetaId
x
if blocker `elem` [neverUnblock, alwaysUnblock] then reraise else handle (err, blocker)
expandModuleAssigns
:: [Either A.Assign A.ModuleName]
-> [C.Name]
-> TCM A.Assigns
expandModuleAssigns :: [Either (FieldAssignment' Expr) ModuleName]
-> [Name] -> TCM Assigns
expandModuleAssigns [Either (FieldAssignment' Expr) ModuleName]
mfs [Name]
xs = do
let (Assigns
fs , [ModuleName]
ms) = [Either (FieldAssignment' Expr) ModuleName]
-> (Assigns, [ModuleName])
forall a b. [Either a b] -> ([a], [b])
partitionEithers [Either (FieldAssignment' Expr) ModuleName]
mfs
fs' <- [Name]
-> (Name -> TCMT IO (Maybe (FieldAssignment' Expr)))
-> TCMT IO [Maybe (FieldAssignment' Expr)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM ([Name]
xs [Name] -> [Name] -> [Name]
forall a. Eq a => [a] -> [a] -> [a]
List.\\ (FieldAssignment' Expr -> Name) -> Assigns -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map' (Getting Name (FieldAssignment' Expr) Name
-> FieldAssignment' Expr -> Name
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting Name (FieldAssignment' Expr) Name
forall a (f :: * -> *).
Functor f =>
(Name -> f Name) -> FieldAssignment' a -> f (FieldAssignment' a)
nameFieldA) Assigns
fs) ((Name -> TCMT IO (Maybe (FieldAssignment' Expr)))
-> TCMT IO [Maybe (FieldAssignment' Expr)])
-> (Name -> TCMT IO (Maybe (FieldAssignment' Expr)))
-> TCMT IO [Maybe (FieldAssignment' Expr)]
forall a b. (a -> b) -> a -> b
$ \ Name
f -> do
pms <- [ModuleName]
-> (ModuleName
-> TCMT IO (Maybe (ModuleName, FieldAssignment' Expr)))
-> TCMT IO [Maybe (ModuleName, FieldAssignment' Expr)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [ModuleName]
ms ((ModuleName
-> TCMT IO (Maybe (ModuleName, FieldAssignment' Expr)))
-> TCMT IO [Maybe (ModuleName, FieldAssignment' Expr)])
-> (ModuleName
-> TCMT IO (Maybe (ModuleName, FieldAssignment' Expr)))
-> TCMT IO [Maybe (ModuleName, FieldAssignment' Expr)]
forall a b. (a -> b) -> a -> b
$ \ ModuleName
m -> do
modScope <- ModuleName -> ScopeM Scope
getNamedScope ModuleName
m
let names :: ThingsInScope AbstractName
names = Scope -> ThingsInScope AbstractName
forall a. InScope a => Scope -> ThingsInScope a
exportedNamesInScope Scope
modScope
return $
case Map.lookup f names of
Just (AbstractName
n :| []) -> (ModuleName, FieldAssignment' Expr)
-> Maybe (ModuleName, FieldAssignment' Expr)
forall a. a -> Maybe a
Just (ModuleName
m, Name -> Expr -> FieldAssignment' Expr
forall a. Name -> a -> FieldAssignment' a
FieldAssignment Name
f (Expr -> FieldAssignment' Expr) -> Expr -> FieldAssignment' Expr
forall a b. (a -> b) -> a -> b
$ Expr -> Expr
forall a. KillRange a => KillRangeT a
killRange (Expr -> Expr) -> Expr -> Expr
forall a b. (a -> b) -> a -> b
$ AbstractName -> Expr
forall a. NameToExpr a => a -> Expr
A.nameToExpr AbstractName
n)
Maybe (List1 AbstractName)
_ -> Maybe (ModuleName, FieldAssignment' Expr)
forall a. Maybe a
Nothing
case catMaybes pms of
[] -> Maybe (FieldAssignment' Expr)
-> TCMT IO (Maybe (FieldAssignment' Expr))
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (FieldAssignment' Expr)
forall a. Maybe a
Nothing
[(ModuleName
_, FieldAssignment' Expr
fa)] -> Maybe (FieldAssignment' Expr)
-> TCMT IO (Maybe (FieldAssignment' Expr))
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (FieldAssignment' Expr -> Maybe (FieldAssignment' Expr)
forall a. a -> Maybe a
Just FieldAssignment' Expr
fa)
(ModuleName, FieldAssignment' Expr)
x:(ModuleName, FieldAssignment' Expr)
y:[(ModuleName, FieldAssignment' Expr)]
zs -> TypeError -> TCMT IO (Maybe (FieldAssignment' Expr))
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> TCMT IO (Maybe (FieldAssignment' Expr)))
-> TypeError -> TCMT IO (Maybe (FieldAssignment' Expr))
forall a b. (a -> b) -> a -> b
$ Name -> List2 ModuleName -> TypeError
AmbiguousField Name
f (List2 ModuleName -> TypeError) -> List2 ModuleName -> TypeError
forall a b. (a -> b) -> a -> b
$ ((ModuleName, FieldAssignment' Expr) -> ModuleName)
-> List2 (ModuleName, FieldAssignment' Expr) -> List2 ModuleName
forall a b. (a -> b) -> List2 a -> List2 b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ModuleName, FieldAssignment' Expr) -> ModuleName
forall a b. (a, b) -> a
fst (List2 (ModuleName, FieldAssignment' Expr) -> List2 ModuleName)
-> List2 (ModuleName, FieldAssignment' Expr) -> List2 ModuleName
forall a b. (a -> b) -> a -> b
$ (ModuleName, FieldAssignment' Expr)
-> (ModuleName, FieldAssignment' Expr)
-> [(ModuleName, FieldAssignment' Expr)]
-> List2 (ModuleName, FieldAssignment' Expr)
forall a. a -> a -> [a] -> List2 a
List2 (ModuleName, FieldAssignment' Expr)
x (ModuleName, FieldAssignment' Expr)
y [(ModuleName, FieldAssignment' Expr)]
zs
return (fs ++! catMaybes fs')
checkRecordExpression
:: Comparison
-> A.RecordAssigns
-> A.Expr
-> Type
-> ConOrigin
-> TCM Term
checkRecordExpression :: Comparison
-> [Either (FieldAssignment' Expr) ModuleName]
-> Expr
-> Type
-> ConOrigin
-> TCM Term
checkRecordExpression Comparison
cmp [Either (FieldAssignment' Expr) ModuleName]
mfs e :: Expr
e@(A.Rec KwRange
kwr ExprInfo
_r [Either (FieldAssignment' Expr) ModuleName]
_) Type
t ConOrigin
origin = do
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.term.rec" Int
10 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
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
"checking record expression"
, Expr -> TCMT IO Doc
forall a (m :: * -> *).
(ToConcrete a, Pretty (ConOfAbs a), MonadAbsToCon m) =>
a -> m Doc
prettyA Expr
e
]
let
resume :: TCM Term
resume = TypeCheckingProblem -> TCM Term
postponeTypeCheckingProblem_ (TypeCheckingProblem -> TCM Term)
-> TypeCheckingProblem -> TCM Term
forall a b. (a -> b) -> a -> b
$ Comparison -> Expr -> Type -> TypeCheckingProblem
CheckExpr Comparison
cmp Expr
e Type
t
fields :: [Name]
fields = [ Name
x | Left (FieldAssignment Name
x Expr
_) <- [Either (FieldAssignment' Expr) ModuleName]
mfs ]
Type
-> (Blocker -> Type -> TCM Term)
-> (NotBlocked -> Type -> TCM Term)
-> TCM Term
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
t -> TCM Term -> Comparison -> Expr -> [Name] -> Type -> TCM Term
guessRecordType TCM Term
resume Comparison
cmp Expr
e [Name]
fields Type
t) ((NotBlocked -> Type -> TCM Term) -> TCM Term)
-> (NotBlocked -> Type -> TCM Term) -> TCM Term
forall a b. (a -> b) -> a -> b
$ \ NotBlocked
_ Type
t -> do
case Type -> Term
forall t a. Type'' t a -> a
unEl Type
t of
Def QName
r Elims
es -> do
let vs :: [Arg Term]
vs = Elims -> [Arg Term]
forall a. [Elim' a] -> [Arg a]
mustAllApplyElims Elims
es
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.term.rec" Int
20 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
" r = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall a. Semigroup a => a -> a -> a
<> Doc -> TCMT IO Doc
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (QName -> Doc
forall a. Pretty a => a -> Doc
P.pretty QName
r)
def <- QName -> TCMT IO RecordData
forall (m :: * -> *).
(HasCallStack, HasConstInfo m, ReadTCState m,
MonadError TCErr m) =>
QName -> m RecordData
getRecordDef QName
r
let
cxs = (Dom Name -> Arg Name) -> [Dom Name] -> [Arg Name]
forall a b. (a -> b) -> [a] -> [b]
map' Dom Name -> Arg Name
forall t a. Dom' t a -> Arg a
argFromDom ([Dom Name] -> [Arg Name]) -> [Dom Name] -> [Arg Name]
forall a b. (a -> b) -> a -> b
$ RecordData -> [Dom Name]
recordFieldNames RecordData
def
xs = (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]
cxs
con = KillRangeT ConHead
forall a. KillRange a => KillRangeT a
killRange KillRangeT ConHead -> KillRangeT ConHead
forall a b. (a -> b) -> a -> b
$ RecordData -> ConHead
_recConHead RecordData
def
reportSDoc "tc.term.rec" 20 $ vcat
[ " xs = " <> pure (P.pretty xs)
, " ftel= " <> prettyTCM (_recTel def)
, " con = " <> pure (P.pretty con)
]
disambiguateRecordFields (map' _nameFieldA $ lefts mfs) (map' unDom $ _recFields def)
fs <- expandModuleAssigns mfs xs
scope <- getScope
let meta Name
x = MetaInfo -> Expr
A.Underscore (MetaInfo -> Expr) -> MetaInfo -> Expr
forall a b. (a -> b) -> a -> b
$ Range
-> ScopeInfo -> Maybe MetaId -> ArgName -> MetaKind -> MetaInfo
A.MetaInfo (KwRange -> Range
forall a. HasRange a => a -> Range
getRange KwRange
kwr) ScopeInfo
scope Maybe MetaId
forall a. Maybe a
Nothing (String -> ArgName
TS.pack (String -> ArgName) -> String -> ArgName
forall a b. (a -> b) -> a -> b
$ Name -> String
forall a. Pretty a => a -> String
prettyShow Name
x) MetaKind
A.UnificationMeta
es <- insertMissingFieldsWarn origin r meta fs cxs
args <- checkArguments_ cmp ExpandLast e es (_recTel def `apply` vs) >>= \case
(Elims
elims, Telescope
remainingTel) | Telescope -> Bool
forall a. Null a => a -> Bool
null Telescope
remainingTel
, Just [Arg Term]
args <- Elims -> Maybe [Arg Term]
forall a. [Elim' a] -> Maybe [Arg a]
allApplyElims Elims
elims -> [Arg Term] -> TCMT IO [Arg Term]
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return [Arg Term]
args
(Elims, Telescope)
_ -> TCMT IO [Arg Term]
forall a. HasCallStack => a
__IMPOSSIBLE__
reportSDoc "tc.term.rec" 20 $ text $ "finished record expression"
return $! Con con origin $! map' Apply args
Term
_ -> TypeError -> TCM Term
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> TCM Term) -> TypeError -> TCM Term
forall a b. (a -> b) -> a -> b
$ Type -> TypeError
ShouldBeRecordType Type
t
checkRecordExpression Comparison
_ [Either (FieldAssignment' Expr) ModuleName]
_ Expr
_ Type
_ ConOrigin
_ = TCM Term
forall a. HasCallStack => a
__IMPOSSIBLE__
guessRecordType :: TCM Term -> Comparison -> A.Expr -> [C.Name] -> Type -> TCM Term
guessRecordType :: TCM Term -> Comparison -> Expr -> [Name] -> Type -> TCM Term
guessRecordType TCM Term
resume Comparison
cmp Expr
e [Name]
fields Type
t = do
rs <- [Name] -> TCM [QName]
findPossibleRecords [Name]
fields
reportSDoc "tc.term.rec" 30 $ "Possible records for" <+> prettyTCM t <+> "are" <?> pretty rs
case rs of
[] -> TypeError -> TCM Term
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> TCM Term) -> TypeError -> TCM Term
forall a b. (a -> b) -> a -> b
$ [Name] -> TypeError
NoKnownRecordWithSuchFields [Name]
fields
[QName
r] -> do
def <- Definition -> TCMT IO Definition
forall (m :: * -> *).
(HasConstInfo m, ReadTCState 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, HasCallStack) =>
QName -> m Definition
getConstInfo QName
r
ps <- freeVarsToApply r
let rt = Definition -> Type
defType Definition
def
reportSDoc "tc.term.rec" 30 $ "Type of unique record" <+> prettyTCM rt
TelV paramTel _ <- telView rt
vs <- newTelMeta paramTel
target <- reduce $ piApply rt vs
s <- case unEl target of
Sort Sort' Term
s -> Sort' Term -> TCMT IO (Sort' Term)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Sort' Term
s
Term
v -> do
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"impossible" Int
10 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
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
"The impossible happened when checking record expression against meta"
, TCMT IO Doc
"Candidate record type r = " 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
r
, TCMT IO Doc
"Type of r = " 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
rt
, TCMT IO Doc
"Ends in (should be sort)= " 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
, String -> TCMT IO Doc
forall (m :: * -> *). Applicative m => String -> m Doc
text (String -> TCMT IO Doc) -> String -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ String
" Raw = " String -> String -> String
forall a. [a] -> [a] -> [a]
++! Term -> String
forall a. Show a => a -> String
show Term
v
]
TCMT IO (Sort' Term)
forall a. HasCallStack => a
__IMPOSSIBLE__
let inferred = Sort' Term -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El Sort' Term
s (Term -> Type) -> Term -> Type
forall a b. (a -> b) -> a -> b
$! QName -> Elims -> Term
Def QName
r (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]
ps [Arg Term] -> [Arg Term] -> [Arg Term]
forall a. [a] -> [a] -> [a]
++! [Arg Term]
vs)
v <- checkExpr e inferred
coerce cmp v inferred t
QName
_:QName
_:[QName]
_ -> do
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.term.expr.rec" Int
10 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
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
"Postponing type checking of"
, 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 :: * -> *).
(ToConcrete a, Pretty (ConOfAbs a), MonadAbsToCon m) =>
a -> m Doc
prettyA Expr
e 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 -> 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
]
TCM Term
resume
checkRecordUpdate
:: Comparison
-> KwRange
-> A.ExprInfo
-> A.Expr
-> A.Assigns
-> A.Expr
-> Type
-> TCM Term
checkRecordUpdate :: Comparison
-> KwRange
-> ExprInfo
-> Expr
-> Assigns
-> Expr
-> Type
-> TCM Term
checkRecordUpdate Comparison
cmp KwRange
kwr ExprInfo
ei Expr
recexpr Assigns
fs Expr
eupd Type
t = do
Type
-> (Blocker -> Type -> TCM Term)
-> (NotBlocked -> Type -> TCM Term)
-> TCM Term
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
_ -> TCM Term
tryInfer) ((NotBlocked -> Type -> TCM Term) -> TCM Term)
-> (NotBlocked -> Type -> TCM Term) -> TCM Term
forall a b. (a -> b) -> a -> b
$ \ NotBlocked
_ Type
t' -> do
TCMT IO (Maybe (QName, [Arg Term], RecordData))
-> TCM Term
-> ((QName, [Arg Term], RecordData) -> TCM Term)
-> TCM Term
forall (m :: * -> *) a b.
Monad m =>
m (Maybe a) -> m b -> (a -> m b) -> m b
caseMaybeM (Type -> TCMT IO (Maybe (QName, [Arg Term], RecordData))
forall (m :: * -> *).
(HasCallStack, PureTCM m) =>
Type -> m (Maybe (QName, [Arg Term], RecordData))
isRecordType Type
t') TCM Term
should (((QName, [Arg Term], RecordData) -> TCM Term) -> TCM Term)
-> ((QName, [Arg Term], RecordData) -> TCM Term) -> TCM Term
forall a b. (a -> b) -> a -> b
$ \ (QName
r, [Arg Term]
_pars, RecordData
defn) -> do
v <- Comparison -> Expr -> Type -> TCM Term
checkExpr' Comparison
cmp Expr
recexpr Type
t'
name <- freshNoName $ getRange recexpr
addLetBinding defaultArgInfo Inserted name v t' $ do
let projs = (Dom QName -> Arg QName) -> [Dom QName] -> [Arg QName]
forall a b. (a -> b) -> [a] -> [b]
map' Dom QName -> Arg QName
forall t a. Dom' t a -> Arg a
argFromDom ([Dom QName] -> [Arg QName]) -> [Dom QName] -> [Arg QName]
forall a b. (a -> b) -> a -> b
$ RecordData -> [Dom QName]
_recFields RecordData
defn
disambiguateRecordFields (map' _nameFieldA fs) (map' unArg projs)
let fs' = (FieldAssignment' Expr -> (Name, Maybe Expr))
-> Assigns -> [(Name, Maybe Expr)]
forall a b. (a -> b) -> [a] -> [b]
map' (\ (FieldAssignment Name
x Expr
e) -> (Name
x, Expr -> Maybe Expr
forall a. a -> Maybe a
Just Expr
e)) Assigns
fs
let axs = (Dom Name -> Arg Name) -> [Dom Name] -> [Arg Name]
forall a b. (a -> b) -> [a] -> [b]
map' Dom Name -> Arg Name
forall t a. Dom' t a -> Arg a
argFromDom ([Dom Name] -> [Arg Name]) -> [Dom Name] -> [Arg Name]
forall a b. (a -> b) -> a -> b
$ RecordData -> [Dom Name]
recordFieldNames RecordData
defn
es <- orderFieldsWarn ConORec r (const Nothing) axs fs'
let es' = (Arg QName -> Maybe Expr -> Maybe Expr)
-> [Arg QName] -> [Maybe Expr] -> [Maybe Expr]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (Name -> ExprInfo -> Arg QName -> Maybe Expr -> Maybe Expr
replaceFields Name
name ExprInfo
ei) [Arg QName]
projs [Maybe Expr]
es
let erec = KwRange
-> ExprInfo -> [Either (FieldAssignment' Expr) ModuleName] -> Expr
A.Rec KwRange
kwr ExprInfo
ei [ FieldAssignment' Expr -> Either (FieldAssignment' Expr) ModuleName
forall a b. a -> Either a b
Left (Name -> Expr -> FieldAssignment' Expr
forall a. Name -> a -> FieldAssignment' a
FieldAssignment Name
x Expr
e) | (Arg ArgInfo
_ Name
x, Just Expr
e) <- [Arg Name] -> [Maybe Expr] -> [(Arg Name, Maybe Expr)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Arg Name]
axs [Maybe Expr]
es' ]
checkExpr' cmp erec t
where
replaceFields :: Name -> A.ExprInfo -> Arg A.QName -> Maybe A.Expr -> Maybe A.Expr
replaceFields :: Name -> ExprInfo -> Arg QName -> Maybe Expr -> Maybe Expr
replaceFields Name
name ExprInfo
ei (Arg ArgInfo
ai QName
p) Maybe Expr
Nothing | ArgInfo -> Bool
forall a. LensHiding a => a -> Bool
visible ArgInfo
ai = Expr -> Maybe Expr
forall a. a -> Maybe a
Just (Expr -> Maybe Expr) -> Expr -> Maybe Expr
forall a b. (a -> b) -> a -> b
$
AppInfo -> Expr -> NamedArg Expr -> Expr
A.App
(Range -> AppInfo
A.defaultAppInfo (Range -> AppInfo) -> Range -> AppInfo
forall a b. (a -> b) -> a -> b
$ ExprInfo -> Range
forall a. HasRange a => a -> Range
getRange ExprInfo
ei)
(ProjOrigin -> AmbiguousQName -> Expr
A.Proj ProjOrigin
ProjSystem (AmbiguousQName -> Expr) -> AmbiguousQName -> Expr
forall a b. (a -> b) -> a -> b
$ QName -> AmbiguousQName
unambiguous QName
p)
(Expr -> NamedArg Expr
forall a. a -> NamedArg a
defaultNamedArg (Expr -> NamedArg Expr) -> Expr -> NamedArg Expr
forall a b. (a -> b) -> a -> b
$ Name -> Expr
A.Var Name
name)
replaceFields Name
_ ExprInfo
_ Arg QName
_ Maybe Expr
me = Maybe Expr
me
tryInfer :: TCM Term
tryInfer = do
(_, trec) <- Expr -> TCM (Term, Type)
inferExpr Expr
recexpr
ifBlocked trec (\ Blocker
_ Type
_ -> TCM Term
postpone) $ \ NotBlocked
_ Type
_ -> do
v <- Comparison -> Expr -> Type -> TCM Term
checkExpr' Comparison
cmp Expr
eupd Type
trec
coerce cmp v trec t
postpone :: TCM Term
postpone = TypeCheckingProblem -> TCM Term
postponeTypeCheckingProblem_ (TypeCheckingProblem -> TCM Term)
-> TypeCheckingProblem -> TCM Term
forall a b. (a -> b) -> a -> b
$ Comparison -> Expr -> Type -> TypeCheckingProblem
CheckExpr Comparison
cmp Expr
eupd Type
t
should :: TCM Term
should = TypeError -> TCM Term
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> TCM Term) -> TypeError -> TCM Term
forall a b. (a -> b) -> a -> b
$ Type -> TypeError
ShouldBeRecordType Type
t
checkRecordWhere
:: Comparison
-> KwRange
-> A.ExprInfo
-> Maybe A.Expr
-> [A.LetBinding]
-> A.Assigns
-> A.Expr
-> Type
-> TCM Term
checkRecordWhere :: Comparison
-> KwRange
-> ExprInfo
-> Maybe Expr
-> [LetBinding]
-> Assigns
-> Expr
-> Type
-> TCM Term
checkRecordWhere Comparison
cmp KwRange
kwr ExprInfo
ei Maybe Expr
update [LetBinding]
decls Assigns
fs Expr
e Type
t = do
let
fnames :: [Name]
fnames = [ Name
x | FieldAssignment Name
x Expr
_ <- Assigns
fs ]
postpone :: TCM Term
postpone = TypeCheckingProblem -> TCM Term
postponeTypeCheckingProblem_ (TypeCheckingProblem -> TCM Term)
-> TypeCheckingProblem -> TCM Term
forall a b. (a -> b) -> a -> b
$ Comparison -> Expr -> Type -> TypeCheckingProblem
CheckExpr Comparison
cmp Expr
e Type
t
tryinfer :: TCM Term
tryinfer
| Just Expr
e0 <- Maybe Expr
update = do
(_, trec) <- Expr -> TCM (Term, Type)
inferExpr Expr
e0
ifBlocked trec (\ Blocker
_ Type
_ -> TCM Term
postpone) \NotBlocked
_ Type
_ -> do
v <- Comparison -> Expr -> Type -> TCM Term
checkExpr' Comparison
cmp Expr
e Type
trec
coerce cmp v trec t
| Bool
otherwise = TCM Term
postpone
findtype :: ((QName, [Arg Term], RecordData) -> TCM Term) -> TCM Term
findtype (QName, [Arg Term], RecordData) -> TCM Term
cont = Type
-> (Blocker -> Type -> TCM Term)
-> (NotBlocked -> Type -> TCM Term)
-> TCM Term
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
t -> TCM Term -> Comparison -> Expr -> [Name] -> Type -> TCM Term
guessRecordType TCM Term
tryinfer Comparison
cmp Expr
e [Name]
fnames Type
t) \NotBlocked
_ Type
t -> do
TCMT IO (Maybe (QName, [Arg Term], RecordData))
-> TCM Term
-> ((QName, [Arg Term], RecordData) -> TCM Term)
-> TCM Term
forall (m :: * -> *) a b.
Monad m =>
m (Maybe a) -> m b -> (a -> m b) -> m b
caseMaybeM (Type -> TCMT IO (Maybe (QName, [Arg Term], RecordData))
forall (m :: * -> *).
(HasCallStack, PureTCM m) =>
Type -> m (Maybe (QName, [Arg Term], RecordData))
isRecordType Type
t) (TypeError -> TCM Term
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> TCM Term) -> TypeError -> TCM Term
forall a b. (a -> b) -> a -> b
$ Type -> TypeError
ShouldBeRecordType Type
t) (QName, [Arg Term], RecordData) -> TCM Term
cont
((QName, [Arg Term], RecordData) -> TCM Term) -> TCM Term
findtype \ (QName
r, [Arg Term]
_pars, RecordData
defn) -> do
let
ei :: ExprInfo
ei = Range -> ExprInfo
A.ExprRange (Expr -> Range
forall a. HasRange a => a -> Range
getRange Expr
e)
cxs :: [Name]
cxs = (Dom Name -> Name) -> [Dom Name] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map' Dom Name -> Name
forall t e. Dom' t e -> e
unDom ([Dom Name] -> [Name]) -> [Dom Name] -> [Name]
forall a b. (a -> b) -> a -> b
$ RecordData -> [Dom Name]
recordFieldNames RecordData
defn
recfs :: Map Name Int
recfs = [(Name, Int)] -> Map Name Int
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(Name, Int)] -> Map Name Int) -> [(Name, Int)] -> Map Name Int
forall a b. (a -> b) -> a -> b
$ [Name] -> [Int] -> [(Name, Int)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Name]
cxs [Int
0..]
names :: Map Name (Int, Name)
names = [(Name, (Int, Name))] -> Map Name (Int, Name)
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
[ (Name
aname, (Int
idx, Name
fname))
| FieldAssignment Name
fname (A.Var Name
aname) <- Assigns
fs
, Just Int
idx <- Maybe Int -> [Maybe Int]
forall a. a -> [a]
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Name -> Map Name Int -> Maybe Int
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Name
fname Map Name Int
recfs)
]
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.record.where" Int
30 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
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 `record where` at 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 (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty Type
t
, TCMT IO Doc
"bound fields:" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Map Name (Int, Name) -> TCMT IO Doc
forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty Map Name (Int, Name)
names
]
let
check :: [A.LetBinding] -> (IntMap.IntMap (A.BindName, MetaId, Term, A.Expr, Type -> TCM Term) -> TCM a) -> TCM a
check :: forall a.
[LetBinding]
-> (IntMap (BindName, MetaId, Term, Expr, Type -> TCM Term)
-> TCM a)
-> TCM a
check (b :: LetBinding
b@(A.LetBind LetInfo
i ArgInfo
info BindName
x Expr
t Expr
e):[LetBinding]
bs) IntMap (BindName, MetaId, Term, Expr, Type -> TCM Term) -> TCM a
cont | Just (Int
idx, Name
fname) <- Name -> Map Name (Int, Name) -> Maybe (Int, Name)
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (BindName -> Name
A.unBind BindName
x) Map Name (Int, Name)
names = do
t <- TCM Type -> TCM Type
forall (m :: * -> *) a. (MonadTCEnv m, MonadDebug m) => m a -> m a
workOnTypes (TCM Type -> TCM Type) -> TCM Type -> TCM Type
forall a b. (a -> b) -> a -> b
$ Expr -> TCM Type
isType_ Expr
t
lets <- Map.keysSet <$> viewTC eLetBindings
let
restore = Lens' TCEnv (Map Name (Open LetBinding))
-> (Map Name (Open LetBinding) -> Map Name (Open LetBinding))
-> TCM Term
-> TCM Term
forall (m :: * -> *) a b.
MonadTCEnv m =>
Lens' TCEnv a -> (a -> a) -> m b -> m b
locallyTC (Map Name (Open LetBinding) -> f (Map Name (Open LetBinding)))
-> TCEnv -> f TCEnv
Lens' TCEnv (Map Name (Open LetBinding))
eLetBindings (Map Name (Open LetBinding)
-> Set Name -> Map Name (Open LetBinding)
forall k a. Ord k => Map k a -> Set k -> Map k a
`Map.restrictKeys` Set Name
lets)
checkit Type
t = TCM Term -> TCM Term
restore (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ Comparison -> Expr -> Type -> TCM Term
checkExpr' Comparison
CmpLeq Expr
e Type
t
(mv, v) <- newValueMeta RunMetaOccursCheck CmpEq t
reportSDoc "tc.record.where" 30 $ "deferring field" <+> prettyA x <+> ":" <+> pretty t
lets `seq` addLetBinding info UserWritten (A.unBind x) v t $ check bs \IntMap (BindName, MetaId, Term, Expr, Type -> TCM Term)
as ->
IntMap (BindName, MetaId, Term, Expr, Type -> TCM Term) -> TCM a
cont (Int
-> (BindName, MetaId, Term, Expr, Type -> TCM Term)
-> IntMap (BindName, MetaId, Term, Expr, Type -> TCM Term)
-> IntMap (BindName, MetaId, Term, Expr, Type -> TCM Term)
forall a. Int -> a -> IntMap a -> IntMap a
IntMap.insert Int
idx (BindName
x, MetaId
mv, Term
v, Expr
e, Type -> TCM Term
checkit) IntMap (BindName, MetaId, Term, Expr, Type -> TCM Term)
as)
check (LetBinding
b:[LetBinding]
bs) IntMap (BindName, MetaId, Term, Expr, Type -> TCM Term) -> TCM a
cont = LetBinding -> TCM a -> TCM a
forall a. LetBinding -> TCM a -> TCM a
checkLetBinding LetBinding
b (TCM a -> TCM a) -> TCM a -> TCM a
forall a b. (a -> b) -> a -> b
$ [LetBinding]
-> (IntMap (BindName, MetaId, Term, Expr, Type -> TCM Term)
-> TCM a)
-> TCM a
forall a.
[LetBinding]
-> (IntMap (BindName, MetaId, Term, Expr, Type -> TCM Term)
-> TCM a)
-> TCM a
check [LetBinding]
bs IntMap (BindName, MetaId, Term, Expr, Type -> TCM Term) -> TCM a
cont
check [] IntMap (BindName, MetaId, Term, Expr, Type -> TCM Term) -> TCM a
cont = IntMap (BindName, MetaId, Term, Expr, Type -> TCM Term) -> TCM a
cont IntMap (BindName, MetaId, Term, Expr, Type -> TCM Term)
forall a. Monoid a => a
mempty
checkUpdate :: ([Either (FieldAssignment' Expr) ModuleName] -> TCM Term)
-> TCM Term
checkUpdate [Either (FieldAssignment' Expr) ModuleName] -> TCM Term
cont = case Maybe Expr
update of
Maybe Expr
Nothing -> [Either (FieldAssignment' Expr) ModuleName] -> TCM Term
cont ((FieldAssignment' Expr
-> Either (FieldAssignment' Expr) ModuleName)
-> Assigns -> [Either (FieldAssignment' Expr) ModuleName]
forall a b. (a -> b) -> [a] -> [b]
map' FieldAssignment' Expr -> Either (FieldAssignment' Expr) ModuleName
forall a b. a -> Either a b
Left Assigns
fs)
Just Expr
exp0 -> do
v <- Comparison -> Expr -> Type -> TCM Term
checkExpr' Comparison
cmp Expr
exp0 Type
t
name <- freshNoName $ getRange exp0
let
here_keys = [Name] -> Set Name
forall a. Ord a => [a] -> Set a
Set.fromList [Name]
fnames
proj QName
n = AppInfo -> Expr -> NamedArg Expr -> Expr
A.App (Range -> AppInfo
A.defaultAppInfo (Range -> AppInfo) -> Range -> AppInfo
forall a b. (a -> b) -> a -> b
$ ExprInfo -> Range
forall a. HasRange a => a -> Range
getRange ExprInfo
ei) (ProjOrigin -> AmbiguousQName -> Expr
A.Proj ProjOrigin
ProjSystem (AmbiguousQName -> Expr) -> AmbiguousQName -> Expr
forall a b. (a -> b) -> a -> b
$ QName -> AmbiguousQName
unambiguous QName
n) (Expr -> NamedArg Expr
forall a. a -> NamedArg a
defaultNamedArg (Name -> Expr
A.Var Name
name))
fs' =
[ FieldAssignment' Expr -> Either (FieldAssignment' Expr) ModuleName
forall a b. a -> Either a b
Left (Name -> Expr -> FieldAssignment' Expr
forall a. Name -> a -> FieldAssignment' a
FieldAssignment Name
fname (QName -> Expr
proj QName
pname))
| (Name
fname, Dom QName -> QName
forall t e. Dom' t e -> e
unDom -> QName
pname) <- [Name] -> [Dom QName] -> [(Name, Dom QName)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Name]
cxs (RecordData -> [Dom QName]
_recFields RecordData
defn)
, Name
fname Name -> Set Name -> Bool
forall a. Ord a => a -> Set a -> Bool
`Set.notMember` Set Name
here_keys
]
addLetBinding defaultArgInfo Inserted name v t $ cont (fs' ++! map' Left fs)
[LetBinding]
-> (IntMap (BindName, MetaId, Term, Expr, Type -> TCM Term)
-> TCM Term)
-> TCM Term
forall a.
[LetBinding]
-> (IntMap (BindName, MetaId, Term, Expr, Type -> TCM Term)
-> TCM a)
-> TCM a
check [LetBinding]
decls \IntMap (BindName, MetaId, Term, Expr, Type -> TCM Term)
later -> ([Either (FieldAssignment' Expr) ModuleName] -> TCM Term)
-> TCM Term
checkUpdate \[Either (FieldAssignment' Expr) ModuleName]
fs' -> do
out <- TCM Term -> TCM Term
forall a. TCM a -> TCM a
reallyDontExpandLast (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$
Comparison
-> [Either (FieldAssignment' Expr) ModuleName]
-> Expr
-> Type
-> ConOrigin
-> TCM Term
checkRecordExpression Comparison
cmp [Either (FieldAssignment' Expr) ModuleName]
fs' (KwRange
-> ExprInfo -> [Either (FieldAssignment' Expr) ModuleName] -> Expr
A.Rec KwRange
kwr ExprInfo
ei [Either (FieldAssignment' Expr) ModuleName]
fs') Type
t ConOrigin
ConORecWhere
forM_ (IntMap.toAscList later) \(Int
_, (BindName
fname, MetaId
mid, Term
meta, Expr
e, Type -> TCM Term
check)) -> do
ty <- MetaId -> TCM Type
forall (m :: * -> *).
(HasBuiltins m, HasCallStack, MonadDebug m, MonadReduce m) =>
MetaId -> m Type
getMetaTypeInContext MetaId
mid
reportSDoc "tc.record.where" 30 $ vcat
[ "checking deferred `record where` binding for " <> prettyA fname <> ":"
, nest 2 $ vcat
[ prettyTCM meta <+> ":" <+> prettyTCM ty
, prettyTCM meta <+> "=" <+> prettyA e ] ]
v <- check ty
equalTerm ty meta v
pure out
checkLiteral :: Literal -> Type -> TCM Term
checkLiteral :: Literal -> Type -> TCM Term
checkLiteral Literal
lit Type
t = do
t' <- Literal -> TCM Type
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
Literal -> m Type
litType Literal
lit
coerce CmpEq (Lit lit) t' t
appViewM :: A.Expr -> TCM AppView
appViewM :: Expr -> TCM AppView
appViewM Expr
e = do
(f, es) <- Expr -> TCM ([NamedArg Expr] -> AppView, DList (NamedArg Expr))
go Expr
e
return $! f $! DL.toList es
where
go :: A.Expr -> TCM (A.Args -> AppView, DL.DList (NamedArg A.Expr))
go :: Expr -> TCM ([NamedArg Expr] -> AppView, DList (NamedArg Expr))
go = \case
A.ScopedExpr ScopeInfo
_ Expr
e -> Expr -> TCM ([NamedArg Expr] -> AppView, DList (NamedArg Expr))
go Expr
e
A.App AppInfo
_ Expr
e1 NamedArg Expr
e2
| A.Dot ExprInfo
_ Expr
e2' <- 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
e2
, Just (AmbiguousQName
f0, Expr
hd) <- Expr -> Maybe (AmbiguousQName, Expr)
maybeProjTurnPostfix Expr
e2'
-> do
ai <- case AmbiguousQName -> Maybe QName
getUnambiguous AmbiguousQName
f0 of
Just QName
f -> QName -> TCMT IO (Maybe Projection)
forall (m :: * -> *).
HasConstInfo m =>
QName -> m (Maybe Projection)
isProjection QName
f TCMT IO (Maybe Projection)
-> (Maybe Projection -> TCMT IO ArgInfo) -> TCMT IO ArgInfo
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
Just Projection
p | Projection -> Bool
isProperProjection_ Projection
p -> ArgInfo -> TCMT IO ArgInfo
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ArgInfo -> TCMT IO ArgInfo) -> ArgInfo -> TCMT IO ArgInfo
forall a b. (a -> b) -> a -> b
$ Projection -> ArgInfo
projArgInfo Projection
p
Maybe Projection
_ -> ArgInfo -> TCMT IO ArgInfo
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ArgInfo
defaultArgInfo
Maybe QName
Nothing -> ArgInfo -> TCMT IO ArgInfo
forall a. a -> TCMT IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ArgInfo
defaultArgInfo
return (Application hd, singleton (unnamedArg ai e1))
A.App AppInfo
_ Expr
e1 NamedArg Expr
arg -> (DList (NamedArg Expr) -> DList (NamedArg Expr))
-> ([NamedArg Expr] -> AppView, DList (NamedArg Expr))
-> ([NamedArg Expr] -> AppView, DList (NamedArg Expr))
forall b c a. (b -> c) -> (a, b) -> (a, c)
forall (p :: * -> * -> *) b c a.
Bifunctor p =>
(b -> c) -> p a b -> p a c
second (DList (NamedArg Expr) -> NamedArg Expr -> DList (NamedArg Expr)
forall a. DList a -> a -> DList a
`DL.snoc` NamedArg Expr
arg) (([NamedArg Expr] -> AppView, DList (NamedArg Expr))
-> ([NamedArg Expr] -> AppView, DList (NamedArg Expr)))
-> TCM ([NamedArg Expr] -> AppView, DList (NamedArg Expr))
-> TCM ([NamedArg Expr] -> AppView, DList (NamedArg Expr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> TCM ([NamedArg Expr] -> AppView, DList (NamedArg Expr))
go Expr
e1
Expr
e -> ([NamedArg Expr] -> AppView, DList (NamedArg Expr))
-> TCM ([NamedArg Expr] -> AppView, DList (NamedArg Expr))
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Expr -> [NamedArg Expr] -> AppView
forall arg. Expr -> [NamedArg arg] -> AppView' arg
Application Expr
e, DList (NamedArg Expr)
forall a. Monoid a => a
mempty)
scopedExpr :: A.Expr -> TCM A.Expr
scopedExpr :: Expr -> TCM Expr
scopedExpr (A.ScopedExpr ScopeInfo
scope Expr
e) = ScopeInfo -> TCM ()
setScope ScopeInfo
scope TCM () -> TCM Expr -> TCM Expr
forall a b. TCMT IO a -> TCMT IO b -> TCMT IO b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Expr -> TCM Expr
scopedExpr Expr
e
scopedExpr (A.Qualified ModuleName
mod Expr
e) = Expr -> TCM Expr
scopedExpr Expr
e
scopedExpr Expr
e = Expr -> TCM Expr
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Expr
e
checkExpr :: A.Expr -> Type -> TCM Term
checkExpr :: Expr -> Type -> TCM Term
checkExpr = Comparison -> Expr -> Type -> TCM Term
checkExpr' Comparison
CmpLeq
checkExpr'
:: Comparison
-> A.Expr
-> Type
-> TCM Term
checkExpr' :: Comparison -> Expr -> Type -> TCM Term
checkExpr' Comparison
cmp Expr
e Type
t =
let
res :: Term -> TCMT IO Doc
res Term
v = [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
vcat
[ TCMT IO Doc
"checkExpr" 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
fsep [ 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
":", 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
" returns" 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 ]
wrap :: TCM Term -> TCM Term
wrap =
String -> Int -> String -> TCM Term -> TCM Term
forall a. String -> Int -> String -> TCMT IO a -> TCMT IO a
forall (m :: * -> *) a.
MonadDebug m =>
String -> Int -> String -> m a -> m a
verboseBracket String
"tc.term.expr.top" Int
5 String
"checkExpr"
(TCM Term -> TCM Term)
-> (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Int -> (Term -> TCMT IO Doc) -> TCM Term -> TCM Term
forall (m :: * -> *) a.
MonadDebug m =>
String -> Int -> (a -> TCMT IO Doc) -> m a -> m a
reportResult String
"tc.term.expr.top" Int
15 Term -> TCMT IO Doc
res
(TCM Term -> TCM Term)
-> (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Call -> TCM Term -> TCM Term
forall a. Call -> TCMT IO a -> TCMT IO a
forall (m :: * -> *) a. MonadTrace m => Call -> m a -> m a
traceCall (Comparison -> Expr -> Type -> Call
CheckExprCall Comparison
cmp Expr
e Type
t)
(TCM Term -> TCM Term)
-> (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DeferredError -> TCM Term) -> TCM Term -> TCM Term
forall (m :: * -> *) a.
MonadError TCErr m =>
(DeferredError -> m a) -> m a -> m a
handleRecoverableError (Comparison -> Type -> DeferredError -> TCM Term
deferredErrorTerm Comparison
cmp Type
t)
(TCM Term -> TCM Term)
-> (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TCM Term -> TCM Term
forall a. TCM a -> TCM a
localScope
(TCM Term -> TCM Term)
-> (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TCM Term -> TCM Term
forall a. TCM a -> TCM a
doExpandLast
in TCM Term -> TCM Term
wrap (TCM Term -> TCM Term) -> TCM Term -> TCM Term
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
=<< do
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.term.expr.top" Int
15 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"Checking" 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, Foldable t) =>
t (m Doc) -> m Doc
fsep [ 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
":", 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
"at " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> (String -> TCMT IO Doc
forall (m :: * -> *). Applicative m => String -> m Doc
text (String -> TCMT IO Doc)
-> (Range -> String) -> Range -> TCMT IO Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Range -> String
forall a. Pretty a => a -> String
prettyShow (Range -> TCMT IO Doc) -> TCMT IO Range -> TCMT IO Doc
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCMT IO Range
forall (m :: * -> *). MonadTCEnv m => m Range
getCurrentRange)
]
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.term.expr.top.detailed" Int
80 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"Checking" 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
fsep [ 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
":", String -> TCMT IO Doc
forall (m :: * -> *). Applicative m => String -> m Doc
text (Type -> String
forall a. Show a => a -> String
show Type
t) ]
tReduced <- Type -> TCM Type
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce Type
t
reportSDoc "tc.term.expr.top" 15 $
" --> " <+> prettyTCM tReduced
e <- scopedExpr e
irrelevantIfProp <- runBlocked (isPropM t) >>= \case
Right Bool
True -> (TCM Term -> TCM Term) -> TCMT IO (TCM Term -> TCM Term)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ((Term -> Term) -> TCM Term -> TCM 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 Term -> Term
dontCare)
Either Blocker Bool
_ -> (TCM Term -> TCM Term) -> TCMT IO (TCM Term -> TCM Term)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return TCM Term -> TCM Term
forall a. a -> a
id
irrelevantIfProp $ tryInsertHiddenLambda e tReduced $ case e of
A.ScopedExpr ScopeInfo
scope Expr
e -> TCM Term
forall a. HasCallStack => a
__IMPOSSIBLE__
A.QuestionMark MetaInfo
i InteractionId
ii -> (Comparison -> Type -> TCM (MetaId, Term))
-> Comparison -> Type -> MetaInfo -> InteractionId -> TCM Term
checkQuestionMark (RunMetaOccursCheck -> Comparison -> Type -> TCM (MetaId, Term)
newValueMeta' RunMetaOccursCheck
RunMetaOccursCheck) Comparison
cmp Type
t MetaInfo
i InteractionId
ii
A.Underscore MetaInfo
i -> MetaInfo -> Comparison -> Type -> TCM Term
checkUnderscore MetaInfo
i Comparison
cmp Type
t
e0 :: Expr
e0@(A.WithApp ExprInfo
_ Expr
e List1 Expr
es) -> do
(tm, _) <- Expr -> TCM (Term, Type)
inferExpr Expr
e
checkWithAppHead cmp t e tm es
e0 :: Expr
e0@(A.App AppInfo
i Expr
q (Arg ArgInfo
ai Named_ Expr
e))
| A.Quote ExprInfo
_ <- Expr -> Expr
unScope Expr
q -> do
if ArgInfo -> Bool
forall a. LensHiding a => a -> Bool
visible ArgInfo
ai then do
x <- Expr -> TCM QName
forall (m :: * -> *).
(MonadTCError m, MonadAbsToCon m) =>
Expr -> m QName
quotedName (Expr -> TCM QName) -> Expr -> TCM QName
forall a b. (a -> b) -> a -> b
$ Named_ Expr -> Expr
forall name a. Named name a -> a
namedThing Named_ Expr
e
ty <- qNameType
coerce cmp (quoteName x) ty t
else TypeError -> TCM Term
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> TCM Term) -> TypeError -> TCM Term
forall a b. (a -> b) -> a -> b
$ CannotQuote -> TypeError
CannotQuote CannotQuote
CannotQuoteHidden
| A.QuoteTerm ExprInfo
_ <- Expr -> Expr
unScope Expr
q -> do
if ArgInfo -> Bool
forall a. LensHiding a => a -> Bool
visible ArgInfo
ai then do
(et, _) <- Expr -> TCM (Term, Type)
inferExpr (Named_ Expr -> Expr
forall name a. Named name a -> a
namedThing Named_ Expr
e)
doQuoteTerm cmp et t
else TypeError -> TCM Term
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> TCM Term) -> TypeError -> TCM Term
forall a b. (a -> b) -> a -> b
$ CannotQuoteTerm -> TypeError
CannotQuoteTerm (CannotQuoteTerm -> TypeError) -> CannotQuoteTerm -> TypeError
forall a b. (a -> b) -> a -> b
$ Hiding -> CannotQuoteTerm
CannotQuoteTermHidden (Hiding -> CannotQuoteTerm) -> Hiding -> CannotQuoteTerm
forall a b. (a -> b) -> a -> b
$ ArgInfo -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding ArgInfo
ai
A.Quote{} -> TypeError -> TCM Term
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> TCM Term) -> TypeError -> TCM Term
forall a b. (a -> b) -> a -> b
$ CannotQuote -> TypeError
CannotQuote CannotQuote
CannotQuoteNothing
A.QuoteTerm{} -> TypeError -> TCM Term
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> TCM Term) -> TypeError -> TCM Term
forall a b. (a -> b) -> a -> b
$ CannotQuoteTerm -> TypeError
CannotQuoteTerm CannotQuoteTerm
CannotQuoteTermNothing
A.Unquote{} -> UnquoteError -> TCM Term
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError UnquoteError
NakedUnquote
A.AbsurdLam ExprInfo
i Hiding
h -> Comparison -> ExprInfo -> Hiding -> Expr -> Type -> TCM Term
checkAbsurdLambda Comparison
cmp ExprInfo
i Hiding
h Expr
e Type
t
A.ExtendedLam ExprInfo
i DefInfo
di QName
qname List1 Clause
cs ->
Comparison
-> ExprInfo
-> DefInfo
-> QName
-> List1 Clause
-> Expr
-> Type
-> TCM Term
checkExtendedLambda Comparison
cmp ExprInfo
i DefInfo
di QName
qname List1 Clause
cs Expr
e Type
t
A.Lam ExprInfo
i (A.DomainFull TypedBinding
b) Expr
e -> Comparison -> TypedBinding -> Expr -> Type -> TCM Term
checkLambda Comparison
cmp TypedBinding
b Expr
e Type
t
A.Lam ExprInfo
i (A.DomainFree TacticAttribute
_ NamedArg (Binder' BindName)
x) Expr
e0
| Maybe (WithOrigin (Ranged ArgName)) -> Bool
forall a. Maybe a -> Bool
isNothing (Named (WithOrigin (Ranged ArgName)) (Binder' BindName)
-> Maybe (WithOrigin (Ranged ArgName))
forall name a. Named name a -> Maybe name
nameOf (Named (WithOrigin (Ranged ArgName)) (Binder' BindName)
-> Maybe (WithOrigin (Ranged ArgName)))
-> Named (WithOrigin (Ranged ArgName)) (Binder' BindName)
-> Maybe (WithOrigin (Ranged ArgName))
forall a b. (a -> b) -> a -> b
$ NamedArg (Binder' BindName)
-> Named (WithOrigin (Ranged ArgName)) (Binder' BindName)
forall e. Arg e -> e
unArg NamedArg (Binder' BindName)
x) Bool -> Bool -> Bool
&& Maybe Pattern -> Bool
forall a. Maybe a -> Bool
isNothing (Binder' BindName -> Maybe Pattern
forall a. Binder' a -> Maybe Pattern
A.binderPattern (Binder' BindName -> Maybe Pattern)
-> Binder' BindName -> Maybe Pattern
forall a b. (a -> b) -> a -> b
$ NamedArg (Binder' BindName) -> Binder' BindName
forall a. NamedArg a -> a
namedArg NamedArg (Binder' BindName)
x) ->
Comparison -> Expr -> Type -> TCM Term
checkExpr' Comparison
cmp (ExprInfo -> LamBinding -> Expr -> Expr
A.Lam ExprInfo
i (ArgInfo -> Binder' Name -> LamBinding
domainFree (NamedArg (Binder' BindName) -> ArgInfo
forall a. LensArgInfo a => a -> ArgInfo
getArgInfo NamedArg (Binder' BindName)
x) (Binder' Name -> LamBinding) -> Binder' Name -> LamBinding
forall a b. (a -> b) -> a -> b
$ BindName -> Name
A.unBind (BindName -> Name) -> Binder' BindName -> Binder' Name
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NamedArg (Binder' BindName) -> Binder' BindName
forall a. NamedArg a -> a
namedArg NamedArg (Binder' BindName)
x) Expr
e0) Type
t
| Bool
otherwise -> TCM Term
forall a. HasCallStack => a
__IMPOSSIBLE__
A.Lit ExprInfo
_ Literal
lit -> Literal -> Type -> TCM Term
checkLiteral Literal
lit Type
t
A.Let ExprInfo
i List1 LetBinding
ds Expr
e -> List1 LetBinding -> TCM Term -> TCM Term
forall (t :: * -> *) a.
Foldable t =>
t LetBinding -> TCM a -> TCM a
checkLetBindings List1 LetBinding
ds (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ Comparison -> Expr -> Type -> TCM Term
checkExpr' Comparison
cmp Expr
e Type
t
e :: Expr
e@A.Pi{} -> do
t' <- Expr -> TCM Type
isType_ Expr
e
let s = Type -> Sort' Term
forall a. LensSort a => a -> Sort' Term
getSort Type
t'
v = Type -> Term
forall t a. Type'' t a -> a
unEl Type
t'
coerce cmp v (sort s) t
A.Generalized Set1 QName
s Expr
e -> do
(_, t') <- Set QName -> TCM Type -> TCM ([Maybe QName], Type)
generalizeType (Set1 QName -> Set QName
forall a. NESet a -> Set a
Set1.toSet Set1 QName
s) (TCM Type -> TCM ([Maybe QName], Type))
-> TCM Type -> TCM ([Maybe QName], Type)
forall a b. (a -> b) -> a -> b
$ Expr -> TCM Type
isType_ Expr
e
let s = Type -> Sort' Term
forall a. LensSort a => a -> Sort' Term
getSort Type
t'
v = Type -> Term
forall t a. Type'' t a -> a
unEl Type
t'
coerce cmp v (sort s) t
e :: Expr
e@A.Fun{} -> do
t' <- Expr -> TCM Type
isType_ Expr
e
let s = Type -> Sort' Term
forall a. LensSort a => a -> Sort' Term
getSort Type
t'
v = Type -> Term
forall t a. Type'' t a -> a
unEl Type
t'
coerce cmp v (sort s) t
A.Rec KwRange
_ ExprInfo
_ [Either (FieldAssignment' Expr) ModuleName]
fs -> Comparison
-> [Either (FieldAssignment' Expr) ModuleName]
-> Expr
-> Type
-> ConOrigin
-> TCM Term
checkRecordExpression Comparison
cmp [Either (FieldAssignment' Expr) ModuleName]
fs Expr
e Type
t ConOrigin
ConORec
A.RecUpdate KwRange
kwr ExprInfo
ei Expr
recexpr Assigns
fs -> Comparison
-> KwRange
-> ExprInfo
-> Expr
-> Assigns
-> Expr
-> Type
-> TCM Term
checkRecordUpdate Comparison
cmp KwRange
kwr ExprInfo
ei Expr
recexpr Assigns
fs Expr
e Type
t
A.RecWhere KwRange
kwr ExprInfo
ei [LetBinding]
decls Assigns
fs -> Comparison
-> KwRange
-> ExprInfo
-> Maybe Expr
-> [LetBinding]
-> Assigns
-> Expr
-> Type
-> TCM Term
checkRecordWhere Comparison
cmp KwRange
kwr ExprInfo
ei Maybe Expr
forall a. Maybe a
Nothing [LetBinding]
decls Assigns
fs Expr
e Type
t
A.RecUpdateWhere KwRange
kwr ExprInfo
ei Expr
exp [LetBinding]
decls Assigns
fs -> Comparison
-> KwRange
-> ExprInfo
-> Maybe Expr
-> [LetBinding]
-> Assigns
-> Expr
-> Type
-> TCM Term
checkRecordWhere Comparison
cmp KwRange
kwr ExprInfo
ei (Expr -> Maybe Expr
forall a. a -> Maybe a
Just Expr
exp) [LetBinding]
decls Assigns
fs Expr
e Type
t
A.DontCare Expr
e -> TCM Term
forall a. HasCallStack => a
__IMPOSSIBLE__
A.Dot{} -> TypeError -> TCM Term
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError TypeError
InvalidDottedExpression
Expr
e -> do
Application hd args <- Expr -> TCM AppView
appViewM Expr
e
e' <- checkApplication cmp hd args e t
pure e'
`catchIlltypedPatternBlockedOnMeta` \ (TCErr
err, Blocker
x) -> do
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.term" Int
50 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
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
"checking pattern got stuck on meta: " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Blocker -> TCMT IO Doc
forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty Blocker
x ]
TypeCheckingProblem -> Blocker -> TCM Term
postponeTypeCheckingProblem (Comparison -> Expr -> Type -> TypeCheckingProblem
CheckExpr Comparison
cmp Expr
e Type
t) Blocker
x
where
tryInsertHiddenLambda
:: A.Expr
-> Type
-> TCM Term
-> TCM Term
tryInsertHiddenLambda :: Expr -> Type -> TCM Term -> TCM Term
tryInsertHiddenLambda Expr
e Type
tReduced TCM Term
fallback
| Pi dom :: Dom Type
dom@(Dom Type -> Type
forall t e. Dom' t e -> e
unDom -> Type
a) Abs Type
b <- Type -> Term
forall t a. Type'' t a -> a
unEl Type
tReduced
, let info :: ArgInfo
info = Dom Type
dom Dom Type -> Getting ArgInfo (Dom Type) ArgInfo -> ArgInfo
forall s a. s -> Getting a s a -> a
^. Getting ArgInfo (Dom Type) ArgInfo
forall t e (f :: * -> *).
Functor f =>
(ArgInfo -> f ArgInfo) -> Dom' t e -> f (Dom' t e)
dInfo
, let h :: Hiding
h = ArgInfo -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding ArgInfo
info
, Hiding -> Bool
forall a. LensHiding a => a -> Bool
notVisible Hiding
h
, Bool -> Bool
not (Hiding -> Expr -> Bool
forall {a}. LensHiding a => a -> Expr -> Bool
hiddenLambdaOrHole Hiding
h Expr
e)
= do
let proceed :: TCM Term
proceed = ArgInfo -> ArgName -> TCM Term
doInsert (Origin -> ArgInfo -> ArgInfo
forall a. LensOrigin a => Origin -> a -> a
setOrigin Origin
Inserted ArgInfo
info) (ArgName -> TCM Term) -> ArgName -> TCM Term
forall a b. (a -> b) -> a -> b
$ Abs Type -> ArgName
forall a. Abs a -> ArgName
absName Abs Type
b
expandHidden <- Lens' TCEnv ExpandHidden -> TCMT IO ExpandHidden
forall (m :: * -> *) a. MonadTCEnv m => Lens' TCEnv a -> m a
viewTC (ExpandHidden -> f ExpandHidden) -> TCEnv -> f TCEnv
Lens' TCEnv ExpandHidden
eExpandLast
if | expandHidden == ReallyDontExpandLast -> fallback
| otherwise -> proceed
| Bool
otherwise = TCM Term
fallback
where
re :: Range
re = Expr -> Range
forall a. HasRange a => a -> Range
getRange Expr
e
rx :: Range
rx = Maybe (Position' (Maybe RangeFile))
-> Range -> (Position' (Maybe RangeFile) -> Range) -> Range
forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe (Range -> Maybe (Position' (Maybe RangeFile))
forall a. Range' a -> Maybe (Position' a)
rStart Range
re) Range
forall a. Range' a
noRange ((Position' (Maybe RangeFile) -> Range) -> Range)
-> (Position' (Maybe RangeFile) -> Range) -> Range
forall a b. (a -> b) -> a -> b
$ \ Position' (Maybe RangeFile)
pos -> Position' (Maybe RangeFile) -> Position' (Maybe RangeFile) -> Range
forall a b. Position' a -> Position' b -> Range' a
posToRange Position' (Maybe RangeFile)
pos Position' (Maybe RangeFile)
pos
doInsert :: ArgInfo -> ArgName -> TCM Term
doInsert ArgInfo
info ArgName
y = do
x <- Name -> Name
forall a. LensInScope a => a -> a
C.setNotInScope (Name -> Name) -> TCMT IO Name -> TCMT IO Name
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Range -> ArgName -> TCMT IO Name
forall (m :: * -> *).
MonadFresh NameId m =>
Range -> ArgName -> m Name
freshName Range
rx ArgName
y
reportSLn "tc.term.expr.impl" 15 $ "Inserting implicit lambda"
checkExpr' cmp (A.Lam (A.ExprRange re) (domainFree info $ A.mkBinder x) e) tReduced
hiddenLambdaOrHole :: a -> Expr -> Bool
hiddenLambdaOrHole a
h = \case
A.AbsurdLam ExprInfo
_ Hiding
h' -> a -> Hiding -> Bool
forall a b. (LensHiding a, LensHiding b) => a -> b -> Bool
sameHiding a
h Hiding
h'
A.ExtendedLam ExprInfo
_ DefInfo
_ QName
_ List1 Clause
cls -> (Clause -> Bool) -> List1 Clause -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Clause -> Bool
hiddenLHS List1 Clause
cls
A.Lam ExprInfo
_ LamBinding
bind Expr
_ -> a -> LamBinding -> Bool
forall a b. (LensHiding a, LensHiding b) => a -> b -> Bool
sameHiding a
h LamBinding
bind
A.QuestionMark{} -> Bool
True
Expr
_ -> Bool
False
hiddenLHS :: Clause -> Bool
hiddenLHS (A.Clause (A.LHS LHSInfo
_ (A.LHSHead QName
_ (NamedArg Pattern
a : [NamedArg Pattern]
_))) [ProblemEq]
_ RHS
_ Maybe WhereDeclarations
_ Catchall
_) = NamedArg Pattern -> Bool
forall a. LensHiding a => a -> Bool
notVisible NamedArg Pattern
a
hiddenLHS Clause
_ = Bool
False
definitelyIntroduction :: Bool
definitelyIntroduction = case Expr
e of
A.Lam{} -> Bool
True
A.AbsurdLam{} -> Bool
True
A.Lit{} -> Bool
True
A.Pi{} -> Bool
True
A.Fun{} -> Bool
True
A.Rec{} -> Bool
True
A.RecUpdate{} -> Bool
True
A.ScopedExpr{} -> Bool
forall a. HasCallStack => a
__IMPOSSIBLE__
Expr
_ -> Bool
False
doQuoteTerm :: Comparison -> Term -> Type -> TCM Term
doQuoteTerm :: Comparison -> Term -> Type -> TCM Term
doQuoteTerm Comparison
cmp Term
et Type
t = do
et' <- Term -> TCM Term
forall (m :: * -> *) a. (HasConstInfo m, TermLike a) => a -> m a
etaContract (Term -> TCM Term) -> TCM Term -> TCM Term
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Term -> TCM Term
forall a (m :: * -> *).
(InstantiateFull a, MonadReduce m) =>
a -> m a
instantiateFull Term
et
quoteMetas <- optQuoteMetas <$> pragmaOptions
let metas = Term -> [MetaId]
forall a. AllMetas a => a -> [MetaId]
allMetasList Term
et'
if quoteMetas || null metas then do
q <- quoteTerm et'
ty <- el primAgdaTerm
coerce cmp q ty t
else
postponeTypeCheckingProblem (DoQuoteTerm cmp et t) $ unblockOnAllMetas $ Set.fromList metas
unquoteM :: A.Expr -> Term -> Type -> TCM ()
unquoteM :: Expr -> Term -> Type -> TCM ()
unquoteM Expr
tacA Term
hole Type
holeType = do
tac <-
Expr -> Type -> TCM Term
checkExpr Expr
tacA (Type -> TCM Term) -> TCM Type -> TCM Term
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (TCM Term -> TCM Type
forall (m :: * -> *). Functor m => m Term -> m Type
el TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primAgdaTerm TCM Type -> TCM Type -> TCM Type
forall (m :: * -> *). HasOptions m => m Type -> m Type -> m Type
--> TCM Term -> TCM Type
forall (m :: * -> *). Functor m => m Term -> m Type
el (TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primAgdaTCM TCM Term -> TCM Term -> TCM Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<#> TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primLevelZero TCM Term -> TCM Term -> TCM Term
forall (m :: * -> *). Applicative m => m Term -> m Term -> m Term
<@> TCM Term
forall (m :: * -> *).
(HasBuiltins m, MonadError TCErr m, MonadTCEnv m, ReadTCState m) =>
m Term
primUnit))
inFreshModuleIfFreeParams $ unquoteTactic tac hole holeType
unquoteTactic :: Term -> Term -> Type -> TCM ()
unquoteTactic :: Term -> Term -> Type -> TCM ()
unquoteTactic Term
tac Term
hole Type
goal = do
TCMT IO Bool -> TCM () -> TCM () -> TCM ()
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
ifM (Getter TCState Bool -> TCMT IO Bool
forall (m :: * -> *) a. ReadTCState m => Getter TCState a -> m a
useTC (Bool -> f Bool) -> TCState -> f TCState
Lens' TCState Bool
Getter TCState Bool
stConsideringInstance) (Blocker -> Constraint -> TCM ()
forall (m :: * -> *).
MonadConstraint m =>
Blocker -> Constraint -> m ()
addConstraint Blocker
neverUnblock (Term -> Term -> Type -> Constraint
UnquoteTactic Term
tac Term
hole Type
goal)) do
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.term.tactic" Int
40 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
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
"Running tactic" 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
tac
, 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
"on" 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
hole 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 -> 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
goal ]
ok <- UnquoteM Term -> TCM (Either UnquoteError (Term, [QName]))
forall a. UnquoteM a -> TCM (Either UnquoteError (a, [QName]))
runUnquoteM (UnquoteM Term -> TCM (Either UnquoteError (Term, [QName])))
-> UnquoteM Term -> TCM (Either UnquoteError (Term, [QName]))
forall a b. (a -> b) -> a -> b
$ Term -> Term -> UnquoteM Term
unquoteTCM Term
tac Term
hole
case ok of
Left (BlockedOnMeta TCState
oldState Blocker
blocker) -> do
TCState -> TCM ()
forall (m :: * -> *). MonadTCState m => TCState -> m ()
putTC TCState
oldState
let stripFreshMeta :: MetaId -> f Blocker
stripFreshMeta MetaId
x = Blocker
-> (MetaVariable -> Blocker) -> Maybe MetaVariable -> Blocker
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Blocker
neverUnblock (Blocker -> MetaVariable -> Blocker
forall a b. a -> b -> a
const (Blocker -> MetaVariable -> Blocker)
-> Blocker -> MetaVariable -> Blocker
forall a b. (a -> b) -> a -> b
$ MetaId -> Blocker
unblockOnMeta MetaId
x) (Maybe MetaVariable -> Blocker)
-> f (Maybe MetaVariable) -> f Blocker
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MetaId -> f (Maybe MetaVariable)
forall (m :: * -> *).
ReadTCState m =>
MetaId -> m (Maybe MetaVariable)
lookupLocalMeta' MetaId
x
blocker' <- (MetaId -> TCMT IO Blocker) -> Blocker -> TCMT IO Blocker
forall (m :: * -> *).
Monad m =>
(MetaId -> m Blocker) -> Blocker -> m Blocker
onBlockingMetasM MetaId -> TCMT IO Blocker
forall {f :: * -> *}. ReadTCState f => MetaId -> f Blocker
stripFreshMeta Blocker
blocker
r <- case Set.toList $ allBlockingMetas blocker' of
MetaId
x : [MetaId]
_ -> Maybe MetaVariable -> Range
forall a. HasRange a => a -> Range
getRange (Maybe MetaVariable -> Range)
-> TCMT IO (Maybe MetaVariable) -> TCMT IO Range
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MetaId -> TCMT IO (Maybe MetaVariable)
forall (m :: * -> *).
ReadTCState m =>
MetaId -> m (Maybe MetaVariable)
lookupLocalMeta' MetaId
x
[] -> Range -> TCMT IO Range
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Range
forall a. Range' a
noRange
setCurrentRange r $
addConstraint blocker' (UnquoteTactic tac hole goal)
Left UnquoteError
err -> UnquoteError -> TCM ()
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError UnquoteError
err
Right (Term, [QName])
_ -> () -> TCM ()
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
checkQuestionMark
:: (Comparison -> Type -> TCM (MetaId, Term))
-> Comparison
-> Type
-> A.MetaInfo
-> InteractionId
-> TCM Term
checkQuestionMark :: (Comparison -> Type -> TCM (MetaId, Term))
-> Comparison -> Type -> MetaInfo -> InteractionId -> TCM Term
checkQuestionMark Comparison -> Type -> TCM (MetaId, Term)
new Comparison
cmp Type
t0 MetaInfo
i InteractionId
ii = do
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.interaction" Int
20 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
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
"Found interaction point"
, String -> TCMT IO Doc
forall (m :: * -> *). Applicative m => String -> m Doc
text (String -> TCMT IO Doc)
-> (IsAbstract -> String) -> IsAbstract -> TCMT IO Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IsAbstract -> String
forall a. Show a => a -> String
show (IsAbstract -> TCMT IO Doc) -> TCMT IO IsAbstract -> TCMT IO Doc
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (TCEnv -> IsAbstract) -> TCMT IO IsAbstract
forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC (TCEnv -> Getting IsAbstract TCEnv IsAbstract -> IsAbstract
forall s a. s -> Getting a s a -> a
^. Getting IsAbstract TCEnv IsAbstract
forall a. LensIsAbstract a => Lens' a IsAbstract
Lens' TCEnv IsAbstract
lensIsAbstract)
, InteractionId -> TCMT IO Doc
forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
pretty InteractionId
ii
, TCMT IO 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
]
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.interaction" Int
90 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
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
"Raw:"
, String -> TCMT IO Doc
forall (m :: * -> *). Applicative m => String -> m Doc
text (Type -> String
forall a. Show a => a -> String
show Type
t0)
]
MetaInfo
-> (Comparison -> Type -> TCM (MetaId, Term))
-> Comparison
-> Type
-> TCM Term
checkMeta MetaInfo
i ((Comparison -> Type -> TCM (MetaId, Term))
-> InteractionId -> Comparison -> Type -> TCM (MetaId, Term)
newQuestionMark' Comparison -> Type -> TCM (MetaId, Term)
new InteractionId
ii) Comparison
cmp Type
t0
checkUnderscore :: A.MetaInfo -> Comparison -> Type -> TCM Term
checkUnderscore :: MetaInfo -> Comparison -> Type -> TCM Term
checkUnderscore MetaInfo
i = MetaInfo
-> (Comparison -> Type -> TCM (MetaId, Term))
-> Comparison
-> Type
-> TCM Term
checkMeta MetaInfo
i (MetaInfo
-> RunMetaOccursCheck -> Comparison -> Type -> TCM (MetaId, Term)
newValueMetaOfKind MetaInfo
i RunMetaOccursCheck
RunMetaOccursCheck)
checkMeta :: A.MetaInfo -> (Comparison -> Type -> TCM (MetaId, Term)) -> Comparison -> Type -> TCM Term
checkMeta :: MetaInfo
-> (Comparison -> Type -> TCM (MetaId, Term))
-> Comparison
-> Type
-> TCM Term
checkMeta MetaInfo
i Comparison -> Type -> TCM (MetaId, Term)
newMeta Comparison
cmp Type
t = (Term, Type) -> Term
forall a b. (a, b) -> a
fst ((Term, Type) -> Term) -> TCM (Term, Type) -> TCM Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MetaInfo
-> (Comparison -> Type -> TCM (MetaId, Term))
-> Maybe (Comparison, Type)
-> TCM (Term, Type)
checkOrInferMeta MetaInfo
i Comparison -> Type -> TCM (MetaId, Term)
newMeta ((Comparison, Type) -> Maybe (Comparison, Type)
forall a. a -> Maybe a
Just (Comparison
cmp , Type
t))
inferMeta :: A.MetaInfo -> (Comparison -> Type -> TCM (MetaId, Term)) -> TCM (AppHead, Type)
inferMeta :: MetaInfo
-> (Comparison -> Type -> TCM (MetaId, Term))
-> TCM (AppHead, Type)
inferMeta MetaInfo
i Comparison -> Type -> TCM (MetaId, Term)
newMeta = (Term -> AppHead) -> (Term, Type) -> (AppHead, Type)
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 Term -> AppHead
TermAppHd ((Term, Type) -> (AppHead, Type))
-> TCM (Term, Type) -> TCM (AppHead, Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MetaInfo
-> (Comparison -> Type -> TCM (MetaId, Term))
-> Maybe (Comparison, Type)
-> TCM (Term, Type)
checkOrInferMeta MetaInfo
i Comparison -> Type -> TCM (MetaId, Term)
newMeta Maybe (Comparison, Type)
forall a. Maybe a
Nothing
checkOrInferMeta
:: A.MetaInfo
-> (Comparison -> Type -> TCM (MetaId, Term))
-> Maybe (Comparison , Type)
-> TCM (Term, Type)
checkOrInferMeta :: MetaInfo
-> (Comparison -> Type -> TCM (MetaId, Term))
-> Maybe (Comparison, Type)
-> TCM (Term, Type)
checkOrInferMeta MetaInfo
i Comparison -> Type -> TCM (MetaId, Term)
newMeta Maybe (Comparison, Type)
mt = do
case MetaInfo -> Maybe MetaId
A.metaNumber MetaInfo
i of
Maybe MetaId
Nothing -> do
ScopeInfo -> (ScopeInfo -> TCM ()) -> TCM ()
forall (m :: * -> *) a.
(Monad m, Null a) =>
a -> (a -> m ()) -> m ()
unlessNull (MetaInfo -> ScopeInfo
A.metaScope MetaInfo
i) ScopeInfo -> TCM ()
setScope
(cmp , t) <- TCMT IO (Comparison, Type)
-> ((Comparison, Type) -> TCMT IO (Comparison, Type))
-> Maybe (Comparison, Type)
-> TCMT IO (Comparison, Type)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ((Comparison
CmpEq,) (Type -> (Comparison, Type))
-> TCM Type -> TCMT IO (Comparison, Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TCM Type -> TCM Type
forall (m :: * -> *) a. (MonadTCEnv m, MonadDebug m) => m a -> m a
workOnTypes TCM Type
newTypeMeta_) (Comparison, Type) -> TCMT IO (Comparison, Type)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Comparison, Type)
mt
(x, v) <- newMeta cmp t
setMetaNameSuggestion x (A.metaNameSuggestion i)
return (v, t)
Just MetaId
x -> do
let v :: Term
v = MetaId -> Elims -> Term
MetaV MetaId
x []
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.meta.check" Int
20 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$
TCMT IO Doc
"checking existing meta " 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
t' <- MetaId -> TCM Type
forall (m :: * -> *). ReadTCState m => MetaId -> m Type
getMetaType MetaId
x
reportSDoc "tc.meta.check" 20 $
nest 2 $ "of type " <+> prettyTCM t'
case mt of
Maybe (Comparison, Type)
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')
Just (Comparison
cmp , Type
t) -> (,Type
t) (Term -> (Term, Type)) -> TCM Term -> TCM (Term, Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Comparison -> Term -> Type -> Type -> TCM Term
coerce Comparison
cmp Term
v Type
t' Type
t
domainFree :: ArgInfo -> A.Binder' A.Name -> A.LamBinding
domainFree :: ArgInfo -> Binder' Name -> LamBinding
domainFree ArgInfo
info Binder' Name
x =
TypedBinding -> LamBinding
A.DomainFull (TypedBinding -> LamBinding) -> TypedBinding -> LamBinding
forall a b. (a -> b) -> a -> b
$ Range
-> List1 (NamedArg (Binder' BindName)) -> Expr -> TypedBinding
A.mkTBind Range
r (NamedArg (Binder' BindName) -> List1 (NamedArg (Binder' BindName))
forall el coll. Singleton el coll => el -> coll
singleton (NamedArg (Binder' BindName)
-> List1 (NamedArg (Binder' BindName)))
-> NamedArg (Binder' BindName)
-> List1 (NamedArg (Binder' BindName))
forall a b. (a -> b) -> a -> b
$ ArgInfo -> Binder' BindName -> NamedArg (Binder' BindName)
forall a. ArgInfo -> a -> NamedArg a
unnamedArg ArgInfo
info (Binder' BindName -> NamedArg (Binder' BindName))
-> Binder' BindName -> NamedArg (Binder' BindName)
forall a b. (a -> b) -> a -> b
$ (Name -> BindName) -> Binder' Name -> Binder' BindName
forall a b. (a -> b) -> Binder' a -> Binder' b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Name -> BindName
A.mkBindName Binder' Name
x)
(Expr -> TypedBinding) -> Expr -> TypedBinding
forall a b. (a -> b) -> a -> b
$ MetaInfo -> Expr
A.Underscore MetaInfo
underscoreInfo
where
r :: Range
r = Binder' Name -> Range
forall a. HasRange a => a -> Range
getRange Binder' Name
x
underscoreInfo :: MetaInfo
underscoreInfo = A.MetaInfo
{ metaRange :: Range
A.metaRange = Range
r
, metaScope :: ScopeInfo
A.metaScope = ScopeInfo
emptyScopeInfo
, metaNumber :: Maybe MetaId
A.metaNumber = Maybe MetaId
forall a. Maybe a
Nothing
, metaNameSuggestion :: ArgName
A.metaNameSuggestion = String -> ArgName
TS.pack (Name -> String
forall a. Pretty a => a -> String
prettyShow (Name -> String) -> Name -> String
forall a b. (a -> b) -> a -> b
$ Name -> Name
A.nameConcrete (Name -> Name) -> Name -> Name
forall a b. (a -> b) -> a -> b
$ Binder' Name -> Name
forall a. Binder' a -> a
A.binderName Binder' Name
x)
, metaKind :: MetaKind
A.metaKind = MetaKind
A.UnificationMeta
}
checkKnownArguments
:: [NamedArg A.Expr]
-> Args
-> Type
-> TCM (Args, Type)
checkKnownArguments :: [NamedArg Expr] -> [Arg Term] -> Type -> TCM ([Arg Term], Type)
checkKnownArguments [] [Arg Term]
vs Type
t = ([Arg Term], Type) -> TCM ([Arg Term], Type)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ([Arg Term]
vs, Type
t)
checkKnownArguments (NamedArg Expr
arg : [NamedArg Expr]
args) [Arg Term]
vs Type
t = do
(vs', t') <- NamedArg Expr -> TCM ([Arg Term], Type) -> TCM ([Arg Term], Type)
forall (m :: * -> *) x a.
(MonadTrace m, HasRange x) =>
x -> m a -> m a
setCurrentRange NamedArg Expr
arg (TCM ([Arg Term], Type) -> TCM ([Arg Term], Type))
-> TCM ([Arg Term], Type) -> TCM ([Arg Term], Type)
forall a b. (a -> b) -> a -> b
$ NamedArg Expr -> [Arg Term] -> Type -> TCM ([Arg Term], Type)
checkKnownArgument NamedArg Expr
arg [Arg Term]
vs Type
t
checkKnownArguments args vs' t'
checkKnownArgument
:: NamedArg A.Expr
-> Args
-> Type
-> TCM (Args, Type)
checkKnownArgument :: NamedArg Expr -> [Arg Term] -> Type -> TCM ([Arg Term], Type)
checkKnownArgument NamedArg Expr
arg [] Type
_ = TypeError -> TCM ([Arg Term], Type)
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> TCM ([Arg Term], Type))
-> TypeError -> TCM ([Arg Term], Type)
forall a b. (a -> b) -> a -> b
$ NamedArg Expr -> TypeError
InvalidProjectionParameter NamedArg Expr
arg
checkKnownArgument NamedArg Expr
arg (Arg ArgInfo
_ Term
v : [Arg Term]
vs) Type
t = do
(dom@(unDom -> a), b) <- Type -> TCMT IO (Dom Type, Abs Type)
forall (m :: * -> *).
MonadReduce m =>
Type -> m (Dom Type, Abs Type)
mustBePi Type
t
if not $ fromMaybe __IMPOSSIBLE__ $ fittingNamedArg arg dom
then checkKnownArgument arg vs (b `absApp` v)
else do
u <- checkNamedArg arg a
equalTerm a u v
return (vs, b `absApp` v)
checkNamedArg :: NamedArg A.Expr -> Type -> TCM Term
checkNamedArg :: NamedArg Expr -> Type -> TCM Term
checkNamedArg arg :: NamedArg Expr
arg@(Arg ArgInfo
info Named_ Expr
e0) Type
t0 = do
let e :: Expr
e = Named_ Expr -> Expr
forall name a. Named name a -> a
namedThing Named_ Expr
e0
let x :: ArgName
x = ArgName -> Named_ Expr -> ArgName
forall a.
(LensNamed a, NameOf a ~ WithOrigin (Ranged ArgName)) =>
ArgName -> a -> ArgName
bareNameWithDefault ArgName
"" Named_ Expr
e0
Call -> TCM Term -> TCM Term
forall a. Call -> TCMT IO a -> TCMT IO a
forall (m :: * -> *) a. MonadTrace m => Call -> m a -> m a
traceCall (Comparison -> Expr -> Type -> Call
CheckExprCall Comparison
CmpLeq Expr
e Type
t0) (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ do
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.term.args.named" Int
15 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ do
TCMT IO Doc
"Checking named arg" 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, Foldable t) =>
t (m Doc) -> m Doc
fsep [ 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
":", Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Type -> m Doc
prettyTCM Type
t0 ]
]
String -> Int -> String -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> String -> m ()
reportSLn String
"tc.term.args.named" Int
75 (String -> TCM ()) -> String -> TCM ()
forall a b. (a -> b) -> a -> b
$ String
" arg = " String -> String -> String
forall a. [a] -> [a] -> [a]
++! NamedArg Expr -> String
forall a. Show a => a -> String
show (NamedArg Expr -> NamedArg Expr
forall a. ExprLike a => a -> a
deepUnscope NamedArg Expr
arg)
let checkU :: MetaInfo -> TCM Term
checkU MetaInfo
i = MetaInfo
-> (Comparison -> Type -> TCM (MetaId, Term))
-> Comparison
-> Type
-> TCM Term
checkMeta MetaInfo
i
(\Comparison
cmp -> MetaKind -> ArgName -> Comparison -> Type -> TCM (MetaId, Term)
newMetaArg (MetaInfo -> MetaKind
A.metaKind MetaInfo
i) ArgName
x Comparison
cmp)
Comparison
CmpLeq Type
t0
let checkQ :: MetaInfo -> InteractionId -> TCM Term
checkQ = (Comparison -> Type -> TCM (MetaId, Term))
-> Comparison -> Type -> MetaInfo -> InteractionId -> TCM Term
checkQuestionMark (ArgName -> Comparison -> Type -> TCM (MetaId, Term)
newInteractionMetaArg ArgName
x) Comparison
CmpLeq Type
t0
if Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Expr -> Bool
isHole Expr
e then Expr -> Type -> TCM Term
checkExpr Expr
e Type
t0 else TCM Term -> TCM Term
forall a. TCM a -> TCM a
localScope (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ do
Expr -> TCM Expr
scopedExpr Expr
e TCM Expr -> (Expr -> 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
A.Underscore MetaInfo
i -> MetaInfo -> TCM Term
checkU MetaInfo
i
A.QuestionMark MetaInfo
i InteractionId
ii -> MetaInfo -> InteractionId -> TCM Term
checkQ MetaInfo
i InteractionId
ii
Expr
_ -> TCM Term
forall a. HasCallStack => a
__IMPOSSIBLE__
where
isHole :: Expr -> Bool
isHole A.Underscore{} = Bool
True
isHole A.QuestionMark{} = Bool
True
isHole (A.ScopedExpr ScopeInfo
_ Expr
e) = Expr -> Bool
isHole Expr
e
isHole Expr
_ = Bool
False
inferExpr :: A.Expr -> TCM (Term, Type)
inferExpr :: Expr -> TCM (Term, Type)
inferExpr = ExpandHidden -> Expr -> TCM (Term, Type)
inferExpr' ExpandHidden
DontExpandLast
inferExpr' :: ExpandHidden -> A.Expr -> TCM (Term, Type)
inferExpr' :: ExpandHidden -> Expr -> TCM (Term, Type)
inferExpr' ExpandHidden
exh Expr
e = 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 (Expr -> Call
InferExpr Expr
e) (TCM (Term, Type) -> TCM (Term, Type))
-> TCM (Term, Type) -> TCM (Term, Type)
forall a b. (a -> b) -> a -> b
$ do
Application hd args <- Expr -> TCM AppView
appViewM Expr
e
reportSDoc "tc.infer" 30 $ vcat
[ "inferExpr': appView of " <+> prettyA e
, " hd = " <+> prettyA hd
, " args = " <+> prettyAs args
]
reportSDoc "tc.infer" 60 $ vcat
[ text $ " hd (raw) = " ++! show hd
]
inferApplication exh hd args e
defOrVar :: A.Expr -> Bool
defOrVar :: Expr -> Bool
defOrVar A.Var{} = Bool
True
defOrVar A.Def'{} = Bool
True
defOrVar A.Proj{} = Bool
True
defOrVar (A.ScopedExpr ScopeInfo
_ Expr
e) = Expr -> Bool
defOrVar Expr
e
defOrVar Expr
_ = Bool
False
checkDontExpandLast :: Comparison -> A.Expr -> Type -> TCM Term
checkDontExpandLast :: Comparison -> Expr -> Type -> TCM Term
checkDontExpandLast Comparison
cmp Expr
e Type
t = do
Application hd args <- Expr -> TCM AppView
appViewM Expr
e
if defOrVar hd then
traceCall (CheckExprCall cmp e t) $ localScope $ dontExpandLast $ do
checkApplication cmp hd args e t
else checkExpr' cmp e t
isModuleFreeVar :: Int -> TCM Bool
isModuleFreeVar :: Int -> TCMT IO Bool
isModuleFreeVar Int
i = do
params <- ModuleName -> TCMT IO [Arg Term]
forall (m :: * -> *).
(HasOptions m, MonadTCEnv m, ReadTCState m, MonadDebug m) =>
ModuleName -> m [Arg Term]
moduleParamsToApply (ModuleName -> TCMT IO [Arg Term])
-> TCMT IO ModuleName -> TCMT IO [Arg Term]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCMT IO ModuleName
forall (m :: * -> *). MonadTCEnv m => m ModuleName
currentModule
return $! any ((== Var i []) . unArg) params
inferExprForWith :: Arg A.Expr -> TCM (Term, Type)
inferExprForWith :: Arg Expr -> TCM (Term, Type)
inferExprForWith (Arg ArgInfo
info Expr
e) = String -> Int -> String -> TCM (Term, Type) -> TCM (Term, Type)
forall a. String -> Int -> String -> TCMT IO a -> TCMT IO a
forall (m :: * -> *) a.
MonadDebug m =>
String -> Int -> String -> m a -> m a
verboseBracket String
"tc.with.infer" Int
20 String
"inferExprForWith" (TCM (Term, Type) -> TCM (Term, Type))
-> TCM (Term, Type) -> TCM (Term, Type)
forall a b. (a -> b) -> a -> b
$ do
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.with.infer" Int
20 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"inferExprForWith " 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
e
String -> Int -> String -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> String -> m ()
reportSLn String
"tc.with.infer" Int
80 (String -> TCM ()) -> String -> TCM ()
forall a b. (a -> b) -> a -> b
$ String
"inferExprForWith " String -> String -> String
forall a. [a] -> [a] -> [a]
++! Expr -> String
forall a. Show a => a -> String
show (Expr -> Expr
forall a. ExprLike a => a -> a
deepUnscope Expr
e)
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 (Expr -> Call
InferExpr Expr
e) (TCM (Term, Type) -> TCM (Term, Type))
-> TCM (Term, Type) -> TCM (Term, Type)
forall a b. (a -> b) -> a -> b
$ do
(v, t) <- (Term, Type) -> TCM (Term, Type)
forall a (m :: * -> *).
(InstantiateFull a, MonadReduce m) =>
a -> m a
instantiateFull ((Term, Type) -> TCM (Term, Type))
-> TCM (Term, Type) -> TCM (Term, Type)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Expr -> TCM (Term, Type)
inferExpr Expr
e
v <- reduce v
case v of
Var Int
i [] -> TCMT IO Bool -> TCM () -> TCM ()
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
whenM (Int -> TCMT IO Bool
isModuleFreeVar Int
i) (TCM () -> TCM ()) -> TCM () -> TCM ()
forall a b. (a -> b) -> a -> b
$ do
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.with.infer" Int
80 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
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
[ String -> TCMT IO Doc
forall (m :: * -> *). Applicative m => String -> m Doc
text (String -> TCMT IO Doc) -> String -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ String
"with expression is variable " String -> String -> String
forall a. [a] -> [a] -> [a]
++! Int -> String
forall a. Show a => a -> String
show Int
i
, TCMT IO Doc
"current modules = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> do String -> TCMT IO Doc
forall (m :: * -> *). Applicative m => String -> m Doc
text (String -> TCMT IO Doc)
-> (ModuleName -> String) -> ModuleName -> TCMT IO Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModuleName -> String
forall a. Show a => a -> String
show (ModuleName -> TCMT IO Doc) -> TCMT IO ModuleName -> TCMT IO Doc
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCMT IO ModuleName
forall (m :: * -> *). MonadTCEnv m => m ModuleName
currentModule
, TCMT IO Doc
"current module free vars = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> do String -> TCMT IO Doc
forall (m :: * -> *). Applicative m => String -> m Doc
text (String -> TCMT IO Doc) -> (Int -> String) -> Int -> TCMT IO Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String
forall a. Show a => a -> String
show (Int -> TCMT IO Doc) -> TCMT IO Int -> TCMT IO Doc
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCMT IO Int
getCurrentModuleFreeVars
, TCMT IO Doc
"context size = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> do String -> TCMT IO Doc
forall (m :: * -> *). Applicative m => String -> m Doc
text (String -> TCMT IO Doc) -> (Int -> String) -> Int -> TCMT IO Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String
forall a. Show a => a -> String
show (Int -> TCMT IO Doc) -> TCMT IO Int -> TCMT IO Doc
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCMT IO Int
forall (m :: * -> *). MonadTCEnv m => m Int
getContextSize
, TCMT IO Doc
"current context = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> do Telescope -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Telescope -> m Doc
prettyTCM (Telescope -> TCMT IO Doc) -> TCMT IO Telescope -> TCMT IO Doc
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCMT IO Telescope
forall (m :: * -> *). MonadTCEnv m => m Telescope
getContextTelescope
]
TypeError -> TCM ()
forall (m :: * -> *) e a.
(HasCallStack, MonadTCError m, Diagnostic e) =>
e -> m a
typeError (TypeError -> TCM ()) -> TypeError -> TCM ()
forall a b. (a -> b) -> a -> b
$ Expr -> Term -> TypeError
WithOnFreeVariable Expr
e Term
v
Term
_ -> () -> TCM ()
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
TelV tel t0 <- telViewUpTo' (-1) (not . visible) t
(v, t) <- case unEl t0 of
Def QName
d Elims
vs -> do
QName -> TCM (Maybe DataOrRecord)
isDataOrRecordType QName
d TCM (Maybe DataOrRecord)
-> (Maybe DataOrRecord -> TCM (Term, Type)) -> TCM (Term, Type)
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
Maybe DataOrRecord
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)
Just{} -> do
(args, t1) <- Int -> (Hiding -> Bool) -> Type -> TCM ([Arg Term], Type)
implicitArgs (-Int
1) Hiding -> Bool
forall a. LensHiding a => a -> Bool
notVisible Type
t
return (v `apply` args, t1)
Term
_ -> (Term, Type) -> TCM (Term, Type)
forall a. a -> TCMT IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (Term
v, Type
t)
solveAwakeConstraints
return (v, t)
checkLetBindings' :: Foldable t => t A.LetBinding -> TCM a -> TCM a
checkLetBindings' :: forall (t :: * -> *) a.
Foldable t =>
t LetBinding -> TCM a -> TCM a
checkLetBindings' = (LetBinding -> (TCM a -> TCM a) -> TCM a -> TCM a)
-> (TCM a -> TCM a) -> t LetBinding -> TCM a -> TCM a
forall a b. (a -> b -> b) -> b -> t a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ((TCM a -> TCM a) -> (TCM a -> TCM a) -> TCM a -> TCM a
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) ((TCM a -> TCM a) -> (TCM a -> TCM a) -> TCM a -> TCM a)
-> (LetBinding -> TCM a -> TCM a)
-> LetBinding
-> (TCM a -> TCM a)
-> TCM a
-> TCM a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LetBinding -> TCM a -> TCM a
forall a. LetBinding -> TCM a -> TCM a
checkLetBinding') TCM a -> TCM a
forall a. a -> a
id
checkLetBinding' :: A.LetBinding -> TCM a -> TCM a
checkLetBinding' :: forall a. LetBinding -> TCM a -> TCM a
checkLetBinding' b :: LetBinding
b@(A.LetBind LetInfo
i ArgInfo
info BindName
x Expr
t Expr
e) TCM a
ret = do
let
check :: Comparison -> Expr -> Type -> TCM Term
check
| ArgInfo -> Origin
forall a. LensOrigin a => a -> Origin
getOrigin ArgInfo
info Origin -> Origin -> Bool
forall a. Eq a => a -> a -> Bool
== Origin
Inserted = Comparison -> Expr -> Type -> TCM Term
checkDontExpandLast
| Bool
otherwise = Comparison -> Expr -> Type -> TCM Term
checkExpr'
t <- TCM Type -> TCM Type
forall (m :: * -> *) a. (MonadTCEnv m, MonadDebug m) => m a -> m a
workOnTypes (TCM Type -> TCM Type) -> TCM Type -> TCM Type
forall a b. (a -> b) -> a -> b
$ Expr -> TCM Type
isType_ Expr
t
v <- check CmpLeq e t
addLetBinding info UserWritten (A.unBind x) v t ret
checkLetBinding' b :: LetBinding
b@(A.LetAxiom LetInfo
i ArgInfo
info BindName
x Expr
t) TCM a
ret = do
t <- TCM Type -> TCM Type
forall (m :: * -> *) a. (MonadTCEnv m, MonadDebug m) => m a -> m a
workOnTypes (TCM Type -> TCM Type) -> TCM Type -> TCM Type
forall a b. (a -> b) -> a -> b
$ Expr -> TCM Type
isType_ Expr
t
current <- currentModule
axn <- qualify current <$> freshName_ (A.unBind x)
addConstant' axn defaultArgInfo t defaultAxiom
val <- Def axn . fmap Apply <$> getContextArgs
addLetAxiom info UserWritten (A.unBind x) val t ret
checkLetBinding' b :: LetBinding
b@(A.LetPatBind LetInfo
i Pattern
p Expr
e) TCM a
ret = do
p <- Pattern -> TCM Pattern
forall a. ExpandPatternSynonyms a => a -> TCM a
expandPatternSynonyms Pattern
p
(v, t) <- inferExpr' ExpandLast e
let
t0 = Sort' Term -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El (Type -> Sort' Term
forall a. LensSort a => a -> Sort' Term
getSort Type
t) (Term -> Type) -> Term -> Type
forall a b. (a -> b) -> a -> b
$ Dom Type -> Abs Type -> Term
Pi (Type -> Dom Type
forall a t. a -> Dom' t a
defaultDom Type
t) (ArgName -> Type -> Abs Type
forall a. ArgName -> a -> Abs a
NoAbs ArgName
forall a. Underscore a => a
underscore Type
HasCallStack => Type
__DUMMY_TYPE__)
p0 = ArgInfo
-> Named (WithOrigin (Ranged ArgName)) Pattern -> NamedArg Pattern
forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
defaultArgInfo (Maybe (WithOrigin (Ranged ArgName))
-> Pattern -> Named (WithOrigin (Ranged ArgName)) Pattern
forall name a. Maybe name -> a -> Named name a
Named Maybe (WithOrigin (Ranged ArgName))
forall a. Maybe a
Nothing Pattern
p)
reportSDoc "tc.term.let.pattern" 10 $ vcat
[ "let-binding pattern p at type t"
, nest 2 $ vcat
[ "p (A) =" <+> prettyA p
, "t =" <+> prettyTCM t
]
]
fvs <- getContextSize
checkLeftHandSide (CheckPattern p EmptyTel t) noRange LetLHS [p0] t0 Nothing [] $ \ (LHSResult Int
_ Telescope
delta0 NAPs
ps Bool
_ Type
_t Substitution
_ [AsBinding]
asb IntSet
_ Bool
_) -> Pattern -> TCM a -> TCM a
forall (m :: * -> *) x a.
(MonadTrace m, HasRange x) =>
x -> m a -> m a
setCurrentRange Pattern
p (TCM a -> TCM a) -> TCM a -> TCM a
forall a b. (a -> b) -> a -> b
$ [AsBinding] -> TCM a -> TCM a
forall a. [AsBinding] -> TCM a -> TCM a
bindAsPatterns [AsBinding]
asb (TCM a -> TCM a) -> TCM a -> TCM a
forall a b. (a -> b) -> a -> b
$ do
let p :: DeBruijnPattern
p = case Int -> NAPs -> NAPs
forall a. Int -> [a] -> [a]
drop Int
fvs NAPs
ps of [Arg (Named_ DeBruijnPattern)
p] -> Arg (Named_ DeBruijnPattern) -> DeBruijnPattern
forall a. NamedArg a -> a
namedArg Arg (Named_ DeBruijnPattern)
p; NAPs
_ -> DeBruijnPattern
forall a. HasCallStack => a
__IMPOSSIBLE__
delta :: Telescope
delta = ListTel -> Telescope
telFromList (ListTel -> Telescope) -> ListTel -> Telescope
forall a b. (a -> b) -> a -> b
$ Int -> ListTel -> ListTel
forall a. Int -> [a] -> [a]
drop Int
fvs (ListTel -> ListTel) -> ListTel -> ListTel
forall a b. (a -> b) -> a -> b
$ Telescope -> ListTel
forall t. Tele (Dom t) -> [Dom (ArgName, t)]
telToList Telescope
delta0
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.term.let.pattern" Int
20 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
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
[ TCMT IO Doc
"p (I) =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> DeBruijnPattern -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => DeBruijnPattern -> m Doc
prettyTCM DeBruijnPattern
p
, TCMT IO Doc
"delta =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> Telescope -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
forall (m :: * -> *). MonadPretty m => Telescope -> m Doc
prettyTCM Telescope
delta
]
String -> Int -> TCMT IO Doc -> TCM ()
forall (m :: * -> *).
MonadDebug m =>
String -> Int -> TCMT IO Doc -> m ()
reportSDoc String
"tc.term.let.pattern" Int
80 (TCMT IO Doc -> TCM ()) -> TCMT IO Doc -> TCM ()
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
[ TCMT IO Doc
"p (I) =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
<+> (String -> TCMT IO Doc
forall (m :: * -> *). Applicative m => String -> m Doc
text (String -> TCMT IO Doc)
-> (DeBruijnPattern -> String) -> DeBruijnPattern -> TCMT IO Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DeBruijnPattern -> String
forall a. Show a => a -> String
show) DeBruijnPattern
p
]
fs <- DeBruijnPattern -> TCM [Term -> Term]
recordPatternToProjections DeBruijnPattern
p
cxt0 <- getContext
let binds = Int -> Context -> [ContextEntry]
cxTake (Telescope -> Int
forall a. Sized a => a -> Int
size Telescope
delta) Context
cxt0
toDrop = [ContextEntry] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [ContextEntry]
binds
sigma = ((Term -> Term) -> Term) -> [Term -> Term] -> [Term]
forall a b. (a -> b) -> [a] -> [b]
map' ((Term -> Term) -> Term -> Term
forall a b. (a -> b) -> a -> b
$ Term
v) [Term -> Term]
fs
sub = [Term] -> Substitution
forall a. DeBruijn a => [a] -> Substitution' a
parallelS ([Term] -> [Term]
forall a. [a] -> [a]
reverse [Term]
sigma)
updateContext sub (cxDrop toDrop) $ do
reportSDoc "tc.term.let.pattern" 20 $ nest 2 $ vcat
[ "delta =" <+> prettyTCM delta
, "binds =" <+> prettyTCM binds
]
let fdelta = Telescope -> [Dom Type]
forall a. TermSubst a => Tele (Dom a) -> [Dom a]
flattenTel Telescope
delta
reportSDoc "tc.term.let.pattern" 20 $ nest 2 $ vcat
[ "fdelta =" <+> addContext delta (prettyTCM fdelta)
]
let tsl = Substitution' (SubstArg [Dom Type]) -> [Dom Type] -> [Dom Type]
forall a. Subst a => Substitution' (SubstArg a) -> a -> a
applySubst Substitution
Substitution' (SubstArg [Dom Type])
sub [Dom Type]
fdelta
let ts = (Dom Type -> Type) -> [Dom Type] -> [Type]
forall a b. (a -> b) -> [a] -> [b]
map' Dom Type -> Type
forall t e. Dom' t e -> e
unDom [Dom Type]
tsl
let infos = (Dom Type -> ArgInfo) -> [Dom Type] -> [ArgInfo]
forall a b. (a -> b) -> [a] -> [b]
map' Dom Type -> ArgInfo
forall t e. Dom' t e -> ArgInfo
domInfo [Dom Type]
tsl
let xs = (ContextEntry -> Name) -> [ContextEntry] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map' ContextEntry -> Name
ctxEntryName ([ContextEntry] -> [Name]) -> [ContextEntry] -> [Name]
forall a b. (a -> b) -> a -> b
$ [ContextEntry] -> [ContextEntry]
forall a. [a] -> [a]
reverse [ContextEntry]
binds
foldr (uncurry4 $ flip addLetBinding UserWritten) ret $ List.zip4 infos xs sigma ts
checkLetBinding' (A.LetApply ModuleInfo
i ModuleName
x ModuleApplication
modapp ScopeCopyInfo
copyInfo ImportDirective
dir) TCM a
ret = do
fv <- TCMT IO Int
getCurrentModuleFreeVars
n <- getContextSize
let new = Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
fv
reportSDoc "tc.term.let.apply" 10 $ "Applying" <+> pretty x <+> prettyA modapp <?> ("with" <+> pshow new <+> "free variables")
reportSDoc "tc.term.let.apply" 20 $ vcat
[ "context =" <+> (prettyTCM =<< getContextTelescope)
, "module =" <+> (prettyTCM =<< currentModule)
, "fv =" <+> text (show fv)
, "copy =" <+> pretty copyInfo
]
checkSectionApplication i x modapp copyInfo
dir{ publicOpen = Nothing }
withAnonymousModule x new ret
checkLetBinding' A.LetOpen{} TCM a
ret = TCM a
ret
checkLetBinding :: A.LetBinding -> TCM a -> TCM a
checkLetBinding :: forall a. LetBinding -> TCM a -> TCM a
checkLetBinding LetBinding
b = Call -> (TCMT IO a -> TCMT IO a) -> TCMT IO a -> TCMT IO a
forall (m :: * -> *) b.
MonadTrace m =>
Call -> (m b -> m b) -> m b -> m b
traceCallCPS' (LetBinding -> Call
CheckLetBinding LetBinding
b) (LetBinding -> TCMT IO a -> TCMT IO a
forall a. LetBinding -> TCM a -> TCM a
checkLetBinding' LetBinding
b)
checkLetBindings :: Foldable t => t A.LetBinding -> TCM a -> TCM a
checkLetBindings :: forall (t :: * -> *) a.
Foldable t =>
t LetBinding -> TCM a -> TCM a
checkLetBindings = (LetBinding -> (TCM a -> TCM a) -> TCM a -> TCM a)
-> (TCM a -> TCM a) -> t LetBinding -> TCM a -> TCM a
forall a b. (a -> b -> b) -> b -> t a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ((TCM a -> TCM a) -> (TCM a -> TCM a) -> TCM a -> TCM a
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) ((TCM a -> TCM a) -> (TCM a -> TCM a) -> TCM a -> TCM a)
-> (LetBinding -> TCM a -> TCM a)
-> LetBinding
-> (TCM a -> TCM a)
-> TCM a
-> TCM a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LetBinding -> TCM a -> TCM a
forall a. LetBinding -> TCM a -> TCM a
checkLetBinding) TCM a -> TCM a
forall a. a -> a
id