-;;; Convert a lambda doing all the basic stuff we would do if we were
-;;; converting a DEFUN. In the old CMU CL system, this was used both
-;;; by the %DEFUN translator and for global inline expansion, but
-;;; since sbcl-0.pre7.something %DEFUN does things differently.
-;;; FIXME: And now it's probably worth rethinking whether this
-;;; function is a good idea.
-;;;
-;;; Unless a :INLINE function, we temporarily clobber the inline
-;;; expansion. This prevents recursive inline expansion of
-;;; opportunistic pseudo-inlines.
-(defun ir1-convert-lambda-for-defun (lambda var expansion converter)
- (declare (cons lambda) (function converter) (type defined-fun var))
- (let ((var-expansion (defined-fun-inline-expansion var)))
- (unless (eq (defined-fun-inlinep var) :inline)
- (setf (defined-fun-inline-expansion var) nil))
- (let* ((name (leaf-source-name var))
- (fun (funcall converter lambda
- :source-name name))
- (fun-info (info :function :info name)))
- (setf (functional-inlinep fun) (defined-fun-inlinep var))
- (assert-new-definition var fun)
- (setf (defined-fun-inline-expansion var) var-expansion)
- ;; If definitely not an interpreter stub, then substitute for
- ;; any old references.
- (unless (or (eq (defined-fun-inlinep var) :notinline)
- (not *block-compile*)
- (and fun-info
- (or (fun-info-transforms fun-info)
- (fun-info-templates fun-info)
- (fun-info-ir2-convert fun-info))))
- (substitute-leaf fun var)
- ;; If in a simple environment, then we can allow backward
- ;; references to this function from following top level forms.
- (when expansion (setf (defined-fun-functional var) fun)))
- fun)))
+;;; Used for global inline expansion. Earlier something like this was
+;;; used by %DEFUN too. FIXME: And now it's probably worth rethinking
+;;; whether this function is a good idea at all.
+(defun ir1-convert-inline-expansion (name expansion var inlinep info)
+ ;; Unless a :INLINE function, we temporarily clobber the inline
+ ;; expansion. This prevents recursive inline expansion of
+ ;; opportunistic pseudo-inlines.
+ (unless (eq inlinep :inline)
+ (setf (defined-fun-inline-expansion var) nil))
+ (let ((fun (ir1-convert-inline-lambda expansion
+ :source-name name
+ ;; prevent instrumentation of
+ ;; known function expansions
+ :system-lambda (and info t))))
+ (setf (functional-inlinep fun) inlinep)
+ (assert-new-definition var fun)
+ (setf (defined-fun-inline-expansion var) expansion)
+ ;; Associate VAR with the FUN -- and in case of an optional dispatch
+ ;; with the various entry-points. This allows XREF to know where the
+ ;; inline CLAMBDA comes from.
+ (flet ((note-inlining (f)
+ (typecase f
+ (functional
+ (setf (functional-inline-expanded f) var))
+ (cons
+ ;; Delayed entry-point.
+ (if (car f)
+ (setf (functional-inline-expanded (cdr f)) var)
+ (let ((old-thunk (cdr f)))
+ (setf (cdr f) (lambda ()
+ (let ((g (funcall old-thunk)))
+ (setf (functional-inline-expanded g) var)
+ g)))))))))
+ (note-inlining fun)
+ (when (optional-dispatch-p fun)
+ (note-inlining (optional-dispatch-main-entry fun))
+ (note-inlining (optional-dispatch-more-entry fun))
+ (mapc #'note-inlining (optional-dispatch-entry-points fun))))
+ ;; substitute for any old references
+ (unless (or (not *block-compile*)
+ (and info
+ (or (fun-info-transforms info)
+ (fun-info-templates info)
+ (fun-info-ir2-convert info))))
+ (substitute-leaf fun var))
+ fun))
+
+(defun %set-inline-expansion (name defined-fun inline-lambda)
+ (cond (inline-lambda
+ (setf (info :function :inline-expansion-designator name)
+ inline-lambda)
+ (when defined-fun
+ (setf (defined-fun-inline-expansion defined-fun)
+ inline-lambda)))
+ (t
+ (clear-info :function :inline-expansion-designator name))))