From: Christophe R. <cs...@ca...> - 2003-05-07 14:20:06
|
Pascal Bourguignon <pj...@in...> writes: >> As an example: consider the type (SINGLE-FLOAT 0.0 1.0). If you ask >> sbcl to create an array :ELEMENT-TYPE '(SINGLE-FLOAT 0.0 1.0), it will >> give you back an array specialized to hold general SINGLE-FLOATs, the >> layout of which looks something like this in memory: >> >> [ header | length | element0 | element1 | element2 ] >> >> where the element<n>s are unboxed single floats (i.e. they don't have >> any header; they are just the bare IEEE single float in bits). This >> is what is meant by a specialized array on some type. > > Yes, but the type inference engine should remember that elements of > this array are always between 0.0 and 1.0, and could apply this > knowledge to (AREF (THE (ARRAY (SINGLE-FLOAT 0.0 1.0) PROBS) 0). I don't think that implementation strategy is as inexpensive as you seem to think it is. Consider: (defun foo (x) (declare (type (simple-array (single-float 0.0 1.0) (*)) x)) (bar x) (aref x 0)) Is the "type inference engine" entitled to assume that the return value from FOO will be a single float in the range 0.0 to 1.0? Well, maybe, by some lights, but BAR here is an arbitrary function that could modify the contents of X in an arbitrary way. To provide reasonable diagnostics in the case of violation of this constraint, we have to execute _runtime_ checks in the presence of any modification inside BAR (and remember, we can change BAR's function binding at will, so we have to remember that we have to reinsert runtime checks on recompiling BAR). >> You might wish to consider what you would need to do to provide a >> specialization of array to hold objects of type (ARRAY BASE-CHAR). > > I think that since objects of type (ARRAY BASE-CHAR *) may be of > different sizes, an array of such objects needs to be an array of > pointers to them. An (ARRAY (ARRAY BASE-CHAR 10) *) could put the > BASE-CHAR inline: > > [ header | length |t|e|n|c|h|a|r|a|c|t|t|e|n|c|h|a|r|a|c|t|...] No, you can't do this. Arrays are objects which have identity; in other words, you can use EQL to ask whether two arrays are in fact the same object. With the above implementation scheme, there would be no way of, say, storing the same array twice in one of these arrays of arrays. Cheers, Christophe -- http://www-jcsu.jesus.cam.ac.uk/~csr21/ +44 1223 510 299/+44 7729 383 757 (set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b))) (defvar b "~&Just another Lisp hacker~%") (pprint #36rJesusCollegeCambridge) |