diff options
author | John Hodge <tpg@mutabah.net> | 2016-12-27 15:07:05 +1100 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-12-27 15:07:05 +1100 |
commit | 6da8fb67c7a3465e2efc64584f688520aa3251b7 (patch) | |
tree | 943b77288dd3994d3f6fcaee26830641f3fbf258 /src/mir/from_hir_match.cpp | |
parent | d1f5cbd543d2e3ae5b1efe3fd432ce9a433bf193 (diff) | |
download | mrust-6da8fb67c7a3465e2efc64584f688520aa3251b7.tar.gz |
MIR Gen - Better handling of split scopes (optional init)
Diffstat (limited to 'src/mir/from_hir_match.cpp')
-rw-r--r-- | src/mir/from_hir_match.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/mir/from_hir_match.cpp b/src/mir/from_hir_match.cpp index 2a9a8dd8..4d61da73 100644 --- a/src/mir/from_hir_match.cpp +++ b/src/mir/from_hir_match.cpp @@ -295,10 +295,13 @@ void MIR_LowerHIR_Match( MirBuilder& builder, MirConverter& conv, ::HIR::ExprNod ac.cond_start = builder.new_bb_unlinked(); builder.set_cur_block( ac.cond_start ); - // TODO: Temp scope. + auto tmp_scope = builder.new_scope_temp(arm.m_cond->span()); conv.visit_node_ptr( arm.m_cond ); ac.cond_lval = builder.get_result_in_lvalue(arm.m_cond->span(), ::HIR::TypeRef(::HIR::CoreType::Bool)); + // NOTE: Terminating the scope slightly early is safe, because the resulting boolean temp isn't invalidated. + builder.terminate_scope( arm.m_code->span(), mv$(tmp_scope) ); ac.cond_end = builder.pause_cur_block(); + // NOTE: Paused so that later code (which knows what the false branch will be) can end it correctly // TODO: What to do with contidionals in the fast model? @@ -312,10 +315,12 @@ void MIR_LowerHIR_Match( MirBuilder& builder, MirConverter& conv, ::HIR::ExprNod // Code DEBUG("-- Body Code"); + ac.code = builder.new_bb_unlinked(); auto tmp_scope = builder.new_scope_temp(arm.m_code->span()); builder.set_cur_block( ac.code ); conv.visit_node_ptr( arm.m_code ); + if( !builder.block_active() && !builder.has_result() ) { DEBUG("Arm diverged"); // Nothing need be done, as the block diverged. @@ -328,7 +333,6 @@ void MIR_LowerHIR_Match( MirBuilder& builder, MirConverter& conv, ::HIR::ExprNod DEBUG("Arm result"); // - Set result auto res = builder.get_result(arm.m_code->span()); - //builder.raise_variables( arm.m_code->span(), res ); builder.push_stmt_assign( arm.m_code->span(), result_val.clone(), mv$(res) ); // - Drop all non-moved values from this scope builder.terminate_scope( arm.m_code->span(), mv$(tmp_scope) ); |