{-# LANGUAGE NondecreasingIndentation #-}

{-# OPTIONS_GHC -fno-warn-orphans #-}

module Agda.Interaction.BasicOps where

import Prelude hiding (null)

import Control.Arrow          ( first )
import Control.Monad          ( (>=>), forM, guard )
import Control.Monad.Except
import Control.Monad.Reader
import Control.Monad.State
import Control.Monad.Identity

import qualified Data.IntMap as IntMap
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.List as List
import Data.Maybe
import Data.Monoid
import Data.Function (on)
import Data.Text (Text)
import qualified Data.Text as T

import Agda.Interaction.Base
import Agda.Interaction.Options
import Agda.Interaction.Response (Goals, ResponseContextEntry(..))

import qualified Agda.Syntax.Concrete as C -- ToDo: Remove with instance of ToConcrete
import Agda.Syntax.Position
import Agda.Syntax.Abstract as A hiding (Open, Apply, Assign)
import Agda.Syntax.Abstract.Views as A
import Agda.Syntax.Abstract.Pretty
import Agda.Syntax.Common
import Agda.Syntax.Info (MetaInfo(..),emptyMetaInfo,exprNoRange,defaultAppInfo_,defaultAppInfo)
import qualified Agda.Syntax.Info as Info
import Agda.Syntax.Internal as I
import Agda.Syntax.Literal
import Agda.Syntax.Translation.InternalToAbstract
import Agda.Syntax.Translation.AbstractToConcrete
import Agda.Syntax.Translation.ConcreteToAbstract
import Agda.Syntax.Scope.Base
import Agda.Syntax.Scope.Monad
import Agda.Syntax.Fixity(Precedence(..), argumentCtx_)
import Agda.Syntax.Parser

import Agda.TheTypeChecker
import Agda.TypeChecking.Constraints
import Agda.TypeChecking.Conversion
import Agda.TypeChecking.Errors ( getAllWarnings, stringTCErr )
import Agda.TypeChecking.Monad as M hiding (MetaInfo)
import Agda.TypeChecking.MetaVars
import Agda.TypeChecking.MetaVars.Mention
import Agda.TypeChecking.Reduce
import Agda.TypeChecking.Substitute
import Agda.TypeChecking.Telescope
import Agda.TypeChecking.With
import Agda.TypeChecking.Coverage
import Agda.TypeChecking.Coverage.Match ( SplitPattern )
import Agda.TypeChecking.Records
import Agda.TypeChecking.Irrelevance (wakeIrrelevantVars)
import Agda.TypeChecking.Pretty ( PrettyTCM, prettyTCM )
import Agda.TypeChecking.IApplyConfluence
import Agda.TypeChecking.Primitive
import Agda.TypeChecking.Names
import Agda.TypeChecking.Free
import Agda.TypeChecking.CheckInternal
import Agda.TypeChecking.SizedTypes.Solve
import qualified Agda.TypeChecking.Pretty as TP
import Agda.TypeChecking.Warnings
  ( runPM, warning, WhichWarnings(..), classifyWarnings, isMetaTCWarning
  , WarningsAndNonFatalErrors, emptyWarningsAndNonFatalErrors )

import Agda.Termination.TermCheck (termMutual)

import Agda.Utils.Functor
import Agda.Utils.Lens
import Agda.Utils.List
import Agda.Utils.List1 (List1, pattern (:|))
import qualified Agda.Utils.List1 as List1
import Agda.Utils.Maybe
import Agda.Utils.Monad
import Agda.Utils.Null
import Agda.Utils.Pretty as P
import Agda.Utils.Permutation
import Agda.Utils.Size
import Agda.Utils.String

import Agda.Utils.Impossible

-- | Parses an expression.

parseExpr :: Range -> String -> TCM C.Expr
parseExpr :: Range -> ArgName -> TCM Expr
parseExpr Range
rng ArgName
s = do
  C.ExprWhere Expr
e WhereClause
wh <- PM ExprWhere -> TCM ExprWhere
forall a. PM a -> TCM a
runPM (PM ExprWhere -> TCM ExprWhere) -> PM ExprWhere -> TCM ExprWhere
forall a b. (a -> b) -> a -> b
$ Parser ExprWhere -> Position -> ArgName -> PM ExprWhere
forall a. Parser a -> Position -> ArgName -> PM a
parsePosString Parser ExprWhere
exprWhereParser Position
pos ArgName
s
  Bool -> TCMT IO () -> TCMT IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (WhereClause -> Bool
forall a. Null a => a -> Bool
null WhereClause
wh) (TCMT IO () -> TCMT IO ()) -> TCMT IO () -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ TypeError -> TCMT IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO ()) -> TypeError -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ ArgName -> TypeError
GenericError (ArgName -> TypeError) -> ArgName -> TypeError
forall a b. (a -> b) -> a -> b
$
    ArgName
"where clauses are not supported in holes"
  Expr -> TCM Expr
forall (m :: * -> *) a. Monad m => a -> m a
return Expr
e
  where pos :: Position
pos = Position -> Maybe Position -> Position
forall a. a -> Maybe a -> a
fromMaybe (Maybe AbsolutePath -> Position
startPos Maybe AbsolutePath
forall a. Maybe a
Nothing) (Maybe Position -> Position) -> Maybe Position -> Position
forall a b. (a -> b) -> a -> b
$ Range -> Maybe Position
forall a. Range' a -> Maybe (Position' a)
rStart Range
rng

parseExprIn :: InteractionId -> Range -> String -> TCM Expr
parseExprIn :: InteractionId -> Range -> ArgName -> TCM Expr
parseExprIn InteractionId
ii Range
rng ArgName
s = do
    MetaId
mId <- InteractionId -> TCMT IO MetaId
forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadError TCErr m, MonadTCEnv m) =>
InteractionId -> m MetaId
lookupInteractionId InteractionId
ii
    MetaId -> Range -> TCMT IO ()
forall (m :: * -> *). MonadMetaSolver m => MetaId -> Range -> m ()
updateMetaVarRange MetaId
mId Range
rng
    Closure Range
mi  <- MetaVariable -> Closure Range
getMetaInfo (MetaVariable -> Closure Range)
-> TCMT IO MetaVariable -> TCMT IO (Closure Range)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MetaId -> TCMT IO MetaVariable
forall (m :: * -> *).
(MonadFail m, ReadTCState m) =>
MetaId -> m MetaVariable
lookupMeta MetaId
mId
    Expr
e   <- Range -> ArgName -> TCM Expr
parseExpr Range
rng ArgName
s
    -- Andreas, 2019-08-19, issue #4007
    -- We need to be in the TCEnv of the meta variable
    -- such that the scope checker can label the clause
    -- of a parsed extended lambda as IsAbstract if the
    -- interaction point was created in AbstractMode.
    Closure Range -> TCM Expr -> TCM Expr
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadTrace m) =>
Closure Range -> m a -> m a
withMetaInfo Closure Range
mi (TCM Expr -> TCM Expr) -> TCM Expr -> TCM Expr
forall a b. (a -> b) -> a -> b
$
      ScopeInfo -> Expr -> ScopeM (AbsOfCon Expr)
forall c. ToAbstract c => ScopeInfo -> c -> ScopeM (AbsOfCon c)
concreteToAbstract (Closure Range -> ScopeInfo
forall a. Closure a -> ScopeInfo
clScope Closure Range
mi) Expr
e

-- Type check the given expression and assign its value to the meta
-- Precondition: we are in the context where the given meta was created.
giveExpr :: UseForce -> Maybe InteractionId -> MetaId -> Expr -> TCM Term
giveExpr :: UseForce -> Maybe InteractionId -> MetaId -> Expr -> TCM Term
giveExpr UseForce
force Maybe InteractionId
mii MetaId
mi Expr
e = do
    MetaVariable
mv <- MetaId -> TCMT IO MetaVariable
forall (m :: * -> *).
(MonadFail m, ReadTCState m) =>
MetaId -> m MetaVariable
lookupMeta MetaId
mi
    let t :: Type
t = case MetaVariable -> Judgement MetaId
mvJudgement MetaVariable
mv of
              IsSort{}    -> Type
forall a. HasCallStack => a
__IMPOSSIBLE__
              HasType MetaId
_ Comparison
_ Type
t -> Type
t
    ArgName -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> TCMT IO Doc -> m ()
reportSDoc ArgName
"interaction.give" Int
20 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$
      TCMT IO Doc
"give: meta type =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
t
    -- Here, we must be in the same context where the meta was created.
    -- Thus, we can safely apply its type to the context variables.
    Args
ctx <- TCMT IO Args
forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m Args
getContextArgs
    Type
t' <- Type
t Type -> Args -> TCMT IO Type
forall a (m :: * -> *).
(PiApplyM a, MonadReduce m, HasBuiltins m) =>
Type -> a -> m Type
`piApplyM` Permutation -> Args -> Args
forall a. Permutation -> [a] -> [a]
permute (Int -> Permutation -> Permutation
takeP (Args -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length Args
ctx) (Permutation -> Permutation) -> Permutation -> Permutation
forall a b. (a -> b) -> a -> b
$ MetaVariable -> Permutation
mvPermutation MetaVariable
mv) Args
ctx
    Call -> TCM Term -> TCM Term
forall (m :: * -> *) a. MonadTrace m => Call -> m a -> m a
traceCall (Comparison -> Expr -> Type -> Call
CheckExprCall Comparison
CmpLeq Expr
e Type
t') (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ do
      ArgName -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> TCMT IO Doc -> m ()
reportSDoc ArgName
"interaction.give" Int
20 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ do
        AbstractMode
a <- (TCEnv -> AbstractMode) -> TCMT IO AbstractMode
forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC TCEnv -> AbstractMode
envAbstractMode
        [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
TP.hsep
          [ ArgName -> TCMT IO Doc
forall (m :: * -> *). Applicative m => ArgName -> m Doc
TP.text (ArgName
"give(" ArgName -> ArgName -> ArgName
forall a. [a] -> [a] -> [a]
++ AbstractMode -> ArgName
forall a. Show a => a -> ArgName
show AbstractMode
a ArgName -> ArgName -> ArgName
forall a. [a] -> [a] -> [a]
++ ArgName
"): instantiated meta type =")
          , Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
t'
          ]
      -- Andreas, 2020-05-27 AIM XXXII, issue #4679
      -- Clear envMutualBlock since cubical only executes
      -- certain checks (checkIApplyConfluence) for an extended lambda
      -- when not in a mutual block.
      Term
v <- Lens' (Maybe MutualId) TCEnv
-> (Maybe MutualId -> Maybe MutualId) -> TCM Term -> TCM Term
forall (m :: * -> *) a b.
MonadTCEnv m =>
Lens' a TCEnv -> (a -> a) -> m b -> m b
locallyTC Lens' (Maybe MutualId) TCEnv
eMutualBlock (Maybe MutualId -> Maybe MutualId -> Maybe MutualId
forall a b. a -> b -> a
const Maybe MutualId
forall a. Maybe a
Nothing) (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$
        Expr -> Type -> TCM Term
checkExpr Expr
e Type
t'
      case MetaVariable -> MetaInstantiation
mvInstantiation MetaVariable
mv of

        InstV{} -> TCMT IO Bool -> TCMT IO () -> TCMT IO ()
forall (m :: * -> *). Monad m => m Bool -> m () -> m ()
unlessM ((Relevance
Irrelevant Relevance -> Relevance -> Bool
forall a. Eq a => a -> a -> Bool
==) (Relevance -> Bool) -> TCMT IO Relevance -> TCMT IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (TCEnv -> Relevance) -> TCMT IO Relevance
forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC TCEnv -> Relevance
forall a. LensRelevance a => a -> Relevance
getRelevance) (TCMT IO () -> TCMT IO ()) -> TCMT IO () -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ do
          Term
v' <- Term -> TCM Term
forall a (m :: * -> *). (Instantiate a, MonadReduce m) => a -> m a
instantiate (Term -> TCM Term) -> Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ MetaId -> Elims -> Term
MetaV MetaId
mi (Elims -> Term) -> Elims -> Term
forall a b. (a -> b) -> a -> b
$ (Arg Term -> Elim) -> Args -> Elims
forall a b. (a -> b) -> [a] -> [b]
map Arg Term -> Elim
forall a. Arg a -> Elim' a
Apply Args
ctx
          ArgName -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> TCMT IO Doc -> m ()
reportSDoc ArgName
"interaction.give" Int
20 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
TP.sep
            [ TCMT IO Doc
"meta was already set to value v' = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> Term -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Term
v'
            , TCMT IO Doc
"now comparing it to given value v = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> Term -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Term
v
            , TCMT IO Doc
"in context " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> TCMT IO Doc -> TCMT IO Doc
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext (Args -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Args
ctx)
            ]
          Type -> Term -> Term -> TCMT IO ()
forall (m :: * -> *).
MonadConversion m =>
Type -> Term -> Term -> m ()
equalTerm Type
t' Term
v Term
v'

        MetaInstantiation
_ -> do -- updateMeta mi v
          ArgName -> Int -> ArgName -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> ArgName -> m ()
reportSLn ArgName
"interaction.give" Int
20 ArgName
"give: meta unassigned, assigning..."
          Args
args <- TCMT IO Args
forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m Args
getContextArgs
          TCMT IO () -> TCMT IO ()
forall (m :: * -> *) a. MonadTCEnv m => m a -> m a
nowSolvingConstraints (TCMT IO () -> TCMT IO ()) -> TCMT IO () -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ CompareDirection
-> MetaId -> Args -> Term -> CompareAs -> TCMT IO ()
assign CompareDirection
DirEq MetaId
mi Args
args Term
v (Type -> CompareAs
AsTermsOf Type
t')

      ArgName -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> TCMT IO Doc -> m ()
reportSDoc ArgName
"interaction.give" Int
20 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"give: meta variable updated!"
      Bool -> TCMT IO () -> TCMT IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (UseForce
force UseForce -> UseForce -> Bool
forall a. Eq a => a -> a -> Bool
== UseForce
WithForce) (TCMT IO () -> TCMT IO ()) -> TCMT IO () -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ Maybe InteractionId -> TCMT IO ()
redoChecks Maybe InteractionId
mii
      MetaId -> TCMT IO ()
wakeupConstraints MetaId
mi
      DefaultToInfty -> TCMT IO ()
solveSizeConstraints DefaultToInfty
DontDefaultToInfty
      Bool
cubical <- Maybe Cubical -> Bool
forall a. Maybe a -> Bool
isJust (Maybe Cubical -> Bool)
-> (PragmaOptions -> Maybe Cubical) -> PragmaOptions -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PragmaOptions -> Maybe Cubical
optCubical (PragmaOptions -> Bool) -> TCMT IO PragmaOptions -> TCMT IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TCMT IO PragmaOptions
forall (m :: * -> *). HasOptions m => m PragmaOptions
pragmaOptions
      -- don't double check with cubical, because it gets in the way too often.
      Bool -> TCMT IO () -> TCMT IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Bool
cubical Bool -> Bool -> Bool
|| UseForce
force UseForce -> UseForce -> Bool
forall a. Eq a => a -> a -> Bool
== UseForce
WithForce) (TCMT IO () -> TCMT IO ()) -> TCMT IO () -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ do
        -- Double check.
        ArgName -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> TCMT IO Doc -> m ()
reportSDoc ArgName
"interaction.give" Int
20 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"give: double checking"
        Term
vfull <- Term -> TCM Term
forall a (m :: * -> *).
(InstantiateFull a, MonadReduce m) =>
a -> m a
instantiateFull Term
v
        Term -> Comparison -> Type -> TCMT IO ()
forall (m :: * -> *).
MonadCheckInternal m =>
Term -> Comparison -> Type -> m ()
checkInternal Term
vfull Comparison
CmpLeq Type
t'
      Term -> TCM Term
forall (m :: * -> *) a. Monad m => a -> m a
return Term
v

-- | After a give, redo termination etc. checks for function which was complemented.
redoChecks :: Maybe InteractionId -> TCM ()
redoChecks :: Maybe InteractionId -> TCMT IO ()
redoChecks Maybe InteractionId
Nothing = () -> TCMT IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
redoChecks (Just InteractionId
ii) = do
  ArgName -> Int -> ArgName -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> ArgName -> m ()
reportSLn ArgName
"interaction.give" Int
20 (ArgName -> TCMT IO ()) -> ArgName -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$
    ArgName
"give: redoing termination check for function surrounding " ArgName -> ArgName -> ArgName
forall a. [a] -> [a] -> [a]
++ InteractionId -> ArgName
forall a. Show a => a -> ArgName
show InteractionId
ii
  InteractionPoint
ip <- InteractionId -> TCMT IO InteractionPoint
forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadError TCErr m) =>
InteractionId -> m InteractionPoint
lookupInteractionPoint InteractionId
ii
  case InteractionPoint -> IPClause
ipClause InteractionPoint
ip of
    IPClause
IPNoClause -> () -> TCMT IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    IPClause{ipcQName :: IPClause -> QName
ipcQName = QName
f} -> do
      MutualId
mb <- QName -> TCM MutualId
mutualBlockOf QName
f
      Result
terErrs <- (TCEnv -> TCEnv) -> TCMT IO Result -> TCMT IO Result
forall (m :: * -> *) a.
MonadTCEnv m =>
(TCEnv -> TCEnv) -> m a -> m a
localTC (\ TCEnv
e -> TCEnv
e { envMutualBlock :: Maybe MutualId
envMutualBlock = MutualId -> Maybe MutualId
forall a. a -> Maybe a
Just MutualId
mb }) (TCMT IO Result -> TCMT IO Result)
-> TCMT IO Result -> TCMT IO Result
forall a b. (a -> b) -> a -> b
$ [QName] -> TCMT IO Result
termMutual []
      Bool -> TCMT IO () -> TCMT IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Result -> Bool
forall a. Null a => a -> Bool
null Result
terErrs) (TCMT IO () -> TCMT IO ()) -> TCMT IO () -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ Warning -> TCMT IO ()
forall (m :: * -> *).
(HasCallStack, MonadWarning m) =>
Warning -> m ()
warning (Warning -> TCMT IO ()) -> Warning -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ Result -> Warning
TerminationIssue Result
terErrs
  -- TODO redo positivity check!

-- | Try to fill hole by expression.
--
--   Returns the given expression unchanged
--   (for convenient generalization to @'refine'@).
give
  :: UseForce       -- ^ Skip safety checks?
  -> InteractionId  -- ^ Hole.
  -> Maybe Range
  -> Expr           -- ^ The expression to give.
  -> TCM Expr       -- ^ If successful, the very expression is returned unchanged.
give :: UseForce -> InteractionId -> Maybe Range -> Expr -> TCM Expr
give UseForce
force InteractionId
ii Maybe Range
mr Expr
e = TCM Expr -> TCM Expr
forall (tcm :: * -> *) a. MonadTCM tcm => TCM a -> tcm a
liftTCM (TCM Expr -> TCM Expr) -> TCM Expr -> TCM Expr
forall a b. (a -> b) -> a -> b
$ do
  -- if Range is given, update the range of the interaction meta
  MetaId
mi  <- InteractionId -> TCMT IO MetaId
forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadError TCErr m, MonadTCEnv m) =>
InteractionId -> m MetaId
lookupInteractionId InteractionId
ii
  Maybe Range -> (Range -> TCMT IO ()) -> TCMT IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe Range
mr ((Range -> TCMT IO ()) -> TCMT IO ())
-> (Range -> TCMT IO ()) -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ MetaId -> Range -> TCMT IO ()
forall (m :: * -> *). MonadMetaSolver m => MetaId -> Range -> m ()
updateMetaVarRange MetaId
mi
  ArgName -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> TCMT IO Doc -> m ()
reportSDoc ArgName
"interaction.give" Int
10 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"giving expression" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> Expr -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Expr
e
  ArgName -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> TCMT IO Doc -> m ()
reportSDoc ArgName
"interaction.give" Int
50 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ ArgName -> TCMT IO Doc
forall (m :: * -> *). Applicative m => ArgName -> m Doc
TP.text (ArgName -> TCMT IO Doc) -> ArgName -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Expr -> ArgName
forall a. Show a => a -> ArgName
show (Expr -> ArgName) -> Expr -> ArgName
forall a b. (a -> b) -> a -> b
$ Expr -> Expr
forall a. ExprLike a => a -> a
deepUnscope Expr
e
  -- Try to give mi := e
  Term
_ <- InteractionId -> TCM Term -> TCM Term
forall (m :: * -> *) a.
(MonadFail m, ReadTCState m, MonadError TCErr m, MonadTCEnv m,
 MonadTrace m) =>
InteractionId -> m a -> m a
withInteractionId InteractionId
ii (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ do
     MetaId -> RunMetaOccursCheck -> TCMT IO ()
forall (m :: * -> *).
MonadMetaSolver m =>
MetaId -> RunMetaOccursCheck -> m ()
setMetaOccursCheck MetaId
mi RunMetaOccursCheck
DontRunMetaOccursCheck -- #589, #2710: Allow giving recursive solutions.
     UseForce -> Maybe InteractionId -> MetaId -> Expr -> TCM Term
giveExpr UseForce
force (InteractionId -> Maybe InteractionId
forall a. a -> Maybe a
Just InteractionId
ii) MetaId
mi Expr
e
    TCM Term -> (TCErr -> TCM Term) -> TCM Term
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError` \ case
      -- Turn PatternErr into proper error:
      PatternErr{} -> TypeError -> TCM Term
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCM Term) -> (Doc -> TypeError) -> Doc -> TCM Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> TypeError
GenericDocError (Doc -> TCM Term) -> TCMT IO Doc -> TCM Term
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< do
        InteractionId -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *) a.
(MonadFail m, ReadTCState m, MonadError TCErr m, MonadTCEnv m,
 MonadTrace m) =>
InteractionId -> m a -> m a
withInteractionId InteractionId
ii (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"Failed to give" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> Expr -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Expr
e
      TCErr
err -> TCErr -> TCM Term
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError TCErr
err
  InteractionId -> TCMT IO ()
forall (m :: * -> *).
MonadInteractionPoints m =>
InteractionId -> m ()
removeInteractionPoint InteractionId
ii
  Expr -> TCM Expr
forall (m :: * -> *) a. Monad m => a -> m a
return Expr
e

-- | Try to fill hole by elaborated expression.
elaborate_give
  :: Rewrite        -- ^ Normalise result?
  -> UseForce       -- ^ Skip safety checks?
  -> InteractionId  -- ^ Hole.
  -> Maybe Range
  -> Expr           -- ^ The expression to give.
  -> TCM Expr       -- ^ If successful, return the elaborated expression.
elaborate_give :: Rewrite
-> UseForce -> InteractionId -> Maybe Range -> Expr -> TCM Expr
elaborate_give Rewrite
norm UseForce
force InteractionId
ii Maybe Range
mr Expr
e = InteractionId -> TCM Expr -> TCM Expr
forall (m :: * -> *) a.
(MonadFail m, ReadTCState m, MonadError TCErr m, MonadTCEnv m,
 MonadTrace m) =>
InteractionId -> m a -> m a
withInteractionId InteractionId
ii (TCM Expr -> TCM Expr) -> TCM Expr -> TCM Expr
forall a b. (a -> b) -> a -> b
$ do
  -- if Range is given, update the range of the interaction meta
  MetaId
mi  <- InteractionId -> TCMT IO MetaId
forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadError TCErr m, MonadTCEnv m) =>
InteractionId -> m MetaId
lookupInteractionId InteractionId
ii
  Maybe Range -> (Range -> TCMT IO ()) -> TCMT IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe Range
mr ((Range -> TCMT IO ()) -> TCMT IO ())
-> (Range -> TCMT IO ()) -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ MetaId -> Range -> TCMT IO ()
forall (m :: * -> *). MonadMetaSolver m => MetaId -> Range -> m ()
updateMetaVarRange MetaId
mi
  ArgName -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> TCMT IO Doc -> m ()
reportSDoc ArgName
"interaction.give" Int
10 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"giving expression" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> Expr -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Expr
e
  ArgName -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> TCMT IO Doc -> m ()
reportSDoc ArgName
"interaction.give" Int
50 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ ArgName -> TCMT IO Doc
forall (m :: * -> *). Applicative m => ArgName -> m Doc
TP.text (ArgName -> TCMT IO Doc) -> ArgName -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Expr -> ArgName
forall a. Show a => a -> ArgName
show (Expr -> ArgName) -> Expr -> ArgName
forall a b. (a -> b) -> a -> b
$ Expr -> Expr
forall a. ExprLike a => a -> a
deepUnscope Expr
e
  -- Try to give mi := e
  Term
v <- InteractionId -> TCM Term -> TCM Term
forall (m :: * -> *) a.
(MonadFail m, ReadTCState m, MonadError TCErr m, MonadTCEnv m,
 MonadTrace m) =>
InteractionId -> m a -> m a
withInteractionId InteractionId
ii (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$ do
     MetaId -> RunMetaOccursCheck -> TCMT IO ()
forall (m :: * -> *).
MonadMetaSolver m =>
MetaId -> RunMetaOccursCheck -> m ()
setMetaOccursCheck MetaId
mi RunMetaOccursCheck
DontRunMetaOccursCheck -- #589, #2710: Allow giving recursive solutions.
     Lens' Bool TCEnv -> (Bool -> Bool) -> TCM Term -> TCM Term
forall (m :: * -> *) a b.
MonadTCEnv m =>
Lens' a TCEnv -> (a -> a) -> m b -> m b
locallyTC Lens' Bool TCEnv
eCurrentlyElaborating (Bool -> Bool -> Bool
forall a b. a -> b -> a
const Bool
True) (TCM Term -> TCM Term) -> TCM Term -> TCM Term
forall a b. (a -> b) -> a -> b
$
       UseForce -> Maybe InteractionId -> MetaId -> Expr -> TCM Term
giveExpr UseForce
force (InteractionId -> Maybe InteractionId
forall a. a -> Maybe a
Just InteractionId
ii) MetaId
mi Expr
e
    TCM Term -> (TCErr -> TCM Term) -> TCM Term
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError` \ case
      -- Turn PatternErr into proper error:
      PatternErr{} -> TypeError -> TCM Term
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCM Term) -> (Doc -> TypeError) -> Doc -> TCM Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc -> TypeError
GenericDocError (Doc -> TCM Term) -> TCMT IO Doc -> TCM Term
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< do
        InteractionId -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *) a.
(MonadFail m, ReadTCState m, MonadError TCErr m, MonadTCEnv m,
 MonadTrace m) =>
