separate_compiler: start migration from layout_builder to coloring on type tables
authorAlexandre Terrasa <alexandre@moz-code.org>
Thu, 8 May 2014 01:42:44 +0000 (21:42 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Fri, 9 May 2014 15:36:48 +0000 (11:36 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/layout_builders.nit
src/separate_compiler.nit

index f7dc388..bab048b 100644 (file)
@@ -25,6 +25,7 @@
 module layout_builders
 
 import abstract_compiler
+import coloring
 
 # Layouts
 
@@ -749,3 +750,12 @@ class ResolutionHasher
                return result
        end
 end
+
+redef class POSetColorer[E]
+       fun to_layout: Layout[E] do
+               var layout = new Layout[E]
+               layout.ids = self.ids
+               layout.pos = self.colors
+               return layout
+       end
+end
index 1e606b3..abb80a2 100644 (file)
@@ -488,18 +488,21 @@ class SeparateCompiler
 
        # colorize live types of the program
        private fun do_type_coloring: POSet[MType] do
+               # Collect types to colorize
+               var live_types = runtime_type_analysis.live_types
+               var live_cast_types = runtime_type_analysis.live_cast_types
                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(live_types)
+               mtypes.add_all(live_cast_types)
                for c in self.box_kinds.keys do
                        mtypes.add(c.mclass_type)
                end
 
-               # Typing Layout
-               var layout_builder = new MTypeColorer(self.mainmodule)
-               # colorize types
-               self.type_layout = layout_builder.build_layout(mtypes)
-               var poset = layout_builder.poset.as(not null)
+               # Compute colors
+               var poset = poset_from_mtypes(mtypes)
+               var colorer = new POSetColorer[MType]
+               colorer.colorize(poset)
+               self.type_layout = colorer.to_layout
                self.type_tables = self.build_type_tables(poset)
 
                # VT and FT are stored with other unresolved types in the big resolution_tables
@@ -508,6 +511,20 @@ class SeparateCompiler
                return poset
        end
 
+       private fun poset_from_mtypes(mtypes: Set[MType]): POSet[MType] do
+               var poset = new POSet[MType]
+               for e in mtypes do
+                       poset.add_node(e)
+                       for o in mtypes do
+                               if e == o then continue
+                               if e.is_subtype(mainmodule, null, o) then
+                                       poset.add_edge(e, o)
+                               end
+                       end
+               end
+               return poset
+       end
+
        # Build type tables
        fun build_type_tables(mtypes: POSet[MType]): Map[MType, Array[nullable MType]] do
                var tables = new HashMap[MType, Array[nullable MType]]