X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Fir1opt.lisp;h=2dcfc4dd3a560c8145e2bd73670007e30a0e3aec;hb=ea1fd7753b7dc1277a7d250fed317300fe1e5772;hp=35720894ff38948146f6700881528b85f4ae792a;hpb=ba38798a5ca26b90647a1993f348806cb32f2d1b;p=sbcl.git diff --git a/src/compiler/ir1opt.lisp b/src/compiler/ir1opt.lisp index 3572089..2dcfc4d 100644 --- a/src/compiler/ir1opt.lisp +++ b/src/compiler/ir1opt.lisp @@ -118,6 +118,41 @@ (declaim (ftype (function (continuation) ctype) continuation-type)) (defun continuation-type (cont) (single-value-type (continuation-derived-type cont))) + +;;; If CONT is an argument of a function, return a type which the +;;; function checks CONT for. +#!-sb-fluid (declaim (inline continuation-externally-checkable-type)) +(defun continuation-externally-checkable-type (cont) + (or (continuation-%externally-checkable-type cont) + (%continuation-%externally-checkable-type cont))) +(defun %continuation-%externally-checkable-type (cont) + (declare (type continuation cont)) + (let ((dest (continuation-dest cont))) + (if (not (and dest (combination-p dest))) + ;; TODO: MV-COMBINATION + (setf (continuation-%externally-checkable-type cont) *wild-type*) + (let* ((fun (combination-fun dest)) + (args (combination-args dest)) + (fun-type (continuation-type fun))) + (if (or (not (fun-type-p fun-type)) + ;; FUN-TYPE might be (AND FUNCTION (SATISFIES ...)). + (fun-type-wild-args fun-type)) + (progn (dolist (arg args) + (setf (continuation-%externally-checkable-type arg) + *wild-type*)) + *wild-type*) + (let* ((arg-types (append (fun-type-required fun-type) + (fun-type-optional fun-type) + (let ((rest (list (or (fun-type-rest fun-type) + *wild-type*)))) + (setf (cdr rest) rest))))) + ;; TODO: &KEY + (loop + for arg of-type continuation in args + and type of-type ctype in arg-types + do (setf (continuation-%externally-checkable-type arg) + type)) + (continuation-%externally-checkable-type cont))))))) ;;;; interface routines used by optimizers @@ -441,13 +476,28 @@ (let ((info (combination-kind node))) (when (fun-info-p info) (let ((attr (fun-info-attributes info))) - (when (and (ir1-attributep attr flushable) + (when (and (not (ir1-attributep attr call)) ;; ### For now, don't delete potentially ;; flushable calls when they have the CALL ;; attribute. Someday we should look at the ;; functional args to determine if they have ;; any side effects. - (not (ir1-attributep attr call))) + (if (policy node (= safety 3)) + (and (ir1-attributep attr flushable) + (every (lambda (arg) + ;; FIXME: when bug 203 + ;; will be fixed, remove + ;; this check + (member (continuation-type-check arg) + '(nil :deleted))) + (basic-combination-args node)) + (valid-fun-use node + (info :function :type + (leaf-source-name (ref-leaf (continuation-use (basic-combination-fun node))))) + :result-test #'always-subtypep + :lossage-fun nil + :unwinnage-fun nil)) + (ir1-attributep attr unsafely-flushable))) (flush-dest (combination-fun node)) (dolist (arg (combination-args node)) (flush-dest arg)) @@ -615,6 +665,7 @@ (new-block (continuation-starts-block new-cont))) (link-node-to-previous-continuation new-node new-cont) (setf (continuation-dest new-cont) new-node) + (setf (continuation-%externally-checkable-type new-cont) nil) (add-continuation-use new-node dummy-cont) (setf (block-last new-block) new-node) @@ -935,31 +986,31 @@ (continuation-use (basic-combination-fun call)) call)) ((not leaf)) - ((or (info :function :source-transform (leaf-source-name leaf)) - (and info - (ir1-attributep (fun-info-attributes info) - predicate) - (let ((dest (continuation-dest (node-cont call)))) - (and dest (not (if-p dest)))))) - (when (and (leaf-has-source-name-p leaf) - ;; FIXME: This SYMBOLP is part of a literal - ;; translation of a test in the old CMU CL - ;; source, and it's not quite clear what - ;; the old source meant. Did it mean "has a - ;; valid name"? Or did it mean "is an - ;; ordinary function name, not a SETF - ;; function"? Either way, the old CMU CL - ;; code probably didn't deal with SETF - ;; functions correctly, and neither does - ;; this new SBCL code, and that should be fixed. - (symbolp (leaf-source-name leaf))) - (let ((dummies (make-gensym-list (length - (combination-args call))))) - (transform-call call - `(lambda ,dummies - (,(leaf-source-name leaf) - ,@dummies)) - (leaf-source-name leaf)))))))))) + ((and (leaf-has-source-name-p leaf) + (or (info :function :source-transform (leaf-source-name leaf)) + (and info + (ir1-attributep (fun-info-attributes info) + predicate) + (let ((dest (continuation-dest (node-cont call)))) + (and dest (not (if-p dest))))))) + ;; FIXME: This SYMBOLP is part of a literal + ;; translation of a test in the old CMU CL + ;; source, and it's not quite clear what + ;; the old source meant. Did it mean "has a + ;; valid name"? Or did it mean "is an + ;; ordinary function name, not a SETF + ;; function"? Either way, the old CMU CL + ;; code probably didn't deal with SETF + ;; functions correctly, and neither does + ;; this new SBCL code, and that should be fixed. + (when (symbolp (leaf-source-name leaf)) + (let ((dummies (make-gensym-list + (length (combination-args call))))) + (transform-call call + `(lambda ,dummies + (,(leaf-source-name leaf) + ,@dummies)) + (leaf-source-name leaf)))))))))) (values)) ;;;; known function optimization @@ -1137,7 +1188,42 @@ (let ((args (mapcar #'continuation-value (combination-args call))) (fun-name (combination-fun-source-name call))) (multiple-value-bind (values win) - (careful-call fun-name args call "constant folding") + (careful-call fun-name + args + call + ;; Note: CMU CL had COMPILER-WARN here, and that + ;; seems more natural, but it's probably not. + ;; + ;; It's especially not while bug 173 exists: + ;; Expressions like + ;; (COND (END + ;; (UNLESS (OR UNSAFE? (<= END SIZE))) + ;; ...)) + ;; can cause constant-folding TYPE-ERRORs (in + ;; #'<=) when END can be proved to be NIL, even + ;; though the code is perfectly legal and safe + ;; because a NIL value of END means that the + ;; #'<= will never be executed. + ;; + ;; Moreover, even without bug 173, + ;; quite-possibly-valid code like + ;; (COND ((NONINLINED-PREDICATE END) + ;; (UNLESS (<= END SIZE)) + ;; ...)) + ;; (where NONINLINED-PREDICATE is something the + ;; compiler can't do at compile time, but which + ;; turns out to make the #'<= expression + ;; unreachable when END=NIL) could cause errors + ;; when the compiler tries to constant-fold (<= + ;; END SIZE). + ;; + ;; So, with or without bug 173, it'd be + ;; unnecessarily evil to do a full + ;; COMPILER-WARNING (and thus return FAILURE-P=T + ;; from COMPILE-FILE) for legal code, so we we + ;; use a wimpier COMPILE-STYLE-WARNING instead. + #'compiler-style-warn + "constant folding") (if (not win) (setf (combination-kind call) :error) (let ((dummies (make-gensym-list (length args)))) @@ -1193,7 +1279,7 @@ (derive-node-type node (continuation-type (set-value node))) (values)) -;;; Return true if the value of Ref will always be the same (and is +;;; Return true if the value of REF will always be the same (and is ;;; thus legal to substitute.) (defun constant-reference-p (ref) (declare (type ref ref)) @@ -1568,7 +1654,8 @@ (flush-dest (combination-fun use)) (let ((fun-cont (basic-combination-fun call))) (setf (continuation-dest fun-cont) use) - (setf (combination-fun use) fun-cont)) + (setf (combination-fun use) fun-cont) + (setf (continuation-%externally-checkable-type fun-cont) nil)) (setf (combination-kind use) :local) (setf (functional-kind fun) :let) (flush-dest (first (basic-combination-args call))) @@ -1598,7 +1685,8 @@ (setf (combination-kind node) :full) (let ((args (combination-args use))) (dolist (arg args) - (setf (continuation-dest arg) node)) + (setf (continuation-dest arg) node) + (setf (continuation-%externally-checkable-type arg) nil)) (setf (combination-args use) nil) (flush-dest list) (setf (combination-args node) args))