binaryen
binaryen copied to clipboard
Type intersection optimizations
It looks like we have getLeastUpperBound which computes a union over types (or more specifically, the smallest union: it finds the type which can contain all the values of two given types, and is closest to them in the hierarchy), but we don't have a method to compute an intersection. The intersection could be useful in cases like this:
(ref.eq
(A)
(B)
)
If the intersection of the types of A and B is empty then no reference can appear on both sides of the comparison, and it must return zero.
I'm wondering could this be extended to more general solution and add Value Range Analysis for all types including numerics?
It would make sense to add a getGreatestLowerBound function. We'll need it as part of LUB calculation if we ever support function subtyping, too.