0.pre7.129:
[sbcl.git] / src / compiler / debug.lisp
index fa8bbf3..7553f5d 100644 (file)
 ;;; *SEEN-BLOCKS* is a hashtable with true values for all blocks which
 ;;; appear in the DFO for one of the specified components.
 ;;;
-;;; *SEEN-FUNCTIONS* is similar, but records all the lambdas we
+;;; *SEEN-FUNS* is similar, but records all the lambdas we
 ;;; reached by recursing on top level functions.
+;;; FIXME: Is it really only LAMBDAs, not e.g. FUNCTIONALs? Then
+;;; shouldn't it be *SEEN-LAMBDAS*?
 (defvar *seen-blocks* (make-hash-table :test 'eq))
-(defvar *seen-functions* (make-hash-table :test 'eq))
+(defvar *seen-funs* (make-hash-table :test 'eq))
 
 ;;; Barf if NODE is in a block which wasn't reached during the graph
 ;;; walk.
     (barf "~S was not reached." node))
   (values))
 
-;;; Check everything that we can think of for consistency. When a definite
-;;; inconsistency is detected, we BARF. Possible problems just cause us to
-;;; BURP. Our argument is a list of components, but we also look at the
-;;; *FREE-VARIABLES*, *FREE-FUNCTIONS* and *CONSTANTS*.
+;;; Check everything that we can think of for consistency. When a
+;;; definite inconsistency is detected, we BARF. Possible problems
+;;; just cause us to BURP. Our argument is a list of components, but
+;;; we also look at the *FREE-VARIABLES*, *FREE-FUNS* and
+;;; *CONSTANTS*.
 ;;;
-;;; First we do a pre-pass which finds all the blocks and lambdas, testing
-;;; that they are linked together properly and entering them in hashtables.
-;;; Next, we iterate over the blocks again, looking at the actual code and
-;;; control flow. Finally, we scan the global leaf hashtables, looking for
-;;; lossage.
+;;; First we do a pre-pass which finds all the CBLOCKs and CLAMBDAs,
+;;; testing that they are linked together properly and entering them
+;;; in hashtables. Next, we iterate over the blocks again, looking at
+;;; the actual code and control flow. Finally, we scan the global leaf
+;;; hashtables, looking for lossage.
 (declaim (ftype (function (list) (values)) check-ir1-consistency))
 (defun check-ir1-consistency (components)
   (clrhash *seen-blocks*)
-  (clrhash *seen-functions*)
+  (clrhash *seen-funs*)
   (dolist (c components)
     (let* ((head (component-head c))
           (tail (component-tail c)))
 |#
     ))
 
-  (check-function-consistency components)
+  (check-fun-consistency components)
 
   (dolist (c components)
     (do ((block (block-next (component-head c)) (block-next block)))
        ((null (block-next block)))
       (check-block-consistency block)))
 
-  (maphash #'(lambda (k v)
-              (declare (ignore k))
-              (unless (or (constant-p v)
-                          (and (global-var-p v)
-                               (member (global-var-kind v)
-                                       '(:global :special))))
-                (barf "strange *FREE-VARIABLES* entry: ~S" v))
-              (dolist (n (leaf-refs v))
-                (check-node-reached n))
-              (when (basic-var-p v)
-                (dolist (n (basic-var-sets v))
-                  (check-node-reached n))))
+  (maphash (lambda (k v)
+            (declare (ignore k))
+            (unless (or (constant-p v)
+                        (and (global-var-p v)
+                             (member (global-var-kind v)
+                                     '(:global :special))))
+              (barf "strange *FREE-VARIABLES* entry: ~S" v))
+            (dolist (n (leaf-refs v))
+              (check-node-reached n))
+            (when (basic-var-p v)
+              (dolist (n (basic-var-sets v))
+                (check-node-reached n))))
           *free-variables*)
 
-  (maphash #'(lambda (k v)
-              (declare (ignore k))
-              (unless (constant-p v)
-                (barf "strange *CONSTANTS* entry: ~S" v))
-              (dolist (n (leaf-refs v))
-                (check-node-reached n)))
+  (maphash (lambda (k v)
+            (declare (ignore k))
+            (unless (constant-p v)
+              (barf "strange *CONSTANTS* entry: ~S" v))
+            (dolist (n (leaf-refs v))
+              (check-node-reached n)))
           *constants*)
 
-  (maphash #'(lambda (k v)
-              (declare (ignore k))
-              (unless (or (functional-p v)
-                          (and (global-var-p v)
-                               (eq (global-var-kind v) :global-function)))
-                (barf "strange *FREE-FUNCTIONS* entry: ~S" v))
-              (dolist (n (leaf-refs v))
-                (check-node-reached n)))
-          *free-functions*)
-  (clrhash *seen-functions*)
+  (maphash (lambda (k v)
+            (declare (ignore k))
+            (unless (or (functional-p v)
+                        (and (global-var-p v)
+                             (eq (global-var-kind v) :global-function)))
+              (barf "strange *FREE-FUNS* entry: ~S" v))
+            (dolist (n (leaf-refs v))
+              (check-node-reached n)))
+          *free-funs*)
+  (clrhash *seen-funs*)
   (clrhash *seen-blocks*)
   (values))
 \f
 
 (defun observe-functional (x)
   (declare (type functional x))
-  (when (gethash x *seen-functions*)
+  (when (gethash x *seen-funs*)
     (barf "~S was seen more than once." x))
   (unless (eq (functional-kind x) :deleted)
-    (setf (gethash x *seen-functions*) t)))
+    (setf (gethash x *seen-funs*) t)))
 
 ;;; Check that the specified function has been seen.
-(defun check-function-reached (fun where)
+(defun check-fun-reached (fun where)
   (declare (type functional fun))
-  (unless (gethash fun *seen-functions*)
+  (unless (gethash fun *seen-funs*)
     (barf "unseen function ~S in ~S" fun where)))
 
-;;; In a lambda, check that the associated nodes are in seen blocks. In an
-;;; optional dispatch, check that the entry points were seen. If the function
-;;; is deleted, ignore it.
-(defun check-function-stuff (functional)
+;;; In a CLAMBDA, check that the associated nodes are in seen blocks.
+;;; In an OPTIONAL-DISPATCH, check that the entry points were seen. If
+;;; the function is deleted, ignore it.
+(defun check-fun-stuff (functional)
   (ecase (functional-kind functional)
     (:external
-     (let ((fun (functional-entry-function functional)))
-       (check-function-reached fun functional)
+     (let ((fun (functional-entry-fun functional)))
+       (check-fun-reached fun functional)
        (when (functional-kind fun)
         (barf "The function for XEP ~S has kind." functional))
-       (unless (eq (functional-entry-function fun) functional)
+       (unless (eq (functional-entry-fun fun) functional)
         (barf "bad back-pointer in function for XEP ~S" functional))))
     ((:let :mv-let :assignment)
-     (check-function-reached (lambda-home functional) functional)
-     (when (functional-entry-function functional)
+     (check-fun-reached (lambda-home functional) functional)
+     (when (functional-entry-fun functional)
        (barf "The LET ~S has entry function." functional))
      (unless (member functional (lambda-lets (lambda-home functional)))
        (barf "The LET ~S is not in LETs for HOME." functional))
      (when (lambda-lets functional)
        (barf "LETs in a LET: ~S" functional)))
     (:optional
-     (when (functional-entry-function functional)
-       (barf ":OPTIONAL ~S has an ENTRY-FUNCTION." functional))
+     (when (functional-entry-fun functional)
+       (barf ":OPTIONAL ~S has an ENTRY-FUN." functional))
      (let ((ef (lambda-optional-dispatch functional)))
-       (check-function-reached ef functional)
+       (check-fun-reached ef functional)
        (unless (or (member functional (optional-dispatch-entry-points ef))
                   (eq functional (optional-dispatch-more-entry ef))
                   (eq functional (optional-dispatch-main-entry ef)))
         (barf ":OPTIONAL ~S is not an e-p for its OPTIONAL-DISPATCH ~S."
               functional ef))))
     (:toplevel
-     (unless (eq (functional-entry-function functional) functional)
-       (barf "The ENTRY-FUNCTION in ~S isn't a self-pointer." functional)))
+     (unless (eq (functional-entry-fun functional) functional)
+       (barf "The ENTRY-FUN in ~S isn't a self-pointer." functional)))
     ((nil :escape :cleanup)
-     (let ((ef (functional-entry-function functional)))
+     (let ((ef (functional-entry-fun functional)))
        (when ef
-        (check-function-reached ef functional)
+        (check-fun-reached ef functional)
         (unless (eq (functional-kind ef) :external)
-          (barf "The ENTRY-FUNCTION in ~S isn't an XEP: ~S."
-                functional
-                ef)))))
+          (barf "The ENTRY-FUN in ~S isn't an XEP: ~S." functional ef)))))
     (:deleted
-     (return-from check-function-stuff)))
+     (return-from check-fun-stuff)))
 
   (case (functional-kind functional)
     ((nil :optional :external :toplevel :escape :cleanup)
        (dolist (fun (lambda-lets functional))
         (unless (eq (lambda-home fun) functional)
           (barf "The home in ~S is not ~S." fun functional))
-        (check-function-reached fun functional))
+        (check-fun-reached fun functional))
        (unless (eq (lambda-home functional) functional)
         (barf "home not self-pointer in ~S" functional)))))
 
         (barf "HOME in ~S should be ~S." var functional))))
     (optional-dispatch
      (dolist (ep (optional-dispatch-entry-points functional))
-       (check-function-reached ep functional))
+       (check-fun-reached ep functional))
      (let ((more (optional-dispatch-more-entry functional)))
-       (when more (check-function-reached more functional)))
-     (check-function-reached (optional-dispatch-main-entry functional)
-                            functional))))
+       (when more (check-fun-reached more functional)))
+     (check-fun-reached (optional-dispatch-main-entry functional)
+                       functional))))
 
