auto_super_init: use CallSite
[nit.git] / src / separate_compiler.nit
index a683a35..09545e4 100644 (file)
@@ -95,6 +95,11 @@ redef class ModelBuilder
                for t in mtypes do
                        compiler.compile_type_to_c(t)
                end
+               # compile remaining types structures (useless but needed for the symbol resolution at link-time)
+               for t in compiler.undead_types do
+                       if mtypes.has(t) then continue
+                       compiler.compile_type_to_c(t)
+               end
 
                compiler.display_stats
 
@@ -114,7 +119,6 @@ class SeparateCompiler
        var runtime_type_analysis: nullable RapidTypeAnalysis
 
        private var undead_types: Set[MType] = new HashSet[MType]
-       private var partial_types: Set[MType] = new HashSet[MType]
        private var live_unresolved_types: Map[MClassDef, Set[MType]] = new HashMap[MClassDef, HashSet[MType]]
 
        private var type_layout: nullable Layout[MType]
@@ -443,16 +447,10 @@ class SeparateCompiler
                var mtypes = new HashSet[MType]
                mtypes.add_all(self.runtime_type_analysis.live_types)
                mtypes.add_all(self.runtime_type_analysis.live_cast_types)
-               mtypes.add_all(self.undead_types)
                for c in self.box_kinds.keys do
                        mtypes.add(c.mclass_type)
                end
 
-               for mtype in mtypes do
-                       retrieve_partial_types(mtype)
-               end
-               mtypes.add_all(self.partial_types)
-
                # Typing Layout
                var layout_builder: TypingLayoutBuilder[MType]
                if modelbuilder.toolcontext.opt_bm_typing.value then
@@ -581,34 +579,6 @@ class SeparateCompiler
                return tables
        end
 
-       fun retrieve_partial_types(mtype: MType) do
-               # add formal types arguments to mtypes
-               if mtype isa MGenericType then
-                       for ft in mtype.arguments do
-                               if ft.need_anchor then
-                                       print("Why do we need anchor here ?")
-                                       abort
-                               end
-                               self.partial_types.add(ft)
-                               retrieve_partial_types(ft)
-                       end
-               end
-               var mclass_type: MClassType
-               if mtype isa MNullableType then
-                       mclass_type = mtype.mtype.as(MClassType)
-               else
-                       mclass_type = mtype.as(MClassType)
-               end
-
-               # add virtual types to mtypes
-               for vt in self.mainmodule.properties(mclass_type.mclass) do
-                       if vt isa MVirtualTypeProp then
-                               var anchored = vt.mvirtualtype.lookup_bound(self.mainmodule, mclass_type).anchor_to(self.mainmodule, mclass_type)
-                               self.partial_types.add(anchored)
-                       end
-               end
-       end
-
        # Separately compile all the method definitions of the module
        fun compile_module_to_c(mmodule: MModule)
        do
@@ -936,8 +906,10 @@ class SeparateCompiler
        
        redef fun finalize_ffi_for_module(nmodule)
        do
+               var old_module = self.mainmodule
                self.mainmodule = nmodule.mmodule.as(not null)
                super
+               self.mainmodule = old_module
        end
 end
 
@@ -1023,6 +995,8 @@ class SeparateCompilerVisitor
 
        private fun table_send(mmethod: MMethod, arguments: Array[RuntimeVariable], const_color: String): nullable RuntimeVariable
        do
+               assert arguments.length == mmethod.intro.msignature.arity + 1 else debug("Invalid arity for {mmethod}. {arguments.length} arguments given.")
+
                var res: nullable RuntimeVariable
                var msignature = mmethod.intro.msignature.resolve_for(mmethod.intro.mclassdef.bound_mtype, mmethod.intro.mclassdef.bound_mtype, mmethod.intro.mclassdef.mmodule, true)
                var ret = msignature.return_mtype
@@ -1077,7 +1051,7 @@ class SeparateCompilerVisitor
                                        self.add("{res} = 1; /* {arg.inspect} cannot be null */")
                                end
                        else
-                               self.add_abort("Reciever is null")
+                               self.add_abort("Receiver is null")
                        end
                        self.add("\} else \{")
                end
@@ -1118,6 +1092,8 @@ class SeparateCompilerVisitor
 
        redef fun call(mmethoddef, recvtype, arguments)
        do
+               assert arguments.length == mmethoddef.msignature.arity + 1 else debug("Invalid arity for {mmethoddef}. {arguments.length} arguments given.")
+
                var res: nullable RuntimeVariable
                var ret = mmethoddef.msignature.return_mtype
                if mmethoddef.mproperty.is_new then