summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/hir_conv/constant_evaluation.cpp6
-rw-r--r--src/trans/monomorphise.cpp4
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) ));
}