ccl icon indicating copy to clipboard operation
ccl copied to clipboard

Inconsistent upgraded array element type for same type-specifier in compiled code

Open appleby opened this issue 5 years ago • 1 comments

CCL Version 1.11.6 DarwinX8664 (installed via homebrew) macOS Mojave Version 10.14.6

Given the following in a file foo.lisp:

(deftype array-index () '(integer 0 #.(1- array-total-size-limit)))

(defstruct foo
  (vec #() :type (vector array-index)))

(defparameter *array*
  (make-array 0 :element-type 'array-index))

(print (array-element-type *array*))
(print (upgraded-array-element-type 'array-index))
(print (make-foo :vec *array*))

Loading the file works fine:

$ ccl --no-init --eval '(load "foo.lisp")' --eval '(quit)'

FIXNUM
FIXNUM
#S(FOO :VEC #())

But compilation produces the following:

$ ccl --no-init --eval '(load (compile-file "foo.lisp"))' --eval '(quit)'

(UNSIGNED-BYTE 64)
FIXNUM
> Error: The value #<VECTOR 0 type (UNSIGNED-BYTE 64), simple>
> is not of the expected type (VECTOR (UNSIGNED-BYTE 56)).
> While executing: MAKE-FOO, in process listener(1).
...

I might be misunderstanding the subtleties of array upgrading, but I was expecting the array produced by the above make-array to be compatible with the slot's typespec.

For reference, the above is a distilled version of some code that appears in the CL-PERMUTATION-TESTS package on quicklisp. I came across this while attempting to (ql:quickload :cl-permutation-tests). I figured I would check here first to see if this is a bug or expected behavior before opening an issue over there.

Maybe/maybe not related issues I found while scrounging around in the issue tracker:

  • https://github.com/Clozure/ccl/issues/81
  • https://github.com/Clozure/ccl/issues/135
  • https://trac.clozure.com/ccl/ticket/1340

appleby avatar Oct 21 '19 15:10 appleby

I've run into what appears to be the same bug. Here's a minimal example:

(let ((xs
        (make-array '(1)
                    :element-type '(integer 0 (#.(- (ash 1 33) 5)))
                    :initial-contents '(1))))
  (declare (type (simple-array (integer 0 (#.(- (ash 1 33) 5))) (*)) xs))
  xs)
  • (upgraded-array-element-type '(integer 0 (#.(- (ash 1 33) 5)))) => fixnum
  • If I compile the make-array form, it returns an array with an element type of (unsigned-byte 64).
  • If I call eval on the make-array form, it returns an array with an element type of fixnum.
  • The array in the type-error's datum slot has an element-type of (unsigned-byte 64). This is true for compiled code and with eval.

ruricolist avatar Nov 02 '20 19:11 ruricolist