Skip to content

Commit

Permalink
move progress ranges of post-elaboration task from end to beginning o…
Browse files Browse the repository at this point in the history
…f command
  • Loading branch information
Kha committed Jan 14, 2025
1 parent 937bdf5 commit b7e5478
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
16 changes: 9 additions & 7 deletions src/Lean/Elab/MutualDef.lean
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ private def elabHeaders (views : Array DefView)
return newHeader
if let some snap := view.headerSnap? then
let (tacStx?, newTacTask?) ← mkTacTask view.value tacPromise
let bodySnap :=
-- Only use first line of body as range when we have incremental tactics as otherwise we
-- would cover their progress
{ range? := if newTacTask?.isSome then
view.ref.getPos?.map fun pos => ⟨pos, pos⟩
else
getBodyTerm? view.value |>.getD view.value |>.getRange?
task := bodyPromise.result }
snap.new.resolve <| some {
diagnostics :=
(← Language.Snapshot.Diagnostics.ofMessageLog (← Core.getAndEmptyMessageLog))
Expand All @@ -223,7 +231,7 @@ private def elabHeaders (views : Array DefView)
tacStx?
tacSnap? := newTacTask?
bodyStx := view.value
bodySnap := mkBodyTask view.value bodyPromise
bodySnap
}
newHeader := { newHeader with
-- We should only forward the promise if we are actually waiting on the
Expand All @@ -245,12 +253,6 @@ where
guard whereDeclsOpt.isNone
return body

/-- Creates snapshot task with appropriate range from body syntax and promise. -/
mkBodyTask (body : Syntax) (new : IO.Promise (Option BodyProcessedSnapshot)) :
Language.SnapshotTask (Option BodyProcessedSnapshot) :=
let rangeStx := getBodyTerm? body |>.getD body
{ range? := rangeStx.getRange?, task := new.result }

/--
If `body` allows for incremental tactic reporting and reuse, creates a snapshot task out of the
passed promise with appropriate range, otherwise immediately resolves the promise to a dummy
Expand Down
24 changes: 13 additions & 11 deletions src/Lean/Language/Lean.lean
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,13 @@ If the option is defined in this library, use '-D{`weak ++ name}' to set it cond

return opts

private def getNiceCommandStartPos? (stx : Syntax) : Option String.Pos := do
let mut stx := stx
if stx[0].isOfKind ``Command.declModifiers then
-- modifiers are morally before the actual declaration
stx := stx[1]
stx.getPos?

/--
Entry point of the Lean language processor.
Expand Down Expand Up @@ -540,15 +547,10 @@ where
let elabPromise ← IO.Promise.new
let finishedPromise ← IO.Promise.new
let reportPromise ← IO.Promise.new
-- (Try to) use last line of command as range for final snapshot task. This ensures we do not
-- retract the progress bar to a previous position in case the command support incremental
-- reporting but has significant work after resolving its last incremental promise, such as
-- final type checking; if it does not support incrementality, `elabSnap` constructed in
-- `parseCmd` and containing the entire range of the command will determine the reported
-- progress and be resolved effectively at the same time as this snapshot task, so `tailPos` is
-- irrelevant in this case.
let endRange? := stx.getTailPos?.map fun pos => ⟨pos, pos⟩
let finishedSnap := { range? := endRange?, task := finishedPromise.result }
-- report terminal tasks on first line of decl such as not to hide incremental tactics'
-- progress
let initRange? := getNiceCommandStartPos? stx |>.map fun pos => ⟨pos, pos⟩
let finishedSnap := { range? := initRange?, task := finishedPromise.result }
let tacticCache ← old?.map (·.tacticCache) |>.getDM (IO.mkRef {})

let minimalSnapshots := internal.cmdlineSnapshots.get cmdState.scopes.head!.opts
Expand All @@ -566,7 +568,7 @@ where
diagnostics, finishedSnap, tacticCache, nextCmdSnap?
stx := stx', parserState := parserState'
elabSnap := { range? := stx.getRange?, task := elabPromise.result }
reportSnap := { range? := endRange?, task := reportPromise.result }
reportSnap := { range? := initRange?, task := reportPromise.result }
}
let cmdState ← doElab stx cmdState beginPos
{ old? := old?.map fun old => ⟨old.stx, old.elabSnap⟩, new := elabPromise }
Expand Down Expand Up @@ -597,7 +599,7 @@ where
pure <| .pure <| .mk { diagnostics := .empty } #[]
reportPromise.resolve <|
.mk { diagnostics := .empty } <|
cmdState.snapshotTasks.push { range? := endRange?, task := traceTask }
cmdState.snapshotTasks.push { range? := initRange?, task := traceTask }
if let some next := next? then
-- We're definitely off the fast-forwarding path now
parseCmd none parserState cmdState next (sync := false) ctx
Expand Down

0 comments on commit b7e5478

Please sign in to comment.