Skip to content

Commit 91cb45d

Browse files
committed
chore: deprecate modn
1 parent 7fce9bc commit 91cb45d

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

src/Init/Data/UInt/Basic.lean

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def UInt8.mul (a b : UInt8) : UInt8 := ⟨a.toBitVec * b.toBitVec⟩
1919
def UInt8.div (a b : UInt8) : UInt8 := ⟨BitVec.udiv a.toBitVec b.toBitVec⟩
2020
@[extern "lean_uint8_mod"]
2121
def UInt8.mod (a b : UInt8) : UInt8 := ⟨BitVec.umod a.toBitVec b.toBitVec⟩
22-
@[extern "lean_uint8_modn"]
23-
def UInt8.modn (a : UInt8) (n : @& Nat) : UInt8 := ⟨Fin.modn a.val n⟩ -- TODO
22+
@[extern "lean_uint8_modn", deprecated UInt8.mod (since := "2024-09-23")]
23+
def UInt8.modn (a : UInt8) (n : @& Nat) : UInt8 := ⟨Fin.modn a.val n⟩
2424
@[extern "lean_uint8_land"]
2525
def UInt8.land (a b : UInt8) : UInt8 := ⟨a.toBitVec &&& b.toBitVec⟩
2626
@[extern "lean_uint8_lor"]
@@ -38,7 +38,10 @@ instance : Add UInt8 := ⟨UInt8.add⟩
3838
instance : Sub UInt8 := ⟨UInt8.sub⟩
3939
instance : Mul UInt8 := ⟨UInt8.mul⟩
4040
instance : Mod UInt8 := ⟨UInt8.mod⟩
41+
42+
set_option linter.deprecated false in
4143
instance : HMod UInt8 Nat UInt8 := ⟨UInt8.modn⟩
44+
4245
instance : Div UInt8 := ⟨UInt8.div⟩
4346
instance : LT UInt8 := ⟨UInt8.lt⟩
4447
instance : LE UInt8 := ⟨UInt8.le⟩
@@ -76,7 +79,7 @@ def UInt16.mul (a b : UInt16) : UInt16 := ⟨a.toBitVec * b.toBitVec⟩
7679
def UInt16.div (a b : UInt16) : UInt16 := ⟨BitVec.udiv a.toBitVec b.toBitVec⟩
7780
@[extern "lean_uint16_mod"]
7881
def UInt16.mod (a b : UInt16) : UInt16 := ⟨BitVec.umod a.toBitVec b.toBitVec⟩
79-
@[extern "lean_uint16_modn"]
82+
@[extern "lean_uint16_modn", deprecated UInt16.mod (since := "2024-09-23")]
8083
def UInt16.modn (a : UInt16) (n : @& Nat) : UInt16 := ⟨Fin.modn a.val n⟩
8184
@[extern "lean_uint16_land"]
8285
def UInt16.land (a b : UInt16) : UInt16 := ⟨a.toBitVec &&& b.toBitVec⟩
@@ -95,7 +98,10 @@ instance : Add UInt16 := ⟨UInt16.add⟩
9598
instance : Sub UInt16 := ⟨UInt16.sub⟩
9699
instance : Mul UInt16 := ⟨UInt16.mul⟩
97100
instance : Mod UInt16 := ⟨UInt16.mod⟩
101+
102+
set_option linter.deprecated false in
98103
instance : HMod UInt16 Nat UInt16 := ⟨UInt16.modn⟩
104+
99105
instance : Div UInt16 := ⟨UInt16.div⟩
100106
instance : LT UInt16 := ⟨UInt16.lt⟩
101107
instance : LE UInt16 := ⟨UInt16.le⟩
@@ -135,7 +141,7 @@ def UInt32.mul (a b : UInt32) : UInt32 := ⟨a.toBitVec * b.toBitVec⟩
135141
def UInt32.div (a b : UInt32) : UInt32 := ⟨BitVec.udiv a.toBitVec b.toBitVec⟩
136142
@[extern "lean_uint32_mod"]
137143
def UInt32.mod (a b : UInt32) : UInt32 := ⟨BitVec.umod a.toBitVec b.toBitVec⟩
138-
@[extern "lean_uint32_modn"]
144+
@[extern "lean_uint32_modn", deprecated UInt32.mod (since := "2024-09-23")]
139145
def UInt32.modn (a : UInt32) (n : @& Nat) : UInt32 := ⟨Fin.modn a.val n⟩
140146
@[extern "lean_uint32_land"]
141147
def UInt32.land (a b : UInt32) : UInt32 := ⟨a.toBitVec &&& b.toBitVec⟩
@@ -152,7 +158,10 @@ instance : Add UInt32 := ⟨UInt32.add⟩
152158
instance : Sub UInt32 := ⟨UInt32.sub⟩
153159
instance : Mul UInt32 := ⟨UInt32.mul⟩
154160
instance : Mod UInt32 := ⟨UInt32.mod⟩
161+
162+
set_option linter.deprecated false in
155163
instance : HMod UInt32 Nat UInt32 := ⟨UInt32.modn⟩
164+
156165
instance : Div UInt32 := ⟨UInt32.div⟩
157166

