Repository navigation
Conversation
…nstancesCommute` When a local instance had a let-bound copy in scope (e.g. from `let := x` in a `do` block), `findRedundantLocalInst?` picked the let-bound alias as the canonical instance for the redundant-instance check. Quoting it back yields a let variable that `whnf` unfolds during the next unquoting round, so the generated `QuotedDefEq` hypothesis degenerated (to `x = x`), the zeta-reduction that would eliminate the redundant instance never happened, and `assertInstancesCommute` rediscovered the same instance until the recursion depth was exceeded. Skip let-bound aliases as canonical-instance witnesses, and add regression tests covering the issue's MWEs. Fixes leanprover-community#38
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 #38.
Problem
assertInstancesCommute(andassumeInstancesCommute) looped withmaximum recursion depth has been reachedwhenever a let-bound copy of a local instance was in scope — e.g. the issue's MWE:Root cause
findRedundantLocalInst?looks for a local instance whose type is synthesizable from the other local instances, thenassertInstancesCommuteImplrecords aQuotedDefEqhypothesis and relies on the next unquoting round zeta-reducing the redundant variable away, so the search terminates.With
let := xin scope, the unquoted context contains$xand a value-less copy$thisof the anonymous let's type (the unquoting drops the let's value), andsynthInstance?finds$thisas a witness that$xis redundant. But quoting$thisback yields the original let variable, andunquoteExprstarts withwhnf, which unfolds it tox. The generatedQuotedDefEqhypothesis therefore degenerates tox = x, the zeta-reduction that would eliminate$xnever happens, and the next round rediscovers the exact same pair — forever.Fix
In
findRedundantLocalInst?, skip a witness whose quoted counterpart is let-bound: such a variable cannot serve as the canonical instance, since it unfolds to something else during unquoting. With the MWE, no canonical instance is found (correctly — there is only one real instance), and elaboration proceeds.This is conservative: it only ever makes the redundancy check find fewer candidates, and the intended path (two genuinely distinct instances of the same class, discharged with a
QuotedDefEqhypothesis) still works — pinned by a test.Tests
New
QqTest/assertInstancesCommuteLet.lean(picked up by theQqTest.+glob):let := xbeforeassertInstancesCommute);synthInstanceQ);assumeInstancesCommute.On unmodified
master, the first two tests fail withmaximum recursion depth has been reached; with this fix the whole file compiles.Verification
On the pinned toolchain (
leanprover/lean4:v4.36.0-rc2):lake build --wfail— passes (30 jobs, no warnings)lake test— passes (exit 0; fullQqTestsuite, 59 jobs, including the new regression file)sorry/admitintroduced; the change is meta-only inQq/AssertInstancesCommute.leanplus tests.