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
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.
15 (declaim (special *compiler-error-bailout*))
17 ;;; *SOURCE-PATHS* is a hashtable from source code forms to the path
18 ;;; taken through the source to reach the form. This provides a way to
19 ;;; keep track of the location of original source forms, even when
20 ;;; macroexpansions and other arbitary permutations of the code
21 ;;; happen. This table is initialized by calling FIND-SOURCE-PATHS on
22 ;;; the original source.
23 (declaim (hash-table *source-paths*))
24 (defvar *source-paths*)
26 ;;; *CURRENT-COMPONENT* is the COMPONENT structure which we link
27 ;;; blocks into as we generate them. This just serves to glue the
28 ;;; emitted blocks together until local call analysis and flow graph
29 ;;; canonicalization figure out what is really going on. We need to
30 ;;; keep track of all the blocks generated so that we can delete them
31 ;;; if they turn out to be unreachable.
33 ;;; FIXME: It's confusing having one variable named *CURRENT-COMPONENT*
34 ;;; and another named *COMPONENT-BEING-COMPILED*. (In CMU CL they
35 ;;; were called *CURRENT-COMPONENT* and *COMPILE-COMPONENT* respectively,
36 ;;; which was also confusing.)
37 (declaim (type (or component null) *current-component*))
38 (defvar *current-component*)
40 ;;; *CURRENT-PATH* is the source path of the form we are currently
41 ;;; translating. See NODE-SOURCE-PATH in the NODE structure.
42 (declaim (list *current-path*))
43 (defvar *current-path*)
45 (defvar *derive-function-types* nil
46 "Should the compiler assume that function types will never change,
47 so that it can use type information inferred from current definitions
48 to optimize code which uses those definitions? Setting this true
49 gives non-ANSI, early-CMU-CL behavior. It can be useful for improving
50 the efficiency of stable code.")
52 (defvar *fun-names-in-this-file* nil)
54 (defvar *post-binding-variable-lexenv* nil)
56 ;;;; namespace management utilities
58 (defun fun-lexically-notinline-p (name)
59 (let ((fun (lexenv-find name funs :test #'equal)))
60 ;; a declaration will trump a proclamation
61 (if (and fun (defined-fun-p fun))
62 (eq (defined-fun-inlinep fun) :notinline)
63 (eq (info :function :inlinep name) :notinline))))
65 ;;; Return a GLOBAL-VAR structure usable for referencing the global
67 (defun find-free-really-fun (name)
68 (unless (info :function :kind name)
69 (setf (info :function :kind name) :function)
70 (setf (info :function :where-from name) :assumed))
71 (let ((where (info :function :where-from name)))
72 (when (and (eq where :assumed)
73 ;; In the ordinary target Lisp, it's silly to report
74 ;; undefinedness when the function is defined in the
75 ;; running Lisp. But at cross-compile time, the current
76 ;; definedness of a function is irrelevant to the
77 ;; definedness at runtime, which is what matters.
78 #-sb-xc-host (not (fboundp name)))
79 (note-undefined-reference name :function))
81 :kind :global-function
83 :type (if (or *derive-function-types*
85 (and (member name *fun-names-in-this-file* :test #'equal)
86 (not (fun-lexically-notinline-p name))))
87 (info :function :type name)
88 (specifier-type 'function))
91 ;;; Has the *FREE-FUNS* entry FREE-FUN become invalid?
93 ;;; In CMU CL, the answer was implicitly always true, so this
94 ;;; predicate didn't exist.
96 ;;; This predicate was added to fix bug 138 in SBCL. In some obscure
97 ;;; circumstances, it was possible for a *FREE-FUNS* entry to contain a
98 ;;; DEFINED-FUN whose DEFINED-FUN-FUNCTIONAL object contained IR1
99 ;;; stuff (NODEs, BLOCKs...) referring to an already compiled (aka
100 ;;; "dead") component. When this IR1 stuff was reused in a new
101 ;;; component, under further obscure circumstances it could be used by
102 ;;; WITH-IR1-ENVIRONMENT-FROM-NODE to generate a binding for
103 ;;; *CURRENT-COMPONENT*. At that point things got all confused, since
104 ;;; IR1 conversion was sending code to a component which had already
105 ;;; been compiled and would never be compiled again.
106 (defun invalid-free-fun-p (free-fun)
107 ;; There might be other reasons that *FREE-FUN* entries could
108 ;; become invalid, but the only one we've been bitten by so far
109 ;; (sbcl-0.pre7.118) is this one:
110 (and (defined-fun-p free-fun)
111 (let ((functional (defined-fun-functional free-fun)))
113 (eql (functional-kind functional) :deleted))
114 (and (lambda-p functional)
116 ;; (The main reason for this first test is to bail
117 ;; out early in cases where the LAMBDA-COMPONENT
118 ;; call in the second test would fail because links
119 ;; it needs are uninitialized or invalid.)
121 ;; If the BIND node for this LAMBDA is null, then
122 ;; according to the slot comments, the LAMBDA has
123 ;; been deleted or its call has been deleted. In
124 ;; that case, it seems rather questionable to reuse
125 ;; it, and certainly it shouldn't be necessary to
126 ;; reuse it, so we cheerfully declare it invalid.
127 (null (lambda-bind functional))
128 ;; If this IR1 stuff belongs to a dead component,
129 ;; then we can't reuse it without getting into
130 ;; bizarre confusion.
131 (eql (component-info (lambda-component functional))
134 ;;; If NAME already has a valid entry in *FREE-FUNS*, then return
135 ;;; the value. Otherwise, make a new GLOBAL-VAR using information from
136 ;;; the global environment and enter it in *FREE-FUNS*. If NAME
137 ;;; names a macro or special form, then we error out using the
138 ;;; supplied context which indicates what we were trying to do that
139 ;;; demanded a function.
140 (declaim (ftype (sfunction (t string) global-var) find-free-fun))
141 (defun find-free-fun (name context)
142 (or (let ((old-free-fun (gethash name *free-funs*)))
143 (and (not (invalid-free-fun-p old-free-fun))
145 (ecase (info :function :kind name)
146 ;; FIXME: The :MACRO and :SPECIAL-FORM cases could be merged.
148 (compiler-error "The macro name ~S was found ~A." name context))
150 (compiler-error "The special form name ~S was found ~A."
154 (check-fun-name name)
155 (note-if-setf-fun-and-macro name)
156 (let ((expansion (fun-name-inline-expansion name))
157 (inlinep (info :function :inlinep name)))
158 (setf (gethash name *free-funs*)
159 (if (or expansion inlinep)
162 :inline-expansion expansion
164 :where-from (info :function :where-from name)
165 :type (if (eq inlinep :notinline)
166 (specifier-type 'function)
167 (info :function :type name)))
168 (find-free-really-fun name))))))))
170 ;;; Return the LEAF structure for the lexically apparent function
171 ;;; definition of NAME.
172 (declaim (ftype (sfunction (t string) leaf) find-lexically-apparent-fun))
173 (defun find-lexically-apparent-fun (name context)
174 (let ((var (lexenv-find name funs :test #'equal)))
177 (aver (and (consp var) (eq (car var) 'macro)))
178 (compiler-error "found macro name ~S ~A" name context))
181 (find-free-fun name context)))))
183 ;;; Return the LEAF node for a global variable reference to NAME. If
184 ;;; NAME is already entered in *FREE-VARS*, then we just return the
185 ;;; corresponding value. Otherwise, we make a new leaf using
186 ;;; information from the global environment and enter it in
187 ;;; *FREE-VARS*. If the variable is unknown, then we emit a warning.
188 (declaim (ftype (sfunction (t) (or leaf cons heap-alien-info)) find-free-var))
189 (defun find-free-var (name)
190 (unless (symbolp name)
191 (compiler-error "Variable name is not a symbol: ~S." name))
192 (or (gethash name *free-vars*)
193 (let ((kind (info :variable :kind name))
194 (type (info :variable :type name))
195 (where-from (info :variable :where-from name)))
196 (when (and (eq where-from :assumed) (eq kind :global))
197 (note-undefined-reference name :variable))
198 (setf (gethash name *free-vars*)
201 (info :variable :alien-info name))
202 ;; FIXME: The return value in this case should really be
203 ;; of type SB!C::LEAF. I don't feel too badly about it,
204 ;; because the MACRO idiom is scattered throughout this
205 ;; file, but it should be cleaned up so we're not
206 ;; throwing random conses around. --njf 2002-03-23
208 (let ((expansion (info :variable :macro-expansion name))
209 (type (type-specifier (info :variable :type name))))
210 `(macro . (the ,type ,expansion))))
212 (let ((value (info :variable :constant-value name)))
213 (make-constant :value value
215 :type (ctype-of value)
216 :where-from where-from)))
218 (make-global-var :kind kind
221 :where-from where-from)))))))
223 ;;; Grovel over CONSTANT checking for any sub-parts that need to be
224 ;;; processed with MAKE-LOAD-FORM. We have to be careful, because
225 ;;; CONSTANT might be circular. We also check that the constant (and
226 ;;; any subparts) are dumpable at all.
227 (eval-when (:compile-toplevel :load-toplevel :execute)
228 ;; The EVAL-WHEN is necessary for #.(1+ LIST-TO-HASH-TABLE-THRESHOLD)
229 ;; below. -- AL 20010227
230 (def!constant list-to-hash-table-threshold 32))
231 (defun maybe-emit-make-load-forms (constant)
232 (let ((things-processed nil)
234 ;; FIXME: Does this LIST-or-HASH-TABLE messiness give much benefit?
235 (declare (type (or list hash-table) things-processed)
236 (type (integer 0 #.(1+ list-to-hash-table-threshold)) count)
238 (labels ((grovel (value)
239 ;; Unless VALUE is an object which which obviously
240 ;; can't contain other objects
242 '(or #-sb-xc-host unboxed-array
243 #+sb-xc-host (simple-array (unsigned-byte 8) (*))
248 (etypecase things-processed
250 (when (member value things-processed :test #'eq)
251 (return-from grovel nil))
252 (push value things-processed)
254 (when (> count list-to-hash-table-threshold)
255 (let ((things things-processed))
256 (setf things-processed
257 (make-hash-table :test 'eq))
258 (dolist (thing things)
259 (setf (gethash thing things-processed) t)))))
261 (when (gethash value things-processed)
262 (return-from grovel nil))
263 (setf (gethash value things-processed) t)))
267 (grovel (cdr value)))
269 (dotimes (i (length value))
270 (grovel (svref value i))))
272 (dotimes (i (length value))
273 (grovel (aref value i))))
275 ;; Even though the (ARRAY T) branch does the exact
276 ;; same thing as this branch we do this separately
277 ;; so that the compiler can use faster versions of
278 ;; array-total-size and row-major-aref.
279 (dotimes (i (array-total-size value))
280 (grovel (row-major-aref value i))))
282 (dotimes (i (array-total-size value))
283 (grovel (row-major-aref value i))))
284 (;; In the target SBCL, we can dump any instance,
285 ;; but in the cross-compilation host,
286 ;; %INSTANCE-FOO functions don't work on general
287 ;; instances, only on STRUCTURE!OBJECTs.
288 #+sb-xc-host structure!object
289 #-sb-xc-host instance
290 (when (emit-make-load-form value)
291 (dotimes (i (- (%instance-length value)
293 #-sb-xc-host (layout-n-untagged-slots
294 (%instance-ref value 0))))
295 (grovel (%instance-ref value i)))))
298 "Objects of type ~S can't be dumped into fasl files."
299 (type-of value)))))))
303 ;;;; some flow-graph hacking utilities
305 ;;; This function sets up the back link between the node and the
306 ;;; ctran which continues at it.
307 (defun link-node-to-previous-ctran (node ctran)
308 (declare (type node node) (type ctran ctran))
309 (aver (not (ctran-next ctran)))
310 (setf (ctran-next ctran) node)
311 (setf (node-prev node) ctran))
313 ;;; This function is used to set the ctran for a node, and thus
314 ;;; determine what is evaluated next. If the ctran has no block, then
315 ;;; we make it be in the block that the node is in. If the ctran heads
316 ;;; its block, we end our block and link it to that block.
317 #!-sb-fluid (declaim (inline use-ctran))
318 (defun use-ctran (node ctran)
319 (declare (type node node) (type ctran ctran))
320 (if (eq (ctran-kind ctran) :unused)
321 (let ((node-block (ctran-block (node-prev node))))
322 (setf (ctran-block ctran) node-block)
323 (setf (ctran-kind ctran) :inside-block)
324 (setf (ctran-use ctran) node)
325 (setf (node-next node) ctran))
326 (%use-ctran node ctran)))
327 (defun %use-ctran (node ctran)
328 (declare (type node node) (type ctran ctran) (inline member))
329 (let ((block (ctran-block ctran))
330 (node-block (ctran-block (node-prev node))))
331 (aver (eq (ctran-kind ctran) :block-start))
332 (when (block-last node-block)
333 (error "~S has already ended." node-block))
334 (setf (block-last node-block) node)
335 (when (block-succ node-block)
336 (error "~S already has successors." node-block))
337 (setf (block-succ node-block) (list block))
338 (when (memq node-block (block-pred block))
339 (error "~S is already a predecessor of ~S." node-block block))
340 (push node-block (block-pred block))))
342 ;;; This function is used to set the ctran for a node, and thus
343 ;;; determine what receives the value.
344 (defun use-lvar (node lvar)
345 (declare (type valued-node node) (type (or lvar null) lvar))
346 (aver (not (node-lvar node)))
348 (setf (node-lvar node) lvar)
349 (cond ((null (lvar-uses lvar))
350 (setf (lvar-uses lvar) node))
351 ((listp (lvar-uses lvar))
352 (aver (not (memq node (lvar-uses lvar))))
353 (push node (lvar-uses lvar)))
355 (aver (neq node (lvar-uses lvar)))
356 (setf (lvar-uses lvar) (list node (lvar-uses lvar)))))
357 (reoptimize-lvar lvar)))
359 #!-sb-fluid(declaim (inline use-continuation))
360 (defun use-continuation (node ctran lvar)
361 (use-ctran node ctran)
362 (use-lvar node lvar))
364 ;;;; exported functions
366 ;;; This function takes a form and the top level form number for that
367 ;;; form, and returns a lambda representing the translation of that
368 ;;; form in the current global environment. The returned lambda is a
369 ;;; top level lambda that can be called to cause evaluation of the
370 ;;; forms. This lambda is in the initial component. If FOR-VALUE is T,
371 ;;; then the value of the form is returned from the function,
372 ;;; otherwise NIL is returned.
374 ;;; This function may have arbitrary effects on the global environment
375 ;;; due to processing of EVAL-WHENs. All syntax error checking is
376 ;;; done, with erroneous forms being replaced by a proxy which signals
377 ;;; an error if it is evaluated. Warnings about possibly inconsistent
378 ;;; or illegal changes to the global environment will also be given.
380 ;;; We make the initial component and convert the form in a PROGN (and
381 ;;; an optional NIL tacked on the end.) We then return the lambda. We
382 ;;; bind all of our state variables here, rather than relying on the
383 ;;; global value (if any) so that IR1 conversion will be reentrant.
384 ;;; This is necessary for EVAL-WHEN processing, etc.
386 ;;; The hashtables used to hold global namespace info must be
387 ;;; reallocated elsewhere. Note also that *LEXENV* is not bound, so
388 ;;; that local macro definitions can be introduced by enclosing code.
389 (defun ir1-toplevel (form path for-value)
390 (declare (list path))
391 (let* ((*current-path* path)
392 (component (make-empty-component))
393 (*current-component* component)
394 (*allow-instrumenting* t))
395 (setf (component-name component) 'initial-component)
396 (setf (component-kind component) :initial)
397 (let* ((forms (if for-value `(,form) `(,form nil)))
398 (res (ir1-convert-lambda-body
400 :debug-name (debug-name 'top-level-form form))))
401 (setf (functional-entry-fun res) res
402 (functional-arg-documentation res) ()
403 (functional-kind res) :toplevel)
406 ;;; *CURRENT-FORM-NUMBER* is used in FIND-SOURCE-PATHS to compute the
407 ;;; form number to associate with a source path. This should be bound
408 ;;; to an initial value of 0 before the processing of each truly
410 (declaim (type index *current-form-number*))
411 (defvar *current-form-number*)
413 ;;; This function is called on freshly read forms to record the
414 ;;; initial location of each form (and subform.) Form is the form to
415 ;;; find the paths in, and TLF-NUM is the top level form number of the
416 ;;; truly top level form.
418 ;;; This gets a bit interesting when the source code is circular. This
419 ;;; can (reasonably?) happen in the case of circular list constants.
420 (defun find-source-paths (form tlf-num)
421 (declare (type index tlf-num))
422 (let ((*current-form-number* 0))
423 (sub-find-source-paths form (list tlf-num)))
425 (defun sub-find-source-paths (form path)
426 (unless (gethash form *source-paths*)
427 (setf (gethash form *source-paths*)
428 (list* 'original-source-start *current-form-number* path))
429 (incf *current-form-number*)
433 (declare (fixnum pos))
436 (when (atom subform) (return))
437 (let ((fm (car subform)))
439 (sub-find-source-paths fm (cons pos path)))
441 (setq subform (cdr subform))
442 (when (eq subform trail) (return)))))
446 (setq trail (cdr trail)))))))
448 ;;;; IR1-CONVERT, macroexpansion and special form dispatching
450 (declaim (ftype (sfunction (ctran ctran (or lvar null) t) (values))
452 (macrolet (;; Bind *COMPILER-ERROR-BAILOUT* to a function that throws
453 ;; out of the body and converts a condition signalling form
454 ;; instead. The source form is converted to a string since it
455 ;; may contain arbitrary non-externalizable objects.
456 (ir1-error-bailout ((start next result form) &body body)
457 (with-unique-names (skip condition)
459 (let ((,condition (catch 'ir1-error-abort
460 (let ((*compiler-error-bailout*
461 (lambda (&optional e)
462 (throw 'ir1-error-abort e))))
464 (return-from ,skip nil)))))
465 (ir1-convert ,start ,next ,result
466 (make-compiler-error-form ,condition ,form)))))))
468 ;; Translate FORM into IR1. The code is inserted as the NEXT of the
469 ;; CTRAN START. RESULT is the LVAR which receives the value of the
470 ;; FORM to be translated. The translators call this function
471 ;; recursively to translate their subnodes.
473 ;; As a special hack to make life easier in the compiler, a LEAF
474 ;; IR1-converts into a reference to that LEAF structure. This allows
475 ;; the creation using backquote of forms that contain leaf
476 ;; references, without having to introduce dummy names into the
478 (defun ir1-convert (start next result form)
479 (ir1-error-bailout (start next result form)
480 (let ((*current-path* (or (gethash form *source-paths*)
481 (cons form *current-path*))))
482 (cond ((step-form-p form)
483 (ir1-convert-step start next result form))
485 (cond ((and (symbolp form) (not (keywordp form)))
486 (ir1-convert-var start next result form))
488 (reference-leaf start next result form))
490 (reference-constant start next result form))))
492 (let ((opname (car form)))
493 (cond ((or (symbolp opname) (leaf-p opname))
494 (let ((lexical-def (if (leaf-p opname)
496 (lexenv-find opname funs))))
497 (typecase lexical-def
499 (ir1-convert-global-functoid start next result
502 (ir1-convert-local-combination start next result
506 (ir1-convert-srctran start next result
509 (aver (and (consp lexical-def)
510 (eq (car lexical-def) 'macro)))
511 (ir1-convert start next result
512 (careful-expand-macro (cdr lexical-def)
514 ((or (atom opname) (not (eq (car opname) 'lambda)))
515 (compiler-error "illegal function call"))
517 ;; implicitly (LAMBDA ..) because the LAMBDA
518 ;; expression is the CAR of an executed form
519 (ir1-convert-combination start next result
523 :debug-name (debug-name
528 ;; Generate a reference to a manifest constant, creating a new leaf
529 ;; if necessary. If we are producing a fasl file, make sure that
530 ;; MAKE-LOAD-FORM gets used on any parts of the constant that it
532 (defun reference-constant (start next result value)
533 (declare (type ctran start next)
534 (type (or lvar null) result)
535 (inline find-constant))
536 (ir1-error-bailout (start next result value)
537 (when (producing-fasl-file)
538 (maybe-emit-make-load-forms value))
539 (let* ((leaf (find-constant value))
540 (res (make-ref leaf)))
541 (push res (leaf-refs leaf))
542 (link-node-to-previous-ctran res start)
543 (use-continuation res next result)))
546 ;;; Add FUNCTIONAL to the COMPONENT-REANALYZE-FUNCTIONALS, unless it's
547 ;;; some trivial type for which reanalysis is a trivial no-op, or
548 ;;; unless it doesn't belong in this component at all.
550 ;;; FUNCTIONAL is returned.
551 (defun maybe-reanalyze-functional (functional)
553 (aver (not (eql (functional-kind functional) :deleted))) ; bug 148
554 (aver-live-component *current-component*)
556 ;; When FUNCTIONAL is of a type for which reanalysis isn't a trivial
558 (when (typep functional '(or optional-dispatch clambda))
560 ;; When FUNCTIONAL knows its component
561 (when (lambda-p functional)
562 (aver (eql (lambda-component functional) *current-component*)))
565 (component-reanalyze-functionals *current-component*)))
569 ;;; Generate a REF node for LEAF, frobbing the LEAF structure as
570 ;;; needed. If LEAF represents a defined function which has already
571 ;;; been converted, and is not :NOTINLINE, then reference the
572 ;;; functional instead.
573 (defun reference-leaf (start next result leaf)
574 (declare (type ctran start next) (type (or lvar null) result) (type leaf leaf))
575 (when (functional-p leaf)
576 (assure-functional-live-p leaf))
577 (let* ((type (lexenv-find leaf type-restrictions))
578 (leaf (or (and (defined-fun-p leaf)
579 (not (eq (defined-fun-inlinep leaf)
581 (let ((functional (defined-fun-functional leaf)))
582 (when (and functional
583 (not (functional-kind functional))
584 ;; Bug MISC.320: ir1-transform
585 ;; can create a reference to a
586 ;; inline-expanded function,
587 ;; defined in another component.
588 (not (and (lambda-p functional)
589 (neq (lambda-component functional)
590 *current-component*))))
591 (maybe-reanalyze-functional functional))))
592 (when (and (lambda-p leaf)
593 (memq (functional-kind leaf)
595 (maybe-reanalyze-functional leaf))
597 (ref (make-ref leaf)))
598 (push ref (leaf-refs leaf))
599 (setf (leaf-ever-used leaf) t)
600 (link-node-to-previous-ctran ref start)
601 (cond (type (let* ((ref-ctran (make-ctran))
602 (ref-lvar (make-lvar))
603 (cast (make-cast ref-lvar
604 (make-single-value-type type)
605 (lexenv-policy *lexenv*))))
606 (setf (lvar-dest ref-lvar) cast)
607 (use-continuation ref ref-ctran ref-lvar)
608 (link-node-to-previous-ctran cast ref-ctran)
609 (use-continuation cast next result)))
610 (t (use-continuation ref next result)))))
612 ;;; Convert a reference to a symbolic constant or variable. If the
613 ;;; symbol is entered in the LEXENV-VARS we use that definition,
614 ;;; otherwise we find the current global definition. This is also
615 ;;; where we pick off symbol macro and alien variable references.
616 (defun ir1-convert-var (start next result name)
617 (declare (type ctran start next) (type (or lvar null) result) (symbol name))
618 (let ((var (or (lexenv-find name vars) (find-free-var name))))
621 (when (lambda-var-p var)
622 (let ((home (ctran-home-lambda-or-null start)))
624 (pushnew var (lambda-calls-or-closes home))))
625 (when (lambda-var-ignorep var)
626 ;; (ANSI's specification for the IGNORE declaration requires
627 ;; that this be a STYLE-WARNING, not a full WARNING.)
629 (compiler-style-warn "reading an ignored variable: ~S" name)
630 ;; there's no need for us to accept ANSI's lameness when
631 ;; processing our own code, though.
633 (warn "reading an ignored variable: ~S" name)))
634 (reference-leaf start next result var))
636 (aver (eq (car var) 'macro))
637 ;; FIXME: [Free] type declarations. -- APD, 2002-01-26
638 (ir1-convert start next result (cdr var)))
640 (ir1-convert start next result `(%heap-alien ',var)))))
643 ;;; Convert anything that looks like a special form, global function
644 ;;; or compiler-macro call.
645 (defun ir1-convert-global-functoid (start next result form)
646 (declare (type ctran start next) (type (or lvar null) result) (list form))
647 (let* ((fun-name (first form))
648 (translator (info :function :ir1-convert fun-name))
649 (cmacro-fun (sb!xc:compiler-macro-function fun-name *lexenv*)))
652 (compiler-warn "ignoring compiler macro for special form"))
653 (funcall translator start next result form))
655 ;; gotcha: If you look up the DEFINE-COMPILER-MACRO
656 ;; macro in the ANSI spec, you might think that
657 ;; suppressing compiler-macro expansion when NOTINLINE
658 ;; is some pre-ANSI hack. However, if you look up the
659 ;; NOTINLINE declaration, you'll find that ANSI
660 ;; requires this behavior after all.
661 (not (eq (info :function :inlinep fun-name) :notinline)))
662 (let ((res (careful-expand-macro cmacro-fun form)))
664 (ir1-convert-global-functoid-no-cmacro
665 start next result form fun-name)
666 (ir1-convert start next result res))))
668 (ir1-convert-global-functoid-no-cmacro start next result
671 ;;; Handle the case of where the call was not a compiler macro, or was
672 ;;; a compiler macro and passed.
673 (defun ir1-convert-global-functoid-no-cmacro (start next result form fun)
674 (declare (type ctran start next) (type (or lvar null) result)
676 ;; FIXME: Couldn't all the INFO calls here be converted into
677 ;; standard CL functions, like MACRO-FUNCTION or something?
678 ;; And what happens with lexically-defined (MACROLET) macros
680 (ecase (info :function :kind fun)
682 (ir1-convert start next result
683 (careful-expand-macro (info :function :macro-function fun)
686 (ir1-convert-srctran start next result
687 (find-free-fun fun "shouldn't happen! (no-cmacro)")
690 (defun muffle-warning-or-die ()
692 (bug "no MUFFLE-WARNING restart"))
694 ;;; Expand FORM using the macro whose MACRO-FUNCTION is FUN, trapping
695 ;;; errors which occur during the macroexpansion.
696 (defun careful-expand-macro (fun form)
697 (let (;; a hint I (WHN) wish I'd known earlier
698 (hint "(hint: For more precise location, try *BREAK-ON-SIGNALS*.)"))
699 (flet (;; Return a string to use as a prefix in error reporting,
700 ;; telling something about which form caused the problem.
702 (let ((*print-pretty* nil)
703 ;; We rely on the printer to abbreviate FORM.
708 #-sb-xc-host "(in macroexpansion of ~S)"
709 ;; longer message to avoid ambiguity "Was it the xc host
710 ;; or the cross-compiler which encountered the problem?"
711 #+sb-xc-host "(in cross-compiler macroexpansion of ~S)"
713 (handler-bind ((style-warning (lambda (c)
715 "~@<~A~:@_~A~@:_~A~:>"
716 (wherestring) hint c)
717 (muffle-warning-or-die)))
718 ;; KLUDGE: CMU CL in its wisdom (version 2.4.6 for
719 ;; Debian Linux, anyway) raises a CL:WARNING
720 ;; condition (not a CL:STYLE-WARNING) for undefined
721 ;; symbols when converting interpreted functions,
722 ;; causing COMPILE-FILE to think the file has a real
723 ;; problem, causing COMPILE-FILE to return FAILURE-P
724 ;; set (not just WARNINGS-P set). Since undefined
725 ;; symbol warnings are often harmless forward
726 ;; references, and since it'd be inordinately painful
727 ;; to try to eliminate all such forward references,
728 ;; these warnings are basically unavoidable. Thus, we
729 ;; need to coerce the system to work through them,
730 ;; and this code does so, by crudely suppressing all
731 ;; warnings in cross-compilation macroexpansion. --
733 #+(and cmu sb-xc-host)
738 ~@<(KLUDGE: That was a non-STYLE WARNING. ~
739 Ordinarily that would cause compilation to ~
740 fail. However, since we're running under ~
741 CMU CL, and since CMU CL emits non-STYLE ~
742 warnings for safe, hard-to-fix things (e.g. ~
743 references to not-yet-defined functions) ~
744 we're going to have to ignore it and ~
745 proceed anyway. Hopefully we're not ~
746 ignoring anything horrible here..)~:@>~:>"
749 (muffle-warning-or-die)))
750 #-(and cmu sb-xc-host)
752 (warn "~@<~A~:@_~A~@:_~A~:>"
753 (wherestring) hint c)
754 (muffle-warning-or-die)))
756 (compiler-error "~@<~A~:@_~A~@:_~A~:>"
757 (wherestring) hint c))))
758 (funcall sb!xc:*macroexpand-hook* fun form *lexenv*)))))
760 ;;;; conversion utilities
762 ;;; Convert a bunch of forms, discarding all the values except the
763 ;;; last. If there aren't any forms, then translate a NIL.
764 (declaim (ftype (sfunction (ctran ctran (or lvar null) list) (values))
765 ir1-convert-progn-body))
766 (defun ir1-convert-progn-body (start next result body)
768 (reference-constant start next result nil)
769 (let ((this-start start)
772 (let ((form (car forms)))
773 (when (endp (cdr forms))
774 (ir1-convert this-start next result form)
776 (let ((this-ctran (make-ctran)))
777 (ir1-convert this-start this-ctran nil form)
778 (setq this-start this-ctran
779 forms (cdr forms)))))))
782 ;;;; converting combinations
784 ;;; Convert a function call where the function FUN is a LEAF. FORM is
785 ;;; the source for the call. We return the COMBINATION node so that
786 ;;; the caller can poke at it if it wants to.
787 (declaim (ftype (sfunction (ctran ctran (or lvar null) list leaf) combination)
788 ir1-convert-combination))
789 (defun ir1-convert-combination (start next result form fun)
790 (let ((ctran (make-ctran))
791 (fun-lvar (make-lvar)))
792 (ir1-convert start ctran fun-lvar `(the (or function symbol) ,fun))
793 (ir1-convert-combination-args fun-lvar ctran next result (cdr form))))
795 ;;; Convert the arguments to a call and make the COMBINATION
796 ;;; node. FUN-LVAR yields the function to call. ARGS is the list of
797 ;;; arguments for the call, which defaults to the cdr of source. We
798 ;;; return the COMBINATION node.
799 (defun ir1-convert-combination-args (fun-lvar start next result args)
800 (declare (type ctran start next)
802 (type (or lvar null) result)
804 (let ((node (make-combination fun-lvar)))
805 (setf (lvar-dest fun-lvar) node)
806 (collect ((arg-lvars))
807 (let ((this-start start))
809 (let ((this-ctran (make-ctran))
810 (this-lvar (make-lvar node)))
811 (ir1-convert this-start this-ctran this-lvar arg)
812 (setq this-start this-ctran)
813 (arg-lvars this-lvar)))
814 (link-node-to-previous-ctran node this-start)
815 (use-continuation node next result)
816 (setf (combination-args node) (arg-lvars))))
819 ;;; Convert a call to a global function. If not :NOTINLINE, then we do
820 ;;; source transforms and try out any inline expansion. If there is no
821 ;;; expansion, but is :INLINE, then give an efficiency note (unless a
822 ;;; known function which will quite possibly be open-coded.) Next, we
823 ;;; go to ok-combination conversion.
824 (defun ir1-convert-srctran (start next result var form)
825 (declare (type ctran start next) (type (or lvar null) result)
826 (type global-var var))
827 (let ((inlinep (when (defined-fun-p var)
828 (defined-fun-inlinep var))))
829 (if (eq inlinep :notinline)
830 (ir1-convert-combination start next result form var)
831 (let ((transform (info :function
833 (leaf-source-name var))))
835 (multiple-value-bind (transformed pass) (funcall transform form)
837 (ir1-convert-maybe-predicate start next result form var)
838 (ir1-convert start next result transformed)))
839 (ir1-convert-maybe-predicate start next result form var))))))
841 ;;; If the function has the PREDICATE attribute, and the RESULT's DEST
842 ;;; isn't an IF, then we convert (IF <form> T NIL), ensuring that a
843 ;;; predicate always appears in a conditional context.
845 ;;; If the function isn't a predicate, then we call
846 ;;; IR1-CONVERT-COMBINATION-CHECKING-TYPE.
847 (defun ir1-convert-maybe-predicate (start next result form var)
848 (declare (type ctran start next)
849 (type (or lvar null) result)
851 (type global-var var))
852 (let ((info (info :function :info (leaf-source-name var))))
854 (ir1-attributep (fun-info-attributes info) predicate)
855 (not (if-p (and result (lvar-dest result)))))
856 (ir1-convert start next result `(if ,form t nil))
857 (ir1-convert-combination-checking-type start next result form var))))
859 ;;; Actually really convert a global function call that we are allowed
862 ;;; If we know the function type of the function, then we check the
863 ;;; call for syntactic legality with respect to the declared function
864 ;;; type. If it is impossible to determine whether the call is correct
865 ;;; due to non-constant keywords, then we give up, marking the call as
866 ;;; :FULL to inhibit further error messages. We return true when the
869 ;;; If the call is legal, we also propagate type assertions from the
870 ;;; function type to the arg and result lvars. We do this now so that
871 ;;; IR1 optimize doesn't have to redundantly do the check later so
872 ;;; that it can do the type propagation.
873 (defun ir1-convert-combination-checking-type (start next result form var)
874 (declare (type ctran start next) (type (or lvar null) result)
877 (let* ((node (ir1-convert-combination start next result form var))
878 (fun-lvar (basic-combination-fun node))
879 (type (leaf-type var)))
880 (when (validate-call-type node type t)
881 (setf (lvar-%derived-type fun-lvar)
882 (make-single-value-type type))
883 (setf (lvar-reoptimize fun-lvar) nil)))
886 ;;; Convert a call to a local function, or if the function has already
887 ;;; been LET converted, then throw FUNCTIONAL to
888 ;;; LOCALL-ALREADY-LET-CONVERTED. The THROW should only happen when we
889 ;;; are converting inline expansions for local functions during
891 (defun ir1-convert-local-combination (start next result form functional)
892 (assure-functional-live-p functional)
893 (ir1-convert-combination start next result
895 (maybe-reanalyze-functional functional)))
899 ;;; Given a list of LAMBDA-VARs and a variable name, return the
900 ;;; LAMBDA-VAR for that name, or NIL if it isn't found. We return the
901 ;;; *last* variable with that name, since LET* bindings may be
902 ;;; duplicated, and declarations always apply to the last.
903 (declaim (ftype (sfunction (list symbol) (or lambda-var list))
905 (defun find-in-bindings (vars name)
909 (when (eq (leaf-source-name var) name)
911 (let ((info (lambda-var-arg-info var)))
913 (let ((supplied-p (arg-info-supplied-p info)))
914 (when (and supplied-p
915 (eq (leaf-source-name supplied-p) name))
916 (setq found supplied-p))))))
917 ((and (consp var) (eq (car var) name))
918 (setf found (cdr var)))))
921 ;;; Called by PROCESS-DECLS to deal with a variable type declaration.
922 ;;; If a LAMBDA-VAR being bound, we intersect the type with the var's
923 ;;; type, otherwise we add a type restriction on the var. If a symbol
924 ;;; macro, we just wrap a THE around the expansion.
925 (defun process-type-decl (decl res vars)
926 (declare (list decl vars) (type lexenv res))
927 (let ((type (compiler-specifier-type (first decl))))
928 (collect ((restr nil cons)
930 (dolist (var-name (rest decl))
931 (when (boundp var-name)
932 (compiler-assert-symbol-home-package-unlocked
933 var-name "declaring the type of ~A"))
934 (let* ((bound-var (find-in-bindings vars var-name))
936 (lexenv-find var-name vars)
937 (find-free-var var-name))))
941 ((process-var (var bound-var)
942 (let* ((old-type (or (lexenv-find var type-restrictions)
944 (int (if (or (fun-type-p type)
945 (fun-type-p old-type))
947 (type-approx-intersection2
949 (cond ((eq int *empty-type*)
950 (unless (policy *lexenv* (= inhibit-warnings 3))
954 "The type declarations ~S and ~S for ~S conflict."
957 (type-specifier old-type)
958 (type-specifier type)
960 (bound-var (setf (leaf-type bound-var) int))
962 (restr (cons var int)))))))
963 (process-var var bound-var)
964 (awhen (and (lambda-var-p var)
965 (lambda-var-specvar var))
966 (process-var it nil))))
968 ;; FIXME: non-ANSI weirdness
969 (aver (eq (car var) 'macro))
970 (new-vars `(,var-name . (macro . (the ,(first decl)
974 "~S is an alien variable, so its type can't be declared."
977 (if (or (restr) (new-vars))
978 (make-lexenv :default res
979 :type-restrictions (restr)
983 ;;; This is somewhat similar to PROCESS-TYPE-DECL, but handles
984 ;;; declarations for function variables. In addition to allowing
985 ;;; declarations for functions being bound, we must also deal with
986 ;;; declarations that constrain the type of lexically apparent
988 (defun process-ftype-decl (spec res names fvars)
989 (declare (type list names fvars)
991 (let ((type (compiler-specifier-type spec)))
992 (collect ((res nil cons))
995 (compiler-assert-symbol-home-package-unlocked
996 name "declaring the ftype of ~A"))
997 (let ((found (find name fvars :key #'leaf-source-name :test #'equal)))
1000 (setf (leaf-type found) type)
1001 (assert-definition-type found type
1002 :unwinnage-fun #'compiler-notify
1003 :where "FTYPE declaration"))
1005 (res (cons (find-lexically-apparent-fun
1006 name "in a function type declaration")
1009 (make-lexenv :default res :type-restrictions (res))
1012 ;;; Process a special declaration, returning a new LEXENV. A non-bound
1013 ;;; special declaration is instantiated by throwing a special variable
1014 ;;; into the variables if BINDING-FORM-P is NIL, or otherwise into
1015 ;;; *POST-BINDING-VARIABLE-LEXENV*.
1016 (defun process-special-decl (spec res vars binding-form-p)
1017 (declare (list spec vars) (type lexenv res))
1018 (collect ((new-venv nil cons))
1019 (dolist (name (cdr spec))
1020 (compiler-assert-symbol-home-package-unlocked name "declaring ~A special")
1021 (let ((var (find-in-bindings vars name)))
1024 (aver (eq (car var) 'macro))
1026 "~S is a symbol-macro and thus can't be declared special."
1029 (when (lambda-var-ignorep var)
1030 ;; ANSI's definition for "Declaration IGNORE, IGNORABLE"
1031 ;; requires that this be a STYLE-WARNING, not a full WARNING.
1032 (compiler-style-warn
1033 "The ignored variable ~S is being declared special."
1035 (setf (lambda-var-specvar var)
1036 (specvar-for-binding name)))
1038 (unless (or (assoc name (new-venv) :test #'eq))
1039 (new-venv (cons name (specvar-for-binding name))))))))
1040 (cond (binding-form-p
1041 (setf *post-binding-variable-lexenv*
1042 (append (new-venv) *post-binding-variable-lexenv*))
1045 (make-lexenv :default res :vars (new-venv)))
1049 ;;; Return a DEFINED-FUN which copies a GLOBAL-VAR but for its INLINEP
1050 ;;; (and TYPE if notinline), plus type-restrictions from the lexenv.
1051 (defun make-new-inlinep (var inlinep local-type)
1052 (declare (type global-var var) (type inlinep inlinep))
1053 (let* ((type (if (and (eq inlinep :notinline)
1054 (not (eq (leaf-where-from var) :declared)))
1055 (specifier-type 'function)
1057 (res (make-defined-fun
1058 :%source-name (leaf-source-name var)
1059 :where-from (leaf-where-from var)
1060 :type (if local-type
1061 (type-intersection local-type type)
1064 (when (defined-fun-p var)
1065 (setf (defined-fun-inline-expansion res)
1066 (defined-fun-inline-expansion var))
1067 (setf (defined-fun-functional res)
1068 (defined-fun-functional var)))
1071 ;;; Parse an inline/notinline declaration. If it's a local function we're
1072 ;;; defining, set its INLINEP. If a global function, add a new FENV entry.
1073 (defun process-inline-decl (spec res fvars)
1074 (let ((sense (cdr (assoc (first spec) *inlinep-translations* :test #'eq)))
1076 (dolist (name (rest spec))
1077 (let ((fvar (find name fvars :key #'leaf-source-name :test #'equal)))
1079 (setf (functional-inlinep fvar) sense)
1080 (let ((found (find-lexically-apparent-fun
1081 name "in an inline or notinline declaration")))
1084 (when (policy *lexenv* (>= speed inhibit-warnings))
1085 (compiler-notify "ignoring ~A declaration not at ~
1086 definition of local function:~% ~S"
1090 (cdr (assoc found (lexenv-type-restrictions res)))))
1091 (push (cons name (make-new-inlinep found sense type))
1094 (make-lexenv :default res :funs new-fenv)
1097 ;;; like FIND-IN-BINDINGS, but looks for #'FOO in the FVARS
1098 (defun find-in-bindings-or-fbindings (name vars fvars)
1099 (declare (list vars fvars))
1101 (destructuring-bind (wot fn-name) name
1102 (unless (eq wot 'function)
1103 (compiler-error "The function or variable name ~S is unrecognizable."
1105 (find fn-name fvars :key #'leaf-source-name :test #'equal))
1106 (find-in-bindings vars name)))
1108 ;;; Process an ignore/ignorable declaration, checking for various losing
1110 (defun process-ignore-decl (spec vars fvars)
1111 (declare (list spec vars fvars))
1112 (dolist (name (rest spec))
1113 (let ((var (find-in-bindings-or-fbindings name vars fvars)))
1116 ;; ANSI's definition for "Declaration IGNORE, IGNORABLE"
1117 ;; requires that this be a STYLE-WARNING, not a full WARNING.
1118 (compiler-style-warn "declaring unknown variable ~S to be ignored"
1120 ;; FIXME: This special case looks like non-ANSI weirdness.
1121 ((and (consp var) (eq (car var) 'macro))
1122 ;; Just ignore the IGNORE decl.
1125 (setf (leaf-ever-used var) t))
1126 ((and (lambda-var-specvar var) (eq (first spec) 'ignore))
1127 ;; ANSI's definition for "Declaration IGNORE, IGNORABLE"
1128 ;; requires that this be a STYLE-WARNING, not a full WARNING.
1129 (compiler-style-warn "declaring special variable ~S to be ignored"
1131 ((eq (first spec) 'ignorable)
1132 (setf (leaf-ever-used var) t))
1134 (setf (lambda-var-ignorep var) t)))))
1137 (defun process-dx-decl (names vars fvars)
1138 (flet ((maybe-notify (control &rest args)
1139 (when (policy *lexenv* (> speed inhibit-warnings))
1140 (apply #'compiler-notify control args))))
1141 (if (policy *lexenv* (= stack-allocate-dynamic-extent 3))
1142 (dolist (name names)
1145 (let* ((bound-var (find-in-bindings vars name))
1147 (lexenv-find name vars)
1148 (find-free-var name))))
1152 (setf (leaf-dynamic-extent var) t)
1154 "ignoring DYNAMIC-EXTENT declaration for free ~S"
1157 (compiler-error "DYNAMIC-EXTENT on symbol-macro: ~S" name))
1159 (compiler-error "DYNAMIC-EXTENT on heap-alien-info: ~S"
1162 (eq (car name) 'function)
1164 (valid-function-name-p (cadr name)))
1165 (let* ((fname (cadr name))
1166 (bound-fun (find fname fvars
1167 :key #'leaf-source-name
1169 (etypecase bound-fun
1171 #!+stack-allocatable-closures
1172 (setf (leaf-dynamic-extent bound-fun) t)
1173 #!-stack-allocatable-closures
1175 "ignoring DYNAMIC-EXTENT declaration on a function ~S ~
1176 (not supported on this platform)." fname))
1178 (compiler-error "DYNAMIC-EXTENT on macro: ~S" fname))
1181 "ignoring DYNAMIC-EXTENT declaration for free ~S"
1183 (t (compiler-error "DYNAMIC-EXTENT on a weird thing: ~S" name))))
1184 (maybe-notify "ignoring DYNAMIC-EXTENT declarations for ~S" names))))
1186 ;;; FIXME: This is non-ANSI, so the default should be T, or it should
1187 ;;; go away, I think.
1188 (defvar *suppress-values-declaration* nil
1190 "If true, processing of the VALUES declaration is inhibited.")
1192 ;;; Process a single declaration spec, augmenting the specified LEXENV
1193 ;;; RES. Return RES and result type. VARS and FVARS are as described
1195 (defun process-1-decl (raw-spec res vars fvars binding-form-p)
1196 (declare (type list raw-spec vars fvars))
1197 (declare (type lexenv res))
1198 (let ((spec (canonized-decl-spec raw-spec))
1199 (result-type *wild-type*))
1202 (special (process-special-decl spec res vars binding-form-p))
1205 (compiler-error "no type specified in FTYPE declaration: ~S" spec))
1206 (process-ftype-decl (second spec) res (cddr spec) fvars))
1207 ((inline notinline maybe-inline)
1208 (process-inline-decl spec res fvars))
1210 (process-ignore-decl spec vars fvars)
1215 :policy (process-optimize-decl spec (lexenv-policy res))))
1219 :handled-conditions (process-muffle-conditions-decl
1220 spec (lexenv-handled-conditions res))))
1221 (unmuffle-conditions
1224 :handled-conditions (process-unmuffle-conditions-decl
1225 spec (lexenv-handled-conditions res))))
1227 (process-type-decl (cdr spec) res vars))
1229 (unless *suppress-values-declaration*
1230 (let ((types (cdr spec)))
1232 (compiler-values-specifier-type
1233 (if (singleton-p types)
1235 `(values ,@types)))))
1238 (process-dx-decl (cdr spec) vars fvars)
1240 ((disable-package-locks enable-package-locks)
1243 :disabled-package-locks (process-package-lock-decl
1244 spec (lexenv-disabled-package-locks res))))
1246 (unless (info :declaration :recognized (first spec))
1247 (compiler-warn "unrecognized declaration ~S" raw-spec))
1251 ;;; Use a list of DECLARE forms to annotate the lists of LAMBDA-VAR
1252 ;;; and FUNCTIONAL structures which are being bound. In addition to
1253 ;;; filling in slots in the leaf structures, we return a new LEXENV,
1254 ;;; which reflects pervasive special and function type declarations,
1255 ;;; (NOT)INLINE declarations and OPTIMIZE declarations, and type of
1256 ;;; VALUES declarations. If BINDING-FORM-P is true, the third return
1257 ;;; value is a list of VARs that should not apply to the lexenv of the
1258 ;;; initialization forms for the bindings, but should apply to the body.
1260 ;;; This is also called in main.lisp when PROCESS-FORM handles a use
1262 (defun process-decls (decls vars fvars &key (lexenv *lexenv*)
1263 (binding-form-p nil))
1264 (declare (list decls vars fvars))
1265 (let ((result-type *wild-type*)
1266 (*post-binding-variable-lexenv* nil))
1267 (dolist (decl decls)
1268 (dolist (spec (rest decl))
1269 (unless (consp spec)
1270 (compiler-error "malformed declaration specifier ~S in ~S" spec decl))
1271 (multiple-value-bind (new-env new-result-type)
1272 (process-1-decl spec lexenv vars fvars binding-form-p)
1273 (setq lexenv new-env)
1274 (unless (eq new-result-type *wild-type*)
1276 (values-type-intersection result-type new-result-type))))))
1277 (values lexenv result-type *post-binding-variable-lexenv*)))
1279 (defun %processing-decls (decls vars fvars ctran lvar binding-form-p fun)
1280 (multiple-value-bind (*lexenv* result-type post-binding-lexenv)
1281 (process-decls decls vars fvars :binding-form-p binding-form-p)
1282 (cond ((eq result-type *wild-type*)
1283 (funcall fun ctran lvar post-binding-lexenv))
1285 (let ((value-ctran (make-ctran))
1286 (value-lvar (make-lvar)))
1287 (multiple-value-prog1
1288 (funcall fun value-ctran value-lvar post-binding-lexenv)
1289 (let ((cast (make-cast value-lvar result-type
1290 (lexenv-policy *lexenv*))))
1291 (link-node-to-previous-ctran cast value-ctran)
1292 (setf (lvar-dest value-lvar) cast)
1293 (use-continuation cast ctran lvar))))))))
1294 (defmacro processing-decls ((decls vars fvars ctran lvar
1295 &optional post-binding-lexenv)
1297 (check-type ctran symbol)
1298 (check-type lvar symbol)
1299 (let ((post-binding-lexenv-p (not (null post-binding-lexenv)))
1300 (post-binding-lexenv (or post-binding-lexenv (gensym))))
1301 `(%processing-decls ,decls ,vars ,fvars ,ctran ,lvar
1302 ,post-binding-lexenv-p
1303 (lambda (,ctran ,lvar ,post-binding-lexenv)
1304 (declare (ignorable ,post-binding-lexenv))
1307 ;;; Return the SPECVAR for NAME to use when we see a local SPECIAL
1308 ;;; declaration. If there is a global variable of that name, then
1309 ;;; check that it isn't a constant and return it. Otherwise, create an
1310 ;;; anonymous GLOBAL-VAR.
1311 (defun specvar-for-binding (name)
1312 (cond ((not (eq (info :variable :where-from name) :assumed))
1313 (let ((found (find-free-var name)))
1314 (when (heap-alien-info-p found)
1316 "~S is an alien variable and so can't be declared special."
1318 (unless (global-var-p found)
1320 "~S is a constant and so can't be declared special."
1324 (make-global-var :kind :special
1326 :where-from :declared))))