Skip to content

[Merged by Bors] - chore: remove useless tactics#11333

Closed
adomani wants to merge 3 commits intomasterfrom
adomani/remove_useless
Closed

[Merged by Bors] - chore: remove useless tactics#11333
adomani wants to merge 3 commits intomasterfrom
adomani/remove_useless

Conversation

@adomani
Copy link
Copy Markdown
Contributor

@adomani adomani commented Mar 12, 2024

The removal of some pointless tactics flagged by #11308.


Open in Gitpod

Copy link
Copy Markdown
Contributor

@grunweg grunweg left a comment

Choose a reason for hiding this comment

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

I love the smell of deleted code in the evening. I'm amazed what gains new linters can yield :-)

@adomani
Copy link
Copy Markdown
Contributor Author

adomani commented Mar 12, 2024

I love the smell of deleted code in the evening. I'm amazed what gains new linters can yield :-)

Honestly, I was not expecting that so many skips and various other unused tactics would be present...

Copy link
Copy Markdown
Contributor

@YaelDillies YaelDillies left a comment

Choose a reason for hiding this comment

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

!bench

instance evaluationPreservesLimits [HasLimits C] (k : K) :
PreservesLimits ((evaluation K C).obj k) where
preservesLimitsOfShape {J} 𝒥 := by skip; infer_instance
preservesLimitsOfShape {_} _𝒥 := inferInstance
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doesn't inferInstance add extra junk that by infer_instance doesn't? Can you check the term is syntactically the same as it was before?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In its current form (with inferInstance):

#print evaluationPreservesLimits

def CategoryTheory.Limits.evaluationPreservesLimits.{v₂, u₂, v, u} : {C : Type u} →
  [inst : Category.{v, u} C] →
    {K : Type u₂} →
      [inst_1 : Category.{v₂, u₂} K] → [inst_2 : HasLimits C] → (k : K) → PreservesLimits ((evaluation K C).obj k) :=
fun {C} [Category.{v, u} C] {K} [Category.{v₂, u₂} K] [HasLimits C] k ↦
  { preservesLimitsOfShape := fun {x} _𝒥 ↦ inferInstance }

As it was before the change:

#print evaluationPreservesLimits

def CategoryTheory.Limits.evaluationPreservesLimits.{v₂, u₂, v, u} : {C : Type u} →
  [inst : Category.{v, u} C] →
    {K : Type u₂} →
      [inst_1 : Category.{v₂, u₂} K] → [inst_2 : HasLimits C] → (k : K) → PreservesLimits ((evaluation K C).obj k) :=
fun {C} [Category.{v, u} C] {K} [Category.{v₂, u₂} K] [HasLimits C] k ↦
  { preservesLimitsOfShape := fun {J} 𝒥 ↦ inferInstance }

Seems that the only difference are the variable names.

