ni_nitdoc: added fast copy past utility to signatures.
[nit.git] / src / separate_compiler.nit
index f6648c7..a2e5128 100644 (file)
@@ -59,12 +59,13 @@ redef class ModelBuilder
        fun run_separate_compiler(mainmodule: MModule, runtime_type_analysis: RapidTypeAnalysis)
        do
                var time0 = get_time
-               self.toolcontext.info("*** COMPILING TO C ***", 1)
+               self.toolcontext.info("*** GENERATING C ***", 1)
 
                var compiler = new SeparateCompiler(mainmodule, self, runtime_type_analysis)
                compiler.compile_header
 
                # compile class structures
+               self.toolcontext.info("Property coloring", 2)
                compiler.new_file("{mainmodule.name}.classes")
                compiler.do_property_coloring
                for m in mainmodule.in_importation.greaters do
@@ -79,11 +80,13 @@ redef class ModelBuilder
 
                # compile methods
                for m in mainmodule.in_importation.greaters do
+                       self.toolcontext.info("Generate C for module {m}", 2)
                        compiler.new_file("{m.name}.sep")
                        compiler.compile_module_to_c(m)
                end
 
                # compile live & cast type structures
+               self.toolcontext.info("Type coloring", 2)
                compiler.new_file("{mainmodule.name}.types")
                var mtypes = compiler.do_type_coloring
                for t in mtypes do
@@ -92,6 +95,8 @@ redef class ModelBuilder
 
                compiler.display_stats
 
+               var time1 = get_time
+               self.toolcontext.info("*** END GENERATING C: {time1-time0} ***", 2)
                write_and_make(compiler)
        end
 end
@@ -217,13 +222,20 @@ class SeparateCompiler
                # Layouts
                var method_layout_builder: PropertyLayoutBuilder[MMethod]
                var attribute_layout_builder: PropertyLayoutBuilder[MAttribute]
-               if modelbuilder.toolcontext.opt_bm_typing.value then
-                       method_layout_builder = new MMethodBMizer(self.mainmodule)
-                       attribute_layout_builder = new MAttributeBMizer(self.mainmodule)
-               else
-                       method_layout_builder = new MMethodColorer(self.mainmodule)
-                       attribute_layout_builder = new MAttributeColorer(self.mainmodule)
-               end
+               #FIXME PH and BM layouts too slow for large programs
+               #if modelbuilder.toolcontext.opt_bm_typing.value then
+               #       method_layout_builder = new MMethodBMizer(self.mainmodule)
+               #       attribute_layout_builder = new MAttributeBMizer(self.mainmodule)
+               #else if modelbuilder.toolcontext.opt_phmod_typing.value then
+               #       method_layout_builder = new MMethodHasher(new PHModOperator, self.mainmodule)
+               #       attribute_layout_builder = new MAttributeHasher(new PHModOperator, self.mainmodule)
+               #else if modelbuilder.toolcontext.opt_phand_typing.value then
+               #       method_layout_builder = new MMethodHasher(new PHAndOperator, self.mainmodule)
+               #       attribute_layout_builder = new MAttributeHasher(new PHAndOperator, self.mainmodule)
+               #else
+               method_layout_builder = new MMethodColorer(self.mainmodule)
+               attribute_layout_builder = new MAttributeColorer(self.mainmodule)
+               #end
 
                # methods coloration
                var method_layout = method_layout_builder.build_layout(mclasses)
@@ -337,7 +349,7 @@ class SeparateCompiler
                end
 
                for mtype in mtypes do
-                       retieve_live_partial_types(mtype)
+                       retrieve_partial_types(mtype)
                end
                mtypes.add_all(self.partial_types)
 
@@ -471,7 +483,7 @@ class SeparateCompiler
                return tables
        end
 
-       fun retieve_live_partial_types(mtype: MType) do
+       fun retrieve_partial_types(mtype: MType) do
                # add formal types arguments to mtypes
                if mtype isa MGenericType then
                        for ft in mtype.arguments do
@@ -480,7 +492,7 @@ class SeparateCompiler
                                        abort
                                end
                                self.partial_types.add(ft)
-                               retieve_live_partial_types(ft)
+                               retrieve_partial_types(ft)
                        end
                end
                var mclass_type: MClassType
@@ -654,7 +666,7 @@ class SeparateCompiler
                        self.header.add_decl("val* BOX_{c_name}({mtype.ctype});")
                        v.add_decl("/* allocate {mtype} */")
                        v.add_decl("val* BOX_{mtype.c_name}({mtype.ctype} value) \{")
-                       v.add("struct instance_{c_name}*res = GC_MALLOC(sizeof(struct instance_{c_name}));")
+                       v.add("struct instance_{c_name}*res = nit_alloc(sizeof(struct instance_{c_name}));")
                        v.require_declaration("type_{c_name}")
                        v.add("res->type = &type_{c_name};")
                        v.require_declaration("class_{c_name}")
@@ -679,7 +691,7 @@ class SeparateCompiler
                        var res = v.new_named_var(mtype, "self")
                        res.is_exact = true
                        var mtype_elt = mtype.arguments.first
-                       v.add("{res} = GC_MALLOC(sizeof(struct instance_{c_name}) + length*sizeof({mtype_elt.ctype}));")
+                       v.add("{res} = nit_alloc(sizeof(struct instance_{c_name}) + length*sizeof({mtype_elt.ctype}));")
                        v.add("{res}->type = type;")
                        hardening_live_type(v, "type")
                        v.require_declaration("class_{c_name}")
@@ -695,7 +707,7 @@ class SeparateCompiler
                v.add_decl("{mtype.ctype} NEW_{c_name}(const struct type* type) \{")
                var res = v.new_named_var(mtype, "self")
                res.is_exact = true
-               v.add("{res} = GC_MALLOC(sizeof(struct instance) + {attrs.length}*sizeof(nitattribute_t));")
+               v.add("{res} = nit_alloc(sizeof(struct instance) + {attrs.length}*sizeof(nitattribute_t));")
                v.add("{res}->type = type;")
                hardening_live_type(v, "type")
                v.require_declaration("class_{c_name}")
@@ -859,7 +871,13 @@ class SeparateCompilerVisitor
        redef fun send(mmethod, arguments)
        do
                if arguments.first.mcasttype.ctype != "val*" then
-                       return self.monomorphic_send(mmethod, arguments.first.mcasttype, arguments)
+                       # In order to shortcut the primitive, we need to find the most specific method
+                       # Howverr, because of performance (no flattening), we always work on the realmainmodule
+                       var m = self.compiler.mainmodule
+                       self.compiler.mainmodule = self.compiler.realmainmodule
+                       var res = self.monomorphic_send(mmethod, arguments.first.mcasttype, arguments)
+                       self.compiler.mainmodule = m
+                       return res
                end
 
                var res: nullable RuntimeVariable