Skip to content

[Merged by Bors] - chore: remove many Type _ before the colon#7718

Closed
sgouezel wants to merge 11 commits intomasterfrom
SG_clean_Type_
Closed

[Merged by Bors] - chore: remove many Type _ before the colon#7718
sgouezel wants to merge 11 commits intomasterfrom
SG_clean_Type_

Conversation

@sgouezel
Copy link
Copy Markdown
Contributor

We have turned to Type* instead of Type _, but many of them remained in mathlib because the straight replacement did not work. In general, having Type _ before the colon is a code smell, though, as it hides which types should be in the same universe and which shouldn't, and is not very robust.

This PR replaces most of the remaining Type _ before the colon (except those in category theory) by Type* or Type u. This has uncovered a few bugs (where declarations were not as polymorphic as they should be).

I had to increase heartbeats at two places when replacing Type _ by Type*, but I think it's worth it as it's really more robust.


Open in Gitpod

#align simply_connected_space.paths_homotopic SimplyConnectedSpace.paths_homotopic

instance (priority := 100) ofContractible (Y : Type _) [TopologicalSpace Y] [ContractibleSpace Y] :
instance (priority := 100) ofContractible (Y : Type u) [TopologicalSpace Y] [ContractibleSpace Y] :
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.

With the old proof, Type _ expanded to just Type !!

theorem norm_sub (h : SameRay ℝ x y) : ‖x - y‖ = |‖x‖ - ‖y‖| := by
rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩
wlog hab : b ≤ a with H
wlog hab : b ≤ a generalizing a b with H
Copy link
Copy Markdown
Contributor Author

@sgouezel sgouezel Oct 16, 2023

Choose a reason for hiding this comment

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

The old proof used the universe in {F : Type _} (where F is a variable not appearing in the theorem statement) in the wlog generalization, to match it with that of ! (so replacing {F : Type _} with {F : Type*} broke the proof for dark magic reasons)

set_option maxHeartbeats 400000 in
instance {A : Type _} [Semiring A] [Algebra R A] {S : Submonoid R} :
set_option maxHeartbeats 500000 in
instance {A : Type*} [Semiring A] [Algebra R A] {S : Submonoid R} :
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.

The type of the instance is the same with Type _ or Type* (so no added generality here), but it is just slightly slower with Type*...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think @semorrison advocated that we should stick to powers of two bump factors rather than small bumps like this

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 the end I think it was powers of 1.2 or 1.3, I think, so coherent with what I've done here.


variable [CompactSpace X]

set_option synthInstance.maxHeartbeats 30000 in
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.

The proof is slightly slower with Type* than with Type _, although the statements are the same in the end...

#align option.join_eq_join Option.joinM_eq_join

theorem bind_eq_bind {α β : Type _} {f : α → Option β} {x : Option α} : x >>= f = x.bind f :=
theorem bind_eq_bind {α β : Type u} {f : α → Option β} {x : Option α} : x >>= f = x.bind f :=
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Another reasonable option for these rare declarations is

Suggested change
theorem bind_eq_bind {α β : Type u} {f : α → Option β} {x : Option α} : x >>= f = x.bind f :=
theorem bind_eq_bind.{u} {α β : Type u} {f : α → Option β} {x : Option α} : x >>= f = x.bind f :=

or

Suggested change
theorem bind_eq_bind {α β : Type u} {f : α → Option β} {x : Option α} : x >>= f = x.bind f :=
universe u in
theorem bind_eq_bind {α β : Type u} {f : α → Option β} {x : Option α} : x >>= f = x.bind f :=

to keep the universe local

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.

Thanks for the suggestions!

Copy link
Copy Markdown
Member

@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

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

bors d+

Thanks! I thought about doing this the other day, but struggled to justify the effort to do so!

theorem RespectsIso.is_localization_away_iff (hP : RingHom.RespectsIso @P) {R S : Type _}
(R' S' : Type _) [CommRing R] [CommRing S] [CommRing R'] [CommRing S'] [Algebra R R']
theorem RespectsIso.is_localization_away_iff (hP : RingHom.RespectsIso @P) {R S : Type u}
(R' S' : Type u) [CommRing R] [CommRing S] [CommRing R'] [CommRing S'] [Algebra R R']
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks slightly suspicious to me; is there really no polymorphism here?

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.

Yes. P only makes sense for rings in the given universe u, and the conclusion mentions P applied both to R, S and to R', S'.

@bors
Copy link
Copy Markdown

bors bot commented Oct 17, 2023

✌️ sgouezel can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@ghost ghost added delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). and removed awaiting-review labels Oct 17, 2023
@sgouezel
Copy link
Copy Markdown
Contributor Author

bors r+

@github-actions github-actions bot added the ready-to-merge This PR has been sent to bors. label Oct 17, 2023
bors bot pushed a commit that referenced this pull request Oct 17, 2023
We have turned to `Type*` instead of `Type _`, but many of them remained in mathlib because the straight replacement did not work. In general, having `Type _` before the colon is a code smell, though, as it hides which types should be in the same universe and which shouldn't, and is not very robust.

This PR replaces most of the remaining `Type _` before the colon (except those in category theory) by `Type*` or `Type u`. This has uncovered a few bugs (where declarations were not as polymorphic as they should be). 

I had to increase heartbeats at two places when replacing `Type _` by `Type*`, but I think it's worth it as it's really more robust.
@bors
Copy link
Copy Markdown

bors bot commented Oct 17, 2023

Pull request successfully merged into master.

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot changed the title chore: remove many Type _ before the colon [Merged by Bors] - chore: remove many Type _ before the colon Oct 17, 2023
@bors bors bot closed this Oct 17, 2023
@bors bors bot deleted the SG_clean_Type_ branch October 17, 2023 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). ready-to-merge This PR has been sent to bors.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants