summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/hir_expand/annotate_value_usage.cpp22
-rw-r--r--src/hir_expand/closures.cpp9
2 files changed, 29 insertions, 2 deletions
diff --git a/src/hir_expand/annotate_value_usage.cpp b/src/hir_expand/annotate_value_usage.cpp
index 5ddfd39b..08c35492 100644
--- a/src/hir_expand/annotate_value_usage.cpp
+++ b/src/hir_expand/annotate_value_usage.cpp
@@ -282,7 +282,27 @@ namespace {
}
void visit(::HIR::ExprNode_CallValue& node) override
{
- auto _ = push_usage( ::HIR::ValueUsage::Move );
+ // TODO: Different usage based on trait.
+ ::HIR::ValueUsage vu = ::HIR::ValueUsage::Borrow;
+ switch( node.m_trait_used )
+ {
+ case ::HIR::ExprNode_CallValue::TraitUsed::Unknown:
+ //TODO(node.span(), "Annotate usage when CallValue trait is unknown");
+ // - Can only happen when the callee is a closure, could do detectection of closure class in this pass?
+ // - Assume Move for now.
+ vu = ::HIR::ValueUsage::Move;
+ break;
+ case ::HIR::ExprNode_CallValue::TraitUsed::Fn:
+ vu = ::HIR::ValueUsage::Borrow;
+ break;
+ case ::HIR::ExprNode_CallValue::TraitUsed::FnMut:
+ vu = ::HIR::ValueUsage::Mutate;
+ break;
+ case ::HIR::ExprNode_CallValue::TraitUsed::FnOnce:
+ vu = ::HIR::ValueUsage::Move;
+ break;
+ }
+ auto _ = push_usage( vu );
this->visit_node_ptr(node.m_value);
for( auto& val : node.m_args )
diff --git a/src/hir_expand/closures.cpp b/src/hir_expand/closures.cpp
index 1faa9401..9ffcf4de 100644
--- a/src/hir_expand/closures.cpp
+++ b/src/hir_expand/closures.cpp
@@ -595,16 +595,19 @@ namespace {
case ::HIR::ValueUsage::Unknown:
BUG(sp, "ValueUsage::Unkown on " << binding_idx);
case ::HIR::ValueUsage::Borrow:
+ DEBUG("Capture by & _#" << binding_idx << " : " << binding_type);
bt = ::HIR::BorrowType::Shared;
capture_nodes.push_back(NEWNODE( ::HIR::TypeRef::new_borrow(bt, cap_ty.clone()), Borrow, sp, bt, mv$(val_node) ));
ty_mono = ::HIR::TypeRef::new_borrow(bt, mv$(ty_mono));
break;
case ::HIR::ValueUsage::Mutate:
+ DEBUG("Capture by &mut _#" << binding_idx << " : " << binding_type);
bt = ::HIR::BorrowType::Unique;
capture_nodes.push_back(NEWNODE( ::HIR::TypeRef::new_borrow(bt, cap_ty.clone()), Borrow, sp, bt, mv$(val_node) ));
ty_mono = ::HIR::TypeRef::new_borrow(bt, mv$(ty_mono));
break;
case ::HIR::ValueUsage::Move:
+ DEBUG("Capture by value _#" << binding_idx << " : " << binding_type);
capture_nodes.push_back( mv$(val_node) );
break;
}
@@ -925,16 +928,18 @@ namespace {
else {
it->second = ::std::max(it->second, usage);
}
- DEBUG("Captured " << slot << " - " << m_variable_types.at(slot));
+ const char* cap_type_name = "?";
switch( usage )
{
case ::HIR::ValueUsage::Unknown:
BUG(sp, "Unknown usage of variable " << slot);
case ::HIR::ValueUsage::Borrow:
+ cap_type_name = "Borrow";
closure.m_class = ::std::max(closure.m_class, ::HIR::ExprNode_Closure::Class::Shared);
break;
case ::HIR::ValueUsage::Mutate:
+ cap_type_name = "Mutate";
closure.m_class = ::std::max(closure.m_class, ::HIR::ExprNode_Closure::Class::Mut);
break;
case ::HIR::ValueUsage::Move:
@@ -942,10 +947,12 @@ namespace {
// closure.m_class = ::std::max(closure.m_class, ::HIR::ExprNode_Closure::Class::Shared);
//}
//else {
+ cap_type_name = "Move";
closure.m_class = ::std::max(closure.m_class, ::HIR::ExprNode_Closure::Class::Once);
//}
break;
}
+ DEBUG("Captured " << slot << " - " << m_variable_types.at(slot) << " :: " << cap_type_name);
}
};