InteractionId -> m a -> m a
withInteractionId InteractionId
ii (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"Failed to give" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> Expr -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Expr
e
      TCErr
err -> TCErr -> TCM Term
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError TCErr
err
  Term
nv <- Rewrite -> Term -> TCM Term
forall t.
(Reduce t, Simplify t, Instantiate t, Normalise t) =>
Rewrite -> t -> TCM t
normalForm Rewrite
norm Term
v
  Lens' Bool TCEnv -> (Bool -> Bool) -> TCM Expr -> TCM Expr
forall (m :: * -> *) a b.
MonadTCEnv m =>
Lens' a TCEnv -> (a -> a) -> m b -> m b
locallyTC Lens' Bool TCEnv
ePrintMetasBare (Bool -> Bool -> Bool
forall a b. a -> b -> a
const Bool
True) (TCM Expr -> TCM Expr) -> TCM Expr -> TCM Expr
forall a b. (a -> b) -> a -> b
$ Term -> TCMT IO (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Term
nv

-- | Try to refine hole by expression @e@.
--
--   This amounts to successively try to give @e@, @e ?@, @e ? ?@, ...
--   Returns the successfully given expression.
refine
  :: UseForce       -- ^ Skip safety checks when giving?
  -> InteractionId  -- ^ Hole.
  -> Maybe Range
  -> Expr           -- ^ The expression to refine the hole with.
  -> TCM Expr       -- ^ The successfully given expression.
refine :: UseForce -> InteractionId -> Maybe Range -> Expr -> TCM Expr
refine UseForce
force InteractionId
ii Maybe Range
mr Expr
e = do
  MetaId
mi <- InteractionId -> TCMT IO MetaId
forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadError TCErr m, MonadTCEnv m) =>
InteractionId -> m MetaId
lookupInteractionId InteractionId
ii
  MetaVariable
mv <- MetaId -> TCMT IO MetaVariable
forall (m :: * -> *).
(MonadFail m, ReadTCState m) =>
MetaId -> m MetaVariable
lookupMeta MetaId
mi
  let range :: Range
range = Range -> Maybe Range -> Range
forall a. a -> Maybe a -> a
fromMaybe (MetaVariable -> Range
forall a. HasRange a => a -> Range
getRange MetaVariable
mv) Maybe Range
mr
      scope :: ScopeInfo
scope = MetaVariable -> ScopeInfo
M.getMetaScope MetaVariable
mv
  ArgName -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> TCMT IO Doc -> m ()
reportSDoc ArgName
"interaction.refine" Int
10 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$
    TCMT IO Doc
"refining with expression" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> Expr -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Expr
e
  ArgName -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> TCMT IO Doc -> m ()
reportSDoc ArgName
"interaction.refine" Int
50 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$
    ArgName -> TCMT IO Doc
forall (m :: * -> *). Applicative m => ArgName -> m Doc
TP.text (ArgName -> TCMT IO Doc) -> ArgName -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Expr -> ArgName
forall a. Show a => a -> ArgName
show (Expr -> ArgName) -> Expr -> ArgName
forall a b. (a -> b) -> a -> b
$ Expr -> Expr
forall a. ExprLike a => a -> a
deepUnscope Expr
e
  -- We try to append up to 10 meta variables
  Int -> Range -> ScopeInfo -> Expr -> TCM Expr
tryRefine Int
10 Range
range ScopeInfo
scope Expr
e
  where
    tryRefine :: Int -> Range -> ScopeInfo -> Expr -> TCM Expr
    tryRefine :: Int -> Range -> ScopeInfo -> Expr -> TCM Expr
tryRefine Int
nrOfMetas Range
r ScopeInfo
scope = Int -> Maybe TCErr -> Expr -> TCM Expr
try Int
nrOfMetas Maybe TCErr
forall a. Maybe a
Nothing
      where
        try :: Int -> Maybe TCErr -> Expr -> TCM Expr
        try :: Int -> Maybe TCErr -> Expr -> TCM Expr
try Int
0 Maybe TCErr
err Expr
e = TCErr -> TCM Expr
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError (TCErr -> TCM Expr) -> (ArgName -> TCErr) -> ArgName -> TCM Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArgName -> TCErr
stringTCErr (ArgName -> TCM Expr) -> ArgName -> TCM Expr
forall a b. (a -> b) -> a -> b
$ case Maybe TCErr
err of
           Just (TypeError CallStack
_ TCState
_ Closure TypeError
cl) | UnequalTerms Comparison
_ I.Pi{} Term
_ CompareAs
_ <- Closure TypeError -> TypeError
forall a. Closure a -> a
clValue Closure TypeError
cl ->
             ArgName
"Cannot refine functions with 10 or more arguments"
           Maybe TCErr
_ ->
             ArgName
"Cannot refine"
        try Int
n Maybe TCErr
_ Expr
e = UseForce -> InteractionId -> Maybe Range -> Expr -> TCM Expr
give UseForce
force InteractionId
ii (Range -> Maybe Range
forall a. a -> Maybe a
Just Range
r) Expr
e TCM Expr -> (TCErr -> TCM Expr) -> TCM Expr
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError` \TCErr
err -> Int -> Maybe TCErr -> Expr -> TCM Expr
try (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (TCErr -> Maybe TCErr
forall a. a -> Maybe a
Just TCErr
err) (Expr -> TCM Expr) -> TCM Expr -> TCM Expr
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Expr -> TCM Expr
appMeta Expr
e

        -- Apply A.Expr to a new meta
        appMeta :: Expr -> TCM Expr
        appMeta :: Expr -> TCM Expr
appMeta Expr
e = do
          let rng :: Range
rng = Range -> Range
rightMargin Range
r -- Andreas, 2013-05-01 conflate range to its right margin to ensure that appended metas are last in numbering.  This fixes issue 841.
          -- Make new interaction point
          InteractionId
ii <- Bool -> Range -> Maybe Int -> TCMT IO InteractionId
forall (m :: * -> *).
MonadInteractionPoints m =>
Bool -> Range -> Maybe Int -> m InteractionId
registerInteractionPoint Bool
False Range
rng Maybe Int
forall a. Maybe a
Nothing
          let info :: MetaInfo
info = Info.MetaInfo
                { metaRange :: Range
Info.metaRange = Range
rng
                , metaScope :: ScopeInfo
Info.metaScope = Lens' [Precedence] ScopeInfo -> LensSet [Precedence] ScopeInfo
forall i o. Lens' i o -> LensSet i o
set Lens' [Precedence] ScopeInfo
scopePrecedence [Precedence
argumentCtx_] ScopeInfo
scope
                    -- Ulf, 2017-09-07: The `argumentCtx_` above is causing #737.
                    -- If we're building an operator application the precedence
                    -- should be something else.
                , metaNumber :: Maybe MetaId
metaNumber = Maybe MetaId
forall a. Maybe a
Nothing -- in order to print just as ?, not ?n
                , metaNameSuggestion :: ArgName
metaNameSuggestion = ArgName
""
                }
              metaVar :: Expr
metaVar = MetaInfo -> InteractionId -> Expr
QuestionMark MetaInfo
info InteractionId
ii

              count :: Name -> a -> a
count Name
x a
e = Sum a -> a
forall a. Sum a -> a
getSum (Sum a -> a) -> Sum a -> a
forall a b. (a -> b) -> a -> b
$ (Expr -> Sum a) -> a -> Sum a
forall a m. ExprLike a => FoldExprFn m a
foldExpr Expr -> Sum a
isX a
e
                where isX :: Expr -> Sum a
isX (A.Var Name
y) | Name
x Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
y = a -> Sum a
forall a. a -> Sum a
Sum a
1
                      isX Expr
_                  = Sum a
forall a. Monoid a => a
mempty

              lamView :: Expr -> Maybe (Binder, Expr)
lamView (A.Lam ExprInfo
_ (DomainFree TacticAttr
_ NamedArg Binder
x) Expr
e) = (Binder, Expr) -> Maybe (Binder, Expr)
forall a. a -> Maybe a
Just (NamedArg Binder -> Binder
forall a. NamedArg a -> a
namedArg NamedArg Binder
x, Expr
e)
              lamView (A.Lam ExprInfo
i (DomainFull (TBind Range
r TacticAttr
t (NamedArg Binder
x :| [NamedArg Binder]
xs) Expr
a)) Expr
e) =
                [NamedArg Binder]
-> Maybe (Binder, Expr)
-> (NonEmpty (NamedArg Binder) -> Maybe (Binder, Expr))
-> Maybe (Binder, Expr)
forall a b. [a] -> b -> (List1 a -> b) -> b
List1.ifNull [NamedArg Binder]
xs {-then-} ((Binder, Expr) -> Maybe (Binder, Expr)
forall a. a -> Maybe a
Just (NamedArg Binder -> Binder
forall a. NamedArg a -> a
namedArg NamedArg Binder
x, Expr
e)) {-else-} ((NonEmpty (NamedArg Binder) -> Maybe (Binder, Expr))
 -> Maybe (Binder, Expr))
-> (NonEmpty (NamedArg Binder) -> Maybe (Binder, Expr))
-> Maybe (Binder, Expr)
forall a b. (a -> b) -> a -> b
$ \ NonEmpty (NamedArg Binder)
xs ->
                  (Binder, Expr) -> Maybe (Binder, Expr)
forall a. a -> Maybe a
Just (NamedArg Binder -> Binder
forall a. NamedArg a -> a
namedArg NamedArg Binder
x, ExprInfo -> LamBinding -> Expr -> Expr
A.Lam ExprInfo
i (TypedBinding -> LamBinding
DomainFull (TypedBinding -> LamBinding) -> TypedBinding -> LamBinding
forall a b. (a -> b) -> a -> b
$ Range
-> TacticAttr -> NonEmpty (NamedArg Binder) -> Expr -> TypedBinding
TBind Range
r TacticAttr
t NonEmpty (NamedArg Binder)
xs Expr
a) Expr
e)
              lamView Expr
_ = Maybe (Binder, Expr)
forall a. Maybe a
Nothing

              -- reduce beta-redexes where the argument is used at most once
              smartApp :: AppInfo -> Expr -> NamedArg Expr -> Expr
smartApp AppInfo
i Expr
e NamedArg Expr
arg =
                case ((Binder, Expr) -> (BindName, Expr))
-> Maybe (Binder, Expr) -> Maybe (BindName, Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Binder -> BindName) -> (Binder, Expr) -> (BindName, Expr)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first Binder -> BindName
forall a. Binder' a -> a
A.binderName) (Expr -> Maybe (Binder, Expr)
lamView (Expr -> Maybe (Binder, Expr)) -> Expr -> Maybe (Binder, Expr)
forall a b. (a -> b) -> a -> b
$ Expr -> Expr
unScope Expr
e) of
                  Just (A.BindName{unBind :: BindName -> Name
unBind = Name
x}, Expr
e) | Name -> Expr -> Integer
forall {a} {a}. (Num a, ExprLike a) => Name -> a -> a
count Name
x Expr
e Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< Integer
2 -> (Expr -> Expr) -> Expr -> Expr
forall a. ExprLike a => (Expr -> Expr) -> a -> a
mapExpr Expr -> Expr
subX Expr
e
                    where subX :: Expr -> Expr
subX (A.Var Name
y) | Name
x Name -> Name -> Bool
forall a. Eq a => a -> a -> Bool
== Name
y = NamedArg Expr -> Expr
forall a. NamedArg a -> a
namedArg NamedArg Expr
arg
                          subX Expr
e = Expr
e
                  Maybe (BindName, Expr)
_ -> AppInfo -> Expr -> NamedArg Expr -> Expr
App AppInfo
i Expr
e NamedArg Expr
arg
          Expr -> TCM Expr
forall (m :: * -> *) a. Monad m => a -> m a
return (Expr -> TCM Expr) -> Expr -> TCM Expr
forall a b. (a -> b) -> a -> b
$ AppInfo -> Expr -> NamedArg Expr -> Expr
smartApp (Range -> AppInfo
defaultAppInfo Range
r) Expr
e (NamedArg Expr -> Expr) -> NamedArg Expr -> Expr
forall a b. (a -> b) -> a -> b
$ Expr -> NamedArg Expr
forall a. a -> NamedArg a
defaultNamedArg Expr
metaVar

-- Andreas, 2017-12-16:
-- Ulf, your attempt to fix #737 introduced regression #2873.
-- Going through concrete syntax does some arbitrary disambiguation
-- of constructors, which subsequently makes refine fail.
-- I am not convinced of the printing-parsing shortcut to address problems.
-- (Unless you prove the roundtrip property.)
--
--           rescopeExpr scope $ smartApp (defaultAppInfo r) e $ defaultNamedArg metaVar
-- -- | Turn an abstract expression into concrete syntax and then back into
-- --   abstract. This ensures that context precedences are set correctly for
-- --   abstract expressions built by hand. Used by refine above.
-- rescopeExpr :: ScopeInfo -> Expr -> TCM Expr
-- rescopeExpr scope = withScope_ scope . (concreteToAbstract_ <=< runAbsToCon . preserveInteractionIds . toConcrete)

{-| Evaluate the given expression in the current environment -}
evalInCurrent :: ComputeMode -> Expr -> TCM Expr
evalInCurrent :: ComputeMode -> Expr -> TCM Expr
evalInCurrent ComputeMode
cmode Expr
e = do
  (Term
v, Type
_t) <- Expr -> TCM (Term, Type)
inferExpr Expr
e
  Term -> TCM Expr
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (Term -> TCM Expr) -> TCM Term -> TCM Expr
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Term -> TCM Term
compute Term
v
  where compute :: Term -> TCM Term
compute | ComputeMode
cmode ComputeMode -> ComputeMode -> Bool
forall a. Eq a => a -> a -> Bool
== ComputeMode
HeadCompute = Term -> TCM Term
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce
                | Bool
otherwise            = Term -> TCM Term
forall a (m :: * -> *). (Normalise a, MonadReduce m) => a -> m a
normalise


evalInMeta :: InteractionId -> ComputeMode -> Expr -> TCM Expr
evalInMeta :: InteractionId -> ComputeMode -> Expr -> TCM Expr
evalInMeta InteractionId
ii ComputeMode
cmode Expr
e =
   do   MetaId
m <- InteractionId -> TCMT IO MetaId
forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadError TCErr m, MonadTCEnv m) =>
InteractionId -> m MetaId
lookupInteractionId InteractionId
ii
        Closure Range
mi <- MetaVariable -> Closure Range
getMetaInfo (MetaVariable -> Closure Range)
-> TCMT IO MetaVariable -> TCMT IO (Closure Range)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MetaId -> TCMT IO MetaVariable
forall (m :: * -> *).
(MonadFail m, ReadTCState m) =>
MetaId -> m MetaVariable
lookupMeta MetaId
m
        Closure Range -> TCM Expr -> TCM Expr
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadTrace m) =>
Closure Range -> m a -> m a
withMetaInfo Closure Range
mi (TCM Expr -> TCM Expr) -> TCM Expr -> TCM Expr
forall a b. (a -> b) -> a -> b
$
            ComputeMode -> Expr -> TCM Expr
evalInCurrent ComputeMode
cmode Expr
e

-- | Modifier for interactive commands,
--   specifying the amount of normalization in the output.
--
normalForm :: (Reduce t, Simplify t, Instantiate t, Normalise t) => Rewrite -> t -> TCM t
normalForm :: forall t.
(Reduce t, Simplify t, Instantiate t, Normalise t) =>
Rewrite -> t -> TCM t
normalForm = \case
  Rewrite
AsIs         -> t -> TCM t
forall a (m :: * -> *). (Instantiate a, MonadReduce m) => a -> m a
instantiate   -- #4975: reify will also instantiate by for goal-type-and-context-and-check
  Rewrite
Instantiated -> t -> TCM t
forall a (m :: * -> *). (Instantiate a, MonadReduce m) => a -> m a
instantiate   --        we get a top-level fresh meta which has disappeared from state by the
  Rewrite
HeadNormal   -> t -> TCM t
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce        --        time we get to reification. Hence instantiate here.
  Rewrite
Simplified   -> t -> TCM t
forall a (m :: * -> *). (Simplify a, MonadReduce m) => a -> m a
simplify
  Rewrite
Normalised   -> t -> TCM t
forall a (m :: * -> *). (Normalise a, MonadReduce m) => a -> m a
normalise

-- | Modifier for the interactive computation command,
--   specifying the mode of computation and result display.
--
computeIgnoreAbstract :: ComputeMode -> Bool
computeIgnoreAbstract :: ComputeMode -> Bool
computeIgnoreAbstract ComputeMode
DefaultCompute  = Bool
False
computeIgnoreAbstract ComputeMode
HeadCompute     = Bool
False
computeIgnoreAbstract ComputeMode
IgnoreAbstract  = Bool
True
computeIgnoreAbstract ComputeMode
UseShowInstance = Bool
True
  -- UseShowInstance requires the result to be a string literal so respecting
  -- abstract can only ever break things.

computeWrapInput :: ComputeMode -> String -> String
computeWrapInput :: ComputeMode -> ArgName -> ArgName
computeWrapInput ComputeMode
UseShowInstance ArgName
s = ArgName
"show (" ArgName -> ArgName -> ArgName
forall a. [a] -> [a] -> [a]
++ ArgName
s ArgName -> ArgName -> ArgName
forall a. [a] -> [a] -> [a]
++ ArgName
")"
computeWrapInput ComputeMode
_               ArgName
s = ArgName
s

showComputed :: ComputeMode -> Expr -> TCM Doc
showComputed :: ComputeMode -> Expr -> TCMT IO Doc
showComputed ComputeMode
UseShowInstance Expr
e =
  case Expr
e of
    A.Lit ExprInfo
_ (LitString Text
s) -> Doc -> TCMT IO Doc
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ArgName -> Doc
text (ArgName -> Doc) -> ArgName -> Doc
forall a b. (a -> b) -> a -> b
$ Text -> ArgName
T.unpack Text
s)
    Expr
_                     -> (Doc
"Not a string:" Doc -> Doc -> Doc
$$) (Doc -> Doc) -> TCMT IO Doc -> TCMT IO Doc
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Expr -> TCMT IO Doc
forall a (m :: * -> *).
(ToConcrete a, Pretty (ConOfAbs a), MonadAbsToCon m) =>
a -> m Doc
prettyATop Expr
e
showComputed ComputeMode
_ Expr
e = Expr -> TCMT IO Doc
forall a (m :: * -> *).
(ToConcrete a, Pretty (ConOfAbs a), MonadAbsToCon m) =>
a -> m Doc
prettyATop Expr
e

-- | Modifier for interactive commands,
--   specifying whether safety checks should be ignored.
outputFormId :: OutputForm a b -> b
outputFormId :: forall a b. OutputForm a b -> b
outputFormId (OutputForm Range
_ [ProblemId]
_ Blocker
_ OutputConstraint a b
o) = OutputConstraint a b -> b
forall {a} {b}. OutputConstraint a b -> b
out OutputConstraint a b
o
  where
    out :: OutputConstraint a b -> b
out = \case
      OfType b
i a
_                 -> b
i
      CmpInType Comparison
_ a
_ b
i b
_          -> b
i
      CmpElim [Polarity]
_ a
_ (b
i:[b]
_) [b]
_        -> b
i
      CmpElim [Polarity]
_ a
_ [] [b]
_           -> b
forall a. HasCallStack => a
__IMPOSSIBLE__
      JustType b
i                 -> b
i
      CmpLevels Comparison
_ b
i b
_            -> b
i
      CmpTypes Comparison
_ b
i b
_             -> b
i
      CmpTeles Comparison
_ b
i b
_             -> b
i
      JustSort b
i                 -> b
i
      CmpSorts Comparison
_ b
i b
_             -> b
i
      Assign b
i a
_                 -> b
i
      TypedAssign b
i a
_ a
_          -> b
i
      PostponedCheckArgs b
i [a]
_ a
_ a
_ -> b
i
      IsEmptyType a
_              -> b
forall a. HasCallStack => a
__IMPOSSIBLE__   -- Should never be used on IsEmpty constraints
      SizeLtSat{}                -> b
forall a. HasCallStack => a
__IMPOSSIBLE__
      FindInstanceOF b
_ a
_ [(a, a, a)]
_        -> b
forall a. HasCallStack => a
__IMPOSSIBLE__
      PTSInstance b
i b
_            -> b
i
      PostponedCheckFunDef{}     -> b
forall a. HasCallStack => a
__IMPOSSIBLE__
      CheckLock b
i b
_              -> b
i
      UsableAtMod Modality
_ b
i            -> b
i

instance Reify ProblemConstraint where
  type ReifiesTo ProblemConstraint = Closure (OutputForm Expr Expr)
  reify :: forall (m :: * -> *).
MonadReify m =>
ProblemConstraint -> m (ReifiesTo ProblemConstraint)
reify (PConstr Set ProblemId
pids Blocker
unblock Closure Constraint
cl) = Closure Constraint
-> (Constraint -> m (OutputForm Expr Expr))
-> m (Closure (OutputForm Expr Expr))
forall (m :: * -> *) a b.
(MonadTCEnv m, ReadTCState m) =>
Closure a -> (a -> m b) -> m (Closure b)
withClosure Closure Constraint
cl ((Constraint -> m (OutputForm Expr Expr))
 -> m (Closure (OutputForm Expr Expr)))
-> (Constraint -> m (OutputForm Expr Expr))
-> m (Closure (OutputForm Expr Expr))
forall a b. (a -> b) -> a -> b
$ \ Constraint
c ->
    Range
-> [ProblemId]
-> Blocker
-> OutputConstraint Expr Expr
-> OutputForm Expr Expr
forall a b.
Range
-> [ProblemId] -> Blocker -> OutputConstraint a b -> OutputForm a b
OutputForm (Constraint -> Range
forall a. HasRange a => a -> Range
getRange Constraint
c) (Set ProblemId -> [ProblemId]
forall a. Set a -> [a]
Set.toList Set ProblemId
pids) Blocker
unblock (OutputConstraint Expr Expr -> OutputForm Expr Expr)
-> m (OutputConstraint Expr Expr) -> m (OutputForm Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Constraint -> m (ReifiesTo Constraint)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Constraint
c

reifyElimToExpr :: MonadReify m => I.Elim -> m Expr
reifyElimToExpr :: forall (m :: * -> *). MonadReify m => Elim -> m Expr
reifyElimToExpr = \case
    I.IApply Term
_ Term
_ Term
v -> Text -> Arg Expr -> Expr
appl Text
"iapply" (Arg Expr -> Expr) -> m (Arg Expr) -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Arg Term -> m (ReifiesTo (Arg Term))
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (Term -> Arg Term
forall a. a -> Arg a
defaultArg (Term -> Arg Term) -> Term -> Arg Term
forall a b. (a -> b) -> a -> b
$ Term
v) -- TODO Andrea: endpoints?
    I.Apply Arg Term
v -> Text -> Arg Expr -> Expr
appl Text
"apply" (Arg Expr -> Expr) -> m (Arg Expr) -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Arg Term -> m (ReifiesTo (Arg Term))
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Arg Term
v
    I.Proj ProjOrigin
_o QName
f -> Text -> Arg Expr -> Expr
appl Text
"proj" (Arg Expr -> Expr) -> m (Arg Expr) -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Arg Term -> m (ReifiesTo (Arg Term))
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify ((Term -> Arg Term
forall a. a -> Arg a
defaultArg (Term -> Arg Term) -> Term -> Arg Term
forall a b. (a -> b) -> a -> b
$ QName -> Elims -> Term
I.Def QName
f []) :: Arg Term)
  where
    appl :: Text -> Arg Expr -> Expr
    appl :: Text -> Arg Expr -> Expr
appl Text
s Arg Expr
v = AppInfo -> Expr -> NamedArg Expr -> Expr
A.App AppInfo
defaultAppInfo_ (ExprInfo -> Literal -> Expr
A.Lit ExprInfo
forall a. Null a => a
empty (Text -> Literal
LitString Text
s)) (NamedArg Expr -> Expr) -> NamedArg Expr -> Expr
forall a b. (a -> b) -> a -> b
$ (Expr -> Named_ Expr) -> Arg Expr -> NamedArg Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Expr -> Named_ Expr
forall a name. a -> Named name a
unnamed Arg Expr
v

instance Reify Constraint where
    type ReifiesTo Constraint = OutputConstraint Expr Expr

    reify :: forall (m :: * -> *).
MonadReify m =>
Constraint -> m (ReifiesTo Constraint)
reify (ValueCmp Comparison
cmp (AsTermsOf Type
t) Term
u Term
v) = Comparison -> Expr -> Expr -> Expr -> OutputConstraint Expr Expr
forall a b. Comparison -> a -> b -> b -> OutputConstraint a b
CmpInType Comparison
cmp (Expr -> Expr -> Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (Expr -> Expr -> OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type -> m (ReifiesTo Type)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Type
t m (Expr -> Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (Expr -> OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Term
u m (Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Term
v
    reify (ValueCmp Comparison
cmp CompareAs
AsSizes Term
u Term
v) = Comparison -> Expr -> Expr -> Expr -> OutputConstraint Expr Expr
forall a b. Comparison -> a -> b -> b -> OutputConstraint a b
CmpInType Comparison
cmp (Expr -> Expr -> Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (Expr -> Expr -> OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Type -> m Expr
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (Type -> m Expr) -> m Type -> m Expr
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< m Type
forall (m :: * -> *).
(HasBuiltins m, MonadTCEnv m, ReadTCState m) =>
m Type
sizeType) m (Expr -> Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (Expr -> OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Term
u m (Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Term
v
    reify (ValueCmp Comparison
cmp CompareAs
AsTypes Term
u Term
v) = Comparison -> Expr -> Expr -> OutputConstraint Expr Expr
forall a b. Comparison -> b -> b -> OutputConstraint a b
CmpTypes Comparison
cmp (Expr -> Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (Expr -> OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Term
u m (Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Term
v
    reify (ValueCmpOnFace Comparison
cmp Term
p Type
t Term
u Term
v) = Comparison -> Expr -> Expr -> Expr -> OutputConstraint Expr Expr
forall a b. Comparison -> a -> b -> b -> OutputConstraint a b
CmpInType Comparison
cmp (Expr -> Expr -> Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (Expr -> Expr -> OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Type -> m Expr
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (Type -> m Expr) -> m Type -> m Expr
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< m Type
ty) m (Expr -> Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (Expr -> OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (Term -> Term
lam_o Term
u) m (Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (Term -> Term
lam_o Term
v)
      where
        lam_o :: Term -> Term
lam_o = ArgInfo -> Abs Term -> Term
I.Lam (Relevance -> ArgInfo -> ArgInfo
forall a. LensRelevance a => Relevance -> a -> a
setRelevance Relevance
Irrelevant ArgInfo
defaultArgInfo) (Abs Term -> Term) -> (Term -> Abs Term) -> Term -> Term
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArgName -> Term -> Abs Term
forall a. ArgName -> a -> Abs a
NoAbs ArgName
"_"
        ty :: m Type
ty = Names -> NamesT m Type -> m Type
forall (m :: * -> *) a. Names -> NamesT m a -> m a
runNamesT [] (NamesT m Type -> m Type) -> NamesT m Type -> m Type
forall a b. (a -> b) -> a -> b
$ do
          NamesT m Term
p <- Term -> NamesT m (NamesT m Term)
forall (m :: * -> *) a.
(MonadFail m, Subst a) =>
a -> NamesT m (NamesT m a)
open Term
p
          NamesT m Type
t <- Type -> NamesT m (NamesT m Type)
forall (m :: * -> *) a.
(MonadFail m, Subst a) =>
a -> NamesT m (NamesT m a)
open Type
t
          ArgName
-> NamesT m Term
-> (NamesT m Term -> NamesT m Type)
-> NamesT m Type
forall (m :: * -> *).
(MonadAddContext m, HasBuiltins m, MonadDebug m) =>
ArgName
-> NamesT m Term
-> (NamesT m Term -> NamesT m Type)
-> NamesT m Type
pPi' ArgName
"o" NamesT m Term
p (\ NamesT m Term
o -> NamesT m Type
t)
    reify (ElimCmp [Polarity]
cmp [IsForced]
_ Type
t Term
v Elims
es1 Elims
es2) =
      [Polarity]
-> Expr -> [Expr] -> [Expr] -> OutputConstraint Expr Expr
forall a b. [Polarity] -> a -> [b] -> [b] -> OutputConstraint a b
CmpElim [Polarity]
cmp (Expr -> [Expr] -> [Expr] -> OutputConstraint Expr Expr)
-> m Expr -> m ([Expr] -> [Expr] -> OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type -> m (ReifiesTo Type)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Type
t m ([Expr] -> [Expr] -> OutputConstraint Expr Expr)
-> m [Expr] -> m ([Expr] -> OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Elim -> m Expr) -> Elims -> m [Expr]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Elim -> m Expr
forall (m :: * -> *). MonadReify m => Elim -> m Expr
reifyElimToExpr Elims
es1
                              m ([Expr] -> OutputConstraint Expr Expr)
-> m [Expr] -> m (OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Elim -> m Expr) -> Elims -> m [Expr]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Elim -> m Expr
forall (m :: * -> *). MonadReify m => Elim -> m Expr
reifyElimToExpr Elims
es2
    reify (LevelCmp Comparison
cmp Level
t Level
t')    = Comparison -> Expr -> Expr -> OutputConstraint Expr Expr
forall a b. Comparison -> b -> b -> OutputConstraint a b
CmpLevels Comparison
cmp (Expr -> Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (Expr -> OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Level -> m (ReifiesTo Level)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Level
t m (Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Level -> m (ReifiesTo Level)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Level
t'
    reify (SortCmp Comparison
cmp Sort
s Sort
s')     = Comparison -> Expr -> Expr -> OutputConstraint Expr Expr
forall a b. Comparison -> b -> b -> OutputConstraint a b
CmpSorts Comparison
cmp (Expr -> Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (Expr -> OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sort -> m (ReifiesTo Sort)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Sort
s m (Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Sort -> m (ReifiesTo Sort)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Sort
s'
    reify (UnquoteTactic Term
tac Term
_ Type
goal) = do
        Expr
tac <- AppInfo -> Expr -> NamedArg Expr -> Expr
A.App AppInfo
defaultAppInfo_ (ExprInfo -> Expr
A.Unquote ExprInfo
exprNoRange) (NamedArg Expr -> Expr) -> (Expr -> NamedArg Expr) -> Expr -> Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expr -> NamedArg Expr
forall a. a -> NamedArg a
defaultNamedArg (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Term
tac
        Expr -> Expr -> OutputConstraint Expr Expr
forall a b. b -> a -> OutputConstraint a b
OfType Expr
tac (Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type -> m (ReifiesTo Type)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Type
goal
    reify (UnBlock MetaId
m) = do
        MetaInstantiation
mi <- MetaVariable -> MetaInstantiation
mvInstantiation (MetaVariable -> MetaInstantiation)
-> m MetaVariable -> m MetaInstantiation
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MetaId -> m MetaVariable
forall (m :: * -> *).
(MonadFail m, ReadTCState m) =>
MetaId -> m MetaVariable
lookupMeta MetaId
m
        Expr
m' <- Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (MetaId -> Elims -> Term
MetaV MetaId
m [])
        case MetaInstantiation
mi of
          BlockedConst Term
t -> do
            Expr
e  <- Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Term
t
            OutputConstraint Expr Expr -> m (OutputConstraint Expr Expr)
forall (m :: * -> *) a. Monad m => a -> m a
return (OutputConstraint Expr Expr -> m (OutputConstraint Expr Expr))
-> OutputConstraint Expr Expr -> m (OutputConstraint Expr Expr)
forall a b. (a -> b) -> a -> b
$ Expr -> Expr -> OutputConstraint Expr Expr
forall a b. b -> a -> OutputConstraint a b
Assign Expr
m' Expr
e
          PostponedTypeCheckingProblem Closure TypeCheckingProblem
cl -> Closure TypeCheckingProblem
-> (TypeCheckingProblem -> m (OutputConstraint Expr Expr))
-> m (OutputConstraint Expr Expr)
forall (m :: * -> *) a c b.
(MonadTCEnv m, ReadTCState m, LensClosure a c) =>
c -> (a -> m b) -> m b
enterClosure Closure TypeCheckingProblem
cl ((TypeCheckingProblem -> m (OutputConstraint Expr Expr))
 -> m (OutputConstraint Expr Expr))
-> (TypeCheckingProblem -> m (OutputConstraint Expr Expr))
-> m (OutputConstraint Expr Expr)
forall a b. (a -> b) -> a -> b
$ \case
            CheckExpr Comparison
cmp Expr
e Type
a -> do
                Expr
a  <- Type -> m (ReifiesTo Type)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Type
a
                OutputConstraint Expr Expr -> m (OutputConstraint Expr Expr)
forall (m :: * -> *) a. Monad m => a -> m a
return (OutputConstraint Expr Expr -> m (OutputConstraint Expr Expr))
-> OutputConstraint Expr Expr -> m (OutputConstraint Expr Expr)
forall a b. (a -> b) -> a -> b
$ Expr -> Expr -> Expr -> OutputConstraint Expr Expr
forall a b. b -> a -> a -> OutputConstraint a b
TypedAssign Expr
m' Expr
e Expr
a
            CheckLambda Comparison
cmp (Arg ArgInfo
ai (List1 (WithHiding Name)
xs, Maybe Type
mt)) Expr
body Type
target -> do
              Expr
domType <- m Expr -> (Type -> m Expr) -> Maybe Type -> m Expr
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Expr -> m Expr
forall (m :: * -> *) a. Monad m => a -> m a
return Expr
forall a. Underscore a => a
underscore) Type -> m Expr
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Maybe Type
mt
              Expr
target  <- Type -> m (ReifiesTo Type)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Type
target
              let mkN :: WithHiding Name -> NamedArg Binder
mkN (WithHiding Hiding
h Name
x) = Hiding -> NamedArg Binder -> NamedArg Binder
forall a. LensHiding a => Hiding -> a -> a
setHiding Hiding
h (NamedArg Binder -> NamedArg Binder)
-> NamedArg Binder -> NamedArg Binder
forall a b. (a -> b) -> a -> b
$ Binder -> NamedArg Binder
forall a. a -> NamedArg a
defaultNamedArg (Binder -> NamedArg Binder) -> Binder -> NamedArg Binder
forall a b. (a -> b) -> a -> b
$ Name -> Binder
A.mkBinder_ Name
x
                  bs :: TypedBinding
bs = Range -> NonEmpty (NamedArg Binder) -> Expr -> TypedBinding
mkTBind Range
forall a. Range' a
noRange ((WithHiding Name -> NamedArg Binder)
-> List1 (WithHiding Name) -> NonEmpty (NamedArg Binder)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap WithHiding Name -> NamedArg Binder
mkN List1 (WithHiding Name)
xs) Expr
domType
                  e :: Expr
e  = ExprInfo -> LamBinding -> Expr -> Expr
A.Lam ExprInfo
Info.exprNoRange (TypedBinding -> LamBinding
DomainFull TypedBinding
bs) Expr
body
              OutputConstraint Expr Expr -> m (OutputConstraint Expr Expr)
forall (m :: * -> *) a. Monad m => a -> m a
return (OutputConstraint Expr Expr -> m (OutputConstraint Expr Expr))
-> OutputConstraint Expr Expr -> m (OutputConstraint Expr Expr)
forall a b. (a -> b) -> a -> b
$ Expr -> Expr -> Expr -> OutputConstraint Expr Expr
forall a b. b -> a -> a -> OutputConstraint a b
TypedAssign Expr
m' Expr
e Expr
target
            CheckArgs Comparison
_ ExpandHidden
_ Range
_ [NamedArg Expr]
args Type
t0 Type
t1 ArgsCheckState CheckedTarget -> TCM Term
_ -> do
              Expr
t0 <- Type -> m (ReifiesTo Type)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Type
t0
              Expr
t1 <- Type -> m (ReifiesTo Type)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Type
t1
              OutputConstraint Expr Expr -> m (OutputConstraint Expr Expr)
forall (m :: * -> *) a. Monad m => a -> m a
return (OutputConstraint Expr Expr -> m (OutputConstraint Expr Expr))
-> OutputConstraint Expr Expr -> m (OutputConstraint Expr Expr)
forall a b. (a -> b) -> a -> b
$ Expr -> [Expr] -> Expr -> Expr -> OutputConstraint Expr Expr
forall a b. b -> [a] -> a -> a -> OutputConstraint a b
PostponedCheckArgs Expr
m' ((NamedArg Expr -> Expr) -> [NamedArg Expr] -> [Expr]
forall a b. (a -> b) -> [a] -> [b]
map (Named_ Expr -> Expr
forall name a. Named name a -> a
namedThing (Named_ Expr -> Expr)
-> (NamedArg Expr -> Named_ Expr) -> NamedArg Expr -> Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NamedArg Expr -> Named_ Expr
forall e. Arg e -> e
unArg) [NamedArg Expr]
args) Expr
t0 Expr
t1
            CheckProjAppToKnownPrincipalArg Comparison
cmp Expr
e ProjOrigin
_ List1 QName
_ [NamedArg Expr]
_ Type
t Int
_ Term
_ Type
_ PrincipalArgTypeMetas
_ -> Expr -> Expr -> Expr -> OutputConstraint Expr Expr
forall a b. b -> a -> a -> OutputConstraint a b
TypedAssign Expr
m' Expr
e (Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type -> m (ReifiesTo Type)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Type
t
            DoQuoteTerm Comparison
cmp Term
v Type
t -> do
              Expr
tm <- AppInfo -> Expr -> NamedArg Expr -> Expr
A.App AppInfo
defaultAppInfo_ (ExprInfo -> Expr
A.QuoteTerm ExprInfo
exprNoRange) (NamedArg Expr -> Expr) -> (Expr -> NamedArg Expr) -> Expr -> Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expr -> NamedArg Expr
forall a. a -> NamedArg a
defaultNamedArg (Expr -> Expr) -> m Expr -> m Expr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Term
v
              Expr -> Expr -> OutputConstraint Expr Expr
forall a b. b -> a -> OutputConstraint a b
OfType Expr
tm (Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type -> m (ReifiesTo Type)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Type
t
          Open{}  -> m (OutputConstraint Expr Expr)
forall a. HasCallStack => a
__IMPOSSIBLE__
          OpenInstance{}  -> m (OutputConstraint Expr Expr)
forall a. HasCallStack => a
__IMPOSSIBLE__
          InstV{} -> m (OutputConstraint Expr Expr)
forall a. HasCallStack => a
__IMPOSSIBLE__
    reify (FindInstance MetaId
m Maybe [Candidate]
mcands) = Expr -> Expr -> [(Expr, Expr, Expr)] -> OutputConstraint Expr Expr
forall a b. b -> a -> [(a, a, a)] -> OutputConstraint a b
FindInstanceOF
      (Expr
 -> Expr -> [(Expr, Expr, Expr)] -> OutputConstraint Expr Expr)
-> m Expr
-> m (Expr -> [(Expr, Expr, Expr)] -> OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (MetaId -> Elims -> Term
MetaV MetaId
m [])
      m (Expr -> [(Expr, Expr, Expr)] -> OutputConstraint Expr Expr)
-> m Expr -> m ([(Expr, Expr, Expr)] -> OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Type -> m Expr
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (Type -> m Expr) -> m Type -> m Expr
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< MetaId -> m Type
forall (m :: * -> *).
(MonadFail m, ReadTCState m) =>
MetaId -> m Type
getMetaType MetaId
m)
      m ([(Expr, Expr, Expr)] -> OutputConstraint Expr Expr)
-> m [(Expr, Expr, Expr)] -> m (OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [Candidate]
-> (Candidate -> m (Expr, Expr, Expr)) -> m [(Expr, Expr, Expr)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM ([Candidate] -> Maybe [Candidate] -> [Candidate]
forall a. a -> Maybe a -> a
fromMaybe [] Maybe [Candidate]
mcands) (\ (Candidate CandidateKind
q Term
tm Type
ty Bool
_) -> do
            (,,) (Expr -> Expr -> Expr -> (Expr, Expr, Expr))
-> m Expr -> m (Expr -> Expr -> (Expr, Expr, Expr))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Term
tm m (Expr -> Expr -> (Expr, Expr, Expr))
-> m Expr -> m (Expr -> (Expr, Expr, Expr))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Term
tm m (Expr -> (Expr, Expr, Expr)) -> m Expr -> m (Expr, Expr, Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Type -> m (ReifiesTo Type)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Type
ty)
    reify (IsEmpty Range
r Type
a) = Expr -> OutputConstraint Expr Expr
forall a b. a -> OutputConstraint a b
IsEmptyType (Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type -> m (ReifiesTo Type)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Type
a
    reify (CheckSizeLtSat Term
a) = Expr -> OutputConstraint Expr Expr
forall a b. a -> OutputConstraint a b
SizeLtSat  (Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Term
a
    reify (CheckFunDef Delayed
d DefInfo
i QName
q [Clause]
cs TCErr
err) = do
      Expr
a <- Type -> m Expr
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (Type -> m Expr) -> m Type -> m Expr
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Definition -> Type
defType (Definition -> Type) -> m Definition -> m Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> QName -> m Definition
forall (m :: * -> *). HasConstInfo m => QName -> m Definition
getConstInfo QName
q
      OutputConstraint Expr Expr -> m (OutputConstraint Expr Expr)
forall (m :: * -> *) a. Monad m => a -> m a
return (OutputConstraint Expr Expr -> m (OutputConstraint Expr Expr))
-> OutputConstraint Expr Expr -> m (OutputConstraint Expr Expr)
forall a b. (a -> b) -> a -> b
$ QName -> Expr -> TCErr -> OutputConstraint Expr Expr
forall a b. QName -> a -> TCErr -> OutputConstraint a b
PostponedCheckFunDef QName
q Expr
a TCErr
err
    reify (HasBiggerSort Sort
a) = Expr -> Expr -> OutputConstraint Expr Expr
forall a b. b -> a -> OutputConstraint a b
OfType (Expr -> Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (Expr -> OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sort -> m (ReifiesTo Sort)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Sort
a m (Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Sort -> m (ReifiesTo Sort)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (Sort -> Sort
forall t. Sort' t -> Sort' t
UnivSort Sort
a)
    reify (HasPTSRule Dom Type
a Abs Sort
b) = do
      (Expr
a,(Name
x,Expr
b)) <- (Type, Abs Sort) -> m (ReifiesTo (Type, Abs Sort))
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (Dom Type -> Type
forall t e. Dom' t e -> e
unDom Dom Type
a,Abs Sort
b)
      OutputConstraint Expr Expr -> m (OutputConstraint Expr Expr)
forall (m :: * -> *) a. Monad m => a -> m a
return (OutputConstraint Expr Expr -> m (OutputConstraint Expr Expr))
-> OutputConstraint Expr Expr -> m (OutputConstraint Expr Expr)
forall a b. (a -> b) -> a -> b
$ Expr -> Expr -> OutputConstraint Expr Expr
forall a b. b -> b -> OutputConstraint a b
PTSInstance Expr
a Expr
b
    reify (CheckLockedVars Term
t Type
_ Arg Term
lk Type
_) = Expr -> Expr -> OutputConstraint Expr Expr
forall a b. b -> b -> OutputConstraint a b
CheckLock (Expr -> Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (Expr -> OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Term
t m (Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (Arg Term -> Term
forall e. Arg e -> e
unArg Arg Term
lk)
    reify (CheckMetaInst MetaId
m) = do
      Type
t <- Judgement MetaId -> Type
forall a. Judgement a -> Type
jMetaType (Judgement MetaId -> Type)
-> (MetaVariable -> Judgement MetaId) -> MetaVariable -> Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MetaVariable -> Judgement MetaId
mvJudgement (MetaVariable -> Type) -> m MetaVariable -> m Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MetaId -> m MetaVariable
forall (m :: * -> *).
(MonadFail m, ReadTCState m) =>
MetaId -> m MetaVariable
lookupMeta MetaId
m
      Expr -> Expr -> OutputConstraint Expr Expr
forall a b. b -> a -> OutputConstraint a b
OfType (Expr -> Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (Expr -> OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (MetaId -> Elims -> Term
MetaV MetaId
m []) m (Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Type -> m (ReifiesTo Type)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Type
t
    reify (CheckType Type
t) = Expr -> OutputConstraint Expr Expr
forall a b. b -> OutputConstraint a b
JustType (Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type -> m (ReifiesTo Type)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Type
t
    reify (UsableAtModality Modality
mod Term
t) = Modality -> Expr -> OutputConstraint Expr Expr
forall a b. Modality -> b -> OutputConstraint a b
UsableAtMod Modality
mod (Expr -> OutputConstraint Expr Expr)
-> m Expr -> m (OutputConstraint Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Term -> m (ReifiesTo Term)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify Term
t

instance (Pretty a, Pretty b) => Pretty (OutputForm a b) where
  pretty :: OutputForm a b -> Doc
pretty (OutputForm Range
r [ProblemId]
pids Blocker
unblock OutputConstraint a b
c) =
    OutputConstraint a b -> Doc
forall a. Pretty a => a -> Doc
pretty OutputConstraint a b
c Doc -> Doc -> Doc
<?>
      [Doc] -> Doc
forall (t :: * -> *). Foldable t => t Doc -> Doc
sep [ Range -> Doc
forall a. Pretty a => a -> Doc
prange Range
r, Doc -> Doc
parensNonEmpty ([Doc] -> Doc
forall (t :: * -> *). Foldable t => t Doc -> Doc
sep [Blocker -> Doc
blockedOn Blocker
unblock, [ProblemId] -> Doc
forall {a}. Pretty a => [a] -> Doc
prPids [ProblemId]
pids]) ]
    where
      prPids :: [a] -> Doc
prPids []    = Doc
forall a. Null a => a
empty
      prPids [a
pid] = Doc
"belongs to problem" Doc -> Doc -> Doc
<+> a -> Doc
forall a. Pretty a => a -> Doc
pretty a
pid
      prPids [a]
pids  = Doc
"belongs to problems" Doc -> Doc -> Doc
<+> [Doc] -> Doc
forall (t :: * -> *). Foldable t => t Doc -> Doc
fsep (Doc -> [Doc] -> [Doc]
forall (t :: * -> *). Foldable t => Doc -> t Doc -> [Doc]
punctuate Doc
"," ([Doc] -> [Doc]) -> [Doc] -> [Doc]
forall a b. (a -> b) -> a -> b
$ (a -> Doc) -> [a] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map a -> Doc
forall a. Pretty a => a -> Doc
pretty [a]
pids)

      comma :: Doc
comma | [ProblemId] -> Bool
forall a. Null a => a -> Bool
null [ProblemId]
pids = Doc
forall a. Null a => a
empty
            | Bool
otherwise = Doc
","

      blockedOn :: Blocker -> Doc
blockedOn (UnblockOnAll Set Blocker
bs) | Set Blocker -> Bool
forall a. Set a -> Bool
Set.null Set Blocker
bs = Doc
forall a. Null a => a
empty
      blockedOn (UnblockOnAny Set Blocker
bs) | Set Blocker -> Bool
forall a. Set a -> Bool
Set.null Set Blocker
bs = Doc
"stuck" Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
P.<> Doc
comma
      blockedOn Blocker
u = Doc
"blocked on" Doc -> Doc -> Doc
<+> (Blocker -> Doc
forall a. Pretty a => a -> Doc
pretty Blocker
u Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
P.<> Doc
comma)

      prange :: a -> Doc
prange a
r | ArgName -> Bool
forall a. Null a => a -> Bool
null ArgName
s = Doc
forall a. Null a => a
empty
               | Bool
otherwise = ArgName -> Doc
text (ArgName -> Doc) -> ArgName -> Doc
forall a b. (a -> b) -> a -> b
$ ArgName
" [ at " ArgName -> ArgName -> ArgName
forall a. [a] -> [a] -> [a]
++ ArgName
s ArgName -> ArgName -> ArgName
forall a. [a] -> [a] -> [a]
++ ArgName
" ]"
        where s :: ArgName
s = a -> ArgName
forall a. Pretty a => a -> ArgName
prettyShow a
r

instance (Pretty a, Pretty b) => Pretty (OutputConstraint a b) where
  pretty :: OutputConstraint a b -> Doc
pretty OutputConstraint a b
oc =
    case OutputConstraint a b
oc of
      OfType b
e a
t           -> b -> Doc
forall a. Pretty a => a -> Doc
pretty b
e Doc -> a -> Doc
forall {a}. Pretty a => Doc -> a -> Doc
.: a
t
      JustType b
e           -> Doc
"Type" Doc -> Doc -> Doc
<+> b -> Doc
forall a. Pretty a => a -> Doc
pretty b
e
      JustSort b
e           -> Doc
"Sort" Doc -> Doc -> Doc
<+> b -> Doc
forall a. Pretty a => a -> Doc
pretty b
e
      CmpInType Comparison
cmp a
t b
e b
e' -> Comparison -> b -> b -> Doc
forall {a} {a} {a}.
(Pretty a, Pretty a, Pretty a) =>
a -> a -> a -> Doc
pcmp Comparison
cmp b
e b
e' Doc -> a -> Doc
forall {a}. Pretty a => Doc -> a -> Doc
.: a
t
      CmpElim [Polarity]
cmp a
t [b]
e [b]
e'   -> [Polarity] -> [b] -> [b] -> Doc
forall {a} {a} {a}.
(Pretty a, Pretty a, Pretty a) =>
a -> a -> a -> Doc
pcmp [Polarity]
cmp [b]
e [b]
e' Doc -> a -> Doc
forall {a}. Pretty a => Doc -> a -> Doc
.: a
t
      CmpTypes  Comparison
cmp b
t b
t'   -> Comparison -> b -> b -> Doc
forall {a} {a} {a}.
(Pretty a, Pretty a, Pretty a) =>
a -> a -> a -> Doc
pcmp Comparison
cmp b
t b
t'
      CmpLevels Comparison
cmp b
t b
t'   -> Comparison -> b -> b -> Doc
forall {a} {a} {a}.
(Pretty a, Pretty a, Pretty a) =>
a -> a -> a -> Doc
pcmp Comparison
cmp b
t b
t'
      CmpTeles  Comparison
cmp b
t b
t'   -> Comparison -> b -> b -> Doc
forall {a} {a} {a}.
(Pretty a, Pretty a, Pretty a) =>
a -> a -> a -> Doc
pcmp Comparison
cmp b
t b
t'
      CmpSorts Comparison
cmp b
s b
s'    -> Comparison -> b -> b -> Doc
forall {a} {a} {a}.
(Pretty a, Pretty a, Pretty a) =>
a -> a -> a -> Doc
pcmp Comparison
cmp b
s b
s'
      Assign b
m a
e           -> Doc -> Doc -> Doc -> Doc
bin (b -> Doc
forall a. Pretty a => a -> Doc
pretty b
m) Doc
":=" (a -> Doc
forall a. Pretty a => a -> Doc
pretty a
e)
      TypedAssign b
m a
e a
a    -> Doc -> Doc -> Doc -> Doc
bin (b -> Doc
forall a. Pretty a => a -> Doc
pretty b
m) Doc
":=" (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ Doc -> Doc -> Doc -> Doc
bin (a -> Doc
forall a. Pretty a => a -> Doc
pretty a
e) Doc
":?" (a -> Doc
forall a. Pretty a => a -> Doc
pretty a
a)
      PostponedCheckArgs b
m [a]
es a
t0 a
t1 ->
        Doc -> Doc -> Doc -> Doc
bin (b -> Doc
forall a. Pretty a => a -> Doc
pretty b
m) Doc
":=" (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ (Doc -> Doc
parens (Doc
"_" Doc -> a -> Doc
forall {a}. Pretty a => Doc -> a -> Doc
.: a
t0) Doc -> Doc -> Doc
<+> [Doc] -> Doc
forall (t :: * -> *). Foldable t => t Doc -> Doc
fsep ((a -> Doc) -> [a] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Doc -> Doc
paren (Doc -> Doc) -> (a -> Doc) -> a -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Doc
forall a. Pretty a => a -> Doc
pretty) [a]
es)) Doc -> a -> Doc
forall {a}. Pretty a => Doc -> a -> Doc
.: a
t1
        where paren :: Doc -> Doc
paren Doc
d = Bool -> Doc -> Doc
mparens ((Char -> Bool) -> ArgName -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (Char -> ArgName -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Char
' ', Char
'\n']) (ArgName -> Bool) -> ArgName -> Bool
forall a b. (a -> b) -> a -> b
$ Doc -> ArgName
forall a. Show a => a -> ArgName
show Doc
d) Doc
d
      IsEmptyType a
a        -> Doc
"Is empty:" Doc -> Doc -> Doc
<+> a -> Doc
forall a. Pretty a => a -> Doc
pretty a
a
      SizeLtSat a
a          -> Doc
"Not empty type of sizes:" Doc -> Doc -> Doc
<+> a -> Doc
forall a. Pretty a => a -> Doc
pretty a
a
      FindInstanceOF b
s a
t [(a, a, a)]
cs -> [Doc] -> Doc
forall (t :: * -> *). Foldable t => t Doc -> Doc
vcat
        [ Doc
"Resolve instance argument" Doc -> Doc -> Doc
<?> (b -> Doc
forall a. Pretty a => a -> Doc
pretty b
s Doc -> a -> Doc
forall {a}. Pretty a => Doc -> a -> Doc
.: a
t)
        , Int -> Doc -> Doc
nest Int
2 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ Doc
"Candidate:"
        , Int -> Doc -> Doc
nest Int
4 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
forall (t :: * -> *). Foldable t => t Doc -> Doc
vcat [ Doc -> Doc -> Doc -> Doc
bin (a -> Doc
forall a. Pretty a => a -> Doc
pretty a
q) Doc
"=" (a -> Doc
forall a. Pretty a => a -> Doc
pretty a
v) Doc -> a -> Doc
forall {a}. Pretty a => Doc -> a -> Doc
.: a
t | (a
q, a
v, a
t) <- [(a, a, a)]
cs ] ]
      PTSInstance b
a b
b      -> Doc
"PTS instance for" Doc -> Doc -> Doc
<+> (b, b) -> Doc
forall a. Pretty a => a -> Doc
pretty (b
a, b
b)
      PostponedCheckFunDef QName
q a
a TCErr
_err ->
        [Doc] -> Doc
forall (t :: * -> *). Foldable t => t Doc -> Doc
vcat [ Doc
"Check definition of" Doc -> Doc -> Doc
<+> QName -> Doc
forall a. Pretty a => a -> Doc
pretty QName
q Doc -> Doc -> Doc
<+> Doc
":" Doc -> Doc -> Doc
<+> a -> Doc
forall a. Pretty a => a -> Doc
pretty a
a ]
             -- , nest 2 "stuck because" <?> pretty err ] -- We don't have Pretty for TCErr
      CheckLock b
t b
lk       -> Doc
"Check lock" Doc -> Doc -> Doc
<+> b -> Doc
forall a. Pretty a => a -> Doc
pretty b
lk Doc -> Doc -> Doc
<+> Doc
"allows" Doc -> Doc -> Doc
<+> b -> Doc
forall a. Pretty a => a -> Doc
pretty b
t
      UsableAtMod Modality
mod b
t    -> Doc
"Is usable at" Doc -> Doc -> Doc
<+> Modality -> Doc
forall a. Pretty a => a -> Doc
pretty Modality
mod Doc -> Doc -> Doc
<+> b -> Doc
forall a. Pretty a => a -> Doc
pretty b
t
    where
      bin :: Doc -> Doc -> Doc -> Doc
bin Doc
a Doc
op Doc
b = [Doc] -> Doc
forall (t :: * -> *). Foldable t => t Doc -> Doc
sep [Doc
a, Int -> Doc -> Doc
nest Int
2 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ Doc
op Doc -> Doc -> Doc
<+> Doc
b]
      pcmp :: a -> a -> a -> Doc
pcmp a
cmp a
a a
b = Doc -> Doc -> Doc -> Doc
bin (a -> Doc
forall a. Pretty a => a -> Doc
pretty a
a) (a -> Doc
forall a. Pretty a => a -> Doc
pretty a
cmp) (a -> Doc
forall a. Pretty a => a -> Doc
pretty a
b)
      Doc
val .: :: Doc -> a -> Doc
.: a
ty = Doc -> Doc -> Doc -> Doc
bin Doc
val Doc
":" (a -> Doc
forall a. Pretty a => a -> Doc
pretty a
ty)


instance (ToConcrete a, ToConcrete b) => ToConcrete (OutputForm a b) where
    type ConOfAbs (OutputForm a b) = OutputForm (ConOfAbs a) (ConOfAbs b)
    toConcrete :: OutputForm a b -> AbsToCon (ConOfAbs (OutputForm a b))
toConcrete (OutputForm Range
r [ProblemId]
pid Blocker
u OutputConstraint a b
c) = Range
-> [ProblemId]
-> Blocker
-> OutputConstraint (ConOfAbs a) (ConOfAbs b)
-> OutputForm (ConOfAbs a) (ConOfAbs b)
forall a b.
Range
-> [ProblemId] -> Blocker -> OutputConstraint a b -> OutputForm a b
OutputForm Range
r [ProblemId]
pid Blocker
u (OutputConstraint (ConOfAbs a) (ConOfAbs b)
 -> OutputForm (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (OutputForm (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> OutputConstraint a b -> AbsToCon (ConOfAbs (OutputConstraint a b))
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete OutputConstraint a b
c

instance (ToConcrete a, ToConcrete b) => ToConcrete (OutputConstraint a b) where
    type ConOfAbs (OutputConstraint a b) = OutputConstraint (ConOfAbs a) (ConOfAbs b)

    toConcrete :: OutputConstraint a b -> AbsToCon (ConOfAbs (OutputConstraint a b))
toConcrete (OfType b
e a
t) = ConOfAbs b
-> ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b)
forall a b. b -> a -> OutputConstraint a b
OfType (ConOfAbs b
 -> ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon
     (ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete b
e AbsToCon (ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs a)
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Precedence -> a -> AbsToCon (ConOfAbs a)
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx a
t
    toConcrete (JustType b
e) = ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b)
forall a b. b -> OutputConstraint a b
JustType (ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete b
e
    toConcrete (JustSort b
e) = ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b)
forall a b. b -> OutputConstraint a b
JustSort (ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete b
e
    toConcrete (CmpInType Comparison
cmp a
t b
e b
e') =
      Comparison
-> ConOfAbs a
-> ConOfAbs b
-> ConOfAbs b
-> OutputConstraint (ConOfAbs a) (ConOfAbs b)
forall a b. Comparison -> a -> b -> b -> OutputConstraint a b
CmpInType Comparison
cmp (ConOfAbs a
 -> ConOfAbs b
 -> ConOfAbs b
 -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs a)
-> AbsToCon
     (ConOfAbs b
      -> ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Precedence -> a -> AbsToCon (ConOfAbs a)
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx a
t AbsToCon
  (ConOfAbs b
   -> ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon
     (ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Precedence -> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx b
e
                                               AbsToCon (ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Precedence -> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx b
e'
    toConcrete (CmpElim [Polarity]
cmp a
t [b]
e [b]
e') =
      [Polarity]
-> ConOfAbs a
-> [ConOfAbs b]
-> [ConOfAbs b]
-> OutputConstraint (ConOfAbs a) (ConOfAbs b)
forall a b. [Polarity] -> a -> [b] -> [b] -> OutputConstraint a b
CmpElim [Polarity]
cmp (ConOfAbs a
 -> [ConOfAbs b]
 -> [ConOfAbs b]
 -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs a)
-> AbsToCon
     ([ConOfAbs b]
      -> [ConOfAbs b] -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Precedence -> a -> AbsToCon (ConOfAbs a)
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx a
t AbsToCon
  ([ConOfAbs b]
   -> [ConOfAbs b] -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon [ConOfAbs b]
-> AbsToCon
     ([ConOfAbs b] -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Precedence -> [b] -> AbsToCon (ConOfAbs [b])
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx [b]
e AbsToCon
  ([ConOfAbs b] -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon [ConOfAbs b]
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Precedence -> [b] -> AbsToCon (ConOfAbs [b])
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx [b]
e'
    toConcrete (CmpTypes Comparison
cmp b
e b
e') = Comparison
-> ConOfAbs b
-> ConOfAbs b
-> OutputConstraint (ConOfAbs a) (ConOfAbs b)
forall a b. Comparison -> b -> b -> OutputConstraint a b
CmpTypes Comparison
cmp (ConOfAbs b
 -> ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon
     (ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Precedence -> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx b
e
                                                  AbsToCon (ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Precedence -> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx b
e'
    toConcrete (CmpLevels Comparison
cmp b
e b
e') = Comparison
-> ConOfAbs b
-> ConOfAbs b
-> OutputConstraint (ConOfAbs a) (ConOfAbs b)
forall a b. Comparison -> b -> b -> OutputConstraint a b
CmpLevels Comparison
cmp (ConOfAbs b
 -> ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon
     (ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Precedence -> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx b
e
                                                    AbsToCon (ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Precedence -> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx b
e'
    toConcrete (CmpTeles Comparison
cmp b
e b
e') = Comparison
-> ConOfAbs b
-> ConOfAbs b
-> OutputConstraint (ConOfAbs a) (ConOfAbs b)
forall a b. Comparison -> b -> b -> OutputConstraint a b
CmpTeles Comparison
cmp (ConOfAbs b
 -> ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon
     (ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete b
e AbsToCon (ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete b
e'
    toConcrete (CmpSorts Comparison
cmp b
e b
e') = Comparison
-> ConOfAbs b
-> ConOfAbs b
-> OutputConstraint (ConOfAbs a) (ConOfAbs b)
forall a b. Comparison -> b -> b -> OutputConstraint a b
CmpSorts Comparison
cmp (ConOfAbs b
 -> ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon
     (ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Precedence -> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx b
e
                                                  AbsToCon (ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Precedence -> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx b
e'
    toConcrete (Assign b
m a
e) = AbsToCon (ConOfAbs (OutputConstraint a b))
-> AbsToCon (ConOfAbs (OutputConstraint a b))
forall a. AbsToCon a -> AbsToCon a
noTakenNames (AbsToCon (ConOfAbs (OutputConstraint a b))
 -> AbsToCon (ConOfAbs (OutputConstraint a b)))
-> AbsToCon (ConOfAbs (OutputConstraint a b))
-> AbsToCon (ConOfAbs (OutputConstraint a b))
forall a b. (a -> b) -> a -> b
$ ConOfAbs b
-> ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b)
forall a b. b -> a -> OutputConstraint a b
Assign (ConOfAbs b
 -> ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon
     (ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete b
m AbsToCon (ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs a)
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Precedence -> a -> AbsToCon (ConOfAbs a)
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx a
e
    toConcrete (TypedAssign b
m a
e a
a) = ConOfAbs b
-> ConOfAbs a
-> ConOfAbs a
-> OutputConstraint (ConOfAbs a) (ConOfAbs b)
forall a b. b -> a -> a -> OutputConstraint a b
TypedAssign (ConOfAbs b
 -> ConOfAbs a
 -> ConOfAbs a
 -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon
     (ConOfAbs a
      -> ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete b
m AbsToCon
  (ConOfAbs a
   -> ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs a)
-> AbsToCon
     (ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Precedence -> a -> AbsToCon (ConOfAbs a)
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx a
e
                                                                  AbsToCon (ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs a)
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Precedence -> a -> AbsToCon (ConOfAbs a)
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx a
a
    toConcrete (PostponedCheckArgs b
m [a]
args a
t0 a
t1) =
      ConOfAbs b
-> [ConOfAbs a]
-> ConOfAbs a
-> ConOfAbs a
-> OutputConstraint (ConOfAbs a) (ConOfAbs b)
forall a b. b -> [a] -> a -> a -> OutputConstraint a b
PostponedCheckArgs (ConOfAbs b
 -> [ConOfAbs a]
 -> ConOfAbs a
 -> ConOfAbs a
 -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon
     ([ConOfAbs a]
      -> ConOfAbs a
      -> ConOfAbs a
      -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete b
m AbsToCon
  ([ConOfAbs a]
   -> ConOfAbs a
   -> ConOfAbs a
   -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon [ConOfAbs a]
-> AbsToCon
     (ConOfAbs a
      -> ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [a] -> AbsToCon (ConOfAbs [a])
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete [a]
args AbsToCon
  (ConOfAbs a
   -> ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs a)
-> AbsToCon
     (ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> AbsToCon (ConOfAbs a)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete a
t0 AbsToCon (ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs a)
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> AbsToCon (ConOfAbs a)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete a
t1
    toConcrete (IsEmptyType a
a) = ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b)
forall a b. a -> OutputConstraint a b
IsEmptyType (ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs a)
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Precedence -> a -> AbsToCon (ConOfAbs a)
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx a
a
    toConcrete (SizeLtSat a
a) = ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b)
forall a b. a -> OutputConstraint a b
SizeLtSat (ConOfAbs a -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs a)
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Precedence -> a -> AbsToCon (ConOfAbs a)
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx a
a
    toConcrete (FindInstanceOF b
s a
t [(a, a, a)]
cs) =
      ConOfAbs b
-> ConOfAbs a
-> [(ConOfAbs a, ConOfAbs a, ConOfAbs a)]
-> OutputConstraint (ConOfAbs a) (ConOfAbs b)
forall a b. b -> a -> [(a, a, a)] -> OutputConstraint a b
FindInstanceOF (ConOfAbs b
 -> ConOfAbs a
 -> [(ConOfAbs a, ConOfAbs a, ConOfAbs a)]
 -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon
     (ConOfAbs a
      -> [(ConOfAbs a, ConOfAbs a, ConOfAbs a)]
      -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete b
s AbsToCon
  (ConOfAbs a
   -> [(ConOfAbs a, ConOfAbs a, ConOfAbs a)]
   -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs a)
-> AbsToCon
     ([(ConOfAbs a, ConOfAbs a, ConOfAbs a)]
      -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> AbsToCon (ConOfAbs a)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete a
t
                     AbsToCon
  ([(ConOfAbs a, ConOfAbs a, ConOfAbs a)]
   -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon [(ConOfAbs a, ConOfAbs a, ConOfAbs a)]
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ((a, a, a) -> AbsToCon (ConOfAbs a, ConOfAbs a, ConOfAbs a))
-> [(a, a, a)] -> AbsToCon [(ConOfAbs a, ConOfAbs a, ConOfAbs a)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\(a
q,a
tm,a
ty) -> (,,) (ConOfAbs a
 -> ConOfAbs a
 -> ConOfAbs a
 -> (ConOfAbs a, ConOfAbs a, ConOfAbs a))
-> AbsToCon (ConOfAbs a)
-> AbsToCon
     (ConOfAbs a -> ConOfAbs a -> (ConOfAbs a, ConOfAbs a, ConOfAbs a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> AbsToCon (ConOfAbs a)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete a
q AbsToCon
  (ConOfAbs a -> ConOfAbs a -> (ConOfAbs a, ConOfAbs a, ConOfAbs a))
-> AbsToCon (ConOfAbs a)
-> AbsToCon (ConOfAbs a -> (ConOfAbs a, ConOfAbs a, ConOfAbs a))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> AbsToCon (ConOfAbs a)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete a
tm AbsToCon (ConOfAbs a -> (ConOfAbs a, ConOfAbs a, ConOfAbs a))
-> AbsToCon (ConOfAbs a)
-> AbsToCon (ConOfAbs a, ConOfAbs a, ConOfAbs a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> AbsToCon (ConOfAbs a)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete a
ty) [(a, a, a)]
cs
    toConcrete (PTSInstance b
a b
b) = ConOfAbs b
-> ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b)
forall a b. b -> b -> OutputConstraint a b
PTSInstance (ConOfAbs b
 -> ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon
     (ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete b
a AbsToCon (ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete b
b
    toConcrete (CheckLock b
a b
b) = ConOfAbs b
-> ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b)
forall a b. b -> b -> OutputConstraint a b
CheckLock (ConOfAbs b
 -> ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon
     (ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete b
a AbsToCon (ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete b
b
    toConcrete (PostponedCheckFunDef QName
q a
a TCErr
err) = QName
-> ConOfAbs a
-> TCErr
-> OutputConstraint (ConOfAbs a) (ConOfAbs b)
forall a b. QName -> a -> TCErr -> OutputConstraint a b
PostponedCheckFunDef QName
q (ConOfAbs a -> TCErr -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs a)
-> AbsToCon (TCErr -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> AbsToCon (ConOfAbs a)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete a
a AbsToCon (TCErr -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon TCErr
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> TCErr -> AbsToCon TCErr
forall (f :: * -> *) a. Applicative f => a -> f a
pure TCErr
err
    toConcrete (UsableAtMod Modality
a b
b) = Modality
-> ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b)
forall a b. Modality -> b -> OutputConstraint a b
UsableAtMod Modality
a (ConOfAbs b -> OutputConstraint (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon (OutputConstraint (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete b
b

instance (Pretty a, Pretty b) => Pretty (OutputConstraint' a b) where
  pretty :: OutputConstraint' a b -> Doc
pretty (OfType' b
e a
t) = b -> Doc
forall a. Pretty a => a -> Doc
pretty b
e Doc -> Doc -> Doc
<+> Doc
":" Doc -> Doc -> Doc
<+> a -> Doc
forall a. Pretty a => a -> Doc
pretty a
t

instance (ToConcrete a, ToConcrete b) => ToConcrete (OutputConstraint' a b) where
  type ConOfAbs (OutputConstraint' a b) = OutputConstraint' (ConOfAbs a) (ConOfAbs b)
  toConcrete :: OutputConstraint' a b
-> AbsToCon (ConOfAbs (OutputConstraint' a b))
toConcrete (OfType' b
e a
t) = ConOfAbs b
-> ConOfAbs a -> OutputConstraint' (ConOfAbs a) (ConOfAbs b)
forall a b. b -> a -> OutputConstraint' a b
OfType' (ConOfAbs b
 -> ConOfAbs a -> OutputConstraint' (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs b)
-> AbsToCon
     (ConOfAbs a -> OutputConstraint' (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> b -> AbsToCon (ConOfAbs b)
forall a. ToConcrete a => a -> AbsToCon (ConOfAbs a)
toConcrete b
e AbsToCon
  (ConOfAbs a -> OutputConstraint' (ConOfAbs a) (ConOfAbs b))
-> AbsToCon (ConOfAbs a)
-> AbsToCon (OutputConstraint' (ConOfAbs a) (ConOfAbs b))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Precedence -> a -> AbsToCon (ConOfAbs a)
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx a
t

instance Reify a => Reify (IPBoundary' a) where
  type ReifiesTo (IPBoundary' a) = IPBoundary' (ReifiesTo a)
  reify :: forall (m :: * -> *).
MonadReify m =>
IPBoundary' a -> m (ReifiesTo (IPBoundary' a))
reify = (a -> m (ReifiesTo a))
-> IPBoundary' a -> m (IPBoundary' (ReifiesTo a))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> m (ReifiesTo a)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify

instance ToConcrete a => ToConcrete (IPBoundary' a) where
  type ConOfAbs (IPBoundary' a) = IPBoundary' (ConOfAbs a)

  toConcrete :: IPBoundary' a -> AbsToCon (ConOfAbs (IPBoundary' a))
toConcrete = (a -> AbsToCon (ConOfAbs a))
-> IPBoundary' a -> AbsToCon (IPBoundary' (ConOfAbs a))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Precedence -> a -> AbsToCon (ConOfAbs a)
forall a. ToConcrete a => Precedence -> a -> AbsToCon (ConOfAbs a)
toConcreteCtx Precedence
TopCtx)

instance Pretty c => Pretty (IPBoundary' c) where
  pretty :: IPBoundary' c -> Doc
pretty (IPBoundary [(c, c)]
eqs c
val c
meta Overapplied
over) = do
    let
      xs :: [Doc]
xs = ((c, c) -> Doc) -> [(c, c)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (\ (c
l,c
r) -> c -> Doc
forall a. Pretty a => a -> Doc
pretty c
l Doc -> Doc -> Doc
<+> Doc
"=" Doc -> Doc -> Doc
<+> c -> Doc
forall a. Pretty a => a -> Doc
pretty c
r) [(c, c)]
eqs
      rhs :: Doc
rhs = case Overapplied
over of
              Overapplied
Overapplied    -> Doc
"=" Doc -> Doc -> Doc
<+> c -> Doc
forall a. Pretty a => a -> Doc
pretty c
meta
              Overapplied
NotOverapplied -> Doc
forall a. Monoid a => a
mempty
    [Doc] -> Doc
forall {a}. Pretty a => [a] -> Doc
prettyList_ [Doc]
xs Doc -> Doc -> Doc
<+> Doc
"⊢" Doc -> Doc -> Doc
<+> c -> Doc
forall a. Pretty a => a -> Doc
pretty c
val Doc -> Doc -> Doc
<+> Doc
rhs

prettyConstraints :: [Closure Constraint] -> TCM [OutputForm C.Expr C.Expr]
prettyConstraints :: [Closure Constraint] -> TCM [OutputForm Expr Expr]
prettyConstraints [Closure Constraint]
cs = do
  [Closure Constraint]
-> (Closure Constraint -> TCMT IO (OutputForm Expr Expr))
-> TCM [OutputForm Expr Expr]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [Closure Constraint]
cs ((Closure Constraint -> TCMT IO (OutputForm Expr Expr))
 -> TCM [OutputForm Expr Expr])
-> (Closure Constraint -> TCMT IO (OutputForm Expr Expr))
-> TCM [OutputForm Expr Expr]
forall a b. (a -> b) -> a -> b
$ \ Closure Constraint
c -> do
            Closure (OutputForm Expr Expr)
cl <- ProblemConstraint -> TCMT IO (ReifiesTo ProblemConstraint)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (Set ProblemId -> Blocker -> Closure Constraint -> ProblemConstraint
PConstr Set ProblemId
forall a. Set a
Set.empty Blocker
alwaysUnblock Closure Constraint
c)
            Closure (OutputForm Expr Expr)
-> (OutputForm Expr Expr -> TCMT IO (OutputForm Expr Expr))
-> TCMT IO (OutputForm Expr Expr)
forall (m :: * -> *) a c b.
(MonadTCEnv m, ReadTCState m, LensClosure a c) =>
c -> (a -> m b) -> m b
enterClosure Closure (OutputForm Expr Expr)
cl OutputForm Expr Expr -> TCMT IO (OutputForm Expr Expr)
forall a (m :: * -> *).
(ToConcrete a, MonadAbsToCon m) =>
a -> m (ConOfAbs a)
abstractToConcrete_

getConstraints :: TCM [OutputForm C.Expr C.Expr]
getConstraints :: TCM [OutputForm Expr Expr]
getConstraints = (ProblemConstraint -> TCM ProblemConstraint)
-> (ProblemConstraint -> Bool) -> TCM [OutputForm Expr Expr]
getConstraints' ProblemConstraint -> TCM ProblemConstraint
forall (m :: * -> *) a. Monad m => a -> m a
return ((ProblemConstraint -> Bool) -> TCM [OutputForm Expr Expr])
-> (ProblemConstraint -> Bool) -> TCM [OutputForm Expr Expr]
forall a b. (a -> b) -> a -> b
$ Bool -> ProblemConstraint -> Bool
forall a b. a -> b -> a
const Bool
True

namedMetaOf :: OutputConstraint A.Expr a -> a
namedMetaOf :: forall a. OutputConstraint Expr a -> a
namedMetaOf (OfType a
i Expr
_) = a
i
namedMetaOf (JustType a
i) = a
i
namedMetaOf (JustSort a
i) = a
i
namedMetaOf (Assign a
i Expr
_) = a
i
namedMetaOf OutputConstraint Expr a
_ = a
forall a. HasCallStack => a
__IMPOSSIBLE__

getConstraintsMentioning :: Rewrite -> MetaId -> TCM [OutputForm C.Expr C.Expr]
getConstraintsMentioning :: Rewrite -> MetaId -> TCM [OutputForm Expr Expr]
getConstraintsMentioning Rewrite
norm MetaId
m = (ProblemConstraint -> TCM ProblemConstraint)
-> (ProblemConstraint -> Bool) -> TCM [OutputForm Expr Expr]
getConstrs ProblemConstraint -> TCM ProblemConstraint
forall {m :: * -> *} {b}.
(InstantiateFull b, MonadReduce m) =>
b -> m b
instantiateBlockingFull (MetaId -> ProblemConstraint -> Bool
forall t. MentionsMeta t => MetaId -> t -> Bool
mentionsMeta MetaId
m)
  -- could be optimized by not doing a full instantiation up front, with a more clever mentionsMeta.
  where
    instantiateBlockingFull :: b -> m b
instantiateBlockingFull b
p
      = Lens' Bool TCState -> (Bool -> Bool) -> m b -> m b
forall (m :: * -> *) a b.
ReadTCState m =>
Lens' a TCState -> (a -> a) -> m b -> m b
locallyTCState Lens' Bool TCState
stInstantiateBlocking (Bool -> Bool -> Bool
forall a b. a -> b -> a
const Bool
True) (m b -> m b) -> m b -> m b
forall a b. (a -> b) -> a -> b
$
          b -> m b
forall a (m :: * -> *).
(InstantiateFull a, MonadReduce m) =>
a -> m a
instantiateFull b
p

    -- Trying to find the actual meta application, as long as it's not
    -- buried too deep.
    -- We could look further but probably not under binders as that would mess with
    -- the call to @unifyElimsMeta@ below.
    hasHeadMeta :: Constraint -> Maybe Elims
hasHeadMeta Constraint
c =
      case Constraint
c of
        ValueCmp Comparison
_ CompareAs
_ Term
u Term
v           -> Term -> Maybe Elims
isMeta Term
u Maybe Elims -> Maybe Elims -> Maybe Elims
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` Term -> Maybe Elims
isMeta Term
v
        ValueCmpOnFace Comparison
cmp Term
p Type
t Term
u Term
v -> Term -> Maybe Elims
isMeta Term
u Maybe Elims -> Maybe Elims -> Maybe Elims
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` Term -> Maybe Elims
isMeta Term
v
        -- TODO: extend to other comparisons?
        ElimCmp [Polarity]
cmp [IsForced]
fs Type
t Term
v Elims
as Elims
bs   -> Maybe Elims
forall a. Maybe a
Nothing
        LevelCmp Comparison
cmp Level
u Level
v           -> Maybe Elims
forall a. Maybe a
Nothing
        SortCmp Comparison
cmp Sort
a Sort
b            -> Maybe Elims
forall a. Maybe a
Nothing
        UnBlock{}                  -> Maybe Elims
forall a. Maybe a
Nothing
        FindInstance{}             -> Maybe Elims
forall a. Maybe a
Nothing
        IsEmpty Range
r Type
t                -> Term -> Maybe Elims
isMeta (Type -> Term
forall t a. Type'' t a -> a
unEl Type
t)
        CheckSizeLtSat Term
t           -> Term -> Maybe Elims
isMeta Term
t
        CheckFunDef{}              -> Maybe Elims
forall a. Maybe a
Nothing
        HasBiggerSort Sort
a            -> Maybe Elims
forall a. Maybe a
Nothing
        HasPTSRule Dom Type
a Abs Sort
b             -> Maybe Elims
forall a. Maybe a
Nothing
        UnquoteTactic{}            -> Maybe Elims
forall a. Maybe a
Nothing
        CheckMetaInst{}            -> Maybe Elims
forall a. Maybe a
Nothing
        CheckType Type
t                -> Term -> Maybe Elims
isMeta (Type -> Term
forall t a. Type'' t a -> a
unEl Type
t)
        CheckLockedVars Term
t Type
_ Arg Term
_ Type
_    -> Term -> Maybe Elims
isMeta Term
t
        UsableAtModality Modality
_ Term
t       -> Term -> Maybe Elims
isMeta Term
t

    isMeta :: Term -> Maybe Elims
isMeta (MetaV MetaId
m' Elims
es_m)
      | MetaId
m MetaId -> MetaId -> Bool
forall a. Eq a => a -> a -> Bool
== MetaId
m' = Elims -> Maybe Elims
forall a. a -> Maybe a
Just Elims
es_m
    isMeta Term
_  = Maybe Elims
forall a. Maybe a
Nothing

    getConstrs :: (ProblemConstraint -> TCM ProblemConstraint)
-> (ProblemConstraint -> Bool) -> TCM [OutputForm Expr Expr]
getConstrs ProblemConstraint -> TCM ProblemConstraint
g ProblemConstraint -> Bool
f = TCM [OutputForm Expr Expr] -> TCM [OutputForm Expr Expr]
forall (tcm :: * -> *) a. MonadTCM tcm => TCM a -> tcm a
liftTCM (TCM [OutputForm Expr Expr] -> TCM [OutputForm Expr Expr])
-> TCM [OutputForm Expr Expr] -> TCM [OutputForm Expr Expr]
forall a b. (a -> b) -> a -> b
$ do
      Constraints
cs <- Constraints -> Constraints
stripConstraintPids (Constraints -> Constraints)
-> (Constraints -> Constraints) -> Constraints -> Constraints
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ProblemConstraint -> Bool) -> Constraints -> Constraints
forall a. (a -> Bool) -> [a] -> [a]
filter ProblemConstraint -> Bool
f (Constraints -> Constraints)
-> TCMT IO Constraints -> TCMT IO Constraints
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((ProblemConstraint -> TCM ProblemConstraint)
-> Constraints -> TCMT IO Constraints
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ProblemConstraint -> TCM ProblemConstraint
g (Constraints -> TCMT IO Constraints)
-> TCMT IO Constraints -> TCMT IO Constraints
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCMT IO Constraints
forall (m :: * -> *). ReadTCState m => m Constraints
M.getAllConstraints)
      ArgName -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> TCMT IO Doc -> m ()
reportSDoc ArgName
"constr.ment" Int
20 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"getConstraintsMentioning"
      Constraints
-> (ProblemConstraint -> TCMT IO (OutputForm Expr Expr))
-> TCM [OutputForm Expr Expr]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM Constraints
cs ((ProblemConstraint -> TCMT IO (OutputForm Expr Expr))
 -> TCM [OutputForm Expr Expr])
-> (ProblemConstraint -> TCMT IO (OutputForm Expr Expr))
-> TCM [OutputForm Expr Expr]
forall a b. (a -> b) -> a -> b
$ \(PConstr Set ProblemId
s Blocker
ub Closure Constraint
c) -> do
        Closure Constraint
c <- Rewrite -> Closure Constraint -> TCM (Closure Constraint)
forall t.
(Reduce t, Simplify t, Instantiate t, Normalise t) =>
Rewrite -> t -> TCM t
normalForm Rewrite
norm Closure Constraint
c
        case Elims -> Maybe Args
forall a. [Elim' a] -> Maybe [Arg a]
allApplyElims (Elims -> Maybe Args) -> Maybe Elims -> Maybe Args
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Constraint -> Maybe Elims
hasHeadMeta (Closure Constraint -> Constraint
forall a. Closure a -> a
clValue Closure Constraint
c) of
          Just Args
as_m -> do
            -- unifyElimsMeta tries to move the constraint into
            -- (an extension of) the context where @m@ comes from.
            MetaId
-> Args
-> Closure Constraint
-> ([(Term, Term)] -> Constraint -> TCMT IO (OutputForm Expr Expr))
-> TCMT IO (OutputForm Expr Expr)
forall a.
MetaId
-> Args
-> Closure Constraint
-> ([(Term, Term)] -> Constraint -> TCM a)
-> TCM a
unifyElimsMeta MetaId
m Args
as_m Closure Constraint
c (([(Term, Term)] -> Constraint -> TCMT IO (OutputForm Expr Expr))
 -> TCMT IO (OutputForm Expr Expr))
-> ([(Term, Term)] -> Constraint -> TCMT IO (OutputForm Expr Expr))
-> TCMT IO (OutputForm Expr Expr)
forall a b. (a -> b) -> a -> b
$ \ [(Term, Term)]
eqs Constraint
c -> do
              (Closure (OutputForm Expr Expr)
 -> (OutputForm Expr Expr -> TCMT IO (OutputForm Expr Expr))
 -> TCMT IO (OutputForm Expr Expr))
-> (OutputForm Expr Expr -> TCMT IO (OutputForm Expr Expr))
-> Closure (OutputForm Expr Expr)
-> TCMT IO (OutputForm Expr Expr)
forall a b c. (a -> b -> c) -> b -> a -> c
flip Closure (OutputForm Expr Expr)
-> (OutputForm Expr Expr -> TCMT IO (OutputForm Expr Expr))
-> TCMT IO (OutputForm Expr Expr)
forall (m :: * -> *) a c b.
(MonadTCEnv m, ReadTCState m, LensClosure a c) =>
c -> (a -> m b) -> m b
enterClosure OutputForm Expr Expr -> TCMT IO (OutputForm Expr Expr)
forall a (m :: * -> *).
(ToConcrete a, MonadAbsToCon m) =>
a -> m (ConOfAbs a)
abstractToConcrete_ (Closure (OutputForm Expr Expr) -> TCMT IO (OutputForm Expr Expr))
-> TCMT IO (Closure (OutputForm Expr Expr))
-> TCMT IO (OutputForm Expr Expr)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ProblemConstraint -> TCMT IO (Closure (OutputForm Expr Expr))
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (ProblemConstraint -> TCMT IO (Closure (OutputForm Expr Expr)))
-> (Closure Constraint -> ProblemConstraint)
-> Closure Constraint
-> TCMT IO (Closure (OutputForm Expr Expr))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set ProblemId -> Blocker -> Closure Constraint -> ProblemConstraint
PConstr Set ProblemId
s Blocker
ub (Closure Constraint -> TCMT IO (Closure (OutputForm Expr Expr)))
-> TCM (Closure Constraint)
-> TCMT IO (Closure (OutputForm Expr Expr))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Constraint -> TCM (Closure Constraint)
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m) =>
a -> m (Closure a)
buildClosure Constraint
c
          Maybe Args
_ -> do
            Closure (OutputForm Expr Expr)
cl <- ProblemConstraint -> TCMT IO (ReifiesTo ProblemConstraint)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (ProblemConstraint -> TCMT IO (ReifiesTo ProblemConstraint))
-> ProblemConstraint -> TCMT IO (ReifiesTo ProblemConstraint)
forall a b. (a -> b) -> a -> b
$ Set ProblemId -> Blocker -> Closure Constraint -> ProblemConstraint
PConstr Set ProblemId
s Blocker
ub Closure Constraint
c
            Closure (OutputForm Expr Expr)
-> (OutputForm Expr Expr -> TCMT IO (OutputForm Expr Expr))
-> TCMT IO (OutputForm Expr Expr)
forall (m :: * -> *) a c b.
(MonadTCEnv m, ReadTCState m, LensClosure a c) =>
c -> (a -> m b) -> m b
enterClosure Closure (OutputForm Expr Expr)
cl OutputForm Expr Expr -> TCMT IO (OutputForm Expr Expr)
forall a (m :: * -> *).
(ToConcrete a, MonadAbsToCon m) =>
a -> m (ConOfAbs a)
abstractToConcrete_

-- Copied from Agda.TypeChecking.Pretty.Warning.prettyConstraints
stripConstraintPids :: Constraints -> Constraints
stripConstraintPids :: Constraints -> Constraints
stripConstraintPids Constraints
cs = (ProblemConstraint -> ProblemConstraint -> Ordering)
-> Constraints -> Constraints
forall a. (a -> a -> Ordering) -> [a] -> [a]
List.sortBy (Bool -> Bool -> Ordering
forall a. Ord a => a -> a -> Ordering
compare (Bool -> Bool -> Ordering)
-> (ProblemConstraint -> Bool)
-> ProblemConstraint
-> ProblemConstraint
-> Ordering
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` ProblemConstraint -> Bool
isBlocked) (Constraints -> Constraints) -> Constraints -> Constraints
forall a b. (a -> b) -> a -> b
$ (ProblemConstraint -> ProblemConstraint)
-> Constraints -> Constraints
forall a b. (a -> b) -> [a] -> [b]
map ProblemConstraint -> ProblemConstraint
stripPids Constraints
cs
  where
    isBlocked :: ProblemConstraint -> Bool
