X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Fknownfun.lisp;h=640b393a5ab533e33ddb19ade592a632e282b5fa;hb=57e21c4b62e8c1a1ee7ef59ed2abb0c864fb06bc;hp=e47a03a643d8492c1ee93f09d24777b002d934e7;hpb=942e5de3f3e27e1cc6ae4aae69c040fa1dc7db00;p=sbcl.git diff --git a/src/compiler/knownfun.lisp b/src/compiler/knownfun.lisp index e47a03a..640b393 100644 --- a/src/compiler/knownfun.lisp +++ b/src/compiler/knownfun.lisp @@ -63,6 +63,9 @@ unsafely-flushable ;; may be moved with impunity. Has no side effects except possibly ;; consing, and is affected only by its arguments. + ;; + ;; Since it is not used now, its distribution in fndb.lisp is + ;; mere random; use with caution. movable ;; The function is a true predicate likely to be open-coded. Convert ;; any non-conditional uses into (IF T NIL). Not usually @@ -116,6 +119,8 @@ (predicate-type nil :type (or ctype null))) (defprinter (fun-info) + (attributes :test (not (zerop attributes)) + :prin1 (decode-ir1-attributes attributes)) (transforms :test transforms) (derive-type :test derive-type) (optimizer :test optimizer) @@ -161,12 +166,14 @@ (string-equal (transform-note x) note) (eq (transform-important x) important))) (fun-info-transforms info)))) - (if old - (setf (transform-function old) fun - (transform-note old) note) - (push (make-transform :type ctype :function fun :note note - :important important) - (fun-info-transforms info))) + (cond (old + (style-warn "Overwriting ~S" old) + (setf (transform-function old) fun + (transform-note old) note)) + (t + (push (make-transform :type ctype :function fun :note note + :important important) + (fun-info-transforms info)))) name)) ;;; Make a FUN-INFO structure with the specified type, attributes @@ -226,12 +233,12 @@ ;;; only be done when the result value is that argument. (defun result-type-first-arg (call) (declare (type combination call)) - (let ((cont (first (combination-args call)))) - (when cont (continuation-type cont)))) + (let ((lvar (first (combination-args call)))) + (when lvar (lvar-type lvar)))) (defun result-type-last-arg (call) (declare (type combination call)) - (let ((cont (car (last (combination-args call))))) - (when cont (continuation-type cont)))) + (let ((lvar (car (last (combination-args call))))) + (when lvar (lvar-type lvar)))) ;;; Derive the result type according to the float contagion rules, but ;;; always return a float. This is used for irrational functions that @@ -239,7 +246,7 @@ (defun result-type-float-contagion (call) (declare (type combination call)) (reduce #'numeric-contagion (combination-args call) - :key #'continuation-type + :key #'lvar-type :initial-value (specifier-type 'single-float))) ;;; Return a closure usable as a derive-type method for accessing the @@ -248,9 +255,9 @@ (defun sequence-result-nth-arg (n) (lambda (call) (declare (type combination call)) - (let ((cont (nth (1- n) (combination-args call)))) - (when cont - (let ((type (continuation-type cont))) + (let ((lvar (nth (1- n) (combination-args call)))) + (when lvar + (let ((type (lvar-type lvar))) (if (array-type-p type) (specifier-type `(vector ,(type-specifier (array-type-element-type type)))) @@ -258,12 +265,52 @@ (when (csubtypep type ltype) ltype)))))))) -;;; Derive the type to be the type specifier which is the N'th arg. +;;; Derive the type to be the type specifier which is the Nth arg. (defun result-type-specifier-nth-arg (n) (lambda (call) (declare (type combination call)) - (let ((cont (nth (1- n) (combination-args call)))) - (when (and cont (constant-continuation-p cont)) - (careful-specifier-type (continuation-value cont)))))) + (let ((lvar (nth (1- n) (combination-args call)))) + (when (and lvar (constant-lvar-p lvar)) + (careful-specifier-type (lvar-value lvar)))))) + +;;; Derive the type to be the type specifier which is the Nth arg, +;;; with the additional restriptions noted in the CLHS for STRING and +;;; SIMPLE-STRING, defined to specialize on CHARACTER, and for VECTOR +;;; (under the page for MAKE-SEQUENCE). +(defun creation-result-type-specifier-nth-arg (n) + (lambda (call) + (declare (type combination call)) + (let ((lvar (nth (1- n) (combination-args call)))) + (when (and lvar (constant-lvar-p lvar)) + (let* ((specifier (lvar-value lvar)) + (lspecifier (if (atom specifier) (list specifier) specifier))) + (cond + ((eq (car lspecifier) 'string) + (destructuring-bind (string &rest size) + lspecifier + (declare (ignore string)) + (careful-specifier-type + `(vector character ,@(when size size))))) + ((eq (car lspecifier) 'simple-string) + (destructuring-bind (simple-string &rest size) + lspecifier + (declare (ignore simple-string)) + (careful-specifier-type + `(simple-array character ,@(if size (list size) '((*))))))) + (t + (let ((ctype (careful-specifier-type specifier))) + (if (and (array-type-p ctype) + (eq (array-type-specialized-element-type ctype) + *wild-type*)) + ;; I don't think I'm allowed to modify what I get + ;; back from SPECIFIER-TYPE; it is, after all, + ;; cached. Better copy it, then. + (let ((real-ctype (copy-structure ctype))) + (setf (array-type-element-type real-ctype) + *universal-type* + (array-type-specialized-element-type real-ctype) + *universal-type*) + real-ctype) + ctype))))))))) (/show0 "knownfun.lisp end of file")