From 7bc0d41070080f3763247eb4d161a703f444d6f7 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Sat, 8 Dec 2012 20:25:43 -0500 Subject: [PATCH] nitg-s: retrieve recursively all partial generic types for new G[H[nullable T], Object] and T: X nitg-s will now find : G[H[nullable X], Object] H[nullable X] nullable X Object as type to generate. H[nullable X] and nullable X are considered as partial type because they are only used as part of a generic livetype. Signed-off-by: Alexandre Terrasa --- src/separate_compiler.nit | 57 ++++++++++++++++++++++++-------------------- tests/base_isa_vt_gen4.nit | 26 ++++++++++++++++++++ 2 files changed, 57 insertions(+), 26 deletions(-) create mode 100644 tests/base_isa_vt_gen4.nit create mode 100644 tests/sav/base_isa_vt_gen4.res diff --git a/src/separate_compiler.nit b/src/separate_compiler.nit index 06b95bc..55570b1 100644 --- a/src/separate_compiler.nit +++ b/src/separate_compiler.nit @@ -93,6 +93,7 @@ class SeparateCompiler super GlobalCompiler # TODO better separation of concerns private var undead_types: Set[MType] = new HashSet[MType] + private var partial_types: Set[MType] = new HashSet[MType] protected var typeids: HashMap[MType, Int] protected writable = new HashMap[MType, Int] private var type_colors: Map[MType, Int] = typeids @@ -266,34 +267,10 @@ class SeparateCompiler mtypes.add_all(self.runtime_type_analysis.live_cast_types) mtypes.add_all(self.undead_types) - self.undead_types.clear for mtype in mtypes do - # add formal types arguments to mtypes - if mtype isa MGenericType then - for ft in mtype.arguments do - if ft.need_anchor then - print("Why do we need anchor here ?") - abort - end - self.undead_types.add(ft) - end - end - var mclass_type: MClassType - if mtype isa MNullableType then - mclass_type = mtype.mtype.as(MClassType) - else - mclass_type = mtype.as(MClassType) - end - - # add virtual types to mtypes - for vt in self.vt_tables[mclass_type.mclass] do - if vt != null then - var anchored = vt.bound.anchor_to(self.mainmodule, mclass_type) - self.undead_types.add(anchored) - end - end + retieve_live_partial_types(mtype) end - mtypes.add_all(self.undead_types) + mtypes.add_all(self.partial_types) # set type unique id if modelbuilder.toolcontext.opt_phmod_typing.value or modelbuilder.toolcontext.opt_phand_typing.value then @@ -379,6 +356,34 @@ class SeparateCompiler return mtypes end + fun retieve_live_partial_types(mtype: MType) do + # add formal types arguments to mtypes + if mtype isa MGenericType then + for ft in mtype.arguments do + if ft.need_anchor then + print("Why do we need anchor here ?") + abort + end + self.partial_types.add(ft) + retieve_live_partial_types(ft) + end + end + var mclass_type: MClassType + if mtype isa MNullableType then + mclass_type = mtype.mtype.as(MClassType) + else + mclass_type = mtype.as(MClassType) + end + + # add virtual types to mtypes + for vt in self.vt_tables[mclass_type.mclass] do + if vt != null then + var anchored = vt.bound.anchor_to(self.mainmodule, mclass_type) + self.partial_types.add(anchored) + end + end + end + # declare live generic types tables selection private fun compile_live_gentype_to_c(mclass: MClass) do if mclass.arity > 0 then diff --git a/tests/base_isa_vt_gen4.nit b/tests/base_isa_vt_gen4.nit new file mode 100644 index 0000000..c3edf4b --- /dev/null +++ b/tests/base_isa_vt_gen4.nit @@ -0,0 +1,26 @@ +import kernel + +class G[U,V] +end + +class H[W] +end + +class A + type T: X + fun foo: Object do return new G[H[nullable T], Object] +end + +class B + super A + redef type T: Y +end + +class X +end +class Y + super X +end + +var b = new B +var bt = b.foo diff --git a/tests/sav/base_isa_vt_gen4.res b/tests/sav/base_isa_vt_gen4.res new file mode 100644 index 0000000..e69de29 -- 1.7.9.5