Hello,

I have a problem that the return type from aref does
not agree with the declared element type of the array.
Here is a short test program:

(declaim (optimize (speed 2) (safety 2)
                   (extensions:inhibit-warnings 0)))
 
(defun elem-length (x i)
  (declare (type (simple-array simple-base-string 1) x))
  (let ((s (aref x i)))
    ; (declare (type simple-base-string s))
    (length s)))

This is the compiler output:

    Python 1.1, target Intel x86
    CLOS 18e (based on PCL September 16 92 PCL (f))
*
; Python version 1.1, VM version Intel x86 on 05 FEB 04 08:39:43 pm.
; Compiling: /lw1/mag/tb/lab/breitko/stuff/markov/lisp/test.lisp 05 FEB 04 05:06:09 pm
 
; Converted ELEM-LENGTH.
; Compiling DEFUN ELEM-LENGTH:
 
;
;
; File: /lw1/mag/tb/lab/breitko/stuff/markov/lisp/test.lisp
 
; In: DEFUN ELEM-LENGTH
 
;   (LENGTH S)
; Note: Unable to optimize due to type uncertainty:
;     The first argument is a (OR NULL VECTOR CONS), not a (SIMPLE-ARRAY * (*)).
;
; Note: Unable to optimize due to type uncertainty:
;     The first argument is a (OR NULL VECTOR CONS), not a VECTOR.
;
; Note: Forced to do static-function Length (cost 52).
;     Unable to do LENGTH/LIST (cost 40) because:
;     The first argument is a (OR NULL VECTOR CONS), not a LIST.
...

Why does the compiler infer (OR NULL VECTOR CONS) for (aref x i)?

Uncommenting the type declareation for s makes it compile
without the optimization notes.

Any help would be welcome.

Regards,
Chris

Reply via email to