1.0.47.15: %FUNCALL IR1 translator macroexpands the function form
authorNikodemus Siivola <nikodemus@random-state.net>
Fri, 8 Apr 2011 13:02:26 +0000 (13:02 +0000)
committerNikodemus Siivola <nikodemus@random-state.net>
Fri, 8 Apr 2011 13:02:26 +0000 (13:02 +0000)
  Code compiled correctly without this, but added an unnecessary cast
  to FUNCTION for the lambda in

    (FUNCALL (LAMBDA ...) ...)

  forms, which prevented local-call conversion and inlining for the
  lambda. Note:

    (FUNCALL (FUNCTION (LAMBDA ...)) ...)

  forms did not suffer from this.

  Step on the way to fixing lp#720382.

NEWS
src/compiler/ir1-translators.lisp
tests/compiler.pure.lisp
version.lisp-expr

diff --git a/NEWS b/NEWS
index 135f26a..6092a89 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,8 @@ changes relative to sbcl-1.0.47:
   * optimization: slightly faster ISQRT. (lp#713343)
   * bug fix: TRACE behaves better when attempting to trace undefined
     functions. (lp#740717)
+  * bug fix: missed optimizations for (FUNCALL (LAMBDA ...) ...) in
+    comparison to (FUNCALL #'(LAMBDA ...) ...).
 
 changes in sbcl-1.0.47 relative to sbcl-1.0.46:
   * bug fix: fix mach port rights leaks in mach exception handling code on
index 238d04e..79c2afc 100644 (file)
@@ -590,7 +590,10 @@ be a lambda expression."
        `(%funcall ,(ensure-lvar-fun-form function 'function) ,@arg-names))))
 
 (def-ir1-translator %funcall ((function &rest args) start next result)
-  (let ((op (when (consp function) (car function))))
+  ;; MACROEXPAND so that (LAMBDA ...) forms arriving here don't get an
+  ;; extra cast inserted for them.
+  (let* ((function (sb!xc:macroexpand function *lexenv*))
+         (op (when (consp function) (car function))))
     (cond ((eq op 'function)
            (with-fun-name-leaf (leaf (second function) start)
              (ir1-convert start next result `(,leaf ,@args))))
index bd70465..77fa813 100644 (file)
                                s)))
                       (g a)))))
 
+(with-test (:name :funcall-lambda-inlined)
+  (assert (not
+           (ctu:find-code-constants
+            (compile nil
+                     `(lambda (x y)
+                        (+ x (funcall (lambda (z) z) y))))
+            :type 'function))))
+
 ;;; This doesn't test LVAR-FUN-IS directly, but captures it
 ;;; pretty accurately anyways.
 (with-test (:name :lvar-fun-is)
index f174645..25c1fbd 100644 (file)
@@ -20,4 +20,4 @@
 ;;; checkins which aren't released. (And occasionally for internal
 ;;; versions, especially for internal versions off the main CVS
 ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"1.0.47.14"
+"1.0.47.15"