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