X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcompiler%2Fnode.lisp;h=564111478795c95406194028854c15895f4140f5;hb=7ce2c42adf3d62f03086de940adaee48e6161a40;hp=1eb7ec0ab982993c248beec42526f34cd2b7b149;hpb=7fd2eb4b1bc68e8aaec233c4a39bdfc40225bda2;p=sbcl.git diff --git a/src/compiler/node.lisp b/src/compiler/node.lisp index 1eb7ec0..5641114 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) @@ -175,15 +177,15 @@ ;; is indicated by the magic ORIGINAL-SOURCE-START marker. The first ;; element of the original source is the "form number", which is the ;; ordinal number of this form in a depth-first, left-to-right walk - ;; of the truly top-level form in which this appears. + ;; of the truly-top-level form in which this appears. ;; ;; Following is a list of integers describing the path taken through ;; the source to get to this point: ;; (K L M ...) => (NTH K (NTH L (NTH M ...))) ;; - ;; The last element in the list is the top-level form number, which + ;; The last element in the list is the top level form number, which ;; is the ordinal number (in this call to the compiler) of the truly - ;; top-level form containing the original source. + ;; top level form containing the original source. (source-path *current-path* :type list) ;; If this node is in a tail-recursive position, then this is set to ;; T. At the end of IR1 (in physical environment analysis) this is @@ -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 @@ -222,6 +224,8 @@ (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,7 @@ (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 ":START c~W" (cont-num (block-start cblock))))) ;;; The BLOCK-ANNOTATION class is inherited (via :INCLUDE) by ;;; different BLOCK-INFO annotation structures so that code @@ -312,18 +319,28 @@ (defstruct (block-annotation (:constructor nil) (:copier nil)) ;; The IR1 block that this block is in the INFO for. - (block (required-argument) :type cblock) + (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 @@ -337,12 +354,12 @@ ;; The possibilities are: ;; NIL ;; an ordinary component, containing non-top-level code - ;; :TOP-LEVEL + ;; :TOPLEVEL ;; a component containing only load-time code - ;; :COMPLEX-TOP-LEVEL + ;; :COMPLEX-TOPLEVEL ;; In the old system, before FUNCTIONAL-HAS-EXTERNAL-REFERENCES-P ;; was defined, this was necessarily a component containing both - ;; top-level and run-time code. Now this state is also used for + ;; top level and run-time code. Now this state is also used for ;; a component with HAS-EXTERNAL-REFERENCES-P functionals in it. ;; :INITIAL ;; the result of initial IR1 conversion, on which component @@ -350,8 +367,8 @@ ;; :DELETED ;; debris left over from component analysis ;; - ;; See also COMPONENT-TOP-LEVELISH-P. - (kind nil :type (member nil :top-level :complex-top-level :initial :deleted)) + ;; See also COMPONENT-TOPLEVELISH-P. + (kind nil :type (member nil :toplevel :complex-toplevel :initial :deleted)) ;; the blocks that are the dummy head and tail of the DFO ;; ;; Entry/exit points have these blocks as their @@ -368,22 +385,22 @@ ;; deleted or LET lambdas. ;; ;; Note that logical associations between CLAMBDAs and COMPONENTs - ;; seem to exist for a while before this is initialized. In - ;; particular, I got burned by writing some code to use this value - ;; to decide which components need LOCAL-CALL-ANALYZE, when it turns - ;; out that LOCAL-CALL-ANALYZE had a role in initializing this value + ;; seem to exist for a while before this is initialized. See e.g. + ;; 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 ;; initialized, it might change as CLAMBDAs are deleted or merged. ;; -- WHN 2001-09-30 (lambdas () :type list) - ;; a list of FUNCTIONAL structures for functions that are newly - ;; converted, and haven't been local-call analyzed yet. Initially - ;; functions are not in the LAMBDAS list. LOCAL-CALL-ANALYZE moves - ;; them there (possibly as LETs, or implicitly as XEPs if an - ;; OPTIONAL-DISPATCH.) Between runs of LOCAL-CALL-ANALYZE there may - ;; be some debris of converted or even deleted functions in this - ;; list. - (new-functions () :type list) + ;; a list of FUNCTIONALs for functions that are newly converted, and + ;; haven't been local-call analyzed yet. Initially functions are not + ;; in the LAMBDAS list. Local call analysis moves them there + ;; (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-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 +409,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) @@ -405,19 +427,30 @@ ;; optimization of the node failed. The description is an alist ;; (TRANSFORM . ARGS), where TRANSFORM is the structure describing ;; the transform that failed, and ARGS is either a list of format - ;; arguments for the note, or the FUNCTION-TYPE that would have + ;; 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-FUNCTIONS, but is used when a function has - ;; already been analyzed, but new references have been added by - ;; inline expansion. Unlike NEW-FUNCTIONS, this is not disjoint from - ;; COMPONENT-LAMBDAS. - (reanalyze-functions 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)) -;;; Before sbcl-0.7.0, there were :TOP-LEVEL things which were magical +;;; 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 ;;; visible/referenced (so don't delete it)". The code <0.7.0 did a lot @@ -425,16 +458,16 @@ ;;; this function is a sort of literal translation of those tests into ;;; the new world. ;;; -;;; FIXME: After things settle down, bare :TOP-LEVEL might go away, at +;;; FIXME: After things settle down, bare :TOPLEVEL might go away, at ;;; which time it might be possible to replace the COMPONENT-KIND -;;; :TOP-LEVEL mess with a flag COMPONENT-HAS-EXTERNAL-REFERENCES-P +;;; :TOPLEVEL mess with a flag COMPONENT-HAS-EXTERNAL-REFERENCES-P ;;; along the lines of FUNCTIONAL-HAS-EXTERNAL-REFERENCES-P. -(defun lambda-top-levelish-p (clambda) - (or (eql (lambda-kind clambda) :top-level) +(defun lambda-toplevelish-p (clambda) + (or (eql (lambda-kind clambda) :toplevel) (lambda-has-external-references-p clambda))) -(defun component-top-levelish-p (component) +(defun component-toplevelish-p (component) (member (component-kind component) - '(:top-level :complex-top-level))) + '(:toplevel :complex-toplevel))) ;;; A CLEANUP structure represents some dynamic binding action. Blocks ;;; are annotated with the current CLEANUP so that dynamic bindings @@ -450,7 +483,7 @@ ;;; change. (defstruct (cleanup (:copier nil)) ;; the kind of thing that has to be cleaned up - (kind (required-argument) + (kind (missing-arg) :type (member :special-bind :catch :unwind-protect :block :tagbody)) ;; the node that messes things up. This is the last node in the ;; non-messed-up environment. Null only temporarily. This could be @@ -488,7 +521,7 @@ ;;; TNs, or eventually stack slots and registers). -- WHN 2001-09-29 (defstruct (physenv (:copier nil)) ;; the function that allocates this physical environment - (function (required-argument) :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 +541,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)) @@ -527,7 +560,7 @@ ;;; end up tail-recursive causes TAIL-SET merging. (defstruct (tail-set) ;; a list of all the LAMBDAs in this tail set - (functions nil :type list) + (funs nil :type list) ;; our current best guess of the type returned by these functions. ;; This is the union across all the functions of the return node's ;; RESULT-TYPE, excluding local calls. @@ -535,12 +568,12 @@ ;; some info used by the back end (info nil)) (defprinter (tail-set :identity t) - functions + funs 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)) @@ -549,7 +582,7 @@ ;; and not the cleanup for the escape block. The CLEANUP-KIND of ;; this thus provides a good indication of what kind of exit is ;; being done. - (cleanup (required-argument) :type cleanup) + (cleanup (missing-arg) :type cleanup) ;; the continuation exited to (the CONT of the EXIT nodes). If this ;; exit is from an escape function (CATCH or UNWIND-PROTECT), then ;; physical environment analysis deletes the escape function and @@ -557,13 +590,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 (required-argument) :type 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,12 +615,31 @@ ;;; hacking the flow graph. (def!struct (leaf (:make-load-form-fun ignore-it) (:constructor nil)) - ;; some name for this leaf. The exact significance of the name - ;; depends on what kind of leaf it is. In a LAMBDA-VAR or - ;; GLOBAL-VAR, this is the symbol name of the variable. In a - ;; functional that is from a DEFUN, this is the defined name. In - ;; other functionals, this is a descriptive string. - (name nil :type t) + ;; 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 + ;; FOO) or 'N or '*Z*, or the special .ANONYMOUS. value if there's + ;; no name for this thing in the source (as can happen for + ;; FUNCTIONALs, e.g. for anonymous LAMBDAs or for functions for + ;; top-level forms; and can also happen for anonymous constants) or + ;; perhaps also if the match between the name and the thing is + ;; 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. + ;; + ;; See also the LEAF-DEBUG-NAME function and the + ;; FUNCTIONAL-%DEBUG-NAME slot. + (%source-name (missing-arg) + :type (or symbol (and cons (satisfies legal-fun-name-p))) + :read-only t) ;; the type which values of this leaf must have (type *universal-type* :type ctype) ;; where the TYPE information came from: @@ -607,6 +659,28 @@ ;; some kind of info used by the back end (info nil)) +;;; LEAF name operations +;;; +;;; KLUDGE: wants CLOS.. +(defun leaf-has-source-name-p (leaf) + (not (eq (leaf-%source-name leaf) + '.anonymous.))) +(defun leaf-source-name (leaf) + (aver (leaf-has-source-name-p leaf)) + (leaf-%source-name leaf)) +(defun leaf-debug-name (leaf) + (if (functional-p leaf) + ;; FUNCTIONALs have additional %DEBUG-NAME behavior. + (functional-debug-name leaf) + ;; Other objects just use their source name. + ;; + ;; (As of sbcl-0.pre7.85, there are a few non-FUNCTIONAL + ;; anonymous objects, (anonymous constants..) and those would + ;; fail here if we ever tried to get debug names from them, but + ;; it looks as though it's never interesting to get debug names + ;; from them, so it's moot. -- WHN) + (leaf-source-name leaf))) + ;;; The CONSTANT structure is used to represent known constant values. ;;; If NAME is not null, then it is the name of the named constant ;;; which this leaf corresponds to, otherwise this is an anonymous @@ -615,12 +689,13 @@ ;; the value of the constant (value nil :type t)) (defprinter (constant :identity t) - (name :test name) + (%source-name :test %source-name) value) ;;; The BASIC-VAR structure represents information common to all ;;; variables which don't correspond to known local functions. -(def!struct (basic-var (:include leaf) (:constructor nil)) +(def!struct (basic-var (:include leaf) + (:constructor nil)) ;; Lists of the set nodes for this variable. (sets () :type list)) @@ -629,48 +704,35 @@ ;;; constant, but don't know what the value is at compile time. (def!struct (global-var (:include basic-var)) ;; kind of variable described - (kind (required-argument) - :type (member :special :global-function :constant :global))) + (kind (missing-arg) + :type (member :special :global-function :global))) (defprinter (global-var :identity t) - name + %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 (required-argument) :type sb!xc:class) - ;; The slot description of the slot. - (slot (required-argument))) -(defprinter (slot-accessor :identity t) - name - for - slot) - -;;; The DEFINED-FUNCTION structure represents functions that are -;;; defined in the same compilation block, or that have inline -;;; expansions, or have a non-NIL INLINEP value. Whenever we change -;;; the INLINEP state (i.e. an inline proclamation) we copy the -;;; structure so that former INLINEP values are preserved. -(def!struct (defined-function (:include global-var - (where-from :defined) - (kind :global-function))) +;;; 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. +;;; an inline proclamation) we copy the structure so that former +;;; INLINEP values are preserved. +(def!struct (defined-fun (:include global-var + (where-from :defined) + (kind :global-function))) ;; The values of INLINEP and INLINE-EXPANSION initialized from the ;; global environment. (inlinep nil :type inlinep) (inline-expansion nil :type (or cons null)) - ;; The block-local definition of this function (either because it - ;; was semi-inline, or because it was defined in this block.) If + ;; the block-local definition of this function (either because it + ;; was semi-inline, or because it was defined in this block). If ;; this function is not an entry point, then this may be deleted or - ;; let-converted. Null if we haven't converted the expansion yet. + ;; LET-converted. Null if we haven't converted the expansion yet. (functional nil :type (or functional null))) -(defprinter (defined-function :identity t) - name +(defprinter (defined-fun :identity t) + %source-name + #!+sb-show id inlinep (functional :test functional)) @@ -680,10 +742,52 @@ ;;; We don't normally manipulate function types for defined functions, ;;; but if someone wants to know, an approximation is there. (def!struct (functional (:include leaf + (%source-name '.anonymous.) (where-from :defined) (type (specifier-type 'function)))) - ;; Some information about how this function is used. These values are - ;; meaningful: + ;; (For public access to this slot, use LEAF-DEBUG-NAME.) + ;; + ;; the name of FUNCTIONAL for debugging purposes, or NIL if we + ;; should just let the SOURCE-NAME fall through + ;; + ;; Unlike the SOURCE-NAME slot, this slot's value should never + ;; affect ordinary code behavior, only debugging/diagnostic behavior. + ;; + ;; The value of this slot can be anything, except that it shouldn't + ;; be a legal function name, since otherwise debugging gets + ;; confusing. (If a legal function name is a good name for the + ;; function, it should be in %SOURCE-NAME, and then we shouldn't + ;; need a %DEBUG-NAME.) In SBCL as of 0.pre7.87, it's always a + ;; string unless it's NIL, since that's how CMU CL represented debug + ;; names. However, eventually I (WHN) think it we should start using + ;; list values instead, since they have much nicer print properties + ;; (abbreviation, skipping package prefixes when unneeded, and + ;; renaming package prefixes when we do things like renaming SB!EXT + ;; to SB-EXT). + ;; + ;; E.g. for the function which implements (DEFUN FOO ...), we could + ;; have + ;; %SOURCE-NAME=FOO + ;; %DEBUG-NAME=NIL + ;; for the function which implements the top level form + ;; (IN-PACKAGE :FOO) we could have + ;; %SOURCE-NAME=NIL + ;; %DEBUG-NAME="top level form (IN-PACKAGE :FOO)" + ;; for the function which implements FOO in + ;; (DEFUN BAR (...) (FLET ((FOO (...) ...)) ...)) + ;; we could have + ;; %SOURCE-NAME=FOO + ;; %DEBUG-NAME="FLET FOO in BAR" + ;; and for the function which implements FOO in + ;; (DEFMACRO FOO (...) ...) + ;; we could have + ;; %SOURCE-NAME=FOO (or maybe .ANONYMOUS.?) + ;; %DEBUG-NAME="DEFMACRO FOO" + (%debug-name nil + :type (or null (not (satisfies legal-fun-name-p))) + :read-only t) + ;; some information about how this function is used. These values + ;; are meaningful: ;; ;; NIL ;; an ordinary function, callable using local call @@ -695,14 +799,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 @@ -710,19 +816,19 @@ ;; ;; :EXTERNAL ;; an external entry point lambda. The function it is an entry - ;; for is in the ENTRY-FUNCTION slot. + ;; for is in the ENTRY-FUN slot. ;; - ;; :TOP-LEVEL - ;; a top-level lambda, holding a compiled top-level form. + ;; :TOPLEVEL + ;; a top level lambda, holding a compiled top level form. ;; Compiled very much like NIL, but provides an indication of - ;; top-level context. A top-level lambda should have *no* - ;; references. Its Entry-Function is a self-pointer. + ;; top level context. A :TOPLEVEL lambda should have *no* + ;; references. Its ENTRY-FUN is a self-pointer. ;; - ;; :TOP-LEVEL-XEP - ;; After a component is compiled, we clobber any top-level code + ;; :TOPLEVEL-XEP + ;; After a component is compiled, we clobber any top level code ;; references to its non-closure XEPs with dummy FUNCTIONAL ;; structures having this kind. This prevents the retained - ;; top-level code from holding onto the IR for the code it + ;; top level code from holding onto the IR for the code it ;; references. ;; ;; :ESCAPE @@ -737,15 +843,15 @@ ;; :DELETED ;; This function has been found to be uncallable, and has been ;; marked for deletion. - (kind nil :type (member nil :optional :deleted :external :top-level + (kind nil :type (member nil :optional :deleted :external :toplevel :escape :cleanup :let :mv-let :assignment - :top-level-xep)) + :toplevel-xep)) ;; Is this a function that some external entity (e.g. the fasl dumper) ;; refers to, so that even when it appears to have no references, it ;; shouldn't be deleted? In the old days (before ;; sbcl-0.pre7.37.flaky5.2) this was sort of implicitly true when - ;; KIND was :TOP-LEVEL. Now it must be set explicitly, both for - ;; :TOP-LEVEL functions and for any other kind of functions that we + ;; KIND was :TOPLEVEL. Now it must be set explicitly, both for + ;; :TOPLEVEL functions and for any other kind of functions that we ;; want to dump or return from #'CL:COMPILE or whatever. (has-external-references-p nil) ;; In a normal function, this is the external entry point (XEP) @@ -757,18 +863,19 @@ ;; In an XEP lambda (indicated by the :EXTERNAL kind), this is the ;; function that the XEP is an entry-point for. The body contains ;; local calls to all the actual entry points in the function. In a - ;; :TOP-LEVEL lambda (which is its own XEP) this is a self-pointer. + ;; :TOPLEVEL lambda (which is its own XEP) this is a self-pointer. ;; ;; With all other kinds, this is null. - (entry-function nil :type (or functional null)) - ;; the value of any inline/notinline declaration for a local function + (entry-fun nil :type (or functional null)) + ;; 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 @@ -776,7 +883,39 @@ ;; various rare miscellaneous info that drives code generation & stuff (plist () :type list)) (defprinter (functional :identity t) - name) + %source-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) + ;; FUNCTIONAL-%DEBUG-NAME takes precedence over FUNCTIONAL-SOURCE-NAME + ;; here because we want different debug names for the functions in + ;; DEFUN FOO and FLET FOO even though they have the same source name. + (or (functional-%debug-name functional) + ;; Note that this will cause an error if the function is + ;; anonymous. In SBCL (as opposed to CMU CL) we make all + ;; FUNCTIONALs have debug names. The CMU CL code didn't bother + ;; in many FUNCTIONALs, especially those which were likely to be + ;; optimized away before the user saw them. However, getting + ;; that right requires a global understanding of the code, + ;; which seems bad, so we just require names for everything. + (leaf-source-name functional))) ;;; The CLAMBDA only deals with required lexical arguments. Special, ;;; optional, keyword and rest arguments are handled by transforming @@ -786,8 +925,8 @@ (:predicate lambda-p) (:constructor make-lambda) (:copier copy-lambda)) - ;; list of LAMBDA-VAR descriptors for args - (vars nil :type list) + ;; list of LAMBDA-VAR descriptors for arguments + (vars nil :type list :read-only t) ;; If this function was ever a :OPTIONAL function (an entry-point ;; for an OPTIONAL-DISPATCH), then this is that OPTIONAL-DISPATCH. ;; The optional dispatch will be :DELETED if this function is no @@ -809,17 +948,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 @@ -841,10 +979,12 @@ ;; in effect. (call-lexenv nil :type (or lexenv null))) (defprinter (clambda :conc-name lambda- :identity t) - name + %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-name vars))) + (vars :prin1 (mapcar #'leaf-source-name vars))) ;;; The OPTIONAL-DISPATCH leaf is used to represent hairy lambdas. It ;;; is a FUNCTIONAL, like LAMBDA. Each legal number of arguments has a @@ -900,7 +1040,9 @@ ;; know what they are doing. (main-entry nil :type (or clambda null))) (defprinter (optional-dispatch :identity t) - name + %source-name + %debug-name + #!+sb-show id (type :test (not (eq type *universal-type*))) (where-from :test (not (eq where-from :assumed))) arglist @@ -921,8 +1063,9 @@ (specialp nil :type boolean) ;; the kind of argument being described. Required args only have arg ;; info structures if they are special. - (kind (required-argument) :type (member :required :optional :keyword :rest - :more-context :more-count)) + (kind (missing-arg) + :type (member :required :optional :keyword :rest + :more-context :more-count)) ;; If true, this is the VAR for SUPPLIED-P variable of a keyword or ;; optional arg. This is true for keywords with non-constant ;; defaults even when there is no user-specified supplied-p var. @@ -931,8 +1074,8 @@ ;; original Lisp code. This is set to NIL in &KEY arguments that are ;; defaulted using the SUPPLIED-P arg. (default nil :type t) - ;; the actual key for a &KEY argument. Note that in ANSI CL this is not - ;; necessarily a keyword: (DEFUN FOO (&KEY ((BAR BAR))) ..). + ;; the actual key for a &KEY argument. Note that in ANSI CL this is + ;; not necessarily a keyword: (DEFUN FOO (&KEY ((BAR BAR))) ...). (key nil :type symbol)) (defprinter (arg-info :identity t) (specialp :test specialp) @@ -949,8 +1092,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) @@ -976,7 +1119,8 @@ ;; good subject for flow analysis. (constraints nil :type (or sset null))) (defprinter (lambda-var :identity t) - name + %source-name + #!+sb-show id (type :test (not (eq type *universal-type*))) (where-from :test (not (eq where-from :assumed))) (ignorep :test ignorep) @@ -988,12 +1132,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. @@ -1005,11 +1150,11 @@ (:constructor make-if) (:copier copy-if)) ;; CONTINUATION for the predicate - (test (required-argument) :type continuation) + (test (missing-arg) :type continuation) ;; the blocks that we execute next in true and false case, ;; respectively (may be the same) - (consequent (required-argument) :type cblock) - (alternative (required-argument) :type cblock)) + (consequent (missing-arg) :type cblock) + (alternative (missing-arg) :type cblock)) (defprinter (cif :conc-name if- :identity t) (test :prin1 (continuation-use test)) consequent @@ -1022,9 +1167,9 @@ (:constructor make-set) (:copier copy-set)) ;; descriptor for the variable set - (var (required-argument) :type basic-var) + (var (missing-arg) :type basic-var) ;; continuation for the value form - (value (required-argument) :type continuation)) + (value (missing-arg) :type continuation)) (defprinter (cset :conc-name set- :identity t) var (value :prin1 (continuation-use value))) @@ -1038,7 +1183,7 @@ (:constructor nil) (:copier nil)) ;; continuation for the function - (fun (required-argument) :type continuation) + (fun (missing-arg) :type continuation) ;; list of CONTINUATIONs for the args. In a local call, an argument ;; continuation may be replaced with NIL to indicate that the ;; corresponding variable is unreferenced, and thus no argument @@ -1047,12 +1192,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)) @@ -1063,6 +1208,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 @@ -1103,7 +1249,7 @@ ;; ir1tran. (lambda nil :type (or clambda null)) ;; the continuation which yields the value of the lambda - (result (required-argument) :type continuation) + (result (missing-arg) :type continuation) ;; the union of the node-derived-type of all uses of the result ;; other than by a local call, intersected with the result's ;; asserted-type. If there are no non-call uses, this is @@ -1119,15 +1265,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 @@ -1137,15 +1284,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)) @@ -1160,7 +1308,7 @@ ;; the name of the unknown thing (name nil :type (or symbol list)) ;; the kind of reference to NAME - (kind (required-argument) :type (member :function :type :variable)) + (kind (missing-arg) :type (member :function :type :variable)) ;; the number of times this thing was used (count 0 :type unsigned-byte) ;; a list of COMPILER-ERROR-CONTEXT structures describing places