0.8.9.10:
[sbcl.git] / src / compiler / ir1tran-lambda.lisp
index 5a74c2b..3fcf355 100644 (file)
@@ -24,7 +24,7 @@
 ;;; If it is losing, we punt with a COMPILER-ERROR. NAMES-SO-FAR is a
 ;;; list of names which have previously been bound. If the NAME is in
 ;;; this list, then we error out.
-(declaim (ftype (function (t list) lambda-var) varify-lambda-arg))
+(declaim (ftype (sfunction (t list) lambda-var) varify-lambda-arg))
 (defun varify-lambda-arg (name names-so-far)
   (declare (inline member))
   (unless (symbolp name)
@@ -47,7 +47,7 @@
 
 ;;; Make the default keyword for a &KEY arg, checking that the keyword
 ;;; isn't already used by one of the VARS.
-(declaim (ftype (function (symbol list t) keyword) make-keyword-for-arg))
+(declaim (ftype (sfunction (symbol list t) symbol) make-keyword-for-arg))
 (defun make-keyword-for-arg (symbol vars keywordify)
   (let ((key (if (and keywordify (not (keywordp symbol)))
                 (keywordicate symbol)
@@ -74,7 +74,7 @@
 ;;;  3. a flag indicating whether other &KEY args are allowed;
 ;;;  4. a list of the &AUX variables; and
 ;;;  5. a list of the &AUX values.
-(declaim (ftype (function (list) (values list boolean boolean list list))
+(declaim (ftype (sfunction (list) (values list boolean boolean list list))
                make-lambda-vars))
 (defun make-lambda-vars (list)
   (multiple-value-bind (required optional restp rest keyp keys allowp auxp aux
 ;;; FIXME: This could and probably should be converted to use
 ;;; SOURCE-NAME and DEBUG-NAME. But I (WHN) don't use &AUX bindings,
 ;;; so I'm not motivated. Patches will be accepted...
-(defun ir1-convert-aux-bindings (start cont body aux-vars aux-vals)
-  (declare (type continuation start cont) (list body aux-vars aux-vals))
+(defun ir1-convert-aux-bindings (start next result body aux-vars aux-vals)
+  (declare (type ctran start next) (type (or lvar null) result)
+           (list body aux-vars aux-vals))
   (if (null aux-vars)
-      (ir1-convert-progn-body start cont body)
-      (let ((fun-cont (make-continuation))
+      (ir1-convert-progn-body start next result body)
+      (let ((ctran (make-ctran))
+            (fun-lvar (make-lvar))
            (fun (ir1-convert-lambda-body body
                                          (list (first aux-vars))
                                          :aux-vars (rest aux-vars)
                                          :debug-name (debug-namify
                                                       "&AUX bindings ~S"
                                                       aux-vars))))
-       (reference-leaf start fun-cont fun)
-       (ir1-convert-combination-args fun-cont cont
+       (reference-leaf start ctran fun-lvar fun)
+       (ir1-convert-combination-args fun-lvar ctran next result
                                      (list (first aux-vals)))))
   (values))
 
 ;;; the body, otherwise we do one special binding and recurse on the
 ;;; rest.
 ;;;
-;;; We make a cleanup and introduce it into the lexical environment.
-;;; If there are multiple special bindings, the cleanup for the blocks
-;;; will end up being the innermost one. We force CONT to start a
-;;; block outside of this cleanup, causing cleanup code to be emitted
-;;; when the scope is exited.
-(defun ir1-convert-special-bindings (start cont body aux-vars aux-vals svars)
-  (declare (type continuation start cont)
+;;; We make a cleanup and introduce it into the lexical
+;;; environment. If there are multiple special bindings, the cleanup
+;;; for the blocks will end up being the innermost one. We force NEXT
+;;; to start a block outside of this cleanup, causing cleanup code to
+;;; be emitted when the scope is exited.
+(defun ir1-convert-special-bindings
+    (start next result body aux-vars aux-vals svars)
+  (declare (type ctran start next) (type (or lvar null) result)
           (list body aux-vars aux-vals svars))
   (cond
    ((null svars)
-    (ir1-convert-aux-bindings start cont body aux-vars aux-vals))
+    (ir1-convert-aux-bindings start next result body aux-vars aux-vals))
    (t
-    (continuation-starts-block cont)
+    (ctran-starts-block next)
     (let ((cleanup (make-cleanup :kind :special-bind))
          (var (first svars))
-         (next-cont (make-continuation))
-         (nnext-cont (make-continuation)))
-      (ir1-convert start next-cont
+         (bind-ctran (make-ctran))
+         (cleanup-ctran (make-ctran)))
+      (ir1-convert start bind-ctran nil
                   `(%special-bind ',(lambda-var-specvar var) ,var))
-      (setf (cleanup-mess-up cleanup) (continuation-use next-cont))
+      (setf (cleanup-mess-up cleanup) (ctran-use bind-ctran))
       (let ((*lexenv* (make-lexenv :cleanup cleanup)))
-       (ir1-convert next-cont nnext-cont '(%cleanup-point))
-       (ir1-convert-special-bindings nnext-cont cont body aux-vars aux-vals
+       (ir1-convert bind-ctran cleanup-ctran nil '(%cleanup-point))
+       (ir1-convert-special-bindings cleanup-ctran next result
+                                      body aux-vars aux-vals
                                      (rest svars))))))
   (values))
 
+;;; FIXME: this is the interface of the CMUCL WITH-DYNAMIC-EXTENT
+;;; macro.  It is slightly confusing, in that START and BODY-START are
+;;; already-existing CTRANs (and FIXME: probably deserve a ONCE-ONLY),
+;;; whereas NEXT is a variable naming a CTRAN in the body.  -- CSR,
+;;; 2004-03-30.
+(defmacro with-dynamic-extent ((start body-start next kind) &body body)
+  (with-unique-names (cleanup next-ctran)
+    `(progn
+      (ctran-starts-block ,body-start)
+      (let ((,cleanup (make-cleanup :kind :dynamic-extent))
+           (,next-ctran (make-ctran))
+           (,next (make-ctran)))
+       (ir1-convert ,start ,next-ctran nil '(%dynamic-extent-start))
+       (setf (cleanup-mess-up ,cleanup) (ctran-use ,next-ctran))
+       (let ((*lexenv* (make-lexenv :cleanup ,cleanup)))
+         (ir1-convert ,next-ctran ,next nil '(%cleanup-point))
+         (locally ,@body))))))
+
 ;;; Create a lambda node out of some code, returning the result. The
 ;;; bindings are specified by the list of VAR structures VARS. We deal
 ;;; with adding the names to the LEXENV-VARS for the conversion. The
 ;;; the special binding code.
 ;;;
 ;;; We ignore any ARG-INFO in the VARS, trusting that someone else is
-;;; dealing with &nonsense.
+;;; dealing with &NONSENSE, except for &REST vars with DYNAMIC-EXTENT.
 ;;;
 ;;; AUX-VARS is a list of VAR structures for variables that are to be
 ;;; sequentially bound. Each AUX-VAL is a form that is to be evaluated
-;;; to get the initial value for the corresponding AUX-VAR. 
+;;; to get the initial value for the corresponding AUX-VAR.
 (defun ir1-convert-lambda-body (body
                                vars
                                &key
                                aux-vars
                                aux-vals
-                               result
                                (source-name '.anonymous.)
                                debug-name
                                 (note-lexical-bindings t))
-  (declare (list body vars aux-vars aux-vals)
-          (type (or continuation null) result))
+  (declare (list body vars aux-vars aux-vals))
 
   ;; We're about to try to put new blocks into *CURRENT-COMPONENT*.
   (aver-live-component *current-component*)
 
   (let* ((bind (make-bind))
         (lambda (make-lambda :vars vars
-                             :bind bind
-                             :%source-name source-name
-                             :%debug-name debug-name))
-        (result (or result (make-continuation))))
+                  :bind bind
+                  :%source-name source-name
+                  :%debug-name debug-name))
+        (result-ctran (make-ctran))
+         (result-lvar (make-lvar))
+        (dx-rest nil))
 
-    (continuation-starts-block result)
+    (awhen (lexenv-lambda *lexenv*)
+      (push lambda (lambda-children it))
+      (setf (lambda-parent lambda) it))
 
     ;; just to check: This function should fail internal assertions if
     ;; we didn't set up a valid debug name above.
 
     (setf (lambda-home lambda) lambda)
     (collect ((svars)
-             (new-venv nil cons))
+              (new-venv nil cons))
 
       (dolist (var vars)
        ;; As far as I can see, LAMBDA-VAR-HOME should never have
        ;; been set before. Let's make sure. -- WHN 2001-09-29
-       (aver (null (lambda-var-home var)))
+       (aver (not (lambda-var-home var)))
        (setf (lambda-var-home var) lambda)
        (let ((specvar (lambda-var-specvar var)))
          (cond (specvar
                (t
                  (when note-lexical-bindings
                    (note-lexical-binding (leaf-source-name var)))
-                (new-venv (cons (leaf-source-name var) var))))))
+                (new-venv (cons (leaf-source-name var) var)))))
+       (let ((info (lambda-var-arg-info var)))
+         (when (and info
+                    (eq (arg-info-kind info) :rest)
+                    (leaf-dynamic-extent var))
+           (setq dx-rest t))))
 
       (let ((*lexenv* (make-lexenv :vars (new-venv)
                                   :lambda lambda
        (setf (bind-lambda bind) lambda)
        (setf (node-lexenv bind) *lexenv*)
 
-       (let ((cont1 (make-continuation))
-             (cont2 (make-continuation)))
-         (continuation-starts-block cont1)
-         (link-node-to-previous-continuation bind cont1)
-         (use-continuation bind cont2)
-         (ir1-convert-special-bindings cont2 result body
-                                       aux-vars aux-vals (svars)))
-
-       (let ((block (continuation-block result)))
-         (when block
-           (let ((return (make-return :result result :lambda lambda))
-                 (tail-set (make-tail-set :funs (list lambda)))
-                 (dummy (make-continuation)))
-             (setf (lambda-tail-set lambda) tail-set)
-             (setf (lambda-return lambda) return)
-             (setf (continuation-dest result) return)
-              (flush-continuation-externally-checkable-type result)
-             (setf (block-last block) return)
-             (link-node-to-previous-continuation return result)
-             (use-continuation return dummy))
-           (link-blocks block (component-tail *current-component*))))))
+       (let ((block (ctran-starts-block result-ctran)))
+         (let ((return (make-return :result result-lvar :lambda lambda))
+                (tail-set (make-tail-set :funs (list lambda))))
+            (setf (lambda-tail-set lambda) tail-set)
+            (setf (lambda-return lambda) return)
+            (setf (lvar-dest result-lvar) return)
+            (link-node-to-previous-ctran return result-ctran)
+            (setf (block-last block) return))
+          (link-blocks block (component-tail *current-component*)))
+
+        (with-component-last-block (*current-component*
+                                    (ctran-block result-ctran))
+          (let ((prebind-ctran (make-ctran))
+                (postbind-ctran (make-ctran)))
+            (ctran-starts-block prebind-ctran)
+            (link-node-to-previous-ctran bind prebind-ctran)
+            (use-ctran bind postbind-ctran)
+           (if dx-rest
+               (with-dynamic-extent (postbind-ctran result-ctran dx :rest)
+                 (ir1-convert-special-bindings dx result-ctran result-lvar
+                                               body aux-vars aux-vals
+                                               (svars)))
+               (ir1-convert-special-bindings postbind-ctran result-ctran
+                                             result-lvar body
+                                             aux-vars aux-vals (svars)))))))
 
     (link-blocks (component-head *current-component*) (node-block bind))
     (push lambda (component-new-functionals *current-component*))
 
     lambda))
 
+;;; Entry point CLAMBDAs have a special kind
+(defun register-entry-point (entry dispatcher)
+  (declare (type clambda entry)
+           (type optional-dispatch dispatcher))
+  (setf (functional-kind entry) :optional)
+  (setf (leaf-ever-used entry) t)
+  (setf (lambda-optional-dispatch entry) dispatcher)
+  entry)
+
 ;;; Create the actual entry-point function for an optional entry
 ;;; point. The lambda binds copies of each of the VARS, then calls FUN
 ;;; with the argument VALS and the DEFAULTS. Presumably the VALS refer
-;;; to the VARS by name. The VALS are passed in in reverse order.
+;;; to the VARS by name. The VALS are passed in the reverse order.
 ;;;
 ;;; If any of the copies of the vars are referenced more than once,
 ;;; then we mark the corresponding var as EVER-USED to inhibit
                                                        ,@(reverse vals)
                                                        ,@(default-vals))))
                                          arg-vars
-                                         :debug-name "&OPTIONAL processor"
+                                         :debug-name
+                                         (debug-namify "&OPTIONAL processor ~D"
+                                                       (random 100))
                                          :note-lexical-bindings nil))))
     (mapc (lambda (var arg-var)
            (when (cdr (leaf-refs arg-var))
 ;;; var, then we add it into the default vars and throw a T into the
 ;;; entry values. The resulting entry point function is returned.
 (defun generate-optional-default-entry (res default-vars default-vals
-                                           entry-vars entry-vals
-                                           vars supplied-p-p body
-                                           aux-vars aux-vals cont
-                                           source-name debug-name)
+                                        entry-vars entry-vals
+                                        vars supplied-p-p body
+                                        aux-vars aux-vals
+                                        source-name debug-name
+                                        force)
   (declare (type optional-dispatch res)
           (list default-vars default-vals entry-vars entry-vals vars body
-                aux-vars aux-vals)
-          (type (or continuation null) cont))
+                aux-vars aux-vals))
   (let* ((arg (first vars))
         (arg-name (leaf-source-name arg))
         (info (lambda-var-arg-info arg))
-        (supplied-p (arg-info-supplied-p info))
+        (default (arg-info-default info))
+         (supplied-p (arg-info-supplied-p info))
+         (force (or force
+                    (not (sb!xc:constantp (arg-info-default info)))))
         (ep (if supplied-p
                 (ir1-convert-hairy-args
                  res
                  (list* (leaf-source-name supplied-p) arg-name default-vals)
                  (cons arg entry-vars)
                  (list* t arg-name entry-vals)
-                 (rest vars) t body aux-vars aux-vals cont
-                 source-name debug-name)
+                 (rest vars) t body aux-vars aux-vals
+                 source-name debug-name
+                  force)
                 (ir1-convert-hairy-args
                  res
                  (cons arg default-vars)
                  (cons arg-name default-vals)
                  (cons arg entry-vars)
                  (cons arg-name entry-vals)
-                 (rest vars) supplied-p-p body aux-vars aux-vals cont
-                 source-name debug-name))))
-
-    (convert-optional-entry ep default-vars default-vals
-                           (if supplied-p
-                               (list (arg-info-default info) nil)
-                               (list (arg-info-default info))))))
+                 (rest vars) supplied-p-p body aux-vars aux-vals
+                 source-name debug-name
+                  force))))
+
+    ;; We want to delay converting the entry, but there exist
+    ;; problems: hidden references should not be established to
+    ;; lambdas of kind NIL should not have (otherwise the compiler
+    ;; might let-convert or delete them) and to variables.
+    (if (or force
+            supplied-p-p ; this entry will be of kind NIL
+            (and (lambda-p ep) (eq (lambda-kind ep) nil)))
+        (convert-optional-entry ep
+                                default-vars default-vals
+                                (if supplied-p
+                                    (list default nil)
+                                    (list default)))
+        (delay
+         (register-entry-point
+           (convert-optional-entry (force ep)
+                                   default-vars default-vals
+                                   (if supplied-p
+                                       (list default nil)
+                                       (list default)))
+           res)))))
 
 ;;; Create the MORE-ENTRY function for the OPTIONAL-DISPATCH RES.
 ;;; ENTRY-VARS and ENTRY-VALS describe the fixed arguments. REST is
       (arg-vars context-temp count-temp)
 
       (when rest
-       (arg-vals `(%listify-rest-args ,n-context ,n-count)))
+       (arg-vals `(%listify-rest-args
+                   ,n-context ,n-count ,(leaf-dynamic-extent rest))))
       (when morep
        (arg-vals n-context)
        (arg-vals n-count))
                 (arg-vars)
                 :debug-name (debug-namify "~S processing" '&more)
                  :note-lexical-bindings nil)))
-       (setf (optional-dispatch-more-entry res) ep))))
+       (setf (optional-dispatch-more-entry res)
+              (register-entry-point ep res)))))
 
   (values))
 
 ;;; type when computing the type for the main entry's argument.
 (defun ir1-convert-more (res default-vars default-vals entry-vars entry-vals
                             rest more-context more-count keys supplied-p-p
-                            body aux-vars aux-vals cont
+                            body aux-vars aux-vals
                             source-name debug-name)
   (declare (type optional-dispatch res)
           (list default-vars default-vals entry-vars entry-vals keys body
-                aux-vars aux-vals)
-          (type (or continuation null) cont))
+                aux-vars aux-vals))
   (collect ((main-vars (reverse default-vars))
            (main-vals default-vals cons)
            (bind-vars)
                        body (main-vars)
                        :aux-vars (append (bind-vars) aux-vars)
                        :aux-vals (append (bind-vals) aux-vals)
-                       :result cont
                        :debug-name (debug-namify "varargs entry for ~A"
                                                  (as-debug-name source-name
                                                                 debug-name))))
           (last-entry (convert-optional-entry main-entry default-vars
                                               (main-vals) ())))
