From: Philip Herron Date: Thu, 1 Jun 2023 11:51:18 +0000 (+0100) Subject: gccrs: get rid of useless helper class and fix header usage X-Git-Tag: basepoints/gcc-15~2508 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3d751cbac030902014856bbbd310a90b02912af;p=thirdparty%2Fgcc.git gccrs: get rid of useless helper class and fix header usage gcc/rust/ChangeLog: * Make-lang.in: remove files * backend/rust-compile-block.h: fix headers * backend/rust-compile-expr.h: likewise * backend/rust-compile-fnparam.h: likewise * backend/rust-compile-item.h: likewise * backend/rust-compile-pattern.h: likewise * backend/rust-compile-resolve-path.h: likewise * backend/rust-compile-stmt.h: likewise * typecheck/rust-autoderef.cc: likewise * typecheck/rust-hir-path-probe.cc: likewise * typecheck/rust-hir-path-probe.h: likewise * typecheck/rust-hir-trait-reference.h: likewise * typecheck/rust-hir-trait-resolve.cc: use a for loop instead * typecheck/rust-hir-trait-resolve.h: fix headers * typecheck/rust-hir-type-check-expr.h: likewise * typecheck/rust-hir-type-check-implitem.h: likewise * typecheck/rust-hir-type-check-item.h: likewise * typecheck/rust-hir-type-check-path.cc: likewise * typecheck/rust-hir-type-check-pattern.h: likewise * typecheck/rust-hir-type-check-stmt.h: likewise * typecheck/rust-hir-type-check-type.h: likewise * typecheck/rust-hir-type-check-util.cc: Removed. * typecheck/rust-hir-type-check-util.h: Removed. Signed-off-by: Philip Herron --- diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index 1d72c86c1687..e708ac30a10e 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -130,7 +130,6 @@ GRS_OBJS = \ rust/rust-tyty-subst.o \ rust/rust-typecheck-context.o \ rust/rust-tyty-bounds.o \ - rust/rust-hir-type-check-util.o \ rust/rust-hir-trait-resolve.o \ rust/rust-hir-trait-reference.o \ rust/rust-hir-type-check-item.o \ diff --git a/gcc/rust/backend/rust-compile-block.h b/gcc/rust/backend/rust-compile-block.h index 8e3b53b86f23..9135c63a7af5 100644 --- a/gcc/rust/backend/rust-compile-block.h +++ b/gcc/rust/backend/rust-compile-block.h @@ -20,6 +20,7 @@ #define RUST_COMPILE_BLOCK #include "rust-compile-base.h" +#include "rust-hir-visitor.h" namespace Rust { namespace Compile { diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index 52db04c200a5..95c00520d7d6 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -20,6 +20,7 @@ #define RUST_COMPILE_EXPR #include "rust-compile-base.h" +#include "rust-hir-visitor.h" namespace Rust { namespace Compile { diff --git a/gcc/rust/backend/rust-compile-fnparam.h b/gcc/rust/backend/rust-compile-fnparam.h index fa249a240fe8..10b4efbb6e8d 100644 --- a/gcc/rust/backend/rust-compile-fnparam.h +++ b/gcc/rust/backend/rust-compile-fnparam.h @@ -20,6 +20,7 @@ #define RUST_COMPILE_FNPARAM #include "rust-compile-base.h" +#include "rust-hir-visitor.h" namespace Rust { namespace Compile { diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h index 87251ea1c60e..7ee1d2826478 100644 --- a/gcc/rust/backend/rust-compile-item.h +++ b/gcc/rust/backend/rust-compile-item.h @@ -20,6 +20,7 @@ #define RUST_COMPILE_ITEM #include "rust-compile-base.h" +#include "rust-hir-visitor.h" namespace Rust { namespace Compile { diff --git a/gcc/rust/backend/rust-compile-pattern.h b/gcc/rust/backend/rust-compile-pattern.h index 3fba9c51f051..dfc67d696248 100644 --- a/gcc/rust/backend/rust-compile-pattern.h +++ b/gcc/rust/backend/rust-compile-pattern.h @@ -17,6 +17,7 @@ // . #include "rust-compile-base.h" +#include "rust-hir-visitor.h" namespace Rust { namespace Compile { diff --git a/gcc/rust/backend/rust-compile-resolve-path.h b/gcc/rust/backend/rust-compile-resolve-path.h index 93b0a7f85558..05c882e5b6fd 100644 --- a/gcc/rust/backend/rust-compile-resolve-path.h +++ b/gcc/rust/backend/rust-compile-resolve-path.h @@ -20,6 +20,7 @@ #define RUST_COMPILE_RESOLVE_PATH #include "rust-compile-base.h" +#include "rust-hir-visitor.h" namespace Rust { namespace Compile { diff --git a/gcc/rust/backend/rust-compile-stmt.h b/gcc/rust/backend/rust-compile-stmt.h index 7b9e93d193db..7ccc356b8bad 100644 --- a/gcc/rust/backend/rust-compile-stmt.h +++ b/gcc/rust/backend/rust-compile-stmt.h @@ -20,6 +20,7 @@ #define RUST_COMPILE_STMT #include "rust-compile-base.h" +#include "rust-hir-visitor.h" namespace Rust { namespace Compile { diff --git a/gcc/rust/typecheck/rust-autoderef.cc b/gcc/rust/typecheck/rust-autoderef.cc index 2f21d2685e4f..8f5f6242aa2b 100644 --- a/gcc/rust/typecheck/rust-autoderef.cc +++ b/gcc/rust/typecheck/rust-autoderef.cc @@ -21,6 +21,7 @@ #include "rust-hir-dot-operator.h" #include "rust-hir-trait-resolve.h" #include "rust-type-util.h" +#include "rust-substitution-mapper.h" namespace Rust { namespace Resolver { diff --git a/gcc/rust/typecheck/rust-hir-path-probe.cc b/gcc/rust/typecheck/rust-hir-path-probe.cc index b38282c487c9..83012ed5ef5d 100644 --- a/gcc/rust/typecheck/rust-hir-path-probe.cc +++ b/gcc/rust/typecheck/rust-hir-path-probe.cc @@ -19,6 +19,8 @@ #include "rust-hir-path-probe.h" #include "rust-hir-trait-resolve.h" #include "rust-type-util.h" +#include "rust-hir-type-bounds.h" +#include "rust-hir-full.h" namespace Rust { namespace Resolver { diff --git a/gcc/rust/typecheck/rust-hir-path-probe.h b/gcc/rust/typecheck/rust-hir-path-probe.h index 893353497a80..1429a64f50ca 100644 --- a/gcc/rust/typecheck/rust-hir-path-probe.h +++ b/gcc/rust/typecheck/rust-hir-path-probe.h @@ -20,10 +20,8 @@ #define RUST_HIR_PATH_PROBE_H #include "rust-hir-type-check-base.h" -#include "rust-hir-full.h" +#include "rust-hir-visitor.h" #include "rust-tyty.h" -#include "rust-substitution-mapper.h" -#include "rust-hir-type-bounds.h" namespace Rust { namespace Resolver { diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.h b/gcc/rust/typecheck/rust-hir-trait-reference.h index 8ccd29f0861d..76d2d8bae83d 100644 --- a/gcc/rust/typecheck/rust-hir-trait-reference.h +++ b/gcc/rust/typecheck/rust-hir-trait-reference.h @@ -20,7 +20,6 @@ #define RUST_HIR_TRAIT_REF_H #include "rust-hir-full.h" -#include "rust-hir-type-check-util.h" #include "rust-tyty-visitor.h" namespace Rust { diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc index 20ee2e25306d..37d4239fc0cb 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc @@ -567,26 +567,34 @@ AssociatedImplTrait::setup_associated_types ( TyTy::SubstitutionArgumentMappings associated_type_args ( std::move (associated_arguments), {}, locus); - ImplTypeIterator iter (*impl, [&] (HIR::TypeAlias &type) { - TraitItemReference *resolved_trait_item = nullptr; - bool ok = trait->lookup_trait_item (type.get_new_type_name (), - &resolved_trait_item); - if (!ok) - return; - if (resolved_trait_item->get_trait_item_type () - != TraitItemReference::TraitItemType::TYPE) - return; - - TyTy::BaseType *lookup; - if (!context->lookup_type (type.get_mappings ().get_hirid (), &lookup)) - return; - - // this might be generic - TyTy::BaseType *substituted - = SubstMapperInternal::Resolve (lookup, associated_type_args); - resolved_trait_item->associated_type_set (substituted); - }); - iter.go (); + auto &impl_items = impl->get_impl_items (); + for (auto &impl_item : impl_items) + { + bool is_type_alias = impl_item->get_impl_item_type () + == HIR::ImplItem::ImplItemType::TYPE_ALIAS; + if (!is_type_alias) + continue; + + HIR::TypeAlias &type = *static_cast (impl_item.get ()); + + TraitItemReference *resolved_trait_item = nullptr; + bool ok = trait->lookup_trait_item (type.get_new_type_name (), + &resolved_trait_item); + if (!ok) + continue; + if (resolved_trait_item->get_trait_item_type () + != TraitItemReference::TraitItemType::TYPE) + continue; + + TyTy::BaseType *lookup; + if (!context->lookup_type (type.get_mappings ().get_hirid (), &lookup)) + continue; + + // this might be generic + TyTy::BaseType *substituted + = SubstMapperInternal::Resolve (lookup, associated_type_args); + resolved_trait_item->associated_type_set (substituted); + } return self_result; } diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.h b/gcc/rust/typecheck/rust-hir-trait-resolve.h index 26bf280361e7..93371a7be253 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.h +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.h @@ -20,6 +20,7 @@ #define RUST_HIR_TRAIT_RESOLVE_H #include "rust-hir-type-check-type.h" +#include "rust-hir-visitor.h" namespace Rust { namespace Resolver { diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h index 031d20fe9e0a..5f931d8d517f 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.h +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h @@ -20,6 +20,7 @@ #define RUST_HIR_TYPE_CHECK_EXPR #include "rust-hir-type-check-base.h" +#include "rust-hir-visitor.h" #include "rust-tyty.h" namespace Rust { diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.h b/gcc/rust/typecheck/rust-hir-type-check-implitem.h index 10c007580c34..7db06c0a89fd 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-implitem.h +++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.h @@ -20,6 +20,7 @@ #define RUST_HIR_TYPE_CHECK_IMPLITEM_H #include "rust-hir-type-check-base.h" +#include "rust-hir-visitor.h" namespace Rust { namespace Resolver { diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.h b/gcc/rust/typecheck/rust-hir-type-check-item.h index b83fb5659485..432b29271a5b 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-item.h +++ b/gcc/rust/typecheck/rust-hir-type-check-item.h @@ -20,6 +20,7 @@ #define RUST_HIR_TYPE_CHECK_ITEM #include "rust-hir-type-check-base.h" +#include "rust-hir-visitor.h" namespace Rust { namespace Resolver { diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index 037a2d7dc166..a52a4e4397ac 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -23,6 +23,7 @@ #include "rust-substitution-mapper.h" #include "rust-hir-path-probe.h" #include "rust-type-util.h" +#include "rust-hir-type-bounds.h" namespace Rust { namespace Resolver { diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.h b/gcc/rust/typecheck/rust-hir-type-check-pattern.h index 4bf371ffa06c..cdfc34ba001f 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-pattern.h +++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.h @@ -20,6 +20,7 @@ #define RUST_HIR_TYPE_CHECK_PATTERN #include "rust-hir-type-check-base.h" +#include "rust-hir-visitor.h" namespace Rust { namespace Resolver { diff --git a/gcc/rust/typecheck/rust-hir-type-check-stmt.h b/gcc/rust/typecheck/rust-hir-type-check-stmt.h index 1c38416b6d5e..947d5ab49721 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-stmt.h +++ b/gcc/rust/typecheck/rust-hir-type-check-stmt.h @@ -20,6 +20,7 @@ #define RUST_HIR_TYPE_CHECK_STMT #include "rust-hir-type-check-base.h" +#include "rust-hir-visitor.h" namespace Rust { namespace Resolver { diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.h b/gcc/rust/typecheck/rust-hir-type-check-type.h index 2eeb12b12833..f8eb9c4c1ba9 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.h +++ b/gcc/rust/typecheck/rust-hir-type-check-type.h @@ -20,6 +20,7 @@ #define RUST_HIR_TYPE_CHECK_TYPE #include "rust-hir-type-check-base.h" +#include "rust-hir-visitor.h" namespace Rust { namespace Resolver { diff --git a/gcc/rust/typecheck/rust-hir-type-check-util.cc b/gcc/rust/typecheck/rust-hir-type-check-util.cc deleted file mode 100644 index b9bd5bc8c834..000000000000 --- a/gcc/rust/typecheck/rust-hir-type-check-util.cc +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) 2021-2024 Free Software Foundation, Inc. - -// This file is part of GCC. - -// GCC is free software; you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation; either version 3, or (at your option) any later -// version. - -// GCC is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. - -// You should have received a copy of the GNU General Public License -// along with GCC; see the file COPYING3. If not see -// . - -#include "rust-hir-type-check-util.h" -#include "rust-hir-full.h" - -namespace Rust { -namespace Resolver { - -void -ImplTypeIterator::go () -{ - for (auto &item : impl.get_impl_items ()) - { - item->accept_vis (*this); - } -} - -void -ImplTypeIterator::visit (HIR::TypeAlias &alias) -{ - cb (alias); -} - -} // namespace Resolver -} // namespace Rust diff --git a/gcc/rust/typecheck/rust-hir-type-check-util.h b/gcc/rust/typecheck/rust-hir-type-check-util.h deleted file mode 100644 index 6d8171a97828..000000000000 --- a/gcc/rust/typecheck/rust-hir-type-check-util.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2021-2024 Free Software Foundation, Inc. - -// This file is part of GCC. - -// GCC is free software; you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation; either version 3, or (at your option) any later -// version. - -// GCC is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. - -// You should have received a copy of the GNU General Public License -// along with GCC; see the file COPYING3. If not see -// . - -#ifndef RUST_HIR_TYPE_CHECK_UTIL_H -#define RUST_HIR_TYPE_CHECK_UTIL_H - -#include "rust-system.h" -#include "rust-hir-visitor.h" - -namespace Rust { -namespace Resolver { - -class ImplTypeIterator : public HIR::HIRFullVisitorBase -{ - using HIR::HIRFullVisitorBase::visit; - -public: - ImplTypeIterator (HIR::ImplBlock &impl, - std::function cb) - : impl (impl), cb (cb) - {} - - void go (); - - void visit (HIR::TypeAlias &alias) override; - -private: - HIR::ImplBlock &impl; - std::function cb; -}; - -} // namespace Resolver -} // namespace Rust - -#endif // RUST_HIR_TYPE_CHECK_UTIL_H