From 319bffddc2e4467fc00efa0a19cf8f2472f3158e Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 10 Sep 2017 22:20:24 +0800 Subject: Const Eval - Evalulate from MIR where possible (avoids BorrowData) --- src/hir_expand/const_eval_full.cpp | 20 ++++++++++++++------ src/trans/codegen_c.cpp | 4 ++-- 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/hir_expand/const_eval_full.cpp b/src/hir_expand/const_eval_full.cpp index b3f5bf1e..4fd10c05 100644 --- a/src/hir_expand/const_eval_full.cpp +++ b/src/hir_expand/const_eval_full.cpp @@ -408,13 +408,21 @@ namespace { // TODO: Monomorph the path? (Not needed... yet) auto ent = get_ent_fullpath(sp, resolve.m_crate, e2.p, EntNS::Value, const_ms); ASSERT_BUG(sp, ent.is_Constant(), "MIR Constant::Const("<m_value_res ); - if( val.is_Invalid() ) { + const auto& c = *ent.as_Constant(); + // Prefer re-evaluating the MIR. + // - Constants insert themselves directly, so this is + // effectively the same thing. + // Avoids _BorrowData leftovers. + if( c.m_value ) { return evaluate_constant(sp, resolve, newval_state, FMT_CB(ss, ss << e2.p;), ent.as_Constant()->m_value, {}, {}); } - // Monomorphise the value according to `const_ms` - monomorph_literal_inplace(sp, val, const_ms); - return val; + else { + auto val = clone_literal( ent.as_Constant()->m_value_res ); + ASSERT_BUG(sp, !val.is_Invalid(), "MIR Constant::Const("<val->is_Deref() ) MIR_TODO(state, "Undo nested deref coercion - " << *p->val); - val = read_lval(*p->val); + val = read_lval(*p->val); } else if( const auto* p = e.val.opt_Static() ) { // Borrow of a static, emit BorrowPath with the same path diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index e8643591..b942dae7 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -1596,7 +1596,7 @@ namespace { m_of << Trans_Mangle( params.monomorph(m_resolve, e)); ), (BorrowData, - MIR_TODO(*m_mir_res, "Handle BorrowData - " << *e); + MIR_TODO(*m_mir_res, "Handle BorrowData (emit_literal) - " << *e); ), (String, m_of << "{ "; @@ -4096,7 +4096,7 @@ namespace { } ), (BorrowData, - MIR_TODO(*m_mir_res, "Handle BorrowData - " << *e); + MIR_TODO(*m_mir_res, "Handle BorrowData (assign_from_literal) - " << *e); ), (String, emit_dst(); m_of << ".PTR = "; -- cgit v1.2.3