Skip to content

Commit e02a140

Browse files
leodemouraKha
andauthored
feat: @[instance_reducible] part 2 (#12263)
This PR implements the second part of #12247. --------- Co-authored-by: Sebastian Ullrich <[email protected]>
1 parent 3deba60 commit e02a140

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+205
-242
lines changed

src/Init/Classical.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ is classically true but not constructively. -/
142142

143143
/-- Transfer decidability of `¬ p` to decidability of `p`. -/
144144
-- This can not be an instance as it would be tried everywhere.
145+
@[instance_reducible]
145146
def decidable_of_decidable_not (p : Prop) [h : Decidable (¬ p)] : Decidable p :=
146147
match h with
147148
| isFalse h => isTrue (Classical.not_not.mp h)

src/Init/Control/MonadAttach.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ information to the return value, except a trivial proof of {name}`True`.
7070
This instance is used whenever no more useful {name}`MonadAttach` instance can be implemented.
7171
It always has a {name}`WeaklyLawfulMonadAttach`, but usually no {name}`LawfulMonadAttach` instance.
7272
-/
73-
@[expose]
73+
@[expose, instance_reducible]
7474
public protected def MonadAttach.trivial {m : Type u → Type v} [Monad m] : MonadAttach m where
7575
CanReturn _ _ := True
7676
attach x := (⟨·, .intro⟩) <$> x

src/Init/Data/Bool.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ def boolPredToPred : Coe (α → Bool) (α → Prop) where
636636
This should not be turned on globally as an instance because it degrades performance in Mathlib,
637637
but may be used locally.
638638
-/
639-
@[expose] def boolRelToRel : Coe (α → α → Bool) (α → α → Prop) where
639+
@[expose, instance_reducible] def boolRelToRel : Coe (α → α → Bool) (α → α → Prop) where
640640
coe r := fun a b => Eq (r a b) true
641641

642642
/-! ### subtypes -/

src/Init/Data/Char/Lemmas.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ instance ltTrans : Trans (· < · : Char → Char → Prop) (· < ·) (· < ·)
4848
trans := Char.lt_trans
4949

5050
-- This instance is useful while setting up instances for `String`.
51+
@[instance_reducible]
5152
def notLTTrans : Trans (¬ · < · : Char → Char → Prop) (¬ · < ·) (¬ · < ·) where
5253
trans h₁ h₂ := by simpa using Char.le_trans (by simpa using h₂) (by simpa using h₁)
5354

src/Init/Data/Fin/Lemmas.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ For example, for `x : Fin k` and `n : Nat`,
118118
it causes `x < n` to be elaborated as `x < ↑n` rather than `↑x < n`,
119119
silently introducing wraparound arithmetic.
120120
-/
121-
@[expose]
121+
@[expose, instance_reducible]
122122
def instNatCast (n : Nat) [NeZero n] : NatCast (Fin n) where
123123
natCast a := Fin.ofNat n a
124124

@@ -140,7 +140,7 @@ This is not a global instance, but may be activated locally via `open Fin.IntCas
140140
141141
See the doc-string for `Fin.NatCast.instNatCast` for more details.
142142
-/
143-
@[expose]
143+
@[expose, instance_reducible]
144144
def instIntCast (n : Nat) [NeZero n] : IntCast (Fin n) where
145145
intCast := Fin.intCast
146146

src/Init/Data/Ord/Basic.lean

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,21 +609,22 @@ protected theorem compare_nil_right_eq_eq {α} [Ord α] {xs : List α} :
609609
end List
610610

611611
/-- The lexicographic order on pairs. -/
612-
@[expose] def lexOrd [Ord α] [Ord β] : Ord (α × β) where
612+
@[expose, instance_reducible]
613+
def lexOrd [Ord α] [Ord β] : Ord (α × β) where
613614
compare := compareLex (compareOn (·.1)) (compareOn (·.2))
614615

615616
/--
616617
Constructs an `BEq` instance from an `Ord` instance that asserts that the result of `compare` is
617618
`Ordering.eq`.
618619
-/
619-
@[expose] def beqOfOrd [Ord α] : BEq α where
620+
@[expose, instance_reducible] def beqOfOrd [Ord α] : BEq α where
620621
beq a b := (compare a b).isEq
621622

622623
/--
623624
Constructs an `LT` instance from an `Ord` instance that asserts that the result of `compare` is
624625
`Ordering.lt`.
625626
-/
626-
@[expose] def ltOfOrd [Ord α] : LT α where
627+
@[expose, instance_reducible] def ltOfOrd [Ord α] : LT α where
627628
lt a b := compare a b = Ordering.lt
628629

629630
@[inline]

src/Init/Data/Order/Factories.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ preferring `a` over `b` when in doubt.
2323
2424
Has a `LawfulOrderLeftLeaningMin α` instance.
2525
-/
26-
@[inline]
26+
@[inline, instance_reducible]
2727
public def _root_.Min.leftLeaningOfLE (α : Type u) [LE α] [DecidableLE α] : Min α where
2828
min a b := if a ≤ b then a else b
2929

@@ -33,7 +33,7 @@ preferring `a` over `b` when in doubt.
3333
3434
Has a `LawfulOrderLeftLeaningMax α` instance.
3535
-/
36-
@[inline]
36+
@[inline, instance_reducible]
3737
public def _root_.Max.leftLeaningOfLE (α : Type u) [LE α] [DecidableLE α] : Max α where
3838
max a b := if b ≤ a then a else b
3939

src/Init/Data/Order/FactoriesExtra.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Creates an `LE α` instance from an `Ord α` instance.
1818
`OrientedOrd α` must be satisfied so that the resulting `LE α` instance faithfully represents
1919
the `Ord α` instance.
2020
-/
21-
@[inline, expose]
21+
@[inline, expose, instance_reducible]
2222
public def _root_.LE.ofOrd (α : Type u) [Ord α] : LE α where
2323
le a b := (compare a b).isLE
2424

@@ -38,7 +38,7 @@ Creates an `LT α` instance from an `Ord α` instance.
3838
`OrientedOrd α` must be satisfied so that the resulting `LT α` instance faithfully represents
3939
the `Ord α` instance.
4040
-/
41-
@[inline, expose]
41+
@[inline, expose, instance_reducible]
4242
public def _root_.LT.ofOrd (α : Type u) [Ord α] :
4343
LT α where
4444
lt a b := compare a b = .lt
@@ -82,7 +82,7 @@ public def _root_.DecidableLT.ofOrd (α : Type u) [LE α] [LT α] [Ord α] [Lawf
8282

8383
/--
8484
Creates a `BEq α` instance from an `Ord α` instance. -/
85-
@[inline, expose]
85+
@[inline, expose, instance_reducible]
8686
public def _root_.BEq.ofOrd (α : Type u) [Ord α] :
8787
BEq α where
8888
beq a b := compare a b = .eq

src/Init/Data/SInt/Basic.lean

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ Examples:
409409
* `(if (5 : Int8) < 5 then "yes" else "no") = "no"`
410410
* `show ¬((7 : Int8) < 7) by decide`
411411
-/
412-
@[extern "lean_int8_dec_lt"]
412+
@[extern "lean_int8_dec_lt", instance_reducible]
413413
def Int8.decLt (a b : Int8) : Decidable (a < b) :=
414414
inferInstanceAs (Decidable (a.toBitVec.slt b.toBitVec))
415415

@@ -425,7 +425,7 @@ Examples:
425425
* `(if (15 : Int8) ≤ 5 then "yes" else "no") = "no"`
426426
* `show (7 : Int8) ≤ 7 by decide`
427427
-/
428-
@[extern "lean_int8_dec_le"]
428+
@[extern "lean_int8_dec_le", instance_reducible]
429429
def Int8.decLe (a b : Int8) : Decidable (a ≤ b) :=
430430
inferInstanceAs (Decidable (a.toBitVec.sle b.toBitVec))
431431

@@ -778,7 +778,7 @@ Examples:
778778
* `(if (5 : Int16) < 5 then "yes" else "no") = "no"`
779779
* `show ¬((7 : Int16) < 7) by decide`
780780
-/
781-
@[extern "lean_int16_dec_lt"]
781+
@[extern "lean_int16_dec_lt", instance_reducible]
782782
def Int16.decLt (a b : Int16) : Decidable (a < b) :=
783783
inferInstanceAs (Decidable (a.toBitVec.slt b.toBitVec))
784784

@@ -794,7 +794,7 @@ Examples:
794794
* `(if (15 : Int16) ≤ 5 then "yes" else "no") = "no"`
795795
* `show (7 : Int16) ≤ 7 by decide`
796796
-/
797-
@[extern "lean_int16_dec_le"]
797+
@[extern "lean_int16_dec_le", instance_reducible]
798798
def Int16.decLe (a b : Int16) : Decidable (a ≤ b) :=
799799
inferInstanceAs (Decidable (a.toBitVec.sle b.toBitVec))
800800

@@ -1163,7 +1163,7 @@ Examples:
11631163
* `(if (5 : Int32) < 5 then "yes" else "no") = "no"`
11641164
* `show ¬((7 : Int32) < 7) by decide`
11651165
-/
1166-
@[extern "lean_int32_dec_lt"]
1166+
@[extern "lean_int32_dec_lt", instance_reducible]
11671167
def Int32.decLt (a b : Int32) : Decidable (a < b) :=
11681168
inferInstanceAs (Decidable (a.toBitVec.slt b.toBitVec))
11691169

@@ -1179,7 +1179,7 @@ Examples:
11791179
* `(if (15 : Int32) ≤ 5 then "yes" else "no") = "no"`
11801180
* `show (7 : Int32) ≤ 7 by decide`
11811181
-/
1182-
@[extern "lean_int32_dec_le"]
1182+
@[extern "lean_int32_dec_le", instance_reducible]
11831183
def Int32.decLe (a b : Int32) : Decidable (a ≤ b) :=
11841184
inferInstanceAs (Decidable (a.toBitVec.sle b.toBitVec))
11851185

@@ -1568,7 +1568,7 @@ Examples:
15681568
* `(if (5 : Int64) < 5 then "yes" else "no") = "no"`
15691569
* `show ¬((7 : Int64) < 7) by decide`
15701570
-/
1571-
@[extern "lean_int64_dec_lt"]
1571+
@[extern "lean_int64_dec_lt", instance_reducible]
15721572
def Int64.decLt (a b : Int64) : Decidable (a < b) :=
15731573
inferInstanceAs (Decidable (a.toBitVec.slt b.toBitVec))
15741574
/--
@@ -1583,7 +1583,7 @@ Examples:
15831583
* `(if (15 : Int64) ≤ 5 then "yes" else "no") = "no"`
15841584
* `show (7 : Int64) ≤ 7 by decide`
15851585
-/
1586-
@[extern "lean_int64_dec_le"]
1586+
@[extern "lean_int64_dec_le", instance_reducible]
15871587
def Int64.decLe (a b : Int64) : Decidable (a ≤ b) :=
15881588
inferInstanceAs (Decidable (a.toBitVec.sle b.toBitVec))
15891589

@@ -1958,7 +1958,7 @@ Examples:
19581958
* `(if (5 : ISize) < 5 then "yes" else "no") = "no"`
19591959
* `show ¬((7 : ISize) < 7) by decide`
19601960
-/
1961-
@[extern "lean_isize_dec_lt"]
1961+
@[extern "lean_isize_dec_lt", instance_reducible]
19621962
def ISize.decLt (a b : ISize) : Decidable (a < b) :=
19631963
inferInstanceAs (Decidable (a.toBitVec.slt b.toBitVec))
19641964

@@ -1974,7 +1974,7 @@ Examples:
19741974
* `(if (15 : ISize) ≤ 5 then "yes" else "no") = "no"`
19751975
* `show (7 : ISize) ≤ 7 by decide`
19761976
-/
1977-
@[extern "lean_isize_dec_le"]
1977+
@[extern "lean_isize_dec_le", instance_reducible]
19781978
def ISize.decLe (a b : ISize) : Decidable (a ≤ b) :=
19791979
inferInstanceAs (Decidable (a.toBitVec.sle b.toBitVec))
19801980

src/Init/Data/Slice/Array/Iterator.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ instance SubarrayIterator.instFinite : Finite (SubarrayIterator α) Id :=
6161

6262
instance [Monad m] : IteratorLoop (SubarrayIterator α) Id m := .defaultImplementation
6363

64-
@[inline, expose]
64+
@[inline, expose, instance_reducible]
6565
def Subarray.instToIterator :=
6666
ToIterator.of (γ := Slice (Internal.SubarrayData α)) (β := α) (SubarrayIterator α) (⟨⟨·⟩⟩)
6767
attribute [instance] Subarray.instToIterator

0 commit comments

Comments
 (0)