X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Fnode.lisp;h=293641ea4ad96d53c31e220350ef4933dc1fa1a4;hb=cf607a404d7518e8a18c9e362913f370eb9a5e38;hp=abda10bb5d0364e5663e3902f63dbf02319a976e;hpb=20748f2dd7965dcd1446a1cb27e5a5af18a0e5bb;p=sbcl.git diff --git a/src/compiler/node.lisp b/src/compiler/node.lisp index abda10b..293641e 100644 --- a/src/compiler/node.lisp +++ b/src/compiler/node.lisp @@ -84,7 +84,7 @@ ;; cached type of this continuation's value. If NIL, then this must ;; be recomputed: see CONTINUATION-DERIVED-TYPE. (%derived-type nil :type (or ctype null)) - ;; Node where this continuation is used, if unique. This is always + ;; the node where this continuation is used, if unique. This is always ;; null in :DELETED and :UNUSED continuations, and is never null in ;; :INSIDE-BLOCK continuations. In a :BLOCK-START continuation, the ;; Block's START-USES indicate whether NIL means no uses or more @@ -124,14 +124,14 @@ ;; will be used. In the latter case, LTN must ensure that a safe ;; implementation *is* used. ;; - ;; :ERROR - ;; There is a compile-time type error in some use of this - ;; continuation. A type check should still be generated, but be - ;; careful. - ;; ;; This is computed lazily by CONTINUATION-DERIVED-TYPE, so use ;; CONTINUATION-TYPE-CHECK instead of the %'ed slot accessor. - (%type-check t :type (member t nil :deleted :no-check :error)) + (%type-check t :type (member t nil :deleted :no-check)) + ;; Asserted type, weakend according to policies + (type-to-check *wild-type* :type ctype) + ;; Cached type which is checked by DEST. If NIL, then this must be + ;; recomputed: see CONTINUATION-EXTERNALLY-CHECKABLE-TYPE. + (%externally-checkable-type nil :type (or null ctype)) ;; something or other that the back end annotates this continuation with (info nil) ;; uses of this continuation in the lexical environment. They are @@ -144,6 +144,8 @@ (defstruct (node (:constructor nil) (:copier nil)) + ;; unique ID for debugging + #!+sb-show (id (new-object-id) :read-only t) ;; the bottom-up derived type for this node. This does not take into ;; consideration output type assertions on this node (actually on its CONT). (derived-type *wild-type* :type ctype) @@ -198,7 +200,7 @@ ;;; Flags that are used to indicate various things about a block, such ;;; as what optimizations need to be done on it: ;;; -- REOPTIMIZE is set when something interesting happens the uses of a -;;; continuation whose Dest is in this block. This indicates that the +;;; continuation whose DEST is in this block. This indicates that the ;;; value-driven (forward) IR1 optimizations should be done on this block. ;;; -- FLUSH-P is set when code in this block becomes potentially flushable, ;;; usually due to a continuation's DEST becoming null. @@ -208,7 +210,7 @@ ;;; checking blocks we have already checked. ;;; -- DELETE-P is true when this block is used to indicate that this block ;;; has been determined to be unreachable and should be deleted. IR1 -;;; phases should not attempt to examine or modify blocks with DELETE-P +;;; phases should not attempt to examine or modify blocks with DELETE-P ;;; set, since they may: ;;; - be in the process of being deleted, or ;;; - have no successors, or @@ -219,9 +221,11 @@ ;;; is set when a continuation type assertion is strengthened. ;;; TEST-MODIFIED is set whenever the test for the ending IF has ;;; changed (may be true when there is no IF.) -(def-boolean-attribute block +(!def-boolean-attribute block reoptimize flush-p type-check delete-p type-asserted test-modified) +;;; FIXME: Tweak so that definitions of e.g. BLOCK-DELETE-P is +;;; findable by grep for 'def.*block-delete-p'. (macrolet ((frob (slot) `(defmacro ,(symbolicate "BLOCK-" slot) (block) `(block-attributep (block-flags ,block) ,',slot)))) @@ -291,7 +295,10 @@ (out nil) ;; the component this block is in, or NIL temporarily during IR1 ;; conversion and in deleted blocks - (component *current-component* :type (or component null)) + (component (progn + (aver-live-component *current-component*) + *current-component*) + :type (or component null)) ;; a flag used by various graph-walking code to determine whether ;; this block has been processed already or what. We make this ;; initially NIL so that FIND-INITIAL-DFO doesn't have to scan the @@ -304,7 +311,9 @@ (test-constraint nil :type (or sset null))) (def!method print-object ((cblock cblock) stream) (print-unreadable-object (cblock stream :type t :identity t) - (format stream ":START c~D" (cont-num (block-start cblock))))) + (format stream "~W :START c~W" + (block-number cblock) + (cont-num (block-start cblock))))) ;;; The BLOCK-ANNOTATION class is inherited (via :INCLUDE) by ;;; different BLOCK-INFO annotation structures so that code @@ -314,16 +323,26 @@ ;; The IR1 block that this block is in the INFO for. (block (missing-arg) :type cblock) ;; the next and previous block in emission order (not DFO). This - ;; determines which block we drop though to, and also used to chain - ;; together overflow blocks that result from splitting of IR2 blocks - ;; in lifetime analysis. + ;; determines which block we drop though to, and is also used to + ;; chain together overflow blocks that result from splitting of IR2 + ;; blocks in lifetime analysis. (next nil :type (or block-annotation null)) (prev nil :type (or block-annotation null))) ;;; A COMPONENT structure provides a handle on a connected piece of ;;; the flow graph. Most of the passes in the compiler operate on ;;; COMPONENTs rather than on the entire flow graph. +;;; +;;; According to the CMU CL internals/front.tex, the reason for +;;; separating compilation into COMPONENTs is +;;; to increase the efficiency of large block compilations. In +;;; addition to improving locality of reference and reducing the +;;; size of flow analysis problems, this allows back-end data +;;; structures to be reclaimed after the compilation of each +;;; component. (defstruct (component (:copier nil)) + ;; unique ID for debugging + #!+sb-show (id (new-object-id) :read-only t) ;; the kind of component ;; ;; (The terminology here is left over from before @@ -369,8 +388,8 @@ ;; ;; Note that logical associations between CLAMBDAs and COMPONENTs ;; seem to exist for a while before this is initialized. See e.g. - ;; the NEW-FUNS slot. In particular, I got burned by writing some - ;; code to use this value to decide which components need + ;; the NEW-FUNCTIONALS slot. In particular, I got burned by writing + ;; some code to use this value to decide which components need ;; LOCALL-ANALYZE-COMPONENT, when it turns out that ;; LOCALL-ANALYZE-COMPONENT had a role in initializing this value ;; (and DFO stuff does too, maybe). Also, even after it's @@ -383,7 +402,7 @@ ;; (possibly as LETs, or implicitly as XEPs if an OPTIONAL-DISPATCH.) ;; Between runs of local call analysis there may be some debris of ;; converted or even deleted functions in this list. - (new-funs () :type list) + (new-functionals () :type list) ;; If this is true, then there is stuff in this component that could ;; benefit from further IR1 optimization. (reoptimize t :type boolean) @@ -392,8 +411,13 @@ (reanalyze nil :type boolean) ;; some sort of name for the code in this component (name "" :type simple-string) - ;; some kind of info used by the back end - (info nil) + ;; When I am a child, this is :NO-IR2-YET. + ;; In my adulthood, IR2 stores notes to itself here. + ;; After I have left the great wheel and am staring into the GC, this + ;; is set to :DEAD to indicate that it's a gruesome error to operate + ;; on me (e.g. by using me as *CURRENT-COMPONENT*, or by pushing + ;; LAMBDAs onto my NEW-FUNCTIONALS, as in sbcl-0.pre7.115). + (info :no-ir2-yet :type (or ir2-component (member :no-ir2-yet :dead))) ;; the SOURCE-INFO structure describing where this component was ;; compiled from (source-info *source-info* :type source-info) @@ -408,15 +432,26 @@ ;; arguments for the note, or the FUN-TYPE that would have ;; enabled the transformation but failed to match. (failed-optimizations (make-hash-table :test 'eq) :type hash-table) - ;; This is similar to NEW-FUNS, but is used when a function has - ;; already been analyzed, but new references have been added by - ;; inline expansion. Unlike NEW-FUNS, this is not disjoint from - ;; COMPONENT-LAMBDAS. - (reanalyze-funs nil :type list)) + ;; This is similar to NEW-FUNCTIONALS, but is used when a function + ;; has already been analyzed, but new references have been added by + ;; inline expansion. Unlike NEW-FUNCTIONALS, this is not disjoint + ;; from COMPONENT-LAMBDAS. + (reanalyze-functionals nil :type list)) (defprinter (component :identity t) name + #!+sb-show id (reanalyze :test reanalyze)) +;;; Check that COMPONENT is suitable for roles which involve adding +;;; new code. (gotta love imperative programming with lotso in-place +;;; side effects...) +(defun aver-live-component (component) + ;; FIXME: As of sbcl-0.pre7.115, we're asserting that + ;; COMPILE-COMPONENT hasn't happened yet. Might it be even better + ;; (certainly stricter, possibly also correct...) to assert that + ;; IR1-FINALIZE hasn't happened yet? + (aver (not (eql (component-info component) :dead)))) + ;;; Before sbcl-0.7.0, there were :TOPLEVEL things which were magical ;;; in multiple ways. That's since been refactored into the orthogonal ;;; properties "optimized for locall with no arguments" and "externally @@ -488,7 +523,7 @@ ;;; TNs, or eventually stack slots and registers). -- WHN 2001-09-29 (defstruct (physenv (:copier nil)) ;; the function that allocates this physical environment - (function (missing-arg) :type clambda) + (lambda (missing-arg) :type clambda :read-only t) #| ; seems not to be used as of sbcl-0.pre7.51 ;; a list of all the lambdas that allocate variables in this ;; physical environment @@ -508,7 +543,7 @@ ;; some kind of info used by the back end (info nil)) (defprinter (physenv :identity t) - function + lambda (closure :test closure) (nlx-info :test nlx-info)) @@ -539,8 +574,8 @@ type (info :test info)) -;;; The NLX-Info structure is used to collect various information -;;; about non-local exits. This is effectively an annotation on the +;;; An NLX-INFO structure is used to collect various information about +;;; non-local exits. This is effectively an annotation on the ;;; CONTINUATION, although it is accessed by searching in the ;;; PHYSENV-NLX-INFO. (def!struct (nlx-info (:make-load-form-fun ignore-it)) @@ -557,13 +592,13 @@ ;; ;; This slot is primarily an indication of where this exit delivers ;; its values to (if any), but it is also used as a sort of name to - ;; allow us to find the NLX-Info that corresponds to a given exit. - ;; For this purpose, the Entry must also be used to disambiguate, + ;; allow us to find the NLX-INFO that corresponds to a given exit. + ;; For this purpose, the ENTRY must also be used to disambiguate, ;; since exits to different places may deliver their result to the ;; same continuation. (continuation (missing-arg) :type continuation) ;; the entry stub inserted by physical environment analysis. This is - ;; a block containing a call to the %NLX-Entry funny function that + ;; a block containing a call to the %NLX-ENTRY funny function that ;; has the original exit destination as its successor. Null only ;; temporarily. (target nil :type (or cblock null)) @@ -582,6 +617,8 @@ ;;; hacking the flow graph. (def!struct (leaf (:make-load-form-fun ignore-it) (:constructor nil)) + ;; unique ID for debugging + #!+sb-show (id (new-object-id) :read-only t) ;; (For public access to this slot, use LEAF-SOURCE-NAME.) ;; ;; the name of LEAF as it appears in the source, e.g. 'FOO or '(SETF @@ -593,6 +630,10 @@ ;; skewed enough (e.g. for macro functions or method functions) that ;; we don't want to have that name affect compilation ;; + ;; (We use .ANONYMOUS. here more or less the way we'd ordinarily use + ;; NIL, but we're afraid to use NIL because it's a symbol which could + ;; be the name of a leaf, if only the constant named NIL.) + ;; ;; The value of this slot in can affect ordinary runtime behavior, ;; e.g. of special variables and known functions, not just debugging. ;; @@ -669,25 +710,11 @@ :type (member :special :global-function :global))) (defprinter (global-var :identity t) %source-name + #!+sb-show id (type :test (not (eq type *universal-type*))) (where-from :test (not (eq where-from :assumed))) kind) -;;; The SLOT-ACCESSOR structure represents slot accessor functions. It -;;; is a subtype of GLOBAL-VAR to make it look more like a normal -;;; function. -(def!struct (slot-accessor (:include global-var - (where-from :defined) - (kind :global-function))) - ;; The description of the structure that this is an accessor for. - (for (missing-arg) :type sb!xc:class) - ;; The slot description of the slot. - (slot (missing-arg))) -(defprinter (slot-accessor :identity t) - %source-name - for - slot) - ;;; A DEFINED-FUN represents a function that is defined in the same ;;; compilation block, or that has an inline expansion, or that has a ;;; non-NIL INLINEP value. Whenever we change the INLINEP state (i.e. @@ -707,6 +734,7 @@ (functional nil :type (or functional null))) (defprinter (defined-fun :identity t) %source-name + #!+sb-show id inlinep (functional :test functional)) @@ -773,14 +801,16 @@ ;; continuation for the call. ;; ;; :MV-LET - ;; Similar to :LET, but the call is an MV-CALL. + ;; Similar to :LET (as per FUNCTIONAL-LETLIKE-P), but the call + ;; is an MV-CALL. ;; ;; :ASSIGNMENT - ;; similar to a LET, but can have other than one call as long as - ;; there is at most one non-tail call. + ;; similar to a LET (as per FUNCTIONAL-SOMEWHAT-LETLIKE-P), but + ;; can have other than one call as long as there is at most + ;; one non-tail call. ;; ;; :OPTIONAL - ;; a lambda that is an entry-point for an optional-dispatch. + ;; a lambda that is an entry point for an OPTIONAL-DISPATCH. ;; Similar to NIL, but requires greater caution, since local call ;; analysis may create new references to this function. Also, the ;; function cannot be deleted even if it has *no* references. The @@ -839,14 +869,15 @@ ;; ;; With all other kinds, this is null. (entry-fun nil :type (or functional null)) - ;; the value of any inline/notinline declaration for a local function + ;; the value of any inline/notinline declaration for a local + ;; function (or NIL in any case if no inline expansion is available) (inlinep nil :type inlinep) ;; If we have a lambda that can be used as in inline expansion for ;; this function, then this is it. If there is no source-level - ;; lambda corresponding to this function then this is Null (but then + ;; lambda corresponding to this function then this is null (but then ;; INLINEP will always be NIL as well.) (inline-expansion nil :type list) - ;; the lexical environment that the inline-expansion should be converted in + ;; the lexical environment that the INLINE-EXPANSION should be converted in (lexenv *lexenv* :type lexenv) ;; the original function or macro lambda list, or :UNSPECIFIED if ;; this is a compiler created function @@ -855,7 +886,23 @@ (plist () :type list)) (defprinter (functional :identity t) %source-name - %debug-name) + %debug-name + #!+sb-show id) + +;;; Is FUNCTIONAL LET-converted? (where we're indifferent to whether +;;; it returns one value or multiple values) +(defun functional-letlike-p (functional) + (member (functional-kind functional) + '(:let :mv-let))) + +;;; Is FUNCTIONAL sorta LET-converted? (where even an :ASSIGNMENT counts) +;;; +;;; FIXME: I (WHN) don't understand this one well enough to give a good +;;; definition or even a good function name, it's just a literal copy +;;; of a CMU CL idiom. Does anyone have a better name or explanation? +(defun functional-somewhat-letlike-p (functional) + (or (functional-letlike-p functional) + (eql (functional-kind functional) :assignment))) ;;; FUNCTIONAL name operations (defun functional-debug-name (functional) @@ -903,17 +950,16 @@ ;; If this CLAMBDA is a LET, then this slot holds the LAMBDA whose ;; LETS list we are in, otherwise it is a self-pointer. (home nil :type (or clambda null)) - ;; a list of all the all the lambdas that have been LET-substituted - ;; in this lambda. This is only non-null in lambdas that aren't - ;; LETs. - (lets () :type list) - ;; a list of all the ENTRY nodes in this function and its LETs, or - ;; null in a LET - (entries () :type list) - ;; a list of all the functions directly called from this function - ;; (or one of its LETs) using a non-LET local call. This may include - ;; deleted functions because nobody bothers to clear them out. - (calls () :type list) + ;; all the lambdas that have been LET-substituted in this lambda. + ;; This is only non-null in lambdas that aren't LETs. + (lets nil :type list) + ;; all the ENTRY nodes in this function and its LETs, or null in a LET + (entries nil :type list) + ;; CLAMBDAs which are locally called by this lambda, and other + ;; objects (closed-over LAMBDA-VARs and XEPs) which this lambda + ;; depends on in such a way that DFO shouldn't put them in separate + ;; components. + (calls-or-closes nil :type list) ;; the TAIL-SET that this LAMBDA is in. This is null during creation. ;; ;; In CMU CL, and old SBCL, this was also NILed out when LET @@ -937,6 +983,7 @@ (defprinter (clambda :conc-name lambda- :identity t) %source-name %debug-name + #!+sb-show id (type :test (not (eq type *universal-type*))) (where-from :test (not (eq where-from :assumed))) (vars :prin1 (mapcar #'leaf-source-name vars))) @@ -997,6 +1044,7 @@ (defprinter (optional-dispatch :identity t) %source-name %debug-name + #!+sb-show id (type :test (not (eq type *universal-type*))) (where-from :test (not (eq where-from :assumed))) arglist @@ -1046,8 +1094,8 @@ ;;; LAMBDA-VARs with no REFs are considered to be deleted; physical ;;; environment analysis isn't done on these variables, so the back ;;; end must check for and ignore unreferenced variables. Note that a -;;; deleted lambda-var may have sets; in this case the back end is -;;; still responsible for propagating the Set-Value to the set's Cont. +;;; deleted LAMBDA-VAR may have sets; in this case the back end is +;;; still responsible for propagating the SET-VALUE to the set's CONT. (def!struct (lambda-var (:include basic-var)) ;; true if this variable has been declared IGNORE (ignorep nil :type boolean) @@ -1074,6 +1122,7 @@ (constraints nil :type (or sset null))) (defprinter (lambda-var :identity t) %source-name + #!+sb-show id (type :test (not (eq type *universal-type*))) (where-from :test (not (eq where-from :assumed))) (ignorep :test ignorep) @@ -1085,12 +1134,13 @@ ;;; A REF represents a reference to a LEAF. REF-REOPTIMIZE is ;;; initially (and forever) NIL, since REFs don't receive any values ;;; and don't have any IR1 optimizer. -(defstruct (ref (:include node (:reoptimize nil)) +(defstruct (ref (:include node (reoptimize nil)) (:constructor make-ref (derived-type leaf)) (:copier nil)) ;; The leaf referenced. (leaf nil :type leaf)) (defprinter (ref :identity t) + #!+sb-show id leaf) ;;; Naturally, the IF node always appears at the end of a block. @@ -1144,12 +1194,12 @@ ;; the kind of function call being made. :LOCAL means that this is a ;; local call to a function in the same component, and that argument ;; syntax checking has been done, etc. Calls to known global - ;; functions are represented by storing the FUNCTION-INFO for the + ;; functions are represented by storing the FUN-INFO for the ;; function in this slot. :FULL is a call to an (as yet) unknown ;; function. :ERROR is like :FULL, but means that we have discovered ;; that the call contains an error, and should not be reconsidered ;; for optimization. - (kind :full :type (or (member :local :full :error) function-info)) + (kind :full :type (or (member :local :full :error) fun-info)) ;; some kind of information attached to this node by the back end (info nil)) @@ -1160,6 +1210,7 @@ (:constructor make-combination (fun)) (:copier nil))) (defprinter (combination :identity t) + #!+sb-show id (fun :prin1 (continuation-use fun)) (args :prin1 (mapcar (lambda (x) (if x @@ -1216,15 +1267,16 @@ ;;;; lexical exits. ;;; The ENTRY node serves to mark the start of the dynamic extent of a -;;; lexical exit. It is the mess-up node for the corresponding :Entry +;;; lexical exit. It is the mess-up node for the corresponding :ENTRY ;;; cleanup. (defstruct (entry (:include node) (:copier nil)) - ;; All of the Exit nodes for potential non-local exits to this point. + ;; All of the EXIT nodes for potential non-local exits to this point. (exits nil :type list) ;; The cleanup for this entry. NULL only temporarily. (cleanup nil :type (or cleanup null))) -(defprinter (entry :identity t)) +(defprinter (entry :identity t) + #!+sb-show id) ;;; The EXIT node marks the place at which exit code would be emitted, ;;; if necessary. This is interposed between the uses of the exit @@ -1234,15 +1286,16 @@ ;;; original exit continuation is the exit node's CONT. (defstruct (exit (:include node) (:copier nil)) - ;; The Entry node that this is an exit for. If null, this is a + ;; the ENTRY node that this is an exit for. If null, this is a ;; degenerate exit. A degenerate exit is used to "fill" an empty ;; block (which isn't allowed in IR1.) In a degenerate exit, Value ;; is always also null. (entry nil :type (or entry null)) - ;; The continuation yeilding the value we are to exit with. If NIL, + ;; the continuation yielding the value we are to exit with. If NIL, ;; then no value is desired (as in GO). (value nil :type (or continuation null))) (defprinter (exit :identity t) + #!+sb-show id (entry :test entry) (value :test value))