1 ;;;; This file contains code which knows about both the type
2 ;;;; representation and the compiler IR1 representation. This stuff is
3 ;;;; used for doing type checking.
5 ;;;; This software is part of the SBCL system. See the README file for
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.
14 ;;;; FIXME: This is a poor name for this file, since CTYPE is the name
15 ;;;; of the type used internally to represent Lisp types. It'd
16 ;;;; probably be good to rename this file to "call-type.lisp" or
17 ;;;; "ir1-type.lisp" or something.
21 ;;; These are the functions that are to be called when a problem is
22 ;;; detected. They are passed format arguments. If null, we don't do
23 ;;; anything. The error function is called when something is
24 ;;; definitely incorrect. The warning function is called when it is
25 ;;; somehow impossible to tell whether the call is correct.
27 ;;; FIXME: *ERROR-FUNCTION* and *WARNING-FUNCTION* are now misnomers.
28 ;;; As per the KLUDGE note below, what the Python compiler
29 ;;; considered a "definite incompatibility" could easily be conforming
30 ;;; ANSI Common Lisp (if the incompatibility is across a compilation
31 ;;; unit boundary, and we don't keep track of whether it is..), so we
32 ;;; have to just report STYLE-WARNINGs instead of ERRORs or full
33 ;;; WARNINGs; and unlike CMU CL, we don't use the condition system
34 ;;; at all when we're reporting notes.
35 (defvar *error-function*)
36 (defvar *warning-function*)
38 ;;; The function that we use for type checking. The derived type is
39 ;;; the first argument and the type we are testing against is the
40 ;;; second argument. The function should return values like CSUBTYPEP.
41 (defvar *test-function*)
42 ;;; FIXME: Why is this a variable? Explain.
44 (declaim (type (or function null) *error-function* *warning-function
47 ;;; *LOSSAGE-DETECTED* is set when a "definite incompatibility" is
48 ;;; detected. *SLIME-DETECTED* is set when we can't tell whether the
49 ;;; call is compatible or not.
51 ;;; KLUDGE: Common Lisp is a dynamic language, even if CMU CL was not.
52 ;;; As far as I can see, none of the "definite incompatibilities"
53 ;;; detected in this file are actually definite under the ANSI spec.
54 ;;; They would be incompatibilites if the use were within the same
55 ;;; compilation unit as the contradictory definition (as per the spec
56 ;;; section "3.2.2.3 Semantic Constraints") but the old Python code
57 ;;; doesn't keep track of whether that's the case. So until/unless we
58 ;;; upgrade the code to keep track of that, we have to handle all
59 ;;; these as STYLE-WARNINGs. -- WHN 2001-02-10
60 (defvar *lossage-detected*)
61 (defvar *slime-detected*)
62 ;;; FIXME: "SLIME" is vivid and concise, but "DEFINITE-CALL-LOSSAGE" and
63 ;;; "POSSIBLE-CALL-LOSSAGE" would be more mnemonic.
65 ;;; Signal a warning if appropriate and set *LOSSAGE-DETECTED*.
66 (declaim (ftype (function (string &rest t) (values)) note-lossage note-slime))
67 (defun note-lossage (format-string &rest format-args)
68 (setq *lossage-detected* t)
69 (when *error-function*
70 (apply *error-function* format-string format-args))
72 (defun note-slime (format-string &rest format-args)
73 (setq *slime-detected* t)
74 (when *warning-function*
75 (apply *warning-function* format-string format-args))
78 (declaim (special *compiler-error-context*))
80 ;;;; stuff for checking a call against a function type
82 ;;;; FIXME: This is stuff to look at when I get around to fixing
83 ;;;; function type inference and declarations.
85 ;;; A dummy version of SUBTYPEP useful when we want a functional like
86 ;;; SUBTYPEP that always returns true.
87 (defun always-subtypep (type1 type2)
88 (declare (ignore type1 type2))
91 ;;; Determine whether a use of a function is consistent with its type.
92 ;;; These values are returned:
93 ;;; T, T: the call is definitely valid.
94 ;;; NIL, T: the call is definitely invalid.
95 ;;; NIL, NIL: unable to determine whether the call is valid.
97 ;;; The ARGUMENT-TEST function is used to determine whether an
98 ;;; argument type matches the type we are checking against. Similarly,
99 ;;; the RESULT-TEST is used to determine whether the result type
100 ;;; matches the specified result.
102 ;;; Unlike the argument test, the result test may be called on values
103 ;;; or function types. If STRICT-RESULT is true and SAFETY is
104 ;;; non-zero, then the NODE-DERIVED-TYPE is always used. Otherwise, if
105 ;;; CONT's TYPE-CHECK is true, then the NODE-DERIVED-TYPE is
106 ;;; intersected with the CONT's ASSERTED-TYPE.
108 ;;; The error and warning functions are functions that are called to
109 ;;; explain the result. We bind *COMPILER-ERROR-CONTEXT* to the
110 ;;; combination node so that COMPILER-WARNING and related functions
111 ;;; will do the right thing if they are supplied.
112 (defun valid-function-use (call type &key
113 ((:argument-test *test-function*) #'csubtypep)
114 (result-test #'values-subtypep)
116 ((:error-function *error-function*))
117 ((:warning-function *warning-function*)))
118 (declare (type function result-test) (type combination call)
119 (type function-type type))
120 (let* ((*lossage-detected* nil)
121 (*slime-detected* nil)
122 (*compiler-error-context* call)
123 (args (combination-args call))
124 (nargs (length args))
125 (required (function-type-required type))
126 (min-args (length required))
127 (optional (function-type-optional type))
128 (max-args (+ min-args (length optional)))
129 (rest (function-type-rest type))
130 (keyp (function-type-keyp type)))
133 ((function-type-wild-args type)
135 (arg args (cdr arg)))
137 (check-arg-type (car arg) *wild-type* i)))
138 ((not (or optional keyp rest))
139 (if (/= nargs min-args)
141 "The function was called with ~R argument~:P, but wants exactly ~R."
143 (check-fixed-and-rest args required nil)))
146 "The function was called with ~R argument~:P, but wants at least ~R."
149 (check-fixed-and-rest args (append required optional) rest))
150 ((not (or keyp rest))
152 "The function was called with ~R argument~:P, but wants at most ~R."
154 ((and keyp (oddp (- nargs max-args)))
156 "The function has an odd number of arguments in the keyword portion."))
158 (check-fixed-and-rest args (append required optional) rest)
160 (check-key-args args max-args type))))
162 (let* ((dtype (node-derived-type call))
163 (return-type (function-type-returns type))
164 (cont (node-cont call))
166 (if (or (not (continuation-type-check cont))
167 (and strict-result (policy call (/= safety 0))))
169 (values-type-intersection (continuation-asserted-type cont)
171 (multiple-value-bind (int win) (funcall result-test out-type return-type)
173 (note-slime "can't tell whether the result is a ~S"
174 (type-specifier return-type)))
176 (note-lossage "The result is a ~S, not a ~S."
177 (type-specifier out-type)
178 (type-specifier return-type))))))
180 (cond (*lossage-detected* (values nil t))
181 (*slime-detected* (values nil nil))
184 ;;; Check that the derived type of the continuation CONT is compatible
185 ;;; with TYPE. N is the arg number, for error message purposes. We
186 ;;; return true if arg is definitely o.k. If the type is a magic
187 ;;; CONSTANT-TYPE, then we check for the argument being a constant
188 ;;; value of the specified type. If there is a manifest type error
189 ;;; (DERIVED-TYPE = NIL), then we flame about the asserted type even
190 ;;; when our type is satisfied under the test.
191 (defun check-arg-type (cont type n)
192 (declare (type continuation cont) (type ctype type) (type index n))
194 ((not (constant-type-p type))
195 (let ((ctype (continuation-type cont)))
196 (multiple-value-bind (int win) (funcall *test-function* ctype type)
198 (note-slime "can't tell whether the ~:R argument is a ~S"
199 n (type-specifier type))
202 (note-lossage "The ~:R argument is a ~S, not a ~S."
203 n (type-specifier ctype) (type-specifier type))
205 ((eq ctype *empty-type*)
206 (note-slime "The ~:R argument never returns a value." n)
209 ((not (constant-continuation-p cont))
210 (note-slime "The ~:R argument is not a constant." n)
213 (let ((val (continuation-value cont))
214 (type (constant-type-type type)))
215 (multiple-value-bind (res win) (ctypep val type)
217 (note-slime "can't tell whether the ~:R argument is a ~
219 n (type-specifier type) val)
222 (note-lossage "The ~:R argument is not a constant ~S:~% ~S"
223 n (type-specifier type) val)
227 ;;; Check that each of the type of each supplied argument intersects
228 ;;; with the type specified for that argument. If we can't tell, then
229 ;;; we complain about the slime.
230 (declaim (ftype (function (list list (or ctype null)) (values)) check-fixed-and-rest))
231 (defun check-fixed-and-rest (args types rest)
232 (do ((arg args (cdr arg))
233 (type types (cdr type))
235 ((or (null type) (null arg))
238 (check-arg-type arg rest n)
241 (check-arg-type (car arg) (car type) n))
244 ;;; Check that the &KEY args are of the correct type. Each key should
245 ;;; be known and the corresponding argument should be of the correct
246 ;;; type. If the key isn't a constant, then we can't tell, so we note
248 (declaim (ftype (function (list fixnum function-type) (values)) check-key-args))
249 (defun check-key-args (args pre-key type)
250 (do ((key (nthcdr pre-key args) (cddr key))
251 (n (1+ pre-key) (+ n 2)))
256 ((not (check-arg-type k (specifier-type 'symbol) n)))
257 ((not (constant-continuation-p k))
258 (note-slime "The ~:R argument (in keyword position) is not a constant."
261 (let* ((name (continuation-value k))
262 (info (find name (function-type-keywords type)
263 :key #'key-info-name)))
265 (unless (function-type-allowp type)
266 (note-lossage "~S is not a known argument keyword."
269 (check-arg-type (second key) (key-info-type info)
273 ;;; Construct a function type from a definition.
275 ;;; Due to the lack of a (LIST X) type specifier, we can't reconstruct
277 (declaim (ftype (function (functional) function-type) definition-type))
278 (defun definition-type (functional)
279 (if (lambda-p functional)
281 :required (mapcar #'leaf-type (lambda-vars functional))
282 :returns (tail-set-type (lambda-tail-set functional)))
287 (dolist (arg (optional-dispatch-arglist functional))
288 (let ((info (lambda-var-arg-info arg))
289 (type (leaf-type arg)))
291 (ecase (arg-info-kind info)
292 (:required (req type))
293 (:optional (opt type))
295 (keys (make-key-info :name (arg-info-key info)
297 ((:rest :more-context)
298 (setq rest *universal-type*))
307 :keyp (optional-dispatch-keyp functional)
308 :allowp (optional-dispatch-allowp functional)
309 :returns (tail-set-type
311 (optional-dispatch-main-entry functional))))))))
313 ;;;; approximate function types
315 ;;;; FIXME: This is stuff to look at when I get around to fixing function
316 ;;;; type inference and declarations.
318 ;;;; Approximate function types provide a condensed representation of all the
319 ;;;; different ways that a function has been used. If we have no declared or
320 ;;;; defined type for a function, then we build an approximate function type by
321 ;;;; examining each use of the function. When we encounter a definition or
322 ;;;; proclamation, we can check the actual type for compatibity with the
325 (defstruct (approximate-function-type (:copier nil))
326 ;; the smallest and largest numbers of arguments that this function
327 ;; has been called with.
328 (min-args sb!xc:call-arguments-limit :type fixnum)
329 (max-args 0 :type fixnum)
330 ;; a list of lists of the all the types that have been used in each
332 (types () :type list)
333 ;; A list of APPROXIMATE-KEY-INFO structures describing all the
334 ;; things that looked like &KEY arguments. There are distinct
335 ;; structures describing each argument position in which the keyword
337 (keys () :type list))
339 (defstruct (approximate-key-info (:copier nil))
340 ;; The keyword name of this argument. Although keyword names don't
341 ;; have to be keywords, we only match on keywords when figuring an
343 (name (required-argument) :type keyword)
344 ;; The position at which this keyword appeared. 0 if it appeared as the
345 ;; first argument, etc.
346 (position (required-argument) :type fixnum)
347 ;; a list of all the argument types that have been used with this keyword
348 (types nil :type list)
349 ;; true if this keyword has appeared only in calls with an obvious
351 (allowp nil :type (member t nil)))
353 ;;; Return an APPROXIMATE-FUNCTION-TYPE representing the context of
354 ;;; CALL. If TYPE is supplied and not null, then we merge the
355 ;;; information into the information already accumulated in TYPE.
356 (declaim (ftype (function (combination
357 &optional (or approximate-function-type null))
358 approximate-function-type)
360 (defun note-function-use (call &optional type)
361 (let* ((type (or type (make-approximate-function-type)))
362 (types (approximate-function-type-types type))
363 (args (combination-args call))
364 (nargs (length args))
365 (allowp (some #'(lambda (x)
366 (and (constant-continuation-p x)
367 (eq (continuation-value x) :allow-other-keys)))
370 (setf (approximate-function-type-min-args type)
371 (min (approximate-function-type-min-args type) nargs))
372 (setf (approximate-function-type-max-args type)
373 (max (approximate-function-type-max-args type) nargs))
375 (do ((old types (cdr old))
376 (arg args (cdr arg)))
378 (setf (approximate-function-type-types type)
380 (mapcar #'(lambda (x)
381 (list (continuation-type x)))
383 (when (null arg) (return))
384 (pushnew (continuation-type (car arg))
388 (collect ((keys (approximate-function-type-keys type) cons))
389 (do ((arg args (cdr arg))
391 ((or (null arg) (null (cdr arg)))
392 (setf (approximate-function-type-keys type) (keys)))
393 (let ((key (first arg))
395 (when (constant-continuation-p key)
396 (let ((name (continuation-value key)))
397 (when (keywordp name)
400 (and (eq (approximate-key-info-name x) name)
401 (= (approximate-key-info-position x)
404 (val-type (continuation-type val)))
407 (approximate-key-info-types old)
410 (setf (approximate-key-info-allowp old) nil)))
412 (keys (make-approximate-key-info
416 :types (list val-type))))))))))))
419 ;;; This is similar to VALID-FUNCTION-USE, but checks an
420 ;;; APPROXIMATE-FUNCTION-TYPE against a real function type.
421 (declaim (ftype (function (approximate-function-type function-type
422 &optional function function function)
423 (values boolean boolean))
424 valid-approximate-type))
425 (defun valid-approximate-type (call-type type &optional
426 (*test-function* #'types-intersect)
428 #'compiler-style-warning)
429 (*warning-function* #'compiler-note))
430 (let* ((*lossage-detected* nil)
431 (*slime-detected* nil)
432 (required (function-type-required type))
433 (min-args (length required))
434 (optional (function-type-optional type))
435 (max-args (+ min-args (length optional)))
436 (rest (function-type-rest type))
437 (keyp (function-type-keyp type)))
439 (when (function-type-wild-args type)
440 (return-from valid-approximate-type (values t t)))
442 (let ((call-min (approximate-function-type-min-args call-type)))
443 (when (< call-min min-args)
445 "~:@<The function was previously called with ~R argument~:P, ~
446 but wants at least ~R.~:>"
449 (let ((call-max (approximate-function-type-max-args call-type)))
450 (cond ((<= call-max max-args))
451 ((not (or keyp rest))
453 "~:@<The function was previously called with ~R argument~:P, ~
454 but wants at most ~R.~:>"
456 ((and keyp (oddp (- call-max max-args)))
458 "~:@<The function was previously called with an odd number of ~
459 arguments in the keyword portion.~:>")))
461 (when (and keyp (> call-max max-args))
462 (check-approximate-keywords call-type max-args type)))
464 (check-approximate-fixed-and-rest call-type (append required optional)
467 (cond (*lossage-detected* (values nil t))
468 (*slime-detected* (values nil nil))
471 ;;; Check that each of the types used at each arg position is
472 ;;; compatible with the actual type.
473 (declaim (ftype (function (approximate-function-type list (or ctype null))
475 check-approximate-fixed-and-rest))
476 (defun check-approximate-fixed-and-rest (call-type fixed rest)
477 (do ((types (approximate-function-type-types call-type) (cdr types))
479 (arg fixed (cdr arg)))
481 (let ((decl-type (or (car arg) rest)))
482 (unless decl-type (return))
483 (check-approximate-arg-type (car types) decl-type "~:R" n)))
486 ;;; Check that each of the call-types is compatible with DECL-TYPE,
487 ;;; complaining if not or if we can't tell.
488 (declaim (ftype (function (list ctype string &rest t) (values))
489 check-approximate-arg-type))
490 (defun check-approximate-arg-type (call-types decl-type context &rest args)
491 (let ((losers *empty-type*))
492 (dolist (ctype call-types)
493 (multiple-value-bind (int win) (funcall *test-function* ctype decl-type)
496 (note-slime "can't tell whether previous ~? argument type ~S is a ~S"
497 context args (type-specifier ctype) (type-specifier decl-type)))
499 (setq losers (type-union ctype losers))))))
501 (unless (eq losers *empty-type*)
502 (note-lossage "~:(~?~) argument should be a ~S but was a ~S in a previous call."
503 context args (type-specifier decl-type) (type-specifier losers))))
506 ;;; Check the types of each manifest keyword that appears in a keyword
507 ;;; argument position. Check the validity of all keys that appeared in
508 ;;; valid keyword positions.
510 ;;; ### We could check the APPROXIMATE-FUNCTION-TYPE-TYPES to make
511 ;;; sure that all arguments in keyword positions were manifest
513 (defun check-approximate-keywords (call-type max-args type)
514 (let ((call-keys (approximate-function-type-keys call-type))
515 (keys (function-type-keywords type)))
517 (let ((name (key-info-name key)))
518 (collect ((types nil append))
519 (dolist (call-key call-keys)
520 (let ((pos (approximate-key-info-position call-key)))
521 (when (and (eq (approximate-key-info-name call-key) name)
522 (> pos max-args) (evenp (- pos max-args)))
523 (types (approximate-key-info-types call-key)))))
524 (check-approximate-arg-type (types) (key-info-type key) "~S" name))))
526 (unless (function-type-allowp type)
527 (collect ((names () adjoin))
528 (dolist (call-key call-keys)
529 (let ((pos (approximate-key-info-position call-key)))
530 (when (and (> pos max-args) (evenp (- pos max-args))
531 (not (approximate-key-info-allowp call-key)))
532 (names (approximate-key-info-name call-key)))))
534 (dolist (name (names))
535 (unless (find name keys :key #'key-info-name)
536 (note-lossage "Function previously called with unknown argument keyword ~S."
539 ;;;; ASSERT-DEFINITION-TYPE
541 ;;; Intersect LAMBDA's var types with TYPES, giving a warning if there
542 ;;; is a mismatch. If all intersections are non-null, we return lists
543 ;;; of the variables and intersections, otherwise we return NIL, NIL.
544 (defun try-type-intersections (vars types where)
545 (declare (list vars types) (string where))
547 (mapc (lambda (var type)
548 (let* ((vtype (leaf-type var))
549 (int (type-approx-intersection2 vtype type)))
551 ((eq int *empty-type*)
553 "Definition's declared type for variable ~A:~% ~S~@
554 conflicts with this type from ~A:~% ~S"
555 (leaf-name var) (type-specifier vtype)
556 where (type-specifier type))
557 (return-from try-type-intersections (values nil nil)))
561 (values vars (res))))
563 ;;; Check that the optional-dispatch OD conforms to Type. We return
564 ;;; the values of TRY-TYPE-INTERSECTIONS if there are no syntax
565 ;;; problems, otherwise NIL, NIL.
567 ;;; Note that the variables in the returned list are the actual
568 ;;; original variables (extracted from the optional dispatch arglist),
569 ;;; rather than the variables that are arguments to the main entry.
570 ;;; This difference is significant only for &KEY args with hairy
571 ;;; defaults. Returning the actual vars allows us to use the right
572 ;;; variable name in warnings.
574 ;;; A slightly subtle point: with keywords and optionals, the type in
575 ;;; the function type is only an assertion on calls --- it doesn't
576 ;;; constrain the type of default values. So we have to union in the
577 ;;; type of the default. With optionals, we can't do any assertion
578 ;;; unless the default is constant.
580 ;;; With keywords, we exploit our knowledge about how hairy keyword
581 ;;; defaulting is done when computing the type assertion to put on the
582 ;;; main-entry argument. In the case of hairy keywords, the default
583 ;;; has been clobbered with NIL, which is the value of the main-entry
584 ;;; arg in the unsupplied case, whatever the actual default value is.
585 ;;; So we can just assume the default is constant, effectively
586 ;;; unioning in NULL, and not totally blow off doing any type
588 (defun find-optional-dispatch-types (od type where)
589 (declare (type optional-dispatch od) (type function-type type)
591 (let* ((min (optional-dispatch-min-args od))
592 (req (function-type-required type))
593 (opt (function-type-optional type)))
594 (flet ((frob (x y what)
597 "The definition has ~R ~A arg~P, but ~A has ~R."
599 (frob min (length req) "fixed")
600 (frob (- (optional-dispatch-max-args od) min) (length opt) "optional"))
601 (flet ((frob (x y what)
604 "The definition ~:[doesn't have~;has~] ~A, but ~
605 ~A ~:[doesn't~;does~]."
607 (frob (optional-dispatch-keyp od) (function-type-keyp type)
609 (unless (optional-dispatch-keyp od)
610 (frob (not (null (optional-dispatch-more-entry od)))
611 (not (null (function-type-rest type)))
613 (frob (optional-dispatch-allowp od) (function-type-allowp type)
614 "&ALLOW-OTHER-KEYS"))
616 (when *lossage-detected*
617 (return-from find-optional-dispatch-types (values nil nil)))
621 (let ((keys (function-type-keywords type))
622 (arglist (optional-dispatch-arglist od)))
623 (dolist (arg arglist)
625 ((lambda-var-arg-info arg)
626 (let* ((info (lambda-var-arg-info arg))
627 (default (arg-info-default info))
628 (def-type (when (constantp default)
629 (ctype-of (eval default)))))
630 (ecase (arg-info-kind info)
632 (let* ((key (arg-info-key info))
633 (kinfo (find key keys :key #'key-info-name)))
636 (res (type-union (key-info-type kinfo)
637 (or def-type (specifier-type 'null)))))
640 "Defining a ~S keyword not present in ~A."
642 (res *universal-type*)))))
643 (:required (res (pop req)))
645 (res (type-union (pop opt) (or def-type *universal-type*))))
647 (when (function-type-rest type)
648 (res (specifier-type 'list))))
650 (when (function-type-rest type)
651 (res *universal-type*)))
653 (when (function-type-rest type)
654 (res (specifier-type 'fixnum)))))
656 (when (arg-info-supplied-p info)
657 (res *universal-type*)
658 (vars (arg-info-supplied-p info)))))
664 (unless (find (key-info-name key) arglist
666 (let ((info (lambda-var-arg-info x)))
668 (arg-info-key info)))))
670 "The definition lacks the ~S key present in ~A."
671 (key-info-name key) where))))
673 (try-type-intersections (vars) (res) where))))
675 ;;; Check that Type doesn't specify any funny args, and do the
677 (defun find-lambda-types (lambda type where)
678 (declare (type clambda lambda) (type function-type type) (string where))
679 (flet ((frob (x what)
682 "The definition has no ~A, but the ~A did."
684 (frob (function-type-optional type) "&OPTIONAL arguments")
685 (frob (function-type-keyp type) "&KEY arguments")
686 (frob (function-type-rest type) "&REST argument"))
687 (let* ((vars (lambda-vars lambda))
688 (nvars (length vars))
689 (req (function-type-required type))
691 (unless (= nvars nreq)
692 (note-lossage "The definition has ~R arg~:P, but the ~A has ~R."
694 (if *lossage-detected*
696 (try-type-intersections vars req where))))
698 ;;; Check for syntactic and type conformance between the definition
699 ;;; FUNCTIONAL and the specified FUNCTION-TYPE. If they are compatible
700 ;;; and REALLY-ASSERT is T, then add type assertions to the definition
701 ;;; from the FUNCTION-TYPE.
703 ;;; If there is a syntactic or type problem, then we call
704 ;;; ERROR-FUNCTION with an error message using WHERE as context
705 ;;; describing where FUNCTION-TYPE came from.
707 ;;; If there is no problem, we return T (even if REALLY-ASSERT was
708 ;;; false). If there was a problem, we return NIL.
709 (defun assert-definition-type
710 (functional type &key (really-assert t)
711 ((:error-function *error-function*)
712 #'compiler-style-warning)
714 (where "previous declaration"))
715 (declare (type functional functional)
716 (type function *error-function*)
718 (unless (function-type-p type) (return-from assert-definition-type t))
719 (let ((*lossage-detected* nil))
720 (multiple-value-bind (vars types)
721 (if (function-type-wild-args type)
723 (etypecase functional
725 (find-optional-dispatch-types functional type where))
727 (find-lambda-types functional type where))))
728 (let* ((type-returns (function-type-returns type))
729 (return (lambda-return (main-entry functional)))
731 (continuation-asserted-type (return-result return)))))
733 ((and atype (not (values-types-intersect atype type-returns)))
735 "The result type from ~A:~% ~S~@
736 conflicts with the definition's result type assertion:~% ~S"
737 where (type-specifier type-returns) (type-specifier atype))
739 (*lossage-detected* nil)
740 ((not really-assert) t)
743 (assert-continuation-type (return-result return) atype))
744 (loop for var in vars and type in types do
745 (cond ((basic-var-sets var)
746 (when (and warning-function
747 (not (csubtypep (leaf-type var) type)))
748 (funcall warning-function
749 "Assignment to argument: ~S~% ~
750 prevents use of assertion from function ~
752 (leaf-name var) where (type-specifier type))))
754 (setf (leaf-type var) type)
755 (dolist (ref (leaf-refs var))
756 (derive-node-type ref type)))))