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