From patchwork Tue Jan 30 12:06:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892860 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=R63VPJXx; 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 4TPPgL1Xp7z23fD for ; Tue, 30 Jan 2024 23:31:58 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 38ECE386D62B for ; Tue, 30 Jan 2024 12:31:56 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 15AE93857BA3 for ; Tue, 30 Jan 2024 12:11:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 15AE93857BA3 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 15AE93857BA3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::330 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616701; cv=none; b=n6qibfMs11PYMueHcBSW50crr8H9lRSf+ObCz54tw2xLuI85wiru90q/N1rW3H0jgxIzjJdfi9I/lWSFz5qPAQMxBfRkbxc0H24bSqYFR5zczAdM6yEH1nE185X0yqeXM37hVyyYHaMuZNNzvLr9exnKuedpmqJybngBHCVh9i4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616701; c=relaxed/simple; bh=FWxd7IlF77xxagALB/FDUIM20Za68M9fLv6cY7aNXeg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Bp3Wv2/2j59l/WQmwFvJ8obD72lFvoXslQZlidkrUh5wIjSE+KekXyp3oCIWK73JKIa2DjT1Thfihis20GPMI9XTkBOkOE+85oNzC/13F27vvcNlOOkgIRLx37RyivV+GqGVIbQY8xoRl74GmB8jgoyqJz0F7aEpV76XVz1/o1g= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-40ef64d8955so18168115e9.3 for ; Tue, 30 Jan 2024 04:11:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616679; x=1707221479; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=I9ArZqsBrOUkqBPAOgu1kvCL6RSOG2lxbq0FhG3/iq4=; b=R63VPJXx7i4PGLRt6E9iiFNT0fbo9yJXKETxpL8GD+pCYT/zEWcjShi+yFKPt4iPeH utg2w9OW8CK9bGZr++KEXcVnoXMmxlViPF/BFYhEwXpm2uC8BJGqTyk5vqiC4SxejJQi xyAxCsChYsyQApku7qBfgGFo9yqRFdqEAfKUMc6lCGj4k06UTxIccJUQTGeq6p+vpkHX bSX3mkm89h1Sjh3OSFEu8lpaeXFkH1oruPPZgfPDQJ0DutlVNmWzaVl+E6FQ2P6ESRup OefcBZ7TuAxMQtEkUOHXd1Ai0Rv9X6sd7EVHzft0EoLENRVDG9rnFNWUL47g2FsnwQtH tAXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616679; x=1707221479; h=content-transfer-encoding:mime-version:reply-to: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=I9ArZqsBrOUkqBPAOgu1kvCL6RSOG2lxbq0FhG3/iq4=; b=bktK93xwPIFZvQ4wFEQCgLUxZcIRkWihApt9Mp47Aw+EPmnXhMVs8fUz/7XGCcBpWz ig8Z88pnHg5yO04YBPih45pfSDIdB9UAxtf45JXDvsLY41Au9Jb1ck4cyjxE06BnTX4E W5N5HuCMmHXe8S7Q/q+TWuUch//Ya/1OPtBdhc0kx3xy5aIT8qMyVWJsbLpXD6u+tAri I76okb6iTWb8XW7YKw4mtukmPoGyEVcV95K5rVLyOXZLXXASkSuMLwzv4b5h/s/dwtyM TSGoJpzgm1EsmF8FXud20nB5+aO/PmcLXf1F/re061duuWak6WWHxPrhqKpY+JEkc0Jb 91XQ== X-Gm-Message-State: AOJu0Yzfl1BAtAPwwfEKvaUcn+Kjj36n0HGbOsOkZmVE/n4Q22w+v5n6 7Qfbo3lBn1s3ZbOJbIMmd6zKCFXKwTIU25eV8DfV98MuEo7hYBL+i8Rye6B7nMVAiaquZCVfikb G/g== X-Google-Smtp-Source: AGHT+IFwX2vGW4ezwrGS4t4Dq9BTg2GTflriFnR84JxmY2lJ7sqhrLhqw62T1rkHZlDbWObGL3AlpA== X-Received: by 2002:adf:cd03:0:b0:33a:fc8c:1dc9 with SMTP id w3-20020adfcd03000000b0033afc8c1dc9mr918142wrm.32.1706616679599; Tue, 30 Jan 2024 04:11:19 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id f9-20020a056000036900b00339307d9d31sm10569894wrf.112.2024.01.30.04.11.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:17 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 039/101] gccrs: early: Resolve paths properly Date: Tue, 30 Jan 2024 13:06:55 +0100 Message-ID: <20240130121026.807464-42-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240130121026.807464-2-arthur.cohen@embecosm.com> References: <20240130121026.807464-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, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: , Reply-To: arthur.cohen@embecosm.com Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org From: Arthur Cohen gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::insert_once): New function. (Early::visit): Likewise. * resolve/rust-early-name-resolver-2.0.h: Likewise. --- .../resolve/rust-early-name-resolver-2.0.cc | 30 +++++++++++++++++++ .../resolve/rust-early-name-resolver-2.0.h | 10 +++++++ 2 files changed, 40 insertions(+) diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc index 2245ba31772..48bb4c68d26 100644 --- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc @@ -26,6 +26,33 @@ namespace Resolver2_0 { Early::Early (NameResolutionContext &ctx) : DefaultResolver (ctx) {} +void +Early::insert_once (AST::MacroInvocation &invocation, NodeId resolved) +{ + // TODO: Should we use `ctx.mark_resolved()`? + AST::MacroRulesDefinition *definition; + auto ok = ctx.mappings.lookup_macro_def (resolved, &definition); + + rust_assert (ok); + + AST::MacroRulesDefinition *existing; + auto exists = ctx.mappings.lookup_macro_invocation (invocation, &existing); + + if (!exists) + ctx.mappings.insert_macro_invocation (invocation, definition); +} + +void +Early::insert_once (AST::MacroRulesDefinition &def) +{ + // TODO: Should we use `ctx.mark_resolved()`? + AST::MacroRulesDefinition *definition; + auto exists = ctx.mappings.lookup_macro_def (def.get_node_id (), &definition); + + if (!exists) + ctx.mappings.insert_macro_def (&def); +} + void Early::go (AST::Crate &crate) { @@ -89,6 +116,7 @@ Early::visit (AST::MacroRulesDefinition &def) DefaultResolver::visit (def); textual_scope.insert (def.get_rule_name ().as_string (), def.get_node_id ()); + insert_once (def); } void @@ -141,6 +169,8 @@ Early::visit (AST::MacroInvocation &invoc) return; } + insert_once (invoc, *definition); + // now do we need to keep mappings or something? or insert "uses" into our // ForeverStack? can we do that? are mappings simpler? auto mappings = Analysis::Mappings::get (); diff --git a/gcc/rust/resolve/rust-early-name-resolver-2.0.h b/gcc/rust/resolve/rust-early-name-resolver-2.0.h index dc273196473..46c4b936866 100644 --- a/gcc/rust/resolve/rust-early-name-resolver-2.0.h +++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.h @@ -60,6 +60,16 @@ public: private: void visit_attributes (std::vector &attrs); + /** + * Insert a resolved macro invocation into the mappings once, meaning that we + * can call this function each time the early name resolution pass is underway + * and it will not trigger assertions for already resolved invocations. + */ + // TODO: Rename + void insert_once (AST::MacroInvocation &invocation, NodeId resolved); + // TODO: Rename + void insert_once (AST::MacroRulesDefinition &definition); + /** * Macros can either be resolved through textual scoping or regular path * scoping - which this class represents. Textual scoping works similarly to a