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 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 most-positive-fixnum
25 "The exclusive upper bound on the number of parameters which may be specifed
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 most-positive-fixnum
30 "The exclusive upper bound on the number of multiple VALUES that you can
33 (defconstant-eqx sb
!xc
:lambda-list-keywords
45 "symbols which are magical in a lambda list")
47 ;;;; cross-compiler-only versions of CL special variables, so that we
48 ;;;; don't have weird interactions with the host compiler
50 (defvar sb
!xc
:*compile-file-pathname
*)
51 (defvar sb
!xc
:*compile-file-truename
*)
52 (defvar sb
!xc
:*compile-print
*)
53 (defvar sb
!xc
:*compile-verbose
*)
55 ;;;; miscellaneous types used both in the cross-compiler and on the target
57 ;;;; FIXME: The INDEX and LAYOUT-DEPTHOID definitions probably belong
58 ;;;; somewhere else, not "early-c", since they're after all not part
61 ;;; the type of LAYOUT-DEPTHOID slot values
62 (def!type sb
!kernel
::layout-depthoid
() '(or index
(integer -
1 -
1)))
64 ;;; possible values for the INLINE-ness of a function.
66 '(member :inline
:maybe-inline
:notinline nil
))
67 (defparameter *inlinep-translations
*
69 (notinline .
:notinline
)
70 (maybe-inline .
:maybe-inline
)))
72 ;;; the lexical environment we are currently converting in
74 (declaim (type lexenv
*lexenv
*))
76 ;;; *FREE-VARS* translates from the names of variables referenced
77 ;;; globally to the LEAF structures for them. *FREE-FUNS* is like
78 ;;; *FREE-VARS*, only it deals with function names.
81 (declaim (type hash-table
*free-vars
* *free-funs
*))
83 ;;; We use the same CONSTANT structure to represent all equal anonymous
84 ;;; constants. This hashtable translates from constants to the LEAFs that
87 (declaim (type hash-table
*constants
*))
89 ;;; *ALLOW-INSTRUMENTING* controls whether we should allow the
90 ;;; insertion of instrumenting code (like a (CATCH ...)) around code
91 ;;; to allow the debugger RETURN and STEP commands to function (we
92 ;;; disallow it for internal stuff).
93 (defvar *allow-instrumenting
*)
95 ;;; miscellaneous forward declarations
96 (defvar *code-segment
*)
97 #!+sb-dyncount
(defvar *collect-dynamic-statistics
*)
98 (defvar *component-being-compiled
*)
99 (defvar *compiler-error-context
*)
100 (defvar *compiler-error-count
*)
101 (defvar *compiler-warning-count
*)
102 (defvar *compiler-style-warning-count
*)
103 (defvar *compiler-note-count
*)
104 (defvar *compiler-trace-output
*)
105 (defvar *constraint-number
*)
106 (defvar *count-vop-usages
*)
107 (defvar *current-path
*)
108 (defvar *current-component
*)
109 (defvar *delayed-ir1-transforms
*)
110 (defvar *handled-conditions
*)
111 (defvar *disabled-package-locks
*)
113 (defvar *dynamic-counts-tn
*)
115 (defvar *event-info
*)
116 (defvar *event-note-threshold
*)
118 (defvar *fixup-notes
*)
120 (defvar *info-environment
*)
122 (defvar *source-info
*)
123 (defvar *trace-table
*)
124 (defvar *undefined-warnings
*)
125 (defvar *warnings-p
*)
127 ;;; This lock is seized in the compiler, and related areas: the
128 ;;; compiler is not presently thread-safe
129 (defvar *big-compiler-lock
*
130 (sb!thread
:make-mutex
:name
"big compiler lock"))
132 ;;; unique ID for the next object created (to let us track object
133 ;;; identity even across GC, useful for understanding weird compiler
134 ;;; bugs where something is supposed to be unique but is instead
135 ;;; exists as duplicate objects)
138 (defvar *object-id-counter
* 0)
139 (defun new-object-id ()
142 (incf *object-id-counter
*))))
144 ;;;; miscellaneous utilities
146 ;;; Delete any undefined warnings for NAME and KIND. This is for the
147 ;;; benefit of the compiler, but it's sometimes called from stuff like
148 ;;; type-defining code which isn't logically part of the compiler.
149 (declaim (ftype (function ((or symbol cons
) keyword
) (values))
151 (defun note-name-defined (name kind
)
152 ;; We do this BOUNDP check because this function can be called when
153 ;; not in a compilation unit (as when loading top level forms).
154 (when (boundp '*undefined-warnings
*)
155 (setq *undefined-warnings
*
156 (delete-if (lambda (x)
157 (and (equal (undefined-warning-name x
) name
)
158 (eq (undefined-warning-kind x
) kind
)))
159 *undefined-warnings
*)))
162 ;;; to be called when a variable is lexically bound
163 (declaim (ftype (function (symbol) (values)) note-lexical-binding
))
164 (defun note-lexical-binding (symbol)
165 ;; This check is intended to protect us from getting silently
166 ;; burned when we define
169 ;; (DEFUN FOO (X) (+ X *FOO*))
174 ;; and then we happen to compile bar.lisp before foo.lisp.
175 (when (looks-like-name-of-special-var-p symbol
)
176 ;; FIXME: should be COMPILER-STYLE-WARNING?
177 (style-warn "using the lexical binding of the symbol ~S, not the~@
178 dynamic binding, even though the symbol name follows the usual naming~@
179 convention (names like *FOO*) for special variables" symbol
))
182 ;;; Hacky (duplicating machinery found elsewhere because this function
183 ;;; turns out to be on a critical path in the compiler) shorthand for
184 ;;; creating debug names from source names or other stems, e.g.
186 ;;; (DEBUG-NAMIFY "FLET " SOURCE-NAME) -> "FLET FOO:BAR"
187 ;;; (DEBUG-NAMIFY "top level form " FORM) -> "top level form (QUUX :FOO)"
189 ;;; If ALT is given it must be a string -- it is then used in place of
190 ;;; either HEAD or TAIL if either of them is EQ to SB-C::.ANONYMOUS.
192 (declaim (inline debug-namify
))
193 (defun debug-namify (head tail
&optional alt
)
194 (declare (type (or null string
) alt
))
195 (flet ((symbol-debug-name (symbol)
196 ;; KLUDGE: (OAOOM warning) very much akin to OUTPUT-SYMBOL.
197 (if (and alt
(eq '.anonymous. symbol
))
199 (let ((package (symbol-package symbol
))
200 (name (symbol-name symbol
)))
202 ((eq package
*keyword-package
*)
203 (concatenate 'string
":" name
))
204 ((eq package
*cl-package
*)
207 (concatenate 'string
"#:" name
))
209 (multiple-value-bind (symbol status
)
210 (find-symbol name package
)
211 (declare (ignore symbol
))
213 (package-name package
)
214 (if (eq status
:external
) ":" "::")
216 (cond ((and (stringp head
) (stringp tail
))
217 (concatenate 'string head tail
))
218 ((and (stringp head
) (symbolp tail
))
219 (concatenate 'string head
(symbol-debug-name tail
)))
220 ((and (symbolp head
) (stringp tail
))
221 (concatenate 'string
(symbol-debug-name head
) tail
))
223 (macrolet ((out (obj s
)
225 (string (write-string ,obj
,s
))
226 (symbol (write-string (symbol-debug-name ,obj
) ,s
))
227 (t (prin1 ,obj
,s
)))))
228 (with-standard-io-syntax
229 (let ((*print-readably
* nil
)
231 (*package
* *cl-package
*)
234 (with-output-to-string (s)