11.01.2014 Views

Black-box composition of mismatched software components

Black-box composition of mismatched software components

Black-box composition of mismatched software components

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

236 E.3. Cake’s tolerance <strong>of</strong> imprecision<br />

for later retrieval. This means that if we encounter a less precise pointer subsequently,<br />

we are nevertheless sure to have a precise solution.<br />

A tentative idea for addressing difficult cases is exploiting “previously seen” in an expensive<br />

but powerful manner. By scanning the stack and static storage, we can potentially<br />

discover other pointers into the heap object than the input pointer or those previously<br />

seen. It is likely that one <strong>of</strong> these is precisely typed. Therefore, if the analysis fails, we can<br />

force such an analysis—perhaps piggy-backed on top <strong>of</strong> a garbage collector, as proposed<br />

for various other dynamic analyses [Reichenbach et al. 2010]—until it hits such a pointer.<br />

Although expensive, this cost is potentially greatly amortised, because the collector may<br />

discover precisely-typed pointers for many other objects at the same time.<br />

E.3 Cake’s tolerance <strong>of</strong> imprecision<br />

The analysis we have shown so far is clearly imprecise. In many cases, however, the Cake<br />

language can tolerate imprecision.<br />

When using array length constraints, the analysis is effectively redundant: the Cake<br />

programmer has given us both a precise element type and a precise array size. Therefore,<br />

it doesn’t matter if the analysis doesn’t yield a unique answer—all the Cake runtime<br />

needs to know is how much <strong>of</strong> the heap block to apply correspondences to, which is a<br />

given. Note, however, that in practice it may also yield a precise typing for the whole<br />

block—e.g. in the example, where perhaps few or no other types contain an array <strong>of</strong> 16<br />

chars, hence allowing the deduction that the block is a FooWidget[3]—and this should be<br />

remembered for future use. This will not succeed in some cases, however: for example, if<br />

the programmer only wants to pass the first 8 characters to the called function, out <strong>of</strong> a<br />

larger string, the analysis will not discover any typings.<br />

Another case is where the pointed-to object is <strong>of</strong> an opaque or shareable type—in this<br />

case, the runtime does not care whether the analysis is ambiguous. Rather, the pointer<br />

can be given to the receiving component as-is, with no need to copy and convert any<br />

data. For example, if a char* is passed and this yields an ambiguous typing for the block<br />

(say, it might be one big array <strong>of</strong> chars or a pointer into some smaller, contained array<br />

<strong>of</strong> chars), this does not matter so long as char is shareable with the receiving component.<br />

Similarly, uncorresponded types are effectively opaque so the runtime need not apply any<br />

correspondences.<br />

Similarly, if no admissible reinterpretation could reach a more specific type <strong>of</strong> object<br />

for which different Cake correspondences are defined than for the imprecise type, then<br />

the imprecise type suffices. For example, if no Window rules are defined, nor rules for<br />

any other type containing Widget, then knowing that the pointed-to object is a Widget<br />

suffices for making the appropriate rule selection..<br />

If the analysis fails, Cake issues a run-time warning and proceed with an imprecise<br />

result. Even in cases beyond those enumerated above, this does not always result in<br />

incorrect behaviour. (In short, this is because even if it would be admissible to reinterpret<br />

the pointer to some containing type, this need not happen in any given execution.)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!