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

[Merged by Bors] - perf(library/congr_lemma): do not check for subsingleton in simp congrs #665

Closed
wants to merge 13 commits into from

Conversation

gebner
Copy link
Member

@gebner gebner commented Jan 9, 2022

This changes the automatically-generated simp congr lemma in several situations:

  • Subsingleton (non-prop) instance arguments are Fixed instead of Cast. Which is very good, because Cast introduces diamonds.
  • However, decidable instances (decidable/decidable_pred/decidable_rel) have a new special kind called SubsingletonInst. The automatically generated lemma looks exactly like the old if_congr (which is no longer marked congr).
  • If you have arguments like (a : α) (b : β a) where b is a subsingleton, then simp can no longer rewrite in a. Not sure if this actually pops up anywhere in practice (for decidability arguments see above).

This also affects the congr tactic slightly since the specialization prefix size is computed without taking subsingleton information into account.

@gebner
Copy link
Member Author

gebner commented Jan 9, 2022

Hmmm, this still synthesizes subsingleton instances in simp. ?!?!?

library/init/meta/simp_tactic.lean Outdated Show resolved Hide resolved
src/library/congr_lemma.cpp Show resolved Hide resolved
@gebner
Copy link
Member Author

gebner commented Jan 11, 2022

bors merge

bors bot pushed a commit that referenced this pull request Jan 11, 2022
…rs (#665)

This changes the automatically-generated simp congr lemma in several situations:
 - Subsingleton (non-prop) instance arguments are Fixed instead of Cast.  Which is very good, because Cast introduces diamonds.
 - However, decidable instances (decidable/decidable_pred/decidable_rel) have a new special kind called SubsingletonInst.  The automatically generated lemma looks exactly like the old `if_congr` (which is no longer marked congr).
 - If you have arguments like `(a : α) (b : β a)` where `b` is a subsingleton, then simp can no longer rewrite in `a`.  Not sure if this actually pops up anywhere in practice (for decidability arguments see above).

This also affects the `congr` tactic slightly since the specialization prefix size is computed without taking subsingleton information into account.
@bors
Copy link

bors bot commented Jan 11, 2022

@bors bors bot changed the title perf(library/congr_lemma): do not check for subsingleton in simp congrs [Merged by Bors] - perf(library/congr_lemma): do not check for subsingleton in simp congrs Jan 11, 2022
@bors bors bot closed this Jan 11, 2022
@bors bors bot deleted the sscongr branch January 11, 2022 10:53
bors bot pushed a commit to leanprover-community/mathlib that referenced this pull request Aug 15, 2022
)

