summaryrefslogtreecommitdiff
path: root/src/trans/codegen.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-12-10 21:27:19 +0800
committerJohn Hodge <tpg@mutabah.net>2016-12-10 21:27:19 +0800
commitd395407fbd9f8a53276fbcc76fd5c61882426b9f (patch)
treef1ff28641f1844d46e2b3486608b025b8f99c43a /src/trans/codegen.cpp
parent5c7994fe17d98405a1d533b1d9ac0579767f6a90 (diff)
downloadmrust-d395407fbd9f8a53276fbcc76fd5c61882426b9f.tar.gz
Trans Codegen - Ensure that vtable types are generated if the TraitObject is referenced
Diffstat (limited to 'src/trans/codegen.cpp')
-rw-r--r--src/trans/codegen.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/trans/codegen.cpp b/src/trans/codegen.cpp
index 3f6413a1..caba6e43 100644
--- a/src/trans/codegen.cpp
+++ b/src/trans/codegen.cpp
@@ -23,11 +23,13 @@ namespace {
struct TypeVisitor
{
+ const ::HIR::Crate& m_crate;
CodeGenerator& codegen;
::std::set< ::HIR::TypeRef> visited;
::std::set< const ::HIR::TypeRef*, PtrComp> active_set;
- TypeVisitor(CodeGenerator& codegen):
+ TypeVisitor(const ::HIR::Crate& crate, CodeGenerator& codegen):
+ m_crate(crate),
codegen(codegen)
{}
@@ -139,6 +141,25 @@ namespace {
)
),
(TraitObject,
+ static Span sp;
+ // Ensure that the data trait's vtable is present
+ const auto& trait = *te.m_trait.m_trait_ptr;
+
+ auto vtable_ty_spath = te.m_trait.m_path.m_path;
+ vtable_ty_spath.m_components.back() += "#vtable";
+ const auto& vtable_ref = m_crate.get_struct_by_path(sp, vtable_ty_spath);
+ // Copy the param set from the trait in the trait object
+ ::HIR::PathParams vtable_params = te.m_trait.m_path.m_params.clone();
+ // - Include associated types on bound
+ for(const auto& ty_b : te.m_trait.m_type_bounds) {
+ auto idx = trait.m_type_indexes.at(ty_b.first);
+ if(vtable_params.m_types.size() <= idx)
+ vtable_params.m_types.resize(idx+1);
+ vtable_params.m_types[idx] = ty_b.second.clone();
+ }
+
+
+ visit_type( ::HIR::TypeRef( ::HIR::GenericPath(vtable_ty_spath, mv$(vtable_params)), &vtable_ref ) );
),
(Array,
visit_type(*te.inner);
@@ -179,7 +200,7 @@ void Trans_Codegen(const ::std::string& outfile, const ::HIR::Crate& crate, cons
{
TRACE_FUNCTION;
- TypeVisitor tv { *codegen };
+ TypeVisitor tv { crate, *codegen };
for(const auto& ent : list.m_functions)
{
TRACE_FUNCTION_F("Enumerate fn " << ent.first);