From patchwork Thu Aug 1 14:56:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1967774 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=TRPDl3KR; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4WZXhX1z0tz1ybX for ; Fri, 2 Aug 2024 01:20:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E219E385ED4B for ; Thu, 1 Aug 2024 15:20:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by sourceware.org (Postfix) with ESMTPS id 7EE273860C0B for ; Thu, 1 Aug 2024 14:59:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7EE273860C0B 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 7EE273860C0B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::236 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524403; cv=none; b=mEpXcBvS/4XVeHtGEsQRbGW2JpXkneTsuv1ozsaaxRwAyDzZoqMJ8fT+z9eYVihhQ6hrbH2Z1nY4A2o5wlpbl6uh//ntxQFxMMFE6MDon23UH4Op2IxU8KkOUZv4zvXM0if+zaD7ZQPLJ1ga/ccEneTgTf18JG6I2pm8xXEi2Hs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524403; c=relaxed/simple; bh=lKGbnkJ6I5OYtfGL+xYfupV9/p/chJLlyXtx37tgOoI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=JViSOrFw5yVQ6A5vuzNlKVnS6ZgiVqqQr8WWW53rw0wP2BPH3F38te+3w2qcGH9NbOfKqlFkgsDjtdh4CTyBjCTp2XzQ60jcoJvE+3SKMcatQOtdxfCIC8Dux5YbyT5YFPTwYE2WAIQhc6xEy08oWIQqlLbIe6pocaSMz+LuvIA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2f01e9f53e3so102172101fa.1 for ; Thu, 01 Aug 2024 07:59:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1722524371; x=1723129171; 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=uRgW1y0OJOOWs/wcZgHwq0a2ObmlY9w33uhPy7U8s/0=; b=TRPDl3KRDnEtDHHF2vdG93XOvvnMvo2g40vcSiubijuB5hux1p77+YtHHbA50ZlONW +iSv8qE5e4IhcRqVObbuI4gUaifJi/qEw1qAfcYdaz6ae9vovqZ24cxHbuK4sKMwOtT9 ZbQo87fABDZQZksqbl005uT9ceLyiowUk9sHrzojCZeJnxDWnQmjGxbS5UOXiT64NyYA AgCqHvNy5bcKIr/0otILCL8g2/WzkSnSLBu7sOvll0P41DTbZcRZsXr4SqyquldsKnp7 Ch3e3TVUphr4ku9mHhLk9WSuK6zjrPKe3kT4t5bRgEnnMCluJzhd/QcRDvggPv/wAePb V8dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524371; x=1723129171; 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=uRgW1y0OJOOWs/wcZgHwq0a2ObmlY9w33uhPy7U8s/0=; b=BTGKFNyIr3aPP2aPxl1BFQLtFZ1vIWGAW/p3Gbj0+3BROH7U53QcF8ccVO/GmrWXh5 s8ai3IM6LE678egFOS3mZovzJyMKo9NTmb+QZ6cSf0MVaI7vzDn+gXnBaxQT7Yq+dyRx StgtHtJwvbhC1tDZQzmOdYQhG938pMyRC1ulCIYpLEFKcDR1NUkX7dW++SGQr+XKVFTz cCZfL88Qe2rU0bGRDdhMYR5YoqgjAgt+d3totLn8QV1Y6A9IQKeYp37KuUW4oElvo5td WMBe3+49IX+z8ZxnjTMxwFTNrHPot7/53sangPS9P93qIE1qnSTjNcPr1TTa/3hjg7rg nLsg== X-Gm-Message-State: AOJu0YySNeG9ciVBQwaG20CFy6M38Rb84vnw6/gRa4rRKWIo8495pcaR C7MqMPjGkZ4p9Tc0yBVxmwRoPPqqc5I1x2M6OSxioLc8Cv47XEKptT0NhygPjWb6/JaSSaJS+S/ cQ9oW X-Google-Smtp-Source: AGHT+IGgW8xvPufQlvc28/cPFLBZ5vmQOkD/6OSTfhbx9GXHOvdtsl0z7qWG5PLCFaOY6uuEwy1Dfw== X-Received: by 2002:a05:651c:22a:b0:2f0:1a95:7106 with SMTP id 38308e7fff4ca-2f15ab2a514mr4783051fa.39.1722524370569; Thu, 01 Aug 2024 07:59:30 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 07:59:30 -0700 (PDT) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [PATCH 063/125] gccrs: nr2.0: Add lookup of resolved nodes. Date: Thu, 1 Aug 2024 16:56:59 +0200 Message-ID: <20240801145809.366388-65-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.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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: * resolve/rust-name-resolution-context.cc (NameResolutionContext::lookup): Add lookup function. * resolve/rust-name-resolution-context.h: Include mappings and optional. --- gcc/rust/resolve/rust-name-resolution-context.cc | 13 +++++++++++++ gcc/rust/resolve/rust-name-resolution-context.h | 3 +++ 2 files changed, 16 insertions(+) diff --git a/gcc/rust/resolve/rust-name-resolution-context.cc b/gcc/rust/resolve/rust-name-resolution-context.cc index f35db7e925e..9fd8d52968a 100644 --- a/gcc/rust/resolve/rust-name-resolution-context.cc +++ b/gcc/rust/resolve/rust-name-resolution-context.cc @@ -17,6 +17,8 @@ // . #include "rust-name-resolution-context.h" +#include "optional.h" +#include "rust-mapping-common.h" namespace Rust { namespace Resolver2_0 { @@ -52,6 +54,17 @@ NameResolutionContext::map_usage (NodeId usage, NodeId definition) rust_assert (inserted); } +tl::optional +NameResolutionContext::lookup (NodeId usage) +{ + auto it = resolved_nodes.find (usage); + + if (it == resolved_nodes.end ()) + return tl::nullopt; + + return it->second; +} + void NameResolutionContext::scoped (Rib rib, NodeId id, std::function lambda, diff --git a/gcc/rust/resolve/rust-name-resolution-context.h b/gcc/rust/resolve/rust-name-resolution-context.h index bc3c4bb5ddb..e896ca05360 100644 --- a/gcc/rust/resolve/rust-name-resolution-context.h +++ b/gcc/rust/resolve/rust-name-resolution-context.h @@ -19,6 +19,7 @@ #ifndef RUST_NAME_RESOLVER_2_0_H #define RUST_NAME_RESOLVER_2_0_H +#include "optional.h" #include "rust-forever-stack.h" #include "rust-hir-map.h" @@ -180,7 +181,9 @@ public: Analysis::Mappings &mappings; // TODO: Rename + // TODO: Use newtype pattern for Usage and Definition void map_usage (NodeId usage, NodeId definition); + tl::optional lookup (NodeId usage); private: /* Map of "usage" nodes which have been resolved to a "definition" node */