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