diff options
author | John Hodge <tpg@ucc.asn.au> | 2019-06-30 13:49:18 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2019-06-30 13:49:18 +0800 |
commit | cb11800ea4a8a542c2a0667870ab3730e2b8b9df (patch) | |
tree | e5925150520fad1ce6205dac9e1404713fdd29c7 /src | |
parent | 5cc6c39bf0a91b12814975fa92124d17383446a1 (diff) | |
download | mrust-cb11800ea4a8a542c2a0667870ab3730e2b8b9df.tar.gz |
HIR Typecheck - Cache drop glue presence
Diffstat (limited to 'src')
-rw-r--r-- | src/hir_typeck/static.cpp | 33 | ||||
-rw-r--r-- | src/hir_typeck/static.hpp | 1 |
2 files changed, 27 insertions, 7 deletions
diff --git a/src/hir_typeck/static.cpp b/src/hir_typeck/static.cpp index 1537d674..ff085ac6 100644 --- a/src/hir_typeck/static.cpp +++ b/src/hir_typeck/static.cpp @@ -2042,10 +2042,19 @@ bool StaticTraitResolve::type_needs_drop_glue(const Span& sp, const ::HIR::TypeR return false; } + auto it = m_drop_cache.find(ty); + if( it != m_drop_cache.end() ) + { + return it->second; + } + auto pp = ::HIR::PathParams(); bool has_direct_drop = this->find_impl(sp, m_lang_Drop, &pp, ty, [&](auto , bool){ return true; }, true); if( has_direct_drop ) + { + m_drop_cache.insert(::std::make_pair(ty.clone(), true)); return true; + } ::HIR::TypeRef tmp_ty; const auto& pe = e.path.m_data.as_Generic(); @@ -2060,6 +2069,7 @@ bool StaticTraitResolve::type_needs_drop_glue(const Span& sp, const ::HIR::TypeR return tpl; } }; + bool needs_drop_glue = false; TU_MATCHA( (e.binding), (pbe), (Unbound, BUG(sp, "Unbound path"); @@ -2076,18 +2086,23 @@ bool StaticTraitResolve::type_needs_drop_glue(const Span& sp, const ::HIR::TypeR for(const auto& e : se) { if( type_needs_drop_glue(sp, monomorph(e.ent)) ) - return true; + { + needs_drop_glue = true; + break; + } } ), (Named, for(const auto& e : se) { if( type_needs_drop_glue(sp, monomorph(e.second.ent)) ) - return true; + { + needs_drop_glue = true; + break; + } } ) ) - return false; ), (Enum, if(const auto* e = pbe->m_data.opt_Data()) @@ -2095,20 +2110,24 @@ bool StaticTraitResolve::type_needs_drop_glue(const Span& sp, const ::HIR::TypeR for(const auto& var : *e) { if( type_needs_drop_glue(sp, monomorph(var.type)) ) - return true; + { + needs_drop_glue = true; + break; + } } } - return false; ), (Union, // Unions don't have drop glue unless they impl Drop - return false; + needs_drop_glue = false; ), (ExternType, // Extern types don't have drop glue - return false; + needs_drop_glue = false; ) ) + m_drop_cache.insert(::std::make_pair(ty.clone(), needs_drop_glue)); + return needs_drop_glue; ), (Diverge, return false; diff --git a/src/hir_typeck/static.hpp b/src/hir_typeck/static.hpp index 781db3b3..4ed72ce6 100644 --- a/src/hir_typeck/static.hpp +++ b/src/hir_typeck/static.hpp @@ -36,6 +36,7 @@ public: private: mutable ::std::map< ::HIR::TypeRef, bool > m_copy_cache; mutable ::std::map< ::HIR::TypeRef, bool > m_clone_cache; + mutable ::std::map< ::HIR::TypeRef, bool > m_drop_cache; public: StaticTraitResolve(const ::HIR::Crate& crate): |