From 99727502394890f93e8d6f3123524ab8aaa098cf Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Wed, 27 Feb 2013 12:39:53 -0500 Subject: [PATCH] layout_builders: better filtering of mproperties in MPropertyColorer 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 --- src/layout_builders.nit | 55 ++++++++++++++++++++++++++++++------- src/separate_compiler.nit | 4 +-- src/separate_erasure_compiler.nit | 2 +- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/src/layout_builders.nit b/src/layout_builders.nit index 925e5e1..3b3a376 100644 --- a/src/layout_builders.nit +++ b/src/layout_builders.nit @@ -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 diff --git a/src/separate_compiler.nit b/src/separate_compiler.nit index 678f81b..55567ef 100644 --- a/src/separate_compiler.nit +++ b/src/separate_compiler.nit @@ -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) diff --git a/src/separate_erasure_compiler.nit b/src/separate_erasure_compiler.nit index 46c7fbb..d16fb06 100644 --- a/src/separate_erasure_compiler.nit +++ b/src/separate_erasure_compiler.nit @@ -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) -- 1.7.9.5