Skip to content

Commit

Permalink
opt
Browse files Browse the repository at this point in the history
  • Loading branch information
Kha committed Jul 20, 2024
1 parent 850f280 commit 7de1727
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions src/Lean/Language/Lean.lean
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,9 @@ where
if (← isBeforeEditPos nextCom.data.parserState.pos) then
return .pure (← unchanged old old.data.parserState)

SnapshotTask.ofIO (some ⟨parserState.pos, ctx.input.endPos⟩) do
SnapshotTask.ofIO (some ⟨parserState.pos, ctx.input.endPos⟩) (Runtime.markPersistent <| doParseCmd old? parserState cmdState ctx)

doParseCmd old? parserState cmdState ctx := do
let beginPos := parserState.pos
let scope := cmdState.scopes.head!
let pmctx := {
Expand All @@ -421,17 +423,6 @@ where
let (stx, parserState, msgLog) := Parser.parseCommand ctx.toInputContext pmctx parserState
.empty

-- semi-fast path
if let some old := old? then
if (← isBeforeEditPos parserState.pos ctx) && old.data.stx == stx then
-- Here we must make sure to pass the *new* parser state; see NOTE in `unchanged`
return (← unchanged old parserState)
-- on first change, make sure to cancel old invocation
-- TODO: pass token into incrementality-aware elaborators to improve reuse of still-valid,
-- still-running elaboration steps?
if let some tk := ctx.oldCancelTk? then
tk.set

-- definitely resolved in `doElab` task
let elabPromise ← IO.Promise.new
let tacticCache ← old?.map (·.data.tacticCache) |>.getDM (IO.mkRef {})
Expand All @@ -443,9 +434,9 @@ where

let next? ← if Parser.isTerminalCommand stx then pure none
-- for now, wait on "command finished" snapshot before parsing next command
else some <$> finishedSnap.bindIO fun finished =>
parseCmd none parserState finished.cmdState ctx
return .mk (nextCmdSnap? := next?) {
else some <$> (finishedSnap.bindIO (sync := true) fun finished =>
parseCmd none parserState finished.cmdState ctx)
return .mk (nextCmdSnap? := next?) <| Runtime.markPersistent {
diagnostics := (← Snapshot.Diagnostics.ofMessageLog msgLog)
stx
parserState
Expand All @@ -465,8 +456,8 @@ where
-- `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 tailPos := stx.getTailPos? |>.getD beginPos
SnapshotTask.ofIO (some ⟨tailPos, tailPos⟩) do
--let tailPos := stx.getTailPos? |>.getD beginPos
.pure <$> do --SnapshotTask.ofIO (some ⟨tailPos, tailPos⟩) do
let scope := cmdState.scopes.head!
let cmdStateRef ← IO.mkRef { cmdState with messages := .empty }
/-
Expand All @@ -479,7 +470,7 @@ where
let cmdCtx : Elab.Command.Context := { ctx with
cmdPos := beginPos
tacticCache? := some tacticCacheNew
snap? := some snap
snap? := none
cancelTk? := some ctx.newCancelTk
}
let (output, _) ←
Expand Down

0 comments on commit 7de1727

Please sign in to comment.