+
+ private fun compute_type_test_layouts(mtypes: Set[MClassType], cast_types: Set[MType]) do
+ # Group cast_type by their classes
+ var bucklets = new HashMap[MClass, Set[MType]]
+ for e in cast_types do
+ var c = e.undecorate.as(MClassType).mclass
+ if not bucklets.has_key(c) then
+ bucklets[c] = new HashSet[MType]
+ end
+ bucklets[c].add(e)
+ end
+
+ # Colorize cast_types from the class hierarchy
+ var colorer = new POSetGroupColorer[MClass, MType](class_conflict_graph, bucklets)
+ type_colors = colorer.colors
+
+ var layouts = new HashMap[MClass, Array[nullable MType]]
+ for c in runtime_type_analysis.live_classes do
+ layouts[c] = colorer.build_layout(c)
+ end
+
+ # Build the table for each live type
+ for t in mtypes do
+ # A live type use the layout of its class
+ var c = t.mclass
+ var layout = layouts[c]
+ var table = new Array[nullable MType].with_capacity(layout.length)
+ type_tables[t] = table
+
+ # For each potential super-type in the layout
+ for sup in layout do
+ if sup == null then
+ table.add null
+ else if t.is_subtype(mainmodule, null, sup) then
+ table.add sup
+ else
+ table.add null
+ end
+ end
+ end
+ end
+