-(defun check-function-consistency (components)
+(defun check-fun-consistency (components)
   (dolist (c components)
     (dolist (new-fun (component-new-funs c))
       (observe-functional new-fun))
     (dolist (fun (component-lambdas c))
       (when (eq (functional-kind fun) :external)
-       (let ((ef (functional-entry-function fun)))
+       (let ((ef (functional-entry-fun fun)))
          (when (optional-dispatch-p ef)
            (observe-functional ef))))
       (observe-functional fun)
 
   (dolist (c components)
     (dolist (new-fun (component-new-funs c))
-      (check-function-stuff new-fun))
+      (check-fun-stuff new-fun))
     (dolist (fun (component-lambdas c))
       (when (eq (functional-kind fun) :deleted)
        (barf "deleted lambda ~S in Lambdas for ~S" fun c))
-      (check-function-stuff fun)
+      (check-fun-stuff fun)
       (dolist (let (lambda-lets fun))
-       (check-function-stuff let)))))
+       (check-fun-stuff let)))))
 \f
 ;;;; loop consistency checking
 
         (this-cont (block-start block))
         (last (block-last block)))
     (unless fun-deleted
-      (check-function-reached fun block))
+      (check-fun-reached fun block))
     (when (not this-cont)
       (barf "~S has no START." block))
     (when (not last)
     (check-block-successors block))
   (values))
 
