Skip to content

Commit d5f7a05

Browse files
merge lean-pr-testing-12286
2 parents 3922e3d + 082d63c commit d5f7a05

File tree

15 files changed

+118
-21
lines changed

15 files changed

+118
-21
lines changed

Mathlib/Analysis/Convex/Segment.lean

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,17 @@ theorem image_openSegment (f : E →ᵃ[𝕜] F) (a b : E) :
246246
@[simp]
247247
theorem vadd_segment [AddTorsor G E] [VAddCommClass G E E] (a : G) (b c : E) :
248248
a +ᵥ [b -[𝕜] c] = [a +ᵥ b -[𝕜] a +ᵥ c] :=
249+
#adaptation_note /-- Prior to https://github.com/leanprover/lean4/pull/12286/
250+
we didn't need this `let` statement. -/
251+
let : AddTorsor E E := addGroupIsAddTorsor E
249252
image_segment 𝕜 ⟨_, LinearMap.id, fun _ _ => vadd_comm _ _ _⟩ b c
250253

251254
@[simp]
252255
theorem vadd_openSegment [AddTorsor G E] [VAddCommClass G E E] (a : G) (b c : E) :
253256
a +ᵥ openSegment 𝕜 b c = openSegment 𝕜 (a +ᵥ b) (a +ᵥ c) :=
257+
#adaptation_note /-- Prior to https://github.com/leanprover/lean4/pull/12286/
258+
we didn't need this `let` statement. -/
259+
let : AddTorsor E E := addGroupIsAddTorsor E
254260
image_openSegment 𝕜 ⟨_, LinearMap.id, fun _ _ => vadd_comm _ _ _⟩ b c
255261

256262
@[simp]

Mathlib/CategoryTheory/Category/Basic.lean

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,40 @@ Often, however, it's not even necessary to include the `.{v}`.
7979
If it is omitted a "free" universe will be used.
8080
-/
8181

