aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-05-23 14:35:17 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 18:37:21 +0100
commit636e9b41035b55a138065398490ad9007b10fe06 (patch)
treee851b9945146ae925a1648cc985bece7a5748f65
parentb8934ebd88b50c6aae304eede565f94cb860a3c2 (diff)
downloadgcc-636e9b41035b55a138065398490ad9007b10fe06.zip
gcc-636e9b41035b55a138065398490ad9007b10fe06.tar.gz
gcc-636e9b41035b55a138065398490ad9007b10fe06.tar.bz2
gccrs: refactor resolve_method_address to be more generic
We can reuse the DefId to lookup the mappings to Items or Trait Items instead of the HirId this is more generic and can then be reused for the deref operator overload during autoderef cycles. Addresses #2190 gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::resolve_method_address): refactor * backend/rust-compile-base.h: likewise * backend/rust-compile-expr.cc (CompileExpr::visit): likewise * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): likewise Signed-off-by: Philip Herron <herron.philip@googlemail.com>
-rw-r--r--gcc/rust/backend/rust-compile-base.cc24
-rw-r--r--gcc/rust/backend/rust-compile-base.h5
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc8
-rw-r--r--gcc/rust/backend/rust-compile-resolve-path.cc3
4 files changed, 17 insertions, 23 deletions
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc
index 6bfc19e..f034b8c 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -766,27 +766,28 @@ HIRCompileBase::named_constant_expression (tree type_tree,
}
tree
-HIRCompileBase::resolve_method_address (
- TyTy::FnType *fntype, HirId ref, TyTy::BaseType *receiver,
- const HIR::PathIdentSegment &segment,
- const Analysis::NodeMapping &expr_mappings, Location expr_locus)
+HIRCompileBase::resolve_method_address (TyTy::FnType *fntype,
+ TyTy::BaseType *receiver,
+ Location expr_locus)
{
+ DefId id = fntype->get_id ();
+ rust_assert (id != UNKNOWN_DEFID);
+
// Now we can try and resolve the address since this might be a forward
// declared function, generic function which has not be compiled yet or
// its an not yet trait bound function
- HIR::ImplItem *resolved_item
- = ctx->get_mappings ()->lookup_hir_implitem (ref, nullptr);
+ HIR::Item *resolved_item = ctx->get_mappings ()->lookup_defid (id);
if (resolved_item != nullptr)
{
if (!fntype->has_subsititions_defined ())
- return CompileInherentImplItem::Compile (resolved_item, ctx);
+ return CompileItem::compile (resolved_item, ctx);
- return CompileInherentImplItem::Compile (resolved_item, ctx, fntype);
+ return CompileItem::compile (resolved_item, ctx, fntype);
}
// it might be resolved to a trait item
HIR::TraitItem *trait_item
- = ctx->get_mappings ()->lookup_hir_trait_item (ref);
+ = ctx->get_mappings ()->lookup_trait_item_defid (id);
HIR::Trait *trait = ctx->get_mappings ()->lookup_trait_item_mapping (
trait_item->get_mappings ().get_hirid ());
@@ -800,7 +801,7 @@ HIRCompileBase::resolve_method_address (
// item so its up to us to figure out if this path should resolve
// to an trait-impl-block-item or if it can be defaulted to the
// trait-impl-item's definition
-
+ const HIR::PathIdentSegment segment (trait_item->trait_identifier ());
auto root = receiver->get_root ();
auto candidates
= Resolver::PathProbeImplTrait::Probe (root, segment, trait_ref);
@@ -840,7 +841,8 @@ HIRCompileBase::resolve_method_address (
TyTy::BaseType *infer_impl_call
= candidate_call->infer_substitions (expr_locus);
monomorphized
- = Resolver::unify_site (ref, TyTy::TyWithLocation (infer_impl_call),
+ = Resolver::unify_site (fntype->get_ref (),
+ TyTy::TyWithLocation (infer_impl_call),
TyTy::TyWithLocation (fntype), expr_locus);
}
diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h
index db47c0f..203705a 100644
--- a/gcc/rust/backend/rust-compile-base.h
+++ b/gcc/rust/backend/rust-compile-base.h
@@ -80,10 +80,7 @@ protected:
tree resolve_unsized_dyn_adjustment (Resolver::Adjustment &adjustment,
tree expression, Location locus);
- tree resolve_method_address (TyTy::FnType *fntype, HirId ref,
- TyTy::BaseType *receiver,
- const HIR::PathIdentSegment &segment,
- const Analysis::NodeMapping &expr_mappings,
+ tree resolve_method_address (TyTy::FnType *fntype, TyTy::BaseType *receiver,
Location expr_locus);
void compile_function_body (tree fndecl, HIR::BlockExpr &function_body,
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 78448dd..00b9a07 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -1757,9 +1757,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
// lookup compiled functions since it may have already been compiled
HIR::PathExprSegment method_name = expr.get_method_name ();
HIR::PathIdentSegment segment_name = method_name.get_segment ();
- fn_expr
- = resolve_method_address (fntype, ref, receiver, segment_name,
- expr.get_mappings (), expr.get_locus ());
+ fn_expr = resolve_method_address (fntype, receiver, expr.get_locus ());
}
// lookup the autoderef mappings
@@ -1899,9 +1897,7 @@ CompileExpr::resolve_operator_overload (
// lookup compiled functions since it may have already been compiled
HIR::PathIdentSegment segment_name (
Analysis::RustLangItem::ToString (lang_item_type));
- tree fn_expr
- = resolve_method_address (fntype, ref, receiver, segment_name,
- expr.get_mappings (), expr.get_locus ());
+ tree fn_expr = resolve_method_address (fntype, receiver, expr.get_locus ());
// lookup the autoderef mappings
std::vector<Resolver::Adjustment> *adjustments = nullptr;
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc
index 97cfe9c..284f4c6 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -213,8 +213,7 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup,
receiver = fn->get_self_type ();
receiver = receiver->destructure ();
- return resolve_method_address (fn, ref, receiver, final_segment,
- mappings, expr_locus);
+ return resolve_method_address (fn, receiver, expr_locus);
}
}