From patchwork Tue Jan 30 12:06:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892812 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=X2Ynwdns; 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 4TPPMz6n4lz23gZ for ; Tue, 30 Jan 2024 23:18:39 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C4406385AC1D for ; Tue, 30 Jan 2024 12:18:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 2A3463858024 for ; Tue, 30 Jan 2024 12:10:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2A3463858024 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 2A3463858024 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::435 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616663; cv=none; b=f351wuI+BOO3nS3b2RTuzNu8B9cFM4+W0HEXke1sz3iErNbKqaa4yFZCBwexdVCaV+4T30iWoc1D/RDzeZkcnSBHRcZJyY2H8oZszILjs5VymI2DES+Iwb/KNddswnvu+XZ0ulPd+P6N/6euXpN78FEE8fjerDYpzcHo2r34gOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616663; c=relaxed/simple; bh=5eAaJc24xQzFY4Hp3Bh0W7V2CakZQQH5i8Xc+zMo6eQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=F8CeR0e6QCBWy0Ms4ftue/vJn6BEjVmGgnEwGx+oHzQEFYFu9/N1gQijWwvxJwbwR8whF42Qd9jnwkWTcyPFahI1tZ/D1q7lUMJXV7HThJOPs8uYZGYfpNBaASl7etApLpHZZXqFPaVEWErg0AnIkTXemj8rXsmgWKgocBgMF54= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-33af4a0beb3so1012254f8f.2 for ; Tue, 30 Jan 2024 04:10:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616657; x=1707221457; 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=vA6A0EKQjxfrcTW/Y49w7J3YUL0aLdfIH1iAzk1c5b8=; b=X2YnwdnsmUiT3wjL3ODUIih6nZLalewxp3+hbjob4Kq+0mtHqlK50s6mxmlfUKe30s PmDZr1hl5MBfAn/Cnc67592xpjf2tPEK2yAkceznDSvtXPxKoHjhtKJkXP9FhtP1XoUk 15obXsROV1bwosX4cHqDCf97XdwfcM73O7XYFLDpTqLEOxM99JKvU2effLnXaSUzWkGe bwZ3SSyKk37RfXQQ0wmbdyFN5m3cRld2FBVQ5o7RG1VXXoMb1BVA+64ickEE7U33ZtSb kI9r427UjSYLqPT7NCvoUt4fMeK65ybxASdT89amTCCj/XqRTDN72csxwW5couWkLPOo LeBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616657; x=1707221457; 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=vA6A0EKQjxfrcTW/Y49w7J3YUL0aLdfIH1iAzk1c5b8=; b=q0PVTBNltZrgBgG8zdJ5Ns8vpAZYfJE0iXrEpl+/OS6zt1tfbP2rab5nB3a9dWiBE7 ZYPVVowL1fqwizaKjCD1/yBJNymdAylmDG3gOA6/sxPo/Jxt9JhEkqq0TPWmud7znvx7 uTs3yAtNhPbHZi7FCIC7LaX5/vo/sdmuEbSaC4mIOR+jngJaw9LysbBXqqp97HR0cWgM sG9S29qOukiw0qYiLVLpu/zve3Jfgwwy/G9lGo0HHLsjk2DBff4Bk+lhHPPgWzNlTFAl InW3I43qQ4QYaRyjwjjI3R3DGR7IeteWwgtgeYzwR1BVBfubSwZf66bdJglvsd7+2EB2 wHGQ== X-Gm-Message-State: AOJu0Yymt1mEUkwByBgdghRaQtKTxP/cetX7LhZPhWwtyfMHILikYjL9 ZcfmXY0xtguctXPxXBzRv4QaSiL220YDu4Tzhu0V+J1YAxjiR8nLis/OWOf2nTc8KkkKAJWfYWd 3oA== X-Google-Smtp-Source: AGHT+IGCNP+a/pMlimpIdvh20wCZfi7cp2WWUxvKIiwWSnAidLytQlqafgWz459tS2KMJSrFgWw8SA== X-Received: by 2002:a5d:56cd:0:b0:33a:e403:dd8e with SMTP id m13-20020a5d56cd000000b0033ae403dd8emr5522837wrw.46.1706616657661; Tue, 30 Jan 2024 04:10:57 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id f9-20020a056000036900b00339307d9d31sm10569894wrf.112.2024.01.30.04.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:10:56 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 010/101] gccrs: forever stack: Fix resolve_path signature Date: Tue, 30 Jan 2024 13:06:26 +0100 Message-ID: <20240130121026.807464-13-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=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: , 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-forever-stack.h: Fix `ForeverStack::resolve_path` signature. * resolve/rust-forever-stack.hxx: Likewise. * resolve/rust-early-name-resolver-2.0.cc (Early::visit): Use new API. (Early::visit_attributes): Likewise. --- .../resolve/rust-early-name-resolver-2.0.cc | 8 +++++--- gcc/rust/resolve/rust-forever-stack.h | 5 ++++- gcc/rust/resolve/rust-forever-stack.hxx | 17 +++++++++-------- 3 files changed, 18 insertions(+), 12 deletions(-) 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 57a38078f14..2245ba31772 100644 --- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc @@ -131,7 +131,7 @@ Early::visit (AST::MacroInvocation &invoc) // we won't have changed `definition` from `nullopt` if there are more // than one segments in our path if (!definition.has_value ()) - definition = ctx.macros.resolve_path (path); + definition = ctx.macros.resolve_path (path.get_segments ()); // if the definition still does not have a value, then it's an error if (!definition.has_value ()) @@ -188,7 +188,8 @@ Early::visit_attributes (std::vector &attrs) auto traits = attr.get_traits_to_derive (); for (auto &trait : traits) { - auto definition = ctx.macros.resolve_path (trait.get ()); + auto definition + = ctx.macros.resolve_path (trait.get ().get_segments ()); if (!definition.has_value ()) { // FIXME: Change to proper error message @@ -210,7 +211,8 @@ Early::visit_attributes (std::vector &attrs) ->lookup_builtin (name) .is_error ()) // Do not resolve builtins { - auto definition = ctx.macros.resolve_path (attr.get_path ()); + auto definition + = ctx.macros.resolve_path (attr.get_path ().get_segments ()); if (!definition.has_value ()) { // FIXME: Change to proper error message diff --git a/gcc/rust/resolve/rust-forever-stack.h b/gcc/rust/resolve/rust-forever-stack.h index 349d0971f61..ec469a9b3fa 100644 --- a/gcc/rust/resolve/rust-forever-stack.h +++ b/gcc/rust/resolve/rust-forever-stack.h @@ -470,10 +470,13 @@ public: /** * Resolve a path to its definition in the current `ForeverStack` * + * // TODO: Add documentation for `segments` + * * @return a valid option with the NodeId if the path is present in the * current map, an empty one otherwise. */ - template tl::optional resolve_path (const P &path); + template + tl::optional resolve_path (const std::vector &segments); std::string as_debug_string (); diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx index 211979fa9b9..8f0ab66b18b 100644 --- a/gcc/rust/resolve/rust-forever-stack.hxx +++ b/gcc/rust/resolve/rust-forever-stack.hxx @@ -429,24 +429,25 @@ ForeverStack::resolve_segments ( } template -template +template tl::optional -ForeverStack::resolve_path (const P &path) +ForeverStack::resolve_path (const std::vector &segments) { + // TODO: What to do if segments.empty() ? + // if there's only one segment, we just use `get` - if (path.get_segments ().size () == 1) - return get (path.get_final_segment ().as_string ()); + if (segments.size () == 1) + return get (segments.back ().as_string ()); auto starting_point = cursor (); - auto &segments = path.get_segments (); return find_starting_point (segments, starting_point) .and_then ([this, &segments, &starting_point] ( - std::vector::const_iterator iterator) { + typename std::vector::const_iterator iterator) { return resolve_segments (starting_point, segments, iterator); }) - .and_then ([&path] (Node final_node) { - return final_node.rib.get (path.get_final_segment ().as_string ()); + .and_then ([&segments] (Node final_node) { + return final_node.rib.get (segments.back ().as_string ()); }); }