/[cmucl]/src/compiler/checkgen.lisp
ViewVC logotype

Contents of /src/compiler/checkgen.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.35 - (show annotations)
Fri Mar 19 15:19:00 2010 UTC (4 years, 1 month ago) by rtoy
Branch: MAIN
CVS Tags: post-merge-intl-branch, snapshot-2010-04
Changes since 1.34: +6 -5 lines
Merge intl-branch 2010-03-18 to HEAD.  To build, you need to use
boot-2010-02-1 as the bootstrap file.  You should probably also use
the new -P option for build.sh to generate and update the po files
while building.
1 ;;; -*- Package: C; Log: C.Log -*-
2 ;;;
3 ;;; **********************************************************************
4 ;;; This code was written as part of the CMU Common Lisp project at
5 ;;; Carnegie Mellon University, and has been placed in the public domain.
6 ;;;
7 (ext:file-comment
8 "$Header: /tiger/var/lib/cvsroots/cmucl/src/compiler/checkgen.lisp,v 1.35 2010/03/19 15:19:00 rtoy Exp $")
9 ;;;
10 ;;; **********************************************************************
11 ;;;
12 ;;; This file implements type check generation. This is a phase that runs
13 ;;; at the very end of IR1. If a type check is too complex for the back end to
14 ;;; directly emit in-line, then we transform the check into an explicit
15 ;;; conditional using TYPEP.
16 ;;;
17 ;;; Written by Rob MacLachlan
18 ;;;
19 (in-package "C")
20 (intl:textdomain "cmucl")
21
22
23 ;;;; Cost estimation:
24
25
26 ;;; Function-Cost -- Internal
27 ;;;
28 ;;; Return some sort of guess about the cost of a call to a function. If
29 ;;; the function has some templates, we return the cost of the cheapest one,
30 ;;; otherwise we return the cost of CALL-NAMED. Calling this with functions
31 ;;; that have transforms can result in relatively meaningless results
32 ;;; (exaggerated costs.)
33 ;;;
34 ;;; We randomly special-case NULL, since it does have a source tranform and is
35 ;;; interesting to us.
36 ;;;
37 (defun function-cost (name)
38 (declare (symbol name))
39 (let ((info (info function info name))
40 (call-cost (template-cost (template-or-lose 'call-named *backend*))))
41 (if info
42 (let ((templates (function-info-templates info)))
43 (if templates
44 (template-cost (first templates))
45 (case name
46 (null (template-cost (template-or-lose 'if-eq *backend*)))
47 (t call-cost))))
48 call-cost)))
49
50
51 ;;; Type-Test-Cost -- Internal
52 ;;;
53 ;;; Return some sort of guess for the cost of doing a test against TYPE.
54 ;;; The result need not be precise as long as it isn't way out in space. The
55 ;;; units are based on the costs specified for various templates in the VM
56 ;;; definition.
57 ;;;
58 (defun type-test-cost (type)
59 (declare (type ctype type))
60 (or (let ((check (type-check-template type)))
61 (if check
62 (template-cost check)
63 (let ((found (cdr (assoc type (backend-type-predicates *backend*)
64 :test #'type=))))
65 (if found
66 (+ (function-cost found) (function-cost 'eq))
67 nil))))
68 (typecase type
69 (union-type
70 (collect ((res 0 +))
71 (dolist (mem (union-type-types type))
72 (res (type-test-cost mem)))
73 (res)))
74 (intersection-type
75 (collect ((res 0 +))
76 (dolist (mem (intersection-type-types type))
77 (res (type-test-cost mem)))
78 (res)))
79 (member-type
80 (* (length (member-type-members type))
81 (function-cost 'eq)))
82 (numeric-type
83 (* (if (numeric-type-complexp type) 2 1)
84 (function-cost
85 (if (csubtypep type (specifier-type 'fixnum)) 'fixnump 'numberp))
86 (+ 1
87 (if (numeric-type-low type) 1 0)
88 (if (numeric-type-high type) 1 0))))
89 (cons-type
90 (+ (type-test-cost (specifier-type 'cons))
91 (function-cost 'car)
92 (type-test-cost (cons-type-car-type type))
93 (function-cost 'cdr)
94 (type-test-cost (cons-type-cdr-type type))))
95 (t
96 (function-cost 'typep)))))
97
98
99 ;;;; Checking strategy determination:
100
101
102 ;;; MAYBE-WEAKEN-CHECK -- Internal
103 ;;;
104 ;;; Return the type we should test for when we really want to check for
105 ;;; Type. If speed, space or compilation speed is more important than safety,
106 ;;; then we return a weaker type if it is easier to check. First we try the
107 ;;; defined type weakenings, then look for any predicate that is cheaper.
108 ;;;
109 ;;; If the supertype is equal in cost to the type, we prefer the supertype.
110 ;;; This produces a closer approximation of the right thing in the presence of
111 ;;; poor cost info.
112 ;;;
113 (defun maybe-weaken-check (type cont)
114 (declare (type ctype type) (type continuation cont))
115 (cond ((policy (continuation-dest cont)
116 (<= speed safety) (<= space safety) (<= cspeed safety))
117 type)
118 (t
119 (let ((min-cost (type-test-cost type))
120 (min-type type)
121 (found-super nil))
122 (dolist (x (backend-type-predicates *backend*))
123 (let ((stype (car x)))
124 (when (and (csubtypep type stype)
125 (not (union-type-p stype))) ;Not #!% COMMON type.
126 (let ((stype-cost (type-test-cost stype)))
127 (when (or (< stype-cost min-cost)
128 (type= stype type))
129 (setq found-super t)
130 (setq min-type stype min-cost stype-cost))))))
131 (if found-super
132 min-type
133 *universal-type*)))))
134
135
136 ;;; NO-FUNCTION-TYPES -- Internal
137 ;;;
138 ;;; Mash any complex function types to FUNCTION.
139 ;;;
140 (defun no-function-types (types)
141 (declare (type list types))
142 (mapcar #'(lambda (type)
143 (if (function-type-p type)
144 (specifier-type 'function)
145 type))
146 types))
147
148
149 ;;; Values-types-asserted -- Internal
150 ;;;
151 ;;; Like values-types, but when an argument is proven to be delivered,
152 ;;; convert asserted optional and rest arguments to required arguments. This
153 ;;; makes it clear that these required arguments may all be type checked.
154 ;;;
155 (defun values-types-asserted (atype ptype)
156 (declare (type ctype atype ptype))
157 (flet ((give-up ()
158 (return-from values-types-asserted (values nil :unknown))))
159 (cond ((eq atype *wild-type*)
160 (give-up))
161 ((not (values-type-p atype))
162 (values (list atype) 1))
163 ((or (values-type-keyp atype)
164 (values-type-allowp atype))
165 (give-up))
166 ;;
167 ;; FIXME: Values type checking is done with a form like
168 ;;
169 ;; (multiple-value-bind (x y z) <form>
170 ;; <type checks for x y z>
171 ;; (values x y z))
172 ;;
173 ;; see Make-Type-Check-Form. This has the unfortunate
174 ;; effect of chopping values when <form> actually returns
175 ;; more values than are being checked. The downside of
176 ;; including this is that it produces a lot of notes.
177 #+nil
178 ((or (eq *wild-type* ptype)
179 (and (values-type-p ptype)
180 (or (values-type-optional ptype)
181 (values-type-rest ptype))))
182 (give-up))
183 (t
184 (let* ((ptype (kernel::coerce-to-values ptype))
185 (preq (values-type-required ptype))
186 (popt (values-type-optional ptype))
187 (prest (values-type-rest ptype)))
188 ;;
189 ;; FIXME: ptype = * is not handled right, I think
190 ;; because * = (VALUES &REST T). It never was
191 ;; handled right. Gerd 2003-05-08.
192 (collect ((types))
193 (dolist (type (values-type-required atype))
194 (if (or (pop preq) (pop popt) prest)
195 (types (single-value-type type))
196 (give-up)))
197 (dolist (type (values-type-optional atype))
198 (if (pop preq)
199 (types (single-value-type type))
200 (give-up)))
201 (let ((arest (values-type-rest atype)))
202 (when arest
203 (loop with rest-type = (single-value-type arest)
204 for arg = (pop preq) while arg do
205 (types rest-type))
206 (when (or popt prest)
207 (give-up))))
208 (values (types) (length (types)))))))))
209
210
211 ;;; Switch to disable check complementing, for evaluation.
212 ;;;
213 (defvar *complement-type-checks* t)
214
215 ;;; MAYBE-NEGATE-CHECK -- Internal
216 ;;;
217 ;;; Cont is a continuation we are doing a type check on and Types is a list
218 ;;; of types that we are checking its values against. If we have proven
219 ;;; that Cont generates a fixed number of values, then for each value, we check
220 ;;; whether it is cheaper to then difference between the proven type and
221 ;;; the corresponding type in Types. If so, we opt for a :HAIRY check with
222 ;;; that test negated. Otherwise, we try to do a simple test, and if that is
223 ;;; impossible, we do a hairy test with non-negated types. If true,
224 ;;; Force-Hairy forces a hairy type check.
225 ;;;
226 ;;; When doing a non-negated check, we call MAYBE-WEAKEN-CHECK to weaken the
227 ;;; test to a convenient supertype (conditional on policy.) If debug-info is
228 ;;; not particularly important (debug <= 1) or speed is 3, then we allow
229 ;;; weakened checks to be simple, resulting in less informative error messages,
230 ;;; but saving space and possibly time.
231 ;;;
232 (defun maybe-negate-check (cont types force-hairy)
233 (declare (type continuation cont) (list types))
234 (multiple-value-bind
235 (ptypes count)
236 (values-types (continuation-proven-type cont))
237 (if (eq count :unknown)
238 (if (and (every #'type-check-template types) (not force-hairy))
239 (values :simple types)
240 (values :hairy
241 (mapcar #'(lambda (x)
242 (list nil (maybe-weaken-check x cont) x))
243 types)))
244 (let ((res (mapcar #'(lambda (p c)
245 (if (csubtypep p c)
246 (list nil *universal-type* c)
247 (let ((diff (type-difference p c))
248 (weak (maybe-weaken-check c cont)))
249 (if (and diff
250 (< (type-test-cost diff)
251 (type-test-cost weak))
252 *complement-type-checks*)
253 (list t diff c)
254 (list nil weak c)))))
255 (no-function-types ptypes) types)))
256 (cond ((or force-hairy (find-if #'first res))
257 (values :hairy res))
258 ((every #'type-check-template types)
259 (values :simple types))
260 ((policy (continuation-dest cont)
261 (or (<= debug 1) (and (= speed 3) (/= debug 3))))
262 (let ((weakened (mapcar #'second res)))
263 (if (every #'type-check-template weakened)
264 (values :simple weakened)
265 (values :hairy res))))
266 (t
267 (values :hairy res)))))))
268
269
270 ;;; CONTINUATION-CHECK-TYPES -- Interface
271 ;;;
272 ;;; Determines whether Cont's assertion is:
273 ;;; -- Checkable by the back end (:SIMPLE), or
274 ;;; -- Not checkable by the back end, but checkable via an explicit test in
275 ;;; type check conversion (:HAIRY), or
276 ;;; -- not reasonably checkable at all (:TOO-HAIRY).
277 ;;;
278 ;;; A type is checkable if it either represents a fixed number of values (as
279 ;;; determined by VALUES-TYPES), or it is the assertion for an MV-Bind. A type
280 ;;; is simply checkable if all the type assertions have a TYPE-CHECK-TEMPLATE.
281 ;;; In this :SIMPLE case, the second value is a list of the type restrictions
282 ;;; specified for the leading positional values.
283 ;;;
284 ;;; We force a check to be hairy even when there are fixed values if we are in
285 ;;; a context where we may be forced to use the unknown values convention
286 ;;; anyway. This is because IR2tran can't generate type checks for unknown
287 ;;; values continuations but people could still be depending on the check being
288 ;;; done. We only care about EXIT and RETURN (not MV-COMBINATION) since these
289 ;;; are the only contexts where the ultimate values receiver
290 ;;;
291 ;;; In the :HAIRY case, the second value is a list of triples of the form:
292 ;;; (Not-P Type Original-Type)
293 ;;;
294 ;;; If true, the Not-P flag indicates a test that the corresponding value is
295 ;;; *not* of the specified Type. Original-Type is the type asserted on this
296 ;;; value in the continuation, for use in error messages. When Not-P is true,
297 ;;; this will be different from Type.
298 ;;;
299 ;;; This allows us to take what has been proven about Cont's type into
300 ;;; consideration. If it is cheaper to test for the difference between the
301 ;;; derived type and the asserted type, then we check for the negation of this
302 ;;; type instead.
303 ;;;
304 ;;; When the proven type represents an unknown number of values, but Cont's
305 ;;; destination receives only a single value, a :hairy type check is
306 ;;; generated for the single-values-type of the asserted type.
307 ;;;
308 (defun continuation-check-types (cont &optional force-hairy)
309 (declare (type continuation cont))
310 (let ((atype (continuation-asserted-type cont))
311 (dest (continuation-dest cont))
312 (proven (continuation-proven-type cont)))
313 (assert (not (eq atype *wild-type*)))
314 (multiple-value-bind (types count)
315 (values-types-asserted atype proven)
316 (cond ((not (eq count :unknown))
317 (let ((types (no-function-types types)))
318 (if (or (exit-p dest)
319 (and (return-p dest)
320 (multiple-value-bind
321 (ignore count)
322 (values-types (return-result-type dest))
323 (declare (ignore ignore))
324 (eq count :unknown))))
325 (maybe-negate-check cont types t)
326 (maybe-negate-check cont types force-hairy))))
327 #+nil
328 ((eq *wild-type* proven)
329 (values :too-hairy nil))
330 ((and (mv-combination-p dest)
331 (eq (basic-combination-kind dest) :local))
332 (assert (values-type-p atype))
333 (maybe-negate-check cont (append (args-type-required atype)
334 (args-type-optional atype))
335 force-hairy))
336 ((or (exit-p dest) (return-p dest) (mv-combination-p dest))
337 (values :too-hairy nil))
338 (t
339 (maybe-negate-check cont (list (single-value-type atype)) t))))))
340
341
342 ;;; Probable-Type-Check-P -- Internal
343 ;;;
344 ;;; Return true if Cont is a continuation whose type the back end is likely
345 ;;; to want to check. Since we don't know what template the back end is going
346 ;;; to choose to implement the continuation's DEST, we use a heuristic. We
347 ;;; always return T unless:
348 ;;; -- Nobody uses the value, or
349 ;;; -- Safety is totally unimportant, or
350 ;;; -- the continuation is an argument to an unknown function, or
351 ;;; -- the continuation is an argument to a known function that has no
352 ;;; IR2-Convert method or :fast-safe templates that are compatible with the
353 ;;; call's type.
354 ;;;
355 ;;; We must only return nil when it is *certain* that a check will not be done,
356 ;;; since if we pass up this chance to do the check, it will be too late. The
357 ;;; penalty for being too conservative is duplicated type checks.
358 ;;;
359 ;;; If there is a compile-time type error, then we always return true unless
360 ;;; the DEST is a full call. With a full call, the theory is that the type
361 ;;; error is probably from a declaration in (or on) the callee, so the callee
362 ;;; should be able to do the check. We want to let the callee do the check,
363 ;;; because it is possible that the error is really in the callee, not the
364 ;;; caller. We don't want to make people recompile all calls to a function
365 ;;; when they were originally compiled with a bad declaration (or an old type
366 ;;; assertion derived from a definition appearing after the call.)
367 ;;;
368 (defun probable-type-check-p (cont)
369 (declare (type continuation cont))
370 (let ((dest (continuation-dest cont)))
371 (cond ((eq (continuation-type-check cont) :error)
372 (if (and (combination-p dest) (eq (combination-kind dest) :error))
373 (policy dest (= safety 3))
374 t))
375 ((or (not dest)
376 (policy dest (zerop safety)))
377 nil)
378 ((basic-combination-p dest)
379 (let ((kind (basic-combination-kind dest)))
380 (cond ((eq cont (basic-combination-fun dest)) t)
381 ((eq kind :local) t)
382 ((member kind '(:full :error)) nil)
383 ((function-info-ir2-convert kind) t)
384 (t
385 (dolist (template (function-info-templates kind) nil)
386 (when (eq (template-policy template) :fast-safe)
387 (multiple-value-bind
388 (val win)
389 (valid-function-use dest (template-type template))
390 (when (or val (not win)) (return t)))))))))
391 (t t))))
392
393
394 ;;; Make-Type-Check-Form -- Internal
395 ;;;
396 ;;; Return a form that we can convert to do a hairy type check of the
397 ;;; specified Types. Types is a list of the format returned by
398 ;;; Continuation-Check-Types in the :HAIRY case. In place of the actual
399 ;;; value(s) we are to check, we use 'Dummy. This constant reference is later
400 ;;; replaced with the actual values continuation.
401 ;;;
402 ;;; Note that we don't attempt to check for required values being unsupplied.
403 ;;; Such checking is impossible to efficiently do at the source level because
404 ;;; our fixed-values conventions are optimized for the common MV-Bind case.
405 ;;;
406 ;;; We can always use Multiple-Value-Bind, since the macro is clever about
407 ;;; binding a single variable.
408 ;;;
409 (defun make-type-check-form (types)
410 (collect ((temps))
411 (dotimes (i (length types))
412 (temps (gensym)))
413
414 `(multiple-value-bind ,(temps)
415 'dummy
416 ,@(mapcar #'(lambda (temp type)
417 (let* ((spec
418 (let ((*unparse-function-type-simplify* t))
419 (type-specifier (second type))))
420 (test (if (first type) `(not ,spec) spec)))
421 `(unless (typep ,temp ',test)
422 (%type-check-error
423 ,temp
424 ',(type-specifier (third type))))))
425 (temps) types)
426 (values ,@(temps)))))
427
428
429 ;;; Convert-Type-Check -- Internal
430 ;;;
431 ;;; Splice in explicit type check code immediately before the node that its
432 ;;; Cont's Dest. This code receives the value(s) that were being passed to
433 ;;; Cont, checks the type(s) of the value(s), then passes them on to Cont.
434 ;;; We:
435 ;;; -- Ensure that Cont starts a block, so that we can freely manipulate its
436 ;;; uses.
437 ;;; -- Make a new continuation and move Cont's uses to it. Set type set
438 ;;; Type-Check in Cont to :DELETED to indicate that the check has been
439 ;;; done.
440 ;;; -- Make the Dest node start its block so that we can splice in the type
441 ;;; check code.
442 ;;; -- Splice in a new block before the Dest block, giving it all the Dest's
443 ;;; predecessors.
444 ;;; -- Convert the check form, using the new block start as Start and a dummy
445 ;;; continuation as Cont.
446 ;;; -- Set the new block's start and end cleanups to the *start* cleanup of
447 ;;; Prev's block. This overrides the incorrect default from
448 ;;; With-IR1-Environment.
449 ;;; -- Finish off the dummy continuation's block, and change the use to a use
450 ;;; of Cont. (we need to use the dummy continuation to get the control
451 ;;; transfer right, since we want to go to Prev's block, not Cont's.)
452 ;;; Link the new block to Prev's block.
453 ;;; -- Substitute the new continuation for the dummy placeholder argument.
454 ;;; Since no let conversion has been done yet, we can find the placeholder.
455 ;;; The [mv-]combination node from the mv-bind in the check form will be
456 ;;; the Use of the new check continuation. We substitute for the first
457 ;;; argument of this node.
458 ;;; -- Invoke local call analysis to convert the call to a let.
459 ;;;
460 (defun convert-type-check (cont types)
461 (declare (type continuation cont) (list types))
462 (with-ir1-environment (continuation-dest cont)
463 (ensure-block-start cont)
464 (let* ((new-start (make-continuation))
465 (dest (continuation-dest cont))
466 (prev (node-prev dest)))
467 (continuation-starts-block new-start)
468 (substitute-continuation-uses new-start cont)
469 (setf (continuation-%type-check cont) :deleted)
470
471 (when (continuation-use prev)
472 (node-ends-block (continuation-use prev)))
473
474 (let* ((prev-block (continuation-block prev))
475 (new-block (continuation-block new-start))
476 (dummy (make-continuation)))
477 (dolist (block (block-pred prev-block))
478 (change-block-successor block prev-block new-block))
479 (ir1-convert new-start dummy (make-type-check-form types))
480 (assert (eq (continuation-block dummy) new-block))
481
482 (let ((node (continuation-use dummy)))
483 (setf (block-last new-block) node)
484 (delete-continuation-use node)
485 (add-continuation-use node cont))
486 (link-blocks new-block prev-block))
487
488 (let* ((node (continuation-use cont))
489 (args (basic-combination-args node))
490 (victim (first args)))
491 (assert (and (= (length args) 1)
492 (eq (constant-value
493 (ref-leaf
494 (continuation-use victim)))
495 'dummy)))
496 (substitute-continuation new-start victim)))
497
498 (local-call-analyze *current-component*))
499
500 (undefined-value))
501
502
503 ;;; DO-TYPE-WARNING -- Internal
504 ;;;
505 ;;; Emit a type warning for Node. If the value of node is being used for a
506 ;;; variable binding, we figure out which one for source context. If the value
507 ;;; is a constant, we print it specially. We ignore nodes whose type is NIL,
508 ;;; since they are supposed to never return.
509 ;;;
510 (defun do-type-warning (node)
511 (declare (type node node))
512 (let* ((*compiler-error-context* node)
513 (cont (node-cont node))
514 (atype-spec (type-specifier (continuation-asserted-type cont)))
515 (dtype (node-derived-type node))
516 (dest (continuation-dest cont))
517 (what (when (and (combination-p dest)
518 (eq (combination-kind dest) :local))
519 (let ((lambda (combination-lambda dest))
520 (pos (eposition cont (combination-args dest))))
521 (format nil _"~:[A possible~;The~] binding of ~S"
522 (and (continuation-use cont)
523 (eq (functional-kind lambda) :let))
524 (leaf-name (elt (lambda-vars lambda) pos)))))))
525 (cond ((eq dtype *empty-type*))
526 ((and (ref-p node) (constant-p (ref-leaf node)))
527 (compiler-warning _N"~:[This~;~:*~A~] is not a ~<~%~9T~:;~S:~>~% ~S"
528 what atype-spec (constant-value (ref-leaf node))))
529 (t
530 (compiler-warning
531 _N"~:[Result~;~:*~A~] is a ~S, ~<~%~9T~:;not a ~S.~>"
532 what (type-specifier dtype) atype-spec))))
533 (undefined-value))
534
535
536 ;;; MARK-ERROR-CONTINUATION -- Internal
537 ;;;
538 ;;; Mark Cont as being a continuation with a manifest type error. We set
539 ;;; the kind to :ERROR, and clear any FUNCTION-INFO if the continuation is an
540 ;;; argument to a known call. The last is done so that the back end doesn't
541 ;;; have to worry about type errors in arguments to known functions. This
542 ;;; clearing is inhibited for things with IR2-CONVERT methods, since we can't
543 ;;; do a full call to funny functions.
544 ;;;
545 (defun mark-error-continuation (cont)
546 (declare (type continuation cont))
547 (setf (continuation-%type-check cont) :error)
548 (let ((dest (continuation-dest cont)))
549 (when (and (combination-p dest)
550 (let ((kind (basic-combination-kind dest)))
551 (or (eq kind :full)
552 (and (function-info-p kind)
553 (not (function-info-ir2-convert kind))))))
554 (setf (basic-combination-kind dest) :error)))
555 (undefined-value))
556
557
558 ;;; Generate-Type-Checks -- Interface
559 ;;;
560 ;;; Loop over all blocks in Component that have TYPE-CHECK set, looking for
561 ;;; continuations with TYPE-CHECK T. We do two mostly unrelated things: detect
562 ;;; compile-time type errors and determine if and how to do run-time type
563 ;;; checks.
564 ;;;
565 ;;; If there is a compile-time type error, then we mark the continuation and
566 ;;; emit a warning if appropriate. This part loops over all the uses of the
567 ;;; continuation, since after we convert the check, the :DELETED kind will
568 ;;; inhibit warnings about the types of other uses.
569 ;;;
570 ;;; If a continuation is too complex to be checked by the back end, or is
571 ;;; better checked with explicit code, then convert to an explicit test.
572 ;;; Assertions that can checked by the back end are passed through. Assertions
573 ;;; that can't be tested are flamed about and marked as not needing to be
574 ;;; checked.
575 ;;;
576 ;;; If we determine that a type check won't be done, then we set TYPE-CHECK
577 ;;; to :NO-CHECK. In the non-hairy cases, this is just to prevent us from
578 ;;; wasting time coming to the same conclusion again on a later iteration. In
579 ;;; the hairy case, we must indicate to LTN that it must choose a safe
580 ;;; implementation, since IR2 conversion will choke on the check.
581 ;;;
582 ;;; The generation of the type checks is delayed until all the type
583 ;;; check decisions have been made because the generation of the type
584 ;;; checks creates new nodes who's derived types aren't always updated
585 ;;; which may lead to inappropriate template choices due to the
586 ;;; modification of argument types.
587 ;;;
588 (defun generate-type-checks (component)
589 (collect ((conts))
590 (do-blocks (block component)
591 (when (block-type-check block)
592 (do-nodes (node cont block)
593 (let ((type-check (continuation-type-check cont)))
594 (unless (member type-check '(nil :error :deleted))
595 (let ((atype (continuation-asserted-type cont)))
596 (do-uses (use cont)
597 (unless (values-types-intersect (node-derived-type use)
598 atype)
599 (mark-error-continuation cont)
600 (unless (policy node (= brevity 3))
601 (do-type-warning use))))))
602 (when (and (eq type-check t)
603 (not *byte-compiling*))
604 (if (probable-type-check-p cont)
605 (conts cont)
606 (setf (continuation-%type-check cont) :no-check)))))
607
608 (setf (block-type-check block) nil)))
609
610 (dolist (cont (conts))
611 (multiple-value-bind (check types)
612 (continuation-check-types
613 cont
614 (and (eq (continuation-%type-check cont) :error)
615 (policy (continuation-dest cont) (= safety 3))))
616 (ecase check
617 (:simple)
618 (:hairy
619 (convert-type-check cont types))
620 (:too-hairy
621 (let* ((context (continuation-dest cont))
622 (*compiler-error-context* context))
623 (when (policy context (>= safety brevity))
624 (compiler-note
625 _N"Type assertion too complex to check:~% ~S."
626 (type-specifier (continuation-asserted-type cont)))))
627 (setf (continuation-%type-check cont) :deleted))))))
628
629 (undefined-value))

  ViewVC Help
Powered by ViewVC 1.1.5