158167
@[extern "lean_uint32_complement"]
@@ -175,7 +184,7 @@ def UInt64.mul (a b : UInt64) : UInt64 := ⟨a.toBitVec * b.toBitVec⟩
175184
def UInt64.div (a b : UInt64) : UInt64 := ⟨BitVec.udiv a.toBitVec b.toBitVec⟩
176185
@[extern "lean_uint64_mod"]
177186
def UInt64.mod (a b : UInt64) : UInt64 := ⟨BitVec.umod a.toBitVec b.toBitVec⟩
178-
@[extern "lean_uint64_modn"]
187+
@[extern "lean_uint64_modn", deprecated UInt64.mod (since := "2024-09-23")]
179188
def UInt64.modn (a : UInt64) (n : @& Nat) : UInt64 := ⟨Fin.modn a.val n⟩
180189
@[extern "lean_uint64_land"]
181190
def UInt64.land (a b : UInt64) : UInt64 := ⟨a.toBitVec &&& b.toBitVec⟩
@@ -194,7 +203,10 @@ instance : Add UInt64 := ⟨UInt64.add⟩
194203
instance : Sub UInt64 := ⟨UInt64.sub⟩
195204
instance : Mul UInt64 := ⟨UInt64.mul⟩
196205
instance : Mod UInt64 := ⟨UInt64.mod⟩
206+
207+
set_option linter.deprecated false in
197208
instance : HMod UInt64 Nat UInt64 := ⟨UInt64.modn⟩
209+
198210
instance : Div UInt64 := ⟨UInt64.div⟩
199211
instance : LT UInt64 := ⟨UInt64.lt⟩
200212
instance : LE UInt64 := ⟨UInt64.le⟩
@@ -231,7 +243,7 @@ def USize.mul (a b : USize) : USize := ⟨a.toBitVec * b.toBitVec⟩
231243
def USize.div (a b : USize) : USize := ⟨a.toBitVec / b.toBitVec⟩
232244
@[extern "lean_usize_mod"]
233245
def USize.mod (a b : USize) : USize := ⟨a.toBitVec % b.toBitVec⟩
234-
@[extern "lean_usize_modn"]
246+
@[extern "lean_usize_modn", deprecated USize.mod (since := "2024-09-23")]
235247
def USize.modn (a : USize) (n : @& Nat) : USize := ⟨Fin.modn a.val n⟩
236248
@[extern "lean_usize_land"]
237249
def USize.land (a b : USize) : USize := ⟨a.toBitVec &&& b.toBitVec⟩
@@ -240,13 +252,16 @@ def USize.lor (a b : USize) : USize := ⟨a.toBitVec ||| b.toBitVec⟩
240252
@[extern "lean_usize_xor"]
241253
def USize.xor (a b : USize) : USize := ⟨a.toBitVec ^^^ b.toBitVec⟩
242254
@[extern "lean_usize_shift_left"]
243-
def USize.shiftLeft (a b : USize) : USize := ⟨a.toBitVec <<< (modn b System.Platform.numBits).toBitVec⟩
255+
def USize.shiftLeft (a b : USize) : USize := ⟨a.toBitVec <<< (mod b (USize.ofNat System.Platform.numBits)).toBitVec⟩
244256
@[extern "lean_usize_shift_right"]
245-
def USize.shiftRight (a b : USize) : USize := ⟨a.toBitVec >>> (modn b System.Platform.numBits).toBitVec⟩
257+
def USize.shiftRight (a b : USize) : USize := ⟨a.toBitVec >>> (mod b (USize.ofNat System.Platform.numBits)).toBitVec⟩
246258

247259
instance : Mul USize := ⟨USize.mul⟩
248260
instance : Mod USize := ⟨USize.mod⟩
261+
262+
set_option linter.deprecated false in
249263
instance : HMod USize Nat USize := ⟨USize.modn⟩
264+
250265
instance : Div USize := ⟨USize.div⟩
251266

252267
@[extern "lean_usize_complement"]

0 commit comments

Comments
 (0)