-
Notifications
You must be signed in to change notification settings - Fork 437
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: partial context info #3159
Merged
Merged
Conversation
This file contains 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
mhuisi
requested review from
Vtec234,
kim-em,
leodemoura and
Kha
as code owners
January 10, 2024 15:04
github-actions
bot
added
the
toolchain-available
A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
label
Jan 10, 2024
leanprover-community-mathlib4-bot
added a commit
to leanprover-community/mathlib4
that referenced
this pull request
Jan 10, 2024
leanprover-community-mathlib4-bot
added
the
breaks-mathlib
This is not necessarily a blocker for merging: but there needs to be a plan
label
Jan 10, 2024
|
leanprover-community-mathlib4-bot
added a commit
to leanprover-community/mathlib4
that referenced
this pull request
Jan 10, 2024
I've added Next steps when that is ready:
|
kim-em
added a commit
to leanprover-community/ProofWidgets4
that referenced
this pull request
Jan 11, 2024
leanprover-community-mathlib4-bot
added a commit
to leanprover-community/mathlib4
that referenced
this pull request
Jan 11, 2024
leanprover-community-mathlib4-bot
added
builds-mathlib
CI has verified that Mathlib builds against this PR
and removed
breaks-mathlib
This is not necessarily a blocker for merging: but there needs to be a plan
labels
Jan 12, 2024
leanprover-community-mathlib4-bot
added a commit
to leanprover-community/mathlib4
that referenced
this pull request
Jan 12, 2024
Kha
requested changes
Jan 19, 2024
leanprover-community-mathlib4-bot
added a commit
to leanprover-community/mathlib4
that referenced
this pull request
Jan 19, 2024
leanprover-community-mathlib4-bot
added a commit
to leanprover-community/mathlib4
that referenced
this pull request
Jan 19, 2024
leanprover-community-mathlib4-bot
added a commit
to leanprover-community/mathlib4
that referenced
this pull request
Jan 19, 2024
Kha
approved these changes
Jan 22, 2024
mhuisi
added a commit
to mhuisi/lean4
that referenced
this pull request
Jan 22, 2024
kim-em
added a commit
to leanprover-community/batteries
that referenced
this pull request
Jan 23, 2024
kim-em
added a commit
to leanprover-community/batteries
that referenced
this pull request
Jan 23, 2024
antonkov
added a commit
to Paper-Proof/paperproof
that referenced
this pull request
Jan 25, 2024
github-merge-queue bot
pushed a commit
that referenced
this pull request
Jan 25, 2024
This PR adds support for the "call hierarchy" feature of LSP that allows quickly navigating both inbound and outbound call sites of functions. In this PR, "call" is taken to mean "usage", so inbound and outbound references of all kinds of identifiers (e.g. functions or types) can be navigated. To implement the call hierarchy feature, this PR implements the LSP requests `textDocument/prepareCallHierarchy`, `callHierarchy/incomingCalls` and `callHierarchy/outgoingCalls`. <details> <summary>Showing the call hierarchy (click to show image)</summary> ![show_call_hierarchy](https://github.com/leanprover/lean4/assets/10852073/add13943-013c-4d0a-a2d4-a7c57ad2ae26) </details> <details> <summary>Incoming calls (click to show image)</summary> ![incoming_calls](https://github.com/leanprover/lean4/assets/10852073/9a803cb4-6690-42b4-9c5c-f301f76367a7) </details> <details> <summary>Outgoing calls (click to show image)</summary> ![outgoing_calls](https://github.com/leanprover/lean4/assets/10852073/a7c4f193-51ab-4365-9473-0309319b1cfe) </details> It is based on #3159, which should be merged before this PR. To route the parent declaration name through to the language server, the `.ilean` format is adjusted, breaking backwards compatibility with version 1 of the ILean format and yielding version 2. This PR also makes the following more minor adjustments: - `Lean.Server.findModuleRefs` now also combines the identifiers of constants and FVars and prefers constant over FVars for the combined identifier. This is necessary because e.g. declarations declared using `where` yield both a constant (for usage outside of the function) and an FVar (for usage inside of the function) with the same range, whereas we would typically like all references to refer to the former. This also fixes a bug introduced in #2462 where renaming a declaration declared using `where` would not rename usages outside of the function, as well as a bug in the unused variable linter where `where` declarations would be reported as unused even if they were being used outside of the function. - The function converting `Lean.Server.RefInfo` to `Lean.Lsp.RefInfo` now also computes the `Lean.DeclarationRanges` for parent declaration names via `MetaM` and must hence be in `IO` now. - Add a utility function `Array.groupByKey` to `HashMap.lean`. - Stylistic refactoring of `Watchdog.lean` and `LanguageFeatures.lean`.
kim-em
added a commit
to leanprover-community/batteries
that referenced
this pull request
Feb 1, 2024
* feat: hover info for `rcases h : ...` (#486) * feat: hover info for `rcases h : ...` * fix * chore: adaptations for leanprover/lean4#3123 (#502) * chore: adaptations for leanprover/lean4#3123 * update toolchain * chore: remove unnecessary `have` (#516) After leanprover/lean4#3132 the linter will complain about this. * chore: simproc PR changes (#496) See leanprover/lean4#3124 Co-authored-by: Scott Morrison <[email protected]> * chore: adaptions for nightly-2023-01-11 (#524) * advance toolchain to nightly-2024-01-12, no updates required * chore: updates to DiscrTree for changes in nightly (#536) * doc: extend docstrings for `ext` and `ext1` (#525) Makes sure to mention that the patterns are processed using `rintro`, and makes sure `ext` mentions `ext1`. * docs(Data/List): typo (#529) * feat: Eq.rec lemma (#385) * chore: Add empty collection instance to BinomialHeap (#532) * Incremental Library Search (#421) This ports library_search from Mathlib to Std. It preserves the ability to do caching, but is designed to support a cacheless mode. The exact and apply tactics are named `std_exact?` and `std_apply?`, but will eventually be renamed. Co-authored-by: Scott Morrison <[email protected]> * fix termination_by clauses in LazyDiscrTree fix LibrarySearch * bump toolchain --------- Co-authored-by: Kyle Miller <[email protected]> Co-authored-by: Martin Dvořák <[email protected]> Co-authored-by: François G. Dorais <[email protected]> Co-authored-by: Joe Hendrix <[email protected]> * feat: adaptations for leanprover/lean4#3159 (#557) * merge origin/main * chore: fixes for `simp` refactor (#571) * move to v4.6.0-rc1 * fix proofs --------- Co-authored-by: Mario Carneiro <[email protected]> Co-authored-by: Leonardo de Moura <[email protected]> Co-authored-by: Joachim Breitner <[email protected]> Co-authored-by: Kyle Miller <[email protected]> Co-authored-by: Martin Dvořák <[email protected]> Co-authored-by: François G. Dorais <[email protected]> Co-authored-by: Joe Hendrix <[email protected]>
fgdorais
added a commit
to fgdorais/batteries
that referenced
this pull request
Feb 18, 2024
) * feat: hover info for `rcases h : ...` (leanprover-community#486) * feat: hover info for `rcases h : ...` * fix * chore: adaptations for leanprover/lean4#3123 (leanprover-community#502) * chore: adaptations for leanprover/lean4#3123 * update toolchain * chore: remove unnecessary `have` (leanprover-community#516) After leanprover/lean4#3132 the linter will complain about this. * chore: simproc PR changes (leanprover-community#496) See leanprover/lean4#3124 Co-authored-by: Scott Morrison <[email protected]> * chore: adaptions for nightly-2023-01-11 (leanprover-community#524) * advance toolchain to nightly-2024-01-12, no updates required * chore: updates to DiscrTree for changes in nightly (leanprover-community#536) * doc: extend docstrings for `ext` and `ext1` (leanprover-community#525) Makes sure to mention that the patterns are processed using `rintro`, and makes sure `ext` mentions `ext1`. * docs(Data/List): typo (leanprover-community#529) * feat: Eq.rec lemma (leanprover-community#385) * chore: Add empty collection instance to BinomialHeap (leanprover-community#532) * Incremental Library Search (leanprover-community#421) This ports library_search from Mathlib to Std. It preserves the ability to do caching, but is designed to support a cacheless mode. The exact and apply tactics are named `std_exact?` and `std_apply?`, but will eventually be renamed. Co-authored-by: Scott Morrison <[email protected]> * fix termination_by clauses in LazyDiscrTree fix LibrarySearch * bump toolchain --------- Co-authored-by: Kyle Miller <[email protected]> Co-authored-by: Martin Dvořák <[email protected]> Co-authored-by: François G. Dorais <[email protected]> Co-authored-by: Joe Hendrix <[email protected]> * feat: adaptations for leanprover/lean4#3159 (leanprover-community#557) * merge origin/main * chore: fixes for `simp` refactor (leanprover-community#571) * move to v4.6.0-rc1 * fix proofs --------- Co-authored-by: Mario Carneiro <[email protected]> Co-authored-by: Leonardo de Moura <[email protected]> Co-authored-by: Joachim Breitner <[email protected]> Co-authored-by: Kyle Miller <[email protected]> Co-authored-by: Martin Dvořák <[email protected]> Co-authored-by: François G. Dorais <[email protected]> Co-authored-by: Joe Hendrix <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
builds-mathlib
CI has verified that Mathlib builds against this PR
toolchain-available
A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN
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.
This PR facilitates augmenting the context of an
InfoTree
with partial contexts while elaborating a command. Using partial contexts, this PR also adds support for tracking the parent declaration name of a term in theInfoTree
. The parent declaration name is needed to compute the call hierarchy in #3082.Specifically, the
Lean.Elab.InfoTree.context
constructor is refactored to take a value of the new typeLean.Elab.PartialContextInfo
instead of aLean.Elab.ContextInfo
, which now refers to a fullInfoTree
context. ThePartialContextInfo
is then merged into aContextInfo
while traversing the tree usingLean.Elab.PartialContextInfo.mergeIntoOuter?
. The partial context after executingliftTermElabM
is stored in values of a new typeLean.Elab.CommandContextInfo
.As a result of this,
Lean.Elab.ContextInfo.save
moves toLean.Elab.CommandContextInfo.save
.For obtaining the parent declaration for a term, a new typeclass
MonadParentDecl
is introduced to save the parent declaration inLean.Elab.withSaveParentDeclInfoContext
.Lean.Elab.Term.withDeclName x
now callswithSaveParentDeclInfoContext x
to save the declaration name.Migration
The changes to the
InfoTree.context
constructor break backwards compatibility with all downstream users that traverse theInfoTree
manually instead of going through the functions inInfoUtils.lean
.To fix this, you can merge the outer
ContextInfo
in a traversal with thePartialContextInfo
of anInfoTree.context
node usingPartialContextInfo.mergeIntoOuter?
. See e.g.Lean.Elab.InfoTree.foldInfo
for an example:Downstream users that manually save
InfoTree
s may need to adjust calls toContextInfo.save
to useCommandContextInfo.save
instead and potentially wrap theirCommandContextInfo
in aPartialContextInfo.commandCtx
constructor when storing it in anInfoTree
orContextInfo.mk
when creating a full context.Motivation
As of now,
ContextInfo
s are always full contexts, constructed as if they were always created inliftTermElabM
after running theTermElabM
action. This is not strictly true; we already createContextInfo
s in several places other thanliftTermElabM
and work around the limitation thatContextInfo
s are always full contexts in certain places (e.g.Info.updateContext?
is a crux that we need because we can't always create partial contexts at the term-level), but it has mostly worked out so far. Note that one must be very careful when saving aContextInfo
in places other thanliftTermElabM
because the context may not be as complete as we would like (e.g. it may lack meta-variable assignments, potentially leading to a language server panic).Unfortunately, the parent declaration of a term is another example of a context that cannot be provided in
liftTermElabM
: The parent declaration is usually set viawithDeclName
, which itself lives inTermElabM
. So by the time we are trying to save the fullContextInfo
, the declaration name is already gone. There is no easy fix for this like in the other cases where we would really just like to augment the context with an extra field.The refactor that we decided on to resolve the issue is to refactor the
InfoTree
to take aPartialContextInfo
instead of aContextInfo
and have code that traverses theInfoTree
merge inner contexts with outer contexts to produce a fullContextInfo
value.Bumps for downstream projects
lean-pr-testing-3159
branch at Std, not yet opened as a PRlean-pr-testing-3159
branch at Mathlib, not yet opened as a PR