diff options
author | John Hodge <tpg@ucc.asn.au> | 2017-02-22 22:17:07 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2017-02-22 22:17:07 +0800 |
commit | 0b94a427d2c4ad46cfbf20529067240b8a8b92e0 (patch) | |
tree | 61cee6d5791b67793421c610d7c7424b682cf4df /src/mir | |
parent | 0b672c4325967ade9a8f9bd8a06071cca09c4276 (diff) | |
download | mrust-0b94a427d2c4ad46cfbf20529067240b8a8b92e0.tar.gz |
MIR - Restrict Constant::Bytes to returning &[u8; N]
Diffstat (limited to 'src/mir')
-rw-r--r-- | src/mir/check.cpp | 10 | ||||
-rw-r--r-- | src/mir/cleanup.cpp | 2 | ||||
-rw-r--r-- | src/mir/from_hir_match.cpp | 8 |
3 files changed, 11 insertions, 9 deletions
diff --git a/src/mir/check.cpp b/src/mir/check.cpp index c76b6e92..638a540c 100644 --- a/src/mir/check.cpp +++ b/src/mir/check.cpp @@ -143,6 +143,7 @@ namespace { // - Requires maintaining state information for all variables/temporaries with support for loops void MIR_Validate_ValState(::MIR::TypeResolve& state, const ::MIR::Function& fcn) { + TRACE_FUNCTION; // > Iterate through code, creating state maps. Save map at the start of each bb. struct ValStates { enum class State { @@ -326,7 +327,6 @@ void MIR_Validate_ValState(::MIR::TypeResolve& state, const ::MIR::Function& fcn } static bool merge_lists(::std::vector<State>& a, ::std::vector<State>& b) { - DEBUG("merge_lists"); bool rv = false; assert( a.size() == b.size() ); for(unsigned int i = 0; i < a.size(); i++) @@ -597,9 +597,6 @@ void MIR_Validate(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path } } - // [ValState] = Value state tracking (use after move, uninit, ...) - MIR_Validate_ValState(state, fcn); - // [Flat] = Basic checks (just iterates BBs) // - [Flat] Types must be valid (correct type for slot etc.) // - Simple check of all assignments/calls/... @@ -703,7 +700,7 @@ void MIR_Validate(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path check_type( ::HIR::TypeRef(::HIR::CoreType::Bool) ); ), (Bytes, - // TODO: Check result (could be either &[u8; N] or &[u8]) + check_type( ::HIR::TypeRef::new_borrow(::HIR::BorrowType::Shared, ::HIR::TypeRef::new_array(::HIR::CoreType::U8, c.size())) ); ), (StaticString, check_type( ::HIR::TypeRef::new_borrow(::HIR::BorrowType::Shared, ::HIR::CoreType::Str) ); @@ -892,6 +889,9 @@ void MIR_Validate(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path ) } } + + // [ValState] = Value state tracking (use after move, uninit, ...) + MIR_Validate_ValState(state, fcn); } // -------------------------------------------------------------------- diff --git a/src/mir/cleanup.cpp b/src/mir/cleanup.cpp index a1da936e..a0f92a0f 100644 --- a/src/mir/cleanup.cpp +++ b/src/mir/cleanup.cpp @@ -410,7 +410,7 @@ const ::HIR::Literal* MIR_Cleanup_GetConstant(const Span& sp, const StaticTraitR ::std::vector<uint8_t> bytestr; for(auto v : lit.as_String()) bytestr.push_back( static_cast<uint8_t>(v) ); - return ::MIR::Constant::make_Bytes( mv$(bytestr) ); + return ::MIR::RValue::make_MakeDst({ ::MIR::Constant(mv$(bytestr)), ::MIR::Constant::make_Uint({ lit.as_String().size(), ::HIR::CoreType::Usize }) }); } else if( te.inner->m_data.is_Array() && *te.inner->m_data.as_Array().inner == ::HIR::CoreType::U8 ) { // TODO: How does this differ at codegen to the above? diff --git a/src/mir/from_hir_match.cpp b/src/mir/from_hir_match.cpp index 05ba510a..60c904a5 100644 --- a/src/mir/from_hir_match.cpp +++ b/src/mir/from_hir_match.cpp @@ -1754,12 +1754,14 @@ int MIR_LowerHIR_Match_Simple__GeneratePattern(MirBuilder& builder, const Span& if( rule.is_Value() ) { ASSERT_BUG(sp, *te.inner == ::HIR::CoreType::U8, "Bytes pattern on non-&[u8]"); auto cloned_val = ::MIR::Constant( rule.as_Value().as_Bytes() ); + auto size_val = ::MIR::Constant::make_Uint({ rule.as_Value().as_Bytes().size(), ::HIR::CoreType::Usize }); auto succ_bb = builder.new_bb_unlinked(); auto inner_val = val.as_Deref().val->clone(); - auto test_lval = builder.lvalue_or_temp(sp, ::HIR::TypeRef::new_borrow(::HIR::BorrowType::Shared, ty.clone()), ::MIR::RValue(mv$(cloned_val))); + auto slice_rval = ::MIR::RValue::make_MakeDst({ mv$(cloned_val), mv$(size_val) }); + auto test_lval = builder.lvalue_or_temp(sp, ::HIR::TypeRef::new_borrow(::HIR::BorrowType::Shared, ty.clone()), mv$(slice_rval)); auto cmp_lval = builder.lvalue_or_temp(sp, ::HIR::CoreType::Bool, ::MIR::RValue::make_BinOp({ mv$(inner_val), ::MIR::eBinOp::EQ, mv$(test_lval) })); builder.end_block( ::MIR::Terminator::make_If({ mv$(cmp_lval), succ_bb, fail_bb }) ); builder.set_cur_block(succ_bb); @@ -1768,9 +1770,9 @@ int MIR_LowerHIR_Match_Simple__GeneratePattern(MirBuilder& builder, const Span& const auto& re = rule.as_Slice(); // Compare length - auto test_lval = builder.lvalue_or_temp(sp, ::HIR::CoreType::Usize, ::MIR::RValue( ::MIR::Constant::make_Uint({ re.len, ::HIR::CoreType::Usize }) )); + auto test_val = ::MIR::Param( ::MIR::Constant::make_Uint({ re.len, ::HIR::CoreType::Usize }) ); auto len_val = builder.lvalue_or_temp(sp, ::HIR::CoreType::Usize, ::MIR::RValue::make_DstMeta({ builder.get_ptr_to_dst(sp, val).clone() })); - auto cmp_lval = builder.lvalue_or_temp(sp, ::HIR::CoreType::Bool, ::MIR::RValue::make_BinOp({ mv$(len_val), ::MIR::eBinOp::EQ, mv$(test_lval) })); + auto cmp_lval = builder.lvalue_or_temp(sp, ::HIR::CoreType::Bool, ::MIR::RValue::make_BinOp({ mv$(len_val), ::MIR::eBinOp::EQ, mv$(test_val) })); auto len_succ_bb = builder.new_bb_unlinked(); builder.end_block( ::MIR::Terminator::make_If({ mv$(cmp_lval), len_succ_bb, fail_bb }) ); |