Instances For
- monadInfo : MonadInfo
Inferred and cached information about the monad.
The mutable variables in declaration order.
- doBlockResultType : Expr
- contInfo : ContInfoRef
Information about
return,breakandcontinuecontinuations.
Instances For
Instances For
A continuation metavariable.
When generating jumps to join points or filling in expressions for break or continue, it is
still unclear what mutable variables need to be passed, because it depends on which mutable
variables were reassigned in the control flow path to any of the jumps.
The mechanism of ContVarId allows to delay the assignment of the jump expressions until the local
contexts of all the jumps are known.
- name : Name
Instances For
Equations
Instances For
Equations
Equations
Equations
- Lean.Elab.Do.instBEqContVarId.beq { name := a } { name := b } = (a == b)
- Lean.Elab.Do.instBEqContVarId.beq x✝¹ x✝ = false
Instances For
Instances For
Information about a jump site associated to ContVarId.
There will be one instance per jump site to a join point, or for each break or continue
element.
- mvar : Expr
The metavariable to be assigned with the jump to the join point. Conveniently, its captured local context is that of the jump, in which the new mutable variable definitions and result variable are in scope.
- ref : Syntax
A reference for error reporting.
Instances For
Information about a ContVarId.
- type : Expr
The monadic type of the continuation.
- tunneledVars : Std.HashSet Name
A superset of the local variable names that the jumps will refer to. Often the
mutvariables. Anylet-bound FV will be turned into ahave-bound FV by setting theirnondepflag in the local context of the metavariable for the jump site. This is a technicality to ensure thatisDefEqwill not inline thelets. - lctx : LocalContext
Local context at the time the continuation variable was created.
- jumps : Array ContVarJump
The tracked jumps to the continuation. Each contains a metavariable to be assigned later.
Instances For
- monadInstanceCache : MonadInstanceCache
- contVars : Std.HashMap ContVarId ContVarInfo
Instances For
Equations
Instances For
Elaboration of a do block do $e; $rest, results in a call
elabTerm `(do $e; $rest) = elabElem e dec, where elabElem e · is the elaborator for do
element e, and dec is the DoElemCont describing the elaboration of the rest of the block
rest.
If the semantics of e resumes its continuation rest, its elaborator must bind its result to
resultName, ensure that it has type resultType and then elaborate rest using dec.
Clearly, for term elements e : m α, the result has type α.
More subtly, for binding elements let x := e or let x ← e, the result has type PUnit and is
unrelated to the type of the bound variable x.
Examples:
returndrops the continuation;return x; pure ()elaborates topure x.let x ← e; rest xelaborates toe >>= fun x => rest x.let x := 3; let y ← (let x ← e); rest xelaborates tolet x := 3; e >>= fun x_1 => let y := (); rest x, which is immediately zeta-reduced tolet x := 3; e >>= fun x_1 => rest x.one; twoelaborates toone >>= fun (_ : PUnit) => two; it is an error ifonedoes not have typePUnit.
- resultName : Name
The name of the monadic result variable.
- resultType : Expr
The type of the monadic result.
The continuation to elaborate the
restof the block.
Instances For
Equations
Instances For
Equations
The type of elaborators for do block elements.
It is elabTerm `(do $e; $rest) = elabElem e dec, where elabElem e · is the elaborator for do
element e, and dec is the DoElemCont describing the elaboration of the rest of the block
rest.
Equations
Instances For
Information about a success, return, break or continue continuation that will be filled in
after the code using it has been elaborated.
- returnCont : DoElemCont
Instances For
Equations
Instances For
Equations
Equations
Instances For
Equations
Instances For
Constructs m α from α.
Equations
- Lean.Elab.Do.mkMonadicType resultType = do let __do_lift ← read pure (Lean.mkApp __do_lift.monadInfo.m resultType)
Instances For
The cached PUnit expression.
Equations
- Lean.Elab.Do.mkPUnit = do let __do_lift ← read pure __do_lift.monadInfo.cachedPUnit
Instances For
The cached PUnit.unit expression.
Equations
- Lean.Elab.Do.mkPUnitUnit = do let __do_lift ← read pure __do_lift.monadInfo.cachedPUnitUnit
Instances For
The expression pure (α:=α) e.
Equations
- Lean.Elab.Do.mkPureApp α e = do let e ← liftM (Lean.Elab.Term.ensureHasType (some α) e) let __do_lift ← Lean.Elab.Do.getCachedPure✝ pure (Lean.mkApp2 __do_lift α e)
Instances For
Create a DoElemCont returning the result using pure.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Register the given name as that of a mut variable if the syntax token mut is present.
Equations
- Lean.Elab.Do.declareMutVar? mutTk? x k = if mutTk?.isSome = true then Lean.Elab.Do.declareMutVar x k else k
Instances For
Throw an error if the given name is not a declared mut variable.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Throw an error if a declaration of the given name would shadow a mut variable.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Elab.Do.elabTerm stx expectedType? = do let __discr ← liftM (Lean.Elab.Do.withPendingMVars✝ (Lean.Elab.Term.elabTerm stx expectedType?)) match __discr with | (e, _pendingMVars) => pure e
Instances For
Equations
- Lean.Elab.Do.elabTermEnsuringType stx expectedType? = do let e ← liftM (Lean.Elab.Term.elabTermEnsuringType stx expectedType?) pure e
Instances For
The subset of mutVars that were reassigned in any of the childCtxs relative to the given
rootCtx.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Adds the new reaching definitions of the given tunneledVars in childCtx relative to rootCtx as
non-dependent decls.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Creates a new continuation variable of type m α given the result type α.
The tunneledVars is a superset of the let-bound variable names that the jumps will refer to.
Often it will be the mut variables. Leaving it empty inlines let-bound variables at jump sites.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Creates a new jump site for the continuation variable, to be synthesized later.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- contVarId.erase = modify fun (s : Lean.Elab.Do.State) => { monadInstanceCache := s.monadInstanceCache, contVars := s.contVars.erase contVarId }
Instances For
The subset of (← read).mutVars that were reassigned at any of the jump sites of the continuation
variable. The result array has the same order as (← read).mutVars.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Restores the local context to oldCtx and adds the new reaching definitions of the mut vars and
result. Then resume the continuation k with the mutVars restored to the given oldMutVars.
This function is useful to de-nest
let mut x := 0
let y := 3
let z ← do
let mut y ← e
x := y + 1
pure y
let y := y + 3
pure (x + y + z)
into
let mut x := 0
let y := 3
let mut y† ← e
x := y† + 1
let z ← pure y†
let y := y + 3
pure (x + y + z)
Note that the continuation of the let z ← ... bind, roughly
k := .cont `z _ `(let y := y + 3; pure (x + y + z)),
needs to elaborated in a local context that contains the reassignment of x, but not the shadowing
mut var definition of y.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Return $e >>= fun ($dec.resultName : $dec.resultType) => $(← dec.k), cancelling
the bind if $(← dec.k) is pure $dec.resultName.
Equations
- dec.mkBindUnlessPure e = Lean.Elab.Do.mkBindCancellingPure dec.resultName dec.resultType e fun (x : Lean.Expr) => dec.k
Instances For
Return let $k.resultName : PUnit := PUnit.unit; $(← k.k), ensuring that the result type of k.k
is PUnit and then immediately zeta-reduce the let.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Call caller with a duplicable proxy of dec.
When the proxy is elaborated more than once, a join point is introduced so that dec is only
elaborated once to fill in the RHS of this join point.
This is useful for control-flow constructs like if and match, where multiple tail-called
branches share the continuation.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given a list of mut vars vars and an FVar tupleVar binding a tuple, bind the mut vars to the
fields of the tuple and call k in the resulting local context.
Equations
- Lean.Elab.Do.bindMutVarsFromTuple vars tupleVar k = do let __do_lift ← liftM tupleVar.getType Lean.Elab.Do.bindMutVarsFromTuple.go✝ k vars tupleVar __do_lift #[]
Instances For
Equations
- Lean.Elab.Do.getReturnCont = do let __do_lift ← read pure __do_lift.contInfo.toContInfo.returnCont
Instances For
Equations
- Lean.Elab.Do.getBreakCont = do let __do_lift ← read pure __do_lift.contInfo.toContInfo.breakCont
Instances For
Equations
- Lean.Elab.Do.getContinueCont = do let __do_lift ← read pure __do_lift.contInfo.toContInfo.continueCont
Instances For
Introduce proxy redefinitions for all mut vars and call the continuation k with a function
elimProxyDefs : Expr → MetaM Expr similar to mkLetFVars that will replace the proxy defs with
the actual reassigned or original definitions.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Prepare the context for elaborating the body of a loop.
This includes setting the return continuation, break continuation, continue continuation, as
well as the changed result type of the do block in the loop body.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Prepare the context for elaborating the body of a finally block.
There is no support for mut vars, break, continue or return in a finally block.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Elab.Do.DoElabM.saveState = do let __do_lift ← liftM Lean.Elab.Term.saveState let __do_lift_1 ← get pure { term := __do_lift, «do» := __do_lift_1 }
Instances For
Equations
- Lean.Elab.Do.instMonadBacktrackSavedStateDoElabM = { saveState := Lean.Elab.Do.DoElabM.saveState, restoreState := fun (b : Lean.Elab.Do.SavedState) => b.restore }
Equations
- Lean.Elab.Do.mkDoElemElabAttributeUnsafe ref = Lean.Elab.mkElabAttribute Lean.Elab.Do.DoElab `builtin_doElem_elab `doElem_elab `Lean.Parser.Term.doElem `Lean.Elab.Do.DoElab "do element" ref
Instances For
Registers a do element elaborator for the given syntax node kind.
A do element elaborator should have type DoElab (which is
Lean.Syntax → DoElemCont → DoElabM Expr), i.e. should take syntax of the given syntax node kind
and a DoElemCont as parameters and produce an expression.
When elaborating a do block do e; rest, the elaborator for e is invoked with the syntax of e
and the DoElemCont representing rest.
The elab_rules and elab commands should usually be preferred over using this attribute
directly.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Elab.Do.elabDoSeq doSeq cont = Lean.Elab.Do.elabDoElems1 (Lean.Parser.Term.getDoElems doSeq) cont
Instances For
Equations
- Lean.Elab.Do.dooBlock = Lean.ParserDescr.node `Lean.Elab.Do.dooBlock 1023 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol "doo") (Lean.ParserDescr.const `doSeq))
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.