Skip to content

Commit 548f78b

Browse files
authored
doc: fix stale references in do elaborator docs (#14026)
This PR fixes doc typos and stale references in the `do` elaborator and parser: the `CodeLiveness.deadSyntactically` docstring describes syntactically dead code, the `Context.doBlockResultType` docstring references `ReturnCont.resultType`, `ControlInfo` comments reference the `returnsEarly` field, the `DoElemContKind` docstring drops a stale remark about `pure` continuations, the `doElem_control_info` docstring markup is repaired, the `ControlInfo.pure`/`sequence`/`alternative` docstrings are rewritten in the style of `ControlInfo.empty`, the `EffectForwarder.lift` docstring references `ControlStack.mkBreak`/`mkContinue`/`mkReturn`, and grammar typos in `withLCtxKeepingMutVarDefs`, `expandToTermMatch` and the `doFor`/`idbg` parser docstrings are fixed.
1 parent 6271d8f commit 548f78b

5 files changed

Lines changed: 26 additions & 18 deletions

File tree

src/Lean/Elab/BuiltinDo/Match.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private def elabDoSeqWithRefinedType (type : Expr) (doSeq : DoSeq) (dec : DoElem
3636
withDoBlockResultType newDoBlockResultType (elabDoSeq doSeq dec)
3737

3838
/--
39-
Expand a `doMatch` into a term `match` term. We do this for `match_syntax` and
39+
Expand a `doMatch` into a term-level `match`. We do this for `match_syntax` and
4040
`match (dependent := true)`. For the latter, the functionality is very restricted to effectively
4141
ban join points.
4242
Reason: In case of a dependent match, it is hard to guarantee that generalization of join points and

src/Lean/Elab/Do/Basic.lean

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ instance : Nonempty DoOpsRef :=
5656

5757
/-- Whether a code block is alive or dead. -/
5858
inductive CodeLiveness where
59-
/-- We inferred the code is semantically dead and don't need to elaborate it at all. -/
59+
/-- We inferred the code is syntactically dead and don't need to elaborate it at all. -/
6060
| deadSyntactically
6161
/-- We inferred the code is semantically dead, but we need to elaborate it to produce a program. -/
6262
| deadSemantically
@@ -115,7 +115,7 @@ structure Context where
115115
mutVarDefs : Std.HashMap Name MutVar := {}
116116
/--
117117
The expected type of the current `do` block.
118-
This can be different from `earlyReturnType` in `for` loop `do` blocks, for example.
118+
This can be different from `ReturnCont.resultType` in `for` loop `do` blocks, for example.
119119
-/
120120
doBlockResultType : Expr
121121
/-- Information about `return`, `break` and `continue` continuations. -/
@@ -160,9 +160,8 @@ unsafe def DoOpsRef.toDoOpsImpl (r : DoOpsRef) : DoOps :=
160160
opaque DoOpsRef.toDoOps (r : DoOpsRef) : DoOps
161161

162162
/--
163-
Whether the continuation of a `do` element is duplicable and if so whether it is just `pure r` for
164-
the result variable `r`. Saying `nonDuplicable` is always safe; `duplicable` allows for more
165-
optimizations.
163+
Whether the continuation of a `do` element is duplicable. Saying `nonDuplicable` is always safe;
164+
`duplicable` allows for more optimizations.
166165
-/
167166
inductive DoElemContKind
168167
| nonDuplicable
@@ -224,7 +223,7 @@ structure ReturnCont where
224223
/--
225224
The elaborator constructing a jump site to the return continuation,
226225
given some return value. The type of this return value determines the type of the jump expression;
227-
this could very well be different than the `resultType` in case an intervening `match` as refined
226+
this could very well be different than the `resultType` in case an intervening `match` has refined
228227
`resultType`. So `k` must *not* hardcode the type `resultType` into its definition; rather it
229228
should infer the type of the return value argument.
230229
-/
@@ -450,7 +449,7 @@ pure (x + y + z)
450449
```
451450
Note that the continuation of the `let z ← ...` bind, roughly
452451
``k := .cont `z _ `(let y := y + 3; pure (x + y + z))``,
453-
needs to elaborated in a local context that contains the reassignment of `x`, but not the shadowing
452+
needs to be elaborated in a local context that contains the reassignment of `x`, but not the shadowing
454453
mut var definition of `y`.
455454
-/
456455
def withLCtxKeepingMutVarDefs (oldLCtx : LocalContext) (oldCtx : Context) (resultName : Name) (k : DoElabM α) : DoElabM α := do

src/Lean/Elab/Do/Control.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ handlers funnelling into `liftedStack` and set the doBlock result type to
248248
`liftedDoBlockResultType`. Semantically
249249
`MonadControl.liftWith fun runInBase => elabElem (runInBase pure)`. Conts
250250
passed to `elabElem` are implicitly wrapped in `runInBase`, realised later by
251-
`ControlStack.synthesizeConts` once the transformer stack `t` is fixed by
251+
`ControlStack.mkBreak`/`mkContinue`/`mkReturn` once the transformer stack `t` is fixed by
252252
aggregating effects across *all* `lift` sites for this lifter.
253253
-/
254254
def EffectForwarder.lift (l : EffectForwarder) (elabElem : DoElemCont → DoElabM Expr) : DoElabM Expr := do

src/Lean/Elab/Do/InferControlInfo.lean

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ structure ControlInfo where
5757
reassigns : NameSet := {}
5858
deriving Inhabited
5959

60-
/-- A `ControlInfo` for an element that always falls through normally with a single exit. -/
60+
/--
61+
The left identity of `ControlInfo.sequence`: a `ControlInfo` describing an element that always
62+
falls through normally with a single regular exit.
63+
-/
6164
def ControlInfo.pure : ControlInfo := {}
6265

6366
/--
@@ -66,7 +69,10 @@ at all (so no regular exits and the next element is trivially unreachable).
6669
-/
6770
def ControlInfo.empty : ControlInfo := { numRegularExits := 0, noFallthrough := true }
6871

69-
/-- Combine info for `a; b`: union effect flags, exits/dead follow `b`/either. -/
72+
/--
73+
The `ControlInfo` of a sequence `a; b`: effect flags are unioned, the regular exits are those of
74+
`b`, and the sequence falls through iff both parts fall through.
75+
-/
7076
def ControlInfo.sequence (a b : ControlInfo) : ControlInfo := {
7177
-- Syntactic fields aggregate unconditionally; the elaborator keeps visiting `b` unless `a` is
7278
-- a syntactically-terminal element (only top-level `return`/`break`/`continue` are, via
@@ -80,7 +86,10 @@ def ControlInfo.sequence (a b : ControlInfo) : ControlInfo := {
8086
noFallthrough := a.noFallthrough || b.noFallthrough,
8187
}
8288

83-
/-- Combine info for branches `a | b`: union flags, sum exits, dead iff both dead. -/
89+
/--
90+
The `ControlInfo` of branches `a | b`: effect flags are unioned, the regular exits are summed, and
91+
the alternative falls through iff at least one branch falls through.
92+
-/
8493
def ControlInfo.alternative (a b : ControlInfo) : ControlInfo := {
8594
breaks := a.breaks || b.breaks,
8695
continues := a.continues || b.continues,
@@ -178,7 +187,7 @@ partial def ofElem (stx : DoElem) : TermElabM ControlInfo := do
178187
-- For/Repeat
179188
| `(doElem| for $[$[$_ :]? $_ in $_],* do $bodySeq) =>
180189
let info ← ofSeq bodySeq
181-
return { info with -- keep only reassigns and earlyReturn
190+
return { info with -- keep only reassigns and returnsEarly
182191
numRegularExits := 1,
183192
continues := false,
184193
breaks := false,
@@ -189,7 +198,7 @@ partial def ofElem (stx : DoElem) : TermElabM ControlInfo := do
189198
-- surrounding continuation still has a polymorphic value to hand back, and any dead-code
190199
-- warning on subsequent elements is actionable.
191200
let info ← ofSeq bodySeq
192-
return { info with -- keep only reassigns and earlyReturn
201+
return { info with -- keep only reassigns and returnsEarly
193202
numRegularExits := if info.breaks then 1 else 0,
194203
continues := false,
195204
breaks := false,

src/Lean/Parser/Do.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ def doIfCond :=
177177
def doForDecl := leading_parser
178178
optional (atomic (ident >> " : ")) >> termParser >> " in " >> withForbidden "do" termParser
179179
/--
180-
`for x in e do s` iterates over `e` assuming `e`'s type has an instance of the `ForIn` typeclass.
180+
`for x in e do s` iterates over `e` assuming `e`'s type has an instance of the `ForIn` typeclass.
181181
`break` and `continue` are supported inside `for` loops.
182-
`for x in e, x2 in e2, ... do s` iterates of the given collections in parallel,
182+
`for x in e, x2 in e2, ... do s` iterates over the given collections in parallel,
183183
until at least one of them is exhausted.
184184
The types of `e2` etc. must implement the `Std.ToStream` typeclass.
185185
-/
@@ -271,11 +271,11 @@ the program need to be recompiled and restarted.
271271
272272
# Known Limitations
273273
274-
* The program will poll for the server for up to 10 minutes and needs to be killed manually
274+
* The program will poll the server for up to 10 minutes and needs to be killed manually
275275
otherwise.
276276
* Use of multiple `idbg` at once untested, likely too much overhead from overlapping imports without
277277
further changes.
278-
* `LEAN_PATH` must be properly set up so compiled program can import its origin module.
278+
* `LEAN_PATH` must be properly set up so the compiled program can import its origin module.
279279
* Untested on Windows and macOS.
280280
-/
281281
@[builtin_doElem_parser] def doIdbg := leading_parser:leadPrec

0 commit comments

Comments
 (0)