isBlocked = Bool -> Bool
not (Bool -> Bool)
-> (ProblemConstraint -> Bool) -> ProblemConstraint -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set ProblemId -> Bool
forall a. Null a => a -> Bool
null (Set ProblemId -> Bool)
-> (ProblemConstraint -> Set ProblemId)
-> ProblemConstraint
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Blocker -> Set ProblemId
allBlockingProblems (Blocker -> Set ProblemId)
-> (ProblemConstraint -> Blocker)
-> ProblemConstraint
-> Set ProblemId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProblemConstraint -> Blocker
constraintUnblocker
    interestingPids :: Set ProblemId
interestingPids = [Set ProblemId] -> Set ProblemId
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions ([Set ProblemId] -> Set ProblemId)
-> [Set ProblemId] -> Set ProblemId
forall a b. (a -> b) -> a -> b
$ (ProblemConstraint -> Set ProblemId)
-> Constraints -> [Set ProblemId]
forall a b. (a -> b) -> [a] -> [b]
map (Blocker -> Set ProblemId
allBlockingProblems (Blocker -> Set ProblemId)
-> (ProblemConstraint -> Blocker)
-> ProblemConstraint
-> Set ProblemId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProblemConstraint -> Blocker
constraintUnblocker) Constraints
cs
    stripPids :: ProblemConstraint -> ProblemConstraint
