summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2017-01-21 18:50:29 +0800
committerJohn Hodge <tpg@mutabah.net>2017-01-21 18:50:29 +0800
commitf3fc3bbcd5d184ce899fa2fba64f38cd6e4ba9b9 (patch)
tree307a30903cad93239a6aa9da6a924411d0ff303d
parentc579e11b9cf7b715932ca944bf372b8c062ecf6c (diff)
downloadmrust-f3fc3bbcd5d184ce899fa2fba64f38cd6e4ba9b9.tar.gz
Typecheck Static - Cache Copy lookups
-rw-r--r--src/hir_typeck/static.cpp23
-rw-r--r--src/hir_typeck/static.hpp3
2 files changed, 24 insertions, 2 deletions
diff --git a/src/hir_typeck/static.cpp b/src/hir_typeck/static.cpp
index c99e606f..ad62d73e 100644
--- a/src/hir_typeck/static.cpp
+++ b/src/hir_typeck/static.cpp
@@ -14,6 +14,8 @@ void StaticTraitResolve::prep_indexes()
TRACE_FUNCTION_F("");
+ m_copy_cache.clear();
+
auto add_equality = [&](::HIR::TypeRef long_ty, ::HIR::TypeRef short_ty){
DEBUG("[prep_indexes] ADD " << long_ty << " => " << short_ty);
// TODO: Sort the two types by "complexity" (most of the time long >= short)
@@ -1199,14 +1201,31 @@ bool StaticTraitResolve::type_is_copy(const Span& sp, const ::HIR::TypeRef& ty)
{
TU_MATCH(::HIR::TypeRef::Data, (ty.m_data), (e),
(Generic,
- return this->iterate_bounds([&](const auto& b) {
+ {
+ auto it = m_copy_cache.find(ty);
+ if( it != m_copy_cache.end() )
+ {
+ DEBUG("Cached " << it->first << " = " << it->second);
+ return it->second;
+ }
+ }
+ bool rv = this->iterate_bounds([&](const auto& b) {
auto pp = ::HIR::PathParams();
return this->find_impl__check_bound(sp, m_lang_Copy, &pp, ty, [&](auto , bool ){ return true; }, b);
});
+ m_copy_cache.insert(::std::make_pair( ty.clone(), rv ));
+ return rv;
),
(Path,
+ {
+ auto it = m_copy_cache.find(ty);
+ if( it != m_copy_cache.end() )
+ return it->second;
+ }
auto pp = ::HIR::PathParams();
- return this->find_impl(sp, m_lang_Copy, &pp, ty, [&](auto , bool){ return true; }, true);
+ bool rv = this->find_impl(sp, m_lang_Copy, &pp, ty, [&](auto , bool){ return true; }, true);
+ m_copy_cache.insert(::std::make_pair( ty.clone(), rv ));
+ return rv;
),
(Diverge,
// The ! type is kinda Copy ...
diff --git a/src/hir_typeck/static.hpp b/src/hir_typeck/static.hpp
index 66a65be5..46dcd1a1 100644
--- a/src/hir_typeck/static.hpp
+++ b/src/hir_typeck/static.hpp
@@ -32,6 +32,9 @@ public:
::HIR::SimplePath m_lang_Box;
::HIR::SimplePath m_lang_PhantomData;
+private:
+ mutable ::std::map< ::HIR::TypeRef, bool > m_copy_cache;
+
public:
StaticTraitResolve(const ::HIR::Crate& crate):
m_crate(crate),