From: Jean Privat Date: Tue, 9 Aug 2016 00:44:00 +0000 (-0400) Subject: rta: fast fix to avoid resolving illegal types. X-Git-Url: http://nitlanguage.org rta: fast fix to avoid resolving illegal types. This requires a more in-depth work to improve the model. Another improvement can also to teach RTA the context of object mechanism so that only legal receivers are attempted. Signed-off-by: Jean Privat --- diff --git a/src/rapid_type_analysis.nit b/src/rapid_type_analysis.nit index 88e2b7e..c5ddc4a 100644 --- a/src/rapid_type_analysis.nit +++ b/src/rapid_type_analysis.nit @@ -313,6 +313,7 @@ class RapidTypeAnalysis if not ot.can_resolve_for(t, t, mainmodule) then continue var rt = ot.anchor_to(mainmodule, t) if live_types.has(rt) then continue + if not is_valid_type(rt) then continue if not check_depth(rt) then continue #print "{ot}/{t} -> {rt}" live_types.add(rt) @@ -329,6 +330,7 @@ class RapidTypeAnalysis for t in live_types do if not ot.can_resolve_for(t, t, mainmodule) then continue var rt = ot.anchor_to(mainmodule, t) + if not is_valid_type(rt) then continue live_cast_types.add(rt) #print " {ot}/{t} -> {rt}" end @@ -336,6 +338,16 @@ class RapidTypeAnalysis #print "cast MType {live_cast_types.length}: {live_cast_types.join(", ")}" end + # Quick and dirty check that a forced type resolution gives a legal type + # TODO: move up in the model and kill `can_resolve_for` + private fun is_valid_type(mtype: MType): Bool + do + if mtype isa MGenericType then + return mtype.is_subtype(mainmodule, null, mtype.mclass.intro.bound_mtype) + end + return true + end + private fun check_depth(mtype: MClassType): Bool do var d = mtype.length