From: Philip Herron Date: Tue, 23 May 2023 13:35:17 +0000 (+0100) Subject: gccrs: refactor resolve_method_address to be more generic X-Git-Tag: basepoints/gcc-15~2523 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=636e9b41035b55a138065398490ad9007b10fe06;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index 6bfc19ee3e35..f034b8c7b0a4 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 db47c0f667c5..203705ac730d 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 78448dd84d08..00b9a0700088 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 *adjustments = nullptr; diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc index 97cfe9c46db1..284f4c6e91e6 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); } }