DavePearce/Whiley — Issue #66: Fix Unnecessary Coercions
Author: DavePearce
Created: 2012-01-16 23:37:48+00:00
State: open

Currently, the compiler generates a lot of coercions and it might be nice to eliminate them. For example,

int f(int x, real y):
if x == y:
return 1
else:
return 2

Here, x is coerced into type real. In practice, this may not be very efficient. It's particularly relevant for set/list types. For example:

int f([int] x, {int} y):
if x == y:
return 1
else:
return 2

Again, x is coerced into type {int} ... which could really be an expensive and unnecessary operation.

Finally, it's not just comparison where this issue arises. For example, set union has a similar problem.