diff options
-rw-r--r-- | src/mir/cleanup.cpp | 26 | ||||
-rw-r--r-- | src/mir/helpers.cpp | 37 | ||||
-rw-r--r-- | src/mir/helpers.hpp | 1 |
3 files changed, 43 insertions, 21 deletions
diff --git a/src/mir/cleanup.cpp b/src/mir/cleanup.cpp index 8a3454c4..c73bc66b 100644 --- a/src/mir/cleanup.cpp +++ b/src/mir/cleanup.cpp @@ -627,12 +627,28 @@ void MIR_Cleanup(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path, } ), (Borrow, - if( lit_ptr->is_BorrowOf() ) { - // TODO: - if( te.inner->m_data.is_Slice() ) { - // TODO: Create DST + if( lit_ptr->is_BorrowOf() ) + { + const auto& path = lit_ptr->as_BorrowOf(); + if( te.inner->m_data.is_Slice() ) + { + ::HIR::TypeRef tmp; + const auto& ty = state.get_static_type(tmp, path); + MIR_ASSERT(state, ty.m_data.is_Array(), "BorrowOf returning slice not of an array"); + unsigned int size = ty.m_data.as_Array().size_val; + + auto ptr_type = ::HIR::TypeRef::new_borrow(::HIR::BorrowType::Shared, + (&ty == &tmp ? mv$(tmp) : ty.clone()) + ); + + auto ptr_lval = mutator.in_temporary( mv$(ptr_type), ::MIR::Constant::make_ItemAddr(path.clone()) ); + auto size_lval = mutator.in_temporary( ::HIR::CoreType::Usize, ::MIR::Constant::make_Uint(size) ); + se.src = ::MIR::RValue::make_MakeDst({ mv$(ptr_lval), mv$(size_lval) }); + } + else + { + e = ::MIR::Constant::make_ItemAddr( path.clone() ); } - e = ::MIR::Constant::make_ItemAddr( lit_ptr->as_BorrowOf().clone() ); } else if( te.inner->m_data.is_Slice() && *te.inner->m_data.as_Slice().inner == ::HIR::CoreType::U8 ) { ::std::vector<uint8_t> bytestr; diff --git a/src/mir/helpers.cpp b/src/mir/helpers.cpp index e2272f31..dc149cd2 100644 --- a/src/mir/helpers.cpp +++ b/src/mir/helpers.cpp @@ -33,6 +33,26 @@ const ::MIR::BasicBlock& ::MIR::TypeResolve::get_block(::MIR::BasicBlockId id) c return m_fcn.blocks[id]; } +const ::HIR::TypeRef& ::MIR::TypeResolve::get_static_type(::HIR::TypeRef& tmp, const ::HIR::Path& path) const +{ + TU_MATCHA( (path.m_data), (pe), + (Generic, + MIR_ASSERT(*this, pe.m_params.m_types.empty(), "Path params on static"); + const auto& s = m_crate.get_static_by_path(sp, pe.m_path); + return s.m_type; + ), + (UfcsKnown, + MIR_TODO(*this, "LValue::Static - UfcsKnown - " << path); + ), + (UfcsUnknown, + MIR_BUG(*this, "Encountered UfcsUnknown in LValue::Static - " << path); + ), + (UfcsInherent, + MIR_TODO(*this, "LValue::Static - UfcsInherent - " << path); + ) + ) + throw ""; +} const ::HIR::TypeRef& ::MIR::TypeResolve::get_lvalue_type(::HIR::TypeRef& tmp, const ::MIR::LValue& val) const { TU_MATCH(::MIR::LValue, (val), (e), @@ -46,22 +66,7 @@ const ::HIR::TypeRef& ::MIR::TypeResolve::get_lvalue_type(::HIR::TypeRef& tmp, c return m_args.at(e.idx).second; ), (Static, - TU_MATCHA( (e.m_data), (pe), - (Generic, - MIR_ASSERT(*this, pe.m_params.m_types.empty(), "Path params on static"); - const auto& s = m_crate.get_static_by_path(sp, pe.m_path); - return s.m_type; - ), - (UfcsKnown, - MIR_TODO(*this, "LValue::Static - UfcsKnown - " << e); - ), - (UfcsUnknown, - MIR_BUG(*this, "Encountered UfcsUnknown in LValue::Static - " << e); - ), - (UfcsInherent, - MIR_TODO(*this, "LValue::Static - UfcsInherent - " << e); - ) - ) + return get_static_type(tmp, e); ), (Return, return m_ret_type; diff --git a/src/mir/helpers.hpp b/src/mir/helpers.hpp index 6382dbed..b0499ec8 100644 --- a/src/mir/helpers.hpp +++ b/src/mir/helpers.hpp @@ -89,6 +89,7 @@ public: const ::MIR::BasicBlock& get_block(::MIR::BasicBlockId id) const; + const ::HIR::TypeRef& get_static_type(::HIR::TypeRef& tmp, const ::HIR::Path& path) const; const ::HIR::TypeRef& get_lvalue_type(::HIR::TypeRef& tmp, const ::MIR::LValue& val) const; const ::HIR::TypeRef* is_type_owned_box(const ::HIR::TypeRef& ty) const; |