lean4-htt/tests/lean/interactive/incrementalTactic.lean
Sebastian Ullrich adfd438164
fix: incremental reuse leading to goals in front of the text cursor being shown (#4395)
As [reported on
Zulip](https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/maybe.20a.20cache.20bug.3F).

We expected that for sound reuse of elaboration results, it is
sufficient to compare the old and new syntax tree's structure and atoms
including position info, but not the whitespace in between them.
However, we have at least one request handler, the goal view, that
inspects the whitespace after a tactic and thus could return incorrect
results on reuse. For now we implement the straightforward fix of
checking the whitespace as well. Alternatives like updating the
whitespace stored in the reused info tree are tbd.

This has the slight disadvantage that adding whitespace at the end of a
tactic will re-execute it (or the entire body, but not the header, if
the body is not a tactic block), but only up to typing the first
character of the next tactic or command.
2024-06-08 15:08:14 +00:00

73 lines
1.9 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/-! Basic incremental reuse in top-level tactic block -/
-- set_option trace.Elab.reuse true
def basic : True := by
dbg_trace "b 0"
apply id
dbg_trace "b 1"
apply id
dbg_trace "b 2"
--^ sync
--^ insert: ".5"
/-!
Ideally trailing whitespace should be ignored. CURRENTLY NOT WORKING as we use `Syntax.eqWithInfo`;
we will need to patch old syntax info stored in the info tree to go back to `Syntax.structRangeEq`.
-/
-- RESET
def trailingWhitespace : True := by
dbg_trace "t 0"
dbg_trace "t 1"
dbg_trace "t 2"
--^ sync
--^ insert: "\n "
-- RESET
-- this used to restore the wrong elab state because of input context mis-tracking
def haveBug : True := by
have (a : Nat) : Nat → True := by
intro n m
--^ sync
--^ delete: "intro n m"
--^ sync
--^ insert: "intro n m"
--^ collectDiagnostics
exact m
/-! incremental reporting should obey `showPartialSyntaxErrors` -/
-- RESET
def partialSyntax : True := by apply (
--^ collectDiagnostics
/-! A tactic block not supported by incrementality should not accidentally swallow messages. -/
-- RESET
def otherMessage : Nat × Nat where
fst := no
snd := by skip
--^ collectDiagnostics
/-! Starting to type a comment should not invalidate the state above it. -/
-- RESET
def strayToken : True := by
dbg_trace "s"
unfold f
--^ sync
--^ insert: " -"
/-!
Insufficient reuse checking of trailing whitespace info in the info tree led to the goal view
showing multiple tactics as they all claimed to be at the end of the file (which they were in prior
versions).
-/
-- RESET
def dup_goals : True := by
show True
--^ sync
--^ insert: "show True\n show True\n show True\n show True\n "
--^ sync
--^ goals
-- (note that request positions are computed relative to the original document, so the checks above
-- will point at a `show` at run time)