diff options
author | John Hodge <tpg@mutabah.net> | 2016-10-23 19:38:13 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-10-23 19:38:13 +0800 |
commit | ea3c657845313a274f99cc568ff4e3310e248e15 (patch) | |
tree | f8e381baa016bc499cb982bff6e8a2aebe392508 | |
parent | 061b63d4fd88e5802927bd42d4b0fd8d5f6fc0f8 (diff) | |
download | mrust-ea3c657845313a274f99cc568ff4e3310e248e15.tar.gz |
AST+HIR - Add stubbed support for erased types (`impl Trait`)
-rw-r--r-- | src/ast/types.cpp | 13 | ||||
-rw-r--r-- | src/ast/types.hpp | 20 | ||||
-rw-r--r-- | src/expand/derive.cpp | 3 | ||||
-rw-r--r-- | src/expand/mod.cpp | 3 | ||||
-rw-r--r-- | src/hir/expr.cpp | 6 | ||||
-rw-r--r-- | src/hir/from_ast.cpp | 19 | ||||
-rw-r--r-- | src/hir/hir.cpp | 6 | ||||
-rw-r--r-- | src/hir/path.cpp | 31 | ||||
-rw-r--r-- | src/hir/path.hpp | 5 | ||||
-rw-r--r-- | src/hir/serialise.cpp | 3 | ||||
-rw-r--r-- | src/hir/type.cpp | 62 | ||||
-rw-r--r-- | src/hir/type.hpp | 5 | ||||
-rw-r--r-- | src/hir/visitor.cpp | 6 | ||||
-rw-r--r-- | src/hir_typeck/common.cpp | 83 | ||||
-rw-r--r-- | src/hir_typeck/expr_cs.cpp | 17 | ||||
-rw-r--r-- | src/hir_typeck/helpers.cpp | 81 | ||||
-rw-r--r-- | src/hir_typeck/outer.cpp | 3 | ||||
-rw-r--r-- | src/hir_typeck/static.cpp | 8 | ||||
-rw-r--r-- | src/mir/from_hir_match.cpp | 22 | ||||
-rw-r--r-- | src/resolve/absolute.cpp | 7 |
20 files changed, 324 insertions, 79 deletions
diff --git a/src/ast/types.cpp b/src/ast/types.cpp index 1c6cc568..7468dcf7 100644 --- a/src/ast/types.cpp +++ b/src/ast/types.cpp @@ -118,6 +118,7 @@ TypeRef::TypeRef(const TypeRef& other) _COPY(Generic) _COPY(Path) _COPY(TraitObject) + _COPY(ErasedType) #undef _COPY #undef _CLONE } @@ -172,6 +173,9 @@ Ordering TypeRef::ord(const TypeRef& x) const ), (TraitObject, return ::ord(ent.traits, x_ent.traits); + ), + (ErasedType, + return ::ord(ent.traits, x_ent.traits); ) ) throw ::std::runtime_error(FMT("BUGCHECK - Unhandled TypeRef class '" << m_data.tag() << "'")); @@ -249,6 +253,15 @@ Ordering TypeRef::ord(const TypeRef& x) const } os << ")"; ) + _(ErasedType, + os << "impl "; + for( const auto& it : ent.traits ) { + if( &it != &ent.traits.front() ) + os << "+"; + os << it; + } + os << ""; + ) } #undef _ //os << ")"; diff --git a/src/ast/types.hpp b/src/ast/types.hpp index 79934e16..66f5797c 100644 --- a/src/ast/types.hpp +++ b/src/ast/types.hpp @@ -96,10 +96,10 @@ TAGGED_UNION(TypeData, None, (TraitObject, struct {
::std::vector<::std::string> hrls;
::std::vector<AST::Path> traits;
- // }),
- //(ImplTrait, struct {
- // ::std::vector<::std::string> hrls;
- // ::std::vector<AST::Path> traits;
+ }),
+ (ErasedType, struct {
+ ::std::vector<::std::string> hrls;
+ ::std::vector<AST::Path> traits;
})
);
@@ -112,18 +112,10 @@ public: virtual ~TypeRef();
- TypeRef(TypeRef&& other) noexcept:
- m_data( mv$(other.m_data) )
- {
- m_span = mv$(other.m_span);
- }
+ TypeRef(TypeRef&& other) noexcept = default;
+ TypeRef& operator=(TypeRef&& other) = default;
TypeRef(const TypeRef& other);
- TypeRef& operator=(TypeRef&& other) {
- m_data = mv$( other.m_data );
- m_span = mv$( other.m_span );
- return *this;
- }
TypeRef& operator=(const TypeRef& other) {
m_data = TypeRef(other).m_data;
return *this;
diff --git a/src/expand/derive.cpp b/src/expand/derive.cpp index 06e2921e..668ecc9b 100644 --- a/src/expand/derive.cpp +++ b/src/expand/derive.cpp @@ -198,6 +198,9 @@ struct Deriver ), (TraitObject, // TODO: Should this be recursed? + ), + (ErasedType, + // TODO: Should this be recursed? ) ) } diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp index ad141a46..607b8f3c 100644 --- a/src/expand/mod.cpp +++ b/src/expand/mod.cpp @@ -213,6 +213,9 @@ void Expand_Type(::AST::Crate& crate, LList<const AST::Module*> modstack, ::AST: (Path, ), (TraitObject, + ), + (ErasedType, + // TODO: Visit paths. ) ) } 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 ); diff --git a/src/hir_typeck/common.cpp b/src/hir_typeck/common.cpp index db89ca5e..e900a066 100644 --- a/src/hir_typeck/common.cpp +++ b/src/hir_typeck/common.cpp @@ -70,6 +70,14 @@ bool monomorphise_type_needed(const ::HIR::TypeRef& tpl) return true; return false; ), + (ErasedType, + if( monomorphise_path_needed(e.m_origin) ) + return true; + for(const auto& trait : e.m_traits) + if( monomorphise_traitpath_needed(trait) ) + return true; + return false; + ), (Array, return monomorphise_type_needed(*e.inner); ), @@ -132,6 +140,33 @@ bool monomorphise_type_needed(const ::HIR::TypeRef& tpl) return rv; } +::HIR::Path monomorphise_path_with(const Span& sp, const ::HIR::Path& tpl, t_cb_generic callback, bool allow_infer) +{ + TU_MATCH(::HIR::Path::Data, (tpl.m_data), (e2), + (Generic, + return ::HIR::Path( monomorphise_genericpath_with(sp, e2, callback, allow_infer) ); + ), + (UfcsKnown, + return ::HIR::Path::Data::make_UfcsKnown({ + box$( monomorphise_type_with_inner(sp, *e2.type, callback, allow_infer) ), + monomorphise_genericpath_with(sp, e2.trait, callback, allow_infer), + e2.item, + monomorphise_path_params_with(sp, e2.params, callback, allow_infer) + }); + ), + (UfcsUnknown, + return ::HIR::Path::Data::make_UfcsUnknown({ + box$( monomorphise_type_with_inner(sp, *e2.type, callback, allow_infer) ), + e2.item, + monomorphise_path_params_with(sp, e2.params, callback, allow_infer) + }); + ), + (UfcsInherent, + TODO(sp, "UfcsInherent - " << tpl); + ) + ) + throw ""; +} ::HIR::TypeRef monomorphise_type_with_inner(const Span& sp, const ::HIR::TypeRef& tpl, t_cb_generic callback, bool allow_infer) { ::HIR::TypeRef rv; @@ -151,32 +186,14 @@ bool monomorphise_type_needed(const ::HIR::TypeRef& tpl) rv = ::HIR::TypeRef(e); ), (Path, - TU_MATCH(::HIR::Path::Data, (e.path.m_data), (e2), - (Generic, - rv = ::HIR::TypeRef( ::HIR::TypeRef::Data::Data_Path { - monomorphise_genericpath_with(sp, e2, callback, allow_infer), - e.binding.clone() - } ); - ), - (UfcsKnown, - rv = ::HIR::TypeRef( ::HIR::Path::Data::make_UfcsKnown({ - box$( monomorphise_type_with_inner(sp, *e2.type, callback, allow_infer) ), - monomorphise_genericpath_with(sp, e2.trait, callback, allow_infer), - e2.item, - monomorphise_path_params_with(sp, e2.params, callback, allow_infer) - }) ); - ), - (UfcsUnknown, - rv = ::HIR::TypeRef( ::HIR::Path::Data::make_UfcsUnknown({ - box$( monomorphise_type_with_inner(sp, *e2.type, callback, allow_infer) ), - e2.item, - monomorphise_path_params_with(sp, e2.params, callback, allow_infer) - }) ); - ), - (UfcsInherent, - TODO(sp, "UfcsInherent - " << tpl); - ) - ) + rv = ::HIR::TypeRef( ::HIR::TypeRef::Data::Data_Path { + monomorphise_path_with(sp, e.path, callback, allow_infer), + e.binding.clone() + } ); + // If the input binding was Opaque, clear it back to Unbound + if( e.binding.is_Opaque() ) { + rv.m_data.as_Path().binding = ::HIR::TypeRef::TypePathBinding(); + } ), (Generic, rv = callback(tpl).clone(); @@ -192,6 +209,20 @@ bool monomorphise_type_needed(const ::HIR::TypeRef& tpl) to.m_lifetime = e.m_lifetime; rv = ::HIR::TypeRef( mv$(to) ); ), + (ErasedType, + auto origin = monomorphise_path_with(sp, e.m_origin, callback, allow_infer); + + ::std::vector< ::HIR::TraitPath> traits; + traits.reserve( e.m_traits.size() ); + for(const auto& trait : e.m_traits) + traits.push_back( monomorphise_traitpath_with(sp, trait, callback, allow_infer) ); + + rv = ::HIR::TypeRef( ::HIR::TypeRef::Data::Data_ErasedType { + mv$(origin), + mv$(traits), + e.m_lifetime + } ); + ), (Array, if( e.size_val == ~0u ) { BUG(sp, "Attempting to clone array with unknown size - " << tpl); diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index e738eb9c..f1acef62 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -1885,6 +1885,9 @@ namespace { (TraitObject, ERROR(sp, E0000, "Non-scalar cast to " << this->context.m_ivars.fmt_type(tgt_ty)); ), + (ErasedType, + ERROR(sp, E0000, "Non-scalar cast to " << this->context.m_ivars.fmt_type(tgt_ty)); + ), (Array, ERROR(sp, E0000, "Non-scalar cast to " << this->context.m_ivars.fmt_type(tgt_ty)); ), @@ -2820,6 +2823,9 @@ namespace { check_type_resolved_pp(sp, marker.m_params, top_type); } ), + (ErasedType, + check_type_resolved_path(sp, e.m_origin, top_type); + ), (Array, this->check_type_resolved(sp, *e.inner, top_type); ), @@ -3043,6 +3049,9 @@ void Context::equate_types(const Span& sp, const ::HIR::TypeRef& li, const ::HIR } // NOTE: Lifetime is ignored ), + (ErasedType, + TODO(sp, "ErasedType"); + ), (Array, this->equate_types(sp, *l_e.inner, *r_e.inner); if( l_e.size_val != r_e.size_val ) { @@ -4163,6 +4172,10 @@ namespace { context.equate_types(sp, ty_dst, node_ptr->m_res_type); return true; ), + (ErasedType, + context.equate_types(sp, ty_dst, ty_src); + return true; + ), (Array, // Raw [T; n] doesn't coerce, only borrows do context.equate_types(sp, ty_dst, node_ptr->m_res_type); @@ -4241,6 +4254,10 @@ namespace { context.equate_types(sp, ty_dst, ty_src); return true; ), + (ErasedType, + context.equate_types(sp, ty_dst, ty_src); + return true; + ), (Array, context.equate_types(sp, ty_dst, ty_src); return true; diff --git a/src/hir_typeck/helpers.cpp b/src/hir_typeck/helpers.cpp index 3820c097..fb7384a5 100644 --- a/src/hir_typeck/helpers.cpp +++ b/src/hir_typeck/helpers.cpp @@ -109,6 +109,9 @@ void HMTypeInferrence::check_for_loops() this->check_pathparams(ivars, marker.m_params); } ), + (ErasedType, + TODO(Span(), "ErasedType"); + ), (Tuple, for(const auto& st : e) { this->check_ty(ivars, st); @@ -291,6 +294,18 @@ void HMTypeInferrence::print_type(::std::ostream& os, const ::HIR::TypeRef& tr) } os << ")"; ), + (ErasedType, + // TODO: Print correctly (with print_type calls) + 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 << "*/"; + ), (Tuple, os << "("; for(const auto& st : e) { @@ -354,6 +369,9 @@ void HMTypeInferrence::expand_ivars(::HIR::TypeRef& type) for(auto& marker : e.m_markers) this->expand_ivars_params(marker.m_params); ), + (ErasedType, + TODO(Span(), "ErasedType"); + ), (Array, this->expand_ivars(*e.inner); ), @@ -431,6 +449,9 @@ void HMTypeInferrence::add_ivars(::HIR::TypeRef& type) for(auto& marker : e.m_markers) this->add_ivars_params(marker.m_params); ), + (ErasedType, + BUG(Span(), "ErasedType getting ivars added"); + ), (Array, add_ivars(*e.inner); ), @@ -701,6 +722,9 @@ bool HMTypeInferrence::type_contains_ivars(const ::HIR::TypeRef& ty) const { return true; return pathparams_contain_ivars(e.m_trait.m_path.m_params); ), + (ErasedType, + TODO(Span(), "ErasedType"); + ), (Tuple, for(const auto& st : e) if( type_contains_ivars(st) ) @@ -813,6 +837,9 @@ bool HMTypeInferrence::types_equal(const ::HIR::TypeRef& rl, const ::HIR::TypeRe return false; return pathparams_equal(le.m_trait.m_path.m_params, re.m_trait.m_path.m_params); ), + (ErasedType, + TODO(Span(), "ErasedType"); + ), (Tuple, return type_list_equal(*this, le, re); ) @@ -1363,6 +1390,29 @@ bool TraitResolution::has_associated_type(const ::HIR::TypeRef& input) const } return false; } + static bool check_path(const TraitResolution& r, const ::HIR::Path& p) { + TU_MATCH(::HIR::Path::Data, (p.m_data), (e2), + (Generic, + return H::check_pathparams(r, e2.m_params); + ), + (UfcsInherent, + TODO(Span(), "Path - UfcsInherent - " << p); + ), + (UfcsKnown, + if( r.has_associated_type(*e2.type) ) + return true; + if( H::check_pathparams(r, e2.trait.m_params) ) + return true; + if( H::check_pathparams(r, e2.params) ) + return true; + return false; + ), + (UfcsUnknown, + BUG(Span(), "Encountered UfcsUnknown - " << p); + ) + ) + throw ""; + } }; //TRACE_FUNCTION_F(input); TU_MATCH(::HIR::TypeRef::Data, (input.m_data), (e), @@ -1380,23 +1430,10 @@ bool TraitResolution::has_associated_type(const ::HIR::TypeRef& input) const return false; ), (Path, - TU_MATCH(::HIR::Path::Data, (e.path.m_data), (e2), - (Generic, - return H::check_pathparams(*this, e2.m_params); - ), - (UfcsInherent, - TODO(Span(), "Path - UfcsInherent - " << e.path); - ), - (UfcsKnown, - // - Only try resolving if the binding isn't known - if( !e.binding.is_Unbound() ) - return false; + // Unbounded UfcsKnown returns true (bound is false) + if( e.path.m_data.is_UfcsKnown() && e.binding.is_Unbound() ) return true; - ), - (UfcsUnknown, - BUG(Span(), "Encountered UfcsUnknown"); - ) - ) + return H::check_path(*this, e.path); ), (Generic, return false; @@ -1411,6 +1448,15 @@ bool TraitResolution::has_associated_type(const ::HIR::TypeRef& input) const } return false; ), + (ErasedType, + if( H::check_path(*this, e.m_origin) ) + return true; + for(const auto& m : e.m_traits) { + if( H::check_pathparams(*this, m.m_path.m_params) ) + return true; + } + return false; + ), (Array, return has_associated_type(*e.inner); ), @@ -1488,6 +1534,9 @@ void TraitResolution::expand_associated_types_inplace(const Span& sp, ::HIR::Typ (TraitObject, // Recurse? ), + (ErasedType, + // Recurse? + ), (Array, expand_associated_types_inplace(sp, *e.inner, stack); ), diff --git a/src/hir_typeck/outer.cpp b/src/hir_typeck/outer.cpp index 175188ea..ff536709 100644 --- a/src/hir_typeck/outer.cpp +++ b/src/hir_typeck/outer.cpp @@ -166,6 +166,9 @@ namespace { // NOTE: Can't mention Self anywhere TODO(sp, "update_self_type - TraitObject"); ), + (ErasedType, + TODO(sp, "update_self_type - ErasedType"); + ), (Tuple, for(auto& sty : e) update_self_type(sp, sty); diff --git a/src/hir_typeck/static.cpp b/src/hir_typeck/static.cpp index 09cd545d..b35dbfe2 100644 --- a/src/hir_typeck/static.cpp +++ b/src/hir_typeck/static.cpp @@ -517,6 +517,9 @@ void StaticTraitResolve::expand_associated_types_inner(const Span& sp, ::HIR::Ty (TraitObject, // Recurse? ), + (ErasedType, + // Recurse? + ), (Array, expand_associated_types_inner(sp, *e.inner); ), @@ -906,9 +909,12 @@ bool StaticTraitResolve::type_is_copy(const Span& sp, const ::HIR::TypeRef& ty) return false; ), (TraitObject, - // [T] isn't Sized, so isn't Copy ether + // (Trait) isn't Sized, so isn't Copy ether return false; ), + (ErasedType, + TODO(Span(), "ErasedType - It's Copy if Copy is a trait in it"); + ), (Tuple, for(const auto& ty : e) if( !type_is_copy(sp, ty) ) diff --git a/src/mir/from_hir_match.cpp b/src/mir/from_hir_match.cpp index 0edc6800..a6446a27 100644 --- a/src/mir/from_hir_match.cpp +++ b/src/mir/from_hir_match.cpp @@ -531,6 +531,9 @@ void PatternRulesetBuilder::append_from_lit(const Span& sp, const ::HIR::Literal (TraitObject, TODO(sp, "Match trait object with literal?"); ), + (ErasedType, + TODO(sp, "Match erased type with literal?"); + ), (Array, ASSERT_BUG(sp, lit.is_List(), "Matching array with non-list literal - " << lit); const auto& list = lit.as_List(); @@ -927,6 +930,13 @@ void PatternRulesetBuilder::append_from(const Span& sp, const ::HIR::Pattern& pa ERROR(sp, E0000, "Attempting to match over a trait object"); } ), + (ErasedType, + if( pat.m_data.is_Any() ) { + } + else { + ERROR(sp, E0000, "Attempting to match over an erased type"); + } + ), (Array, // Sequential match just like tuples. m_field_path.push_back(0); @@ -1363,6 +1373,12 @@ int MIR_LowerHIR_Match_Simple__GeneratePattern(MirBuilder& builder, const Span& } return 1; ), + (ErasedType, + if( !rule.is_Any() ) { + BUG(sp, "Attempting to match an erased type"); + } + return 1; + ), (Array, if( !rule.is_Any() ) { unsigned int total = 0; @@ -2747,6 +2763,9 @@ void DecisionTreeGen::get_ty_and_val( (TraitObject, BUG(sp, "Destructuring a trait object - " << *cur_ty); ), + (ErasedType, + BUG(sp, "Destructuring an erased type - " << *cur_ty); + ), (Array, assert(idx < e.size_val); cur_ty = &*e.inner; @@ -2880,6 +2899,9 @@ void DecisionTreeGen::generate_tree_code( (TraitObject, ERROR(sp, E0000, "Attempting to match over a trait object"); ), + (ErasedType, + ERROR(sp, E0000, "Attempting to match over an erased type"); + ), (Array, // TODO: Slice patterns, sequential comparison/sub-match TODO(sp, "Match over array"); diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp index 4a4ac5cb..ca79094e 100644 --- a/src/resolve/absolute.cpp +++ b/src/resolve/absolute.cpp @@ -1500,6 +1500,13 @@ void Resolve_Absolute_Type(Context& context, TypeRef& type) Resolve_Absolute_Path(context, type.span(), Context::LookupMode::Type, trait); } //context.pop_lifetimes(); + ), + (ErasedType, + //context.push_lifetimes( e.hrls ); + for(auto& trait : e.traits) { + Resolve_Absolute_Path(context, type.span(), Context::LookupMode::Type, trait); + } + //context.pop_lifetimes(); ) ) } |