From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7905) id AA4633858C50; Tue, 31 Jan 2023 13:17:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AA4633858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675171050; bh=H5xGpw/Gr37gHLXKjL3M9pzWCSJbtK1RCnjJYr6a4ME=; h=From:To:Subject:Date:From; b=gxP8CQescAndWGB7r2H1vqUn/ZMD9YLQLBo19fGna4c1vvEa/nVvL80an98d9KnH4 v7T/jKrWHNcPxU0Mwlgw4olVhzfny63tD2LyWg6Q3VWttc29ezXJ38vGWsABRFj23O HrfqCSrwfUdvY3uGoyHqmn/sVpZcgu0aeT/K0vOA= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Arthur Cohen To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-5572] gccrs: Fix duplicated function generation on higher ranked trait bounds X-Act-Checkin: gcc X-Git-Author: Philip Herron X-Git-Refname: refs/heads/master X-Git-Oldrev: 9c60f0e1e5cd5a60d5a057193611aa0c38894cc7 X-Git-Newrev: 11a37f8950405c15409f57e9684157a267f5948f Message-Id: <20230131131730.AA4633858C50@sourceware.org> Date: Tue, 31 Jan 2023 13:17:30 +0000 (GMT) List-Id: https://gcc.gnu.org/g:11a37f8950405c15409f57e9684157a267f5948f commit r13-5572-g11a37f8950405c15409f57e9684157a267f5948f Author: Philip Herron Date: Tue Sep 27 12:19:43 2022 +0100 gccrs: Fix duplicated function generation on higher ranked trait bounds Deuplicate function elimination can fail when we compile helpers during higher ranked trait bound monomorphization. This because the TyTy::BaseType info can be lost/reset during the compilation process. This adds a second mechanism to match based on the manged names which is a bit more reliable. This patch is required since the query based refactor of the type system so this issue was likely hidden to to using duplicated type info for higher ranked trait bounds. gcc/rust/ChangeLog: * backend/rust-compile-context.h: Add new optional `asm_name` string argument to `lookup_function_decl`. * backend/rust-compile-item.cc (CompileItem::visit): Compute assembly name and pass it to `lookup_function_decl` when calling it. Diff: --- gcc/rust/backend/rust-compile-context.h | 21 ++++++++++++++++++++- gcc/rust/backend/rust-compile-item.cc | 14 ++++++++------ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index 2d379c2a5fa..49f78e19b20 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -148,7 +148,8 @@ public: } bool lookup_function_decl (HirId id, tree *fn, DefId dId = UNKNOWN_DEFID, - const TyTy::BaseType *ref = nullptr) + const TyTy::BaseType *ref = nullptr, + const std::string &asm_name = std::string ()) { // for for any monomorphized fns if (ref != nullptr) @@ -163,11 +164,29 @@ public: { const TyTy::BaseType *r = e.first; tree f = e.second; + if (ref->is_equal (*r)) { *fn = f; return true; } + + if (DECL_ASSEMBLER_NAME_SET_P (f) && !asm_name.empty ()) + { + tree raw = DECL_ASSEMBLER_NAME_RAW (f); + const char *rptr = IDENTIFIER_POINTER (raw); + + bool lengths_match_p + = IDENTIFIER_LENGTH (raw) == asm_name.size (); + if (lengths_match_p + && strncmp (rptr, asm_name.c_str (), + IDENTIFIER_LENGTH (raw)) + == 0) + { + *fn = f; + return true; + } + } } return false; } diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc index d1cdc3b6698..b2e9b3fbf6d 100644 --- a/gcc/rust/backend/rust-compile-item.cc +++ b/gcc/rust/backend/rust-compile-item.cc @@ -134,11 +134,18 @@ CompileItem::visit (HIR::Function &function) } } + const Resolver::CanonicalPath *canonical_path = nullptr; + bool ok = ctx->get_mappings ()->lookup_canonical_path ( + function.get_mappings ().get_nodeid (), &canonical_path); + rust_assert (ok); + + const std::string asm_name = ctx->mangle_item (fntype, *canonical_path); + // items can be forward compiled which means we may not need to invoke this // code. We might also have already compiled this generic function as well. tree lookup = NULL_TREE; if (ctx->lookup_function_decl (fntype->get_ty_ref (), &lookup, - fntype->get_id (), fntype)) + fntype->get_id (), fntype, asm_name)) { // has this been added to the list then it must be finished if (ctx->function_completed (lookup)) @@ -160,11 +167,6 @@ CompileItem::visit (HIR::Function &function) fntype->override_context (); } - const Resolver::CanonicalPath *canonical_path = nullptr; - bool ok = ctx->get_mappings ()->lookup_canonical_path ( - function.get_mappings ().get_nodeid (), &canonical_path); - rust_assert (ok); - if (function.get_qualifiers ().is_const ()) ctx->push_const_context ();