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

perf: inline the Decidable (Coprime _ _) instance #1036

Merged
merged 1 commit into from
Nov 12, 2024

Conversation

eric-wieser
Copy link
Member

@eric-wieser eric-wieser commented Nov 11, 2024

Without this change, when faced with

if gcd m n = 1 then
  f (gcd m n)
else
  0

the compiler will fail to perform CSE and compute gcd m n twice, as the Decidable instance is inferred as the one in this PR, which obscures the implementation from the compiler.

See https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Compiler.20inserts.20.60instDecidableCoprime.60.3F/near/444709593

Deleting the instance would also work.

Without this change, when faced with
```
if gcd m n = 1 then
  f (gcd m n)
```
the compiler will fail to perform CSE, as the `Decidable` instance is
inferred as the one in this PR, which obscures the implementation from
the compiler.

See https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/Compiler.20inserts.20.60inBatteriesecidableCoprime.60.3F/near/444709593
@eric-wieser eric-wieser requested a review from digama0 November 11, 2024 17:37
@eric-wieser eric-wieser changed the title Inline the Decidable (Coprime _ _) instance perf: inline the Decidable (Coprime _ _) instance Nov 11, 2024
@github-actions github-actions bot added the awaiting-review This PR is ready for review; the author thinks it is ready to be merged. label Nov 11, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Nov 11, 2024
@leanprover-community-bot
Copy link
Collaborator

Mathlib CI status (docs):

@kim-em kim-em added this pull request to the merge queue Nov 12, 2024
Merged via the queue into main with commit 12381da Nov 12, 2024
4 checks passed
@github-actions github-actions bot removed the awaiting-review This PR is ready for review; the author thinks it is ready to be merged. label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants