Skip to content
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

feat: respond to info view requests as soon as relevant tactic has finished execution #4727

Merged
merged 2 commits into from
Jul 24, 2024

Conversation

Kha
Copy link
Member

@Kha Kha commented Jul 11, 2024

After each tactic step, we save the info tree created by it together with an appropriate info tree context that makes it stand-alone (which we already did before to some degree, see Info.updateContext?). Then, in the adjusted request handlers, we first search for a snapshot task containing the required position, if so wait on it, and if it yielded an info tree, use it to answer the request, or else continue searching and waiting, falling back to the full info tree, which should be unchanged by this PR.

The definition header does not report info trees early as in general it is not stand-alone in the tactic sense but may contain e.g. metavariables solved by the body in which case we do want to show the ultimate state as before. This could be refined in the future in case there are no unsolved mvars.

The adjusted request handlers are exactly the ones waited on together by the info view, so they all have to be adjusted to have any effect on the UX. Further request handlers may be adjusted in the future.

No new tests as "replies early" is not something we can test with our current framework but the existing test suite did help in uncovering functional regressions.

Comment on lines -419 to +421
let nextLine := { line := pos.line + 1, character := 0 }
let t := doc.cmdSnaps.waitUntil fun snap => filemap.lspPosToUtf8Pos nextLine ≤ snap.endPos
mapTask t fun (snaps, _) => do
let some snap := snaps.getLast?
| return ⟨∅⟩
runTermElabM snap do
mapTask (findInfoTreeAtPos doc <| filemap.lspPosToUtf8Pos pos) fun
| some infoTree@(.context (.commandCtx cc) _) =>
ContextInfo.runMetaM { cc with } {} do
Copy link
Member Author

@Kha Kha Jul 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vtec234 Could you explain why this request handler used a very different waiting/position searching logic from other requests and how it should behave under incremental tactic execution?

Copy link
Member

@Vtec234 Vtec234 Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I reading correctly that the only difference is the use of waitUntil versus waitFind? (which is what withWaitFindSnap uses)? I honestly don't remember, but my guess would be that this is because nextLine need not be a valid position in the file (it might be one more than the last line), so if you use waitFind? and ask for a snapshot whose endPos is at least nextLine, you might get none. But waitUntil will give you the entire list in case nothing matching the predicate is found. This is correct as it'll give us the last snapshot in the file. From this we can retrieve the widgets. Whatever adaptations you made to the other handlers should be made here, modulo the above observation.

Copy link
Member

@Vtec234 Vtec234 Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and we use nextLine because we want to show widgets appearing anywhere on pos.line, regardless of column/character.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an example where showing all widgets in a line is valuable, considering that this is not how the rest of the info view behaves? To be clear, the one regression I see in my changes is that if someone puts multiple tactics in a single line, they will only see the widgets of the selected tactic. Which sounds pretty acceptable to me in any case.

Copy link
Member

@Vtec234 Vtec234 Jul 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, the motivation is described in the last bullet of #2963.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That justification just links to another uncommented code blocks devoid of actual documented motivation :( . Getting to the bottom of this is very frustrating and I'm inclined to go forward with changing the semantcs (in the minor way described above) to what makes the most sense to me in the long term.

Copy link
Member

@Vtec234 Vtec234 Jul 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it might be fine to break that since we now have widget messages. The motivation I linked (and the undocumented piece of 'Try this' code) were about making the 'Try this' widget be displayed under the same conditions (any on the line, ignoring columns) as diagnostics. But now we can put 'Try this' in a diagnostic.

@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Jul 11, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jul 11, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jul 11, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan release-ci Enable all CI checks for a PR, like is done for releases labels Jul 11, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

leanprover-community-mathlib4-bot commented Jul 11, 2024

Mathlib CI status (docs):

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Jul 11, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jul 11, 2024
@Kha Kha marked this pull request as ready for review July 15, 2024 07:54
@Kha Kha requested review from Vtec234, mhuisi and kim-em as code owners July 15, 2024 07:54
@leodemoura leodemoura force-pushed the master branch 2 times, most recently from 32d60c5 to 696f70b Compare July 20, 2024 02:58
@Kha Kha added this pull request to the merge queue Jul 24, 2024
Merged via the queue into leanprover:master with commit af0b563 Jul 24, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan release-ci Enable all CI checks for a PR, like is done for releases toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants