You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Native compiler: Bool.or(x, pick(Bool, cond, a, b)) returns the wrong value #1026
The native compiler (bend file.bend -o out) computes Bool.or(x, pick(Bool, <computed condition>, a, b)) wrongly. The checker and the default lane (bend file.bend) get it right.
Reproduces on 2.0.25 and 2.0.27 (latest), macOS 14.5 arm64, Homebrew clang 23.1.1.
Repro
importBasedefpick(-A: Data, c: Bool, a: A, b: A) ->A:
matchc:
caseTrue{}:
acaseFalse{}:
bdeflim(+m: Maybe<&2, Nat>) ->Nat:
Maybe.default(&2, Nat, m, 0n)
# n bound once, used in the condition and in a branchdeff(+x: Bool, +m: Maybe<&2, Nat>) ->Bool:
+n=lim(m)
Bool.or(x, pick(Bool, Nat.is_lt(0n, n), False{}, Nat.is_eq(n, 0n)))
# same, n not reuseddefg(+x: Bool, +m: Maybe<&2, Nat>) ->Bool:
Bool.or(x, pick(Bool, Nat.is_lt(0n, lim(m)), False{}, Nat.is_eq(lim(m), 0n)))
# same, without Bool.ordefh(+m: Maybe<&2, Nat>) ->Bool:
+n=lim(m)
pick(Bool, Nat.is_lt(0n, n), False{}, Nat.is_eq(n, 0n))
defmain() ->IO(Unit):
doIO<Unit>:
IO.print("f "++Bool.show(f(False{}, Some{0n})) ++" g "++Bool.show(g(False{}, Some{0n})) ++" h "++Bool.show(h(Some{0n})))
With m = Some{0n}, n = 0: the condition 0 < 0 is False, so pick returns Nat.is_eq(0, 0) = True, and Bool.or(False, True) = True.
f
g
h
bend canary.bend (default lane)
True
True
True
bend canary.bend -o canary && ./canary
False
False
True
h (the same pick without Bool.or) is right when compiled; f and g are wrong whether or not n is reused.
Activity
bend: proof budget from an idle VM (77 s), and link the miscompile re…
Intrinsic arguments take their parameter layouts, so a boxed Bool fro…