@@ -524,12 +524,12 @@ where
524
524
if let some oldNext := old.nextCmdSnap? then do
525
525
let newProm ← IO.Promise.new
526
526
-- can reuse range, syntax unchanged
527
- BaseIO.chainTask (sync := true ) old.finishedSnap .task fun oldFinished =>
527
+ BaseIO.chainTask (sync := true ) old.resultSnap .task fun oldResult =>
528
528
-- also wait on old command parse snapshot as parsing is cheap and may allow for
529
529
-- elaboration reuse
530
530
BaseIO.chainTask (sync := true ) oldNext.task fun oldNext => do
531
531
let cancelTk ← IO.CancelToken.new
532
- parseCmd oldNext newParserState oldFinished .cmdState newProm sync cancelTk ctx
532
+ parseCmd oldNext newParserState oldResult .cmdState newProm sync cancelTk ctx
533
533
prom.resolve <| { old with nextCmdSnap? := some {
534
534
stx? := none
535
535
reportingRange? := some ⟨newParserState.pos, ctx.input.endPos⟩
@@ -582,7 +582,8 @@ where
582
582
prom.resolve <| {
583
583
diagnostics := .empty, stx := .missing, parserState
584
584
elabSnap := default
585
- finishedSnap := .finished none { diagnostics := .empty, cmdState }
585
+ resultSnap := .finished none { diagnostics := .empty, cmdState }
586
+ infoTreeSnap := .finished none { diagnostics := .empty }
586
587
reportSnap := default
587
588
nextCmdSnap? := none
588
589
}
@@ -592,6 +593,7 @@ where
592
593
let _ ← (if sync then BaseIO.asTask else (.pure <$> ·)) do
593
594
-- definitely resolved in `doElab` task
594
595
let elabPromise ← IO.Promise.new
596
+ let resultPromise ← IO.Promise.new
595
597
let finishedPromise ← IO.Promise.new
596
598
let reportPromise ← IO.Promise.new
597
599
let minimalSnapshots := internal.cmdlineSnapshots.get cmdState.scopes.head!.opts
@@ -602,11 +604,6 @@ where
602
604
-- report terminal tasks on first line of decl such as not to hide incremental tactics'
603
605
-- progress
604
606
let initRange? := getNiceCommandStartPos? stx |>.map fun pos => ⟨pos, pos⟩
605
- let finishedSnap := {
606
- stx? := stx'
607
- reportingRange? := initRange?
608
- task := finishedPromise.result!
609
- }
610
607
let next? ← if Parser.isTerminalCommand stx then pure none
611
608
-- for now, wait on "command finished" snapshot before parsing next command
612
609
else some <$> IO.Promise.new
@@ -621,21 +618,55 @@ where
621
618
-- use per-command cancellation token for elaboration so that
622
619
let elabCmdCancelTk ← IO.CancelToken.new
623
620
prom.resolve {
624
- diagnostics, finishedSnap, nextCmdSnap?
621
+ diagnostics, nextCmdSnap?
625
622
stx := stx', parserState := parserState'
626
623
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! }
627
626
reportSnap := { stx? := none, reportingRange? := initRange?, task := reportPromise.result! }
628
627
}
629
628
let cmdState ← doElab stx cmdState beginPos
630
629
{ old? := old?.map fun old => ⟨old.stx, old.elabSnap⟩, new := elabPromise }
631
- finishedPromise elabCmdCancelTk ctx
630
+ elabCmdCancelTk ctx
631
+
632
+ let mut reportedCmdState := cmdState
633
+ let cmdline := internal.cmdlineSnapshots.get scope.opts && !Parser.isTerminalCommand stx
634
+ if cmdline then
635
+ -- discard all metadata apart from the environment; see `internal.cmdlineSnapshots`
636
+ reportedCmdState := { env := reportedCmdState.env, maxRecDepth := 0 }
637
+ resultPromise.resolve {
638
+ diagnostics := (← Snapshot.Diagnostics.ofMessageLog cmdState.messages)
639
+ traces := cmdState.traceState
640
+ cmdState := reportedCmdState
641
+ }
642
+
643
+ -- report info tree when relevant tasks are finished
644
+ BaseIO.chainTask (sync := true ) (t := cmdState.infoState.substituteLazy) fun infoSt => do
645
+ let infoTree := infoSt.trees[0 ]!
646
+ let opts := cmdState.scopes.head!.opts
647
+ let mut msgLog := MessageLog.empty
648
+ if (← isTracingEnabledForCore `Elab.info opts) then
649
+ if let .ok msg ← infoTree.format.toBaseIO then
650
+ let data := .tagged `trace <| .trace { cls := `Elab.info } .nil #[msg]
651
+ msgLog := msgLog.add {
652
+ fileName := ctx.fileName
653
+ severity := MessageSeverity.information
654
+ pos := ctx.fileMap.toPosition beginPos
655
+ data := data
656
+ }
657
+ finishedPromise.resolve {
658
+ diagnostics := (← Snapshot.Diagnostics.ofMessageLog msgLog)
659
+ infoTree? := infoTree
660
+ }
661
+
662
+ -- report traces when *all* tasks are finished
632
663
let traceTask ←
633
664
if (← isTracingEnabledForCore `Elab.snapshotTree cmdState.scopes.head!.opts) then
634
665
-- We want to trace all of `CommandParsedSnapshot` but `traceTask` is part of it, so let's
635
666
-- create a temporary snapshot tree containing all tasks but it
636
667
let snaps := #[
637
668
{ stx? := stx', task := elabPromise.result!.map (sync := true ) toSnapshotTree },
638
- { stx? := stx', task := finishedPromise .result!.map (sync := true ) toSnapshotTree }] ++
669
+ { stx? := stx', task := resultPromise .result!.map (sync := true ) toSnapshotTree }] ++
639
670
cmdState.snapshotTasks
640
671
let tree := SnapshotTree.mk { diagnostics := .empty } snaps
641
672
BaseIO.bindTask (← tree.waitAll) fun _ => do
@@ -665,8 +696,8 @@ where
665
696
parseCmd none parserState cmdState next (sync := false ) elabCmdCancelTk ctx
666
697
667
698
doElab (stx : Syntax) (cmdState : Command.State) (beginPos : String.Pos)
668
- (snap : SnapshotBundle DynamicSnapshot) (finishedPromise : IO.Promise CommandFinishedSnapshot)
669
- (cancelTk : IO.CancelToken) : LeanProcessingM Command.State := do
699
+ (snap : SnapshotBundle DynamicSnapshot) (cancelTk : IO.CancelToken) :
700
+ LeanProcessingM Command.State := do
670
701
let ctx ← read
671
702
let scope := cmdState.scopes.head!
672
703
-- reset per-command state
@@ -693,21 +724,9 @@ where
693
724
data := output
694
725
}
695
726
let cmdState : Command.State := { cmdState with messages }
696
- let mut reportedCmdState := cmdState
697
727
-- definitely resolve eventually
698
728
snap.new.resolve <| .ofTyped { diagnostics := .empty : SnapshotLeaf }
699
729
700
- let infoTree : InfoTree := cmdState.infoState.trees[0 ]!
701
- let cmdline := internal.cmdlineSnapshots.get scope.opts && !Parser.isTerminalCommand stx
702
- if cmdline then
703
- -- discard all metadata apart from the environment; see `internal.cmdlineSnapshots`
704
- reportedCmdState := { env := reportedCmdState.env, maxRecDepth := 0 }
705
- finishedPromise.resolve {
706
- diagnostics := (← Snapshot.Diagnostics.ofMessageLog cmdState.messages)
707
- infoTree? := infoTree
708
- traces := cmdState.traceState
709
- cmdState := reportedCmdState
710
- }
711
730
-- The reported `cmdState` in the snapshot may be minimized as seen above, so we return the full
712
731
-- state here for further processing on the same thread
713
732
return cmdState
@@ -735,6 +754,6 @@ where goCmd snap :=
735
754
if let some next := snap.nextCmdSnap? then
736
755
goCmd next.get
737
756
else
738
- snap.finishedSnap .get.cmdState
757
+ snap.resultSnap .get.cmdState
739
758
740
759
end Lean
0 commit comments