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 ;;; FIXME: Shouldn't SB!C::&MORE be in this list?
19 (defconstant-eqx sb!xc:lambda-list-keywords
20 '(&optional &rest &key &aux &body &whole &allow-other-keys &environment)
23 "symbols which are magical in a lambda list")
25 ;;;; cross-compiler-only versions of CL special variables, so that we
26 ;;;; don't have weird interactions with the host compiler
28 (defvar sb!xc:*compile-file-pathname*)
29 (defvar sb!xc:*compile-file-truename*)
30 (defvar sb!xc:*compile-print*)
31 (defvar sb!xc:*compile-verbose*)
33 ;;;; miscellaneous types used both in the cross-compiler and on the target
35 ;;;; FIXME: The INDEX and LAYOUT-DEPTHOID definitions probably belong
36 ;;;; somewhere else, not "early-c", since they're after all not part
39 ;;; the type of LAYOUT-DEPTHOID slot values
40 (def!type sb!kernel::layout-depthoid () '(or index (integer -1 -1)))
42 ;;; a value for an optimization declaration
43 (def!type sb!c::cookie-quality () '(or (rational 0 3) null))
45 ;;; A COOKIE holds information about the compilation environment for a
46 ;;; node. See the LEXENV definition for a description of how it is
48 (def!struct (cookie (:copier nil))
49 (speed nil :type cookie-quality)
50 (space nil :type cookie-quality)
51 (safety nil :type cookie-quality)
52 (cspeed nil :type cookie-quality)
53 (brevity nil :type cookie-quality)
54 (debug nil :type cookie-quality))
56 ;;; KLUDGE: This needs to be executable in cold init toplevel forms,
57 ;;; earlier than the default copier closure created by DEFSTRUCT
58 ;;; toplevel forms would be available, and earlier than LAYOUT-INFO is
59 ;;; initialized (which is a prerequisite for COPY-STRUCTURE to work),
60 ;;; so we define it explicitly using DEFUN, so that it can be
61 ;;; installed by the cold loader, and using hand-written,
62 ;;; hand-maintained slot-by-slot copy it doesn't need to call
63 ;;; COPY-STRUCTURE. -- WHN 19991019
64 (defun copy-cookie (cookie)
65 (make-cookie :speed (cookie-speed cookie)
66 :space (cookie-space cookie)
67 :safety (cookie-safety cookie)
68 :cspeed (cookie-cspeed cookie)
69 :brevity (cookie-brevity cookie)
70 :debug (cookie-debug cookie)))
72 ;;; *DEFAULT-COOKIE* holds the current global compiler policy
73 ;;; information. Whenever the policy is changed, we copy the structure
74 ;;; so that old uses will still get the old values.
75 ;;; *DEFAULT-INTERFACE-COOKIE* holds any values specified by an
76 ;;; OPTIMIZE-INTERFACE declaration.
78 ;;; FIXME: Why isn't COOKIE called POLICY?
79 (declaim (type cookie *default-cookie* *default-interface-cookie*))
80 (defvar *default-cookie*) ; initialized in cold init
81 (defvar *default-interface-cookie*) ; initialized in cold init
83 ;;; possible values for the INLINE-ness of a function.
85 '(member :inline :maybe-inline :notinline nil))
86 (defparameter *inlinep-translations*
88 (notinline . :notinline)
89 (maybe-inline . :maybe-inline)))
91 ;;; The lexical environment we are currently converting in.
93 (declaim (type lexenv *lexenv*))
95 ;;; *FREE-VARIABLES* translates from the names of variables referenced
96 ;;; globally to the LEAF structures for them. *FREE-FUNCTIONS* is like
97 ;;; *FREE-VARIABLES*, only it deals with function names.
98 (defvar *free-variables*)
99 (defvar *free-functions*)
100 (declaim (hash-table *free-variables* *free-functions*))
102 ;;; We use the same Constant structure to represent all equal anonymous
103 ;;; constants. This hashtable translates from constants to the Leafs that
106 (declaim (hash-table *constants*))
108 ;;; miscellaneous forward declarations
109 (defvar *code-segment*)
110 #!+sb-dyncount (defvar *collect-dynamic-statistics*)
111 (defvar *component-being-compiled*)
112 (defvar *compiler-error-context*)
113 (defvar *compiler-error-count*)
114 (defvar *compiler-warning-count*)
115 (defvar *compiler-style-warning-count*)
116 (defvar *compiler-note-count*)
117 (defvar *converting-for-interpreter*)
118 (defvar *count-vop-usages*)
119 (defvar *current-path*)
120 (defvar *current-component*)
121 (defvar *default-cookie*)
122 (defvar *default-interface-cookie*)
123 (defvar *dynamic-counts-tn*)
125 (defvar *event-info*)
126 (defvar *event-note-threshold*)
130 (defvar *info-environment*)
132 (defvar *source-info*)
133 (defvar *trace-table*)
134 (defvar *undefined-warnings*)
135 (defvar *warnings-p*)
137 ;;;; miscellaneous utilities
139 ;;; Delete any undefined warnings for NAME and KIND. This is for the
140 ;;; benefit of the compiler, but it's sometimes called from stuff like
141 ;;; type-defining code which isn't logically part of the compiler.
142 (declaim (ftype (function ((or symbol cons) keyword) (values))
144 (defun note-name-defined (name kind)
145 ;; We do this BOUNDP check because this function can be called when
146 ;; not in a compilation unit (as when loading top-level forms).
147 (when (boundp '*undefined-warnings*)
148 (setq *undefined-warnings*
149 (delete-if (lambda (x)
150 (and (equal (undefined-warning-name x) name)
151 (eq (undefined-warning-kind x) kind)))
152 *undefined-warnings*)))
155 ;;; to be called when a variable is lexically bound
156 (declaim (ftype (function (symbol) (values)) note-lexical-binding))
157 (defun note-lexical-binding (symbol)
158 (let ((name (symbol-name symbol)))
159 ;; This check is intended to protect us from getting silently
160 ;; burned when we define
163 ;; (DEFUN FOO (X) (+ X *FOO*))
168 ;; and then we happen to compile bar.lisp before foo.lisp.
169 (when (and (char= #\* (aref name 0))
170 (char= #\* (aref name (1- (length name)))))
171 ;; FIXME: should be COMPILER-STYLE-WARNING?
172 (style-warn "using the lexical binding of the symbol ~S, not the~@
173 dynamic binding, even though the symbol name follows the usual naming~@
174 convention (names like *FOO*) for special variables" symbol)))