summaryrefslogtreecommitdiff
path: root/src/hir
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-06-08 09:25:20 +0800
committerJohn Hodge <tpg@mutabah.net>2016-06-08 09:25:20 +0800
commit1ad65688d231ddee98ebf8425f45eba305f324f7 (patch)
tree1ea71b20215b9f049efb96e2a0ae41f0debb8ad6 /src/hir
parent54a3d0f37aa0c9994a4a39ab5245826119d414de (diff)
downloadmrust-1ad65688d231ddee98ebf8425f45eba305f324f7.tar.gz
HIR Typecheck - Rough checking of bounds when searching for UFCS
Diffstat (limited to 'src/hir')
-rw-r--r--src/hir/hir.hpp2
-rw-r--r--src/hir/type.cpp64
-rw-r--r--src/hir/type.hpp6
3 files changed, 57 insertions, 15 deletions
diff --git a/src/hir/hir.hpp b/src/hir/hir.hpp
index c6dec6c8..3447aaa0 100644
--- a/src/hir/hir.hpp
+++ b/src/hir/hir.hpp
@@ -204,8 +204,6 @@ TAGGED_UNION(ValueItem, Import,
// --------------------------------------------------------------------
-typedef ::std::function<const ::HIR::TypeRef&(const ::HIR::TypeRef&)> t_cb_resolve_type;
-
class TypeImpl
{
public:
diff --git a/src/hir/type.cpp b/src/hir/type.cpp
index dfaf9d1d..e4931dbf 100644
--- a/src/hir/type.cpp
+++ b/src/hir/type.cpp
@@ -241,17 +241,38 @@ bool ::HIR::TypeRef::operator==(const ::HIR::TypeRef& x) const
)
throw "";
}
-void ::HIR::TypeRef::match_generics(const Span& sp, const ::HIR::TypeRef& x, ::std::function<void(unsigned int, const ::HIR::TypeRef&)> callback) const
+
+
+typedef ::std::function<void(unsigned int, const ::HIR::TypeRef&)> t_cb_match_generics;
+
+namespace {
+ bool match_generics_pp(const Span& sp, const ::HIR::PathParams& t, const ::HIR::PathParams& x, ::HIR::t_cb_resolve_type resolve_placeholder, t_cb_match_generics callback)
+ {
+ if( t.m_types.size() != x.m_types.size() ) {
+ return false;
+ }
+
+ for(unsigned int i = 0; i < t.m_types.size(); i ++ )
+ {
+ t.m_types[i].match_generics( sp, x.m_types[i], resolve_placeholder, callback );
+ }
+
+ return true;
+ }
+}
+
+void ::HIR::TypeRef::match_generics(const Span& sp, const ::HIR::TypeRef& x_in, t_cb_resolve_type resolve_placeholder, t_cb_match_generics callback) const
{
if( m_data.is_Infer() ) {
- BUG(sp, "");
+ BUG(sp, "Encountered '_' as this - " << *this);
}
if( m_data.is_Generic() ) {
- callback(m_data.as_Generic().binding, x);
+ callback(m_data.as_Generic().binding, x_in);
return ;
}
+ const auto& x = (x_in.m_data.is_Infer() || x_in.m_data.is_Generic() ? resolve_placeholder(x_in) : x_in);
if( m_data.tag() != x.m_data.tag() ) {
- BUG(sp, "");
+ BUG(sp, "TypeRef::match_generics with mismatched forms - " << *this << " and " << x);
}
TU_MATCH(::HIR::TypeRef::Data, (m_data, x.m_data), (te, xe),
(Infer, throw "";),
@@ -261,29 +282,50 @@ void ::HIR::TypeRef::match_generics(const Span& sp, const ::HIR::TypeRef& x, ::s
(Diverge,
),
(Path,
- TODO(sp, "Path");
+ if( te.path.m_data.tag() != xe.path.m_data.tag() ) {
+ BUG(sp, "TypeRef::match_generics with mismatched forms - " << *this << " and " << x);
+ }
+ TU_MATCH(::HIR::Path::Data, (te.path.m_data, xe.path.m_data), (tpe, xpe),
+ (Generic,
+ if( tpe.m_path != xpe.m_path ) {
+ BUG(sp, "TypeRef::match_generics with mismatched forms - " << *this << " and " << x);
+ }
+ if( !match_generics_pp(sp, tpe.m_params, xpe.m_params, resolve_placeholder, callback) ) {
+ BUG(sp, "TypeRef::match_generics with mismatched forms - " << *this << " and " << x);
+ }
+ ),
+ (UfcsKnown,
+ TODO(sp, "Path UfcsKnown - " << *this << " and " << x);
+ ),
+ (UfcsUnknown,
+ TODO(sp, "Path UfcsUnknown - " << *this << " and " << x);
+ ),
+ (UfcsInherent,
+ TODO(sp, "Path UfcsInherent - " << *this << " and " << x);
+ )
+ )
),
(TraitObject,
TODO(sp, "TraitObject");
),
(Array,
- te.inner->match_generics( sp, *xe.inner, callback );
+ te.inner->match_generics( sp, *xe.inner, resolve_placeholder, callback );
),
(Slice,
- te.inner->match_generics( sp, *xe.inner, callback );
+ te.inner->match_generics( sp, *xe.inner, resolve_placeholder, callback );
),
(Tuple,
if( te.size() != xe.size() ) {
- BUG(sp, "");
+ BUG(sp, "TypeRef::match_generics with mismatched forms - " << *this << " and " << x);
}
for(unsigned int i = 0; i < te.size(); i ++ )
- te[i].match_generics( sp, xe[i], callback );
+ te[i].match_generics( sp, xe[i], resolve_placeholder, callback );
),
(Pointer,
- te.inner->match_generics( sp, *xe.inner, callback );
+ te.inner->match_generics( sp, *xe.inner, resolve_placeholder, callback );
),
(Borrow,
- te.inner->match_generics( sp, *xe.inner, callback );
+ te.inner->match_generics( sp, *xe.inner, resolve_placeholder, callback );
),
(Function,
TODO(sp, "Function");
diff --git a/src/hir/type.hpp b/src/hir/type.hpp
index 75cf4485..adb48df0 100644
--- a/src/hir/type.hpp
+++ b/src/hir/type.hpp
@@ -15,6 +15,8 @@ class Enum;
class TypeRef;
+typedef ::std::function<const ::HIR::TypeRef&(const ::HIR::TypeRef&)> t_cb_resolve_type;
+
enum class InferClass
{
None,
@@ -168,7 +170,7 @@ public:
// Match generics in `this` with types from `x`
// Raises a bug against `sp` if there is a form mismatch or `this` has an infer
- void match_generics(const Span& sp, const ::HIR::TypeRef& x, ::std::function<void(unsigned int, const ::HIR::TypeRef&)> callback) const;
+ void match_generics(const Span& sp, const ::HIR::TypeRef& x, t_cb_resolve_type resolve_placeholder, ::std::function<void(unsigned int, const ::HIR::TypeRef&)> callback) const;
enum Compare {
Equal,
@@ -176,7 +178,7 @@ public:
Unequal,
};
// Compares this type with another, using `resolve_placeholder` to get replacements for generics/infers in `x`
- Compare compare_with_paceholders(const Span& sp, const ::HIR::TypeRef& x, ::std::function<const ::HIR::TypeRef&(const ::HIR::TypeRef&)> resolve_placeholder) const;
+ Compare compare_with_paceholders(const Span& sp, const ::HIR::TypeRef& x, t_cb_resolve_type resolve_placeholder) const;
};
extern ::std::ostream& operator<<(::std::ostream& os, const ::HIR::TypeRef& ty);