fix: remove incorrect strictOr/strictAnd optimizations (#8594)

This PR removes incorrect optimizations for strictOr/strictAnd from the
old compiler, along with deleting an incorrect test. In order to do
these optimizations correctly, nontermination analysis is required.
Arguably, the correct way to express these optimizations is by exposing
the implementation of strictOr/strictAnd to a nontermination-aware phase
of the compiler, and then having them follow from more general
transformations.
This commit is contained in:
Cameron Zwarich 2025-06-02 09:14:56 -07:00 committed by GitHub
parent b73a67a635
commit 3ccc9ca7ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 1 additions and 40 deletions

View file

@ -150,36 +150,8 @@ def natFoldFns : List (Name × BinFoldFn) :=
(``Nat.ble, foldNatBle)
]
def getBoolLit : Expr → Option Bool
| Expr.const ``Bool.true _ => some true
| Expr.const ``Bool.false _ => some false
| _ => none
def foldStrictAnd (_ : Bool) (a₁ a₂ : Expr) : Option Expr :=
let v₁ := getBoolLit a₁
let v₂ := getBoolLit a₂
match v₁, v₂ with
| some true, _ => a₂
| some false, _ => a₁
| _, some true => a₁
| _, some false => a₂
| _, _ => none
def foldStrictOr (_ : Bool) (a₁ a₂ : Expr) : Option Expr :=
let v₁ := getBoolLit a₁
let v₂ := getBoolLit a₂
match v₁, v₂ with
| some true, _ => a₁
| some false, _ => a₂
| _, some true => a₂
| _, some false => a₁
| _, _ => none
def boolFoldFns : List (Name × BinFoldFn) :=
[(``strictOr, foldStrictOr), (``strictAnd, foldStrictAnd)]
def binFoldFns : List (Name × BinFoldFn) :=
boolFoldFns ++ uintBinFoldFns ++ natFoldFns
uintBinFoldFns ++ natFoldFns
def foldNatSucc (_ : Bool) (a : Expr) : Option Expr := do
let n ← getNumLit a

View file

@ -1,11 +0,0 @@
partial def spin : Nat → Bool
| n => spin (n)
@[inline] def C : Nat := 0
def f (b : Nat) :=
if strictOr (C == 0) (spin b) then "hello"
else "world"
def main (xs : List String) : IO Unit :=
IO.println (f 0)