aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-05-23 14:35:17 +0100
committerPhilip Herron <philip.herron@embecosm.com>2023-05-26 16:28:04 +0000
commite656f08b6f7794c0c04a808fec50ea9a079577c7 (patch)
treefc2cc85773dabf7b4e9b4184bc7980f09b15280a
parent9e2ecdf3b9d4c4216d67c24ab6e65a48290c08df (diff)
downloadgcc-e656f08b6f7794c0c04a808fec50ea9a079577c7.zip
gcc-e656f08b6f7794c0c04a808fec50ea9a079577c7.tar.gz
gcc-e656f08b6f7794c0c04a808fec50ea9a079577c7.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 7e3e67b..caa10ed 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 d2d6a9a..957aba1 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 58895da..8db52d4 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 d4e3780..5989499 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);
}
}