stripPids (PConstr Set ProblemId
pids Blocker
unblock Closure Constraint
c) = Set ProblemId -> Blocker -> Closure Constraint -> ProblemConstraint
PConstr (Set ProblemId -> Set ProblemId -> Set ProblemId
forall a. Ord a => Set a -> Set a -> Set a
Set.intersection Set ProblemId
pids Set ProblemId
interestingPids) Blocker
unblock Closure Constraint
c

getConstraints' :: (ProblemConstraint -> TCM ProblemConstraint) -> (ProblemConstraint -> Bool) -> TCM [OutputForm C.Expr C.Expr]
getConstraints' :: (ProblemConstraint -> TCM ProblemConstraint)
-> (ProblemConstraint -> Bool) -> TCM [OutputForm Expr Expr]
getConstraints' ProblemConstraint -> TCM ProblemConstraint
g ProblemConstraint -> Bool
f = TCM [OutputForm Expr Expr] -> TCM [OutputForm Expr Expr]
forall (tcm :: * -> *) a. MonadTCM tcm => TCM a -> tcm a
liftTCM (TCM [OutputForm Expr Expr] -> TCM [OutputForm Expr Expr])
-> TCM [OutputForm Expr Expr] -> TCM [OutputForm Expr Expr]
forall a b. (a -> b) -> a -> b
$ do
    Constraints
cs <- Constraints -> Constraints
stripConstraintPids (Constraints -> Constraints)
-> (Constraints -> Constraints) -> Constraints -> Constraints
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ProblemConstraint -> Bool) -> Constraints -> Constraints
forall a. (a -> Bool) -> [a] -> [a]
filter ProblemConstraint -> Bool
f (Constraints -> Constraints)
-> TCMT IO Constraints -> TCMT IO Constraints
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((ProblemConstraint -> TCM ProblemConstraint)
-> Constraints -> TCMT IO Constraints
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ProblemConstraint -> TCM ProblemConstraint
g (Constraints -> TCMT IO Constraints)
-> TCMT IO Constraints -> TCMT IO Constraints
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCMT IO Constraints
forall (m :: * -> *). ReadTCState m => m Constraints
M.getAllConstraints)
    [OutputForm Expr Expr]
cs <- Constraints
-> (ProblemConstraint -> TCMT IO (OutputForm Expr Expr))
-> TCM [OutputForm Expr Expr]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM Constraints
cs ((ProblemConstraint -> TCMT IO (OutputForm Expr Expr))
 -> TCM [OutputForm Expr Expr])
-> (ProblemConstraint -> TCMT IO (OutputForm Expr Expr))
-> TCM [OutputForm Expr Expr]
forall a b. (a -> b) -> a -> b
$ \ProblemConstraint
c -> do
            Closure (OutputForm Expr Expr)
cl <- ProblemConstraint -> TCMT IO (ReifiesTo ProblemConstraint)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify ProblemConstraint
c
            Closure (OutputForm Expr Expr)
-> (OutputForm Expr Expr -> TCMT IO (OutputForm Expr Expr))
-> TCMT IO (OutputForm Expr Expr)
forall (m :: * -> *) a c b.
(MonadTCEnv m, ReadTCState m, LensClosure a c) =>
c -> (a -> m b) -> m b
enterClosure Closure (OutputForm Expr Expr)
cl OutputForm Expr Expr -> TCMT IO (OutputForm Expr Expr)
forall a (m :: * -> *).
(ToConcrete a, MonadAbsToCon m) =>
a -> m (ConOfAbs a)
abstractToConcrete_
    [OutputForm Expr Expr]
ss <- ((InteractionId, MetaId, Expr) -> TCMT IO (OutputForm Expr Expr))
-> [(InteractionId, MetaId, Expr)] -> TCM [OutputForm Expr Expr]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (InteractionId, MetaId, Expr) -> TCMT IO (OutputForm Expr Expr)
forall {m :: * -> *} {a}.
(MonadTrace m, ToConcrete a, MonadStConcreteNames m, HasOptions m,
 HasBuiltins m, MonadDebug m) =>
(InteractionId, MetaId, a) -> m (OutputForm (ConOfAbs a) Expr)
toOutputForm ([(InteractionId, MetaId, Expr)] -> TCM [OutputForm Expr Expr])
-> TCMT IO [(InteractionId, MetaId, Expr)]
-> TCM [OutputForm Expr Expr]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Bool -> Rewrite -> TCMT IO [(InteractionId, MetaId, Expr)]
getSolvedInteractionPoints Bool
True Rewrite
AsIs -- get all
    [OutputForm Expr Expr] -> TCM [OutputForm Expr Expr]
forall (m :: * -> *) a. Monad m => a -> m a
return ([OutputForm Expr Expr] -> TCM [OutputForm Expr Expr])
-> [OutputForm Expr Expr] -> TCM [OutputForm Expr Expr]
forall a b. (a -> b) -> a -> b
$ [OutputForm Expr Expr]
ss [OutputForm Expr Expr]
-> [OutputForm Expr Expr] -> [OutputForm Expr Expr]
forall a. [a] -> [a] -> [a]
++ [OutputForm Expr Expr]
cs
  where
    toOutputForm :: (InteractionId, MetaId, a) -> m (OutputForm (ConOfAbs a) Expr)
toOutputForm (InteractionId
ii, MetaId
mi, a
e) = do
      Closure Range
mv <- MetaVariable -> Closure Range
getMetaInfo (MetaVariable -> Closure Range)
-> m MetaVariable -> m (Closure Range)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MetaId -> m MetaVariable
forall (m :: * -> *).
(MonadFail m, ReadTCState m) =>
MetaId -> m MetaVariable
lookupMeta MetaId
mi
      Closure Range
-> m (OutputForm (ConOfAbs a) Expr)
-> m (OutputForm (ConOfAbs a) Expr)
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadTrace m) =>
Closure Range -> m a -> m a
withMetaInfo Closure Range
mv (m (OutputForm (ConOfAbs a) Expr)
 -> m (OutputForm (ConOfAbs a) Expr))
-> m (OutputForm (ConOfAbs a) Expr)
-> m (OutputForm (ConOfAbs a) Expr)
forall a b. (a -> b) -> a -> b
$ do
        let m :: Expr
m = MetaInfo -> InteractionId -> Expr
QuestionMark MetaInfo
emptyMetaInfo{ metaNumber :: Maybe MetaId
metaNumber = MetaId -> Maybe MetaId
forall a. a -> Maybe a
Just (MetaId -> Maybe MetaId) -> MetaId -> Maybe MetaId
forall a b. (a -> b) -> a -> b
$ InteractionId -> MetaId
forall a b. (Integral a, Num b) => a -> b
fromIntegral InteractionId
ii } InteractionId
ii
        OutputForm a Expr -> m (ConOfAbs (OutputForm a Expr))
forall a (m :: * -> *).
(ToConcrete a, MonadAbsToCon m) =>
a -> m (ConOfAbs a)
abstractToConcrete_ (OutputForm a Expr -> m (ConOfAbs (OutputForm a Expr)))
-> OutputForm a Expr -> m (ConOfAbs (OutputForm a Expr))
forall a b. (a -> b) -> a -> b
$ Range
-> [ProblemId]
-> Blocker
-> OutputConstraint a Expr
-> OutputForm a Expr
forall a b.
Range
-> [ProblemId] -> Blocker -> OutputConstraint a b -> OutputForm a b
OutputForm Range
forall a. Range' a
noRange [] Blocker
alwaysUnblock (OutputConstraint a Expr -> OutputForm a Expr)
-> OutputConstraint a Expr -> OutputForm a Expr
forall a b. (a -> b) -> a -> b
$ Expr -> a -> OutputConstraint a Expr
forall a b. b -> a -> OutputConstraint a b
Assign Expr
m a
e


