lean4-htt/tests/elab/try_eval_suggest.lean
Joachim Breitner 432d11541b
feat: add try? => tac syntax and parallel cancellation test (#13301)
This PR adds a `try? => tac` syntax that runs `evalSuggest` directly on
a given tactic, useful for testing the `try?` machinery in isolation. It
also adds a server_interactive test (`cancellation_par.lean`) that
demonstrates a cancellation bug with parallel tactic combinators.

The test contrasts three combinators:
- **`first`** (sequential): cancellation works correctly — the tactic
runs on the main elaboration thread and shares its cancel token.
- **`attempt_all_par`** (parallel): cancellation is broken — the subtask
spawned via `asTask` gets a fresh cancel token that is never set on
re-elaboration.
- **`first_par`** (parallel): same bug as `attempt_all_par`.

The test uses a `check_cancel <label>` helper tactic that detects leaked
cancel tokens without any timing dependency: the second invocation (from
re-elaboration) signals the first, which then checks whether its cancel
token was set.

Related issue: #13300

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-28 10:00:35 +00:00

51 lines
1.1 KiB
Text

/-!
# Tests for `try? => tac` syntax
These tests verify that the `try? => tac` syntax correctly runs a user-supplied tactic
through `evalSuggest` and reports suggestions.
-/
/-- info: Try this:
[apply] rfl -/
#guard_msgs (info) in
example : 1 = 1 := by
try? => rfl
/-- info: Try this:
[apply] rfl -/
#guard_msgs (info) in
example : 1 = 1 := by
try? => first | assumption | rfl
/-- info: Try these:
[apply] rfl
[apply] simp_all -/
#guard_msgs (info) in
example : 1 = 1 := by
try? => attempt_all | rfl | simp_all
/-- info: Try these:
[apply] rfl
[apply] simp_all -/
#guard_msgs (info) in
example : 1 = 1 := by
try? => attempt_all_par | rfl | simp_all
-- first_par returns whichever finishes first; just test it doesn't error
#guard_msgs (drop info) in
example : 1 = 1 := by
try? => first_par | rfl | simp_all
/-- info: Try these:
[apply] assumption
[apply] rfl -/
#guard_msgs (info) in
example (h : 1 = 1) : 1 = 1 := by
try? => attempt_all | assumption | rfl
-- `max` config option should limit suggestions
/-- info: Try this:
[apply] rfl -/
#guard_msgs (info) in
example : 1 = 1 := by
try? (max := 1) => attempt_all | rfl | simp_all