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: make sure isDefEqSingleton rule checks types #6421

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kmill
Copy link
Collaborator

@kmill kmill commented Dec 20, 2024

This PR fixes an issue where the isDefEqSingleton rule could apply in inappropriate situations. In particular, if S is a one-field structure with field f, then S.f ?m =?= v was being reduced to ?m =?= { f := v } even if { f := v } was type-incorrect.

Closes #6420

This PR fixes an issue where the `isDefEqSingleton` rule could apply in inappropriate situations. In particular, if `S` is a one-field structure with field `f`, then `S.f ?m =?= v` was being reduced to `?m =?= { f := v }` even if `{ f := v }` was type-incorrect.

Closes leanprover#6420
@kmill kmill added awaiting-review Waiting for someone to review the PR changelog-other and removed awaiting-review Waiting for someone to review the PR labels Dec 20, 2024
@kmill kmill marked this pull request as draft December 20, 2024 02:43
@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 Dec 20, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 20, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 20, 2024
@leanprover-community-bot leanprover-community-bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Dec 20, 2024
@leanprover-community-bot
Copy link
Collaborator

leanprover-community-bot commented Dec 20, 2024

Mathlib CI status (docs):

@leanprover-community-bot leanprover-community-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 Dec 20, 2024
@kmill kmill marked this pull request as ready for review December 20, 2024 06:42
@kmill
Copy link
Collaborator Author

kmill commented Dec 20, 2024

@leodemoura I made this PR to validate the explanation of #6420. I don't know the isDefEq code well enough to know if there is a better way to implement this — perhaps you would want to implement it differently. The bug is low priority.

There were two places where mathlib was somehow taking advantage of this bug, but neither looked intentional.

else
if !(← isAssignable sFn) then
return false
let ctor := mkAppN (mkConst ctorVal.name sTypeFn.constLevels!) sType.getAppArgs
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add a comment explaining this change? It can be based on the PR description.
Additional requests regarding coding convetion:

  • let Expr.forallE _ ty ... => let .forallE _ ty ...
  • unless ← isDefEq ty (← inferType v) do => unless (← isDefEq ty (← inferType v)) do

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

General question about isDefEq that came up in a Zulip discussion: some users believe that you are not supposed to use isDefEq on terms if you have not already ensured isDefEq for their inferred types. Is that the case?

If so, then this PR is not necessary, but it would raise a bunch of questions for me (I don't recall seeing any meta code that specifically ensured isDefEq on inferred types).

Copy link
Member

Choose a reason for hiding this comment

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

I don't have time to context switch to this module right now. Moreover, I feel like this is going to be a really long thread. Let's create one at the Lean FRO Zulip.

BTW, I want to minimize as much as possible changes to ExprDefEq.lean, and do it in batches whenever we decide to the context switch.

That said, at first sight, this PR is consistent with the current design. We already have functions such as checkTypesAndAssign.

Copy link
Member

Choose a reason for hiding this comment

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

BTW, were you able to trigger the bug without meta-programming? If not, I prefer to put this PR on hold.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No problem, it's low-priority. I'll let you know if I manage to trigger it without meta-programming.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just to let you know, I pushed a simple example that uses just the have and exact tactics. (Please feel free to keep this PR on hold.)

leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 20, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 20, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/batteries that referenced this pull request Dec 21, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Dec 21, 2024
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 changelog-other 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.

isDefEq creates type-incorrect terms when applying isDefEqSingleton rule
3 participants