X-Git-Url: http://nitlanguage.org diff --git a/src/rapid_type_analysis.nit b/src/rapid_type_analysis.nit index 0c08063..404ebce 100644 --- a/src/rapid_type_analysis.nit +++ b/src/rapid_type_analysis.nit @@ -14,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. - # Rapid type analysis on the AST # # Rapid type analysis is an analyse that aproximates the set of live classes @@ -24,6 +23,7 @@ module rapid_type_analysis import semantize +private import explain_assert_api import csv # for live_types_to_csv private import ordered_tree # for live_methods_to_tree @@ -62,7 +62,7 @@ class RapidTypeAnalysis # live_methods to determine new methoddefs to visit var live_types = new HashSet[MClassType] - # The pool of undesolved live types + # The pool of unresolved live types # They are globally resolved at the end of the analaysis var live_open_types = new HashSet[MClassType] @@ -245,7 +245,6 @@ class RapidTypeAnalysis v.add_monomorphic_send(vararg, self.modelbuilder.force_get_primitive_method(node, "with_native", vararg.mclass, self.mainmodule)) end - # TODO? new_msignature var sig = msignature var osig = mmeth.intro.msignature.as(not null) for i in [0..sig.arity[ do @@ -261,9 +260,15 @@ class RapidTypeAnalysis if npropdef isa AClassdef then if mmethoddef.mproperty.is_root_init then + # Final init call if not mmethoddef.is_intro then self.add_super_send(v.receiver, mmethoddef) end + else if mmethoddef.mclassdef.default_init == mmethoddef then + # default_init call + for i in mmethoddef.initializers do + if i isa MMethod then self.add_send(v.receiver, i) + end else npropdef.debug "cannot RTA {mmethoddef}" abort @@ -382,7 +387,6 @@ class RapidTypeAnalysis v.enter_visit(npropdef.n_block) end end - end fun add_cast(mtype: MType) @@ -668,6 +672,31 @@ redef class AAsCastExpr end end +redef class AAssertExpr + redef fun accept_rapid_type_visitor(v) + do + if can_explain_assert(v.analysis.modelbuilder) then + var str = explain_assert_str + if str != null then str.accept_rapid_type_visitor(v) + end + end + + # Does `modelbuilder` know the classes to build a superstring to explain a failed assert? + private fun can_explain_assert(modelbuilder: ModelBuilder): Bool + do + var nas = modelbuilder.model.get_mclasses_by_name("NativeArray") + if nas == null then return false + + nas = modelbuilder.model.get_mclasses_by_name("Array") + if nas == null or nas.is_empty then return false + + nas = modelbuilder.model.get_mclasses_by_name("String") + if nas == null or nas.is_empty then return false + + return true + end +end + redef class ASendExpr redef fun accept_rapid_type_visitor(v) do @@ -675,6 +704,13 @@ redef class ASendExpr end end +redef class ACallrefExpr + redef fun accept_rapid_type_visitor(v) + do + super + v.add_type(mtype.as(MClassType)) + end +end redef class ASendReassignFormExpr redef fun accept_rapid_type_visitor(v)