summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2019-11-10 18:30:41 +0800
committerJohn Hodge <tpg@mutabah.net>2019-11-10 18:30:41 +0800
commita49bda9adff96a3bb5926ce1d6df8a199224976b (patch)
treeec1be25001986b585f0004be09216d5fcff9a162
parent77606c6ee9bb15e7636517b3063799093241f1c5 (diff)
downloadmrust-a49bda9adff96a3bb5926ce1d6df8a199224976b.tar.gz
HIR Expand - Ensure that all erased types are evaluated before MIR generation
-rw-r--r--src/hir_expand/erased_types.cpp35
-rw-r--r--src/main.cpp9
-rw-r--r--src/mir/check.cpp1
-rw-r--r--src/mir/from_hir.cpp2
-rw-r--r--src/mir/visit_crate_mir.cpp19
5 files changed, 15 insertions, 51 deletions
diff --git a/src/hir_expand/erased_types.cpp b/src/hir_expand/erased_types.cpp
index 22c037f8..13337dab 100644
--- a/src/hir_expand/erased_types.cpp
+++ b/src/hir_expand/erased_types.cpp
@@ -154,37 +154,23 @@ namespace {
::HIR::Visitor::visit_function(p, fcn);
m_fcn_path = nullptr;
}
+ };
+ class OuterVisitor_Fixup:
+ public ::HIR::Visitor
+ {
+ StaticTraitResolve m_resolve;
+ public:
+ OuterVisitor_Fixup(const ::HIR::Crate& crate):
+ m_resolve(crate)
+ {}
void visit_type(::HIR::TypeRef& ty) override
{
static const Span sp;
if( ty.m_data.is_ErasedType() )
{
- //ASSERT_BUG(sp, m_fcn_path, "Erased type outside of a function - " << ty);
-
const auto& e = ty.m_data.as_ErasedType();
- TU_MATCHA( (e.m_origin.m_data), (pe),
- (Generic,
- if( m_fcn_path && *m_fcn_path == pe.m_path ) {
- ::HIR::Visitor::visit_type(ty);
- return ;
- }
- ),
- (UfcsUnknown,
- BUG(sp, "UfcsUnknown unexpected");
- ),
- (UfcsKnown,
- BUG(sp, "UfcsKnown not supported");
- ),
- (UfcsInherent,
- if( m_fcn_path && m_fcn_path->parent && m_fcn_path->parent->ty && !m_fcn_path->parent->trait && *m_fcn_path->parent->ty == *pe.type && m_fcn_path->name == pe.item ) {
- ::HIR::Visitor::visit_type(ty);
- return ;
- }
- )
- )
-
TRACE_FUNCTION_FR(ty, ty);
::HIR::PathParams impl_params;
@@ -213,5 +199,8 @@ void HIR_Expand_ErasedType(::HIR::Crate& crate)
{
OuterVisitor ov(crate);
ov.visit_crate( crate );
+
+ OuterVisitor_Fixup ov_fix(crate);
+ ov_fix.visit_crate(crate);
}
diff --git a/src/main.cpp b/src/main.cpp
index d63d4041..0002e1a8 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -617,15 +617,6 @@ int main(int argc, char *argv[])
MIR_CheckCrate(*hir_crate);
});
- if( params.debug.dump_hir )
- {
- // DUMP after consteval (full HIR again)
- CompilePhaseV("Dump HIR", [&]() {
- ::std::ofstream os (FMT(params.outfile << "_2_hir.rs"));
- HIR_Dump( os, *hir_crate );
- });
- }
-
// - Expand constants in HIR and virtualise calls
CompilePhaseV("MIR Cleanup", [&]() {
MIR_CleanupCrate(*hir_crate);
diff --git a/src/mir/check.cpp b/src/mir/check.cpp
index d159c85f..fde39724 100644
--- a/src/mir/check.cpp
+++ b/src/mir/check.cpp
@@ -276,6 +276,7 @@ void MIR_Validate_ValState(::MIR::TypeResolve& state, const ::MIR::Function& fcn
{
bool rv = false;
assert( a.size() == b.size() );
+ // TODO: This is a really hot bit of code (according to valgrind), need to find a way of cooling it
for(unsigned int i = 0; i < a.size(); i++)
{
rv |= merge_state(a[i], b[i]);
diff --git a/src/mir/from_hir.cpp b/src/mir/from_hir.cpp
index 1c1a9c69..b373e6e0 100644
--- a/src/mir/from_hir.cpp
+++ b/src/mir/from_hir.cpp
@@ -2537,7 +2537,7 @@ namespace {
::MIR::FunctionPointer LowerMIR(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path, const ::HIR::ExprPtr& ptr, const ::HIR::TypeRef& ret_ty, const ::HIR::Function::args_t& args)
{
- TRACE_FUNCTION;
+ TRACE_FUNCTION_F(path);
::MIR::Function fcn;
fcn.locals.reserve(ptr.m_bindings.size());
diff --git a/src/mir/visit_crate_mir.cpp b/src/mir/visit_crate_mir.cpp
index 0bbf20ae..22e77274 100644
--- a/src/mir/visit_crate_mir.cpp
+++ b/src/mir/visit_crate_mir.cpp
@@ -34,24 +34,7 @@ void MIR::OuterVisitor::visit_function(::HIR::ItemPath p, ::HIR::Function& item)
if( item.m_code )
{
DEBUG("Function code " << p);
- // TODO: Get span without needing hir/expr.hpp
- static Span sp;
-
- // Replace ErasedType instances in `ret_type`
- const auto& ret_type = item.m_return;
- auto ret_type_v = clone_ty_with(sp, ret_type, [&](const auto& tpl, auto& rv) {
- if( tpl.m_data.is_ErasedType() )
- {
- const auto& e = tpl.m_data.as_ErasedType();
- assert(e.m_index < item.m_code.m_erased_types.size());
- rv = item.m_code.m_erased_types[e.m_index].clone();
- return true;
- }
- return false;
- });
- this->m_resolve.expand_associated_types(sp, ret_type_v);
-
- m_cb(m_resolve, p, item.m_code, item.m_args, ret_type_v);
+ m_cb(m_resolve, p, item.m_code, item.m_args, item.m_return);
}
}
void MIR::OuterVisitor::visit_static(::HIR::ItemPath p, ::HIR::Static& item)