82+
library_note «universe output parameters and typeclass caching»
83+
/--
84+
Many classes in Mathlib have universe parameters that do not appear in their
85+
input parameter types. For example:
86+
* `Category.{v} (C : Type u)` — the morphism universe `v` is not determined by `C`
87+
* `HasLimitsOfSize.{v₁, u₁} (C : Type u) [Category.{v} C]` — the shape universes `v₁, u₁`
88+
are not determined by `C`
89+
* `Small.{w} (α : Type v)` — the target universe `w` is not determined by `α`
90+
(but `v` is determined by `α`, so `v` *is* an output)
91+
* `Functor.IsContinuous.{t} (F) (J) (K)` — the sheaf type universe `t` is not determined
92+
by `F`, `J`, `K`
93+
* `UnivLE.{u, v}` — has no input parameters at all
94+
95+
By default (since https://github.com/leanprover/lean4/pull/12286), Lean treats any universe
96+
parameter not occurring in input types as an output parameter, and erases it from typeclass
97+
resolution cache keys. This means that queries differing only in such a universe share a
98+
cache entry — the first result found is reused.
99+
100+
This is correct when the universe truly is determined by the inputs (e.g., `v` in
101+
`Small.{w} (α : Type v)`), but incorrect when the universe is part of the *question*
102+
(e.g., `v` in `Category.{v} C`). Cache collisions cause "stuck at solving universe constraint"
103+
errors or silent misresolution.
104+
105+
The `@[univ_out_params]` attribute
106+
(from https://github.com/leanprover/lean4/pull/12423) overrides the default:
107+
* `@[univ_out_params]` — no universe parameters are output (all kept in cache key)
108+
* `@[univ_out_params v]` — only `v` is output
109+
110+
**Rule of thumb:** if the class is typically used with explicit universe annotations
111+
(e.g., `HasLimitsOfSize.{v₁, u₁} C`) or is marked `@[pp_with_univ]`, its "extra" universe
112+
parameters are likely inputs, not outputs, and the class should be annotated with
113+
`@[univ_out_params]`.
114+
-/
115+
82116
universe v u
83117

84118
namespace CategoryTheory
@@ -191,7 +225,11 @@ set_option mathlib.tactic.category.grind true
191225
/-- The typeclass `Category C` describes morphisms associated to objects of type `C`.
192226
The universe levels of the objects and morphisms are unconstrained, and will often need to be
193227
specified explicitly, as `Category.{v} C`. (See also `LargeCategory` and `SmallCategory`.) -/
194-
@[pp_with_univ, stacks 0014]
228+
-- After https://github.com/leanprover/lean4/pull/12286 and
229+
-- https://github.com/leanprover/lean4/pull/12423, the morphism universe `v` would default to
230+
-- being a universe output parameter.
231+
-- See Note [universe output parameters and typeclass caching].
232+
@[univ_out_params, pp_with_univ, stacks 0014]
195233
class Category (obj : Type u) : Type max u (v + 1) extends CategoryStruct.{v} obj where
196234
/-- Identity morphisms are left identities for composition. -/
197235
id_comp : ∀ {X Y : obj} (f : X ⟶ Y), 𝟙 X ≫ f = f := by cat_disch

Mathlib/CategoryTheory/Enriched/Limits/HasConicalLimits.lean

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ attribute [instance] HasConicalLimitsOfShape.hasConicalLimit
7272
`C` has all conical limits of size `v₁ u₁` (`HasLimitsOfSize.{v₁ u₁} C`)
7373
if it has conical limits of every shape `J : Type u₁` with `[Category.{v₁} J]`.
7474
-/
75-
@[pp_with_univ]
75+
-- After https://github.com/leanprover/lean4/pull/12286 and
76+
-- https://github.com/leanprover/lean4/pull/12423, the shape universes `v₁, u₁` would default
77+
-- to universe output parameters. See Note [universe output parameters and typeclass caching].
78+
@[univ_out_params, pp_with_univ]
7679
class HasConicalLimitsOfSize : Prop where
7780
/-- All functors `F : J ⥤ C` from all small `J` have conical limits -/
7881
hasConicalLimitsOfShape : ∀ (J : Type u₁) [Category.{v₁} J], HasConicalLimitsOfShape J V C := by

Mathlib/CategoryTheory/EssentiallySmall.lean

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ namespace CategoryTheory
3838

3939
/-- A category is `EssentiallySmall.{w}` if there exists
4040
an equivalence to some `S : Type w` with `[SmallCategory S]`. -/
41-
@[pp_with_univ]
41+
-- After https://github.com/leanprover/lean4/pull/12286 and
42+
-- https://github.com/leanprover/lean4/pull/12423, the smallness universe `w` in
43+
-- `EssentiallySmall` and `LocallySmall` would default to a universe output parameter.
44+
-- See Note [universe output parameters and typeclass caching].
45+
@[univ_out_params, pp_with_univ]
4246
class EssentiallySmall (C : Type u) [Category.{v} C] : Prop where
4347
/-- An essentially small category is equivalent to some small category. -/
4448
equiv_smallCategory : ∃ (S : Type w) (_ : SmallCategory S), Nonempty (C ≌ S)
@@ -88,7 +92,8 @@ theorem essentiallySmallSelf : EssentiallySmall.{max w v u} C :=
8892
8993
See `ShrinkHoms C` for a category instance where every hom set has been replaced by a small model.
9094
-/
91-
@[pp_with_univ]
95+
-- See comment on `EssentiallySmall` above.
96+
@[univ_out_params, pp_with_univ]
9297
class LocallySmall (C : Type u) [Category.{v} C] : Prop where
9398
/-- A locally small category has small hom-types. -/
9499
hom_small : ∀ X Y : C, Small.{w} (X ⟶ Y) := by infer_instance

Mathlib/CategoryTheory/Limits/Creates.lean

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ class CreatesLimitsOfShape (J : Type w) [Category.{w'} J] (F : C ⥤ D) where
8282

8383
-- This should be used with explicit universe variables.
8484
/-- `F` creates limits if it creates limits of shape `J` for any `J`. -/
85-
@[nolint checkUnivs, pp_with_univ]
85+
-- After https://github.com/leanprover/lean4/pull/12286 and
86+
-- https://github.com/leanprover/lean4/pull/12423, the shape universes in
87+
-- `CreatesLimitsOfSize` and `CreatesColimitsOfSize` would default to universe output parameters.
88+
-- See Note [universe output parameters and typeclass caching].
89+
@[univ_out_params, nolint checkUnivs, pp_with_univ]
8690
class CreatesLimitsOfSize (F : C ⥤ D) where
8791
CreatesLimitsOfShape : ∀ {J : Type w} [Category.{w'} J], CreatesLimitsOfShape J F := by
8892
infer_instance
@@ -111,7 +115,7 @@ class CreatesColimitsOfShape (J : Type w) [Category.{w'} J] (F : C ⥤ D) where
111115

112116
-- This should be used with explicit universe variables.
113117
/-- `F` creates colimits if it creates colimits of shape `J` for any small `J`. -/
114-
@[nolint checkUnivs, pp_with_univ]
118+
@[univ_out_params, nolint checkUnivs, pp_with_univ]
115119
class CreatesColimitsOfSize (F : C ⥤ D) where
116120
CreatesColimitsOfShape : ∀ {J : Type w} [Category.{w'} J], CreatesColimitsOfShape J F := by
117121
infer_instance

Mathlib/CategoryTheory/Limits/Filtered.lean

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,17 @@ section
7070
variable (C)
7171

7272
/-- Class for having all cofiltered limits of a given size. -/
73-
@[pp_with_univ]
73+
-- After https://github.com/leanprover/lean4/pull/12286 and
74+
-- https://github.com/leanprover/lean4/pull/12423, the shape universes in
75+
-- `HasCofilteredLimitsOfSize` and `HasFilteredColimitsOfSize` would default to universe
76+
-- output parameters. See Note [universe output parameters and typeclass caching].
77+
@[univ_out_params, pp_with_univ]
7478
class HasCofilteredLimitsOfSize : Prop where
7579
/-- For all filtered types of size `w`, we have limits -/
7680
HasLimitsOfShape : ∀ (I : Type w) [Category.{w'} I] [IsCofiltered I], HasLimitsOfShape I C
7781

7882
/-- Class for having all filtered colimits of a given size. -/
79-
@[pp_with_univ]
83+
@[univ_out_params, pp_with_univ]
8084
class HasFilteredColimitsOfSize : Prop where
8185
/-- For all filtered types of a size `w`, we have colimits -/
8286
HasColimitsOfShape : ∀ (I : Type w) [Category.{w'} I] [IsFiltered I], HasColimitsOfShape I C

Mathlib/CategoryTheory/Limits/HasLimits.lean

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ class HasLimitsOfShape : Prop where
104104
/-- `C` has all limits of size `v₁ u₁` (`HasLimitsOfSize.{v₁ u₁} C`)
105105
if it has limits of every shape `J : Type u₁` with `[Category.{v₁} J]`.
106106
-/
107-
@[pp_with_univ]
107+
-- After https://github.com/leanprover/lean4/pull/12286 and
108+
-- https://github.com/leanprover/lean4/pull/12423, the shape universes `v₁, u₁` would default
109+
-- to universe output parameters. See Note [universe output parameters and typeclass caching].
110+
@[univ_out_params, pp_with_univ]
108111
class HasLimitsOfSize (C : Type u) [Category.{v} C] : Prop where
109112
/-- All functors `F : J ⥤ C` from all small `J` have limits -/
110113
has_limits_of_shape : ∀ (J : Type u₁) [Category.{v₁} J], HasLimitsOfShape J C := by
@@ -626,7 +629,10 @@ class HasColimitsOfShape : Prop where
626629
/-- `C` has all colimits of size `v₁ u₁` (`HasColimitsOfSize.{v₁ u₁} C`)
627630
if it has colimits of every shape `J : Type u₁` with `[Category.{v₁} J]`.
628631
-/
629-
@[pp_with_univ]
632+
-- After https://github.com/leanprover/lean4/pull/12286 and
633+
-- https://github.com/leanprover/lean4/pull/12423, the shape universes `v₁, u₁` would default
634+
-- to universe output parameters. See Note [universe output parameters and typeclass caching].
635+
@[univ_out_params, pp_with_univ]
630636
class HasColimitsOfSize (C : Type u) [Category.{v} C] : Prop where
631637
/-- All `F : J ⥤ C` have colimits for all small `J` -/
632638
has_colimits_of_shape : ∀ (J : Type u₁) [Category.{v₁} J], HasColimitsOfShape J C := by

Mathlib/CategoryTheory/Limits/Preserves/Basic.lean

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ class PreservesColimitsOfShape (J : Type w) [Category.{w'} J] (F : C ⥤ D) : Pr
7575
-- This should be used with explicit universe variables.
7676
/-- `PreservesLimitsOfSize.{v u} F` means that `F` sends all limit cones over any
7777
diagram `J ⥤ C` to limit cones, where `J : Type u` with `[Category.{v} J]`. -/
78-
@[nolint checkUnivs, pp_with_univ]
78+
-- After https://github.com/leanprover/lean4/pull/12286 and
79+
-- https://github.com/leanprover/lean4/pull/12423, the shape universes `w, w'` in
80+
-- `PreservesLimitsOfSize`, `PreservesColimitsOfSize`, `ReflectsLimitsOfSize`, and
81+
-- `ReflectsColimitsOfSize` would default to universe output parameters.
82+
-- See Note [universe output parameters and typeclass caching].
83+
@[univ_out_params, nolint checkUnivs, pp_with_univ]
7984
class PreservesLimitsOfSize (F : C ⥤ D) : Prop where
8085
preservesLimitsOfShape : ∀ {J : Type w} [Category.{w'} J], PreservesLimitsOfShape J F := by
8186
infer_instance
@@ -88,7 +93,7 @@ abbrev PreservesLimits (F : C ⥤ D) :=
8893
-- This should be used with explicit universe variables.
8994
/-- `PreservesColimitsOfSize.{v u} F` means that `F` sends all colimit cocones over any
9095
diagram `J ⥤ C` to colimit cocones, where `J : Type u` with `[Category.{v} J]`. -/
91-
@[nolint checkUnivs, pp_with_univ]
96+
@[univ_out_params, nolint checkUnivs, pp_with_univ]
9297
class PreservesColimitsOfSize (F : C ⥤ D) : Prop where
9398
preservesColimitsOfShape : ∀ {J : Type w} [Category.{w'} J], PreservesColimitsOfShape J F := by
9499
infer_instance
@@ -355,7 +360,7 @@ whenever the image of a cone over some `K : J ⥤ C` under `F` is a limit cone i
355360
the cone was already a limit cone in `C`.
356361
Note that we do not assume a priori that `D` actually has any limits.
357362
-/
358-
@[nolint checkUnivs, pp_with_univ]
363+
@[univ_out_params, nolint checkUnivs, pp_with_univ]
359364
class ReflectsLimitsOfSize (F : C ⥤ D) : Prop where
360365
reflectsLimitsOfShape : ∀ {J : Type w} [Category.{w'} J], ReflectsLimitsOfShape J F := by
361366
infer_instance
@@ -374,7 +379,7 @@ whenever the image of a cocone over some `K : J ⥤ C` under `F` is a colimit co
374379
the cocone was already a colimit cocone in `C`.
375380
Note that we do not assume a priori that `D` actually has any colimits.
376381
-/
377-
@[nolint checkUnivs, pp_with_univ]
382+
@[univ_out_params, nolint checkUnivs, pp_with_univ]
378383
class ReflectsColimitsOfSize (F : C ⥤ D) : Prop where
379384
reflectsColimitsOfShape : ∀ {J : Type w} [Category.{w'} J], ReflectsColimitsOfShape J F := by
380385
infer_instance

Mathlib/CategoryTheory/Limits/Preserves/Filtered.lean

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ section Preserves
4343
-- This should be used with explicit universe variables.
4444
/-- `PreservesFilteredColimitsOfSize.{w', w} F` means that `F` sends all colimit cocones over any
4545
filtered diagram `J ⥤ C` to colimit cocones, where `J : Type w` with `[Category.{w'} J]`. -/
46-
@[nolint checkUnivs, pp_with_univ]
46+
-- After https://github.com/leanprover/lean4/pull/12286 and
47+
-- https://github.com/leanprover/lean4/pull/12423, the shape universes in
48+
-- `PreservesFilteredColimitsOfSize`, `ReflectsFilteredColimitsOfSize`,
49+
-- `PreservesCofilteredLimitsOfSize`, and `ReflectsCofilteredLimitsOfSize` would default to
50+
-- universe output parameters. See Note [universe output parameters and typeclass caching].
51+
@[univ_out_params, nolint checkUnivs, pp_with_univ]
4752
class PreservesFilteredColimitsOfSize (F : C ⥤ D) : Prop where
4853
preserves_filtered_colimits :
4954
∀ (J : Type w) [Category.{w'} J] [IsFiltered J], PreservesColimitsOfShape J F
@@ -99,7 +104,7 @@ section Reflects
99104
-- This should be used with explicit universe variables.
100105
/-- `ReflectsFilteredColimitsOfSize.{w', w} F` means that whenever the image of a filtered cocone
101106
under `F` is a colimit cocone, the original cocone was already a colimit. -/
102-
@[nolint checkUnivs, pp_with_univ]
107+
@[univ_out_params, nolint checkUnivs, pp_with_univ]
103108
class ReflectsFilteredColimitsOfSize (F : C ⥤ D) : Prop where
104109
reflects_filtered_colimits :
105110
∀ (J : Type w) [Category.{w'} J] [IsFiltered J], ReflectsColimitsOfShape J F
@@ -159,7 +164,7 @@ section Preserves
159164
-- This should be used with explicit universe variables.
160165
/-- `PreservesCofilteredLimitsOfSize.{w', w} F` means that `F` sends all limit cones over any
161166
cofiltered diagram `J ⥤ C` to limit cones, where `J : Type w` with `[Category.{w'} J]`. -/
162-
@[nolint checkUnivs, pp_with_univ]
167+
@[univ_out_params, nolint checkUnivs, pp_with_univ]
163168
class PreservesCofilteredLimitsOfSize (F : C ⥤ D) : Prop where
164169
preserves_cofiltered_limits :
165170
∀ (J : Type w) [Category.{w'} J] [IsCofiltered J], PreservesLimitsOfShape J F
@@ -215,7 +220,7 @@ section Reflects
215220
-- This should be used with explicit universe variables.
216221
/-- `ReflectsCofilteredLimitsOfSize.{w', w} F` means that whenever the image of a cofiltered cone
217222
under `F` is a limit cone, the original cone was already a limit. -/
218-
@[nolint checkUnivs, pp_with_univ]
223+
@[univ_out_params, nolint checkUnivs, pp_with_univ]
219224
class ReflectsCofilteredLimitsOfSize (F : C ⥤ D) : Prop where
220225
reflects_cofiltered_limits :
221226
∀ (J : Type w) [Category.{w'} J] [IsCofiltered J], ReflectsLimitsOfShape J F

Mathlib/CategoryTheory/Localization/SmallHom.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ variable (L : C ⥤ D) [L.IsLocalization W] (X Y Z : C)
4343
/-- This property holds if the type of morphisms between `X` and `Y`
4444
in the localized category with respect to `W : MorphismProperty C`
4545
is small. -/
46+
-- After https://github.com/leanprover/lean4/pull/12286 and
47+
-- https://github.com/leanprover/lean4/pull/12423, the universe `w` would default to a
48+
-- universe output parameter. See Note [universe output parameters and typeclass caching].
49+
@[univ_out_params]
4650
class HasSmallLocalizedHom : Prop where
4751
small : Small.{w} (W.Q.obj X ⟶ W.Q.obj Y)
4852

0 commit comments

Comments
 (0)