X-Git-Url: http://nitlanguage.org diff --git a/src/rapid_type_analysis.nit b/src/rapid_type_analysis.nit index 6be21eb..cfe091a 100644 --- a/src/rapid_type_analysis.nit +++ b/src/rapid_type_analysis.nit @@ -102,6 +102,18 @@ class RapidTypeAnalysis # The customized method definitions that remain to visit private var todo: List[CustomizedMethodDef] = new List[CustomizedMethodDef] + # Adapt and remove nullable + # return null if we got the null type + fun cleanup_type(mtype: MType, recvtype: MClassType): nullable MClassType + do + mtype = mtype.anchor_to(self.mainmodule, recvtype) + if mtype isa MNullType then return null + if mtype isa MNullableType then mtype = mtype.mtype + assert mtype isa MClassType + assert not mtype.need_anchor + return mtype + end + # Add a live type to the pool # # If the types is already live, then do nothing. @@ -161,10 +173,9 @@ class RapidTypeAnalysis fun add_monomorphic_send(mtype: MClassType, mmethod: MMethod) do assert self.live_types.has(mtype) - var defs = mmethod.lookup_definitions(self.mainmodule, mtype) - if defs.is_empty then return - assert defs.length == 1 else print "conflict on {mtype} for {mmethod}: {defs.join(" ")}" - self.add_static_call(mtype, defs.first) + if not mtype.has_mproperty(self.mainmodule, mmethod) then return + var def = mmethod.lookup_first_definition(self.mainmodule, mtype) + self.add_static_call(mtype, def) end # Add a customized_methoddefs to the pool @@ -219,6 +230,14 @@ class RapidTypeAnalysis self.add_type(native) end + for i in [0..mr.mmethoddef.msignature.arity[ do + var origtype = mr.mmethoddef.mproperty.intro.msignature.mparameters[i].mtype + if not origtype.need_anchor then continue # skip non covariant stuff + var paramtype = mr.mmethoddef.msignature.mparameters[i].mtype + paramtype = self.cleanup_type(paramtype, mr.receiver).as(not null) + self.add_cast_type(paramtype) + end + if not self.modelbuilder.mpropdef2npropdef.has_key(mr.mmethoddef) then # It is an init for a class? if mr.mmethoddef.mproperty.name == "init" then @@ -378,6 +397,10 @@ private class RapidTypeVisitor do if node == null then return node.accept_rapid_type_vistor(self) + if node isa AExpr then + var implicit_cast_to = node.implicit_cast_to + if implicit_cast_to != null then self.add_cast_type(implicit_cast_to) + end node.visit_all(self) end @@ -566,15 +589,9 @@ redef class ASuperExpr return end - #FIXME: we do not want an ugly static call! - var mpropdef = v.mpropdef - var mpropdefs = mpropdef.mproperty.lookup_super_definitions(mpropdef.mclassdef.mmodule, mpropdef.mclassdef.bound_mtype) - if mpropdefs.length != 1 then - debug("MPRODFEFS for super {mpropdef} for {v.receiver}: {mpropdefs.join(", ")}") - end - var msuperpropdef = mpropdefs.first - assert msuperpropdef isa MMethodDef - v.analysis.add_static_call(v.receiver, msuperpropdef) + var mpropdef = v.mpropdef.lookup_next_definition(v.analysis.mainmodule, v.receiver) + assert mpropdef isa MMethodDef + v.analysis.add_static_call(v.receiver, mpropdef) end end