Eliminate "unused variable" warning from ARRAY-ROW-MAJOR-INDEX
[sbcl.git] / src / compiler / ir1tran-lambda.lisp
index 63b14da..ce06727 100644 (file)
                 (dolist (default defaults)
                   (if (sb!xc:constantp default)
                       (default-vals default)
-                      (let ((var (gensym)))
+                      (let ((var (sb!xc:gensym)))
                         (default-bindings `(,var ,default))
                         (default-vals var))))
                 (let ((bindings (default-bindings))
                                  :type (leaf-type var)
                                  :where-from (leaf-where-from var))))
 
-    (let* ((n-context (gensym "N-CONTEXT-"))
+    (let* ((n-context (sb!xc:gensym "N-CONTEXT-"))
            (context-temp (make-lambda-var :%source-name n-context))
-           (n-count (gensym "N-COUNT-"))
+           (n-count (sb!xc:gensym "N-COUNT-"))
            (count-temp (make-lambda-var :%source-name n-count
                                         :type (specifier-type 'index))))
 
       (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)))
       (when morep
         (arg-vals n-context)
         (arg-vals n-count))
       ;; and take advantage of the base+index+displacement addressing
       ;; mode on x86oids.)
       (when (optional-dispatch-keyp res)
-        (let ((n-index (gensym "N-INDEX-"))
-              (n-key (gensym "N-KEY-"))
-              (n-value-temp (gensym "N-VALUE-TEMP-"))
-              (n-allowp (gensym "N-ALLOWP-"))
-              (n-losep (gensym "N-LOSEP-"))
+        (let ((n-index (sb!xc:gensym "N-INDEX-"))
+              (n-key (sb!xc:gensym "N-KEY-"))
+              (n-value-temp (sb!xc:gensym "N-VALUE-TEMP-"))
+              (n-allowp (sb!xc:gensym "N-ALLOWP-"))
+              (n-lose (sb!xc:gensym "N-LOSE-"))
+              (n-losep (sb!xc:gensym "N-LOSEP-"))
               (allowp (or (optional-dispatch-allowp res)
                           (policy *lexenv* (zerop safety))))
               (found-allow-p nil))
                      (default (arg-info-default info))
                      (keyword (arg-info-key info))
                      (supplied-p (arg-info-supplied-p info))
-                     (n-value (gensym "N-VALUE-"))
+                     (n-value (sb!xc:gensym "N-VALUE-"))
                      (clause (cond (supplied-p
-                                    (let ((n-supplied (gensym "N-SUPPLIED-")))
+                                    (let ((n-supplied (sb!xc:gensym "N-SUPPLIED-")))
                                       (temps n-supplied)
                                       (arg-vals n-value n-supplied)
                                       `((eq ,n-key ',keyword)
                 (tests clause)))
 
             (unless allowp
-              (temps n-allowp n-losep)
+              (temps n-allowp n-lose n-losep)
               (unless found-allow-p
                 (tests `((eq ,n-key :allow-other-keys)
                          (setq ,n-allowp ,n-value-temp))))
               (tests `(t
-                       (setq ,n-losep (list ,n-key)))))
+                       (setq ,n-lose ,n-key
+                             ,n-losep t))))
 
             (body
              `(when (oddp ,n-count)
 
             (unless allowp
               (body `(when (and ,n-losep (not ,n-allowp))
-                       (%unknown-key-arg-error (car ,n-losep))))))))
+                       (%unknown-key-arg-error ,n-lose)))))))
 
       (let ((ep (ir1-convert-lambda-body
                  `((let ,(temps)
             (bind-vals))
     (when rest
       (main-vars rest)
-      (main-vals '()))
+      (main-vals '())
+      (unless (lambda-var-ignorep rest)
+        ;; Make up two extra variables, and squirrel them away in
+        ;; ARG-INFO-DEFAULT for transforming (VALUES-LIST REST) into
+        ;; (%MORE-ARG-VALUES CONTEXT 0 COUNT) when possible.
+        (let* ((context-name (sb!xc:gensym "REST-CONTEXT-"))
+               (context (make-lambda-var :%source-name context-name
+                                         :arg-info (make-arg-info :kind :more-context)))
+               (count-name (sb!xc:gensym "REST-COUNT-"))
+               (count (make-lambda-var :%source-name count-name
+                                       :arg-info (make-arg-info :kind :more-count)
+                                       :type (specifier-type 'index))))
+          (setf (arg-info-default (lambda-var-arg-info rest)) (list context count)
+                (lambda-var-ever-used context) t
+                (lambda-var-ever-used count) t)
+          (setf more-context context
+                more-count count))))
     (when more-context
       (main-vars more-context)
       (main-vals nil)
         (main-vars val-temp)
         (bind-vars key)
         (cond ((or hairy-default supplied-p)
-               (let* ((n-supplied (gensym "N-SUPPLIED-"))
+               (let* ((n-supplied (sb!xc:gensym "N-SUPPLIED-"))
                       (supplied-temp (make-lambda-var
                                       :%source-name n-supplied)))
                  (unless supplied-p
                (main-vals (arg-info-default info))
                (bind-vals n-val)))))
 
-    (let* ((name (or debug-name source-name))
-           (main-entry (ir1-convert-lambda-body
+    (let* ((main-entry (ir1-convert-lambda-body
                         body (main-vars)
                         :aux-vars (append (bind-vars) aux-vars)
                         :aux-vals (append (bind-vals) aux-vals)
                         :post-binding-lexenv post-binding-lexenv
-                        :debug-name (debug-name 'varargs-entry name)
+                        :source-name source-name
+                        :debug-name debug-name
                         :system-lambda system-lambda))
+           (name (or debug-name source-name))
            (last-entry (convert-optional-entry main-entry default-vars
                                                (main-vals) () name)))
       (setf (optional-dispatch-main-entry res)
                          :aux-vars aux-vars
                          :aux-vals aux-vals
                          :post-binding-lexenv post-binding-lexenv
-                         :debug-name (debug-name 'hairy-arg-processor name)
+                         :source-name source-name
+                         :debug-name debug-name
                          :system-lambda system-lambda)))
 
                (setf (optional-dispatch-main-entry res) fun)
                                                ,*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
                             source-name debug-name nil post-binding-lexenv
                             system-lambda)
+    ;; ir1-convert-hairy-args can throw 'locall-already-let-converted
+    ;; push optional-dispatch into the current component only after it
+    ;; normally returned
+    (push res (component-new-functionals *current-component*))
     (setf (optional-dispatch-min-args res) min)
     (setf (optional-dispatch-max-args res)
           (+ (1- (length (optional-dispatch-entry-points res))) min))
                             forms))
                  (forms (if (eq result-type *wild-type*)
                             forms
-                            `((the ,result-type (progn ,@forms)))))
+                            `((the ,(type-specifier result-type) (progn ,@forms)))))
                  (*allow-instrumenting* (and (not system-lambda) *allow-instrumenting*))
                  (res (cond ((or (find-if #'lambda-var-arg-info vars) keyp)
                              (ir1-convert-hairy-lambda forms vars keyp
                          :maybe-add-debug-catch t
                          :source-name source-name
                          :debug-name debug-name))
-    ((instance-lambda)
-     (deprecation-warning :final "0.9.3.32" 'instance-lambda 'lambda)
-     (ir1-convert-lambda `(lambda (&rest args)
-                            (declare (ignore args))
-                            (deprecation-error "0.9.3.32" 'instance-lambda 'lambda))
-                         :source-name source-name
-                         :debug-name debug-name))
     ((named-lambda)
      (let ((name (cadr thing))
            (lambda-expression `(lambda ,@(cddr thing))))
       (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))))
+
 ;;; the even-at-compile-time part of DEFUN
 ;;;
-;;; The INLINE-EXPANSION is a LAMBDA-WITH-LEXENV, or NIL if there is
-;;; no inline expansion.
-(defun %compiler-defun (name lambda-with-lexenv compile-toplevel)
+;;; The INLINE-LAMBDA is a LAMBDA-WITH-LEXENV, or NIL if there is no
+;;; inline expansion.
+(defun %compiler-defun (name inline-lambda compile-toplevel)
   (let ((defined-fun nil)) ; will be set below if we're in the compiler
     (when compile-toplevel
-      (setf defined-fun (if lambda-with-lexenv
-                            (get-defined-fun name (fifth lambda-with-lexenv))
-                            (get-defined-fun name)))
+      (with-single-package-locked-error
+          (:symbol name "defining ~S as a function")
+        (setf defined-fun
+              (if inline-lambda
+                  (get-defined-fun name (fifth inline-lambda))
+                  (get-defined-fun name))))
       (when (boundp '*lexenv*)
-        (remhash name *free-funs*)
         (aver (fasl-output-p *compile-object*))
         (if (member name *fun-names-in-this-file* :test #'equal)
             (warn 'duplicate-definition :name name)
-            (push name *fun-names-in-this-file*))))
+            (push name *fun-names-in-this-file*)))
+      (%set-inline-expansion name defined-fun inline-lambda))
 
     (become-defined-fun-name name)
 
-    (cond (lambda-with-lexenv
-           (setf (info :function :inline-expansion-designator name)
-                 lambda-with-lexenv)
-           (when defined-fun
-             (setf (defined-fun-inline-expansion defined-fun)
-                   lambda-with-lexenv)))
-          (t
-           (clear-info :function :inline-expansion-designator name)))
-
     ;; old CMU CL comment:
     ;;   If there is a type from a previous definition, blast it,
     ;;   since it is obsolete.