Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: miscompilation in constant folding #4311

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Lean/Compiler/ConstFolding.lean
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,13 @@ def foldCharOfNat (beforeErasure : Bool) (a : Expr) : Option Expr := do
else
return mkUInt32Lit 0

def foldToNat (_ : Bool) (a : Expr) : Option Expr := do
def foldToNat (size : Nat) (_ : Bool) (a : Expr) : Option Expr := do
let n ← getNumLit a
return mkRawNatLit n
return mkRawNatLit (n % size)


def uintFoldToNatFns : List (Name × UnFoldFn) :=
numScalarTypes.foldl (fun r info => (info.toNatFn, foldToNat) :: r) []
numScalarTypes.foldl (fun r info => (info.toNatFn, foldToNat info.size) :: r) []

def unFoldFns : List (Name × UnFoldFn) :=
[(``Nat.succ, foldNatSucc),
Expand Down
24 changes: 24 additions & 0 deletions tests/lean/run/4306.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/--
info: 12776324570088369205
-/
#guard_msgs in
#eval (123456789012345678901).toUInt64

/--
info: 12776324570088369205
-/
#guard_msgs in
#eval (123456789012345678901).toUInt64.toNat

/--
error: application type mismatch
Lean.ofReduceBool false._nativeDecide_1 true (Eq.refl true)
argument has type
true = true
but function has type
Lean.reduceBool false._nativeDecide_1 = true → false._nativeDecide_1 = true
-/
#guard_msgs in
theorem false : False := by
have : (123456789012345678901).toUInt64.toNat = 123456789012345678901 := by native_decide
simp [Nat.toUInt64] at this
Loading