From: arthur.cohen@embecosm.com
To: gcc-patches@gcc.gnu.org
Cc: gcc-rust@gcc.gnu.org, Philip Herron <herron.philip@googlemail.com>
Subject: [committed 41/88] gccrs: Refactor PathProbe into cc file
Date: Wed, 5 Apr 2023 16:03:25 +0200 [thread overview]
Message-ID: <20230405140411.3016563-42-arthur.cohen@embecosm.com> (raw)
In-Reply-To: <20230405140411.3016563-1-arthur.cohen@embecosm.com>
From: Philip Herron <herron.philip@googlemail.com>
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:
* typecheck/rust-hir-path-probe.cc (PathProbeType::PathProbeType): refactor
(PathProbeType::Probe): likewise
(PathProbeType::visit): likewise
(PathProbeType::process_enum_item_for_candiates): likewise
(PathProbeType::process_impl_items_for_candidates): likewise
(PathProbeType::is_reciever_generic): likewise
(PathProbeImplTrait::PathProbeImplTrait): likewise
(PathProbeImplTrait::Probe): likewise
(PathProbeImplTrait::process_trait_impl_items_for_candidates): likewise
* typecheck/rust-hir-path-probe.h (struct PathProbeCandidate): likewise
* typecheck/rust-hir-trait-resolve.cc
(PathProbeImplTrait::process_trait_impl_items_for_candidates): likewise
---
gcc/rust/typecheck/rust-hir-path-probe.cc | 344 +++++++++++++++++++
gcc/rust/typecheck/rust-hir-path-probe.h | 302 +---------------
gcc/rust/typecheck/rust-hir-trait-resolve.cc | 22 --
3 files changed, 360 insertions(+), 308 deletions(-)
diff --git a/gcc/rust/typecheck/rust-hir-path-probe.cc b/gcc/rust/typecheck/rust-hir-path-probe.cc
index cb3270d3623..06d8920d2eb 100644
--- a/gcc/rust/typecheck/rust-hir-path-probe.cc
+++ b/gcc/rust/typecheck/rust-hir-path-probe.cc
@@ -18,10 +18,168 @@
#include "rust-hir-path-probe.h"
#include "rust-hir-type-check-item.h"
+#include "rust-hir-trait-resolve.h"
namespace Rust {
namespace Resolver {
+// PathProbeType
+
+PathProbeType::PathProbeType (const TyTy::BaseType *receiver,
+ const HIR::PathIdentSegment &query,
+ DefId specific_trait_id)
+ : TypeCheckBase (), receiver (receiver), search (query),
+ current_impl (nullptr), specific_trait_id (specific_trait_id)
+{}
+
+std::set<PathProbeCandidate>
+PathProbeType::Probe (const TyTy::BaseType *receiver,
+ const HIR::PathIdentSegment &segment_name,
+ bool probe_impls, bool probe_bounds,
+ bool ignore_mandatory_trait_items,
+ DefId specific_trait_id)
+{
+ PathProbeType probe (receiver, segment_name, specific_trait_id);
+ if (probe_impls)
+ {
+ if (receiver->get_kind () == TyTy::TypeKind::ADT)
+ {
+ const TyTy::ADTType *adt
+ = static_cast<const TyTy::ADTType *> (receiver);
+ if (adt->is_enum ())
+ probe.process_enum_item_for_candiates (adt);
+ }
+
+ probe.process_impl_items_for_candidates ();
+ }
+
+ if (!probe_bounds)
+ return probe.candidates;
+
+ if (!probe.is_reciever_generic ())
+ {
+ std::vector<std::pair<TraitReference *, HIR::ImplBlock *>> probed_bounds
+ = TypeBoundsProbe::Probe (receiver);
+ for (auto &candidate : probed_bounds)
+ {
+ const TraitReference *trait_ref = candidate.first;
+ if (specific_trait_id != UNKNOWN_DEFID)
+ {
+ if (trait_ref->get_mappings ().get_defid () != specific_trait_id)
+ continue;
+ }
+
+ HIR::ImplBlock *impl = candidate.second;
+ probe.process_associated_trait_for_candidates (
+ trait_ref, impl, ignore_mandatory_trait_items);
+ }
+ }
+
+ for (const TyTy::TypeBoundPredicate &predicate :
+ receiver->get_specified_bounds ())
+ {
+ const TraitReference *trait_ref = predicate.get ();
+ if (specific_trait_id != UNKNOWN_DEFID)
+ {
+ if (trait_ref->get_mappings ().get_defid () != specific_trait_id)
+ continue;
+ }
+
+ probe.process_predicate_for_candidates (predicate,
+ ignore_mandatory_trait_items);
+ }
+
+ return probe.candidates;
+}
+
+void
+PathProbeType::visit (HIR::TypeAlias &alias)
+{
+ Identifier name = alias.get_new_type_name ();
+ if (search.as_string ().compare (name) == 0)
+ {
+ HirId tyid = alias.get_mappings ().get_hirid ();
+ TyTy::BaseType *ty = nullptr;
+ bool ok = query_type (tyid, &ty);
+ rust_assert (ok);
+
+ PathProbeCandidate::ImplItemCandidate impl_item_candidate{&alias,
+ current_impl};
+ PathProbeCandidate candidate{
+ PathProbeCandidate::CandidateType::IMPL_TYPE_ALIAS, ty,
+ alias.get_locus (), impl_item_candidate};
+ candidates.insert (std::move (candidate));
+ }
+}
+
+void
+PathProbeType::visit (HIR::ConstantItem &constant)
+{
+ Identifier name = constant.get_identifier ();
+ if (search.as_string ().compare (name) == 0)
+ {
+ HirId tyid = constant.get_mappings ().get_hirid ();
+ TyTy::BaseType *ty = nullptr;
+ bool ok = query_type (tyid, &ty);
+ rust_assert (ok);
+
+ PathProbeCandidate::ImplItemCandidate impl_item_candidate{&constant,
+ current_impl};
+ PathProbeCandidate candidate{
+ PathProbeCandidate::CandidateType::IMPL_CONST, ty,
+ constant.get_locus (), impl_item_candidate};
+ candidates.insert (std::move (candidate));
+ }
+}
+
+void
+PathProbeType::visit (HIR::Function &function)
+{
+ Identifier name = function.get_function_name ();
+ if (search.as_string ().compare (name) == 0)
+ {
+ HirId tyid = function.get_mappings ().get_hirid ();
+ TyTy::BaseType *ty = nullptr;
+ bool ok = query_type (tyid, &ty);
+ rust_assert (ok);
+
+ PathProbeCandidate::ImplItemCandidate impl_item_candidate{&function,
+ current_impl};
+ PathProbeCandidate candidate{PathProbeCandidate::CandidateType::IMPL_FUNC,
+ ty, function.get_locus (),
+ impl_item_candidate};
+ candidates.insert (std::move (candidate));
+ }
+}
+
+void
+PathProbeType::process_enum_item_for_candiates (const TyTy::ADTType *adt)
+{
+ if (specific_trait_id != UNKNOWN_DEFID)
+ return;
+
+ TyTy::VariantDef *v;
+ if (!adt->lookup_variant (search.as_string (), &v))
+ return;
+
+ PathProbeCandidate::EnumItemCandidate enum_item_candidate{adt, v};
+ PathProbeCandidate candidate{PathProbeCandidate::CandidateType::ENUM_VARIANT,
+ receiver->clone (),
+ mappings->lookup_location (adt->get_ty_ref ()),
+ enum_item_candidate};
+ candidates.insert (std::move (candidate));
+}
+
+void
+PathProbeType::process_impl_items_for_candidates ()
+{
+ mappings->iterate_impl_items (
+ [&] (HirId id, HIR::ImplItem *item, HIR::ImplBlock *impl) mutable -> bool {
+ process_impl_item_candidate (id, item, impl);
+ return true;
+ });
+}
+
void
PathProbeType::process_impl_item_candidate (HirId id, HIR::ImplItem *item,
HIR::ImplBlock *impl)
@@ -42,5 +200,191 @@ PathProbeType::process_impl_item_candidate (HirId id, HIR::ImplItem *item,
item->accept_vis (*this);
}
+void
+PathProbeType::process_associated_trait_for_candidates (
+ const TraitReference *trait_ref, HIR::ImplBlock *impl,
+ bool ignore_mandatory_trait_items)
+{
+ const TraitItemReference *trait_item_ref = nullptr;
+ if (!trait_ref->lookup_trait_item (search.as_string (), &trait_item_ref))
+ return;
+
+ bool trait_item_needs_implementation = !trait_item_ref->is_optional ();
+ if (ignore_mandatory_trait_items && trait_item_needs_implementation)
+ return;
+
+ PathProbeCandidate::CandidateType candidate_type;
+ switch (trait_item_ref->get_trait_item_type ())
+ {
+ case TraitItemReference::TraitItemType::FN:
+ candidate_type = PathProbeCandidate::CandidateType::TRAIT_FUNC;
+ break;
+ case TraitItemReference::TraitItemType::CONST:
+ candidate_type = PathProbeCandidate::CandidateType::TRAIT_ITEM_CONST;
+ break;
+ case TraitItemReference::TraitItemType::TYPE:
+ candidate_type = PathProbeCandidate::CandidateType::TRAIT_TYPE_ALIAS;
+ break;
+
+ case TraitItemReference::TraitItemType::ERROR:
+ default:
+ gcc_unreachable ();
+ break;
+ }
+
+ TyTy::BaseType *trait_item_tyty = trait_item_ref->get_tyty ();
+
+ // we can substitute the Self with the receiver here
+ if (trait_item_tyty->get_kind () == TyTy::TypeKind::FNDEF)
+ {
+ TyTy::FnType *fn = static_cast<TyTy::FnType *> (trait_item_tyty);
+ TyTy::SubstitutionParamMapping *param = nullptr;
+ for (auto ¶m_mapping : fn->get_substs ())
+ {
+ const HIR::TypeParam &type_param = param_mapping.get_generic_param ();
+ if (type_param.get_type_representation ().compare ("Self") == 0)
+ {
+ param = ¶m_mapping;
+ break;
+ }
+ }
+ rust_assert (param != nullptr);
+
+ std::vector<TyTy::SubstitutionArg> mappings;
+ mappings.push_back (TyTy::SubstitutionArg (param, receiver->clone ()));
+
+ Location locus; // FIXME
+ TyTy::SubstitutionArgumentMappings args (std::move (mappings), {}, locus);
+ trait_item_tyty = SubstMapperInternal::Resolve (trait_item_tyty, args);
+ }
+
+ PathProbeCandidate::TraitItemCandidate trait_item_candidate{trait_ref,
+ trait_item_ref,
+ impl};
+
+ PathProbeCandidate candidate{candidate_type, trait_item_tyty,
+ trait_item_ref->get_locus (),
+ trait_item_candidate};
+ candidates.insert (std::move (candidate));
+}
+
+void
+PathProbeType::process_predicate_for_candidates (
+ const TyTy::TypeBoundPredicate &predicate, bool ignore_mandatory_trait_items)
+{
+ const TraitReference *trait_ref = predicate.get ();
+
+ TyTy::TypeBoundPredicateItem item
+ = predicate.lookup_associated_item (search.as_string ());
+ if (item.is_error ())
+ return;
+
+ if (ignore_mandatory_trait_items && item.needs_implementation ())
+ return;
+
+ const TraitItemReference *trait_item_ref = item.get_raw_item ();
+ PathProbeCandidate::CandidateType candidate_type;
+ switch (trait_item_ref->get_trait_item_type ())
+ {
+ case TraitItemReference::TraitItemType::FN:
+ candidate_type = PathProbeCandidate::CandidateType::TRAIT_FUNC;
+ break;
+ case TraitItemReference::TraitItemType::CONST:
+ candidate_type = PathProbeCandidate::CandidateType::TRAIT_ITEM_CONST;
+ break;
+ case TraitItemReference::TraitItemType::TYPE:
+ candidate_type = PathProbeCandidate::CandidateType::TRAIT_TYPE_ALIAS;
+ break;
+
+ case TraitItemReference::TraitItemType::ERROR:
+ default:
+ gcc_unreachable ();
+ break;
+ }
+
+ TyTy::BaseType *trait_item_tyty = item.get_tyty_for_receiver (receiver);
+ PathProbeCandidate::TraitItemCandidate trait_item_candidate{trait_ref,
+ trait_item_ref,
+ nullptr};
+ PathProbeCandidate candidate{candidate_type, trait_item_tyty,
+ trait_item_ref->get_locus (),
+ trait_item_candidate};
+ candidates.insert (std::move (candidate));
+}
+
+std::vector<std::pair<const TraitReference *, HIR::ImplBlock *>>
+PathProbeType::union_bounds (
+ const std::vector<std::pair</*const*/ TraitReference *, HIR::ImplBlock *>> a,
+ const std::vector<std::pair<const TraitReference *, HIR::ImplBlock *>> b)
+ const
+{
+ std::map<DefId, std::pair<const TraitReference *, HIR::ImplBlock *>> mapper;
+ for (auto &ref : a)
+ {
+ mapper.insert ({ref.first->get_mappings ().get_defid (), ref});
+ }
+ for (auto &ref : b)
+ {
+ mapper.insert ({ref.first->get_mappings ().get_defid (), ref});
+ }
+
+ std::vector<std::pair<const TraitReference *, HIR::ImplBlock *>> union_set;
+ for (auto it = mapper.begin (); it != mapper.end (); it++)
+ {
+ union_set.push_back ({it->second.first, it->second.second});
+ }
+ return union_set;
+}
+
+bool
+PathProbeType::is_reciever_generic () const
+{
+ const TyTy::BaseType *root = receiver->get_root ();
+ bool receiver_is_type_param = root->get_kind () == TyTy::TypeKind::PARAM;
+ bool receiver_is_dyn = root->get_kind () == TyTy::TypeKind::DYNAMIC;
+ return receiver_is_type_param || receiver_is_dyn;
+}
+
+// PathProbImplTrait
+
+PathProbeImplTrait::PathProbeImplTrait (const TyTy::BaseType *receiver,
+ const HIR::PathIdentSegment &query,
+ const TraitReference *trait_reference)
+ : PathProbeType (receiver, query, UNKNOWN_DEFID),
+ trait_reference (trait_reference)
+{}
+
+std::set<PathProbeCandidate>
+PathProbeImplTrait::Probe (const TyTy::BaseType *receiver,
+ const HIR::PathIdentSegment &segment_name,
+ const TraitReference *trait_reference)
+{
+ PathProbeImplTrait probe (receiver, segment_name, trait_reference);
+ // iterate all impls for this trait and receiver
+ // then search for possible candidates using base class behaviours
+ probe.process_trait_impl_items_for_candidates ();
+ return probe.candidates;
+}
+
+void
+PathProbeImplTrait::process_trait_impl_items_for_candidates ()
+{
+ mappings->iterate_impl_items (
+ [&] (HirId id, HIR::ImplItem *item, HIR::ImplBlock *impl) mutable -> bool {
+ // just need to check if this is an impl block for this trait the next
+ // function checks the receiver
+ if (!impl->has_trait_ref ())
+ return true;
+
+ TraitReference *resolved
+ = TraitResolver::Lookup (*(impl->get_trait_ref ().get ()));
+ if (!trait_reference->is_equal (*resolved))
+ return true;
+
+ process_impl_item_candidate (id, item, impl);
+ return true;
+ });
+}
+
} // namespace Resolver
} // namespace Rust
diff --git a/gcc/rust/typecheck/rust-hir-path-probe.h b/gcc/rust/typecheck/rust-hir-path-probe.h
index bb8698ce0e1..783282a0dc9 100644
--- a/gcc/rust/typecheck/rust-hir-path-probe.h
+++ b/gcc/rust/typecheck/rust-hir-path-probe.h
@@ -152,7 +152,7 @@ struct PathProbeCandidate
return UNKNOWN_DEFID;
}
- bool operator< (const PathProbeCandidate &c) const
+ bool operator<(const PathProbeCandidate &c) const
{
return get_defid () < c.get_defid ();
}
@@ -165,144 +165,16 @@ public:
Probe (const TyTy::BaseType *receiver,
const HIR::PathIdentSegment &segment_name, bool probe_impls,
bool probe_bounds, bool ignore_mandatory_trait_items,
- DefId specific_trait_id = UNKNOWN_DEFID)
- {
- PathProbeType probe (receiver, segment_name, specific_trait_id);
- if (probe_impls)
- {
- if (receiver->get_kind () == TyTy::TypeKind::ADT)
- {
- const TyTy::ADTType *adt
- = static_cast<const TyTy::ADTType *> (receiver);
- if (adt->is_enum ())
- probe.process_enum_item_for_candiates (adt);
- }
-
- probe.process_impl_items_for_candidates ();
- }
+ DefId specific_trait_id = UNKNOWN_DEFID);
- if (!probe_bounds)
- return probe.candidates;
-
- if (!probe.is_reciever_generic ())
- {
- std::vector<std::pair<TraitReference *, HIR::ImplBlock *>> probed_bounds
- = TypeBoundsProbe::Probe (receiver);
- for (auto &candidate : probed_bounds)
- {
- const TraitReference *trait_ref = candidate.first;
- if (specific_trait_id != UNKNOWN_DEFID)
- {
- if (trait_ref->get_mappings ().get_defid ()
- != specific_trait_id)
- continue;
- }
-
- HIR::ImplBlock *impl = candidate.second;
- probe.process_associated_trait_for_candidates (
- trait_ref, impl, ignore_mandatory_trait_items);
- }
- }
-
- for (const TyTy::TypeBoundPredicate &predicate :
- receiver->get_specified_bounds ())
- {
- const TraitReference *trait_ref = predicate.get ();
- if (specific_trait_id != UNKNOWN_DEFID)
- {
- if (trait_ref->get_mappings ().get_defid () != specific_trait_id)
- continue;
- }
-
- probe.process_predicate_for_candidates (predicate,
- ignore_mandatory_trait_items);
- }
-
- return probe.candidates;
- }
-
- void visit (HIR::TypeAlias &alias) override
- {
- Identifier name = alias.get_new_type_name ();
- if (search.as_string ().compare (name) == 0)
- {
- HirId tyid = alias.get_mappings ().get_hirid ();
- TyTy::BaseType *ty = nullptr;
- bool ok = query_type (tyid, &ty);
- rust_assert (ok);
-
- PathProbeCandidate::ImplItemCandidate impl_item_candidate{&alias,
- current_impl};
- PathProbeCandidate candidate{
- PathProbeCandidate::CandidateType::IMPL_TYPE_ALIAS, ty,
- alias.get_locus (), impl_item_candidate};
- candidates.insert (std::move (candidate));
- }
- }
-
- void visit (HIR::ConstantItem &constant) override
- {
- Identifier name = constant.get_identifier ();
- if (search.as_string ().compare (name) == 0)
- {
- HirId tyid = constant.get_mappings ().get_hirid ();
- TyTy::BaseType *ty = nullptr;
- bool ok = query_type (tyid, &ty);
- rust_assert (ok);
-
- PathProbeCandidate::ImplItemCandidate impl_item_candidate{&constant,
- current_impl};
- PathProbeCandidate candidate{
- PathProbeCandidate::CandidateType::IMPL_CONST, ty,
- constant.get_locus (), impl_item_candidate};
- candidates.insert (std::move (candidate));
- }
- }
-
- void visit (HIR::Function &function) override
- {
- Identifier name = function.get_function_name ();
- if (search.as_string ().compare (name) == 0)
- {
- HirId tyid = function.get_mappings ().get_hirid ();
- TyTy::BaseType *ty = nullptr;
- bool ok = query_type (tyid, &ty);
- rust_assert (ok);
-
- PathProbeCandidate::ImplItemCandidate impl_item_candidate{&function,
- current_impl};
- PathProbeCandidate candidate{
- PathProbeCandidate::CandidateType::IMPL_FUNC, ty,
- function.get_locus (), impl_item_candidate};
- candidates.insert (std::move (candidate));
- }
- }
+ void visit (HIR::TypeAlias &alias) override;
+ void visit (HIR::ConstantItem &constant) override;
+ void visit (HIR::Function &function) override;
protected:
- void process_enum_item_for_candiates (const TyTy::ADTType *adt)
- {
- if (specific_trait_id != UNKNOWN_DEFID)
- return;
-
- TyTy::VariantDef *v;
- if (!adt->lookup_variant (search.as_string (), &v))
- return;
-
- PathProbeCandidate::EnumItemCandidate enum_item_candidate{adt, v};
- PathProbeCandidate candidate{
- PathProbeCandidate::CandidateType::ENUM_VARIANT, receiver->clone (),
- mappings->lookup_location (adt->get_ty_ref ()), enum_item_candidate};
- candidates.insert (std::move (candidate));
- }
+ void process_enum_item_for_candiates (const TyTy::ADTType *adt);
- void process_impl_items_for_candidates ()
- {
- mappings->iterate_impl_items ([&] (HirId id, HIR::ImplItem *item,
- HIR::ImplBlock *impl) mutable -> bool {
- process_impl_item_candidate (id, item, impl);
- return true;
- });
- }
+ void process_impl_items_for_candidates ();
void process_impl_item_candidate (HirId id, HIR::ImplItem *item,
HIR::ImplBlock *impl);
@@ -310,156 +182,24 @@ protected:
void
process_associated_trait_for_candidates (const TraitReference *trait_ref,
HIR::ImplBlock *impl,
- bool ignore_mandatory_trait_items)
- {
- const TraitItemReference *trait_item_ref = nullptr;
- if (!trait_ref->lookup_trait_item (search.as_string (), &trait_item_ref))
- return;
-
- bool trait_item_needs_implementation = !trait_item_ref->is_optional ();
- if (ignore_mandatory_trait_items && trait_item_needs_implementation)
- return;
-
- PathProbeCandidate::CandidateType candidate_type;
- switch (trait_item_ref->get_trait_item_type ())
- {
- case TraitItemReference::TraitItemType::FN:
- candidate_type = PathProbeCandidate::CandidateType::TRAIT_FUNC;
- break;
- case TraitItemReference::TraitItemType::CONST:
- candidate_type = PathProbeCandidate::CandidateType::TRAIT_ITEM_CONST;
- break;
- case TraitItemReference::TraitItemType::TYPE:
- candidate_type = PathProbeCandidate::CandidateType::TRAIT_TYPE_ALIAS;
- break;
-
- case TraitItemReference::TraitItemType::ERROR:
- default:
- gcc_unreachable ();
- break;
- }
-
- TyTy::BaseType *trait_item_tyty = trait_item_ref->get_tyty ();
-
- // we can substitute the Self with the receiver here
- if (trait_item_tyty->get_kind () == TyTy::TypeKind::FNDEF)
- {
- TyTy::FnType *fn = static_cast<TyTy::FnType *> (trait_item_tyty);
- TyTy::SubstitutionParamMapping *param = nullptr;
- for (auto ¶m_mapping : fn->get_substs ())
- {
- const HIR::TypeParam &type_param
- = param_mapping.get_generic_param ();
- if (type_param.get_type_representation ().compare ("Self") == 0)
- {
- param = ¶m_mapping;
- break;
- }
- }
- rust_assert (param != nullptr);
-
- std::vector<TyTy::SubstitutionArg> mappings;
- mappings.push_back (TyTy::SubstitutionArg (param, receiver->clone ()));
-
- Location locus; // FIXME
- TyTy::SubstitutionArgumentMappings args (std::move (mappings), {},
- locus);
- trait_item_tyty = SubstMapperInternal::Resolve (trait_item_tyty, args);
- }
-
- PathProbeCandidate::TraitItemCandidate trait_item_candidate{trait_ref,
- trait_item_ref,
- impl};
-
- PathProbeCandidate candidate{candidate_type, trait_item_tyty,
- trait_item_ref->get_locus (),
- trait_item_candidate};
- candidates.insert (std::move (candidate));
- }
+ bool ignore_mandatory_trait_items);
void
process_predicate_for_candidates (const TyTy::TypeBoundPredicate &predicate,
- bool ignore_mandatory_trait_items)
- {
- const TraitReference *trait_ref = predicate.get ();
-
- TyTy::TypeBoundPredicateItem item
- = predicate.lookup_associated_item (search.as_string ());
- if (item.is_error ())
- return;
-
- if (ignore_mandatory_trait_items && item.needs_implementation ())
- return;
-
- const TraitItemReference *trait_item_ref = item.get_raw_item ();
- PathProbeCandidate::CandidateType candidate_type;
- switch (trait_item_ref->get_trait_item_type ())
- {
- case TraitItemReference::TraitItemType::FN:
- candidate_type = PathProbeCandidate::CandidateType::TRAIT_FUNC;
- break;
- case TraitItemReference::TraitItemType::CONST:
- candidate_type = PathProbeCandidate::CandidateType::TRAIT_ITEM_CONST;
- break;
- case TraitItemReference::TraitItemType::TYPE:
- candidate_type = PathProbeCandidate::CandidateType::TRAIT_TYPE_ALIAS;
- break;
-
- case TraitItemReference::TraitItemType::ERROR:
- default:
- gcc_unreachable ();
- break;
- }
-
- TyTy::BaseType *trait_item_tyty = item.get_tyty_for_receiver (receiver);
- PathProbeCandidate::TraitItemCandidate trait_item_candidate{trait_ref,
- trait_item_ref,
- nullptr};
- PathProbeCandidate candidate{candidate_type, trait_item_tyty,
- trait_item_ref->get_locus (),
- trait_item_candidate};
- candidates.insert (std::move (candidate));
- }
+ bool ignore_mandatory_trait_items);
protected:
PathProbeType (const TyTy::BaseType *receiver,
- const HIR::PathIdentSegment &query, DefId specific_trait_id)
- : TypeCheckBase (), receiver (receiver), search (query),
- current_impl (nullptr), specific_trait_id (specific_trait_id)
- {}
+ const HIR::PathIdentSegment &query, DefId specific_trait_id);
std::vector<std::pair<const TraitReference *, HIR::ImplBlock *>>
union_bounds (
const std::vector<std::pair</*const*/ TraitReference *, HIR::ImplBlock *>>
a,
const std::vector<std::pair<const TraitReference *, HIR::ImplBlock *>> b)
- const
- {
- std::map<DefId, std::pair<const TraitReference *, HIR::ImplBlock *>> mapper;
- for (auto &ref : a)
- {
- mapper.insert ({ref.first->get_mappings ().get_defid (), ref});
- }
- for (auto &ref : b)
- {
- mapper.insert ({ref.first->get_mappings ().get_defid (), ref});
- }
-
- std::vector<std::pair<const TraitReference *, HIR::ImplBlock *>> union_set;
- for (auto it = mapper.begin (); it != mapper.end (); it++)
- {
- union_set.push_back ({it->second.first, it->second.second});
- }
- return union_set;
- }
+ const;
- bool is_reciever_generic () const
- {
- const TyTy::BaseType *root = receiver->get_root ();
- bool receiver_is_type_param = root->get_kind () == TyTy::TypeKind::PARAM;
- bool receiver_is_dyn = root->get_kind () == TyTy::TypeKind::DYNAMIC;
- return receiver_is_type_param || receiver_is_dyn;
- }
+ bool is_reciever_generic () const;
const TyTy::BaseType *receiver;
const HIR::PathIdentSegment &search;
@@ -489,24 +229,14 @@ public:
static std::set<PathProbeCandidate>
Probe (const TyTy::BaseType *receiver,
const HIR::PathIdentSegment &segment_name,
- const TraitReference *trait_reference)
- {
- PathProbeImplTrait probe (receiver, segment_name, trait_reference);
- // iterate all impls for this trait and receiver
- // then search for possible candidates using base class behaviours
- probe.process_trait_impl_items_for_candidates ();
- return probe.candidates;
- }
+ const TraitReference *trait_reference);
private:
- void process_trait_impl_items_for_candidates ();
-
PathProbeImplTrait (const TyTy::BaseType *receiver,
const HIR::PathIdentSegment &query,
- const TraitReference *trait_reference)
- : PathProbeType (receiver, query, UNKNOWN_DEFID),
- trait_reference (trait_reference)
- {}
+ const TraitReference *trait_reference);
+
+ void process_trait_impl_items_for_candidates ();
const TraitReference *trait_reference;
};
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index 85cad8e9c21..19f95ca4488 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -594,27 +594,5 @@ TraitItemReference::is_object_safe () const
return false;
}
-// rust-hir-path-probe.h
-
-void
-PathProbeImplTrait::process_trait_impl_items_for_candidates ()
-{
- mappings->iterate_impl_items (
- [&] (HirId id, HIR::ImplItem *item, HIR::ImplBlock *impl) mutable -> bool {
- // just need to check if this is an impl block for this trait the next
- // function checks the receiver
- if (!impl->has_trait_ref ())
- return true;
-
- TraitReference *resolved
- = TraitResolver::Lookup (*(impl->get_trait_ref ().get ()));
- if (!trait_reference->is_equal (*resolved))
- return true;
-
- process_impl_item_candidate (id, item, impl);
- return true;
- });
-}
-
} // namespace Resolver
} // namespace Rust
--
2.40.0
next prev parent reply other threads:[~2023-04-05 14:05 UTC|newest]
Thread overview: 92+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-05 14:02 Rust front-end update 2023-04-05 arthur.cohen
2023-04-05 14:02 ` [committed 01/88] gccrs: fatal_error_flag: Fix typo in error message arthur.cohen
2023-04-05 14:02 ` [committed 02/88] gccrs: unsafe: check use of `target_feature` attribute arthur.cohen
2023-04-05 14:02 ` [committed 03/88] gccrs: Check for mutable references in const functions arthur.cohen
2023-04-05 14:02 ` [committed 04/88] gccrs: rust: add bound parsing in parse_generic_arg arthur.cohen
2023-04-05 14:02 ` [committed 05/88] gccrs: Implement declarative macro 2.0 parser arthur.cohen
2023-04-05 14:02 ` [committed 06/88] gccrs: Add name resolution to generic argument associated item bindings arthur.cohen
2023-04-05 14:02 ` [committed 07/88] gccrs: Support associated type bound arguments arthur.cohen
2023-04-05 14:02 ` [committed 08/88] gccrs: Reuse TypeCheckPattern on LetStmt's arthur.cohen
2023-04-05 14:02 ` [committed 09/88] gccrs: Add get_locus function for abstract class MetaItemInner arthur.cohen
2023-04-05 14:02 ` [committed 10/88] gccrs: diagnostics: Add underline for tokens in diagnostics arthur.cohen
2023-04-05 14:02 ` [committed 11/88] gccrs: Change how CompileVarDecl outputs Bvariable's arthur.cohen
2023-04-05 14:02 ` [committed 12/88] gccrs: testsuite: Handle Windows carriage returns properly arthur.cohen
2023-04-05 14:02 ` [committed 13/88] gccrs: Support GroupedPattern during name resolution arthur.cohen
2023-04-05 14:02 ` [committed 14/88] gccrs: Do not crash on empty macros expand. Fixes #1712 arthur.cohen
2023-04-05 14:02 ` [committed 15/88] gccrs: Add HIR lowering for GroupedPattern arthur.cohen
2023-04-05 14:03 ` [committed 16/88] gccrs: Add get_item method for HIR::GroupedPattern arthur.cohen
2023-04-05 14:03 ` [committed 17/88] gccrs: Add type resolution for grouped patterns arthur.cohen
2023-04-05 14:03 ` [committed 18/88] gccrs: Added missing GroupedPattern visitors for code generation arthur.cohen
2023-04-05 14:03 ` [committed 19/88] gccrs: Rename file rust-ast-full-test.cc to rust-ast.cc arthur.cohen
2023-04-05 14:03 ` [committed 20/88] gccrs: moved operator.h to util/rust-operators.h arthur.cohen
2023-04-05 14:03 ` [committed 21/88] gccrs: fixed compiler error message on wildcard pattern within expression arthur.cohen
2023-04-05 14:03 ` [committed 22/88] gccrs: fixed indentations in AST pretty expanded dump of trait arthur.cohen
2023-04-05 14:03 ` [committed 23/88] gccrs: macro: Allow builtin `MacroInvocation`s within the AST arthur.cohen
2023-04-05 14:03 ` [committed 24/88] gccrs: Create and use CompilePatternLet visitor for compiling let statments arthur.cohen
2023-04-05 14:03 ` [committed 25/88] gccrs: parser: Allow parsing multiple reference types arthur.cohen
2023-04-05 14:03 ` [committed 26/88] gccrs: Move rust-buffered-queue.h to util folder #1766 arthur.cohen
2023-04-05 14:03 ` [committed 27/88] gccrs: Improve GroupedPattern lowering arthur.cohen
2023-04-05 14:03 ` [committed 28/88] gccrs: Remove HIR::GroupedPattern arthur.cohen
2023-04-05 14:03 ` [committed 29/88] gccrs: Optimize HIR::ReferencePattern arthur.cohen
2023-04-05 14:03 ` [committed 30/88] gccrs: Implement lowering ReferencePattern from AST to HIR arthur.cohen
2023-04-05 14:03 ` [committed 31/88] gccrs: parser: Improve parsing of complex generic arguments arthur.cohen
2023-04-05 14:03 ` [committed 32/88] gccrs: parser: Fix parsing of closure param list arthur.cohen
2023-04-05 14:03 ` [committed 33/88] gccrs: Add support for feature check arthur.cohen
2023-04-05 14:03 ` [committed 34/88] gccrs: Removed comment copy-pasted from gcc/tree.def arthur.cohen
2023-04-05 14:03 ` [committed 35/88] gccrs: Add another test case for passing associated type-bounds arthur.cohen
2023-04-05 14:03 ` [committed 36/88] gccrs: Move TypePredicateItem impl out of the header arthur.cohen
2023-04-05 14:03 ` [committed 37/88] gccrs: Refactor TyVar and TypeBoundPredicates arthur.cohen
2023-04-05 14:03 ` [committed 38/88] gccrs: Refactor SubstitutionRef base class into its own CC file arthur.cohen
2023-04-05 14:03 ` [committed 39/88] gccrs: Refactor all substitution mapper code implementation " arthur.cohen
2023-04-05 14:03 ` [committed 40/88] gccrs: Refactor BaseType, InferType and ErrorType impl into cc file arthur.cohen
2023-04-05 14:03 ` arthur.cohen [this message]
2023-04-05 14:03 ` [committed 42/88] gccrs: Refactor PathProbeType code into CC file arthur.cohen
2023-04-05 14:03 ` [committed 43/88] gccrs: Refactor all code out of the rust-tyty.h header arthur.cohen
2023-04-05 14:03 ` [committed 44/88] gccrs: Rename rust-tyctx.cc to rust-typecheck-context.cc arthur.cohen
2023-04-05 14:03 ` [committed 45/88] gccrs: Rename header rust-hir-trait-ref.h to rust-hir-trait-reference.h arthur.cohen
2023-04-05 14:03 ` [committed 46/88] gccrs: Refactor handle_substitutions to take a reference arthur.cohen
2023-04-05 14:03 ` [committed 47/88] gccrs: Clear the substitution callbacks when copying ArgumentMappings arthur.cohen
2023-04-05 14:03 ` [committed 48/88] gccrs: Add missing param subst callback arthur.cohen
2023-04-05 14:03 ` [committed 49/88] gccrs: Remove monomorphization hack to setup possible associated types arthur.cohen
2023-04-05 14:03 ` [committed 50/88] gccrs: Refactor the type unification code arthur.cohen
2023-04-05 14:03 ` [committed 51/88] gccrs: Fix nullptr dereference arthur.cohen
2023-04-05 14:03 ` [committed 52/88] gccrs: Add missing Sized, Copy and Clone lang item mappings arthur.cohen
2023-04-05 14:03 ` [committed 53/88] gccrs: Fix higher ranked trait bounds computation of self arthur.cohen
2023-04-05 14:03 ` [committed 54/88] gccrs: Remove bad error message on checking function arguments arthur.cohen
2023-04-05 14:03 ` [committed 55/88] gccrs: Add general TypeBounds checks arthur.cohen
2023-04-05 14:03 ` [committed 56/88] gccrs: Add support for TuplePattern in let statements arthur.cohen
2023-04-05 14:03 ` [committed 57/88] gccrs: rust-item: include rust-expr.h arthur.cohen
2023-04-05 14:03 ` [committed 58/88] gccrs: parser: Expose parse_macro_invocation as public API arthur.cohen
2023-04-05 14:03 ` [committed 59/88] gccrs: expansion: Add `get_token_slice` to `MacroInvocLexer` class arthur.cohen
2023-04-05 14:03 ` [committed 60/88] gccrs: macros: Perform macro expansion in a fixed-point fashion arthur.cohen
2023-04-05 14:03 ` [committed 61/88] gccrs: expander: Add documentation for `expand_eager_invocations` arthur.cohen
2023-04-05 14:03 ` [committed 62/88] gccrs: typecheck: Refactor rust-hir-trait-reference.h arthur.cohen
2023-04-05 14:03 ` [committed 63/88] gccrs: cli: Update safety warning message arthur.cohen
2023-04-05 14:03 ` [committed 64/88] gccrs: Update copyright years arthur.cohen
2023-04-05 14:03 ` [committed 65/88] gccrs: Add feature gate for "rust-intrinsic" arthur.cohen
2023-04-05 14:03 ` [committed 66/88] gccrs: Add variadic argument type checking arthur.cohen
2023-04-05 14:03 ` [committed 67/88] gccrs: Add test arthur.cohen
2023-04-05 14:03 ` [committed 68/88] gccrs: Simplify WildcardPattern let statement handling arthur.cohen
2023-04-05 14:03 ` [committed 69/88] gccrs: lex: Prevent directories in RAIIFile arthur.cohen
2023-04-05 14:03 ` [committed 70/88] gccrs: testsuite: Add empty string macro test arthur.cohen
2023-04-05 14:03 ` [committed 71/88] gccrs: Add support for parsing empty tuple patterns arthur.cohen
2023-04-05 14:03 ` [committed 72/88] gccrs: Implemented UTF-8 checking for include_str!() arthur.cohen
2023-04-05 14:03 ` [committed 73/88] gccrs: Extract query_type from TypeCheckBase to be a simple extern arthur.cohen
2023-04-05 14:03 ` [committed 74/88] gccrs: Add new virtual function HIR::ImplItem::get_impl_item_name arthur.cohen
2023-04-05 14:03 ` [committed 75/88] gccrs: Support for Sized builtin marker trait arthur.cohen
2023-04-05 14:04 ` [committed 76/88] gccrs: Fix regression in testcase arthur.cohen
2023-04-05 14:04 ` [committed 77/88] gccrs: Add trailing newline arthur.cohen
2023-04-05 14:04 ` [committed 78/88] gccrs: builtins: Return empty list of tokens instead of nullptr arthur.cohen
2023-04-05 14:04 ` [committed 79/88] gccrs: Fix formatting arthur.cohen
2023-04-05 14:04 ` [committed 80/88] gccrs: Add AST::AltPattern class arthur.cohen
2023-04-05 14:04 ` [committed 81/88] gccrs: Fix up DejaGnu directives in 'rust/compile/issue-1830_{bytes,str}.rs' test cases [#1838] arthur.cohen
2023-04-05 14:04 ` [committed 82/88] gccrs: rename rust-hir-full-tests.cc arthur.cohen
2023-04-05 14:04 ` [committed 83/88] gccrs: add test case to show our query-type system is working arthur.cohen
2023-04-05 14:04 ` [committed 84/88] gccrs: ast: Refactor TraitItem to keep Location info arthur.cohen
2023-04-05 14:04 ` [committed 85/88] gccrs: diagnostic: Refactor Error class arthur.cohen
2023-04-05 14:04 ` [committed 86/88] gccrs: Added AST Node AST::InlineAsm arthur.cohen
2023-04-05 14:04 ` [committed 87/88] gccrs: Address unsafe with/without block handling ambiguity arthur.cohen
2023-04-05 14:04 ` [committed 88/88] gccrs: Fix issue with parsing unsafe block expression statements arthur.cohen
2023-04-06 7:59 ` Rust front-end update 2023-04-05 Thomas Schwinge
2023-04-06 9:05 ` Arthur Cohen
2023-04-11 9:09 ` Richard Biener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230405140411.3016563-42-arthur.cohen@embecosm.com \
--to=arthur.cohen@embecosm.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=gcc-rust@gcc.gnu.org \
--cc=herron.philip@googlemail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).