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