| Safe Haskell | None |
|---|---|
| Language | Haskell98 |
Agda.TypeChecking.MetaVars.Occurs
Description
The occurs check for unification. Does pruning on the fly.
When hitting a meta variable:
- Compute flex/rigid for its arguments.
- Compare to allowed variables.
- Mark arguments with rigid occurrences of disallowed variables for deletion.
- Attempt to delete marked arguments.
- We don't need to check for success, we can just continue occurs checking.
- modifyOccursCheckDefs :: (Set QName -> Set QName) -> TCM ()
- initOccursCheck :: MetaVariable -> TCM ()
- defNeedsChecking :: QName -> TCM Bool
- tallyDef :: QName -> TCM ()
- data OccursCtx
- = Flex
- | Rigid
- | StronglyRigid
- | Top
- | Irrel
- data UnfoldStrategy
- defArgs :: UnfoldStrategy -> OccursCtx -> OccursCtx
- unfold :: UnfoldStrategy -> Term -> TCM (Blocked Term)
- leaveTop :: OccursCtx -> OccursCtx
- weakly :: OccursCtx -> OccursCtx
- strongly :: OccursCtx -> OccursCtx
- patternViolation' :: Int -> String -> TCM a
- abort :: OccursCtx -> TypeError -> TCM a
- type Vars = ([Nat], [Nat])
- goIrrelevant :: Vars -> Vars
- allowedVar :: Nat -> Vars -> Bool
- takeRelevant :: Vars -> [Nat]
- liftUnderAbs :: Vars -> Vars
- class Occurs t where
- occurs :: UnfoldStrategy -> OccursCtx -> MetaId -> Vars -> t -> TCM t
- metaOccurs :: MetaId -> t -> TCM ()
- occursCheck :: (Occurs a, InstantiateFull a, PrettyTCM a) => MetaId -> Vars -> a -> TCM a
- prune :: MetaId -> Args -> [Nat] -> TCM PruneResult
- hasBadRigid :: [Nat] -> Term -> ExceptT () TCM Bool
- isNeutral :: MonadTCM tcm => Blocked t -> QName -> Elims -> tcm Bool
- rigidVarsNotContainedIn :: (MonadTCM tcm, FoldRigid a) => a -> [Nat] -> tcm Bool
- class FoldRigid a where
- data PruneResult
- killArgs :: [Bool] -> MetaId -> TCM PruneResult
- killedType :: [(Dom (ArgName, Type), Bool)] -> Type -> ([Arg Bool], Type)
- performKill :: [Arg Bool] -> MetaId -> Type -> TCM ()
Documentation
initOccursCheck :: MetaVariable -> TCM () Source
Set the names of definitions to be looked at to the defs in the current mutual block.
defNeedsChecking :: QName -> TCM Bool Source
Is a def in the list of stuff to be checked?
Constructors
| Flex | we are in arguments of a meta |
| Rigid | we are not in arguments of a meta but a bound var |
| StronglyRigid | we are at the start or in the arguments of a constructor |
| Top | we are at the term root (this turns into |
| Irrel | we are in an irrelevant argument |
data UnfoldStrategy Source
Instances
defArgs :: UnfoldStrategy -> OccursCtx -> OccursCtx Source
patternViolation' :: Int -> String -> TCM a Source
goIrrelevant :: Vars -> Vars Source
allowedVar :: Nat -> Vars -> Bool Source
takeRelevant :: Vars -> [Nat] Source
liftUnderAbs :: Vars -> Vars Source
Extended occurs check.
Methods
occurs :: UnfoldStrategy -> OccursCtx -> MetaId -> Vars -> t -> TCM t Source
metaOccurs :: MetaId -> t -> TCM () Source
Instances
| Occurs QName Source | |
| Occurs Clause Source | |
| Occurs LevelAtom Source | |
| Occurs PlusLevel Source | |
| Occurs Level Source | |
| Occurs Sort Source | |
| Occurs Type Source | |
| Occurs Term Source | |
| Occurs Defn Source | |
| Occurs a => Occurs [a] Source | |
| (Occurs a, Subst a) => Occurs (Abs a) Source | |
| Occurs a => Occurs (Elim' a) Source | |
| Occurs a => Occurs (Dom a) Source | |
| Occurs a => Occurs (Arg a) Source | |
| (Occurs a, Occurs b) => Occurs (a, b) Source |
occursCheck :: (Occurs a, InstantiateFull a, PrettyTCM a) => MetaId -> Vars -> a -> TCM a Source
When assigning m xs := v, check that m does not occur in v
and that the free variables of v are contained in xs.
Getting rid of flexible occurrences
prune :: MetaId -> Args -> [Nat] -> TCM PruneResult Source
prune m' vs xs attempts to remove all arguments from vs whose
free variables are not contained in xs.
If successful, m' is solved by the new, pruned meta variable and we
return True else False.
Issue 1147:
If any of the meta args vs is matchable, e.g., is a constructor term,
we cannot prune, because the offending variables could be removed by
reduction for a suitable instantiation of the meta variable.
hasBadRigid :: [Nat] -> Term -> ExceptT () TCM Bool Source
hasBadRigid xs v = Just True iff one of the rigid variables in v is not in xs.
Actually we can only prune if a bad variable is in the head. See issue 458.
Or in a non-eliminateable position (see succeed/PruningNonMillerPattern).
hasBadRigid xs v = Nothing means that
we cannot prune at all as one of the meta args is matchable.
(See issue 1147.)
isNeutral :: MonadTCM tcm => Blocked t -> QName -> Elims -> tcm Bool Source
Check whether a term Def f es is finally stuck.
Currently, we give only a crude approximation.
rigidVarsNotContainedIn :: (MonadTCM tcm, FoldRigid a) => a -> [Nat] -> tcm Bool Source
Check whether any of the variables (given as de Bruijn indices) occurs *definitely* in the term in a rigid position. Reduces the term successively to remove variables in dead subterms. This fixes issue 1386.
class FoldRigid a where Source
Collect the *definitely* rigid variables in a monoid. We need to successively reduce the expression to do this.
Instances
| FoldRigid LevelAtom Source | |
| FoldRigid PlusLevel Source | |
| FoldRigid Level Source | |
| FoldRigid Sort Source | |
| FoldRigid Type Source | |
| FoldRigid Term Source | |
| FoldRigid a => FoldRigid [a] Source | |
| (Subst a, FoldRigid a) => FoldRigid (Abs a) Source | |
| FoldRigid a => FoldRigid (Elim' a) Source | |
| FoldRigid a => FoldRigid (Dom a) Source | |
| FoldRigid a => FoldRigid (Arg a) Source | |
| (FoldRigid a, FoldRigid b) => FoldRigid (a, b) Source |
data PruneResult Source
Constructors
| NothingToPrune | the kill list is empty or only |
| PrunedNothing | there is no possible kill (because of type dep.) |
| PrunedSomething | managed to kill some args in the list |
| PrunedEverything | all prescribed kills where performed |
Instances
killArgs :: [Bool] -> MetaId -> TCM PruneResult Source
killArgs [k1,...,kn] X prunes argument i from metavar X if ki==True.
Pruning is carried out whenever > 0 arguments can be pruned.
True is only returned if all arguments could be pruned.
killedType :: [(Dom (ArgName, Type), Bool)] -> Type -> ([Arg Bool], Type) Source
killedType [((x1,a1),k1)..((xn,an),kn)] b = ([k'1..k'n],t')
(ignoring Dom). Let t' = (xs:as) -> b.
Invariant: k'i == True iff ki == True and pruning the ith argument from
type b is possible without creating unbound variables.
t' is type t after pruning all k'i==True.