diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-06-16 11:41:48 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-06-16 12:09:07 +0100 |
commit | 44481c1c2bdf7d160928dde30f48fdc54e75bf38 (patch) | |
tree | c23d9bc49979377b15a57dbdc7524595a9a5be0b | |
parent | 59f09fd5a48046ceba064bde2f230386fbc3700f (diff) | |
download | gcc-44481c1c2bdf7d160928dde30f48fdc54e75bf38.zip gcc-44481c1c2bdf7d160928dde30f48fdc54e75bf38.tar.gz gcc-44481c1c2bdf7d160928dde30f48fdc54e75bf38.tar.bz2 |
Cleanup HIR to canonicalize TraitImpl to be treated as an impl block
HIR should desugar the AST as best it can. Trait impl blocks are just impl
blocks. The HIR impl block can just have an optional<TraitRef> in order to
represent a trait impl block.
-rw-r--r-- | gcc/rust/backend/rust-compile-base.h | 3 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-implitem.h | 8 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-item.h | 16 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-implitem.h | 17 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-item.h | 30 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-full-decls.h | 2 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-full-test.cc | 88 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-item.h | 189 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-visitor.h | 1 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir.h | 26 | ||||
-rw-r--r-- | gcc/rust/lint/rust-lint-marklive-base.h | 1 | ||||
-rw-r--r-- | gcc/rust/lint/rust-lint-marklive.h | 10 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-const-fold-base.h | 1 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-base.h | 1 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-implitem.h | 14 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-item.h | 15 | ||||
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-toplevel.h | 41 |
17 files changed, 32 insertions, 431 deletions
diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h index b071a30..29e7562 100644 --- a/gcc/rust/backend/rust-compile-base.h +++ b/gcc/rust/backend/rust-compile-base.h @@ -148,8 +148,7 @@ public: virtual void visit (HIR::TraitItemType &item) {} virtual void visit (HIR::Trait &trait) {} virtual void visit (HIR::InherentImpl &impl) {} - virtual void visit (HIR::TraitImpl &impl) {} - // virtual void visit(ExternalItem& item) {} + virtual void visit (HIR::ExternalStaticItem &item) {} virtual void visit (HIR::ExternalFunctionItem &item) {} virtual void visit (HIR::ExternBlock &block) {} diff --git a/gcc/rust/backend/rust-compile-implitem.h b/gcc/rust/backend/rust-compile-implitem.h index a4fb6d1..a5ca13b 100644 --- a/gcc/rust/backend/rust-compile-implitem.h +++ b/gcc/rust/backend/rust-compile-implitem.h @@ -42,14 +42,6 @@ public: item->accept_vis (compiler); } - static void Compile (TyTy::BaseType *self, HIR::TraitImplItem *item, - Context *ctx, bool compile_fns, - TyTy::BaseType *concrete = nullptr) - { - CompileInherentImplItem compiler (self, ctx, compile_fns, concrete); - item->accept_vis (compiler); - } - void visit (HIR::ConstantItem &constant) override { TyTy::BaseType *resolved_type = nullptr; diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h index e681652..e3b6d0f 100644 --- a/gcc/rust/backend/rust-compile-item.h +++ b/gcc/rust/backend/rust-compile-item.h @@ -290,22 +290,6 @@ public: compile_fns); } - void visit (HIR::TraitImpl &impl_block) override - { - TyTy::BaseType *self_lookup = nullptr; - if (!ctx->get_tyctx ()->lookup_type ( - impl_block.get_type ()->get_mappings ().get_hirid (), &self_lookup)) - { - rust_error_at (impl_block.get_locus (), - "failed to resolve type of impl"); - return; - } - - for (auto &impl_item : impl_block.get_impl_items ()) - CompileInherentImplItem::Compile (self_lookup, impl_item.get (), ctx, - compile_fns); - } - private: CompileItem (Context *ctx, bool compile_fns, TyTy::BaseType *concrete) : HIRCompileBase (ctx), compile_fns (compile_fns), concrete (concrete) diff --git a/gcc/rust/hir/rust-ast-lower-implitem.h b/gcc/rust/hir/rust-ast-lower-implitem.h index f830918..31ebb83 100644 --- a/gcc/rust/hir/rust-ast-lower-implitem.h +++ b/gcc/rust/hir/rust-ast-lower-implitem.h @@ -43,14 +43,13 @@ public: return resolver.translated; } - static HIR::TraitImplItem *translate (AST::TraitImplItem *item, - HirId parent_impl_id) + static HIR::InherentImplItem *translate (AST::TraitImplItem *item, + HirId parent_impl_id) { ASTLowerImplItem resolver (parent_impl_id); item->accept_vis (resolver); - rust_assert (resolver.trait_impl_item != nullptr); - // can get a way with this for now since they have the same hierarchy - return resolver.trait_impl_item; + rust_assert (resolver.translated != nullptr); + return resolver.translated; } void visit (AST::ConstantItem &constant) override @@ -72,7 +71,6 @@ public: constant.get_outer_attrs (), constant.get_locus ()); translated = translated_constant; - trait_impl_item = translated_constant; mappings->insert_hir_implitem (mapping.get_crate_num (), mapping.get_hirid (), parent_impl_id, @@ -161,7 +159,6 @@ public: } translated = fn; - trait_impl_item = fn; } void visit (AST::Method &method) override @@ -250,17 +247,15 @@ public: } translated = mth; - trait_impl_item = mth; } private: ASTLowerImplItem (HirId parent_impl_id) - : translated (nullptr), trait_impl_item (nullptr), - parent_impl_id (parent_impl_id) + : translated (nullptr), parent_impl_id (parent_impl_id) {} HIR::InherentImplItem *translated; - HIR::TraitImplItem *trait_impl_item; + HirId parent_impl_id; }; diff --git a/gcc/rust/hir/rust-ast-lower-item.h b/gcc/rust/hir/rust-ast-lower-item.h index 206eeff..74ec361 100644 --- a/gcc/rust/hir/rust-ast-lower-item.h +++ b/gcc/rust/hir/rust-ast-lower-item.h @@ -365,7 +365,7 @@ public: } } - HIR::Type *trait_type + HIR::Type *impl_type = ASTLoweringType::translate (impl_block.get_type ().get ()); auto crate_num = mappings->get_current_crate (); @@ -387,7 +387,7 @@ public: translated = new HIR::InherentImpl (mapping, std::move (impl_items), std::move (generic_params), - std::unique_ptr<HIR::Type> (trait_type), + std::unique_ptr<HIR::Type> (impl_type), where_clause, vis, impl_block.get_inner_attrs (), impl_block.get_outer_attrs (), impl_block.get_locus ()); @@ -472,6 +472,7 @@ public: void visit (AST::TraitImpl &impl_block) override { std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items; + HIR::WhereClause where_clause (std::move (where_clause_items)); HIR::Visibility vis = HIR::Visibility::create_public (); @@ -505,35 +506,32 @@ public: } } - HIR::Type *trait_type + HIR::Type *impl_type = ASTLoweringType::translate (impl_block.get_type ().get ()); - HIR::Type *trait = nullptr; auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, impl_block.get_node_id (), mappings->get_next_hir_id (crate_num), mappings->get_next_localdef_id (crate_num)); - std::vector<std::unique_ptr<HIR::TraitImplItem> > impl_items; + std::vector<std::unique_ptr<HIR::InherentImplItem> > impl_items; std::vector<HirId> impl_item_ids; for (auto &impl_item : impl_block.get_impl_items ()) { - HIR::TraitImplItem *lowered + HIR::InherentImplItem *lowered = ASTLowerImplItem::translate (impl_item.get (), mapping.get_hirid ()); - impl_items.push_back (std::unique_ptr<HIR::TraitImplItem> (lowered)); - impl_item_ids.push_back ( - lowered->get_trait_impl_mappings ().get_hirid ()); + impl_items.push_back (std::unique_ptr<HIR::InherentImplItem> (lowered)); + impl_item_ids.push_back (lowered->get_impl_mappings ().get_hirid ()); } translated - = new HIR::TraitImpl (mapping, std::unique_ptr<HIR::Type> (trait), - impl_block.is_unsafe (), impl_block.is_exclam (), - std::move (impl_items), std::move (generic_params), - std::unique_ptr<HIR::Type> (trait_type), - where_clause, vis, impl_block.get_inner_attrs (), - impl_block.get_outer_attrs (), - impl_block.get_locus ()); + = new HIR::InherentImpl (mapping, std::move (impl_items), + std::move (generic_params), + std::unique_ptr<HIR::Type> (impl_type), + where_clause, vis, impl_block.get_inner_attrs (), + impl_block.get_outer_attrs (), + impl_block.get_locus ()); mappings->insert_defid_mapping (mapping.get_defid (), translated); mappings->insert_hir_item (mapping.get_crate_num (), mapping.get_hirid (), diff --git a/gcc/rust/hir/tree/rust-hir-full-decls.h b/gcc/rust/hir/tree/rust-hir-full-decls.h index 6fae193..0920fe1 100644 --- a/gcc/rust/hir/tree/rust-hir-full-decls.h +++ b/gcc/rust/hir/tree/rust-hir-full-decls.h @@ -38,7 +38,6 @@ class LifetimeParam; class TraitItem; class InherentImplItem; -class TraitImplItem; struct Crate; class PathExpr; @@ -196,7 +195,6 @@ class TraitItemType; class Trait; class Impl; class InherentImpl; -class TraitImpl; class ExternalItem; class ExternalStaticItem; struct NamedFunctionParam; diff --git a/gcc/rust/hir/tree/rust-hir-full-test.cc b/gcc/rust/hir/tree/rust-hir-full-test.cc index d080d8b..e465b2d 100644 --- a/gcc/rust/hir/tree/rust-hir-full-test.cc +++ b/gcc/rust/hir/tree/rust-hir-full-test.cc @@ -1084,88 +1084,6 @@ BlockExpr::as_string () const } std::string -TraitImpl::as_string () const -{ - std::string str = VisItem::as_string (); - - if (has_unsafe) - { - str += "unsafe "; - } - - str += "impl "; - - // generic params - str += "\n Generic params: "; - if (!has_generics ()) - { - str += "none"; - } - else - { - for (const auto ¶m : generic_params) - { - str += "\n " + param->as_string (); - } - } - - str += "\n Has exclam: "; - if (has_exclam) - { - str += "true"; - } - else - { - str += "false"; - } - - str += "\n TypePath (to trait): " + trait_path->as_string (); - - str += "\n Type (struct to impl on): " + trait_type->as_string (); - - str += "\n Where clause: "; - if (!has_where_clause ()) - { - str += "none"; - } - else - { - str += where_clause.as_string (); - } - - // inner attributes - str += "\n inner attributes: "; - if (inner_attrs.empty ()) - { - str += "none"; - } - else - { - /* note that this does not print them with "inner attribute" syntax - - * just the body */ - for (const auto &attr : inner_attrs) - { - str += "\n " + attr.as_string (); - } - } - - str += "\n trait impl items: "; - if (!has_impl_items ()) - { - str += "none"; - } - else - { - for (const auto &item : impl_items) - { - str += "\n " + item->as_string (); - } - } - - return str; -} - -std::string TypeAlias::as_string () const { std::string str = VisItem::as_string (); @@ -4693,12 +4611,6 @@ InherentImpl::accept_vis (HIRVisitor &vis) } void -TraitImpl::accept_vis (HIRVisitor &vis) -{ - vis.visit (*this); -} - -void ExternalStaticItem::accept_vis (HIRVisitor &vis) { vis.visit (*this); diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h index e466a35..abb82fd 100644 --- a/gcc/rust/hir/tree/rust-hir-item.h +++ b/gcc/rust/hir/tree/rust-hir-item.h @@ -578,7 +578,7 @@ protected: }; // A method (function belonging to a type) -class Method : public InherentImplItem, public TraitImplItem +class Method : public InherentImplItem { Analysis::NodeMapping mappings; @@ -700,11 +700,6 @@ public: return get_mappings (); }; - Analysis::NodeMapping get_trait_impl_mappings () const override - { - return get_mappings (); - }; - // Returns whether function has return type - if not, it is void. bool has_function_return_type () const { return return_type != nullptr; } @@ -753,8 +748,6 @@ public: Location get_impl_locus () const final { return get_locus (); } - Location get_trait_impl_locus () const final { return get_locus (); } - std::unique_ptr<BlockExpr> &get_function_body () { return function_body; } const std::unique_ptr<BlockExpr> &get_function_body () const { @@ -768,13 +761,6 @@ protected: { return new Method (*this); } - - /* Use covariance to implement clone function as returning this object - * rather than base */ - Method *clone_trait_impl_item_impl () const override - { - return new Method (*this); - } }; // Item that supports visibility - abstract base class @@ -1274,7 +1260,7 @@ protected: class LetStmt; // Rust function declaration HIR node -class Function : public VisItem, public InherentImplItem, public TraitImplItem +class Function : public VisItem, public InherentImplItem { FunctionQualifiers qualifiers; Identifier function_name; @@ -1377,8 +1363,6 @@ public: Location get_impl_locus () const final { return get_locus (); } - Location get_trait_impl_locus () const final { return get_locus (); } - void accept_vis (HIRVisitor &vis) override; Analysis::NodeMapping get_impl_mappings () const override @@ -1386,11 +1370,6 @@ public: return get_mappings (); }; - Analysis::NodeMapping get_trait_impl_mappings () const override - { - return get_mappings (); - }; - std::vector<FunctionParam> &get_function_params () { return function_params; } const std::vector<FunctionParam> &get_function_params () const { @@ -1444,23 +1423,10 @@ protected: { return new Function (*this); } - - /* Use covariance to implement clone function as returning this object - * rather than base */ - Function *clone_trait_impl_item_impl () const override - { - return new Function (*this); - } - - /* Use covariance to implement clone function as returning this object - * rather than base */ - /*virtual Function* clone_statement_impl() const override { - return new Function(*this); - }*/ }; // Rust type alias (i.e. typedef) HIR node -class TypeAlias : public VisItem, public TraitImplItem +class TypeAlias : public VisItem, public InherentImplItem { Identifier new_type_name; @@ -1512,11 +1478,8 @@ public: { VisItem::operator= (other); new_type_name = other.new_type_name; - // generic_params = other.generic_params; where_clause = other.where_clause; existing_type = other.existing_type->clone_type (); - // visibility = other.visibility->clone_visibility(); - // outer_attrs = other.outer_attrs; locus = other.locus; generic_params.reserve (other.generic_params.size ()); @@ -1532,7 +1495,7 @@ public: Location get_locus () const { return locus; } - Location get_trait_impl_locus () const final { return get_locus (); } + Location get_impl_locus () const final { return get_locus (); } void accept_vis (HIRVisitor &vis) override; @@ -1545,14 +1508,12 @@ public: return generic_params; } - // TODO: is this better? Or is a "vis_block" better? WhereClause &get_where_clause () { rust_assert (has_where_clause ()); return where_clause; } - // TODO: is this better? Or is a "vis_block" better? std::unique_ptr<Type> &get_type_aliased () { rust_assert (existing_type != nullptr); @@ -1561,7 +1522,7 @@ public: Identifier get_new_type_name () const { return new_type_name; } - Analysis::NodeMapping get_trait_impl_mappings () const override + Analysis::NodeMapping get_impl_mappings () const override { return get_mappings (); }; @@ -1573,16 +1534,10 @@ protected: /* Use covariance to implement clone function as returning this object * rather than base */ - TypeAlias *clone_trait_impl_item_impl () const override + TypeAlias *clone_inherent_impl_item_impl () const override { return new TypeAlias (*this); } - - /* Use covariance to implement clone function as returning this object - * rather than base */ - /*virtual TypeAlias* clone_statement_impl() const override { - return new TypeAlias(*this); - }*/ }; // Rust base struct declaration HIR node - abstract base class @@ -2226,28 +2181,13 @@ protected: /* Use covariance to implement clone function as returning this object * rather than base */ Union *clone_item_impl () const override { return new Union (*this); } - - /* Use covariance to implement clone function as returning this object - * rather than base */ - /*virtual Union* clone_statement_impl() const override { - return new Union(*this); - }*/ }; -/* "Constant item" HIR node - used for constant, compile-time expressions - * within module scope (like constexpr) */ -class ConstantItem : public VisItem, - public InherentImplItem, - public TraitImplItem +class ConstantItem : public VisItem, public InherentImplItem { - // either has an identifier or "_" - maybe handle in identifier? - // bool identifier_is_underscore; - // if no identifier declared, identifier will be "_" Identifier identifier; - std::unique_ptr<Type> type; std::unique_ptr<Expr> const_expr; - Location locus; public: @@ -2284,16 +2224,14 @@ public: ConstantItem (ConstantItem &&other) = default; ConstantItem &operator= (ConstantItem &&other) = default; - /* Returns whether constant item is an "unnamed" (wildcard underscore used - * as identifier) constant. */ + // Returns whether constant item is an "unnamed" (wildcard underscore used + // as identifier) constant. bool is_unnamed () const { return identifier == std::string ("_"); } Location get_locus () const { return locus; } Location get_impl_locus () const final { return get_locus (); } - Location get_trait_impl_locus () const final { return get_locus (); } - void accept_vis (HIRVisitor &vis) override; Type *get_type () { return type.get (); } @@ -2307,11 +2245,6 @@ public: return get_mappings (); }; - Analysis::NodeMapping get_trait_impl_mappings () const override - { - return get_mappings (); - }; - protected: /* Use covariance to implement clone function as returning this object * rather than base */ @@ -2326,19 +2259,6 @@ protected: { return new ConstantItem (*this); } - - /* Use covariance to implement clone function as returning this object - * rather than base */ - ConstantItem *clone_trait_impl_item_impl () const override - { - return new ConstantItem (*this); - } - - /* Use covariance to implement clone function as returning this object - * rather than base */ - /*virtual ConstantItem* clone_statement_impl() const override { - return new ConstantItem(*this); - }*/ }; /* Static item HIR node - items within module scope with fixed storage @@ -3120,104 +3040,13 @@ protected: { return new InherentImpl (*this); } - - /* Use covariance to implement clone function as returning this object - * rather than base */ - /*virtual InherentImpl* clone_statement_impl() const override { - return new InherentImpl(*this); - }*/ -}; - -// The "impl footrait for foo" impl block declaration HIR node -class TraitImpl : public Impl -{ - bool has_unsafe; - bool has_exclam; - std::unique_ptr<Type> trait_path; - - // bool has_impl_items; - std::vector<std::unique_ptr<TraitImplItem> > impl_items; - -public: - std::string as_string () const override; - - // Returns whether trait impl has impl items. - bool has_impl_items () const { return !impl_items.empty (); } - - // Mega-constructor - TraitImpl (Analysis::NodeMapping mappings, std::unique_ptr<Type> trait_path, - bool is_unsafe, bool has_exclam, - std::vector<std::unique_ptr<TraitImplItem> > impl_items, - std::vector<std::unique_ptr<GenericParam> > generic_params, - std::unique_ptr<Type> trait_type, WhereClause where_clause, - Visibility vis, AST::AttrVec inner_attrs, AST::AttrVec outer_attrs, - Location locus) - : Impl (std::move (mappings), std::move (generic_params), - std::move (trait_type), std::move (where_clause), std::move (vis), - std::move (inner_attrs), std::move (outer_attrs), locus), - has_unsafe (is_unsafe), has_exclam (has_exclam), - trait_path (std::move (trait_path)), impl_items (std::move (impl_items)) - {} - - // TODO: constructors with less params - - // Copy constructor with vector clone - TraitImpl (TraitImpl const &other) - : Impl (other), has_unsafe (other.has_unsafe), - has_exclam (other.has_exclam), - trait_path (other.trait_path->clone_type ()) - { - impl_items.reserve (other.impl_items.size ()); - for (const auto &e : other.impl_items) - impl_items.push_back (e->clone_trait_impl_item ()); - } - - // Overloaded assignment operator with vector clone - TraitImpl &operator= (TraitImpl const &other) - { - Impl::operator= (other); - trait_path = other.trait_path->clone_type (); - has_unsafe = other.has_unsafe; - has_exclam = other.has_exclam; - - impl_items.reserve (other.impl_items.size ()); - for (const auto &e : other.impl_items) - impl_items.push_back (e->clone_trait_impl_item ()); - - return *this; - } - - // move constructors - TraitImpl (TraitImpl &&other) = default; - TraitImpl &operator= (TraitImpl &&other) = default; - - void accept_vis (HIRVisitor &vis) override; - std::vector<std::unique_ptr<TraitImplItem> > &get_impl_items () - { - return impl_items; - }; - -protected: - /* Use covariance to implement clone function as returning this object - * rather than base */ - TraitImpl *clone_item_impl () const override { return new TraitImpl (*this); } - - /* Use covariance to implement clone function as returning this object - * rather than base */ - /*virtual TraitImpl* clone_statement_impl() const override { - return new TraitImpl(*this); - }*/ }; // Abstract base class for an item used inside an extern block class ExternalItem { - // bool has_outer_attrs; AST::AttrVec outer_attrs; - - // bool has_visibility; Visibility visibility; - Identifier item_name; Location locus; diff --git a/gcc/rust/hir/tree/rust-hir-visitor.h b/gcc/rust/hir/tree/rust-hir-visitor.h index 2efbbcf..0be28f3 100644 --- a/gcc/rust/hir/tree/rust-hir-visitor.h +++ b/gcc/rust/hir/tree/rust-hir-visitor.h @@ -128,7 +128,6 @@ public: virtual void visit (TraitItemType &item) = 0; virtual void visit (Trait &trait) = 0; virtual void visit (InherentImpl &impl) = 0; - virtual void visit (TraitImpl &impl) = 0; virtual void visit (ExternalStaticItem &item) = 0; virtual void visit (ExternalFunctionItem &item) = 0; virtual void visit (ExternBlock &block) = 0; diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h index 795e8e4..693fdd0 100644 --- a/gcc/rust/hir/tree/rust-hir.h +++ b/gcc/rust/hir/tree/rust-hir.h @@ -645,8 +645,6 @@ public: const Analysis::NodeMapping &get_mappings () const { return mappings; } }; -/* Abstract base class for items used within an inherent impl block (the impl - * name {} one) */ class InherentImplItem { protected: @@ -671,30 +669,6 @@ public: virtual Location get_impl_locus () const = 0; }; -// Abstract base class for items used in a trait impl -class TraitImplItem -{ -protected: - virtual TraitImplItem *clone_trait_impl_item_impl () const = 0; - -public: - virtual ~TraitImplItem (){}; - - // Unique pointer custom clone function - std::unique_ptr<TraitImplItem> clone_trait_impl_item () const - { - return std::unique_ptr<TraitImplItem> (clone_trait_impl_item_impl ()); - } - - virtual std::string as_string () const = 0; - - virtual void accept_vis (HIRVisitor &vis) = 0; - - virtual Analysis::NodeMapping get_trait_impl_mappings () const = 0; - - virtual Location get_trait_impl_locus () const = 0; -}; - // A crate HIR object - holds all the data for a single compilation unit struct Crate { diff --git a/gcc/rust/lint/rust-lint-marklive-base.h b/gcc/rust/lint/rust-lint-marklive-base.h index dda85a7..670554e 100644 --- a/gcc/rust/lint/rust-lint-marklive-base.h +++ b/gcc/rust/lint/rust-lint-marklive-base.h @@ -144,7 +144,6 @@ public: virtual void visit (HIR::TraitItemType &) override {} virtual void visit (HIR::Trait &) override {} virtual void visit (HIR::InherentImpl &) override {} - virtual void visit (HIR::TraitImpl &) override {} virtual void visit (HIR::ExternalStaticItem &) override {} virtual void visit (HIR::ExternalFunctionItem &) override {} diff --git a/gcc/rust/lint/rust-lint-marklive.h b/gcc/rust/lint/rust-lint-marklive.h index abc1ed3..cb22926 100644 --- a/gcc/rust/lint/rust-lint-marklive.h +++ b/gcc/rust/lint/rust-lint-marklive.h @@ -104,13 +104,7 @@ public: item.get ()->accept_vis (*this); } } - void visit (HIR::TraitImpl &impl) override - { - for (auto &&item : impl.get_impl_items ()) - { - item.get ()->accept_vis (*this); - } - } + void visit (HIR::LetStmt &stmt) override { if (stmt.has_init_expr ()) @@ -150,4 +144,4 @@ private: } // namespace Analysis } // namespace Rust -#endif
\ No newline at end of file +#endif diff --git a/gcc/rust/typecheck/rust-hir-const-fold-base.h b/gcc/rust/typecheck/rust-hir-const-fold-base.h index fce24d9..e16273e 100644 --- a/gcc/rust/typecheck/rust-hir-const-fold-base.h +++ b/gcc/rust/typecheck/rust-hir-const-fold-base.h @@ -147,7 +147,6 @@ public: virtual void visit (HIR::TraitItemType &) override {} virtual void visit (HIR::Trait &) override {} virtual void visit (HIR::InherentImpl &) override {} - virtual void visit (HIR::TraitImpl &) override {} virtual void visit (HIR::ExternalStaticItem &) override {} virtual void visit (HIR::ExternalFunctionItem &) override {} diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.h b/gcc/rust/typecheck/rust-hir-type-check-base.h index 3b2853c..eaa484e 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-base.h +++ b/gcc/rust/typecheck/rust-hir-type-check-base.h @@ -146,7 +146,6 @@ public: virtual void visit (HIR::TraitItemType &) override {} virtual void visit (HIR::Trait &) override {} virtual void visit (HIR::InherentImpl &) override {} - virtual void visit (HIR::TraitImpl &) override {} virtual void visit (HIR::ExternalStaticItem &) override {} virtual void visit (HIR::ExternalFunctionItem &) override {} diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.h b/gcc/rust/typecheck/rust-hir-type-check-implitem.h index bed89b8..2f54d0c 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-implitem.h +++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.h @@ -41,14 +41,6 @@ public: item->accept_vis (resolver); } - static void - Resolve (HIR::TraitImplItem *item, TyTy::BaseType *self, - std::vector<TyTy::SubstitutionParamMapping> substitutions) - { - TypeCheckTopLevelImplItem resolver (self, substitutions); - item->accept_vis (resolver); - } - void visit (HIR::ConstantItem &constant) override { TyTy::BaseType *type = TypeCheckType::Resolve (constant.get_type ()); @@ -227,12 +219,6 @@ public: item->accept_vis (resolver); } - static void Resolve (HIR::TraitImplItem *item, TyTy::BaseType *self) - { - TypeCheckImplItem resolver (self); - item->accept_vis (resolver); - } - void visit (HIR::Function &function) override { TyTy::BaseType *lookup; diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.h b/gcc/rust/typecheck/rust-hir-type-check-item.h index 47d9a8a..1205dce 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-item.h +++ b/gcc/rust/typecheck/rust-hir-type-check-item.h @@ -55,21 +55,6 @@ public: TypeCheckImplItem::Resolve (impl_item.get (), self); } - void visit (HIR::TraitImpl &impl_block) override - { - TyTy::BaseType *self = nullptr; - if (!context->lookup_type ( - impl_block.get_type ()->get_mappings ().get_hirid (), &self)) - { - rust_error_at (impl_block.get_locus (), - "failed to resolve Self for TraitImpl"); - return; - } - - for (auto &impl_item : impl_block.get_impl_items ()) - TypeCheckImplItem::Resolve (impl_item.get (), self); - } - void visit (HIR::Function &function) override { TyTy::BaseType *lookup; diff --git a/gcc/rust/typecheck/rust-hir-type-check-toplevel.h b/gcc/rust/typecheck/rust-hir-type-check-toplevel.h index 3ec231f..e01b46f 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-toplevel.h +++ b/gcc/rust/typecheck/rust-hir-type-check-toplevel.h @@ -273,47 +273,6 @@ public: substitutions); } - void visit (HIR::TraitImpl &impl_block) override - { - std::vector<TyTy::SubstitutionParamMapping> substitutions; - if (impl_block.has_generics ()) - { - for (auto &generic_param : impl_block.get_generic_params ()) - { - switch (generic_param.get ()->get_kind ()) - { - case HIR::GenericParam::GenericKind::LIFETIME: - // Skipping Lifetime completely until better handling. - break; - - case HIR::GenericParam::GenericKind::TYPE: { - auto param_type - = TypeResolveGenericParam::Resolve (generic_param.get ()); - context->insert_type (generic_param->get_mappings (), - param_type); - - substitutions.push_back (TyTy::SubstitutionParamMapping ( - static_cast<HIR::TypeParam &> (*generic_param), - param_type)); - } - break; - } - } - } - - // TODO - // resolve the trait and check all items implemented - - auto self - = TypeCheckType::Resolve (impl_block.get_type ().get (), &substitutions); - if (self == nullptr || self->get_kind () == TyTy::TypeKind::ERROR) - return; - - for (auto &impl_item : impl_block.get_impl_items ()) - TypeCheckTopLevelImplItem::Resolve (impl_item.get (), self, - substitutions); - } - private: TypeCheckTopLevel () : TypeCheckBase () {} }; |