getIPBoundary :: Rewrite -> InteractionId -> TCM [IPBoundary' C.Expr]
getIPBoundary :: Rewrite -> InteractionId -> TCM [IPBoundary' Expr]
getIPBoundary Rewrite
norm InteractionId
ii = do
      InteractionPoint
ip <- InteractionId -> TCMT IO InteractionPoint
forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadError TCErr m) =>
InteractionId -> m InteractionPoint
lookupInteractionPoint InteractionId
ii
      case InteractionPoint -> IPClause
ipClause InteractionPoint
ip of
        IPClause { ipcBoundary :: IPClause -> [Closure (IPBoundary' Term)]
ipcBoundary = [Closure (IPBoundary' Term)]
cs } -> do
          [Closure (IPBoundary' Term)]
-> (Closure (IPBoundary' Term) -> TCMT IO (IPBoundary' Expr))
-> TCM [IPBoundary' Expr]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [Closure (IPBoundary' Term)]
cs ((Closure (IPBoundary' Term) -> TCMT IO (IPBoundary' Expr))
 -> TCM [IPBoundary' Expr])
-> (Closure (IPBoundary' Term) -> TCMT IO (IPBoundary' Expr))
-> TCM [IPBoundary' Expr]
forall a b. (a -> b) -> a -> b
$ \ Closure (IPBoundary' Term)
cl -> Closure (IPBoundary' Term)
-> (IPBoundary' Term -> TCMT IO (IPBoundary' Expr))
-> TCMT IO (IPBoundary' Expr)
forall (m :: * -> *) a c b.
(MonadTCEnv m, ReadTCState m, LensClosure a c) =>
c -> (a -> m b) -> m b
enterClosure Closure (IPBoundary' Term)
cl ((IPBoundary' Term -> TCMT IO (IPBoundary' Expr))
 -> TCMT IO (IPBoundary' Expr))
-> (IPBoundary' Term -> TCMT IO (IPBoundary' Expr))
-> TCMT IO (IPBoundary' Expr)
forall a b. (a -> b) -> a -> b
$ \ IPBoundary' Term
b ->
            ReifiesTo (IPBoundary' Term) -> TCMT IO (IPBoundary' Expr)
forall a (m :: * -> *).
(ToConcrete a, MonadAbsToCon m) =>
a -> m (ConOfAbs a)
abstractToConcrete_ (ReifiesTo (IPBoundary' Term) -> TCMT IO (IPBoundary' Expr))
-> TCMT IO (ReifiesTo (IPBoundary' Term))
-> TCMT IO (IPBoundary' Expr)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< IPBoundary' Term -> TCMT IO (ReifiesTo (IPBoundary' Term))
forall i. Reify i => i -> TCM (ReifiesTo i)
reifyUnblocked (IPBoundary' Term -> TCMT IO (ReifiesTo (IPBoundary' Term)))
-> TCMT IO (IPBoundary' Term)
-> TCMT IO (ReifiesTo (IPBoundary' Term))
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Rewrite -> IPBoundary' Term -> TCMT IO (IPBoundary' Term)
forall t.
(Reduce t, Simplify t, Instantiate t, Normalise t) =>
Rewrite -> t -> TCM t
normalForm Rewrite
norm IPBoundary' Term
b
        IPClause
IPNoClause -> [IPBoundary' Expr] -> TCM [IPBoundary' Expr]
forall (m :: * -> *) a. Monad m => a -> m a
return []

-- | Goals and Warnings

getGoals :: TCM Goals
getGoals :: TCM Goals
getGoals = Rewrite -> Rewrite -> TCM Goals
getGoals' Rewrite
AsIs Rewrite
Simplified
  -- visible metas (as-is)
  -- hidden metas (unsolved implicit arguments simplified)

getGoals'
  :: Rewrite    -- ^ Degree of normalization of goals.
  -> Rewrite    -- ^ Degree of normalization of hidden goals.
  -> TCM Goals
getGoals' :: Rewrite -> Rewrite -> TCM Goals
getGoals' Rewrite
normVisible Rewrite
normHidden = do
  [OutputConstraint Expr InteractionId]
visibleMetas <- Rewrite -> TCM [OutputConstraint Expr InteractionId]
typesOfVisibleMetas Rewrite
normVisible
  [OutputConstraint Expr NamedMeta]
hiddenMetas <- Rewrite -> TCM [OutputConstraint Expr NamedMeta]
typesOfHiddenMetas Rewrite
normHidden
  Goals -> TCM Goals
forall (m :: * -> *) a. Monad m => a -> m a
return ([OutputConstraint Expr InteractionId]
visibleMetas, [OutputConstraint Expr NamedMeta]
hiddenMetas)

-- | Print open metas nicely.
showGoals :: Goals -> TCM String
showGoals :: Goals -> TCM ArgName
showGoals ([OutputConstraint Expr InteractionId]
ims, [OutputConstraint Expr NamedMeta]
hms) = do
  [Doc]
di <- [OutputConstraint Expr InteractionId]
-> (OutputConstraint Expr InteractionId -> TCMT IO Doc)
-> TCMT IO [Doc]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [OutputConstraint Expr InteractionId]
ims ((OutputConstraint Expr InteractionId -> TCMT IO Doc)
 -> TCMT IO [Doc])
-> (OutputConstraint Expr InteractionId -> TCMT IO Doc)
-> TCMT IO [Doc]
forall a b. (a -> b) -> a -> b
$ \ OutputConstraint Expr InteractionId
i ->
    InteractionId -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *) a.
(MonadFail m, ReadTCState m, MonadError TCErr m, MonadTCEnv m,
 MonadTrace m) =>
InteractionId -> m a -> m a
withInteractionId (OutputForm Expr InteractionId -> InteractionId
forall a b. OutputForm a b -> b
outputFormId (OutputForm Expr InteractionId -> InteractionId)
-> OutputForm Expr InteractionId -> InteractionId
forall a b. (a -> b) -> a -> b
$ Range
-> [ProblemId]
-> Blocker
-> OutputConstraint Expr InteractionId
-> OutputForm Expr InteractionId
forall a b.
Range
-> [ProblemId] -> Blocker -> OutputConstraint a b -> OutputForm a b
OutputForm Range
forall a. Range' a
noRange [] Blocker
alwaysUnblock OutputConstraint Expr InteractionId
i) (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$
      OutputConstraint Expr InteractionId -> TCMT IO Doc
forall a (m :: * -> *).
(ToConcrete a, Pretty (ConOfAbs a), MonadAbsToCon m) =>
a -> m Doc
prettyATop OutputConstraint Expr InteractionId
i
  Names
dh <- (OutputConstraint Expr NamedMeta -> TCM ArgName)
-> [OutputConstraint Expr NamedMeta] -> TCMT IO Names
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM OutputConstraint Expr NamedMeta -> TCM ArgName
showA' [OutputConstraint Expr NamedMeta]
hms
  ArgName -> TCM ArgName
forall (m :: * -> *) a. Monad m => a -> m a
return (ArgName -> TCM ArgName) -> ArgName -> TCM ArgName
forall a b. (a -> b) -> a -> b
$ Names -> ArgName
unlines (Names -> ArgName) -> Names -> ArgName
forall a b. (a -> b) -> a -> b
$ (Doc -> ArgName) -> [Doc] -> Names
forall a b. (a -> b) -> [a] -> [b]
map Doc -> ArgName
forall a. Show a => a -> ArgName
show [Doc]
di Names -> Names -> Names
forall a. [a] -> [a] -> [a]
++ Names
dh
  where
    showA' :: OutputConstraint A.Expr NamedMeta -> TCM String
    showA' :: OutputConstraint Expr NamedMeta -> TCM ArgName
showA' OutputConstraint Expr NamedMeta
m = do
      let i :: MetaId
i = NamedMeta -> MetaId
nmid (NamedMeta -> MetaId) -> NamedMeta -> MetaId
forall a b. (a -> b) -> a -> b
$ OutputConstraint Expr NamedMeta -> NamedMeta
forall a. OutputConstraint Expr a -> a
namedMetaOf OutputConstraint Expr NamedMeta
m
      Range
r <- MetaId -> TCMT IO Range
forall (m :: * -> *).
(MonadFail m, ReadTCState m) =>
MetaId -> m Range
getMetaRange MetaId
i
      Doc
d <- MetaId -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *) a.
(MonadFail m, MonadTCEnv m, ReadTCState m, MonadTrace m) =>
MetaId -> m a -> m a
withMetaId MetaId
i (OutputConstraint Expr NamedMeta -> TCMT IO Doc
forall a (m :: * -> *).
(ToConcrete a, Pretty (ConOfAbs a), MonadAbsToCon m) =>
a -> m Doc
prettyATop OutputConstraint Expr NamedMeta
m)
      ArgName -> TCM ArgName
forall (m :: * -> *) a. Monad m => a -> m a
return (ArgName -> TCM ArgName) -> ArgName -> TCM ArgName
forall a b. (a -> b) -> a -> b
$ Doc -> ArgName
forall a. Show a => a -> ArgName
show Doc
d ArgName -> ArgName -> ArgName
forall a. [a] -> [a] -> [a]
++ ArgName
"  [ at " ArgName -> ArgName -> ArgName
forall a. [a] -> [a] -> [a]
++ Range -> ArgName
forall a. Pretty a => a -> ArgName
prettyShow Range
r ArgName -> ArgName -> ArgName
forall a. [a] -> [a] -> [a]
++ ArgName
" ]"

getWarningsAndNonFatalErrors :: TCM WarningsAndNonFatalErrors
getWarningsAndNonFatalErrors :: TCM WarningsAndNonFatalErrors
getWarningsAndNonFatalErrors = do
  [TCWarning]
mws <- WhichWarnings -> TCMT IO [TCWarning]
forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadWarning m) =>
WhichWarnings -> m [TCWarning]
getAllWarnings WhichWarnings
AllWarnings
  let notMetaWarnings :: [TCWarning]
notMetaWarnings = (TCWarning -> Bool) -> [TCWarning] -> [TCWarning]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (TCWarning -> Bool) -> TCWarning -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TCWarning -> Bool
isMetaTCWarning) [TCWarning]
mws
  WarningsAndNonFatalErrors -> TCM WarningsAndNonFatalErrors
forall (m :: * -> *) a. Monad m => a -> m a
return (WarningsAndNonFatalErrors -> TCM WarningsAndNonFatalErrors)
-> WarningsAndNonFatalErrors -> TCM WarningsAndNonFatalErrors
forall a b. (a -> b) -> a -> b
$ case [TCWarning]
notMetaWarnings of
    ws :: [TCWarning]
ws@(TCWarning
_:[TCWarning]
_) -> [TCWarning] -> WarningsAndNonFatalErrors
classifyWarnings [TCWarning]
ws
    [TCWarning]
_ -> WarningsAndNonFatalErrors
emptyWarningsAndNonFatalErrors

-- | Collecting the context of the given meta-variable.
getResponseContext
  :: Rewrite      -- ^ Normalise?
  -> InteractionId
  -> TCM [ResponseContextEntry]
getResponseContext :: Rewrite -> InteractionId -> TCM [ResponseContextEntry]
getResponseContext Rewrite
norm InteractionId
ii = InteractionId -> Rewrite -> TCM [ResponseContextEntry]
contextOfMeta InteractionId
ii Rewrite
norm

-- | @getSolvedInteractionPoints True@ returns all solutions,
--   even if just solved by another, non-interaction meta.
--
--   @getSolvedInteractionPoints False@ only returns metas that
--   are solved by a non-meta.

getSolvedInteractionPoints :: Bool -> Rewrite -> TCM [(InteractionId, MetaId, Expr)]
getSolvedInteractionPoints :: Bool -> Rewrite -> TCMT IO [(InteractionId, MetaId, Expr)]
getSolvedInteractionPoints Bool
all Rewrite
norm = [[(InteractionId, MetaId, Expr)]]
-> [(InteractionId, MetaId, Expr)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[(InteractionId, MetaId, Expr)]]
 -> [(InteractionId, MetaId, Expr)])
-> TCMT IO [[(InteractionId, MetaId, Expr)]]
-> TCMT IO [(InteractionId, MetaId, Expr)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
  ((InteractionId, MetaId)
 -> TCMT IO [(InteractionId, MetaId, Expr)])
-> [(InteractionId, MetaId)]
-> TCMT IO [[(InteractionId, MetaId, Expr)]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (InteractionId, MetaId) -> TCMT IO [(InteractionId, MetaId, Expr)]
solution ([(InteractionId, MetaId)]
 -> TCMT IO [[(InteractionId, MetaId, Expr)]])
-> TCMT IO [(InteractionId, MetaId)]
-> TCMT IO [[(InteractionId, MetaId, Expr)]]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCMT IO [(InteractionId, MetaId)]
forall (m :: * -> *). ReadTCState m => m [(InteractionId, MetaId)]
getInteractionIdsAndMetas
  where
    solution :: (InteractionId, MetaId) -> TCMT IO [(InteractionId, MetaId, Expr)]
solution (InteractionId
i, MetaId
m) = do
      MetaVariable
mv <- MetaId -> TCMT IO MetaVariable
forall (m :: * -> *).
(MonadFail m, ReadTCState m) =>
MetaId -> m MetaVariable
lookupMeta MetaId
m
      Closure Range
-> TCMT IO [(InteractionId, MetaId, Expr)]
-> TCMT IO [(InteractionId, MetaId, Expr)]
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadTrace m) =>
Closure Range -> m a -> m a
withMetaInfo (MetaVariable -> Closure Range
getMetaInfo MetaVariable
mv) (TCMT IO [(InteractionId, MetaId, Expr)]
 -> TCMT IO [(InteractionId, MetaId, Expr)])
-> TCMT IO [(InteractionId, MetaId, Expr)]
-> TCMT IO [(InteractionId, MetaId, Expr)]
forall a b. (a -> b) -> a -> b
$ do
        Args
args  <- TCMT IO Args
forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m Args
getContextArgs
        ScopeInfo
scope <- TCMT IO ScopeInfo
forall (m :: * -> *). ReadTCState m => m ScopeInfo
getScope
        let sol :: Term -> TCMT IO [(InteractionId, MetaId, Expr)]
sol Term
v = do
              -- Andreas, 2014-02-17 exclude metas solved by metas
              Term
v <- Term -> TCM Term
forall a (m :: * -> *). (Instantiate a, MonadReduce m) => a -> m a
instantiate Term
v
              let isMeta :: Bool
isMeta = case Term
v of MetaV{} -> Bool
True; Term
_ -> Bool
False
              if Bool
isMeta Bool -> Bool -> Bool
&& Bool -> Bool
not Bool
all then [(InteractionId, MetaId, Expr)]
-> TCMT IO [(InteractionId, MetaId, Expr)]
forall (m :: * -> *) a. Monad m => a -> m a
return [] else do
                Expr
e <- Expr -> TCM Expr
forall (m :: * -> *) a. (MonadTCEnv m, BlankVars a) => a -> m a
blankNotInScope (Expr -> TCM Expr) -> TCM Expr -> TCM Expr
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Term -> TCM Expr
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (Term -> TCM Expr) -> TCM Term -> TCM Expr
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Rewrite -> Term -> TCM Term
forall t.
(Reduce t, Simplify t, Instantiate t, Normalise t) =>
Rewrite -> t -> TCM t
normalForm Rewrite
norm Term
v
                [(InteractionId, MetaId, Expr)]
-> TCMT IO [(InteractionId, MetaId, Expr)]
forall (m :: * -> *) a. Monad m => a -> m a
return [(InteractionId
i, MetaId
m, ScopeInfo -> Expr -> Expr
ScopedExpr ScopeInfo
scope Expr
e)]
            unsol :: TCMT IO [a]
unsol = [a] -> TCMT IO [a]
forall (m :: * -> *) a. Monad m => a -> m a
return []
        case MetaVariable -> MetaInstantiation
mvInstantiation MetaVariable
mv of
          InstV{}                        -> Term -> TCMT IO [(InteractionId, MetaId, Expr)]
sol (MetaId -> Elims -> Term
MetaV MetaId
m (Elims -> Term) -> Elims -> Term
forall a b. (a -> b) -> a -> b
$ (Arg Term -> Elim) -> Args -> Elims
forall a b. (a -> b) -> [a] -> [b]
map Arg Term -> Elim
forall a. Arg a -> Elim' a
Apply Args
args)
          Open{}                         -> TCMT IO [(InteractionId, MetaId, Expr)]
forall {a}. TCMT IO [a]
unsol
          OpenInstance{}                 -> TCMT IO [(InteractionId, MetaId, Expr)]
forall {a}. TCMT IO [a]
unsol
          BlockedConst{}                 -> TCMT IO [(InteractionId, MetaId, Expr)]
forall {a}. TCMT IO [a]
unsol
          PostponedTypeCheckingProblem{} -> TCMT IO [(InteractionId, MetaId, Expr)]
forall {a}. TCMT IO [a]
unsol

typeOfMetaMI :: Rewrite -> MetaId -> TCM (OutputConstraint Expr NamedMeta)
typeOfMetaMI :: Rewrite -> MetaId -> TCM (OutputConstraint Expr NamedMeta)
typeOfMetaMI Rewrite
norm MetaId
mi =
     do MetaVariable
mv <- MetaId -> TCMT IO MetaVariable
forall (m :: * -> *).
(MonadFail m, ReadTCState m) =>
MetaId -> m MetaVariable
lookupMeta MetaId
mi
        Closure Range
-> TCM (OutputConstraint Expr NamedMeta)
-> TCM (OutputConstraint Expr NamedMeta)
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadTrace m) =>
Closure Range -> m a -> m a
withMetaInfo (MetaVariable -> Closure Range
getMetaInfo MetaVariable
mv) (TCM (OutputConstraint Expr NamedMeta)
 -> TCM (OutputConstraint Expr NamedMeta))
-> TCM (OutputConstraint Expr NamedMeta)
-> TCM (OutputConstraint Expr NamedMeta)
forall a b. (a -> b) -> a -> b
$
          MetaVariable
-> Judgement MetaId -> TCM (OutputConstraint Expr NamedMeta)
rewriteJudg MetaVariable
mv (MetaVariable -> Judgement MetaId
mvJudgement MetaVariable
mv)
   where
    rewriteJudg :: MetaVariable -> Judgement MetaId ->
                   TCM (OutputConstraint Expr NamedMeta)
    rewriteJudg :: MetaVariable
-> Judgement MetaId -> TCM (OutputConstraint Expr NamedMeta)
rewriteJudg MetaVariable
mv (HasType MetaId
i Comparison
cmp Type
t) = do
      ArgName
ms <- MetaId -> TCM ArgName
forall (m :: * -> *).
(MonadFail m, ReadTCState m) =>
MetaId -> m ArgName
getMetaNameSuggestion MetaId
i
      -- Andreas, 2019-03-17, issue #3638:
      -- Need to put meta type into correct context _before_ normalizing,
      -- otherwise rewrite rules in parametrized modules will not fire.
      Args
vs <- TCMT IO Args
forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m Args
getContextArgs
      Type
t <- Type
t Type -> Args -> TCMT IO Type
forall a (m :: * -> *).
(PiApplyM a, MonadReduce m, HasBuiltins m) =>
Type -> a -> m Type
`piApplyM` Permutation -> Args -> Args
forall a. Permutation -> [a] -> [a]
permute (Int -> Permutation -> Permutation
takeP (Args -> Int
forall a. Sized a => a -> Int
size Args
vs) (Permutation -> Permutation) -> Permutation -> Permutation
forall a b. (a -> b) -> a -> b
$ MetaVariable -> Permutation
mvPermutation MetaVariable
mv) Args
vs
      Type
t <- Rewrite -> Type -> TCMT IO Type
forall t.
(Reduce t, Simplify t, Instantiate t, Normalise t) =>
Rewrite -> t -> TCM t
normalForm Rewrite
norm Type
t
      let x :: NamedMeta
x = ArgName -> MetaId -> NamedMeta
NamedMeta ArgName
ms MetaId
i
      ArgName -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> TCMT IO Doc -> m ()
reportSDoc ArgName
"interactive.meta" Int
10 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
TP.vcat
        [ ArgName -> TCMT IO Doc
forall (m :: * -> *). Applicative m => ArgName -> m Doc
TP.text (ArgName -> TCMT IO Doc) -> ArgName -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Names -> ArgName
unwords [ArgName
"permuting", MetaId -> ArgName
forall a. Show a => a -> ArgName
show MetaId
i, ArgName
"with", Permutation -> ArgName
forall a. Show a => a -> ArgName
show (Permutation -> ArgName) -> Permutation -> ArgName
forall a b. (a -> b) -> a -> b
$ MetaVariable -> Permutation
mvPermutation MetaVariable
mv]
        , Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
TP.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
TP.vcat
          [ TCMT IO Doc
"len  =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> ArgName -> TCMT IO Doc
forall (m :: * -> *). Applicative m => ArgName -> m Doc
TP.text (Int -> ArgName
forall a. Show a => a -> ArgName
show (Int -> ArgName) -> Int -> ArgName
forall a b. (a -> b) -> a -> b
$ Args -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length Args
vs)
          , TCMT IO Doc
"args =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> Args -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Args
vs
          , TCMT IO Doc
"t    =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
t
          , TCMT IO Doc
"x    =" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> NamedMeta -> TCMT IO Doc
forall (m :: * -> *) a. (Applicative m, Pretty a) => a -> m Doc
TP.pretty NamedMeta
x
          ]
        ]
      ArgName -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> TCMT IO Doc -> m ()
reportSDoc ArgName
"interactive.meta.scope" Int
20 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ ArgName -> TCMT IO Doc
forall (m :: * -> *). Applicative m => ArgName -> m Doc
TP.text (ArgName -> TCMT IO Doc) -> ArgName -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ ScopeInfo -> ArgName
forall a. Show a => a -> ArgName
show (ScopeInfo -> ArgName) -> ScopeInfo -> ArgName
forall a b. (a -> b) -> a -> b
$ MetaVariable -> ScopeInfo
getMetaScope MetaVariable
mv
      -- Andreas, 2016-01-19, issue #1783: need piApplyM instead of just piApply
      NamedMeta -> Expr -> OutputConstraint Expr NamedMeta
forall a b. b -> a -> OutputConstraint a b
OfType NamedMeta
x (Expr -> OutputConstraint Expr NamedMeta)
-> TCM Expr -> TCM (OutputConstraint Expr NamedMeta)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Type -> TCM (ReifiesTo Type)
forall i. Reify i => i -> TCM (ReifiesTo i)
reifyUnblocked Type
t
    rewriteJudg MetaVariable
mv (IsSort MetaId
i Type
t) = do
      ArgName
ms <- MetaId -> TCM ArgName
forall (m :: * -> *).
(MonadFail m, ReadTCState m) =>
MetaId -> m ArgName
getMetaNameSuggestion MetaId
i
      OutputConstraint Expr NamedMeta
-> TCM (OutputConstraint Expr NamedMeta)
forall (m :: * -> *) a. Monad m => a -> m a
return (OutputConstraint Expr NamedMeta
 -> TCM (OutputConstraint Expr NamedMeta))
-> OutputConstraint Expr NamedMeta
-> TCM (OutputConstraint Expr NamedMeta)
forall a b. (a -> b) -> a -> b
$ NamedMeta -> OutputConstraint Expr NamedMeta
forall a b. b -> OutputConstraint a b
JustSort (NamedMeta -> OutputConstraint Expr NamedMeta)
-> NamedMeta -> OutputConstraint Expr NamedMeta
forall a b. (a -> b) -> a -> b
$ ArgName -> MetaId -> NamedMeta
NamedMeta ArgName
ms MetaId
i


typeOfMeta :: Rewrite -> InteractionId -> TCM (OutputConstraint Expr InteractionId)
typeOfMeta :: Rewrite
-> InteractionId -> TCM (OutputConstraint Expr InteractionId)
typeOfMeta Rewrite
norm InteractionId
ii = Rewrite
-> (InteractionId, MetaId)
-> TCM (OutputConstraint Expr InteractionId)
typeOfMeta' Rewrite
norm ((InteractionId, MetaId)
 -> TCM (OutputConstraint Expr InteractionId))
-> (MetaId -> (InteractionId, MetaId))
-> MetaId
-> TCM (OutputConstraint Expr InteractionId)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (InteractionId
ii,) (MetaId -> TCM (OutputConstraint Expr InteractionId))
-> TCMT IO MetaId -> TCM (OutputConstraint Expr InteractionId)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< InteractionId -> TCMT IO MetaId
forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadError TCErr m, MonadTCEnv m) =>
InteractionId -> m MetaId
lookupInteractionId InteractionId
ii

typeOfMeta' :: Rewrite -> (InteractionId, MetaId) -> TCM (OutputConstraint Expr InteractionId)
typeOfMeta' :: Rewrite
-> (InteractionId, MetaId)
-> TCM (OutputConstraint Expr InteractionId)
typeOfMeta' Rewrite
norm (InteractionId
ii, MetaId
mi) = (NamedMeta -> InteractionId)
-> OutputConstraint Expr NamedMeta
-> OutputConstraint Expr InteractionId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\NamedMeta
_ -> InteractionId
ii) (OutputConstraint Expr NamedMeta
 -> OutputConstraint Expr InteractionId)
-> TCM (OutputConstraint Expr NamedMeta)
-> TCM (OutputConstraint Expr InteractionId)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Rewrite -> MetaId -> TCM (OutputConstraint Expr NamedMeta)
typeOfMetaMI Rewrite
norm MetaId
mi

typesOfVisibleMetas :: Rewrite -> TCM [OutputConstraint Expr InteractionId]
typesOfVisibleMetas :: Rewrite -> TCM [OutputConstraint Expr InteractionId]
typesOfVisibleMetas Rewrite
norm =
  TCM [OutputConstraint Expr InteractionId]
-> TCM [OutputConstraint Expr InteractionId]
forall (tcm :: * -> *) a. MonadTCM tcm => TCM a -> tcm a
liftTCM (TCM [OutputConstraint Expr InteractionId]
 -> TCM [OutputConstraint Expr InteractionId])
-> TCM [OutputConstraint Expr InteractionId]
-> TCM [OutputConstraint Expr InteractionId]
forall a b. (a -> b) -> a -> b
$ ((InteractionId, MetaId)
 -> TCM (OutputConstraint Expr InteractionId))
-> [(InteractionId, MetaId)]
-> TCM [OutputConstraint Expr InteractionId]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Rewrite
-> (InteractionId, MetaId)
-> TCM (OutputConstraint Expr InteractionId)
typeOfMeta' Rewrite
norm) ([(InteractionId, MetaId)]
 -> TCM [OutputConstraint Expr InteractionId])
-> TCMT IO [(InteractionId, MetaId)]
-> TCM [OutputConstraint Expr InteractionId]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCMT IO [(InteractionId, MetaId)]
forall (m :: * -> *). ReadTCState m => m [(InteractionId, MetaId)]
getInteractionIdsAndMetas

typesOfHiddenMetas :: Rewrite -> TCM [OutputConstraint Expr NamedMeta]
typesOfHiddenMetas :: Rewrite -> TCM [OutputConstraint Expr NamedMeta]
typesOfHiddenMetas Rewrite
norm = TCM [OutputConstraint Expr NamedMeta]
-> TCM [OutputConstraint Expr NamedMeta]
forall (tcm :: * -> *) a. MonadTCM tcm => TCM a -> tcm a
liftTCM (TCM [OutputConstraint Expr NamedMeta]
 -> TCM [OutputConstraint Expr NamedMeta])
-> TCM [OutputConstraint Expr NamedMeta]
-> TCM [OutputConstraint Expr NamedMeta]
forall a b. (a -> b) -> a -> b
$ do
  [MetaId]
is    <- TCMT IO [MetaId]
forall (m :: * -> *). ReadTCState m => m [MetaId]
getInteractionMetas
  IntMap MetaVariable
store <- (Int -> MetaVariable -> Bool)
-> IntMap MetaVariable -> IntMap MetaVariable
forall a. (Int -> a -> Bool) -> IntMap a -> IntMap a
IntMap.filterWithKey ([MetaId] -> MetaId -> MetaVariable -> Bool
forall {t :: * -> *} {a}.
(Foldable t, Eq a) =>
t a -> a -> MetaVariable -> Bool
openAndImplicit [MetaId]
is (MetaId -> MetaVariable -> Bool)
-> (Int -> MetaId) -> Int -> MetaVariable -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> MetaId
MetaId) (IntMap MetaVariable -> IntMap MetaVariable)
-> TCMT IO (IntMap MetaVariable) -> TCMT IO (IntMap MetaVariable)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TCMT IO (IntMap MetaVariable)
forall (m :: * -> *). ReadTCState m => m (IntMap MetaVariable)
getMetaStore
  (Int -> TCM (OutputConstraint Expr NamedMeta))
-> [Int] -> TCM [OutputConstraint Expr NamedMeta]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Rewrite -> MetaId -> TCM (OutputConstraint Expr NamedMeta)
typeOfMetaMI Rewrite
norm (MetaId -> TCM (OutputConstraint Expr NamedMeta))
-> (Int -> MetaId) -> Int -> TCM (OutputConstraint Expr NamedMeta)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> MetaId
MetaId) ([Int] -> TCM [OutputConstraint Expr NamedMeta])
-> [Int] -> TCM [OutputConstraint Expr NamedMeta]
forall a b. (a -> b) -> a -> b
$ IntMap MetaVariable -> [Int]
forall a. IntMap a -> [Int]
IntMap.keys IntMap MetaVariable
store
  where
  openAndImplicit :: t a -> a -> MetaVariable -> Bool
openAndImplicit t a
is a
x MetaVariable
m | Maybe MetaId -> Bool
forall a. Maybe a -> Bool
isJust (MetaVariable -> Maybe MetaId
mvTwin MetaVariable
m) = Bool
False
  openAndImplicit t a
is a
x MetaVariable
m =
    case MetaVariable -> MetaInstantiation
mvInstantiation MetaVariable
m of
      M.InstV{} -> Bool
False
      MetaInstantiation
M.Open    -> a
x a -> t a -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` t a
is
      MetaInstantiation
M.OpenInstance -> a
x a -> t a -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` t a
is  -- OR: True !?
      M.BlockedConst{} -> Bool
False
      M.PostponedTypeCheckingProblem{} -> Bool
False

-- | Create type of application of new helper function that would solve the goal.
metaHelperType :: Rewrite -> InteractionId -> Range -> String -> TCM (OutputConstraint' Expr Expr)
metaHelperType :: Rewrite
-> InteractionId
-> Range
-> ArgName
-> TCM (OutputConstraint' Expr Expr)
metaHelperType Rewrite
norm InteractionId
ii Range
rng ArgName
s = case ArgName -> Names
words ArgName
s of
  []    -> TCM (OutputConstraint' Expr Expr)
forall {a}. TCMT IO a
failure
  ArgName
f : Names
_ -> InteractionId
-> TCM (OutputConstraint' Expr Expr)
-> TCM (OutputConstraint' Expr Expr)
forall (m :: * -> *) a.
(MonadFail m, ReadTCState m, MonadError TCErr m, MonadTCEnv m,
 MonadTrace m) =>
InteractionId -> m a -> m a
withInteractionId InteractionId
ii (TCM (OutputConstraint' Expr Expr)
 -> TCM (OutputConstraint' Expr Expr))
-> TCM (OutputConstraint' Expr Expr)
-> TCM (OutputConstraint' Expr Expr)
forall a b. (a -> b) -> a -> b
$ do
    ArgName -> TCMT IO ()
ensureName ArgName
f
    A.Application Expr
h [NamedArg Expr]
args <- Expr -> AppView' Expr
A.appView (Expr -> AppView' Expr) -> (Expr -> Expr) -> Expr -> AppView' Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expr -> Expr
getBody (Expr -> Expr) -> (Expr -> Expr) -> Expr -> Expr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expr -> Expr
forall a. ExprLike a => a -> a
deepUnscope (Expr -> AppView' Expr) -> TCM Expr -> TCMT IO (AppView' Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> InteractionId -> Range -> ArgName -> TCM Expr
parseExprIn InteractionId
ii Range
rng (ArgName
"let " ArgName -> ArgName -> ArgName
forall a. [a] -> [a] -> [a]
++ ArgName
f ArgName -> ArgName -> ArgName
forall a. [a] -> [a] -> [a]
++ ArgName
" = _ in " ArgName -> ArgName -> ArgName
forall a. [a] -> [a] -> [a]
++ ArgName
s)
    Name -> Bool
inCxt   <- [Name] -> Name -> Bool
forall a. Ord a => [a] -> a -> Bool
hasElem ([Name] -> Name -> Bool)
-> TCMT IO [Name] -> TCMT IO (Name -> Bool)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TCMT IO [Name]
forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m [Name]
getContextNames
    Args
cxtArgs <- TCMT IO Args
forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m Args
getContextArgs
    Type
a0      <- (Type -> Args -> Type
`piApply` Args
cxtArgs) (Type -> Type) -> TCMT IO Type -> TCMT IO Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (MetaId -> TCMT IO Type
forall (m :: * -> *).
(MonadFail m, ReadTCState m) =>
MetaId -> m Type
getMetaType (MetaId -> TCMT IO Type) -> TCMT IO MetaId -> TCMT IO Type
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< InteractionId -> TCMT IO MetaId
forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadError TCErr m, MonadTCEnv m) =>
InteractionId -> m MetaId
lookupInteractionId InteractionId
ii)
    case (NamedArg Expr -> Maybe Name) -> [NamedArg Expr] -> Maybe [Name]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Expr -> Maybe Name
isVar (Expr -> Maybe Name)
-> (NamedArg Expr -> Expr) -> NamedArg Expr -> Maybe Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NamedArg Expr -> Expr
forall a. NamedArg a -> a
namedArg) [NamedArg Expr]
args Maybe [Name] -> ([Name] -> Maybe [Name]) -> Maybe [Name]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ [Name]
xs -> [Name]
xs [Name] -> Maybe () -> Maybe [Name]
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Bool -> Maybe ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard ((Name -> Bool) -> [Name] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Name -> Bool
inCxt [Name]
xs) of

     -- Andreas, 2019-10-11
     -- If all arguments are variables, there is no need to abstract.
     -- We simply make exactly the given arguments visible and all other hidden.
     Just [Name]
xs -> do
      let inXs :: Name -> Bool
inXs = [Name] -> Name -> Bool
forall a. Ord a => [a] -> a -> Bool
hasElem [Name]
xs
      let hideButXs :: Dom (Name, Type) -> Dom (Name, Type)
hideButXs Dom (Name, Type)
dom = Hiding -> Dom (Name, Type) -> Dom (Name, Type)
forall a. LensHiding a => Hiding -> a -> a
setHiding (if Name -> Bool
inXs (Name -> Bool) -> Name -> Bool
forall a b. (a -> b) -> a -> b
$ (Name, Type) -> Name
forall a b. (a, b) -> a
fst ((Name, Type) -> Name) -> (Name, Type) -> Name
forall a b. (a -> b) -> a -> b
$ Dom (Name, Type) -> (Name, Type)
forall t e. Dom' t e -> e
unDom Dom (Name, Type)
dom then Hiding
NotHidden else Hiding
Hidden) Dom (Name, Type)
dom
      Telescope
tel  <- ListTel -> Telescope
telFromList (ListTel -> Telescope)
-> ([Dom (Name, Type)] -> ListTel)
-> [Dom (Name, Type)]
-> Telescope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Dom (Name, Type) -> Dom (ArgName, Type))
-> [Dom (Name, Type)] -> ListTel
forall a b. (a -> b) -> [a] -> [b]
map (((Name, Type) -> (ArgName, Type))
-> Dom (Name, Type) -> Dom (ArgName, Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Name -> ArgName) -> (Name, Type) -> (ArgName, Type)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first Name -> ArgName
nameToArgName) (Dom (Name, Type) -> Dom (ArgName, Type))
-> (Dom (Name, Type) -> Dom (Name, Type))
-> Dom (Name, Type)
-> Dom (ArgName, Type)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dom (Name, Type) -> Dom (Name, Type)
hideButXs) ([Dom (Name, Type)] -> ListTel)
-> ([Dom (Name, Type)] -> [Dom (Name, Type)])
-> [Dom (Name, Type)]
-> ListTel
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Dom (Name, Type)] -> [Dom (Name, Type)]
forall a. [a] -> [a]
reverse ([Dom (Name, Type)] -> Telescope)
-> TCMT IO [Dom (Name, Type)] -> TCMT IO Telescope
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TCMT IO [Dom (Name, Type)]
forall (m :: * -> *). MonadTCEnv m => m [Dom (Name, Type)]
getContext
      Expr -> Expr -> OutputConstraint' Expr Expr
forall a b. b -> a -> OutputConstraint' a b
OfType' Expr
h (Expr -> OutputConstraint' Expr Expr)
-> TCM Expr -> TCM (OutputConstraint' Expr Expr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
        -- Andreas, 2019-10-11: I actually prefer pi-types over ->.
        (TCEnv -> TCEnv) -> TCM Expr -> TCM Expr
forall (m :: * -> *) a.
MonadTCEnv m =>
(TCEnv -> TCEnv) -> m a -> m a
localTC (\TCEnv
e -> TCEnv
e { envPrintDomainFreePi :: Bool
envPrintDomainFreePi = Bool
True }) (TCM Expr -> TCM Expr) -> TCM Expr -> TCM Expr
forall a b. (a -> b) -> a -> b
$ Type -> TCM (ReifiesTo Type)
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (Type -> TCM (ReifiesTo Type)) -> Type -> TCM (ReifiesTo Type)
forall a b. (a -> b) -> a -> b
$ Telescope -> Type -> Type
telePiVisible Telescope
tel Type
a0

     -- If some arguments are not variables.
     Maybe [Name]
Nothing -> do
      Args
cxtArgs  <- TCMT IO Args
forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m Args
getContextArgs
      -- cleanupType relies on with arguments being named 'w',
      -- so we'd better rename any actual 'w's to avoid confusion.
      Telescope
tel  <- Identity Telescope -> Telescope
forall a. Identity a -> a
runIdentity (Identity Telescope -> Telescope)
-> (Telescope -> Identity Telescope) -> Telescope -> Telescope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ArgName -> Identity ArgName) -> Telescope -> Identity Telescope
forall (f :: * -> *).
Applicative f =>
(ArgName -> f ArgName) -> Telescope -> f Telescope
onNamesTel ArgName -> Identity ArgName
forall {a} {m :: * -> *}. (Eq a, IsString a, Monad m) => a -> m a
unW (Telescope -> Telescope) -> TCMT IO Telescope -> TCMT IO Telescope
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TCMT IO Telescope
forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m Telescope
getContextTelescope
      let a :: Type
a = Identity Type -> Type
forall a. Identity a -> a
runIdentity (Identity Type -> Type) -> (Type -> Identity Type) -> Type -> Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ArgName -> Identity ArgName) -> Type -> Identity Type
forall (m :: * -> *).
Applicative m =>
(ArgName -> m ArgName) -> Type -> m Type
onNames ArgName -> Identity ArgName
forall {a} {m :: * -> *}. (Eq a, IsString a, Monad m) => a -> m a
unW (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$ Type
a0
      [Arg (Term, EqualityView)]
vtys <- (NamedArg Expr -> TCMT IO (Arg (Term, EqualityView)))
-> [NamedArg Expr] -> TCMT IO [Arg (Term, EqualityView)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\ NamedArg Expr
a -> ((Term, Type) -> Arg (Term, EqualityView))
-> TCM (Term, Type) -> TCMT IO (Arg (Term, EqualityView))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ArgInfo -> (Term, EqualityView) -> Arg (Term, EqualityView)
forall e. ArgInfo -> e -> Arg e
Arg (NamedArg Expr -> ArgInfo
forall a. LensArgInfo a => a -> ArgInfo
getArgInfo NamedArg Expr
a) ((Term, EqualityView) -> Arg (Term, EqualityView))
-> ((Term, Type) -> (Term, EqualityView))
-> (Term, Type)
-> Arg (Term, EqualityView)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Type -> EqualityView) -> (Term, Type) -> (Term, EqualityView)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Type -> EqualityView
OtherType) (TCM (Term, Type) -> TCMT IO (Arg (Term, EqualityView)))
-> TCM (Term, Type) -> TCMT IO (Arg (Term, EqualityView))
forall a b. (a -> b) -> a -> b
$ Expr -> TCM (Term, Type)
inferExpr (Expr -> TCM (Term, Type)) -> Expr -> TCM (Term, Type)
forall a b. (a -> b) -> a -> b
$ NamedArg Expr -> Expr
forall a. NamedArg a -> a
namedArg NamedArg Expr
a) [NamedArg Expr]
args
      -- Remember the arity of a
      TelV Telescope
atel Type
_ <- Type -> TCMT IO (TelV Type)
forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Type -> m (TelV Type)
telView Type
a
      let arity :: Int
arity = Telescope -> Int
forall a. Sized a => a -> Int
size Telescope
atel
          (Telescope
delta1, Telescope
delta2, Permutation
_, Type
a', [Arg (Term, EqualityView)]
vtys') = Telescope
-> Type
-> [Arg (Term, EqualityView)]
-> (Telescope, Telescope, Permutation, Type,
    [Arg (Term, EqualityView)])
splitTelForWith Telescope
tel Type
a [Arg (Term, EqualityView)]
vtys
      Expr
a <- (TCEnv -> TCEnv) -> TCM Expr -> TCM Expr
forall (m :: * -> *) a.
MonadTCEnv m =>
(TCEnv -> TCEnv) -> m a -> m a
localTC (\TCEnv
e -> TCEnv
e { envPrintDomainFreePi :: Bool
envPrintDomainFreePi = Bool
True }) (TCM Expr -> TCM Expr) -> TCM Expr -> TCM Expr
forall a b. (a -> b) -> a -> b
$ do
        Type -> TCM Expr
forall i (m :: * -> *).
(Reify i, MonadReify m) =>
i -> m (ReifiesTo i)
reify (Type -> TCM Expr) -> TCMT IO Type -> TCM Expr
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Int -> [NamedArg Expr] -> Type -> TCMT IO Type
cleanupType Int
arity [NamedArg Expr]
args (Type -> TCMT IO Type) -> TCMT IO Type -> TCMT IO Type
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Rewrite -> Type -> TCMT IO Type
forall t.
(Reduce t, Simplify t, Instantiate t, Normalise t) =>
Rewrite -> t -> TCM t
normalForm Rewrite
norm (Type -> TCMT IO Type) -> TCMT IO Type -> TCMT IO Type
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (Type, Int) -> Type
forall a b. (a, b) -> a
fst ((Type, Int) -> Type) -> TCMT IO (Type, Int) -> TCMT IO Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Telescope
-> [Arg (Term, EqualityView)]
-> Telescope
-> Type
-> [(Int, (Term, Term))]
-> TCMT IO (Type, Int)
withFunctionType Telescope
delta1 [Arg (Term, EqualityView)]
vtys' Telescope
delta2 Type
a' []
      ArgName -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> TCMT IO Doc -> m ()
reportSDoc ArgName
"interaction.helper" Int
10 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
TP.vcat ([TCMT IO Doc] -> TCMT IO Doc) -> [TCMT IO Doc] -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$
        let extractOtherType :: EqualityView -> Type
extractOtherType = \case { OtherType Type
a -> Type
a; EqualityView
_ -> Type
forall a. HasCallStack => a
__IMPOSSIBLE__ } in
        let ([Term]
vs, [Type]
as)   = (Arg (Term, EqualityView) -> (Term, Type))
-> [Arg (Term, EqualityView)] -> ([Term], [Type])
forall a b c. (a -> (b, c)) -> [a] -> ([b], [c])
unzipWith ((EqualityView -> Type) -> (Term, EqualityView) -> (Term, Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap EqualityView -> Type
extractOtherType ((Term, EqualityView) -> (Term, Type))
-> (Arg (Term, EqualityView) -> (Term, EqualityView))
-> Arg (Term, EqualityView)
-> (Term, Type)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Arg (Term, EqualityView) -> (Term, EqualityView)
forall e. Arg e -> e
unArg) [Arg (Term, EqualityView)]
vtys in
        let ([Term]
vs', [Type]
as') = (Arg (Term, EqualityView) -> (Term, Type))
-> [Arg (Term, EqualityView)] -> ([Term], [Type])
forall a b c. (a -> (b, c)) -> [a] -> ([b], [c])
unzipWith ((EqualityView -> Type) -> (Term, EqualityView) -> (Term, Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap EqualityView -> Type
extractOtherType ((Term, EqualityView) -> (Term, Type))
-> (Arg (Term, EqualityView) -> (Term, EqualityView))
-> Arg (Term, EqualityView)
-> (Term, Type)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Arg (Term, EqualityView) -> (Term, EqualityView)
forall e. Arg e -> e
unArg) [Arg (Term, EqualityView)]
vtys' in
        [ TCMT IO Doc
"generating helper function"
        , Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
TP.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
"tel    = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> TCMT IO Doc -> TCMT IO Doc
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext (Telescope -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Telescope
tel)
        , Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
TP.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
"a      = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> Expr -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Expr
a
        , Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
TP.nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"vs     = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> [Term] -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM [Term]
vs
        , Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
TP.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
"as     = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> [Type] -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM [Type]
as
        , Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
TP.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
"delta1 = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> TCMT IO Doc -> TCMT IO Doc
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext (Telescope -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Telescope
delta1)
        , Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
TP.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
"delta2 = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> TCMT IO Doc -> TCMT IO Doc
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext (Telescope -> TCMT IO Doc -> TCMT IO Doc
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Telescope
delta1 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Telescope -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Telescope
delta2)
        , Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
TP.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
"a'     = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> TCMT IO Doc -> TCMT IO Doc
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext (Telescope -> TCMT IO Doc -> TCMT IO Doc
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Telescope
delta1 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Telescope -> TCMT IO Doc -> TCMT IO Doc
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Telescope
delta2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Type
a')
        , Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
TP.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
"as'    = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> TCMT IO Doc -> TCMT IO Doc
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext (Telescope -> TCMT IO Doc -> TCMT IO Doc
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Telescope
delta1 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Type] -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM [Type]
as')
        , Int -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Functor m => Int -> m Doc -> m Doc
TP.nest Int
2 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ TCMT IO Doc
"vs'    = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> TCMT IO Doc -> TCMT IO Doc
forall (tcm :: * -> *) a.
(MonadTCEnv tcm, ReadTCState tcm) =>
tcm a -> tcm a
inTopContext (Telescope -> TCMT IO Doc -> TCMT IO Doc
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Telescope
delta1 (TCMT IO Doc -> TCMT IO Doc) -> TCMT IO Doc -> TCMT IO Doc
forall a b. (a -> b) -> a -> b
$ [Term] -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM [Term]
vs')
        ]
      OutputConstraint' Expr Expr -> TCM (OutputConstraint' Expr Expr)
forall (m :: * -> *) a. Monad m => a -> m a
return (OutputConstraint' Expr Expr -> TCM (OutputConstraint' Expr Expr))
-> OutputConstraint' Expr Expr -> TCM (OutputConstraint' Expr Expr)
forall a b. (a -> b) -> a -> b
$ Expr -> Expr -> OutputConstraint' Expr Expr
forall a b. b -> a -> OutputConstraint' a b
OfType' Expr
h Expr
a
  where
    failure :: TCMT IO a
failure = TypeError -> TCMT IO a
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO a) -> TypeError -> TCMT IO a
forall a b. (a -> b) -> a -> b
$ ArgName -> TypeError
GenericError (ArgName -> TypeError) -> ArgName -> TypeError
forall a b. (a -> b) -> a -> b
$ ArgName
"Expected an argument of the form f e1 e2 .. en"
    ensureName :: ArgName -> TCMT IO ()
ensureName ArgName
f = do
      Expr
ce <- Range -> ArgName -> TCM Expr
parseExpr Range
rng ArgName
f
      (TCMT IO () -> (Name -> TCMT IO ()) -> TCMT IO ())
-> (Name -> TCMT IO ()) -> TCMT IO () -> TCMT IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Maybe Name -> TCMT IO () -> (Name -> TCMT IO ()) -> TCMT IO ()
forall a b. Maybe a -> b -> (a -> b) -> b
caseMaybe (Maybe Name -> TCMT IO () -> (Name -> TCMT IO ()) -> TCMT IO ())
-> Maybe Name -> TCMT IO () -> (Name -> TCMT IO ()) -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ Expr -> Maybe Name
isName Expr
ce) (\ Name
_ -> () -> TCMT IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()) (TCMT IO () -> TCMT IO ()) -> TCMT IO () -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ do
         ArgName -> Int -> ArgName -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> ArgName -> m ()
reportSLn ArgName
"interaction.helper" Int
10 (ArgName -> TCMT IO ()) -> ArgName -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ ArgName
"ce = " ArgName -> ArgName -> ArgName
forall a. [a] -> [a] -> [a]
++ Expr -> ArgName
forall a. Show a => a -> ArgName
show Expr
ce
         TCMT IO ()
forall {a}. TCMT IO a
failure
    isVar :: A.Expr -> Maybe A.Name
    isVar :: Expr -> Maybe Name
isVar = \case
      A.Var Name
x -> Name -> Maybe Name
forall a. a -> Maybe a
Just Name
x
      Expr
_ -> Maybe Name
forall a. Maybe a
Nothing
    cleanupType :: Int -> [NamedArg Expr] -> Type -> TCMT IO Type
cleanupType Int
arity [NamedArg Expr]
args Type
t = do
      -- Get the arity of t
      TelV Telescope
ttel Type
_ <- Type -> TCMT IO (TelV Type)
forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Type -> m (TelV Type)
telView Type
t
      -- Compute the number of pi-types subject to stripping.
      let n :: Int
n = Telescope -> Int
forall a. Sized a => a -> Int
size Telescope
ttel Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
arity
      -- It cannot be negative, otherwise we would have performed a
      -- negative number of with-abstractions.
      Bool -> TCMT IO () -> TCMT IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
0) TCMT IO ()
forall a. HasCallStack => a
__IMPOSSIBLE__
      Type -> TCMT IO Type
forall (m :: * -> *) a. Monad m => a -> m a
return (Type -> TCMT IO Type) -> Type -> TCMT IO Type
forall a b. (a -> b) -> a -> b
$ State [NamedArg Expr] Type -> [NamedArg Expr] -> Type
forall s a. State s a -> s -> a
evalState (Type -> State [NamedArg Expr] Type
renameVars (Type -> State [NamedArg Expr] Type)
-> Type -> State [NamedArg Expr] Type
forall a b. (a -> b) -> a -> b
$ Int -> Type -> Type
forall {a}. (Eq a, Num a) => a -> Type -> Type
stripUnused Int
n Type
t) [NamedArg Expr]
args

    getBody :: Expr -> Expr
getBody (A.Let ExprInfo
_ List1 LetBinding
_ Expr
e)      = Expr
e
    getBody Expr
_                  = Expr
forall a. HasCallStack => a
__IMPOSSIBLE__

    -- Strip the non-dependent abstractions from the first n abstractions.
    stripUnused :: a -> Type -> Type
stripUnused a
n (El Sort
s Term
v) = Sort -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El Sort
s (Term -> Type) -> Term -> Type
forall a b. (a -> b) -> a -> b
$ a -> Term -> Term
strip a
n Term
v
    strip :: a -> Term -> Term
strip a
0 = Term -> Term
forall a. a -> a
id
    strip a
n = \case
      I.Pi Dom Type
a Abs Type
b -> case a -> Type -> Type
stripUnused (a
na -> a -> a
forall a. Num a => a -> a -> a
-a
1) (Type -> Type) -> Abs Type -> Abs Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Abs Type
b of
        Abs Type
b | Abs Type -> ArgName
forall a. Abs a -> ArgName
absName Abs Type
b ArgName -> ArgName -> Bool
forall a. Eq a => a -> a -> Bool
== ArgName
"w"   -> Dom Type -> Abs Type -> Term
I.Pi Dom Type
a Abs Type
b
        NoAbs ArgName
_ Type
b              -> Type -> Term
forall t a. Type'' t a -> a
unEl Type
b
        Abs ArgName
s Type
b | Int
0 Int -> Type -> Bool
forall a. Free a => Int -> a -> Bool
`freeIn` Type
b -> Dom Type -> Abs Type -> Term
I.Pi (Dom Type -> Dom Type
forall a. LensHiding a => a -> a
hide Dom Type
a) (ArgName -> Type -> Abs Type
forall a. ArgName -> a -> Abs a
Abs ArgName
s Type
b)
                | Bool
otherwise    -> Impossible -> Term -> Term
forall a. Subst a => Impossible -> a -> a
strengthen Impossible
HasCallStack => Impossible
impossible (Type -> Term
forall t a. Type'' t a -> a
unEl Type
b)
      Term
v -> Term
v  -- todo: handle if goal type is a Pi

    -- renameVars = onNames (stringToArgName <.> renameVar . argNameToString)
    renameVars :: Type -> State [NamedArg Expr] Type
renameVars = (ArgName -> StateT [NamedArg Expr] Identity ArgName)
-> Type -> State [NamedArg Expr] Type
forall (m :: * -> *).
Applicative m =>
(ArgName -> m ArgName) -> Type -> m Type
onNames ArgName -> StateT [NamedArg Expr] Identity ArgName
renameVar

    -- onNames :: Applicative m => (ArgName -> m ArgName) -> Type -> m Type
    onNames :: Applicative m => (String -> m String) -> Type -> m Type
    onNames :: forall (m :: * -> *).
Applicative m =>
(ArgName -> m ArgName) -> Type -> m Type
onNames ArgName -> m ArgName
f (El Sort
s Term
v) = Sort -> Term -> Type
forall t a. Sort' t -> a -> Type'' t a
El Sort
s (Term -> Type) -> m Term -> m Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ArgName -> m ArgName) -> Term -> m Term
forall {f :: * -> *}.
Applicative f =>
(ArgName -> f ArgName) -> Term -> f Term
onNamesTm ArgName -> m ArgName
f Term
v

    -- onNamesTel :: Applicative f => (ArgName -> f ArgName) -> I.Telescope -> f I.Telescope
    onNamesTel :: Applicative f => (String -> f String) -> I.Telescope -> f I.Telescope
    onNamesTel :: forall (f :: * -> *).
Applicative f =>
(ArgName -> f ArgName) -> Telescope -> f Telescope
onNamesTel ArgName -> f ArgName
f Telescope
I.EmptyTel = Telescope -> f Telescope
forall (f :: * -> *) a. Applicative f => a -> f a
pure Telescope
forall a. Tele a
I.EmptyTel
    onNamesTel ArgName -> f ArgName
f (I.ExtendTel Dom Type
a Abs Telescope
b) = Dom Type -> Abs Telescope -> Telescope
forall a. a -> Abs (Tele a) -> Tele a
I.ExtendTel (Dom Type -> Abs Telescope -> Telescope)
-> f (Dom Type) -> f (Abs Telescope -> Telescope)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Type -> f Type) -> Dom Type -> f (Dom Type)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((ArgName -> f ArgName) -> Type -> f Type
forall (m :: * -> *).
Applicative m =>
(ArgName -> m ArgName) -> Type -> m Type
onNames ArgName -> f ArgName
f) Dom Type
a f (Abs Telescope -> Telescope) -> f (Abs Telescope) -> f Telescope
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ArgName -> f ArgName)
-> ((ArgName -> f ArgName) -> Telescope -> f Telescope)
-> Abs Telescope
-> f (Abs Telescope)
forall {f :: * -> *} {t} {a}.
Applicative f =>
(ArgName -> f ArgName)
-> ((ArgName -> f ArgName) -> t -> f a) -> Abs t -> f (Abs a)
onNamesAbs ArgName -> f ArgName
f (ArgName -> f ArgName) -> Telescope -> f Telescope
forall (f :: * -> *).
Applicative f =>
(ArgName -> f ArgName) -> Telescope -> f Telescope
onNamesTel Abs Telescope
b

    onNamesTm :: (ArgName -> f ArgName) -> Term -> f Term
onNamesTm ArgName -> f ArgName
f = \case
      I.Var Int
x Elims
es   -> Int -> Elims -> Term
I.Var Int
x (Elims -> Term) -> f Elims -> f Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ArgName -> f ArgName) -> Elims -> f Elims
onNamesElims ArgName -> f ArgName
f Elims
es
      I.Def QName
q Elims
es   -> QName -> Elims -> Term
I.Def QName
q (Elims -> Term) -> f Elims -> f Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ArgName -> f ArgName) -> Elims -> f Elims
onNamesElims ArgName -> f ArgName
f Elims
es
      I.Con ConHead
c ConInfo
ci Elims
args -> ConHead -> ConInfo -> Elims -> Term
I.Con ConHead
c ConInfo
ci (Elims -> Term) -> f Elims -> f Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ArgName -> f ArgName) -> Elims -> f Elims
onNamesArgs ArgName -> f ArgName
f Elims
args
      I.Lam ArgInfo
i Abs Term
b    -> ArgInfo -> Abs Term -> Term
I.Lam ArgInfo
i (Abs Term -> Term) -> f (Abs Term) -> f Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ArgName -> f ArgName)
-> ((ArgName -> f ArgName) -> Term -> f Term)
-> Abs Term
-> f (Abs Term)
forall {f :: * -> *} {t} {a}.
Applicative f =>
(ArgName -> f ArgName)
-> ((ArgName -> f ArgName) -> t -> f a) -> Abs t -> f (Abs a)
onNamesAbs ArgName -> f ArgName
f (ArgName -> f ArgName) -> Term -> f Term
onNamesTm Abs Term
b
      I.Pi Dom Type
a Abs Type
b     -> Dom Type -> Abs Type -> Term
I.Pi (Dom Type -> Abs Type -> Term)
-> f (Dom Type) -> f (Abs Type -> Term)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Type -> f Type) -> Dom Type -> f (Dom Type)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((ArgName -> f ArgName) -> Type -> f Type
forall (m :: * -> *).
Applicative m =>
(ArgName -> m ArgName) -> Type -> m Type
onNames ArgName -> f ArgName
f) Dom Type
a f (Abs Type -> Term) -> f (Abs Type) -> f Term
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (ArgName -> f ArgName)
-> ((ArgName -> f ArgName) -> Type -> f Type)
-> Abs Type
-> f (Abs Type)
forall {f :: * -> *} {t} {a}.
Applicative f =>
(ArgName -> f ArgName)
-> ((ArgName -> f ArgName) -> t -> f a) -> Abs t -> f (Abs a)
onNamesAbs ArgName -> f ArgName
f (ArgName -> f ArgName) -> Type -> f Type
forall (m :: * -> *).
Applicative m =>
(ArgName -> m ArgName) -> Type -> m Type
onNames Abs Type
b
      I.DontCare Term
v -> Term -> Term
I.DontCare (Term -> Term) -> f Term -> f Term
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ArgName -> f ArgName) -> Term -> f Term
onNamesTm ArgName -> f ArgName
f Term
v
      v :: Term
v@I.Lit{}    -> Term -> f Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
v
      v :: Term
v@I.Sort{}   -> Term -> f Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
v
      v :: Term
v@I.Level{}  -> Term -> f Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
v
      v :: Term
v@I.MetaV{}  -> Term -> f Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
v
      v :: Term
v@I.Dummy{}  -> Term -> f Term
forall (f :: * -> *) a. Applicative f => a -> f a
pure Term
v
    onNamesElims :: (ArgName -> f ArgName) -> Elims -> f Elims
onNamesElims ArgName -> f ArgName
f = (Elim -> f Elim) -> Elims -> f Elims
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Elim -> f Elim) -> Elims -> f Elims)
-> (Elim -> f Elim) -> Elims -> f Elims
forall a b. (a -> b) -> a -> b
$ (Term -> f Term) -> Elim -> f Elim
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Term -> f Term) -> Elim -> f Elim)
-> (Term -> f Term) -> Elim -> f Elim
forall a b. (a -> b) -> a -> b
$ (ArgName -> f ArgName) -> Term -> f Term
onNamesTm ArgName -> f ArgName
f
    onNamesArgs :: (ArgName -> f ArgName) -> Elims -> f Elims
onNamesArgs ArgName -> f ArgName
f  = (Elim -> f Elim) -> Elims -> f Elims
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Elim -> f Elim) -> Elims -> f Elims)
-> (Elim -> f Elim) -> Elims -> f Elims
forall a b. (a -> b) -> a -> b
$ (Term -> f Term) -> Elim -> f Elim
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((Term -> f Term) -> Elim -> f Elim)
-> (Term -> f Term) -> Elim -> f Elim
forall a b. (a -> b) -> a -> b
$ (ArgName -> f ArgName) -> Term -> f Term
onNamesTm ArgName -> f ArgName
f
    onNamesAbs :: (ArgName -> f ArgName)
-> ((ArgName -> f ArgName) -> t -> f a) -> Abs t -> f (Abs a)
onNamesAbs ArgName -> f ArgName
f   = (ArgName -> f ArgName)
-> (ArgName -> f ArgName)
-> ((ArgName -> f ArgName) -> t -> f a)
-> Abs t
-> f (Abs a)
forall {f :: * -> *} {t} {t} {a}.
Applicative f =>
t
-> (ArgName -> f ArgName) -> (t -> t -> f a) -> Abs t -> f (Abs a)
onNamesAbs' ArgName -> f ArgName
f (ArgName -> ArgName
stringToArgName (ArgName -> ArgName)
-> (ArgName -> f ArgName) -> ArgName -> f ArgName
forall (m :: * -> *) b c a.
Functor m =>
(b -> c) -> (a -> m b) -> a -> m c
<.> ArgName -> f ArgName
f (ArgName -> f ArgName)
-> (ArgName -> ArgName) -> ArgName -> f ArgName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArgName -> ArgName
argNameToString)
    onNamesAbs' :: t
-> (ArgName -> f ArgName) -> (t -> t -> f a) -> Abs t -> f (Abs a)
onNamesAbs' t
f ArgName -> f ArgName
f' t -> t -> f a
nd (Abs   ArgName
s t
x) = ArgName -> a -> Abs a
forall a. ArgName -> a -> Abs a
Abs   (ArgName -> a -> Abs a) -> f ArgName -> f (a -> Abs a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ArgName -> f ArgName
f' ArgName
s f (a -> Abs a) -> f a -> f (Abs a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> t -> t -> f a
nd t
f t
x
    onNamesAbs' t
f ArgName -> f ArgName
f' t -> t -> f a
nd (NoAbs ArgName
s t
x) = ArgName -> a -> Abs a
forall a. ArgName -> a -> Abs a
NoAbs (ArgName -> a -> Abs a) -> f ArgName -> f (a -> Abs a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ArgName -> f ArgName
f' ArgName
s f (a -> Abs a) -> f a -> f (Abs a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> t -> t -> f a
nd t
f t
x

    unW :: a -> m a
unW a
"w" = a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
".w"
    unW a
s   = a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
s

    renameVar :: ArgName -> StateT [NamedArg Expr] Identity ArgName
renameVar ArgName
"w" = StateT [NamedArg Expr] Identity ArgName
betterName
    renameVar ArgName
s   = ArgName -> StateT [NamedArg Expr] Identity ArgName
forall (f :: * -> *) a. Applicative f => a -> f a
pure ArgName
s

    betterName :: StateT [NamedArg Expr] Identity ArgName
betterName = do
      [NamedArg Expr]
xs <- StateT [NamedArg Expr] Identity [NamedArg Expr]
forall s (m :: * -> *). MonadState s m => m s
get
      case [NamedArg Expr]
xs of
        []         -> StateT [NamedArg Expr] Identity ArgName
forall a. HasCallStack => a
__IMPOSSIBLE__
        NamedArg Expr
arg : [NamedArg Expr]
args -> do
          [NamedArg Expr] -> StateT [NamedArg Expr] Identity ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put [NamedArg Expr]
args
          ArgName -> StateT [NamedArg Expr] Identity ArgName
forall (m :: * -> *) a. Monad m => a -> m a
return (ArgName -> StateT [NamedArg Expr] Identity ArgName)
-> ArgName -> StateT [NamedArg Expr] Identity ArgName
forall a b. (a -> b) -> a -> b
$ if
            | Arg ArgInfo
_ (Named Maybe NamedName
_ (A.Var Name
x)) <- NamedArg Expr
arg -> Name -> ArgName
forall a. Pretty a => a -> ArgName
prettyShow (Name -> ArgName) -> Name -> ArgName
forall a b. (a -> b) -> a -> b
$ Name -> Name
A.nameConcrete Name
x
            | Just ArgName
x <- NamedArg Expr -> Maybe ArgName
forall a. (LensNamed a, NameOf a ~ NamedName) => a -> Maybe ArgName
bareNameOf NamedArg Expr
arg         -> ArgName -> ArgName
argNameToString ArgName
x
            | Bool
otherwise                        -> ArgName
"w"


-- | Gives a list of names and corresponding types.
--   This list includes not only the local variables in scope, but also the let-bindings.

contextOfMeta :: InteractionId -> Rewrite -> TCM [ResponseContextEntry]
contextOfMeta :: InteractionId -> Rewrite -> TCM [ResponseContextEntry]
contextOfMeta InteractionId
ii Rewrite
norm = InteractionId
-> TCM [ResponseContextEntry] -> TCM [ResponseContextEntry]
forall (m :: * -> *) a.
(MonadFail m, ReadTCState m, MonadError TCErr m, MonadTCEnv m,
 MonadTrace m) =>
InteractionId -> m a -> m a
withInteractionId InteractionId
ii (TCM [ResponseContextEntry] -> TCM [ResponseContextEntry])
-> TCM [ResponseContextEntry] -> TCM [ResponseContextEntry]
forall a b. (a -> b) -> a -> b
$ do
  Closure Range
info <- MetaVariable -> Closure Range
getMetaInfo (MetaVariable -> Closure Range)
-> TCMT IO MetaVariable -> TCMT IO (Closure Range)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (MetaId -> TCMT IO MetaVariable
forall (m :: * -> *).
(MonadFail m, ReadTCState m) =>
MetaId -> m MetaVariable
lookupMeta (MetaId -> TCMT IO MetaVariable)
-> TCMT IO MetaId -> TCMT IO MetaVariable
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< InteractionId -> TCMT IO MetaId
forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadError TCErr m, MonadTCEnv m) =>
InteractionId -> m MetaId
lookupInteractionId InteractionId
ii)
  Closure Range
-> TCM [ResponseContextEntry] -> TCM [ResponseContextEntry]
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadTrace m) =>
Closure Range -> m a -> m a
withMetaInfo Closure Range
info (TCM [ResponseContextEntry] -> TCM [ResponseContextEntry])
-> TCM [ResponseContextEntry] -> TCM [ResponseContextEntry]
forall a b. (a -> b) -> a -> b
$ do
    -- List of local variables.
    [Dom (Name, Type)]
cxt <- TCMT IO [Dom (Name, Type)]
forall (m :: * -> *). MonadTCEnv m => m [Dom (Name, Type)]
getContext
    let localVars :: [Dom (Name, Type)]
localVars = (Int -> Dom (Name, Type) -> Dom (Name, Type))
-> [Int] -> [Dom (Name, Type)] -> [Dom (Name, Type)]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Int -> Dom (Name, Type) -> Dom (Name, Type)
forall a. Subst a => Int -> a -> a
raise [Int
1..] [Dom (Name, Type)]
cxt
    -- List of let-bindings.
    [(Name, Open (Term, Dom Type))]
letVars <- Map Name (Open (Term, Dom Type)) -> [(Name, Open (Term, Dom Type))]
forall k a. Map k a -> [(k, a)]
Map.toAscList (Map Name (Open (Term, Dom Type))
 -> [(Name, Open (Term, Dom Type))])
-> TCMT IO (Map Name (Open (Term, Dom Type)))
-> TCMT IO [(Name, Open (Term, Dom Type))]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (TCEnv -> Map Name (Open (Term, Dom Type)))
-> TCMT IO (Map Name (Open (Term, Dom Type)))
forall (m :: * -> *) a. MonadTCEnv m => (TCEnv -> a) -> m a
asksTC TCEnv -> Map Name (Open (Term, Dom Type))
envLetBindings
    -- Reify the types and filter out bindings without a name.
    [ResponseContextEntry]
-> [ResponseContextEntry] -> [ResponseContextEntry]
forall a. [a] -> [a] -> [a]
(++) ([ResponseContextEntry]
 -> [ResponseContextEntry] -> [ResponseContextEntry])
-> TCM [ResponseContextEntry]
-> TCMT IO ([ResponseContextEntry] -> [ResponseContextEntry])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Dom (Name, Type)]
-> (Dom (Name, Type) -> TCMT IO (Maybe ResponseContextEntry))
-> TCM [ResponseContextEntry]
forall (m :: * -> *) a b.
Monad m =>
[a] -> (a -> m (Maybe b)) -> m [b]
forMaybeM ([Dom (Name, Type)] -> [Dom (Name, Type)]
forall a. [a] -> [a]
reverse [Dom (Name, Type)]
localVars) Dom (Name, Type) -> TCMT IO (Maybe ResponseContextEntry)
mkVar
         TCMT IO ([ResponseContextEntry] -> [ResponseContextEntry])
-> TCM [ResponseContextEntry] -> TCM [ResponseContextEntry]
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> [(Name, Open (Term, Dom Type))]
-> ((Name, Open (Term, Dom Type))
    -> TCMT IO (Maybe ResponseContextEntry))
-> TCM [ResponseContextEntry]
forall (m :: * -> *) a b.
Monad m =>
[a] -> (a -> m (Maybe b)) -> m [b]
forMaybeM [(Name, Open (Term, Dom Type))]
letVars (Name, Open (Term, Dom Type))
-> TCMT IO (Maybe ResponseContextEntry)
mkLet

  where
    mkVar :: Dom (Name, Type) -> TCM (Maybe ResponseContextEntry)
    mkVar :: Dom (Name, Type) -> TCMT IO (Maybe ResponseContextEntry)
mkVar Dom{ domInfo :: forall t e. Dom' t e -> ArgInfo
domInfo = ArgInfo
ai, unDom :: forall t e. Dom' t e -> e
unDom = (Name
name, Type
t) } = do
      if ArgInfo -> Name -> Bool
shouldHide ArgInfo
ai Name
name then Maybe ResponseContextEntry -> TCMT IO (Maybe ResponseContextEntry)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe ResponseContextEntry
forall a. Maybe a
Nothing else ResponseContextEntry -> Maybe ResponseContextEntry
forall a. a -> Maybe a
Just (ResponseContextEntry -> Maybe ResponseContextEntry)
-> TCMT IO ResponseContextEntry
-> TCMT IO (Maybe ResponseContextEntry)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
        let n :: Name
n = Name -> Name
nameConcrete Name
name
        Name
x  <- Name -> TCMT IO (ConOfAbs Name)
forall a (m :: * -> *).
(ToConcrete a, MonadAbsToCon m) =>
a -> m (ConOfAbs a)
abstractToConcrete_ Name
name
        let s :: NameInScope
s = Name -> NameInScope
forall a. LensInScope a => a -> NameInScope
C.isInScope Name
x
        Expr
ty <- Type -> TCM Expr
forall i. Reify i => i -> TCM (ReifiesTo i)
reifyUnblocked (Type -> TCM Expr) -> TCMT IO Type -> TCM Expr
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Rewrite -> Type -> TCMT IO Type
forall t.
(Reduce t, Simplify t, Instantiate t, Normalise t) =>
Rewrite -> t -> TCM t
normalForm Rewrite
norm Type
t
        ResponseContextEntry -> TCMT IO ResponseContextEntry
forall (m :: * -> *) a. Monad m => a -> m a
return (ResponseContextEntry -> TCMT IO ResponseContextEntry)
-> ResponseContextEntry -> TCMT IO ResponseContextEntry
forall a b. (a -> b) -> a -> b
$ Name
-> Name
-> Arg Expr
-> TacticAttr
-> NameInScope
-> ResponseContextEntry
ResponseContextEntry Name
n Name
x (ArgInfo -> Expr -> Arg Expr
forall e. ArgInfo -> e -> Arg e
Arg ArgInfo
ai Expr
ty) TacticAttr
forall a. Maybe a
Nothing NameInScope
s

    mkLet :: (Name, Open (Term, Dom Type)) -> TCM (Maybe ResponseContextEntry)
    mkLet :: (Name, Open (Term, Dom Type))
-> TCMT IO (Maybe ResponseContextEntry)
mkLet (Name
name, Open (Term, Dom Type)
lb) = do
      (Term
tm, !Dom Type
dom) <- Open (Term, Dom Type) -> TCMT IO (Term, Dom Type)
forall a (m :: * -> *).
(TermSubst a, MonadTCEnv m) =>
Open a -> m a
getOpen Open (Term, Dom Type)
lb
      if ArgInfo -> Name -> Bool
shouldHide (Dom Type -> ArgInfo
forall t e. Dom' t e -> ArgInfo
domInfo Dom Type
dom) Name
name then Maybe ResponseContextEntry -> TCMT IO (Maybe ResponseContextEntry)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe ResponseContextEntry
forall a. Maybe a
Nothing else ResponseContextEntry -> Maybe ResponseContextEntry
forall a. a -> Maybe a
Just (ResponseContextEntry -> Maybe ResponseContextEntry)
-> TCMT IO ResponseContextEntry
-> TCMT IO (Maybe ResponseContextEntry)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> do
        let n :: Name
n = Name -> Name
nameConcrete Name
name
        Name
x  <- Name -> TCMT IO (ConOfAbs Name)
forall a (m :: * -> *).
(ToConcrete a, MonadAbsToCon m) =>
a -> m (ConOfAbs a)
abstractToConcrete_ Name
name
        let s :: NameInScope
s = Name -> NameInScope
forall a. LensInScope a => a -> NameInScope
C.isInScope Name
x
        Arg Expr
ty <- Dom Type -> TCMT IO (Arg Expr)
forall i. Reify i => i -> TCM (ReifiesTo i)
reifyUnblocked (Dom Type -> TCMT IO (Arg Expr))
-> TCMT IO (Dom Type) -> TCMT IO (Arg Expr)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Rewrite -> Dom Type -> TCMT IO (Dom Type)
forall t.
(Reduce t, Simplify t, Instantiate t, Normalise t) =>
Rewrite -> t -> TCM t
normalForm Rewrite
norm Dom Type
dom
        Expr
v  <- Term -> TCM Expr
forall i. Reify i => i -> TCM (ReifiesTo i)
reifyUnblocked (Term -> TCM Expr) -> TCM Term -> TCM Expr
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Rewrite -> Term -> TCM Term
forall t.
(Reduce t, Simplify t, Instantiate t, Normalise t) =>
Rewrite -> t -> TCM t
normalForm Rewrite
norm Term
tm
        ResponseContextEntry -> TCMT IO ResponseContextEntry
forall (m :: * -> *) a. Monad m => a -> m a
return (ResponseContextEntry -> TCMT IO ResponseContextEntry)
-> ResponseContextEntry -> TCMT IO ResponseContextEntry
forall a b. (a -> b) -> a -> b
$ Name
-> Name
-> Arg Expr
-> TacticAttr
-> NameInScope
-> ResponseContextEntry
ResponseContextEntry Name
n Name
x Arg Expr
ty (Expr -> TacticAttr
forall a. a -> Maybe a
Just Expr
v) NameInScope
s

    shouldHide :: ArgInfo -> A.Name -> Bool
    shouldHide :: ArgInfo -> Name -> Bool
shouldHide ArgInfo
ai Name
n = Bool -> Bool
not (ArgInfo -> Bool
forall a. LensHiding a => a -> Bool
isInstance ArgInfo
ai) Bool -> Bool -> Bool
&& (Name -> Bool
forall a. IsNoName a => a -> Bool
isNoName Name
n Bool -> Bool -> Bool
|| Name -> Bool
nameIsRecordName Name
n)

-- | Returns the type of the expression in the current environment
--   We wake up irrelevant variables just in case the user want to
--   invoke that command in an irrelevant context.
typeInCurrent :: Rewrite -> Expr -> TCM Expr
typeInCurrent :: Rewrite -> Expr -> TCM Expr
typeInCurrent Rewrite
norm Expr
e =
    do  (Term
_,Type
t) <- TCM (Term, Type) -> TCM (Term, Type)
forall (m :: * -> *) a. MonadTCEnv m => m a -> m a
wakeIrrelevantVars (TCM (Term, Type) -> TCM (Term, Type))
-> TCM (Term, Type) -> TCM (Term, Type)
forall a b. (a -> b) -> a -> b
$ Expr -> TCM (Term, Type)
inferExpr Expr
e
        Type
v <- Rewrite -> Type -> TCMT IO Type
forall t.
(Reduce t, Simplify t, Instantiate t, Normalise t) =>
Rewrite -> t -> TCM t
normalForm Rewrite
norm Type
t
        Type -> TCM (ReifiesTo Type)
forall i. Reify i => i -> TCM (ReifiesTo i)
reifyUnblocked Type
v



typeInMeta :: InteractionId -> Rewrite -> Expr -> TCM Expr
typeInMeta :: InteractionId -> Rewrite -> Expr -> TCM Expr
typeInMeta InteractionId
ii Rewrite
norm Expr
e =
   do   MetaId
m <- InteractionId -> TCMT IO MetaId
forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadError TCErr m, MonadTCEnv m) =>
InteractionId -> m MetaId
lookupInteractionId InteractionId
ii
        Closure Range
mi <- MetaVariable -> Closure Range
getMetaInfo (MetaVariable -> Closure Range)
-> TCMT IO MetaVariable -> TCMT IO (Closure Range)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MetaId -> TCMT IO MetaVariable
forall (m :: * -> *).
(MonadFail m, ReadTCState m) =>
MetaId -> m MetaVariable
lookupMeta MetaId
m
        Closure Range -> TCM Expr -> TCM Expr
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadTrace m) =>
Closure Range -> m a -> m a
withMetaInfo Closure Range
mi (TCM Expr -> TCM Expr) -> TCM Expr -> TCM Expr
forall a b. (a -> b) -> a -> b
$
            Rewrite -> Expr -> TCM Expr
