Instances For
Whether a code block is alive or dead.
- deadSyntactically : CodeLiveness
We inferred the code is semantically dead and don't need to elaborate it at all.
- deadSemantically : CodeLiveness
We inferred the code is semantically dead, but we need to elaborate it to produce a program.
- alive : CodeLiveness
The code is alive. (Or it is dead, but we failed to prove it so.)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Equations
- Lean.Elab.Do.instToMessageDataCodeLiveness = { toMessageData := fun (l : Lean.Elab.Do.CodeLiveness) => (Lean.MessageData.ofFormat ∘ Std.format) (toString l) }
The least upper bound of two code livenesses.
Equations
Instances For
- monadInfo : MonadInfo
Inferred and cached information about the monad.
The mutable variables in declaration order.
- mutVarDefs : Std.HashMap Name FVarId
Maps mutable variable names to their initial FVarIds.
- doBlockResultType : Expr
The expected type of the current
doblock. This can be different fromearlyReturnTypeinforloopdoblocks, for example. - contInfo : ContInfoRef
Information about
return,breakandcontinuecontinuations. - deadCode : CodeLiveness
Whether the current
doelement is dead code.elabDoElemwill emit a warning if not.alive.
Instances For
Instances For
Whether the continuation of a do element is duplicable and if so whether it is just pure r for
the result variable r. Saying nonDuplicable is always safe; duplicable allows for more
optimizations.
- nonDuplicable : DoElemContKind
- duplicable : DoElemContKind
Instances For
Equations
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. It assumes that the result of thedoblock is bound toresultNamewith the correct type (that is,resultType, potentially refined by a dependentmatch).- kind : DoElemContKind
Whether we are OK with generating the code of the continuation multiple times, e.g. in different branches of a
matchorif.
Instances For
Equations
Equations
Instances For
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
- resultType : Expr
The elaborator constructing a jump site to the return continuation, given some return value. The type of this return value determines the type of the jump expression; this could very well be different than the
resultTypein case an interveningmatchas refinedresultType. Sokmust not hardcode the typeresultTypeinto its definition; rather it should infer the type of the return value argument.
Instances For
Instances For
Equations
Information about a success, return, break or continue continuation that will be filled in
after the code using it has been elaborated.
- returnCont : ReturnCont
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
- One or more equations did not get rendered due to their size.
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
Create a ReturnCont 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
Register the given names as that of mut variables if the syntax token mut is present.
Equations
- Lean.Elab.Do.declareMutVars? mutTk? xs k = if mutTk?.isSome = true then Lean.Elab.Do.declareMutVars xs 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
Create a fresh α that would fit in m α.
Equations
- Lean.Elab.Do.mkFreshResultType userName kind = do let __do_lift ← read liftM (Lean.Meta.mkFreshExprMVar (some (Lean.mkSort (Lean.mkLevelSucc __do_lift.monadInfo.u))) kind userName)
Instances For
Like controlAt TermElabM, but it maintains the state using the DoElabM's ref cell instead of returning it
in the TermElabM result. This makes it possible to run multiple DoElabM computations in a row.
Equations
- Lean.Elab.Do.controlAtTermElabM k ctx = k fun {β : Type} (x : Lean.Elab.Do.DoElabM β) => x ctx
Instances For
Equations
- Lean.Elab.Do.mapTermElabM f k = Lean.Elab.Do.controlAtTermElabM fun (runInBase : {β : Type} → Lean.Elab.Do.DoElabM β → Lean.Elab.TermElabM β) => f (runInBase k)
Instances For
Equations
- Lean.Elab.Do.map1TermElabM f k = Lean.Elab.Do.controlAtTermElabM fun (runInBase : {β : Type} → Lean.Elab.Do.DoElabM β → Lean.Elab.TermElabM β) => f fun (b : β) => runInBase (k b)
Instances For
Equations
- One or more equations did not get rendered due to their size.
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
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 or e is some pure computation.
Equations
- One or more equations did not get rendered due to their size.
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
Elaborate the DoElemCont with the deadCode flag set to deadSyntactically to emit warnings.
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.DoElabM.saveState = do let __do_lift ← liftM Lean.Elab.Term.saveState pure { term := __do_lift }
Instances For
Equations
- Lean.Elab.Do.instMonadBacktrackSavedStateDoElabM = { saveState := Lean.Elab.Do.DoElabM.saveState, restoreState := fun (b : Lean.Elab.Do.SavedState) => b.restore }
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Lean.Elab.Do.doElabToSyntax hint doElab k ref = Lean.Elab.Do.doElabToSyntaxWithExpectedType hint (fun (_ty? : Option Lean.Expr) => doElab) k ref
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
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
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
- Lean.Elab.Do.enterFinally resultType k = Lean.Elab.Do.withoutControl (Lean.Elab.Do.withDoBlockResultType resultType k)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
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
- One or more equations did not get rendered due to their size.