layout_builders: better filtering of mproperties in MPropertyColorer
authorAlexandre Terrasa <alexandre@moz-code.org>
Wed, 27 Feb 2013 17:39:53 +0000 (12:39 -0500)
committerAlexandre Terrasa <alexandre@moz-code.org>
Mon, 4 Mar 2013 18:20:02 +0000 (13:20 -0500)
Previously using `if mprop isa E then properties.add(mprop)` where `E` was a formal type
but inneficien with compilers using erasure.

Fixed this with hardcoded subtyping test in 3 subclasses : MMethodColorer, MAttributeColorer & MVirtualTypePropColorer

This fix allow better tables computation reducing the total amount of holes.

Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/layout_builders.nit
src/separate_compiler.nit
src/separate_erasure_compiler.nit

index 925e5e1..3b3a376 100644 (file)
@@ -254,9 +254,6 @@ abstract class PropertyLayoutBuilder[E: MProperty]
 
        type LAYOUT: PropertyLayout[E]
 
-       private var mmodule: MModule
-       init(mmodule: MModule) do self.mmodule = mmodule
-
        # Compute properties ids and position
        fun build_layout(mclasses: Set[MClass]): LAYOUT is abstract
 end
@@ -267,9 +264,8 @@ class CLPropertyLayoutBuilder[E: MProperty]
 
        private var colorer: MPropertyColorer[E]
 
-       init(mmodule: MModule) do
-               super
-               self.colorer = new MPropertyColorer[E](mmodule)
+       init(colorer: MPropertyColorer[E]) do
+               self.colorer = colorer
        end
 
        # Compute mclasses ids and position using BM
@@ -538,7 +534,7 @@ private class MClassColorer
 end
 
 # MProperty coloring
-private class MPropertyColorer[E: MProperty]
+abstract class MPropertyColorer[E: MProperty]
 
        private var mmodule: MModule
        private var class_colorer: MClassColorer
@@ -610,10 +606,49 @@ private class MPropertyColorer[E: MProperty]
        end
 
        # Filter properties
-       private fun properties(mclass: MClass): Set[E] do
-               var properties = new HashSet[E]
+       private fun properties(mclass: MClass): Set[E] is abstract
+end
+
+# Coloring for MMethods
+class MMethodColorer
+       super MPropertyColorer[MMethod]
+
+       init(mmodule: MModule) do super
+
+       redef fun properties(mclass) do
+               var properties = new HashSet[MMethod]
+               for mprop in self.mmodule.properties(mclass) do
+                       if mprop isa MMethod then properties.add(mprop)
+               end
+               return properties
+       end
+end
+
+# Coloring for MMAttributes
+class MAttributeColorer
+       super MPropertyColorer[MAttribute]
+
+       init(mmodule: MModule) do super
+
+       redef fun properties(mclass) do
+               var properties = new HashSet[MAttribute]
+               for mprop in self.mmodule.properties(mclass) do
+                       if mprop isa MAttribute then properties.add(mprop)
+               end
+               return properties
+       end
+end
+
+# Coloring for MVirtualTypeProps
+class MVirtualTypePropColorer
+       super MPropertyColorer[MVirtualTypeProp]
+
+       init(mmodule: MModule) do super
+
+       redef fun properties(mclass) do
+               var properties = new HashSet[MVirtualTypeProp]
                for mprop in self.mmodule.properties(mclass) do
-                       if mprop isa E then properties.add(mprop)
+                       if mprop isa MVirtualTypeProp then properties.add(mprop)
                end
                return properties
        end
index 678f81b..55567ef 100644 (file)
@@ -211,14 +211,14 @@ class SeparateCompiler
                var mclasses = new HashSet[MClass].from(modelbuilder.model.mclasses)
 
                # methods coloration
-               var method_coloring = new CLPropertyLayoutBuilder[MMethod](mainmodule)
+               var method_coloring = new CLPropertyLayoutBuilder[MMethod](new MMethodColorer(mainmodule))
                var method_layout = method_coloring.build_layout(mclasses)
                self.method_tables = build_method_tables(mclasses, method_layout)
                self.compile_color_consts(method_layout.pos)
                self.method_layout = method_layout
 
                # attributes coloration
-               var attribute_coloring = new CLPropertyLayoutBuilder[MAttribute](mainmodule)
+               var attribute_coloring = new CLPropertyLayoutBuilder[MAttribute](new MAttributeColorer(mainmodule))
                var attr_layout = attribute_coloring.build_layout(mclasses)
                self.attr_tables = build_attr_tables(mclasses, attr_layout)
                self.compile_color_consts(attr_layout.pos)
index 46c7fbb..d16fb06 100644 (file)
@@ -89,7 +89,7 @@ class SeparateErasureCompiler
                self.class_tables = self.build_class_typing_tables(mclasses)
 
                # vt coloration
-               var vt_coloring = new CLPropertyLayoutBuilder[MVirtualTypeProp](mainmodule)
+               var vt_coloring = new CLPropertyLayoutBuilder[MVirtualTypeProp](new MVirtualTypePropColorer(mainmodule))
                var vt_layout = vt_coloring.build_layout(mclasses)
                self.vt_tables = build_vt_tables(mclasses, vt_layout)
                self.compile_color_consts(vt_layout.pos)