typeInCurrent Rewrite
norm Expr
e

-- | The intro tactic.
--
-- Returns the terms (as strings) that can be
-- used to refine the goal. Uses the coverage checker
-- to find out which constructors are possible.
--
introTactic :: Bool -> InteractionId -> TCM [String]
introTactic :: Bool -> InteractionId -> TCMT IO Names
introTactic Bool
pmLambda InteractionId
ii = do
  MetaId
mi <- InteractionId -> TCMT IO MetaId
forall (m :: * -> *).
(MonadFail m, ReadTCState m, MonadError TCErr m, MonadTCEnv m) =>
InteractionId -> m MetaId
lookupInteractionId InteractionId
ii
  MetaVariable
mv <- MetaId -> TCMT IO MetaVariable
forall (m :: * -> *).
(MonadFail m, ReadTCState m) =>
MetaId -> m MetaVariable
lookupMeta MetaId
mi
  Closure Range -> TCMT IO Names -> TCMT IO Names
forall (m :: * -> *) a.
(MonadTCEnv m, ReadTCState m, MonadTrace m) =>
Closure Range -> m a -> m a
withMetaInfo (MetaVariable -> Closure Range
getMetaInfo MetaVariable
mv) (TCMT IO Names -> TCMT IO Names) -> TCMT IO Names -> TCMT IO Names
forall a b. (a -> b) -> a -> b
$ case MetaVariable -> Judgement MetaId
mvJudgement MetaVariable
mv of
    HasType MetaId