-;;; Check that Block is properly terminated. Each successor must be
+;;; Check that BLOCK is properly terminated. Each successor must be
 ;;; accounted for by the type of the last node.
 (declaim (ftype (function (cblock) (values)) check-block-successors))
 (defun check-block-successors (block)
 \f
 ;;;; node consistency checking
 
-;;; Check that the Dest for Cont is the specified Node. We also mark the
-;;; block Cont is in as Seen.
+;;; Check that the DEST for CONT is the specified NODE. We also mark
+;;; the block CONT is in as SEEN.
 (declaim (ftype (function (continuation node) (values)) check-dest))
 (defun check-dest (cont node)
   (let ((kind (continuation-kind cont)))
         (barf "DEST for ~S should be ~S." cont node)))))
   (values))
 
-;;; This function deals with checking for consistency the type-dependent
-;;; information in a node.
+;;; This function deals with checking for consistency of the
+;;; type-dependent information in a node.
 (defun check-node-consistency (node)
   (declare (type node node))
   (etypecase node
                         :toplevel)
               (barf ":TOPLEVEL-XEP ref in non-top-level component: ~S"
                     node))
-            (check-function-reached leaf node)))))
+            (check-fun-reached leaf node)))))
     (basic-combination
      (check-dest (basic-combination-fun node) node)
      (dolist (arg (basic-combination-args node))
     (cset
      (check-dest (set-value node) node))
     (bind
-     (check-function-reached (bind-lambda node) node))
+     (check-fun-reached (bind-lambda node) node))
     (creturn
-     (check-function-reached (return-lambda node) node)
+     (check-fun-reached (return-lambda node) node)
      (check-dest (return-result node) node)
      (unless (eq (block-last (node-block node)) node)
        (barf "RETURN not at block end: ~S" node)))
         (num 0 (1+ num)))
        ((null ref)
         (when (< num count)
-          (barf "There should be at least ~D ~A in ~S, but are only ~D."
+          (barf "There should be at least ~W ~A in ~S, but there are only ~W."
                 count what vop num))
         (when (and (not more-p) (> num count))
-          (barf "There should be ~D ~A in ~S, but are ~D."
+          (barf "There should be ~W ~A in ~S, but are ~W."
                 count what vop num)))
       (unless (eq (tn-ref-vop ref) vop)
        (barf "VOP is ~S isn't ~S." ref vop))
           (atypes (template-arg-types info))
           (rtypes (template-result-types info)))
       (check-tn-refs (vop-args vop) vop nil
-                    (count-if-not #'(lambda (x)
-                                      (and (consp x)
-                                           (eq (car x) :constant)))
+                    (count-if-not (lambda (x)
+                                    (and (consp x)
+                                         (eq (car x) :constant)))
                                   atypes)
                     (template-more-args-type info) "args")
       (check-tn-refs (vop-results vop) vop t
       (incf const))
 
     (format stream
-     "~%TNs: ~D local, ~D temps, ~D constant, ~D env, ~D comp, ~D global.~@
-       Wired: ~D, Unused: ~D. ~D block~:P, ~D global conflict~:P.~%"
+     "~%TNs: ~W local, ~W temps, ~W constant, ~W env, ~W comp, ~W global.~@
+       Wired: ~W, Unused: ~W. ~W block~:P, ~W global conflict~:P.~%"
        local temps const environment comp global wired unused
        (ir2-block-count component)
        confs))
            (barf "strange TN ~S in LTN map for ~S" tn block)))))))
 
 ;;; All TNs live at the beginning of an environment must be passing
