From patchwork Thu Aug 1 14:57:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1967791 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=embecosm.com header.i=@embecosm.com header.a=rsa-sha256 header.s=google header.b=bDNU1ATn; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WZXnS3M02z1ybX for ; Fri, 2 Aug 2024 01:24:28 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BADCD3860750 for ; Thu, 1 Aug 2024 15:24:26 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 391D8385E45A for ; Thu, 1 Aug 2024 14:59:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 391D8385E45A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 391D8385E45A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::52b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524407; cv=none; b=SJGE8MDaFfQX0LlNU/n0VKjaCR/mvyUZjFNGR/BdKV7uH4FzIUog0OmUIbV4Qw+YkkTg6RQ0aOHWVgFm7M29n4RMLsHt/PylEUpqHKRkzELna4EaMmmEQEkPB0hIgLlQS3XZAWwrW2VvmMJCogz9exbmG7zR9IxY/GLj1BjKEMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524407; c=relaxed/simple; bh=peGEJsedBMZymuz2XbTApnQeaCcIwC4u0dd7X/EC+30=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=P21Id3EPztHjkxKaatt/+Y4jTuQLNsMkIaJAGKETig4tePB71OvQ6qmN0QPEv37lvSDnAyNHe+Y6CXIchrpXkCgyKLaaaNh/6D6Z7Fe+CnBbe6ripAsKvOZDYX7XK0Yfas4zEpp3S8fvP2SjQLPGmiF5Y3Z5CPkIg2jwG68YD9g= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5b01af9b0c9so6167306a12.3 for ; Thu, 01 Aug 2024 07:59:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1722524372; x=1723129172; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ib1Sds8WH6Dl0wjEyyE0jL4syggnm/CT6Psqbf6zkPQ=; b=bDNU1ATnhhRHXBzabTd7fwuS1tz8LC5vtWMOXe4OJccn71NCvFIbzCDDBKOuKomQ01 V4p2gUuIDCDhUIOz+YbDhKDdbQMYyItAFsJK5ByQTfYjpeLj79CyuI4wANXslwfgru/Z uFYGGjTkOiYEbL9gVkDLQIivuX9CrSbUFi4oQ8jIww15N7tYSUHFHdrv/1pwlHU3db0h 5KE3TwjlJCkG9DorbIXrDaLzgSpTTrwAI+b+3W45i16XaVgYDIPO5/uNMXqOtVjfkIqh aQkxhEObVZKRbNaAEMsUV0YJiI+fJLhv7feIP0CckFhYY6xdb3J+Fo7JfUw7WmESt5Wf Nnzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524372; x=1723129172; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ib1Sds8WH6Dl0wjEyyE0jL4syggnm/CT6Psqbf6zkPQ=; b=D+jhvCVaDRUZ4ex9E9CpOwp0Cx7E586wA+ZKkgg4EqUVWAx1aIs+Rfewn76WTZPosS owOyiAy+nPmeIxUtoywIznNwd9W8S445QAcjqIL4jLKHEu0m9pZ/PIr4R/QEco3Lz0x4 5NOPi50n0wVP+L7955rm1tzdPuMPnqVtl2x68SW+l2JsqKjo2Q6cY60yWkM9Hdnl9WB3 fqqvbqzbB2BBiJyIkRSUordij0caTXjpWxsHMYvft5rzC6yK1EpYyagkXA/SpCC1fZRB 7XShxmeR/Fkb0gW/aLCRPJX//6sYH+pkTo90oBHI/XLEtlSUb8Vl4RvTS3WNCNuq6ENz 2tcQ== X-Gm-Message-State: AOJu0YzkPInuEjLBP872+9ogbIb96Cv28loIdV0KJg7rlqJRqdnuefcq TJ0eUA/NmGUL0D06Iwg3EHceHLTcJlnDnEfJ0rQ9cfSAcqSUBI35JCJD7y9iiBZr/zh5kmX9Cxg lfBX6 X-Google-Smtp-Source: AGHT+IFjbMigQORbGjtwGsnLZd2Y6JKJGI2U4vtbVJKLa/EL4lvPHygGPQe3vQqpwP+PUi+ZoraXug== X-Received: by 2002:aa7:c3d9:0:b0:57c:db99:a131 with SMTP id 4fb4d7f45d1cf-5b7f57f5159mr416136a12.29.1722524371651; Thu, 01 Aug 2024 07:59:31 -0700 (PDT) Received: from platypus.lan ([2a04:cec2:9:dc84:3622:6733:ff49:ee91]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5ac63590592sm10252456a12.25.2024.08.01.07.59.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 07:59:31 -0700 (PDT) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [PATCH 065/125] gccrs: backend: Use new name resolver where necessary Date: Thu, 1 Aug 2024 16:57:01 +0200 Message-ID: <20240801145809.366388-67-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240801145809.366388-2-arthur.cohen@embecosm.com> References: <20240801145809.366388-2-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org gcc/rust/ChangeLog: * backend/rust-compile-base.cc: Use new ImmutableNrCtx. * backend/rust-compile-context.h: Likewise. * backend/rust-compile-expr.cc: Likewise. * backend/rust-compile-item.cc: Likewise. --- gcc/rust/backend/rust-compile-base.cc | 1 + gcc/rust/backend/rust-compile-context.h | 1 + gcc/rust/backend/rust-compile-expr.cc | 22 ++++++++++++++---- gcc/rust/backend/rust-compile-item.cc | 31 ++++++++++++++++++++----- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index 4d6f0275b00..584d6a03ea9 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -31,6 +31,7 @@ #include "rust-type-util.h" #include "rust-compile-implitem.h" #include "rust-attribute-values.h" +#include "rust-immutable-name-resolution-context.h" #include "fold-const.h" #include "stringpool.h" diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index 36a36e79f68..671aee196c2 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -27,6 +27,7 @@ #include "rust-hir-full.h" #include "rust-mangle.h" #include "rust-tree.h" +#include "rust-immutable-name-resolution-context.h" namespace Rust { namespace Compile { diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 65de24bf9d8..6a9bb73ffe0 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -2311,11 +2311,23 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr, if (is_block_expr) { auto body_mappings = function_body->get_mappings (); - Resolver::Rib *rib = nullptr; - bool ok - = ctx->get_resolver ()->find_name_rib (body_mappings.get_nodeid (), - &rib); - rust_assert (ok); + if (flag_name_resolution_2_0) + { + auto nr_ctx + = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + + auto candidate = nr_ctx.values.to_rib (body_mappings.get_nodeid ()); + + rust_assert (candidate.has_value ()); + } + else + { + Resolver::Rib *rib = nullptr; + bool ok + = ctx->get_resolver ()->find_name_rib (body_mappings.get_nodeid (), + &rib); + rust_assert (ok); + } } tree enclosing_scope = NULL_TREE; diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc index 234ad2aa59c..8feed51efa4 100644 --- a/gcc/rust/backend/rust-compile-item.cc +++ b/gcc/rust/backend/rust-compile-item.cc @@ -19,6 +19,7 @@ #include "rust-compile-item.h" #include "rust-compile-implitem.h" #include "rust-compile-extern.h" +#include "rust-immutable-name-resolution-context.h" namespace Rust { namespace Compile { @@ -149,12 +150,30 @@ 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); + Resolver::CanonicalPath canonical_path + = Resolver::CanonicalPath::create_empty (); + + if (flag_name_resolution_2_0) + { + auto nr_ctx + = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + + auto path = nr_ctx.values.to_canonical_path ( + function.get_mappings ().get_nodeid ()); + + canonical_path = path.value (); + } + else + { + const Resolver::CanonicalPath *path = nullptr; + bool ok = ctx->get_mappings ()->lookup_canonical_path ( + function.get_mappings ().get_nodeid (), &path); + rust_assert (ok); + + canonical_path = *path; + } - const std::string asm_name = ctx->mangle_item (fntype, *canonical_path); + 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. @@ -181,7 +200,7 @@ CompileItem::visit (HIR::Function &function) function.get_function_params (), function.get_qualifiers (), function.get_visibility (), function.get_outer_attrs (), function.get_locus (), - function.get_definition ().get (), canonical_path, + function.get_definition ().get (), &canonical_path, fntype); reference = address_expression (fndecl, ref_locus);