X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fcompiler%2Ftypetran.lisp;fp=src%2Fcompiler%2Ftypetran.lisp;h=aeb9a7b4b8cfe7da471c808971ca55781edfb7a3;hb=aa01df7a18a5d8747423173bda7c20eb46092514;hp=3c000d5bbebbd799d834c42ab6339026806629ab;hpb=c325337271f3d5a1a1c1b5fe2bd009d7ab31b7ac;p=sbcl.git diff --git a/src/compiler/typetran.lisp b/src/compiler/typetran.lisp index 3c000d5..aeb9a7b 100644 --- a/src/compiler/typetran.lisp +++ b/src/compiler/typetran.lisp @@ -71,32 +71,46 @@ ;;; If the lvar OBJECT definitely is or isn't of the specified ;;; type, then return T or NIL as appropriate. Otherwise quietly ;;; GIVE-UP-IR1-TRANSFORM. -(defun ir1-transform-type-predicate (object type) +(defun ir1-transform-type-predicate (object type node) (declare (type lvar object) (type ctype type)) (let ((otype (lvar-type object))) - (cond ((not (types-equal-or-intersect otype type)) - nil) - ((csubtypep otype type) - t) - ((eq type *empty-type*) - nil) - (t - (let ((intersect (type-intersection2 type otype))) - (unless intersect - (give-up-ir1-transform)) - (multiple-value-bind (constantp value) - (type-singleton-p intersect) - (if constantp - `(eql object ',value) - (give-up-ir1-transform)))))))) + (flet ((tricky () + (cond ((typep type 'alien-type-type) + ;; We don't transform alien type tests until here, because + ;; once we do that the rest of the type system can no longer + ;; reason about them properly -- so we'd miss out on type + ;; derivation, etc. + (delay-ir1-transform node :optimize) + (let ((alien-type (alien-type-type-alien-type type))) + ;; If it's a lisp-rep-type, the CTYPE should be one already. + (aver (not (compute-lisp-rep-type alien-type))) + `(sb!alien::alien-value-typep object ',alien-type))) + (t + (give-up-ir1-transform))))) + (cond ((not (types-equal-or-intersect otype type)) + nil) + ((csubtypep otype type) + t) + ((eq type *empty-type*) + nil) + (t + (let ((intersect (type-intersection2 type otype))) + (unless intersect + (tricky)) + (multiple-value-bind (constantp value) + (type-singleton-p intersect) + (if constantp + `(eql object ',value) + (tricky))))))))) ;;; Flush %TYPEP tests whose result is known at compile time. -(deftransform %typep ((object type)) +(deftransform %typep ((object type) * * :node node) (unless (constant-lvar-p type) (give-up-ir1-transform)) (ir1-transform-type-predicate object - (ir1-transform-specifier-type (lvar-value type)))) + (ir1-transform-specifier-type (lvar-value type)) + node)) ;;; This is the IR1 transform for simple type predicates. It checks ;;; whether the single argument is known to (not) be of the @@ -108,7 +122,7 @@ (basic-combination-fun node)))) *backend-predicate-types*))) (aver ctype) - (ir1-transform-type-predicate object ctype))) + (ir1-transform-type-predicate object ctype node))) ;;; If FIND-CLASSOID is called on a constant class, locate the ;;; CLASSOID-CELL at load time.