Change initialization of interned array ctypes.
[sbcl.git] / src / compiler / ir1tran.lisp
blob72f4fe86f9d4e6ec70590f5ac0223657bda64d68
1 ;;;; This file contains code which does the translation from Lisp code
2 ;;;; to the first intermediate representation (IR1).
4 ;;;; This software is part of the SBCL system. See the README file for
5 ;;;; more information.
6 ;;;;
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.
13 (in-package "SB!C")
15 (declaim (special *compiler-error-bailout*))
17 ;;; *CURRENT-FORM-NUMBER* is used in FIND-SOURCE-PATHS to compute the
18 ;;; form number to associate with a source path. This should be bound
19 ;;; to an initial value of 0 before the processing of each truly
20 ;;; top level form.
21 (declaim (type index *current-form-number*))
22 (defvar *current-form-number*)
24 ;;; *SOURCE-PATHS* is a hashtable from source code forms to the path
25 ;;; taken through the source to reach the form. This provides a way to
26 ;;; keep track of the location of original source forms, even when
27 ;;; macroexpansions and other arbitary permutations of the code
28 ;;; happen. This table is initialized by calling FIND-SOURCE-PATHS on
29 ;;; the original source.
30 ;;;
31 ;;; It is fairly useless to store symbols, characters, or fixnums in
32 ;;; this table, as 42 is EQ to 42 no matter where in the source it
33 ;;; appears. GET-SOURCE-PATH and NOTE-SOURCE-PATH functions should be
34 ;;; always used to access this table.
35 (declaim (hash-table *source-paths*))
36 (defvar *source-paths*)
38 (declaim (inline source-form-has-path-p))
39 (defun source-form-has-path-p (form)
40 (not (typep form '(or symbol fixnum character))))
42 (defun get-source-path (form)
43 (when (source-form-has-path-p form)
44 (gethash form *source-paths*)))
46 (defun ensure-source-path (form)
47 (or (get-source-path form)
48 (cons (simplify-source-path-form form)
49 *current-path*)))
51 (defun simplify-source-path-form (form)
52 (if (consp form)
53 (let ((op (car form)))
54 ;; In the compiler functions can be directly represented
55 ;; by leaves. Having leaves in the source path is pretty
56 ;; hard on the poor user, however, so replace with the
57 ;; source-name when possible.
58 (if (and (leaf-p op) (leaf-has-source-name-p op))
59 (cons (leaf-source-name op) (cdr form))
60 form))
61 form))
63 (defun note-source-path (form &rest arguments)
64 (when (source-form-has-path-p form)
65 (setf (gethash form *source-paths*)
66 (apply #'list* 'original-source-start *current-form-number* arguments))))
68 ;;; *CURRENT-COMPONENT* is the COMPONENT structure which we link
69 ;;; blocks into as we generate them. This just serves to glue the
70 ;;; emitted blocks together until local call analysis and flow graph
71 ;;; canonicalization figure out what is really going on. We need to
72 ;;; keep track of all the blocks generated so that we can delete them
73 ;;; if they turn out to be unreachable.
74 ;;;
75 ;;; FIXME: It's confusing having one variable named *CURRENT-COMPONENT*
76 ;;; and another named *COMPONENT-BEING-COMPILED*. (In CMU CL they
77 ;;; were called *CURRENT-COMPONENT* and *COMPILE-COMPONENT* respectively,
78 ;;; which was also confusing.)
79 (declaim (type (or component null) *current-component*))
80 (defvar *current-component*)
82 ;;; *CURRENT-PATH* is the source path of the form we are currently
83 ;;; translating. See NODE-SOURCE-PATH in the NODE structure.
84 (declaim (list *current-path*))
85 (defvar *current-path*)
87 (defvar *derive-function-types* nil
88 #!+sb-doc
89 "Should the compiler assume that function types will never change,
90 so that it can use type information inferred from current definitions
91 to optimize code which uses those definitions? Setting this true
92 gives non-ANSI, early-CMU-CL behavior. It can be useful for improving
93 the efficiency of stable code.")
95 (defvar *fun-names-in-this-file* nil)
97 (defvar *post-binding-variable-lexenv* nil)
99 ;;;; namespace management utilities
101 ;; As with LEXENV-FIND, we assume use of *LEXENV*, but macroexpanders
102 ;; receive an explicit environment and should pass it.
103 ;; A declaration will trump a proclamation.
104 (defun fun-lexically-notinline-p (name &optional (env *lexenv*))
105 (let ((answer
106 (typecase env
107 (null nil)
108 #!+(and sb-fasteval (host-feature sb-xc))
109 (sb!interpreter:basic-env
110 (sb!interpreter::fun-lexically-notinline-p name env))
112 (let ((fun (cdr (assoc name (lexenv-funs env) :test #'equal))))
113 ;; FIXME: this seems to omit FUNCTIONAL
114 (when (defined-fun-p fun)
115 (return-from fun-lexically-notinline-p
116 (eq (defined-fun-inlinep fun) :notinline))))))))
117 ;; If ANSWER is NIL, go for the global value
118 (eq (or answer (info :function :inlinep name))
119 :notinline)))
121 (defun maybe-defined-here (name where)
122 (if (and (eq :defined where)
123 (member name *fun-names-in-this-file* :test #'equal))
124 :defined-here
125 where))
127 ;;; Return a GLOBAL-VAR structure usable for referencing the global
128 ;;; function NAME.
129 (defun find-global-fun (name latep)
130 (unless (info :function :kind name)
131 (setf (info :function :kind name) :function)
132 (setf (info :function :where-from name) :assumed))
133 (let ((where (info :function :where-from name)))
134 (when (and (eq where :assumed)
135 ;; In the ordinary target Lisp, it's silly to report
136 ;; undefinedness when the function is defined in the
137 ;; running Lisp. But at cross-compile time, the current
138 ;; definedness of a function is irrelevant to the
139 ;; definedness at runtime, which is what matters.
140 #-sb-xc-host (not (fboundp name))
141 ;; LATEP is true when the user has indicated that
142 ;; late-late binding is desired by using eg. a quoted
143 ;; symbol -- in which case it makes little sense to
144 ;; complain about undefined functions.
145 (not latep))
146 (note-undefined-reference name :function))
147 (let ((ftype (proclaimed-ftype name))
148 (notinline (fun-lexically-notinline-p name)))
149 (make-global-var
150 :kind :global-function
151 :%source-name name
152 :type (if (or (eq where :declared)
153 (and (not latep)
154 (not notinline)
155 *derive-function-types*))
156 ftype
157 (specifier-type 'function))
158 :defined-type (if (and (not latep) (not notinline))
159 ftype
160 (specifier-type 'function))
161 :where-from (if notinline
162 where
163 (maybe-defined-here name where))))))
165 ;;; Have some DEFINED-FUN-FUNCTIONALS of a *FREE-FUNS* entry become invalid?
166 ;;; Drop 'em.
168 ;;; This was added to fix bug 138 in SBCL. It is possible for a *FREE-FUNS*
169 ;;; entry to contain a DEFINED-FUN whose DEFINED-FUN-FUNCTIONAL object
170 ;;; contained IR1 stuff (NODEs, BLOCKs...) referring to an already compiled
171 ;;; (aka "dead") component. When this IR1 stuff was reused in a new component,
172 ;;; under further obscure circumstances it could be used by
173 ;;; WITH-IR1-ENVIRONMENT-FROM-NODE to generate a binding for
174 ;;; *CURRENT-COMPONENT*. At that point things got all confused, since IR1
175 ;;; conversion was sending code to a component which had already been compiled
176 ;;; and would never be compiled again.
178 ;;; Note: as of 1.0.24.41 this seems to happen only in XC, and the original
179 ;;; BUGS entry also makes it seem like this might not be an issue at all on
180 ;;; target.
181 (defun clear-invalid-functionals (free-fun)
182 ;; There might be other reasons that *FREE-FUN* entries could
183 ;; become invalid, but the only one we've been bitten by so far
184 ;; (sbcl-0.pre7.118) is this one:
185 (when (defined-fun-p free-fun)
186 (setf (defined-fun-functionals free-fun)
187 (delete-if (lambda (functional)
188 (or (eq (functional-kind functional) :deleted)
189 (when (lambda-p functional)
191 ;; (The main reason for this first test is to bail
192 ;; out early in cases where the LAMBDA-COMPONENT
193 ;; call in the second test would fail because links
194 ;; it needs are uninitialized or invalid.)
196 ;; If the BIND node for this LAMBDA is null, then
197 ;; according to the slot comments, the LAMBDA has
198 ;; been deleted or its call has been deleted. In
199 ;; that case, it seems rather questionable to reuse
200 ;; it, and certainly it shouldn't be necessary to
201 ;; reuse it, so we cheerfully declare it invalid.
202 (not (lambda-bind functional))
203 ;; If this IR1 stuff belongs to a dead component,
204 ;; then we can't reuse it without getting into
205 ;; bizarre confusion.
206 (eq (component-info (lambda-component functional))
207 :dead)))))
208 (defined-fun-functionals free-fun)))
209 nil))
211 ;;; If NAME already has a valid entry in *FREE-FUNS*, then return
212 ;;; the value. Otherwise, make a new GLOBAL-VAR using information from
213 ;;; the global environment and enter it in *FREE-FUNS*. If NAME
214 ;;; names a macro or special form, then we error out using the
215 ;;; supplied context which indicates what we were trying to do that
216 ;;; demanded a function.
217 (declaim (ftype (sfunction (t string) global-var) find-free-fun))
218 (defun find-free-fun (name context)
219 (or (let ((old-free-fun (gethash name *free-funs*)))
220 (when old-free-fun
221 (clear-invalid-functionals old-free-fun)
222 old-free-fun))
223 (ecase (info :function :kind name)
224 ;; FIXME: The :MACRO and :SPECIAL-FORM cases could be merged.
225 (:macro
226 (compiler-error "The macro name ~S was found ~A." name context))
227 (:special-form
228 (compiler-error "The special form name ~S was found ~A."
229 name
230 context))
231 ((:function nil)
232 (check-fun-name name)
233 (let ((expansion (fun-name-inline-expansion name))
234 (inlinep (info :function :inlinep name)))
235 (setf (gethash name *free-funs*)
236 (if (or expansion inlinep)
237 (let ((where (info :function :where-from name)))
238 (make-defined-fun
239 :%source-name name
240 :inline-expansion expansion
241 :inlinep inlinep
242 :where-from (if (eq inlinep :notinline)
243 where
244 (maybe-defined-here name where))
245 :type (if (and (eq inlinep :notinline)
246 (neq where :declared))
247 (specifier-type 'function)
248 (proclaimed-ftype name))))
249 (find-global-fun name nil))))))))
251 ;;; Return the LEAF structure for the lexically apparent function
252 ;;; definition of NAME.
253 (declaim (ftype (sfunction (t string) leaf) find-lexically-apparent-fun))
254 (defun find-lexically-apparent-fun (name context)
255 (let ((var (lexenv-find name funs :test #'equal)))
256 (cond (var
257 (unless (leaf-p var)
258 (aver (and (consp var) (eq (car var) 'macro)))
259 (compiler-error "found macro name ~S ~A" name context))
260 var)
262 (find-free-fun name context)))))
264 (defun maybe-find-free-var (name)
265 (gethash name *free-vars*))
267 ;;; Return the LEAF node for a global variable reference to NAME. If
268 ;;; NAME is already entered in *FREE-VARS*, then we just return the
269 ;;; corresponding value. Otherwise, we make a new leaf using
270 ;;; information from the global environment and enter it in
271 ;;; *FREE-VARS*. If the variable is unknown, then we emit a warning.
272 (declaim (ftype (sfunction (t) (or leaf cons heap-alien-info)) find-free-var))
273 (defun find-free-var (name)
274 (unless (symbolp name)
275 (compiler-error "Variable name is not a symbol: ~S." name))
276 (or (gethash name *free-vars*)
277 (let ((kind (info :variable :kind name))
278 (type (info :variable :type name))
279 (where-from (info :variable :where-from name))
280 (deprecation-state (deprecated-thing-p 'variable name)))
281 (when (and (eq kind :unknown) (not deprecation-state))
282 (note-undefined-reference name :variable))
283 (setf (gethash name *free-vars*)
284 (case kind
285 (:alien
286 (info :variable :alien-info name))
287 ;; FIXME: The return value in this case should really be
288 ;; of type SB!C::LEAF. I don't feel too badly about it,
289 ;; because the MACRO idiom is scattered throughout this
290 ;; file, but it should be cleaned up so we're not
291 ;; throwing random conses around. --njf 2002-03-23
292 (:macro
293 (let ((expansion (info :variable :macro-expansion name))
294 (type (type-specifier (info :variable :type name))))
295 `(macro . (the ,type ,expansion))))
296 (:constant
297 (let ((value (symbol-value name)))
298 ;; Override the values of standard symbols in XC,
299 ;; since we can't redefine them.
300 #+sb-xc-host
301 (when (eql (find-symbol (symbol-name name) :cl) name)
302 (multiple-value-bind (xc-value foundp)
303 (xc-constant-value name)
304 (cond (foundp
305 (setf value xc-value))
306 ((not (eq value name))
307 (compiler-warn
308 "Using cross-compilation host's definition of ~S: ~A~%"
309 name (symbol-value name))))))
310 (find-constant value name)))
312 (make-global-var :kind kind
313 :%source-name name
314 :type type
315 :where-from where-from)))))))
317 ;;; Grovel over CONSTANT checking for any sub-parts that need to be
318 ;;; processed with MAKE-LOAD-FORM. We have to be careful, because
319 ;;; CONSTANT might be circular. We also check that the constant (and
320 ;;; any subparts) are dumpable at all.
321 (defun maybe-emit-make-load-forms (constant &optional (name nil namep))
322 (let ((xset (alloc-xset)))
323 (labels ((trivialp (value)
324 (typep value
325 '(or
326 #-sb-xc-host
327 (or unboxed-array #!+sb-simd-pack simd-pack)
328 #+sb-xc-host
329 (and array (not (array t)))
330 symbol
331 number
332 character
333 string))) ; subsumed by UNBOXED-ARRAY
334 (grovel (value)
335 ;; Unless VALUE is an object which which obviously
336 ;; can't contain other objects
337 (unless (trivialp value)
338 (if (xset-member-p value xset)
339 (return-from grovel nil)
340 (add-to-xset value xset))
341 (typecase value
342 (cons
343 (grovel (car value))
344 (grovel (cdr value)))
345 (simple-vector
346 (dotimes (i (length value))
347 (grovel (svref value i))))
348 ((vector t)
349 (dotimes (i (length value))
350 (grovel (aref value i))))
351 ((simple-array t)
352 ;; Even though the (ARRAY T) branch does the exact
353 ;; same thing as this branch we do this separately
354 ;; so that the compiler can use faster versions of
355 ;; array-total-size and row-major-aref.
356 (dotimes (i (array-total-size value))
357 (grovel (row-major-aref value i))))
358 ((array t)
359 (dotimes (i (array-total-size value))
360 (grovel (row-major-aref value i))))
361 (#+sb-xc-host structure!object
362 #-sb-xc-host instance
363 ;; In the target SBCL, we can dump any instance, but
364 ;; in the cross-compilation host, %INSTANCE-FOO
365 ;; functions don't work on general instances, only on
366 ;; STRUCTURE!OBJECTs.
368 ;; Behold the wonderfully clear sense of this-
369 ;; WHEN (EMIT-MAKE-LOAD-FORM VALUE)
370 ;; meaning "when you're _NOT_ using a custom load-form"
372 ;; FIXME: What about funcallable instances with
373 ;; user-defined MAKE-LOAD-FORM methods?
374 (when (emit-make-load-form value)
375 #+sb-xc-host
376 (aver (zerop (layout-raw-slot-metadata
377 (%instance-layout value))))
378 (do-instance-tagged-slot (i value)
379 (grovel (%instance-ref value i)))))
380 ;; The cross-compiler can dump certain instances that are not
381 ;; subtypes of STRUCTURE!OBJECT, as long as it has processed
382 ;; the defstruct.
383 #+sb-xc-host
384 ((satisfies sb!kernel::xc-dumpable-structure-instance-p)
385 (do-instance-tagged-slot (i value)
386 (grovel (%instance-ref value i))))
388 (compiler-error
389 "Objects of type ~S can't be dumped into fasl files."
390 (type-of value)))))))
391 ;; Dump all non-trivial named constants using the name.
392 (if (and namep (not (typep constant '(or symbol character
393 ;; FIXME: Cold init breaks if we
394 ;; try to reference FP constants
395 ;; thru their names.
396 #+sb-xc-host number
397 #-sb-xc-host fixnum))))
398 (emit-make-load-form constant name)
399 (grovel constant))))
400 (values))
402 ;;;; some flow-graph hacking utilities
404 ;;; This function sets up the back link between the node and the
405 ;;; ctran which continues at it.
406 (defun link-node-to-previous-ctran (node ctran)
407 (declare (type node node) (type ctran ctran))
408 (aver (not (ctran-next ctran)))
409 (setf (ctran-next ctran) node)
410 (setf (node-prev node) ctran))
412 ;;; This function is used to set the ctran for a node, and thus
413 ;;; determine what is evaluated next. If the ctran has no block, then
414 ;;; we make it be in the block that the node is in. If the ctran heads
415 ;;; its block, we end our block and link it to that block.
416 #!-sb-fluid (declaim (inline use-ctran))
417 (defun use-ctran (node ctran)
418 (declare (type node node) (type ctran ctran))
419 (if (eq (ctran-kind ctran) :unused)
420 (let ((node-block (ctran-block (node-prev node))))
421 (setf (ctran-block ctran) node-block)
422 (setf (ctran-kind ctran) :inside-block)
423 (setf (ctran-use ctran) node)
424 (setf (node-next node) ctran))
425 (%use-ctran node ctran)))
426 (defun %use-ctran (node ctran)
427 (declare (type node node) (type ctran ctran) (inline member))
428 (let ((block (ctran-block ctran))
429 (node-block (ctran-block (node-prev node))))
430 (aver (eq (ctran-kind ctran) :block-start))
431 (when (block-last node-block)
432 (error "~S has already ended." node-block))
433 (setf (block-last node-block) node)
434 (when (block-succ node-block)
435 (error "~S already has successors." node-block))
436 (setf (block-succ node-block) (list block))
437 (when (memq node-block (block-pred block))
438 (error "~S is already a predecessor of ~S." node-block block))
439 (push node-block (block-pred block))))
441 ;;; Insert NEW before OLD in the flow-graph.
442 (defun insert-node-before (old new)
443 (let ((prev (node-prev old))
444 (temp (make-ctran)))
445 (ensure-block-start prev)
446 (setf (ctran-next prev) nil)
447 (link-node-to-previous-ctran new prev)
448 (use-ctran new temp)
449 (link-node-to-previous-ctran old temp))
450 (values))
452 ;;; This function is used to set the ctran for a node, and thus
453 ;;; determine what receives the value.
454 (defun use-lvar (node lvar)
455 (declare (type valued-node node) (type (or lvar null) lvar))
456 (aver (not (node-lvar node)))
457 (when lvar
458 (setf (node-lvar node) lvar)
459 (cond ((null (lvar-uses lvar))
460 (setf (lvar-uses lvar) node))
461 ((listp (lvar-uses lvar))
462 (aver (not (memq node (lvar-uses lvar))))
463 (push node (lvar-uses lvar)))
465 (aver (neq node (lvar-uses lvar)))
466 (setf (lvar-uses lvar) (list node (lvar-uses lvar)))))
467 (reoptimize-lvar lvar)))
469 #!-sb-fluid(declaim (inline use-continuation))
470 (defun use-continuation (node ctran lvar)
471 (use-ctran node ctran)
472 (use-lvar node lvar))
474 ;;;; exported functions
476 ;;; This function takes a form and the top level form number for that
477 ;;; form, and returns a lambda representing the translation of that
478 ;;; form in the current global environment. The returned lambda is a
479 ;;; top level lambda that can be called to cause evaluation of the
480 ;;; forms. This lambda is in the initial component. If FOR-VALUE is T,
481 ;;; then the value of the form is returned from the function,
482 ;;; otherwise NIL is returned.
484 ;;; This function may have arbitrary effects on the global environment
485 ;;; due to processing of EVAL-WHENs. All syntax error checking is
486 ;;; done, with erroneous forms being replaced by a proxy which signals
487 ;;; an error if it is evaluated. Warnings about possibly inconsistent
488 ;;; or illegal changes to the global environment will also be given.
490 ;;; We make the initial component and convert the form in a PROGN (and
491 ;;; an optional NIL tacked on the end.) We then return the lambda. We
492 ;;; bind all of our state variables here, rather than relying on the
493 ;;; global value (if any) so that IR1 conversion will be reentrant.
494 ;;; This is necessary for EVAL-WHEN processing, etc.
496 ;;; The hashtables used to hold global namespace info must be
497 ;;; reallocated elsewhere. Note also that *LEXENV* is not bound, so
498 ;;; that local macro definitions can be introduced by enclosing code.
499 (defun ir1-toplevel (form path for-value &optional (allow-instrumenting t))
500 (declare (list path))
501 (let* ((*current-path* path)
502 (component (make-empty-component))
503 (*current-component* component)
504 (*allow-instrumenting* allow-instrumenting))
505 (setf (component-name component) 'initial-component)
506 (setf (component-kind component) :initial)
507 (let* ((forms (if for-value `(,form) `(,form nil)))
508 (res (ir1-convert-lambda-body
509 forms ()
510 :debug-name (debug-name 'top-level-form #+sb-xc-host nil #-sb-xc-host form))))
511 (setf (functional-entry-fun res) res
512 (functional-arg-documentation res) ()
513 (functional-kind res) :toplevel)
514 res)))
516 ;;; This function is called on freshly read forms to record the
517 ;;; initial location of each form (and subform.) Form is the form to
518 ;;; find the paths in, and TLF-NUM is the top level form number of the
519 ;;; truly top level form.
521 ;;; This gets a bit interesting when the source code is circular. This
522 ;;; can (reasonably?) happen in the case of circular list constants.
523 (defun find-source-paths (form tlf-num)
524 (declare (type index tlf-num))
525 (let ((*current-form-number* 0))
526 (sub-find-source-paths form (list tlf-num)))
527 (values))
528 (defun sub-find-source-paths (form path)
529 (unless (get-source-path form)
530 (note-source-path form path)
531 (incf *current-form-number*)
532 (let ((pos 0)
533 (subform form)
534 (trail form))
535 (declare (fixnum pos))
536 (macrolet ((frob ()
537 `(progn
538 (when (atom subform) (return))
539 (let ((fm (car subform)))
540 (when (sb!int:comma-p fm)
541 (setf fm (sb!int:comma-expr fm)))
542 (cond ((consp fm)
543 ;; If it's a cons, recurse.
544 (sub-find-source-paths fm (cons pos path)))
545 ((eq 'quote fm)
546 ;; Don't look into quoted constants.
547 ;; KLUDGE: this can't actually know about constants.
548 ;; e.g. (let ((quote (error "foo")))) or
549 ;; (list quote (error "foo")) are not
550 ;; constants and yet are ignored.
551 (return))
552 ((not (zerop pos))
553 ;; Otherwise store the containing form. It's not
554 ;; perfect, but better than nothing.
555 (note-source-path subform pos path)))
556 (incf pos))
557 (setq subform (cdr subform))
558 (when (eq subform trail) (return)))))
559 (loop
560 (frob)
561 (frob)
562 (setq trail (cdr trail)))))))
564 ;;;; IR1-CONVERT, macroexpansion and special form dispatching
566 (declaim (ftype (sfunction (ctran ctran (or lvar null) t)
567 (values))
568 ir1-convert))
569 (macrolet (;; Bind *COMPILER-ERROR-BAILOUT* to a function that throws
570 ;; out of the body and converts a condition signalling form
571 ;; instead. The source form is converted to a string since it
572 ;; may contain arbitrary non-externalizable objects.
573 (ir1-error-bailout ((start next result form) &body body)
574 (with-unique-names (skip condition)
575 `(block ,skip
576 (let ((,condition (catch 'ir1-error-abort
577 (let ((*compiler-error-bailout*
578 (lambda (&optional e)
579 (throw 'ir1-error-abort e))))
580 ,@body
581 (return-from ,skip nil)))))
582 (ir1-convert ,start ,next ,result
583 (make-compiler-error-form ,condition
584 ,form)))))))
586 ;; Translate FORM into IR1. The code is inserted as the NEXT of the
587 ;; CTRAN START. RESULT is the LVAR which receives the value of the
588 ;; FORM to be translated. The translators call this function
589 ;; recursively to translate their subnodes.
591 ;; As a special hack to make life easier in the compiler, a LEAF
592 ;; IR1-converts into a reference to that LEAF structure. This allows
593 ;; the creation using backquote of forms that contain leaf
594 ;; references, without having to introduce dummy names into the
595 ;; namespace.
596 (defun ir1-convert (start next result form)
597 (let* ((*current-path* (ensure-source-path form))
598 (start (instrument-coverage start nil form)))
599 (ir1-error-bailout (start next result form)
600 (cond ((atom form)
601 (cond ((and (symbolp form) (not (keywordp form)))
602 (ir1-convert-var start next result form))
603 ((leaf-p form)
604 (reference-leaf start next result form))
606 (reference-constant start next result form))))
608 (ir1-convert-functoid start next result form)))))
609 (values))
611 ;; Generate a reference to a manifest constant, creating a new leaf
612 ;; if necessary.
613 (defun reference-constant (start next result value)
614 (declare (type ctran start next)
615 (type (or lvar null) result))
616 (ir1-error-bailout (start next result value)
617 (let* ((leaf (find-constant value))
618 (res (make-ref leaf)))
619 (push res (leaf-refs leaf))
620 (link-node-to-previous-ctran res start)
621 (use-continuation res next result)))
622 (values)))
624 ;;; Add FUNCTIONAL to the COMPONENT-REANALYZE-FUNCTIONALS, unless it's
625 ;;; some trivial type for which reanalysis is a trivial no-op, or
626 ;;; unless it doesn't belong in this component at all.
628 ;;; FUNCTIONAL is returned.
629 (defun maybe-reanalyze-functional (functional)
631 (aver (not (eql (functional-kind functional) :deleted))) ; bug 148
632 (aver-live-component *current-component*)
634 ;; When FUNCTIONAL is of a type for which reanalysis isn't a trivial
635 ;; no-op
636 (when (typep functional '(or optional-dispatch clambda))
638 ;; When FUNCTIONAL knows its component
639 (when (lambda-p functional)
640 (aver (eql (lambda-component functional) *current-component*)))
642 (pushnew functional
643 (component-reanalyze-functionals *current-component*)))
645 functional)
647 ;;; Generate a REF node for LEAF, frobbing the LEAF structure as
648 ;;; needed. If LEAF represents a defined function which has already
649 ;;; been converted, and is not :NOTINLINE, then reference the
650 ;;; functional instead.
651 (defun reference-leaf (start next result leaf &optional (name '.anonymous.))
652 (declare (type ctran start next) (type (or lvar null) result) (type leaf leaf))
653 (assure-leaf-live-p leaf)
654 (let* ((type (lexenv-find leaf type-restrictions))
655 (leaf (or (and (defined-fun-p leaf)
656 (not (eq (defined-fun-inlinep leaf)
657 :notinline))
658 (let ((functional (defined-fun-functional leaf)))
659 (when (and functional (not (functional-kind functional)))
660 (maybe-reanalyze-functional functional))))
661 (when (and (lambda-p leaf)
662 (memq (functional-kind leaf)
663 '(nil :optional)))
664 (maybe-reanalyze-functional leaf))
665 leaf))
666 (ref (make-ref leaf name)))
667 (push ref (leaf-refs leaf))
668 (setf (leaf-ever-used leaf) t)
669 (link-node-to-previous-ctran ref start)
670 (cond (type (let* ((ref-ctran (make-ctran))
671 (ref-lvar (make-lvar))
672 (cast (make-cast ref-lvar
673 (make-single-value-type type)
674 (lexenv-policy *lexenv*))))
675 (setf (lvar-dest ref-lvar) cast)
676 (use-continuation ref ref-ctran ref-lvar)
677 (link-node-to-previous-ctran cast ref-ctran)
678 (use-continuation cast next result)))
679 (t (use-continuation ref next result)))))
681 (defun always-boundp (name)
682 (case (info :variable :always-bound name)
683 (:always-bound t)
684 ;; Compiling to fasl considers a symbol always-bound if its
685 ;; :always-bound info value is now T or will eventually be T.
686 (:eventually (producing-fasl-file))))
688 ;;; Convert a reference to a symbolic constant or variable. If the
689 ;;; symbol is entered in the LEXENV-VARS we use that definition,
690 ;;; otherwise we find the current global definition. This is also
691 ;;; where we pick off symbol macro and alien variable references.
692 (defun ir1-convert-var (start next result name)
693 (declare (type ctran start next) (type (or lvar null) result) (symbol name))
694 (let ((var (or (lexenv-find name vars) (find-free-var name))))
695 (if (and (global-var-p var) (not (always-boundp name)))
696 ;; KLUDGE: If the variable may be unbound, convert using SYMBOL-VALUE
697 ;; which is not flushable, so that unbound dead variables signal an
698 ;; error (bug 412, lp#722734): checking for null RESULT is not enough,
699 ;; since variables can become dead due to later optimizations.
700 (ir1-convert start next result
701 (if (eq (global-var-kind var) :global)
702 `(symbol-global-value ',name)
703 `(symbol-value ',name)))
704 (etypecase var
705 (leaf
706 (cond
707 ((lambda-var-p var)
708 (let ((home (ctran-home-lambda-or-null start)))
709 (when home
710 (sset-adjoin var (lambda-calls-or-closes home))))
711 (when (lambda-var-ignorep var)
712 ;; (ANSI's specification for the IGNORE declaration requires
713 ;; that this be a STYLE-WARNING, not a full WARNING.)
714 #-sb-xc-host
715 (compiler-style-warn "reading an ignored variable: ~S" name)
716 ;; there's no need for us to accept ANSI's lameness when
717 ;; processing our own code, though.
718 #+sb-xc-host
719 (warn "reading an ignored variable: ~S" name)))
721 ;; This case signals {EARLY,LATE}-DEPRECATION-WARNING
722 ;; for CONSTANT nodes in :EARLY and :LATE deprecation
723 ;; (constants in :FINAL deprecation are represented as
724 ;; symbol-macros).
725 (aver (memq (check-deprecated-thing 'variable name)
726 '(nil :early :late)))))
727 (reference-leaf start next result var name))
728 ((cons (eql macro)) ; symbol-macro
729 ;; This case signals {EARLY,LATE,FINAL}-DEPRECATION-WARNING
730 ;; for symbol-macros. Includes variables, constants,
731 ;; etc. in :FINAL deprecation.
732 (check-deprecated-thing 'variable name)
733 ;; FIXME: [Free] type declarations. -- APD, 2002-01-26
734 (ir1-convert start next result (cdr var)))
735 (heap-alien-info
736 (ir1-convert start next result `(%heap-alien ',var))))))
737 (values))
739 ;;; Find a compiler-macro for a form, taking FUNCALL into account.
740 (defun find-compiler-macro (opname form)
741 (flet ((legal-cm-name-p (name)
742 (and (legal-fun-name-p name)
743 (or (not (symbolp name))
744 (not (sb!xc:macro-function name *lexenv*))))))
745 (if (eq opname 'funcall)
746 (let ((fun-form (cadr form)))
747 (cond ((and (consp fun-form) (eq 'function (car fun-form))
748 (not (cddr fun-form)))
749 (let ((real-fun (cadr fun-form)))
750 (if (legal-cm-name-p real-fun)
751 (values (sb!xc:compiler-macro-function real-fun *lexenv*)
752 real-fun)
753 (values nil nil))))
754 ((sb!xc:constantp fun-form *lexenv*)
755 (let ((fun (constant-form-value fun-form *lexenv*)))
756 (if (legal-cm-name-p fun)
757 ;; CLHS tells us that local functions must shadow
758 ;; compiler-macro-functions, but since the call is
759 ;; through a name, we are obviously interested
760 ;; in the global function.
761 ;; KLUDGE: CLHS 3.2.2.1.1 also says that it can be
762 ;; "a list whose car is funcall and whose cadr is
763 ;; a list (function name)", that means that
764 ;; (funcall 'name) that gets here doesn't fit the
765 ;; definition.
766 (values (sb!xc:compiler-macro-function fun nil) fun)
767 (values nil nil))))
769 (values nil nil))))
770 (if (legal-fun-name-p opname)
771 (values (sb!xc:compiler-macro-function opname *lexenv*) opname)
772 (values nil nil)))))
774 ;;; If FORM has a usable compiler macro, use it; otherwise return FORM itself.
775 ;;; Return the name of the compiler-macro as a secondary value, if applicable.
776 (defun expand-compiler-macro (form)
777 (binding* ((name (car form))
778 ((cmacro-fun cmacro-fun-name)
779 (find-compiler-macro name form)))
780 (cond
781 ((and cmacro-fun
782 ;; CLHS 3.2.2.1.3 specifies that NOTINLINE
783 ;; suppresses compiler-macros.
784 (not (fun-lexically-notinline-p cmacro-fun-name)))
785 (check-deprecated-thing 'function name)
786 (values (handler-case (careful-expand-macro cmacro-fun form t)
787 (compiler-macro-keyword-problem (condition)
788 (print-compiler-message
789 *error-output* "note: ~A" (list condition))
790 form))
791 cmacro-fun-name))
793 (values form nil)))))
795 ;;; Picks off special forms and compiler-macro expansions, and hands
796 ;;; the rest to IR1-CONVERT-COMMON-FUNCTOID
797 (defun ir1-convert-functoid (start next result form)
798 (let* ((op (car form))
799 (translator (and (symbolp op) (info :function :ir1-convert op))))
800 (if translator
801 (funcall translator start next result form)
802 (multiple-value-bind (res cmacro-fun-name)
803 (expand-compiler-macro form)
804 (cond ((eq res form)
805 (ir1-convert-common-functoid start next result form op))
807 (unless (policy *lexenv* (zerop store-xref-data))
808 (record-call cmacro-fun-name (ctran-block start)
809 *current-path*))
810 (ir1-convert start next result res)))))))
812 ;;; Handles the "common" cases: any other forms except special forms
813 ;;; and compiler-macros.
814 (defun ir1-convert-common-functoid (start next result form op)
815 (cond ((or (symbolp op) (leaf-p op))
816 (let ((lexical-def (if (leaf-p op) op (lexenv-find op funs))))
817 (typecase lexical-def
818 (null
819 (check-deprecated-thing 'function op)
820 (ir1-convert-global-functoid start next result form op))
821 (functional
822 (ir1-convert-local-combination start next result form
823 lexical-def))
824 (global-var
825 (check-deprecated-thing 'function (leaf-source-name lexical-def))
826 (ir1-convert-srctran start next result lexical-def form))
828 (aver (and (consp lexical-def) (eq (car lexical-def) 'macro)))
829 (ir1-convert start next result
830 (careful-expand-macro (cdr lexical-def) form))))))
831 ((or (atom op) (not (eq (car op) 'lambda)))
832 (compiler-error "illegal function call"))
834 ;; implicitly (LAMBDA ..) because the LAMBDA expression is
835 ;; the CAR of an executed form.
836 (ir1-convert start next result `(%funcall ,@form)))))
838 ;;; Convert anything that looks like a global function call.
839 (defun ir1-convert-global-functoid (start next result form fun)
840 (declare (type ctran start next) (type (or lvar null) result)
841 (list form))
842 (when (eql fun 'declare)
843 (compiler-error
844 "~@<There is no function named ~S. ~
845 References to ~S in some contexts (like starts of blocks) are unevaluated ~
846 expressions, but here the expression is being evaluated, which invokes ~
847 undefined behaviour.~@:>" fun fun))
848 ;; FIXME: Couldn't all the INFO calls here be converted into
849 ;; standard CL functions, like MACRO-FUNCTION or something? And what
850 ;; happens with lexically-defined (MACROLET) macros here, anyway?
851 (ecase (info :function :kind fun)
852 (:macro
853 (ir1-convert start next result
854 (careful-expand-macro (info :function :macro-function fun)
855 form))
856 (unless (policy *lexenv* (zerop store-xref-data))
857 (record-macroexpansion fun (ctran-block start) *current-path*)))
858 ((nil :function)
859 (ir1-convert-srctran start next result
860 (find-free-fun fun "shouldn't happen! (no-cmacro)")
861 form))))
863 ;;; Expand FORM using the macro whose MACRO-FUNCTION is FUN, trapping
864 ;;; errors which occur during the macroexpansion.
865 (defun careful-expand-macro (fun form &optional cmacro)
866 (flet (;; Return a string to use as a prefix in error reporting,
867 ;; telling something about which form caused the problem.
868 (wherestring ()
869 (let (;; We rely on the printer to abbreviate FORM.
870 (*print-length* 3)
871 (*print-level* 3))
872 (format nil
873 "~@<~A of ~S. Use ~S to intercept.~%~:@>"
874 (cond (cmacro
875 #-sb-xc-host "Error during compiler-macroexpansion"
876 #+sb-xc-host "Error during XC compiler-macroexpansion")
878 #-sb-xc-host "during macroexpansion"
879 #+sb-xc-host "during XC macroexpansion"))
880 form
881 '*break-on-signals*))))
882 (handler-bind (;; KLUDGE: CMU CL in its wisdom (version 2.4.6 for Debian
883 ;; Linux, anyway) raises a CL:WARNING condition (not a
884 ;; CL:STYLE-WARNING) for undefined symbols when converting
885 ;; interpreted functions, causing COMPILE-FILE to think the
886 ;; file has a real problem, causing COMPILE-FILE to return
887 ;; FAILURE-P set (not just WARNINGS-P set). Since undefined
888 ;; symbol warnings are often harmless forward references,
889 ;; and since it'd be inordinately painful to try to
890 ;; eliminate all such forward references, these warnings
891 ;; are basically unavoidable. Thus, we need to coerce the
892 ;; system to work through them, and this code does so, by
893 ;; crudely suppressing all warnings in cross-compilation
894 ;; macroexpansion. -- WHN 19990412
895 #+(and cmu sb-xc-host)
896 (warning (lambda (c)
897 (compiler-notify
898 "~@<~A~:@_~
899 ~A~:@_~
900 ~@<(KLUDGE: That was a non-STYLE WARNING. ~
901 Ordinarily that would cause compilation to ~
902 fail. However, since we're running under ~
903 CMU CL, and since CMU CL emits non-STYLE ~
904 warnings for safe, hard-to-fix things (e.g. ~
905 references to not-yet-defined functions) ~
906 we're going to have to ignore it and ~
907 proceed anyway. Hopefully we're not ~
908 ignoring anything horrible here..)~:@>~:>"
909 (wherestring)
911 (muffle-warning)
912 (bug "no MUFFLE-WARNING restart")))
913 (error
914 (lambda (c)
915 (cond
916 (cmacro
917 ;; The spec is silent on what we should do. Signaling
918 ;; a full warning but declining to expand seems like
919 ;; a conservative and sane thing to do.
920 (compiler-warn "~@<~A~@:_ ~A~:>" (wherestring) c)
921 (return-from careful-expand-macro form))
923 (compiler-error "~@<~A~@:_ ~A~:>"
924 (wherestring) c))))))
925 (funcall (valid-macroexpand-hook) fun form *lexenv*))))
927 ;;;; conversion utilities
929 ;;; Convert a bunch of forms, discarding all the values except the
930 ;;; last. If there aren't any forms, then translate a NIL.
931 (declaim (ftype (sfunction (ctran ctran (or lvar null) list) (values))
932 ir1-convert-progn-body))
933 (defun ir1-convert-progn-body (start next result body)
934 (if (endp body)
935 (reference-constant start next result nil)
936 (let ((this-start start)
937 (forms body))
938 (loop
939 (let ((form (car forms)))
940 (setf this-start
941 (maybe-instrument-progn-like this-start forms form))
942 (when (endp (cdr forms))
943 (ir1-convert this-start next result form)
944 (return))
945 (let ((this-ctran (make-ctran)))
946 (ir1-convert this-start this-ctran nil form)
947 (setq this-start this-ctran
948 forms (cdr forms)))))))
949 (values))
952 ;;;; code coverage
954 ;;; Check the policy for whether we should generate code coverage
955 ;;; instrumentation. If not, just return the original START
956 ;;; ctran. Otherwise insert code coverage instrumentation after
957 ;;; START, and return the new ctran.
958 (defun instrument-coverage (start mode form)
959 ;; We don't actually use FORM for anything, it's just convenient to
960 ;; have around when debugging the instrumentation.
961 (declare (ignore form))
962 (if (and (policy *lexenv* (> store-coverage-data 0))
963 *code-coverage-records*
964 *allow-instrumenting*)
965 (let ((path (source-path-original-source *current-path*)))
966 (when mode
967 (push mode path))
968 (if (member (ctran-block start)
969 (gethash path *code-coverage-blocks*))
970 ;; If this source path has already been instrumented in
971 ;; this block, don't instrument it again.
972 start
973 (let ((store
974 ;; Get an interned record cons for the path. A cons
975 ;; with the same object identity must be used for
976 ;; each instrument for the same block.
977 (or (gethash path *code-coverage-records*)
978 (setf (gethash path *code-coverage-records*)
979 (cons path +code-coverage-unmarked+))))
980 (next (make-ctran))
981 (*allow-instrumenting* nil))
982 (push (ctran-block start)
983 (gethash path *code-coverage-blocks*))
984 (let ((*allow-instrumenting* nil))
985 (ir1-convert start next nil
986 `(locally
987 (declare (optimize speed
988 (safety 0)
989 (debug 0)
990 (check-constant-modification 0)))
991 ;; We're being naughty here, and
992 ;; modifying constant data. That's ok,
993 ;; we know what we're doing.
994 (%rplacd ',store t))))
995 next)))
996 start))
998 ;;; In contexts where we don't have a source location for FORM
999 ;;; e.g. due to it not being a cons, but where we have a source
1000 ;;; location for the enclosing cons, use the latter source location if
1001 ;;; available. This works pretty well in practice, since many PROGNish
1002 ;;; macroexpansions will just directly splice a block of forms into
1003 ;;; some enclosing form with `(progn ,@body), thus retaining the
1004 ;;; EQness of the conses.
1005 (defun maybe-instrument-progn-like (start forms form)
1006 (or (when (and *allow-instrumenting*
1007 (not (get-source-path form)))
1008 (let ((*current-path* (get-source-path forms)))
1009 (when *current-path*
1010 (instrument-coverage start nil form))))
1011 start))
1013 (defun record-code-coverage (info cc)
1014 (setf (gethash info *code-coverage-info*) cc))
1016 (defun clear-code-coverage ()
1017 (clrhash *code-coverage-info*))
1019 (defun reset-code-coverage ()
1020 (maphash (lambda (info cc)
1021 (declare (ignore info))
1022 (dolist (cc-entry cc)
1023 (setf (cdr cc-entry) +code-coverage-unmarked+)))
1024 *code-coverage-info*))
1026 (defun code-coverage-record-marked (record)
1027 (aver (consp record))
1028 (ecase (cdr record)
1029 ((#.+code-coverage-unmarked+) nil)
1030 ((t) t)))
1033 ;;;; converting combinations
1035 ;;; Does this form look like something that we should add single-stepping
1036 ;;; instrumentation for?
1037 (defun step-form-p (form)
1038 (flet ((step-symbol-p (symbol)
1039 (and (not (member (symbol-package symbol)
1040 (load-time-value
1041 ;; KLUDGE: packages we're not interested in
1042 ;; stepping.
1043 (mapcar #'find-package '(sb!c sb!int sb!impl
1044 sb!kernel sb!pcl)) t)))
1045 ;; Consistent treatment of *FOO* vs (SYMBOL-VALUE '*FOO*):
1046 ;; we insert calls to SYMBOL-VALUE for most non-lexical
1047 ;; variable references in order to avoid them being elided
1048 ;; if the value is unused.
1049 (or (not (member symbol '(symbol-value symbol-global-value)))
1050 (not (constantp (second form)))))))
1051 (and *allow-instrumenting*
1052 (policy *lexenv* (= insert-step-conditions 3))
1053 (listp form)
1054 (symbolp (car form))
1055 (step-symbol-p (car form)))))
1057 ;;; Convert a function call where the function FUN is a LEAF. FORM is
1058 ;;; the source for the call. We return the COMBINATION node so that
1059 ;;; the caller can poke at it if it wants to.
1060 (declaim (ftype (sfunction (ctran ctran (or lvar null) list leaf) combination)
1061 ir1-convert-combination))
1062 (defun ir1-convert-combination (start next result form fun)
1063 (let ((ctran (make-ctran))
1064 (fun-lvar (make-lvar)))
1065 (ir1-convert start ctran fun-lvar `(the (or function symbol) ,fun))
1066 (let ((combination
1067 (ir1-convert-combination-args fun-lvar ctran next result
1068 (cdr form))))
1069 (when (step-form-p form)
1070 ;; Store a string representation of the form in the
1071 ;; combination node. This will let the IR2 translator know
1072 ;; that we want stepper instrumentation for this node. The
1073 ;; string will be stored in the debug-info by DUMP-1-LOCATION.
1074 (setf (combination-step-info combination)
1075 (let ((*print-pretty* t)
1076 (*print-circle* t)
1077 (*print-readably* nil))
1078 (prin1-to-string form))))
1079 combination)))
1081 ;;; Convert the arguments to a call and make the COMBINATION
1082 ;;; node. FUN-LVAR yields the function to call. ARGS is the list of
1083 ;;; arguments for the call, which defaults to the cdr of source. We
1084 ;;; return the COMBINATION node.
1085 (defun ir1-convert-combination-args (fun-lvar start next result args)
1086 (declare (type ctran start next)
1087 (type lvar fun-lvar)
1088 (type (or lvar null) result)
1089 (list args))
1090 (let ((node (make-combination fun-lvar)))
1091 (setf (lvar-dest fun-lvar) node)
1092 (collect ((arg-lvars))
1093 (let ((this-start start)
1094 (forms args))
1095 (dolist (arg args)
1096 (setf this-start
1097 (maybe-instrument-progn-like this-start forms arg))
1098 (setf forms (cdr forms))
1099 (let ((this-ctran (make-ctran))
1100 (this-lvar (make-lvar node)))
1101 (ir1-convert this-start this-ctran this-lvar arg)
1102 (setq this-start this-ctran)
1103 (arg-lvars this-lvar)))
1104 (link-node-to-previous-ctran node this-start)
1105 (use-continuation node next result)
1106 (setf (combination-args node) (arg-lvars))))
1107 node))
1109 ;;; Convert a call to a global function. If not :NOTINLINE, then we do
1110 ;;; source transforms and try out any inline expansion. If there is no
1111 ;;; expansion, but is :INLINE, then give an efficiency note (unless a
1112 ;;; known function which will quite possibly be open-coded.) Next, we
1113 ;;; go to ok-combination conversion.
1114 (defun ir1-convert-srctran (start next result var form)
1115 (declare (type ctran start next) (type (or lvar null) result)
1116 (type global-var var))
1117 (let ((name (leaf-source-name var))
1118 (inlinep (when (defined-fun-p var)
1119 (defined-fun-inlinep var))))
1120 (if (eq inlinep :notinline)
1121 (ir1-convert-combination start next result form var)
1122 (let* ((transform (info :function :source-transform name)))
1123 (if transform
1124 (multiple-value-bind (transformed pass)
1125 (if (functionp transform)
1126 (funcall transform form *lexenv*)
1127 (let ((result
1128 (if (eq (cdr transform) :predicate)
1129 (and (singleton-p (cdr form))
1130 `(%instance-typep
1131 ,(cadr form)
1132 ',(dd-name (car transform))))
1133 (slot-access-transform
1134 (if (consp name) :write :read)
1135 (cdr form) transform))))
1136 (values result (null result))))
1137 (cond (pass
1138 (ir1-convert-maybe-predicate start next result form var))
1140 (unless (policy *lexenv* (zerop store-xref-data))
1141 (record-call name (ctran-block start) *current-path*))
1142 (ir1-convert start next result transformed))))
1143 (ir1-convert-maybe-predicate start next result form var))))))
1145 ;;; KLUDGE: If we insert a synthetic IF for a function with the PREDICATE
1146 ;;; attribute, don't generate any branch coverage instrumentation for it.
1147 (defvar *instrument-if-for-code-coverage* t)
1149 ;;; If the function has the PREDICATE attribute, and the RESULT's DEST
1150 ;;; isn't an IF, then we convert (IF <form> T NIL), ensuring that a
1151 ;;; predicate always appears in a conditional context.
1153 ;;; If the function isn't a predicate, then we call
1154 ;;; IR1-CONVERT-COMBINATION-CHECKING-TYPE.
1155 (defun ir1-convert-maybe-predicate (start next result form var)
1156 (declare (type ctran start next)
1157 (type (or lvar null) result)
1158 (list form)
1159 (type global-var var))
1160 (let ((info (info :function :info (leaf-source-name var))))
1161 (if (and info
1162 (ir1-attributep (fun-info-attributes info) predicate)
1163 (not (if-p (and result (lvar-dest result)))))
1164 (let ((*instrument-if-for-code-coverage* nil))
1165 (ir1-convert start next result `(if ,form t nil)))
1166 (ir1-convert-combination-checking-type start next result form var))))
1168 ;;; Actually really convert a global function call that we are allowed
1169 ;;; to early-bind.
1171 ;;; If we know the function type of the function, then we check the
1172 ;;; call for syntactic legality with respect to the declared function
1173 ;;; type. If it is impossible to determine whether the call is correct
1174 ;;; due to non-constant keywords, then we give up, marking the call as
1175 ;;; :FULL to inhibit further error messages. We return true when the
1176 ;;; call is legal.
1178 ;;; If the call is legal, we also propagate type assertions from the
1179 ;;; function type to the arg and result lvars. We do this now so that
1180 ;;; IR1 optimize doesn't have to redundantly do the check later so
1181 ;;; that it can do the type propagation.
1182 (defun ir1-convert-combination-checking-type (start next result form var)
1183 (declare (type ctran start next) (type (or lvar null) result)
1184 (list form)
1185 (type leaf var))
1186 (let* ((node (ir1-convert-combination start next result form var))
1187 (fun-lvar (basic-combination-fun node))
1188 (type (leaf-type var)))
1189 (when (validate-call-type node type var t)
1190 (setf (lvar-%derived-type fun-lvar)
1191 (make-single-value-type type))
1192 (setf (lvar-reoptimize fun-lvar) nil)))
1193 (values))
1195 ;;; Convert a call to a local function, or if the function has already
1196 ;;; been LET converted, then throw FUNCTIONAL to
1197 ;;; LOCALL-ALREADY-LET-CONVERTED. The THROW should only happen when we
1198 ;;; are converting inline expansions for local functions during
1199 ;;; optimization.
1200 (defun ir1-convert-local-combination (start next result form functional)
1201 (assure-functional-live-p functional)
1202 (ir1-convert-combination start next result
1203 form
1204 (maybe-reanalyze-functional functional)))
1206 ;;;; PROCESS-DECLS
1208 ;;; Given a list of LAMBDA-VARs and a variable name, return the
1209 ;;; LAMBDA-VAR for that name, or NIL if it isn't found. We return the
1210 ;;; *last* variable with that name, since LET* bindings may be
1211 ;;; duplicated, and declarations always apply to the last.
1212 (declaim (ftype (sfunction (list symbol) (or lambda-var list))
1213 find-in-bindings))
1214 (defun find-in-bindings (vars name)
1215 (let ((found nil))
1216 (dolist (var vars)
1217 (cond ((leaf-p var)
1218 (when (eq (leaf-source-name var) name)
1219 (setq found var))
1220 (let ((info (lambda-var-arg-info var)))
1221 (when info
1222 (let ((supplied-p (arg-info-supplied-p info)))
1223 (when (and supplied-p
1224 (eq (leaf-source-name supplied-p) name))
1225 (setq found supplied-p))))))
1226 ((and (consp var) (eq (car var) name))
1227 (setf found (cdr var)))))
1228 found))
1230 ;;; Called by PROCESS-DECLS to deal with a variable type declaration.
1231 ;;; If a LAMBDA-VAR being bound, we intersect the type with the var's
1232 ;;; type, otherwise we add a type restriction on the var. If a symbol
1233 ;;; macro, we just wrap a THE around the expansion.
1234 (defun process-type-decl (decl res vars context)
1235 (declare (type list decl vars) (type lexenv res))
1236 (let* ((type-specifier (first decl))
1237 (type (progn
1238 (when (typep type-specifier 'type-specifier)
1239 (check-deprecated-type type-specifier))
1240 (compiler-specifier-type type-specifier))))
1241 (collect ((restr nil cons)
1242 (new-vars nil cons))
1243 (dolist (var-name (rest decl))
1244 (unless (symbolp var-name)
1245 (compiler-error "Variable name is not a symbol: ~S." var-name))
1246 (when (boundp var-name)
1247 (program-assert-symbol-home-package-unlocked
1248 context var-name "declaring the type of ~A"))
1249 (let* ((bound-var (find-in-bindings vars var-name))
1250 (var (or bound-var
1251 (lexenv-find var-name vars)
1252 (find-free-var var-name))))
1253 (etypecase var
1254 (leaf
1255 (flet
1256 ((process-var (var bound-var)
1257 (let* ((old-type (or (lexenv-find var type-restrictions)
1258 (leaf-type var)))
1259 (int (if (or (fun-type-p type)
1260 (fun-type-p old-type))
1261 type
1262 (type-approx-intersection2
1263 old-type type))))
1264 (cond ((eq int *empty-type*)
1265 (unless (policy *lexenv* (= inhibit-warnings 3))
1266 (warn
1267 'type-warning
1268 :format-control
1269 "The type declarations ~S and ~S for ~S conflict."
1270 :format-arguments
1271 (list
1272 (type-specifier old-type)
1273 (type-specifier type)
1274 var-name))))
1275 (bound-var
1276 (setf (leaf-type bound-var) int
1277 (leaf-where-from bound-var) :declared))
1279 (restr (cons var int)))))))
1280 (process-var var bound-var)
1281 (awhen (and (lambda-var-p var)
1282 (lambda-var-specvar var))
1283 (process-var it nil))))
1284 (cons
1285 ;; FIXME: non-ANSI weirdness. [See lp#309122]
1286 (aver (eq (car var) 'macro))
1287 (new-vars `(,var-name . (macro . (the ,(first decl)
1288 ,(cdr var))))))
1289 (heap-alien-info
1290 (compiler-error
1291 "~S is an alien variable, so its type can't be declared."
1292 var-name)))))
1294 (if (or (restr) (new-vars))
1295 (make-lexenv :default res
1296 :type-restrictions (restr)
1297 :vars (new-vars))
1298 res))))
1300 ;;; This is somewhat similar to PROCESS-TYPE-DECL, but handles
1301 ;;; declarations for function variables. In addition to allowing
1302 ;;; declarations for functions being bound, we must also deal with
1303 ;;; declarations that constrain the type of lexically apparent
1304 ;;; functions.
1305 (defun process-ftype-decl (type-specifier res names fvars context)
1306 (declare (type list names fvars)
1307 (type lexenv res))
1308 (let ((type (compiler-specifier-type type-specifier)))
1309 (check-deprecated-type type-specifier)
1310 (unless (csubtypep type (specifier-type 'function))
1311 (compiler-style-warn "ignoring declared FTYPE: ~S (not a function type)"
1312 type-specifier)
1313 (return-from process-ftype-decl res))
1314 (collect ((res nil cons))
1315 (dolist (name names)
1316 (when (fboundp name)
1317 (program-assert-symbol-home-package-unlocked
1318 context name "declaring the ftype of ~A"))
1319 (let ((found (find name fvars :key #'leaf-source-name :test #'equal)))
1320 (cond
1321 (found
1322 (setf (leaf-type found) type)
1323 (assert-definition-type found type
1324 :unwinnage-fun #'compiler-notify
1325 :where "FTYPE declaration"))
1327 (res (cons (find-lexically-apparent-fun
1328 name "in a function type declaration")
1329 type))))))
1330 (if (res)
1331 (make-lexenv :default res :type-restrictions (res))
1332 res))))
1334 ;;; Process a special declaration, returning a new LEXENV. A non-bound
1335 ;;; special declaration is instantiated by throwing a special variable
1336 ;;; into the variables if BINDING-FORM-P is NIL, or otherwise into
1337 ;;; *POST-BINDING-VARIABLE-LEXENV*.
1338 (defun process-special-decl (spec res vars binding-form-p context)
1339 (declare (list spec vars) (type lexenv res))
1340 (collect ((new-venv nil cons))
1341 (dolist (name (cdr spec))
1342 ;; While CLHS seems to allow local SPECIAL declarations for constants,
1343 ;; whatever the semantics are supposed to be is not at all clear to me
1344 ;; -- since constants aren't allowed to be bound it should be a no-op as
1345 ;; no-one can observe the difference portably, but specials are allowed
1346 ;; to be bound... yet nowhere does it say that the special declaration
1347 ;; removes the constantness. Call it a spec bug and prohibit it. Same
1348 ;; for GLOBAL variables.
1349 (let ((kind (info :variable :kind name)))
1350 (unless (member kind '(:special :unknown))
1351 (error "Can't declare ~(~A~) variable locally special: ~S" kind name)))
1352 (program-assert-symbol-home-package-unlocked
1353 context name "declaring ~A special")
1354 (let ((var (find-in-bindings vars name)))
1355 (etypecase var
1356 (cons
1357 (aver (eq (car var) 'macro))
1358 (compiler-error
1359 "~S is a symbol-macro and thus can't be declared special."
1360 name))
1361 (lambda-var
1362 (when (lambda-var-ignorep var)
1363 ;; ANSI's definition for "Declaration IGNORE, IGNORABLE"
1364 ;; requires that this be a STYLE-WARNING, not a full WARNING.
1365 (compiler-style-warn
1366 "The ignored variable ~S is being declared special."
1367 name))
1368 (setf (lambda-var-specvar var)
1369 (specvar-for-binding name)))
1370 (null
1371 (unless (or (assoc name (new-venv) :test #'eq))
1372 (new-venv (cons name (specvar-for-binding name))))))))
1373 (cond (binding-form-p
1374 (setf *post-binding-variable-lexenv*
1375 (append (new-venv) *post-binding-variable-lexenv*))
1376 res)
1377 ((new-venv)
1378 (make-lexenv :default res :vars (new-venv)))
1380 res))))
1382 ;;; Return a DEFINED-FUN which copies a GLOBAL-VAR but for its INLINEP
1383 ;;; (and TYPE if notinline), plus type-restrictions from the lexenv.
1384 (defun make-new-inlinep (var inlinep local-type)
1385 (declare (type global-var var) (type inlinep inlinep))
1386 (let* ((type (if (and (eq inlinep :notinline)
1387 (not (eq (leaf-where-from var) :declared)))
1388 (specifier-type 'function)
1389 (leaf-type var)))
1390 (res (make-defined-fun
1391 :%source-name (leaf-source-name var)
1392 :where-from (leaf-where-from var)
1393 :type (if local-type
1394 (type-intersection local-type type)
1395 type)
1396 :inlinep inlinep)))
1397 (when (defined-fun-p var)
1398 (setf (defined-fun-inline-expansion res)
1399 (defined-fun-inline-expansion var))
1400 (setf (defined-fun-functionals res)
1401 (defined-fun-functionals var)))
1402 ;; FIXME: Is this really right? Needs we not set the FUNCTIONAL
1403 ;; to the original global-var?
1404 res))
1406 ;;; Parse an inline/notinline declaration. If it's a local function we're
1407 ;;; defining, set its INLINEP. If a global function, add a new FENV entry.
1408 (defun process-inline-decl (spec res fvars)
1409 (let ((sense (cdr (assoc (first spec) *inlinep-translations* :test #'eq)))
1410 (new-fenv ()))
1411 (dolist (name (rest spec))
1412 (let ((fvar (find name fvars :key #'leaf-source-name :test #'equal)))
1413 (if fvar
1414 (setf (functional-inlinep fvar) sense)
1415 (let ((found (find-lexically-apparent-fun
1416 name "in an inline or notinline declaration")))
1417 (etypecase found
1418 (functional
1419 (when (policy *lexenv* (>= speed inhibit-warnings))
1420 (compiler-notify "ignoring ~A declaration not at ~
1421 definition of local function:~% ~S"
1422 sense name)))
1423 (global-var
1424 (let ((type
1425 (cdr (assoc found (lexenv-type-restrictions res)))))
1426 (push (cons name (make-new-inlinep found sense type))
1427 new-fenv))))))))
1428 (if new-fenv
1429 (make-lexenv :default res :funs new-fenv)
1430 res)))
1432 ;;; like FIND-IN-BINDINGS, but looks for #'FOO in the FVARS
1433 (defun find-in-bindings-or-fbindings (name vars fvars)
1434 (declare (list vars fvars))
1435 (typecase name
1436 (atom
1437 (find-in-bindings vars name))
1438 ((cons (eql function) (cons * null))
1439 (find (cadr name) fvars :key #'leaf-source-name :test #'equal))
1441 (compiler-error "Malformed function or variable name ~S." name))))
1443 ;;; Process an ignore/ignorable declaration, checking for various losing
1444 ;;; conditions.
1445 (defun process-ignore-decl (spec vars fvars lexenv)
1446 (declare (list spec vars fvars))
1447 (dolist (name (rest spec))
1448 (let ((var (find-in-bindings-or-fbindings name vars fvars)))
1449 (cond
1450 ((not var)
1451 ;; ANSI's definition for "Declaration IGNORE, IGNORABLE"
1452 ;; requires that this be a STYLE-WARNING, not a full WARNING.
1453 ;; But, other Lisp hosts signal a full warning, so when building
1454 ;; the cross-compiler, compile it as #'WARN so that in a self-hosted
1455 ;; build we can at least crash in the same way,
1456 ;; until we resolve this question about how severe the warning is.
1457 (multiple-value-call #+sb-xc-host #'warn
1458 #-sb-xc-host #'compiler-style-warn
1459 "~A declaration for ~A: ~A"
1460 (first spec)
1461 (if (symbolp name)
1462 (values
1463 (case (info :variable :kind name)
1464 (:special "a special variable")
1465 (:global "a global lexical variable")
1466 (:alien "a global alien variable")
1467 (t (if (assoc name (lexenv-vars lexenv))
1468 "a variable from outer scope"
1469 "an unknown variable")))
1470 name)
1471 (values
1472 (cond ((assoc (second name) (lexenv-funs lexenv)
1473 :test #'equal)
1474 "a function from outer scope")
1475 ((info :function :kind (second name))
1476 "a global function")
1478 "an unknown function"))
1479 (second name)))))
1480 ((and (consp var) (eq (car var) 'macro))
1481 ;; Just ignore the IGNORE decl: we don't currently signal style-warnings
1482 ;; for unused symbol-macros, so there's no need to do anything.
1484 ((functional-p var)
1485 (setf (leaf-ever-used var) t))
1486 ((and (lambda-var-specvar var) (eq (first spec) 'ignore))
1487 ;; ANSI's definition for "Declaration IGNORE, IGNORABLE"
1488 ;; requires that this be a STYLE-WARNING, not a full WARNING.
1489 (compiler-style-warn "Declaring special variable ~S to be ~A"
1490 name
1491 (first spec)))
1492 ((eq (first spec) 'ignorable)
1493 (setf (leaf-ever-used var) t))
1495 (setf (lambda-var-ignorep var) t)))))
1496 (values))
1498 (defun process-extent-decl (names vars fvars kind)
1499 (let ((extent
1500 (ecase kind
1501 (truly-dynamic-extent
1502 :always-dynamic)
1503 (dynamic-extent
1504 (when *stack-allocate-dynamic-extent*
1505 :maybe-dynamic))
1506 (indefinite-extent
1507 :indefinite))))
1508 (if extent
1509 (dolist (name names)
1510 (cond
1511 ((symbolp name)
1512 (let* ((bound-var (find-in-bindings vars name))
1513 (var (or bound-var
1514 (lexenv-find name vars)
1515 (maybe-find-free-var name))))
1516 (etypecase var
1517 (leaf
1518 (if bound-var
1519 (if (and (leaf-extent var) (neq extent (leaf-extent var)))
1520 (warn "Multiple incompatible extent declarations for ~S?" name)
1521 (setf (leaf-extent var) extent))
1522 (compiler-notify
1523 "Ignoring free ~S declaration: ~S" kind name)))
1524 (cons
1525 (compiler-error "~S on symbol-macro: ~S" kind name))
1526 (heap-alien-info
1527 (compiler-error "~S on alien-variable: ~S" kind name))
1528 (null
1529 (compiler-style-warn
1530 "Unbound variable declared ~S: ~S" kind name)))))
1531 ((and (consp name)
1532 (eq (car name) 'function)
1533 (null (cddr name))
1534 (valid-function-name-p (cadr name))
1535 (neq :indefinite extent))
1536 (let* ((fname (cadr name))
1537 (bound-fun (find fname fvars
1538 :key #'leaf-source-name
1539 :test #'equal))
1540 (fun (or bound-fun (lexenv-find fname funs))))
1541 (etypecase fun
1542 (leaf
1543 (if bound-fun
1544 #!+stack-allocatable-closures
1545 (setf (leaf-extent bound-fun) extent)
1546 #!-stack-allocatable-closures
1547 (compiler-notify
1548 "Ignoring DYNAMIC-EXTENT declaration on function ~S ~
1549 (not supported on this platform)." fname)
1550 (compiler-notify
1551 "Ignoring free DYNAMIC-EXTENT declaration: ~S" name)))
1552 (cons
1553 (compiler-error "DYNAMIC-EXTENT on macro: ~S" name))
1554 (null
1555 (compiler-style-warn
1556 "Unbound function declared DYNAMIC-EXTENT: ~S" name)))))
1558 (compiler-error "~S on a weird thing: ~S" kind name))))
1559 (when (policy *lexenv* (= speed 3))
1560 (compiler-notify "Ignoring DYNAMIC-EXTENT declarations: ~S" names)))))
1562 ;;; FIXME: This is non-ANSI, so the default should be T, or it should
1563 ;;; go away, I think.
1564 ;;; Or just rename the declaration to SB-C:RESULT-TYPE so that it's not
1565 ;;; a symbol in the CL package, and then eliminate this switch.
1566 ;;; It's permissible to have implementation-specific declarations.
1567 (defvar *suppress-values-declaration* nil
1568 #!+sb-doc
1569 "If true, processing of the VALUES declaration is inhibited.")
1571 ;;; Process a single declaration spec, augmenting the specified LEXENV
1572 ;;; RES. Return RES and result type. VARS and FVARS are as described
1573 ;;; PROCESS-DECLS.
1574 (defun process-1-decl (raw-spec res vars fvars binding-form-p context)
1575 (declare (type list raw-spec vars fvars))
1576 (declare (type lexenv res))
1577 (let ((spec (canonized-decl-spec raw-spec))
1578 (optimize-qualities))
1579 ;; FIXME: we can end up with a chain of spurious parent lexenvs,
1580 ;; when logically the processing of decls should yield at most
1581 ;; two new lexenvs: one for the bindings and one for post-binding.
1582 ;; It's possible that there's a simple fix of re-linking the resulting
1583 ;; lexenv directly to *lexenv* as its parent.
1584 (values
1585 (case (first spec)
1586 (type
1587 (process-type-decl (cdr spec) res vars context))
1588 ((ignore ignorable)
1589 (process-ignore-decl spec vars fvars res)
1590 res)
1591 (special (process-special-decl spec res vars binding-form-p context))
1592 (ftype
1593 (unless (cdr spec)
1594 (compiler-error "no type specified in FTYPE declaration: ~S" spec))
1595 (process-ftype-decl (second spec) res (cddr spec) fvars context))
1596 ((inline notinline maybe-inline)
1597 (process-inline-decl spec res fvars))
1598 (optimize
1599 (multiple-value-bind (new-policy specified-qualities)
1600 (process-optimize-decl spec (lexenv-policy res))
1601 (setq optimize-qualities specified-qualities)
1602 (make-lexenv :default res :policy new-policy)))
1603 (muffle-conditions
1604 (make-lexenv
1605 :default res
1606 :handled-conditions (process-muffle-conditions-decl
1607 spec (lexenv-handled-conditions res))))
1608 (unmuffle-conditions
1609 (make-lexenv
1610 :default res
1611 :handled-conditions (process-unmuffle-conditions-decl
1612 spec (lexenv-handled-conditions res))))
1613 ((dynamic-extent truly-dynamic-extent indefinite-extent)
1614 (process-extent-decl (cdr spec) vars fvars (first spec))
1615 res)
1616 ((disable-package-locks enable-package-locks)
1617 (make-lexenv
1618 :default res
1619 :disabled-package-locks (process-package-lock-decl
1620 spec (lexenv-disabled-package-locks res))))
1621 ;; We may want to detect LAMBDA-LIST and VALUES decls here,
1622 ;; and report them as "Misplaced" rather than "Unrecognized".
1624 (unless (info :declaration :recognized (first spec))
1625 (compiler-warn "unrecognized declaration ~S" raw-spec))
1626 (let ((fn (info :declaration :handler (first spec))))
1627 (if fn
1628 (funcall fn res spec vars fvars)
1629 res))))
1630 optimize-qualities)))
1632 ;;; Use a list of DECLARE forms to annotate the lists of LAMBDA-VAR
1633 ;;; and FUNCTIONAL structures which are being bound. In addition to
1634 ;;; filling in slots in the leaf structures, we return a new LEXENV,
1635 ;;; which reflects pervasive special and function type declarations,
1636 ;;; (NOT)INLINE declarations and OPTIMIZE declarations, and type of
1637 ;;; VALUES declarations. If BINDING-FORM-P is true, the third return
1638 ;;; value is a list of VARs that should not apply to the lexenv of the
1639 ;;; initialization forms for the bindings, but should apply to the body.
1641 ;;; This is also called in main.lisp when PROCESS-FORM handles a use
1642 ;;; of LOCALLY.
1643 (defun process-decls (decls vars fvars &key
1644 (lexenv *lexenv*) (binding-form-p nil) (context :compile)
1645 (allow-lambda-list nil))
1646 (declare (list decls vars fvars))
1647 (let ((result-type *wild-type*)
1648 (allow-values-decl allow-lambda-list)
1649 (explicit-check)
1650 (allow-explicit-check allow-lambda-list)
1651 (lambda-list (if allow-lambda-list :unspecified nil))
1652 (optimize-qualities)
1653 (*post-binding-variable-lexenv* nil))
1654 (flet ((process-it (spec decl)
1655 (cond ((atom spec)
1656 (compiler-error "malformed declaration specifier ~S in ~S"
1657 spec decl))
1658 ((and (eq allow-lambda-list t)
1659 (typep spec '(cons (eql lambda-list) (cons t null))))
1660 (setq lambda-list (cadr spec) allow-lambda-list nil))
1661 ((and allow-values-decl
1662 (typep spec '(cons (eql values)))
1663 (not *suppress-values-declaration*))
1664 ;; Why do we allow more than one VALUES decl? I don't know.
1665 (setq result-type
1666 (values-type-intersection
1667 result-type
1668 (compiler-values-specifier-type
1669 (let ((types (cdr spec)))
1670 (if (singleton-p types)
1671 (car types)
1672 `(values ,@types)))))))
1673 ((and allow-explicit-check
1674 (typep spec '(cons (eql explicit-check))))
1675 ;; EXPLICIT-CHECK can specify that all arguments will be
1676 ;; checked by the function body, and/or all results.
1677 ;; Alternatively, a subset of arguments can be listed,
1678 ;; so that sequence operations can dispatch on the sequence
1679 ;; arguments, but benefit from automatic checks of others.
1680 ;; You can't actually specify anything yet, as the goal
1681 ;; is to be 100% compatible with the globaldb attribute.
1682 (aver (not (cdr spec)))
1683 (setq explicit-check t
1684 allow-explicit-check nil)) ; at most one of this decl
1686 (multiple-value-bind (new-env new-qualities)
1687 (process-1-decl spec lexenv vars fvars
1688 binding-form-p context)
1689 (setq lexenv new-env
1690 optimize-qualities
1691 (nconc new-qualities optimize-qualities)))))))
1692 (dolist (decl decls)
1693 (dolist (spec (rest decl))
1694 (if (eq context :compile)
1695 (let ((*current-path* (or (get-source-path spec)
1696 (get-source-path decl)
1697 *current-path*)))
1698 (process-it spec decl))
1699 ;; Kludge: EVAL calls this function to deal with LOCALLY.
1700 (process-it spec decl)))))
1701 (warn-repeated-optimize-qualities (lexenv-policy lexenv) optimize-qualities)
1702 (values lexenv result-type *post-binding-variable-lexenv*
1703 lambda-list explicit-check)))
1705 (defun %processing-decls (decls vars fvars ctran lvar binding-form-p fun)
1706 (multiple-value-bind (*lexenv* result-type post-binding-lexenv)
1707 (process-decls decls vars fvars :binding-form-p binding-form-p)
1708 (cond ((eq result-type *wild-type*)
1709 (funcall fun ctran lvar post-binding-lexenv))
1711 (let ((value-ctran (make-ctran))
1712 (value-lvar (make-lvar)))
1713 (multiple-value-prog1
1714 (funcall fun value-ctran value-lvar post-binding-lexenv)
1715 (let ((cast (make-cast value-lvar result-type
1716 (lexenv-policy *lexenv*))))
1717 (link-node-to-previous-ctran cast value-ctran)
1718 (setf (lvar-dest value-lvar) cast)
1719 (use-continuation cast ctran lvar))))))))
1721 (defmacro processing-decls ((decls vars fvars ctran lvar
1722 &optional post-binding-lexenv)
1723 &body forms)
1724 (check-type ctran symbol)
1725 (check-type lvar symbol)
1726 (let ((post-binding-lexenv-p (not (null post-binding-lexenv)))
1727 (post-binding-lexenv (or post-binding-lexenv (sb!xc:gensym "LEXENV"))))
1728 `(%processing-decls ,decls ,vars ,fvars ,ctran ,lvar
1729 ,post-binding-lexenv-p
1730 (lambda (,ctran ,lvar ,post-binding-lexenv)
1731 (declare (ignorable ,post-binding-lexenv))
1732 ,@forms))))
1734 ;;; Return the SPECVAR for NAME to use when we see a local SPECIAL
1735 ;;; declaration. If there is a global variable of that name, then
1736 ;;; check that it isn't a constant and return it. Otherwise, create an
1737 ;;; anonymous GLOBAL-VAR.
1738 (defun specvar-for-binding (name)
1739 (cond ((not (eq (info :variable :where-from name) :assumed))
1740 (let ((found (find-free-var name)))
1741 (when (heap-alien-info-p found)
1742 (compiler-error
1743 "~S is an alien variable and so can't be declared special."
1744 name))
1745 (unless (global-var-p found)
1746 (compiler-error
1747 "~S is a constant and so can't be declared special."
1748 name))
1749 found))
1751 (make-global-var :kind :special
1752 :%source-name name
1753 :where-from :declared))))