summaryrefslogtreecommitdiff
path: root/src/hir
diff options
context:
space:
mode:
Diffstat (limited to 'src/hir')
-rw-r--r--src/hir/expr.cpp6
-rw-r--r--src/hir/from_ast.cpp19
-rw-r--r--src/hir/hir.cpp6
-rw-r--r--src/hir/path.cpp31
-rw-r--r--src/hir/path.hpp5
-rw-r--r--src/hir/serialise.cpp3
-rw-r--r--src/hir/type.cpp62
-rw-r--r--src/hir/type.hpp5
-rw-r--r--src/hir/visitor.cpp6
9 files changed, 121 insertions, 22 deletions
diff --git a/src/hir/expr.cpp b/src/hir/expr.cpp
index 6c13f270..e11002d9 100644
--- a/src/hir/expr.cpp
+++ b/src/hir/expr.cpp
@@ -250,6 +250,12 @@ void ::HIR::ExprVisitorDef::visit_type(::HIR::TypeRef& ty)
this->visit_generic_path(::HIR::Visitor::PathContext::TYPE, trait);
}
),
+ (ErasedType,
+ this->visit_path(::HIR::Visitor::PathContext::TYPE, e.m_origin);
+ for(auto& trait : e.m_traits) {
+ this->visit_trait_path(trait);
+ }
+ ),
(Array,
this->visit_type( *e.inner );
//this->visit_expr( e.size );
diff --git a/src/hir/from_ast.cpp b/src/hir/from_ast.cpp
index cd8be320..bb40ece9 100644
--- a/src/hir/from_ast.cpp
+++ b/src/hir/from_ast.cpp
@@ -706,6 +706,7 @@
if( e.hrls.size() > 0 )
TODO(ty.span(), "TraitObjects with HRLS - " << ty);
::HIR::TypeRef::Data::Data_TraitObject v;
+ // TODO: Lifetime
for(const auto& t : e.traits)
{
DEBUG("t = " << t);
@@ -729,6 +730,24 @@
//ASSERT_BUG(ty.span(), v.m_trait.m_path.m_path != ::HIR::SimplePath(), "TraitObject type didn't contain a data trait - " << ty);
return ::HIR::TypeRef( ::HIR::TypeRef::Data::make_TraitObject( mv$(v) ) );
),
+ (ErasedType,
+ if( e.hrls.size() > 0 )
+ TODO(ty.span(), "ErasedType with HRLS - " << ty);
+ ASSERT_BUG(ty.span(), e.traits.size() > 0, "ErasedType with no traits");
+
+ ::std::vector< ::HIR::TraitPath> traits;
+ for(const auto& t : e.traits)
+ {
+ DEBUG("t = " << t);
+ traits.push_back( LowerHIR_TraitPath(ty.span(), t) );
+ }
+ // Leave `m_origin` until the bind pass
+ return ::HIR::TypeRef( ::HIR::TypeRef::Data::make_ErasedType(::HIR::TypeRef::Data::Data_ErasedType {
+ ::HIR::Path(::HIR::SimplePath()),
+ mv$(traits),
+ ::HIR::LifetimeRef() // TODO: Lifetime ref
+ } ) );
+ ),
(Function,
::std::vector< ::HIR::TypeRef> args;
for(const auto& arg : e.info.m_arg_types)
diff --git a/src/hir/hir.cpp b/src/hir/hir.cpp
index 404674ac..f49c2f80 100644
--- a/src/hir/hir.cpp
+++ b/src/hir/hir.cpp
@@ -131,6 +131,9 @@ namespace {
}
return true;
),
+ (ErasedType,
+ throw "Unexpected ErasedType in matches_type_int";
+ ),
(Array,
if( ! matches_type_int(params, *le.inner, *re.inner, ty_res, expand_generic) )
return false;
@@ -301,6 +304,9 @@ namespace {
(TraitObject,
TODO(sp, "TraitObject - " << left);
),
+ (ErasedType,
+ TODO(sp, "ErasedType - " << left);
+ ),
(Function,
TU_IFLET(::HIR::TypeRef::Data, right.m_data, Function, re,
TODO(sp, "Function");
diff --git a/src/hir/path.cpp b/src/hir/path.cpp
index f0590e38..8e522aa9 100644
--- a/src/hir/path.cpp
+++ b/src/hir/path.cpp
@@ -356,3 +356,34 @@ namespace {
throw "";
}
+Ordering HIR::Path::ord(const ::HIR::Path& x) const
+{
+ ORD( (unsigned)m_data.tag(), (unsigned)x.m_data.tag() );
+ TU_MATCH(::HIR::Path::Data, (this->m_data, x.m_data), (tpe, xpe),
+ (Generic,
+ return ::ord(tpe, xpe);
+ ),
+ (UfcsInherent,
+ ORD(*tpe.type, *xpe.type);
+ ORD(tpe.item, xpe.item);
+ return ::ord(tpe.params, xpe.params);
+ ),
+ (UfcsKnown,
+ ORD(*tpe.type, *xpe.type);
+ ORD(tpe.trait, xpe.trait);
+ ORD(tpe.item, xpe.item);
+ return ::ord(tpe.params, xpe.params);
+ ),
+ (UfcsUnknown,
+ ORD(*tpe.type, *xpe.type);
+ ORD(tpe.item, xpe.item);
+ return ::ord(tpe.params, xpe.params);
+ )
+ )
+ throw "";
+}
+
+bool ::HIR::Path::operator==(const Path& x) const {
+ return this->ord(x) == ::OrdEqual;
+}
+
diff --git a/src/hir/path.hpp b/src/hir/path.hpp
index 0ee4c958..715037d5 100644
--- a/src/hir/path.hpp
+++ b/src/hir/path.hpp
@@ -195,6 +195,11 @@ public:
Path clone() const;
Compare compare_with_placeholders(const Span& sp, const Path& x, t_cb_resolve_type resolve_placeholder) const;
+ Ordering ord(const Path& x) const;
+
+ bool operator==(const Path& x) const;
+ bool operator!=(const Path& x) const { return !(*this == x); }
+
friend ::std::ostream& operator<<(::std::ostream& os, const Path& x);
};
diff --git a/src/hir/serialise.cpp b/src/hir/serialise.cpp
index 506245c1..c7224840 100644
--- a/src/hir/serialise.cpp
+++ b/src/hir/serialise.cpp
@@ -89,6 +89,9 @@ namespace {
serialise_genericpath(m);
//write_string(e.lifetime); // TODO: Need a better type
),
+ (ErasedType,
+ TODO(Span(), "ErasedType");
+ ),
(Array,
assert(e.size_val != ~0u);
serialise_type(*e.inner);
diff --git a/src/hir/type.cpp b/src/hir/type.cpp
index 812e01e4..5233b681 100644
--- a/src/hir/type.cpp
+++ b/src/hir/type.cpp
@@ -103,6 +103,17 @@ void ::HIR::TypeRef::fmt(::std::ostream& os) const
os << "+ '" << e.m_lifetime.name;
os << ")";
),
+ (ErasedType,
+ os << "impl ";
+ for(const auto& tr : e.m_traits) {
+ if( &tr != &e.m_traits[0] )
+ os << "+";
+ os << tr;
+ }
+ if( e.m_lifetime.name != "" )
+ os << "+ '" << e.m_lifetime.name;
+ os << "/*" << e.m_origin << "*/";
+ ),
(Array,
os << "[" << *e.inner << "; ";
if( e.size_val != ~0u )
@@ -225,6 +236,9 @@ bool ::HIR::TypeRef::operator==(const ::HIR::TypeRef& x) const
}
return te.m_lifetime == xe.m_lifetime;
),
+ (ErasedType,
+ return te.m_origin == xe.m_origin;
+ ),
(Array,
if( *te.inner != *xe.inner )
return false;
@@ -299,28 +313,7 @@ Ordering HIR::TypeRef::ord(const ::HIR::TypeRef& x) const
return ::ord( static_cast<unsigned>(te), static_cast<unsigned>(xe) );
),
(Path,
- ORD( (unsigned)te.path.m_data.tag(), (unsigned)xe.path.m_data.tag() );
- TU_MATCH(::HIR::Path::Data, (te.path.m_data, xe.path.m_data), (tpe, xpe),
- (Generic,
- return ::ord(tpe, xpe);
- ),
- (UfcsInherent,
- ORD(*tpe.type, *xpe.type);
- ORD(tpe.item, xpe.item);
- return ::ord(tpe.params, xpe.params);
- ),
- (UfcsKnown,
- ORD(*tpe.type, *xpe.type);
- ORD(tpe.trait, xpe.trait);
- ORD(tpe.item, xpe.item);
- return ::ord(tpe.params, xpe.params);
- ),
- (UfcsUnknown,
- ORD(*tpe.type, *xpe.type);
- ORD(tpe.item, xpe.item);
- return ::ord(tpe.params, xpe.params);
- )
- )
+ return ::ord( te.path, xe.path );
),
(Generic,
ORD(te.name, xe.name);
@@ -334,6 +327,11 @@ Ordering HIR::TypeRef::ord(const ::HIR::TypeRef& x) const
return OrdEqual;
//return ::ord(te.m_lifetime, xe.m_lifetime);
),
+ (ErasedType,
+ ORD(te.m_origin, xe.m_origin);
+ ORD(te.m_traits, xe.m_traits);
+ return OrdEqual;
+ ),
(Array,
ORD(*te.inner, *xe.inner);
ORD(te.size_val, xe.size_val);
@@ -413,6 +411,9 @@ bool ::HIR::TypeRef::contains_generics() const
(TraitObject,
TODO(Span(), "TraitObject");
),
+ (ErasedType,
+ TODO(Span(), "ErasedType");
+ ),
(Array,
return te.inner->contains_generics();
),
@@ -664,6 +665,9 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x
}
return cmp;
),
+ (ErasedType,
+ TODO(sp, "ErasedType - match_test_generics_fuzz - " << v << " -- " << x);
+ ),
(Array,
return te.inner->match_test_generics_fuzz( sp, *xe.inner, resolve_placeholder, callback );
),
@@ -757,6 +761,17 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x
rv.m_lifetime = e.m_lifetime;
return ::HIR::TypeRef( Data::make_TraitObject( mv$(rv) ) );
),
+ (ErasedType,
+ ::std::vector< ::HIR::TraitPath> traits;
+ traits.reserve( e.m_traits.size() );
+ for(const auto& trait : e.m_traits)
+ traits.push_back( trait.clone() );
+ return ::HIR::TypeRef( Data::make_ErasedType({
+ e.m_origin.clone(),
+ mv$(traits),
+ e.m_lifetime
+ }) );
+ ),
(Array,
unsigned int size_val = e.size_val;
if( e.size_val == ~0u ) {
@@ -1000,6 +1015,9 @@ bool ::HIR::TypeRef::match_test_generics(const Span& sp, const ::HIR::TypeRef& x
}
return rv;
),
+ (ErasedType,
+ TODO(sp, "ErasedType");
+ ),
(Array,
if( le.size_val != re.size_val )
return Compare::Unequal;
diff --git a/src/hir/type.hpp b/src/hir/type.hpp
index fecaaa88..63a87059 100644
--- a/src/hir/type.hpp
+++ b/src/hir/type.hpp
@@ -133,6 +133,11 @@ public:
::std::vector< ::HIR::GenericPath > m_markers;
::HIR::LifetimeRef m_lifetime;
}),
+ (ErasedType, struct {
+ ::HIR::Path m_origin;
+ ::std::vector< ::HIR::TraitPath> m_traits;
+ ::HIR::LifetimeRef m_lifetime;
+ }),
(Array, struct {
::std::unique_ptr<TypeRef> inner;
::HIR::ExprPtr size;
diff --git a/src/hir/visitor.cpp b/src/hir/visitor.cpp
index 05e99734..42713c36 100644
--- a/src/hir/visitor.cpp
+++ b/src/hir/visitor.cpp
@@ -295,6 +295,12 @@ void ::HIR::Visitor::visit_type(::HIR::TypeRef& ty)
this->visit_generic_path(trait, ::HIR::Visitor::PathContext::TYPE);
}
),
+ (ErasedType,
+ this->visit_path(e.m_origin, ::HIR::Visitor::PathContext::TYPE);
+ for(auto& trait : e.m_traits) {
+ this->visit_trait_path(trait);
+ }
+ ),
(Array,
this->visit_type( *e.inner );
this->visit_expr( e.size );