+ Add `unique` instances when the codomain types are subsingletons and rename the original `unique` instances (which apply when the domain is empty) to `unique_of_is_empty`. These are in analogy to [pi.unique](https://leanprover-community.github.io/mathlib_docs/logic/unique.html#pi.unique) and [pi.unique_of_is_empty](https://leanprover-community.github.io/mathlib_docs/logic/unique.html#pi.unique_of_is_empty).

+ Golf the `unique` instances for (d)finsupp using `fun_like.coe_injective.unique`. The names `unique_of_left` and `unique_of_right` remain unchanged in the finsupp case, because finsupp is special in that it consists of non-dependent functions, unlike dfinsupp or direct_sum.

(There was a concern that adding `unique` instances would slow down `simp` (see #6025), but it has been fixed in [lean#665](leanprover-community/lean#665).)
bors bot pushed a commit to leanprover-community/mathlib that referenced this pull request Aug 15, 2022
#### Background

The `simp` tactic used to [look for subsingleton instances excessively](https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.235672.20breaks.20timeout/near/223034551), so every subsingleton/unique instances added to mathlib could slow down `simp` performance; in fact, removing some subsingleton instances locally led to such speedup that three hacks #5779, #5878 and #6639 along this line have been merged into mathlib. Since the problem was discovered, new subsingleton instances were mostly turned into lemma/defs, with a reference to gh-6025 that @eric-wieser created to track them and a notice to restore them as instances once safe to do so.

This bad behavior of `simp` was finally fixed in [lean#665](leanprover-community/lean#665) by @gebner in January 2022, so it is now safe to remove the hacks and restore the instances. In fact, the hack #5878 was already removed in [#13127](c7626b7#diff-02976f8e19552b3c7ea070e30761e4e99f1333085cc5bb94fa170861c6ed27bcL497). I [measured the difference in performance](https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.235672.20breaks.20timeout/near/293228091) from removing one of the remaining hacks and it was negligible.

Therefore, in this PR, we:

+ Remove both hacks remaining;

+ Turn all would-be instances that mention gh-6025 into actual global instances;

+ Golf proofs that explicitly invoked these instances previously;

+ Remove `local attribute [instance]` lines that were added when these instances were needed.

Closes #6025.
bors bot pushed a commit to leanprover-community/mathlib that referenced this pull request Aug 15, 2022
#### Background

The `simp` tactic used to [look for subsingleton instances excessively](https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.235672.20breaks.20timeout/near/223034551), so every subsingleton/unique instances added to mathlib could slow down `simp` performance; in fact, removing some subsingleton instances locally led to such speedup that three hacks #5779, #5878 and #6639 along this line have been merged into mathlib. Since the problem was discovered, new subsingleton instances were mostly turned into lemma/defs, with a reference to gh-6025 that @eric-wieser created to track them and a notice to restore them as instances once safe to do so.

This bad behavior of `simp` was finally fixed in [lean#665](leanprover-community/lean#665) by @gebner in January 2022, so it is now safe to remove the hacks and restore the instances. In fact, the hack #5878 was already removed in [#13127](c7626b7#diff-02976f8e19552b3c7ea070e30761e4e99f1333085cc5bb94fa170861c6ed27bcL497). I [measured the difference in performance](https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.235672.20breaks.20timeout/near/293228091) from removing one of the remaining hacks and it was negligible.

Therefore, in this PR, we:

+ Remove both hacks remaining;

+ Turn all would-be instances that mention gh-6025 into actual global instances;

+ Golf proofs that explicitly invoked these instances previously;

+ Remove `local attribute [instance]` lines that were added when these instances were needed.

Closes #6025.
bors bot pushed a commit to leanprover-community/mathlib that referenced this pull request Aug 15, 2022
#### Background

The `simp` tactic used to [look for subsingleton instances excessively](https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.235672.20breaks.20timeout/near/223034551), so every subsingleton/unique instances added to mathlib could slow down `simp` performance; in fact, removing some subsingleton instances locally led to such speedup that three hacks #5779, #5878 and #6639 along this line have been merged into mathlib. Since the problem was discovered, new subsingleton instances were mostly turned into lemma/defs, with a reference to gh-6025 that @eric-wieser created to track them and a notice to restore them as instances once safe to do so.

This bad behavior of `simp` was finally fixed in [lean#665](leanprover-community/lean#665) by @gebner in January 2022, so it is now safe to remove the hacks and restore the instances. In fact, the hack #5878 was already removed in [#13127](c7626b7#diff-02976f8e19552b3c7ea070e30761e4e99f1333085cc5bb94fa170861c6ed27bcL497). I [measured the difference in performance](https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.235672.20breaks.20timeout/near/293228091) from removing one of the remaining hacks and it was negligible.

Therefore, in this PR, we:

+ Remove both hacks remaining;

+ Turn all would-be instances that mention gh-6025 into actual global instances;

+ Golf proofs that explicitly invoked these instances previously;

+ Remove `local attribute [instance]` lines that were added when these instances were needed.

Closes #6025.
bors bot pushed a commit to leanprover-community/mathlib that referenced this pull request Aug 16, 2022
#### Background

The `simp` tactic used to [look for subsingleton instances excessively](https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.235672.20breaks.20timeout/near/223034551), so every subsingleton/unique instances added to mathlib could slow down `simp` performance; in fact, removing some subsingleton instances locally led to such speedup that three hacks #5779, #5878 and #6639 along this line have been merged into mathlib. Since the problem was discovered, new subsingleton instances were mostly turned into lemma/defs, with a reference to gh-6025 that @eric-wieser created to track them and a notice to restore them as instances once safe to do so.

This bad behavior of `simp` was finally fixed in [lean#665](leanprover-community/lean#665) by @gebner in January 2022, so it is now safe to remove the hacks and restore the instances. In fact, the hack #5878 was already removed in [#13127](c7626b7#diff-02976f8e19552b3c7ea070e30761e4e99f1333085cc5bb94fa170861c6ed27bcL497). I [measured the difference in performance](https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.235672.20breaks.20timeout/near/293228091) from removing one of the remaining hacks and it was negligible.

Therefore, in this PR, we:

+ Remove both hacks remaining;

+ Turn all would-be instances that mention gh-6025 into actual global instances;

+ Golf proofs that explicitly invoked these instances previously;

+ Remove `local attribute [instance]` lines that were added when these instances were needed.

Closes #6025.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants