1 ;;;; This file contains compiler code and compiler-related stuff which
2 ;;;; can be built early on. Some of the stuff may be here because it's
3 ;;;; needed early on, some other stuff (e.g. constants) just because
4 ;;;; it might as well be done early so we don't have to think about
5 ;;;; whether it's done early enough.
7 ;;;; This software is part of the SBCL system. See the README file for
10 ;;;; This software is derived from the CMU CL system, which was
11 ;;;; written at Carnegie Mellon University and released into the
12 ;;;; public domain. The software is in the public domain and is
13 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
14 ;;;; files for more information.
18 ;;; ANSI limits on compilation
19 (def!constant sb
!xc
:call-arguments-limit sb
!xc
:most-positive-fixnum
21 "The exclusive upper bound on the number of arguments which may be passed
22 to a function, including &REST args.")
23 (def!constant sb
!xc
:lambda-parameters-limit sb
!xc
:most-positive-fixnum
25 "The exclusive upper bound on the number of parameters which may be specified
26 in a given lambda list. This is actually the limit on required and &OPTIONAL
27 parameters. With &KEY and &AUX you can get more.")
28 (def!constant sb
!xc
:multiple-values-limit sb
!xc
:most-positive-fixnum
30 "The exclusive upper bound on the number of multiple VALUES that you can
33 ;;;; cross-compiler-only versions of CL special variables, so that we
34 ;;;; don't have weird interactions with the host compiler
36 (defvar sb
!xc
:*compile-file-pathname
*)
37 (defvar sb
!xc
:*compile-file-truename
*)
38 (defvar sb
!xc
:*compile-print
*)
39 (defvar sb
!xc
:*compile-verbose
*)
41 ;;;; miscellaneous types used both in the cross-compiler and on the target
43 ;;;; FIXME: The INDEX and LAYOUT-DEPTHOID definitions probably belong
44 ;;;; somewhere else, not "early-c", since they're after all not part
47 ;;; the type of LAYOUT-DEPTHOID slot values
48 (def!type layout-depthoid
() '(or index
(integer -
1 -
1)))
50 ;;; An INLINEP value describes how a function is called. The values
51 ;;; have these meanings:
52 ;;; NIL No declaration seen: do whatever you feel like, but don't
53 ;;; dump an inline expansion.
54 ;;; :NOTINLINE NOTINLINE declaration seen: always do full function call.
55 ;;; :INLINE INLINE declaration seen: save expansion, expanding to it
58 ;;; Retain expansion, but only use it opportunistically.
59 ;;; :MAYBE-INLINE is quite different from :INLINE. As explained
60 ;;; by APD on #lisp 2005-11-26: "MAYBE-INLINE lambda is
61 ;;; instantiated once per component, INLINE - for all
62 ;;; references (even under #'without FUNCALL)."
64 '(member :inline
:maybe-inline
:notinline nil
))
65 (defparameter *inlinep-translations
*
67 (notinline .
:notinline
)
68 (maybe-inline .
:maybe-inline
)))
70 ;;; *FREE-VARS* translates from the names of variables referenced
71 ;;; globally to the LEAF structures for them. *FREE-FUNS* is like
72 ;;; *FREE-VARS*, only it deals with function names.
75 (declaim (type hash-table
*free-vars
* *free-funs
*))
77 ;;; We use the same CONSTANT structure to represent all equal anonymous
78 ;;; constants. This hashtable translates from constants to the LEAFs that
81 (declaim (type hash-table
*constants
*))
83 ;;; *ALLOW-INSTRUMENTING* controls whether we should allow the
84 ;;; insertion of instrumenting code (like a (CATCH ...)) around code
85 ;;; to allow the debugger RETURN and STEP commands to function (we
86 ;;; disallow it for internal stuff).
87 (defvar *allow-instrumenting
*)
89 ;;; miscellaneous forward declarations
90 (defvar *code-segment
*)
91 #!+sb-dyncount
(defvar *collect-dynamic-statistics
*)
92 (defvar *component-being-compiled
*)
93 (defvar *compiler-error-context
*)
94 (defvar *compiler-error-count
*)
95 (defvar *compiler-warning-count
*)
96 (defvar *compiler-style-warning-count
*)
97 (defvar *compiler-note-count
*)
98 (defvar *compiler-trace-output
*)
99 (defvar *constraint-universe
*)
100 (defvar *current-path
*)
101 (defvar *current-component
*)
102 (defvar *delayed-ir1-transforms
*)
103 (defvar *eval-tlf-index
*)
104 (defvar *dynamic-counts-tn
*)
106 (defvar *event-info
*)
107 (defvar *event-note-threshold
*)
109 (defvar *fixup-notes
*)
112 (defvar *unboxed-constants
*)
113 (defstruct (unboxed-constants (:conc-name constant-
)
114 (:predicate nil
) (:copier nil
))
115 (table (make-hash-table :test
#'equal
) :read-only t
)
117 (sb!assem
:make-segment
:type
:elsewhere
119 :inst-hook
(default-segment-inst-hook)
120 :alignment
0) :read-only t
)
121 (vector (make-array 16 :adjustable t
:fill-pointer
0) :read-only t
))
122 (declaim (freeze-type unboxed-constants
)))
123 (defvar *source-info
*)
124 (defvar *source-plist
*)
125 (defvar *source-namestring
*)
126 (defvar *undefined-warnings
*)
127 (defvar *warnings-p
*)
128 (defvar *lambda-conversions
*)
130 (defvar *stack-allocate-dynamic-extent
* t
132 "If true (the default), the compiler respects DYNAMIC-EXTENT declarations
133 and stack allocates otherwise inaccessible parts of the object whenever
134 possible. Potentially long (over one page in size) vectors are, however, not
135 stack allocated except in zero SAFETY code, as such a vector could overflow
136 the stack without triggering overflow protection.")
138 (!begin-collecting-cold-init-forms
)
139 ;;; This lock is seized in the compiler, and related areas -- like the
140 ;;; classoid/layout/class system.
141 (defglobal **world-lock
** nil
)
143 (setf **world-lock
** (sb!thread
:make-mutex
:name
"World Lock")))
144 (!defun-from-collected-cold-init-forms
!world-lock-cold-init
)
146 (defmacro with-world-lock
(() &body body
)
147 `(sb!thread
:with-recursive-lock
(**world-lock
**)
150 (declaim (type fixnum
*compiler-sset-counter
*))
151 (defvar *compiler-sset-counter
* 0)
153 ;;; unique ID for the next object created (to let us track object
154 ;;; identity even across GC, useful for understanding weird compiler
155 ;;; bugs where something is supposed to be unique but is instead
156 ;;; exists as duplicate objects)
159 (defvar *object-id-counter
* 0)
160 (defun new-object-id ()
163 (incf *object-id-counter
*))))
165 ;;;; miscellaneous utilities
167 ;;; This is for "observers" who want to know if type names have been added.
168 ;;; Rather than registering listeners, they can detect changes by comparing
169 ;;; their stored nonce to the current nonce. Additionally the observers
170 ;;; can detect whether function definitions have occurred.
171 (declaim (fixnum *type-cache-nonce
*))
172 (!defglobal
*type-cache-nonce
* 0)
174 (def!struct
(undefined-warning
175 #-no-ansi-print-object
176 (:print-object
(lambda (x s
)
177 (print-unreadable-object (x s
:type t
)
178 (prin1 (undefined-warning-name x
) s
))))
180 ;; the name of the unknown thing
181 (name nil
:type
(or symbol list
))
182 ;; the kind of reference to NAME
183 (kind (missing-arg) :type
(member :function
:type
:variable
))
184 ;; the number of times this thing was used
185 (count 0 :type unsigned-byte
)
186 ;; a list of COMPILER-ERROR-CONTEXT structures describing places
187 ;; where this thing was used. Note that we only record the first
188 ;; *UNDEFINED-WARNING-LIMIT* calls.
189 (warnings () :type list
))
191 ;;; Delete any undefined warnings for NAME and KIND. This is for the
192 ;;; benefit of the compiler, but it's sometimes called from stuff like
193 ;;; type-defining code which isn't logically part of the compiler.
194 (declaim (ftype (function ((or symbol cons
) keyword
) (values))
196 (defun note-name-defined (name kind
)
197 #-sb-xc-host
(atomic-incf *type-cache-nonce
*)
198 ;; We do this BOUNDP check because this function can be called when
199 ;; not in a compilation unit (as when loading top level forms).
200 (when (boundp '*undefined-warnings
*)
201 (let ((name (uncross name
)))
202 (setq *undefined-warnings
*
203 (delete-if (lambda (x)
204 (and (equal (undefined-warning-name x
) name
)
205 (eq (undefined-warning-kind x
) kind
)))
206 *undefined-warnings
*))))
209 ;;; to be called when a variable is lexically bound
210 (declaim (ftype (function (symbol) (values)) note-lexical-binding
))
211 (defun note-lexical-binding (symbol)
212 ;; This check is intended to protect us from getting silently
213 ;; burned when we define
216 ;; (DEFUN FOO (X) (+ X *FOO*))
221 ;; and then we happen to compile bar.lisp before foo.lisp.
222 (when (looks-like-name-of-special-var-p symbol
)
223 ;; FIXME: should be COMPILER-STYLE-WARNING?
224 (style-warn 'asterisks-around-lexical-variable-name
226 "using the lexical binding of the symbol ~
227 ~/sb-impl::print-symbol-with-prefix/, not the~@
229 :format-arguments
(list symbol
)))
232 (def!struct
(debug-name-marker (:print-function print-debug-name-marker
)))
234 (defvar *debug-name-level
* 4)
235 (defvar *debug-name-length
* 12)
236 (defvar *debug-name-punt
*)
237 (defvar *debug-name-sharp
*)
238 (defvar *debug-name-ellipsis
*)
240 (defmethod make-load-form ((marker debug-name-marker
) &optional env
)
241 (declare (ignore env
))
242 (cond ((eq marker
*debug-name-sharp
*)
243 `(if (boundp '*debug-name-sharp
*)
245 (make-debug-name-marker)))
246 ((eq marker
*debug-name-ellipsis
*)
247 `(if (boundp '*debug-name-ellipsis
*)
248 *debug-name-ellipsis
*
249 (make-debug-name-marker)))
251 (warn "Dumping unknown debug-name marker.")
252 '(make-debug-name-marker))))
254 (defun print-debug-name-marker (marker stream level
)
255 (declare (ignore level
))
256 (cond ((eq marker
*debug-name-sharp
*)
257 (write-char #\
# stream
))
258 ((eq marker
*debug-name-ellipsis
*)
259 (write-string "..." stream
))
261 (write-string "???" stream
))))
263 (setf *debug-name-sharp
* (make-debug-name-marker)
264 *debug-name-ellipsis
* (make-debug-name-marker))
266 (declaim (ftype (sfunction () list
) name-context
))
267 (defun debug-name (type thing
&optional context
)
268 (let ((*debug-name-punt
* nil
))
272 (if (plusp *debug-name-level
*)
273 (let ((*debug-name-level
* (1- *debug-name-level
*)))
274 (do ((tail (cdr x
) (cdr tail
))
275 (name (cons (walk (car x
)) nil
)
276 (cons (walk (car tail
)) name
))
277 (n (1- *debug-name-length
*) (1- n
)))
278 ((or (not (consp tail
))
281 (cond (*debug-name-punt
*
282 (setf *debug-name-punt
* nil
)
285 (nconc (nreverse name
) (walk tail
)))
287 (setf *debug-name-punt
* t
)
288 (nconc (nreverse name
) (list *debug-name-ellipsis
*)))))))
290 ((or symbol number string
)
294 (let ((name (list* type
(walk thing
) (when context
(name-context)))))
295 (when (legal-fun-name-p name
)
296 (bug "~S is a legal function name, and cannot be used as a ~
300 ;;; Set this to NIL to inhibit assembly-level optimization. (For
301 ;;; compiler debugging, rather than policy control.)
302 (defvar *assembly-optimize
* t
)
304 (in-package "SB!ALIEN")
306 ;;; Information describing a heap-allocated alien.
307 (def!struct
(heap-alien-info)
308 ;; The type of this alien.
309 (type (missing-arg) :type alien-type
)
311 (alien-name (missing-arg) :type simple-string
)
313 (datap (missing-arg) :type boolean
))
314 (!set-load-form-method heap-alien-info
(:xc
:target
))