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