From patchwork Tue Jan 30 12:06:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 194048 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1176994dyb; Tue, 30 Jan 2024 04:17:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IEtK5Yad+9KcotuUdK22E1xe70ANAGTjdh42w8J20X5qXjg54uS8udhztDsgNUyIU0vzdB0 X-Received: by 2002:ad4:5b87:0:b0:68c:4ece:7c13 with SMTP id 7-20020ad45b87000000b0068c4ece7c13mr1074874qvp.54.1706617021010; Tue, 30 Jan 2024 04:17:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706617020; cv=pass; d=google.com; s=arc-20160816; b=bkq/fohymIZRDPM+wdjZK47URujhExjATa52e6dXpvtjYCtA62F11z4xWKuyzcsJfW HTf9yX8C7Y9JmewGp+zqv2sOkfHx4JP3aHn7KZ4SjC+HzHIEffvdupqbZDnVEdLZ5pWo 0ytt8XB/oVN48P3KeaidwTEQcm9vZWHOpA9/owr65bFL0DYnLqBkjuv6mmXAA6HeUsPE E97alSMm87qB9x2yFPjKVS9cNdzJyKfpxH6SQXdygA7kRtTDlDHF4hLa5vw4yhWZyuiv SWpZs+vdVX3pyQHVLcnqkl/JFF16uBApd0+d61Khe6f9D+2COqIFtsuxDFLwqTbte6U0 iv2w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=3BtTVOTTc+QSfGDQq3+cLC2DSjVbspRvC3zL2WUZErw=; fh=6KiXNvQww/MsyVplklPLl//mUuD+DtDm73nSHh4O4+g=; b=f5Z48LojTTEqsor9ZHDGbb97jJTFLSgIJRq1ctgpEkzn2t0Dvfhd96ezuTxvAGUnyR IrAL9JenLMdd/tC2J9A3gfj7mMhbMGAHJAAKQFlsIy9ftYtE8h1uses3IqwkEWMPKeTc GgeGOCu73o4fJl757XYsFQG17fysrfgsXSKyzCBlUmYq1LzChTnrR3bZeiaY9qDE1Y8q fNrpqH3z/lry4cmEl7OfDnUo1otV739o8luIfH1DiGbWARc6M/St5u+GCuPQrYNj80tz qaKrtB3EdZWCP6zMQhsayi54g+50PWAMWNh4SllZEOllc1Vq0r1tzZDiynwIbIWGtR0b m6xA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Po8B1KXA; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id q4-20020ad45ca4000000b0068c5c8960b9si2062690qvh.478.2024.01.30.04.17.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:17:00 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=Po8B1KXA; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 24A0F3857720 for ; Tue, 30 Jan 2024 12:16:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id BFDC63858012 for ; Tue, 30 Jan 2024 12:10:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BFDC63858012 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 BFDC63858012 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::335 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616661; cv=none; b=LIOexUU9tPSu5GaWR9XgKqUsogfHWJFv45cmv97bUiuu0kS+HOsWpX4QbijwwtocwOD6jV/DHxQPYQK2YUKbX1cXqjJfEQTKW/6HrXzM79bQXIWC+jpQcinql+hjAikb7SE6uMla3u1q2ux7ZxJdUcyfm7B/n/yyL7G+UetTbRc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616661; c=relaxed/simple; bh=aSyWwnez/G5kPGp+NXGFQJGK0g60e21nwGoU2b1H2pc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=JVVqCmgaEWPiOxiAQHBY2B573fQUaHIA5kulWWVBlTuymB+WM7/q7WdJTwOpLvX8yPxNsyBcBEtfd0Z8pbb7vCPMuGbHiWFTlGutPFlPVUVAYang9gEmGb2lApqqNl6eaxaYBebqybixfDKsvrSXiDpI0KvtOoFP+S50qVaLY2o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-40ed3101ce3so52306705e9.2 for ; Tue, 30 Jan 2024 04:10:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616655; x=1707221455; 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=3BtTVOTTc+QSfGDQq3+cLC2DSjVbspRvC3zL2WUZErw=; b=Po8B1KXAWjDTtqlxHv0bSl7fNMuveNtyA159kXjfhHpMiKrWOVSbeqzqGRrKIkAC9x UwsvGIZH9tzO5fo9tu0KfmBLL6S7t/GmgHSHTRcYz6M4iuEPm7qQKmadc4XK7Y4cuOX/ GeBzmUU3ZSLXwms9gwDMlBO42cDjwE/dvDaSkJ2IIUwXxDEbxDxVZ6ALJeerhmuXnxkX OZlS58h8EhpcnqTM4y6R27mJ+t/4PMW0/JEs7D665i41Bytep8HJZBBYoBzhtuvUHDVe /cqmtAip8GIZTi9cwP+m3mDizFJLzuaiPlglMAfiukhaZfVl5kJugr8NhVfvXF7DMiKl 3Vdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616655; x=1707221455; 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=3BtTVOTTc+QSfGDQq3+cLC2DSjVbspRvC3zL2WUZErw=; b=dL7cGcF5xrG3/oudnmAsqsmBLM7u1aiZgBi6oUFMqGSYYpFU1T0GJFyjHMfIFyDkNw rJT70KHGyCdboePpRve/wYev/wjnNs9YD/3937dbpN3oTyzpJi5Dp883Lc8bAmoVQ6lK pNYPlg93c3ozTM/gMg9rboUhkR/p8dRAlFnQwe27uJZ8E7n21dX+OmKevC1waBM9Ah08 592U0ugWbEOVwBOoUrGfCZDNHL0IgJEs85nSaOil7gItg6H+cODQh2Dr3gosX5CKTrXW 9w0/i0bwKWTkBVJk9afyJHVxKPo+TZ7NE4UDWXcwXfl2UeeRwRIO6AZgp+GSyfr7U6Z3 sZVQ== X-Gm-Message-State: AOJu0YymF9uSjy34K5js/jR9Jf2j9o01Pt0UUbjczBp18eMbFjGSk1dS y0iryXth1uo0Uv/G/OFjO2fzs4NAjQz5w+WRrQJx7nNv0PlWX1G0XXALfGvzcLBAoPdVha40xn9 Ehg== X-Received: by 2002:a05:600c:4e91:b0:40e:490f:3f31 with SMTP id f17-20020a05600c4e9100b0040e490f3f31mr7055767wmq.35.1706616655754; Tue, 30 Jan 2024 04:10:55 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:10:55 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 008/101] gccrs: forever-stack: Fix basic get logic Date: Tue, 30 Jan 2024 13:06:24 +0100 Message-ID: <20240130121026.807464-11-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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789517649676687333 X-GMAIL-MSGID: 1789517649676687333 From: Arthur Cohen gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: Improve resolve_path API. * resolve/rust-forever-stack.hxx: Likewise and fix implementation. --- gcc/rust/resolve/rust-forever-stack.h | 19 +++++++------ gcc/rust/resolve/rust-forever-stack.hxx | 38 ++++++++++++------------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/gcc/rust/resolve/rust-forever-stack.h b/gcc/rust/resolve/rust-forever-stack.h index 7ee08491987..349d0971f61 100644 --- a/gcc/rust/resolve/rust-forever-stack.h +++ b/gcc/rust/resolve/rust-forever-stack.h @@ -473,7 +473,7 @@ public: * @return a valid option with the NodeId if the path is present in the * current map, an empty one otherwise. */ - tl::optional resolve_path (const AST::SimplePath &path); + template tl::optional resolve_path (const P &path); std::string as_debug_string (); @@ -550,18 +550,19 @@ private: /* Helper types and functions for `resolve_path` */ - using SegIterator = std::vector::const_iterator; + template + using SegIterator = typename std::vector::const_iterator; Node &find_closest_module (Node &starting_point); - tl::optional - find_starting_point (const std::vector &segments, - Node &starting_point); + template + tl::optional> + find_starting_point (const std::vector &segments, Node &starting_point); - tl::optional - resolve_segments (Node &starting_point, - const std::vector &segments, - SegIterator iterator); + template + tl::optional resolve_segments (Node &starting_point, + const std::vector &segments, + SegIterator iterator); }; } // namespace Resolver2_0 diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx index 5acdf06c770..806745eb908 100644 --- a/gcc/rust/resolve/rust-forever-stack.hxx +++ b/gcc/rust/resolve/rust-forever-stack.hxx @@ -208,15 +208,8 @@ ForeverStack::update_cursor (Node &new_cursor) } template -tl::optional -ForeverStack::get (const Identifier &name) -{ - return tl::nullopt; -} - -template <> inline tl::optional -ForeverStack::get (const Identifier &name) +ForeverStack::get (const Identifier &name) { tl::optional resolved_node = tl::nullopt; @@ -226,9 +219,9 @@ ForeverStack::get (const Identifier &name) return candidate.map_or ( [&resolved_node] (NodeId found) { - // macro resolving does not need to care about various ribs - they are - // available from all contexts if defined in the current scope, or an - // outermore one. so if we do have a candidate, we can return it + // for most namespaces, we do not need to care about various ribs - they + // are available from all contexts if defined in the current scope, or + // an outermore one. so if we do have a candidate, we can return it // directly and stop iterating resolved_node = found; @@ -278,9 +271,9 @@ ForeverStack::find_closest_module (Node &starting_point) /* If a the given condition is met, emit an error about misused leading path * segments */ +template static inline bool -check_leading_kw_at_start (const AST::SimplePathSegment &segment, - bool condition) +check_leading_kw_at_start (const S &segment, bool condition) { if (condition) rust_error_at ( @@ -297,9 +290,10 @@ check_leading_kw_at_start (const AST::SimplePathSegment &segment, // `super` segment, we go back to the cursor's parent until we reach the // correct one or the root. template -tl::optional::const_iterator> -ForeverStack::find_starting_point ( - const std::vector &segments, Node &starting_point) +template +tl::optional::const_iterator> +ForeverStack::find_starting_point (const std::vector &segments, + Node &starting_point) { auto iterator = segments.begin (); @@ -357,10 +351,11 @@ ForeverStack::find_starting_point ( } template +template tl::optional::Node &> ForeverStack::resolve_segments ( - Node &starting_point, const std::vector &segments, - std::vector::const_iterator iterator) + Node &starting_point, const std::vector &segments, + typename std::vector::const_iterator iterator) { auto *current_node = &starting_point; for (; !is_last (iterator, segments); iterator++) @@ -407,9 +402,14 @@ ForeverStack::resolve_segments ( } template +template tl::optional -ForeverStack::resolve_path (const AST::SimplePath &path) +ForeverStack::resolve_path (const P &path) { + // if there's only one segment, we just use `get` + if (path.get_segments ().size () == 1) + return get (path.get_final_segment ().as_string ()); + auto starting_point = cursor (); auto &segments = path.get_segments ();