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