-;;; locations associated with that environment. We make an exception for wired
-;;; TNs in XEP functions, since we randomly reference wired TNs to access the
-;;; full call passing locations.
+;;; locations associated with that environment. We make an exception
+;;; for wired TNs in XEP functions, since we randomly reference wired
+;;; TNs to access the full call passing locations.
 (defun check-environment-lifetimes (component)
   (dolist (fun (component-lambdas component))
     (let* ((env (lambda-physenv fun))
           (2env (physenv-info env))
           (vars (lambda-vars fun))
-          (closure (ir2-physenv-environment 2env))
+          (closure (ir2-physenv-closure 2env))
           (pc (ir2-physenv-return-pc-pass 2env))
           (fp (ir2-physenv-old-fp 2env))
-          (2block (block-info
-                   (node-block
-                    (lambda-bind
-                     (physenv-function env))))))
+          (2block (block-info (lambda-block (physenv-lambda env)))))
       (do ((conf (ir2-block-global-tns 2block)
                 (global-conflicts-next conf)))
          ((null conf))
          (unless (or (eq (global-conflicts-kind conf) :write)
                      (eq tn pc)
                      (eq tn fp)
-                     (and (external-entry-point-p fun)
-                          (tn-offset tn))
+                     (and (xep-p fun) (tn-offset tn))
                      (member (tn-kind tn) '(:environment :debug-environment))
                      (member tn vars :key #'leaf-info)
                      (member tn closure :key #'cdr))
            (barf "strange TN live at head of ~S: ~S" env tn))))))
   (values))
 
-;;; Check for some basic sanity in the TN conflict data structures, and also
-;;; check that no TNs are unexpectedly live at environment entry.
+;;; Check for some basic sanity in the TN conflict data structures,
+;;; and also check that no TNs are unexpectedly live at environment
+;;; entry.
 (defun check-life-consistency (component)
   (check-tn-conflicts component)
   (check-block-conflicts component)
     (component (component-head thing))
 #|    (cloop (loop-head thing))|#
     (integer (continuation-block (num-cont thing)))
-    (functional (node-block (lambda-bind (main-entry thing))))
+    (functional (lambda-block (main-entry thing)))
     (null (error "Bad thing: ~S." thing))
-    (symbol (block-or-lose (gethash thing *free-functions*)))))
+    (symbol (block-or-lose (gethash thing *free-funs*)))))
 
 ;;; Print cN.
 (defun print-continuation (cont)
          (basic-combination
           (let ((kind (basic-combination-kind node)))
             (format t "~(~A ~A~) c~D"
-                    (if (function-info-p kind) "known" kind)
+                    (if (fun-info-p kind) "known" kind)
                     (type-of node)
                     (cont-num (basic-combination-fun node)))
             (dolist (arg (basic-combination-args node))
 
   (let ((succ (block-succ block)))
     (format t "successors~{ c~D~}~%"
-           (mapcar #'(lambda (x) (cont-num (block-start x))) succ)))
+           (mapcar (lambda (x) (cont-num (block-start x))) succ)))
   (values))
 
 ;;; Print a useful representation of a TN. If the TN has a leaf, then do a
            (vop-next vop))
        (number 0 (1+ number)))
       ((null vop))
-    (format t "~D: " number)
+    (format t "~W: " number)
     (print-vop vop)))
 
 ;;; This is like PRINT-NODES, but dumps the IR2 representation of the
 ;;; Make a list out of all of the recorded conflicts.
 (defun listify-conflicts-table ()
   (collect ((res))
-    (maphash #'(lambda (k v)
-                (declare (ignore v))
-                (when k
-                  (res k)))
+    (maphash (lambda (k v)
+              (declare (ignore v))
+              (when k
+                (res k)))
             *list-conflicts-table*)
     (clrhash *list-conflicts-table*)
     (res)))