HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

ModuleAgda-2.7.0.1Haskell2010

Agda.TypeChecking.MetaVars.Occurs

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.

  • 6 types
  • 2 classes
  • 30 values
  • PackageAgda-2.7.0.1
  • Exports38
  • LanguageHaskell2010
  • LicenceMIT
  • SourceOccurs.hs

MetaOccursCheck: going into definitions to exclude cyclic solutions

4 declarations
valuetallyDef :: QName -> TCM ()
#

Remove a def from the list of defs to be looked at.

OccursM monad and its services

3 declarations

Modality handling.

valuedefinitionCheck :: QName -> OccursM ()
#

Occurs check fails if a defined name is not available since it was declared in irrelevant or erased context.

Unfolding during occurs check.

valueconArgs :: Elims -> OccursM a -> OccursM a
#

For a path constructor `c : ... -> Path D a b`, we have that e.g. `c es i0` reduces to a. So we have to consider its arguments as flexible when we do not actually unfold.

Managing rigidiy during occurs check.

Error throwing during occurs check.

Implementation of the occurs check.

6 declarations
classclass Occurs t where
#

Extended occurs check.

Methods

Instances13Occurs, …
  • Occurs QNameDefined in Agda-2.7.0.1 · Agda.TypeChecking.MetaVars.Occurs
  • Occurs ClauseDefined in Agda-2.7.0.1 · Agda.TypeChecking.MetaVars.Occurs
  • Occurs ElimsDefined in Agda-2.7.0.1 · Agda.TypeChecking.MetaVars.Occurs
  • Occurs LevelDefined in Agda-2.7.0.1 · Agda.TypeChecking.MetaVars.Occurs
  • Occurs PlusLevelDefined in Agda-2.7.0.1 · Agda.TypeChecking.MetaVars.Occurs
  • Occurs SortDefined in Agda-2.7.0.1 · Agda.TypeChecking.MetaVars.Occurs
  • Occurs TermDefined in Agda-2.7.0.1 · Agda.TypeChecking.MetaVars.Occurs
  • Occurs TypeDefined in Agda-2.7.0.1 · Agda.TypeChecking.MetaVars.Occurs
  • Occurs DefnDefined in Agda-2.7.0.1 · Agda.TypeChecking.MetaVars.Occurs
  • Occurs (Abs Term)Defined in Agda-2.7.0.1 · Agda.TypeChecking.MetaVars.Occurs
  • Occurs (Abs Type)Defined in Agda-2.7.0.1 · Agda.TypeChecking.MetaVars.Occurs
  • Occurs a => Occurs (Arg a)Defined in Agda-2.7.0.1 · Agda.TypeChecking.MetaVars.Occurs
  • Occurs a => Occurs (Dom a)Defined in Agda-2.7.0.1 · Agda.TypeChecking.MetaVars.Occurs

Pruning: getting rid of flexible occurrences.

10 declarations
valueprune
  1. :: (PureTCM m, MonadMetaSolver m)
  2. => MetaId

    Meta to prune.

  3. -> Args

    Arguments to meta variable.

  4. -> (Nat -> Bool)

    Test for allowed variable (de Bruijn index).

  5. -> m PruneResult
#

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.

valuehasBadRigid
  1. :: PureTCM m
  2. => (Nat -> Bool)

    Test for allowed variable (de Bruijn index).

  3. -> Term

    Argument of meta variable.

  4. -> ExceptT () m Bool

    Exception if argument is matchable.

#

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.)

valuerigidVarsNotContainedIn
  1. :: (PureTCM m, AnyRigid a)
  2. => a
  3. -> (Nat -> Bool)

    Test for allowed variable (de Bruijn index).

  4. -> m Bool
#

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.

classclass AnyRigid a where
#

Collect the *definitely* rigid variables in a monoid. We need to successively reduce the expression to do this.

Methods

Instances11AnyRigid, …
valuekilledType
  1. :: MonadReduce m
  2. => [(Dom (ArgName, Type), Bool)]
  3. -> Type
  4. -> m ([Arg Bool], Type)
#

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.

valueperformKill
  1. :: MonadMetaSolver m
  2. => [Arg Bool]

    Arguments to old meta var in left to right order with Bool indicating whether they can be pruned.

  3. -> MetaId

    The old meta var to receive pruning.

  4. -> Type

    The pruned type of the new meta var.

  5. -> m ()
#

Instantiate a meta variable with a new one that only takes the arguments which are not pruneable.

Orphan instances

1 instance