Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Term.instToStringNamedArg = { toString := fun (s : Lean.Elab.Term.NamedArg) => "(" ++ toString s.name ++ " := " ++ toString s.val ++ ")" }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instances For
Erase entry for binderName
from namedArgs
.
Equations
- Lean.Elab.Term.eraseNamedArg namedArgs binderName = List.filter (fun (x : Lean.Elab.Term.NamedArg) => x.name != binderName) namedArgs
Instances For
Default application elaborator #
- ellipsis : Bool
true
if..
was used - explicit : Bool
true
if@
modifier was used - resultIsOutParamSupport : Bool
If the result type of an application is the
outParam
of some local instance, then special support may be needed because type class resolution interacts poorly with coercions in this kind of situation. This flag enables the special support.The idea is quite simple, if the result type is the
outParam
of some local instance, we simply executesynthesizeSyntheticMVarsUsingDefault
. We added this feature to make sure examples as follows are correctly elaborated.class GetElem (Cont : Type u) (Idx : Type v) (Elem : outParam (Type w)) where getElem (xs : Cont) (i : Idx) : Elem export GetElem (getElem) instance : GetElem (Array α) Nat α where getElem xs i := xs.get ⟨i, sorry⟩ opaque f : Option Bool → Bool opaque g : Bool → Bool def bad (xs : Array Bool) : Bool := let x := getElem xs 0 f x && g x
Without the special support, Lean fails at
g x
sayingx
has typeOption Bool
but is expected to have typeBool
. From the user's point of view this is a bug, sincelet x := getElem xs 0
clearly constrainsx
to beBool
, but we only obtain this information after we apply theOfNat
default instance for0
.Before converging to this solution, we have tried to create a "coercion placeholder" when
resultIsOutParamSupport = true
, but it did not work well in practice. For example, it failed in the example above.
Instances For
Auxiliary structure for elaborating the application f args namedArgs
.
- f : Lean.Expr
- fType : Lean.Expr
- args : List Lean.Elab.Term.Arg
Remaining regular arguments.
- namedArgs : List Lean.Elab.Term.NamedArg
remaining named arguments to be processed.
When named arguments are provided and explicit arguments occurring before them are missing, the elaborator eta-expands the declaration. For example,
def f (x y : Nat) := x + y #check f (y := 5) -- fun x => f x 5
etaArgs
stores the fresh free variables for implementing the eta-expansion. When..
is used, eta-expansion is disabled, and missing arguments are treated as_
.- toSetErrorCtx : Array Lean.MVarId
Metavariables that we need to set the error context using the application being built.
- instMVars : Array Lean.MVarId
Metavariables for the instance implicit arguments that have already been processed.
- propagateExpected : Bool
The following field is used to implement the
propagateExpectedType
heuristic. It is set totrue
true whenexpectedType
still has to be propagated. - resultTypeOutParam? : Option Lean.MVarId
If the result type may be the
outParam
of some local instance. See comment atContext.resultIsOutParamSupport
Instances For
Equations
Instances For
Try to synthesize metavariables are instMVars
using type class resolution.
The ones that cannot be synthesized yet are registered.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Remove named argument with name binderName
from namedArgs
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Elaborate function application arguments.
Eliminator-like function application elaborator #
Information about an eliminator used by the elab-as-elim elaborator.
This is not to be confused with Lean.Meta.ElimInfo
, which is for induction
and cases
.
The elab-as-elim routine is less restrictive in what counts as an eliminator, and it doesn't need
to have a strict notion of what is a "target" — all it cares about are
- that the return type of a function is of the form
m ...
wherem
is a parameter (unlikeinduction
andcases
eliminators, the arguments tom
, known as "discriminants", can be any expressions, not just parameters), and - which arguments should be eagerly elaborated, to make discriminants be as elaborated as possible for the expected type generalization procedure, and which should be postponed (since they are the "minor premises").
Note that the routine isn't doing induction/cases on particular expressions. The purpose of elab-as-elim is to successfully solve the higher-order unification problem between the return type of the function and the expected type.
- elimExpr : Lean.Expr
The eliminator.
- elimType : Lean.Expr
The type of the eliminator.
- motivePos : Nat
The position of the motive parameter.
Positions of "major" parameters (those that should be eagerly elaborated because they can contribute to the motive inference procedure). All parameters that are neither the motive nor a major parameter are "minor" parameters. The major parameters include all of the parameters that transitively appear in the motive's arguments, as well as "first-order" arguments that include such parameters, since they too can help with elaborating discriminants.
For example, in the following theorem the argument
h : a = b
should be elaborated eagerly because it containsb
, which occurs inmotive b
.theorem Eq.subst' {α} {motive : α → Prop} {a b : α} (h : a = b) : motive a → motive b
For another example, the term
isEmptyElim (α := α)
is an underapplied eliminator, and it needs argumentα
to be elaborated eagerly to create a type-correct motive.def isEmptyElim [IsEmpty α] {p : α → Sort _} (a : α) : p a := ... example {α : Type _} [IsEmpty α] : id (α → False) := isEmptyElim (α := α)
Instances For
Equations
- Lean.Elab.Term.instReprElabElimInfo = { reprPrec := Lean.Elab.Term.reprElabElimInfo✝ }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instances For
Context of the elab_as_elim
elaboration procedure.
- elimInfo : Lean.Elab.Term.ElabElimInfo
- expectedType : Lean.Expr
Instances For
State of the elab_as_elim
elaboration procedure.
- f : Lean.Expr
The resultant expression being built.
- fType : Lean.Expr
`f : fType
- namedArgs : List Lean.Elab.Term.NamedArg
User-provided named arguments that still have to be processed.
- args : List Lean.Elab.Term.Arg
User-provided arguments that still have to be processed.
- instMVars : Array Lean.MVarId
Instance implicit arguments collected so far.
- idx : Nat
Position of the next argument to be processed. We use it to decide whether the argument is the motive or a discriminant.
Store the metavariable used to represent the motive that will be computed at
finalize
.
Instances For
Infer the motive
using the expected type by kabstract
ing the discriminants.
Instances For
If the eliminator is over-applied, we "revert" the extra arguments. Returns the function with the reverted arguments applied and the new generalized expected type.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Construct the resulting application after all discriminants have been elaborated, and we have consumed as many given arguments as possible.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Return the next argument to be processed.
The result is .none
if it is an implicit argument which was not provided using a named argument.
The result is .undef
if args
is empty and namedArgs
does contain an entry for binderName
.
Instances For
Set the motive
field in the state.
Instances For
Save information for producing error messages.
Equations
- Lean.Elab.Term.ElabElim.saveArgInfo arg binderName = if arg.isMVar = true then liftM (Lean.Elab.Term.registerMVarArgName arg.mvarId! binderName) else pure PUnit.unit
Instances For
Create an implicit argument using the given BinderInfo
.
Instances For
Main loop of the elimAsElab
procedure.
Function application elaboration #
Elaborate a f
-application using namedArgs
and args
as the arguments.
expectedType?
the expected type if available. It is used to propagate typing information only. This method does not ensure the result has this type.explicit = true
when notation@
is used, and implicit arguments are assumed to be provided atnamedArgs
andargs
.ellipsis = true
when notation..
is used. That is, we add_
for missing arguments.resultIsOutParamSupport
is used to control whether special support is used when processing applications of functions that return output parameter of some local instance. Example:
The result typeGetElem.getElem : {Cont : Type u_1} → {Idx : Type u_2} → {elem : Type u_3} → {dom : cont → idx → Prop} → [self : GetElem cont idx elem dom] → (xs : cont) → (i : idx) → dom xs i → elem
elem
is the output parameter of the local instanceself
. When this parameter is set totrue
, we executesynthesizeSyntheticMVarsUsingDefault
. For additional details, see comment atElabAppArgs.resultIsOutParam
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Return some info
if we should elaborate as an eliminator.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Auxiliary inductive datatype that represents the resolution of an LVal
.
- projFn: Lean.Name → Lean.Name → Lean.Name → Lean.Elab.Term.LValResolution
When applied to
f
, effectively expands toBaseStruct.fieldName (self := Struct.toBase f)
. This is a special named argument where it suppresses any explicit arguments depending on it so that type parameters don't need to be supplied. - projIdx: Lean.Name → Nat → Lean.Elab.Term.LValResolution
- const: Lean.Name → Lean.Name → Lean.Name → Lean.Elab.Term.LValResolution
When applied to
f
, effectively expands toconstName ... (Struct.toBase f)
, with the argument placed in the correct positional argument if possible, or otherwise as a named argument. TheStruct.toBase
is not present ifbaseStructName == structName
, in which case these do not need to be structures. Supports generalized field notation. - localRec: Lean.Name → Lean.Name → Lean.Expr → Lean.Elab.Term.LValResolution
Like
const
, but withfvar
instead ofconstName
. ThefullName
is the name of the recursive function, andbaseName
is the base name of the type to search for in the parameter list.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Interaction between errToSorry
and observing
. #
The method
elabTerm
catches exceptions, logs them, and returns a synthetic sorry (IFctx.errToSorry
== true).When we elaborate choice nodes (and overloaded identifiers), we track multiple results using the
observing x
combinator. Theobserving x
executesx
and returns aTermElabResult
.
observing x
does not check for synthetic sorry's, just an exception. Thus, it may think x
worked when it didn't
if a synthetic sorry was introduced. We decided that checking for synthetic sorrys at observing
is not a good solution
because it would not be clear to decide what the "main" error message for the alternative is. When the result contains
a synthetic sorry
, it is not clear which error message corresponds to the sorry
. Moreover, while executing x
, many
error messages may have been logged. Recall that we need an error per alternative at mergeFailures
.
Thus, we decided to set errToSorry
to false
whenever processing choice nodes and overloaded symbols.
Important: we rely on the property that after errToSorry
is set to
false, no elaboration function executed by x
will reset it to
true
.
Instances For
Instances For
Equations
- One or more equations did not get rendered due to their size.