From b29f6c2670c6e9f71c466004a55073f03df94037 Mon Sep 17 00:00:00 2001 From: Douglas Katzman Date: Thu, 5 May 2016 19:40:29 -0400 Subject: [PATCH] Merge two nearly identical functions. --- src/code/coerce.lisp | 1 + src/code/fdefinition.lisp | 12 +++++++++--- src/interpreter/sexpr.lisp | 14 +------------- src/interpreter/special-forms.lisp | 2 +- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/code/coerce.lisp b/src/code/coerce.lisp index 4b7b191e3..8c40c31e0 100644 --- a/src/code/coerce.lisp +++ b/src/code/coerce.lisp @@ -65,6 +65,7 @@ ;; [Also note, we won't encapsulate a macro or special-form, so this ;; introspective technique to decide what kind something is works either way] (let ((def (fdefinition symbol))) + (declare (notinline macro/special-guard-fun-p)) ; not performance-critical (if (macro/special-guard-fun-p def) (error (ecase (car (%fun-name def)) (:macro "~S names a macro.") diff --git a/src/code/fdefinition.lisp b/src/code/fdefinition.lisp index 845d32e7f..4e0bd9686 100644 --- a/src/code/fdefinition.lisp +++ b/src/code/fdefinition.lisp @@ -290,18 +290,24 @@ ;; whether FUNCTION is the same closure as for a known macro. ;; For cold-init to work, this must pick any macro defined before ;; this function is. A safe choice is a macro from this same file. +(declaim (inline macro/special-guard-fun-p)) (defun macro/special-guard-fun-p (function) - (and (closurep function) + ;; When inlined, this is a few instructions shorter than CLOSUREP + ;; if we already know that FUNCTION is a function. + ;; It will signal a type error if not, which is the right thing to do anyway. + ;; (this isn't quite a true predicate) + (and (= (fun-subtype function) sb!vm:closure-header-widetag) ;; Prior to cold-init fixing up the load-time-value, this compares ;; %closure-fun to 0, which is ok - it returns NIL. - (eq (load-time-value - (%closure-fun (symbol-function '%coerce-name-to-fun)) t) + (eq (load-time-value (%closure-fun (macro-function '%coerce-name-to-fun)) + t) (%closure-fun function)))) ;; Reject any "object of implementation-dependent nature" that ;; so happens to be a function in SBCL, but which must not be ;; bound to a function-name by way of (SETF FEDFINITION). (defun err-if-unacceptable-function (object setter) + (declare (notinline macro/special-guard-fun-p)) ; not performance-critical (when (macro/special-guard-fun-p object) (error 'simple-reference-error :references (list '(:ansi-cl :function fdefinition)) diff --git a/src/interpreter/sexpr.lisp b/src/interpreter/sexpr.lisp index 6a95dc078..1a7cf0181 100644 --- a/src/interpreter/sexpr.lisp +++ b/src/interpreter/sexpr.lisp @@ -874,18 +874,6 @@ Test case. (get-thinginator) ; errs - it correctly perceives the redefinition |# -;;; Figure out if F is supposed to be funcallable, versus is the error trampoline -;;; that is installed in a global macro's fdefn object. It is very efficient -;;; to do this by seeing if F is a closure over the error trampoline, versus asking -;;; the horribly slow globaldb if F's name's macro-function is NIL. -;;; In the common case where F isn't a closure, it definitely isn't a macro. -(declaim (inline %looks-like-macro-p)) -(defun %looks-like-macro-p (f) ; f is a FUNCTION - (and (= (fun-subtype (truly-the function f)) sb-vm:closure-header-widetag) - ;; compare to a known global macro - (eq (load-time-value (%closure-fun (symbol-function 'or)) t) - (%closure-fun f)))) - ;;; Return T if SYMBOL might get redefined as a macro when it was previously ;;; a function and vice versa. Extra checks are done on every use of the symbol ;;; as a function name. @@ -1108,7 +1096,7 @@ Test case. (if (allow-macro-redefinition env) (macrolet ((re-expand-p () '(let ((f (fdefn-fun fdefn))) - (and f (%looks-like-macro-p f))))) + (and f (sb-impl::macro/special-guard-fun-p f))))) (generate-switch)) (macrolet ((re-expand-p () nil)) (generate-switch))))) diff --git a/src/interpreter/special-forms.lisp b/src/interpreter/special-forms.lisp index aaf131fb9..403ce7187 100644 --- a/src/interpreter/special-forms.lisp +++ b/src/interpreter/special-forms.lisp @@ -1166,7 +1166,7 @@ (hlambda FUNCTION (fdefn) (env) (declare (ignore env)) (let ((fun (sb-c:safe-fdefn-fun fdefn))) - (if (%looks-like-macro-p fun) + (if (sb-impl::macro/special-guard-fun-p fun) (not-a-function (fdefn-name fdefn)) fun))) (hlambda FUNCTION (fdefn) (env) ; could not be a macro -- 2.11.4.GIT