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: derive BEq on structure with Prop-fields #3191

Merged
merged 3 commits into from
Jan 18, 2024

Conversation

arthur-adjedj
Copy link
Contributor

Closes #3140

@arthur-adjedj arthur-adjedj requested a review from kim-em as a code owner January 17, 2024 12:44
@arthur-adjedj arthur-adjedj changed the title fix: derive BEq on structure with Prop-fields. fix: derive BEq on structure with Prop-fields Jan 17, 2024
@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 Jan 17, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 17, 2024
Comment on lines 60 to 65
let isProof := (← inferType (← inferType x)).isProp
if isProof then
continue
if (← inferType x).isAppOf indVal.name then
rhs ← `($rhs && $(mkIdent auxFunName):ident $a:ident $b:ident)
else
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is running inferType twice; maybe store as xType and reuse?

Also, maybe use xType.isProof:

def isProof (e : Expr) : MetaM Bool := do
match (← isProofQuick e) with
| .true => return true
| .false => return false
| .undef => Meta.isProp (← inferType e)

Copy link
Contributor Author

@arthur-adjedj arthur-adjedj Jan 17, 2024

Choose a reason for hiding this comment

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

Thanks for pointing it out. Looking that the code for isProof, I believe it should be isProp xType and not xType.isProof.

(Sidenote : there are two isProp in practice, Expr.isProp returns true when the given expr is syntactically Prop, whereas Meta.isProp returns true is the expression lives in Prop, this is confusing IMO).

Since similar code was present in DecEq.lean, I've taken the liberty of using Meta.isProp there too.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, I guess I meant isProof x? Not sure if it’s better if you have to run inferType x later anyways.

Copy link
Collaborator

Choose a reason for hiding this comment

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

An good point about Meta.isProp and isProp. This is very confusing indeed, but I think you got it right :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thought process is that isProofQuick and isPropQuick are very similar, and should be comparable in terms of performance. However, if isProofQuick fails, it will have to infer the type, and call isPropQuick afterwards. since inferType x is already called once, I believe using isProp to be more efficient here.

@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Jan 17, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

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

Mathlib CI status (docs):

leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 17, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 17, 2024
Copy link
Collaborator

@nomeata nomeata left a comment

Choose a reason for hiding this comment

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

LGTM. I’ll leave it open for a day before merging if you don't mind in case someone else wants to 👀 it as well.

@arthur-adjedj
Copy link
Contributor Author

arthur-adjedj commented Jan 17, 2024

Perfect. Thanks for having taken the time to review this :-)

@nomeata nomeata added the will-merge-soon …unless someone speaks up label Jan 17, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 17, 2024
@kim-em kim-em added this pull request to the merge queue Jan 18, 2024
Merged via the queue into leanprover:master with commit a2ed4db Jan 18, 2024
15 checks passed
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 will-merge-soon …unless someone speaks up
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deriving BEq fails for structures with Prop fields
4 participants