diff options
author | John Hodge <tpg@ucc.asn.au> | 2019-05-11 20:35:31 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2019-05-11 20:35:31 +0800 |
commit | 1345b89c88d32fed62df16e492e18bcf7ded477c (patch) | |
tree | 6a98cdf15b2b0a45d62084107560ff32c7d91c5d /src | |
parent | 20ecad6f1d3b70b199486876dc804c4850cf5fdb (diff) | |
download | mrust-1345b89c88d32fed62df16e492e18bcf7ded477c.tar.gz |
HIR Const Eval - Use cached monomorphsed values in consteval, evaluate in reverse
Diffstat (limited to 'src')
-rw-r--r-- | src/hir_conv/constant_evaluation.cpp | 6 | ||||
-rw-r--r-- | src/trans/monomorphise.cpp | 4 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/hir_conv/constant_evaluation.cpp b/src/hir_conv/constant_evaluation.cpp index 0ccb6e6f..22909cdc 100644 --- a/src/hir_conv/constant_evaluation.cpp +++ b/src/hir_conv/constant_evaluation.cpp @@ -414,6 +414,12 @@ namespace HIR { //check_lit_type(item.m_value->span(), item.m_type, item.m_value_res); } + auto it = c.m_monomorph_cache.find(*e2.p); + if( it != c.m_monomorph_cache.end() ) + { + MIR_ASSERT(state, !it->second.is_Defer(), "Cached literal for " << *e2.p << " is Defer"); + return clone_literal( it->second ); + } return clone_literal( c.m_value_res ); } TU_ARM(c, ItemAddr, e2) diff --git a/src/trans/monomorphise.cpp b/src/trans/monomorphise.cpp index 50924e2f..6c331d9c 100644 --- a/src/trans/monomorphise.cpp +++ b/src/trans/monomorphise.cpp @@ -376,7 +376,8 @@ void Trans_Monomorphise_List(const ::HIR::Crate& crate, TransList& list) } // Also do constants and statics (stored in where?) - for(auto& ent : list.m_constants) + // - NOTE: Done in reverse order, because consteval needs used constants to be evaluated + for(auto& ent : reverse(list.m_constants)) { const auto& path = ent.first; const auto& pp = ent.second->pp; @@ -396,6 +397,7 @@ void Trans_Monomorphise_List(const ::HIR::Crate& crate, TransList& list) ms.pp_impl = &pp.pp_impl; ms.pp_method = &pp.pp_method; auto new_lit = eval.evaluate_constant(path, c.m_value, ::std::move(ty), ::std::move(ms)); + ASSERT_BUG(Span(), !new_lit.is_Defer(), "Result of evaluating " << path << " was still Defer"); // 2. Store evaluated HIR::Literal in c.m_monomorph_cache c.m_monomorph_cache.insert(::std::make_pair( path.clone(), ::std::move(new_lit) )); } |