Whether a local declaration should be found by type class search, tactics, etc. and shown in the goal display.
- default : LocalDeclKind
Participates fully in type class search, tactics, and is shown even if inaccessible.
For example: the
xinfun x => _has the default kind. - implDetail : LocalDeclKind
Invisible to type class search or tactics, and hidden in the goal display.
This kind is used for temporary variables in macros. For example:
return (← foo) + barexpands tofoo >>= fun __tmp => pure (__tmp + bar), where__tmphas theimplDetailkind. - auxDecl : LocalDeclKind
Auxiliary local declaration for recursive calls. The behavior is similar to
implDetail.For example:
def foo (n : Nat) : Nat := _adds the local declarationfoo : Nat → Natto allow recursive calls. This declaration has theauxDeclkind.
Instances For
A declaration for a LocalContext. This is used to register which free variables are in scope.
See LocalDecl.index, LocalDecl.fvarId, LocalDecl.userName, LocalDecl.type for accessors for
arguments common to both constructors.
- cdecl
(index : Nat)
(fvarId : FVarId)
(userName : Name)
(type : Expr)
(bi : BinderInfo)
(kind : LocalDeclKind)
: LocalDecl
A local variable without any value.
Lean.LocalContext.mkBindingcreates lambdas or foralls fromcdecls. - ldecl
(index : Nat)
(fvarId : FVarId)
(userName : Name)
(type value : Expr)
(nondep : Bool)
(kind : LocalDeclKind)
: LocalDecl
A let-bound free variable, with a value
value : Expr. Ifnondep := false, then the variable is definitionally equal to its value. Ifnondep := true, then the variable has an opaque value; we call these "have-bound free variables."Lean.LocalContext.mkBindingcreates let/have expressions fromldecls.Important: The
nondep := truecase is subtle; it is not merely an opaqueldecl!- In most contexts, nondependent
ldecls should be treated likecdecls. For example, suppose we have a tactic goalx : α := v (nondep) ⊢ b. It would be incorrect forrevert xto produce the goal⊢ have x : α := v; b, since this would be saying "to provebwithout knowledge of the value ofx, it suffices to provehave x : α := v; bfor this particular value ofx." Instead,revert xmust produce the goal⊢ ∀ x : α, b. Furthermore, given a goal⊢ have x : α := v; b, theintro xtactic should yield a dependentldecl, since users expect to be able to make use of the value ofx, plus, as discussed, ifintroyielded a nondepldeclthenintro x; revert xwould convert the goal into a forall, not ahave. - Also:
valuemight not be type correct. Metaprograms may decide to pretend that allnondep := trueldecls arecdecls (for example, when reverting variables). As a consequence, nondepldecls may have type-incorrect values. This design decision allows metaprograms to not have to think about nondepldecls, so long asLocalDeclvalues are consumed throughLocalDecl.isLetandLocalDecl.value?with(allowNondep := false). Rule: never use(generalizeNondepLet := false)inmkBinding-family functions within a local context you do not own. SeeLocalDecl.setNondepfor some additional discussion. - Where then do nondep ldecls come from? Common functions are
Meta.mapLetDecl,Meta.withLetDecl, andMeta.letTelescope. Thehaveterm syntax makes use of a nondep ldecl as well.
Therefore,
nondep := trueshould be used with consideration. Its primary use is in metaprograms that enterlet/havetelescopes and wish to reconstruct them. - In most contexts, nondependent
Instances For
Equations
Instances For
Equations
Instances For
The position of the decl in the local context.
Equations
Instances For
The unique id of the free variable.
Equations
Instances For
The pretty-printable name of the variable.
Equations
Instances For
Is the local declaration an implementation-detail hypothesis (including auxiliary declarations)?
Equations
Instances For
Sets the nondep flag of an ldecl, otherwise returns cdecls unchanged.
This is a low-level function, and it is the responsibility of the caller to ensure that
transitions of nondep are valid.
Rules:
- If the declaration is not under the caller's control, then setting
nondep := falsemust not be done. General nondependentldecls should be treated likecdecls. See also the docstring forLocalDecl.ldeclabout thevaluenot necessarily being type correct. - Setting
nondep := trueis usually fine.- Caution: be sure any relevant caches are cleared so that the value associated to this
FVarIddoes not leak. - Caution: be sure that metavariables dependent on this declaration created before and after the transition are not mixed,
since unification does not check "
nondep-compatibility" of local contexts when assigning metavariables.
- Caution: be sure any relevant caches are cleared so that the value associated to this
For example, setting nondep := false is fine from within a telescope combinator, to update the local context
right before calling mkLetFVars:
let lctx ← getLCtx
letTelescope e fun xs b => do
let lctx' ← xs.foldlM (init := lctx) fun lctx' x => do
let decl ← x.fvarId!.getDecl
-- Clear the flag if it's not a prop.
let decl' := decl.setNondep <| ← pure decl.isNondep <&&> Meta.isProp decl.type
pure <| lctx'.addDecl decl'
withLCtx' lctx' do
mkLetFVars (usedLetOnly := false) (generalizeNondepLet := false) xs b
- The declarations for
xsare in the control of this metaprogram. mkLetFVarsdoes make use ofMetaMcaches.- Even if
ehas metavariables, these do not includexsin their contexts, so the change of thenondepflag does not cause any issues in theabstractMsystem used bymkLetFVars.
Equations
Instances For
A LocalContext is an ordered set of local variable declarations.
It is used to store the free variables (also known as local constants) that
are in scope. It also maps free variables corresponding to auxiliary declarations
(recursive references and where and let rec bindings) to their fully-qualified global names.
When inspecting a goal or expected type in the infoview, the local
context is all of the variables above the ⊢ symbol.
- fvarIdToDecl : PersistentHashMap FVarId LocalDecl
- decls : PersistentArray (Option LocalDecl)
Instances For
Equations
Instances For
Equations
Instances For
Low level API for creating local declarations (LocalDecl.cdecl).
It is used to implement actions in the monads Elab and Tactic.
It should not be used directly since the argument (fvarId : FVarId) is
assumed to be unique. You can create a unique fvarId with mkFreshFVarId.
Equations
Instances For
Low level API for let declarations. Do not use directly.
Equations
Instances For
Low level API for auxiliary declarations. Do not use directly.
Equations
Instances For
Low level API for adding a local declaration. Do not use directly.
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Gets the declaration for expression e in the local context.
If e is not a free variable or not present then panics.
Equations
Instances For
Equations
Instances For
Returns true when the lctx contains the free variable e.
Panics if e is not an fvar.
Equations
Instances For
Return all of the free variables in the given context.
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Low-level function for updating the local context.
Assumptions about f, the resulting nested expressions must be definitionally equal to their original values,
the index nor fvarId are modified.
Equations
Instances For
Set the kind of the given fvar.
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Given lctx₁ - exceptFVars of the form (x_1 : A_1) ... (x_n : A_n), then return true
iff there is a local context B_1* (x_1 : A_1) ... B_n* (x_n : A_n) which is a prefix
of lctx₂ where B_i's are (possibly empty) sequences of local declarations.
Equations
Instances For
Equations
Instances For
Creates the expression fun x₁ .. xₙ => b for free variables xs = #[x₁, .., xₙ],
suitably abstracting b and the types for each of the xᵢ.
Equations
Instances For
Creates the expression (x₁:α₁) → .. → (xₙ:αₙ) → b for free variables xs = #[x₁, .., xₙ],
suitably abstracting b and the types for each of the xᵢ, αᵢ.
Equations
Instances For
Equations
Instances For
Equations
Instances For
Return true if lctx contains a local declaration satisfying p.
Equations
Instances For
Return true if all declarations in lctx satisfy p.
Equations
Instances For
If option pp.sanitizeNames is set to true, add tombstone to shadowed local declaration names and ones contains macroscopes.
Equations
Instances For
Given an FVarId, this function returns the corresponding user name,
but only if the name can be used to recover the original FVarId.
Equations
Instances For
Sort the given FVarIds by the order in which they appear in lctx. If any of
the FVarIds do not appear in lctx, the result is unspecified.