summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-12-10 14:39:57 +0800
committerJohn Hodge <tpg@mutabah.net>2016-12-10 14:40:22 +0800
commit19ed45d6273199af5c1b2f9fa142237709108d30 (patch)
tree70362c66789ca55d88a06b1716097c03d527b712 /src
parent00c5eed2172d9f3e642a809343a527bf8de5fa0d (diff)
downloadmrust-19ed45d6273199af5c1b2f9fa142237709108d30.tar.gz
MIR Cleanup - Convert fn() calls to by-value
Diffstat (limited to 'src')
-rw-r--r--src/hir_typeck/static.hpp2
-rw-r--r--src/mir/cleanup.cpp22
2 files changed, 23 insertions, 1 deletions
diff --git a/src/hir_typeck/static.hpp b/src/hir_typeck/static.hpp
index 1fd1d51c..11de2970 100644
--- a/src/hir_typeck/static.hpp
+++ b/src/hir_typeck/static.hpp
@@ -21,7 +21,7 @@ public:
::std::map< ::HIR::TypeRef, ::HIR::TypeRef> m_type_equalities;
-private:
+
::HIR::SimplePath m_lang_Copy;
::HIR::SimplePath m_lang_Sized;
::HIR::SimplePath m_lang_Fn;
diff --git a/src/mir/cleanup.cpp b/src/mir/cleanup.cpp
index f921d655..787028c1 100644
--- a/src/mir/cleanup.cpp
+++ b/src/mir/cleanup.cpp
@@ -751,6 +751,28 @@ void MIR_Cleanup(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path,
e.fcn = mv$(tgt_lvalue);
}
}
+
+ if( path.m_data.is_UfcsKnown() && path.m_data.as_UfcsKnown().type->m_data.is_Function() )
+ {
+ const auto& pe = path.m_data.as_UfcsKnown();
+ const auto& fcn_ty = pe.type->m_data.as_Function();
+ if( pe.trait.m_path == resolve.m_lang_Fn || pe.trait.m_path == resolve.m_lang_FnMut || pe.trait.m_path == resolve.m_lang_FnOnce )
+ {
+ MIR_ASSERT(state, e.args.size() == 2, "Fn* call requires two arguments");
+ auto fcn_lvalue = mv$(e.args[0]);
+ auto args_lvalue = mv$(e.args[1]);
+
+ DEBUG("Convert function pointer call");
+
+ e.args.clear();
+ e.args.reserve( fcn_ty.m_arg_types.size() );
+ for(unsigned int i = 0; i < fcn_ty.m_arg_types.size(); i ++)
+ {
+ e.args.push_back( ::MIR::LValue::make_Field({ box$(args_lvalue.clone()), i }) );
+ }
+ e.fcn = mv$(fcn_lvalue);
+ }
+ }
)
)