Open sigmundch opened 7 years ago
In the above example we tell from the type hierarchy that testing an interface type is equivalent to testing an extended-only type. We can change all x is I
to x is A
and remove I
from the program. The optimization works regardless of what is in the list.
I'd rather implement type test strength reduction on a per-check basis. The type hierarchy might not support the cheaper test, but we might know enough about x
to know that a cheaper tests can be used. If all tests reduce to a cheaper test then we have optimized out the demand for is I
.
Is there something similar to be done with as I
and type assertions? These produce errors containing the type name so a similar strength reduction would change the error message.
It might be possible to optimize
is
checks if we know that the target is an interface and that all implementations of that interface are also derived from a common base class that implements such interface. For example in this code:We should be able to compile
x is I
asx is A
. That would allow us to tree-shake the interface entirely and possibly make the check more efficient./cc @rakudrama