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