1 ;;;; structures for the first intermediate representation in the
4 ;;;; This software is part of the SBCL system. See the README file for
7 ;;;; This software is derived from the CMU CL system, which was
8 ;;;; written at Carnegie Mellon University and released into the
9 ;;;; public domain. The software is in the public domain and is
10 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
11 ;;;; files for more information.
15 ;;; The front-end data structure (IR1) is composed of nodes and
16 ;;; continuations. The general idea is that continuations contain
17 ;;; top-down information and nodes contain bottom-up, derived
18 ;;; information. A continuation represents a place in the code, while
19 ;;; a node represents code that does something.
21 ;;; This representation is more of a flow-graph than an augmented
22 ;;; syntax tree. The evaluation order is explicitly represented in the
23 ;;; linkage by continuations, rather than being implicit in the nodes
24 ;;; which receive the the results of evaluation. This allows us to
25 ;;; decouple the flow of results from the flow of control. A
26 ;;; continuation represents both, but the continuation can represent
27 ;;; the case of a discarded result by having no DEST.
29 (def!struct (continuation
30 (:make-load-form-fun ignore-it)
31 (:constructor make-continuation (&optional dest)))
32 ;; an indication of the way that this continuation is currently used
35 ;; A continuation for which all control-related slots have the
36 ;; default values. A continuation is unused during IR1 conversion
37 ;; until it is assigned a block, and may be also be temporarily
38 ;; unused during later manipulations of IR1. In a consistent
39 ;; state there should never be any mention of :UNUSED
40 ;; continuations. Next can have a non-null value if the next node
41 ;; has already been determined.
44 ;; A continuation that has been deleted from IR1. Any pointers into
45 ;; IR1 are cleared. There are two conditions under which a deleted
46 ;; continuation may appear in code:
47 ;; -- The CONT of the LAST node in a block may be a deleted
48 ;; continuation when the original receiver of the continuation's
49 ;; value was deleted. Note that DEST in a deleted continuation is
50 ;; null, so it is easy to know not to attempt delivering any
51 ;; values to the continuation.
52 ;; -- Unreachable code that hasn't been deleted yet may receive
53 ;; deleted continuations. All such code will be in blocks that
54 ;; have DELETE-P set. All unreachable code is deleted by control
55 ;; optimization, so the backend doesn't have to worry about this.
58 ;; The continuation that is the START of BLOCK. This is the only kind
59 ;; of continuation that can have more than one use. The BLOCK's
60 ;; START-USES is a list of all the uses.
62 ;; :DELETED-BLOCK-START
63 ;; Like :BLOCK-START, but BLOCK has been deleted. A block
64 ;; starting continuation is made into a deleted block start when
65 ;; the block is deleted, but the continuation still may have
66 ;; value semantics. Since there isn't any code left, next is
70 ;; A continuation that is the CONT of some node in BLOCK.
71 (kind :unused :type (member :unused :deleted :inside-block :block-start
72 :deleted-block-start))
73 ;; The node which receives this value, if any. In a deleted
74 ;; continuation, this is null even though the node that receives
75 ;; this continuation may not yet be deleted.
76 (dest nil :type (or node null))
77 ;; If this is a NODE, then it is the node which is to be evaluated
78 ;; next. This is always null in :DELETED and :UNUSED continuations,
79 ;; and will be null in a :INSIDE-BLOCK continuation when this is the
81 (next nil :type (or node null))
82 ;; an assertion on the type of this continuation's value
83 (asserted-type *wild-type* :type ctype)
84 ;; cached type of this continuation's value. If NIL, then this must
85 ;; be recomputed: see CONTINUATION-DERIVED-TYPE.
86 (%derived-type nil :type (or ctype null))
87 ;; the node where this continuation is used, if unique. This is always
88 ;; null in :DELETED and :UNUSED continuations, and is never null in
89 ;; :INSIDE-BLOCK continuations. In a :BLOCK-START continuation, the
90 ;; Block's START-USES indicate whether NIL means no uses or more
92 (use nil :type (or node null))
93 ;; the basic block this continuation is in. This is null only in
94 ;; :DELETED and :UNUSED continuations. Note that blocks that are
95 ;; unreachable but still in the DFO may receive deleted
96 ;; continuations, so it isn't o.k. to assume that any continuation
97 ;; that you pick up out of its DEST node has a BLOCK.
98 (block nil :type (or cblock null))
99 ;; set to true when something about this continuation's value has
100 ;; changed. See REOPTIMIZE-CONTINUATION. This provides a way for IR1
101 ;; optimize to determine which operands to a node have changed. If
102 ;; the optimizer for this node type doesn't care, it can elect not
103 ;; to clear this flag.
104 (reoptimize t :type boolean)
105 ;; an indication of what we have proven about how this contination's
106 ;; type assertion is satisfied:
109 ;; No type check is necessary (proven type is a subtype of the assertion.)
112 ;; A type check is needed.
115 ;; Don't do a type check, but believe (intersect) the assertion.
116 ;; A T check can be changed to :DELETED if we somehow prove the
117 ;; check is unnecessary, or if we eliminate it through a policy
121 ;; Type check generation sets the slot to this if a check is
122 ;; called for, but it believes it has proven that the check won't
123 ;; be done for policy reasons or because a safe implementation
124 ;; will be used. In the latter case, LTN must ensure that a safe
125 ;; implementation *is* used.
127 ;; This is computed lazily by CONTINUATION-DERIVED-TYPE, so use
128 ;; CONTINUATION-TYPE-CHECK instead of the %'ed slot accessor.
129 (%type-check t :type (member t nil :deleted :no-check))
130 ;; something or other that the back end annotates this continuation with
132 ;; uses of this continuation in the lexical environment. They are
133 ;; recorded so that when one continuation is substituted for another
134 ;; the environment may be updated properly.
135 (lexenv-uses nil :type list))
137 (def!method print-object ((x continuation) stream)
138 (print-unreadable-object (x stream :type t :identity t)))
140 (defstruct (node (:constructor nil)
142 ;; unique ID for debugging
143 #!+sb-show (id (new-object-id) :read-only t)
144 ;; the bottom-up derived type for this node. This does not take into
145 ;; consideration output type assertions on this node (actually on its CONT).
146 (derived-type *wild-type* :type ctype)
147 ;; True if this node needs to be optimized. This is set to true
148 ;; whenever something changes about the value of a continuation
149 ;; whose DEST is this node.
150 (reoptimize t :type boolean)
151 ;; the continuation which receives the value of this node. This also
152 ;; indicates what we do controlwise after evaluating this node. This
153 ;; may be null during IR1 conversion.
154 (cont nil :type (or continuation null))
155 ;; the continuation that this node is the next of. This is null
156 ;; during IR1 conversion when we haven't linked the node in yet or
157 ;; in nodes that have been deleted from the IR1 by UNLINK-NODE.
158 (prev nil :type (or continuation null))
159 ;; the lexical environment this node was converted in
160 (lexenv *lexenv* :type lexenv)
161 ;; a representation of the source code responsible for generating
164 ;; For a form introduced by compilation (does not appear in the
165 ;; original source), the path begins with a list of all the
166 ;; enclosing introduced forms. This list is from the inside out,
167 ;; with the form immediately responsible for this node at the head
170 ;; Following the introduced forms is a representation of the
171 ;; location of the enclosing original source form. This transition
172 ;; is indicated by the magic ORIGINAL-SOURCE-START marker. The first
173 ;; element of the original source is the "form number", which is the
174 ;; ordinal number of this form in a depth-first, left-to-right walk
175 ;; of the truly-top-level form in which this appears.
177 ;; Following is a list of integers describing the path taken through
178 ;; the source to get to this point:
179 ;; (K L M ...) => (NTH K (NTH L (NTH M ...)))
181 ;; The last element in the list is the top level form number, which
182 ;; is the ordinal number (in this call to the compiler) of the truly
183 ;; top level form containing the original source.
184 (source-path *current-path* :type list)
185 ;; If this node is in a tail-recursive position, then this is set to
186 ;; T. At the end of IR1 (in physical environment analysis) this is
187 ;; computed for all nodes (after cleanup code has been emitted).
188 ;; Before then, a non-null value indicates that IR1 optimization has
189 ;; converted a tail local call to a direct transfer.
191 ;; If the back-end breaks tail-recursion for some reason, then it
192 ;; can null out this slot.
193 (tail-p nil :type boolean))
195 ;;; Flags that are used to indicate various things about a block, such
196 ;;; as what optimizations need to be done on it:
197 ;;; -- REOPTIMIZE is set when something interesting happens the uses of a
198 ;;; continuation whose DEST is in this block. This indicates that the
199 ;;; value-driven (forward) IR1 optimizations should be done on this block.
200 ;;; -- FLUSH-P is set when code in this block becomes potentially flushable,
201 ;;; usually due to a continuation's DEST becoming null.
202 ;;; -- TYPE-CHECK is true when the type check phase should be run on this
203 ;;; block. IR1 optimize can introduce new blocks after type check has
204 ;;; already run. We need to check these blocks, but there is no point in
205 ;;; checking blocks we have already checked.
206 ;;; -- DELETE-P is true when this block is used to indicate that this block
207 ;;; has been determined to be unreachable and should be deleted. IR1
208 ;;; phases should not attempt to examine or modify blocks with DELETE-P
209 ;;; set, since they may:
210 ;;; - be in the process of being deleted, or
211 ;;; - have no successors, or
212 ;;; - receive :DELETED continuations.
213 ;;; -- TYPE-ASSERTED, TEST-MODIFIED
214 ;;; These flags are used to indicate that something in this block
215 ;;; might be of interest to constraint propagation. TYPE-ASSERTED
216 ;;; is set when a continuation type assertion is strengthened.
217 ;;; TEST-MODIFIED is set whenever the test for the ending IF has
218 ;;; changed (may be true when there is no IF.)
219 (def-boolean-attribute block
220 reoptimize flush-p type-check delete-p type-asserted test-modified)
222 ;;; FIXME: Tweak so that definitions of e.g. BLOCK-DELETE-P is
223 ;;; findable by grep for 'def.*block-delete-p'.
224 (macrolet ((frob (slot)
225 `(defmacro ,(symbolicate "BLOCK-" slot) (block)
226 `(block-attributep (block-flags ,block) ,',slot))))
232 (frob test-modified))
234 ;;; The CBLOCK structure represents a basic block. We include
235 ;;; SSET-ELEMENT so that we can have sets of blocks. Initially the
236 ;;; SSET-ELEMENT-NUMBER is null, DFO analysis numbers in reverse DFO.
237 ;;; During IR2 conversion, IR1 blocks are re-numbered in forward emit
238 ;;; order. This latter numbering also forms the basis of the block
239 ;;; numbering in the debug-info (though that is relative to the start
240 ;;; of the function.)
241 (defstruct (cblock (:include sset-element)
242 (:constructor make-block (start))
243 (:constructor make-block-key)
246 (:copier copy-block))
247 ;; a list of all the blocks that are predecessors/successors of this
248 ;; block. In well-formed IR1, most blocks will have one successor.
249 ;; The only exceptions are:
250 ;; 1. component head blocks (any number)
251 ;; 2. blocks ending in an IF (1 or 2)
252 ;; 3. blocks with DELETE-P set (zero)
253 (pred nil :type list)
254 (succ nil :type list)
255 ;; the continuation which heads this block (either a :BLOCK-START or
256 ;; :DELETED-BLOCK-START), or NIL when we haven't made the start
257 ;; continuation yet (and in the dummy component head and tail
259 (start nil :type (or continuation null))
260 ;; a list of all the nodes that have START as their CONT
261 (start-uses nil :type list)
262 ;; the last node in this block. This is NIL when we are in the
263 ;; process of building a block (and in the dummy component head and
265 (last nil :type (or node null))
266 ;; the forward and backward links in the depth-first ordering of the
267 ;; blocks. These slots are NIL at beginning/end.
268 (next nil :type (or null cblock))
269 (prev nil :type (or null cblock))
270 ;; This block's attributes: see above.
271 (flags (block-attributes reoptimize flush-p type-check type-asserted
274 ;; CMU CL had a KILL slot here, documented as "set used by
275 ;; constraint propagation", which was used in constraint propagation
276 ;; as a list of LAMBDA-VARs killed, and in copy propagation as an
277 ;; SSET, representing I dunno what. I (WHN) found this confusing,
278 ;; and furthermore it caused type errors when I was trying to make
279 ;; the compiler produce fully general LAMBDA functions directly
280 ;; (instead of doing as CMU CL always did, producing extra little
281 ;; functions which return the LAMDBA you need) and therefore taking
282 ;; a new path through the compiler. So I split this into two:
283 ;; KILL-LIST = list of LAMBDA-VARs killed, used in constraint propagation
284 ;; KILL-SSET = an SSET value, used in copy propagation
285 (kill-list nil :type list)
286 (kill-sset nil :type (or sset null))
287 ;; other sets used in constraint propagation and/or copy propagation
291 ;; the component this block is in, or NIL temporarily during IR1
292 ;; conversion and in deleted blocks
294 (aver-live-component *current-component*)
296 :type (or component null))
297 ;; a flag used by various graph-walking code to determine whether
298 ;; this block has been processed already or what. We make this
299 ;; initially NIL so that FIND-INITIAL-DFO doesn't have to scan the
300 ;; entire initial component just to clear the flags.
302 ;; some kind of info used by the back end
304 ;; If true, then constraints that hold in this block and its
305 ;; successors by merit of being tested by its IF predecessor.
306 (test-constraint nil :type (or sset null)))
307 (def!method print-object ((cblock cblock) stream)
308 (print-unreadable-object (cblock stream :type t :identity t)
309 (format stream ":START c~W" (cont-num (block-start cblock)))))
311 ;;; The BLOCK-ANNOTATION class is inherited (via :INCLUDE) by
312 ;;; different BLOCK-INFO annotation structures so that code
313 ;;; (specifically control analysis) can be shared.
314 (defstruct (block-annotation (:constructor nil)
316 ;; The IR1 block that this block is in the INFO for.
317 (block (missing-arg) :type cblock)
318 ;; the next and previous block in emission order (not DFO). This
319 ;; determines which block we drop though to, and is also used to
320 ;; chain together overflow blocks that result from splitting of IR2
321 ;; blocks in lifetime analysis.
322 (next nil :type (or block-annotation null))
323 (prev nil :type (or block-annotation null)))
325 ;;; A COMPONENT structure provides a handle on a connected piece of
326 ;;; the flow graph. Most of the passes in the compiler operate on
327 ;;; COMPONENTs rather than on the entire flow graph.
329 ;;; According to the CMU CL internals/front.tex, the reason for
330 ;;; separating compilation into COMPONENTs is
331 ;;; to increase the efficiency of large block compilations. In
332 ;;; addition to improving locality of reference and reducing the
333 ;;; size of flow analysis problems, this allows back-end data
334 ;;; structures to be reclaimed after the compilation of each
336 (defstruct (component (:copier nil))
337 ;; unique ID for debugging
338 #!+sb-show (id (new-object-id) :read-only t)
339 ;; the kind of component
341 ;; (The terminology here is left over from before
342 ;; sbcl-0.pre7.34.flaky5.2, when there was no such thing as
343 ;; FUNCTIONAL-HAS-EXTERNAL-REFERENCES-P, so that Python was
344 ;; incapable of building standalone :EXTERNAL functions, but instead
345 ;; had to implement things like #'CL:COMPILE as FUNCALL of a little
346 ;; toplevel stub whose sole purpose was to return an :EXTERNAL
349 ;; The possibilities are:
351 ;; an ordinary component, containing non-top-level code
353 ;; a component containing only load-time code
355 ;; In the old system, before FUNCTIONAL-HAS-EXTERNAL-REFERENCES-P
356 ;; was defined, this was necessarily a component containing both
357 ;; top level and run-time code. Now this state is also used for
358 ;; a component with HAS-EXTERNAL-REFERENCES-P functionals in it.
360 ;; the result of initial IR1 conversion, on which component
361 ;; analysis has not been done
363 ;; debris left over from component analysis
365 ;; See also COMPONENT-TOPLEVELISH-P.
366 (kind nil :type (member nil :toplevel :complex-toplevel :initial :deleted))
367 ;; the blocks that are the dummy head and tail of the DFO
369 ;; Entry/exit points have these blocks as their
370 ;; predecessors/successors. Null temporarily. The start and return
371 ;; from each non-deleted function is linked to the component head
372 ;; and tail. Until physical environment analysis links NLX entry
373 ;; stubs to the component head, every successor of the head is a
374 ;; function start (i.e. begins with a BIND node.)
375 (head nil :type (or null cblock))
376 (tail nil :type (or null cblock))
377 ;; This becomes a list of the CLAMBDA structures for all functions
378 ;; in this component. OPTIONAL-DISPATCHes are represented only by
379 ;; their XEP and other associated lambdas. This doesn't contain any
380 ;; deleted or LET lambdas.
382 ;; Note that logical associations between CLAMBDAs and COMPONENTs
383 ;; seem to exist for a while before this is initialized. See e.g.
384 ;; the NEW-FUNCTIONALS slot. In particular, I got burned by writing
385 ;; some code to use this value to decide which components need
386 ;; LOCALL-ANALYZE-COMPONENT, when it turns out that
387 ;; LOCALL-ANALYZE-COMPONENT had a role in initializing this value
388 ;; (and DFO stuff does too, maybe). Also, even after it's
389 ;; initialized, it might change as CLAMBDAs are deleted or merged.
391 (lambdas () :type list)
392 ;; a list of FUNCTIONALs for functions that are newly converted, and
393 ;; haven't been local-call analyzed yet. Initially functions are not
394 ;; in the LAMBDAS list. Local call analysis moves them there
395 ;; (possibly as LETs, or implicitly as XEPs if an OPTIONAL-DISPATCH.)
396 ;; Between runs of local call analysis there may be some debris of
397 ;; converted or even deleted functions in this list.
398 (new-functionals () :type list)
399 ;; If this is true, then there is stuff in this component that could
400 ;; benefit from further IR1 optimization.
401 (reoptimize t :type boolean)
402 ;; If this is true, then the control flow in this component was
403 ;; messed up by IR1 optimizations, so the DFO should be recomputed.
404 (reanalyze nil :type boolean)
405 ;; some sort of name for the code in this component
406 (name "<unknown>" :type simple-string)
407 ;; When I am a child, this is :NO-IR2-YET.
408 ;; In my adulthood, IR2 stores notes to itself here.
409 ;; After I have left the great wheel and am staring into the GC, this
410 ;; is set to :DEAD to indicate that it's a gruesome error to operate
411 ;; on me (e.g. by using me as *CURRENT-COMPONENT*, or by pushing
412 ;; LAMBDAs onto my NEW-FUNCTIONALS, as in sbcl-0.pre7.115).
413 (info :no-ir2-yet :type (or ir2-component (member :no-ir2-yet :dead)))
414 ;; the SOURCE-INFO structure describing where this component was
416 (source-info *source-info* :type source-info)
417 ;; count of the number of inline expansions we have done while
418 ;; compiling this component, to detect infinite or exponential
420 (inline-expansions 0 :type index)
421 ;; a map from combination nodes to things describing how an
422 ;; optimization of the node failed. The description is an alist
423 ;; (TRANSFORM . ARGS), where TRANSFORM is the structure describing
424 ;; the transform that failed, and ARGS is either a list of format
425 ;; arguments for the note, or the FUN-TYPE that would have
426 ;; enabled the transformation but failed to match.
427 (failed-optimizations (make-hash-table :test 'eq) :type hash-table)
428 ;; This is similar to NEW-FUNCTIONALS, but is used when a function
429 ;; has already been analyzed, but new references have been added by
430 ;; inline expansion. Unlike NEW-FUNCTIONALS, this is not disjoint
431 ;; from COMPONENT-LAMBDAS.
432 (reanalyze-functionals nil :type list))
433 (defprinter (component :identity t)
436 (reanalyze :test reanalyze))
438 ;;; Check that COMPONENT is suitable for roles which involve adding
439 ;;; new code. (gotta love imperative programming with lotso in-place
441 (defun aver-live-component (component)
442 ;; FIXME: As of sbcl-0.pre7.115, we're asserting that
443 ;; COMPILE-COMPONENT hasn't happened yet. Might it be even better
444 ;; (certainly stricter, possibly also correct...) to assert that
445 ;; IR1-FINALIZE hasn't happened yet?
446 (aver (not (eql (component-info component) :dead))))
448 ;;; Before sbcl-0.7.0, there were :TOPLEVEL things which were magical
449 ;;; in multiple ways. That's since been refactored into the orthogonal
450 ;;; properties "optimized for locall with no arguments" and "externally
451 ;;; visible/referenced (so don't delete it)". The code <0.7.0 did a lot
452 ;;; of tests a la (EQ KIND :TOP_LEVEL) in the "don't delete it?" sense;
453 ;;; this function is a sort of literal translation of those tests into
456 ;;; FIXME: After things settle down, bare :TOPLEVEL might go away, at
457 ;;; which time it might be possible to replace the COMPONENT-KIND
458 ;;; :TOPLEVEL mess with a flag COMPONENT-HAS-EXTERNAL-REFERENCES-P
459 ;;; along the lines of FUNCTIONAL-HAS-EXTERNAL-REFERENCES-P.
460 (defun lambda-toplevelish-p (clambda)
461 (or (eql (lambda-kind clambda) :toplevel)
462 (lambda-has-external-references-p clambda)))
463 (defun component-toplevelish-p (component)
464 (member (component-kind component)
465 '(:toplevel :complex-toplevel)))
467 ;;; A CLEANUP structure represents some dynamic binding action. Blocks
468 ;;; are annotated with the current CLEANUP so that dynamic bindings
469 ;;; can be removed when control is transferred out of the binding
470 ;;; environment. We arrange for changes in dynamic bindings to happen
471 ;;; at block boundaries, so that cleanup code may easily be inserted.
472 ;;; The "mess-up" action is explicitly represented by a funny function
473 ;;; call or ENTRY node.
475 ;;; We guarantee that CLEANUPs only need to be done at block boundaries
476 ;;; by requiring that the exit continuations initially head their
477 ;;; blocks, and then by not merging blocks when there is a cleanup
479 (defstruct (cleanup (:copier nil))
480 ;; the kind of thing that has to be cleaned up
482 :type (member :special-bind :catch :unwind-protect :block :tagbody))
483 ;; the node that messes things up. This is the last node in the
484 ;; non-messed-up environment. Null only temporarily. This could be
485 ;; deleted due to unreachability.
486 (mess-up nil :type (or node null))
487 ;; a list of all the NLX-INFO structures whose NLX-INFO-CLEANUP is
488 ;; this cleanup. This is filled in by physical environment analysis.
489 (nlx-info nil :type list))
490 (defprinter (cleanup :identity t)
493 (nlx-info :test nlx-info))
495 ;;; A PHYSENV represents the result of physical environment analysis.
497 ;;; As far as I can tell from reverse engineering, this IR1 structure
498 ;;; represents the physical environment (which is probably not the
499 ;;; standard Lispy term for this concept, but I dunno what is the
500 ;;; standard term): those things in the lexical environment which a
501 ;;; LAMBDA actually interacts with. Thus in
502 ;;; (DEFUN FROB-THINGS (THINGS)
503 ;;; (DOLIST (THING THINGS)
504 ;;; (BLOCK FROBBING-ONE-THING
505 ;;; (MAPCAR (LAMBDA (PATTERN)
506 ;;; (WHEN (FITS-P THING PATTERN)
507 ;;; (RETURN-FROM FROB-THINGS (LIST :FIT THING PATTERN))))
509 ;;; the variables THINGS, THING, and PATTERN and the block names
510 ;;; FROB-THINGS and FROBBING-ONE-THING are all in the inner LAMBDA's
511 ;;; lexical environment, but of those only THING, PATTERN, and
512 ;;; FROB-THINGS are in its physical environment. In IR1, we largely
513 ;;; just collect the names of these things; in IR2 an IR2-PHYSENV
514 ;;; structure is attached to INFO and used to keep track of
515 ;;; associations between these names and less-abstract things (like
516 ;;; TNs, or eventually stack slots and registers). -- WHN 2001-09-29
517 (defstruct (physenv (:copier nil))
518 ;; the function that allocates this physical environment
519 (lambda (missing-arg) :type clambda :read-only t)
520 #| ; seems not to be used as of sbcl-0.pre7.51
521 ;; a list of all the lambdas that allocate variables in this
522 ;; physical environment
523 (lambdas nil :type list)
525 ;; This ultimately converges to a list of all the LAMBDA-VARs and
526 ;; NLX-INFOs needed from enclosing environments by code in this
527 ;; physical environment. In the meantime, it may be
528 ;; * NIL at object creation time
529 ;; * a superset of the correct result, generated somewhat later
530 ;; * smaller and smaller sets converging to the correct result as
531 ;; we notice and delete unused elements in the superset
532 (closure nil :type list)
533 ;; a list of NLX-INFO structures describing all the non-local exits
534 ;; into this physical environment
535 (nlx-info nil :type list)
536 ;; some kind of info used by the back end
538 (defprinter (physenv :identity t)
540 (closure :test closure)
541 (nlx-info :test nlx-info))
543 ;;; An TAIL-SET structure is used to accumulate information about
544 ;;; tail-recursive local calls. The "tail set" is effectively the
545 ;;; transitive closure of the "is called tail-recursively by"
548 ;;; All functions in the same tail set share the same TAIL-SET
549 ;;; structure. Initially each function has its own TAIL-SET, but when
550 ;;; IR1-OPTIMIZE-RETURN notices a tail local call, it joins the tail
551 ;;; sets of the called function and the calling function.
553 ;;; The tail set is somewhat approximate, because it is too early to
554 ;;; be sure which calls will be tail-recursive. Any call that *might*
555 ;;; end up tail-recursive causes TAIL-SET merging.
556 (defstruct (tail-set)
557 ;; a list of all the LAMBDAs in this tail set
558 (funs nil :type list)
559 ;; our current best guess of the type returned by these functions.
560 ;; This is the union across all the functions of the return node's
561 ;; RESULT-TYPE, excluding local calls.
562 (type *wild-type* :type ctype)
563 ;; some info used by the back end
565 (defprinter (tail-set :identity t)
570 ;;; An NLX-INFO structure is used to collect various information about
571 ;;; non-local exits. This is effectively an annotation on the
572 ;;; CONTINUATION, although it is accessed by searching in the
573 ;;; PHYSENV-NLX-INFO.
574 (def!struct (nlx-info (:make-load-form-fun ignore-it))
575 ;; the cleanup associated with this exit. In a catch or
576 ;; unwind-protect, this is the :CATCH or :UNWIND-PROTECT cleanup,
577 ;; and not the cleanup for the escape block. The CLEANUP-KIND of
578 ;; this thus provides a good indication of what kind of exit is
580 (cleanup (missing-arg) :type cleanup)
581 ;; the continuation exited to (the CONT of the EXIT nodes). If this
582 ;; exit is from an escape function (CATCH or UNWIND-PROTECT), then
583 ;; physical environment analysis deletes the escape function and
584 ;; instead has the %NLX-ENTRY use this continuation.
586 ;; This slot is primarily an indication of where this exit delivers
587 ;; its values to (if any), but it is also used as a sort of name to
588 ;; allow us to find the NLX-INFO that corresponds to a given exit.
589 ;; For this purpose, the ENTRY must also be used to disambiguate,
590 ;; since exits to different places may deliver their result to the
591 ;; same continuation.
592 (continuation (missing-arg) :type continuation)
593 ;; the entry stub inserted by physical environment analysis. This is
594 ;; a block containing a call to the %NLX-ENTRY funny function that
595 ;; has the original exit destination as its successor. Null only
597 (target nil :type (or cblock null))
598 ;; some kind of info used by the back end
600 (defprinter (nlx-info :identity t)
607 ;;; Variables, constants and functions are all represented by LEAF
608 ;;; structures. A reference to a LEAF is indicated by a REF node. This
609 ;;; allows us to easily substitute one for the other without actually
610 ;;; hacking the flow graph.
611 (def!struct (leaf (:make-load-form-fun ignore-it)
613 ;; unique ID for debugging
614 #!+sb-show (id (new-object-id) :read-only t)
615 ;; (For public access to this slot, use LEAF-SOURCE-NAME.)
617 ;; the name of LEAF as it appears in the source, e.g. 'FOO or '(SETF
618 ;; FOO) or 'N or '*Z*, or the special .ANONYMOUS. value if there's
619 ;; no name for this thing in the source (as can happen for
620 ;; FUNCTIONALs, e.g. for anonymous LAMBDAs or for functions for
621 ;; top-level forms; and can also happen for anonymous constants) or
622 ;; perhaps also if the match between the name and the thing is
623 ;; skewed enough (e.g. for macro functions or method functions) that
624 ;; we don't want to have that name affect compilation
626 ;; (We use .ANONYMOUS. here more or less the way we'd ordinarily use
627 ;; NIL, but we're afraid to use NIL because it's a symbol which could
628 ;; be the name of a leaf, if only the constant named NIL.)
630 ;; The value of this slot in can affect ordinary runtime behavior,
631 ;; e.g. of special variables and known functions, not just debugging.
633 ;; See also the LEAF-DEBUG-NAME function and the
634 ;; FUNCTIONAL-%DEBUG-NAME slot.
635 (%source-name (missing-arg)
636 :type (or symbol (and cons (satisfies legal-fun-name-p)))
638 ;; the type which values of this leaf must have
639 (type *universal-type* :type ctype)
640 ;; where the TYPE information came from:
641 ;; :DECLARED, from a declaration.
642 ;; :ASSUMED, from uses of the object.
643 ;; :DEFINED, from examination of the definition.
644 ;; FIXME: This should be a named type. (LEAF-WHERE-FROM? Or
645 ;; perhaps just WHERE-FROM, since it's not just used in LEAF,
646 ;; but also in various DEFINE-INFO-TYPEs in globaldb.lisp,
647 ;; and very likely elsewhere too.)
648 (where-from :assumed :type (member :declared :assumed :defined))
649 ;; list of the REF nodes for this leaf
651 ;; true if there was ever a REF or SET node for this leaf. This may
652 ;; be true when REFS and SETS are null, since code can be deleted.
653 (ever-used nil :type boolean)
654 ;; some kind of info used by the back end
657 ;;; LEAF name operations
659 ;;; KLUDGE: wants CLOS..
660 (defun leaf-has-source-name-p (leaf)
661 (not (eq (leaf-%source-name leaf)
663 (defun leaf-source-name (leaf)
664 (aver (leaf-has-source-name-p leaf))
665 (leaf-%source-name leaf))
666 (defun leaf-debug-name (leaf)
667 (if (functional-p leaf)
668 ;; FUNCTIONALs have additional %DEBUG-NAME behavior.
669 (functional-debug-name leaf)
670 ;; Other objects just use their source name.
672 ;; (As of sbcl-0.pre7.85, there are a few non-FUNCTIONAL
673 ;; anonymous objects, (anonymous constants..) and those would
674 ;; fail here if we ever tried to get debug names from them, but
675 ;; it looks as though it's never interesting to get debug names
676 ;; from them, so it's moot. -- WHN)
677 (leaf-source-name leaf)))
679 ;;; The CONSTANT structure is used to represent known constant values.
680 ;;; If NAME is not null, then it is the name of the named constant
681 ;;; which this leaf corresponds to, otherwise this is an anonymous
683 (def!struct (constant (:include leaf))
684 ;; the value of the constant
686 (defprinter (constant :identity t)
687 (%source-name :test %source-name)
690 ;;; The BASIC-VAR structure represents information common to all
691 ;;; variables which don't correspond to known local functions.
692 (def!struct (basic-var (:include leaf)
694 ;; Lists of the set nodes for this variable.
695 (sets () :type list))
697 ;;; The GLOBAL-VAR structure represents a value hung off of the symbol
698 ;;; NAME. We use a :CONSTANT VAR when we know that the thing is a
699 ;;; constant, but don't know what the value is at compile time.
700 (def!struct (global-var (:include basic-var))
701 ;; kind of variable described
703 :type (member :special :global-function :global)))
704 (defprinter (global-var :identity t)
707 (type :test (not (eq type *universal-type*)))
708 (where-from :test (not (eq where-from :assumed)))
711 ;;; A DEFINED-FUN represents a function that is defined in the same
712 ;;; compilation block, or that has an inline expansion, or that has a
713 ;;; non-NIL INLINEP value. Whenever we change the INLINEP state (i.e.
714 ;;; an inline proclamation) we copy the structure so that former
715 ;;; INLINEP values are preserved.
716 (def!struct (defined-fun (:include global-var
717 (where-from :defined)
718 (kind :global-function)))
719 ;; The values of INLINEP and INLINE-EXPANSION initialized from the
720 ;; global environment.
721 (inlinep nil :type inlinep)
722 (inline-expansion nil :type (or cons null))
723 ;; the block-local definition of this function (either because it
724 ;; was semi-inline, or because it was defined in this block). If
725 ;; this function is not an entry point, then this may be deleted or
726 ;; LET-converted. Null if we haven't converted the expansion yet.
727 (functional nil :type (or functional null)))
728 (defprinter (defined-fun :identity t)
732 (functional :test functional))
736 ;;; We default the WHERE-FROM and TYPE slots to :DEFINED and FUNCTION.
737 ;;; We don't normally manipulate function types for defined functions,
738 ;;; but if someone wants to know, an approximation is there.
739 (def!struct (functional (:include leaf
740 (%source-name '.anonymous.)
741 (where-from :defined)
742 (type (specifier-type 'function))))
743 ;; (For public access to this slot, use LEAF-DEBUG-NAME.)
745 ;; the name of FUNCTIONAL for debugging purposes, or NIL if we
746 ;; should just let the SOURCE-NAME fall through
748 ;; Unlike the SOURCE-NAME slot, this slot's value should never
749 ;; affect ordinary code behavior, only debugging/diagnostic behavior.
751 ;; The value of this slot can be anything, except that it shouldn't
752 ;; be a legal function name, since otherwise debugging gets
753 ;; confusing. (If a legal function name is a good name for the
754 ;; function, it should be in %SOURCE-NAME, and then we shouldn't
755 ;; need a %DEBUG-NAME.) In SBCL as of 0.pre7.87, it's always a
756 ;; string unless it's NIL, since that's how CMU CL represented debug
757 ;; names. However, eventually I (WHN) think it we should start using
758 ;; list values instead, since they have much nicer print properties
759 ;; (abbreviation, skipping package prefixes when unneeded, and
760 ;; renaming package prefixes when we do things like renaming SB!EXT
763 ;; E.g. for the function which implements (DEFUN FOO ...), we could
767 ;; for the function which implements the top level form
768 ;; (IN-PACKAGE :FOO) we could have
770 ;; %DEBUG-NAME="top level form (IN-PACKAGE :FOO)"
771 ;; for the function which implements FOO in
772 ;; (DEFUN BAR (...) (FLET ((FOO (...) ...)) ...))
775 ;; %DEBUG-NAME="FLET FOO in BAR"
776 ;; and for the function which implements FOO in
777 ;; (DEFMACRO FOO (...) ...)
779 ;; %SOURCE-NAME=FOO (or maybe .ANONYMOUS.?)
780 ;; %DEBUG-NAME="DEFMACRO FOO"
782 :type (or null (not (satisfies legal-fun-name-p)))
784 ;; some information about how this function is used. These values
788 ;; an ordinary function, callable using local call
791 ;; a lambda that is used in only one local call, and has in
792 ;; effect been substituted directly inline. The return node is
793 ;; deleted, and the result is computed with the actual result
794 ;; continuation for the call.
797 ;; Similar to :LET (as per FUNCTIONAL-LETLIKE-P), but the call
801 ;; similar to a LET (as per FUNCTIONAL-SOMEWHAT-LETLIKE-P), but
802 ;; can have other than one call as long as there is at most
803 ;; one non-tail call.
806 ;; a lambda that is an entry point for an OPTIONAL-DISPATCH.
807 ;; Similar to NIL, but requires greater caution, since local call
808 ;; analysis may create new references to this function. Also, the
809 ;; function cannot be deleted even if it has *no* references. The
810 ;; OPTIONAL-DISPATCH is in the LAMDBA-OPTIONAL-DISPATCH.
813 ;; an external entry point lambda. The function it is an entry
814 ;; for is in the ENTRY-FUN slot.
817 ;; a top level lambda, holding a compiled top level form.
818 ;; Compiled very much like NIL, but provides an indication of
819 ;; top level context. A :TOPLEVEL lambda should have *no*
820 ;; references. Its ENTRY-FUN is a self-pointer.
823 ;; After a component is compiled, we clobber any top level code
824 ;; references to its non-closure XEPs with dummy FUNCTIONAL
825 ;; structures having this kind. This prevents the retained
826 ;; top level code from holding onto the IR for the code it
831 ;; special functions used internally by CATCH and UNWIND-PROTECT.
832 ;; These are pretty much like a normal function (NIL), but are
833 ;; treated specially by local call analysis and stuff. Neither
834 ;; kind should ever be given an XEP even though they appear as
835 ;; args to funny functions. An :ESCAPE function is never actually
836 ;; called, and thus doesn't need to have code generated for it.
839 ;; This function has been found to be uncallable, and has been
840 ;; marked for deletion.
841 (kind nil :type (member nil :optional :deleted :external :toplevel
842 :escape :cleanup :let :mv-let :assignment
844 ;; Is this a function that some external entity (e.g. the fasl dumper)
845 ;; refers to, so that even when it appears to have no references, it
846 ;; shouldn't be deleted? In the old days (before
847 ;; sbcl-0.pre7.37.flaky5.2) this was sort of implicitly true when
848 ;; KIND was :TOPLEVEL. Now it must be set explicitly, both for
849 ;; :TOPLEVEL functions and for any other kind of functions that we
850 ;; want to dump or return from #'CL:COMPILE or whatever.
851 (has-external-references-p nil)
852 ;; In a normal function, this is the external entry point (XEP)
853 ;; lambda for this function, if any. Each function that is used
854 ;; other than in a local call has an XEP, and all of the
855 ;; non-local-call references are replaced with references to the
858 ;; In an XEP lambda (indicated by the :EXTERNAL kind), this is the
859 ;; function that the XEP is an entry-point for. The body contains
860 ;; local calls to all the actual entry points in the function. In a
861 ;; :TOPLEVEL lambda (which is its own XEP) this is a self-pointer.
863 ;; With all other kinds, this is null.
864 (entry-fun nil :type (or functional null))
865 ;; the value of any inline/notinline declaration for a local
866 ;; function (or NIL in any case if no inline expansion is available)
867 (inlinep nil :type inlinep)
868 ;; If we have a lambda that can be used as in inline expansion for
869 ;; this function, then this is it. If there is no source-level
870 ;; lambda corresponding to this function then this is null (but then
871 ;; INLINEP will always be NIL as well.)
872 (inline-expansion nil :type list)
873 ;; the lexical environment that the INLINE-EXPANSION should be converted in
874 (lexenv *lexenv* :type lexenv)
875 ;; the original function or macro lambda list, or :UNSPECIFIED if
876 ;; this is a compiler created function
877 (arg-documentation nil :type (or list (member :unspecified)))
878 ;; various rare miscellaneous info that drives code generation & stuff
879 (plist () :type list))
880 (defprinter (functional :identity t)
885 ;;; Is FUNCTIONAL LET-converted? (where we're indifferent to whether
886 ;;; it returns one value or multiple values)
887 (defun functional-letlike-p (functional)
888 (member (functional-kind functional)
891 ;;; Is FUNCTIONAL sorta LET-converted? (where even an :ASSIGNMENT counts)
893 ;;; FIXME: I (WHN) don't understand this one well enough to give a good
894 ;;; definition or even a good function name, it's just a literal copy
895 ;;; of a CMU CL idiom. Does anyone have a better name or explanation?
896 (defun functional-somewhat-letlike-p (functional)
897 (or (functional-letlike-p functional)
898 (eql (functional-kind functional) :assignment)))
900 ;;; FUNCTIONAL name operations
901 (defun functional-debug-name (functional)
902 ;; FUNCTIONAL-%DEBUG-NAME takes precedence over FUNCTIONAL-SOURCE-NAME
903 ;; here because we want different debug names for the functions in
904 ;; DEFUN FOO and FLET FOO even though they have the same source name.
905 (or (functional-%debug-name functional)
906 ;; Note that this will cause an error if the function is
907 ;; anonymous. In SBCL (as opposed to CMU CL) we make all
908 ;; FUNCTIONALs have debug names. The CMU CL code didn't bother
909 ;; in many FUNCTIONALs, especially those which were likely to be
910 ;; optimized away before the user saw them. However, getting
911 ;; that right requires a global understanding of the code,
912 ;; which seems bad, so we just require names for everything.
913 (leaf-source-name functional)))
915 ;;; The CLAMBDA only deals with required lexical arguments. Special,
916 ;;; optional, keyword and rest arguments are handled by transforming
917 ;;; into simpler stuff.
918 (def!struct (clambda (:include functional)
920 (:predicate lambda-p)
921 (:constructor make-lambda)
922 (:copier copy-lambda))
923 ;; list of LAMBDA-VAR descriptors for arguments
924 (vars nil :type list :read-only t)
925 ;; If this function was ever a :OPTIONAL function (an entry-point
926 ;; for an OPTIONAL-DISPATCH), then this is that OPTIONAL-DISPATCH.
927 ;; The optional dispatch will be :DELETED if this function is no
929 (optional-dispatch nil :type (or optional-dispatch null))
930 ;; the BIND node for this LAMBDA. This node marks the beginning of
931 ;; the lambda, and serves to explicitly represent the lambda binding
932 ;; semantics within the flow graph representation. This is null in
933 ;; deleted functions, and also in LETs where we deleted the call and
934 ;; bind (because there are no variables left), but have not yet
935 ;; actually deleted the LAMBDA yet.
936 (bind nil :type (or bind null))
937 ;; the RETURN node for this LAMBDA, or NIL if it has been deleted.
938 ;; This marks the end of the lambda, receiving the result of the
939 ;; body. In a LET, the return node is deleted, and the body delivers
940 ;; the value to the actual continuation. The return may also be
941 ;; deleted if it is unreachable.
942 (return nil :type (or creturn null))
943 ;; If this CLAMBDA is a LET, then this slot holds the LAMBDA whose
944 ;; LETS list we are in, otherwise it is a self-pointer.
945 (home nil :type (or clambda null))
946 ;; all the lambdas that have been LET-substituted in this lambda.
947 ;; This is only non-null in lambdas that aren't LETs.
948 (lets nil :type list)
949 ;; all the ENTRY nodes in this function and its LETs, or null in a LET
950 (entries nil :type list)
951 ;; CLAMBDAs which are locally called by this lambda, and other
952 ;; objects (closed-over LAMBDA-VARs and XEPs) which this lambda
953 ;; depends on in such a way that DFO shouldn't put them in separate
955 (calls-or-closes nil :type list)
956 ;; the TAIL-SET that this LAMBDA is in. This is null during creation.
958 ;; In CMU CL, and old SBCL, this was also NILed out when LET
959 ;; conversion happened. That caused some problems, so as of
960 ;; sbcl-0.pre7.37.flaky5.2 when I was trying to get the compiler to
961 ;; emit :EXTERNAL functions directly, and so now the value
962 ;; is no longer NILed out in LET conversion, but instead copied
963 ;; (so that any further optimizations on the rest of the tail
964 ;; set won't modify the value) if necessary.
965 (tail-set nil :type (or tail-set null))
966 ;; the structure which represents the phsical environment that this
967 ;; function's variables are allocated in. This is filled in by
968 ;; physical environment analysis. In a LET, this is EQ to our home's
969 ;; physical environment.
970 (physenv nil :type (or physenv null))
971 ;; In a LET, this is the NODE-LEXENV of the combination node. We
972 ;; retain it so that if the LET is deleted (due to a lack of vars),
973 ;; we will still have caller's lexenv to figure out which cleanup is
975 (call-lexenv nil :type (or lexenv null)))
976 (defprinter (clambda :conc-name lambda- :identity t)
980 (type :test (not (eq type *universal-type*)))
981 (where-from :test (not (eq where-from :assumed)))
982 (vars :prin1 (mapcar #'leaf-source-name vars)))
984 ;;; The OPTIONAL-DISPATCH leaf is used to represent hairy lambdas. It
985 ;;; is a FUNCTIONAL, like LAMBDA. Each legal number of arguments has a
986 ;;; function which is called when that number of arguments is passed.
987 ;;; The function is called with all the arguments actually passed. If
988 ;;; additional arguments are legal, then the LEXPR style MORE-ENTRY
989 ;;; handles them. The value returned by the function is the value
990 ;;; which results from calling the OPTIONAL-DISPATCH.
992 ;;; The theory is that each entry-point function calls the next entry
993 ;;; point tail-recursively, passing all the arguments passed in and
994 ;;; the default for the argument the entry point is for. The last
995 ;;; entry point calls the real body of the function. In the presence
996 ;;; of SUPPLIED-P args and other hair, things are more complicated. In
997 ;;; general, there is a distinct internal function that takes the
998 ;;; SUPPLIED-P args as parameters. The preceding entry point calls
999 ;;; this function with NIL filled in for the SUPPLIED-P args, while
1000 ;;; the current entry point calls it with T in the SUPPLIED-P
1003 ;;; Note that it is easy to turn a call with a known number of
1004 ;;; arguments into a direct call to the appropriate entry-point
1005 ;;; function, so functions that are compiled together can avoid doing
1007 (def!struct (optional-dispatch (:include functional))
1008 ;; the original parsed argument list, for anyone who cares
1009 (arglist nil :type list)
1010 ;; true if &ALLOW-OTHER-KEYS was supplied
1011 (allowp nil :type boolean)
1012 ;; true if &KEY was specified (which doesn't necessarily mean that
1013 ;; there are any &KEY arguments..)
1014 (keyp nil :type boolean)
1015 ;; the number of required arguments. This is the smallest legal
1016 ;; number of arguments.
1017 (min-args 0 :type unsigned-byte)
1018 ;; the total number of required and optional arguments. Args at
1019 ;; positions >= to this are &REST, &KEY or illegal args.
1020 (max-args 0 :type unsigned-byte)
1021 ;; list of the LAMBDAs which are the entry points for non-rest,
1022 ;; non-key calls. The entry for MIN-ARGS is first, MIN-ARGS+1
1023 ;; second, ... MAX-ARGS last. The last entry-point always calls the
1024 ;; main entry; in simple cases it may be the main entry.
1025 (entry-points nil :type list)
1026 ;; an entry point which takes MAX-ARGS fixed arguments followed by
1027 ;; an argument context pointer and an argument count. This entry
1028 ;; point deals with listifying rest args and parsing keywords. This
1029 ;; is null when extra arguments aren't legal.
1030 (more-entry nil :type (or clambda null))
1031 ;; the main entry-point into the function, which takes all arguments
1032 ;; including keywords as fixed arguments. The format of the
1033 ;; arguments must be determined by examining the arglist. This may
1034 ;; be used by callers that supply at least MAX-ARGS arguments and
1035 ;; know what they are doing.
1036 (main-entry nil :type (or clambda null)))
1037 (defprinter (optional-dispatch :identity t)
1041 (type :test (not (eq type *universal-type*)))
1042 (where-from :test (not (eq where-from :assumed)))
1048 (entry-points :test entry-points)
1049 (more-entry :test more-entry)
1052 ;;; The ARG-INFO structure allows us to tack various information onto
1053 ;;; LAMBDA-VARs during IR1 conversion. If we use one of these things,
1054 ;;; then the var will have to be massaged a bit before it is simple
1056 (def!struct arg-info
1057 ;; true if this arg is to be specially bound
1058 (specialp nil :type boolean)
1059 ;; the kind of argument being described. Required args only have arg
1060 ;; info structures if they are special.
1062 :type (member :required :optional :keyword :rest
1063 :more-context :more-count))
1064 ;; If true, this is the VAR for SUPPLIED-P variable of a keyword or
1065 ;; optional arg. This is true for keywords with non-constant
1066 ;; defaults even when there is no user-specified supplied-p var.
1067 (supplied-p nil :type (or lambda-var null))
1068 ;; the default for a keyword or optional, represented as the
1069 ;; original Lisp code. This is set to NIL in &KEY arguments that are
1070 ;; defaulted using the SUPPLIED-P arg.
1071 (default nil :type t)
1072 ;; the actual key for a &KEY argument. Note that in ANSI CL this is
1073 ;; not necessarily a keyword: (DEFUN FOO (&KEY ((BAR BAR))) ...).
1074 (key nil :type symbol))
1075 (defprinter (arg-info :identity t)
1076 (specialp :test specialp)
1078 (supplied-p :test supplied-p)
1079 (default :test default)
1082 ;;; The LAMBDA-VAR structure represents a lexical lambda variable.
1083 ;;; This structure is also used during IR1 conversion to describe
1084 ;;; lambda arguments which may ultimately turn out not to be simple
1087 ;;; LAMBDA-VARs with no REFs are considered to be deleted; physical
1088 ;;; environment analysis isn't done on these variables, so the back
1089 ;;; end must check for and ignore unreferenced variables. Note that a
1090 ;;; deleted LAMBDA-VAR may have sets; in this case the back end is
1091 ;;; still responsible for propagating the SET-VALUE to the set's CONT.
1092 (def!struct (lambda-var (:include basic-var))
1093 ;; true if this variable has been declared IGNORE
1094 (ignorep nil :type boolean)
1095 ;; the CLAMBDA that this var belongs to. This may be null when we are
1096 ;; building a lambda during IR1 conversion.
1097 (home nil :type (or null clambda))
1098 ;; This is set by physical environment analysis if it chooses an
1099 ;; indirect (value cell) representation for this variable because it
1100 ;; is both set and closed over.
1101 (indirect nil :type boolean)
1102 ;; The following two slots are only meaningful during IR1 conversion
1103 ;; of hairy lambda vars:
1105 ;; The ARG-INFO structure which holds information obtained from
1106 ;; &keyword parsing.
1107 (arg-info nil :type (or arg-info null))
1108 ;; if true, the GLOBAL-VAR structure for the special variable which
1109 ;; is to be bound to the value of this argument
1110 (specvar nil :type (or global-var null))
1111 ;; Set of the CONSTRAINTs on this variable. Used by constraint
1112 ;; propagation. This is left null by the lambda pre-pass if it
1113 ;; determine that this is a set closure variable, and is thus not a
1114 ;; good subject for flow analysis.
1115 (constraints nil :type (or sset null)))
1116 (defprinter (lambda-var :identity t)
1119 (type :test (not (eq type *universal-type*)))
1120 (where-from :test (not (eq where-from :assumed)))
1121 (ignorep :test ignorep)
1122 (arg-info :test arg-info)
1123 (specvar :test specvar))
1125 ;;;; basic node types
1127 ;;; A REF represents a reference to a LEAF. REF-REOPTIMIZE is
1128 ;;; initially (and forever) NIL, since REFs don't receive any values
1129 ;;; and don't have any IR1 optimizer.
1130 (defstruct (ref (:include node (reoptimize nil))
1131 (:constructor make-ref (derived-type leaf))
1133 ;; The leaf referenced.
1134 (leaf nil :type leaf))
1135 (defprinter (ref :identity t)
1139 ;;; Naturally, the IF node always appears at the end of a block.
1140 ;;; NODE-CONT is a dummy continuation, and is there only to keep
1142 (defstruct (cif (:include node)
1145 (:constructor make-if)
1147 ;; CONTINUATION for the predicate
1148 (test (missing-arg) :type continuation)
1149 ;; the blocks that we execute next in true and false case,
1150 ;; respectively (may be the same)
1151 (consequent (missing-arg) :type cblock)
1152 (alternative (missing-arg) :type cblock))
1153 (defprinter (cif :conc-name if- :identity t)
1154 (test :prin1 (continuation-use test))
1158 (defstruct (cset (:include node
1159 (derived-type *universal-type*))
1162 (:constructor make-set)
1164 ;; descriptor for the variable set
1165 (var (missing-arg) :type basic-var)
1166 ;; continuation for the value form
1167 (value (missing-arg) :type continuation))
1168 (defprinter (cset :conc-name set- :identity t)
1170 (value :prin1 (continuation-use value)))
1172 ;;; The BASIC-COMBINATION structure is used to represent both normal
1173 ;;; and multiple value combinations. In a local function call, this
1174 ;;; node appears at the end of its block and the body of the called
1175 ;;; function appears as the successor. The NODE-CONT remains the
1176 ;;; continuation which receives the value of the call.
1177 (defstruct (basic-combination (:include node)
1180 ;; continuation for the function
1181 (fun (missing-arg) :type continuation)
1182 ;; list of CONTINUATIONs for the args. In a local call, an argument
1183 ;; continuation may be replaced with NIL to indicate that the
1184 ;; corresponding variable is unreferenced, and thus no argument
1185 ;; value need be passed.
1186 (args nil :type list)
1187 ;; the kind of function call being made. :LOCAL means that this is a
1188 ;; local call to a function in the same component, and that argument
1189 ;; syntax checking has been done, etc. Calls to known global
1190 ;; functions are represented by storing the FUN-INFO for the
1191 ;; function in this slot. :FULL is a call to an (as yet) unknown
1192 ;; function. :ERROR is like :FULL, but means that we have discovered
1193 ;; that the call contains an error, and should not be reconsidered
1194 ;; for optimization.
1195 (kind :full :type (or (member :local :full :error) fun-info))
1196 ;; some kind of information attached to this node by the back end
1199 ;;; The COMBINATION node represents all normal function calls,
1200 ;;; including FUNCALL. This is distinct from BASIC-COMBINATION so that
1201 ;;; an MV-COMBINATION isn't COMBINATION-P.
1202 (defstruct (combination (:include basic-combination)
1203 (:constructor make-combination (fun))
1205 (defprinter (combination :identity t)
1207 (fun :prin1 (continuation-use fun))
1208 (args :prin1 (mapcar (lambda (x)
1210 (continuation-use x)
1214 ;;; An MV-COMBINATION is to MULTIPLE-VALUE-CALL as a COMBINATION is to
1215 ;;; FUNCALL. This is used to implement all the multiple-value
1216 ;;; receiving forms.
1217 (defstruct (mv-combination (:include basic-combination)
1218 (:constructor make-mv-combination (fun))
1220 (defprinter (mv-combination)
1221 (fun :prin1 (continuation-use fun))
1222 (args :prin1 (mapcar #'continuation-use args)))
1224 ;;; The BIND node marks the beginning of a lambda body and represents
1225 ;;; the creation and initialization of the variables.
1226 (defstruct (bind (:include node)
1228 ;; the lambda we are binding variables for. Null when we are
1229 ;; creating the LAMBDA during IR1 translation.
1230 (lambda nil :type (or clambda null)))
1234 ;;; The RETURN node marks the end of a lambda body. It collects the
1235 ;;; return values and represents the control transfer on return. This
1236 ;;; is also where we stick information used for TAIL-SET type
1238 (defstruct (creturn (:include node)
1239 (:conc-name return-)
1240 (:predicate return-p)
1241 (:constructor make-return)
1242 (:copier copy-return))
1243 ;; the lambda we are returning from. Null temporarily during
1245 (lambda nil :type (or clambda null))
1246 ;; the continuation which yields the value of the lambda
1247 (result (missing-arg) :type continuation)
1248 ;; the union of the node-derived-type of all uses of the result
1249 ;; other than by a local call, intersected with the result's
1250 ;; asserted-type. If there are no non-call uses, this is
1252 (result-type *wild-type* :type ctype))
1253 (defprinter (creturn :conc-name return- :identity t)
1257 ;;;; non-local exit support
1259 ;;;; In IR1, we insert special nodes to mark potentially non-local
1262 ;;; The ENTRY node serves to mark the start of the dynamic extent of a
1263 ;;; lexical exit. It is the mess-up node for the corresponding :ENTRY
1265 (defstruct (entry (:include node)
1267 ;; All of the EXIT nodes for potential non-local exits to this point.
1268 (exits nil :type list)
1269 ;; The cleanup for this entry. NULL only temporarily.
1270 (cleanup nil :type (or cleanup null)))
1271 (defprinter (entry :identity t)
1274 ;;; The EXIT node marks the place at which exit code would be emitted,
1275 ;;; if necessary. This is interposed between the uses of the exit
1276 ;;; continuation and the exit continuation's DEST. Instead of using
1277 ;;; the returned value being delivered directly to the exit
1278 ;;; continuation, it is delivered to our VALUE continuation. The
1279 ;;; original exit continuation is the exit node's CONT.
1280 (defstruct (exit (:include node)
1282 ;; the ENTRY node that this is an exit for. If null, this is a
1283 ;; degenerate exit. A degenerate exit is used to "fill" an empty
1284 ;; block (which isn't allowed in IR1.) In a degenerate exit, Value
1285 ;; is always also null.
1286 (entry nil :type (or entry null))
1287 ;; the continuation yielding the value we are to exit with. If NIL,
1288 ;; then no value is desired (as in GO).
1289 (value nil :type (or continuation null)))
1290 (defprinter (exit :identity t)
1293 (value :test value))
1295 ;;;; miscellaneous IR1 structures
1297 (defstruct (undefined-warning
1298 #-no-ansi-print-object
1299 (:print-object (lambda (x s)
1300 (print-unreadable-object (x s :type t)
1301 (prin1 (undefined-warning-name x) s))))
1303 ;; the name of the unknown thing
1304 (name nil :type (or symbol list))
1305 ;; the kind of reference to NAME
1306 (kind (missing-arg) :type (member :function :type :variable))
1307 ;; the number of times this thing was used
1308 (count 0 :type unsigned-byte)
1309 ;; a list of COMPILER-ERROR-CONTEXT structures describing places
1310 ;; where this thing was used. Note that we only record the first
1311 ;; *UNDEFINED-WARNING-LIMIT* calls.
1312 (warnings () :type list))
1314 ;;; a helper for the POLICY macro, defined late here so that the
1315 ;;; various type tests can be inlined
1316 (declaim (ftype (function ((or list lexenv node functional)) list)
1318 (defun %coerce-to-policy (thing)
1319 (let ((result (etypecase thing
1321 (lexenv (lexenv-policy thing))
1322 (node (lexenv-policy (node-lexenv thing)))
1323 (functional (lexenv-policy (functional-lexenv thing))))))
1324 ;; Test the first element of the list as a rudimentary sanity
1325 ;; that it really does look like a valid policy.
1326 (aver (or (null result) (policy-quality-name-p (caar result))))
1330 ;;;; Freeze some structure types to speed type testing.
1333 (declaim (freeze-type node leaf lexenv continuation cblock component cleanup
1334 physenv tail-set nlx-info))