-      (setf (optional-dispatch-main-entry res) main-entry)
+      (setf (optional-dispatch-main-entry res)
+            (register-entry-point main-entry res))
       (convert-more-entry res entry-vars entry-vals rest more-context keys)
 
-      (push (if supplied-p-p
+      (push (register-entry-point
+             (if supplied-p-p
                (convert-optional-entry last-entry entry-vars entry-vals ())
                last-entry)
+             res)
            (optional-dispatch-entry-points res))
       last-entry)))
 
 ;;; When we run into a &REST or &KEY arg, we punt out to
 ;;; IR1-CONVERT-MORE, which finishes for us in this case.
 (defun ir1-convert-hairy-args (res default-vars default-vals
-                                   entry-vars entry-vals
-                                   vars supplied-p-p body aux-vars
-                                   aux-vals cont
-                                  source-name debug-name)
+                               entry-vars entry-vals
+                               vars supplied-p-p body aux-vars
+                               aux-vals
+                               source-name debug-name
+                               force)
   (declare (type optional-dispatch res)
            (list default-vars default-vals entry-vars entry-vals vars body
-                 aux-vars aux-vals)
-           (type (or continuation null) cont))
+                 aux-vars aux-vals))
   (cond ((not vars)
          (if (optional-dispatch-keyp res)
              ;; Handle &KEY with no keys...
              (ir1-convert-more res default-vars default-vals
                                entry-vars entry-vals
                                nil nil nil vars supplied-p-p body aux-vars
-                               aux-vals cont source-name debug-name)
+                               aux-vals source-name debug-name)
              (let ((fun (ir1-convert-lambda-body
                         body (reverse default-vars)
                         :aux-vars aux-vars
                         :aux-vals aux-vals
-                        :result cont
                         :debug-name (debug-namify
                                      "hairy arg processor for ~A"
                                      (as-debug-name source-name
                                                     debug-name)))))
                (setf (optional-dispatch-main-entry res) fun)
+               (register-entry-point fun res)
                (push (if supplied-p-p
-                         (convert-optional-entry fun entry-vars entry-vals ())
-                         fun)
+                         (register-entry-point
+                          (convert-optional-entry fun entry-vars entry-vals ())
+                          res)
+                          fun)
                      (optional-dispatch-entry-points res))
                fun)))
         ((not (lambda-var-arg-info (first vars)))
                 (nvals (cons (leaf-source-name arg) default-vals)))
            (ir1-convert-hairy-args res nvars nvals nvars nvals
                                    (rest vars) nil body aux-vars aux-vals
-                                   cont
-                                  source-name debug-name)))
+                                  source-name debug-name
+                                   nil)))
         (t
          (let* ((arg (first vars))
                 (info (lambda-var-arg-info arg))
               (let ((ep (generate-optional-default-entry
                          res default-vars default-vals
                          entry-vars entry-vals vars supplied-p-p body
-                         aux-vars aux-vals cont
-                        source-name debug-name)))
-                (push (if supplied-p-p
-                          (convert-optional-entry ep entry-vars entry-vals ())
-                          ep)
+                         aux-vars aux-vals
+                        source-name debug-name
+                         force)))
+                ;; See GENERATE-OPTIONAL-DEFAULT-ENTRY.
+                (push (if (lambda-p ep)
+                          (register-entry-point
+                           (if supplied-p-p
+                               (convert-optional-entry ep entry-vars entry-vals ())
+                               ep)
+                           res)
+                          (progn (aver (not supplied-p-p))
+                                 ep))
                       (optional-dispatch-entry-points res))
                 ep))
              (:rest
               (ir1-convert-more res default-vars default-vals
                                 entry-vars entry-vals
                                 arg nil nil (rest vars) supplied-p-p body
-                                aux-vars aux-vals cont
+                                aux-vars aux-vals
                                source-name debug-name))
              (:more-context
               (ir1-convert-more res default-vars default-vals
                                 entry-vars entry-vals
                                 nil arg (second vars) (cddr vars) supplied-p-p
-                                body aux-vars aux-vals cont
+                                body aux-vars aux-vals
                                source-name debug-name))
              (:keyword
               (ir1-convert-more res default-vars default-vals
                                 entry-vars entry-vals
                                 nil nil nil vars supplied-p-p body aux-vars
-                                aux-vals cont source-name debug-name)))))))
+                                aux-vals source-name debug-name)))))))
 
 ;;; This function deals with the case where we have to make an
 ;;; OPTIONAL-DISPATCH to represent a LAMBDA. We cons up the result and
 ;;; call IR1-CONVERT-HAIRY-ARGS to do the work. When it is done, we
 ;;; figure out the MIN-ARGS and MAX-ARGS.
