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

fix: oversight in isReadOnlyOrSyntheticOpaque #4206

Merged
merged 3 commits into from
May 18, 2024

Conversation

JovanGerb
Copy link
Contributor

@JovanGerb JovanGerb commented May 17, 2024

Explanation

In the case that assignSyntheticOpaque := true and the given metavariable is syntheticOpaque and the depth of the metavariable is not the current depth, isReadOnlyOrSyntheticOpaque returns false, even though the metavariable is read-only because of being declared at a smaller depth. This causes the metavariable to (wrongly) be able to be instantiated by isDefEq.

This bug was found at the proof of RingHom.PropertyIsLocal.sourceAffineLocally_of_source_openCover, which involves a type class synthesis for CommRing ?m.2404, and the synthesis manages to instantiate this metavariable into different values, even though synthInstance? increases the metavariable depth. This synthesis fails after 1 second.

I found the bug while modifying the instance synthesis code: the modified code spent several minutes on this failed synthesis.

Test

The problem can be verified with the test:

run_meta do
  let m ← mkFreshExprMVar (Expr.sort levelOne) MetavarKind.syntheticOpaque
  withAssignableSyntheticOpaque do
  withNewMCtxDepth do
  let eq ← isDefEq m (.const ``Nat [])
  Lean.logInfo m! "{eq}"

this unification used to succeed, giving true, and this fix makes it return false.

Impact on Mathlib

This fix causes a change in the behaviour of congr, convert and friends, which breaks a couple of proofs in mathlib. Most of these are fixed by supplying more arguments.

I fixed these proofs, and benched mathlib. The result is that most files are unaffected, but some files are significantly improved. This is most prominent in Mathlib.RingTheory.Jacobson, where the number of instructions has decreased by 28%. The overall improvement is a 0.3% reduction in instructions.

Zulip message

@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 May 17, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request May 17, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request May 17, 2024
@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label May 17, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

leanprover-community-mathlib4-bot commented May 17, 2024

Mathlib CI status (docs):

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request May 17, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request May 17, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request May 17, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request May 17, 2024
@leanprover-community-mathlib4-bot 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 May 18, 2024
@leodemoura leodemoura added this pull request to the merge queue May 18, 2024
@leodemoura leodemoura changed the title fix: oversight in isReadOnlyOrSyntheticOpaque fix: oversight in isReadOnlyOrSyntheticOpaque May 18, 2024
Merged via the queue into leanprover:master with commit 9fde33a May 18, 2024
26 checks passed
@JovanGerb
Copy link
Contributor Author

Do my changes on the Lean-pr-testing-4206 branch automatically get merged on the nightly-testing branch of mathlib?

@kim-em
Copy link
Collaborator

kim-em commented May 20, 2024

@JovanGerb, they don't automatically get merged. I really need to set up a bot that generates notifications about merged PRs that have associated lean-pr-testing-NNNN branches downstream.

In the meantime, if this happens again, the right thing to do is ping me on zulip so I know to look for it!

mathlib-bors bot pushed a commit to leanprover-community/mathlib4 that referenced this pull request May 20, 2024
This backports some changes that fill in a few implicit arguments.

nightly-2024-05-19 has trouble with these and the bug fix in leanprover/lean4#4206, and needs some fixes.

I *think* all these changes are not actually problematic, and perhaps even improve readability.

If a maintainer agrees, let's just do this on master. If any of these look at all bad, please just say so and I'll remove it from this PR and consider doing a minimization to understand if/why it is really necessary.
@JovanGerb JovanGerb deleted the unificationBug branch May 21, 2024 20:44
callesonne pushed a commit to leanprover-community/mathlib4 that referenced this pull request Jun 4, 2024
This backports some changes that fill in a few implicit arguments.

nightly-2024-05-19 has trouble with these and the bug fix in leanprover/lean4#4206, and needs some fixes.

I *think* all these changes are not actually problematic, and perhaps even improve readability.

If a maintainer agrees, let's just do this on master. If any of these look at all bad, please just say so and I'll remove it from this PR and consider doing a minimization to understand if/why it is really necessary.
js2357 pushed a commit to leanprover-community/mathlib4 that referenced this pull request Jun 18, 2024
This backports some changes that fill in a few implicit arguments.

nightly-2024-05-19 has trouble with these and the bug fix in leanprover/lean4#4206, and needs some fixes.

I *think* all these changes are not actually problematic, and perhaps even improve readability.

If a maintainer agrees, let's just do this on master. If any of these look at all bad, please just say so and I'll remove it from this PR and consider doing a minimization to understand if/why it is really necessary.
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants