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