_ Comparison
_ Type
t -> do
        Type
t <- Type -> TCMT IO Type
forall a (m :: * -> *). (Reduce a, MonadReduce m) => a -> m a
reduce (Type -> TCMT IO Type) -> TCMT IO Type -> TCMT IO Type
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Type -> Args -> TCMT IO Type
forall a (m :: * -> *).
(PiApplyM a, MonadReduce m, HasBuiltins m) =>
Type -> a -> m Type
piApplyM Type
t (Args -> TCMT IO Type) -> TCMT IO Args -> TCMT IO Type
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TCMT IO Args
forall (m :: * -> *). (Applicative m, MonadTCEnv m) => m Args
getContextArgs
        -- Andreas, 2013-03-05 Issue 810: skip hidden domains in introduction
        -- of constructor.
        TelV Telescope
tel' Type
t <- Int -> (Dom Type -> Bool) -> Type -> TCMT IO (TelV Type)
forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Int -> (Dom Type -> Bool) -> Type -> m (TelV Type)
telViewUpTo' (-Int
1) Dom Type -> Bool
forall a. LensHiding a => a -> Bool
notVisible Type
t
        -- if we cannot introduce a constructor, we try a lambda
        let fallback :: TCMT IO Names
fallback = do
              Bool
cubical <- Maybe Cubical -> Bool
forall a. Maybe a -> Bool
isJust (Maybe Cubical -> Bool)
-> (PragmaOptions -> Maybe Cubical) -> PragmaOptions -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PragmaOptions -> Maybe Cubical
optCubical (PragmaOptions -> Bool) -> TCMT IO PragmaOptions -> TCMT IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TCMT IO PragmaOptions
forall (m :: * -> *). HasOptions m => m PragmaOptions
pragmaOptions
              TelV Telescope
tel Type
_ <- (if Bool
cubical then Type -> TCMT IO (TelV Type)
forall (m :: * -> *). PureTCM m => Type -> m (TelV Type)
telViewPath else Type -> TCMT IO (TelV Type)
forall (m :: * -> *).
(MonadReduce m, MonadAddContext m) =>
Type -> m (TelV Type)
telView) Type
t
              ArgName -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> TCMT IO Doc -> m ()
reportSDoc ArgName
"interaction.intro" Int
20 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
TP.sep
                [ TCMT IO Doc
"introTactic/fallback"
                , TCMT IO Doc
"tel' = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> Telescope -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Telescope
tel'
                , TCMT IO Doc
"tel  = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> Telescope -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Telescope
tel
                ]
              case (Telescope
tel', Telescope
tel) of
                (Telescope
EmptyTel, Telescope
EmptyTel) -> Names -> TCMT IO Names
forall (m :: * -> *) a. Monad m => a -> m a
return []
                (Telescope, Telescope)
_ -> ListTel -> TCMT IO Names
introFun (Telescope -> ListTel
forall t. Tele (Dom t) -> [Dom (ArgName, t)]
telToList Telescope
tel' ListTel -> ListTel -> ListTel
forall a. [a] -> [a] -> [a]
++ Telescope -> ListTel
forall t. Tele (Dom t) -> [Dom (ArgName, t)]
telToList Telescope
tel)

        case Type -> Term
forall t a. Type'' t a -> a
unEl Type
t of
          I.Def QName
d Elims
_ -> do
            Definition
def <- QName -> TCMT IO Definition
forall (m :: * -> *). HasConstInfo m => QName -> m Definition
getConstInfo QName
d
            case Definition -> Defn
theDef Definition
def of
              Datatype{}    -> Telescope -> TCMT IO Names -> TCMT IO Names
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Telescope
tel' (TCMT IO Names -> TCMT IO Names) -> TCMT IO Names -> TCMT IO Names
forall a b. (a -> b) -> a -> b
$ Type -> TCMT IO Names
introData Type
t
              Record{ recNamedCon :: Defn -> Bool
recNamedCon = Bool
name }
                | Bool
name      -> Telescope -> TCMT IO Names -> TCMT IO Names
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Telescope
tel' (TCMT IO Names -> TCMT IO Names) -> TCMT IO Names -> TCMT IO Names
forall a b. (a -> b) -> a -> b
$ Type -> TCMT IO Names
introData Type
t
                | Bool
otherwise -> Telescope -> TCMT IO Names -> TCMT IO Names
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Telescope
tel' (TCMT IO Names -> TCMT IO Names) -> TCMT IO Names -> TCMT IO Names
forall a b. (a -> b) -> a -> b
$ QName -> TCMT IO Names
introRec QName
d
              Defn
_ -> TCMT IO Names
fallback
          Term
_ -> TCMT IO Names
fallback
     TCMT IO Names -> (TCErr -> TCMT IO Names) -> TCMT IO Names
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
`catchError` \TCErr
_ -> Names -> TCMT IO Names
forall (m :: * -> *) a. Monad m => a -> m a
return []
    Judgement MetaId
_ -> TCMT IO Names
forall a. HasCallStack => a
__IMPOSSIBLE__
  where
    conName :: [NamedArg SplitPattern] -> [I.ConHead]
    conName :: [NamedArg SplitPattern] -> [ConHead]
conName [NamedArg SplitPattern
p] = [ ConHead
c | I.ConP ConHead
c ConPatternInfo
_ [NamedArg SplitPattern]
_ <- [NamedArg SplitPattern -> SplitPattern
forall a. NamedArg a -> a
namedArg NamedArg SplitPattern
p] ]
    conName [NamedArg SplitPattern]
_   = [ConHead]
forall a. HasCallStack => a
__IMPOSSIBLE__

    showUnambiguousConName :: ConHead -> f ArgName
showUnambiguousConName ConHead
v =
       Doc -> ArgName
render (Doc -> ArgName) -> (QName -> Doc) -> QName -> ArgName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QName -> Doc
forall a. Pretty a => a -> Doc
pretty (QName -> ArgName) -> f QName -> f ArgName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> AbsToCon QName -> f QName
forall (m :: * -> *) c. MonadAbsToCon m => AbsToCon c -> m c
runAbsToCon (AllowAmbiguousNames -> QName -> AbsToCon QName
lookupQName AllowAmbiguousNames
AmbiguousNothing (QName -> AbsToCon QName) -> QName -> AbsToCon QName
forall a b. (a -> b) -> a -> b
$ ConHead -> QName
I.conName ConHead
v)

    showTCM :: PrettyTCM a => a -> TCM String
    showTCM :: forall a. PrettyTCM a => a -> TCM ArgName
showTCM a
v = Doc -> ArgName
render (Doc -> ArgName) -> TCMT IO Doc -> TCM ArgName
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM a
v

    introFun :: ListTel -> TCM [String]
    introFun :: ListTel -> TCMT IO Names
introFun ListTel
tel = Telescope -> TCMT IO Names -> TCMT IO Names
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Telescope
tel' (TCMT IO Names -> TCMT IO Names) -> TCMT IO Names -> TCMT IO Names
forall a b. (a -> b) -> a -> b
$ do
        ArgName -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> TCMT IO Doc -> m ()
reportSDoc ArgName
"interaction.intro" Int
10 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ do TCMT IO Doc
"introFun" TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> Telescope -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM (ListTel -> Telescope
telFromList ListTel
tel)
        Bool
imp <- TCMT IO Bool
forall (m :: * -> *). HasOptions m => m Bool
showImplicitArguments
        let okHiding0 :: Hiding -> Bool
okHiding0 Hiding
h = Bool
imp Bool -> Bool -> Bool
|| Hiding
h Hiding -> Hiding -> Bool
forall a. Eq a => a -> a -> Bool
== Hiding
NotHidden
            -- if none of the vars were displayed, we would get a parse error
            -- thus, we switch to displaying all
            allHidden :: Bool
allHidden   = Bool -> Bool
not ((Hiding -> Bool) -> [Hiding] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Hiding -> Bool
okHiding0 [Hiding]
hs)
            okHiding :: Hiding -> Bool
okHiding    = if Bool
allHidden then Bool -> Hiding -> Bool
forall a b. a -> b -> a
const Bool
True else Hiding -> Bool
okHiding0
        Names
vars <- -- setShowImplicitArguments (imp || allHidden) $
                (if Bool
allHidden then TCMT IO Names -> TCMT IO Names
forall (m :: * -> *) a. ReadTCState m => m a -> m a
withShowAllArguments else TCMT IO Names -> TCMT IO Names
forall a. a -> a
id) (TCMT IO Names -> TCMT IO Names) -> TCMT IO Names -> TCMT IO Names
forall a b. (a -> b) -> a -> b
$
                  (Arg Term -> TCM ArgName) -> Args -> TCMT IO Names
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Arg Term -> TCM ArgName
forall a. PrettyTCM a => a -> TCM ArgName
showTCM [ Hiding -> Arg Term -> Arg Term
forall a. LensHiding a => Hiding -> a -> a
setHiding Hiding
h (Arg Term -> Arg Term) -> Arg Term -> Arg Term
forall a b. (a -> b) -> a -> b
$ Term -> Arg Term
forall a. a -> Arg a
defaultArg (Term -> Arg Term) -> Term -> Arg Term
forall a b. (a -> b) -> a -> b
$ Int -> Term
var Int
i :: Arg Term
                               | (Hiding
h, Int
i) <- [Hiding] -> [Int] -> [(Hiding, Int)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Hiding]
hs ([Int] -> [(Hiding, Int)]) -> [Int] -> [(Hiding, Int)]
forall a b. (a -> b) -> a -> b
$ Int -> [Int]
forall a. Integral a => a -> [a]
downFrom Int
n
                               , Hiding -> Bool
okHiding Hiding
h
                               ]
        if Bool
pmLambda
           then Names -> TCMT IO Names
forall (m :: * -> *) a. Monad m => a -> m a
return [ Names -> ArgName
unwords (Names -> ArgName) -> Names -> ArgName
forall a b. (a -> b) -> a -> b
$ [ArgName
"λ", ArgName
"{"] Names -> Names -> Names
forall a. [a] -> [a] -> [a]
++ Names
vars Names -> Names -> Names
forall a. [a] -> [a] -> [a]
++ [ArgName
"→", ArgName
"?", ArgName
"}"] ]
           else Names -> TCMT IO Names
forall (m :: * -> *) a. Monad m => a -> m a
return [ Names -> ArgName
unwords (Names -> ArgName) -> Names -> ArgName
forall a b. (a -> b) -> a -> b
$ [ArgName
"λ"]      Names -> Names -> Names
forall a. [a] -> [a] -> [a]
++ Names
vars Names -> Names -> Names
forall a. [a] -> [a] -> [a]
++ [ArgName
"→", ArgName
"?"] ]
      where
        n :: Int
n = ListTel -> Int
forall a. Sized a => a -> Int
size ListTel
tel
        hs :: [Hiding]
hs   = (Dom (ArgName, Type) -> Hiding) -> ListTel -> [Hiding]
forall a b. (a -> b) -> [a] -> [b]
map Dom (ArgName, Type) -> Hiding
forall a. LensHiding a => a -> Hiding
getHiding ListTel
tel
        tel' :: Telescope