-(defun ir1-convert-hairy-lambda (body vars keyp allowp aux-vars aux-vals cont
+(defun ir1-convert-hairy-lambda (body vars keyp allowp aux-vars aux-vals
                                      &key
                                      (source-name '.anonymous.)
                                      (debug-name (debug-namify
                                                   "OPTIONAL-DISPATCH ~S"
                                                   vars)))
-  (declare (list body vars aux-vars aux-vals) (type continuation cont))
+  (declare (list body vars aux-vars aux-vals))
   (let ((res (make-optional-dispatch :arglist vars
                                     :allowp allowp
                                     :keyp keyp
                                     :%source-name source-name
-                                    :%debug-name debug-name))
+                                    :%debug-name debug-name
+                                     :plist `(:ir1-environment
+                                              (,*lexenv*
+                                               ,*current-path*))))
        (min (or (position-if #'lambda-var-arg-info vars) (length vars))))
     (aver-live-component *current-component*)
     (push res (component-new-functionals *current-component*))
     (ir1-convert-hairy-args res () () () () vars nil body aux-vars aux-vals
-                           cont source-name debug-name)
+                           source-name debug-name nil)
     (setf (optional-dispatch-min-args res) min)
     (setf (optional-dispatch-max-args res)
          (+ (1- (length (optional-dispatch-entry-points res))) min))
 
-    (flet ((frob (ep)
-            (when ep
-              (setf (functional-kind ep) :optional)
-              (setf (leaf-ever-used ep) t)
-              (setf (lambda-optional-dispatch ep) res))))
-      (dolist (ep (optional-dispatch-entry-points res)) (frob ep))
-      (frob (optional-dispatch-more-entry res))
-      (frob (optional-dispatch-main-entry res)))
-
     res))
 
 ;;; Convert a LAMBDA form into a LAMBDA leaf or an OPTIONAL-DISPATCH leaf.
 (defun ir1-convert-lambda (form &key (source-name '.anonymous.)
-                                    debug-name
-                                    allow-debug-catch-tag)
+                           debug-name
+                           allow-debug-catch-tag)
 
   (unless (consp form)
     (compiler-error "A ~S was found when expecting a lambda expression:~%  ~S"
     (multiple-value-bind (vars keyp allow-other-keys aux-vars aux-vals)
        (make-lambda-vars (cadr form))
       (multiple-value-bind (forms decls) (parse-body (cddr form))
-       (let* ((result-cont (make-continuation))
-              (*lexenv* (process-decls decls
-                                       (append aux-vars vars)
-                                       nil result-cont))
-              (forms (if (and *allow-debug-catch-tag*
-                              (policy *lexenv* (> debug (max speed space))))
-                         `((catch (make-symbol "SB-DEBUG-CATCH-TAG")
-                             ,@forms))
-                         forms))
-              (res (if (or (find-if #'lambda-var-arg-info vars) keyp)
-                       (ir1-convert-hairy-lambda forms vars keyp
-                                                 allow-other-keys
-                                                 aux-vars aux-vals result-cont
-                                                 :source-name source-name
-                                                 :debug-name debug-name)
-                       (ir1-convert-lambda-body forms vars
-                                                :aux-vars aux-vars
-                                                :aux-vals aux-vals
-                                                :result result-cont
-                                                :source-name source-name
-                                                :debug-name debug-name))))
+       (binding* (((*lexenv* result-type)
+                    (process-decls decls (append aux-vars vars) nil))
+                   (forms (if (and *allow-debug-catch-tag*
+                                   (policy *lexenv* (>= insert-debug-catch 2)))
+                              `((catch (make-symbol "SB-DEBUG-CATCH-TAG")
+                                  ,@forms))
+                              forms))
+                   (forms (if (eq result-type *wild-type*)
+                              forms
+                              `((the ,result-type (progn ,@forms)))))
+                   (res (if (or (find-if #'lambda-var-arg-info vars) keyp)
+                            (ir1-convert-hairy-lambda forms vars keyp
+                                                      allow-other-keys
+                                                      aux-vars aux-vals
+                                                      :source-name source-name
+                                                      :debug-name debug-name)
+                            (ir1-convert-lambda-body forms vars
+                                                     :aux-vars aux-vars
+                                                     :aux-vals aux-vals
+                                                     :source-name source-name
+                                                     :debug-name debug-name))))
          (setf (functional-inline-expansion res) form)
          (setf (functional-arg-documentation res) (cadr form))
          res)))))
     ((named-lambda)
      (let ((name (cadr thing)))
        (if (legal-fun-name-p name)
-          (let ((res (apply #'ir1-convert-lambda `(lambda ,@(cddr thing))
+          (let ((defined-fun-res (get-defined-fun name))
+                 (res (apply #'ir1-convert-lambda `(lambda ,@(cddr thing))
                             :source-name name
                             :debug-name nil
                             args)))
             (assert-global-function-definition-type name res)
+             (setf (defined-fun-functional defined-fun-res)
+                   res)
+             (unless (eq (defined-fun-inlinep defined-fun-res) :notinline)
+               (substitute-leaf-if
+                (lambda (ref)
+                  (policy ref (> recognize-self-calls 0)))
+                res defined-fun-res))
             res)
           (apply #'ir1-convert-lambda `(lambda ,@(cddr thing))
                  :debug-name name args))))
                          `(() () () . ,(cdr fun)))
     (let ((*lexenv* (make-lexenv
                     :default (process-decls decls nil nil
-                                            (make-continuation)
                                             (make-null-lexenv))
                     :vars (copy-list symbol-macros)
                     :funs (mapcar (lambda (x)
      ;; compilation unit, so we can't do that. -- WHN 2001-02-11
      :lossage-fun #'compiler-style-warn
      :unwinnage-fun (cond (info #'compiler-style-warn)
-                         (for-real #'compiler-note)
+                         (for-real #'compiler-notify)
                          (t nil))
      :really-assert
      (and for-real
            (specifier-type 'function))))
 
   (values))
+
+\f
+;;; Entry point utilities
+
+;;; Return a function for the Nth entry point.
+(defun optional-dispatch-entry-point-fun (dispatcher n)
+  (declare (type optional-dispatch dispatcher)
+           (type unsigned-byte n))
+  (let* ((env (getf (optional-dispatch-plist dispatcher) :ir1-environment))
+         (*lexenv* (first env))
+         (*current-path* (second env)))
+    (force (nth n (optional-dispatch-entry-points dispatcher)))))