X-Git-Url: http://nitlanguage.org diff --git a/src/rapid_type_analysis.nit b/src/rapid_type_analysis.nit index 7fcb4bc..81e14fa 100644 --- a/src/rapid_type_analysis.nit +++ b/src/rapid_type_analysis.nit @@ -36,6 +36,13 @@ redef class ModelBuilder do var analysis = new RapidTypeAnalysis(self, mainmodule) analysis.run_analysis + + if toolcontext.opt_log.value then + var basename = toolcontext.log_directory / mainmodule.name + analysis.live_methods_to_tree.write_to_file(basename + ".rta_methods.txt") + analysis.live_types_to_csv.write_to_file(basename + ".rta_types.csv") + end + return analysis end end @@ -86,9 +93,8 @@ class RapidTypeAnalysis var mtype = callsite.recv var anchor = callsite.anchor if anchor != null then mtype = mtype.anchor_to(callsite.mmodule, anchor) - mtype = mtype.as_notnullable - assert mtype isa MClassType - mtype = mtype.mclass.intro.bound_mtype + mtype = mtype.undecorate + if mtype isa MClassType then mtype = mtype.mclass.intro.bound_mtype var mproperty = callsite.mproperty var res = live_targets_cache[mtype, mproperty] if res != null then return res @@ -111,7 +117,7 @@ class RapidTypeAnalysis # Return a ready-to-save CSV document objet that agregates informations about live types. # Each discovered type is listed in a line, with its status: resolution, liveness, cast-liveness. # Note: types are listed in an alphanumeric order to improve human reading. - fun live_types_to_csv: CSVDocument + fun live_types_to_csv: CsvDocument do # Gather all kind of type var typeset = new HashSet[MType] @@ -121,7 +127,8 @@ class RapidTypeAnalysis typeset.add_all(live_open_cast_types) var types = typeset.to_a (new CachedAlphaComparator).sort(types) - var res = new CSVDocument + var res = new CsvDocument + res.format = new CsvFormat('"', ';', "\n") res.header = ["Type", "Resolution", "Liveness", "Cast-liveness"] for t in types do var reso @@ -130,7 +137,7 @@ class RapidTypeAnalysis if t isa MClassType and (live_types.has(t) or live_open_types.has(t)) then live = "LIVE" else live = "DEAD" var cast if live_cast_types.has(t) or live_open_cast_types.has(t) then cast = "CAST LIVE" else cast = "CAST DEAD" - res.add_line(t, reso, live, cast) + res.add_record(t, reso, live, cast) end return res end @@ -218,9 +225,9 @@ class RapidTypeAnalysis var node = self.modelbuilder.mpropdef2node(mmethoddef) var elttype = mmethoddef.msignature.mparameters[vararg_rank].mtype #elttype = elttype.anchor_to(self.mainmodule, v.receiver) - var vararg = self.mainmodule.get_primitive_class("Array").get_mtype([elttype]) + var vararg = self.mainmodule.array_type(elttype) v.add_type(vararg) - var native = self.mainmodule.get_primitive_class("NativeArray").get_mtype([elttype]) + var native = self.mainmodule.native_array_type(elttype) v.add_type(native) v.add_monomorphic_send(vararg, self.modelbuilder.force_get_primitive_method(node, "with_native", vararg.mclass, self.mainmodule)) end @@ -314,7 +321,7 @@ class RapidTypeAnalysis do var d = mtype.length if d > 255 then - 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}.") + 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}`.") end end @@ -343,10 +350,7 @@ class RapidTypeAnalysis var bound_mtype = mtype.anchor_to(mainmodule, recv) for cd in bound_mtype.collect_mclassdefs(mainmodule) do - if not self.modelbuilder.mclassdef2nclassdef.has_key(cd) then continue - var nclassdef = self.modelbuilder.mclassdef2nclassdef[cd] - for npropdef in nclassdef.n_propdefs do - if not npropdef isa AAttrPropdef then continue + for npropdef in modelbuilder.collect_attr_propdef(cd) do if not npropdef.has_value then continue var mpropdef = npropdef.mpropdef.as(not null) @@ -385,7 +389,6 @@ class RapidTypeAnalysis if mproperty.mpropdefs.length <= 1 then return # If all definitions of a method are live, we can remove the definition of the totry set for d in mproperty.mpropdefs do - if d.is_abstract then continue if not live_methoddefs.has(d) then return end #print "full property: {mpropdef.mproperty} for {mpropdef.mproperty.mpropdefs.length} definitions" @@ -462,17 +465,12 @@ class RapidTypeVisitor do mtype = mtype.anchor_to(self.analysis.mainmodule, self.receiver) if mtype isa MNullType then return null - mtype = mtype.as_notnullable + mtype = mtype.undecorate assert mtype isa MClassType assert not mtype.need_anchor return mtype end - fun get_class(name: String): MClass - do - return analysis.mainmodule.get_primitive_class(name) - end - fun get_method(recv: MType, name: String): MMethod do var mtype = cleanup_type(recv) @@ -537,18 +535,20 @@ redef class AArrayExpr do var mtype = self.mtype.as(MClassType) v.add_type(mtype) - var native = v.analysis.mainmodule.get_primitive_class("NativeArray").get_mtype([mtype.arguments.first]) + var native = v.analysis.mainmodule.native_array_type(mtype.arguments.first) v.add_type(native) mtype = v.cleanup_type(mtype).as(not null) var prop = v.get_method(mtype, "with_native") v.add_monomorphic_send(mtype, prop) + v.add_callsite(with_capacity_callsite) + v.add_callsite(push_callsite) end end redef class AStringFormExpr redef fun accept_rapid_type_visitor(v) do - var native = v.get_class("NativeString").mclass_type + var native = v.analysis.mainmodule.native_string_type v.add_type(native) var prop = v.get_method(native, "to_s_with_length") v.add_monomorphic_send(native, prop) @@ -558,13 +558,17 @@ end redef class ASuperstringExpr redef fun accept_rapid_type_visitor(v) do - var arraytype = v.get_class("Array").get_mtype([v.get_class("Object").mclass_type]) + var mmodule = v.analysis.mainmodule + var object_type = mmodule.object_type + var arraytype = mmodule.array_type(object_type) v.add_type(arraytype) - v.add_type(v.get_class("NativeArray").get_mtype([v.get_class("Object").mclass_type])) + var nattype = mmodule.native_array_type(object_type) + v.add_type(nattype) var prop = v.get_method(arraytype, "join") v.add_monomorphic_send(arraytype, prop) var prop2 = v.get_method(arraytype, "with_native") v.add_monomorphic_send(arraytype, prop2) + v.add_monomorphic_send(nattype, v.get_method(nattype, "native_to_s")) end end