tel' = ListTel -> Telescope
telFromList [ ((ArgName, Type) -> (ArgName, Type))
-> Dom (ArgName, Type) -> Dom (ArgName, Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (ArgName, Type) -> (ArgName, Type)
forall {a} {b}. (Eq a, IsString a) => (a, b) -> (a, b)
makeName Dom (ArgName, Type)
b | Dom (ArgName, Type)
b <- ListTel
tel ]
        makeName :: (a, b) -> (a, b)
makeName (a
"_", b
t) = (a
"x", b
t)
        makeName (a
x, b
t)   = (a
x, b
t)

    introData :: I.Type -> TCM [String]
    introData :: Type -> TCMT IO Names
introData Type
t = do
      let tel :: Telescope
tel  = ListTel -> Telescope
telFromList [(ArgName, Type) -> Dom (ArgName, Type)
forall a. a -> Dom a
defaultDom (ArgName
"_", Type
t)]
          pat :: [Arg (Named name DeBruijnPattern)]
pat  = [Named name DeBruijnPattern -> Arg (Named name DeBruijnPattern)
forall a. a -> Arg a
defaultArg (Named name DeBruijnPattern -> Arg (Named name DeBruijnPattern))
-> Named name DeBruijnPattern -> Arg (Named name DeBruijnPattern)
forall a b. (a -> b) -> a -> b
$ DeBruijnPattern -> Named name DeBruijnPattern
forall a name. a -> Named name a
unnamed (DeBruijnPattern -> Named name DeBruijnPattern)
-> DeBruijnPattern -> Named name DeBruijnPattern
forall a b. (a -> b) -> a -> b
$ ArgName -> Int -> DeBruijnPattern
forall a. DeBruijn a => ArgName -> Int -> a
debruijnNamedVar ArgName
"c" Int
0]
      Either SplitError Covering
r <- Induction
-> Telescope
-> [NamedArg DeBruijnPattern]
-> TCM (Either SplitError Covering)
splitLast Induction
CoInductive Telescope
tel [NamedArg DeBruijnPattern]
forall {name}. [Arg (Named name DeBruijnPattern)]
pat
      case Either SplitError Covering
r of
        Left SplitError
err -> Names -> TCMT IO Names
forall (m :: * -> *) a. Monad m => a -> m a
return []
        Right Covering
cov ->
           (ConHead -> TCM ArgName) -> [ConHead] -> TCMT IO Names
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ConHead -> TCM ArgName
forall {f :: * -> *}.
(MonadTCEnv f, ReadTCState f, MonadStConcreteNames f, HasOptions f,
 HasBuiltins f, MonadDebug f) =>
ConHead -> f ArgName
showUnambiguousConName ([ConHead] -> TCMT IO Names) -> [ConHead] -> TCMT IO Names
forall a b. (a -> b) -> a -> b
$ (SplitClause -> [ConHead]) -> [SplitClause] -> [ConHead]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ([NamedArg SplitPattern] -> [ConHead]
conName ([NamedArg SplitPattern] -> [ConHead])
-> (SplitClause -> [NamedArg SplitPattern])
-> SplitClause
-> [ConHead]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SplitClause -> [NamedArg SplitPattern]
scPats) ([SplitClause] -> [ConHead]) -> [SplitClause] -> [ConHead]
forall a b. (a -> b) -> a -> b
$ Covering -> [SplitClause]
splitClauses Covering
cov

    introRec :: QName -> TCM [String]
    introRec :: QName -> TCMT IO Names
introRec QName
d = do
      [Dom Name]
hfs <- QName -> TCMT IO [Dom Name]
forall (m :: * -> *).
(HasConstInfo m, ReadTCState m, MonadError TCErr m) =>
QName -> m [Dom Name]
getRecordFieldNames QName
d
      [Name]
fs <- TCMT IO Bool -> TCMT IO [Name] -> TCMT IO [Name] -> TCMT IO [Name]
forall (m :: * -> *) a. Monad m => m Bool -> m a -> m a -> m a
ifM TCMT IO Bool
forall (m :: * -> *). HasOptions m => m Bool
showImplicitArguments
            ([Name] -> TCMT IO [Name]
forall (m :: * -> *) a. Monad m => a -> m a
return ([Name] -> TCMT IO [Name]) -> [Name] -> TCMT IO [Name]
forall a b. (a -> b) -> a -> b
$ (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]
hfs)
            ([Name] -> TCMT IO [Name]
forall (m :: * -> *) a. Monad m => a -> m a
return [ Dom Name -> Name
forall t e. Dom' t e -> e
unDom Dom Name
a | Dom Name
a <- [Dom Name]
hfs, Dom Name -> Bool
forall a. LensHiding a => a -> Bool
visible Dom Name
a ])
      let e :: Expr
e = Range -> RecordAssignments -> Expr
C.Rec Range
forall a. Range' a
noRange (RecordAssignments -> Expr) -> RecordAssignments -> Expr
forall a b. (a -> b) -> a -> b
$ [Name] -> (Name -> RecordAssignment) -> RecordAssignments
forall (m :: * -> *) a b. Functor m => m a -> (a -> b) -> m b
for [Name]
fs ((Name -> RecordAssignment) -> RecordAssignments)
-> (Name -> RecordAssignment) -> RecordAssignments
forall a b. (a -> b) -> a -> b
$ \ Name
f ->
            FieldAssignment -> RecordAssignment
forall a b. a -> Either a b
Left (FieldAssignment -> RecordAssignment)
-> FieldAssignment -> RecordAssignment
forall a b. (a -> b) -> a -> b
$ Name -> Expr -> FieldAssignment
forall a. Name -> a -> FieldAssignment' a
C.FieldAssignment Name
f (Expr -> FieldAssignment) -> Expr -> FieldAssignment
forall a b. (a -> b) -> a -> b
$ Range -> Maybe Int -> Expr
C.QuestionMark Range
forall a. Range' a
noRange Maybe Int
forall a. Maybe a
Nothing
      Names -> TCMT IO Names
forall (m :: * -> *) a. Monad m => a -> m a
return [ Expr -> ArgName
forall a. Pretty a => a -> ArgName
prettyShow Expr
e ]
      -- Andreas, 2019-02-25, remark:
      -- prettyShow is ok here since we are just printing something like
      -- record { f1 = ? ; ... ; fn = ?}
      -- which does not involve any qualified names, and the fi are C.Name.

-- | Runs the given computation as if in an anonymous goal at the end
--   of the top-level module.
--
--   Sets up current module, scope, and context.
atTopLevel :: TCM a -> TCM a
atTopLevel :: forall a. TCM a -> TCM a
atTopLevel TCM a
m = TCM a -> TCM a
forall (m :: * -> *) a. MonadTCEnv m => m a -> m a
inConcreteMode (TCM a -> TCM a) -> TCM a -> TCM a
forall a b. (a -> b) -> a -> b
$ do
  let err :: TCMT IO a
err = TypeError -> TCMT IO a
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO a) -> TypeError -> TCMT IO a
forall a b. (a -> b) -> a -> b
$ ArgName -> TypeError
GenericError ArgName
"The file has not been loaded yet."
  TCMT IO (Maybe ModuleName)
-> TCM a -> (ModuleName -> TCM a) -> TCM a
forall (m :: * -> *) a b.
Monad m =>
m (Maybe a) -> m b -> (a -> m b) -> m b
caseMaybeM (Lens' (Maybe ModuleName) TCState -> TCMT IO (Maybe ModuleName)
forall (m :: * -> *) a. ReadTCState m => Lens' a TCState -> m a
useTC Lens' (Maybe ModuleName) TCState
stCurrentModule) TCM a
forall {a}. TCMT IO a
err ((ModuleName -> TCM a) -> TCM a) -> (ModuleName -> TCM a) -> TCM a
forall a b. (a -> b) -> a -> b
$ \ ModuleName
current -> do
    TCMT IO (Maybe ModuleInfo)
-> TCM a -> (ModuleInfo -> TCM a) -> TCM a
forall (m :: * -> *) a b.
Monad m =>
m (Maybe a) -> m b -> (a -> m b) -> m b
caseMaybeM (TopLevelModuleName -> TCMT IO (Maybe ModuleInfo)
forall (m :: * -> *).
ReadTCState m =>
TopLevelModuleName -> m (Maybe ModuleInfo)
getVisitedModule (TopLevelModuleName -> TCMT IO (Maybe ModuleInfo))
-> TopLevelModuleName -> TCMT IO (Maybe ModuleInfo)
forall a b. (a -> b) -> a -> b
$ ModuleName -> TopLevelModuleName
toTopLevelModuleName ModuleName
current) TCM a
forall a. HasCallStack => a
__IMPOSSIBLE__ ((ModuleInfo -> TCM a) -> TCM a) -> (ModuleInfo -> TCM a) -> TCM a
forall a b. (a -> b) -> a -> b
$ \ ModuleInfo
mi -> do
      let scope :: ScopeInfo
scope = Interface -> ScopeInfo
iInsideScope (Interface -> ScopeInfo) -> Interface -> ScopeInfo
forall a b. (a -> b) -> a -> b
$ ModuleInfo -> Interface
miInterface ModuleInfo
mi
      Telescope
tel <- ModuleName -> TCMT IO Telescope
forall (m :: * -> *).
(Functor m, ReadTCState m) =>
ModuleName -> m Telescope
lookupSection ModuleName
current
      -- Get the names of the local variables from @scope@
      -- and put them into the context.
      --
      -- Andreas, 2017-04-24, issue #2552:
      --
      -- Delete the let-bound ones, since they are not represented
      -- in the module telescope.
      --
      -- This is a temporary fix until a better solution is available,
      -- e.g., when the module telescope represents let-bound variables.
      --
      -- Unfortunately, referring to let-bound variables
      -- from the top level module telescope will for now result in a not-in-scope error.
      let names :: [A.Name]
          names :: [Name]
names = (LocalVar -> Name) -> [LocalVar] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map LocalVar -> Name
localVar ([LocalVar] -> [Name]) -> [LocalVar] -> [Name]
forall a b. (a -> b) -> a -> b
$ (LocalVar -> Bool) -> [LocalVar] -> [LocalVar]
forall a. (a -> Bool) -> [a] -> [a]
filter ((BindingSource
LetBound BindingSource -> BindingSource -> Bool
forall a. Eq a => a -> a -> Bool
/=) (BindingSource -> Bool)
-> (LocalVar -> BindingSource) -> LocalVar -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LocalVar -> BindingSource
localBindingSource)
                               ([LocalVar] -> [LocalVar]) -> [LocalVar] -> [LocalVar]
forall a b. (a -> b) -> a -> b
$ ((Name, LocalVar) -> LocalVar) -> [(Name, LocalVar)] -> [LocalVar]
forall a b. (a -> b) -> [a] -> [b]
map (Name, LocalVar) -> LocalVar
forall a b. (a, b) -> b
snd ([(Name, LocalVar)] -> [LocalVar])
-> [(Name, LocalVar)] -> [LocalVar]
forall a b. (a -> b) -> a -> b
$ [(Name, LocalVar)] -> [(Name, LocalVar)]
forall a. [a] -> [a]
reverse ([(Name, LocalVar)] -> [(Name, LocalVar)])
-> [(Name, LocalVar)] -> [(Name, LocalVar)]
forall a b. (a -> b) -> a -> b
$ ScopeInfo
scope ScopeInfo
-> Lens' [(Name, LocalVar)] ScopeInfo -> [(Name, LocalVar)]
forall o i. o -> Lens' i o -> i
^. Lens' [(Name, LocalVar)] ScopeInfo
scopeLocals
      -- Andreas, 2016-12-31, issue #2371
      -- The following is an unnecessary complication, as shadowed locals
      -- are not in scope anyway (they are ambiguous).
      -- -- Replace the shadowed names by fresh names (such that they do not shadow imports)
      -- let mnames :: [Maybe A.Name]
      --     mnames = map (notShadowedLocal . snd) $ reverse $ scopeLocals scope
      -- names <- mapM (maybe freshNoName_ return) mnames
      let types :: [Dom I.Type]
          types :: [Dom Type]
types = (Dom (ArgName, Type) -> Dom Type) -> ListTel -> [Dom Type]
forall a b. (a -> b) -> [a] -> [b]
map ((ArgName, Type) -> Type
forall a b. (a, b) -> b
snd ((ArgName, Type) -> Type) -> Dom (ArgName, Type) -> Dom Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>) (ListTel -> [Dom Type]) -> ListTel -> [Dom Type]
forall a b. (a -> b) -> a -> b
$ Telescope -> ListTel
forall t. Tele (Dom t) -> [Dom (ArgName, t)]
telToList Telescope
tel
          gamma :: ListTel' A.Name
          gamma :: [Dom (Name, Type)]
gamma = [Dom (Name, Type)]
-> Maybe [Dom (Name, Type)] -> [Dom (Name, Type)]
forall a. a -> Maybe a -> a
fromMaybe [Dom (Name, Type)]
forall a. HasCallStack => a
__IMPOSSIBLE__ (Maybe [Dom (Name, Type)] -> [Dom (Name, Type)])
-> Maybe [Dom (Name, Type)] -> [Dom (Name, Type)]
forall a b. (a -> b) -> a -> b
$
                    (Name -> Dom Type -> Dom (Name, Type))
-> [Name] -> [Dom Type] -> Maybe [Dom (Name, Type)]
forall a b c. (a -> b -> c) -> [a] -> [b] -> Maybe [c]
zipWith' (\ Name
x Dom Type
dom -> (Name
x,) (Type -> (Name, Type)) -> Dom Type -> Dom (Name, Type)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Dom Type
dom) [Name]
names [Dom Type]
types
      ArgName -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> TCMT IO Doc -> m ()
reportSDoc ArgName
"interaction.top" Int
20 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
TP.vcat
        [ TCMT IO Doc
"BasicOps.atTopLevel"
        , TCMT IO Doc
"  names = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
TP.sep ((Name -> TCMT IO Doc) -> [Name] -> [TCMT IO Doc]
forall a b. (a -> b) -> [a] -> [b]
map Name -> TCMT IO Doc
forall a (m :: * -> *).
(ToConcrete a, Pretty (ConOfAbs a), MonadAbsToCon m) =>
a -> m Doc
prettyA   [Name]
names)
        , TCMT IO Doc
"  types = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
TP.sep ((Dom Type -> TCMT IO Doc) -> [Dom Type] -> [TCMT IO Doc]
forall a b. (a -> b) -> [a] -> [b]
map Dom Type -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM [Dom Type]
types)
        ]
      ModuleName -> TCM a -> TCM a
forall (m :: * -> *) a. MonadTCEnv m => ModuleName -> m a -> m a
M.withCurrentModule ModuleName
current (TCM a -> TCM a) -> TCM a -> TCM a
forall a b. (a -> b) -> a -> b
$
        ScopeInfo -> TCM a -> TCM a
forall (m :: * -> *) a. ReadTCState m => ScopeInfo -> m a -> m a
withScope_ ScopeInfo
scope (TCM a -> TCM a) -> TCM a -> TCM a
forall a b. (a -> b) -> a -> b
$
          [Dom (Name, Type)] -> TCM a -> TCM a
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext [Dom (Name, Type)]
gamma (TCM a -> TCM a) -> TCM a -> TCM a
forall a b. (a -> b) -> a -> b
$ do
            -- We're going inside the top-level module, so we have to set the
            -- checkpoint for it and all its submodules to the new checkpoint.
            CheckpointId
cp <- Lens' CheckpointId TCEnv -> TCMT IO CheckpointId
forall (m :: * -> *) a. MonadTCEnv m => Lens' a TCEnv -> m a
viewTC Lens' CheckpointId TCEnv
eCurrentCheckpoint
            Lens' (Map ModuleName CheckpointId) TCState
stModuleCheckpoints Lens' (Map ModuleName CheckpointId) TCState
-> (Map ModuleName CheckpointId -> Map ModuleName CheckpointId)
-> TCMT IO ()
forall (m :: * -> *) a.
MonadTCState m =>
Lens' a TCState -> (a -> a) -> m ()
`modifyTCLens` (CheckpointId -> CheckpointId)
-> Map ModuleName CheckpointId -> Map ModuleName CheckpointId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (CheckpointId -> CheckpointId -> CheckpointId
forall a b. a -> b -> a
const CheckpointId
cp)
            TCM a
m

-- | Parse a name.
parseName :: Range -> String -> TCM C.QName
parseName :: Range -> ArgName -> TCM QName
parseName Range
r ArgName
s = do
  Expr
e <- Range -> ArgName -> TCM Expr
parseExpr Range
r ArgName
s
  let failure :: TCM QName
failure = TypeError -> TCM QName
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCM QName) -> TypeError -> TCM QName
forall a b. (a -> b) -> a -> b
$ ArgName -> TypeError
GenericError (ArgName -> TypeError) -> ArgName -> TypeError
forall a b. (a -> b) -> a -> b
$ ArgName
"Not an identifier: " ArgName -> ArgName -> ArgName
forall a. [a] -> [a] -> [a]
++ Expr -> ArgName
forall a. Show a => a -> ArgName
show Expr
e ArgName -> ArgName -> ArgName
forall a. [a] -> [a] -> [a]
++ ArgName
"."
  TCM QName -> (QName -> TCM QName) -> Maybe QName -> TCM QName
forall b a. b -> (a -> b) -> Maybe a -> b
maybe TCM QName
failure QName -> TCM QName
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe QName -> TCM QName) -> Maybe QName -> TCM QName
forall a b. (a -> b) -> a -> b
$ Expr -> Maybe QName
isQName Expr
e

-- | Check whether an expression is a (qualified) identifier.
isQName :: C.Expr -> Maybe C.QName
isQName :: Expr -> Maybe QName
isQName = \case
  C.Ident QName
x                    -> QName -> Maybe QName
forall (m :: * -> *) a. Monad m => a -> m a
return QName
x
  Expr
_ -> Maybe QName
forall a. Maybe a
Nothing

isName :: C.Expr -> Maybe C.Name
isName :: Expr -> Maybe Name
isName = Expr -> Maybe QName
isQName (Expr -> Maybe QName)
-> (QName -> Maybe Name) -> Expr -> Maybe Name
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \case
  C.QName Name
x -> Name -> Maybe Name
forall (m :: * -> *) a. Monad m => a -> m a
return Name
x
  QName
_ -> Maybe Name
forall a. Maybe a
Nothing

-- | Returns the contents of the given module or record.

moduleContents
  :: Rewrite
     -- ^ How should the types be presented?
  -> Range
     -- ^ The range of the next argument.
  -> String
     -- ^ The module name.
  -> TCM ([C.Name], I.Telescope, [(C.Name, Type)])
     -- ^ Module names,
     --   context extension needed to print types,
     --   names paired up with corresponding types.

moduleContents :: Rewrite
-> Range -> ArgName -> TCM ([Name], Telescope, [(Name, Type)])
moduleContents Rewrite
norm Range
rng ArgName
s = Call
-> TCM ([Name], Telescope, [(Name, Type)])
-> TCM ([Name], Telescope, [(Name, Type)])
forall (m :: * -> *) a. MonadTrace m => Call -> m a -> m a
traceCall Call
ModuleContents (TCM ([Name], Telescope, [(Name, Type)])
 -> TCM ([Name], Telescope, [(Name, Type)]))
-> TCM ([Name], Telescope, [(Name, Type)])
-> TCM ([Name], Telescope, [(Name, Type)])
forall a b. (a -> b) -> a -> b
$ do
  if ArgName -> Bool
forall a. Null a => a -> Bool
null (ArgName -> ArgName
trim ArgName
s) then Rewrite -> Maybe QName -> TCM ([Name], Telescope, [(Name, Type)])
getModuleContents Rewrite
norm Maybe QName
forall a. Maybe a
Nothing else do
  Expr
e <- Range -> ArgName -> TCM Expr
parseExpr Range
rng ArgName
s
  case Expr -> Maybe QName
isQName Expr
e of
    -- If the expression is not a single identifier, it is not a module name
    -- and treated as a record expression.
    Maybe QName
Nothing -> Rewrite -> Expr -> TCM ([Name], Telescope, [(Name, Type)])
getRecordContents Rewrite
norm Expr
e
    -- Otherwise, if it is not in scope as a module name, it is treated
    -- as a record name.
    Just QName
x  -> do
      [AbstractModule]
ms :: [AbstractModule] <- QName -> ScopeInfo -> [AbstractModule]
forall a. InScope a => QName -> ScopeInfo -> [a]
scopeLookup QName
x (ScopeInfo -> [AbstractModule])
-> TCMT IO ScopeInfo -> TCMT IO [AbstractModule]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TCMT IO ScopeInfo
forall (m :: * -> *). ReadTCState m => m ScopeInfo
getScope
      if [AbstractModule] -> Bool
forall a. Null a => a -> Bool
null [AbstractModule]
ms then Rewrite -> Expr -> TCM ([Name], Telescope, [(Name, Type)])
getRecordContents Rewrite
norm Expr
e else Rewrite -> Maybe QName -> TCM ([Name], Telescope, [(Name, Type)])
getModuleContents Rewrite
norm (Maybe QName -> TCM ([Name], Telescope, [(Name, Type)]))
-> Maybe QName -> TCM ([Name], Telescope, [(Name, Type)])
forall a b. (a -> b) -> a -> b
$ QName -> Maybe QName
forall a. a -> Maybe a
Just QName
x

-- | Returns the contents of the given record identifier.

getRecordContents
  :: Rewrite  -- ^ Amount of normalization in types.
  -> C.Expr   -- ^ Expression presumably of record type.
  -> TCM ([C.Name], I.Telescope, [(C.Name, Type)])
              -- ^ Module names,
              --   context extension,
              --   names paired up with corresponding types.
getRecordContents :: Rewrite -> Expr -> TCM ([Name], Telescope, [(Name, Type)])
getRecordContents Rewrite
norm Expr
ce = do
  Expr
e <- Expr -> ScopeM (AbsOfCon Expr)
forall c. ToAbstract c => c -> ScopeM (AbsOfCon c)
toAbstract Expr
ce
  (Term
_, Type
t) <- Expr -> TCM (Term, Type)
inferExpr Expr
e
  let notRecordType :: TCMT IO (QName, Args, Defn)
notRecordType = TypeError -> TCMT IO (QName, Args, Defn)
forall (m :: * -> *) a.
(HasCallStack, MonadTCError m) =>
TypeError -> m a
typeError (TypeError -> TCMT IO (QName, Args, Defn))
-> TypeError -> TCMT IO (QName, Args, Defn)
forall a b. (a -> b) -> a -> b
$ Type -> TypeError
ShouldBeRecordType Type
t
  (QName
q, Args
vs, Defn
defn) <- TCMT IO (QName, Args, Defn)
-> TCMT IO (Maybe (QName, Args, Defn))
-> TCMT IO (QName, Args, Defn)
forall (m :: * -> *) a. Monad m => m a -> m (Maybe a) -> m a
fromMaybeM TCMT IO (QName, Args, Defn)
notRecordType (TCMT IO (Maybe (QName, Args, Defn))
 -> TCMT IO (QName, Args, Defn))
-> TCMT IO (Maybe (QName, Args, Defn))
-> TCMT IO (QName, Args, Defn)
forall a b. (a -> b) -> a -> b
$ Type -> TCMT IO (Maybe (QName, Args, Defn))
forall (m :: * -> *).
PureTCM m =>
Type -> m (Maybe (QName, Args, Defn))
isRecordType Type
t
  case Defn
defn of
    Record{ recFields :: Defn -> [Dom QName]
recFields = [Dom QName]
fs, recTel :: Defn -> Telescope
recTel = Telescope
rtel } -> do
      let xs :: [Name]
xs   = (Dom QName -> Name) -> [Dom QName] -> [Name]
forall a b. (a -> b) -> [a] -> [b]
map (Name -> Name
nameConcrete (Name -> Name) -> (Dom QName -> Name) -> Dom QName -> Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. QName -> Name
qnameName (QName -> Name) -> (Dom QName -> QName) -> Dom QName -> Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dom QName -> QName
forall t e. Dom' t e -> e
unDom) [Dom QName]
fs
          tel :: Telescope
tel  = Telescope -> Args -> Telescope
forall t. Apply t => t -> Args -> t
apply Telescope
rtel Args
vs
          doms :: [Dom Type]
doms = Telescope -> [Dom Type]
forall a. TermSubst a => Tele (Dom a) -> [Dom a]
flattenTel Telescope
tel
      -- Andreas, 2019-04-10, issue #3687: use flattenTel
      -- to bring types into correct scope.
      ArgName -> Int -> TCMT IO Doc -> TCMT IO ()
forall (m :: * -> *).
MonadDebug m =>
ArgName -> Int -> TCMT IO Doc -> m ()
reportSDoc ArgName
"interaction.contents.record" Int
20 (TCMT IO Doc -> TCMT IO ()) -> TCMT IO Doc -> TCMT IO ()
forall a b. (a -> b) -> a -> b
$ [TCMT IO Doc] -> TCMT IO Doc
forall (m :: * -> *) (t :: * -> *).
(Applicative m, Foldable t) =>
t (m Doc) -> m Doc
TP.vcat
        [ TCMT IO Doc
"getRecordContents"
        , TCMT IO Doc
"  cxt  = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> (Telescope -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> 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 :: * -> *). (Applicative m, MonadTCEnv m) => m Telescope
getContextTelescope)
        , TCMT IO Doc
"  tel  = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> Telescope -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM Telescope
tel
        , TCMT IO Doc
"  doms = " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> [Dom Type] -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM [Dom Type]
doms
        , TCMT IO Doc
"  doms'= " TCMT IO Doc -> TCMT IO Doc -> TCMT IO Doc
forall (m :: * -> *). Applicative m => m Doc -> m Doc -> m Doc
TP.<+> Telescope -> TCMT IO Doc -> TCMT IO Doc
forall b (m :: * -> *) a.
(AddContext b, MonadAddContext m) =>
b -> m a -> m a
addContext Telescope
tel ([Dom Type] -> TCMT IO Doc
forall a (m :: * -> *). (PrettyTCM a, MonadPretty m) => a -> m Doc
prettyTCM [Dom Type]
doms)
        ]
      [Type]
ts <- (Dom Type -> TCMT IO Type) -> [Dom Type] -> TCMT IO [Type]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Rewrite -> Type -> TCMT IO Type
forall t.
(Reduce t, Simplify t, Instantiate t, Normalise t) =>
Rewrite -> t -> TCM t
normalForm Rewrite
norm (Type -> TCMT IO Type)
-> (Dom Type -> Type) -> Dom Type -> TCMT IO Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dom Type -> Type
forall t e. Dom' t e -> e
unDom) [Dom Type]
doms
      ([Name], Telescope, [(Name, Type)])
-> TCM ([Name], Telescope, [(Name, Type)])
forall (m :: * -> *) a. Monad m => a -> m a
return ([], Telescope
tel, [Name] -> [Type] -> [(Name, Type)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Name]
xs [Type]
ts)
    Defn
_ -> TCM ([Name], Telescope, [(Name, Type)])
forall a. HasCallStack => a
__IMPOSSIBLE__

-- | Returns the contents of the given module.

getModuleContents
  :: Rewrite
       -- ^ Amount of normalization in types.
  -> Maybe C.QName
       -- ^ Module name, @Nothing@ if top-level module.
  -> TCM ([C.Name], I.Telescope, [(C.Name, Type)])
       -- ^ Module names,
       --   context extension,
       --   names paired up with corresponding types.
getModuleContents :: Rewrite -> Maybe QName -> TCM ([Name], Telescope, [(Name, Type)])
getModuleContents Rewrite
norm Maybe QName
mm = do
  Scope
modScope <- case Maybe QName
mm of
    Maybe QName
Nothing -> TCMT IO Scope
getCurrentScope
    Just QName
m  -> ModuleName -> TCMT IO Scope
getNamedScope (ModuleName -> TCMT IO Scope)
-> (AbstractModule -> ModuleName)
-> AbstractModule
-> TCMT IO Scope
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AbstractModule -> ModuleName
amodName (AbstractModule -> TCMT IO Scope)
-> TCMT IO AbstractModule -> TCMT IO Scope
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< QName -> TCMT IO AbstractModule
resolveModule QName
m
  let modules :: ThingsInScope AbstractModule
      modules :: ThingsInScope AbstractModule
modules = Scope -> ThingsInScope AbstractModule
forall a. InScope a => Scope -> ThingsInScope a
exportedNamesInScope Scope
modScope
      names :: ThingsInScope AbstractName
      names :: ThingsInScope AbstractName
names = Scope -> ThingsInScope AbstractName
forall a. InScope a => Scope -> ThingsInScope a
exportedNamesInScope Scope
modScope
      xns :: [(Name, AbstractName)]
xns = [ (Name
x,AbstractName
n) | (Name
x, [AbstractName]
ns) <- ThingsInScope AbstractName -> [(Name, [AbstractName])]
forall k a. Map k a -> [(k, a)]
Map.toList ThingsInScope AbstractName
names, AbstractName
n <- [AbstractName]
ns ]
  [(Name, Type)]
types <- [(Name, AbstractName)]
-> ((Name, AbstractName) -> TCMT IO (Name, Type))
-> TCMT IO [(Name, Type)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [(Name, AbstractName)]
xns (((Name, AbstractName) -> TCMT IO (Name, Type))
 -> TCMT IO [(Name, Type)])
-> ((Name, AbstractName) -> TCMT IO (Name, Type))
-> TCMT IO [(Name, Type)]
forall a b. (a -> b) -> a -> b
$ \(Name
x, AbstractName
n) -> do
    Definition
d <- QName -> TCMT IO Definition
forall (m :: * -> *). HasConstInfo m => QName -> m Definition
getConstInfo (QName -> TCMT IO Definition) -> QName -> TCMT IO Definition
forall a b. (a -> b) -> a -> b
$ AbstractName -> QName
anameName AbstractName
n
    Type
t <- Rewrite -> Type -> TCMT IO Type
forall t.
(Reduce t, Simplify t, Instantiate t, Normalise t) =>
Rewrite -> t -> TCM t
normalForm Rewrite
norm (Type -> TCMT IO Type) -> TCMT IO Type -> TCMT IO Type
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (Definition -> Type
defType (Definition -> Type) -> TCMT IO Definition -> TCMT IO Type
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Definition -> TCMT IO Definition
forall (m :: * -> *).
(Functor m, HasConstInfo m, HasOptions m, ReadTCState m,
 MonadTCEnv m, MonadDebug m) =>
Definition -> m Definition
instantiateDef Definition
d)
    (Name, Type) -> TCMT IO (Name, Type)
forall (m :: * -> *) a. Monad m => a -> m a
return (Name
x, Type
t)
  ([Name], Telescope, [(Name, Type)])
-> TCM ([Name], Telescope, [(Name, Type)])
forall (m :: * -> *) a. Monad m => a -> m a
return (ThingsInScope AbstractModule -> [Name]
forall k a. Map k a -> [k]
Map.keys ThingsInScope AbstractModule
modules, Telescope
forall a. Tele a
EmptyTel, [(Name, Type)]
types)


whyInScope :: String -> TCM (Maybe LocalVar, [AbstractName], [AbstractModule])
whyInScope :: ArgName -> TCM (Maybe LocalVar, [AbstractName], [AbstractModule])
whyInScope ArgName
s = do
  QName
x     <- Range -> ArgName -> TCM QName
parseName Range
forall a. Range' a
noRange ArgName
s
  ScopeInfo
scope <- TCMT IO ScopeInfo
forall (m :: * -> *). ReadTCState m => m ScopeInfo
getScope
  (Maybe LocalVar, [AbstractName], [AbstractModule])
-> TCM (Maybe LocalVar, [AbstractName], [AbstractModule])
forall (m :: * -> *) a. Monad m => a -> m a
return ( QName -> [(QName, LocalVar)] -> Maybe LocalVar
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup QName
x ([(QName, LocalVar)] -> Maybe LocalVar)
-> [(QName, LocalVar)] -> Maybe LocalVar
forall a b. (a -> b) -> a -> b
$ ((Name, LocalVar) -> (QName, LocalVar))
-> [(Name, LocalVar)] -> [(QName, LocalVar)]
forall a b. (a -> b) -> [a] -> [b]
map ((Name -> QName) -> (Name, LocalVar) -> (QName, LocalVar)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (b, d) (c, d)
first Name -> QName
C.QName) ([(Name, LocalVar)] -> [(QName, LocalVar)])
-> [(Name, LocalVar)] -> [(QName, LocalVar)]
forall a b. (a -> b) -> a -> b
$ ScopeInfo
scope ScopeInfo
-> Lens' [(Name, LocalVar)] ScopeInfo -> [(Name, LocalVar)]
forall o i. o -> Lens' i o -> i
^. Lens' [(Name, LocalVar)] ScopeInfo
scopeLocals
         , QName -> ScopeInfo -> [AbstractName]
forall a. InScope a => QName -> ScopeInfo -> [a]
scopeLookup QName
x ScopeInfo
scope
         , QName -> ScopeInfo -> [AbstractModule]
forall a. InScope a => QName -> ScopeInfo -> [a]
scopeLookup QName
x ScopeInfo
scope )