X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Fknownfun.lisp;h=d80d29969fa6586dd19b26c57de7059d3095abef;hb=510a9c48b7a80bf89ee54bdbd92519e76e8e178d;hp=839ab4514bad86e71fd3382560b9eed9698eea7c;hpb=b80843eb9c1a6acb15d477f855a6f9d0f1c0b15b;p=sbcl.git diff --git a/src/compiler/knownfun.lisp b/src/compiler/knownfun.lisp index 839ab45..d80d299 100644 --- a/src/compiler/knownfun.lisp +++ b/src/compiler/knownfun.lisp @@ -64,9 +64,9 @@ ;; not be asserted when a definition is compiled. explicit-check) -(defstruct (function-info #-sb-xc-host (:pure t)) +(defstruct (fun-info #-sb-xc-host (:pure t)) ;; Boolean attributes of this function. - (attributes (required-argument) :type attributes) + (attributes (missing-arg) :type attributes) ;; A list of Transform structures describing transforms for this function. (transforms () :type list) ;; A function which computes the derived type for a call to this function by @@ -99,13 +99,9 @@ (predicate-type nil :type (or ctype null)) ;; If non-null, use this function to annotate the known call for the byte ;; compiler. If it returns NIL, then change the call to :full. - (byte-annotate nil :type (or function null)) - ;; If non-null, use this function to generate the byte code for this known - ;; call. This function can only give up if there is a byte-annotate function - ;; that arranged for the functional to be pushed onto the stack. - (byte-compile nil :type (or function null))) + (byte-annotate nil :type (or function null))) -(defprinter (function-info) +(defprinter (fun-info) (transforms :test transforms) (derive-type :test derive-type) (optimizer :test optimizer) @@ -113,28 +109,36 @@ (ir2-convert :test ir2-convert) (templates :test templates) (predicate-type :test predicate-type) - (byte-annotate :test byte-annotate) - (byte-compile :test byte-compile)) + (byte-annotate :test byte-annotate)) ;;;; interfaces to defining macros ;;; an IR1 transform (defstruct (transform (:copier nil)) - ;; the function-type which enables this transform - (type (required-argument) :type ctype) + ;; the function type which enables this transform. + ;; + ;; (Note that declaring this :TYPE FUN-TYPE probably wouldn't + ;; work because some function types, like (SPECIFIER-TYPE 'FUNCTION0 + ;; itself, are represented as BUILT-IN-TYPE, and at least as of + ;; sbcl-0.pre7.54 or so, that's inconsistent with being a + ;; FUN-TYPE.) + (type (missing-arg) :type ctype) ;; the transformation function. Takes the COMBINATION node and returns a ;; lambda, or throws out. - (function (required-argument) :type function) - ;; string used in efficency notes - (note (required-argument) :type string) + (function (missing-arg) :type function) + ;; string used in efficiency notes + (note (missing-arg) :type string) ;; T if we should emit a failure note even if SPEED=INHIBIT-WARNINGS. (important nil :type (member t nil)) - ;; usable for byte code, native code, or both + ;; usable for byte code, native code, or both? + ;; + ;; FIXME: Now that there's no byte compiler, this is stale and could + ;; all go away. (when :native :type (member :byte :native :both))) (defprinter (transform) type note important when) -;;; Grab the FUNCTION-INFO and enter the function, replacing any old +;;; Grab the FUN-INFO and enter the function, replacing any old ;;; one with the same type and note. (declaim (ftype (function (t list function &optional (or string null) (member t nil) (member :native :byte :both)) @@ -143,21 +147,22 @@ (defun %deftransform (name type fun &optional note important (when :native)) (let* ((ctype (specifier-type type)) (note (or note "optimize")) - (info (function-info-or-lose name)) + (info (fun-info-or-lose name)) (old (find-if (lambda (x) (and (type= (transform-type x) ctype) (string-equal (transform-note x) note) (eq (transform-important x) important) (eq (transform-when x) when))) - (function-info-transforms info)))) + (fun-info-transforms info)))) (if old - (setf (transform-function old) fun (transform-note old) note) + (setf (transform-function old) fun + (transform-note old) note) (push (make-transform :type ctype :function fun :note note :important important :when when) - (function-info-transforms info))) + (fun-info-transforms info))) name)) -;;; Make a FUNCTION-INFO structure with the specified type, attributes +;;; Make a FUN-INFO structure with the specified type, attributes ;;; and optimizers. (declaim (ftype (function (list list attributes &key (:derive-type (or function null)) @@ -166,42 +171,47 @@ %defknown)) (defun %defknown (names type attributes &key derive-type optimizer) (let ((ctype (specifier-type type)) - (info (make-function-info :attributes attributes + (info (make-fun-info :attributes attributes :derive-type derive-type :optimizer optimizer)) - (target-env (or *backend-info-environment* *info-environment*))) + (target-env *info-environment*)) (dolist (name names) - (when (info :function :info name) - ;; This is an error because it's generally a bad thing to blow - ;; away all the old optimization stuff. It's also a potential - ;; source of sneaky bugs: - ;; DEFKNOWN FOO - ;; DEFTRANSFORM FOO - ;; DEFKNOWN FOO ; possibly hidden inside some macroexpansion - ;; ; Now the DEFTRANSFORM doesn't exist in the target Lisp. - ;; However, it's continuable because it might be useful to do - ;; it when testing new optimization stuff interactively. - #+nil (cerror "Go ahead, overwrite it." - "overwriting old FUNCTION-INFO for ~S" name) - (warn "overwriting old FUNCTION-INFO for ~S" name)) + (let ((old-fun-info (info :function :info name))) + (when old-fun-info + ;; This is handled as an error because it's generally a bad + ;; thing to blow away all the old optimization stuff. It's + ;; also a potential source of sneaky bugs: + ;; DEFKNOWN FOO + ;; DEFTRANSFORM FOO + ;; DEFKNOWN FOO ; possibly hidden inside some macroexpansion + ;; ; Now the DEFTRANSFORM doesn't exist in the target Lisp. + ;; However, it's continuable because it might be useful to do + ;; it when testing new optimization stuff interactively. + (cerror "Go ahead, overwrite it." + "~@" + old-fun-info name))) (setf (info :function :type name target-env) ctype) (setf (info :function :where-from name target-env) :declared) (setf (info :function :kind name target-env) :function) (setf (info :function :info name target-env) info))) names) -;;; Return the FUNCTION-INFO for NAME or die trying. Since this is +;;; Return the FUN-INFO for NAME or die trying. Since this is ;;; used by callers who want to modify the info, and the info may be ;;; shared, we copy it. We don't have to copy the lists, since each ;;; function that has generators or transforms has already been ;;; through here. -(declaim (ftype (function (t) function-info) function-info-or-lose)) -(defun function-info-or-lose (name) - (let ((*info-environment* (or *backend-info-environment* - *info-environment*))) +(declaim (ftype (function (t) fun-info) fun-info-or-lose)) +(defun fun-info-or-lose (name) + (let (;; FIXME: Do we need this rebinding here? It's a literal + ;; translation of the old CMU CL rebinding to + ;; (OR *BACKEND-INFO-ENVIRONMENT* *INFO-ENVIRONMENT*), + ;; and it's not obvious whether the rebinding to itself is + ;; needed that SBCL doesn't need *BACKEND-INFO-ENVIRONMENT*. + (*info-environment* *info-environment*)) (let ((old (info :function :info name))) (unless old (error "~S is not a known function." name)) - (setf (info :function :info name) (copy-function-info old))))) + (setf (info :function :info name) (copy-fun-info old))))) ;;;; generic type inference methods @@ -229,17 +239,17 @@ ;;; argument. If arg is a list, result is a list. If arg is a vector, result ;;; is a vector with the same element type. (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))) - (if (array-type-p type) - (specifier-type - `(vector ,(type-specifier (array-type-element-type type)))) - (let ((ltype (specifier-type 'list))) - (when (csubtypep type ltype) - ltype)))))))) + (lambda (call) + (declare (type combination call)) + (let ((cont (nth (1- n) (combination-args call)))) + (when cont + (let ((type (continuation-type cont))) + (if (array-type-p type) + (specifier-type + `(vector ,(type-specifier (array-type-element-type type)))) + (let ((ltype (specifier-type 'list))) + (when (csubtypep type ltype) + ltype)))))))) ;;; Derive the type to be the type specifier which is the N'th arg. (defun result-type-specifier-nth-arg (n)