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