Skip to content

Commit 3544d4d

Browse files
committed
fix: overeager uint constant folding
1 parent c41cb64 commit 3544d4d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/Lean/Compiler/LCNF/Simp/ConstantFold.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,10 @@ def arithmeticFolders : List (Name × Folder) := [
356356
(``UInt32.add, Folder.first #[Folder.mkBinary UInt32.add, Folder.leftRightNeutral (0 : UInt32)]),
357357
(``UInt64.add, Folder.first #[Folder.mkBinary UInt64.add, Folder.leftRightNeutral (0 : UInt64)]),
358358
(``Nat.sub, Folder.first #[Folder.mkBinary Nat.sub, Folder.leftRightNeutral 0]),
359-
(``UInt8.sub, Folder.first #[Folder.mkBinary UInt8.sub, Folder.leftRightNeutral (0 : UInt8)]),
360-
(``UInt16.sub, Folder.first #[Folder.mkBinary UInt16.sub, Folder.leftRightNeutral (0 : UInt16)]),
361-
(``UInt32.sub, Folder.first #[Folder.mkBinary UInt32.sub, Folder.leftRightNeutral (0 : UInt32)]),
362-
(``UInt64.sub, Folder.first #[Folder.mkBinary UInt64.sub, Folder.leftRightNeutral (0 : UInt64)]),
359+
(``UInt8.sub, Folder.first #[Folder.mkBinary UInt8.sub, Folder.rightNeutral (0 : UInt8)]),
360+
(``UInt16.sub, Folder.first #[Folder.mkBinary UInt16.sub, Folder.rightNeutral (0 : UInt16)]),
361+
(``UInt32.sub, Folder.first #[Folder.mkBinary UInt32.sub, Folder.rightNeutral (0 : UInt32)]),
362+
(``UInt64.sub, Folder.first #[Folder.mkBinary UInt64.sub, Folder.rightNeutral (0 : UInt64)]),
363363
-- We don't convert Nat multiplication by a power of 2 into a left shift, because the fast path
364364
-- for multiplication isn't any slower than a fast path for left shift that checks for overflow.
365365
(``UInt8.mul, Folder.first #[Folder.mkBinary UInt8.mul, Folder.leftRightNeutral (1 : UInt8), Folder.leftRightAnnihilator (0 : UInt8) 0, Folder.mulShift ``UInt8.shiftLeft (UInt8.shiftLeft 1 ·) UInt8.log2]),
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/-!
2+
This test guards against a uint constant folding bug
3+
-/
4+
5+
6+
def danger : UInt64 := UInt64.ofNat UInt64.size - 1
7+
theorem danger_eq_large : danger = 18446744073709551615 := by decide +kernel
8+
/--
9+
error: Tactic `native_decide` evaluated that the proposition
10+
danger = 1
11+
is false
12+
-/
13+
#guard_msgs in
14+
theorem danger_eq_one : danger = 1 := by native_decide
15+
theorem bad : False := by simpa using danger_eq_large.symm.trans danger_eq_one

0 commit comments

Comments
 (0)