diff options
author | John Hodge <tpg@mutabah.net> | 2016-07-16 16:45:51 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-07-16 16:45:51 +0800 |
commit | b9543cd50d06c3478987cf3ab6ea4215fd9124e6 (patch) | |
tree | dbdba7e0d16575fcd2e48236de6c074451b7030b /src | |
parent | ae0dbea6b5d416dbae9f50a594d23d1ceebccccf (diff) | |
download | mrust-b9543cd50d06c3478987cf3ab6ea4215fd9124e6.tar.gz |
HIR Typecheck CS - Reduce log spam
Diffstat (limited to 'src')
-rw-r--r-- | src/hir/path.cpp | 4 | ||||
-rw-r--r-- | src/hir/path.hpp | 2 | ||||
-rw-r--r-- | src/hir_typeck/expr_cs.cpp | 31 | ||||
-rw-r--r-- | src/hir_typeck/helpers.cpp | 1 |
4 files changed, 23 insertions, 15 deletions
diff --git a/src/hir/path.cpp b/src/hir/path.cpp index 6a7e00f7..b66cb26b 100644 --- a/src/hir/path.cpp +++ b/src/hir/path.cpp @@ -184,6 +184,10 @@ bool ::HIR::TraitPath::operator==(const ::HIR::TraitPath& x) const m_data( ::HIR::Path::Data::make_Generic(::HIR::GenericPath(mv$(sp))) ) { } +::HIR::Path::Path(TypeRef ty, GenericPath trait, ::std::string item, PathParams item_params): + m_data( Data::make_UfcsKnown({ box$(mv$(ty)), mv$(trait), mv$(item), mv$(item_params) }) ) +{ +} ::HIR::Path HIR::Path::clone() const { TU_MATCH(Data, (m_data), (e), diff --git a/src/hir/path.hpp b/src/hir/path.hpp index 9ec75522..59b5f111 100644 --- a/src/hir/path.hpp +++ b/src/hir/path.hpp @@ -161,6 +161,8 @@ public: Path(GenericPath _); Path(SimplePath _); + Path(TypeRef ty, GenericPath trait, ::std::string item, PathParams item_params=PathParams()); + Path clone() const; Compare compare_with_placeholders(const Span& sp, const Path& x, t_cb_resolve_type resolve_placeholder) const; diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index 668d2b9d..7b304f9d 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -1855,8 +1855,9 @@ void Context::dump() const { void Context::equate_types(const Span& sp, const ::HIR::TypeRef& li, const ::HIR::TypeRef& ri) { // Instantly apply equality + TRACE_FUNCTION_F(li << " == " << ri); - // TODO: Check if the type contains a replacable associated type + // Check if the type contains a replacable associated type ::HIR::TypeRef l_tmp; ::HIR::TypeRef r_tmp; const auto& l_t = this->m_resolve.expand_associated_types(sp, this->m_ivars.get_type(li), l_tmp); @@ -1900,30 +1901,26 @@ void Context::equate_types(const Span& sp, const ::HIR::TypeRef& li, const ::HIR ) // - If the destructuring would fail - if( l_t.compare_with_placeholders(sp, r_t, this->m_ivars.callback_resolve_infer()) == ::HIR::Compare::Unequal ) - { + //if( l_t.compare_with_placeholders(sp, r_t, this->m_ivars.callback_resolve_infer()) == ::HIR::Compare::Unequal ) + //{ // BUT! It was due to an unknown associated type TU_IFLET(::HIR::TypeRef::Data, r_t.m_data, Path, r_e, TU_IFLET(::HIR::Path::Data, r_e.path.m_data, UfcsKnown, rpe, if( r_e.binding.is_Unbound() ) { - // TODO: Try this operation again later? this->equate_types_assoc(sp, l_t, rpe.trait.m_path, rpe.trait.m_params.clone().m_types, *rpe.type, rpe.item.c_str()); return ; - //TODO(sp, "Defer structural equality of unknown associated type"); } ) ) TU_IFLET(::HIR::TypeRef::Data, l_t.m_data, Path, l_e, TU_IFLET(::HIR::Path::Data, l_e.path.m_data, UfcsKnown, lpe, if( l_e.binding.is_Unbound() ) { - // TODO: Try this operation again later? this->equate_types_assoc(sp, r_t, lpe.trait.m_path, lpe.trait.m_params.clone().m_types, *lpe.type, lpe.item.c_str()); return ; - //TODO(sp, "Defer structural equality of unknown associated type"); } ) ) - } + //} if( l_t.m_data.tag() != r_t.m_data.tag() ) { ERROR(sp, E0000, "Type mismatch between " << this->m_ivars.fmt_type(l_t) << " and " << this->m_ivars.fmt_type(r_t)); @@ -1958,10 +1955,10 @@ void Context::equate_types(const Span& sp, const ::HIR::TypeRef& li, const ::HIR this->equate_types(sp, *lpe.type, *rpe.type); ), (UfcsKnown, + if( lpe.trait.m_path != rpe.trait.m_path || lpe.item != rpe.item ) + ERROR(sp, E0000, "Type mismatch between " << l_t << " and " << r_t); equality_typeparams(lpe.trait.m_params, rpe.trait.m_params); equality_typeparams(lpe.params, rpe.params); - if( lpe.item != rpe.item ) - ERROR(sp, E0000, "Type mismatch between " << l_t << " and " << r_t); this->equate_types(sp, *lpe.type, *rpe.type); ), (UfcsUnknown, @@ -2455,7 +2452,7 @@ void Context::equate_types_assoc(const Span& sp, const ::HIR::TypeRef& l, const name, is_op }); - DEBUG("equate_types_assoc(" << this->link_assoc.back() << ")"); + DEBUG("(" << this->link_assoc.back() << ")"); this->m_ivars.mark_change(); } void Context::add_revisit(::HIR::ExprNode& node) { @@ -3025,9 +3022,13 @@ namespace { DEBUG("- (fail) bounded impl " << v.trait << v.params << " (ty_right = " << context.m_ivars.fmt_type(v.impl_ty)); return false; } - if( v.name != "" && assoc.count(v.name) == 0 ) - BUG(sp, "Getting associated type '" << v.name << "' which isn't in " << v.trait); - const auto& out_ty = (v.name == "" ? v.left_ty : assoc.at(v.name)); + ::HIR::TypeRef out_ty_o; + if( v.name != "" && assoc.count(v.name) == 0 ) { + auto ty1 = ::HIR::TypeRef( ::HIR::Path(::HIR::Path( v.impl_ty.clone(), ::HIR::GenericPath(v.trait, v.params.clone()), v.name, ::HIR::PathParams() )) ); + out_ty_o = context.m_resolve.expand_associated_types(sp, mv$(ty1)); + //BUG(sp, "Getting associated type '" << v.name << "' which isn't in " << v.trait << " (" << ty << ")"); + } + const auto& out_ty = (v.name == "" ? v.left_ty : (out_ty_o == ::HIR::TypeRef() ? assoc.at(v.name) : out_ty_o)); // - If we're looking for an associated type, allow it to eliminate impossible impls // > This makes `let v: usize = !0;` work without special cases @@ -3038,7 +3039,7 @@ namespace { return false; } // if solid or fuzzy, leave as-is - output_type = assoc.at(v.name).clone(); + output_type = out_ty.clone(); } count += 1; if( cmp == ::HIR::Compare::Equal ) { diff --git a/src/hir_typeck/helpers.cpp b/src/hir_typeck/helpers.cpp index 3af93ac9..a66a6f84 100644 --- a/src/hir_typeck/helpers.cpp +++ b/src/hir_typeck/helpers.cpp @@ -1586,6 +1586,7 @@ bool TraitResolution::find_trait_impls_bound(const Span& sp, const ::HIR::Simple DEBUG("Fuzzy match"); } // Hand off to the closure, and return true if it does + // TODO: The type bounds are only the types that are specified. if( callback(e.type, e.trait.m_path.m_params, e.trait.m_type_bounds) ) { return true; } |