;; 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
;;; 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))
;; the kind of component
;;
;; 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
;; :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
;; 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-FUNS 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-funs () :type list)
;; If this is true, then there is stuff in this component that could
;; benefit from further IR1 optimization.
(reoptimize t :type boolean)
;; 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
+ ;; 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-FUNCTIONS, this is not disjoint from
+ ;; inline expansion. Unlike NEW-FUNS, this is not disjoint from
;; COMPONENT-LAMBDAS.
- (reanalyze-functions nil :type list))
+ (reanalyze-funs nil :type list))
(defprinter (component :identity t)
name
(reanalyze :test reanalyze))
-;;; Before sbcl-0.7.0, there were :TOP-LEVEL things which were magical
+;;; 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
;;; 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
;;; 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
;; 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))
;;; 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.
;; some info used by the back end
(info nil))
(defprinter (tail-set :identity t)
- functions
+ funs
type
(info :test info))
;;; 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.
+ ;; (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
+ ;;
+ ;; The value of this slot in can affect ordinary runtime behavior,
+ ;; e.g. of special variables and known functions, not just debugging.
;;
- ;; KLUDGE: Note that at least for LAMBDA-VARs, this is important not
- ;; just for debugging but for ordinary compilation as well. In
- ;; particular, in RECOGNIZE-KNOWN-CALL function calls are compiled
- ;; differently based on the LEAF-NAME.
- (name nil :type t)
+ ;; 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:
;; 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
;; 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))
(kind (missing-arg)
:type (member :special :global-function :global)))
(defprinter (global-var :identity t)
- name
+ %source-name
(type :test (not (eq type *universal-type*)))
(where-from :test (not (eq where-from :assumed)))
kind)
;; The slot description of the slot.
(slot (missing-arg)))
(defprinter (slot-accessor :identity t)
- name
+ %source-name
for
slot)
;; LET-converted. Null if we haven't converted the expansion yet.
(functional nil :type (or functional null)))
(defprinter (defined-fun :identity t)
- name
+ %source-name
inlinep
(functional :test functional))
\f
;;; 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))))
+ ;; (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:
;;
;;
;; :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
;; :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)
;; 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))
+ (entry-fun nil :type (or functional null))
;; the value of any inline/notinline declaration for a local function
(inlinep nil :type inlinep)
;; If we have a lambda that can be used as in inline expansion for
;; various rare miscellaneous info that drives code generation & stuff
(plist () :type list))
(defprinter (functional :identity t)
- name)
+ %source-name
+ %debug-name)
+
+;;; 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
(: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
;; in effect.
(call-lexenv nil :type (or lexenv null)))
(defprinter (clambda :conc-name lambda- :identity t)
- name
+ %source-name
+ %debug-name
(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
;; know what they are doing.
(main-entry nil :type (or clambda null)))
(defprinter (optional-dispatch :identity t)
- name
+ %source-name
+ %debug-name
(type :test (not (eq type *universal-type*)))
(where-from :test (not (eq where-from :assumed)))
arglist
;; 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)
;;; 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)
;; good subject for flow analysis.
(constraints nil :type (or sset null)))
(defprinter (lambda-var :identity t)
- name
+ %source-name
(type :test (not (eq type *universal-type*)))
(where-from :test (not (eq where-from :assumed)))
(ignorep :test ignorep)