0.7.7.24:
[sbcl.git] / src / compiler / fndb.lisp
1 ;;;; This file defines all the standard functions to be known
2 ;;;; functions. Each function has type and side-effect information,
3 ;;;; and may also have IR1 optimizers.
4
5 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; more information.
7 ;;;;
8 ;;;; This software is derived from the CMU CL system, which was
9 ;;;; written at Carnegie Mellon University and released into the
10 ;;;; public domain. The software is in the public domain and is
11 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
12 ;;;; files for more information.
13
14 (in-package "SB!C")
15 \f
16 ;;;; information for known functions:
17
18 (defknown coerce (t type-specifier) t
19   ;; Note:
20   ;; (1) This is not FLUSHABLE because it's defined to signal errors.
21   ;; (2) It's not worth trying to make this FOLDABLE in the
22   ;;     cross-compiler,because
23   ;;       (a) it would probably be really hard to make all the 
24   ;;           tricky issues (e.g. which specialized array types are
25   ;;           supported) match between cross-compiler and target
26   ;;           compiler, and besides
27   ;;       (b) leaving it not FOLDABLE lets us use the idiom
28   ;;               (COERCE FOO 'SOME-SPECIALIZED-ARRAY-TYPE-OR-ANOTHER)
29   ;;           as a way of delaying the generation of specialized
30   ;;           array types until runtime, which helps us keep the
31   ;;           cross-compiler's dumper relatively simple and which
32   ;;           lets us preserve distinctions which might not even exist
33   ;;           on the cross-compilation host (because ANSI doesn't
34   ;;           guarantee that specialized array types exist there).
35   ;; FIXME: It's actually not clear that COERCE on non-NUMBER types
36   ;; is FOLDABLE at all. Check this.
37   (movable #-sb-xc-host foldable)
38   :derive-type (result-type-specifier-nth-arg 2))
39 (defknown list-to-simple-string* (list) simple-string)
40 (defknown list-to-bit-vector* (list) bit-vector)
41 (defknown list-to-vector* (list type-specifier) vector)
42 (defknown list-to-simple-vector* (list) simple-vector)
43 (defknown vector-to-vector* (vector type-specifier) vector)
44 (defknown vector-to-simple-string* (vector) vector)
45
46 (defknown type-of (t) t (foldable flushable))
47
48 ;;; These can be affected by type definitions, so they're not FOLDABLE.
49 (defknown (upgraded-complex-part-type upgraded-array-element-type)
50           (type-specifier) type-specifier
51   (flushable))
52 \f
53 ;;;; from the "Predicates" chapter:
54
55 ;;; FIXME: Is it right to have TYPEP (and TYPE-OF, elsewhere; and
56 ;;; perhaps SPECIAL-OPERATOR-P and others) be FOLDABLE in the
57 ;;; cross-compilation host? After all, some type relationships (e.g.
58 ;;; FIXNUMness) might be different between host and target. Perhaps
59 ;;; this property should be protected by #-SB-XC-HOST? Perhaps we need
60 ;;; 3-stage bootstrapping after all? (Ugh! It's *so* slow already!)
61 (defknown typep (t type-specifier) t
62   (flushable
63    ;; Unlike SUBTYPEP or UPGRADED-ARRAY-ELEMENT-TYPE and friends, this
64    ;; seems to be FOLDABLE. Like SUBTYPEP, it's affected by type
65    ;; definitions, but unlike SUBTYPEP, there should be no way to make
66    ;; a TYPEP expression with constant arguments which doesn't return
67    ;; an error before the type declaration (because of undefined
68    ;; type). E.g. you can do
69    ;;   (SUBTYPEP 'INTEGER 'FOO) => NIL, NIL
70    ;;   (DEFTYPE FOO () T)
71    ;;   (SUBTYPEP 'INTEGER 'FOO) => T, T
72    ;; but the analogous
73    ;;   (TYPEP 12 'FOO)
74    ;;   (DEFTYPE FOO () T)
75    ;;   (TYPEP 12 'FOO)
76    ;; doesn't work because the first call is an error.
77    ;;
78    ;; (UPGRADED-ARRAY-ELEMENT-TYPE and UPGRADED-COMPLEX-PART-TYPE have
79    ;; behavior like SUBTYPEP in this respect, not like TYPEP.)
80    foldable))
81 (defknown subtypep (type-specifier type-specifier) (values boolean boolean) 
82   ;; This is not FOLDABLE because its value is affected by type
83   ;; definitions.
84   ;;
85   ;; FIXME: Is it OK to fold this when the types have already been
86   ;; defined? Does the code inherited from CMU CL already do this?
87   (flushable)) 
88
89 (defknown (null symbolp atom consp listp numberp integerp rationalp floatp
90                 complexp characterp stringp bit-vector-p vectorp
91                 simple-vector-p simple-string-p simple-bit-vector-p arrayp
92                 sb!xc:packagep functionp compiled-function-p not)
93   (t) boolean (movable foldable flushable))
94
95 (defknown (eq eql) (t t) boolean (movable foldable flushable))
96 (defknown (equal equalp) (t t) boolean (foldable flushable recursive))
97 \f
98 ;;;; classes
99
100 (sb!xc:deftype name-for-class () t)
101 (defknown class-name (sb!xc:class) name-for-class (flushable))
102 (defknown find-class (name-for-class &optional t lexenv)
103   (or sb!xc:class null) ())
104 (defknown class-of (t) sb!xc:class (flushable))
105 (defknown layout-of (t) layout (flushable))
106 (defknown copy-structure (structure-object) structure-object
107   (flushable unsafe))
108 \f
109 ;;;; from the "Control Structure" chapter:
110
111 ;;; This is not FLUSHABLE, since it's required to signal an error if
112 ;;; unbound.
113 (defknown (symbol-value symbol-function) (symbol) t ())
114
115 (defknown boundp (symbol) boolean (flushable))
116 (defknown fboundp ((or symbol cons)) boolean (flushable explicit-check))
117 (defknown special-operator-p (symbol) t
118   ;; The set of special operators never changes.
119   (movable foldable flushable)) 
120 (defknown set (symbol t) t (unsafe)
121   :derive-type #'result-type-last-arg)
122 (defknown fdefinition ((or symbol cons)) function (unsafe explicit-check))
123 (defknown %set-fdefinition ((or symbol cons) function) function
124   (unsafe explicit-check))
125 (defknown makunbound (symbol) symbol)
126 (defknown fmakunbound ((or symbol cons)) (or symbol cons)
127   (unsafe explicit-check))
128 (defknown (get-setf-method get-setf-method-multiple-value)
129   ((or list symbol) &optional lexenv)
130   (values list list list form form)
131   (flushable))
132 (defknown apply (callable t &rest t) *) ; ### Last arg must be List...
133 (defknown funcall (callable &rest t) *)
134
135 (defknown (mapcar maplist mapcan mapcon) (callable list &rest list) list
136   (call))
137
138 (defknown (mapc mapl) (callable list &rest list) list (foldable call))
139
140 ;;; We let VALUES-LIST be foldable, since constant-folding will turn
141 ;;; it into VALUES. VALUES is not foldable, since MV constants are
142 ;;; represented by a call to VALUES.
143 (defknown values (&rest t) * (movable flushable unsafe))
144 (defknown values-list (list) * (movable foldable flushable))
145 \f
146 ;;;; from the "Macros" chapter:
147
148 (defknown macro-function (symbol &optional lexenv)
149   (or function null)
150   (flushable))
151 (defknown (macroexpand macroexpand-1) (t &optional lexenv)
152   (values form &optional boolean))
153
154 (defknown compiler-macro-function (t &optional lexenv)
155   (or function null)
156   (flushable))
157 \f
158 ;;;; from the "Declarations" chapter:
159
160 (defknown proclaim (list) (values) (recursive))
161
162 ;;;; from the "Symbols" chapter:
163
164 (defknown get (symbol t &optional t) t (flushable))
165 (defknown remprop (symbol t) t)
166 (defknown symbol-plist (symbol) list (flushable))
167 (defknown getf (list t &optional t) t (foldable flushable))
168 (defknown get-properties (list list) (values t t list) (foldable flushable))
169 (defknown symbol-name (symbol) simple-string (movable foldable flushable))
170 (defknown make-symbol (string) symbol (flushable))
171 (defknown copy-symbol (symbol &optional t) symbol (flushable))
172 (defknown gensym (&optional (or string unsigned-byte)) symbol ())
173 (defknown symbol-package (symbol) (or sb!xc:package null) (flushable))
174 (defknown keywordp (t) boolean (flushable))       ; If someone uninterns it...
175 \f
176 ;;;; from the "Packages" chapter:
177
178 (sb!xc:deftype package-designator () '(or stringable sb!xc:package))
179 (sb!xc:deftype symbols () '(or list symbol))
180
181 (defknown gentemp (&optional string package-designator) symbol)
182
183 (defknown make-package (stringable &key
184                                    (:use list)
185                                    (:nicknames list)
186                                    ;; ### extensions...
187                                    (:internal-symbols index)
188                                    (:external-symbols index))
189   sb!xc:package)
190 (defknown find-package (package-designator) (or sb!xc:package null)
191   (flushable))
192 (defknown package-name (package-designator) (or simple-string null)
193   (flushable))
194 (defknown package-nicknames (package-designator) list (flushable))
195 (defknown rename-package (package-designator package-designator &optional list)
196   sb!xc:package)
197 (defknown package-use-list (package-designator) list (flushable))
198 (defknown package-used-by-list (package-designator) list (flushable))
199 (defknown package-shadowing-symbols (package-designator) list (flushable))
200 (defknown list-all-packages () list (flushable))
201 (defknown intern (string &optional package-designator)
202   (values symbol (member :internal :external :inherited nil))
203   ())
204 (defknown find-symbol (string &optional package-designator)
205   (values symbol (member :internal :external :inherited nil))
206   (flushable))
207 (defknown (export import) (symbols &optional package-designator) (eql t))
208 (defknown unintern (symbol &optional package-designator) boolean)
209 (defknown unexport (symbols &optional package-designator) (eql t))
210 (defknown shadowing-import (symbols &optional package-designator) (eql t))
211 (defknown shadow ((or symbol string list) &optional package-designator)
212   (eql t))
213 (defknown (use-package unuse-package)
214   ((or list package-designator) &optional package-designator) (eql t))
215 (defknown find-all-symbols (stringable) list (flushable))
216 \f
217 ;;;; from the "Numbers" chapter:
218
219 (defknown zerop (number) boolean (movable foldable flushable explicit-check))
220 (defknown (plusp minusp) (real) boolean
221   (movable foldable flushable explicit-check))
222 (defknown (oddp evenp) (integer) boolean
223   (movable foldable flushable explicit-check))
224 (defknown (= /=) (number &rest number) boolean
225   (movable foldable flushable explicit-check))
226 (defknown (< > <= >=) (real &rest real) boolean
227   (movable foldable flushable explicit-check))
228 (defknown (max min) (real &rest real) real
229   (movable foldable flushable explicit-check))
230
231 (defknown + (&rest number) number
232   (movable foldable flushable explicit-check))
233 (defknown - (number &rest number) number
234   (movable foldable flushable explicit-check))
235 (defknown * (&rest number) number
236   (movable foldable flushable explicit-check))
237 (defknown / (number &rest number) number
238   (movable foldable flushable explicit-check))
239 (defknown (1+ 1-) (number) number
240   (movable foldable flushable explicit-check))
241
242 (defknown conjugate (number) number
243   (movable foldable flushable explicit-check))
244
245 (defknown gcd (&rest integer) unsigned-byte
246   (movable foldable flushable explicit-check)
247   #|:derive-type 'boolean-result-type|#)
248 (defknown lcm (&rest integer) unsigned-byte
249   (movable foldable flushable explicit-check))
250
251 #+sb-xc-host ; (See CROSS-FLOAT-INFINITY-KLUDGE.)
252 (defknown exp (number) irrational
253   (movable foldable flushable explicit-check recursive)
254   :derive-type #'result-type-float-contagion)
255
256 #-sb-xc-host ; (See CROSS-FLOAT-INFINITY-KLUDGE.)
257 (defknown exp (number) irrational
258   (movable foldable flushable explicit-check recursive))
259
260 (defknown expt (number number) number
261   (movable foldable flushable explicit-check recursive))
262 (defknown log (number &optional real) irrational
263   (movable foldable flushable explicit-check))
264 (defknown sqrt (number) irrational
265   (movable foldable flushable explicit-check))
266 (defknown isqrt (unsigned-byte) unsigned-byte
267   (movable foldable flushable explicit-check recursive))
268
269 (defknown (abs phase signum) (number) number
270   (movable foldable flushable explicit-check))
271 (defknown cis (real) (complex float)
272   (movable foldable flushable explicit-check))
273
274 #+sb-xc-host ; (See CROSS-FLOAT-INFINITY-KLUDGE.)
275 (progn
276 (defknown (sin cos) (number)
277   (or (float -1.0 1.0) (complex float))
278   (movable foldable flushable explicit-check recursive)
279   :derive-type #'result-type-float-contagion)
280
281 (defknown atan
282   (number &optional real) irrational
283   (movable foldable flushable explicit-check recursive)
284   :derive-type #'result-type-float-contagion)
285
286 (defknown (tan sinh cosh tanh asinh)
287   (number) irrational (movable foldable flushable explicit-check recursive)
288   :derive-type #'result-type-float-contagion)
289 ) ; PROGN
290
291 #-sb-xc-host ; (See CROSS-FLOAT-INFINITY-KLUDGE.)
292 (progn
293 (defknown (sin cos) (number)
294   (or (float -1.0 1.0) (complex float))
295   (movable foldable flushable explicit-check recursive))
296
297 (defknown atan
298   (number &optional real) irrational
299   (movable foldable flushable explicit-check recursive))
300
301 (defknown (tan sinh cosh tanh asinh)
302   (number) irrational (movable foldable flushable explicit-check recursive))
303 ) ; PROGN
304
305 (defknown (asin acos acosh atanh)
306   (number) irrational
307   (movable foldable flushable explicit-check recursive))
308
309 (defknown float (real &optional float) float
310   (movable foldable flushable explicit-check))
311
312 (defknown (rational) (real) rational
313   (movable foldable flushable explicit-check))
314
315 (defknown (rationalize) (real) rational
316   (movable foldable flushable explicit-check recursive))
317
318 (defknown (numerator denominator) (rational) integer
319   (movable foldable flushable))
320
321 (defknown (floor ceiling truncate round)
322   (real &optional real) (values integer real)
323   (movable foldable flushable explicit-check))
324
325 (defknown (mod rem) (real real) real
326   (movable foldable flushable explicit-check))
327
328 (defknown (ffloor fceiling fround ftruncate)
329   (real &optional real) (values float float)
330   (movable foldable flushable explicit-check))
331
332 (defknown decode-float (float) (values float float-exponent float)
333   (movable foldable flushable explicit-check))
334 (defknown scale-float (float float-exponent) float
335   (movable foldable flushable explicit-check))
336 (defknown float-radix (float) float-radix
337   (movable foldable flushable explicit-check))
338 (defknown float-sign (float &optional float) float
339   (movable foldable flushable explicit-check))
340 (defknown (float-digits float-precision) (float) float-digits
341   (movable foldable flushable explicit-check))
342 (defknown integer-decode-float (float)
343           (values integer float-exponent (member -1 1))
344           (movable foldable flushable explicit-check))
345
346 (defknown complex (real &optional real) number
347   (movable foldable flushable explicit-check))
348
349 (defknown (realpart imagpart) (number) real (movable foldable flushable))
350
351 (defknown (logior logxor logand logeqv) (&rest integer) integer
352   (movable foldable flushable explicit-check))
353
354 (defknown (lognand lognor logandc1 logandc2 logorc1 logorc2)
355           (integer integer) integer
356   (movable foldable flushable explicit-check))
357
358 (defknown boole (boole-code integer integer) integer
359   (movable foldable flushable))
360
361 (defknown lognot (integer) integer (movable foldable flushable explicit-check))
362 (defknown logtest (integer integer) boolean (movable foldable flushable))
363 (defknown logbitp (bit-index integer) boolean (movable foldable flushable))
364 (defknown ash (integer integer) integer
365   (movable foldable flushable explicit-check))
366 (defknown (logcount integer-length) (integer) bit-index
367   (movable foldable flushable explicit-check))
368 ;;; FIXME: According to the ANSI spec, it's legal to use any
369 ;;; nonnegative indices for BYTE arguments, not just BIT-INDEX. It's
370 ;;; hard to come up with useful ways to do this, but it is possible to
371 ;;; come up with *legal* ways to do this, so it would be nice
372 ;;; to fix this so we comply with the spec.
373 (defknown byte (bit-index bit-index) byte-specifier
374   (movable foldable flushable))
375 (defknown (byte-size byte-position) (byte-specifier) bit-index
376   (movable foldable flushable))
377 (defknown ldb (byte-specifier integer) integer (movable foldable flushable))
378 (defknown ldb-test (byte-specifier integer) boolean
379   (movable foldable flushable))
380 (defknown mask-field (byte-specifier integer) integer
381   (movable foldable flushable))
382 (defknown dpb (integer byte-specifier integer) integer
383   (movable foldable flushable))
384 (defknown deposit-field (integer byte-specifier integer) integer
385   (movable foldable flushable))
386 (defknown random ((real (0)) &optional random-state) (real 0) ())
387 (defknown make-random-state (&optional (or (member nil t) random-state))
388   random-state (flushable))
389 (defknown random-state-p (t) boolean (movable foldable flushable))
390 \f
391 ;;;; from the "Characters" chapter:
392 (defknown (standard-char-p graphic-char-p alpha-char-p
393                            upper-case-p lower-case-p both-case-p alphanumericp)
394   (character) boolean (movable foldable flushable))
395
396 (defknown digit-char-p (character &optional unsigned-byte)
397   (or (integer 0 35) null) (movable foldable flushable))
398
399 (defknown (char= char/= char< char> char<= char>= char-equal char-not-equal
400                  char-lessp char-greaterp char-not-greaterp char-not-lessp)
401   (character &rest character) boolean (movable foldable flushable))
402
403 (defknown character (t) character (movable foldable flushable))
404 (defknown char-code (character) char-code (movable foldable flushable))
405 (defknown (char-upcase char-downcase) (character) character
406   (movable foldable flushable))
407 (defknown digit-char (integer &optional integer)
408   (or character null) (movable foldable flushable))
409 (defknown char-int (character) char-code (movable foldable flushable))
410 (defknown char-name (character) (or simple-string null)
411   (movable foldable flushable))
412 (defknown name-char (stringable) (or character null)
413   (movable foldable flushable))
414 (defknown code-char (char-code) base-char
415   ;; By suppressing constant folding on CODE-CHAR when the
416   ;; cross-compiler is running in the cross-compilation host vanilla
417   ;; ANSI Common Lisp, we can use CODE-CHAR expressions to delay until
418   ;; target Lisp run time the generation of CHARACTERs which aren't
419   ;; STANDARD-CHARACTERs. That way, we don't need to rely on the host
420   ;; Common Lisp being able to handle any characters other than those
421   ;; guaranteed by the ANSI spec.
422   (movable #-sb-xc-host foldable flushable))
423 \f
424 ;;;; from the "Sequences" chapter:
425
426 (defknown elt (sequence index) t (foldable flushable))
427
428 (defknown subseq (sequence index &optional sequence-end) consed-sequence
429   (flushable)
430   :derive-type (sequence-result-nth-arg 1))
431
432 (defknown copy-seq (sequence) consed-sequence (flushable)
433   :derive-type #'result-type-first-arg)
434
435 (defknown length (sequence) index (foldable flushable))
436
437 (defknown reverse (sequence) consed-sequence (flushable)
438   :derive-type #'result-type-first-arg)
439
440 (defknown nreverse (sequence) sequence ()
441   :derive-type #'result-type-first-arg)
442
443 (defknown make-sequence (type-specifier index
444                                         &key
445                                         (:initial-element t))
446   consed-sequence
447   (movable flushable unsafe)
448   :derive-type (result-type-specifier-nth-arg 1))
449
450 (defknown concatenate (type-specifier &rest sequence) consed-sequence
451   (flushable)
452   :derive-type (result-type-specifier-nth-arg 1))
453
454 (defknown (map %map) (type-specifier callable sequence &rest sequence)
455   consed-sequence
456   (flushable call)
457 ; :DERIVE-TYPE 'TYPE-SPEC-ARG1 ? Nope... (MAP NIL ...) returns NULL, not NIL.
458   )
459 (defknown %map-to-list-arity-1 (callable sequence) list (flushable call))
460 (defknown %map-to-simple-vector-arity-1 (callable sequence) simple-vector
461   (flushable call))
462 (defknown %map-to-nil-on-simple-vector (callable simple-vector) null
463   (flushable call))
464 (defknown %map-to-nil-on-vector (callable vector) null (flushable call))
465 (defknown %map-to-nil-on-sequence (callable sequence) null (flushable call))
466
467 ;;; returns the result from the predicate...
468 (defknown some (callable sequence &rest sequence) t
469   (foldable flushable call))
470
471 (defknown (every notany notevery) (callable sequence &rest sequence) boolean
472   (foldable flushable call))
473
474 ;;; unsafe for :INITIAL-VALUE...
475 (defknown reduce (callable
476                   sequence
477                   &key
478                   (:from-end t)
479                   (:start index)
480                   (:end sequence-end)
481                   (:initial-value t)
482                   (:key callable))
483   t
484   (foldable flushable call unsafe))
485
486 (defknown fill (sequence t &key (:start index) (:end sequence-end)) sequence
487   (unsafe)
488   :derive-type #'result-type-first-arg)
489
490 (defknown replace (sequence
491                    sequence
492                    &key
493                    (:start1 index)
494                    (:end1 sequence-end)
495                    (:start2 index)
496                    (:end2 sequence-end))
497   sequence ()
498   :derive-type #'result-type-first-arg)
499
500 (defknown remove
501   (t sequence &key (:from-end t) (:test callable)
502      (:test-not callable) (:start index) (:end sequence-end)
503      (:count sequence-end) (:key callable))
504   consed-sequence
505   (flushable call)
506   :derive-type (sequence-result-nth-arg 2))
507
508 (defknown substitute
509   (t t sequence &key (:from-end t) (:test callable)
510      (:test-not callable) (:start index) (:end sequence-end)
511      (:count sequence-end) (:key callable))
512   consed-sequence
513   (flushable call)
514   :derive-type (sequence-result-nth-arg 3))
515
516 (defknown (remove-if remove-if-not)
517   (callable sequence &key (:from-end t) (:start index) (:end sequence-end)
518             (:count sequence-end) (:key callable))
519   consed-sequence
520   (flushable call)
521   :derive-type (sequence-result-nth-arg 2))
522
523 (defknown (substitute-if substitute-if-not)
524   (t callable sequence &key (:from-end t) (:start index) (:end sequence-end)
525      (:count sequence-end) (:key callable))
526   consed-sequence
527   (flushable call)
528   :derive-type (sequence-result-nth-arg 3))
529
530 (defknown delete
531   (t sequence &key (:from-end t) (:test callable)
532      (:test-not callable) (:start index) (:end sequence-end)
533      (:count sequence-end) (:key callable))
534   sequence
535   (flushable call)
536   :derive-type (sequence-result-nth-arg 2))
537
538 (defknown nsubstitute
539   (t t sequence &key (:from-end t) (:test callable)
540      (:test-not callable) (:start index) (:end sequence-end)
541      (:count sequence-end) (:key callable))
542   sequence
543   (flushable call)
544   :derive-type (sequence-result-nth-arg 3))
545
546 (defknown (delete-if delete-if-not)
547   (callable sequence &key (:from-end t) (:start index) (:end sequence-end)
548             (:count sequence-end) (:key callable))
549   sequence
550   (flushable call)
551   :derive-type (sequence-result-nth-arg 2))
552
553 (defknown (nsubstitute-if nsubstitute-if-not)
554   (t callable sequence &key (:from-end t) (:start index) (:end sequence-end)
555      (:count sequence-end) (:key callable))
556   sequence
557   (flushable call)
558   :derive-type (sequence-result-nth-arg 3))
559
560 (defknown remove-duplicates
561   (sequence &key (:test callable) (:test-not callable) (:start index)
562             (:from-end t) (:end sequence-end) (:key callable))
563   consed-sequence
564   (flushable call)
565   :derive-type (sequence-result-nth-arg 1))
566
567 (defknown delete-duplicates
568   (sequence &key (:test callable) (:test-not callable) (:start index)
569             (:from-end t) (:end sequence-end) (:key callable))
570   sequence
571   (flushable call)
572   :derive-type (sequence-result-nth-arg 1))
573
574 (defknown find (t sequence &key (:test callable) (:test-not callable)
575                   (:start index) (:from-end t) (:end sequence-end)
576                   (:key callable))
577   t
578   (foldable flushable call))
579
580 (defknown (find-if find-if-not)
581   (callable sequence &key (:from-end t) (:start index) (:end sequence-end)
582             (:key callable))
583   t
584   (foldable flushable call))
585
586 (defknown position (t sequence &key (:test callable) (:test-not callable)
587                       (:start index) (:from-end t) (:end sequence-end)
588                       (:key callable))
589   (or index null)
590   (foldable flushable call))
591
592 (defknown (position-if position-if-not)
593   (callable sequence &key (:from-end t) (:start index) (:end sequence-end)
594             (:key callable))
595   (or index null)
596   (foldable flushable call))
597
598 (defknown count (t sequence &key (:test callable) (:test-not callable)
599                       (:start index) (:from-end t) (:end sequence-end)
600                       (:key callable))
601   index
602   (foldable flushable call))
603
604 (defknown (count-if count-if-not)
605   (callable sequence &key (:from-end t) (:start index) (:end sequence-end)
606             (:key callable))
607   index
608   (foldable flushable call))
609
610 (defknown (mismatch search)
611   (sequence sequence &key (:from-end t) (:test callable) (:test-not callable)
612             (:start1 index) (:end1 sequence-end)
613             (:start2 index) (:end2 sequence-end)
614             (:key callable))
615   (or index null)
616   (foldable flushable call))
617
618 ;;; not FLUSHABLE, since vector sort guaranteed in-place...
619 (defknown (stable-sort sort) (sequence callable &key (:key callable)) sequence
620   (call)
621   :derive-type (sequence-result-nth-arg 1))
622
623 (defknown merge (type-specifier sequence sequence callable
624                                 &key (:key callable))
625   sequence
626   (flushable call)
627   :derive-type (result-type-specifier-nth-arg 1))
628
629 ;;; not FLUSHABLE, despite what CMU CL's DEFKNOWN said..
630 (defknown read-sequence (sequence stream
631                                   &key
632                                   (:start index)
633                                   (:end sequence-end))
634   (index)
635   ())
636
637 (defknown write-sequence (sequence stream
638                                    &key
639                                    (:start index)
640                                    (:end sequence-end))
641   sequence
642   ()
643   :derive-type (sequence-result-nth-arg 1))
644 \f
645 ;;;; from the "Manipulating List Structure" chapter:
646 (defknown (car cdr caar cadr cdar cddr
647                caaar caadr cadar caddr cdaar cdadr cddar cdddr
648                caaaar caaadr caadar caaddr cadaar cadadr caddar cadddr
649                cdaaar cdaadr cdadar cdaddr cddaar cddadr cdddar cddddr
650                first second third fourth fifth sixth seventh eighth ninth tenth
651                rest)
652   (list)
653   t
654   (foldable flushable))
655
656 (defknown cons (t t) cons (movable flushable unsafe))
657
658 (defknown tree-equal (t t &key (:test callable) (:test-not callable)) boolean
659   (foldable flushable call))
660 (defknown endp (t) boolean (foldable flushable movable))
661 (defknown list-length (list) (or index null) (foldable flushable))
662 (defknown (nth nthcdr) (index list) t (foldable flushable))
663 (defknown last (list &optional index) list (foldable flushable))
664 (defknown list (&rest t) list (movable flushable unsafe))
665 (defknown list* (t &rest t) t (movable flushable unsafe))
666 (defknown make-list (index &key (:initial-element t)) list
667   (movable flushable unsafe))
668
669 ;;; All but last must be of type LIST, but there seems to be no way to
670 ;;; express that in this syntax..
671 (defknown append (&rest t) t (flushable))
672
673 (defknown copy-list (list) list (flushable))
674 (defknown copy-alist (list) list (flushable))
675 (defknown copy-tree (t) t (flushable recursive))
676 (defknown revappend (list t) t (flushable))
677 (defknown nconc (&rest list) list ())
678 (defknown nreconc (list t) list ())
679 (defknown butlast (list &optional index) list (flushable))
680 (defknown nbutlast (list &optional index) list ())
681 (defknown ldiff (list t) list (flushable))
682 (defknown (rplaca rplacd) (cons t) list (unsafe))
683
684 (defknown (nsubst subst) (t t t &key (:key callable) (:test callable)
685                             (:test-not callable))
686   list (flushable unsafe call))
687
688 (defknown (subst-if subst-if-not nsubst-if nsubst-if-not)
689           (t t t &key (:key callable))
690   list (flushable unsafe call))
691
692 (defknown (sublis nsublis) (list t &key (:key callable) (:test callable)
693                                  (:test-not callable))
694   list (flushable unsafe call))
695
696 (defknown member (t list &key (:key callable) (:test callable)
697                     (:test-not callable))
698   list (foldable flushable call))
699 (defknown (member-if member-if-not) (callable list &key (:key callable))
700   list (foldable flushable call))
701
702 (defknown tailp (t list) boolean (foldable flushable))
703
704 (defknown adjoin (t list &key (:key callable) (:test callable)
705                     (:test-not callable))
706   list (foldable flushable unsafe call))
707
708 (defknown (union intersection set-difference set-exclusive-or)
709   (list list &key (:key callable) (:test callable) (:test-not callable))
710   list
711   (foldable flushable call))
712
713 (defknown (nunion nintersection nset-difference nset-exclusive-or)
714   (list list &key (:key callable) (:test callable) (:test-not callable))
715   list
716   (foldable flushable call))
717
718 (defknown subsetp
719   (list list &key (:key callable) (:test callable) (:test-not callable))
720   boolean
721   (foldable flushable call))
722
723 (defknown acons (t t t) list (movable flushable unsafe))
724 (defknown pairlis (t t &optional t) list (flushable unsafe))
725
726 (defknown (rassoc assoc)
727           (t list &key (:key callable) (:test callable) (:test-not callable))
728   list (foldable flushable call))
729 (defknown (assoc-if-not assoc-if rassoc-if rassoc-if-not)
730           (callable list &key (:key callable)) list (foldable flushable call))
731
732 (defknown (memq assq) (t list) list (foldable flushable unsafe))
733 (defknown delq (t list) list (flushable unsafe))
734 \f
735 ;;;; from the "Hash Tables" chapter:
736
737 (defknown make-hash-table
738   (&key (:test callable) (:size unsigned-byte)
739         (:rehash-size (or (integer 1) (float (1.0))))
740         (:rehash-threshold (real 0 1))
741         (:weak-p t))
742   hash-table
743   (flushable unsafe))
744 (defknown hash-table-p (t) boolean (movable foldable flushable))
745 (defknown gethash (t hash-table &optional t) (values t boolean)
746   (flushable unsafe)) ; not FOLDABLE, since hash table contents can change
747 (defknown %puthash (t hash-table t) t (unsafe))
748 (defknown remhash (t hash-table) boolean ())
749 (defknown maphash (callable hash-table) null (flushable call))
750 (defknown clrhash (hash-table) hash-table ())
751 (defknown hash-table-count (hash-table) index (flushable))
752 (defknown hash-table-rehash-size (hash-table) (or (integer 1) (float (1.0)))
753   (foldable flushable))
754 (defknown hash-table-rehash-threshold (hash-table) (real 0 1)
755   (foldable flushable))
756 (defknown hash-table-size (hash-table) index (flushable))
757 (defknown hash-table-test (hash-table) symbol (foldable flushable))
758 (defknown sxhash (t) (integer 0 #.sb!xc:most-positive-fixnum)
759   (foldable flushable))
760 \f
761 ;;;; from the "Arrays" chapter
762
763 (defknown make-array ((or index list)
764                       &key
765                       (:element-type type-specifier)
766                       (:initial-element t)
767                       (:initial-contents t)
768                       (:adjustable t)
769                       (:fill-pointer t)
770                       (:displaced-to (or array null))
771                       (:displaced-index-offset index))
772   array (flushable unsafe))
773
774 (defknown vector (&rest t) simple-vector (flushable unsafe))
775
776 (defknown aref (array &rest index) t (foldable flushable))
777 (defknown row-major-aref (array index) t (foldable flushable))
778
779 (defknown array-element-type (array)
780   type-specifier
781   (foldable flushable recursive))
782 (defknown array-rank (array) array-rank (foldable flushable))
783 (defknown array-dimension (array array-rank) index (foldable flushable))
784 (defknown array-dimensions (array) list (foldable flushable))
785 (defknown array-in-bounds-p (array &rest index) boolean (foldable flushable))
786 (defknown array-row-major-index (array &rest index) array-total-size
787   (foldable flushable))
788 (defknown array-total-size (array) array-total-size (foldable flushable))
789 (defknown adjustable-array-p (array) boolean (movable foldable flushable))
790
791 (defknown svref (simple-vector index) t (foldable flushable))
792 (defknown bit ((array bit) &rest index) bit (foldable flushable))
793 (defknown sbit ((simple-array bit) &rest index) bit (foldable flushable))
794
795 (defknown (bit-and bit-ior bit-xor bit-eqv bit-nand bit-nor bit-andc1 bit-andc2
796                    bit-orc1 bit-orc2)
797   ((array bit) (array bit) &optional (or (array bit) (member t)))
798   (array bit)
799   (foldable)
800   #|:derive-type #'result-type-last-arg|#)
801
802 (defknown bit-not ((array bit) &optional (or (array bit) (member t)))
803   (array bit)
804   (foldable)
805   #|:derive-type #'result-type-last-arg|#)
806
807 (defknown array-has-fill-pointer-p (array) boolean
808   (movable foldable flushable))
809 (defknown fill-pointer (vector) index (foldable flushable))
810 (defknown vector-push (t vector) (or index null) ())
811 (defknown vector-push-extend (t vector &optional index) index ())
812 (defknown vector-pop (vector) t ())
813
814 (defknown adjust-array
815   (array (or index list) &key (:element-type type-specifier)
816          (:initial-element t) (:initial-contents list)
817          (:fill-pointer t) (:displaced-to (or array null))
818          (:displaced-index-offset index))
819   array (unsafe))
820 ;  :derive-type 'result-type-arg1) Not even close...
821 \f
822 ;;;; from the "Strings" chapter:
823
824 (defknown char (string index) character (foldable flushable))
825 (defknown schar (simple-string index) character (foldable flushable))
826
827 (sb!xc:deftype stringable () '(or character string symbol))
828
829 (defknown (string= string-equal)
830   (stringable stringable &key (:start1 index) (:end1 sequence-end)
831               (:start2 index) (:end2 sequence-end))
832   boolean
833   (foldable flushable))
834
835 (defknown (string< string> string<= string>= string/= string-lessp
836                    string-greaterp string-not-lessp string-not-greaterp
837                    string-not-equal)
838   (stringable stringable &key (:start1 index) (:end1 sequence-end)
839               (:start2 index) (:end2 sequence-end))
840   (or index null)
841   (foldable flushable))
842
843 (defknown make-string (index &key (:element-type type-specifier)
844                        (:initial-element character))
845   simple-string (flushable))
846
847 (defknown (string-trim string-left-trim string-right-trim)
848   (sequence stringable) simple-string (flushable))
849
850 (defknown (string-upcase string-downcase string-capitalize)
851   (stringable &key (:start index) (:end sequence-end))
852   simple-string (flushable))
853
854 (defknown (nstring-upcase nstring-downcase nstring-capitalize)
855   (string &key (:start index) (:end sequence-end))
856   string ())
857
858 (defknown string (stringable) string
859   (flushable explicit-check))
860 \f
861 ;;;; internal non-keyword versions of string predicates:
862
863 (defknown (string<* string>* string<=* string>=* string/=*)
864   (stringable stringable index sequence-end index sequence-end)
865   (or index null)
866   (foldable flushable))
867
868 (defknown string=*
869   (stringable stringable index sequence-end index sequence-end)
870   boolean
871   (foldable flushable))
872 \f
873 ;;;; from the "Eval" chapter:
874
875 (defknown eval (t) * (recursive))
876 (defknown constantp (t &optional lexenv) boolean
877   (foldable flushable))
878 \f
879 ;;;; from the "Streams" chapter:
880
881 (defknown make-synonym-stream (symbol) stream (flushable))
882 (defknown make-broadcast-stream (&rest stream) stream (flushable))
883 (defknown make-concatenated-stream (&rest stream) stream (flushable))
884 (defknown make-two-way-stream (stream stream) stream (flushable))
885 (defknown make-echo-stream (stream stream) stream (flushable))
886 (defknown make-string-input-stream (string &optional index index) stream
887   (flushable unsafe))
888 (defknown make-string-output-stream () stream (flushable))
889 (defknown get-output-stream-string (stream) simple-string ())
890 (defknown streamp (t) boolean (movable foldable flushable))
891 (defknown stream-element-type (stream) type-specifier
892   (movable foldable flushable))
893 (defknown (output-stream-p input-stream-p) (stream) boolean
894   (movable foldable flushable))
895 (defknown close (stream &key (:abort t)) (eql t) ())
896 \f
897 ;;;; from the "Input/Output" chapter:
898
899 ;;; (The I/O functions are given effects ANY under the theory that
900 ;;; code motion over I/O operations is particularly confusing and not
901 ;;; very important for efficiency.)
902
903 (defknown copy-readtable (&optional (or readtable null) (or readtable null))
904   readtable
905   ())
906 (defknown readtablep (t) boolean (movable foldable flushable))
907
908 (defknown set-syntax-from-char
909   (character character &optional (or readtable null) readtable) (eql t)
910   ())
911
912 (defknown set-macro-character (character callable &optional t readtable)
913   (eql t)
914   (unsafe))
915 (defknown get-macro-character (character &optional (or readtable null))
916   (values callable boolean) (flushable))
917
918 (defknown make-dispatch-macro-character (character &optional t readtable)
919   (eql t) ())
920 (defknown set-dispatch-macro-character
921   (character character callable &optional readtable) function
922   (unsafe))
923 (defknown get-dispatch-macro-character
924   (character character &optional (or readtable null)) (or callable null)
925   ())
926
927 ;;; may return any type due to eof-value...
928 (defknown (read read-preserving-whitespace read-char-no-hang read-char)
929   (&optional streamlike t t t) t (explicit-check))
930
931 (defknown read-delimited-list (character &optional streamlike t) t
932   (explicit-check))
933 (defknown read-line (&optional streamlike t t t) (values t boolean)
934   (explicit-check))
935 (defknown unread-char (character &optional streamlike) t
936   (explicit-check))
937 (defknown peek-char (&optional (or character (member nil t)) streamlike t t t)
938   t
939   (explicit-check))
940 (defknown listen (&optional streamlike) boolean (flushable explicit-check))
941
942 (defknown clear-input (&optional stream) null (explicit-check))
943
944 (defknown read-from-string
945   (string &optional t t
946           &key
947           (:start index)
948           (:end sequence-end)
949           (:preserve-whitespace t))
950   (values t index))
951 (defknown parse-integer
952   (string &key
953           (:start index)
954           (:end sequence-end)
955           (:radix (integer 2 36))
956           (:junk-allowed t))
957   (values (or integer null ()) index))
958
959 (defknown read-byte (stream &optional t t) t (explicit-check))
960
961 (defknown write
962   (t &key
963      (:stream streamlike)
964      (:escape t)
965      (:radix t)
966      (:base (integer 2 36))
967      (:circle t)
968      (:pretty t)
969      (:level (or unsigned-byte null))
970      (:readably t)
971      (:length (or unsigned-byte null))
972      (:case t)
973      (:array t)
974      (:gensym t)
975      (:lines (or unsigned-byte null))
976      (:right-margin (or unsigned-byte null))
977      (:miser-width (or unsigned-byte null))
978      (:pprint-dispatch t))
979   t
980   (any explicit-check)
981   :derive-type #'result-type-first-arg)
982
983 (defknown (prin1 print princ) (t &optional streamlike) t (any explicit-check)
984   :derive-type #'result-type-first-arg)
985
986 ;;; xxx-TO-STRING functions are not foldable because they depend on
987 ;;; the dynamic environment.
988 (defknown write-to-string
989   (t &key (:escape t) (:radix t) (:base (integer 2 36)) (:readably t)
990      (:circle t) (:pretty t) (:level (or unsigned-byte null))
991      (:length (or unsigned-byte null)) (:case t) (:array t) (:gensym t)
992      (:lines (or unsigned-byte null)) (:right-margin (or unsigned-byte null))
993      (:miser-width (or unsigned-byte null)) (:pprint-dispatch t))
994   simple-string
995   (foldable flushable explicit-check))
996
997 (defknown (prin1-to-string princ-to-string) (t) simple-string (flushable))
998
999 (defknown write-char (character &optional streamlike) character
1000   (explicit-check))
1001 (defknown (write-string write-line)
1002   (string &optional streamlike &key (:start index) (:end sequence-end))
1003   string
1004   (explicit-check))
1005
1006 (defknown (terpri finish-output force-output clear-output)
1007   (&optional streamlike) null
1008   (explicit-check))
1009
1010 (defknown fresh-line (&optional streamlike) boolean
1011   (explicit-check))
1012
1013 (defknown write-byte (integer stream) integer
1014   (explicit-check))
1015
1016 (defknown format ((or streamlike string) (or string function) &rest t)
1017   (or string null)
1018   (explicit-check))
1019
1020 (defknown (y-or-n-p yes-or-no-p) (&optional string &rest t) boolean
1021   (explicit-check))
1022 \f
1023 ;;;; from the "File System Interface" chapter:
1024
1025 ;;; (No pathname functions are FOLDABLE because they all potentially
1026 ;;; depend on *DEFAULT-PATHNAME-DEFAULTS*, e.g. to provide a default
1027 ;;; host when parsing a namestring. They are not FLUSHABLE because
1028 ;;; parsing of a PATHNAME-DESIGNATOR might signal an error.)
1029
1030 (defknown wild-pathname-p (pathname-designator
1031                            &optional
1032                            (member nil :host :device
1033                                    :directory :name
1034                                    :type :version))
1035   boolean
1036   ())
1037 (defknown pathname-match-p (pathname-designator pathname-designator) boolean
1038   ())
1039 (defknown translate-pathname (pathname-designator
1040                               pathname-designator
1041                               pathname-designator &key)
1042   pathname
1043   ())
1044
1045 (defknown logical-pathname (pathname-designator) logical-pathname ())
1046 (defknown translate-logical-pathname (pathname-designator &key) pathname ())
1047 (defknown load-logical-pathname-translations (string) t ())
1048 (defknown logical-pathname-translations (logical-host-designator) list ())
1049
1050 (defknown pathname (pathname-designator) pathname ())
1051 (defknown truename (pathname-designator) pathname ())
1052
1053 (defknown parse-namestring
1054   (pathname-designator &optional
1055                        (or list host string (member :unspecific))
1056                        pathname-designator
1057                        &key
1058                        (:start index)
1059                        (:end sequence-end)
1060                        (:junk-allowed t))
1061   (values (or pathname null) sequence-end)
1062   ())
1063
1064 (defknown merge-pathnames
1065   (pathname-designator &optional pathname-designator pathname-version)
1066   pathname
1067   ())
1068
1069 (defknown make-pathname
1070  (&key (:defaults pathname-designator)
1071        (:host (or string pathname-host))
1072        (:device (or string pathname-device))
1073        (:directory (or pathname-directory string (member :wild)))
1074        (:name (or pathname-name string (member :wild)))
1075        (:type (or pathname-type string (member :wild)))
1076        (:version pathname-version) (:case (member :local :common)))
1077   pathname ())
1078
1079 (defknown pathnamep (t) boolean (movable flushable))
1080
1081 (defknown pathname-host (pathname-designator
1082                          &key (:case (member :local :common)))
1083   pathname-host ())
1084 (defknown pathname-device (pathname-designator
1085                            &key (:case (member :local :common)))
1086   pathname-device ())
1087 (defknown pathname-directory (pathname-designator
1088                               &key (:case (member :local :common)))
1089   pathname-directory ())
1090 (defknown pathname-name (pathname-designator
1091                          &key (:case (member :local :common)))
1092   pathname-name ())
1093 (defknown pathname-type (pathname-designator
1094                          &key (:case (member :local :common)))
1095   pathname-type ())
1096 (defknown pathname-version (pathname-designator)
1097   pathname-version ())
1098
1099 (defknown (namestring file-namestring directory-namestring host-namestring)
1100   (pathname-designator) simple-string
1101   ())
1102
1103 (defknown enough-namestring (pathname-designator &optional pathname-designator)
1104   simple-string
1105   ())
1106
1107 (defknown user-homedir-pathname (&optional t) pathname (flushable))
1108
1109 (defknown open
1110   (pathname-designator &key
1111                        (:direction (member :input :output :io :probe))
1112                        (:element-type type-specifier)
1113                        (:if-exists (member :error :new-version :rename
1114                                            :rename-and-delete :overwrite
1115                                            :append :supersede nil))
1116                        (:if-does-not-exist (member :error :create nil))
1117                        (:external-format (member :default)))
1118   (or stream null))
1119
1120 (defknown rename-file (pathname-designator filename)
1121   (values pathname pathname pathname))
1122 (defknown delete-file (pathname-designator) t)
1123 (defknown probe-file (pathname-designator) (or pathname null) ())
1124 (defknown file-write-date (pathname-designator) (or unsigned-byte null)
1125   ())
1126 (defknown file-author (pathname-designator) (or simple-string null)
1127   ())
1128
1129 (defknown file-position (stream &optional
1130                                 (or unsigned-byte (member :start :end)))
1131   (or unsigned-byte (member t nil)))
1132 (defknown file-length (stream) (or unsigned-byte null) (flushable))
1133
1134 (defknown load
1135   ((or filename stream)
1136    &key
1137    (:verbose t)
1138    (:print t)
1139    (:if-does-not-exist (member :error :create nil))
1140    (:external-format (member :default)))
1141   t)
1142
1143 (defknown directory (pathname-designator &key)
1144   list ())
1145 \f
1146 ;;;; from the "Errors" chapter:
1147
1148 (defknown error (t &rest t) nil) ; never returns
1149 (defknown cerror (string t &rest t) null)
1150 (defknown warn (t &rest t) null)
1151 (defknown break (&optional t &rest t) null)
1152
1153 ;;; and analogous SBCL extension:
1154 (defknown bug (t &rest t) nil) ; never returns
1155 \f
1156 ;;;; from the "Miscellaneous" Chapter:
1157
1158 (defknown compile ((or symbol cons) &optional (or list function null))
1159   (values (or function symbol cons) boolean boolean))
1160
1161 (defknown compile-file
1162   (filename
1163    &key
1164
1165    ;; ANSI options
1166    (:output-file (or filename
1167                      null
1168                      ;; FIXME: This last case is a non-ANSI hack.
1169                      (member t)))
1170    (:verbose t)
1171    (:print t)
1172    (:external-format t)
1173
1174    ;; extensions
1175    (:trace-file t)
1176    (:block-compile t))
1177   (values (or pathname null) boolean boolean))
1178
1179 (defknown disassemble (callable &key
1180                                 (:stream stream)
1181                                 (:use-labels t))
1182   null)
1183
1184 (defknown fdocumentation (t symbol)
1185   (or string null)
1186   (flushable))
1187
1188 (defknown describe (t &optional (or stream (member t nil))) (values))
1189 (defknown inspect (t) (values))
1190 (defknown room (&optional (member t nil :default)) (values))
1191 (defknown ed (&optional (or symbol cons filename) &key (:init t) (:display t))
1192   t)
1193 (defknown dribble (&optional filename &key (:if-exists t)) (values))
1194
1195 (defknown apropos      (stringable &optional package-designator t) (values))
1196 (defknown apropos-list (stringable &optional package-designator t) list
1197   (flushable))
1198
1199 (defknown get-decoded-time ()
1200   (values (integer 0 59) (integer 0 59) (integer 0 23) (integer 1 31)
1201           (integer 1 12) unsigned-byte (integer 0 6) boolean (rational -24 24))
1202   (flushable))
1203
1204 (defknown get-universal-time () unsigned-byte (flushable))
1205
1206 (defknown decode-universal-time
1207           (unsigned-byte &optional (or null (rational -24 24)))
1208   (values (integer 0 59) (integer 0 59) (integer 0 23) (integer 1 31)
1209           (integer 1 12) unsigned-byte (integer 0 6) boolean (rational -24 24))
1210   (flushable))
1211
1212 (defknown encode-universal-time
1213   ((integer 0 59) (integer 0 59) (integer 0 23) (integer 1 31)
1214    (integer 1 12) unsigned-byte &optional (or null (rational -24 24)))
1215   unsigned-byte
1216   (flushable))
1217
1218 (defknown (get-internal-run-time get-internal-real-time)
1219   () internal-time (flushable))
1220
1221 (defknown sleep ((or (rational 0) (float 0.0))) null)
1222
1223 ;;; Even though ANSI defines LISP-IMPLEMENTATION-TYPE and
1224 ;;; LISP-IMPLEMENTATION-VERSION to possibly punt and return NIL, we
1225 ;;; know that there's no valid reason for our implementations to ever
1226 ;;; do so, so we can safely guarantee that they'll return strings.
1227 (defknown (lisp-implementation-type lisp-implementation-version)
1228   () simple-string (flushable))
1229
1230 ;;; For any of these functions, meaningful information might not be
1231 ;;; available, so -- unlike the related LISP-IMPLEMENTATION-FOO
1232 ;;; functions -- these really can return NIL.
1233 (defknown (machine-type machine-version machine-instance
1234            software-type software-version
1235            short-site-name long-site-name)
1236   () (or simple-string null) (flushable))
1237
1238 (defknown identity (t) t (movable foldable flushable unsafe)
1239   :derive-type #'result-type-first-arg)
1240
1241 (defknown constantly (t) function (movable flushable))
1242 (defknown complement (function) function (movable flushable))
1243 \f
1244 ;;;; miscellaneous extensions
1245
1246 (defknown get-bytes-consed () unsigned-byte (flushable))
1247
1248 ;;; PCOUNTERs
1249 (defknown incf-pcounter (pcounter unsigned-byte) pcounter)
1250 (defknown pcounter->integer (pcounter) unsigned-byte)
1251 (defknown %incf-pcounter-or-fixnum ((or pcounter fixnum) unsigned-byte)
1252   (or pcounter fixnum))
1253 (defknown pcounter-or-fixnum->integer ((or pcounter fixnum)) unsigned-byte)
1254 \f
1255 ;;;; magical compiler frobs
1256
1257 ;;; We can't fold this in general because of SATISFIES. There is a
1258 ;;; special optimizer anyway.
1259 (defknown %typep (t (or type-specifier ctype)) boolean
1260   (movable flushable explicit-check))
1261 (defknown %instance-typep (t (or type-specifier ctype)) boolean
1262   (movable flushable explicit-check))
1263
1264 (defknown %cleanup-point () t)
1265 (defknown %special-bind (t t) t)
1266 (defknown %special-unbind (t) t)
1267 (defknown %listify-rest-args (t index) list (flushable))
1268 (defknown %more-arg-context (t t) (values t index) (flushable))
1269 (defknown %more-arg (t index) t)
1270 (defknown %more-arg-values (t index index) * (flushable))
1271 (defknown %verify-arg-count (index index) (values))
1272 (defknown %arg-count-error (t) nil)
1273 (defknown %unknown-values () *)
1274 (defknown %catch (t t) t)
1275 (defknown %unwind-protect (t t) t)
1276 (defknown (%catch-breakup %unwind-protect-breakup) () t)
1277 (defknown %lexical-exit-breakup (t) t)
1278 (defknown %continue-unwind (t t t) nil)
1279 (defknown %throw (t &rest t) nil) ; This is MV-called.
1280 (defknown %nlx-entry (t) *)
1281 (defknown %%primitive (t t &rest t) *)
1282 (defknown %pop-values (t) t)
1283 (defknown %type-check-error (t t) nil)
1284 (defknown %odd-key-args-error () nil)
1285 (defknown %unknown-key-arg-error (t) nil)
1286 (defknown (%ldb %mask-field) (bit-index bit-index integer) unsigned-byte
1287   (movable foldable flushable explicit-check))
1288 (defknown (%dpb %deposit-field) (integer bit-index bit-index integer) integer
1289   (movable foldable flushable explicit-check))
1290 (defknown %negate (number) number (movable foldable flushable explicit-check))
1291 (defknown %check-bound (array index fixnum) index (movable foldable flushable))
1292 (defknown data-vector-ref (simple-array index) t
1293   (foldable flushable explicit-check))
1294 (defknown data-vector-set (array index t) t (unsafe explicit-check))
1295 (defknown hairy-data-vector-ref (array index) t
1296   (foldable flushable explicit-check))
1297 (defknown hairy-data-vector-set (array index t) t (unsafe explicit-check))
1298 (defknown sb!kernel:%caller-frame-and-pc () (values t t) (flushable))
1299 (defknown sb!kernel:%with-array-data (array index (or index null))
1300   (values (simple-array * (*)) index index index)
1301   (foldable flushable))
1302 (defknown %set-symbol-package (symbol t) t (unsafe))
1303 (defknown %coerce-name-to-fun ((or symbol cons)) function (flushable))
1304 (defknown %coerce-callable-to-fun (callable) function (flushable))
1305 (defknown failed-%with-array-data (t t t) nil)
1306 (defknown %find-position
1307   (t sequence t index sequence-end function function)
1308   (values t (or index null))
1309   (flushable call))
1310 (defknown (%find-position-if %find-position-if-not)
1311   (function sequence t index sequence-end function)
1312   (values t (or index null))
1313   (call))
1314
1315 (defknown sb!kernel::arg-count-error (t t t t t t) nil (unsafe))
1316 \f
1317 ;;;; SETF inverses
1318
1319 (defknown %aset (array &rest t) t (unsafe))
1320 (defknown %set-row-major-aref (array index t) t (unsafe))
1321 (defknown %rplaca (cons t) t (unsafe))
1322 (defknown %rplacd (cons t) t (unsafe))
1323 (defknown %put (symbol t t) t (unsafe))
1324 (defknown %setelt (sequence index t) t (unsafe))
1325 (defknown %svset (simple-vector index t) t (unsafe))
1326 (defknown %bitset (bit-vector &rest index) bit (unsafe))
1327 (defknown %sbitset (simple-bit-vector &rest index) bit (unsafe))
1328 (defknown %charset (string index character) character (unsafe))
1329 (defknown %scharset (simple-string index character) character (unsafe))
1330 (defknown %set-symbol-value (symbol t) t (unsafe))
1331 (defknown (setf symbol-function) (function symbol) function (unsafe))
1332 (defknown %set-symbol-plist (symbol t) t (unsafe))
1333 (defknown (setf fdocumentation) ((or string null) t symbol)
1334   (or string null)
1335   ())
1336 (defknown %setnth (index list t) t (unsafe))
1337 (defknown %set-fill-pointer (vector index) index (unsafe))
1338 \f
1339 ;;;; miscellaneous internal utilities
1340
1341 (defknown %fun-name (function) t (flushable))
1342 (defknown (setf %fun-name) (t function) t (unsafe))