Skip to content

Commit ccfc89f

Browse files
authored
fix: compiler constant folding bug for Bool (#13989)
This PR fixes a bug in the constant folding for `Bool` wherein the compiler incorrectly determined 0-ary functions that participate in constant folding to be equal to `false`.
1 parent 659e8bb commit ccfc89f

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,11 @@ instance : Literal String where
8989
mkLit := mkStringLit
9090

9191
def getBoolLit (fvarId : FVarId) : CompilerM (Option Bool) := do
92-
let some (.const ctor [] #[]) ← findLetValue? fvarId | return none
93-
return ctor == ``Bool.true
92+
let some (.const name [] #[]) ← findLetValue? fvarId | return none
93+
match name with
94+
| ``Bool.true => return some true
95+
| ``Bool.false => return some false
96+
| _ => return none
9497

9598
def mkBoolLit (b : Bool) : FolderM (LetValue .pure) :=
9699
let ctor := if b then ``Bool.true else ``Bool.false
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/-! This is a regression test for a bug in the LCNF simp constant folder for Bool -/
2+
3+
@[noinline]
4+
def myBool := true
5+
6+
def a := (Bool.decEq myBool true).decide
7+
8+
/-- info: true -/
9+
#guard_msgs in
10+
#eval a

0 commit comments

Comments
 (0)