Repository navigation
Conversation
…tion body When a level variable is only referenced transitively through antiquotations (e.g. `q($a = $a)` with `a : Q($α)` and `α : Q(Type u)`), the quotation elaborator used to record a TermInfo for `u` whose syntax was the entire quotation body. This made clicking `u` highlight the whole body and made occurrences look unrelated to the actual antiquotations. Now collect, for each identifier in the macro-expanded quotation body that resolves to a free variable of the quoted context, the level parameters transitively mentioned by its quoted type (following types of referenced antiquotations), and record the level-variable TermInfos at those identifiers instead. Syntactic level occurrences (e.g. `Type u` inside the body) keep the previous behaviour. Fixes leanprover-community#98.
…th master Upstream master bumped the toolchain past this branch (v4.36.0-rc2 -> v4.36.0 -> v4.37.0-rc1 in leanprover-community#179/leanprover-community#180), conflicting with the rc1->rc2 bump this branch carried from the fork's merge-base. Setting the branch's toolchain to master's makes the merge clean; the PR diff relative to the merge result is unchanged. Verified locally on leanprover/lean4:v4.37.0-rc1 (upstream master ad0c9f8 + this branch, toolchain conflict resolved to master's version): `lake build --wfail` passes (31 jobs, no warnings) and `lake test` passes (exit 0, incl. QqTest.highlight).
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #98.
Problem
With
clicking the level variable
uhighlighted the entire quotation body$a = $a, and clicking theabinder produced no highlights at all.Root cause: after elaborating a quotation,
UnquoteState.withLevelNamesrecords aTermInfofor each referenced level variable withaddTermInfo' (← getRef) fvar. Insideq(...)elaboration,getRefis the whole quotation body (withRef tinImpl.macro). So whenever a level variable is only referenced transitively through antiquotations (hereuappears in the type ofα, hence in the type of the antiquotation$a), a spuriousTermInfoforuis attached to the compound body syntax$a = $a, and Lean's occurrence linker links that whole region tou.Fix
Before recording the level-variable infos,
Impl.macronow walks the macro-expanded quotation body and, for each identifier that resolves to a free variable of the quoted context, collects the level parameters transitively mentioned by its quoted type (following the types of referenced antiquotations —$a's type mentions$α, whose type mentionsu).withLevelNamesthen records theTermInfoforuat exactly those identifiers (both$aoccurrences), instead of at the body.Two pre-existing behaviours are deliberately preserved:
Type u) still fall back to recording atgetRef, i.e. the wholeType unode.ql(...)elaboration records at its own ref as before.After the fix, clicking
uhighlights its binder, theType uoccurrences, and precisely the two$aantiquotations; clicking theabinder highlights the binder and both$auses.Tests
New
QqTest/highlight.lean(picked up by theQqTest.+glob): elaborates the issue's scenario programmatically (elabCommandTopLeveldiscards preceding commands' info trees, sorun_cmddrivesIO.processCommandsitself) and asserts that noTermInfoforuis attached to compound quotation-body syntax, and thatuis referenced at the$aantiquotations. On unmodifiedmasterit fails with the bogus whole-body info (level variable referenced at non-identifier syntax: (Term.type _ = _ ...)); with the fix it passes.Verification (toolchain
leanprover/lean4:v4.36.0-rc2, the repo pin)lake build— clean (30 jobs)lake test— exit 0, fullQqTestsuite including the new file, no errors or warningsmaster(teeth check): fails as expectedlake env lean --serverJSON-RPCdocumentHighlightprobes: before the fix theubinder's highlights include the whole$a = $aregion and theabinder yields no highlights; after the fix, the groups are exactly {ubinder,Type usites, both$aantiquotations} and {abinder, both$auses}. An offlinefindModuleRefscomputation over the same file confirms the same reference groups.sorry/admit.