diff options
author | John Hodge <tpg@mutabah.net> | 2016-06-08 23:29:51 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-06-08 23:29:51 +0800 |
commit | b61f4dc10daca6590b526801d971d4a8368062e9 (patch) | |
tree | 2a7cfcf4693983220c801e72b12aa6fc3c9ec9de /src | |
parent | e637dc66e04a587764dbb48a54765c1526dbaa3f (diff) | |
download | mrust-b61f4dc10daca6590b526801d971d4a8368062e9.tar.gz |
HIR Typecheck - Runs fully over libcore, no validation yet
Diffstat (limited to 'src')
-rw-r--r-- | src/hir/hir.cpp | 8 | ||||
-rw-r--r-- | src/hir/type.cpp | 4 | ||||
-rw-r--r-- | src/hir_typeck/expr.cpp | 19 |
3 files changed, 22 insertions, 9 deletions
diff --git a/src/hir/hir.cpp b/src/hir/hir.cpp index dc0aca0a..1dce63f8 100644 --- a/src/hir/hir.cpp +++ b/src/hir/hir.cpp @@ -32,9 +32,10 @@ namespace HIR { namespace { bool matches_type_int(const ::HIR::GenericParams& params, const ::HIR::TypeRef& left, const ::HIR::TypeRef& right_in, ::HIR::t_cb_resolve_type ty_res) { - //DEBUG("left = " << left << ", right = " << right); assert(! left.m_data.is_Infer() ); - const auto& right = (right_in.m_data.is_Infer() ? ty_res(right_in) : right_in); + const auto& right = (right_in.m_data.is_Infer() || right_in.m_data.is_Generic() ? ty_res(right_in) : right_in); + + //DEBUG("left = " << left << ", right = " << right); // TODO: What indicates what out of ty_res? @@ -42,6 +43,9 @@ namespace { // TODO: Why is this false? A _ type could match anything return false; } + if( right.m_data.is_Generic() ) { + return left.m_data.is_Generic(); + } if( left.m_data.is_Generic() ) { // True? (TODO: Check bounds?) diff --git a/src/hir/type.cpp b/src/hir/type.cpp index f3ba220f..d324bc57 100644 --- a/src/hir/type.cpp +++ b/src/hir/type.cpp @@ -416,6 +416,7 @@ namespace { } ::HIR::TypeRef::Compare HIR::TypeRef::compare_with_paceholders(const Span& sp, const ::HIR::TypeRef& x, ::std::function<const ::HIR::TypeRef&(const ::HIR::TypeRef&)> resolve_placeholder) const { + TRACE_FUNCTION_F(*this << " ?= " << x); assert( !this->m_data.is_Infer() ); const auto& right = (x.m_data.is_Infer() ? resolve_placeholder(x) : (x.m_data.is_Generic() ? resolve_placeholder(x) : x)); @@ -460,6 +461,9 @@ namespace { throw ""; ) + // If righthand is a type parameter, it can only match another type parameter + // - See `(Generic,` below + if( this->m_data.tag() != right.m_data.tag() ) { return Compare::Unequal; } diff --git a/src/hir_typeck/expr.cpp b/src/hir_typeck/expr.cpp index 987b3789..043456e0 100644 --- a/src/hir_typeck/expr.cpp +++ b/src/hir_typeck/expr.cpp @@ -1001,18 +1001,24 @@ namespace { equality_typeparams(lpe.m_params, rpe.m_params); ), (UfcsInherent, - this->apply_equality(sp, *lpe.type, cb_left, *rpe.type, cb_right, nullptr); equality_typeparams(lpe.params, rpe.params); + if( lpe.item != rpe.item ) + ERROR(sp, E0000, "Type mismatch between " << l_t << " and " << r_t); + this->apply_equality(sp, *lpe.type, cb_left, *rpe.type, cb_right, nullptr); ), (UfcsKnown, - this->apply_equality(sp, *lpe.type, cb_left, *rpe.type, cb_right, nullptr); 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->apply_equality(sp, *lpe.type, cb_left, *rpe.type, cb_right, nullptr); ), (UfcsUnknown, - this->apply_equality(sp, *lpe.type, cb_left, *rpe.type, cb_right, nullptr); // TODO: If the type is fully known, locate a suitable trait item equality_typeparams(lpe.params, rpe.params); + if( lpe.item != rpe.item ) + ERROR(sp, E0000, "Type mismatch between " << l_t << " and " << r_t); + this->apply_equality(sp, *lpe.type, cb_left, *rpe.type, cb_right, nullptr); ) ) ), @@ -1156,7 +1162,7 @@ namespace { return true; } else { - DEBUG("- Bound " << type << " : " << trait << " failed"); + DEBUG("- Bound " << type << " ("<<placeholder(type)<<") : " << trait << " failed"); return false; } } @@ -1226,13 +1232,13 @@ namespace { impl_args.resize( impl.m_params.m_types.size() ); // - Match with `Self` auto cb_res = [&](unsigned int slot, const ::HIR::TypeRef& ty) { - DEBUG("Set " << slot << " = " << ty); + DEBUG("- Set " << slot << " = " << ty); if( slot >= impl_args.size() ) { BUG(sp, "Impl parameter out of range - " << slot); } auto& slot_r = impl_args.at(slot); if( slot_r != nullptr ) { - DEBUG("- Match " << slot_r << " == " << ty); + DEBUG("TODO: Match " << slot_r << " == " << ty << " when encountered twice"); } else { slot_r = &ty; @@ -1261,7 +1267,6 @@ namespace { (TraitBound, if( !this->check_trait_bound(sp, be.type, be.trait.m_path, expand_placeholder) ) { - DEBUG("- Bound " << be.type << " : " << be.trait.m_path << " failed"); return false; } ) |