diff options
author | John Hodge <tpg@mutabah.net> | 2016-12-04 22:34:37 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-12-04 22:34:37 +0800 |
commit | 837b788070f5bf81c2279b92ac3458ecd030356a (patch) | |
tree | 68a9bcc1d9caeeec56b84212e0f604eda29851a0 | |
parent | f9a548574dff561acc6ef72c6157e051b6076a4b (diff) | |
download | mrust-837b788070f5bf81c2279b92ac3458ecd030356a.tar.gz |
MIR Gen - Fix vtable types
-rw-r--r-- | src/mir/from_hir.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp index cedbb5f5..3d28ef7d 100644 --- a/src/mir/from_hir.cpp +++ b/src/mir/from_hir.cpp @@ -1090,12 +1090,26 @@ namespace { (TraitObject, // TODO: Obtain the vtable if the destination is a trait object // vtable exists as an unnamable associated type + const auto& trait = *e.m_trait.m_trait_ptr; + auto vtable_ty_spath = e.m_trait.m_path.m_path; + vtable_ty_spath.m_components.back() += "#vtable"; + const auto& vtable_ref = m_builder.crate().get_struct_by_path(node.span(), vtable_ty_spath); + // Copy the param set from the trait in the trait object + ::HIR::PathParams vtable_params = e.m_trait.m_path.m_params.clone(); + // - Include associated types on bound + for(const auto& ty_b : e.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(); + } + auto vtable_type = ::HIR::TypeRef( ::HIR::GenericPath(vtable_ty_spath, mv$(vtable_params)), &vtable_ref ); + ::HIR::Path vtable { ty_in.clone(), e.m_trait.m_path.clone(), "#vtable" }; - ::HIR::TypeRef vtable_type { {} }; auto vtable_lval = m_builder.lvalue_or_temp( node.span(), - ::HIR::TypeRef::new_borrow(::HIR::BorrowType::Shared, mv$(vtable_type)), + ::HIR::TypeRef::new_pointer(::HIR::BorrowType::Shared, mv$(vtable_type)), ::MIR::RValue( ::MIR::Constant::make_ItemAddr(mv$(vtable)) ) ); |