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