X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Farray-tran.lisp;h=a57dc9361b6336ac324f8847c1ba74153fb1e3f4;hb=74a1797f60e26c7adbc491840f89bbaab08e504d;hp=14eb3de5f28aed3bbf2c3db373a69efb8de7d08c;hpb=06b2b990a391c342759c52348d5e67357e427ecf;p=sbcl.git diff --git a/src/compiler/array-tran.lisp b/src/compiler/array-tran.lisp index 14eb3de..a57dc93 100644 --- a/src/compiler/array-tran.lisp +++ b/src/compiler/array-tran.lisp @@ -800,19 +800,23 @@ ;; without bloating the code. If we already know the type of the array ;; with sufficient precision, skip directly to DATA-VECTOR-REF. (deftransform aref ((array index) (t t) * :node node) - (let ((type (lvar-type array))) - (cond ((and (array-type-p type) - (null (array-type-complexp type)) - (not (eql (extract-upgraded-element-type array) - *wild-type*)) - (eql (length (array-type-dimensions type)) 1)) - `(data-vector-ref array (%check-bound array - (array-dimension array 0) - index))) - ((policy node (zerop insert-array-bounds-checks)) - `(hairy-data-vector-ref array index)) - (t - `(hairy-data-vector-ref/check-bounds array index))))) + (let* ((type (lvar-type array)) + (element-ctype (extract-upgraded-element-type array))) + (cond + ((and (array-type-p type) + (null (array-type-complexp type)) + (not (eql element-ctype *wild-type*)) + (eql (length (array-type-dimensions type)) 1)) + (let* ((declared-element-ctype (extract-declared-element-type array)) + (bare-form + `(data-vector-ref array + (%check-bound array (array-dimension array 0) index)))) + (if (type= declared-element-ctype element-ctype) + bare-form + `(the ,(type-specifier declared-element-ctype) ,bare-form)))) + ((policy node (zerop insert-array-bounds-checks)) + `(hairy-data-vector-ref array index)) + (t `(hairy-data-vector-ref/check-bounds array index))))) (deftransform %aset ((array index new-value) (t t t) * :node node) (if (policy node (zerop insert-array-bounds-checks)) @@ -823,6 +827,7 @@ ;;; available, switch back to the normal one to give other transforms ;;; a stab at it. (macrolet ((define (name transform-to extra extra-type) + (declare (ignore extra-type)) `(deftransform ,name ((array index ,@extra)) (let ((type (lvar-type array)) (element-type (extract-upgraded-element-type array)))