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

Contents of /src/compiler/checkgen.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.31 - (hide annotations)
Sun Apr 13 11:57:16 2003 UTC (11 years ago) by gerd
Branch: MAIN
CVS Tags: remove_negative_zero_not_zero
Changes since 1.30: +17 -5 lines
  	The SEQUENCE-COUNT type was previously used in c:fndb, but since
	C::SEQUENCE-COUNT /= KERNEL::SEQUENCE-COUNT, it was an unknown
	type.  Please read boot4.lisp.

	* src/code/exports.lisp ("KERNEL"): Export sequence-count.

	* src-types/bootfiles/18e/boot4.lisp: New file.


	Make compute-effective-slot-definition AMOP compliant.
	Patch from Kevin Rosenberg.

	* src/pcl/std-class.lisp (compute-slots): Pass slot name
	to compute-effective-slot-definition.
	(compute-slots): Likewise.
	(compute-effective-slot-definition): Add parameter slot-name.

	* src/pcl/generic-functions.lisp (compute-effective-slot-definition):
	Add second parameter slot-name.


	Allow non-keyword keyword names in lambda lists.  This fixes test
	cases STRUCTURE-BOA-TEST-15/[1-8], and FLET.30.

	* src/compiler/node.lisp (arg-info): Accept non-keyword
	keyword names.

	* src/code/type.lisp (key-info): Likewise.


	Fix type system bugs detected by Paul Dietz' test suite
	This is to a large extent a port from SBCL.

	* src/code/type.lisp: Mostly rewritten with code ported from
	SBCL.

	* src/compiler/typetran.lisp (ir1-transform-type-predicate):
	Return nil if type is *empty-type*.
	(source-transform-negation-typep)
	(source-transform-intersection-typep): New functions.
	(source-transform-array-typep): Handle unknown array element types.
	(typep): Add handling of negation and intersection types.

	* src/compiler/srctran.lisp (make-canonical-union-type):
	Simplify, now that #'type-union is smarter.
	(ir1-transform-<-helper): Give up on non-numeric, non-member
	types.

	* src/compiler/checkgen.lisp (type-test-cost): Add a case
	for intersection-type.
	(values-types-asserted): Don't use coerce-to-values, see
	the comment there.

	* src/compiler/array-tran.lisp (array-dimension): Accept
	:maybe as array-type-complexp.

	* src/code/pred.lisp (%%typep): Add handling of
	negation-types and intersection-types.  Change cases of
	hairy-types, union-types, and arrays with unknown element type.

	* src/code/exports.lisp ("KERNEL"): Export negation-type,
	negation-type-type, intersection-type, intersection-type-types.

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

  ViewVC Help
Powered by ViewVC 1.1.5