Eliminate style-warning about undefined type GLOBAL-VAR
[sbcl.git] / src / compiler / fun-info.lisp
blob3cd1d07b193b44175e258df6f8fad42fefda46fd
1 ;;;; Define IR1 boolean attributes and the FUN-INFO structure
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 (in-package "SB!C")
14 ;;; IR1 boolean function attributes
15 ;;;
16 ;;; There are a number of boolean attributes of known functions which
17 ;;; we like to have in IR1. This information is mostly side effect
18 ;;; information of a sort, but it is different from the kind of
19 ;;; information we want in IR2. We aren't interested in a fine
20 ;;; breakdown of side effects, since we do very little code motion on
21 ;;; IR1. We are interested in some deeper semantic properties such as
22 ;;; whether it is safe to pass stack closures to.
23 ;;;
24 ;;; FIXME: This whole notion of "bad" explicit attributes is bad for
25 ;;; maintenance. How confident are we that we have no defknowns for functions
26 ;;; with functional arguments that are missing the CALL attribute? Much better
27 ;;; to have NO-CALLS, as it is much less likely to break accidentally.
28 (!def-boolean-attribute ir1
29 ;; may call functions that are passed as arguments. In order to
30 ;; determine what other effects are present, we must find the
31 ;; effects of all arguments that may be functions.
32 call
33 ;; may fail to return during correct execution. Errors are O.K.
34 ;; UNUSED, BEWARE OF BITROT.
35 unwind
36 ;; the (default) worst case. Includes all the other bad things, plus
37 ;; any other possible bad thing. If this is present, the above bad
38 ;; attributes will be explicitly present as well.
39 any
40 ;; all arguments are safe for dynamic extent.
41 ;; (We used to have an UNSAFE attribute, which was basically the inverse
42 ;; of this, but it was unused and bitrotted, so when we started making
43 ;; use of the information we flipped the name and meaning the safe way
44 ;; around.)
45 dx-safe
46 ;; may be constant-folded. The function has no side effects, but may
47 ;; be affected by side effects on the arguments. e.g. SVREF, MAPC.
48 ;; Functions that side-effect their arguments are not considered to
49 ;; be foldable. Although it would be "legal" to constant fold them
50 ;; (since it "is an error" to modify a constant), we choose not to
51 ;; mark these functions as foldable in this database.
52 foldable
53 ;; may be eliminated if value is unused. The function has no side
54 ;; effects except possibly cons. If a function might signal errors,
55 ;; then it is not flushable even if it is movable, foldable or
56 ;; unsafely-flushable. Implies UNSAFELY-FLUSHABLE. (In safe code
57 ;; type checking of arguments is always performed by the caller, so
58 ;; a function which SHOULD signal an error if arguments are not of
59 ;; declared types may be FLUSHABLE.)
60 flushable
61 ;; unsafe call may be eliminated if value is unused. The function
62 ;; has no side effects except possibly cons and signalling an error
63 ;; in the safe code. If a function MUST signal errors, then it is
64 ;; not unsafely-flushable even if it is movable or foldable.
65 unsafely-flushable
66 ;; return value is important, and ignoring it is probably a mistake.
67 ;; Unlike the other attributes, this is used only for style
68 ;; warnings and has no effect on optimization.
69 important-result
70 ;; may be moved with impunity. Has no side effects except possibly
71 ;; consing, and is affected only by its arguments.
72 ;; UNUSED, BEWARE OF BITROT.
73 movable
74 ;; The function is a true predicate likely to be open-coded. Convert
75 ;; any non-conditional uses into (IF <pred> T NIL). Not usually
76 ;; specified to DEFKNOWN, since this is implementation dependent,
77 ;; and is usually automatically set by the DEFINE-VOP :CONDITIONAL
78 ;; option.
79 predicate
80 ;; Inhibit any warning for compiling a recursive definition.
81 ;; (Normally the compiler warns when compiling a recursive
82 ;; definition for a known function, since it might be a botched
83 ;; interpreter stub.)
84 recursive
85 ;; The function does explicit argument type checking, so the
86 ;; declared type should not be asserted when a definition is
87 ;; compiled.
88 explicit-check
89 ;; The function should always be translated by a VOP (i.e. it should
90 ;; should never be converted into a full call). This is used strictly
91 ;; as a consistency checking mechanism inside the compiler during IR2
92 ;; transformation.
93 always-translatable
94 ;; If a function is called with two arguments and the first one is a
95 ;; constant, then the arguments will be swapped.
96 commutative)
98 (defstruct (fun-info #-sb-xc-host (:pure t))
99 ;; boolean attributes of this function.
100 (attributes (missing-arg) :type attributes)
101 ;; TRANSFORM structures describing transforms for this function
102 (transforms () :type list)
103 ;; a function which computes the derived type for a call to this
104 ;; function by examining the arguments. This is null when there is
105 ;; no special method for this function.
106 (derive-type nil :type (or function null))
107 ;; a function that does various unspecified code transformations by
108 ;; directly hacking the IR. Returns true if further optimizations of
109 ;; the call shouldn't be attempted.
111 ;; KLUDGE: This return convention (non-NIL if you shouldn't do
112 ;; further optimiz'ns) is backwards from the return convention for
113 ;; transforms. -- WHN 19990917
114 (optimizer nil :type (or function null))
115 ;; a function computing the constant or literal arguments which are
116 ;; destructively modified by the call.
117 (destroyed-constant-args nil :type (or function null))
118 ;; If true, a special-case LTN annotation method that is used in
119 ;; place of the standard type/policy template selection. It may use
120 ;; arbitrary code to choose a template, decide to do a full call, or
121 ;; conspire with the IR2-CONVERT method to do almost anything. The
122 ;; COMBINATION node is passed as the argument.
123 (ltn-annotate nil :type (or function null))
124 ;; If true, the special-case IR2 conversion method for this
125 ;; function. This deals with funny functions, and anything else that
126 ;; can't be handled using the template mechanism. The COMBINATION
127 ;; node and the IR2-BLOCK are passed as arguments.
128 (ir2-convert nil :type (or function null))
129 ;; If true, the function can stack-allocate the result. The
130 ;; COMBINATION node is passed as an argument.
131 (stack-allocate-result nil :type (or function null))
132 ;; If true, the function can add flow-sensitive type information
133 ;; about the state of the world after its execution. The COMBINATION
134 ;; node is passed as an argument, along with the current set of
135 ;; active constraints for the block. The function returns a
136 ;; sequence of constraints; a constraint is a triplet of a
137 ;; constraint kind (a symbol, see (defstruct (constraint ...)) in
138 ;; constraint.lisp) and arguments, either LVARs, LAMBDA-VARs, or
139 ;; CTYPEs. If any of these arguments is NIL, the constraint is
140 ;; skipped. This simplifies integration with OK-LVAR-LAMBDA-VAR,
141 ;; which maps LVARs to LAMBDA-VARs. An optional fourth value in
142 ;; each constraint flips the meaning of the constraint if it is
143 ;; non-NIL.
144 (constraint-propagate nil :type (or function null))
145 ;; If true, the function can add flow-sensitive type information
146 ;; depending on the truthiness of its return value. Returns two
147 ;; values, a LVAR and a CTYPE. The LVAR is of that CTYPE iff the
148 ;; function returns true.
149 ;; It may also return additional third and fourth values. Each is
150 ;; a sequence of constraints (see CONSTRAINT-PROPAGATE), for the
151 ;; consequent and alternative branches, respectively.
152 (constraint-propagate-if nil :type (or function null))
153 ;; all the templates that could be used to translate this function
154 ;; into IR2, sorted by increasing cost.
155 (templates nil :type list)
156 ;; If non-null, then this function is a unary type predicate for
157 ;; this type.
158 (predicate-type nil :type (or ctype null))
159 ;; If non-null, the index of the argument which becomes the result
160 ;; of the function.
161 (result-arg nil :type (or index null)))
163 (defprinter (fun-info)
164 (attributes :test (not (zerop attributes))
165 :prin1 (decode-ir1-attributes attributes))
166 (transforms :test transforms)
167 (derive-type :test derive-type)
168 (optimizer :test optimizer)
169 (ltn-annotate :test ltn-annotate)
170 (ir2-convert :test ir2-convert)
171 (templates :test templates)
172 (predicate-type :test predicate-type))