binaryen icon indicating copy to clipboard operation
binaryen copied to clipboard

Type intersection optimizations

Open kripken opened this issue 3 years ago • 2 comments

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.

kripken avatar Jun 28 '22 18:06 kripken

I'm wondering could this be extended to more general solution and add Value Range Analysis for all types including numerics?

MaxGraey avatar Jun 28 '22 18:06 MaxGraey

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.

tlively avatar Jun 28 '22 18:06 tlively