manticore
manticore copied to clipboard
Case simplify produces invalid BOM
Seems there's a bug in case simplify? I'm using d5dfda20e063ce4c49f82555121ff95fafae1c76
➤ ../trunk-pmlc/bin/pmlc -Cbom.check-all=true fib-datatype.pml
***** Bogus BOM in Main after case-simplify *****
** invalid cast:(_t<D762>#2:int) = (int)left<F8FC>#5:any
** invalid cast:(_t<D773>#1:int) = (int)right<F8FD>#7:any
** type mismatch in return from fib<F8FA>#3.3
== expected any
== but found int
** type mismatch in return from fib<F8FA>#3.3
== expected any
== but found int
** invalid cast:(_t<D751>#1:int) = (int)right<F8FD>#7:any
** type mismatch in return from fib<F8FA>#3.3
== expected any
== but found int
** type mismatch in return from fib<F8FA>#3.3
== expected any
== but found int
** invalid cast:(_t<D78A>#1:int) = (int)ans<F90E>#3:any
broken BOM dumped to broken-BOM
bom/check-bom.sml:544.11-544.28: Fail: broken BOM
See fib-datatype.pml below:
datatype fib_result
= Zero
| One
| Val of int
fun add a b = (case (a, b)
of (Zero, b) => b
| (a, Zero) => a
| (One, One) => Val 2
| (One, Val b) => Val (b+1)
| (Val a, One) => Val (a+1)
| (Val a, Val b) => Val (a+b)
(* end case *))
fun show a = (case a
of Zero => "0"
| One => "1"
| Val a => Int.toString a
(* end case *))
fun fib n = (case n
of 0 => Zero
| 1 => One
| _ => let
val left = fib (n-1)
val right = fib (n-2)
in
add left right
end
(* end case *))
val i2s = Int.toString
val n = 30 (* https://oeis.org/A000045/list *)
val ans = fib n
val _ = print ("fib(" ^ i2s n ^ ") = " ^ show ans ^ "\n")
Replacing the definition of add in the above with
fun asInt a = (case a
of Zero => 0
| One => 1
| Val a => a
(* end case *))
fun add a b = Val ((asInt a) + (asInt b))
changes the number of type mismatches, but does not solve the issue
➤ ../trunk-pmlc/bin/pmlc -Cbom.check-all=true fib-datatype.pml
***** Bogus BOM in Main after case-simplify *****
** invalid cast:(_t<D85C>#1:int) = (int)left<F8C4>#3:any
** invalid cast:(_t<D862>#1:int) = (int)right<F8C5>#3:any
** type mismatch in return from fib<F8C2>#3.3
== expected any
== but found int
** invalid cast:(_t<D73A>#1:int) = (int)ans<F8D1>#3:any
broken BOM dumped to broken-BOM
bom/check-bom.sml:544.11-544.28: Fail: broken BOM
-Cbom.enable-unbox=false doesn't change this message either.