diff options
author | John Hodge <tpg@mutabah.net> | 2016-11-18 23:22:29 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-11-18 23:22:29 +0800 |
commit | 9e88045cd45d4ccdb121c0bc8996fc20cc273416 (patch) | |
tree | b78d2397501b2415816f4831ee9f0aefe421d9e0 /src/hir_expand/closures.cpp | |
parent | ae6ac6e148e895e58c17bddf051768a41669ddf2 (diff) | |
download | mrust-9e88045cd45d4ccdb121c0bc8996fc20cc273416.tar.gz |
HIR Expand ErasedType - Replace non-local erased types in return types
Diffstat (limited to 'src/hir_expand/closures.cpp')
-rw-r--r-- | src/hir_expand/closures.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/hir_expand/closures.cpp b/src/hir_expand/closures.cpp index ccd293af..2523eb68 100644 --- a/src/hir_expand/closures.cpp +++ b/src/hir_expand/closures.cpp @@ -511,6 +511,28 @@ namespace { } }; auto monomorph = [&](const auto& ty){ return monomorphise_type_with(sp, ty, monomorph_cb); }; + auto cb_replace = [&](const auto& tpl, auto& rv) { + if( tpl.m_data.is_Infer() ) { + BUG(sp, ""); + } + else if( tpl.m_data.is_Generic() ) { + rv = monomorph_cb(tpl).clone(); + return true; + } + //else if( tpl.m_data.is_ErasedType() ) { + // const auto& e = tpl.m_data.as_ErasedType(); + // + // // TODO: Share code with + // TODO(sp, "Repalce ErasedType with origin " << e.m_origin << " #" << e.m_index); + // //ASSERT_BUG(sp, e.m_index < fcn_ptr->m_code.m_erased_types.size(), ""); + // //const auto& erased_type_replacement = fcn_ptr->m_code.m_erased_types.at(e.m_index); + // //rv = monomorphise_type_with(sp, erased_type_replacement, monomorph_cb, false); + // //return true; + //} + else { + return false; + } + }; // - Clone the bounds (from both levels) auto monomorph_bound = [&](const ::HIR::GenericBound& b)->auto { @@ -612,14 +634,15 @@ namespace { // - Args ::std::vector< ::HIR::Pattern> args_pat_inner; ::std::vector< ::HIR::TypeRef> args_ty_inner; + for(const auto& arg : node.m_args) { args_pat_inner.push_back( arg.first.clone() ); ev.visit_pattern( args_pat_inner.back() ); - args_ty_inner.push_back( monomorphise_type_with(sp, arg.second, monomorph_cb) ); + args_ty_inner.push_back( clone_ty_with(sp, arg.second, cb_replace) ); } ::HIR::TypeRef args_ty { mv$(args_ty_inner) }; ::HIR::Pattern args_pat { {}, ::HIR::Pattern::Data::make_Tuple({ mv$(args_pat_inner) }) }; - ::HIR::TypeRef ret_type = monomorphise_type_with(sp, node.m_return, monomorph_cb); + ::HIR::TypeRef ret_type = clone_ty_with(sp, node.m_return, cb_replace); DEBUG("args_ty = " << args_ty << ", ret_type = " << ret_type); @@ -634,6 +657,7 @@ namespace { DEBUG("-- Fixing types in signature"); fixup.visit_type( args_ty ); fixup.visit_type( ret_type ); + // TODO: Replace erased types too } // --- |