diff options
author | John Hodge <tpg@ucc.asn.au> | 2018-06-30 12:30:38 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2018-06-30 12:30:38 +0800 |
commit | 87ec3ea65bc42214c4e78c991ec2033fc103bf63 (patch) | |
tree | 95f5b62513858f2efd236a692be077a46556e565 /src | |
parent | 98c49f19838c1049be70cfe0a8bd7852b03ecafb (diff) | |
download | mrust-87ec3ea65bc42214c4e78c991ec2033fc103bf63.tar.gz |
HIR Expand VTable - Fix incorrect associated type lookups
Diffstat (limited to 'src')
-rw-r--r-- | src/hir_expand/vtable.cpp | 18 | ||||
-rw-r--r-- | src/trans/codegen_c.cpp | 1 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/hir_expand/vtable.cpp b/src/hir_expand/vtable.cpp index 4bc1cbc5..79e163ac 100644 --- a/src/hir_expand/vtable.cpp +++ b/src/hir_expand/vtable.cpp @@ -66,6 +66,7 @@ namespace { unsigned int i; void add_types_from_trait(const ::HIR::Trait& tr) { for(const auto& ty : tr.m_types) { + DEBUG(ty.first << " #" << i); auto rv = trait_ptr->m_type_indexes.insert( ::std::make_pair(ty.first, i) ); if(rv.second == false) { //TODO(Span(), "Handle conflicting associated types - '" << ty.first << "'"); @@ -97,12 +98,19 @@ namespace { auto clone_cb = [&](const auto& t, auto& o) { if(t.m_data.is_Path() && t.m_data.as_Path().path.m_data.is_UfcsKnown()) { const auto& pe = t.m_data.as_Path().path.m_data.as_UfcsKnown(); - DEBUG("t=" << t); - if( *pe.type == ::HIR::TypeRef("Self", 0xFFFF) /*&& pe.trait == trait_path*/ && tr.m_type_indexes.count(pe.item) ) { + bool is_self = (*pe.type == ::HIR::TypeRef("Self", 0xFFFF)); + auto it = trait_ptr->m_type_indexes.find(pe.item); + bool has_item = (it != trait_ptr->m_type_indexes.end()); + // TODO: Check the trait against m_type_indexes + if( is_self /*&& pe.trait == trait_path*/ && has_item ) { + DEBUG("[clone_cb] t=" << t << " -> " << it->second); // Replace with a new type param, need to know the index of it - o = ::HIR::TypeRef("a#"+pe.item, tr.m_type_indexes.at(pe.item)); + o = ::HIR::TypeRef("a#"+pe.item, it->second); return true; } + else { + DEBUG("[clone_cb] t=" << t << "(" << is_self << has_item << ")"); + } } return false; }; @@ -134,6 +142,10 @@ namespace { DEBUG("- '" << vi.first << "' NOT object safe (generic), not creating vtable"); return false; } + if( ve.m_receiver == ::HIR::Function::Receiver::Value ) { + DEBUG("- '" << vi.first << "' NOT object safe (by-value), not creating vtable"); + return false; + } ::HIR::FunctionType ft; ft.is_unsafe = ve.m_unsafe; diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index c30657bf..91138d14 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -1923,6 +1923,7 @@ namespace { // Find the corresponding vtable entry for(const auto& m : trait.m_value_indexes) { + // NOTE: The "3" is the number of non-method vtable entries if( m.second.first != 3+i ) continue ; |