11.11.2014 Views

Design of CMU Common Lisp.pdf - Common Lisp.net

Design of CMU Common Lisp.pdf - Common Lisp.net

Design of CMU Common Lisp.pdf - Common Lisp.net

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.

Chapter 5<br />

ICR conversion<br />

5.1 Canonical forms<br />

#—<br />

Would be useful to have a Freeze-Type proclamation. Its primary use would be to say that the indicated type<br />

won’t acquire any new subtypes in the future. This allows better open-coding <strong>of</strong> structure type predicates, since<br />

the possible types that would satisfy the predicate will be constant at compile time, and thus can be compiled<br />

as a skip-chain <strong>of</strong> EQ tests.<br />

Of course, this is only a big win when the subtypes are few: the most important case is when there are none.<br />

If the closure <strong>of</strong> the subtypes is much larger than the average number <strong>of</strong> supertypes <strong>of</strong> an inferior, then it is<br />

better to grab the list <strong>of</strong> superiors out <strong>of</strong> the object’s type, and test for membership in that list.<br />

Should type-specific numeric equality be done by EQL rather than =? i.e. should = on two fixnums become<br />

EQL and then convert to EQL/FIXNUM? Currently we transform EQL into =, which is complicated, since we<br />

have to prove the operands are the class <strong>of</strong> numeric type before we do it. Also, when EQL sees one operand is a<br />

FIXNUM, it transforms to EQ, but the generator for EQ isn’t expecting numbers, so it doesn’t use an immediate<br />

compare.<br />

5.1.1 Array hackery<br />

Array type tests are transformed to %array-typep, separation <strong>of</strong> the implementation-dependent array-type<br />

handling. This way we can transform STRINGP to:<br />

(or (simple-string-p x)<br />

(and (complex-array-p x)<br />

(= (array-rank x) 1)<br />

(simple-string-p (%array-data x))))<br />

In addition to the similar bit-vector-p, we also handle vectorp and any type tests on which the a dimension<br />

isn’t wild. [Note that we will want to expand into frobs compatible with those that array references expand into<br />

so that the same optimizations will work on both.]<br />

These changes combine to convert hairy type checks into hairy typep’s, and then convert hairyp typeps into<br />

simple typeps.<br />

Do we really need non-VOP templates? It seems that we could get the desired effect through implementationdependent<br />

ICR transforms. The main risk would be <strong>of</strong> obscuring the type semantics <strong>of</strong> the code. We could fairly<br />

easily retain all the type information present at the time the tranform is run, but if we discover new type information,<br />

then it won’t be propagated unless the VM also supplies type inference methods for its internal frobs<br />

(precluding the use <strong>of</strong> %PRIMITIVE, since primitives don’t have derive-type methods.)<br />

I guess one possibility would be to have the call still considered ”known” even though it has been transformed.<br />

But this doesn’t work, since we start doing LET optimizations that trash the arglist once the call has<br />

been transformed (and indeed we want to.)<br />

18

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

Saved successfully!

Ooh no, something went wrong!