01042e4457f6c728afbd361b68fda86547c8dcec
[nit.git] / src / rapid_type_analysis.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2012 Jean Privat <jean@pryen.org>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17
18 # Rapid type analysis on the AST
19 #
20 # Rapid type analysis is an analyse that aproximates the set of live classes
21 # and the set of live methods starting from the entry point of the program.
22 # These two sets are interdependant and computed together.
23 # It is quite efficient but the type set is global and pollutes each call site.
24 module rapid_type_analysis
25
26 import semantize
27 private import explain_assert_api
28
29 import csv # for live_types_to_csv
30 private import ordered_tree # for live_methods_to_tree
31
32 private import more_collections
33
34 redef class ModelBuilder
35 # Performs a rapid-type-analysis on the program associated with `mainmodule`.
36 fun do_rapid_type_analysis(mainmodule: MModule): RapidTypeAnalysis
37 do
38 var analysis = new RapidTypeAnalysis(self, mainmodule)
39 analysis.run_analysis
40
41 if toolcontext.opt_log.value then
42 var basename = toolcontext.log_directory / mainmodule.name
43 analysis.live_methods_to_tree.write_to_file(basename + ".rta_methods.txt")
44 analysis.live_types_to_csv.write_to_file(basename + ".rta_types.csv")
45 end
46
47 return analysis
48 end
49 end
50
51 # RapidTypeAnalysis looks for alive rapid types in application.
52 # The entry point of the analysis is the mainmodule of the application.
53 class RapidTypeAnalysis
54 # The modelbuilder used to get the AST.
55 var modelbuilder: ModelBuilder
56
57 # The main module of the analysis.
58 # Used to perform types operations.
59 var mainmodule: MModule
60
61 # The pool to live types.
62 # During the analysis, new types are added and combined with
63 # live_methods to determine new methoddefs to visit
64 var live_types = new HashSet[MClassType]
65
66 # The pool of unresolved live types
67 # They are globally resolved at the end of the analaysis
68 var live_open_types = new HashSet[MClassType]
69
70 # Live (instantiated) classes.
71 var live_classes = new HashSet[MClass]
72
73 # The pool of types used to perform type checks (isa and as).
74 var live_cast_types = new HashSet[MType]
75
76 # The pool of undesolved types used to perform type checks (isa and as).
77 # They are globally resolved at the end of the analaysis
78 var live_open_cast_types = new HashSet[MType]
79
80 # Live method definitions.
81 var live_methoddefs = new HashSet[MMethodDef]
82
83 # Live methods.
84 var live_methods = new HashSet[MMethod]
85
86 # Live mmodules.
87 # Those with a live method definitions (see `live_methoddefs`)
88 var live_mmodules = new HashSet[MModule]
89
90 # Live callsites.
91 var live_callsites = new HashSet[CallSite]
92
93 private var live_targets_cache = new HashMap2[MType, MProperty, Set[MMethodDef]]
94
95 # The live targets of a specific callsite.
96 fun live_targets(callsite: CallSite): Set[MMethodDef]
97 do
98 var mtype = callsite.recv
99 var anchor = callsite.anchor
100 if anchor != null then mtype = mtype.anchor_to(callsite.mmodule, anchor)
101 mtype = mtype.undecorate
102 if mtype isa MClassType then mtype = mtype.mclass.intro.bound_mtype
103 var mproperty = callsite.mproperty
104 var res = live_targets_cache[mtype, mproperty]
105 if res != null then return res
106 res = new ArraySet[MMethodDef]
107 live_targets_cache[mtype, mproperty] = res
108
109 for c in live_classes do
110 var tc = c.intro.bound_mtype
111 if not tc.is_subtype(mainmodule, null, mtype) then continue
112 var d = mproperty.lookup_first_definition(mainmodule, tc)
113 res.add d
114 end
115
116 return res
117 end
118
119 # Live call-to-super.
120 var live_super_sends = new HashSet[MMethodDef]
121
122 # Return a ready-to-save CSV document objet that agregates informations about live types.
123 # Each discovered type is listed in a line, with its status: resolution, liveness, cast-liveness.
124 # Note: types are listed in an alphanumeric order to improve human reading.
125 fun live_types_to_csv: CsvDocument
126 do
127 # Gather all kind of type
128 var typeset = new HashSet[MType]
129 typeset.add_all(live_types)
130 typeset.add_all(live_open_types)
131 typeset.add_all(live_cast_types)
132 typeset.add_all(live_open_cast_types)
133 var types = typeset.to_a
134 (new CachedAlphaComparator).sort(types)
135 var res = new CsvDocument
136 res.separator = ';'
137 res.header = ["Type", "Resolution", "Liveness", "Cast-liveness"]
138 for t in types do
139 var reso
140 if t.need_anchor then reso = "OPEN " else reso = "CLOSED"
141 var live
142 if t isa MClassType and (live_types.has(t) or live_open_types.has(t)) then live = "LIVE" else live = "DEAD"
143 var cast
144 if live_cast_types.has(t) or live_open_cast_types.has(t) then cast = "CAST LIVE" else cast = "CAST DEAD"
145 res.add_record(t, reso, live, cast)
146 end
147 return res
148 end
149
150 # Return a ready-to-save OrderedTree object that agregates infomration about live methods.
151 # Note: methods are listed in an alphanumeric order to improve human reading.
152 fun live_methods_to_tree: OrderedTree[Object]
153 do
154 var tree = new OrderedTree[Object]
155 for x in live_methods do
156 var xn = x.full_name
157 tree.add(null, xn)
158 for z in x.mpropdefs do
159 var zn = z.to_s
160 if live_methoddefs.has(z) then
161 tree.add(xn, zn)
162 if live_super_sends.has(z) then
163 tree.add(zn, zn + "(super)")
164 end
165 else if live_super_sends.has(z) then
166 tree.add(xn, zn + "(super)")
167 end
168 end
169 end
170 tree.sort_with(alpha_comparator)
171 return tree
172 end
173
174 # Methods that are still candidate to the try_send
175 private var totry_methods = new HashSet[MMethod]
176
177 # Methods that are are no more candidate to the try_send
178 private var totry_methods_to_remove = new Array[MMethod]
179
180 # Methods that are or were candidate to the try_send
181 # Used to ensure that try_send is only used once
182 private var try_methods = new HashSet[MMethod]
183
184 # The method definitions that remain to visit
185 private var todo = new List[MMethodDef]
186
187 private fun force_alive(classname: String)
188 do
189 var classes = self.modelbuilder.model.get_mclasses_by_name(classname)
190 if classes != null then for c in classes do self.add_new(c.mclass_type, c.mclass_type)
191 end
192
193 # Run the analysis until all visitable method definitions are visited.
194 fun run_analysis
195 do
196 var maintype = mainmodule.sys_type
197 if maintype == null then return # No entry point
198 add_new(maintype, maintype)
199 var initprop = mainmodule.try_get_primitive_method("init", maintype.mclass)
200 if initprop != null then
201 add_send(maintype, initprop)
202 end
203 var mainprop = mainmodule.try_get_primitive_method("run", maintype.mclass) or else
204 mainmodule.try_get_primitive_method("main", maintype.mclass)
205 if mainprop != null then
206 add_send(maintype, mainprop)
207 end
208
209 var finalizable_type = mainmodule.finalizable_type
210 if finalizable_type != null then
211 var finalize_meth = mainmodule.try_get_primitive_method("finalize", finalizable_type.mclass)
212 if finalize_meth != null then add_send(finalizable_type, finalize_meth)
213 end
214
215 # Force primitive types
216 force_alive("Bool")
217 force_alive("Float")
218 force_alive("Char")
219 force_alive("Pointer")
220 force_alive("Byte")
221 force_alive("Int")
222 force_alive("Int8")
223 force_alive("Int16")
224 force_alive("UInt16")
225 force_alive("Int32")
226 force_alive("UInt32")
227
228 while not todo.is_empty do
229 var mmethoddef = todo.shift
230 var mmeth = mmethoddef.mproperty
231 var msignature = mmethoddef.msignature
232 if msignature == null then continue # Skip broken method
233
234 #print "# visit {mmethoddef}"
235 var v = new RapidTypeVisitor(self, mmethoddef.mclassdef.bound_mtype, mmethoddef)
236
237 var vararg_rank = msignature.vararg_rank
238 if vararg_rank > -1 then
239 var node = self.modelbuilder.mpropdef2node(mmethoddef)
240 var elttype = msignature.mparameters[vararg_rank].mtype
241 #elttype = elttype.anchor_to(self.mainmodule, v.receiver)
242 var vararg = self.mainmodule.array_type(elttype)
243 v.add_type(vararg)
244 var native = self.mainmodule.native_array_type(elttype)
245 v.add_type(native)
246 v.add_monomorphic_send(vararg, self.modelbuilder.force_get_primitive_method(node, "with_native", vararg.mclass, self.mainmodule))
247 end
248
249 # TODO? new_msignature
250 var sig = msignature
251 var osig = mmeth.intro.msignature.as(not null)
252 for i in [0..sig.arity[ do
253 var origtype = osig.mparameters[i].mtype
254 if not origtype.need_anchor then continue # skip non covariant stuff
255 var paramtype = sig.mparameters[i].mtype
256 add_cast(paramtype)
257 end
258
259 if mmethoddef.is_abstract then continue
260
261 var npropdef = modelbuilder.mpropdef2node(mmethoddef)
262
263 if npropdef isa AClassdef then
264 if mmethoddef.mproperty.is_root_init then
265 if not mmethoddef.is_intro then
266 self.add_super_send(v.receiver, mmethoddef)
267 end
268 else
269 npropdef.debug "cannot RTA {mmethoddef}"
270 abort
271 end
272 continue
273 else if mmethoddef.constant_value != null then
274 # Make the return type live
275 v.add_type(msignature.return_mtype.as(MClassType))
276 continue
277 else if npropdef == null then
278 abort
279 end
280
281 if npropdef isa AMethPropdef then
282 var auto_super_inits = npropdef.auto_super_inits
283 if auto_super_inits != null then
284 for auto_super_init in auto_super_inits do
285 v.add_callsite(auto_super_init)
286 end
287 end
288 if npropdef.auto_super_call then
289 self.add_super_send(v.receiver, mmethoddef)
290 end
291 end
292
293 if mmethoddef.is_intern or mmethoddef.is_extern then
294 # UGLY: We force the "instantation" of the concrete return type if any
295 var ret = msignature.return_mtype
296 if ret != null and ret isa MClassType and ret.mclass.kind != abstract_kind and ret.mclass.kind != interface_kind then
297 v.add_type(ret)
298 end
299 end
300
301 v.enter_visit(npropdef)
302 end
303
304 #print "MMethod {live_methods.length}: {live_methods.join(", ")}"
305 #print "MMethodDef {live_methoddefs.length}: {live_methoddefs.join(", ")}"
306
307 #print "open MType {live_open_types.length}: {live_open_types.join(", ")}"
308 var todo_types = new List[MClassType]
309 todo_types.add_all(live_types)
310 while not todo_types.is_empty do
311 var t = todo_types.shift
312 for ot in live_open_types do
313 #print "{ot}/{t} ?"
314 if not ot.can_resolve_for(t, t, mainmodule) then continue
315 var rt = ot.anchor_to(mainmodule, t)
316 if live_types.has(rt) then continue
317 if not rt.is_legal_in(mainmodule) then continue
318 if not check_depth(rt) then continue
319 #print "{ot}/{t} -> {rt}"
320 live_types.add(rt)
321 # unshift means a deep-first visit.
322 # So that the `check_depth` limit is reached sooner.
323 todo_types.unshift(rt)
324 end
325 end
326 #print "MType {live_types.length}: {live_types.join(", ")}"
327
328 #print "open cast MType {live_open_cast_types.length}: {live_open_cast_types.join(", ")}"
329 for ot in live_open_cast_types do
330 #print "live_open_cast_type: {ot}"
331 for t in live_types do
332 if not ot.can_resolve_for(t, t, mainmodule) then continue
333 var rt = ot.anchor_to(mainmodule, t)
334 if not rt.is_legal_in(mainmodule) then continue
335 live_cast_types.add(rt)
336 #print " {ot}/{t} -> {rt}"
337 end
338 end
339 #print "cast MType {live_cast_types.length}: {live_cast_types.join(", ")}"
340 end
341
342 private fun check_depth(mtype: MClassType): Bool
343 do
344 var d = mtype.length
345 if d > 255 then
346 self.modelbuilder.toolcontext.fatal_error(null, "Fatal Error: limitation in the rapidtype analysis engine: a type depth of {d} is too important, the problematic type is `{mtype}`.")
347 return false
348 end
349 return true
350 end
351
352 fun add_new(recv: MClassType, mtype: MClassType)
353 do
354 assert not recv.need_anchor
355 if mtype.need_anchor then
356 if live_open_types.has(mtype) then return
357 live_open_types.add(mtype)
358 else
359 if live_types.has(mtype) then return
360 live_types.add(mtype)
361 end
362
363 var mclass = mtype.mclass
364 if live_classes.has(mclass) then return
365 live_classes.add(mclass)
366
367 for p in totry_methods do try_send(mtype, p)
368 for p in live_super_sends do try_super_send(mtype, p)
369
370 # Remove cleared ones
371 for p in totry_methods_to_remove do totry_methods.remove(p)
372 totry_methods_to_remove.clear
373
374 var bound_mtype = mtype.anchor_to(mainmodule, recv)
375 for cd in bound_mtype.collect_mclassdefs(mainmodule)
376 do
377 for npropdef in modelbuilder.collect_attr_propdef(cd) do
378 if not npropdef.has_value then continue
379
380 var mpropdef = npropdef.mreadpropdef.as(not null)
381 var v = new RapidTypeVisitor(self, bound_mtype, mpropdef)
382 v.enter_visit(npropdef.n_expr)
383 v.enter_visit(npropdef.n_block)
384 end
385 end
386
387 end
388
389 fun add_cast(mtype: MType)
390 do
391 if mtype.need_anchor then
392 live_open_cast_types.add(mtype)
393 else
394 live_cast_types.add(mtype)
395 end
396 end
397
398 fun try_send(recv: MClassType, mproperty: MMethod)
399 do
400 recv = recv.mclass.intro.bound_mtype
401 if not recv.has_mproperty(mainmodule, mproperty) then return
402 var d = mproperty.lookup_first_definition(mainmodule, recv)
403 add_call(d)
404 end
405
406 fun add_call(mpropdef: MMethodDef)
407 do
408 if live_methoddefs.has(mpropdef) then return
409 live_methoddefs.add(mpropdef)
410 live_mmodules.add(mpropdef.mclassdef.mmodule)
411 todo.add(mpropdef)
412
413 var mproperty = mpropdef.mproperty
414 if mproperty.mpropdefs.length <= 1 then return
415 # If all definitions of a method are live, we can remove the definition of the totry set
416 for d in mproperty.mpropdefs do
417 if not live_methoddefs.has(d) then return
418 end
419 #print "full property: {mpropdef.mproperty} for {mpropdef.mproperty.mpropdefs.length} definitions"
420 totry_methods_to_remove.add(mpropdef.mproperty)
421 end
422
423 fun add_send(recv: MType, mproperty: MMethod)
424 do
425 if try_methods.has(mproperty) then return
426 #print "new prop: {mproperty}"
427 live_methods.add(mproperty)
428 try_methods.add(mproperty)
429 if mproperty.mpropdefs.length == 1 then
430 # If there is only one definition, just add the definition and do not try again the property
431 var d = mproperty.mpropdefs.first
432 add_call(d)
433 return
434 end
435 # Else, the property is potentially called with various reciever
436 # So just try the methods with existing receiver and register it for future receiver
437 totry_methods.add(mproperty)
438 for c in live_classes do
439 try_send(c.intro.bound_mtype, mproperty)
440 end
441 end
442
443 fun try_super_send(recv: MClassType, mpropdef: MMethodDef)
444 do
445 recv = recv.mclass.intro.bound_mtype
446 if not recv.collect_mclassdefs(mainmodule).has(mpropdef.mclassdef) then return
447 var d = mpropdef.lookup_next_definition(mainmodule, recv)
448 add_call(d)
449 end
450
451 fun add_super_send(recv: MType, mpropdef: MMethodDef)
452 do
453 assert mpropdef.has_supercall
454 if live_super_sends.has(mpropdef) then return
455 #print "new super prop: {mpropdef}"
456 live_super_sends.add(mpropdef)
457 for c in live_classes do
458 try_super_send(c.intro.bound_mtype, mpropdef)
459 end
460 end
461 end
462
463 class RapidTypeVisitor
464 super Visitor
465
466 var analysis: RapidTypeAnalysis
467 var receiver: MClassType
468 var mpropdef: MPropDef
469
470 init
471 do
472 assert not receiver.need_anchor
473 end
474
475 redef fun visit(n)
476 do
477 if n isa AExpr then
478 if n.mtype != null or n.is_typed then
479 n.accept_rapid_type_visitor(self)
480 var implicit_cast_to = n.implicit_cast_to
481 if implicit_cast_to != null then self.add_cast_type(implicit_cast_to)
482 end
483 else
484 n.accept_rapid_type_visitor(self)
485 end
486
487 # RTA does not enter in AAnnotations
488 if not n isa AAnnotations then
489 n.visit_all(self)
490 end
491 end
492
493 fun cleanup_type(mtype: MType): nullable MClassType
494 do
495 mtype = mtype.anchor_to(self.analysis.mainmodule, self.receiver)
496 if mtype isa MNullType then return null
497 mtype = mtype.undecorate
498 assert mtype isa MClassType
499 assert not mtype.need_anchor
500 return mtype
501 end
502
503 fun get_method(recv: MType, name: String): MMethod
504 do
505 var mtype = cleanup_type(recv)
506 assert mtype != null
507 return self.analysis.modelbuilder.force_get_primitive_method(self.current_node.as(not null), name, mtype.mclass, self.analysis.mainmodule)
508 end
509
510 fun add_type(mtype: MClassType) do analysis.add_new(receiver, mtype)
511
512 fun add_monomorphic_send(mtype: MType, mproperty: MMethod)
513 do
514 analysis.live_methods.add(mproperty)
515 analysis.try_send(mtype.as(MClassType), mproperty)
516 end
517
518 fun add_send(mtype: MType, mproperty: MMethod) do analysis.add_send(mtype, mproperty)
519
520 fun add_cast_type(mtype: MType) do analysis.add_cast(mtype)
521
522 fun add_callsite(callsite: nullable CallSite) do if callsite != null then
523 for m in callsite.mpropdef.initializers do
524 if m isa MMethod then
525 analysis.add_send(callsite.recv, m)
526 end
527 end
528 analysis.add_send(callsite.recv, callsite.mproperty)
529 analysis.live_callsites.add(callsite)
530 end
531 end
532
533 ###
534
535 redef class ANode
536 private fun accept_rapid_type_visitor(v: RapidTypeVisitor)
537 do
538 end
539 end
540
541 redef class AExpr
542 # Make the `mtype` of the expression live
543 # Used by literals and instantiations
544 fun allocate_mtype(v: RapidTypeVisitor)
545 do
546 var mtype = self.mtype
547 if not mtype isa MClassType then return
548 v.add_type(self.mtype.as(MClassType))
549 end
550 end
551
552 redef class AIntegerExpr
553 redef fun accept_rapid_type_visitor(v)
554 do
555 allocate_mtype(v)
556 end
557 end
558
559 redef class AFloatExpr
560 redef fun accept_rapid_type_visitor(v)
561 do
562 allocate_mtype(v)
563 end
564 end
565
566 redef class ACharExpr
567 redef fun accept_rapid_type_visitor(v)
568 do
569 allocate_mtype(v)
570 end
571 end
572
573 redef class AArrayExpr
574 redef fun accept_rapid_type_visitor(v)
575 do
576 var mtype = self.mtype.as(MClassType)
577 v.add_type(mtype)
578 var native = v.analysis.mainmodule.native_array_type(mtype.arguments.first)
579 v.add_type(native)
580 mtype = v.cleanup_type(mtype).as(not null)
581 var prop = v.get_method(mtype, "with_native")
582 v.add_monomorphic_send(mtype, prop)
583 v.add_callsite(with_capacity_callsite)
584 v.add_callsite(push_callsite)
585 end
586 end
587
588 redef class AStringFormExpr
589 redef fun accept_rapid_type_visitor(v)
590 do
591 var native = v.analysis.mainmodule.c_string_type
592 v.add_type(native)
593 var prop = v.get_method(native, "to_s_unsafe")
594 v.add_monomorphic_send(native, prop)
595 v.add_callsite(to_re)
596 v.add_callsite(ignore_case)
597 v.add_callsite(newline)
598 v.add_callsite(extended)
599 v.add_callsite(to_bytes_with_copy)
600 end
601 end
602
603 redef class ASuperstringExpr
604 redef fun accept_rapid_type_visitor(v)
605 do
606 var mmodule = v.analysis.mainmodule
607 var object_type = mmodule.string_type
608 var arraytype = mmodule.array_type(object_type)
609 v.add_type(arraytype)
610 var nattype = mmodule.native_array_type(object_type)
611 v.add_type(nattype)
612 var prop = v.get_method(arraytype, "join")
613 v.add_monomorphic_send(arraytype, prop)
614 var prop2 = v.get_method(arraytype, "with_native")
615 v.add_monomorphic_send(arraytype, prop2)
616 v.add_monomorphic_send(nattype, v.get_method(nattype, "native_to_s"))
617 end
618 end
619
620 redef class ACrangeExpr
621 redef fun accept_rapid_type_visitor(v)
622 do
623 var mtype = self.mtype
624 if not mtype isa MClassType then return
625 v.add_type(mtype)
626 v.add_callsite(init_callsite)
627 end
628 end
629
630 redef class AOrangeExpr
631 redef fun accept_rapid_type_visitor(v)
632 do
633 var mtype = self.mtype
634 if not mtype isa MClassType then return
635 v.add_type(mtype)
636 v.add_callsite(init_callsite)
637 end
638 end
639
640 redef class ATrueExpr
641 redef fun accept_rapid_type_visitor(v)
642 do
643 allocate_mtype(v)
644 end
645 end
646
647 redef class AFalseExpr
648 redef fun accept_rapid_type_visitor(v)
649 do
650 allocate_mtype(v)
651 end
652 end
653
654 redef class AIsaExpr
655 redef fun accept_rapid_type_visitor(v)
656 do
657 var cast_type = self.cast_type
658 if cast_type == null then return
659 v.add_cast_type(cast_type)
660 end
661 end
662
663 redef class AAsCastExpr
664 redef fun accept_rapid_type_visitor(v)
665 do
666 var mtype = self.mtype
667 if mtype == null then return
668 v.add_cast_type(mtype)
669 end
670 end
671
672 redef class AAssertExpr
673 redef fun accept_rapid_type_visitor(v)
674 do
675 if can_explain_assert(v.analysis.modelbuilder) then
676 var str = explain_assert_str
677 if str != null then str.accept_rapid_type_visitor(v)
678 end
679 end
680
681 # Does `modelbuilder` know the classes to build a superstring to explain a failed assert?
682 private fun can_explain_assert(modelbuilder: ModelBuilder): Bool
683 do
684 var nas = modelbuilder.model.get_mclasses_by_name("NativeArray")
685 if nas == null then return false
686
687 nas = modelbuilder.model.get_mclasses_by_name("Array")
688 if nas == null or nas.is_empty then return false
689
690 nas = modelbuilder.model.get_mclasses_by_name("String")
691 if nas == null or nas.is_empty then return false
692
693 return true
694 end
695 end
696
697 redef class ASendExpr
698 redef fun accept_rapid_type_visitor(v)
699 do
700 v.add_callsite(callsite)
701 end
702 end
703
704
705 redef class ASendReassignFormExpr
706 redef fun accept_rapid_type_visitor(v)
707 do
708 v.add_callsite(callsite)
709 v.add_callsite(reassign_callsite)
710 v.add_callsite(write_callsite)
711 end
712 end
713
714 redef class AVarReassignExpr
715 redef fun accept_rapid_type_visitor(v)
716 do
717 v.add_callsite(reassign_callsite)
718 end
719 end
720
721 redef class AAttrReassignExpr
722 redef fun accept_rapid_type_visitor(v)
723 do
724 v.add_callsite(reassign_callsite)
725 end
726 end
727
728 redef class ASuperExpr
729 redef fun accept_rapid_type_visitor(v)
730 do
731 var callsite = self.callsite
732 if callsite != null then
733 v.add_callsite(callsite)
734 return
735 end
736
737 v.analysis.add_super_send(v.receiver, mpropdef.as(not null))
738 end
739 end
740
741 redef class AForGroup
742 redef fun accept_rapid_type_visitor(v)
743 do
744 v.add_callsite(self.method_iterator)
745 v.add_callsite(self.method_is_ok)
746 if self.variables.length == 1 then
747 v.add_callsite(self.method_item)
748 else if self.variables.length == 2 then
749 v.add_callsite(self.method_key)
750 v.add_callsite(self.method_item)
751 else
752 abort
753 end
754 v.add_callsite(self.method_next)
755 var mf = self.method_finish
756 if mf != null then v.add_callsite(mf)
757 end
758 end
759
760 redef class ANewExpr
761 redef fun accept_rapid_type_visitor(v)
762 do
763 var mtype = self.recvtype.as(not null)
764 v.add_type(mtype)
765 v.add_callsite(callsite)
766 end
767 end