Skip to content

Commit 12b35fc

Browse files
datokratarthur-adjedj
authored andcommitted
fix: expose Int* definitions for simprocs and decide (fixes leanprover#10546) (leanprover#10631)
This PR exposes the definitions about `Int*`. The main reason is that the `SInt` simprocs require many of them to be exposed. Furthermore, `decide` now works with `Int*` operations. This fixes leanprover#10631.
1 parent 6337973 commit 12b35fc

File tree

7 files changed

+54
-22
lines changed

7 files changed

+54
-22
lines changed

src/Init/Data/SInt/Basic.lean

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module
88
prelude
99
public import Init.Data.UInt.Basic
1010

11-
public section
11+
@[expose] public section
1212

1313
set_option linter.missingDocs true
1414

@@ -23,7 +23,7 @@ Signed 8-bit integers.
2323
This type has special support in the compiler so it can be represented by an unboxed 8-bit value.
2424
-/
2525
structure Int8 where
26-
private ofUInt8 ::
26+
ofUInt8 ::
2727
/--
2828
Converts an 8-bit signed integer into the 8-bit unsigned integer that is its two's complement
2929
encoding.
@@ -36,7 +36,7 @@ Signed 16-bit integers.
3636
This type has special support in the compiler so it can be represented by an unboxed 16-bit value.
3737
-/
3838
structure Int16 where
39-
private ofUInt16 ::
39+
ofUInt16 ::
4040
/--
4141
Converts an 16-bit signed integer into the 16-bit unsigned integer that is its two's complement
4242
encoding.
@@ -49,7 +49,7 @@ Signed 32-bit integers.
4949
This type has special support in the compiler so it can be represented by an unboxed 32-bit value.
5050
-/
5151
structure Int32 where
52-
private ofUInt32 ::
52+
ofUInt32 ::
5353
/--
5454
Converts an 32-bit signed integer into the 32-bit unsigned integer that is its two's complement
5555
encoding.
@@ -62,7 +62,7 @@ Signed 64-bit integers.
6262
This type has special support in the compiler so it can be represented by an unboxed 64-bit value.
6363
-/
6464
structure Int64 where
65-
private ofUInt64 ::
65+
ofUInt64 ::
6666
/--
6767
Converts an 64-bit signed integer into the 64-bit unsigned integer that is its two's complement
6868
encoding.
@@ -76,7 +76,7 @@ On a 32-bit architecture, `ISize` is equivalent to `Int32`. On a 64-bit machine,
7676
`Int64`. This type has special support in the compiler so it can be represented by an unboxed value.
7777
-/
7878
structure ISize where
79-
private ofUSize ::
79+
ofUSize ::
8080
/--
8181
Converts a word-sized signed integer into the word-sized unsigned integer that is its two's
8282
complement encoding.

tests/lean/run/simpSInt.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
module
2+
13
#check_simp (-64 : Int8).toBitVec ~> 192#8
24
#check_simp (-64 : Int16).toBitVec ~> 65472#16
35
#check_simp (-64 : Int32).toBitVec ~> 4294967232#32

tests/lean/run/simprocSInt.lean

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
module
2+
13
section
24

35
variable (x : Int)
@@ -30,6 +32,9 @@ section
3032

3133
variable (x : Int8)
3234

35+
example : (5 : Int8) = 5 := by decide
36+
example : (5 : Int8) ≤ 5 := by decide
37+
example : (5 : Int8) < 6 := by decide
3338
example : Int8.toInt (-(-(-8))) + 8 = 0 := by simp +ground only
3439
example : Int8.toInt (-8) + 8 = 0 := by simp +ground only
3540
#check_simp (-5 : Int8).toNatClampNeg ~> 0
@@ -73,6 +78,9 @@ section
7378

7479
variable (x : Int16)
7580

81+
example : (5 : Int16) = 5 := by decide
82+
example : (5 : Int16) ≤ 5 := by decide
83+
example : (5 : Int16) < 6 := by decide
7684
example : Int16.toInt (-(-(-16))) + 16 = 0 := by simp +ground only
7785
example : Int16.toInt (-16) + 16 = 0 := by simp +ground only
7886
#check_simp (-5 : Int16).toNatClampNeg ~> 0
@@ -111,6 +119,9 @@ section
111119

112120
variable (x : Int32)
113121

122+
example : (5 : Int32) = 5 := by decide
123+
example : (5 : Int32) ≤ 5 := by decide
124+
example : (5 : Int32) < 6 := by decide
114125
example : Int32.toInt (-(-(-32))) + 32 = 0 := by simp +ground only
115126
example : Int32.toInt (-32) + 32 = 0 := by simp +ground only
116127
#check_simp (-5 : Int32).toNatClampNeg ~> 0
@@ -149,6 +160,9 @@ section
149160

150161
variable (x : Int64)
151162

163+
example : (5 : Int64) = 5 := by decide
164+
example : (5 : Int64) ≤ 5 := by decide
165+
example : (5 : Int64) < 6 := by decide
152166
example : Int64.toInt (-(-(-64))) + 64 = 0 := by simp +ground only
153167
example : Int64.toInt (-64) + 64 = 0 := by simp +ground only
154168
#check_simp (-5 : Int64).toNatClampNeg ~> 0

tests/lean/run/simprocUInt.lean

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
module
2+
13
section
24

35
variable (x : Nat)
@@ -17,6 +19,9 @@ section
1719

1820
variable (x : UInt8)
1921

22+
example : (5 : UInt8) = 5 := by decide
23+
example : (5 : UInt8) ≤ 5 := by decide
24+
example : (5 : UInt8) < 6 := by decide
2025
#check_simp x = 2 + 3 ~> x = 5
2126
#check_simp x = 2 * 3 ~> x = 6
2227
#check_simp x = 2 - 3 ~> x = 255
@@ -40,6 +45,9 @@ section
4045

4146
variable (x : UInt16)
4247

48+
example : (5 : UInt16) = 5 := by decide
49+
example : (5 : UInt16) ≤ 5 := by decide
50+
example : (5 : UInt16) < 6 := by decide
4351
#check_simp x = 2 + 3 ~> x = 5
4452
#check_simp x = 2 * 3 ~> x = 6
4553
#check_simp x = 2 - 3 ~> x = 65535
@@ -63,6 +71,9 @@ section
6371

6472
variable (x : UInt32)
6573

74+
example : (5 : UInt32) = 5 := by decide
75+
example : (5 : UInt32) ≤ 5 := by decide
76+
example : (5 : UInt32) < 6 := by decide
6677
#check_simp x = 2 + 3 ~> x = 5
6778
#check_simp x = 2 * 3 ~> x = 6
6879
#check_simp x = 2 - 3 ~> x = 4294967295
@@ -86,6 +97,9 @@ section
8697

8798
variable (x : UInt64)
8899

100+
example : (5 : UInt64) = 5 := by decide
101+
example : (5 : UInt64) ≤ 5 := by decide
102+
example : (5 : UInt64) < 6 := by decide
89103
#check_simp x = 2 + 3 ~> x = 5
90104
#check_simp x = 2 * 3 ~> x = 6
91105
#check_simp x = 2 - 3 ~> x = 18446744073709551615

tests/lean/sint_basic.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
module
2+
13
#check Int8
24
#eval Int8.ofInt 20
35
#eval Int8.ofInt (-20)

tests/lean/sint_basic.lean.expected.out

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ true
7373
true
7474
true
7575
[Compiler.IR] [result]
76-
def myId8 (x_1 : u8) : u8 :=
76+
def _private.sint_basic.0.myId8 (x_1 : u8) : u8 :=
7777
ret x_1
78-
def myId8._boxed (x_1 : tagged) : tagged :=
78+
def _private.sint_basic.0.myId8._boxed (x_1 : tagged) : tagged :=
7979
let x_2 : u8 := unbox x_1;
80-
let x_3 : u8 := myId8 x_2;
80+
let x_3 : u8 := _private.sint_basic.0.myId8 x_2;
8181
let x_4 : tobj := box x_3;
8282
ret x_4
8383
Int16 : Type
@@ -155,11 +155,11 @@ true
155155
true
156156
true
157157
[Compiler.IR] [result]
158-
def myId16 (x_1 : u16) : u16 :=
158+
def _private.sint_basic.0.myId16 (x_1 : u16) : u16 :=
159159
ret x_1
160-
def myId16._boxed (x_1 : tagged) : tagged :=
160+
def _private.sint_basic.0.myId16._boxed (x_1 : tagged) : tagged :=
161161
let x_2 : u16 := unbox x_1;
162-
let x_3 : u16 := myId16 x_2;
162+
let x_3 : u16 := _private.sint_basic.0.myId16 x_2;
163163
let x_4 : tobj := box x_3;
164164
ret x_4
165165
Int32 : Type
@@ -237,12 +237,12 @@ true
237237
true
238238
true
239239
[Compiler.IR] [result]
240-
def myId32 (x_1 : u32) : u32 :=
240+
def _private.sint_basic.0.myId32 (x_1 : u32) : u32 :=
241241
ret x_1
242-
def myId32._boxed (x_1 : tobj) : tobj :=
242+
def _private.sint_basic.0.myId32._boxed (x_1 : tobj) : tobj :=
243243
let x_2 : u32 := unbox x_1;
244244
dec x_1;
245-
let x_3 : u32 := myId32 x_2;
245+
let x_3 : u32 := _private.sint_basic.0.myId32 x_2;
246246
let x_4 : tobj := box x_3;
247247
ret x_4
248248
Int64 : Type
@@ -320,12 +320,12 @@ true
320320
true
321321
true
322322
[Compiler.IR] [result]
323-
def myId64 (x_1 : u64) : u64 :=
323+
def _private.sint_basic.0.myId64 (x_1 : u64) : u64 :=
324324
ret x_1
325-
def myId64._boxed (x_1 : tobj) : tobj :=
325+
def _private.sint_basic.0.myId64._boxed (x_1 : tobj) : tobj :=
326326
let x_2 : u64 := unbox x_1;
327327
dec x_1;
328-
let x_3 : u64 := myId64 x_2;
328+
let x_3 : u64 := _private.sint_basic.0.myId64 x_2;
329329
let x_4 : tobj := box x_3;
330330
ret x_4
331331
ISize : Type
@@ -403,11 +403,11 @@ true
403403
true
404404
true
405405
[Compiler.IR] [result]
406-
def myIdSize (x_1 : usize) : usize :=
406+
def _private.sint_basic.0.myIdSize (x_1 : usize) : usize :=
407407
ret x_1
408-
def myIdSize._boxed (x_1 : tobj) : tobj :=
408+
def _private.sint_basic.0.myIdSize._boxed (x_1 : tobj) : tobj :=
409409
let x_2 : usize := unbox x_1;
410410
dec x_1;
411-
let x_3 : usize := myIdSize x_2;
411+
let x_3 : usize := _private.sint_basic.0.myIdSize x_2;
412412
let x_4 : tobj := box x_3;
413413
ret x_4

tests/lean/test_single.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
source ../common.sh
33

44
# these tests don't have to succeed
5-
exec_capture lean -DprintMessageEndPos=true -Dlinter.all=false -Dexperimental.module=true "$f" || true
5+
exec_capture lean -DprintMessageEndPos=true -Dlinter.all=false -Dexperimental.module=true -DElab.inServer=true "$f" || true
66
diff_produced

0 commit comments

Comments
 (0)