- (warn-about-possible-float-info-loss ()
- (warn-possible-cross-type-float-info-loss
- `(cross-typep ,host-object ,target-type))))
- (cond (;; Handle various SBCL-specific types which can't exist on
- ;; the ANSI cross-compilation host. KLUDGE: This code will
- ;; need to be tweaked by hand if the names of these types
- ;; ever change, ugh!
- (if (consp target-type)
- (member (car target-type)
- '(sb!alien:alien))
- (member target-type
- '(system-area-pointer
- funcallable-instance
- sb!alien-internals:alien-value)))
- (values nil t))
- (;; special case when TARGET-TYPE isn't a type spec, but
- ;; instead a CLASS object
- (typep target-type 'sb!xc::structure-class)
- ;; SBCL-specific types which have an analogue specially
- ;; created on the host system
- (if (sb!xc:subtypep (sb!xc:class-name target-type)
- 'sb!kernel::structure!object)
- (values (typep host-object (sb!xc:class-name target-type)) t)
- (values nil t)))
- ((and (symbolp target-type)
- (find-class target-type nil)
- (subtypep target-type 'sb!kernel::structure!object))
- (values (typep host-object target-type) t))
- ((and (symbolp target-type)
- (sb!xc:find-class target-type nil)
- (sb!xc:subtypep target-type 'cl:structure-object)
- (typep host-object '(or symbol number list character)))
- (values nil t))
- (;; easy cases of arrays and vectors
- (member target-type
- '(array simple-string simple-vector string vector))
- (values (typep host-object target-type) t))
- (;; general cases of vectors
- (and (not (unknown-type-p (values-specifier-type target-type)))
- (sb!xc:subtypep target-type 'cl:vector))
- (if (vectorp host-object)
- (warn-and-give-up) ; general case of vectors being way too hard
- (values nil t))) ; but "obviously not a vector" being easy
- (;; general cases of arrays
- (and (not (unknown-type-p (values-specifier-type target-type)))
- (sb!xc:subtypep target-type 'cl:array))
- (if (arrayp host-object)
- (warn-and-give-up) ; general case of arrays being way too hard
- (values nil t))) ; but "obviously not an array" being easy
- ((consp target-type)
- (let ((first (first target-type))
- (rest (rest target-type)))
- (case first
- ;; Many complex types are guaranteed to correspond exactly
- ;; between any host ANSI Common Lisp and the target SBCL.
- ((integer member mod rational real signed-byte unsigned-byte)
- (values (typep host-object target-type) t))
- ;; Floating point types are guaranteed to correspond,
- ;; too, but less exactly.
- ((single-float double-float)
- (cond ((floatp host-object)
- (warn-about-possible-float-info-loss)
- (values (typep host-object target-type) t))
- (t
- (values nil t))))
- ;; Some complex types have translations that are less
- ;; trivial.
- (and (every/type #'cross-typep host-object rest))
- (or (any/type #'cross-typep host-object rest))
- ;; If we want to work with the KEYWORD type, we need
- ;; to grok (SATISFIES KEYWORDP).
- (satisfies
- (destructuring-bind (predicate-name) rest
- (if (and (in-cl-package-p predicate-name)
- (fboundp predicate-name))
- ;; Many things like KEYWORDP, ODDP, PACKAGEP,
- ;; and NULL correspond between host and target.
- (values (not (null (funcall predicate-name host-object)))
- t)
- ;; For symbols not in the CL package, it's not
- ;; in general clear how things correspond
- ;; between host and target, so we punt.
- (warn-and-give-up))))
- ;; Some complex types are too hard to handle in the positive
- ;; case, but at least we can be confident in a large fraction of
- ;; the negative cases..
- ((base-string simple-base-string simple-string)
- (if (stringp host-object)
- (warn-and-give-up)
- (values nil t)))
- ((vector simple-vector)
- (if (vectorp host-object)
- (warn-and-give-up)
- (values nil t)))
- ((array simple-array)
- (if (arrayp host-object)
- (warn-and-give-up)
- (values nil t)))
- (function
- (if (functionp host-object)
- (warn-and-give-up)
- (values nil t)))
- ;; And the Common Lisp type system is complicated, and
- ;; we don't try to implement everything.
- (otherwise (warn-and-give-up)))))
- (t
- (case target-type
- ((*)
- ;; KLUDGE: SBCL has * as an explicit wild type. While this is
- ;; sort of logical (because (e.g. (ARRAY * 1)) is a valid type)
- ;; it's not ANSI: looking at the ANSI definitions of complex
- ;; types like like ARRAY shows that they consider * different
- ;; from other type names. Someday we should probably get rid of
- ;; this non-ANSIism in base SBCL, but until we do, we might as
- ;; well here in the cross compiler. And in order to make sure
- ;; that we don't continue doing it after we someday patch SBCL's
- ;; type system so that * is no longer a type, we make this
- ;; assertion:
- (assert (typep (specifier-type '*) 'named-type))
- (values t t))
- ;; Many simple types are guaranteed to correspond exactly
+ (warn-about-possible-float-info-loss ()
+ (warn-possible-cross-type-float-info-loss
+ `(cross-typep ,host-object ,raw-target-type)))
+ ;; a convenient idiom for making more matches to special cases:
+ ;; Test both forms of target type for membership in LIST.
+ ;;
+ ;; (In order to avoid having to use too much deep knowledge
+ ;; of types, it's sometimes convenient to test RAW-TARGET-TYPE
+ ;; as well as the expanded type, since we can get matches with
+ ;; just EQL. E.g. SIMPLE-STRING can be matched with EQL, while
+ ;; safely matching its expansion,
+ ;; (OR (SIMPLE-ARRAY CHARACTER (*)) (SIMPLE-BASE-STRING *))
+ ;; would require logic clever enough to know that, e.g., OR is
+ ;; commutative.)
+ (target-type-is-in (list)
+ (or (member raw-target-type list)
+ (member target-type list))))
+ (cond (;; Handle various SBCL-specific types which can't exist on
+ ;; the ANSI cross-compilation host. KLUDGE: This code will
+ ;; need to be tweaked by hand if the names of these types
+ ;; ever change, ugh!
+ (if (consp target-type)
+ (member (car target-type)
+ '(sb!alien:alien))
+ (member target-type
+ '(system-area-pointer
+ funcallable-instance
+ sb!alien-internals:alien-value)))
+ (values nil t))
+ (;; special case when TARGET-TYPE isn't a type spec, but
+ ;; instead a CLASS object.
+ (typep target-type 'class)
+ (bug "We don't support CROSS-TYPEP of CLASS type specifiers"))
+ ((and (symbolp target-type)
+ (find-classoid target-type nil)
+ (sb!xc:subtypep target-type 'cl:structure-object)
+ (typep host-object '(or symbol number list character)))
+ (values nil t))
+ ((and (symbolp target-type)
+ (find-class target-type nil)
+ (subtypep target-type 'sb!kernel::structure!object))
+ (values (typep host-object target-type) t))
+ (;; easy cases of arrays and vectors
+ (target-type-is-in
+ '(array simple-string simple-vector string vector))
+ (values (typep host-object target-type) t))
+ (;; general cases of vectors
+ (and (not (unknown-type-p (values-specifier-type target-type)))
+ (sb!xc:subtypep target-type 'cl:vector))
+ (if (vectorp host-object)
+ (warn-and-give-up) ; general-case vectors being way too hard
+ (values nil t))) ; but "obviously not a vector" being easy
+ (;; general cases of arrays
+ (and (not (unknown-type-p (values-specifier-type target-type)))
+ (sb!xc:subtypep target-type 'cl:array))
+ (if (arrayp host-object)
+ (warn-and-give-up) ; general-case arrays being way too hard
+ (values nil t))) ; but "obviously not an array" being easy
+ ((target-type-is-in '(*))
+ ;; KLUDGE: SBCL has * as an explicit wild type. While
+ ;; this is sort of logical (because (e.g. (ARRAY * 1)) is
+ ;; a valid type) it's not ANSI: looking at the ANSI
+ ;; definitions of complex types like like ARRAY shows
+ ;; that they consider * different from other type names.
+ ;; Someday we should probably get rid of this non-ANSIism
+ ;; in base SBCL, but until we do, we might as well here
+ ;; in the cross compiler. And in order to make sure that
+ ;; we don't continue doing it after we someday patch
+ ;; SBCL's type system so that * is no longer a type, we
+ ;; make this assertion. -- WHN 2001-08-08
+ (aver (typep (values-specifier-type '*) 'named-type))
+ (values t t))
+ (;; Many simple types are guaranteed to correspond exactly