theorem node4L_size {l x m y r} (hm : Sized m) :
size (@node4L α l x m y r) = size l + size m + size r + 2 := by
cases m <;> simp [node4L, node3L, node'] <;> [skip; simp [size, hm.1]] <;> abel
cases m <;> simp [node4L, node3L, node'] <;> [abel; (simp [size, hm.1]; abel)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure that one is necessarily an improvement

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am happy to revert it back to where it was, but it is shorter and produces the same proof. (Really identical, very long, output of #print.)

@@ -518,8 +518,7 @@ theorem linearIndependent_iUnion_of_directed {η : Type*} {s : η → Set M} (hs
(h : ∀ i, LinearIndependent R (fun x => x : s i → M)) :
LinearIndependent R (fun x => x : (⋃ i, s i) → M) := by
by_cases hη : Nonempty η
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You will be able to golf further by doing cases isEmpty_or_nonempty η instead of that `by_cases

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, but I would definitely say that this is out of scope for this PR!

rcases n with ⟨_, ⟨⟩⟩
-- Porting note: The proof errors unless `done` or a `;` is added after `rcases`
done
rcases n with ⟨_, ⟨⟩⟩;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems like you haven't addressed the porting note, and removing done isn't a particularly great idea either.

I suggest you nolint done calls by default.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Isn't the issue that rcases does not realize that its pattern is over, since | could be an or? Again, I can put the porting note back, but replacing done by ; also "fixes" the error.

Copy link
Copy Markdown
Contributor Author

@adomani adomani Mar 12, 2024

Choose a reason for hiding this comment

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

Here is an example:

example (x : Bool) (h : false ∨ true) : True := by
  match x with
    | true => rcases h with ⟨⟩
    | false  -- <--- this is still part of `rcases`: I am calling `false` the `true` proof! x)
              · exact .intro  -- <--- the proof if `h` is `false`
              · exact .intro  -- <--- the proof if `h` is `true`
    | false => exact .intro   -- <--- the second `match` arm!

@riccardobrasca
Copy link
Copy Markdown
Member

!bench

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit 7e21612.
There were significant changes against commit e8f2336:

  Benchmark                              Metric         Change
  ============================================================
- ~Mathlib.Computability.TuringMachine   instructions    17.0%

@YaelDillies
Copy link
Copy Markdown
Contributor

Seems like some tactics weren't useless after all.

Preferring `assumption` over `aesop` has some performance implications!
@adomani
Copy link
Copy Markdown
Contributor Author

adomani commented Mar 13, 2024

🤦 the file that slowed down is a file where I replaced some splits and assumptions into a single aesop call. I reverted that change, since it was only flagged up by a skip and it should not be flagged by the second generation linter anyway!

@adomani
Copy link
Copy Markdown
Contributor Author

adomani commented Mar 13, 2024

!bench

@leanprover-bot
Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit c8593e7.
There were no significant changes against commit e8f2336.

@riccardobrasca
Copy link
Copy Markdown
Member

Thanks!

bors merge

@github-actions github-actions bot added ready-to-merge This PR has been sent to bors. and removed awaiting-review labels Mar 13, 2024
mathlib-bors bot pushed a commit that referenced this pull request Mar 13, 2024
The removal of some pointless tactics flagged by #11308.
@mathlib-bors
Copy link
Copy Markdown
Contributor

mathlib-bors bot commented Mar 13, 2024

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors bot changed the title chore: remove useless tactics [Merged by Bors] - chore: remove useless tactics Mar 13, 2024
@mathlib-bors mathlib-bors bot closed this Mar 13, 2024
@mathlib-bors mathlib-bors bot deleted the adomani/remove_useless branch March 13, 2024 12:48
dagurtomas pushed a commit that referenced this pull request Mar 22, 2024
The removal of some pointless tactics flagged by #11308.
utensil pushed a commit that referenced this pull request Mar 26, 2024
The removal of some pointless tactics flagged by #11308.
xgenereux pushed a commit that referenced this pull request Apr 15, 2024
The removal of some pointless tactics flagged by #11308.
uniwuni pushed a commit that referenced this pull request Apr 19, 2024
The removal of some pointless tactics flagged by #11308.
callesonne pushed a commit that referenced this pull request Apr 22, 2024
The removal of some pointless tactics flagged by #11308.
mathlib-bors bot pushed a commit that referenced this pull request Jun 30, 2024
The `unusedTactic` linter emits a warning if a tactic does nothing.

Previous PRs (see below) removed all the "unused tactics" that the linter flagged.

Here is an overview of this PR:
* the linter is defined in `Mathlib/Tactic/Linter/UnusedTactic.lean`;
* the file `Mathlib/GroupTheory/Perm/Cycle/Concrete.lean` contains the "only" `set_option` to opt out of the linter, since it defines notation that uses `decide` that the notation itself does not use;
* 17 test files that have surgically opted out of the linter;
* noise to import the new file, place it low in the import hierarchy and update `noshake`.


PRs removing some unused tactics:
* #11333
* #11351
* #11365
* #11379

[Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/pointless.20tactic.20linter)
dagurtomas pushed a commit that referenced this pull request Jul 2, 2024
The `unusedTactic` linter emits a warning if a tactic does nothing.

Previous PRs (see below) removed all the "unused tactics" that the linter flagged.

Here is an overview of this PR:
* the linter is defined in `Mathlib/Tactic/Linter/UnusedTactic.lean`;
* the file `Mathlib/GroupTheory/Perm/Cycle/Concrete.lean` contains the "only" `set_option` to opt out of the linter, since it defines notation that uses `decide` that the notation itself does not use;
* 17 test files that have surgically opted out of the linter;
* noise to import the new file, place it low in the import hierarchy and update `noshake`.


PRs removing some unused tactics:
* #11333
* #11351
* #11365
* #11379

[Zulip thread](https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/pointless.20tactic.20linter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge This PR has been sent to bors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants