Add a declaration
[sbcl.git] / src / code / symbol.lisp
blobaff49ee83a72ed51b19582f682d58e304e9de9dd
1 ;;;; code to manipulate symbols (but not packages, which are handled
2 ;;;; elsewhere)
3 ;;;;
4 ;;;; Many of these definitions are trivial interpreter entries to
5 ;;;; functions open-coded by the compiler.
7 ;;;; This software is part of the SBCL system. See the README file for
8 ;;;; more information.
9 ;;;;
10 ;;;; This software is derived from the CMU CL system, which was
11 ;;;; written at Carnegie Mellon University and released into the
12 ;;;; public domain. The software is in the public domain and is
13 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
14 ;;;; files for more information.
16 (in-package "SB!IMPL")
18 (declaim (maybe-inline get get3 %put getf remprop %putf get-properties keywordp))
20 #-sb-xc-host
21 (eval-when (:compile-toplevel :load-toplevel :execute)
22 (defun handle-deprecated-global-variable (name)
23 (multiple-value-bind (state since replacements)
24 (check-deprecated-variable name)
25 (when (eq state :final)
26 `(deprecation-error ,since ',name '(,@replacements))))))
28 (defun symbol-value (symbol)
29 #!+sb-doc
30 "Return SYMBOL's current bound value."
31 (declare (optimize (safety 1)))
32 (symbol-value symbol))
34 #-sb-xc-host
35 (define-compiler-macro symbol-value (&whole form symbol &environment env)
36 (when (sb!xc:constantp symbol env)
37 (let ((name (constant-form-value symbol env)))
38 (awhen (and (symbolp name) (handle-deprecated-global-variable name))
39 (return-from symbol-value it))))
40 form)
42 (defun boundp (symbol)
43 #!+sb-doc
44 "Return non-NIL if SYMBOL is bound to a value."
45 (boundp symbol))
47 (defun set (symbol new-value)
48 #!+sb-doc
49 "Set SYMBOL's value cell to NEW-VALUE."
50 (declare (type symbol symbol))
51 (about-to-modify-symbol-value symbol 'set new-value)
52 (%set-symbol-value symbol new-value))
54 (defun %set-symbol-value (symbol new-value)
55 (%set-symbol-value symbol new-value))
57 (defun symbol-global-value (symbol)
58 #!+sb-doc
59 "Return the SYMBOL's current global value. Identical to SYMBOL-VALUE,
60 in single-threaded builds: in multithreaded builds bound values are
61 distinct from the global value. Can also be SETF."
62 (declare (optimize (safety 1)))
63 (symbol-global-value symbol))
65 #-sb-xc-host
66 (define-compiler-macro symbol-global-value (&whole form symbol &environment env)
67 (when (sb!xc:constantp symbol env)
68 (let ((name (constant-form-value symbol env)))
69 (awhen (and (symbolp name) (handle-deprecated-global-variable name))
70 (return-from symbol-global-value it))))
71 form)
73 (defun set-symbol-global-value (symbol new-value)
74 (about-to-modify-symbol-value symbol 'set new-value)
75 (%set-symbol-global-value symbol new-value))
77 (declaim (inline %makunbound))
78 (defun %makunbound (symbol)
79 (%set-symbol-value symbol (%primitive sb!c:make-unbound-marker)))
81 (defun makunbound (symbol)
82 #!+sb-doc
83 "Make SYMBOL unbound, removing any value it may currently have."
84 (with-single-package-locked-error (:symbol symbol "unbinding the symbol ~A")
85 ;; :EVENTUALLY is allowed for :always-bound here, as it has no bearing
86 (when (eq (info :variable :always-bound symbol) :always-bound)
87 (error "Can't make ~A variable unbound: ~S" 'always-bound symbol))
88 (about-to-modify-symbol-value symbol 'makunbound)
89 (%makunbound symbol)
90 symbol))
92 ;; Compute a symbol's hash. Also used by FIND-SYMBOL which requires that a hash
93 ;; be a pure function of the name and not a semi-opaque property of the symbol.
94 ;; The hash of all symbols named "NIL" must be the same, so not to pessimize
95 ;; FIND-SYMBOL by special-casing the finding of CL:NIL with an extra "or"
96 ;; in the hash-equality test. i.e. We can't recognize that CL:NIL was the
97 ;; object sought (having an exceptional hash) until it has been found.
98 (defun compute-symbol-hash (string length)
99 (declare (simple-string string) (index length))
100 (if (and (= length 3)
101 (locally
102 ;; SXHASH-SUBSTRING is unsafe, so this is too. but do we know that
103 ;; length is ok, or is it an accident that it can scan too far?
104 (declare (optimize (safety 0)))
105 (string-dispatch (simple-base-string (simple-array character (*)))
106 string
107 (and (char= (schar string 0) #\N)
108 (char= (schar string 1) #\I)
109 (char= (schar string 2) #\L)))))
110 ;; FIXME: hardwire this. See similar comment at
111 ;; (deftransform sxhash ((x) (symbol))
112 (return-from compute-symbol-hash (symbol-hash nil)))
113 ;; And make a symbol's hash not the same as (sxhash name) in general.
114 (let ((sxhash (logand (lognot (%sxhash-simple-substring string length))
115 sb!xc:most-positive-fixnum)))
116 (if (zerop sxhash) #x55AA sxhash))) ; arbitrary substitute for 0
118 ;; Return SYMBOL's hash, a strictly positive fixnum, computing it if not stored.
119 ;; The inlined code for (SXHASH symbol) only calls ENSURE-SYMBOL-HASH if
120 ;; needed, however this is ok to call even if the hash is already nonzero.
121 (defun ensure-symbol-hash (symbol)
122 (let ((hash (symbol-hash symbol)))
123 (if (zerop hash)
124 (let ((name (symbol-name symbol)))
125 (%set-symbol-hash symbol (compute-symbol-hash name (length name))))
126 hash)))
128 ;;; Interpreter stub: Return whatever is in the SYMBOL-HASH slot of SYMBOL.
129 (defun symbol-hash (symbol)
130 (symbol-hash symbol))
132 (defun symbol-function (symbol)
133 #!+sb-doc
134 "Return SYMBOL's current function definition. Settable with SETF."
135 (%coerce-name-to-fun symbol symbol-fdefn))
137 ;; I think there are two bugs here.
138 ;; Per CLHS "SETF may be used with symbol-function to replace a global
139 ;; function definition when the symbol's function definition
140 ;; does not represent a special operator."
141 ;; 1. This should fail:
142 ;; * (in-package CL) ; circumvent package lock
143 ;; * (setf (symbol-function 'if) #'cons) => #<FUNCTION CONS>
144 ;; 2. (SETF (SYMBOL-FUNCTION 'I-ONCE-WAS-A-MACRO) #'CONS)
145 ;; should _probably_ make I-ONCE-WAS-A-MACRO not a macro
146 (defun (setf symbol-function) (new-value symbol)
147 (declare (type symbol symbol) (type function new-value))
148 ;; (SYMBOL-FUNCTION symbol) == (FDEFINITION symbol) according to the writeup
149 ;; on SYMBOL-FUNCTION. It doesn't say that SETF behaves the same, but let's
150 ;; assume it does, and that we can't assign our macro/special guard funs.
151 (err-if-unacceptable-function new-value '(setf symbol-function))
152 (with-single-package-locked-error
153 (:symbol symbol "setting the symbol-function of ~A")
154 ;; This code is a little "surprising" in that it is not just a limited
155 ;; case of (SETF FDEFINITION), but instead a different thing.
156 ;; I really think the code paths should be reconciled.
157 ;; e.g. what's up with *USER-HASH-TABLE-TESTS* being checked
158 ;; in %SET-FDEFINITION but not here?
159 (maybe-clobber-ftype symbol)
160 (let ((fdefn (find-or-create-fdefn symbol)))
161 (setf (fdefn-fun fdefn) new-value))))
163 ;;; Accessors for the dual-purpose info/plist slot
165 ;; A symbol's INFO slot is always in one of three states:
166 ;; 1. NIL ; the initial state
167 ;; 2. #(data ....) ; globaldb used the slot
168 ;; 3. (PLIST . NIL) or (PLIST . #(data ...)) ; plist was touched,
169 ;; and also possibly globaldb used the slot
171 ;; State 1 transitions to state 2 by assigning globaldb data,
172 ;; or to state 3 via ({SETF|CAS} SYMBOL-PLIST).
173 ;; (SETF INFO) by itself will never cause 1 -> 3 transition.
174 ;; State 2 transitions to state 3 via ({SETF|CAS} SYMBOL-PLIST).
175 ;; There are *no* other permissible state transitions.
177 (defun symbol-info (symbol)
178 (symbol-info symbol))
180 ;; An "interpreter stub" for an operation that is only implemented for
181 ;; the benefit of platforms without compare-and-swap-vops.
182 (defun (setf symbol-info) (new-info symbol)
183 (setf (symbol-info symbol) new-info))
185 ;; Atomically update SYMBOL's info/plist slot to contain a new info vector.
186 ;; The vector is computed by calling UPDATE-FN on the old vector,
187 ;; repeatedly as necessary, until no conflict happens with other updaters.
188 ;; The function may choose to abort the update by returning NIL.
189 (defun update-symbol-info (symbol update-fn)
190 (declare (symbol symbol)
191 (type (function (t) t) update-fn))
192 (prog ((info-holder (symbol-info symbol))
193 (current-vect))
194 outer-restart
195 ;; Do not use SYMBOL-INFO-VECTOR - this must not perform a slot read again.
196 (setq current-vect (if (listp info-holder) (cdr info-holder) info-holder))
197 inner-restart
198 ;; KLUDGE: The "#." on +nil-packed-infos+ is due to slightly crippled
199 ;; fops in genesis's fasload. Anonymizing the constant works around the
200 ;; issue, at the expense of an extra copy of the empty info vector.
201 (let ((new-vect (funcall update-fn
202 (or current-vect #.+nil-packed-infos+))))
203 (unless (simple-vector-p new-vect)
204 (aver (null new-vect))
205 (return)) ; nothing to do
206 (if (consp info-holder) ; State 3: exchange the CDR
207 (let ((old (%compare-and-swap-cdr info-holder current-vect new-vect)))
208 (when (eq old current-vect) (return t)) ; win
209 (setq current-vect old) ; Don't touch holder- it's still a cons
210 (go inner-restart)))
211 ;; State 1 or 2: info-holder is NIL or a vector.
212 ;; Exchange the contents of the info slot. Type-inference derives
213 ;; SIMPLE-VECTOR-P on the args to CAS, so no extra checking.
214 (let ((old (%compare-and-swap-symbol-info symbol info-holder new-vect)))
215 (when (eq old info-holder) (return t)) ; win
216 ;; Check whether we're in state 2 or 3 now.
217 ;; Impossible to be in state 1: nobody ever puts NIL in the slot.
218 ;; Up above, we bailed out if the update-fn returned NIL.
219 (setq info-holder old)
220 (go outer-restart)))))
222 (eval-when (:compile-toplevel)
223 ;; If we're in state 1 or state 3, we can take (CAR (SYMBOL-INFO S))
224 ;; to get the property list. If we're in state 2, this same access
225 ;; gets the fixnum which is the VECTOR-LENGTH of the info vector.
226 ;; So all we have to do is turn any fixnum to NIL, and we have a plist.
227 ;; Ensure that this pun stays working.
228 (assert (= (- (* sb!vm:n-word-bytes sb!vm:cons-car-slot)
229 sb!vm:list-pointer-lowtag)
230 (- (* sb!vm:n-word-bytes sb!vm:vector-length-slot)
231 sb!vm:other-pointer-lowtag))))
233 (defun symbol-plist (symbol)
234 #!+sb-doc
235 "Return SYMBOL's property list."
236 #!+symbol-info-vops
237 (symbol-plist symbol) ; VOP translates it
238 #!-symbol-info-vops
239 (let ((list (car (truly-the list (symbol-info symbol))))) ; a white lie
240 ;; Just ensure the result is not a fixnum, and we're done.
241 (if (fixnump list) nil list)))
243 (declaim (ftype (sfunction (symbol t) cons) %ensure-plist-holder)
244 (inline %ensure-plist-holder))
246 ;; When a plist update (setf or cas) is first performed on a symbol,
247 ;; a one-time allocation of an extra cons is done which creates two
248 ;; "slots" from one: a slot for the info-vector and a slot for the plist.
249 ;; This avoids complications in the implementation of the user-facing
250 ;; (CAS SYMBOL-PLIST) function, which should not have to be aware of
251 ;; competition from globaldb mutators even if no other threads attempt
252 ;; to manipulate the plist per se.
254 ;; Given a SYMBOL and its current INFO of type (OR LIST SIMPLE-VECTOR)
255 ;; ensure that SYMBOL's current info is a cons, and return that.
256 ;; If racing with multiple threads, at most one thread will install the cons.
257 (defun %ensure-plist-holder (symbol info)
258 ;; Invoked only when SYMBOL is known to be a symbol.
259 (declare (optimize (safety 0)))
260 (if (consp info) ; it's fine to call this with a cell already installed
261 info ; all done
262 (let (newcell)
263 ;; The pointer from the new cons to the old info must be persisted
264 ;; to memory before the symbol's info slot points to the cons.
265 ;; [x86oid doesn't need the barrier, others might]
266 (sb!thread:barrier (:write)
267 (setq newcell (cons nil info)))
268 (loop (let ((old (%compare-and-swap-symbol-info symbol info newcell)))
269 (cond ((eq old info) (return newcell)) ; win
270 ((consp old) (return old))) ; somebody else made a cons!
271 (setq info old)
272 (sb!thread:barrier (:write) ; Retry using same newcell
273 (rplacd newcell info)))))))
275 (declaim (inline %compare-and-swap-symbol-plist
276 %set-symbol-plist))
278 (defun %compare-and-swap-symbol-plist (symbol old new)
279 ;; This is the entry point into which (CAS SYMBOL-PLIST) is transformed.
280 ;; If SYMBOL's info cell is a cons, we can do (CAS CAR). Otherwise punt.
281 (declare (symbol symbol) (list old new))
282 (let ((cell (symbol-info symbol)))
283 (if (consp cell)
284 (%compare-and-swap-car cell old new)
285 (%%compare-and-swap-symbol-plist symbol old new))))
287 (defun %%compare-and-swap-symbol-plist (symbol old new)
288 ;; This is just the second half of a partially-inline function, to avoid
289 ;; code bloat in the exceptional case. Type assertions should have been
290 ;; done - or not, per policy - by the caller of %COMPARE-AND-SWAP-SYMBOL-PLIST
291 ;; so now use TRULY-THE to avoid further type checking.
292 (%compare-and-swap-car (%ensure-plist-holder (truly-the symbol symbol)
293 (symbol-info symbol))
294 old new))
296 (defun %set-symbol-plist (symbol new-value)
297 ;; This is the entry point into which (SETF SYMBOL-PLIST) is transformed.
298 ;; If SYMBOL's info cell is a cons, we can do (SETF CAR). Otherwise punt.
299 (declare (symbol symbol) (list new-value))
300 (let ((cell (symbol-info symbol)))
301 (if (consp cell)
302 (setf (car cell) new-value)
303 (%%set-symbol-plist symbol new-value))))
305 (defun %%set-symbol-plist (symbol new-value)
306 ;; Same considerations as for %%COMPARE-AND-SWAP-SYMBOL-PLIST,
307 ;; with a slight efficiency hack: if the symbol has no plist holder cell
308 ;; and the NEW-VALUE is NIL, try to avoid creating a holder cell.
309 ;; Yet we must write something, because omitting a memory operation
310 ;; could have a subtle effect in the presence of multi-threading.
311 (let ((info (symbol-info (truly-the symbol symbol))))
312 (when (and (not new-value) (atom info)) ; try to treat this as a no-op
313 (let ((old (%compare-and-swap-symbol-info symbol info info)))
314 (if (eq old info) ; good enough
315 (return-from %%set-symbol-plist new-value) ; = nil
316 (setq info old))))
317 (setf (car (%ensure-plist-holder symbol info)) new-value)))
319 ;;; End of Info/Plist slot manipulation
321 (defun symbol-name (symbol)
322 #!+sb-doc
323 "Return SYMBOL's name as a string."
324 (symbol-name symbol))
326 (defun symbol-package (symbol)
327 #!+sb-doc
328 "Return the package SYMBOL was interned in, or NIL if none."
329 (symbol-package symbol))
331 (defun %set-symbol-package (symbol package)
332 (declare (type symbol symbol))
333 (%set-symbol-package symbol package))
335 (defun make-symbol (string)
336 #!+sb-doc
337 "Make and return a new symbol with the STRING as its print name."
338 (declare (type string string))
339 (%make-symbol (if (simple-string-p string)
340 string
341 (subseq string 0))))
343 (defun get (symbol indicator &optional (default nil))
344 #!+sb-doc
345 "Look on the property list of SYMBOL for the specified INDICATOR. If this
346 is found, return the associated value, else return DEFAULT."
347 (get3 symbol indicator default))
349 (defun get3 (symbol indicator default)
350 (let (cdr-pl)
351 (do ((pl (symbol-plist symbol) (cdr cdr-pl)))
352 ((atom pl) default)
353 (setq cdr-pl (cdr pl))
354 (cond ((atom cdr-pl)
355 (error "~S has an odd number of items in its property list."
356 symbol))
357 ((eq (car pl) indicator)
358 (return (car cdr-pl)))))))
360 (defun %put (symbol indicator value)
361 #!+sb-doc
362 "The VALUE is added as a property of SYMBOL under the specified INDICATOR.
363 Returns VALUE."
364 (do ((pl (symbol-plist symbol) (cddr pl)))
365 ((endp pl)
366 (setf (symbol-plist symbol)
367 (list* indicator value (symbol-plist symbol)))
368 value)
369 (cond ((endp (cdr pl))
370 (error "~S has an odd number of items in its property list."
371 symbol))
372 ((eq (car pl) indicator)
373 (rplaca (cdr pl) value)
374 (return value)))))
376 (defun remprop (symbol indicator)
377 #!+sb-doc
378 "Look on property list of SYMBOL for property with specified
379 INDICATOR. If found, splice this indicator and its value out of
380 the plist, and return the tail of the original list starting with
381 INDICATOR. If not found, return () with no side effects.
383 NOTE: The ANSI specification requires REMPROP to return true (not false)
384 or false (the symbol NIL). Portable code should not rely on any other value."
385 (do ((pl (symbol-plist symbol) (cddr pl))
386 (prev nil pl))
387 ((atom pl) nil)
388 (cond ((atom (cdr pl))
389 (error "~S has an odd number of items in its property list."
390 symbol))
391 ((eq (car pl) indicator)
392 (cond (prev (rplacd (cdr prev) (cddr pl)))
394 (setf (symbol-plist symbol) (cddr pl))))
395 (return pl)))))
397 (defun getf (place indicator &optional (default ()))
398 #!+sb-doc
399 "Search the property list stored in PLACE for an indicator EQ to INDICATOR.
400 If one is found, return the corresponding value, else return DEFAULT."
401 (do ((plist place (cddr plist)))
402 ((null plist) default)
403 (cond ((atom (cdr plist))
404 (error 'simple-type-error
405 :format-control "malformed property list: ~S."
406 :format-arguments (list place)
407 :datum (cdr plist)
408 :expected-type 'cons))
409 ((eq (car plist) indicator)
410 (return (cadr plist))))))
412 (defun %putf (place property new-value)
413 (declare (type list place))
414 (do ((plist place (cddr plist)))
415 ((endp plist) (list* property new-value place))
416 (declare (type list plist))
417 (when (eq (car plist) property)
418 (setf (cadr plist) new-value)
419 (return place))))
421 (defun get-properties (place indicator-list)
422 #!+sb-doc
423 "Like GETF, except that INDICATOR-LIST is a list of indicators which will
424 be looked for in the property list stored in PLACE. Three values are
425 returned, see manual for details."
426 (do ((plist place (cddr plist)))
427 ((null plist) (values nil nil nil))
428 (cond ((atom (cdr plist))
429 (error 'simple-type-error
430 :format-control "malformed property list: ~S."
431 :format-arguments (list place)
432 :datum (cdr plist)
433 :expected-type 'cons))
434 ((memq (car plist) indicator-list)
435 (return (values (car plist) (cadr plist) plist))))))
437 (defun copy-symbol (symbol &optional (copy-props nil) &aux new-symbol)
438 #!+sb-doc
439 "Make and return a new uninterned symbol with the same print name
440 as SYMBOL. If COPY-PROPS is false, the new symbol is neither bound
441 nor fbound and has no properties, else it has a copy of SYMBOL's
442 function, value and property list."
443 (declare (type symbol symbol))
444 (setq new-symbol (make-symbol (symbol-name symbol)))
445 (when copy-props
446 (%set-symbol-value new-symbol
447 (%primitive sb!c:fast-symbol-value symbol))
448 (setf (symbol-plist new-symbol)
449 (copy-list (symbol-plist symbol)))
450 (when (fboundp symbol)
451 (setf (symbol-function new-symbol) (symbol-function symbol))))
452 new-symbol)
454 (defun keywordp (object)
455 #!+sb-doc
456 "Return true if Object is a symbol in the \"KEYWORD\" package."
457 (and (symbolp object)
458 (eq (symbol-package object) *keyword-package*)))
460 ;;;; GENSYM and friends
462 (defun %make-symbol-name (prefix counter)
463 (declare (string prefix))
464 (if (typep counter '(and fixnum unsigned-byte))
465 (let ((s ""))
466 (declare (simple-string s))
467 (labels ((recurse (depth n)
468 (multiple-value-bind (q r) (truncate n 10)
469 (if (plusp q)
470 (recurse (1+ depth) q)
471 (let ((et (if (or (base-string-p prefix)
472 (every #'base-char-p prefix))
473 'base-char 'character)))
474 (setq s (make-string (+ (length prefix) depth)
475 :element-type et))
476 (replace s prefix)))
477 (setf (char s (- (length s) depth))
478 (code-char (+ (char-code #\0) r)))
479 s)))
480 (recurse 1 counter)))
481 (with-simple-output-to-string (s)
482 (write-string prefix s)
483 (%output-integer-in-base counter 10 s))))
485 (defvar *gensym-counter* 0
486 #!+sb-doc
487 "counter for generating unique GENSYM symbols")
488 (declaim (type unsigned-byte *gensym-counter*))
490 (defun gensym (&optional (thing "G"))
491 #!+sb-doc
492 "Creates a new uninterned symbol whose name is a prefix string (defaults
493 to \"G\"), followed by a decimal number. Thing, when supplied, will
494 alter the prefix if it is a string, or be used for the decimal number
495 if it is a number, of this symbol. The default value of the number is
496 the current value of *gensym-counter* which is incremented each time
497 it is used."
498 (multiple-value-bind (prefix int)
499 (if (integerp thing)
500 (values "G" thing)
501 (values thing (let ((old *gensym-counter*))
502 (setq *gensym-counter* (1+ old))
503 old)))
504 (make-symbol (%make-symbol-name prefix int))))
506 (defvar *gentemp-counter* 0)
507 (declaim (type unsigned-byte *gentemp-counter*))
509 (defun gentemp (&optional (prefix "T") (package (sane-package)))
510 #!+sb-doc
511 "Creates a new symbol interned in package PACKAGE with the given PREFIX."
512 (declare (type string prefix))
513 (loop for name = (%make-symbol-name prefix (incf *gentemp-counter*))
514 while (nth-value 1 (find-symbol name package))
515 finally (return (values (intern name package)))))
517 ;;; This function is to be called just before a change which would affect the
518 ;;; symbol value. We don't absolutely have to call this function before such
519 ;;; changes, since such changes to constants are given as undefined behavior,
520 ;;; it's nice to do so. To circumvent this you need code like this:
522 ;;; (defvar foo)
523 ;;; (defun set-foo (x) (setq foo x))
524 ;;; (defconstant foo 42)
525 ;;; (set-foo 13)
526 ;;; foo => 13, (constantp 'foo) => t
528 ;;; ...in which case you frankly deserve to lose.
529 (defun about-to-modify-symbol-value (symbol action &optional (new-value nil valuep) bind)
530 (declare (symbol symbol))
531 (flet ((describe-action ()
532 (ecase action
533 (set "set SYMBOL-VALUE of ~S")
534 (progv "bind ~S")
535 (compare-and-swap "compare-and-swap SYMBOL-VALUE of ~S")
536 (defconstant "define ~S as a constant")
537 (makunbound "make ~S unbound"))))
538 (let ((kind (info :variable :kind symbol)))
539 (multiple-value-bind (what continue)
540 (cond ((eq :constant kind)
541 (cond ((eq symbol t)
542 (values "Veritas aeterna. (can't ~@?)" nil))
543 ((eq symbol nil)
544 (values "Nihil ex nihil. (can't ~@?)" nil))
545 ((keywordp symbol)
546 (values "Can't ~@?." nil))
548 (values "Constant modification: attempt to ~@?." t))))
549 ((and bind (eq :global kind))
550 (values "Can't ~@? (global variable)." nil)))
551 (when what
552 (if continue
553 (cerror "Modify the constant." what (describe-action) symbol)
554 (error what (describe-action) symbol)))
555 (when valuep
556 ;; :VARIABLE :TYPE is in the db only if it is declared, so no need to
557 ;; check.
558 (let ((type (info :variable :type symbol)))
559 (unless (sb!kernel::%%typep new-value type nil)
560 (let ((spec (type-specifier type)))
561 (error 'simple-type-error
562 :format-control "~@<Cannot ~@? to ~S, not of type ~S.~:@>"
563 :format-arguments (list (describe-action) symbol new-value spec)
564 :datum new-value
565 :expected-type spec)))))))
566 nil))