-
Notifications
You must be signed in to change notification settings - Fork 598
feat: allow a general evalTac
at evalSepTactics
#7702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JovanGerb
wants to merge
3
commits into
leanprover:master
Choose a base branch
from
JovanGerb:evalSepTactics
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+10
−7
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,8 +33,11 @@ open Language in | |
/-- | ||
Evaluates a tactic script in form of a syntax node with alternating tactics and separators as | ||
children. | ||
-/ | ||
partial def evalSepTactics : Tactic := goEven | ||
|
||
The user can provide their own tactic evaluation function `evalTac`. | ||
-/ | ||
@[specialize] | ||
partial def evalSepTactics (evalTac : Tactic := evalTactic) : Tactic := goEven | ||
where | ||
-- `stx[0]` is the next tactic step, if any | ||
goEven stx := do | ||
|
@@ -64,7 +67,7 @@ where | |
-- compare `stx[0]` for `finished`/`next` reuse, focus on remainder of script | ||
Term.withNarrowedTacticReuse (stx := stx) (fun stx => (stx[0], mkNullNode stx.getArgs[1:])) fun stxs => do | ||
let some snap := (← readThe Term.Context).tacSnap? | ||
| do evalTactic tac; goOdd stxs | ||
| do evalTac tac; goOdd stxs | ||
let mut reusableResult? := none | ||
let mut oldNext? := none | ||
if let some old := snap.old? then | ||
|
@@ -87,15 +90,15 @@ where | |
next := #[{ stx? := stxs, task := next.resultD default }] | ||
} | ||
-- Run `tac` in a fresh info tree state and store resulting state in snapshot for | ||
-- incremental reporting, then add back saved trees. Here we rely on `evalTactic` | ||
-- incremental reporting, then add back saved trees. Here we rely on `evalTac` | ||
-- producing at most one info tree as otherwise `getInfoTreeWithContext?` would panic. | ||
let trees ← getResetInfoTrees | ||
try | ||
let (_, state) ← withRestoreOrSaveFull reusableResult? | ||
-- set up nested reuse; `evalTactic` will check for `isIncrementalElab` | ||
-- set up nested reuse; `evalTac` will check for `isIncrementalElab` | ||
(tacSnap? := some { old? := oldInner?, new := inner }) do | ||
Term.withReuseContext tac do | ||
evalTactic tac | ||
evalTac tac | ||
finished.resolve { | ||
diagnostics := (← Language.Snapshot.Diagnostics.ofMessageLog | ||
(← Core.getAndEmptyMessageLog)) | ||
|
@@ -120,7 +123,7 @@ where | |
Term.withNarrowedTacticReuse (fun stx => (stx[0], mkNullNode stx.getArgs[1:])) goEven stx | ||
|
||
@[builtin_tactic seq1] def evalSeq1 : Tactic := fun stx => | ||
evalSepTactics stx[0] | ||
(evalSepTactics) stx[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please just pass the argument explicitly, in which case we may as well remove the default value |
||
|
||
@[builtin_tactic paren, builtin_incremental] def evalParen : Tactic := | ||
Term.withNarrowedArgTacticReuse 1 evalTactic | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please expand this comment with an example of why one might want to do this? Otherwise future maintainers will be absolutely puzzled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would write something like this:
Assume a tactic developer writes a new general modified tactic execution,
for example calling automation each step, displaying the goal in a specific
way, modifying the behavior of some tactics...
Then it is possible to create a tactic scope in which this tactic is called
on each line of the scope, while preserving the incremental elaboration by