From 67ce86fd06cee81d3f875da09eb1a2d9b48edbbf Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 8 Sep 2017 17:13:55 +0800 Subject: MIR Gen - Fix box drop flags --- src/mir/mir.cpp | 2 +- src/mir/mir_builder.cpp | 22 +++------------------- src/mir/optimise.cpp | 13 ++++++++++--- 3 files changed, 14 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/mir/mir.cpp b/src/mir/mir.cpp index 09e978f9..6af64001 100644 --- a/src/mir/mir.cpp +++ b/src/mir/mir.cpp @@ -490,7 +490,7 @@ namespace MIR { if(e.kind == ::MIR::eDropKind::SHALLOW) os << " SHALLOW"; if(e.flag_idx != ~0u) - os << "IF df$" << e.flag_idx; + os << " IF df$" << e.flag_idx; os << ")"; ), (ScopeEnd, diff --git a/src/mir/mir_builder.cpp b/src/mir/mir_builder.cpp index 97942ba2..1e72282a 100644 --- a/src/mir/mir_builder.cpp +++ b/src/mir/mir_builder.cpp @@ -2033,27 +2033,11 @@ VarState& MirBuilder::get_val_state_mut(const Span& sp, const ::MIR::LValue& lv) if( is_box ) { - ::MIR::LValue inner_lv; - // 1. If the inner lvalue isn't a slot with move information, move out of the lvalue into a temporary (with standard temp scope) - TU_MATCH_DEF( ::MIR::LValue, (*e.val), (ei), - ( - with_val_type(sp, *e.val, [&](const auto& ty){ inner_lv = this->new_temporary(ty); }); - this->push_stmt_assign(sp, inner_lv.clone(), ::MIR::RValue( mv$(*e.val) )); - *e.val = inner_lv.clone(); - ), - (Argument, - inner_lv = ::MIR::LValue(ei); - ), - (Local, - inner_lv = ::MIR::LValue(ei); - ) - ) - // 2. Mark the slot as requiring only a shallow drop - ::std::vector inner; - inner.push_back(VarState::make_Valid({})); - auto& ivs = get_val_state_mut(sp, inner_lv); + auto& ivs = get_val_state_mut(sp, *e.val); if( ! ivs.is_MovedOut() ) { + ::std::vector inner; + inner.push_back(VarState::make_Valid({})); unsigned int drop_flag = (ivs.is_Optional() ? ivs.as_Optional() : ~0u); ivs = VarState::make_MovedOut({ box$(VarState::make_Valid({})), drop_flag }); } diff --git a/src/mir/optimise.cpp b/src/mir/optimise.cpp index 34a516de..d99c5b7c 100644 --- a/src/mir/optimise.cpp +++ b/src/mir/optimise.cpp @@ -24,7 +24,7 @@ #define DUMP_AFTER_PASS 1 #define DUMP_AFTER_DONE 0 -#define CHECK_AFTER_DONE 1 +#define CHECK_AFTER_DONE 2 // 1 = Check before GC, 2 = check before and after GC namespace { ::MIR::BasicBlockId get_new_target(const ::MIR::TypeResolve& state, ::MIR::BasicBlockId bb) @@ -520,6 +520,10 @@ void MIR_OptimiseMin(const StaticTraitResolve& resolve, const ::HIR::ItemPath& p MIR_Optimise_GarbageCollect(state, fcn); //MIR_Validate_Full(resolve, path, fcn, args, ret_type); MIR_SortBlocks(resolve, path, fcn); + +#if CHECK_AFTER_DONE > 1 + MIR_Validate(resolve, path, fcn, args, ret_type); +#endif return ; } void MIR_Optimise(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path, ::MIR::Function& fcn, const ::HIR::Function::args_t& args, const ::HIR::TypeRef& ret_type) @@ -631,6 +635,9 @@ void MIR_Optimise(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path //MIR_Validate_Full(resolve, path, fcn, args, ret_type); MIR_SortBlocks(resolve, path, fcn); +#if CHECK_AFTER_DONE > 1 + MIR_Validate(resolve, path, fcn, args, ret_type); +#endif } // -------------------------------------------------------------------- @@ -2720,11 +2727,11 @@ bool MIR_Optimise_GarbageCollect(::MIR::TypeResolve& state, ::MIR::Function& fcn if( se->flag_idx != ~0u && df_rewrite_table[se->flag_idx] == ~0u) { if( fcn.drop_flags.at(se->flag_idx) ) { - DEBUG(state << "Remove flag from " << stmt); + DEBUG(state << "Remove flag from " << stmt << " - Flag never set and default true"); se->flag_idx = ~0u; } else { - DEBUG(state << "Remove " << stmt); + DEBUG(state << "Remove " << stmt << " - Flag never set and default false"); to_remove_statements[stmt_idx] = true; continue ; } -- cgit v1.2.3