@@ -397,7 +397,7 @@ where
397397 diagnostics := oldProcessed.diagnostics
398398 result? := some {
399399 cmdState := oldProcSuccess.cmdState
400- firstCmdSnap := { stx? := none, task := prom.result! } } }
400+ firstCmdSnap := { stx? := none, task := prom.result!, cancelTk? := cancelTk } } }
401401 else
402402 return .finished newStx oldProcessed) } }
403403 else return old
@@ -450,7 +450,7 @@ where
450450 processHeader (stx : Syntax) (parserState : Parser.ModuleParserState) :
451451 LeanProcessingM (SnapshotTask HeaderProcessedSnapshot) := do
452452 let ctx ← read
453- SnapshotTask.ofIO stx (some ⟨0 , ctx.input.endPos⟩) <|
453+ SnapshotTask.ofIO stx none (some ⟨0 , ctx.input.endPos⟩) <|
454454 ReaderT.run (r := ctx) <| -- re-enter reader in new task
455455 withHeaderExceptions (α := HeaderProcessedSnapshot) ({ · with result? := none }) do
456456 let setup ← match (← setupImports stx) with
@@ -507,7 +507,7 @@ where
507507 infoTree? := cmdState.infoState.trees[0 ]!
508508 result? := some {
509509 cmdState
510- firstCmdSnap := { stx? := none, task := prom.result! }
510+ firstCmdSnap := { stx? := none, task := prom.result!, cancelTk? := cancelTk }
511511 }
512512 }
513513
@@ -523,17 +523,19 @@ where
523523 -- from `old`
524524 if let some oldNext := old.nextCmdSnap? then do
525525 let newProm ← IO.Promise.new
526+ let cancelTk ← IO.CancelToken.new
526527 -- can reuse range, syntax unchanged
527528 BaseIO.chainTask (sync := true ) old.resultSnap.task fun oldResult =>
528529 -- also wait on old command parse snapshot as parsing is cheap and may allow for
529530 -- elaboration reuse
530531 BaseIO.chainTask (sync := true ) oldNext.task fun oldNext => do
531- let cancelTk ← IO.CancelToken.new
532532 parseCmd oldNext newParserState oldResult.cmdState newProm sync cancelTk ctx
533533 prom.resolve <| { old with nextCmdSnap? := some {
534534 stx? := none
535535 reportingRange? := some ⟨newParserState.pos, ctx.input.endPos⟩
536- task := newProm.result! } }
536+ task := newProm.result!
537+ cancelTk? := cancelTk
538+ } }
537539 else prom.resolve old -- terminal command, we're done!
538540
539541 -- fast path, do not even start new task for this snapshot (see [Incremental Parsing])
@@ -615,15 +617,16 @@ where
615617 })
616618 let diagnostics ← Snapshot.Diagnostics.ofMessageLog msgLog
617619
618- -- use per-command cancellation token for elaboration so that
620+ -- use per-command cancellation token for elaboration so that cancellation of further commands
621+ -- does not affect current command
619622 let elabCmdCancelTk ← IO.CancelToken.new
620623 prom.resolve {
621624 diagnostics, nextCmdSnap?
622625 stx := stx', parserState := parserState'
623626 elabSnap := { stx? := stx', task := elabPromise.result!, cancelTk? := some elabCmdCancelTk }
624- resultSnap := { stx? := stx', reportingRange? := initRange?, task := resultPromise.result! }
625- infoTreeSnap := { stx? := stx', reportingRange? := initRange?, task := finishedPromise.result! }
626- reportSnap := { stx? := none, reportingRange? := initRange?, task := reportPromise.result! }
627+ resultSnap := { stx? := stx', reportingRange? := initRange?, task := resultPromise.result!, cancelTk? := none }
628+ infoTreeSnap := { stx? := stx', reportingRange? := initRange?, task := finishedPromise.result!, cancelTk? := none }
629+ reportSnap := { stx? := none, reportingRange? := initRange?, task := reportPromise.result!, cancelTk? := none }
627630 }
628631 let cmdState ← doElab stx cmdState beginPos
629632 { old? := old?.map fun old => ⟨old.stx, old.elabSnap⟩, new := elabPromise }
@@ -665,8 +668,8 @@ where
665668 -- We want to trace all of `CommandParsedSnapshot` but `traceTask` is part of it, so let's
666669 -- create a temporary snapshot tree containing all tasks but it
667670 let snaps := #[
668- { stx? := stx', task := elabPromise.result!.map (sync := true ) toSnapshotTree },
669- { stx? := stx', task := resultPromise.result!.map (sync := true ) toSnapshotTree }] ++
671+ { stx? := stx', task := elabPromise.result!.map (sync := true ) toSnapshotTree, cancelTk? := none },
672+ { stx? := stx', task := resultPromise.result!.map (sync := true ) toSnapshotTree, cancelTk? := none }] ++
670673 cmdState.snapshotTasks
671674 let tree := SnapshotTree.mk { diagnostics := .empty } snaps
672675 BaseIO.bindTask (← tree.waitAll) fun _ => do
@@ -690,6 +693,7 @@ where
690693 stx? := none
691694 reportingRange? := initRange?
692695 task := traceTask
696+ cancelTk? := none
693697 }
694698 if let some next := next? then
695699 -- We're definitely off the fast-forwarding path now
0 commit comments