summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-08-17 18:32:39 +0800
committerJohn Hodge <tpg@mutabah.net>2016-08-17 18:32:39 +0800
commit83dbbbf519677dac24a6eac3c2ef2c95894db501 (patch)
tree79179c114d3dd7fb22c42a3dc6d351ec5e990bc8
parent2d3e89a56b91ba2a21f887da7e4eb1ba7e750626 (diff)
downloadmrust-83dbbbf519677dac24a6eac3c2ef2c95894db501.tar.gz
MIR Gen - Planning for inserting drops
-rw-r--r--Notes/MIR.md7
-rw-r--r--src/mir/from_hir.cpp10
2 files changed, 16 insertions, 1 deletions
diff --git a/Notes/MIR.md b/Notes/MIR.md
index 9e7a780f..4357d764 100644
--- a/Notes/MIR.md
+++ b/Notes/MIR.md
@@ -56,4 +56,11 @@ Drop Scopes
- Standard scoped definitions (e.g. blocks) - Where the runtime scope and the generator's stack frame correspond
- Deferred scope completion (e.g. within match codegen)
- Generated drops for panic cleanup.
+ - Would want to track moves within sub-blocks (i.e. if/match arms)
+- Ideas
+ - Scope IDs passed to terminator construction.
+ - RAII guards to ensure that a constructed scope is dropped (and all child scopes are terminated before it is)
+ - Scopes contain child scopes (started within them)
+ - Special named scope for the entire function.
+ - For match, scope handles can be passed around
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp
index d8bcd49c..b8953fec 100644
--- a/src/mir/from_hir.cpp
+++ b/src/mir/from_hir.cpp
@@ -196,6 +196,8 @@ namespace {
this->visit_node_ptr(node.m_value);
m_builder.push_stmt_assign( ::MIR::LValue::make_Return({}), m_builder.get_result(node.span()) );
+ // TODO: Insert drop of all current scopes
+ //terminate_scope_early( 0 );
m_builder.end_block( ::MIR::Terminator::make_Return({}) );
}
void visit(::HIR::ExprNode_Let& node) override
@@ -212,6 +214,7 @@ namespace {
void visit(::HIR::ExprNode_Loop& node) override
{
TRACE_FUNCTION_F("_Loop");
+ //auto loop_body_scope = m_builder.new_scope(node.span()); // TODO: Does loop actually need a scope? It usually contains a block.
auto loop_block = m_builder.new_bb_linked();
auto loop_next = m_builder.new_bb_unlinked();
@@ -231,6 +234,7 @@ namespace {
// Terminate block with a jump back to the start
if( m_builder.block_active() )
{
+ // TODO: Insert drop of all scopes within the current scope
m_builder.end_block( ::MIR::Terminator::make_Goto(loop_block) );
}
m_builder.set_cur_block(loop_next);
@@ -251,6 +255,8 @@ namespace {
target_block = &*it;
}
+ // TODO: Insert drop of all active scopes within the loop
+ //terminate_scope_early( target_block->scope );
if( node.m_continue ) {
m_builder.end_block( ::MIR::Terminator::make_Goto(target_block->cur) );
}
@@ -299,6 +305,7 @@ namespace {
if( m_builder.block_active() )
{
m_builder.push_stmt_assign( result_val.clone(), m_builder.get_result(node.m_true->span()) );
+ // TODO: Emit drops for all variables defined within this branch. (Needed? The inner should handle that)
m_builder.end_block( ::MIR::Terminator::make_Goto(next_block) );
}
@@ -309,6 +316,7 @@ namespace {
if( m_builder.block_active() )
{
m_builder.push_stmt_assign( result_val.clone(), m_builder.get_result(node.m_false->span()) );
+ // TODO: Emit drops for all variables defined within this branch.
m_builder.end_block( ::MIR::Terminator::make_Goto(next_block) );
}
}
@@ -923,7 +931,7 @@ namespace {
}));
m_builder.set_cur_block(panic_block);
- // TODO: Proper panic handling
+ // TODO: Proper panic handling, including scope destruction
m_builder.end_block( ::MIR::Terminator::make_Diverge({}) );
m_builder.set_cur_block( next_block );