# It is quite efficient but the type set is global and pollutes each call site.
module rapid_type_analysis
-import model
-import modelbuilder
-import typing
-import auto_super_init
+import semantize
-import csv # for live_types_to_csv
-import ordered_tree # for live_methods_to_tree
+private import csv # for live_types_to_csv
+private import ordered_tree # for live_methods_to_tree
private import more_collections
redef class ModelBuilder
+ # Performs a rapid-type-analysis on the program associated with `mainmodule`.
fun do_rapid_type_analysis(mainmodule: MModule): RapidTypeAnalysis
do
var analysis = new RapidTypeAnalysis(self, mainmodule)
force_alive("Int")
force_alive("Float")
force_alive("Char")
+ force_alive("Pointer")
while not todo.is_empty do
var mmethoddef = todo.shift
v.add_monomorphic_send(vararg, self.modelbuilder.force_get_primitive_method(node, "with_native", vararg.mclass, self.mainmodule))
end
+ # TODO? new_msignature
var sig = mmethoddef.msignature.as(not null)
var osig = mmeth.intro.msignature.as(not null)
for i in [0..sig.arity[ do
if not modelbuilder.mpropdef2npropdef.has_key(mmethoddef) then
# It is an init for a class?
- if mmeth.name == "init" then
+ if mmeth.is_root_init then
var nclassdef = self.modelbuilder.mclassdef2nclassdef[mmethoddef.mclassdef]
assert mmethoddef == nclassdef.mfree_init
- var super_inits = nclassdef.super_inits
- if super_inits != null then
- #assert args.length == 1
- for su in super_inits do
- v.add_monomorphic_send(v.receiver, su)
- end
- end
+ if mmethoddef.mproperty.is_root_init and not mmethoddef.is_intro then
+ self.add_super_send(v.receiver, mmethoddef)
+ end
+ else if mmethoddef.constant_value != null then
+ # Make the return type live
+ v.add_type(mmethoddef.msignature.return_mtype.as(MClassType))
else
abort
end
v.add_callsite(auto_super_init)
end
end
+ if npropdef.auto_super_call then
+ self.add_super_send(v.receiver, mmethoddef)
+ end
end
- if mmeth.is_new then
- v.add_type(v.receiver)
- else if mmethoddef.is_intern or mmethoddef.is_extern then
+ if mmethoddef.is_intern or mmethoddef.is_extern then
# UGLY: We force the "instantation" of the concrete return type if any
var ret = mmethoddef.msignature.return_mtype
if ret != null and ret isa MClassType and ret.mclass.kind != abstract_kind and ret.mclass.kind != interface_kind then
var nclassdef = self.modelbuilder.mclassdef2nclassdef[cd]
for npropdef in nclassdef.n_propdefs do
if not npropdef isa AAttrPropdef then continue
- var nexpr = npropdef.n_expr
- if nexpr == null then continue
+ if not npropdef.has_value then continue
+
var mpropdef = npropdef.mpropdef.as(not null)
var v = new RapidTypeVisitor(self, bound_mtype, mpropdef)
- v.enter_visit(nexpr)
+ v.enter_visit(npropdef.n_expr)
+ v.enter_visit(npropdef.n_block)
end
end
var receiver: MClassType
var mpropdef: MPropDef
- init(analysis: RapidTypeAnalysis, receiver: MClassType, mpropdef: MPropDef)
+ init
do
- self.analysis = analysis
- self.receiver = receiver
- self.mpropdef = mpropdef
assert not receiver.need_anchor
end
fun add_cast_type(mtype: MType) do analysis.add_cast(mtype)
fun add_callsite(callsite: nullable CallSite) do if callsite != null then
+ for m in callsite.mpropdef.initializers do
+ if m isa MMethod then
+ analysis.add_send(callsite.recv, m)
+ end
+ end
analysis.add_send(callsite.recv, callsite.mproperty)
analysis.live_callsites.add(callsite)
end
abort
end
v.add_callsite(self.method_next)
+ var mf = self.method_finish
+ if mf != null then v.add_callsite(mf)
end
end
redef class ANewExpr
redef fun accept_rapid_type_visitor(v)
do
- var mtype = self.mtype.as(MClassType)
+ var mtype = self.recvtype.as(not null)
v.add_type(mtype)
v.add_callsite(callsite)
end