From patchwork Tue Jan 30 12:06:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892806 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=PzzcCqnH; 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 4TPPDX0yMLz23dQ for ; Tue, 30 Jan 2024 23:12:12 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1C7D73857359 for ; Tue, 30 Jan 2024 12:12:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 765FF3858407 for ; Tue, 30 Jan 2024 12:10:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 765FF3858407 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 765FF3858407 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::334 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616656; cv=none; b=TtlgryhQowQ5q3NXbXqHkC3H5PEVGqUFkvHh9s5JtIJh6drpOZPY5LqtTRO1h6CcISoan39WPo4H+M07HkGMTlTEjeD6zDWCvLVV/NIVX1RgiDxHFzdu6QbK/ar6Txm3U6m8eL728td53ZMs/41l8jsAf3TmD5v12Un5E2tWxqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616656; c=relaxed/simple; bh=wlhisV3f9BFpORfCt34y1LIMxcELpLgxGD64iBMjUyU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=v+GTMiEbBlsgrJkpz7aMpqFWp4u7wSEigO0AMdPAx9wduFGFxp54YVIKfHm1Avm4MV6XjAGAMzXllM51FQshixcXkFYmY20hitAkfWR0QDPR9/ACt986ZThi63s8U6zVmStPCzMd+JMjeEbhUMeGNLsCoJGxlH+K/UQNphhNdNQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40efcb37373so8956875e9.2 for ; Tue, 30 Jan 2024 04:10:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616649; x=1707221449; 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=2FiiYG5wITwXf4jrhe2S+b2TsGW5AjR58EQEudQaO4A=; b=PzzcCqnHQtwk+aK8ZWO5VzU03yDwp42wY+1cw9r23b0FQXlUzsatlFPnR8X7zBMg8+ 9HwDmrJ+DXbeXjUVu5Q9Fu9JM3GQLWw9Pl3BTqvZ9bdRudDyi5Y4ssCT0fEf7f5gNufE gRBwEdGnZPemavq2e3+mzKispLiuRqlj++wjisZ5jOQvBW2v1zPnjSceqORo5UlLPRnk LJ0arzV1OvOdVVDNr4ObcwV1yuwzC6wbJpyDd10RJGGbvHFQO3ylR5RsZXmceKRRbJis bhuJU0SYg9nYws+R+ZnAgXmev+HrYDtoX7smwcWBadgfggB+y8SziITA2dCU5IV0e4xh XppA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616649; x=1707221449; 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=2FiiYG5wITwXf4jrhe2S+b2TsGW5AjR58EQEudQaO4A=; b=RQz6sojFhTyfA9v+1nau+2+wy0p8iCWJgNYDvuIPr2MpW9lmyJ8LvnqvUwB8kCjq2w qfjN1XXNF/SwD70ND6d1uIkON3Qgz19U/XiT1qC0xKl8Dni6ls2ueNRZcCZ5zbcD5ieR Jh0JCptywdaQmDlM3BvPBC7eA0+gqHeOk5uYcny3wbXZlLiXyseuW1lL5wH4hSo6eWDQ PuA9VxSNlzU2rzJAp6rYIaKI7F1OiNHg5Z1YHpmHRZbtikoTrA3PNogqjbjNqOi58ve9 64VIYCR3e+1anParJN/7fyh31dUyRTFDCYn8SmDTkhHvuY4ni5LMT2ruv4TjjuWnQLQZ H2vQ== X-Gm-Message-State: AOJu0YyWP4m0pwgVs0mwmxLEaEAWmBhxuGvSL5zf0Ozlu4dygfOY3rAR LjbG3LlVTWzdfGVZxTpFCGpnpeaV34GT91O6z94uUGKLkHbECNMF538bi2A9odNut9qn2hnqYdk jUA== X-Google-Smtp-Source: AGHT+IELp0rBFM14V065YjXOgr89Jc66inUUNJdPmAOsO3bpf4m905cHbWYEf+eOVTayxgElV/kyPA== X-Received: by 2002:adf:e311:0:b0:337:c4c1:a3af with SMTP id b17-20020adfe311000000b00337c4c1a3afmr6110068wrj.35.1706616649358; Tue, 30 Jan 2024 04:10:49 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:10:49 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 001/101] gccrs: Add visibility to trait item Date: Tue, 30 Jan 2024 13:06:17 +0100 Message-ID: <20240130121026.807464-4-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: Pierre-Emmanuel Patry The compiler shall parse visibility modifiers on trait items and reject those at a later stage (ast validation). gcc/rust/ChangeLog: * ast/rust-item.h (struct Visibility): Move Visibility from here... * ast/rust-ast.h (struct Visibility): ...to here. * parse/rust-parse-impl.h (Parser::parse_trait_item): Parse visibility before giving it back to the item parsing function. (Parser::parse_trait_type): Add visibility modifier. * parse/rust-parse.h (RUST_PARSE_H): Change function prototype. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/ast/rust-ast.h | 248 ++++++++++++++++--------------- gcc/rust/ast/rust-item.h | 5 +- gcc/rust/parse/rust-parse-impl.h | 10 +- gcc/rust/parse/rust-parse.h | 3 +- 4 files changed, 140 insertions(+), 126 deletions(-) diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 67ae92fb42d..4dc7f9710f3 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -490,6 +490,126 @@ operator!= (const SimplePath &lhs, const std::string &rhs) // forward decl for Attribute class AttrInput; +// Visibility of item - if the item has it, then it is some form of public +struct Visibility +{ +public: + enum VisType + { + PRIV, + PUB, + PUB_CRATE, + PUB_SELF, + PUB_SUPER, + PUB_IN_PATH + }; + +private: + VisType vis_type; + // Only assigned if vis_type is IN_PATH + SimplePath in_path; + location_t locus; + + // should this store location info? + +public: + // Creates a Visibility - TODO make constructor protected or private? + Visibility (VisType vis_type, SimplePath in_path, location_t locus) + : vis_type (vis_type), in_path (std::move (in_path)), locus (locus) + {} + + VisType get_vis_type () const { return vis_type; } + + // Returns whether visibility is in an error state. + bool is_error () const + { + return vis_type == PUB_IN_PATH && in_path.is_empty (); + } + + // Returns whether a visibility has a path + bool has_path () const { return !is_error () && vis_type >= PUB_CRATE; } + + // Returns whether visibility is public or not. + bool is_public () const { return vis_type != PRIV && !is_error (); } + + location_t get_locus () const { return locus; } + + // empty? + // Creates an error visibility. + static Visibility create_error () + { + return Visibility (PUB_IN_PATH, SimplePath::create_empty (), + UNDEF_LOCATION); + } + + // Unique pointer custom clone function + /*std::unique_ptr clone_visibility() const { + return std::unique_ptr(clone_visibility_impl()); + }*/ + + /* TODO: think of a way to only allow valid Visibility states - polymorphism + * is one idea but may be too resource-intensive. */ + + // Creates a public visibility with no further features/arguments. + // empty? + static Visibility create_public (location_t pub_vis_location) + { + return Visibility (PUB, SimplePath::create_empty (), pub_vis_location); + } + + // Creates a public visibility with crate-relative paths + static Visibility create_crate (location_t crate_tok_location, + location_t crate_vis_location) + { + return Visibility (PUB_CRATE, + SimplePath::from_str ("crate", crate_tok_location), + crate_vis_location); + } + + // Creates a public visibility with self-relative paths + static Visibility create_self (location_t self_tok_location, + location_t self_vis_location) + { + return Visibility (PUB_SELF, + SimplePath::from_str ("self", self_tok_location), + self_vis_location); + } + + // Creates a public visibility with parent module-relative paths + static Visibility create_super (location_t super_tok_location, + location_t super_vis_location) + { + return Visibility (PUB_SUPER, + SimplePath::from_str ("super", super_tok_location), + super_vis_location); + } + + // Creates a private visibility + static Visibility create_private () + { + return Visibility (PRIV, SimplePath::create_empty (), UNDEF_LOCATION); + } + + // Creates a public visibility with a given path or whatever. + static Visibility create_in_path (SimplePath in_path, + location_t in_path_vis_location) + { + return Visibility (PUB_IN_PATH, std::move (in_path), in_path_vis_location); + } + + std::string as_string () const; + const SimplePath &get_path () const { return in_path; } + SimplePath &get_path () { return in_path; } + +protected: + // Clone function implementation - not currently virtual but may be if + // polymorphism used + /*virtual*/ Visibility *clone_visibility_impl () const + { + return new Visibility (*this); + } +}; + // aka Attr // Attribute AST representation struct Attribute @@ -1042,125 +1162,6 @@ protected: Item *clone_stmt_impl () const final override { return clone_item_impl (); } }; -// Visibility of item - if the item has it, then it is some form of public -struct Visibility -{ -public: - enum VisType - { - PRIV, - PUB, - PUB_CRATE, - PUB_SELF, - PUB_SUPER, - PUB_IN_PATH - }; - -private: - VisType vis_type; - // Only assigned if vis_type is IN_PATH - SimplePath in_path; - location_t locus; - - // should this store location info? - -public: - // Creates a Visibility - TODO make constructor protected or private? - Visibility (VisType vis_type, SimplePath in_path, location_t locus) - : vis_type (vis_type), in_path (std::move (in_path)), locus (locus) - {} - - VisType get_vis_type () const { return vis_type; } - - // Returns whether visibility is in an error state. - bool is_error () const - { - return vis_type == PUB_IN_PATH && in_path.is_empty (); - } - - // Returns whether a visibility has a path - bool has_path () const { return !is_error () && vis_type >= PUB_CRATE; } - - // Returns whether visibility is public or not. - bool is_public () const { return vis_type != PRIV && !is_error (); } - - location_t get_locus () const { return locus; } - - // empty? - // Creates an error visibility. - static Visibility create_error () - { - return Visibility (PUB_IN_PATH, SimplePath::create_empty (), - UNDEF_LOCATION); - } - - // Unique pointer custom clone function - /*std::unique_ptr clone_visibility() const { - return std::unique_ptr(clone_visibility_impl()); - }*/ - - /* TODO: think of a way to only allow valid Visibility states - polymorphism - * is one idea but may be too resource-intensive. */ - - // Creates a public visibility with no further features/arguments. - // empty? - static Visibility create_public (location_t pub_vis_location) - { - return Visibility (PUB, SimplePath::create_empty (), pub_vis_location); - } - - // Creates a public visibility with crate-relative paths - static Visibility create_crate (location_t crate_tok_location, - location_t crate_vis_location) - { - return Visibility (PUB_CRATE, - SimplePath::from_str ("crate", crate_tok_location), - crate_vis_location); - } - - // Creates a public visibility with self-relative paths - static Visibility create_self (location_t self_tok_location, - location_t self_vis_location) - { - return Visibility (PUB_SELF, - SimplePath::from_str ("self", self_tok_location), - self_vis_location); - } - - // Creates a public visibility with parent module-relative paths - static Visibility create_super (location_t super_tok_location, - location_t super_vis_location) - { - return Visibility (PUB_SUPER, - SimplePath::from_str ("super", super_tok_location), - super_vis_location); - } - - // Creates a private visibility - static Visibility create_private () - { - return Visibility (PRIV, SimplePath::create_empty (), UNDEF_LOCATION); - } - - // Creates a public visibility with a given path or whatever. - static Visibility create_in_path (SimplePath in_path, - location_t in_path_vis_location) - { - return Visibility (PUB_IN_PATH, std::move (in_path), in_path_vis_location); - } - - std::string as_string () const; - const SimplePath &get_path () const { return in_path; } - SimplePath &get_path () { return in_path; } - -protected: - // Clone function implementation - not currently virtual but may be if - // polymorphism used - /*virtual*/ Visibility *clone_visibility_impl () const - { - return new Visibility (*this); - } -}; // Item that supports visibility - abstract base class class VisItem : public Item { @@ -1649,13 +1650,20 @@ class TraitItem : virtual public AssociatedItem { protected: TraitItem (location_t locus) - : node_id (Analysis::Mappings::get ()->get_next_node_id ()), locus (locus) + : node_id (Analysis::Mappings::get ()->get_next_node_id ()), + vis (Visibility::create_private ()), locus (locus) + {} + + TraitItem (Visibility vis, location_t locus) + : node_id (Analysis::Mappings::get ()->get_next_node_id ()), vis (vis), + locus (locus) {} // Clone function implementation as pure virtual method virtual TraitItem *clone_associated_item_impl () const override = 0; NodeId node_id; + Visibility vis; location_t locus; public: diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 8b53bc63a83..2c0e45962ce 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -3048,8 +3048,9 @@ public: TraitItemType (Identifier name, std::vector> type_param_bounds, - std::vector outer_attrs, location_t locus) - : TraitItem (locus), outer_attrs (std::move (outer_attrs)), + std::vector outer_attrs, Visibility vis, + location_t locus) + : TraitItem (vis, locus), outer_attrs (std::move (outer_attrs)), name (std::move (name)), type_param_bounds (std::move (type_param_bounds)) {} diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index fd648c53e14..0ae89dc3907 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -22,6 +22,7 @@ /* DO NOT INCLUDE ANYWHERE - this is automatically included with rust-parse.h * This is also the reason why there are no include guards. */ +#include "rust-item.h" #include "rust-token.h" #define INCLUDE_ALGORITHM #include "rust-diagnostics.h" @@ -5012,12 +5013,14 @@ Parser::parse_trait_item () // parse outer attributes (if they exist) AST::AttrVec outer_attrs = parse_outer_attributes (); + AST::Visibility vis = parse_visibility (); + // lookahead to determine what type of trait item to parse const_TokenPtr tok = lexer.peek_token (); switch (tok->get_id ()) { case TYPE: - return parse_trait_type (std::move (outer_attrs)); + return parse_trait_type (std::move (outer_attrs), vis); case CONST: // disambiguate with function qualifier if (lexer.peek_token (1)->get_id () == IDENTIFIER) @@ -5176,7 +5179,8 @@ Parser::parse_trait_item () // Parse a typedef trait item. template std::unique_ptr -Parser::parse_trait_type (AST::AttrVec outer_attrs) +Parser::parse_trait_type (AST::AttrVec outer_attrs, + AST::Visibility vis) { location_t locus = lexer.peek_token ()->get_locus (); skip_token (TYPE); @@ -5208,7 +5212,7 @@ Parser::parse_trait_type (AST::AttrVec outer_attrs) return std::unique_ptr ( new AST::TraitItemType (std::move (ident), std::move (bounds), - std::move (outer_attrs), locus)); + std::move (outer_attrs), vis, locus)); } // Parses a constant trait item. diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index 9e924e0015c..08e6ce000f4 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -17,6 +17,7 @@ along with GCC; see the file COPYING3. If not see #ifndef RUST_PARSE_H #define RUST_PARSE_H +#include "rust-item.h" #include "rust-lex.h" #include "rust-ast-full.h" #include "rust-diagnostics.h" @@ -331,7 +332,7 @@ private: std::unique_ptr parse_trait (AST::Visibility vis, AST::AttrVec outer_attrs); std::unique_ptr - parse_trait_type (AST::AttrVec outer_attrs); + parse_trait_type (AST::AttrVec outer_attrs, AST::Visibility); std::unique_ptr parse_trait_const (AST::AttrVec outer_attrs); std::unique_ptr parse_self_param (); From patchwork Tue Jan 30 12:06:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892807 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=IfFX1wtp; 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 4TPPDq4mNMz23dQ for ; Tue, 30 Jan 2024 23:12:27 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8A3F8385802B for ; Tue, 30 Jan 2024 12:12:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by sourceware.org (Postfix) with ESMTPS id 7943F385828A for ; Tue, 30 Jan 2024 12:10:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7943F385828A 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 7943F385828A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616656; cv=none; b=KygXQEF3EJBKTK0/ySms6XSjF+deaODnMkVvv2uMVg/D6JOsTtpFcaKm1fgowYHvRiLJTlVR3OdKhFf4E1QfTWIziN1lDQARbEUxm9yiZyS7BQhH3LiDeFaZ/p4MaiOjExNeFGoT7tQoeoZ5isw6XmZCSDg1Ou43xn/3iuQUyyg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616656; c=relaxed/simple; bh=Epbf87t6/3d/uCVS9Cf0cvGH7/5qXzBXkOY798BNHiM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=X9YKygy+Eg1nqu9sRCm/6EYIuhncegRqHJU9SZ3fbCNBU4+BZe3TKVkbcu1Jh1xRJHMVOaEM3z717nsqzBw+k1oEEUcbtfsqwgHBOHNUblPs+CpMFIKeFkgw+9h3dkr2NqhdD7vjwhvDwv9BOwtixy9gpbWd8DC8mdQqXEFuasM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-51025cafb51so5500674e87.2 for ; Tue, 30 Jan 2024 04:10:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616651; x=1707221451; 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=Ap00SXxB/m3TXm5PBDbnlsXuLUv51Lc5YaBAFv8i8ew=; b=IfFX1wtpDq1chREF0lNUyWvi1SMTWBEjREfJeLNAV8L5GzZJAueI8ewk9FYwtpgN3n iCbNKsNxVe5Vbl1znx78Q2qVE6HPuvGaalL/2ut7quYHwdIRCexOvgesnSU0qeGIK4VU 3CcxJFhqgEsFlh8Tvme6ctXKnI8V0kVpUZZN2Q2wLr+06x+yembsJQsRklXxrFEgEtfe eUmqDDNvku6B/nWnD5BU6E8uGNVXNTjBEYfvTnZpTLXcnjEqTLziOq/6aGNsyVRDwTFv w53Es3jPCjnTuJyd53kq9TsWUfHjUHHoCGxZiA0u7i86lH0+F/V8RjBTuu/iCBwjZkQ3 dWfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616651; x=1707221451; 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=Ap00SXxB/m3TXm5PBDbnlsXuLUv51Lc5YaBAFv8i8ew=; b=S+DpxXdFyMcmEduuVEzDwv29rhnVcwsIE/pxhavKe0u08B89KaJ6HwUpgja981zsZ9 8fNoNiwQBb0m0PCyaK9oHrVy1RyBMYw0K7pX51JuwOVZENfnzVBxCQFOUXOnvB3ExbY3 SEDRnI1ktV2jFPGSLkJzAp295ZdFQYwXH2rQiURMQALcJ823m6tkNI2f6mEDChKbKEr4 JkaBex+kr1+6MKZNjVHklK4HFXk3r27wVCf8i/NGY0+GOSo+uzoVK93qyR2+49Et6yq4 dyGi0Ors66as74COtJNwExLnuYIh/kXSLqY4S/psCAC14M0fHbY3xLufmlzDRlUQrQ9R jEYQ== X-Gm-Message-State: AOJu0YyXNwQFkWaekwMijivu9TFa93Ct65ZNH2IyH77nOXJ49mk+W1/t IkIiKLE8jeYDD7IXwMHMjFqbNMlAfFlsoSv/6KCyPfEipF0q6vbNAfneCjj0P0YqDaOOy5jjAft jtQ== X-Google-Smtp-Source: AGHT+IF1X47uAOBpzi6Hzct0rNpG1Dyx3Tvhg/V/OvL157ZnDHqAFUV4e5KXxEbeIM04AbBLpl5s/A== X-Received: by 2002:ac2:4db8:0:b0:511:976:b299 with SMTP id h24-20020ac24db8000000b005110976b299mr4887127lfe.52.1706616650717; Tue, 30 Jan 2024 04:10:50 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:10:50 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 002/101] gccrs: Add a test to highlight public trait type parsing Date: Tue, 30 Jan 2024 13:06:18 +0100 Message-ID: <20240130121026.807464-5-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: Pierre-Emmanuel Patry This new test highlight the parser's behavior around public trait types. gcc/testsuite/ChangeLog: * rust/compile/trait_pub_type.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- gcc/testsuite/rust/compile/trait_pub_type.rs | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 gcc/testsuite/rust/compile/trait_pub_type.rs diff --git a/gcc/testsuite/rust/compile/trait_pub_type.rs b/gcc/testsuite/rust/compile/trait_pub_type.rs new file mode 100644 index 00000000000..85f6462e3b5 --- /dev/null +++ b/gcc/testsuite/rust/compile/trait_pub_type.rs @@ -0,0 +1,6 @@ +fn main() {} + +#[cfg(FALSE)] +trait T { + pub type X; +} From patchwork Tue Jan 30 12:06:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892811 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=S0vfTewh; 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 4TPPM16jyRz23gZ for ; Tue, 30 Jan 2024 23:17:49 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E34813857725 for ; Tue, 30 Jan 2024 12:17:47 +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 DCE913858000 for ; Tue, 30 Jan 2024 12:10:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DCE913858000 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 DCE913858000 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=1706616657; cv=none; b=Vo0s4dQkC4Ac8cdXumLqi8IQKe/r9qzatO/Wlx2COH5STyZAwaw2MVlB+Jnn+yIQ65xXiRCeKuCHlUYjhWzZed1lFQGIZyFMbWNTQcnPZcABCeXY0ss3EcrgbyZUYbdFbbYNMtagMCZJXRi1pvod1+O6C5ExRlIwGnLClcVnMFs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616657; c=relaxed/simple; bh=rkkQtLfG9Cc8vbbSITDgLNbuoKQIi8V40f1u5tvuEH4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=I85vnKojKpTP8UJ4RUp8ePdg8RPGDMwsZK1CSyeRNAagZ8ODJ9p09kK4Ktqd4VvigadzI+yVzORmRWD7RsyudVXQTmIMEDjWAZnBCvpJobp0HKHPIugQkYIFcndIpBG1lp0+T0FDz7lDuerhdugKXihAiW9jJujfGz06kB3WB04= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2cf45305403so37534641fa.2 for ; Tue, 30 Jan 2024 04:10:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616651; x=1707221451; 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=RsFUMNZGNUmy6CpSPO7EBBkfBGnB+T1WGXUzR7rBCcY=; b=S0vfTewhdaoPdRoqiEGrQPLIHnPaFcdAarrJzPs9FWqY/vSoqnvBMCDEXVgDZeaHOe vv8fJBrtSg4FFZbt8PfV9KSPu+IuC5DRJgOGTVmqLN/cdQOxKXmRzYbk+Q7O457SAWSG x7ACZ0rNuNXSrSYe5LJWOzFDRzkPTIbwsF3u8M15cLYKe3X5YfkhUpz25Tcbc0vaXOvY t10N7FvBllxdSpdxzni+lEAae9fA90rPzgivaOfYfqJkAukN082srRtsbJjTYQvlEuNU ex5Wl4sMPIf4z4zpaLs55Obpra+SjovqIhtheg7upSMVKd+x4gjvKY3MIcEZmj+UVJlJ rqAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616651; x=1707221451; 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=RsFUMNZGNUmy6CpSPO7EBBkfBGnB+T1WGXUzR7rBCcY=; b=ByoLpU33tNfuLYpDLqeRWkdJGpk65n+09zyb5aFw4oC5kNWYGmxicvUd5wcYcBUxQt rnb8DGVAtqRlXQxljoyFSHfaaDpe7dVi6aoQhc000STOHYvQv67vhFhuJcfY8r359cHg wDSK8xpipS4Qb4YmaMXDLAT2VCFppTXYRhUR9biThVhHfHP2/h3BjHxL4GnWOYrlrSEV OlzUhQZDNwaQ2my6ZqI/AR5igPCM5wN0/Oa8hYH0SHowK0RyhLBSB0BTaGYM7mQ0cvGO TMBN/igMnqHDiTdvvw8JqC9RdZiyoEqi9ekQDmBdtJ7qDY2floOzhG8X7UvNh2ZplTrY iTRQ== X-Gm-Message-State: AOJu0YwrSkBCKe1z/40BqmtBCBM97iyC6Hcho8eqsIH/zpL5NZIYhv0M +DIY2TnyIx/4IDdvaEiEqSPOngTMsu4EN5zntKjwKW73FJrB3xvU7NiXgx2QzP62cxtJwmiyGjp 3Kg== X-Google-Smtp-Source: AGHT+IHGYWoHnSytoG+hB9KrOLPt87LrLH5IUaeTb2FxtUX6tihkKAUvGbGLdm3KVbQLYxtuHU0Fsg== X-Received: by 2002:a05:651c:104f:b0:2d0:480b:8d76 with SMTP id x15-20020a05651c104f00b002d0480b8d76mr4143404ljm.47.1706616651509; Tue, 30 Jan 2024 04:10:51 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:10:51 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 003/101] gccrs: Fix error emission for self pointers Date: Tue, 30 Jan 2024 13:06:19 +0100 Message-ID: <20240130121026.807464-6-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: Pierre-Emmanuel Patry Self pointer checking loop condition was inverted, the latter was therefore never executed. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_self_param): Fix the loop exit condition. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/parse/rust-parse-impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 0ae89dc3907..1ebe1ed442c 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -7129,7 +7129,7 @@ Parser::parse_self_param () for (auto &s : ptrs) { size_t i = 0; - for (i = 0; i > s.size (); i++) + for (i = 0; i < s.size (); i++) if (lexer.peek_token (i)->get_id () != s[i]) break; if (i == s.size ()) From patchwork Tue Jan 30 12:06:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892808 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=QPSn+QOh; 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 4TPPJx3NDtz23gZ for ; Tue, 30 Jan 2024 23:16:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6F3C1385803A for ; Tue, 30 Jan 2024 12:15:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 588993858295 for ; Tue, 30 Jan 2024 12:10:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 588993858295 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 588993858295 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::331 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616658; cv=none; b=pPOJqV1IjLjPAMtO/uAQff7rnFwXs8VpjJDRaWbSDVqFcA1+FkPh9EfoC5Qvo61QFyH7jMKxLlneWZ97ukcqJ13nBIrHIvYb0suN4sm2XFkHen2aqQB3Gbw0PcpjbXe2D/LYW/c7T8Dj4Jm9uFtgfkBKG8PTDZ2djcZw5mf2q5M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616658; c=relaxed/simple; bh=2db6XbycPDK1uxdrDo9crMoNgodRprwZXaTGc77PcZs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=UcWf22d260NFfo1cfQhSAqKxTSIkFukrpT8sHY+XkaXtJNdS0q0LasDI9ULNuP+iCeONw9gYdt6yhmdfnRi+9EHCB2wEPFCxnI2rn5KOYrqSD3naeP20GARLTKEzSc0VCdnTVTTrYhv3gpIM4xnQ2TBHigWDOH0oi96rHeT3OzE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-40eacb6067dso52372335e9.1 for ; Tue, 30 Jan 2024 04:10:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616652; x=1707221452; 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=7xoPxrkkfSFHEMZEenGxVGmEmD0lTBQk2GncYUzypyM=; b=QPSn+QOhX9fFDnwdebW0SswHW5UMp6+TBKRpFaQfN1VFKCJSzmb/rjvZ6D4W6uGJBG q8Qeka3uxhTHcqFFVN9uplQ3AWu6vJM2J1Hh8WDDwjR6qloks6SozRo/hsf+DXQAcnky 7U5/GGYnEYAqIvNw3pS0V506qwgat+ypKxIFBH7bwEGXAzBocwHXCH9oJCWVvLUJllvk dLCqWfcNjpcvYWmfnyAvbvfEkg8lTV7bBS+9qOxMPYrOzUBjLOpd3DrSfrfktBKCyb0w x8vqU28eQiCTUdUctH8TEGz0XxfIzLQUgRjhGvDvN7wmvxItvUcDiThHuZOnlqGT09z8 LYxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616652; x=1707221452; 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=7xoPxrkkfSFHEMZEenGxVGmEmD0lTBQk2GncYUzypyM=; b=ZKq+Pq6G48u9rCQKjuNOye9uohyGcYxpC0KT24YiibQp0KN2kmFdH0XItRPKwIzkn0 a4dmnOW7mUT86m9DXP63SFd117GL9QM5QH2nFusEQom7El1dr7f832sWgl2A5KM8R+Ae KGdt2vibOfVfBoApYVqff09k751rZJHQRT5AmZ2KweYov1yP+j+SfaqE7wu3E/QMc1FC Iyb5FEDixgM616Db7uBSJ+B0uKrruZbS7A//ttDfHug8AH775g0Gdczcov0y/Ig/zowh PYV5TIjEglR9DREEiA92wHemEexnNQEceHabLVvJOpXstW9teJQbm+rEelEd90/dOgTw XKMg== X-Gm-Message-State: AOJu0YwBpy1Co7/4xaAa+2AKCKqI7FjRJFEPYELVJSc+zrb/Xu5PBuZ7 LA9uWd9oA+rdXif8z6KEnr74ToF5P/iwzwRs8P+4rqFAytfWnLdgTXfjXaP3A4oSe4uHMeGDPFJ uYg== X-Google-Smtp-Source: AGHT+IEvoJP8CmGfdgFriMko/6lJGJ5zVX1TsvDvwRzzAPixKk9CI9rEObjp5ZvpHngfrgItkdu50g== X-Received: by 2002:a05:600c:4754:b0:40e:a39e:461f with SMTP id w20-20020a05600c475400b0040ea39e461fmr7890395wmo.38.1706616651989; Tue, 30 Jan 2024 04:10:51 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:10:51 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 004/101] gccrs: Report self parameter parsing error kind Date: Tue, 30 Jan 2024 13:06:20 +0100 Message-ID: <20240130121026.807464-7-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: Pierre-Emmanuel Patry Self parameter parsing errors may come from different situations, which should not be handled in the same way. It is now possible to differentiate a missing self parameter from a self pointer or a parsing error. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_function): Early return on unrecoverable errors. (Parser::parse_trait_item): Likewise. (Parser::parse_self_param): Update return type. * parse/rust-parse.h (enum ParseSelfError): Add enumeration to describe different self parameter parsing errors. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/parse/rust-parse-impl.h | 72 ++++++++++++++++++++------------ gcc/rust/parse/rust-parse.h | 12 +++++- 2 files changed, 56 insertions(+), 28 deletions(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 1ebe1ed442c..de17412c3b6 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -2880,8 +2880,13 @@ Parser::parse_function (AST::Visibility vis, return nullptr; } - std::unique_ptr initial_param = parse_self_param (); - if (initial_param != nullptr) + auto initial_param = parse_self_param (); + + if (!initial_param.has_value () + && initial_param.error () != ParseSelfError::NOT_SELF) + return nullptr; + + if (initial_param.has_value ()) skip_token (COMMA); // parse function parameters (only if next token isn't right paren) @@ -2891,9 +2896,9 @@ Parser::parse_function (AST::Visibility vis, function_params = parse_function_params ([] (TokenId id) { return id == RIGHT_PAREN; }); - if (initial_param != nullptr) + if (initial_param.has_value ()) function_params.insert (function_params.begin (), - std::move (initial_param)); + std::move (*initial_param)); if (!skip_token (RIGHT_PAREN)) { @@ -5063,13 +5068,15 @@ Parser::parse_trait_item () /* now for function vs method disambiguation - method has opening * "self" param */ - std::unique_ptr initial_param = parse_self_param (); + auto initial_param = parse_self_param (); + if (!initial_param.has_value () && initial_param.error () != NOT_SELF) + return nullptr; /* FIXME: ensure that self param doesn't accidently consume tokens for * a function */ bool is_method = false; - if (initial_param != nullptr) + if (initial_param.has_value ()) { - if (initial_param->is_self ()) + if ((*initial_param)->is_self ()) is_method = true; /* skip comma so function and method regular params can be parsed @@ -5089,9 +5096,9 @@ Parser::parse_trait_item () return nullptr; } - if (initial_param != nullptr) + if (initial_param.has_value ()) function_params.insert (function_params.begin (), - std::move (initial_param)); + std::move (*initial_param)); // parse return type (optional) std::unique_ptr return_type = parse_function_return_type (); @@ -5609,14 +5616,18 @@ Parser::parse_inherent_impl_function_or_method ( // now for function vs method disambiguation - method has opening "self" // param - std::unique_ptr initial_param = parse_self_param (); + auto initial_param = parse_self_param (); + + if (!initial_param.has_value () && initial_param.error () != NOT_SELF) + return nullptr; + /* FIXME: ensure that self param doesn't accidently consume tokens for a * function one idea is to lookahead up to 4 tokens to see whether self is * one of them */ bool is_method = false; - if (initial_param != nullptr) + if (initial_param.has_value ()) { - if (initial_param->is_self ()) + if ((*initial_param)->is_self ()) is_method = true; /* skip comma so function and method regular params can be parsed in @@ -5629,9 +5640,9 @@ Parser::parse_inherent_impl_function_or_method ( std::vector> function_params = parse_function_params ([] (TokenId id) { return id == RIGHT_PAREN; }); - if (initial_param != nullptr) + if (initial_param.has_value ()) function_params.insert (function_params.begin (), - std::move (initial_param)); + std::move (*initial_param)); if (!skip_token (RIGHT_PAREN)) { @@ -5817,13 +5828,17 @@ Parser::parse_trait_impl_function_or_method ( // now for function vs method disambiguation - method has opening "self" // param - std::unique_ptr initial_param = parse_self_param (); + auto initial_param = parse_self_param (); + + if (!initial_param.has_value () && initial_param.error () != NOT_SELF) + return nullptr; + // FIXME: ensure that self param doesn't accidently consume tokens for a // function bool is_method = false; - if (initial_param != nullptr) + if (initial_param.has_value ()) { - if (initial_param->is_self ()) + if ((*initial_param)->is_self ()) is_method = true; // skip comma so function and method regular params can be parsed in @@ -5861,9 +5876,9 @@ Parser::parse_trait_impl_function_or_method ( } } - if (initial_param != nullptr) + if (initial_param.has_value ()) function_params.insert (function_params.begin (), - std::move (initial_param)); + std::move (*initial_param)); // DEBUG rust_debug ("successfully parsed function params in function or method " @@ -7112,7 +7127,7 @@ Parser::parse_qualified_path_in_type () // Parses a self param. Also handles self param not existing. template -std::unique_ptr +tl::expected, ParseSelfError> Parser::parse_self_param () { bool has_reference = false; @@ -7133,8 +7148,11 @@ Parser::parse_self_param () if (lexer.peek_token (i)->get_id () != s[i]) break; if (i == s.size ()) - rust_error_at (lexer.peek_token ()->get_locus (), - "cannot pass % by raw pointer"); + { + rust_error_at (lexer.peek_token ()->get_locus (), + "cannot pass % by raw pointer"); + return tl::make_unexpected (ParseSelfError::SELF_PTR); + } } // Trying to find those patterns: @@ -7154,7 +7172,7 @@ Parser::parse_self_param () is_self = true; if (!is_self) - return nullptr; + return tl::make_unexpected (ParseSelfError::NOT_SELF); // test if self is a reference parameter if (lexer.peek_token ()->get_id () == AMP) @@ -7175,7 +7193,7 @@ Parser::parse_self_param () add_error (std::move (error)); // skip after somewhere? - return nullptr; + return tl::make_unexpected (ParseSelfError::PARSING); } } } @@ -7193,7 +7211,7 @@ Parser::parse_self_param () if (self_tok->get_id () != SELF) { // skip after somewhere? - return nullptr; + return tl::make_unexpected (ParseSelfError::NOT_SELF); } lexer.skip_token (); @@ -7212,7 +7230,7 @@ Parser::parse_self_param () add_error (std::move (error)); // skip after somewhere? - return nullptr; + return tl::make_unexpected (ParseSelfError::PARSING); } } @@ -7225,7 +7243,7 @@ Parser::parse_self_param () add_error (std::move (error)); // skip after somewhere? - return nullptr; + return tl::make_unexpected (ParseSelfError::PARSING); } if (has_reference) diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index 08e6ce000f4..e873d5292cd 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -22,6 +22,8 @@ along with GCC; see the file COPYING3. If not see #include "rust-ast-full.h" #include "rust-diagnostics.h" +#include "expected.h" + namespace Rust { /* HACK: used to resolve the expression-or-statement problem at the end of a * block by allowing either to be returned (technically). Tagged union would @@ -93,6 +95,12 @@ struct ParseRestrictions bool allow_close_after_expr_stmt = false; }; +enum ParseSelfError +{ + SELF_PTR, + PARSING, + NOT_SELF, +}; // Parser implementation for gccrs. // TODO: if updated to C++20, ManagedTokenSource would be useful as a concept template class Parser @@ -335,7 +343,9 @@ private: parse_trait_type (AST::AttrVec outer_attrs, AST::Visibility); std::unique_ptr parse_trait_const (AST::AttrVec outer_attrs); - std::unique_ptr parse_self_param (); + + tl::expected, ParseSelfError> parse_self_param (); + std::unique_ptr parse_impl (AST::Visibility vis, AST::AttrVec outer_attrs); std::unique_ptr From patchwork Tue Jan 30 12:06:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892818 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=RDC070OL; 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 4TPPPV33Bzz23gZ for ; Tue, 30 Jan 2024 23:19:58 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DF9BB3858037 for ; Tue, 30 Jan 2024 12:19:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 5AB8A3858420 for ; Tue, 30 Jan 2024 12:10:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5AB8A3858420 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 5AB8A3858420 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616658; cv=none; b=jHi7GgTPJsD2UIZP5Mr7hpF2og6uaOfpXZDQ5i+GDqIkoAScTdfJY+q38Y/VU6N99fye3qTOAXRzhri2PMlvf34uhRwW3KCw9Gb6E500daPnRstgo16V9WQTFQUJk2UHIH2YsEgwJAW6Ltj1TSTgRLcGByjhnm8PCsIjF1iZQ6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616658; c=relaxed/simple; bh=hsH7citPP5JhDe8i0Wpj6AyM1jqYHBQb6+yhq9yo1WQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Sz7hR9WAbXJZHCc8WG3kohAiC7cSpOyTae9nkxpY2ag1Zqp4nDZtXMH9QEVk3av0SnKnz6/h3fJC901zY2Z83RO6LgeHDIiUUkUkkogm6PbBKTIjXDL9SfolDcxSr9OdimxtTADAX4+9FRQhqCji1JX9loYQbzk4jfnn+UbXxKo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40fafae5532so1864045e9.1 for ; Tue, 30 Jan 2024 04:10:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616654; x=1707221454; 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=azHRcw2LPwTrBH4l3Dkj85RnNy2lZu3gFIkBfciGaCQ=; b=RDC070OLirQ/nidNHRzru12Yc8O1hkmv5F74M7568Feu8FpOjRD9p/rr3CJE5CMCpN I85kqBtv6xwN3XEC9l1Zuy5FW0jTC4bV2O4Fyl6afzGd5msrKJGoW12MoNdKAKKGZMKx Pt6vb2K1elz8MWlEAHPdCQXHC2jjJxSb/CgxxNDzwSnV/ErJiBhtbkh/CWm1VgrTR4VM pB0kF4854uUI4xWn6b4d2XcPwgsHbQ05skVU/drsBs6FeP+agG/+bK41fyZlLp3cMpY5 CE5D8aZyueFEBh9lp7iwKWdX0jmvyghcMcutaHdClHFxdXuLEfsooVPHO4BikcmAszVs pnbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616654; x=1707221454; 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=azHRcw2LPwTrBH4l3Dkj85RnNy2lZu3gFIkBfciGaCQ=; b=sBVEGF9kSCEByk3wiuSGBqZPdp3KOXl5GOzh5PIVZOFKFWXIlGIpiVjBAe5Zz71jjO NZ1+pfP+EjGGQpHwWD7au9HChJmWiK5w7Nf0KLhU0koWTwOURl1lBPaKYql4H/OkJ6GB ktpmw42NNi3VL8/tTV3zvhhv2hIVjAOt2MJPcja2xVz/lXbDBnp/G2jeYxy7LK9x2+9p YJ6UWcQN2itqX5v2CmEjvximfee/NuWwiSKVgJv1R66xApTo9yO+SKEuYzMeMtEsY6eS 0dxTpMvAcfEjEIWUNJQqxcNXXWaCiPlgrZVfjWgFW599TBzuVIYjE/yiOh8EmWUN0y8R Cq1w== X-Gm-Message-State: AOJu0Yw+i/nxxt096Vo8f1Pus9b8djaKRyLzA7JLXd6+V2qYbUO5nRdN I3zoMOvQcwR3c8+IfqSGDyZRXtYc/GbdNW3yV8tE+Uo+ECsbu5IKH8uRqZMNmPp0Bu+0N2NBAUa ULA== X-Google-Smtp-Source: AGHT+IFRMfvbb+tqYIz2cwRp6vli1GbI5LCu3pTAeFew/4MVSupOe9pu2y6/efkWHfvqg4jto+Ey5A== X-Received: by 2002:adf:ff92:0:b0:33a:e791:d8a6 with SMTP id j18-20020adfff92000000b0033ae791d8a6mr5173179wrr.47.1706616653830; Tue, 30 Jan 2024 04:10:53 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:10:52 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 005/101] gccrs: Add new test for parsing errors on self pointers Date: Tue, 30 Jan 2024 13:06:21 +0100 Message-ID: <20240130121026.807464-8-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: Pierre-Emmanuel Patry Add new tests to highlight the behavior of errors thrown when meeting a self pointer. gcc/testsuite/ChangeLog: * rust/compile/self_const_ptr.rs: New test. * rust/compile/self_mut_ptr.rs: New test. * rust/compile/self_ptr.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- gcc/testsuite/rust/compile/self_const_ptr.rs | 8 ++++++++ gcc/testsuite/rust/compile/self_mut_ptr.rs | 8 ++++++++ gcc/testsuite/rust/compile/self_ptr.rs | 8 ++++++++ 3 files changed, 24 insertions(+) create mode 100644 gcc/testsuite/rust/compile/self_const_ptr.rs create mode 100644 gcc/testsuite/rust/compile/self_mut_ptr.rs create mode 100644 gcc/testsuite/rust/compile/self_ptr.rs diff --git a/gcc/testsuite/rust/compile/self_const_ptr.rs b/gcc/testsuite/rust/compile/self_const_ptr.rs new file mode 100644 index 00000000000..014fe1b63d8 --- /dev/null +++ b/gcc/testsuite/rust/compile/self_const_ptr.rs @@ -0,0 +1,8 @@ +struct MyStruct; + +impl MyStruct { + pub fn do_something(*const self) {} + // { dg-error "cannot pass .self. by raw pointer" "" { target *-*-* } .-1 } + // { dg-error "failed to parse inherent impl item in inherent impl" "" { target *-*-* } .-2 } + // { dg-error "failed to parse item in crate" "" { target *-*-* } .-3 } +} diff --git a/gcc/testsuite/rust/compile/self_mut_ptr.rs b/gcc/testsuite/rust/compile/self_mut_ptr.rs new file mode 100644 index 00000000000..2a127b7dcb2 --- /dev/null +++ b/gcc/testsuite/rust/compile/self_mut_ptr.rs @@ -0,0 +1,8 @@ +struct MyStruct; + +impl MyStruct { + pub fn do_something(*mut self) {} + // { dg-error "cannot pass .self. by raw pointer" "" { target *-*-* } .-1 } + // { dg-error "failed to parse inherent impl item in inherent impl" "" { target *-*-* } .-2 } + // { dg-error "failed to parse item in crate" "" { target *-*-* } .-3 } +} diff --git a/gcc/testsuite/rust/compile/self_ptr.rs b/gcc/testsuite/rust/compile/self_ptr.rs new file mode 100644 index 00000000000..fd7ff6ce5d2 --- /dev/null +++ b/gcc/testsuite/rust/compile/self_ptr.rs @@ -0,0 +1,8 @@ +struct MyStruct; + +impl MyStruct { + pub fn do_something(*self) {} + // { dg-error "cannot pass .self. by raw pointer" "" { target *-*-* } .-1 } + // { dg-error "failed to parse inherent impl item in inherent impl" "" { target *-*-* } .-2 } + // { dg-error "failed to parse item in crate" "" { target *-*-* } .-3 } +} From patchwork Tue Jan 30 12:06:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892820 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=DrMvEZsB; 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 4TPPQ03kV2z23dQ for ; Tue, 30 Jan 2024 23:20:24 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 887A73857349 for ; Tue, 30 Jan 2024 12:20:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 25FD93858298 for ; Tue, 30 Jan 2024 12:10:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 25FD93858298 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 25FD93858298 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616659; cv=none; b=gscyf9L98sMHWr7xAy44l/7Qj7DpaDWlR1/kBVopyhLidykDf1Vyuhev0CKPIteLWIQ1R6DEORIg/7JgNvLtCtEKeGNqFxl4u+aXYdyLJOvW7lt4D6Gq7Ws7ZM8uQLjpH0HDwo2MlPQkKeN5dZGJSamqKwuylCHcRJ9WFH2JC04= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616659; c=relaxed/simple; bh=n4EHKhaThq/CKI8lAbQGTDgooTS1OuFvy1yLUeA8le0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=HlPST+C87B0zlZREqMwZXXglTNnMY3MUpAy8UBTOrv9+xLhjz0L+0Y52FfGn0UQSUuL6Su7Saeapl3D823+cGNS3lf5IlMW5lRkX/O06dsYCODnrhGdutADjkhcqiqfnHnmLSsmsWPkRqwPjO+qmYTlnZPl6aTKB+ubLgGZQWow= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-33aea66a31cso1188413f8f.1 for ; Tue, 30 Jan 2024 04:10:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616654; x=1707221454; 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=h+4MyOJXx2eww9qsPWju5OoyMFPjyNIzLy+HiMrddJw=; b=DrMvEZsBBxMDMd1hSEz7xW2teHQ/5LXt/j3Tt5VMPlHQJ/7N5Vs66Gz1fBLg+I03ec Fnn1iDGVodWzbO0e/imtTSrnuKpN5zafcl1kuerLtIc+nn+3itZbdUZR67TH3aArN6zw LgKedKTLAkYPZzbHXzSfVLXjsx15hhHREaGJsB5e8MdtaYiCTnL1bsEq6d20bVLeR+a8 2rr0WuZLrjFmaM4AOHJVrzNnVZX1OM050/7jgcvnZi1+3t505J1yshb16Oki+eAxCaPc BNGkzgG1o1jkaiozX1xlJdrIxwgG20WVu6/Xu2PqSiJJJYf3lhh1h6bvtqJ74D/g1MzZ v1Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616654; x=1707221454; 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=h+4MyOJXx2eww9qsPWju5OoyMFPjyNIzLy+HiMrddJw=; b=dEpLKrDxmy4gRTg+xn8530w0wIJk+ymT2pm79EuCSbfKypqZnXWF2AVCEkXHsLi2P+ +z5r/6PCN1GYPiQEzZ+NmukHYkokGeCTs0rkn4z6AgliIJJyYONSnmbHknkZnxj9bosS uz0rBttoCYUW/PT+ZOE/D5cY1qcWyxkU7IJGjUyQU9UL8EhybA+fRncrOHgFCTXuwc7B GXqvcqlGCXGIDnS5jKQS6I56ksx+C0I11BZWkvSoiOvQWv9GVbm5L3QIc9AFlTDj+gvd JTgYD5FqmiyT/8SVCnj6K7Qf+nChejoglKS58L6J2Pt58EcSBK817Yull0REBGb0/kka 3Nng== X-Gm-Message-State: AOJu0YxabTJ4QzmzEGS88F059IJ++9prFMmXTXT0F+rqI/+ntlKuvQvs FthqUlL2PdeY0SmAM1JfQZryGk3jjkBKTsN0nfA/vrxiQwaJV4XukxWSODu8irEcA1qHEJkr5+G oZQ== X-Google-Smtp-Source: AGHT+IGKjKlF4IGAlR7OoyITgKQm3/h5nE4Oh8fgQIowZAbuqWlyNdB5CtH2xfQoYdyyzWn0k79oHg== X-Received: by 2002:a5d:4e89:0:b0:337:cf50:5ff with SMTP id e9-20020a5d4e89000000b00337cf5005ffmr7032500wru.61.1706616654197; Tue, 30 Jan 2024 04:10:54 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:10:54 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 006/101] gccrs: ast: Change *Path nodes API Date: Tue, 30 Jan 2024 13:06:22 +0100 Message-ID: <20240130121026.807464-9-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: * ast/rust-ast.h: Change Path API to be more consistent. * ast/rust-path.h: Likewise. * ast/rust-ast-collector.cc (TokenCollector::visit): Use new API. * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Likewise. * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Likewise. * resolve/rust-forever-stack.hxx: Likewise. --- gcc/rust/ast/rust-ast-collector.cc | 2 +- gcc/rust/ast/rust-ast.h | 2 +- gcc/rust/ast/rust-path.h | 9 +++++++++ gcc/rust/resolve/rust-ast-resolve-item.cc | 2 +- gcc/rust/resolve/rust-ast-resolve-path.cc | 2 +- gcc/rust/resolve/rust-forever-stack.hxx | 7 ++++--- 6 files changed, 17 insertions(+), 7 deletions(-) diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc index cb8dfd80016..7d3d3e204f7 100644 --- a/gcc/rust/ast/rust-ast-collector.cc +++ b/gcc/rust/ast/rust-ast-collector.cc @@ -191,7 +191,7 @@ TokenCollector::visit (SimplePathSegment &segment) { push (Rust::Token::make (SUPER, segment.get_locus ())); } - else if (segment.is_lower_self ()) + else if (segment.is_lower_self_seg ()) { push (Rust::Token::make (SELF, segment.get_locus ())); } diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 4dc7f9710f3..47c02d6ac8b 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -399,7 +399,7 @@ public: { return as_string ().compare ("crate") == 0; } - bool is_lower_self () const { return as_string ().compare ("self") == 0; } + bool is_lower_self_seg () const { return as_string ().compare ("self") == 0; } bool is_big_self () const { return as_string ().compare ("Self") == 0; } }; diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h index b76664fa7dd..ccac6303bb4 100644 --- a/gcc/rust/ast/rust-path.h +++ b/gcc/rust/ast/rust-path.h @@ -536,6 +536,7 @@ public: { return !has_generic_args () && get_ident_segment ().is_crate_segment (); } + bool is_lower_self_seg () const { return !has_generic_args () && get_ident_segment ().is_lower_self (); @@ -646,6 +647,14 @@ public: outer_attrs = std::move (new_attrs); } + NodeId get_pattern_node_id () const { return get_node_id (); } + + PathExprSegment &get_final_segment () { return get_segments ().back (); } + const PathExprSegment &get_final_segment () const + { + return get_segments ().back (); + } + protected: /* Use covariance to implement clone function as returning this object * rather than base */ diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 1fc6b920c5e..eaee5bc8606 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -1031,7 +1031,7 @@ ResolveItem::visit (AST::UseDeclaration &use_item) if (!ok) continue; - const AST::SimplePathSegment &final_seg = path.get_final_segment (); + const AST::SimplePathSegment &final_seg = path.get_segments ().back (); auto decl = CanonicalPath::new_seg (resolved_node_id, final_seg.as_string ()); diff --git a/gcc/rust/resolve/rust-ast-resolve-path.cc b/gcc/rust/resolve/rust-ast-resolve-path.cc index fd2a844a506..9e982d0610e 100644 --- a/gcc/rust/resolve/rust-ast-resolve-path.cc +++ b/gcc/rust/resolve/rust-ast-resolve-path.cc @@ -367,7 +367,7 @@ ResolvePath::resolve_path (AST::SimplePath *expr) // is_first_segment ? "true" : "false", // is_final_segment ? "true" : "false"); if (resolved_node_id == UNKNOWN_NODEID && !is_first_segment - && is_final_segment && segment.is_lower_self ()) + && is_final_segment && segment.is_lower_self_seg ()) { resolved_node_id = previous_resolved_node_id; } diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx index 8bdda67782a..5acdf06c770 100644 --- a/gcc/rust/resolve/rust-forever-stack.hxx +++ b/gcc/rust/resolve/rust-forever-stack.hxx @@ -313,7 +313,8 @@ ForeverStack::find_starting_point ( for (; !is_last (iterator, segments); iterator++) { auto seg = *iterator; - auto is_self_or_crate = seg.is_crate_path_seg () || seg.is_lower_self (); + auto is_self_or_crate + = seg.is_crate_path_seg () || seg.is_lower_self_seg (); // if we're after the first path segment and meet `self` or `crate`, it's // an error - we should only be seeing `super` keywords at this point @@ -327,7 +328,7 @@ ForeverStack::find_starting_point ( iterator++; break; } - if (seg.is_lower_self ()) + if (seg.is_lower_self_seg ()) { // do nothing and exit iterator++; @@ -371,7 +372,7 @@ ForeverStack::resolve_segments ( // check that we don't encounter *any* leading keywords afterwards if (check_leading_kw_at_start (seg, seg.is_crate_path_seg () || seg.is_super_path_seg () - || seg.is_lower_self ())) + || seg.is_lower_self_seg ())) return tl::nullopt; tl::optional::Node &> child = tl::nullopt; From patchwork Tue Jan 30 12:06:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892826 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=cfmyxD/8; 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 4TPPSr3Hpyz23dQ for ; Tue, 30 Jan 2024 23:22:52 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 66FE63858017 for ; Tue, 30 Jan 2024 12:22:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id DC883385800D for ; Tue, 30 Jan 2024 12:10:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DC883385800D 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 DC883385800D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616660; cv=none; b=lRvIfH3SDAgSj7dC0g8cj0qfI0smhkGBpCxDadn6KelCQJYrTLgJxh13JYpWgjVhG1jZ23Ol/+4yv1e7tjI4+Ef89OEaZkDob3J2iQhMFiKR9+aD1peVRALnIR8lfsxCK/CfQZGHsnmEAssz1y5Uu3jNDqpagVlOIWZe+vLVLXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616660; c=relaxed/simple; bh=r7Xw6S9uiZHpaFXwHJMOWWkHAsI/4DoCI7SPFiU7adk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=AX1uIaPtCPVUPvqGZIK70PnVu3khYrSZPwQb447PPer9g8Ow1aUaDw4orul3Pbd5xX42PvX2GGQE9StEw88mHri6+kgh/3ufMW4Tnjt+//z2dNk1KWHiqcLwQSS6kvNcL0A9Cfw+jBxceud4ICfS4+VeFf0VhqJp3t6Dn2D4U2s= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-33aeb088324so1539280f8f.2 for ; Tue, 30 Jan 2024 04:10:56 -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=UFUj8oXvszxBtgA1dFNDIG0cvROUwhGsgQytSRWEMVs=; b=cfmyxD/8WAaQvsx3ejiU2hKlSLBcUoHK0JRSXFuIjs77Z5mcP//d1f6zcMGMpm2wyX pmn8pd3EldgZXmaVFRjw/LAayjHIQLxSjcHw0Cbltn9KntC6X3W7pEr0f4eplVPpzCTh ENYNgNDIV62Xu61miPCoONWMQ7bLtKA9094jKWFK6kQML5oifSpivqX4FDcjYHTfUgmy Ke73Yti1OAmCqyEPNJNKhwYHDhumYkvJb9E35bHGC/8uiff4WNppnM37/q7oJzi4fAKr Wy9cQtnLPEShnYvipjbKExRGbW2jG2COF0PeCd+erXKPSgxriCduc7Kj6KuAzXIA/uZo O/QA== 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=UFUj8oXvszxBtgA1dFNDIG0cvROUwhGsgQytSRWEMVs=; b=AG1L3H+Vw5UJvNhUvLwlr5o4z9QjlAXwk/4NOjq7mhnBKury5PABppHrvUVoisAOos SGWpXeuFq1FFy+jb+sFK714RGnAxY6bcug5PNVe4VsmhRLhQN6KmUJQ7TNtW31VVElvl BJU1qVuQYriG8itA4AQMyC+ypUYoHBCRqP3mrbwvWq681tBksH12OtozGjg9OYhyOmWc 2/sfYnS5iW7sVX8v+o+367qh81TdvDlfSI0q2sYUJPXBb0HZ0e0NnmvWstmfdJq5mdtU eVuWNpxwFdPAeJIqs6zvUZwjDoNd5EyLLYVIF7xbHIICqEhw6Kn81WGpz413a5f0rKKV GEiA== X-Gm-Message-State: AOJu0YxwhnpsC8PafxoLzTuFqZrML7sTDV3tbDPUvbH5n767+inokqXO kDmqvlN6DwfVEewW9biQydN7DZVrV1ayMDZJK+7wkVVjg4cP+di30/wgPfkr7qS92sJ/+VchlVK Nmw== X-Google-Smtp-Source: AGHT+IEs12hxacHOQKcOvZGwVnsEARTSm91THiSd/m0uNG8VpGMuP9+Vl4DlPGBfGEahtxlSE8ogXA== X-Received: by 2002:adf:e40d:0:b0:339:5951:801d with SMTP id g13-20020adfe40d000000b003395951801dmr5999535wrm.6.1706616655391; 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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:10:54 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 007/101] gccrs: rib: Add Namespace enum Date: Tue, 30 Jan 2024 13:06:23 +0100 Message-ID: <20240130121026.807464-10-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-rib.h: Add Namespace enum. --- gcc/rust/resolve/rust-rib.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/gcc/rust/resolve/rust-rib.h b/gcc/rust/resolve/rust-rib.h index 37bd90f1f75..4ffd00a5d6c 100644 --- a/gcc/rust/resolve/rust-rib.h +++ b/gcc/rust/resolve/rust-rib.h @@ -27,6 +27,31 @@ namespace Rust { namespace Resolver2_0 { +/** + +pub enum Namespace { + /// The type namespace includes `struct`s, `enum`s, `union`s, `trait`s, and +`mod`s + /// (and, by extension, crates). + /// + /// Note that the type namespace includes other items; this is not an + /// exhaustive list. + TypeNS, + /// The value namespace includes `fn`s, `const`s, `static`s, and local +variables (including function arguments). ValueNS, + /// The macro namespace includes `macro_rules!` macros, declarative `macro`s, + /// procedural macros, attribute macros, `derive` macros, and non-macro +attributes + /// like `#[inline]` and `#[rustfmt::skip]`. + MacroNS, +} + +*/ + +// FIXME: There's no `labels` namespace, not sure if we need one or how to keep +// one +// FIXME: And where are things like loop labels kept? + /** * All namespaces that Rust's name resolution needs to handle */ 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: 1892809 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=Po8B1KXA; 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 4TPPK31wWfz23gZ for ; Tue, 30 Jan 2024 23:16:07 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 160F23857727 for ; Tue, 30 Jan 2024 12:16:05 +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-Google-Smtp-Source: AGHT+IFcBcbBNbhUGgJxmZYOUbLIYk6BYOGO7tbTPGDAkMdusWrkcjBpVJqVMPgIt8RDiGjh8CKLHA== 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+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 (); From patchwork Tue Jan 30 12:06:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892832 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=CydJG1+A; 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 4TPPWR6bPRz23fD for ; Tue, 30 Jan 2024 23:25:07 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E9E27385E008 for ; Tue, 30 Jan 2024 12:25:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 73703385801F for ; Tue, 30 Jan 2024 12:10:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 73703385801F 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 73703385801F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::332 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616661; cv=none; b=V8hASwXbh8paXB5vmU8hGGn3JAfbSNXj+EbNwys6byvBmojqyn2pcgskuWoCMkfEvkfVCzzLGjqQ8grnerr5eoJYnSzCLO44xKL5ENmy7ud4JD7qTHkOoSjVZWOWVS326NAP8ICeDcB1k7kvcNfscv9ogC1HgPmODSLU6RW9YF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616661; c=relaxed/simple; bh=7ndiFrcraf9h3eHC9XJgGgR+8NJKjQnZTgkfmkovmAk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QrE0vupf7eZQsehO6W8rpSII/PLrDxd2dHCzdy/7fkLxxIuhx6ppKa+kxaY6urkaIfFOCfrP7UkIFAKHYsiBE7tWcm9lUaP9Zs5MDJyRjbXxJArrcUpgIMSqJs93MMSCoPhTaa2ksl/cUlOwC0A2u9qQKhlonoE+pf8N+Kx3q3A= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40faf6788d1so1638055e9.0 for ; Tue, 30 Jan 2024 04:10:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616656; x=1707221456; 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=SM5FPqGsTqK4mDPcsmuBGQtDBFibXUOYX8m/x89exW8=; b=CydJG1+A6stsU+QTMlshTSksgsE5FJkIQ2hEcYl8taHEr5TQCEj0N/DoEZud1HLmpQ UlKgj0WwWPE45GyBRomYojOrZycpY0TiDeYJCGHARxw2tLrN8xkHG1K/yO7Ea6cNnB3M osKGNjVa56b6QLxt5l2CDFV1vX9j4i9G+KqejHwQ2SXlNXdSRCNthtsysV7gGSxWyNiK xeFh3L7T3R0Z6rpzAFjMkTDmklYjGleUYiU7TjppubuZwAdNk4WJ4iSH81ToJHWxCTl2 Zrrc6Mg1Oso2bKvgvB3wLCL0e1IeuYEQde9pyKXo8+O3U9TsSS/tKkBf+MRmEOZvR4JF Y/lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616656; x=1707221456; 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=SM5FPqGsTqK4mDPcsmuBGQtDBFibXUOYX8m/x89exW8=; b=frVuJdSY2IvzZxkdeJlfewzL2NRE8Bs8jm1QOtPbRZyswda3EgeSGjrhxbq3QdE4r7 D/kJvrhKQFVYfG2B8KrOxpEjURGJovYMDDxGYLQg0jKw5CctEgwbsuTmHyfY2H6rywZ1 bpwW90xEH5eDrVXoJ/2J7HTbD5o12dkNoeKEZrbU5Nc/uQ26yIz9eoMYgxVb+fElY7Az F2bpyIx1hRwqX7WfdOiiRKaRfzPQqVyWpWvMtoYhVugEUVk6+tGOaftHO7QtzJdLM/pj xH4TpFY1dkT9dQUSmODkscpkSPkVAAgSWtThQnugc/6C9r4M5rDWvH31Au1ri5lMSd7A K1Rw== X-Gm-Message-State: AOJu0YzHn9bNnpwauUCE0kkfkv1hLaKhdZCMwuO5F62QGL8dQAcoXs5b f5ygoOVglKXYuOzq7QB3vuOZhGXOVtW+bTH6Jhy8T3waJ9EFv9dBsFFADW8TPD9EwvOZZQlcDZv Nmg== X-Google-Smtp-Source: AGHT+IEpcFeNdpEIcWqv+ouwAj5QcMUxglk7AIWVGRQgR7B05O3SypPhLsJSCrZureXRrJeqfx4fwA== X-Received: by 2002:adf:f851:0:b0:336:c79d:7504 with SMTP id d17-20020adff851000000b00336c79d7504mr1437797wrq.2.1706616656129; Tue, 30 Jan 2024 04:10:56 -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 009/101] gccrs: foreverstack: Specialize `get` for Namespace::Labels Date: Tue, 30 Jan 2024 13:06:25 +0100 Message-ID: <20240130121026.807464-12-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-forever-stack.hxx: Add specific behavior for `ForeverStack::get` when dealing with labels. --- gcc/rust/resolve/rust-forever-stack.hxx | 29 ++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx index 806745eb908..211979fa9b9 100644 --- a/gcc/rust/resolve/rust-forever-stack.hxx +++ b/gcc/rust/resolve/rust-forever-stack.hxx @@ -208,7 +208,7 @@ ForeverStack::update_cursor (Node &new_cursor) } template -inline tl::optional +tl::optional ForeverStack::get (const Identifier &name) { tl::optional resolved_node = tl::nullopt; @@ -234,6 +234,33 @@ ForeverStack::get (const Identifier &name) return resolved_node; } +template <> +tl::optional inline ForeverStack::get ( + const Identifier &name) +{ + tl::optional resolved_node = tl::nullopt; + + reverse_iter ([&resolved_node, &name] (Node ¤t) { + // looking up for labels cannot go through function ribs + // TODO: What other ribs? + if (current.rib.kind == Rib::Kind::Function) + return KeepGoing::No; + + auto candidate = current.rib.get (name.as_string ()); + + // FIXME: Factor this in a function with the generic `get` + return candidate.map_or ( + [&resolved_node] (NodeId found) { + resolved_node = found; + + return KeepGoing::No; + }, + KeepGoing::Yes); + }); + + return resolved_node; +} + /* Check if an iterator points to the last element */ template static bool 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 ()); }); } From patchwork Tue Jan 30 12:06:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892810 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=Ry4Gsvm9; 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 4TPPKL43SYz23gZ for ; Tue, 30 Jan 2024 23:16:22 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 77398385802A for ; Tue, 30 Jan 2024 12:16:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 38F4E3858013 for ; Tue, 30 Jan 2024 12:11:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 38F4E3858013 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 38F4E3858013 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::333 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616663; cv=none; b=s8nA2EePSbjhtncPNKef3bMatZ86zzatABHGPu0CkbHwBppTd1PPgL7hkrwqK2xDVs/j3VjLMbJmdxwVYf3NWJgwzqpe/JOWTZ/fLXncyjO8SDI3nXieJVN/niE0tVKRJAu4LNq8DE3yhqJSC0PMLs4jh/QAf9F9C223nFseutw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616663; c=relaxed/simple; bh=SARfAZZfppjviofKp//rwOzBoEsEhUL3XzVwaZQ5xPU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ClzYW2pJpX55nyeEacQ4GyOsMFgZSdKbL+TK5K0RYjgqNbYbI0l9WY7yEZ04w0JMmj6+ORDv3ouxwNu8CF1ajn5u8QgPDZyVmLX0kqMd1gSEaZ98JCIrYM042i/vbZnNtmSr4omr/NJwIWHeKWjLEUT0fNi0Rhs0KuCGarc6XFw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40faf6788d1so1638255e9.0 for ; Tue, 30 Jan 2024 04:11:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616658; x=1707221458; 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=JbjvnR7SPKCHqLG43as+0BfNS49SF2SIiL28v3ta9vc=; b=Ry4Gsvm9ZHQWc+5v2ZepNqR7CAa7j6uAx9ZpEL3qtid3ATQjyyxUDYGGdZ9FCiHc8b QQnPFYZKhZNTGlAm0s/SEpCwaiektzXHyno/cpTpYjAld64XCA2wxgSJ34tXhCm/tMp2 qBH5XcwtdZrXattL6oKNQF5aUzwdOZaHnQa77wMbyVTLPE3wO0X7v474zGpUWyRpC+Yj jRiTFNSc/za944g5DakkbJ7x5dfA21vleraMJmzx6H86evsJFoTES0yaWKYhmzKlEgkD wnl7mmgDI1CR0ZpSspji8XcH8LNqmDTCgCrW8VrjiopkAl5iFlQJN/KgaNX8mp7QoFnp y+Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616658; x=1707221458; 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=JbjvnR7SPKCHqLG43as+0BfNS49SF2SIiL28v3ta9vc=; b=MCialAIdqZZiaa4EOR7Btv11Ak2Z1htT56En0ICmDa9O6WYJP8HOLZoQb2miVMgEUu +jNrAQQJenA4TyjpBjFZSJLZtD/tjUJYb15JDZWimcpsZ+dVPf1HZScg9LCxn5OnzBor l+lIryrEm0wqjbSnDrmZgEl8ZOsuRgaKX/v1VgMuLRUzGBPQ2vmsCRfp+TAHY+0OXShO at79mVikulIz9qRFE8wa2C97jw5zKhziBb5E7zKD5ZVFEonvMA+6zCAbl9zAGq/V5r70 xRls+0zsP7wK/mcp0agDiLHcT4XA/pczOC2FWqNo8+s/7u5OMU5hwdLvURsg48miY7rb M5eQ== X-Gm-Message-State: AOJu0Yx6ys5GFS4j2iR9W9KVncdZp8wQT+sJ+MNPP9GFVCe0pLCjIGZ+ Cp8exM5rlUQ7bLynv1NHtgEzwWYuVTpCh5AseQH4FRV2HWOJptIICpY2uFeB0puA3O5ukrJNCmS 5pw== X-Google-Smtp-Source: AGHT+IGTYGdiXCpmlwKztBNdScVle5XhD4f2xJgAL+3NPT8kMy8WoSPL6Lruuo3u/n1srjdpYK2v4g== X-Received: by 2002:adf:f285:0:b0:33a:f090:f758 with SMTP id k5-20020adff285000000b0033af090f758mr1424709wro.27.1706616658014; Tue, 30 Jan 2024 04:10:58 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:10:57 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 011/101] gccrs: forever stack: Improve resolve_path implementation Date: Tue, 30 Jan 2024 13:06:27 +0100 Message-ID: <20240130121026.807464-14-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-forever-stack.hxx: Do not copy segment when dereferencing iterator in `find_starting_point`. --- gcc/rust/resolve/rust-forever-stack.hxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx index 8f0ab66b18b..642135cda85 100644 --- a/gcc/rust/resolve/rust-forever-stack.hxx +++ b/gcc/rust/resolve/rust-forever-stack.hxx @@ -333,7 +333,7 @@ ForeverStack::find_starting_point (const std::vector &segments, for (; !is_last (iterator, segments); iterator++) { - auto seg = *iterator; + auto &seg = *iterator; auto is_self_or_crate = seg.is_crate_path_seg () || seg.is_lower_self_seg (); From patchwork Tue Jan 30 12:06:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892814 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=JLqAxKbQ; 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 4TPPNG64r3z23gZ for ; Tue, 30 Jan 2024 23:18:54 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D76BB385DC05 for ; Tue, 30 Jan 2024 12:18:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 5D12138582A3 for ; Tue, 30 Jan 2024 12:11:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5D12138582A3 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 5D12138582A3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616666; cv=none; b=v6wLaSkrX5sykNECFCojtfeByxed4iDRv2J7aInAijnczG6emEcazFfHzCUxDaTYmN2hC9X8fjj3Os3Wb7RsvXkN7RuEpfehyRKSDw+Ej8MOFy0mIvywun6wHFTAZoMvx0a5RhDYEhlpaxh6HkkqC5hEQFn4+C8tf66JJrc7Lhc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616666; c=relaxed/simple; bh=vVoXioeFEmJ9J7I3VRvk/12lq1KUVEzC++eRzh9faBI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XQFFXS40HMewjDC8ROUpCVoctZSpp3sW/CGfOsDMaUZAkjhPWS1hKwhLfOrOk7ayVK0yIgHADdWAHixKL+5H5F15KFKLkAUiL4EYbCOR4QYZs9fdX/WR5v9f4r3ycUlZwaz4P+owBvgAkLejiPaERw1tGs2mlakXi72BweXdubs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-33aef64f702so1046640f8f.3 for ; Tue, 30 Jan 2024 04:11:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616658; x=1707221458; 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=zMaBmClI87H01KBkQpbYdoKmuuYOGOFP18Y59AXZt14=; b=JLqAxKbQWkWpZY7yhl3be09MGSwiNMANaIuAJefHj6V06ddd00lSTl9c8XaxzQpoNX UwJYgCbaDMr/nL94Gkcb3nn4CSwKyeWodd8jCO9i9o3rqXNqe4vpfMriD3BRqsR7wsm9 w27SIdIe9CshHbRlxay3Fs+Z/vlsUWXA93+gDNjRi4kjKCEIi0xM3EBWWKr7Zn24qVWz ePVi9cn6pOW5ZF2eif4XTFX5K1rShBlQi3zW9l3Lrb37yPQ7R8ZQ83Tsa4StEP+fB79T BIrSueF2nudtTJS6W2zEsWbS16OMlxfXpOZdheYz/RweiaznJ2BO7fw65E9MG9yhk3ev x+Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616658; x=1707221458; 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=zMaBmClI87H01KBkQpbYdoKmuuYOGOFP18Y59AXZt14=; b=oTjk1Icqcupra0MIcsRFA5orGC0fkC83/1uzhiYVUd+YSlSZEHmV8v9p2moDRjF7rv F6PwOUjIobHvHErbMj2adoOAeOw6ZLkeJ36A1qh6z7Ok2ckEhnRPuNFPSJxIr8NV2M0o hJS23X6UDzzIp/Ds7AXXUo41o2IxKSZ4ezjqi8HziXIdslzA7p9ynhR6n8P9J+T8HRZ8 QBqplKmDijzofkcp+Pe0006gFMDR0xBrFlx0XSucJ1fS1x9eNXrw7Zb6/euL8eb6vELY juG/yZqp6HjtHxpat5edMDjwnI936iZ53SJKlxwxqs8gBr8/ED8TUJ7Z2mh03SmW9hKE hSkA== X-Gm-Message-State: AOJu0YzBi3gD9wrkni+g/bYVVUshDTYeJ68/FkzSmqRlm9SBz1WRw++s U7o9/91k6PMkMndzVHtkL9I+tWUnzwiW+EEQpJUWFBSTMEikcgM8BT/NTs6Dtx9Ktosr4ApcM1s WqQ== X-Google-Smtp-Source: AGHT+IHzBslxj2tdVBdzpxNjBkBAwf2CFSo12EsVdXc3EfwuRKIlMAbxlRp906dDBB81TJkt1eWENg== X-Received: by 2002:adf:fecc:0:b0:33a:e89f:1dc6 with SMTP id q12-20020adffecc000000b0033ae89f1dc6mr4239751wrs.29.1706616658443; Tue, 30 Jan 2024 04:10:58 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:10:58 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 012/101] gccrs: foreverstack: Add `to_canonical_path` method Date: Tue, 30 Jan 2024 13:06:28 +0100 Message-ID: <20240130121026.807464-15-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-forever-stack.h: New method. * resolve/rust-forever-stack.hxx: Likewise. --- gcc/rust/resolve/rust-forever-stack.h | 25 ++++++- gcc/rust/resolve/rust-forever-stack.hxx | 90 ++++++++++++++++++++++++- 2 files changed, 110 insertions(+), 5 deletions(-) diff --git a/gcc/rust/resolve/rust-forever-stack.h b/gcc/rust/resolve/rust-forever-stack.h index ec469a9b3fa..37277ddb3ad 100644 --- a/gcc/rust/resolve/rust-forever-stack.h +++ b/gcc/rust/resolve/rust-forever-stack.h @@ -396,7 +396,10 @@ template class ForeverStack { public: ForeverStack () - : root (Node (Rib (Rib::Kind::Normal))), cursor_reference (root) + // FIXME: Is that valid? Do we use the root? If yes, we should give the + // crate's node id to ForeverStack's constructor + : root (Node (Rib (Rib::Kind::Normal), UNKNOWN_NODEID)), + cursor_reference (root) { rust_assert (root.is_root ()); rust_assert (root.is_leaf ()); @@ -478,6 +481,12 @@ public: template tl::optional resolve_path (const std::vector &segments); + // FIXME: Documentation + tl::optional to_canonical_path (NodeId id); + + // FIXME: Documentation + tl::optional to_rib (NodeId rib_id); + std::string as_debug_string (); private: @@ -509,8 +518,10 @@ private: class Node { public: - Node (Rib rib) : rib (rib) {} - Node (Rib rib, Node &parent) : rib (rib), parent (parent) {} + Node (Rib rib, NodeId id) : rib (rib), id (id) {} + Node (Rib rib, NodeId id, Node &parent) + : rib (rib), id (id), parent (parent) + {} bool is_root () const; bool is_leaf () const; @@ -520,6 +531,8 @@ private: Rib rib; // this is the "value" of the node - the data it keeps. std::map children; // all the other nodes it links to + NodeId id; // The node id of the Node's scope + tl::optional parent; // `None` only if the node is a root }; @@ -566,6 +579,12 @@ private: tl::optional resolve_segments (Node &starting_point, const std::vector &segments, SegIterator iterator); + + /* Helper functions for forward resolution (to_canonical_path, to_rib...) */ + + // FIXME: Documentation + tl::optional> dfs (Node &starting_point, + NodeId to_find); }; } // namespace Resolver2_0 diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx index 642135cda85..4e06da235bf 100644 --- a/gcc/rust/resolve/rust-forever-stack.hxx +++ b/gcc/rust/resolve/rust-forever-stack.hxx @@ -66,8 +66,8 @@ ForeverStack::push_inner (Rib rib, Link link) // the iterator and a boolean. If the value already exists, the iterator // points to it. Otherwise, it points to the newly emplaced value, so we can // just update our cursor(). - auto emplace - = cursor ().children.emplace (std::make_pair (link, Node (rib, cursor ()))); + auto emplace = cursor ().children.emplace ( + std::make_pair (link, Node (rib, link.id, cursor ()))); auto it = emplace.first; auto existed = !emplace.second; @@ -451,6 +451,92 @@ ForeverStack::resolve_path (const std::vector &segments) }); } +template +tl::optional::Node &, std::string>> +ForeverStack::dfs (ForeverStack::Node &starting_point, NodeId to_find) +{ + auto &values = starting_point.rib.get_values (); + + for (auto &kv : values) + if (kv.second == to_find) + return {{starting_point, kv.first}}; + + for (auto &child : starting_point.children) + { + auto candidate = dfs (child.second, to_find); + + if (candidate.has_value ()) + return candidate; + } + + return tl::nullopt; +} + +template +tl::optional +ForeverStack::to_canonical_path (NodeId id) +{ + // find the id in the current forever stack, starting from the root, + // performing either a BFS or DFS once the Node containing the ID is found, go + // back up to the root (parent().parent().parent()...) accumulate link + // segments reverse them that's your canonical path + + return dfs (root, id).map ([this, id] (std::pair tuple) { + auto containing_node = tuple.first; + auto name = tuple.second; + + auto segments = std::vector (); + + reverse_iter (containing_node, [&segments] (Node ¤t) { + if (current.is_root ()) + return KeepGoing::No; + + auto children = current.parent.value ().children; + const Link *outer_link = nullptr; + + for (auto &kv : children) + { + auto &link = kv.first; + auto &child = kv.second; + + if (link.id == child.id) + { + outer_link = &link; + break; + } + } + + rust_assert (outer_link); + + outer_link->path.map ([&segments, outer_link] (Identifier path) { + segments.emplace (segments.begin (), + Resolver::CanonicalPath::new_seg (outer_link->id, + path.as_string ())); + }); + + return KeepGoing::Yes; + }); + + auto path = Resolver::CanonicalPath::create_empty (); + for (const auto &segment : segments) + path = path.append (segment); + + // Finally, append the name + path = path.append (Resolver::CanonicalPath::new_seg (id, name)); + rust_debug ("[ARTHUR] found path: %s. Size: %lu", path.get ().c_str (), + segments.size ()); + + return path; + }); +} + +template +tl::optional +ForeverStack::to_rib (NodeId rib_id) +{ + return tl::nullopt; +} + template void ForeverStack::stream_rib (std::stringstream &stream, const Rib &rib, From patchwork Tue Jan 30 12:06:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892813 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=PHEB+hra; 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 4TPPNB1gr6z23gZ for ; Tue, 30 Jan 2024 23:18:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2D7EB385B512 for ; Tue, 30 Jan 2024 12:18:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id 9DF423858034 for ; Tue, 30 Jan 2024 12:11:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9DF423858034 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 9DF423858034 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::229 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616664; cv=none; b=rWxilQ4iYBf+7NcYf2PY5ALou6ry0JOKODfc4ddlz+esV2PAsR3txcq3EncecjW5RIRP5gnIvqy3I2BfzeVJA4YUYwaeEiVN+SH4xSAFZ5UCl+hl2BQdavBR0nq9Icbc54twDNMBp1tw/hQIB+/LbzlgZP5oSKmISMrPTJcOIg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616664; c=relaxed/simple; bh=u0LufJgOETfsbbkuJgKzJVFxRbyQmbFFz0nirPTbPoc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=YO5j3+UZtn1ckitZg5dx/dUDz0EhT7kjHCYOKI84WoycfEaiN2PxWe9721eg9kYld2Yx2Xu1xrToxtVsYiYq56qT0OqNQkn5nXgFxecJpd1bh6YjHTMWt+NwP3IRIascnx1fbmEvjT/82TMSiSWjWsI4GVsgBheoespaUwX15Qg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2cf206e4d56so41758001fa.3 for ; Tue, 30 Jan 2024 04:11:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616660; x=1707221460; 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=AAA+tUrpjHaW4zs1uyJOfNzO47oHzJEHDWM2+KLxQRQ=; b=PHEB+hraSZXqGyLlHU+2CoCZO1kf9vs1F2/CclLpsnjpxlkIqkFHz4FZAqtvNbNri0 xio1FqubPBPBPmCuLel34i9qNVZbEIVbbquefBSTwXy3O76D82uFHKY6LuX5MDprvUCb kvSRUIakT8xQC8t6m4k7Nt8KPUCSRR9cYCn7eOp3IWDk3vQKbWMgHGml+5z+kVL8/yIA taCh92V2cABGjP++2lcPSf0Go3HR7eG1PqcO2WEwis5PDQxFHYW9Bs+oLgHo8yJSnekU +szQTsgLNehSdrtz+MQjxKQdMayKNXjV8F023tour+Qjdn/LP+wv2JZ1J32fo+72NaNs QjjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616660; x=1707221460; 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=AAA+tUrpjHaW4zs1uyJOfNzO47oHzJEHDWM2+KLxQRQ=; b=dANVzAmyVuL8q/gJ/IW8bDGvdXhYuX47+7PO+Mk55aAkg6m5Ibu4o1vWlBv0PqwX95 fQ7AKTvB42Cy1xJ7/bvgJXDDglRU5sxboVRO7/h5do3y4bYOSozyvWcUL5qDSskYzGAq 7FgJ9nLPeaOR1tEupROxbCW04vB2IiW1jxLylwNeKSRBWwrx2GxjTXOdJ4PQXR+UIOau k3pIBv6uTukdWZjG20nWieWgV2mrONWG6tbr980xlxkjybzimGSoyUWp1ZmJo9hvISQQ N74gn8uYpziBV47AN8vo7WMRs+GZDI+xPQ2hYYIKCWCCnShRbzalBuj+3LybFPDHrUuO dtiA== X-Gm-Message-State: AOJu0Yyc/FVhQH0Ox3TPUx7nT/VtwOcl+43bBqpjoIi10EcsoI1m78kZ XM8IZFnohqvSKmoMq1HDweVpQnTLUjEAMvl7mvUKmAoxmo0KgRP+YwNE0xwn80Fgctx2o12id78 /VA== X-Google-Smtp-Source: AGHT+IEr11s/OYDdsCfqG2XQjmF112lXWWETf90fxoJETLhXgRGP7s8dlI8jUpnaydG/9SOzhZizXg== X-Received: by 2002:a2e:b8c4:0:b0:2cd:3b6:b3d7 with SMTP id s4-20020a2eb8c4000000b002cd03b6b3d7mr6308444ljp.34.1706616659853; Tue, 30 Jan 2024 04:10:59 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:10:58 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 013/101] gccrs: foreverstack: Add `to_rib` method Date: Tue, 30 Jan 2024 13:06:29 +0100 Message-ID: <20240130121026.807464-16-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-forever-stack.h: New method. * resolve/rust-forever-stack.hxx: Likewise. --- gcc/rust/resolve/rust-forever-stack.h | 2 ++ gcc/rust/resolve/rust-forever-stack.hxx | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/gcc/rust/resolve/rust-forever-stack.h b/gcc/rust/resolve/rust-forever-stack.h index 37277ddb3ad..a540e682e5b 100644 --- a/gcc/rust/resolve/rust-forever-stack.h +++ b/gcc/rust/resolve/rust-forever-stack.h @@ -585,6 +585,8 @@ private: // FIXME: Documentation tl::optional> dfs (Node &starting_point, NodeId to_find); + // FIXME: Documentation + tl::optional dfs_rib (Node &starting_point, NodeId to_find); }; } // namespace Resolver2_0 diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx index 4e06da235bf..65796172b08 100644 --- a/gcc/rust/resolve/rust-forever-stack.hxx +++ b/gcc/rust/resolve/rust-forever-stack.hxx @@ -532,11 +532,29 @@ ForeverStack::to_canonical_path (NodeId id) template tl::optional -ForeverStack::to_rib (NodeId rib_id) +ForeverStack::dfs_rib (ForeverStack::Node &starting_point, NodeId to_find) { + if (starting_point.id == to_find) + return starting_point.rib; + + for (auto &child : starting_point.children) + { + auto candidate = dfs_rib (child.second, to_find); + + if (candidate.has_value ()) + return candidate; + } + return tl::nullopt; } +template +tl::optional +ForeverStack::to_rib (NodeId rib_id) +{ + return dfs_rib (root, rib_id); +} + template void ForeverStack::stream_rib (std::stringstream &stream, const Rib &rib, From patchwork Tue Jan 30 12:06:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892821 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=eHpMOlg5; 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 4TPPQG6Bxgz23dQ for ; Tue, 30 Jan 2024 23:20:38 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 373763857434 for ; Tue, 30 Jan 2024 12:20:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id 230223858037 for ; Tue, 30 Jan 2024 12:11:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 230223858037 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 230223858037 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616666; cv=none; b=q/f0k3seZI7V/M3T43SAxhYLbP+umC+GwbYfy47wO1Q2cy6DCMfLWiCOKOxx418kn5k1DkgLk1KF+qYPc11OWiivIr6p2rGRdIgPJKzQQi2l3jHwapmpy87GWJp9WvFNAPVhpErcSpyD/+K/1i9PBWb86IS/LmzgqvBKbWHCl44= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616666; c=relaxed/simple; bh=B6ARVYXELAe6CqsolDgpi4/wV5Zs4MNx7wtvjNSM228=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Q9xkfS3pHNyeNeXM21yHvnGkgjBspQ3bWYIS/rFPqnDYgCdSHR6mVMqLEqnWvCAE99DhI92HInZIg4nqoy4hZNhFBmSGo8usordXrpxbj8HyEfCkArsbYLPW6rPxG3XujHjHdigKhFSO8radI+LKvzZwdXAhp/+fHcsbTdEIEso= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-40efcb37373so8959155e9.2 for ; Tue, 30 Jan 2024 04:11:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616660; x=1707221460; 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=AyRNf4lSAfxyQsH5fPehileaxW/ucbVOZ214gA+esq0=; b=eHpMOlg571fwo8pzkUnhAOGQbPY2hTc/EU9RYf+vNfA13gz4MTH0GI+xZAFCdUwlUu +Aq1IuTgt64jxl+5z8YKF5vBccxSOiz5Na4mxCJ5XJtx/dgdFmHGre0DIywFXYRxDU62 Zfk6CokIHSFPwpNpHpcvOD8A7657dOBJLvRB0Mhn2JIh4qvGLHvUhqQLmzwRW2Yv9Sqm osWFXoEC373Ze8k6DORskGGve7sJ76UVioDBvGf8YY1jyAI+Xd9BnqwtpCFyf4wJA//D NgjThtuKGm4A0aB8DUG/i8FKdxDCKTyRohAg6IxE5zNnOTsES4CNpBULQn983eYg+spj W4Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616660; x=1707221460; 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=AyRNf4lSAfxyQsH5fPehileaxW/ucbVOZ214gA+esq0=; b=i4xEkAGC7EnFzQx7usITvQNY3zy0iLSWMV6Nf2KoBmdxHZCvu5fLR2mh8MriVOVAwQ SXzM00wOGsP23R6PaVb4+3sQFC7AjxJHt1azmAcmqcFgTaAgUYhTpJV7NFxhpNW2IfUq y15kXW9z4RyPNGNQaFCTYF/ulBD6T3i3dbX9ZO7g7BpiD0CKAgt1erjudlUbb/eYWm2x a8ZdMlaLezJi/fryB18eobYdksZEedMNAP/+DbEZg7nNX0hTWloUow/t3KqHhVWkucpO R/n7Tvc4ErLz/+CUKLI4lzoUUD2rh5G3J6dgQugkmRFuPQahq6G4nT6828GIa5b2ubtg dxxA== X-Gm-Message-State: AOJu0Yy0QW/iQjA0UBDQ12VEdnlTaOIakhqtqSFsQKqW8VMra2tF+YhB IPeQvVgsPTd3MYJXNhsCakvtRN8mvpMKaoiVoPaN5c5F7mzvct0u0ItGqxErz7L8UQ6ZVjBfzFB j8Q== X-Google-Smtp-Source: AGHT+IHgjY4kwudvcHMzp0oIXqRsuDDAwYQpdU4k8t44G8AtvAJUFhXO6PsH0BNWrLYbsom18kyJYA== X-Received: by 2002:adf:ae4a:0:b0:337:bf75:7703 with SMTP id u10-20020adfae4a000000b00337bf757703mr5808724wrd.58.1706616660693; Tue, 30 Jan 2024 04:11:00 -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.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:00 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 014/101] gccrs: resolve: Format if properly Date: Tue, 30 Jan 2024 13:06:30 +0100 Message-ID: <20240130121026.807464-17-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-ast-resolve-path.cc (ResolvePath::resolve_path): Format. --- gcc/rust/resolve/rust-ast-resolve-path.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gcc/rust/resolve/rust-ast-resolve-path.cc b/gcc/rust/resolve/rust-ast-resolve-path.cc index 9e982d0610e..56c352e13ea 100644 --- a/gcc/rust/resolve/rust-ast-resolve-path.cc +++ b/gcc/rust/resolve/rust-ast-resolve-path.cc @@ -368,9 +368,7 @@ ResolvePath::resolve_path (AST::SimplePath *expr) // is_final_segment ? "true" : "false"); if (resolved_node_id == UNKNOWN_NODEID && !is_first_segment && is_final_segment && segment.is_lower_self_seg ()) - { - resolved_node_id = previous_resolved_node_id; - } + resolved_node_id = previous_resolved_node_id; // final check if (resolved_node_id == UNKNOWN_NODEID) From patchwork Tue Jan 30 12:06:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892824 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=HqNzRkhl; 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 4TPPQm2bHcz23dQ for ; Tue, 30 Jan 2024 23:21:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5157F385DC22 for ; Tue, 30 Jan 2024 12:21:02 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id F0C58385802A for ; Tue, 30 Jan 2024 12:11:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F0C58385802A 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 F0C58385802A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::430 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616666; cv=none; b=U5C10GPGTkxIUU+gDyCfXK1Y6eiREHsCn+BG+gVx5/KusA7u7/0Zp4qmqs5XLJQ1uhsqmP8QM5YiEsZtHAM90F+YPVFljBls0nLx4D866JpcuP7xWJmIeXCbIj8ePWQmkFfvZjzyKtsH8mdyQRwJrUdJwRdPUsTYY0Hyo2kSEog= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616666; c=relaxed/simple; bh=me4JcO/D5ImQxGOueIzkqBcoqDvg5Fg0XWlCTy8PRtE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TZ7RLZ1SHX4ZO3bF01KJJqw4Giw4qd0e+uSSa72On07j7OMqbsexB3tOx4ndzMf2EugEM0sxd7ArYeQEM4UkhX/okmPiIAmi64dWiwIApeJoyrG9oKAlsAMKRqOII75Ug2GchEupo8kzUa+/xPek4H3dw7OQEHS224VzCfXeuN8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-33ae6dfa923so1618399f8f.1 for ; Tue, 30 Jan 2024 04:11:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616661; x=1707221461; 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=hSpbfn2uEnZS7rmnMnKyTYVddFHdl0Vs5fwoZ+MDDvE=; b=HqNzRkhl8acJsMno4+ezMeMMk6yEDmnog5T+Ls53Y1Ks1uvQwKQkU9OvNBsp1hUudo PBdfTSizPcVwMR644ge7ZqnKeCceVrhzdWjkFtUAucPXBCGz95Q377+I7mO1iecfhu1W c9ebSMA/zKQzvMdapf/ElYJbJtMw3LM0lb6g+y6wT5HZeyGlRqt2CUz0d+fo+WNFWpgi q/5ytsSdQvrq0MYHdlS0VBKADcc2WmXaYpNOFuvM1LfCLZiwOn8roas9J/ccYtwtXvyY qT+1suJEsnvbB6m+YRcU7NLOoAFqd3agHgnjzSu6fkG12iuKaYyk3bN+8b30m6yxDuJk oHyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616661; x=1707221461; 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=hSpbfn2uEnZS7rmnMnKyTYVddFHdl0Vs5fwoZ+MDDvE=; b=tfRZPRbKmNR13DCpb9uUYVi1pusg2ZSZ/ZbDvRpYiUc7obP7sepDdkl0IUH1bM+mC1 RFrRj3huQsuDXWtA9Y8j99jXI7hnn6xP4JtazSyyp61qepUlTWgN5n2IN529+qlB6MFX 6RaQSf2O0dMQKF/2tZkhfEwdrg94MvWdwKTng1iLWqz4fw0kTW5eyJuJHOacV4pJBb9s mszMSQFGEHloPqZOfAyEA5/+lNADUJrgFq/uzklYtVRKfQJED7C2MVi4wB2dx4tgUGr0 DSIOsO6wAWb1fqH/btaE0wXOFr7jfC5dEfgA8F5K1j6Z/RvfIpg7fWNUglRPjqPohF45 1BOw== X-Gm-Message-State: AOJu0YxiQwRq8DNHKzBCq1V7isJWvAMSOHpFLqFNfVLJaQWzlBXCK3JZ 9+zI3FZrmh+H+MtOLEQW/E+UCdNjwaP91QbbioHJZLEho6ROwy7C67FmUhTg1LhX7rU9cMYdXBq UhQ== X-Google-Smtp-Source: AGHT+IEcofXq9IDRKSRPMwN54GdOtigeqa6UFJTzafuDL1hHJib+fhR2UxqPXB+HA3XZlmGYn4EUqA== X-Received: by 2002:a5d:6d05:0:b0:33a:f642:7a21 with SMTP id e5-20020a5d6d05000000b0033af6427a21mr2597831wrq.42.1706616661515; Tue, 30 Jan 2024 04:11:01 -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.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:00 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 015/101] gccrs: forever stack: Remove development debug info Date: Tue, 30 Jan 2024 13:06:31 +0100 Message-ID: <20240130121026.807464-18-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-forever-stack.hxx: Remove debug log. --- gcc/rust/resolve/rust-forever-stack.hxx | 2 -- 1 file changed, 2 deletions(-) diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx index 65796172b08..867144adf92 100644 --- a/gcc/rust/resolve/rust-forever-stack.hxx +++ b/gcc/rust/resolve/rust-forever-stack.hxx @@ -523,8 +523,6 @@ ForeverStack::to_canonical_path (NodeId id) // Finally, append the name path = path.append (Resolver::CanonicalPath::new_seg (id, name)); - rust_debug ("[ARTHUR] found path: %s. Size: %lu", path.get ().c_str (), - segments.size ()); return path; }); From patchwork Tue Jan 30 12:06:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892846 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=Qp4hDwi2; 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 4TPPbL5YkSz23gZ for ; Tue, 30 Jan 2024 23:28:29 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 636C43865C30 for ; Tue, 30 Jan 2024 12:28:27 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id A454F385800C for ; Tue, 30 Jan 2024 12:11:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A454F385800C 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 A454F385800C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::434 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616672; cv=none; b=X7QgVlBAmkEuEAd1mH0ICeG5e6uktNv+Vh9VA32c+bZMun9/clmdEHoOaKQ7Ro8CaJxox6IuJZXfU7CzujQ2W819gPF+sEpAOiKi1/6ILvDDuvi0aGVxQlt93dgkF0MkZzL2woP6Ro7JCWNjZ3YDGL1Ug/2ML2N70QGXGsRZ464= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616672; c=relaxed/simple; bh=f/eweAY8QY1x3Z3GLRKbV18bHJaX+5nlabgR0C4BgMY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ivxZ+xiQcQScCSCNQIzgfzigPZ3fo5mmwARHoQdteDbQHJVaDBXOMrWZTezOAZnza00VP4WcLvYBVFJJJMODxSmhY05dHQqfBlL3wqn8gAAZJapBqRwDi5tq5cLQHqVYjkbf2tI3qiOQqoJtUupefTX++lSa2iBcVPRnSRXHFa4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-33af3c7ef60so1151870f8f.0 for ; Tue, 30 Jan 2024 04:11:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616662; x=1707221462; 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=JlNvBoB9Z/n9/WwzWrOvY19COsZ5wSmxkFc1drcPtbI=; b=Qp4hDwi2+vMXlO3SoA1oe/Bg4kxczq27a/qkFOi3c8M+QaChfvyIN5TjRWM87uWRWj 18RYG8Rr91hkDLEOKMMs77r0LIq2QQHLFIj5hoxm/XI8Mi/EYSTLzzc0tk8IvHKhQfj8 yKg6JTT6pM890vaIzctLxquDVnZROmSlU+OM2j69oV+/1j0YAdnyWMvsWJRImCgYP9ZH q5yj6j/M2rmVySKh1gP0YevSI9PexTJRsWikWc9zxXxF4UIpY/obv1la75H7jOBvw8R4 r/BcQyXpgiA8mrvwazVviQrdGVe39S4nWrB5G+vUgzcz/1xzjxawHbSzyYqIm91vB+9Q n6lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616662; x=1707221462; 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=JlNvBoB9Z/n9/WwzWrOvY19COsZ5wSmxkFc1drcPtbI=; b=IE775Qu3Zmaei49DrpA7U1jeTT2bR/doZAXp3zFePi+BpWduWZJhQ5UKbtX1663rdi pQC78tEnBcZb+aGUyIOltyqDvEgOOPC1gAc1m+kJQefQ1rh/11JosPJxU7kI+seXSGQb rMOQil4bd3sKGSpVgzOkHeHtMxQiSXOldofxlUhKplJ5rAxAJfxMyP+OHtAF8L36AMTb 8P9XVk973uBF6HusEcbd/etzQ+rSh7Y5LgeEYwDmnZS3usxMYSMXLU/bQ9lMcYSjxcux spyV1I5hAckHYCsvgNg0fAlf9SCQn/R63/dZot7VLjN+nf0HaS0iVpP4MuPp1wTdJpTL 0QIg== X-Gm-Message-State: AOJu0YwnXoQfppxH0VNXFoeQw/pjqSdWKRTulvEvhlqlfYiXcZacZKTX VIik7r6K4rgqK51oisHB86OYlZBHi51nhl52tJcxkCfqnjpJCdXFjoMM3PPKlFKaZFNsO0m5aaz N7Q== X-Google-Smtp-Source: AGHT+IEcXzTYN7pPWaq5wYi1UWW+c/03xL8y1To/x1B3bG2a8T91Bg17eAItBvEWfNWr7vrpdxIOQQ== X-Received: by 2002:a5d:51ca:0:b0:33a:ee39:5b4a with SMTP id n10-20020a5d51ca000000b0033aee395b4amr4103305wrv.36.1706616662181; Tue, 30 Jan 2024 04:11:02 -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.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:01 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 016/101] gccrs: Reject auto traits with generic parameters Date: Tue, 30 Jan 2024 13:06:32 +0100 Message-ID: <20240130121026.807464-19-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: Pierre-Emmanuel Patry Generic parameters are not allowed on auto traits, the compiler should emit an error. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add check for generics on auto traits. * checks/errors/rust-ast-validation.h: Add visit function prototype. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/checks/errors/rust-ast-validation.cc | 14 ++++++++++++++ gcc/rust/checks/errors/rust-ast-validation.h | 1 + 2 files changed, 15 insertions(+) diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index f6ce45eacca..37d3668a9e0 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -96,4 +96,18 @@ ASTValidation::visit (AST::Function &function) AST::ContextualASTVisitor::visit (function); } +void +ASTValidation::visit (AST::Trait &trait) +{ + if (trait.is_auto ()) + { + if (trait.has_generics ()) + rust_error_at (trait.get_generic_params ()[0]->get_locus (), + ErrorCode::E0567, + "auto traits cannot have generic parameters"); + } + + AST::ContextualASTVisitor::visit (trait); +} + } // namespace Rust diff --git a/gcc/rust/checks/errors/rust-ast-validation.h b/gcc/rust/checks/errors/rust-ast-validation.h index 44995eb1fbc..49133ee0c3d 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.h +++ b/gcc/rust/checks/errors/rust-ast-validation.h @@ -38,6 +38,7 @@ public: virtual void visit (AST::LoopLabel &label); virtual void visit (AST::ExternalFunctionItem &item); virtual void visit (AST::Function &function); + virtual void visit (AST::Trait &trait); }; } // namespace Rust From patchwork Tue Jan 30 12:06:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892829 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=MhxsDfP4; 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 4TPPVJ4ghzz23dQ for ; Tue, 30 Jan 2024 23:24:08 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 881423857B8E for ; Tue, 30 Jan 2024 12:24:06 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by sourceware.org (Postfix) with ESMTPS id 8DEB3385802F for ; Tue, 30 Jan 2024 12:11:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8DEB3385802F 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 8DEB3385802F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::22a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616672; cv=none; b=xf9BfrSpqSUjGgQwoGtaZBBIffMDASTQiGD1kMTBFv9AkI6embMxQTEqulZMoLTXjrbhoUu5lxdg2J9MuxJWMU2BoQ2mrf+Xo9PFTY6TDqrl3z64MlHMLmH2c/6DBi6PfzHNe+KtmoV0+rbHGtFOkZmsk/s697F3Z8lOwXJevF4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616672; c=relaxed/simple; bh=x5RAaYviGvsFqL6Evkz2XXpiWAtOMZiYIYN/6kvyr18=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=V6e2OnOpuTyioSgOOCAVNF/zRF1vXXq4R7L0cShSWJg5z0VkY2gba1BKP/rDWTq61KEbsFsNneNMqGr7IJxBzt00iuFAq+cDSgGtMSFNeCqRJjkX9Y8xDGN6ibVLzHmRSoPRIWWW4zxRriMHCOYb8oTrNIVsIaDKe1/ivUUroLM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2cf328885b4so44812361fa.3 for ; Tue, 30 Jan 2024 04:11:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616663; x=1707221463; 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=dJcjaOZ0PLvd59Ruz3QS999PV0mU8bJ5Yq/VU+P6Z5Q=; b=MhxsDfP4kqMengPYR3zcthlAVFhLWgcN6B7t44MHohOJNgsiJrNsIbSAZkRYkwJLBM WbjS1vhS9mh75DrJYCGns3YI+v2kEuIkjNKDfJDGx/g5h9+dNlY78uF3bM32VAlVvYIx pYr/gE3fl/siTUA95ytdUcEVLrS3Kzd5TWW/9OBfV7fq1JBYX6LjH2bnwT9YhZDLmdo7 P4eGfrVTmGWxM5uZ/gZ2oBZRh8W+SEFnZ6d7ce4H2VUrowe1CYvakNSpUBEJg0g5BcJZ l0feQpW1XazHyaxmV8Gc4vQW8q+3ZJ4W8czSnoLm9S7/0G/+j1JaoURMkQupy24259UF 8GLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616663; x=1707221463; 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=dJcjaOZ0PLvd59Ruz3QS999PV0mU8bJ5Yq/VU+P6Z5Q=; b=JaAbAA4QhsUXM7wQe6a/OvPL93VPac+e/+wiA7leRDRjcTLDeDGBbdBl8P7nmrBYds msQ8Qv4GHLgnqRE4PkChZ797IT1Fv3kTGbzKj98m5dSxMGRG5886uzMhr3n06s/czEZv iWPzEJSa3EYsSHmXKn/CG/Cy87YRetm0uYPnm9i7jYUzt92kQnZlPUQe4TGX9/OguygT KqARbOBJKrMPUIObaqR5v6/6vLuZsBlesuEuj5pX5wKmUtEm9UUyc5X+UmqW2o8ZY5+u PI+is6WHTtj7ryAkqjyU+QyVpdXBEBQ0KYvt/8xyCfrbYS6iv7jNrmAG+zyqUXsymJRU MM2Q== X-Gm-Message-State: AOJu0Yz1Ln+f6XZ1MO4ec3SmAvUU7vy3434C3vpRP51Sik+vUYgkQl4d zFOpDOHBkg8QpjsgRexC4z/x6ONNAByydj0pWITs4zP/fRCxseU/2+qgoDb68Gy6VQL791CtMTs G2g== X-Google-Smtp-Source: AGHT+IHTAB852lXo1SJxUBXa8OeReAIbgM2KDJjVaXtSPUheOppWBEtFisD6t3Yf35p+7B70I6/cZw== X-Received: by 2002:a2e:2ac6:0:b0:2cf:3f81:1526 with SMTP id q189-20020a2e2ac6000000b002cf3f811526mr5467112ljq.47.1706616662851; Tue, 30 Jan 2024 04:11:02 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:02 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 017/101] gccrs: Add regression test for generic auto traits Date: Tue, 30 Jan 2024 13:06:33 +0100 Message-ID: <20240130121026.807464-20-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: Pierre-Emmanuel Patry Generics are forbidden on auto traits and an error should be emitted. This commit highlight this behavior. gcc/testsuite/ChangeLog: * rust/compile/generic_auto_trait.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- gcc/testsuite/rust/compile/generic_auto_trait.rs | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 gcc/testsuite/rust/compile/generic_auto_trait.rs diff --git a/gcc/testsuite/rust/compile/generic_auto_trait.rs b/gcc/testsuite/rust/compile/generic_auto_trait.rs new file mode 100644 index 00000000000..ae6a51d0244 --- /dev/null +++ b/gcc/testsuite/rust/compile/generic_auto_trait.rs @@ -0,0 +1,2 @@ +auto trait IsCooler {} +// { dg-error "auto traits cannot have generic parameters .E0567." "" { target *-*-* } .-1 } From patchwork Tue Jan 30 12:06:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892828 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=Vst070OB; 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 4TPPTv3K7vz23dQ for ; Tue, 30 Jan 2024 23:23:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7149E385770A for ; Tue, 30 Jan 2024 12:23:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by sourceware.org (Postfix) with ESMTPS id E43FC3858032 for ; Tue, 30 Jan 2024 12:11:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E43FC3858032 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 E43FC3858032 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::22b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616673; cv=none; b=DUynydaWF3Z4GELIxtkalrKL9S9RZhIOH7j3TaLzczI6WPnUMXtyIOr1dIuSEVfPjq9aeJxcnmb5y7SYMs5zzxY1l3I4JdSESGNSGJeRVz/XHwT6Vw479k/41tl8N2lurkR7Gz0XSfxGuHBLFUG2uk28jcaXj4SbKBs9EyL0ni0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616673; c=relaxed/simple; bh=E+itCyfrJ1Gc9H5x44DyCta3QxZL/q9Nzdn27TOE1Pw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=E7pYMoeB/iBYgqsgLTQcJFBxFh6KcKOojD6I6iPx3pP16Z5AooVG9MNFY6D9gzC6Qwk3pV9edAARFVz+lDJ88XSX5yRiqrcOH5CPA28DL5jO+QFY8HjF2pTR1Z+HOsQ+iTLXSzBG/nBe3kDQV8wbjH9HkLvtUJPZl//83XeY520= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2d05b06b5f9so6689311fa.3 for ; Tue, 30 Jan 2024 04:11:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616663; x=1707221463; 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=1eg/fqxpXzJ3ahmRGZMh8cWitAYvnGbTkXIvIM8cFsE=; b=Vst070OBoCrpofND+92XktMJ18121hjDjnhxIklNJRGOMlqfR+wV90NyR//C6ddhDx c3bYi5fP24+bmUl9m4FUPF+10viEk6MhyV254wou4CMRVZj+bNK1qfzgfoob2oKxIsWq 5HRO/LRBe7dGPowCCmYIlmjEcUxMJA03YdO/VL6HqRaMXblWXIMIFaNjGr57BrYUDfYd 6rK5DNJVP/o04lMq55OjipeUlRWfinw61rwnhc5MHRRZ+CopGUqJGxe8EJbksdaOxJKq h7zwn6QJPGYdDLqUpg9Hln989GkEtN3Qw9cJXydw4/Ih+TgJsHPiMhE4R4N86MIvrbVn 6Jsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616663; x=1707221463; 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=1eg/fqxpXzJ3ahmRGZMh8cWitAYvnGbTkXIvIM8cFsE=; b=Clrn92qnaYq9aCItMcNToAPo3jB2wQUWlVMtOI7NrMH++2gyeyNAorWc7V6T5/mKzg oMu3vROxNs6Uym8OI21nLnO7Szpe+j8d8/6qDHfRdpgQrYofFRLIZZLraArQMOITMtq1 1+f7Wna8N7CuDox+JydeDl61fLEmfrkCTuNbiemJQHgK5ldYBYdEe2YVaSGbpUvQwiQB aTlC0bFOHDuhvEBaRuhDZ2uUy0dQkzcv9olgnwZLmSD7kB9EH5TFVuVwVoAgv08znykl rXQCnAB7ysS0NCjBiDeNQf4a4vHDqyH3NuPlMyq6hvu9vHX7C3BG/dG6/DPt2tA1QAYN eFWA== X-Gm-Message-State: AOJu0Yyjb+wRZTBLgdlAwkLxK812b8xRgbnoV1ONRzGMYPoVnGADwc3l anlgS8ctFOaQ+0WbKfK8Y5KiYCVHy3DRUvZ9X5srePRk64Bogh+lMro5tpU05Bv1gLOQBNLYNDu lfg== X-Google-Smtp-Source: AGHT+IG3rJ0sujlsBhSr0oH/SVPfPCX5AXCslIRWB2knGkC0YI5UT2q0fQD4zOXQI3ZJZFNI9s9sXg== X-Received: by 2002:a05:651c:1c9:b0:2d0:5985:1580 with SMTP id d9-20020a05651c01c900b002d059851580mr1426357ljn.6.1706616663253; Tue, 30 Jan 2024 04:11:03 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:03 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 018/101] gccrs: Reject auto traits with super trait Date: Tue, 30 Jan 2024 13:06:34 +0100 Message-ID: <20240130121026.807464-21-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: Pierre-Emmanuel Patry Reject auto traits containing a super trait bound during AST validation pass. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Reject auto traits with super traits. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/checks/errors/rust-ast-validation.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index 37d3668a9e0..aeae6035db8 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -105,6 +105,10 @@ ASTValidation::visit (AST::Trait &trait) rust_error_at (trait.get_generic_params ()[0]->get_locus (), ErrorCode::E0567, "auto traits cannot have generic parameters"); + if (trait.has_type_param_bounds ()) + rust_error_at (trait.get_type_param_bounds ()[0]->get_locus (), + ErrorCode::E0568, + "auto traits cannot have super traits"); } AST::ContextualASTVisitor::visit (trait); From patchwork Tue Jan 30 12:06:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892851 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=TyVVqs9X; 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 4TPPcq53wbz23gc for ; Tue, 30 Jan 2024 23:29:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A78DE386C597 for ; Tue, 30 Jan 2024 12:29:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 3C2053858011 for ; Tue, 30 Jan 2024 12:11:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3C2053858011 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 3C2053858011 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::331 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616673; cv=none; b=IbirB2gLtyJMW8jLdmr/rhd3AlqmksCbTfHyhqbRfAd1es28S5NbQ5ZUsew7SBffnuhNj6sSkpO6TWhNvVcaKlE6Y5Z9uxTaX8Ulbmc3CjwHMqVVBHpm6VeU1Jm7j6v/loYDhFObWMucmqnsKSzBQQ2EpSgJOE6s38ca2pRG6gw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616673; c=relaxed/simple; bh=kXMRablxmdhB/Uw+4C9wA5nkkVvmwJYn/ZjxA1dOxa8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nL8IHSSfvDyYCzHKv4ve1FYflSVjaO1nJhgPglqdEAjLixOjxJMqXsKpoHld/98rkVTFwykYxPEaBP7Wy86bvOeaLziHzB/tbFr+PrnlUGK1RJNUnAkwvFQGikM/3dAKOyys0kXS4FnHeKCQHeHHtPI8JEuGCUX70w+I3jaEJ1U= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-40f033c2e30so4226615e9.0 for ; Tue, 30 Jan 2024 04:11:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616664; x=1707221464; 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=5WIG602jF0/NcdS+HfCAx3v6LginBYLqhITxXSERSas=; b=TyVVqs9Xik1/9DqPhahGBCRVEfdPM3Vk73BaWj700an3iOSK9QYGkO2JmYuAh+zgLx GqBTj3wNWQppStCINRsTCzXtBfFtdwklBCexPuJZxavwM0c2iy7m7uKEy52evHkk+mWm +0jCdFIg5joKaU8LoykuyCGEI/zmcmao+/tv3gkNv8ScEMxN4iYY+jsHtj2ru/BfrUpI 1YAbu61NRYr0yoWABYhjQCgBBECCW43uaQf8aBRNE3BhtYaNPga16ZMVq1pgvRpXkTPH +cvu9gl0mXVmTw1iQZcMpbV9YIl0IRs/8uFIlhOpiWXUDmzEt//eD17ndiIe2pEeit43 wGrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616664; x=1707221464; 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=5WIG602jF0/NcdS+HfCAx3v6LginBYLqhITxXSERSas=; b=RCyx7Pf5KeN6CP6LZxvrVXEpZHJjrJnJuU+MElrm6HDkY+dD5FI0kxJZbChP2ZsDKg EdhAzeUGb0Q5/XcdqIv3hV1DL2tH36XmUiRUCDyljL5R8eLM9BdO3q628lyEfh8MWnbN tENrlngbNuWUhi0XQXF5205/hMhXjpIwFojXhqZmIZdgyo55qPXuIklyIShwqHbcYYpo 9uXKWSBAj+d9qFudp9BGgWc4Fed2Nku7oI69En283wg3GdNZlQaI4zoMgopKVBaXj01A t8Y2sumH0qC0lzCQ8JIXBYIYyH8GNEqMlIFEAIkBu1DR4duN95I8eC5h6/bHQG1/OOJj eJ3w== X-Gm-Message-State: AOJu0Yy2mHjsF2O4sexkWhl1aTo2t0Tfp4gW03eBnqqIzqNlbJy43fQ1 btpt4rURmb4mpSZmdHc0Rciu5tRn7B7YoHrB4UCsLAeAl1E+9oq19RJUIaJ/S6+F6N1tXJDf3aN ulw== X-Google-Smtp-Source: AGHT+IF4MGzquryoEQoTJPY0XdUURQEZb7yC5re81/QD8WawyBNhHzmLXEyhNHWNhRjhWKFTrDrcdw== X-Received: by 2002:adf:ca84:0:b0:337:c4b3:e03e with SMTP id r4-20020adfca84000000b00337c4b3e03emr5592044wrh.1.1706616663878; Tue, 30 Jan 2024 04:11:03 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:03 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 019/101] gccrs: Add a regression test for super trait on auto trait Date: Tue, 30 Jan 2024 13:06:35 +0100 Message-ID: <20240130121026.807464-22-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: Pierre-Emmanuel Patry Add a new regression test to highlight the error behavior with a super trait on an auto trait. gcc/testsuite/ChangeLog: * rust/compile/auto_trait_super_trait.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- gcc/testsuite/rust/compile/auto_trait_super_trait.rs | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 gcc/testsuite/rust/compile/auto_trait_super_trait.rs diff --git a/gcc/testsuite/rust/compile/auto_trait_super_trait.rs b/gcc/testsuite/rust/compile/auto_trait_super_trait.rs new file mode 100644 index 00000000000..1080afb5124 --- /dev/null +++ b/gcc/testsuite/rust/compile/auto_trait_super_trait.rs @@ -0,0 +1,4 @@ +trait Cold {} + +auto trait IsCool: Cold {} +// { dg-error "auto traits cannot have super traits .E0568." "" { target *-*-* } .-1 } From patchwork Tue Jan 30 12:06:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892825 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=ZQGpRKhF; 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 4TPPSh2Vxcz23dQ for ; Tue, 30 Jan 2024 23:22:44 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DC834385802A for ; Tue, 30 Jan 2024 12:22:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 1FA843858025 for ; Tue, 30 Jan 2024 12:11:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1FA843858025 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 1FA843858025 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616677; cv=none; b=wzmSLQ5FoiMps2+PzTUnY3iEK3jpCZ1K92q3+Iq3vB/tmnE7VILbKaJJGT8QhoLCvbHIsf01Vmb5FK54n1KjJoKo9M4TNEoVbAKDXRVrM0TwxuwFBKR08AE0yhOjv6PC7tuRBRayzKNcc764llZKCK/9bHIzOBxHajk+ERWHrck= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616677; c=relaxed/simple; bh=qySKkAy2xXtzOvTSeqNMvV8Q6r96ejExksDQ5XUJIUk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=mdIELmDFnBc3JWKK2lE7cMRE2qK/fNNnyZY0Eo22LtayCTgawMNnsoQ1WmHleVxB/KccLSpFxg9c8sFacpwAZBadiBHCgTSBCU1IAHzpg7bTqmOfKWeJ4vbk0+pAXS934cakO63yEdG4vmawoeNANaos+wkTNu/97P8alnDJLhs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-337d05b8942so3297309f8f.3 for ; Tue, 30 Jan 2024 04:11:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616664; x=1707221464; 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=hoWOQVO7lwBw2MZmFyW3YYka2iOC8wpdlZetPxAgbjo=; b=ZQGpRKhFE+EzbxZuX+F/eXU6x8CelDoE9cVXr0gVb08xbQaAsMmtU+PjLPZ/zU8ZE4 BiZh6SQ00o0t18c9GxtgUqdxrQR31qAP154l06HHRMUl36khGG/kk05iSRNAqucreTL7 DuQ9fGza1szIgH6nOwQgXyFRwEV5GYK8atsDZUg4DGRvWLvuqmU+YoiH4UcNfsukSFtw CaByUG7bIeanmfbZw2JQJs0ofKTpU9GvdGu3ALpCEYS9FWHNf+jpDd2fQpxtcHWgZnWh tYkb0X+2vyO10LfTG9iOd7zJL70qT5O4Kx9EtiWNLUG783qVpsS2caIplABI80GuEP+H C5mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616664; x=1707221464; 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=hoWOQVO7lwBw2MZmFyW3YYka2iOC8wpdlZetPxAgbjo=; b=Vp/jvY+SdmSbpCa2EUiopaY5U2hIuS8ub6u4YPKr7D4myRa32BgzbJjHyqIPwcEZcH TD3Qsc9VljeLk+zr+G4RTaCm0oKRd5TITUAe26yG5MvOupTeoAxNd840+7XcLhVc+vt+ ZBGPjI6aDaCNblJ/BLgmJLLw+4uuexMwF1wWwz2iPmXzW23KSbCvgIXDveNHGWON2fAo kGzeWu2jpT8MHQGdmghyIt9lUZpfv0Bq6QWEzusH1/SVIACpFfei4gYPgkFTKfXWxA9X t80RxSfqn4op7PCVBFx/ADhU2DhlS9zwcb4APObYrMJ+KsV9e42OeMqpIDIUg5eMASTt 6d3w== X-Gm-Message-State: AOJu0Yzoz2FmsAObTPbLUjbbs9fTUA5bnmw5ORixtvBrvZnHiIoctK0l 183LZEOZlrDGLxk/+JOjinsOEPWBwP2tzivJipqyGjfJex3emGPdyc2uun1/uqnwZ9BtSt0wWPE vMw== X-Google-Smtp-Source: AGHT+IHwrg/5h9iUs6DUNiWnEvAY1S2BPO9CnQFxRQlkxRjfZzoiyPEP0vdFyY37VQCwHkMSN5ZjSw== X-Received: by 2002:a5d:5982:0:b0:33a:f51c:8a8a with SMTP id n2-20020a5d5982000000b0033af51c8a8amr3303416wri.45.1706616664742; Tue, 30 Jan 2024 04:11:04 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:04 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 020/101] gccrs: Add check for associated items on auto traits Date: Tue, 30 Jan 2024 13:06:36 +0100 Message-ID: <20240130121026.807464-23-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: Pierre-Emmanuel Patry Reject rust code with associated items on auto traits. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add auto trait associated item check in AST validation pass. * parse/rust-parse-impl.h: Remove old error emission done during parsing pass. gcc/testsuite/ChangeLog: * rust/compile/auto_trait_invalid.rs: Update old test with updated error message. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/checks/errors/rust-ast-validation.cc | 7 +++++++ gcc/rust/parse/rust-parse-impl.h | 12 ------------ gcc/testsuite/rust/compile/auto_trait_invalid.rs | 5 +++-- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index aeae6035db8..673290959f4 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -109,6 +109,13 @@ ASTValidation::visit (AST::Trait &trait) rust_error_at (trait.get_type_param_bounds ()[0]->get_locus (), ErrorCode::E0568, "auto traits cannot have super traits"); + if (trait.has_trait_items ()) + { + rust_error_at (trait.get_identifier ().get_locus (), ErrorCode::E0380, + "auto traits cannot have methods or associated items"); + for (const auto &item : trait.get_trait_items ()) + Error::Hint (item->get_locus (), "remove this item").emit (); + } } AST::ContextualASTVisitor::visit (trait); diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index de17412c3b6..45c72e495c2 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -4989,18 +4989,6 @@ Parser::parse_trait (AST::Visibility vis, return nullptr; } - if (is_auto_trait && !trait_items.empty ()) - { - add_error (Error (locus, ErrorCode::E0380, - "auto traits cannot have associated items")); - - // FIXME: unsure if this should be done at parsing time or not - for (const auto &item : trait_items) - add_error (Error::Hint (item->get_locus (), "remove this item")); - - return nullptr; - } - trait_items.shrink_to_fit (); return std::unique_ptr ( new AST::Trait (std::move (ident), is_unsafe, is_auto_trait, diff --git a/gcc/testsuite/rust/compile/auto_trait_invalid.rs b/gcc/testsuite/rust/compile/auto_trait_invalid.rs index 66e45531f5d..3be2acbb53b 100644 --- a/gcc/testsuite/rust/compile/auto_trait_invalid.rs +++ b/gcc/testsuite/rust/compile/auto_trait_invalid.rs @@ -2,7 +2,9 @@ #![feature(optin_builtin_traits)] -unsafe auto trait Invalid { // { dg-error "auto traits cannot have associated items" } +auto trait Invalid { + // { dg-error "auto traits cannot have methods or associated items" "" { target *-*-* } .-1 } + fn foo(); // { dg-message "remove this item" } fn bar() {} // { dg-message "remove this item" } @@ -13,4 +15,3 @@ unsafe auto trait Invalid { // { dg-error "auto traits cannot have associated it const BAR: i32 = 15; // { dg-message "remove this item" } } -// { dg-error "failed to parse item in crate" "" {target *-*-* } .+1 } From patchwork Tue Jan 30 12:06:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892834 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=eMyP1lHq; 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 4TPPWf714Nz23gc for ; Tue, 30 Jan 2024 23:25:18 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EBA413858036 for ; Tue, 30 Jan 2024 12:25:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 48F4D3857C40 for ; Tue, 30 Jan 2024 12:11:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 48F4D3857C40 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 48F4D3857C40 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616677; cv=none; b=G0o+ydwL+nylUP1quUKMhnvgaObKI9+uBYqU/cUf/4sXUPOY42wJQFEu57WXqT6toRDwEm+f336voD9qGiwolDt9XWgH2hC9y5JE56Gmr4+j/bPsx+73bWVk4BcZ2TqDXtJ1Lr8tekLjq1rGDo/VTIMdHWBk4WLhEY9pl59aSrw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616677; c=relaxed/simple; bh=dKj9erYfDS78OtSzz6OkyCZHrzuTBDcxAdvAdu9Xg7I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=qGvfvXjlx7JQyB/rvYDXQTy+UEbLF42+EpoOqcppuQ6EPwsJvsCCZwoGGRO/IOxkBZR0sJWIXPQB/fdaCsFYZ/gWRd2mHz6qtBCrwh8Z2uzQPb5QgcQoFiIHmsFxkXftkYhr8EIDY3ke657vRHkHWhFDZAm9v9aezAb8B5FPnjw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-33ae51f8111so1919712f8f.2 for ; Tue, 30 Jan 2024 04:11:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616665; x=1707221465; 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=pLxE6X+xtTCQJHOMy1mn8hdIvKvPXwYlNBK+63B9uVY=; b=eMyP1lHq/Xd7ysdVS1eiPwhSy63jDfMMIebG1fukXMF/pfb52p0bF6nW9qzB5PYGwz pc/DttUXnC1efQubPaWq2R+gFopzuUVGtrJEhYy1a94bm/OtyD5n9vgJiWudw7Xw3+Em ZE1vAFdHSm5uxWvKT07VPICoAB3Ts37bU6ddhw2eeCtRiPGbRhZxQGcZRjpgSjmtmZOL ynbSLra9eGgCb1IiKexpLZQPzM0hkpt/3GoXi0H+erhCtIPC0lF1BYdzZwkuEzFpIQ4A +fD3HEjEaJHpWbwA9AyVS9szBjWCqKL7MlK2r27U0MqW6Q193xVyMJ9MnYLiZp6WZio8 7IjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616665; x=1707221465; 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=pLxE6X+xtTCQJHOMy1mn8hdIvKvPXwYlNBK+63B9uVY=; b=Mj8deKRsJuysqlFITkso/XY6IdOQtIaSrVXHxWjIKyorevgcTud8zqyc89u5rpv5lp Xr+UUoDQwkoO5jx0lFhTG68hZjlf3qoF8ssVvHbsrCj+L2gv7/3JxDp6SMtuVQCZ8ZDv 9RollnAGyDV6HwB1Ja033/aBv1+YBf6dVPaFRRGrDFg7Jt8DuwF+LwSk8/9xihYmCgvi 2MCAlgpY+fETiKtbmGdrMHiJP/lMz3poaXmQr8raVwVmpOqkbW6t2IWq2iC0Y94GS6Vw WnH2XMN8vnShYr4+jvuDzSuivgk1bgvV6MwbhGM8TfC0F6v9pIQze/vj2WsIEtm/WP/v mV/g== X-Gm-Message-State: AOJu0YwnO6MG5yM3m2vxmLuWVBNzYSecFkyXVCJpJIDE9VsJcoM6zqEg Q7VhpcfhqKk8oAPG8EXpck1jbSnwZmt2ujcJEV8LyW8o4RXAPx1eutoTVDoR44SQRVkSZZkzOtJ EBA== X-Google-Smtp-Source: AGHT+IFYcRvQb/6+pWkctK0oNaHnF4ukhA6u7D3fUyGhZ88g3gDMIx9fCUtVYI7TwK760OC49Qx8nA== X-Received: by 2002:a05:6000:184b:b0:33a:fcf3:e502 with SMTP id c11-20020a056000184b00b0033afcf3e502mr949399wri.35.1706616665364; Tue, 30 Jan 2024 04:11:05 -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.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:04 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 021/101] gccrs: Emit an error on variadic non extern functions Date: Tue, 30 Jan 2024 13:06:37 +0100 Message-ID: <20240130121026.807464-24-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: Pierre-Emmanuel Patry Variadic regular functions were recently added in the parser as they should be rejected in the ast validation pass. This commit add the ast validation pass rejecting this kind of variadic arguments. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add ast validation pass to reject variadic arguments on regular functions. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/checks/errors/rust-ast-validation.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index 673290959f4..4142cc6317e 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -93,6 +93,11 @@ ASTValidation::visit (AST::Function &function) function.get_self_param ()->get_locus (), "% parameter is only allowed in associated functions"); + if (function.is_variadic ()) + rust_error_at ( + function.get_function_params ().back ()->get_locus (), + "only foreign or % functions may be C-variadic"); + AST::ContextualASTVisitor::visit (function); } From patchwork Tue Jan 30 12:06:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892823 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=gRvkTmPn; 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 4TPPQL6LJjz23dQ for ; Tue, 30 Jan 2024 23:20:42 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CE9903858010 for ; Tue, 30 Jan 2024 12:20:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id 8E0DA3857C42 for ; Tue, 30 Jan 2024 12:11:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8E0DA3857C42 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 8E0DA3857C42 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616678; cv=none; b=cTgF8+izJpDtgPeLmi2A7OwCYaXO8Sz/gZnzaa0rDIokQG8N0cLbeSj4zHgowJGcVa6qAon+H5K4VQvj/bpM46NP5RjkqPaUJaDLwLW+EVWV3QZ6+gju4k6p25SK/87T9g3dl0UsTQnSFd76lWPUIjESSi91rV8aDDHrss7Yr54= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616678; c=relaxed/simple; bh=OQQV4N/cpNjrh7EOYN15seiSY9fGWW1hE1l0dp5Sz+8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=EgrkoK7thKdJW5/VS6DhaGZBGlycRSlbdHPQp9Se9kDWKiYrFqCYQPa0aW0/rkcgZwuxw9YEJBn6Xvu8ydE3yqDYHyaxHVLxemt3aJRGxwmPJUtEFgIrogQDlMsFtmJkJa6fbMQFx7bcEYjPdpCmYpfmMfG4tbD/ZFHpJFrA5nY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40e72a567eeso56787905e9.0 for ; Tue, 30 Jan 2024 04:11:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616665; x=1707221465; 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=XkkwHu6Cy0ALhtrXjmLMxM1tFV9jr5qIVQo9Cag4UWo=; b=gRvkTmPn1FRlVTZxmBSZffiGxBkODx+/uXfhobZh2wYCRLEum2OkD76egxnCkr2o66 1GW9vbJvRgEGDKsn/pqPpYkNMq/mLf76DBoqLNVF22aqqFvSp4y9XBarDuca11zsLTgi 50l93UIDRN1IWbFEdSDG+b3v777T7ww6BvOenQgJ+gkZnvIuow5qj14bLJvHSs7fsne7 ZH8NlmBmeoM7BUBfvgQLUkVvCJoNq0pIHsEZS9VWt/rpr1eAYpnXAf1J1IAbO07eLIgR YcQnWJF2xSzkTCom1GcqdrlWu1fG3RkcJHKrq4z4qa2DAFDVMbphulpsy58Q4KABIrPK dF4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616665; x=1707221465; 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=XkkwHu6Cy0ALhtrXjmLMxM1tFV9jr5qIVQo9Cag4UWo=; b=pcQK3foaurzg5EFEr4HAvdqC9RnLBvVWFXTxj0r51hqDt3yansWbXCeX4aVHT+wW2W OZF9X2N9V1WqRoHbWF6fQG4TgPTBTdvoZ5zooJDfY8QrBSQ6W5b8x59s7MJGVKikysjG UpaScKZDto/bV0wgbsS2+BxWvL/hq9Dn+S+YRHvMkkBfCOTRoNazIc+Pv4lS73tBFlNX wO36zSU7kj0EW0mvwDp7VRIyHyVgx1OJzjpzqYpRiRDw+/nhnSBpOnAbMgs7HdcKOQ2X nsupiUn2rIRMdWDE1W3pa5aRixlCrjcYD69Lg1UCkGzDsg7Z2PtEoFEEzoScrmT3GcNb JzrQ== X-Gm-Message-State: AOJu0YzCPFluPErbome2+NarmLWfPxn65pMdPPIWkbxE+ttWsEoxyqcn saUr5SudG41cpEvNNDpdIopr+XueqvMVk/C4rL010pi1+ItAF8LeCEb0ON5s55Nbu7IEY0JnEB0 8Gg== X-Google-Smtp-Source: AGHT+IFEOpKei0RNSxyO3CSM1EUVW6LSLCbpqecYoRXpkOlScB70BYR8XQjA4fpiL3Iavpw635dkEQ== X-Received: by 2002:adf:d1cf:0:b0:33a:ed61:b043 with SMTP id b15-20020adfd1cf000000b0033aed61b043mr5053067wrd.44.1706616665722; Tue, 30 Jan 2024 04:11:05 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:05 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 022/101] gccrs: Add a test regular variadic functions errors Date: Tue, 30 Jan 2024 13:06:38 +0100 Message-ID: <20240130121026.807464-25-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: Pierre-Emmanuel Patry Add a new regression test for the error message in regular function variadic errors during ast validation pass. gcc/testsuite/ChangeLog: * rust/compile/non_foreign_variadic_function.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- gcc/testsuite/rust/compile/non_foreign_variadic_function.rs | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 gcc/testsuite/rust/compile/non_foreign_variadic_function.rs diff --git a/gcc/testsuite/rust/compile/non_foreign_variadic_function.rs b/gcc/testsuite/rust/compile/non_foreign_variadic_function.rs new file mode 100644 index 00000000000..2a4d3090a66 --- /dev/null +++ b/gcc/testsuite/rust/compile/non_foreign_variadic_function.rs @@ -0,0 +1,4 @@ +pub fn toto(a: i32, ...) {} +// { dg-error "only foreign or .unsafe extern .C.. functions may be C-variadic" "" { target *-*-* } .-1 } + +fn main() {} From patchwork Tue Jan 30 12:06:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892856 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=MgbZyPde; 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 4TPPf25c6pz23gc for ; Tue, 30 Jan 2024 23:30:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C68CD38708C9 for ; Tue, 30 Jan 2024 12:30:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 390DD385829C for ; Tue, 30 Jan 2024 12:11:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 390DD385829C 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 390DD385829C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616679; cv=none; b=MvTn/c3OrtW+JDa0du0Q5X1CPXxy0ZzLeQI8NchZVQqssANZnXbvKdGHF7alFJd0mpWYqY1iUDD7BMu8bNGEEdrdi1aHhhLubpg3fR1NliE7y94QgLu7T5CJL0KHlWSVYUy7gRS8voh+neT5mXtVt2VoaeYvFuh1FocXbFgG+GE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616679; c=relaxed/simple; bh=y3e4XIikNWXkKAiG0/1PCyG5rwolRGECA5F5D/FLtOk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=h12XgHYfvM7Fv8VFMhUWZIxjQ+akmotWdetwD0buj0aK0Jr/AUo6EyWrJIeDk7037DUo9VNlG9tUl/4o0kzMXDN57YljVEKIQZmDGMpjLm2GOvmPUb8iN1wTxQs/caiWP+utHCCs3ZLgsGzpTOWDtm0Qhs7SUXc5wVEhXNh6oDg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-33aef64f702so1046705f8f.3 for ; Tue, 30 Jan 2024 04:11:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616667; x=1707221467; 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=KD2ydI9/qQ7fWdczTLRyDZgI5EVQesffVkxsd6WWbig=; b=MgbZyPdeFc+YeAUkDGMNKFKwzlCOxrJj8kWfy1z26o1Uv7bcXXZuvIx6sbBK9CbzV4 D5zNBun6ikNkkNjeS47i+MgKwsPzcrIc1ygl2cU/fQWqqJxTqBfyLvs6RdnkrZMobmF1 mqHIXQ25KNlhxX1S9I2eKVRszYUYuyGCk9dwsOlSPvzEcxJpiv2Hc6S3MpSytDUsPt3+ I6xNnk0WdO6OmRyOZk8Co6vDTian/YLqKaoOlGzqqJFOgccRjTTFNAZb6UjsruYqlmZ5 LkZqsy1RAZrkYduF4kZupCDqoHffRwtCzqUMfhOvFODqztPSJmPG2stMnPSxXAGJnYG2 /0nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616667; x=1707221467; 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=KD2ydI9/qQ7fWdczTLRyDZgI5EVQesffVkxsd6WWbig=; b=PS9X8k0rXNYewhyO//PZrCWjRrXgWBoaM3GQU3IS4gzAEcA5EJzZa5Z/7fpOAp5zWn T/4en6rr0coX14kkqRE/SjrOKuKSCRQmdFVucqLyoXWo0PkR4l4IeOgiYyZHqdEWyVZ3 /6D3bZVwonFLQYxRZA4eJGu5DKuMsYa27yJuIJugnFfYopJtDScB9p7OBitJvW6f7bpZ fsnJ6007RWdH8uHO9sn7xMSKuOQXoHdBgI2yLUXzxkHfXLpZC8zyDjJdW3rhkRJS4X5v /12ZEs9EyiPga+vRoVoC3HhNk0hTHZBxxBe+ACCqR/bhRXMQdPgyVrIv45gqa8u+1xSG MWpg== X-Gm-Message-State: AOJu0YwscLDUZrPjZyGnYa303uA6FnjbV8RquvGgxB25RB2XdjuXnF4R g/VwjNajd7M+FAdZOhr8ax/Goc1t968lOoB3Em7xq40tZub/+L/ote4yOXo3eUCgD0o0vyCazDc NvA== X-Google-Smtp-Source: AGHT+IH46zffB6tDeM4FmMV7q0LC/jsac13l6oXNjNqVHOYGrT8S7kRNY42+/h/du+DZx7/8AY1T6g== X-Received: by 2002:a05:6000:1972:b0:337:b315:5643 with SMTP id da18-20020a056000197200b00337b3155643mr5887025wrb.6.1706616666775; Tue, 30 Jan 2024 04:11:06 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:05 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 023/101] gccrs: Add ast validation check on union variant number Date: Tue, 30 Jan 2024 13:06:39 +0100 Message-ID: <20240130121026.807464-26-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: Pierre-Emmanuel Patry Unions with zero fields are forbidden. Add regression test for empty unions. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add zero field check during ast validation pass. * checks/errors/rust-ast-validation.h: Add union visit function prototype. gcc/testsuite/ChangeLog: * rust/compile/const_generics_8.rs: Fill the union with dummy values. * rust/compile/empty_union.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/checks/errors/rust-ast-validation.cc | 10 ++++++++++ gcc/rust/checks/errors/rust-ast-validation.h | 2 ++ gcc/testsuite/rust/compile/const_generics_8.rs | 7 ++++++- gcc/testsuite/rust/compile/empty_union.rs | 2 ++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/rust/compile/empty_union.rs diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index 4142cc6317e..dad7f5edded 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -18,6 +18,7 @@ #include "rust-ast-validation.h" #include "rust-diagnostics.h" +#include "rust-item.h" #include "rust-keyword-values.h" namespace Rust { @@ -81,6 +82,15 @@ ASTValidation::visit (AST::ExternalFunctionItem &item) AST::ContextualASTVisitor::visit (item); } +void +ASTValidation::visit (AST::Union &item) +{ + if (item.get_variants ().empty ()) + rust_error_at (item.get_locus (), "unions cannot have zero fields"); + + AST::ContextualASTVisitor::visit (item); +} + void ASTValidation::visit (AST::Function &function) { diff --git a/gcc/rust/checks/errors/rust-ast-validation.h b/gcc/rust/checks/errors/rust-ast-validation.h index 49133ee0c3d..1052168ea72 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.h +++ b/gcc/rust/checks/errors/rust-ast-validation.h @@ -21,6 +21,7 @@ #include "rust-ast-visitor.h" #include "rust-ast-full.h" +#include "rust-item.h" namespace Rust { @@ -37,6 +38,7 @@ public: virtual void visit (AST::Lifetime &lifetime); virtual void visit (AST::LoopLabel &label); virtual void visit (AST::ExternalFunctionItem &item); + virtual void visit (AST::Union &item); virtual void visit (AST::Function &function); virtual void visit (AST::Trait &trait); }; diff --git a/gcc/testsuite/rust/compile/const_generics_8.rs b/gcc/testsuite/rust/compile/const_generics_8.rs index c7810830f46..bb34652b9a6 100644 --- a/gcc/testsuite/rust/compile/const_generics_8.rs +++ b/gcc/testsuite/rust/compile/const_generics_8.rs @@ -8,7 +8,12 @@ enum Bidoule {} type Bipboupe = Bidule; trait Fooable {} -union Bidoulepe {} // { dg-error "default values for const generic parameters are not allowed in .union. items" } +union Bidoulepe { + // { dg-error "default values for const generic parameters are not allowed in .union. items" "" {target *-*-* } .-1 } + int: i32, + float: f32, +} + fn const_default() {} // { dg-error "default values for const generic parameters are not allowed in .function. items" } // Note - missing generic parameter - needs name resolution on const generics diff --git a/gcc/testsuite/rust/compile/empty_union.rs b/gcc/testsuite/rust/compile/empty_union.rs new file mode 100644 index 00000000000..6114df5d9c0 --- /dev/null +++ b/gcc/testsuite/rust/compile/empty_union.rs @@ -0,0 +1,2 @@ +#[repr(C)] +union MyUnion {} // { dg-error "unions cannot have zero fields" } From patchwork Tue Jan 30 12:06:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892830 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=YuNwQvy+; 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 4TPPW92sGgz23dQ for ; Tue, 30 Jan 2024 23:24:53 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5F722385782F for ; Tue, 30 Jan 2024 12:24:51 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id AC5ED385800B for ; Tue, 30 Jan 2024 12:11:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AC5ED385800B 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 AC5ED385800B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616682; cv=none; b=xcpLobESawW1zmSt403jtnm18ACRfrvdMCtfHKQBtlYRVZMywqH1RrG9gVMnCHswj31kiKwkPkK0eDf0erJqK/FvEAJvYVFD6FVuaRvLESvDNfRZWmFzFrwqM4AKaDUxSxpwFeIE9r4T+aCJ9UhnctAcPAKyBUikdo7RR9A9w1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616682; c=relaxed/simple; bh=gBlem/nlnxSjTManPeEAYmvS8WVPwLdehJbHtr3ab20=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=DklDKqQu9HtFCo7kOmXJ110PjsIMcMPRLfja4bNs5dGWWP29jaMPzTn0djbiLOTbav1tpCgY3qTeecmuBxSfPd3PPYQdFV2P54NSlJRg/HxccwBYe3h+Lx2qpxATumpx0B/wIOxZGZuv++/PKppK5wGPgmtFsJknsclRIWNQXFA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-337d05b8942so3297335f8f.3 for ; Tue, 30 Jan 2024 04:11:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616668; x=1707221468; 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=N01dnkyDOcPTFk1HjAorGkB1OoXv+R1KXnl8SMpgPvo=; b=YuNwQvy+Nf8JfX1t9FIT9UpKFKymI39N8WcayxiDsoUxlef8yMX6HtBB8koEKcRBgc kFqXqIYcpq8NlGwejcRI+JcbRhpjBksvqPVB8YOtGdLQc+ZKQfM6lARW8ROkU+hgw/aq r6CHw6tVQKqVBlnqDOUCxmSMHFnHx6LRvp52xP+j1yLC750oyzG5g5K2uSWNJrGVsElG hdXthJGukmgcEuoJH1IZA0LmNxWkhQThu0ZW/ZyNYMX+gMPfkb1ltVoYM3jUfgScvGde hyJQC6I6Vva/tz5OKI+2iUwQWmyqAljsjqC/o6eyZWniR4SBpR5YckVQcrsYNbYGA2qf Nj7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616668; x=1707221468; 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=N01dnkyDOcPTFk1HjAorGkB1OoXv+R1KXnl8SMpgPvo=; b=c7BjSsetd3X4kDZ3sE1aZTxN6XcPcbKOcyp4f1YomgMdHIeJMWWgILoYXd2n9fFD2F JZ1hX0F66yY/e/rgpmj85yk83GlAy6i6ffxZcOQT4pbkRCueARmyXy6mgJtTjYhoQFuK lqYprLLUHBb4VXPoR161t3PK68ehPbta4i4oeHpgeFWTYmQzDFR0+oaZXM6tOhXy8tLy TLfOQxvP5ZfLy9+v21w2EY9M9d2kHS7fw3Xb52BfPleEWrT8wtHq+KlJfKRcC4seTuxa v05CNb6cIDai6Wf9VrPmTwPPEhpvnkq5fW6gvKwSEoHJAMkU3Y0RpOneUoq3IPA8m6pT 8N/w== X-Gm-Message-State: AOJu0YyxmQsNO61mScjAZn/T5KoKL8sdVvikm5K0EsoVvH9YxJ2szPlx fOWk78rAyyo/ENEiOup/hIlUoucqz2kA9ufXvuHHQlkUlPyKsN435/bFJAFFhTKRzykEAq+vxV+ Yvg== X-Google-Smtp-Source: AGHT+IERzmn4nX8Mm3kxrEXyu0xfzysltHT7CBCEOMzL6Py7buylRF06yOYZ5IJCact4f3oG45nV3A== X-Received: by 2002:adf:ea02:0:b0:337:2940:ab7b with SMTP id q2-20020adfea02000000b003372940ab7bmr5930511wrm.1.1706616667548; Tue, 30 Jan 2024 04:11:07 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:07 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 024/101] gccrs: Replace TOK suffix with KW Date: Tue, 30 Jan 2024 13:06:40 +0100 Message-ID: <20240130121026.807464-27-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: Pierre-Emmanuel Patry TOK suffix was chosen to disambiguate some identifiers with c++ reserved keyword. Even though this list lies within the rust-token header, this macro is used in many context sometimes unrelated with the lexer and tokens. This TOK suffix may appear surprising in such context. gcc/rust/ChangeLog: * lex/rust-token.h (enum PrimitiveCoreType): Change keyword suffix from tok to kw. * ast/rust-ast-collector.cc (TokenCollector::visit): Update suffix to match the new declaration. * lex/rust-lex.cc (Lexer::parse_raw_identifier): Likewise. * parse/rust-parse-impl.h (can_tok_start_type): Likewise. (Parser::parse_item): Likewise. (Parser::parse_vis_item): Likewise. (Parser::parse_extern_crate): Likewise. (Parser::parse_function): Likewise. (Parser::parse_function_qualifiers): Likewise. (Parser::parse_struct): Likewise. (Parser::parse_enum): Likewise. (Parser::parse_static_item): Likewise. (Parser::parse_trait_item): Likewise. (Parser::parse_inherent_impl_item): Likewise. (Parser::parse_trait_impl_item): Likewise. (Parser::parse_extern_block): Likewise. (Parser::parse_external_item): Likewise. (Parser::parse_stmt): Likewise. (Parser::parse_return_expr): Likewise. (Parser::parse_match_expr): Likewise. (Parser::parse_type): Likewise. (Parser::parse_for_prefixed_type): Likewise. (Parser::parse_type_no_bounds): Likewise. (Parser::parse_stmt_or_expr): Likewise. * parse/rust-parse.cc (peculiar_fragment_match_compatible): Likewie. * util/rust-token-converter.cc (convert): Likewise. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/ast/rust-ast-collector.cc | 30 +++--- gcc/rust/lex/rust-lex.cc | 2 +- gcc/rust/lex/rust-token.h | 20 ++-- gcc/rust/parse/rust-parse-impl.h | 134 +++++++++++++------------- gcc/rust/parse/rust-parse.cc | 18 ++-- gcc/rust/util/rust-token-converter.cc | 18 ++-- 6 files changed, 111 insertions(+), 111 deletions(-) diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc index 7d3d3e204f7..8f394e595ed 100644 --- a/gcc/rust/ast/rust-ast-collector.cc +++ b/gcc/rust/ast/rust-ast-collector.cc @@ -332,7 +332,7 @@ TokenCollector::visit (FunctionQualifiers &qualifiers) push (Rust::Token::make (UNSAFE, qualifiers.get_locus ())); if (qualifiers.is_extern ()) { - push (Rust::Token::make (EXTERN_TOK, qualifiers.get_locus ())); + push (Rust::Token::make (EXTERN_KW, qualifiers.get_locus ())); if (qualifiers.has_abi ()) { push (Rust::Token::make_string (UNDEF_LOCATION, @@ -1323,7 +1323,7 @@ TokenCollector::visit (RangeToInclExpr &expr) void TokenCollector::visit (ReturnExpr &expr) { - push (Rust::Token::make (RETURN_TOK, expr.get_locus ())); + push (Rust::Token::make (RETURN_KW, expr.get_locus ())); if (expr.has_returned_expr ()) visit (expr.get_returned_expr ()); } @@ -1463,7 +1463,7 @@ TokenCollector::visit (MatchCase &match_case) void TokenCollector::visit (MatchExpr &expr) { - push (Rust::Token::make (MATCH_TOK, expr.get_locus ())); + push (Rust::Token::make (MATCH_KW, expr.get_locus ())); visit (expr.get_scrutinee_expr ()); push (Rust::Token::make (LEFT_CURLY, UNDEF_LOCATION)); newline (); @@ -1609,7 +1609,7 @@ void TokenCollector::visit (ExternCrate &crate) { visit_items_as_lines (crate.get_outer_attrs ()); - push (Rust::Token::make (EXTERN_TOK, crate.get_locus ())); + push (Rust::Token::make (EXTERN_KW, crate.get_locus ())); push (Rust::Token::make (CRATE, UNDEF_LOCATION)); auto ref = crate.get_referenced_crate (); push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (ref))); @@ -1717,7 +1717,7 @@ TokenCollector::visit (Function &function) auto qualifiers = function.get_qualifiers (); visit (qualifiers); - push (Rust::Token::make (FN_TOK, function.get_locus ())); + push (Rust::Token::make (FN_KW, function.get_locus ())); auto name = function.get_function_name ().as_string (); push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (name))); if (function.has_generics ()) @@ -1778,7 +1778,7 @@ TokenCollector::visit (StructStruct &struct_item) if (struct_item.has_visibility ()) visit (struct_item.get_visibility ()); auto struct_name = struct_item.get_identifier ().as_string (); - push (Rust::Token::make (STRUCT_TOK, struct_item.get_locus ())); + push (Rust::Token::make (STRUCT_KW, struct_item.get_locus ())); push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (struct_name))); if (struct_item.has_generics ()) @@ -1800,7 +1800,7 @@ TokenCollector::visit (TupleStruct &tuple_struct) { visit_items_as_lines (tuple_struct.get_outer_attrs ()); auto struct_name = tuple_struct.get_identifier ().as_string (); - push (Rust::Token::make (STRUCT_TOK, tuple_struct.get_locus ())); + push (Rust::Token::make (STRUCT_KW, tuple_struct.get_locus ())); push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (struct_name))); if (tuple_struct.has_generics ()) visit (tuple_struct.get_generic_params ()); @@ -1856,7 +1856,7 @@ TokenCollector::visit (Enum &enumeration) visit_items_as_lines (enumeration.get_outer_attrs ()); if (enumeration.has_visibility ()) visit (enumeration.get_visibility ()); - push (Rust::Token::make (ENUM_TOK, enumeration.get_locus ())); + push (Rust::Token::make (ENUM_KW, enumeration.get_locus ())); auto id = enumeration.get_identifier ().as_string (); push ( Rust::Token::make_identifier (enumeration.get_locus (), std::move (id))); @@ -1915,7 +1915,7 @@ void TokenCollector::visit (StaticItem &item) { visit_items_as_lines (item.get_outer_attrs ()); - push (Rust::Token::make (STATIC_TOK, item.get_locus ())); + push (Rust::Token::make (STATIC_KW, item.get_locus ())); if (item.is_mutable ()) push (Rust::Token::make (MUT, UNDEF_LOCATION)); @@ -1961,7 +1961,7 @@ TokenCollector::visit (TraitItemFunc &item) auto func = item.get_trait_function_decl (); auto id = func.get_identifier ().as_string (); - push (Rust::Token::make (FN_TOK, item.get_locus ())); + push (Rust::Token::make (FN_KW, item.get_locus ())); push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id))); push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION)); @@ -2000,7 +2000,7 @@ TokenCollector::visit (TraitItemMethod &item) auto method = item.get_trait_method_decl (); auto id = method.get_identifier ().as_string (); - push (Rust::Token::make (FN_TOK, item.get_locus ())); + push (Rust::Token::make (FN_KW, item.get_locus ())); push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id))); push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION)); @@ -2112,7 +2112,7 @@ TokenCollector::visit (ExternalStaticItem &item) visit_items_as_lines (item.get_outer_attrs ()); if (item.has_visibility ()) visit (item.get_visibility ()); - push (Rust::Token::make (STATIC_TOK, item.get_locus ())); + push (Rust::Token::make (STATIC_KW, item.get_locus ())); if (item.is_mut ()) push (Rust::Token::make (MUT, UNDEF_LOCATION)); push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id))); @@ -2131,7 +2131,7 @@ TokenCollector::visit (ExternalFunctionItem &function) auto id = function.get_identifier ().as_string (); - push (Rust::Token::make (FN_TOK, function.get_locus ())); + push (Rust::Token::make (FN_KW, function.get_locus ())); push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id))); if (function.has_generics ()) visit (function.get_generic_params ()); @@ -2152,7 +2152,7 @@ void TokenCollector::visit (ExternBlock &block) { visit_items_as_lines (block.get_outer_attrs ()); - push (Rust::Token::make (EXTERN_TOK, block.get_locus ())); + push (Rust::Token::make (EXTERN_KW, block.get_locus ())); if (block.has_abi ()) { @@ -2821,7 +2821,7 @@ TokenCollector::visit (BareFunctionType &type) visit (type.get_function_qualifiers ()); - push (Rust::Token::make (FN_TOK, type.get_locus ())); + push (Rust::Token::make (FN_KW, type.get_locus ())); push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION)); visit_items_joined_by_separator (type.get_function_params (), COMMA); diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index 107dbad2ff9..2d41c114f73 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -1940,7 +1940,7 @@ Lexer::parse_raw_identifier (location_t loc) using namespace Rust::Values; std::set invalid{ - Keywords::CRATE, Keywords::EXTERN_TOK, Keywords::SELF, + Keywords::CRATE, Keywords::EXTERN_KW, Keywords::SELF, Keywords::SUPER, Keywords::SELF_ALIAS, }; diff --git a/gcc/rust/lex/rust-token.h b/gcc/rust/lex/rust-token.h index 5da8b6cd200..50513acb68d 100644 --- a/gcc/rust/lex/rust-token.h +++ b/gcc/rust/lex/rust-token.h @@ -162,11 +162,11 @@ enum PrimitiveCoreType RS_TOKEN_KEYWORD (DO, "do") /* unused */ \ RS_TOKEN_KEYWORD (DYN, "dyn") \ RS_TOKEN_KEYWORD (ELSE, "else") \ - RS_TOKEN_KEYWORD (ENUM_TOK, "enum") \ - RS_TOKEN_KEYWORD (EXTERN_TOK, "extern") \ + RS_TOKEN_KEYWORD (ENUM_KW, "enum") \ + RS_TOKEN_KEYWORD (EXTERN_KW, "extern") \ RS_TOKEN_KEYWORD (FALSE_LITERAL, "false") \ - RS_TOKEN_KEYWORD (FINAL_TOK, "final") /* unused */ \ - RS_TOKEN_KEYWORD (FN_TOK, "fn") \ + RS_TOKEN_KEYWORD (FINAL_KW, "final") /* unused */ \ + RS_TOKEN_KEYWORD (FN_KW, "fn") \ RS_TOKEN_KEYWORD (FOR, "for") \ RS_TOKEN_KEYWORD (IF, "if") \ RS_TOKEN_KEYWORD (IMPL, "impl") \ @@ -174,20 +174,20 @@ enum PrimitiveCoreType RS_TOKEN_KEYWORD (LET, "let") \ RS_TOKEN_KEYWORD (LOOP, "loop") \ RS_TOKEN_KEYWORD (MACRO, "macro") \ - RS_TOKEN_KEYWORD (MATCH_TOK, "match") \ + RS_TOKEN_KEYWORD (MATCH_KW, "match") \ RS_TOKEN_KEYWORD (MOD, "mod") \ RS_TOKEN_KEYWORD (MOVE, "move") \ RS_TOKEN_KEYWORD (MUT, "mut") \ - RS_TOKEN_KEYWORD (OVERRIDE_TOK, "override") /* unused */ \ - RS_TOKEN_KEYWORD (PRIV, "priv") /* unused */ \ + RS_TOKEN_KEYWORD (OVERRIDE_KW, "override") /* unused */ \ + RS_TOKEN_KEYWORD (PRIV, "priv") /* unused */ \ RS_TOKEN_KEYWORD (PUB, "pub") \ RS_TOKEN_KEYWORD (REF, "ref") \ - RS_TOKEN_KEYWORD (RETURN_TOK, "return") \ + RS_TOKEN_KEYWORD (RETURN_KW, "return") \ RS_TOKEN_KEYWORD (SELF_ALIAS, \ "Self") /* mrustc does not treat this as a reserved word*/ \ RS_TOKEN_KEYWORD (SELF, "self") \ - RS_TOKEN_KEYWORD (STATIC_TOK, "static") \ - RS_TOKEN_KEYWORD (STRUCT_TOK, "struct") \ + RS_TOKEN_KEYWORD (STATIC_KW, "static") \ + RS_TOKEN_KEYWORD (STRUCT_KW, "struct") \ RS_TOKEN_KEYWORD (SUPER, "super") \ RS_TOKEN_KEYWORD (TRAIT, "trait") \ RS_TOKEN_KEYWORD (TRUE_LITERAL, "true") \ diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 45c72e495c2..8b006142b16 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -160,8 +160,8 @@ can_tok_start_type (TokenId id) case ASYNC: case CONST: case UNSAFE: - case EXTERN_TOK: - case FN_TOK: + case EXTERN_KW: + case FN_KW: case IMPL: case DYN: case QUESTION_MARK: @@ -1114,14 +1114,14 @@ Parser::parse_item (bool called_from_statement) return nullptr; case PUB: case MOD: - case EXTERN_TOK: + case EXTERN_KW: case USE: - case FN_TOK: + case FN_KW: case TYPE: - case STRUCT_TOK: - case ENUM_TOK: + case STRUCT_KW: + case ENUM_KW: case CONST: - case STATIC_TOK: + case STATIC_KW: case AUTO: case TRAIT: case IMPL: @@ -1302,7 +1302,7 @@ Parser::parse_vis_item (AST::AttrVec outer_attrs) { case MOD: return parse_module (std::move (vis), std::move (outer_attrs)); - case EXTERN_TOK: + case EXTERN_KW: // lookahead to resolve syntactical production t = lexer.peek_token (1); @@ -1310,7 +1310,7 @@ Parser::parse_vis_item (AST::AttrVec outer_attrs) { case CRATE: return parse_extern_crate (std::move (vis), std::move (outer_attrs)); - case FN_TOK: // extern function + case FN_KW: // extern function return parse_function (std::move (vis), std::move (outer_attrs)); case LEFT_CURLY: // extern block return parse_extern_block (std::move (vis), std::move (outer_attrs)); @@ -1320,7 +1320,7 @@ Parser::parse_vis_item (AST::AttrVec outer_attrs) switch (t->get_id ()) { - case FN_TOK: + case FN_KW: return parse_function (std::move (vis), std::move (outer_attrs)); case LEFT_CURLY: return parse_extern_block (std::move (vis), @@ -1345,13 +1345,13 @@ Parser::parse_vis_item (AST::AttrVec outer_attrs) } case USE: return parse_use_decl (std::move (vis), std::move (outer_attrs)); - case FN_TOK: + case FN_KW: return parse_function (std::move (vis), std::move (outer_attrs)); case TYPE: return parse_type_alias (std::move (vis), std::move (outer_attrs)); - case STRUCT_TOK: + case STRUCT_KW: return parse_struct (std::move (vis), std::move (outer_attrs)); - case ENUM_TOK: + case ENUM_KW: return parse_enum (std::move (vis), std::move (outer_attrs)); // TODO: implement union keyword but not really because of // context-dependence case UNION: crappy hack to do union "keyword" @@ -1376,8 +1376,8 @@ Parser::parse_vis_item (AST::AttrVec outer_attrs) case UNDERSCORE: return parse_const_item (std::move (vis), std::move (outer_attrs)); case UNSAFE: - case EXTERN_TOK: - case FN_TOK: + case EXTERN_KW: + case FN_KW: return parse_function (std::move (vis), std::move (outer_attrs)); default: add_error ( @@ -1388,7 +1388,7 @@ Parser::parse_vis_item (AST::AttrVec outer_attrs) lexer.skip_token (1); // TODO: is this right thing to do? return nullptr; } - case STATIC_TOK: + case STATIC_KW: return parse_static_item (std::move (vis), std::move (outer_attrs)); case AUTO: case TRAIT: @@ -1404,8 +1404,8 @@ Parser::parse_vis_item (AST::AttrVec outer_attrs) case AUTO: case TRAIT: return parse_trait (std::move (vis), std::move (outer_attrs)); - case EXTERN_TOK: - case FN_TOK: + case EXTERN_KW: + case FN_KW: return parse_function (std::move (vis), std::move (outer_attrs)); case IMPL: return parse_impl (std::move (vis), std::move (outer_attrs)); @@ -2482,7 +2482,7 @@ Parser::parse_extern_crate (AST::Visibility vis, AST::AttrVec outer_attrs) { location_t locus = lexer.peek_token ()->get_locus (); - if (!skip_token (EXTERN_TOK)) + if (!skip_token (EXTERN_KW)) { skip_after_semicolon (); return nullptr; @@ -2854,7 +2854,7 @@ Parser::parse_function (AST::Visibility vis, // Get qualifiers for function if they exist AST::FunctionQualifiers qualifiers = parse_function_qualifiers (); - skip_token (FN_TOK); + skip_token (FN_KW); // Save function name token const_TokenPtr function_name_tok = expect_token (IDENTIFIER); @@ -2962,7 +2962,7 @@ Parser::parse_function_qualifiers () has_unsafe = true; } - if (lexer.peek_token ()->get_id () == EXTERN_TOK) + if (lexer.peek_token ()->get_id () == EXTERN_KW) { lexer.skip_token (); has_extern = true; @@ -4193,7 +4193,7 @@ Parser::parse_struct (AST::Visibility vis, /* Tuple struct <- 'struct' IDENTIFIER generic_params? '(' tuple_fields? ')' * where_clause? ';' */ location_t locus = lexer.peek_token ()->get_locus (); - skip_token (STRUCT_TOK); + skip_token (STRUCT_KW); // parse struct name const_TokenPtr name_tok = expect_token (IDENTIFIER); @@ -4521,7 +4521,7 @@ Parser::parse_enum (AST::Visibility vis, AST::AttrVec outer_attrs) { location_t locus = lexer.peek_token ()->get_locus (); - skip_token (ENUM_TOK); + skip_token (ENUM_KW); // parse enum name const_TokenPtr enum_name_tok = expect_token (IDENTIFIER); @@ -4856,7 +4856,7 @@ Parser::parse_static_item (AST::Visibility vis, AST::AttrVec outer_attrs) { location_t locus = lexer.peek_token ()->get_locus (); - skip_token (STATIC_TOK); + skip_token (STATIC_KW); // determine whether static item is mutable bool is_mut = false; @@ -5024,8 +5024,8 @@ Parser::parse_trait_item () // TODO: find out how to disable gcc "implicit fallthrough" error gcc_fallthrough (); case UNSAFE: - case EXTERN_TOK: - case FN_TOK: { + case EXTERN_KW: + case FN_KW: { /* function and method can't be disambiguated by lookahead alone * (without a lot of work and waste), so either make a * "parse_trait_function_or_method" or parse here mostly and pass in @@ -5035,7 +5035,7 @@ Parser::parse_trait_item () // parse function or method qualifiers AST::FunctionQualifiers qualifiers = parse_function_qualifiers (); - skip_token (FN_TOK); + skip_token (FN_KW); // parse function or method name const_TokenPtr ident_tok = expect_token (IDENTIFIER); @@ -5484,9 +5484,9 @@ Parser::parse_inherent_impl_item () // TODO: is a recursive call to parse_inherent_impl_item better? switch (lexer.peek_token ()->get_id ()) { - case EXTERN_TOK: + case EXTERN_KW: case UNSAFE: - case FN_TOK: + case FN_KW: // function or method return parse_inherent_impl_function_or_method (std::move (vis), std::move ( @@ -5503,8 +5503,8 @@ Parser::parse_inherent_impl_item () return parse_const_item (std::move (vis), std::move (outer_attrs)); case UNSAFE: - case EXTERN_TOK: - case FN_TOK: + case EXTERN_KW: + case FN_KW: return parse_inherent_impl_function_or_method (std::move (vis), std::move ( outer_attrs)); @@ -5526,9 +5526,9 @@ Parser::parse_inherent_impl_item () return nullptr; } } - case EXTERN_TOK: + case EXTERN_KW: case UNSAFE: - case FN_TOK: + case FN_KW: // function or method return parse_inherent_impl_function_or_method ( AST::Visibility::create_private (), std::move (outer_attrs)); @@ -5544,8 +5544,8 @@ Parser::parse_inherent_impl_item () return parse_const_item (AST::Visibility::create_private (), std::move (outer_attrs)); case UNSAFE: - case EXTERN_TOK: - case FN_TOK: + case EXTERN_KW: + case FN_KW: return parse_inherent_impl_function_or_method ( AST::Visibility::create_private (), std::move (outer_attrs)); default: @@ -5583,7 +5583,7 @@ Parser::parse_inherent_impl_function_or_method ( // parse function or method qualifiers AST::FunctionQualifiers qualifiers = parse_function_qualifiers (); - skip_token (FN_TOK); + skip_token (FN_KW); // parse function or method name const_TokenPtr ident_tok = expect_token (IDENTIFIER); @@ -5720,9 +5720,9 @@ Parser::parse_trait_impl_item () return parse_macro_invocation_semi (std::move (outer_attrs)); case TYPE: return parse_type_alias (visibility, std::move (outer_attrs)); - case EXTERN_TOK: + case EXTERN_KW: case UNSAFE: - case FN_TOK: + case FN_KW: // function or method return parse_trait_impl_function_or_method (visibility, std::move (outer_attrs)); @@ -5737,8 +5737,8 @@ Parser::parse_trait_impl_item () case UNDERSCORE: return parse_const_item (visibility, std::move (outer_attrs)); case UNSAFE: - case EXTERN_TOK: - case FN_TOK: + case EXTERN_KW: + case FN_KW: return parse_trait_impl_function_or_method (visibility, std::move (outer_attrs)); default: @@ -5786,7 +5786,7 @@ Parser::parse_trait_impl_function_or_method ( // parse function or method qualifiers AST::FunctionQualifiers qualifiers = parse_function_qualifiers (); - skip_token (FN_TOK); + skip_token (FN_KW); // parse function or method name const_TokenPtr ident_tok = expect_token (IDENTIFIER); @@ -5931,7 +5931,7 @@ Parser::parse_extern_block (AST::Visibility vis, AST::AttrVec outer_attrs) { location_t locus = lexer.peek_token ()->get_locus (); - skip_token (EXTERN_TOK); + skip_token (EXTERN_KW); // detect optional abi name std::string abi; @@ -6167,7 +6167,7 @@ Parser::parse_external_item () { case IDENTIFIER: return parse_macro_invocation_semi (outer_attrs); - case STATIC_TOK: { + case STATIC_KW: { // parse extern static item lexer.skip_token (); @@ -6217,7 +6217,7 @@ Parser::parse_external_item () has_mut, std::move (vis), std::move (outer_attrs), locus)); } - case FN_TOK: + case FN_KW: return parse_external_function_item (std::move (vis), std::move (outer_attrs)); case TYPE: @@ -6266,14 +6266,14 @@ Parser::parse_stmt (ParseRestrictions restrictions) return parse_let_stmt (std::move (outer_attrs), restrictions); case PUB: case MOD: - case EXTERN_TOK: + case EXTERN_KW: case USE: - case FN_TOK: + case FN_KW: case TYPE: - case STRUCT_TOK: - case ENUM_TOK: + case STRUCT_KW: + case ENUM_KW: case CONST: - case STATIC_TOK: + case STATIC_KW: case AUTO: case TRAIT: case IMPL: @@ -7675,7 +7675,7 @@ Parser::parse_return_expr (AST::AttrVec outer_attrs, if (locus == UNKNOWN_LOCATION) { locus = lexer.peek_token ()->get_locus (); - skip_token (RETURN_TOK); + skip_token (RETURN_KW); } // parse expression to return, if it exists @@ -8448,7 +8448,7 @@ Parser::parse_match_expr (AST::AttrVec outer_attrs, if (locus == UNKNOWN_LOCATION) { locus = lexer.peek_token ()->get_locus (); - skip_token (MATCH_TOK); + skip_token (MATCH_KW); } /* parse scrutinee expression, which is required (and HACK to prevent struct @@ -9246,8 +9246,8 @@ Parser::parse_type (bool save_errors) case ASYNC: case CONST: case UNSAFE: - case EXTERN_TOK: - case FN_TOK: + case EXTERN_KW: + case FN_KW: // bare function type (with no for lifetimes) return parse_bare_function_type (std::vector ()); case IMPL: @@ -9563,8 +9563,8 @@ Parser::parse_for_prefixed_type () case ASYNC: case CONST: case UNSAFE: - case EXTERN_TOK: - case FN_TOK: + case EXTERN_KW: + case FN_KW: return parse_bare_function_type (std::move (for_lifetimes)); case SCOPE_RESOLUTION: case IDENTIFIER: @@ -9686,7 +9686,7 @@ Parser::parse_bare_function_type ( AST::FunctionQualifiers qualifiers = parse_function_qualifiers (); - if (!skip_token (FN_TOK)) + if (!skip_token (FN_KW)) return nullptr; if (!skip_token (LEFT_PAREN)) @@ -10072,8 +10072,8 @@ Parser::parse_type_no_bounds () case ASYNC: case CONST: case UNSAFE: - case EXTERN_TOK: - case FN_TOK: + case EXTERN_KW: + case FN_KW: // bare function type (with no for lifetimes) return parse_bare_function_type (std::vector ()); case IMPL: @@ -11632,14 +11632,14 @@ Parser::parse_stmt_or_expr () } case PUB: case MOD: - case EXTERN_TOK: + case EXTERN_KW: case USE: - case FN_TOK: + case FN_KW: case TYPE: - case STRUCT_TOK: - case ENUM_TOK: + case STRUCT_KW: + case ENUM_KW: case CONST: - case STATIC_TOK: + case STATIC_KW: case AUTO: case TRAIT: case IMPL: { @@ -11670,8 +11670,8 @@ Parser::parse_stmt_or_expr () parse_vis_item (std::move (outer_attrs))); return ExprOrStmt (std::move (item)); } - case EXTERN_TOK: - case FN_TOK: { + case EXTERN_KW: + case FN_KW: { // unsafe function std::unique_ptr item ( parse_vis_item (std::move (outer_attrs))); @@ -12535,7 +12535,7 @@ Parser::null_denotation_not_path ( case DOT_DOT_EQ: // range to inclusive expr return parse_range_to_inclusive_expr (tok, std::move (outer_attrs)); - case RETURN_TOK: + case RETURN_KW: // FIXME: is this really a null denotation expression? return parse_return_expr (std::move (outer_attrs), tok->get_locus ()); case BREAK: @@ -12578,7 +12578,7 @@ Parser::null_denotation_not_path ( case FOR: return parse_for_loop_expr (std::move (outer_attrs), AST::LoopLabel::error ()); - case MATCH_TOK: + case MATCH_KW: // also an expression with block return parse_match_expr (std::move (outer_attrs), tok->get_locus ()); case LEFT_SQUARE: diff --git a/gcc/rust/parse/rust-parse.cc b/gcc/rust/parse/rust-parse.cc index 0f91c7ffe61..504a409cc4d 100644 --- a/gcc/rust/parse/rust-parse.cc +++ b/gcc/rust/parse/rust-parse.cc @@ -194,11 +194,11 @@ peculiar_fragment_match_compatible (const AST::MacroMatchFragment &last_match, DO, DYN, ELSE, - ENUM_TOK, - EXTERN_TOK, + ENUM_KW, + EXTERN_KW, FALSE_LITERAL, - FINAL_TOK, - FN_TOK, + FINAL_KW, + FN_KW, FOR, IF, IMPL, @@ -206,18 +206,18 @@ peculiar_fragment_match_compatible (const AST::MacroMatchFragment &last_match, LET, LOOP, MACRO, - MATCH_TOK, + MATCH_KW, MOD, MOVE, MUT, - OVERRIDE_TOK, + OVERRIDE_KW, PUB, REF, - RETURN_TOK, + RETURN_KW, SELF_ALIAS, SELF, - STATIC_TOK, - STRUCT_TOK, + STATIC_KW, + STRUCT_KW, SUPER, TRAIT, TRUE_LITERAL, diff --git a/gcc/rust/util/rust-token-converter.cc b/gcc/rust/util/rust-token-converter.cc index 537bca3a3f7..41f810542de 100644 --- a/gcc/rust/util/rust-token-converter.cc +++ b/gcc/rust/util/rust-token-converter.cc @@ -134,10 +134,10 @@ convert (const std::vector &tokens) case DO: case DYN: case ELSE: - case ENUM_TOK: - case EXTERN_TOK: - case FINAL_TOK: - case FN_TOK: + case ENUM_KW: + case EXTERN_KW: + case FINAL_KW: + case FN_KW: case FOR: case IF: case IMPL: @@ -145,19 +145,19 @@ convert (const std::vector &tokens) case LET: case LOOP: case MACRO: - case MATCH_TOK: + case MATCH_KW: case MOD: case MOVE: case MUT: - case OVERRIDE_TOK: + case OVERRIDE_KW: case PRIV: case PUB: case REF: - case RETURN_TOK: + case RETURN_KW: case SELF_ALIAS: case SELF: - case STATIC_TOK: - case STRUCT_TOK: + case STATIC_KW: + case STRUCT_KW: case SUPER: case TRAIT: case TRY: From patchwork Tue Jan 30 12:06:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892838 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=JSPYyBwc; 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 4TPPY53xRZz23gZ for ; Tue, 30 Jan 2024 23:26:33 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8449D3861812 for ; Tue, 30 Jan 2024 12:26:31 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 0F772385801D for ; Tue, 30 Jan 2024 12:11:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0F772385801D 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 0F772385801D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::431 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616681; cv=none; b=PbMCXK96GcGzSa68ZoSDdX2y8oqduDp2JXXGKxaJLgxruUV20PlI2Mj2Yc8iQcWwchxQERUqySwB/WGkrP8VJP1yEF7hUBhHwcAJfHhKNnZM5k+b7A7oiVKfFBmyQ+cleXcnEG5z6fDzQxS96Sr76ro5gfII98ZSBFBCzuDo4Qw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616681; c=relaxed/simple; bh=6SVQGInhXthSVbm99z8Prg07atKX80OKKX5Kh6q9XTE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=MvDYOnz2hRTjIWoY5yV9YuXSvnzTn7/Vlwst6O1/qwF2J58EBG+So4E4Ds4QfnF2p3Tph+zK1OVAYAaM6PhdZpN/P7Wz9mkiW+e5dpGNzvmXbTkm9hEOJ/DjZtcA+Ze7lptjdt+FzxSxapDl5jA7lUc7EBfYVCSlDxGdrcCJ5r0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-33ae6dfa923so1618473f8f.1 for ; Tue, 30 Jan 2024 04:11:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616668; x=1707221468; 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=qWh0Q4x17LM2TyaXtoDWrBk2CzIUUbnfKfj9jSBUbCw=; b=JSPYyBwcdKdlzLUzZFsM3gR4aTg70CYIEg8SyLLDJtvhqTu3vT9RxFheADsfzwKATA f8Y1iJcOq++vogdWcDbpbtOa/UfQaj7jZJQ7LT+dT43mVZOg1q2ojkqJHsjO+qRo5uR6 x8YkESRt6mOpAVj1J/Z9Yd4cyzxQui2z1uDr6oArj6k8CVmu3ZIqhIKRfTo/Kt3Y3zZm +E3wJ9DXgmoQRp6bIYx0Xa4hVuoW5u3r9/IHdNlLGIRgN6nIj/aiiqJGJS6IxI+sqx0F N+MHviBqulmFrm/uvsGAiwXQbjI4h0jBE361V8r5os3ivqI8rQEJBaDV8Zcv4QvIlujl mcVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616668; x=1707221468; 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=qWh0Q4x17LM2TyaXtoDWrBk2CzIUUbnfKfj9jSBUbCw=; b=ID2gUr/XFJge8VHGHPTTjLdSRPO9ZWptIPHSfKHlfJd5ALRzRH6p0b9ugRztjqqYxq PCEpsBfNQr1KIt0WIwYxmDIZ+KMy8pSxEGBtOqXwB6sl7TirY6sBDxMiUMfBrD1hwheS RA+m7JKITEodYeGcFhCwaLYpdQC7kybLVdQFxK58T4Sv6bMmTdugUfSsPyYpxznSA7RV KH/8n3grJZ6bzzdaYMng7wrEzsUDt6KvfuTcdzy5TGfOHy8+40CpZmRxaHNkSdhJ2bbA znA6F1k7czXu5yXfPGEjRGSr6h5cVkwMiPZRyEQqmjR/tmR2oqfkzcz1Bg78vjzOlIRb oXdg== X-Gm-Message-State: AOJu0Yxs7YfM0pfBzYqU2kHapn6Jh1lYe1e6zNcz/8RpUQuZyRdXHHxF mqSOMtiS/XjqU47Qnx8DeMUkn7uD8aVV3dwgvePR/NB1UXxC55Yu7GnJ4NnfdQp7VhPLVbGPZPM lTQ== X-Google-Smtp-Source: AGHT+IHzy7bwp1rkBPh63mt5bBxMUK//OFqc6kry1yX+diu6QepGjOHIAWWXAzydsO6T97wnTVFiAA== X-Received: by 2002:a5d:69cc:0:b0:33a:e56f:1ddb with SMTP id s12-20020a5d69cc000000b0033ae56f1ddbmr6147355wrw.46.1706616667927; Tue, 30 Jan 2024 04:11:07 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:07 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 025/101] gccrs: Add edition separation for keywords Date: Tue, 30 Jan 2024 13:06:41 +0100 Message-ID: <20240130121026.807464-28-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: Pierre-Emmanuel Patry It might be required in the future to get only the keywords from a specific edition. To do so we need a mean to differentiate keywords based on their edition. This commit changes the existing keyword macro to allow such behavior. gcc/rust/ChangeLog: * lex/rust-token.h (enum PrimitiveCoreType): Change enum macro calls. (RS_TOKEN_KEYWORD): Remove generic token keyword macro. (RS_TOKEN_KEYWORD_2015): Introduce keywords for edition 2015. (RS_TOKEN_KEYWORD_2018): Likewise with edition 2018. * lex/rust-token.cc (RS_TOKEN_KEYWORD): Remove old macro definition. (RS_TOKEN_KEYWORD_2015): Replace with 2015 definition... (RS_TOKEN_KEYWORD_2018): ... and 2018 definition. * util/rust-keyword-values.cc (RS_TOKEN_KEYWORD): Likewise. (RS_TOKEN_KEYWORD_2015): Likewise. (RS_TOKEN_KEYWORD_2018): Likewise. * util/rust-keyword-values.h (RS_TOKEN_KEYWORD): Likewise. (RS_TOKEN_KEYWORD_2015): Likewise. (RS_TOKEN_KEYWORD_2018): Likewise. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/lex/rust-token.cc | 24 ++++-- gcc/rust/lex/rust-token.h | 114 ++++++++++++++------------- gcc/rust/util/rust-keyword-values.cc | 6 +- gcc/rust/util/rust-keyword-values.h | 6 +- 4 files changed, 82 insertions(+), 68 deletions(-) diff --git a/gcc/rust/lex/rust-token.cc b/gcc/rust/lex/rust-token.cc index ea355051bba..7bb327358a2 100644 --- a/gcc/rust/lex/rust-token.cc +++ b/gcc/rust/lex/rust-token.cc @@ -31,9 +31,11 @@ get_token_description (TokenId id) #define RS_TOKEN(name, descr) \ case name: \ return descr; -#define RS_TOKEN_KEYWORD(x, y) RS_TOKEN (x, y) +#define RS_TOKEN_KEYWORD_2015(x, y) RS_TOKEN (x, y) +#define RS_TOKEN_KEYWORD_2018 RS_TOKEN_KEYWORD_2015 RS_TOKEN_LIST -#undef RS_TOKEN_KEYWORD +#undef RS_TOKEN_KEYWORD_2015 +#undef RS_TOKEN_KEYWORD_2018 #undef RS_TOKEN default: rust_unreachable (); @@ -50,9 +52,11 @@ token_id_to_str (TokenId id) #define RS_TOKEN(name, _) \ case name: \ return #name; -#define RS_TOKEN_KEYWORD(x, y) RS_TOKEN (x, y) +#define RS_TOKEN_KEYWORD_2015(x, y) RS_TOKEN (x, y) +#define RS_TOKEN_KEYWORD_2018 RS_TOKEN_KEYWORD_2015 RS_TOKEN_LIST -#undef RS_TOKEN_KEYWORD +#undef RS_TOKEN_KEYWORD_2015 +#undef RS_TOKEN_KEYWORD_2018 #undef RS_TOKEN default: rust_unreachable (); @@ -65,10 +69,12 @@ token_id_is_keyword (TokenId id) { switch (id) { -#define RS_TOKEN_KEYWORD(name, _) case name: +#define RS_TOKEN_KEYWORD_2015(name, _) case name: +#define RS_TOKEN_KEYWORD_2018 RS_TOKEN_KEYWORD_2015 #define RS_TOKEN(a, b) RS_TOKEN_LIST return true; -#undef RS_TOKEN_KEYWORD +#undef RS_TOKEN_KEYWORD_2015 +#undef RS_TOKEN_KEYWORD_2018 #undef RS_TOKEN default: return false; @@ -81,15 +87,17 @@ token_id_keyword_string (TokenId id) { switch (id) { -#define RS_TOKEN_KEYWORD(id, str_ptr) \ +#define RS_TOKEN_KEYWORD_2015(id, str_ptr) \ case id: { \ static const std::string str (str_ptr); \ return str; \ } \ rust_unreachable (); +#define RS_TOKEN_KEYWORD_2018 RS_TOKEN_KEYWORD_2015 #define RS_TOKEN(a, b) RS_TOKEN_LIST -#undef RS_TOKEN_KEYWORD +#undef RS_TOKEN_KEYWORD_2015 +#undef RS_TOKEN_KEYWORD_2018 #undef RS_TOKEN default: rust_unreachable (); diff --git a/gcc/rust/lex/rust-token.h b/gcc/rust/lex/rust-token.h index 50513acb68d..df321000511 100644 --- a/gcc/rust/lex/rust-token.h +++ b/gcc/rust/lex/rust-token.h @@ -59,8 +59,8 @@ enum PrimitiveCoreType }; // RS_TOKEN(name, description) -// RS_TOKEN_KEYWORD(name, identifier) -// +// RS_TOKEN_KEYWORD_{2015,2018}(name, identifier) + // Keep RS_TOKEN_KEYWORD sorted /* note that abstract, async, become, box, do, final, macro, override, priv, @@ -148,68 +148,70 @@ enum PrimitiveCoreType RS_TOKEN (INNER_DOC_COMMENT, "#![doc]") \ RS_TOKEN (OUTER_DOC_COMMENT, "#[doc]") \ /* have "weak" union and 'static keywords? */ \ - RS_TOKEN_KEYWORD (ABSTRACT, "abstract") /* unused */ \ - RS_TOKEN_KEYWORD (AS, "as") \ - RS_TOKEN_KEYWORD (ASYNC, "async") /* unused */ \ - RS_TOKEN_KEYWORD (AUTO, "auto") \ - RS_TOKEN_KEYWORD (BECOME, "become") /* unused */ \ - RS_TOKEN_KEYWORD (BOX, "box") /* unused */ \ - RS_TOKEN_KEYWORD (BREAK, "break") \ - RS_TOKEN_KEYWORD (CONST, "const") \ - RS_TOKEN_KEYWORD (CONTINUE, "continue") \ - RS_TOKEN_KEYWORD (CRATE, "crate") \ + RS_TOKEN_KEYWORD_2015 (ABSTRACT, "abstract") /* unused */ \ + RS_TOKEN_KEYWORD_2015 (AS, "as") \ + RS_TOKEN_KEYWORD_2018 (ASYNC, "async") /* unused */ \ + RS_TOKEN_KEYWORD_2015 (AUTO, "auto") \ + RS_TOKEN_KEYWORD_2015 (BECOME, "become") /* unused */ \ + RS_TOKEN_KEYWORD_2015 (BOX, "box") /* unused */ \ + RS_TOKEN_KEYWORD_2015 (BREAK, "break") \ + RS_TOKEN_KEYWORD_2015 (CONST, "const") \ + RS_TOKEN_KEYWORD_2015 (CONTINUE, "continue") \ + RS_TOKEN_KEYWORD_2015 (CRATE, "crate") \ /* FIXME: Do we need to add $crate (DOLLAR_CRATE) as a reserved kw? */ \ - RS_TOKEN_KEYWORD (DO, "do") /* unused */ \ - RS_TOKEN_KEYWORD (DYN, "dyn") \ - RS_TOKEN_KEYWORD (ELSE, "else") \ - RS_TOKEN_KEYWORD (ENUM_KW, "enum") \ - RS_TOKEN_KEYWORD (EXTERN_KW, "extern") \ - RS_TOKEN_KEYWORD (FALSE_LITERAL, "false") \ - RS_TOKEN_KEYWORD (FINAL_KW, "final") /* unused */ \ - RS_TOKEN_KEYWORD (FN_KW, "fn") \ - RS_TOKEN_KEYWORD (FOR, "for") \ - RS_TOKEN_KEYWORD (IF, "if") \ - RS_TOKEN_KEYWORD (IMPL, "impl") \ - RS_TOKEN_KEYWORD (IN, "in") \ - RS_TOKEN_KEYWORD (LET, "let") \ - RS_TOKEN_KEYWORD (LOOP, "loop") \ - RS_TOKEN_KEYWORD (MACRO, "macro") \ - RS_TOKEN_KEYWORD (MATCH_KW, "match") \ - RS_TOKEN_KEYWORD (MOD, "mod") \ - RS_TOKEN_KEYWORD (MOVE, "move") \ - RS_TOKEN_KEYWORD (MUT, "mut") \ - RS_TOKEN_KEYWORD (OVERRIDE_KW, "override") /* unused */ \ - RS_TOKEN_KEYWORD (PRIV, "priv") /* unused */ \ - RS_TOKEN_KEYWORD (PUB, "pub") \ - RS_TOKEN_KEYWORD (REF, "ref") \ - RS_TOKEN_KEYWORD (RETURN_KW, "return") \ - RS_TOKEN_KEYWORD (SELF_ALIAS, \ - "Self") /* mrustc does not treat this as a reserved word*/ \ - RS_TOKEN_KEYWORD (SELF, "self") \ - RS_TOKEN_KEYWORD (STATIC_KW, "static") \ - RS_TOKEN_KEYWORD (STRUCT_KW, "struct") \ - RS_TOKEN_KEYWORD (SUPER, "super") \ - RS_TOKEN_KEYWORD (TRAIT, "trait") \ - RS_TOKEN_KEYWORD (TRUE_LITERAL, "true") \ - RS_TOKEN_KEYWORD (TRY, "try") /* unused */ \ - RS_TOKEN_KEYWORD (TYPE, "type") \ - RS_TOKEN_KEYWORD (TYPEOF, "typeof") /* unused */ \ - RS_TOKEN_KEYWORD (UNSAFE, "unsafe") \ - RS_TOKEN_KEYWORD (UNSIZED, "unsized") /* unused */ \ - RS_TOKEN_KEYWORD (USE, "use") \ - RS_TOKEN_KEYWORD (VIRTUAL, "virtual") /* unused */ \ - RS_TOKEN_KEYWORD (WHERE, "where") \ - RS_TOKEN_KEYWORD (WHILE, "while") \ - RS_TOKEN_KEYWORD (YIELD, "yield") /* unused */ \ + RS_TOKEN_KEYWORD_2015 (DO, "do") /* unused */ \ + RS_TOKEN_KEYWORD_2018 (DYN, "dyn") \ + RS_TOKEN_KEYWORD_2015 (ELSE, "else") \ + RS_TOKEN_KEYWORD_2015 (ENUM_KW, "enum") \ + RS_TOKEN_KEYWORD_2015 (EXTERN_KW, "extern") \ + RS_TOKEN_KEYWORD_2015 (FALSE_LITERAL, "false") \ + RS_TOKEN_KEYWORD_2015 (FINAL_KW, "final") /* unused */ \ + RS_TOKEN_KEYWORD_2015 (FN_KW, "fn") \ + RS_TOKEN_KEYWORD_2015 (FOR, "for") \ + RS_TOKEN_KEYWORD_2015 (IF, "if") \ + RS_TOKEN_KEYWORD_2015 (IMPL, "impl") \ + RS_TOKEN_KEYWORD_2015 (IN, "in") \ + RS_TOKEN_KEYWORD_2015 (LET, "let") \ + RS_TOKEN_KEYWORD_2015 (LOOP, "loop") \ + RS_TOKEN_KEYWORD_2015 (MACRO, "macro") \ + RS_TOKEN_KEYWORD_2015 (MATCH_KW, "match") \ + RS_TOKEN_KEYWORD_2015 (MOD, "mod") \ + RS_TOKEN_KEYWORD_2015 (MOVE, "move") \ + RS_TOKEN_KEYWORD_2015 (MUT, "mut") \ + RS_TOKEN_KEYWORD_2015 (OVERRIDE_KW, "override") /* unused */ \ + RS_TOKEN_KEYWORD_2015 (PRIV, "priv") /* unused */ \ + RS_TOKEN_KEYWORD_2015 (PUB, "pub") \ + RS_TOKEN_KEYWORD_2015 (REF, "ref") \ + RS_TOKEN_KEYWORD_2015 (RETURN_KW, "return") \ + RS_TOKEN_KEYWORD_2015 ( \ + SELF_ALIAS, "Self") /* mrustc does not treat this as a reserved word*/ \ + RS_TOKEN_KEYWORD_2015 (SELF, "self") \ + RS_TOKEN_KEYWORD_2015 (STATIC_KW, "static") \ + RS_TOKEN_KEYWORD_2015 (STRUCT_KW, "struct") \ + RS_TOKEN_KEYWORD_2015 (SUPER, "super") \ + RS_TOKEN_KEYWORD_2015 (TRAIT, "trait") \ + RS_TOKEN_KEYWORD_2015 (TRUE_LITERAL, "true") \ + RS_TOKEN_KEYWORD_2015 (TRY, "try") /* unused */ \ + RS_TOKEN_KEYWORD_2015 (TYPE, "type") \ + RS_TOKEN_KEYWORD_2015 (TYPEOF, "typeof") /* unused */ \ + RS_TOKEN_KEYWORD_2015 (UNSAFE, "unsafe") \ + RS_TOKEN_KEYWORD_2015 (UNSIZED, "unsized") /* unused */ \ + RS_TOKEN_KEYWORD_2015 (USE, "use") \ + RS_TOKEN_KEYWORD_2015 (VIRTUAL, "virtual") /* unused */ \ + RS_TOKEN_KEYWORD_2015 (WHERE, "where") \ + RS_TOKEN_KEYWORD_2015 (WHILE, "while") \ + RS_TOKEN_KEYWORD_2015 (YIELD, "yield") /* unused */ \ RS_TOKEN (LAST_TOKEN, "") // Contains all token types. Crappy implementation via x-macros. enum TokenId { #define RS_TOKEN(name, _) name, -#define RS_TOKEN_KEYWORD(x, y) RS_TOKEN (x, y) +#define RS_TOKEN_KEYWORD_2015(x, y) RS_TOKEN (x, y) +#define RS_TOKEN_KEYWORD_2018 RS_TOKEN_KEYWORD_2015 RS_TOKEN_LIST -#undef RS_TOKEN_KEYWORD +#undef RS_TOKEN_KEYWORD_2015 +#undef RS_TOKEN_KEYWORD_2018 #undef RS_TOKEN }; diff --git a/gcc/rust/util/rust-keyword-values.cc b/gcc/rust/util/rust-keyword-values.cc index 58a404dc2aa..8aa5ef1371a 100644 --- a/gcc/rust/util/rust-keyword-values.cc +++ b/gcc/rust/util/rust-keyword-values.cc @@ -28,9 +28,11 @@ get_keywords () { std::map m = { #define RS_TOKEN(x, y) -#define RS_TOKEN_KEYWORD(tok, key) {key, tok}, +#define RS_TOKEN_KEYWORD_2015(tok, key) {key, tok}, +#define RS_TOKEN_KEYWORD_2018 RS_TOKEN_KEYWORD_2015 RS_TOKEN_LIST -#undef RS_TOKEN_KEYWORD +#undef RS_TOKEN_KEYWORD_2015 +#undef RS_TOKEN_KEYWORD_2018 #undef RS_TOKEN }; return m; diff --git a/gcc/rust/util/rust-keyword-values.h b/gcc/rust/util/rust-keyword-values.h index 3edae55c76e..769b2100c41 100644 --- a/gcc/rust/util/rust-keyword-values.h +++ b/gcc/rust/util/rust-keyword-values.h @@ -33,9 +33,11 @@ public: // Rust keyword values public: #define RS_TOKEN(x, y) -#define RS_TOKEN_KEYWORD(tok, key) static constexpr auto &tok = key; +#define RS_TOKEN_KEYWORD_2015(tok, key) static constexpr auto &tok = key; +#define RS_TOKEN_KEYWORD_2018 RS_TOKEN_KEYWORD_2015 RS_TOKEN_LIST -#undef RS_TOKEN_KEYWORD +#undef RS_TOKEN_KEYWORD_2015 +#undef RS_TOKEN_KEYWORD_2018 #undef RS_TOKEN }; From patchwork Tue Jan 30 12:06:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892844 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=WTQkG6ZU; 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 4TPPZm3ZBpz23gc for ; Tue, 30 Jan 2024 23:28:00 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 810EA3861838 for ; Tue, 30 Jan 2024 12:27:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by sourceware.org (Postfix) with ESMTPS id 5CA86385801E for ; Tue, 30 Jan 2024 12:11:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5CA86385801E 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 5CA86385801E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616681; cv=none; b=lv8bQVULhC4/R0uSLs5oJmcxCcjZKRPvMoHhLgDIu/B3NdRJKScpgPdQYtbMlcsajNcvGyzLVR4HwB2BxN+elnFlCFGCifa8Nvmso2ziqA84SfRn5wZ0BcnYZTGJ/hleUELQdgPU0De9nLBK35OWi8wJv/slIX/1U7VWST1DolE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616681; c=relaxed/simple; bh=UghAqn1zcs0WVMjM9MHB+crbvJZ1+qrzhJDy7ZQ5QqE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=LAhUMye5teArP2GAc3C2GFkVcv4N9xl1ncx5P/e8Kqu1pLNsBQL6USAzSDeBMQ4CWjd18tGZZgGbmh4vNDyxtu/FgnveNlZNETKEs7F+6BQmcQszXj0mjhxZevf5paKgJ3FxtA2+MWoZ3VBSaof1xBqHw9PwF431SNFoWlW1YS4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-5102b00c2cdso3280356e87.3 for ; Tue, 30 Jan 2024 04:11:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616669; x=1707221469; 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=zAmgzH0sDhe3iFA+EwRaChPi+cFzcmlo8h9H+LYIMVQ=; b=WTQkG6ZUKYNytC10xVFr9CmEEXPWkj9CuKNaV8qZrbBAmHcQQ6LaJ3hM4ZIGGisNnC Dwfg2z2bQiInG77bBVTrQxUFjs1fX0tNd5hKHkJ/BJEN6mBQWgA7Y/wlCtbWTukZhH01 PlRA91TII3pO+s6+WNEGavkemnqAUMFa/x9o6KS+oJLOJasQVrmr75JiaTPzcprWFKuj LaEv9EX/iCvdzDq59YmNPq3HTxZoxdv8LT9+zwxZEaAJU5r/KxbPiqDntJAzKZccKri0 VLWtNy3jT3DQI/a4MMxbrUF974z/8On73Nnfz4zy+OtjV3ZuasYU5Auu8fusFb6uFgdW xlGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616669; x=1707221469; 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=zAmgzH0sDhe3iFA+EwRaChPi+cFzcmlo8h9H+LYIMVQ=; b=RDmkB5DLWEKSO1G62u4KMAWXhirXt5Ny4MoYoxlHkA0Nu/SDGFJVGrPJGMVY2RMjh9 r/IR503a21pa8ejw/kmQEe24E5YQU0YZXTIoJUwKJzp17OMt7totCjjW8t/IzPaqHiVt 7fgTNXZ7hoV2n0beVevbLT5Rej+5pZKK2uCfN/ptbh4qMIa0JPdkmaI30Io7UoOXnSyx p2UZUVvDJ7U0BsP6s9xNwF+AyYouCqEwE2GzqLC6/tbCeQobWut5dHDgiXvvzr53iKJn h2k9v+c2/f6mfz7nI0Q/4fey/f6Pbec40ndzuDqfR3iqknf2qi4A8dQ2syEJWaGBj0U9 wMiA== X-Gm-Message-State: AOJu0YzwUvz7DF0bcrs292xT0XtAI8uzImYpvcpedTrHFSCCT8LLTxRS 8/gGlfcM0pNHbJ+86DLPsFozQ+fSnkXzvIBpgXnytbewatzRkKMifZ6FRIrzKVJQg4Vq5lWzXhJ KQA== X-Google-Smtp-Source: AGHT+IHO8GFSKqvQ1riDla6q+kGCSRSjq1iOUKYyP28bDGCMQ4V3XdSih172zU5QfQlJsTtvMYlwyg== X-Received: by 2002:a05:6512:e8f:b0:511:f41:6144 with SMTP id bi15-20020a0565120e8f00b005110f416144mr4988694lfb.61.1706616669163; Tue, 30 Jan 2024 04:11:09 -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.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:08 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 026/101] gccrs: Treat underscore as a keyword Date: Tue, 30 Jan 2024 13:06:42 +0100 Message-ID: <20240130121026.807464-29-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: Pierre-Emmanuel Patry Make the underscore token a 2015 keyword. gcc/rust/ChangeLog: * lex/rust-token.h (enum PrimitiveCoreType): Change macro for underscore in token list. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/lex/rust-token.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gcc/rust/lex/rust-token.h b/gcc/rust/lex/rust-token.h index df321000511..401452f515c 100644 --- a/gcc/rust/lex/rust-token.h +++ b/gcc/rust/lex/rust-token.h @@ -120,8 +120,6 @@ enum PrimitiveCoreType RS_TOKEN (SCOPE_RESOLUTION, "::") /* dodgy */ \ RS_TOKEN (SINGLE_QUOTE, "'") /* should i differentiate from lifetime? */ \ RS_TOKEN (DOUBLE_QUOTE, "\"") \ - RS_TOKEN (UNDERSCORE, \ - "_") /* TODO: treat as reserved word like mrustc instead? */ \ RS_TOKEN (IDENTIFIER, "identifier") \ RS_TOKEN (INT_LITERAL, \ "integer literal") /* do different int and float types need \ @@ -194,6 +192,7 @@ enum PrimitiveCoreType RS_TOKEN_KEYWORD_2015 (TRY, "try") /* unused */ \ RS_TOKEN_KEYWORD_2015 (TYPE, "type") \ RS_TOKEN_KEYWORD_2015 (TYPEOF, "typeof") /* unused */ \ + RS_TOKEN_KEYWORD_2015 (UNDERSCORE, "_") \ RS_TOKEN_KEYWORD_2015 (UNSAFE, "unsafe") \ RS_TOKEN_KEYWORD_2015 (UNSIZED, "unsized") /* unused */ \ RS_TOKEN_KEYWORD_2015 (USE, "use") \ From patchwork Tue Jan 30 12:06:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892861 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=XCqtFaCo; 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 4TPPgM5mkFz23fD for ; Tue, 30 Jan 2024 23:31:59 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CBF2D3870C0C for ; Tue, 30 Jan 2024 12:31:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 3EAFD38582AA for ; Tue, 30 Jan 2024 12:11:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3EAFD38582AA 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 3EAFD38582AA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::430 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616683; cv=none; b=SxSabLYeABS3rbmpNmgFytZKfW+JpX8X7lJfElfHVI1Nu83PrOxDRIuLhrvMBW1H7yahL9d90B7RZHl6CVkTEhJeuLRRiNhD1vE6mAva3gjy6d/UmalMDtNvgm5r0xuX2qlOvK3MadCrXzFc+gZtzsFyX0uBsAxe+eepx55iOhM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616683; c=relaxed/simple; bh=R9itsR0XP/iDPx10OHKKEJYfvP6aVrqNn31/lYLcvK0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=JOj6z8MQr3Db+FFblebEVdfZknwO2iLpQ0VgSoiI6PC5SV8s1y483VF6XqA4BMg94nWSRLLvJrgpIqayOnc/m3hrcG0og3p1FHSEjjOY2lyiWOR1IIu9TnzKzXFfVIGwRsxr8Up91rBBgQU0he4YnsvmLr+wL+xFFBxqmVz/X6A= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-33aef64f702so1046732f8f.3 for ; Tue, 30 Jan 2024 04:11:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616670; x=1707221470; 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=bj0J6+uMbDfJg4olQXCEQYNbH9pS7KC5U0NlOFXweRY=; b=XCqtFaCooFs7OHhnUJ4PH12IJCs5lEbh+cLZVae/X2jAEbxLeTa2xPi0bAjm0ZjPme oZ0pantMEhjiVEf8/vpjAkW7iCyt74PZzvsfx8FYYmzgoz6ldzqylg+RnI57J5I8blYe l8VDmThSfjteROLLIrFnYBq03YRYFnfU80FkOkqJmzKvLY5NdAQP237JdrFxHjtHdan4 iatY0gWX/ELWKbCLpQAigR8y3Il+HYaZ+pqGL7Iiyzx0NNxiRtuRuGiCdZfD543W4AN3 xSc7L4NLVHRfEA6otXmtrtn+qy+lBISTGe0O4MWr1U8ZY4EYpUIJH3/kF1Vvk+9r7XS/ yp/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616670; x=1707221470; 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=bj0J6+uMbDfJg4olQXCEQYNbH9pS7KC5U0NlOFXweRY=; b=VsX/L+a/y6VzUDBfqwkGTwQqgQOmWgULNw9UKtvLx84Yf/SsBYwOUko5cQtyQl8KEL 8EyfBD4MNyqrWDpCsdxBeFA2bIqr84jDtegkuCwzDBR3uyd7fa/ytG1y78fMXmxs/LVk wTgSWoNz3OQ2QJ5UrIiX3H1kvR9fR7305TZPSy6Zzkxqge/mAFcXyx6bzTyGrA9J/zLC MPe54V9IsKIuUyM6e/smH385sDXijO4JzlCrbRq/wStIPByzq/S8xie4VFbkFL5kFlgH GLOPN37Whs4kXdixkLiZrqhOayUdtF3STBIpd+h3hRT0mFbLjHkDR7SZiR6gVgTkMVFe PWHg== X-Gm-Message-State: AOJu0YyP6s+cYmsJjaWxXXfzfX+BSzV0V3+3WqoBvwzSJjhx8610JWDG OxYIpr48TqveNqlwqLhIAKXqLNzQt8NqefXAm7i/jAZVCe3fs1kgasvr6uDM3xepy8HDEAh+imL Z3g== X-Google-Smtp-Source: AGHT+IFSLWkzMTu1uMwaxUHSYMDBNvquJImtaFa3R55mEAJ2s8kUIPxQr82Yz6DJYmwztL/V5dEvIQ== X-Received: by 2002:adf:f684:0:b0:33a:ead8:40bd with SMTP id v4-20020adff684000000b0033aead840bdmr4244710wrp.47.1706616670283; Tue, 30 Jan 2024 04:11:10 -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.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:09 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 027/101] gccrs: Add await keyword Date: Tue, 30 Jan 2024 13:06:43 +0100 Message-ID: <20240130121026.807464-30-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: Pierre-Emmanuel Patry The 2018 edition await keyword was missing from the keyword list. gcc/rust/ChangeLog: * lex/rust-token.h (enum PrimitiveCoreType): Add await keyword definition. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/lex/rust-token.h | 1 + 1 file changed, 1 insertion(+) diff --git a/gcc/rust/lex/rust-token.h b/gcc/rust/lex/rust-token.h index 401452f515c..e38c3cf9943 100644 --- a/gcc/rust/lex/rust-token.h +++ b/gcc/rust/lex/rust-token.h @@ -150,6 +150,7 @@ enum PrimitiveCoreType RS_TOKEN_KEYWORD_2015 (AS, "as") \ RS_TOKEN_KEYWORD_2018 (ASYNC, "async") /* unused */ \ RS_TOKEN_KEYWORD_2015 (AUTO, "auto") \ + RS_TOKEN_KEYWORD_2018 (AWAIT, "await") \ RS_TOKEN_KEYWORD_2015 (BECOME, "become") /* unused */ \ RS_TOKEN_KEYWORD_2015 (BOX, "box") /* unused */ \ RS_TOKEN_KEYWORD_2015 (BREAK, "break") \ From patchwork Tue Jan 30 12:06:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892876 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=SGWM9ph0; 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 4TPPlr4vVJz23dQ for ; Tue, 30 Jan 2024 23:35:52 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A0ED13830B7C for ; Tue, 30 Jan 2024 12:35:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id EC3BF3858038 for ; Tue, 30 Jan 2024 12:11:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC3BF3858038 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 EC3BF3858038 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616686; cv=none; b=R62KFNy+sU93CMp6ETp+Z/MPTSn4oSBgwlvPvpMA0Ju9tTrieYHjHb4lPmiqvQyQlwbE6/zTRcSpObHUnC2owG6glsDSXvFiG839UNalFc51m2yBJtfPbl9RbIiWa+db5mm5OpwLDeiI+Dv9iYFC6YwWi1nwAgSojLzyESxQMAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616686; c=relaxed/simple; bh=e7MDRmHwX+8o9Y7E0b/i7G8FA2sKcmFCz9TYMesq15U=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=t73LfsLCu9YMmH9rHWD9k2rn7QbDadgYDSKvn8utVRQ0fPyx3RXK49V8GrLhcGlRS490GpTftm36/9sbWXfTyU1SeBTZTHQXh0nN5iPMdBgQJJTGkWJwh6xYugJzthD/QLXc7p8pS7rzEK1rFsgz6hrJZHCaL0l9V/RMOibgGmo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-33aea66a31cso1188615f8f.1 for ; Tue, 30 Jan 2024 04:11:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616671; x=1707221471; 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=Lm0Um1BuS8z6KeEky56sUOYmtudG6PQX5VEvTBMwogU=; b=SGWM9ph0RBS9eXmXHHxpVrPIuSlovZ6eAb5AdepSLCc74d0y59Q65JmkIjvU1C6YWf OQ+nxfaOmxhUwVAX2mnC9zp3XD6g1fuANTExMQIEE3xl5nIBnjMKMO+0Tv/njuW+WMwR aA5FqWwEjDUyG+GbI1kom9w0x6WjiLPwgixl9TImsHuN9R8juzgSbO7eBkXE+ocBgzzX LNFYJX4mTZTEuDPTDYvXL87N/vPeoEzGXPeJ9NsZfWVEkL1Sn3iH570X5wctXx9Gx0dr UdufehdDHEibSX7KoRIXEpG0CAe8iOkY6+5WcGDVWI1fcxlZ03dowe7Uvo3b/dlRnEM2 md5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616671; x=1707221471; 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=Lm0Um1BuS8z6KeEky56sUOYmtudG6PQX5VEvTBMwogU=; b=JnOD/hqZ0A9YQPeQFTk6mXGiMTdzsdNhEQecmZCCvltA6CyGBkuPSdcfjfilLtCg0b NGXVNbJz20u2Ic0T2KGms4F7hDypH0kiScH2xiqjwEuDDlsr0WzgiF/IH/xkqFynLc71 yqAlcW9+3m/fjJjSPJU8h8to0roc1PJqDpntF7rJ272DVWqgTB5etuwv9Kz7jxRa8MsW x71d/7Z7e8FpxGo4xJdM7FPOTdRblF81SGyTwT/QVCrPANgduamFWf4qXanxTmphGiLU +1fFeOZ3ANSlAC8Lnh7IuAhfWQ1yRzLEjR4ja6sITKYeBZgUNje6BmCCm5O51UM+AdIW I+bA== X-Gm-Message-State: AOJu0YzG1TsUYQuhNarU2TUvU5BYDiqfPvApUq5SHzclB2RhuSmCnW5Z zEXNJX4WntPoKkgOtkJ9bFvYITAXArjEfq6jgACk+t214S7zcMtjAbxpFb2FxbRrmP77iyGQf+3 yxQ== X-Google-Smtp-Source: AGHT+IEknZ2eI2jk03R6lmV6y1yls/3wC0AhPvVNV25RoNLzCGIpHh+isdL2zWsWWiYk2K1RGtdNIw== X-Received: by 2002:a05:6000:1a8c:b0:33a:ed47:2858 with SMTP id f12-20020a0560001a8c00b0033aed472858mr4904709wry.63.1706616671512; Tue, 30 Jan 2024 04:11:11 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:10 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 028/101] gccrs: Replace some keyword raw values Date: Tue, 30 Jan 2024 13:06:44 +0100 Message-ID: <20240130121026.807464-31-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, KAM_SHORT, 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: Pierre-Emmanuel Patry Raw values cannot be understood easily by most tools. This commit replace some raw values with their variable counterpart. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Replace raw value with keyword call. * ast/rust-ast.h: Likewise. * parse/rust-parse-impl.h (Parser::parse_path_ident_segment): Likewise. (Parser::parse_macro_match_fragment): Likewise. (Parser::parse_extern_crate): Likewise. (Parser::parse_use_tree): Likewise. (Parser::parse_const_item): Likewise. (Parser::parse_literal_expr): Likewise. (Parser::parse_maybe_named_param): Likewise. (Parser::parse_pattern_no_alt): Likewise. (Parser::left_denotation): Likewise. (Parser::parse_path_in_expression_pratt): Likewise. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/ast/rust-ast-collector.cc | 13 ++++---- gcc/rust/ast/rust-ast.h | 24 ++++++++++---- gcc/rust/parse/rust-parse-impl.h | 52 +++++++++++++++++------------- 3 files changed, 53 insertions(+), 36 deletions(-) diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc index 8f394e595ed..5b12875c349 100644 --- a/gcc/rust/ast/rust-ast-collector.cc +++ b/gcc/rust/ast/rust-ast-collector.cc @@ -17,6 +17,7 @@ // . #include "rust-ast-collector.h" #include "rust-item.h" +#include "rust-keyword-values.h" namespace Rust { namespace AST { @@ -461,11 +462,11 @@ TokenCollector::visit (Lifetime &lifetime) break; case Lifetime::LifetimeType::STATIC: push (Rust::Token::make_lifetime (lifetime.get_locus (), - std::move ("static"))); + Values::Keywords::STATIC_KW)); break; case Lifetime::LifetimeType::WILDCARD: - push ( - Rust::Token::make_lifetime (lifetime.get_locus (), std::move ("_"))); + push (Rust::Token::make_lifetime (lifetime.get_locus (), + Values::Keywords::UNDERSCORE)); break; } } @@ -787,9 +788,9 @@ TokenCollector::visit (Literal &lit, location_t locus) lit.get_type_hint ())); break; case Literal::LitType::BOOL: { - if (value == "false") + if (value == Values::Keywords::FALSE_LITERAL) push (Rust::Token::make (FALSE_LITERAL, locus)); - else if (value == "true") + else if (value == Values::Keywords::TRUE_LITERAL) push (Rust::Token::make (TRUE_LITERAL, locus)); else rust_unreachable (); // Not a boolean @@ -1484,7 +1485,7 @@ TokenCollector::visit (AwaitExpr &expr) visit (expr.get_awaited_expr ()); push (Rust::Token::make (DOT, expr.get_locus ())); // TODO: Check status of await keyword (Context dependant ?) - push (Rust::Token::make_identifier (UNDEF_LOCATION, "await")); + push (Rust::Token::make_identifier (UNDEF_LOCATION, Values::Keywords::AWAIT)); } void diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 47c02d6ac8b..4049e4d2607 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -25,6 +25,7 @@ #include "rust-token.h" #include "rust-location.h" #include "rust-diagnostics.h" +#include "rust-keyword-values.h" namespace Rust { // TODO: remove typedefs and make actual types for these @@ -393,14 +394,20 @@ public: const std::string &get_segment_name () const { return segment_name; } bool is_super_path_seg () const { - return as_string ().compare ("super") == 0; + return as_string ().compare (Values::Keywords::SUPER) == 0; } bool is_crate_path_seg () const { - return as_string ().compare ("crate") == 0; + return as_string ().compare (Values::Keywords::CRATE) == 0; + } + bool is_lower_self_seg () const + { + return as_string ().compare (Values::Keywords::SELF) == 0; + } + bool is_big_self () const + { + return as_string ().compare (Values::Keywords::SELF_ALIAS) == 0; } - bool is_lower_self_seg () const { return as_string ().compare ("self") == 0; } - bool is_big_self () const { return as_string ().compare ("Self") == 0; } }; // A simple path without generic or type arguments @@ -562,7 +569,8 @@ public: location_t crate_vis_location) { return Visibility (PUB_CRATE, - SimplePath::from_str ("crate", crate_tok_location), + SimplePath::from_str (Values::Keywords::CRATE, + crate_tok_location), crate_vis_location); } @@ -571,7 +579,8 @@ public: location_t self_vis_location) { return Visibility (PUB_SELF, - SimplePath::from_str ("self", self_tok_location), + SimplePath::from_str (Values::Keywords::SELF, + self_tok_location), self_vis_location); } @@ -580,7 +589,8 @@ public: location_t super_vis_location) { return Visibility (PUB_SUPER, - SimplePath::from_str ("super", super_tok_location), + SimplePath::from_str (Values::Keywords::SUPER, + super_tok_location), super_vis_location); } diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 8b006142b16..28659060568 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -743,19 +743,20 @@ Parser::parse_path_ident_segment () case SUPER: lexer.skip_token (); - return AST::PathIdentSegment ("super", t->get_locus ()); + return AST::PathIdentSegment (Values::Keywords::SUPER, t->get_locus ()); case SELF: lexer.skip_token (); - return AST::PathIdentSegment ("self", t->get_locus ()); + return AST::PathIdentSegment (Values::Keywords::SELF, t->get_locus ()); case SELF_ALIAS: lexer.skip_token (); - return AST::PathIdentSegment ("Self", t->get_locus ()); + return AST::PathIdentSegment (Values::Keywords::SELF_ALIAS, + t->get_locus ()); case CRATE: lexer.skip_token (); - return AST::PathIdentSegment ("crate", t->get_locus ()); + return AST::PathIdentSegment (Values::Keywords::CRATE, t->get_locus ()); case DOLLAR_SIGN: if (lexer.peek_token (1)->get_id () == CRATE) { @@ -2141,7 +2142,7 @@ Parser::parse_macro_match_fragment () Identifier ident; auto identifier = lexer.peek_token (); if (identifier->get_id () == UNDERSCORE) - ident = {"_", identifier->get_locus ()}; + ident = {Values::Keywords::UNDERSCORE, identifier->get_locus ()}; else ident = {identifier}; @@ -2506,7 +2507,7 @@ Parser::parse_extern_crate (AST::Visibility vis, lexer.skip_token (); break; case SELF: - crate_name = "self"; + crate_name = Values::Keywords::SELF; lexer.skip_token (); break; default: @@ -2547,7 +2548,7 @@ Parser::parse_extern_crate (AST::Visibility vis, lexer.skip_token (); break; case UNDERSCORE: - as_name = "_"; + as_name = Values::Keywords::UNDERSCORE; lexer.skip_token (); break; default: @@ -2806,7 +2807,8 @@ Parser::parse_use_tree () return std::unique_ptr ( new AST::UseTreeRebind (AST::UseTreeRebind::WILDCARD, std::move (path), locus, - {"_", t->get_locus ()})); + {Values::Keywords::UNDERSCORE, + t->get_locus ()})); default: add_error (Error ( t->get_locus (), @@ -4788,7 +4790,7 @@ Parser::parse_const_item (AST::Visibility vis, * wildcard */ const_TokenPtr ident_tok = lexer.peek_token (); // make default identifier the underscore wildcard one - std::string ident ("_"); + std::string ident (Values::Keywords::UNDERSCORE); switch (ident_tok->get_id ()) { case IDENTIFIER: @@ -7640,12 +7642,12 @@ Parser::parse_literal_expr (AST::AttrVec outer_attrs) // use true and false keywords rather than "bool literal" Rust terminology case TRUE_LITERAL: type = AST::Literal::BOOL; - literal_value = "true"; + literal_value = Values::Keywords::TRUE_LITERAL; lexer.skip_token (); break; case FALSE_LITERAL: type = AST::Literal::BOOL; - literal_value = "false"; + literal_value = Values::Keywords::FALSE_LITERAL; lexer.skip_token (); break; default: @@ -9654,7 +9656,7 @@ Parser::parse_maybe_named_param (AST::AttrVec outer_attrs) else if (current->get_id () == UNDERSCORE && next->get_id () == COLON) { // wildcard param - name = {"_", current->get_locus ()}; + name = {Values::Keywords::UNDERSCORE, current->get_locus ()}; kind = AST::MaybeNamedParam::WILDCARD; lexer.skip_token (1); } @@ -10548,12 +10550,14 @@ Parser::parse_pattern_no_alt () case TRUE_LITERAL: lexer.skip_token (); return std::unique_ptr ( - new AST::LiteralPattern ("true", AST::Literal::BOOL, t->get_locus (), + new AST::LiteralPattern (Values::Keywords::TRUE_LITERAL, + AST::Literal::BOOL, t->get_locus (), t->get_type_hint ())); case FALSE_LITERAL: lexer.skip_token (); return std::unique_ptr ( - new AST::LiteralPattern ("false", AST::Literal::BOOL, t->get_locus (), + new AST::LiteralPattern (Values::Keywords::FALSE_LITERAL, + AST::Literal::BOOL, t->get_locus (), t->get_type_hint ())); case CHAR_LITERAL: case BYTE_CHAR_LITERAL: @@ -12383,12 +12387,14 @@ Parser::null_denotation_not_path ( tok->get_type_hint (), {}, tok->get_locus ())); case TRUE_LITERAL: return std::unique_ptr ( - new AST::LiteralExpr ("true", AST::Literal::BOOL, tok->get_type_hint (), - {}, tok->get_locus ())); + new AST::LiteralExpr (Values::Keywords::TRUE_LITERAL, + AST::Literal::BOOL, tok->get_type_hint (), {}, + tok->get_locus ())); case FALSE_LITERAL: return std::unique_ptr ( - new AST::LiteralExpr ("false", AST::Literal::BOOL, - tok->get_type_hint (), {}, tok->get_locus ())); + new AST::LiteralExpr (Values::Keywords::FALSE_LITERAL, + AST::Literal::BOOL, tok->get_type_hint (), {}, + tok->get_locus ())); case LEFT_PAREN: return parse_grouped_or_tuple_expr (std::move (outer_attrs), tok->get_locus ()); @@ -12877,7 +12883,7 @@ Parser::left_denotation (const_TokenPtr tok, const_TokenPtr next_tok = lexer.peek_token (); if (next_tok->get_id () == IDENTIFIER - && next_tok->get_str () == "await") + && next_tok->get_str () == Values::Keywords::AWAIT) { // await expression return parse_await_expr (tok, std::move (left), @@ -14367,16 +14373,16 @@ Parser::parse_path_in_expression_pratt (const_TokenPtr tok) initial_str = tok->get_str (); break; case SUPER: - initial_str = "super"; + initial_str = Values::Keywords::SUPER; break; case SELF: - initial_str = "self"; + initial_str = Values::Keywords::SELF; break; case SELF_ALIAS: - initial_str = "Self"; + initial_str = Values::Keywords::SELF_ALIAS; break; case CRATE: - initial_str = "crate"; + initial_str = Values::Keywords::CRATE; break; case DOLLAR_SIGN: if (lexer.peek_token ()->get_id () == CRATE) From patchwork Tue Jan 30 12:06:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892866 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=WhvYiUsr; 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 4TPPj21tG1z23fD for ; Tue, 30 Jan 2024 23:33:26 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 393173875DF3 for ; Tue, 30 Jan 2024 12:33:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 2CB2A3857C45 for ; Tue, 30 Jan 2024 12:11:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2CB2A3857C45 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 2CB2A3857C45 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::431 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616683; cv=none; b=FTTm+eIEMczYLVt9SI/evzUtcr3wN28beOZBfK8hxbDtymI0qGBOJWx+LW7JffMAewqNPkz39wW25Qnp2hLwwcWJt1OLDoXQSbXDVJtnwrttTmAZ8gcOu1xw5Q/WMamsLZSqb1tRk2rYzcLpvCuM7BesLa2GrJG8q83MxLdzmf0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616683; c=relaxed/simple; bh=1KM3XOTx+OBcvNua9Q22Alm6XZ8f/oURA1H2XudK80E=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=dswR/Itxc9xoZ1XSNsXt3qioH9j4JtpI83bv6X2AV2YZzMepX7BptKZ7WrMQN0IznlTfzcXOoTwjZ3lBbvGzGzlKyK2/6QeHM8qux4CqGlz9eE8uFi457fwLAdaF/Ddn8McldeyWYZc76tIF8j3j+PCkx26KleiD4k5CvmtlhJQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-33ae51f8111so1919809f8f.2 for ; Tue, 30 Jan 2024 04:11:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616672; x=1707221472; 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=1hI5ul/nN/WJfM/4k9bug7luwoQK7BhQuffp06BUC/0=; b=WhvYiUsrhiePsiVChXhEDl984fdKOLstfJtXfVCoX7IUdir7/iPKEb87w4dTj/W08O oSXFNHPxALqt4fN9GKFiEFiqIRdvpzVSxjJxaToXqLljUIaDsysrcx6UqOytD9Oi7E55 fEbMqmU2b6p7JKJ6VS0YK8t5FnS+MJk7MNXfXuqdzPUYqFZ+zYK6fL+PgLdLwfunmJ79 Pw3Ww7pXspIchyV59xqhnTQ0D1LGuKT9F0yxg20DTIHS8XgfREL13T7oTf7SW5Dh1tab JBbatIDec+bluU17c6kOb9PE1RZ7XoDgZXd3AI+Mt/CB6qfypTBe7wahKArp3z931HIM 9keg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616672; x=1707221472; 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=1hI5ul/nN/WJfM/4k9bug7luwoQK7BhQuffp06BUC/0=; b=tLvl6QUMjXryUAo+WUiWCC5/GuunA2jgeV+G+LipYKF+4YRPl58BXbi4jyDWz2wM3t 8FY5WUDIYgDT4umfGs9iaVUiOvUZijwAYa8d4HKW9VVrfW24JCqzMYc69VkPRDPXKBn0 tI0mLXHUmBg/UEYX8RxVzTbmaX2uveYz0Wim7SWXSKMNjWuBvWKR7L9ADrPdQQgpJPX7 0QHA5SLAJZy4vBjTUVwbPtYR16Z73mK4M10oyC661/yZP4l/mhNfxZFXEYvRmxQ4RLBH lSNJDf1U5o/ONPAExF+Z5doL5ms4mQjfrNWZexGCdrCXc1di7NU58lgn5UFrP0qPV1eS hJtQ== X-Gm-Message-State: AOJu0YxUtmRbuf+bjtDwD4XUI5ncAlsoCwyJyb9DIJ6A/d6CPi5t8kqR +eup9bkXlhRZaUHN7h9iT4JGoEZ9DtfEtEmXlWqK0LHjsinn9Z+ZtKXjVX+feeOfofHLLHuA5A9 Y9Q== X-Google-Smtp-Source: AGHT+IFaWiS3fy4PQNSl0sVhrofmki4uNoSITVFsRJDrPif5+AwnAwImlQ07RHYa3t5wAkziYoxE/w== X-Received: by 2002:adf:cd10:0:b0:33a:e52b:b70a with SMTP id w16-20020adfcd10000000b0033ae52bb70amr5674810wrm.52.1706616672281; Tue, 30 Jan 2024 04:11:12 -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.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:11 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 029/101] gccrs: Add a list of weak keyword Date: Tue, 30 Jan 2024 13:06:45 +0100 Message-ID: <20240130121026.807464-32-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: Pierre-Emmanuel Patry Retrieving a weak keyword value is done using raw values. Introducing a list of weak keywords means this could change. gcc/rust/ChangeLog: * util/rust-keyword-values.h (class WeakKeywords): Add new class with weak keyword constexpr. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/util/rust-keyword-values.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gcc/rust/util/rust-keyword-values.h b/gcc/rust/util/rust-keyword-values.h index 769b2100c41..4a6f1df525d 100644 --- a/gcc/rust/util/rust-keyword-values.h +++ b/gcc/rust/util/rust-keyword-values.h @@ -41,6 +41,20 @@ public: #undef RS_TOKEN }; +class WeakKeywords +{ +public: + static constexpr auto &AUTO = "auto"; + static constexpr auto &BUILTIN = "builtin"; + static constexpr auto &CATCH = "catch"; + static constexpr auto &DEFAULT = "default"; + static constexpr auto &GEN = "gen"; + static constexpr auto &MACRO_RULES = "macro_rules"; + static constexpr auto &RAW = "raw"; + static constexpr auto &UNION = "union"; + static constexpr auto &YEET = "yeet"; +}; + } // namespace Values } // namespace Rust From patchwork Tue Jan 30 12:06:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892836 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=ddh4xPKA; 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 4TPPXY2Xn9z23gZ for ; Tue, 30 Jan 2024 23:26:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 919293860744 for ; Tue, 30 Jan 2024 12:26:02 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by sourceware.org (Postfix) with ESMTPS id 0910F3858015 for ; Tue, 30 Jan 2024 12:11:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0910F3858015 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 0910F3858015 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::232 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616690; cv=none; b=dQOzoHK1EXvnF3TN7wTM/KqCMCGIH1qBIoralqa7JvVhMMJREAW1MOPDeGSPFr5Vor+XvSALkZCRjDlUgcoYG3fEOpLydvNgGrh0SXf7IM6ksGIr5+/6DXTOL0u+7LcKEkf9pElGcrgLVzvqlcgcfx1V5MpHbKuCCSvwNIpT7zI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616690; c=relaxed/simple; bh=n0qlva23R/mdGvhF3Fg8aIAaJq/ktFxYKViE1JDxF2g=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=mVqtdnMYDoefBGJ6q77GZ61H2A+qSqvnUVX6KT+lDPUBCdp/MamS95ecSC8CeD6Fjjo4D2GOA251I0KDesN3gaN2PpM4++vA1lOlex6fV9Qi7YXinL1boa70Ed0c1t0gaE3O34cwQtwhlCayy81eTEkxUZwuCM2WMh6fQB/qV7M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2cf2fdd518bso34998721fa.1 for ; Tue, 30 Jan 2024 04:11:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616674; x=1707221474; 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=pM95hFU5oiyqIxzv4O4c5hGB3ZdxfRx9o5up0a86vxw=; b=ddh4xPKAr7R+8Ns8sOvmB81BWR6W0e7OPm8g9v9Gx1SNEKMyvhdrGEaYSFyWR/VYCY yFpbLDtchh9maV7yVwpTN8H+ZmHrnSX0QuoNan2CG17ItcnAcxQ89WZVrCYoeKnszLqO RFKaUPd8fi91uZcqQN/qXZZBeooKGPp2EUJ9EtfcuUlypHYShlXJ+AcpQwCAkEmMm+A2 iFjDDEq/3Aui/7uIkmjiYEGnB3y0rzHA+FS8LvJhx57wvK+PhkRWIJGmLkkMJVwZa2KU aLaQeZ8nEMvk9PQJ9M9wpPJVXMsfQRxnsTVjAqBXgDO9InjuW6exE0z9XiOYqv7A9xpC mSwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616674; x=1707221474; 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=pM95hFU5oiyqIxzv4O4c5hGB3ZdxfRx9o5up0a86vxw=; b=pUR8dfoRvsAX+NEPIwice7PxWKZldr6uRcqBbKRk+G2LU35ANFdns1jeXkqal58pEV shMx07AtaFB7xtucLDz/kV3Tb3Zmo8kduM9oJdVmvJ5aOj6P1ymQM4JE+qDrDv6TG2oY C5DbW9mQ+R/Zjs7jOmcTssP22RDYbMgfUUsxnZmkbZ5o0gIwpQ97ZbJQLTc2zmor/eU1 YeApDxR/Qyg4ZONHMM6saYurc4Zl9K8XIT6A00cfP/EDEZ27eO69LIbyXrTLNVHAPJZv 3I4y1NXVlD2cfQS/J97c/7kZCXo31Gna1xfR8Qt/K+bJeLB42yvybiQ9nQwXjobiN+kk Xlgg== X-Gm-Message-State: AOJu0Yzue+KjgUTNDR34fOR6x5fTpiMlHrdpHzBjCI2C6sR7JGxJRZ2A Vm+Dmldl8glaR3kK8mUDfFs48ywNfaWcP4zr1GTzEWfwj7mDi0NQbUzl6Nnly1Pb5T74jCMIjzH ImA== X-Google-Smtp-Source: AGHT+IHTjAEq06qeRkee6iw/Lt9CIvJTYomO5flcZ1sEMxFghMKEeczKwR40R5Rz0GuTb1sYQAAK5A== X-Received: by 2002:a2e:9b8e:0:b0:2ce:c0f:4b6 with SMTP id z14-20020a2e9b8e000000b002ce0c0f04b6mr5597708lji.39.1706616673438; Tue, 30 Jan 2024 04:11:13 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:12 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 030/101] gccrs: Replace some weak keyword raw value with constexpr Date: Tue, 30 Jan 2024 13:06:46 +0100 Message-ID: <20240130121026.807464-33-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: Pierre-Emmanuel Patry Raw values may have typos or contain error, replacing those will improve the codebase. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Replace raw value. * parse/rust-parse-impl.h (Parser::is_macro_rules_def): Likewise. (Parser::parse_item): Likewise. (Parser::parse_vis_item): Likewise. (Parser::parse_macro_rules_def): Likewise. (Parser::parse_union): Likewise. (Parser::parse_trait_impl_item): Likewise. (Parser::parse_stmt): Likewise. (Parser::parse_stmt_or_expr): Likewise. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/ast/rust-ast-collector.cc | 6 ++++-- gcc/rust/parse/rust-parse-impl.h | 24 +++++++++++++----------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc index 5b12875c349..3e3a959578e 100644 --- a/gcc/rust/ast/rust-ast-collector.cc +++ b/gcc/rust/ast/rust-ast-collector.cc @@ -1875,7 +1875,8 @@ TokenCollector::visit (Union &union_item) { visit_items_as_lines (union_item.get_outer_attrs ()); auto id = union_item.get_identifier ().as_string (); - push (Rust::Token::make_identifier (union_item.get_locus (), "union")); + push (Rust::Token::make_identifier (union_item.get_locus (), + Values::WeakKeywords::UNION)); push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (id))); if (union_item.has_generics ()) @@ -2256,7 +2257,8 @@ TokenCollector::visit (MacroRulesDefinition &rules_def) auto rule_name = rules_def.get_rule_name ().as_string (); - push (Rust::Token::make_identifier (rules_def.get_locus (), "macro_rules")); + push (Rust::Token::make_identifier (rules_def.get_locus (), + Values::WeakKeywords::MACRO_RULES)); push (Rust::Token::make (EXCLAM, UNDEF_LOCATION)); push (Rust::Token::make_identifier (UNDEF_LOCATION, std::move (rule_name))); diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 28659060568..37eddc1b753 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -1085,7 +1085,7 @@ Parser::is_macro_rules_def (const_TokenPtr t) bool allowed_macro_name = (macro_name == IDENTIFIER || macro_name == TRY); - return t->get_str () == "macro_rules" + return t->get_str () == Values::WeakKeywords::MACRO_RULES && lexer.peek_token (1)->get_id () == EXCLAM && allowed_macro_name; } @@ -1146,13 +1146,13 @@ Parser::parse_item (bool called_from_statement) // crappy hack to do union "keyword" case IDENTIFIER: // TODO: ensure std::string and literal comparison works - if (t->get_str () == "union" + if (t->get_str () == Values::WeakKeywords::UNION && lexer.peek_token (1)->get_id () == IDENTIFIER) { return parse_vis_item (std::move (outer_attrs)); // or should this go straight to parsing union? } - else if (t->get_str () == "default" + else if (t->get_str () == Values::WeakKeywords::DEFAULT && lexer.peek_token (1)->get_id () != EXCLAM) { add_error (Error (t->get_locus (), @@ -1357,7 +1357,7 @@ Parser::parse_vis_item (AST::AttrVec outer_attrs) // TODO: implement union keyword but not really because of // context-dependence case UNION: crappy hack to do union "keyword" case IDENTIFIER: - if (t->get_str () == "union" + if (t->get_str () == Values::WeakKeywords::UNION && lexer.peek_token (1)->get_id () == IDENTIFIER) { return parse_union (std::move (vis), std::move (outer_attrs)); @@ -1436,7 +1436,8 @@ Parser::parse_macro_rules_def (AST::AttrVec outer_attrs) { // ensure that first token is identifier saying "macro_rules" const_TokenPtr t = lexer.peek_token (); - if (t->get_id () != IDENTIFIER || t->get_str () != "macro_rules") + if (t->get_id () != IDENTIFIER + || t->get_str () != Values::WeakKeywords::MACRO_RULES) { Error error ( t->get_locus (), @@ -4734,7 +4735,7 @@ Parser::parse_union (AST::Visibility vis, /* hack - "weak keyword" by finding identifier called "union" (lookahead in * item switch) */ const_TokenPtr union_keyword = expect_token (IDENTIFIER); - rust_assert (union_keyword->get_str () == "union"); + rust_assert (union_keyword->get_str () == Values::WeakKeywords::UNION); location_t locus = union_keyword->get_locus (); // parse actual union name @@ -5715,7 +5716,7 @@ Parser::parse_trait_impl_item () // semi return parse_macro_invocation_semi (std::move (outer_attrs)); case IDENTIFIER: - if (lexer.peek_token ()->get_str () == "default") + if (lexer.peek_token ()->get_str () == Values::WeakKeywords::DEFAULT) return parse_trait_impl_function_or_method (visibility, std::move (outer_attrs)); else @@ -5779,7 +5780,8 @@ Parser::parse_trait_impl_function_or_method ( auto is_default = false; auto t = lexer.peek_token (); - if (t->get_id () == IDENTIFIER && t->get_str () == "default") + if (t->get_id () == IDENTIFIER + && t->get_str () == Values::WeakKeywords::DEFAULT) { is_default = true; lexer.skip_token (); @@ -6300,7 +6302,7 @@ Parser::parse_stmt (ParseRestrictions restrictions) break; // crappy hack to do union "keyword" case IDENTIFIER: - if (t->get_str () == "union" + if (t->get_str () == Values::WeakKeywords::UNION && lexer.peek_token (1)->get_id () == IDENTIFIER) { return parse_vis_item (std::move (outer_attrs)); @@ -11704,7 +11706,7 @@ Parser::parse_stmt_or_expr () // crappy hack to do union "keyword" case IDENTIFIER: - if (t->get_str () == "union" + if (t->get_str () == Values::WeakKeywords::UNION && lexer.peek_token (1)->get_id () == IDENTIFIER) { std::unique_ptr item ( @@ -11712,7 +11714,7 @@ Parser::parse_stmt_or_expr () return ExprOrStmt (std::move (item)); // or should this go straight to parsing union? } - else if (t->get_str () == "macro_rules" + else if (t->get_str () == Values::WeakKeywords::MACRO_RULES && lexer.peek_token (1)->get_id () == EXCLAM) { // macro_rules! macro item From patchwork Tue Jan 30 12:06:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892871 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=NglV2Ex2; 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 4TPPkY69c0z23fD for ; Tue, 30 Jan 2024 23:34:45 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CF8E7386F474 for ; Tue, 30 Jan 2024 12:34:43 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 6835F38582A5 for ; Tue, 30 Jan 2024 12:11:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6835F38582A5 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 6835F38582A5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::433 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616686; cv=none; b=rfS56xz82g+Qm/c+7vYxfn0RdaFLfN2W3r2xQvjUY8vFWIx4LNKQwIMU2p6Fc6KbuXu3lWoWLwZtttRlM6BfWzGe+MYXk3ocTphxtuH2T8i7MBFOFRgMamPToo5oJUytrS+c7qV97LCRwkBIKh9D2SR4fj6owtlKPJjEzs8CCtk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616686; c=relaxed/simple; bh=MtXUyebEhxYk2gyiVidZgZdy4bpAKRXtvnGMbYDaDrs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KBOfED3ebANFgdwmja9qu9r0G97a40wrlQruC18bDuxOc39WcOd+FISi+lFuoBJFshkrK+OrPFxrWocznyBoFr1tx8d2K12ciyila0B2+QejEGoeRx12BYvKyFMsmWiOjbY8cT1EcNVOK0bmV7WVxQOh/bsd4sEmU2zRCrpCev8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-33ae7ae1c32so1688920f8f.3 for ; Tue, 30 Jan 2024 04:11:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616674; x=1707221474; 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=+HHNBziI5JY3AI0XuA626L38zneN3r0M1gj9ZNQjrGg=; b=NglV2Ex2Q8spjW7ieBWNlFX/yab113kQGWtSiHT4DAwrbD/LFPsex7g/i/LdWDJT7e TJefwIzC5ZEADa3uCXk0gKcwP7sX8OClUe8kR4Qsupo9wKjr8F4JIcE/G5IDLXaB7tE6 7RQ382nZMlMQdy+TfMiCe6vRYGf9FfsM//kTkHWGQJAt+MU4cG13SiZNAkwq2DBHxaz0 Pfr638q35NIX/4Sv0np5eml0/zycHnfLN5ik/mxUDeDeQDyQgznWH2e7ne83c6pVzO6t qjcqJ8o4BMNb6/RiIFWMsD3Pyufb3K4Cgf8E9Wv5cWAOytCJYJEJRYABBUV/b+lZ6IJI gVaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616674; x=1707221474; 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=+HHNBziI5JY3AI0XuA626L38zneN3r0M1gj9ZNQjrGg=; b=a97XQs5/JUd7XjgvqO022PL02l2CFPFMAj9vQeZOJnmcnLnpcHqoro4R/i0I5y1Zf9 jR/Dm+B2PH29dFiT+i6zgJVT5cTOU+k0vQQ40mVO0UHXkm9eup6SOfXCOXuX5B/84esT 2m3pzRxU/SOK1nNw716FOJq/KCDEDEIXyeXyXwfpBwQtNnFH9UARJ9Zh/UH9A/c6s8gL Zv0oe8XAeyp3jWihFXbc1v9tYX3gEJwU4DLD+9zNATp8A2GFvhf5uG5bON8il8raeMI/ ea8u7pTXEW8ZXBXVt/6YY8FnHqQnRT6AN6hmThDW74gxnhnpEmJ8KriW3BO4JmssDy1G LN6g== X-Gm-Message-State: AOJu0YziqcegRRQQcFzl02040RMG1mjMlM+DCbHVcJ6tyUgEx0jCGLWZ h6Rg6StIIJUcIi2+CQMt0aeHQrbGoWE/vJgCXUhePrBFUBy/3XKumtlcsEIaN09YjY6DOp+PZDu JXQ== X-Google-Smtp-Source: AGHT+IFToWlkUixWIY56O3E4qyQ8z73rVVWrs6BM1UiKII+NGKNsEY6rQdQGdosiL+FMRFBlUhHBHw== X-Received: by 2002:a05:6000:1565:b0:33a:f00c:cb5 with SMTP id 5-20020a056000156500b0033af00c0cb5mr4452907wrz.6.1706616673872; Tue, 30 Jan 2024 04:11:13 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:13 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 031/101] gccrs: Introduce a proper keyword list Date: Tue, 30 Jan 2024 13:06:47 +0100 Message-ID: <20240130121026.807464-34-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: Pierre-Emmanuel Patry The old "keyword" list was used for the lexer, and could therefore not be used with keyword spanning over multiple tokens as those tokens should remain lexed as is. Hence the introduction of a new list macro for keyword exclusive tasks. This also means we can no longer match a token id for each keyword. The token id map has been renamed to keep it's properties. gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::classify_keyword): Update keyword map name. * lex/rust-token.h (enum PrimitiveCoreType): Remove some deprecated comments. * util/rust-keyword-values.cc (get_keywords): Update the keyword map name. (RS_TOKEN): Define as empty (RS_TOKEN_KEYWORD_2015): Add the emission value. (RS_TOKEN_KEYWORD_2018): Likewise. * util/rust-keyword-values.h (RS_KEYWORD_LIST): Introduce the keyword list. (RS_TOKEN_KEYWORD_2018): Define multiple new keywords. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/lex/rust-lex.cc | 2 +- gcc/rust/lex/rust-token.h | 2 -- gcc/rust/util/rust-keyword-values.cc | 13 ++++++++++++- gcc/rust/util/rust-keyword-values.h | 13 +++++++++++-- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index 2d41c114f73..5bff2d9125c 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -260,7 +260,7 @@ Lexer::replace_current_token (TokenPtr replacement) TokenId Lexer::classify_keyword (const std::string &str) { - auto &keywords = Rust::Values::Keywords::keywords; + auto &keywords = Rust::Values::Keywords::keywords_tokens; auto keyword = keywords.find (str); if (keyword == keywords.end ()) diff --git a/gcc/rust/lex/rust-token.h b/gcc/rust/lex/rust-token.h index e38c3cf9943..438b29b4957 100644 --- a/gcc/rust/lex/rust-token.h +++ b/gcc/rust/lex/rust-token.h @@ -145,7 +145,6 @@ enum PrimitiveCoreType /* Doc Comments */ \ RS_TOKEN (INNER_DOC_COMMENT, "#![doc]") \ RS_TOKEN (OUTER_DOC_COMMENT, "#[doc]") \ - /* have "weak" union and 'static keywords? */ \ RS_TOKEN_KEYWORD_2015 (ABSTRACT, "abstract") /* unused */ \ RS_TOKEN_KEYWORD_2015 (AS, "as") \ RS_TOKEN_KEYWORD_2018 (ASYNC, "async") /* unused */ \ @@ -157,7 +156,6 @@ enum PrimitiveCoreType RS_TOKEN_KEYWORD_2015 (CONST, "const") \ RS_TOKEN_KEYWORD_2015 (CONTINUE, "continue") \ RS_TOKEN_KEYWORD_2015 (CRATE, "crate") \ - /* FIXME: Do we need to add $crate (DOLLAR_CRATE) as a reserved kw? */ \ RS_TOKEN_KEYWORD_2015 (DO, "do") /* unused */ \ RS_TOKEN_KEYWORD_2018 (DYN, "dyn") \ RS_TOKEN_KEYWORD_2015 (ELSE, "else") \ diff --git a/gcc/rust/util/rust-keyword-values.cc b/gcc/rust/util/rust-keyword-values.cc index 8aa5ef1371a..9e1d2bcdef6 100644 --- a/gcc/rust/util/rust-keyword-values.cc +++ b/gcc/rust/util/rust-keyword-values.cc @@ -38,7 +38,18 @@ get_keywords () return m; } -const std::map Keywords::keywords = get_keywords (); +const std::map Keywords::keywords_tokens + = get_keywords (); + +const std::set Keywords::keywords = { +#define RS_TOKEN(x, y) +#define RS_TOKEN_KEYWORD_2015(tok, key) {key}, +#define RS_TOKEN_KEYWORD_2018 RS_TOKEN_KEYWORD_2015 + RS_KEYWORD_LIST +#undef RS_TOKEN_KEYWORD_2015 +#undef RS_TOKEN_KEYWORD_2018 +#undef RS_TOKEN +}; } // namespace Values } // namespace Rust diff --git a/gcc/rust/util/rust-keyword-values.h b/gcc/rust/util/rust-keyword-values.h index 4a6f1df525d..01c98a2cde4 100644 --- a/gcc/rust/util/rust-keyword-values.h +++ b/gcc/rust/util/rust-keyword-values.h @@ -21,6 +21,14 @@ #include "rust-token.h" +// Append keywords made from multiple tokens to the existing token-keyword list +#define RS_KEYWORD_LIST \ + RS_TOKEN_LIST \ + RS_TOKEN_KEYWORD_2015 (DOLLAR_CRATE, "$crate") \ + RS_TOKEN_KEYWORD_2015 (PATH_ROOT, "{{root}}") \ + RS_TOKEN_KEYWORD_2015 (STATIC_LIFETIME, "'static") \ + RS_TOKEN_KEYWORD_2015 (UNDERSCORE_LIFETIME, "'_") + namespace Rust { namespace Values { @@ -28,14 +36,15 @@ namespace Values { class Keywords { public: - const static std::map keywords; + const static std::map keywords_tokens; + const static std::set keywords; // Rust keyword values public: #define RS_TOKEN(x, y) #define RS_TOKEN_KEYWORD_2015(tok, key) static constexpr auto &tok = key; #define RS_TOKEN_KEYWORD_2018 RS_TOKEN_KEYWORD_2015 - RS_TOKEN_LIST + RS_KEYWORD_LIST #undef RS_TOKEN_KEYWORD_2015 #undef RS_TOKEN_KEYWORD_2018 #undef RS_TOKEN From patchwork Tue Jan 30 12:06:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892881 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=QepjgyjK; 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 4TPPnK292Pz23dQ for ; Tue, 30 Jan 2024 23:37:09 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 573A03861876 for ; Tue, 30 Jan 2024 12:37:07 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id A9A973858289 for ; Tue, 30 Jan 2024 12:11:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A9A973858289 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 A9A973858289 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::434 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616688; cv=none; b=PsFoDJmTSOEte1Vin0OOvuyg9eLzFIMDklxXHqwbM+HYrzl9rxU3ecOFIj43x8nEcrbrLNSKtvKozLKaaWTHuJuCap0IPvo2FwlfRHfLscxaQxPt90OtpakxqK8ojVEiSzeis4tjQVhYTqNKZ/g0CZsEKvHqPj7IDo6nY25/Llk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616688; c=relaxed/simple; bh=VuhQbL6y+Nqu6SlxLin+D5zxWSOv9vafi/+uJoUwgBA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hIyrso0PzD9cW/bwLNKgHyo7C4NiyGVy+8Uwpt8SxQkNFzK7rxOzpOsOwf06M+Cl3SQtTyZUnhMhzcOJLzpbezte+UlQbAGBtkEeIbmOM65O8NsIOnxplVKhH6Dzj63AEyOVU3B0ybcUdDHfm5+9HiXtmVlKFTiAX2i2ykeRVU0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-3394b892691so2129562f8f.1 for ; Tue, 30 Jan 2024 04:11:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616674; x=1707221474; 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=BICrr66xJU+6tF/NHZ8Rq1bmcWtq7X62yN12NOXM4+4=; b=QepjgyjK8bM1md4r8MPPrZo8Per00zeIFYT8zyTVYv6BxYFZsXY9LR21wRXjrf7j4T 5gxIPW7ZRQgc8ZYT9MPCql/H/3Q2AiIN0QWgH1U4106RRm9wD3Bdum1y2lDD88OaEs+B nq/siAn1WJNcRqq+uqIYcyh0BVGyOW5AE1+FnotQu0AxUr5N4WlL6YDooUKO0gnYrOZh W699ofgrk3KI082bqfhSSWNq78wTdxm35cWBVtss4iHGSWIy94adyFsruQY/55W14ZN/ ksNk7p8dY15IsHoX3qrwvmFfT1LjhrUPkvL9lyvqU46MhcWXYEQj0CJfEPr+GNIeywGK 6R+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616674; x=1707221474; 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=BICrr66xJU+6tF/NHZ8Rq1bmcWtq7X62yN12NOXM4+4=; b=iJPmXFrvhquZCcygqnJ3XPDzWAl62Asj32a8jw741bw+agiBrqw3RHQF6Aq8v1WlSH 7Wrzg1hTn8tvunjlaEGzTy81yAhtvSLxGb9v0wH9NnpnmC0ovGDxOdMXiYG4EYPBk/2a 9TRaMjovxpcpA3i1JUv//b+ONzwv2yMkieo5RCKpxX9/JP8/TQteIx3xJmMZiocPVfpU LLeyzxyQUzFy66+Ou2OF4IYSVwLG8czxmi+DWDh+fX+bfIaeiuN58y+1k9xHSh2Vxxr3 1C2En00YTEGr46fc8Omw/00ooC+NpIS5m2XcnonR9bNC9bp4vE0xuUqmHXZaDUJWkkZd usxA== X-Gm-Message-State: AOJu0Yx0m1RmtVyDrEmyOn2AH3MRxnCtjVvf6ZhKWrTeoL4GO6SEgBiM hqOlFLsZQ6QUVNQHVLbaEZOGQlVtRX36kpuefVdizeorT7LcUtgF3mS35ABUb6+q3AM2qYPHLEl 3PA== X-Google-Smtp-Source: AGHT+IHZfC7W6aZnHSo2uRgfVIRM+MflQwglu8vo5iUDAydGOvyG4kI9fuZ9w/x2P1O6UArZTUE8CA== X-Received: by 2002:a5d:5002:0:b0:33a:ec95:3168 with SMTP id e2-20020a5d5002000000b0033aec953168mr1376826wrt.13.1706616674250; Tue, 30 Jan 2024 04:11:14 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:14 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, M V V S Manoj Kumar Subject: [COMMITTED 032/101] gccrs: Added support to Parse ASYNC function Date: Tue, 30 Jan 2024 13:06:48 +0100 Message-ID: <20240130121026.807464-35-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: M V V S Manoj Kumar Fixes issue #2650 The parser now parses ASYNC functions. Added ASYNC case to parse_item Added a new function parse_async_item which is called in parse_vis_item to handle the ASYNC case. Parse_async_item also checks the current Rust edition and generates an error if the edition is 2015 gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_item): Likewise. (Parser::parse_vis_item): Likewise. (Parser::parse_async_item): Likewise. * parse/rust-parse.h: Made declaration for parse_async_item. gcc/testsuite/ChangeLog: * rust/compile/issue-2650-1.rs: New test.(edition=2018) * rust/compile/issue-2650-2.rs: New test.(edition=2015) Signed-off-by: M V V S Manoj Kumar --- gcc/rust/parse/rust-parse-impl.h | 40 ++++++++++++++++++++++ gcc/rust/parse/rust-parse.h | 2 ++ gcc/testsuite/rust/compile/issue-2650-1.rs | 5 +++ gcc/testsuite/rust/compile/issue-2650-2.rs | 5 +++ 4 files changed, 52 insertions(+) create mode 100644 gcc/testsuite/rust/compile/issue-2650-1.rs create mode 100644 gcc/testsuite/rust/compile/issue-2650-2.rs diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 37eddc1b753..53b3839db37 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -30,6 +30,7 @@ #include "rust-dir-owner.h" #include "rust-attribute-values.h" #include "rust-keyword-values.h" +#include "rust-session-manager.h" #include "optional.h" @@ -1113,6 +1114,8 @@ Parser::parse_item (bool called_from_statement) add_error (std::move (error)); } return nullptr; + + case ASYNC: case PUB: case MOD: case EXTERN_KW: @@ -1389,6 +1392,10 @@ Parser::parse_vis_item (AST::AttrVec outer_attrs) lexer.skip_token (1); // TODO: is this right thing to do? return nullptr; } + // for async functions + case ASYNC: + return parse_async_item (std::move (vis), std::move (outer_attrs)); + case STATIC_KW: return parse_static_item (std::move (vis), std::move (outer_attrs)); case AUTO: @@ -1429,6 +1436,39 @@ Parser::parse_vis_item (AST::AttrVec outer_attrs) return nullptr; } +template +std::unique_ptr +Parser::parse_async_item (AST::Visibility vis, + AST::AttrVec outer_attrs) +{ + const_TokenPtr t = lexer.peek_token (); + if (Session::get_instance ().options.get_edition () + == CompileOptions::Edition::E2015) + { + add_error (Error (t->get_locus (), ErrorCode::E0670, + "% is not permitted in Rust 2015")); + add_error ( + Error::Hint (t->get_locus (), + "to use %, switch to Rust 2018 or later")); + } + + t = lexer.peek_token (1); + + switch (t->get_id ()) + { + case UNSAFE: + case FN_KW: + return parse_function (std::move (vis), std::move (outer_attrs)); + + default: + add_error ( + Error (t->get_locus (), "expected item, found keyword %")); + + lexer.skip_token (1); + return nullptr; + } +} + // Parses a macro rules definition syntax extension whatever thing. template std::unique_ptr diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index e873d5292cd..d3718467b48 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -357,6 +357,8 @@ private: std::unique_ptr parse_extern_block (AST::Visibility vis, AST::AttrVec outer_attrs); std::unique_ptr parse_method (); + std::unique_ptr parse_async_item (AST::Visibility vis, + AST::AttrVec outer_attrs); // Expression-related (Pratt parsed) std::unique_ptr diff --git a/gcc/testsuite/rust/compile/issue-2650-1.rs b/gcc/testsuite/rust/compile/issue-2650-1.rs new file mode 100644 index 00000000000..381398e19f5 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2650-1.rs @@ -0,0 +1,5 @@ +// { dg-additional-options "-frust-edition=2018" } + +pub async fn a() -> u32 { + 1 +} diff --git a/gcc/testsuite/rust/compile/issue-2650-2.rs b/gcc/testsuite/rust/compile/issue-2650-2.rs new file mode 100644 index 00000000000..5132e6e1158 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2650-2.rs @@ -0,0 +1,5 @@ +// { dg-additional-options "-frust-edition=2015" } + +pub async fn a() -> u32 { // { dg-error "'async fn' is not permitted in Rust 2015" } + 1 +} From patchwork Tue Jan 30 12:06:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892827 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=fziryMWR; 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 4TPPSr4kKmz23fD for ; Tue, 30 Jan 2024 23:22:52 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 890443857C70 for ; Tue, 30 Jan 2024 12:22:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 94640385843B for ; Tue, 30 Jan 2024 12:11:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 94640385843B 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 94640385843B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::432 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616689; cv=none; b=smQJoHZKBXm7KsJFRPTC/8X5w2iqxfCzomT4uavdVj3zAhCzmS5O4DnaULE2fGE5VEEDtovZquvlFVP4lbQfRJzkDTQzeweVfGRL+sJOJ9WiLRVaC7NqATyeSXbEuczR+Z19nwhxWVHgQ8gDQmoQrRcL0gybPdAzt1e0+j/XhHU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616689; c=relaxed/simple; bh=2UimXqWmNKzhiEE4P+mEnnZsCj90XNplJmJyfnom6qk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=v7xABTY9XPLvnYZrPrURjwjr5MtIeMNwmF5k/Uf2MWY+IpTLs560qpLoAkELXaZjvasNmioUDb3UQIp2Qq3WiQIHHzfwhH1ICJ4UhVptBMb0L32wG94nkZn8BkbphqQZLpHXrg8dza00H9eerQsLrYfhnsznlqD5EknSj81kHCo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-33aeb088324so1539435f8f.2 for ; Tue, 30 Jan 2024 04:11:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616674; x=1707221474; 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=E+qMo473AEZ3fsPP5ymBE7WjR7rVHNv82oxqYkfediU=; b=fziryMWRZmqkQKPe1A8t+YJ30DORzLuugy1zkTcRuHv/C0frz1Sk5dxuea0qHIMQse YjZJsR4a4e9j0FCGxjiWH0JXpgzY6LarqRD+8gRxF/4WOSY4a3TV4+Y0ayAJfCvn8gei U+/Sz5MO36oNI/PEBHFma+9RPSiJ8egUGXUdn0jXg3Vu6CUo4oI3HS4qp+eU8dRSRWXW aHCP94GlKkHKPbk9UOVqVXaK/G80qhsJn0GYiEILgJkIgM0hX6GSRxtBPgwxwgjgB2A2 JCYHztLkmoWSOAulyEnAune6pW7FR3dODrx4AW0JMr3bJoep9rk1NND0ky3IZZrVtTMm 52Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616674; x=1707221474; 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=E+qMo473AEZ3fsPP5ymBE7WjR7rVHNv82oxqYkfediU=; b=jNlpsufFIBQchpX/7ywIcI2CGdyNVre2PWTrRCcLaCoiuFw2pEc5YdaMrZo+Hv4dUo aeThDsFnxgdFalf627t8a+J5qDx4oRqaKG1qFo7zQdxtAWP5pnH5JNodsQQUz5zKbONu /ZqCV2+GiTmLMz3MjpjaeelCevSC+x7eq38/J8ELJBZnqcNVhVUTBOIaFV8qHOIT61VH gRjqplHF2oNkGyMkDs+ClGuti/9mXyjgiu8PKUxn43B3JlvcYI1m5QUHv18gf4sjucXz rsfcCQKG/u+0qvgnFF5c0gb6rr/8P55WmXS4GqpLfk8WLS3N9shO82u4NSuhBakXMtwV eMWQ== X-Gm-Message-State: AOJu0YyXKzLfQfFlAK0FkldsWFiUqFp+6U0itmn+byiWtsTDo+psnScb YWRV3WJGUHVZ+XHs1iGjGax0m+aXo284GMqKmZ5r+TJ4Y11aNEPHHlwWBuA/liGcNBlhL5Zl04N RwA== X-Google-Smtp-Source: AGHT+IGUszuSSNgwkKyYUno9bXT3O0Z3WpLtHhmiNG9zLV/LvqypXcJBp8lNhpRmu8n9y+y3HlZfPw== X-Received: by 2002:adf:f2c5:0:b0:33a:e525:e91b with SMTP id d5-20020adff2c5000000b0033ae525e91bmr6743182wrp.19.1706616674611; Tue, 30 Jan 2024 04:11:14 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:14 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 033/101] gccrs: ctx: Add Labels ForeverStack to the resolver. Date: Tue, 30 Jan 2024 13:06:49 +0100 Message-ID: <20240130121026.807464-36-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 Not sure if dealing with "labels" is the proper way of doing so, so we might eventually change this to use `resolver.values` later on. gcc/rust/ChangeLog: * resolve/rust-name-resolution-context.h: Add a Labels stack. --- gcc/rust/resolve/rust-name-resolution-context.h | 1 + 1 file changed, 1 insertion(+) diff --git a/gcc/rust/resolve/rust-name-resolution-context.h b/gcc/rust/resolve/rust-name-resolution-context.h index 64db5d1a580..6d14be35986 100644 --- a/gcc/rust/resolve/rust-name-resolution-context.h +++ b/gcc/rust/resolve/rust-name-resolution-context.h @@ -173,6 +173,7 @@ public: ForeverStack values; ForeverStack types; ForeverStack macros; + ForeverStack labels; }; } // namespace Resolver2_0 From patchwork Tue Jan 30 12:06:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892850 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=EPrbzGHf; 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 4TPPcq17DLz23gZ for ; Tue, 30 Jan 2024 23:29:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9BCFE384DEE0 for ; Tue, 30 Jan 2024 12:29:44 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 6B4A23857C4B for ; Tue, 30 Jan 2024 12:11:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6B4A23857C4B 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 6B4A23857C4B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::334 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616696; cv=none; b=nb7+doi5CVR7yzvV83mTDkUJ+WNu5Ock5jf7OsWvkHWmXKLMSfK8sowVVx0DhlIdFjsmGV9CxEJRJDE95TLRw9CgnSrt/3+HAL6kfOG13qLTL+9PudMycdPmYmwNdOuekn1jujOSBMYR15ALADhf/s7uar5KO9yHvrS+i3yMkU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616696; c=relaxed/simple; bh=9buXZqtaGoK/zH4RbZYZ/kqgVU2UzhcwgSt2yttomvE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nfvJUxFzjzT0g1NrV38pB5yvpIdDmzW2wsYNrJN2oLgAJOwztHiXZgLwjACyPVPkqCuzvkVewwzeF8wUHf4pvmIJZ5Ri6AhbtIOAJkPwL6ha/zet3ziudBpYIuez1hF9DRluLL+2WWpfsiL5XFyCWfLAavBiKpSTPOa/q/iJddE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40e72a567eeso56789655e9.0 for ; Tue, 30 Jan 2024 04:11:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616676; x=1707221476; 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=5b02A3thki/rKgHoCIWOYRR6iZyiTHc+tKiC4usqP4Y=; b=EPrbzGHfr3Y6s1yUizQXZjybhrKambNbsL6q15Cv1hGu41NM7+fW3UyTK3Ps1VDbjy P4aHtKa1EzjoZLH8g3/WRBDRIPdMcF2vBM/QGi4jYCcw0wW+gBZsuEiS0A31c1SHCj3C 6TiH8PKAjp+Hcl9AtJ3VXoD+rZvNhFEHp6SMQIw3Roh95eN/h2MUx0LphqreGFzZsnFl RqVEWtO4oRqnT4XJLti9HbZi8/UicIEHuXGH9mp/ae0QKOdAmG9mJt0OLwaggrgUTANW lYZacNqRqh99IHYmS0czUyZURokaUyjnSDRDLUqh+gb/3Q152lROVezDHIkueGx2TSt9 OxLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616676; x=1707221476; 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=5b02A3thki/rKgHoCIWOYRR6iZyiTHc+tKiC4usqP4Y=; b=BXiMWU8/qROrWA2izl2eA1FcuyqNZGvHHiG4FjIgstwaWH+6G9QUKn4siHK1UkySZj 9BJoOhk5mSs+kkBAZlx+v1rYJWYPmmwMHN9EYbXrER4eRqZRj95x4k2jma6XavYbMh3P SDcRTREa9rwAOYSGao51SOGauXMhMkQSUoNU0DEyAVn1DStDLI0mbbUAMbJZqv1Y+ugy pUHJyEhXvGg1NlTGriRQpkatBvs4zwNA1noIWLAbDExpC+aes2nOrnE9pOkOpUikYPDs smj/kqwtGDMhXDOuxsss3Fd+Bfkyf1EFCg/8/64tLN443w62HfCIV2LN2w++vfuGao47 Sm0A== X-Gm-Message-State: AOJu0YzGMq86tVbD0rLUNYhvGb+fMT+80tQ/EbXSKZGShMYruxX5oxpY Hi0tSEyKOz5I4cgrXvVnzECF4OHB8c35/pqLeqchQ+iMR2Ds/mkYvLPRkbJq3ldK9uJRLhW7Y5q osg== X-Google-Smtp-Source: AGHT+IF4NwoB0sUTeUR+m1Oeo5mhbp3iHLaj3XgL1SjaLV9IztWjDiWRFFpYaBVPm3NfeKC6CqX6Wg== X-Received: by 2002:a05:600c:4754:b0:40e:a39e:461f with SMTP id w20-20020a05600c475400b0040ea39e461fmr7891402wmo.38.1706616675929; Tue, 30 Jan 2024 04:11:15 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:14 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 034/101] gccrs: nr2.0: Add base for late name resolution Date: Tue, 30 Jan 2024 13:06:50 +0100 Message-ID: <20240130121026.807464-37-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, KAM_SHORT, 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: * Make-lang.in: Compile late name resolver. * resolve/rust-late-name-resolver-2.0.cc: New file. * resolve/rust-late-name-resolver-2.0.h: New file. --- gcc/rust/Make-lang.in | 1 + .../resolve/rust-late-name-resolver-2.0.cc | 105 ++++++++++++++++++ .../resolve/rust-late-name-resolver-2.0.h | 57 ++++++++++ 3 files changed, 163 insertions(+) create mode 100644 gcc/rust/resolve/rust-late-name-resolver-2.0.cc create mode 100644 gcc/rust/resolve/rust-late-name-resolver-2.0.h diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index f2cadd55eed..47cc87750be 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -116,6 +116,7 @@ GRS_OBJS = \ rust/rust-default-resolver.o \ rust/rust-toplevel-name-resolver-2.0.o \ rust/rust-early-name-resolver-2.0.o \ + rust/rust-late-name-resolver-2.0.o \ rust/rust-early-name-resolver.o \ rust/rust-name-resolver.o \ rust/rust-ast-resolve.o \ diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc new file mode 100644 index 00000000000..352d59b0920 --- /dev/null +++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc @@ -0,0 +1,105 @@ +// Copyright (C) 2020-2023 Free Software Foundation, Inc. + +// This file is part of GCC. + +// GCC is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3, or (at your option) any later +// version. + +// GCC is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. + +// You should have received a copy of the GNU General Public License +// along with GCC; see the file COPYING3. If not see +// . + +#include "rust-ast-full.h" +#include "rust-late-name-resolver-2.0.h" +#include "rust-default-resolver.h" + +namespace Rust { +namespace Resolver2_0 { + +Late::Late (NameResolutionContext &ctx) : DefaultResolver (ctx) {} + +void +Late::go (AST::Crate &crate) +{ + for (auto &item : crate.items) + item->accept_vis (*this); +} + +void +Late::new_label (Identifier name, NodeId id) +{ + // labels can always shadow, so `insert` should never fail. if it does, we're + // in big trouble! + auto ok = ctx.labels.insert (name, id); + + rust_assert (ok); +} + +void +Late::visit (AST::LetStmt &let) +{ + // so we don't need that method + DefaultResolver::visit (let); + + // how do we deal with the fact that `let a = blipbloup` should look for a + // label and cannot go through function ribs, but `let a = blipbloup()` can? + + // how do we insert ribs here, and only pop them when we exit the current + // function? + // keep a list of ribs to pop when a scope exits? so only for blocks? + // how do we pop ribs that need to be popped not in order? + // I think it's not important if we have shadowing, correct? + + // if we have shadowing, it should work! we'll see + + // ctx.insert(Identifier name, NodeId id, Namespace ns) + // ctx.scoped (Rib::Kind::Normal /* FIXME: Is that valid? */, + // Namespace::Labels, + // let.get_node_id (), [] () {}); +} + +void +Late::visit (AST::IdentifierPattern &identifier) +{ + // do we insert in labels or in values + // but values does not allow shadowing... since functions cannot shadow + // do we insert functions in labels as well? + new_label (identifier.get_ident (), identifier.get_node_id ()); +} + +void +Late::visit (AST::IdentifierExpr &expr) +{ + // TODO: same thing as visit(PathInExpression) here? + + auto label = ctx.labels.get (expr.get_ident ()); + auto value = ctx.values.get (expr.get_ident ()); + + rust_debug ("[ARTHUR] label: %d", label ? *label : -1); + rust_debug ("[ARTHUR] value: %d", value ? *value : -1); +} + +void +Late::visit (AST::PathInExpression &expr) +{ + // TODO: How do we have a nice error with `can't capture dynamic environment + // in a function item` error here? + // do we emit it in `get`? + + auto label = ctx.labels.resolve_path (expr.get_segments ()); + + auto value = ctx.values.resolve_path (expr.get_segments ()); + + rust_debug ("[ARTHUR] label: %d", label ? *label : -1); + rust_debug ("[ARTHUR] value: %d", value ? *value : -1); +} + +} // namespace Resolver2_0 +} // namespace Rust diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h b/gcc/rust/resolve/rust-late-name-resolver-2.0.h new file mode 100644 index 00000000000..12540c0d220 --- /dev/null +++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h @@ -0,0 +1,57 @@ +// Copyright (C) 2020-2023 Free Software Foundation, Inc. + +// This file is part of GCC. + +// GCC is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3, or (at your option) any later +// version. + +// GCC is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. + +// You should have received a copy of the GNU General Public License +// along with GCC; see the file COPYING3. If not see +// . + +#ifndef RUST_LATE_NAME_RESOLVER_2_0_H +#define RUST_LATE_NAME_RESOLVER_2_0_H + +#include "rust-ast-full.h" +#include "rust-default-resolver.h" + +namespace Rust { +namespace Resolver2_0 { + +class Late : public DefaultResolver +{ + using DefaultResolver::visit; + +public: + Late (NameResolutionContext &ctx); + + void go (AST::Crate &crate); + + void new_label (Identifier name, NodeId id); + + // some more label declarations + void visit (AST::LetStmt &) override; + // TODO: Do we need this? + // void visit (AST::Method &) override; + void visit (AST::IdentifierPattern &) override; + + // resolutions + void visit (AST::IdentifierExpr &) override; + void visit (AST::PathInExpression &) override; + +private: +}; + +// TODO: Add missing mappings and data structures + +} // namespace Resolver2_0 +} // namespace Rust + +#endif // ! RUST_LATE_NAME_RESOLVER_2_0_H From patchwork Tue Jan 30 12:06:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892833 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=Wc0nzEp1; 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 4TPPWf6lzlz23gZ for ; Tue, 30 Jan 2024 23:25:18 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DD81C385F012 for ; Tue, 30 Jan 2024 12:25:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id C2EED385840D for ; Tue, 30 Jan 2024 12:11:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C2EED385840D 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 C2EED385840D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::433 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616693; cv=none; b=vjgfux5NL7sHwTq0rxdp3stL5iGR8z4MdNrEce/RBLmfy2zezsHBQ76LVF588N0xnvxmWsZ1TYjuje5mzaBqf8FNBn3Ebm65FXues52HSjZ1s0Jx+wqWKYKCiQDoYkEbUwik6TqOk/DPALCFH+MjKfz6GjzlTtlSgMtEKARRtrM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616693; c=relaxed/simple; bh=CdJ3CPKlrq9CG0QKSxKnDCjcTsJjbRVSTTngeZi/39k=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=L/tTlrjsQomCnBDRoP8OF3+0SvjHcGSg2dqrv8LVJIqZW3kyeQtRvSTS1XP5jmDFIrBPmhzW3gr8heLRk7nNT94gZY54ybppNQ2C9Ym74NC+6EwaSnWbdGGs0K6PiH4CoZQJsiZBovxx9/xkbrqnHEBjwYbfiLfnuJOTje5lcTk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-33aeb088324so1539449f8f.2 for ; Tue, 30 Jan 2024 04:11:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616676; x=1707221476; 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=5plG00MsU9I/B34gHjIEB8BfWLRRr5l4boid2XA5QwA=; b=Wc0nzEp1iLQsgOugig3oHAUgnx6X5iJqvLg6aUaPnNIZmbnSOla76ltGKYqpOgDipR eIsiC6FVv/65sGV7oBUxOAung1ihsEoqRGn/aM/ULzuKKfuwmG0971BUZzRx4ld+jigl WrINSGd3lPxXIL2IXRb8WHbN09tysqU1jWxe1tWQYtPjj9JrKvjTgWqCbJN0Vht+ZfTN SpBsMlcY60fkbLJYYnXGIDHkwV8LjRCbxv8b9Rqc5xfH/oBY0wBGCB02zMsA4orkf+A9 exU1HI2Aaik/1FBU2W6BflCZkl7Xp5GtZof0rKCUzRJUgyOs2bz7AgPb/KLtw+OIhJJq g0/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616676; x=1707221476; 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=5plG00MsU9I/B34gHjIEB8BfWLRRr5l4boid2XA5QwA=; b=VfGBTdUWbf5I/KRJTzQ+0E+jaSMhzet4cftCeDQZurXpkhk6jM0Ga9J8zFfbZ32g1t 7UTQ2Yx4EFyofEGlZ5lQTakkAr/9UC2/zyigd+6CHAyDIoWMaphZ+Xwr7eNrGv/Ut865 7dDXoqY2wU5hcJ7haKDCzN7UebYkf1PxGPV0clI4tejk4CtpOoilF6C/TF+sgUeIj8qM UA6AuwRGHgxARaUFlb6yDJR0+NG98ztCNxd9aEPTQrVtJggRFD/Rs+5mGuTvjeKUSSUW xOPphYd58h4jvDyBj4gob1nQ1jrb7UZqhsVPUkZ8bXIZ4ppWeBgybVL0vv18EU1D0DRd 3E5g== X-Gm-Message-State: AOJu0YxQDKKYHqibvY5QxZYWoMshdh8LSdnfvwmNtpLDsc8e5NPB1yzj LR0Qby/6OJNqH6XJG01b52+Q0YVkwXFO6BC2o+SQzoT9RhC8S8Sl3p4dBSvsv9XRcDXXvqNU9Ko B4w== X-Google-Smtp-Source: AGHT+IESYGeDgYOPRxy10QUim1yygimBHiPiiMrEigjCvj+uo2hJPC0srIqazu6YPPmN2BNkZoZsrg== X-Received: by 2002:a5d:6b12:0:b0:339:3a25:6d70 with SMTP id v18-20020a5d6b12000000b003393a256d70mr5800598wrw.66.1706616676341; Tue, 30 Jan 2024 04:11:16 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:16 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 035/101] gccrs: toplevel: Use DefaultResolver for Function Date: Tue, 30 Jan 2024 13:06:51 +0100 Message-ID: <20240130121026.807464-38-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-toplevel-name-resolver-2.0.cc (TopLevel::visit): Use the DefaultResolver in the toplevel visitor. --- gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc index fc62db729b5..fbded3e49e1 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc @@ -185,10 +185,7 @@ TopLevel::visit (AST::Function &function) insert_or_error_out (function.get_function_name (), function, Namespace::Values); - auto def_fn - = [this, &function] () { function.get_definition ()->accept_vis (*this); }; - - ctx.scoped (Rib::Kind::Function, function.get_node_id (), def_fn); + DefaultResolver::visit (function); } void From patchwork Tue Jan 30 12:06:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892886 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=EOEx1cxK; 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 4TPPpm3mjYz23gc for ; Tue, 30 Jan 2024 23:38:24 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6892E3830B49 for ; Tue, 30 Jan 2024 12:38:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 118123857C46 for ; Tue, 30 Jan 2024 12:11:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 118123857C46 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 118123857C46 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::333 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616700; cv=none; b=hAKNBroLHoUWUsKSskO2ilhx21v1o0weQdo7OCzPIEDuNuMtTUX64uC25ELf3vrU4iZEp7FrucS2f9bUEEQynigrK1Ff1M1E43UJ1FjX0Cqm8buLblNX3va6ZXTox/HwHpGU1K6DGiGTm6CpgVK1MO3rgKzVzyAiKoV5pTvKsMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616700; c=relaxed/simple; bh=6+cvX1FW/q4w9tvSbDu91h2Iu9usQhm1OMmqMulsuh8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TXe+R5pDKH8xshW1U0PRODwZM40qxINFhD+evfMVaIXlCJZtCXZhew9VnvX1vf0S9FZfmqFm0maMAbxwz74l9sd8PcIg3JLjCQ1AoF5ktc6jJi+AaXUIne4MkyGuHxVHwwLzgJyA31P1QekrGdVQIsEsjcvYV6+5USNl3czIfGg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40fafc8bd6dso1458495e9.0 for ; Tue, 30 Jan 2024 04:11:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616676; x=1707221476; 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=EGxTRYG800KL4c+ppg1YlWIolB7MsdY7NmOX8ir/pbU=; b=EOEx1cxK10ADFSalPBhymTXhjUrPfX+DyIgtZc8SzeMbtFONNokiYkfMI87U+GvlHE ZeRoMT3KUGWa3SNcz0KdW4wL4xE/JhkciDWz3nw9riZ/wv/LAyAuSah3Kas6Ao8q3dI3 DcWUvDbCk8FpAkcCumrjXS+Sl8mnFpLtYMNVF6xetylzhThF3uakvuTGyS5JI1l6TQtW zOu/9jCwJSUFXHTM/ZLoI1saiHkA9eLj11QWbMZIkwUuAy9wvgB1az8Kk5zt0Ff4paBs ovqzajzeMZLUcd/3SbWpRhpEUsOK/QRl5Nt4L7Gr7Ncrf2IGeZmb1Jvlgkj5uU3AcHpU 2iFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616676; x=1707221476; 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=EGxTRYG800KL4c+ppg1YlWIolB7MsdY7NmOX8ir/pbU=; b=wrStOwAKk8DRmbq8ycuTNuXoYRj2kkRWbFuer7Am5kjM3UYw4UB5wdC+gpbMuaXr7b JiPNv8FHg8W11oMWogd8GvTfJyb1Vi8uisvwyIhicQuZEJsAmmv1Sh5nKZS7XrBrCxzF w/4Rkm0+mAM3K4gsbrK3mSDyPy/NBHrKzsSxbcHhgPI4/4SAf3CSRqqmDq5qEpNHqJMS eF5S5bMYUcrGK40fF3r0dnGOKge1/lzcViaayQyXGvY9nw542WoiKrforLnlMLieb2B1 9HAYpX9XCy9HDbkCkNtXhiup0rxuWdi4lGj9+zdIRffo4GiGrmT3ohg0mTyNyDraQ6cb bYAA== X-Gm-Message-State: AOJu0YwYdcVdU+OBo2u5kSRdj5C1v1c2OFXe99ttm7Ym9+7zEw+f6EKF Yw+5Xd7YSNeoZADD/k04iiCXE7NFeEYzlAhtTd8/43aNO7Zev3AU5Z+Pbd+IHMkIaa3Esuir+S2 pyw== X-Google-Smtp-Source: AGHT+IEr5L3eON55d0LZXr9iEdGN6ed4yG9jK8+LyjX61ancCChBzUGuku0Km8YKkabzD4+3jHq0GQ== X-Received: by 2002:a5d:62cc:0:b0:33a:f4b4:8023 with SMTP id o12-20020a5d62cc000000b0033af4b48023mr3157339wrv.7.1706616676686; Tue, 30 Jan 2024 04:11:16 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:16 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 036/101] gccrs: nr2.0: Store mappings in NameResolutionContext Date: Tue, 30 Jan 2024 13:06:52 +0100 Message-ID: <20240130121026.807464-39-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-name-resolution-context.h: Store a reference to the mappings. * resolve/rust-name-resolution-context.cc (NameResolutionContext::NameResolutionContext): Likewise. --- gcc/rust/resolve/rust-name-resolution-context.cc | 4 ++++ gcc/rust/resolve/rust-name-resolution-context.h | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/gcc/rust/resolve/rust-name-resolution-context.cc b/gcc/rust/resolve/rust-name-resolution-context.cc index 82771cdd923..8bb7a9a15c1 100644 --- a/gcc/rust/resolve/rust-name-resolution-context.cc +++ b/gcc/rust/resolve/rust-name-resolution-context.cc @@ -21,6 +21,10 @@ namespace Rust { namespace Resolver2_0 { +NameResolutionContext::NameResolutionContext () + : mappings (*Analysis::Mappings::get ()) +{} + tl::expected NameResolutionContext::insert (Identifier name, NodeId id, Namespace ns) { diff --git a/gcc/rust/resolve/rust-name-resolution-context.h b/gcc/rust/resolve/rust-name-resolution-context.h index 6d14be35986..d63ee33378b 100644 --- a/gcc/rust/resolve/rust-name-resolution-context.h +++ b/gcc/rust/resolve/rust-name-resolution-context.h @@ -21,6 +21,7 @@ #include "optional.h" #include "rust-forever-stack.h" +#include "rust-hir-map.h" namespace Rust { namespace Resolver2_0 { @@ -136,6 +137,8 @@ correct class NameResolutionContext { public: + NameResolutionContext (); + /** * Insert a new value in the current rib. * @@ -174,6 +177,8 @@ public: ForeverStack types; ForeverStack macros; ForeverStack labels; + + Analysis::Mappings &mappings; }; } // namespace Resolver2_0 From patchwork Tue Jan 30 12:06:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892840 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=JnTOI/zg; 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 4TPPYs6v7Kz23gc for ; Tue, 30 Jan 2024 23:27:13 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D56353861815 for ; Tue, 30 Jan 2024 12:27:11 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id 37CC33857B88 for ; Tue, 30 Jan 2024 12:11:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 37CC33857B88 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 37CC33857B88 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616700; cv=none; b=B3oLQWAaa5p3u/SzEQIFE9yJEfOyLmjmD0RUwu5sT4WjSZbpL0KhXzC6M8c80NiYP6p+aUgojMJWcwR3Zuie9IsrXKjRc6Cgh6gtQVBxZnOV+tas/g6UvHCOGFONaD5YpTvs3oRs3V7IeDfaTUcfjCFNRuqeuhQGP1gP5pcWoaI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616700; c=relaxed/simple; bh=jv9mW2DrmByg8EcGvLOpP8r8sKEJSP+WSJPCchUykLw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vZFDlohUCm8TQsmen4DwujPKgLrIzKOLBkLMRI142rJUpFD3WuB/M3g+OQsDr9bR2z0ESzmjQcjkzECF4pmjessXdSjw59CAba6y7zeX7qBQW4U9WIjfERoP+/MUeibB1d664ToX54oXaQtMt+eL2xfhzkkts1U44omnCr/8ymU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40faff092a2so521055e9.2 for ; Tue, 30 Jan 2024 04:11:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616677; x=1707221477; 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=uwiq8F4F7HGDALS4iVjm/n1qtQx7j9Nj3PdBnVt3h+4=; b=JnTOI/zgN/veJgysAnLJwutry8UTupkDMSsknpQ/xH2as3YoNGq/TRBis+kBBLQSMC c6JbzvjR6PKtHl1YFIgWHjCpINF3qRXHo01dkFhFCWiekRSXBLW2nPFhcRvWzq/5wfcf 4AYsn9H2uYd8lxKnbzcyDDwNhaC9d0hpJ5pGYHBpB8BBP8CGWS/lCIzONJpEcMd2rnc5 T7Pbd857IcWopSwo+BUa3RmbM74lYnitiD8zl9dNtDO1D2UQC8eJ05wgk5H261QWMNWR 3EUk4Q7Ro62/ym8vBSJar4qnMGDBZaB17fK/rLPle4z9uZyey3Kl+mrmPsNMwXOs4omw 6dKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616677; x=1707221477; 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=uwiq8F4F7HGDALS4iVjm/n1qtQx7j9Nj3PdBnVt3h+4=; b=O9+S8eqZZhZsi4cA8H6soFz83YL/R9ts4dSSAqZY2bJh/1THUBLELcdUbam2Z1Ab5X 41ngvgf97RX7mxYwR3/R1iBfL/fMCzpTPGwfSry3Qis+AVSVlTOd+0IapDJksgd4JTPK QzH0UkmCQbr/C+H3jRfjBLKw5P0v4wVzvt6Jxj6ms5RPg69Nf78llpaasRkOjTYVaLrV sxW+aRqkfcMWKCkTOciO7rD4VeQLnUGC5pDeI383/ccS6CJJGOm5o4wHt+kVgGypu2Yj 6Euqsp8u/Vf7MQWWtQCJrTszSji1QHLDG6KvX7yRxjv5NZYTFpLbPvrpmZYgVe4zxpER TQ0Q== X-Gm-Message-State: AOJu0YwDY1FCo0ZMv8Ewrw4/jS5CgvxZonusnX9x4s2njHvcqvx3Gndb ElFcI/OyDZyv4POxo9syw7ImeHMxBzZxlhhMivYSmQjOSgE5+bXfFGabE9/4s+4JnvMepAsFI3l sFQ== X-Google-Smtp-Source: AGHT+IE6Yl/pvuur+70b3/6TNt77OPjg2V1vQtN7mpnDyBCj6JIpZelRzYyZL/AJ6rNWnMtIVO9RhA== X-Received: by 2002:a05:600c:502b:b0:40e:f9d4:2b03 with SMTP id n43-20020a05600c502b00b0040ef9d42b03mr3452305wmr.12.1706616677305; Tue, 30 Jan 2024 04:11:17 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:16 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 037/101] gccrs: late: Start setting up builtin types Date: Tue, 30 Jan 2024 13:06:53 +0100 Message-ID: <20240130121026.807464-40-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, KAM_SHORT, 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-late-name-resolver-2.0.cc (Late::setup_builtin_types): New function. (Late::go): Setup builtin types. * resolve/rust-late-name-resolver-2.0.h: * resolve/rust-name-resolution-context.cc (NameResolutionContext::map_usage): New function. * resolve/rust-name-resolution-context.h: Likewise. --- .../resolve/rust-late-name-resolver-2.0.cc | 42 +++++++++++++++++++ .../resolve/rust-late-name-resolver-2.0.h | 2 + .../resolve/rust-name-resolution-context.cc | 9 ++++ .../resolve/rust-name-resolution-context.h | 8 +++- 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc index 352d59b0920..3236886f37d 100644 --- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc @@ -16,18 +16,60 @@ // along with GCC; see the file COPYING3. If not see // . +#include "optional.h" #include "rust-ast-full.h" #include "rust-late-name-resolver-2.0.h" #include "rust-default-resolver.h" +#include "rust-tyty.h" +#include "rust-hir-type-check.h" namespace Rust { namespace Resolver2_0 { Late::Late (NameResolutionContext &ctx) : DefaultResolver (ctx) {} +void +Late::setup_builtin_types () +{ + auto next_id = [this] () { return ctx.mappings.get_next_hir_id (); }; + + static const std::pair builtins[] = { + {"u8", new TyTy::UintType (next_id (), TyTy::UintType::U8)}, + {"u16", new TyTy::UintType (next_id (), TyTy::UintType::U16)}, + {"u32", new TyTy::UintType (next_id (), TyTy::UintType::U32)}, + {"u64", new TyTy::UintType (next_id (), TyTy::UintType::U64)}, + {"u128", new TyTy::UintType (next_id (), TyTy::UintType::U128)}, + {"i8", new TyTy::IntType (next_id (), TyTy::IntType::I8)}, + {"i16", new TyTy::IntType (next_id (), TyTy::IntType::I16)}, + {"i32", new TyTy::IntType (next_id (), TyTy::IntType::I32)}, + {"i64", new TyTy::IntType (next_id (), TyTy::IntType::I64)}, + {"i128", new TyTy::IntType (next_id (), TyTy::IntType::I128)}, + {"f32", new TyTy::FloatType (next_id (), TyTy::FloatType::F32)}, + {"f64", new TyTy::FloatType (next_id (), TyTy::FloatType::F64)}, + {"usize", new TyTy::USizeType (next_id ())}, + {"isize", new TyTy::ISizeType (next_id ())}, + // missing char, str, never, () + // does name resolution play a part for this? or is it all at typechecking? + // yeah it seems to be name resolution as well, which makes sense + }; + + for (const auto &builtin : builtins) + { + // we should be able to use `insert_at_root` or `insert` here, since we're + // at the root :) hopefully! + auto ok + = ctx.types.insert (builtin.first, builtin.second->get_ref () + /* FIXME: Invalid! This returns an *HirId* */); + + rust_assert (ok); + } +} + void Late::go (AST::Crate &crate) { + setup_builtin_types (); + for (auto &item : crate.items) item->accept_vis (*this); } diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h b/gcc/rust/resolve/rust-late-name-resolver-2.0.h index 12540c0d220..f54bbf2eea4 100644 --- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h +++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h @@ -47,6 +47,8 @@ public: void visit (AST::PathInExpression &) override; private: + /* Setup Rust's builtin types (u8, i32, !...) in the resolver */ + void setup_builtin_types (); }; // TODO: Add missing mappings and data structures diff --git a/gcc/rust/resolve/rust-name-resolution-context.cc b/gcc/rust/resolve/rust-name-resolution-context.cc index 8bb7a9a15c1..f71ef91505b 100644 --- a/gcc/rust/resolve/rust-name-resolution-context.cc +++ b/gcc/rust/resolve/rust-name-resolution-context.cc @@ -43,6 +43,15 @@ NameResolutionContext::insert (Identifier name, NodeId id, Namespace ns) } } +void +NameResolutionContext::map_usage (NodeId usage, NodeId definition) +{ + auto inserted = resolved_nodes.emplace (usage, definition).second; + + // is that valid? + rust_assert (inserted); +} + 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 d63ee33378b..7a1924581ab 100644 --- a/gcc/rust/resolve/rust-name-resolution-context.h +++ b/gcc/rust/resolve/rust-name-resolution-context.h @@ -19,7 +19,6 @@ #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" @@ -179,6 +178,13 @@ public: ForeverStack labels; Analysis::Mappings &mappings; + + // TODO: Rename + void map_usage (NodeId usage, NodeId definition); + +private: + /* Map of "usage" nodes which have been resolved to a "definition" node */ + std::map resolved_nodes; }; } // namespace Resolver2_0 From patchwork Tue Jan 30 12:06:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892855 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=CcqMcRuw; 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 4TPPf170y2z23fD for ; Tue, 30 Jan 2024 23:30:49 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F29B0386EC0E for ; Tue, 30 Jan 2024 12:30:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 334C43857C5E for ; Tue, 30 Jan 2024 12:11:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 334C43857C5E 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 334C43857C5E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::429 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616700; cv=none; b=w/F27HB788IlmMRerK+P7Az+JrvMHnsQIbJkBOrOv38kgQXqpFkyZS6F68qQkAGuPGgw85SYDQ/7rGdsjhE5dopJGfjjOBx1jU4esjL/VT2F8BFa/RgtlDeaF3c2DNyx14BZ5z4jeEZNIxBm6EdHPYuavZf92KL9GVQmQfYIQzk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616700; c=relaxed/simple; bh=6nF3GfjIhkf0+o7M+mjYp9Dg6vUPs+tWmBRRWyGmTj4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FU338R0Yjk7A9i7aKB9n207h+3qdcUBa8VQAgTaCqFhX/k/++Crs4AH3//UkRAHw6L8pDqAyFH7o3oGICkZZPryS65GbIWppoMJUWsmLIWTgrnPLFiwM7u4y4lyctB1T5SBmkoG64tEeqVHzdD/xYO8LLF/5v3wIP5vSP17KsZM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-33ae6dfa923so1618620f8f.1 for ; Tue, 30 Jan 2024 04:11:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616677; x=1707221477; 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=FPdj5EeUJg4+xnxlKqzyKOWIy2wu4ozREOJKI5LW+98=; b=CcqMcRuw0kzNLnxH64uLbixdB67mrpYNvX+Ugc5fw8+cFoNknlfvZCLObidT2oGduQ flrRL7+tyBajxKngxicZvEbAV2SDBvhLX4zmp2KVOi3HsGdEuSma4yb/b6SG5SqZEIwx ntC7jxpo0AHhly4siV9edu2MsD0BqhoYDhPZaiPCaU8hn9S3WQzdxwTy5yhp98jGRK+Z mdoLFr1jMRUOiRIbqWkohDCx1/Ay+3pH3hJJcfEpx8wlRQyWPZwGj0RGKGnuFURkBLEJ mAFKhiqlMshc7zocu5PFiO5cbTwVAE9CabnjFFM3AfQTP1CHV2mIW+1IX+FSfpCeA1OU lbow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616677; x=1707221477; 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=FPdj5EeUJg4+xnxlKqzyKOWIy2wu4ozREOJKI5LW+98=; b=VUx+kV+LeM6spW3CJytt+FYPYyNPKTsk7e0SQFcjO262aTVROwLK1OwF7guHnZ4HlV GqdtbEULwhRXbwo1r/zfQV8fJdjFMjO84vs/EHrwrhP84m3Gmx6AEclWp9e3E6JivVt+ e6QIg/TzfpTsJrRD7mU1Hr5KDWX4hShKYxKC9unVntXMGX66jOP7y1velrDYcLKAXKmP LdcharQHDgoGMKxcUwaALFfNw7ef/wn93cIdMEOEiuvmfl8T1iCCzWTaDu/VIpKyarq7 lp/qAfAEPFvJwvDSvG5l34iL+C7x/mIgSTfcILSrqdrOaZr5fn0GCH9NfjiVFxWrn7UI Ydlw== X-Gm-Message-State: AOJu0YwyugIsODldIJT8jlUI0FEJcJjPOjZnW8/xgBc5k3Iu2WjA8ugJ shscyC1niY8WWGbe33HsWuM1VyX+SPU9/0hNBYqmHXr+ux4MCNAAnb9Yhpu0cOO4YBgDrx5To+c ZiQ== X-Google-Smtp-Source: AGHT+IEGtGyhoGhnGvnV7Ib7sb2eLwADi85D3HXh5uGaCiUDIJiXxsN0RNU42gVkfrWCxgRYK1r+Uw== X-Received: by 2002:adf:f84a:0:b0:33a:de27:b138 with SMTP id d10-20020adff84a000000b0033ade27b138mr6348725wrq.47.1706616677646; Tue, 30 Jan 2024 04:11:17 -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 038/101] gccrs: late: Start storing mappings properly in the resolver Date: Tue, 30 Jan 2024 13:06:54 +0100 Message-ID: <20240130121026.807464-41-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-late-name-resolver-2.0.cc (Late::visit): Store mappings after having resolved them. * resolve/rust-late-name-resolver-2.0.h: Add `TypePath` visitor. --- .../resolve/rust-late-name-resolver-2.0.cc | 33 ++++++++++++++++--- .../resolve/rust-late-name-resolver-2.0.h | 1 + 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc index 3236886f37d..5f70f575582 100644 --- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc @@ -20,6 +20,7 @@ #include "rust-ast-full.h" #include "rust-late-name-resolver-2.0.h" #include "rust-default-resolver.h" +#include "rust-path.h" #include "rust-tyty.h" #include "rust-hir-type-check.h" @@ -121,11 +122,24 @@ Late::visit (AST::IdentifierExpr &expr) { // TODO: same thing as visit(PathInExpression) here? + tl::optional resolved = tl::nullopt; auto label = ctx.labels.get (expr.get_ident ()); auto value = ctx.values.get (expr.get_ident ()); - rust_debug ("[ARTHUR] label: %d", label ? *label : -1); - rust_debug ("[ARTHUR] value: %d", value ? *value : -1); + if (label) + resolved = label; + else if (value) + resolved = value; + // TODO: else emit error? + + ctx.map_usage (expr.get_node_id (), *resolved); + + // in the old resolver, resolutions are kept in the resolver, not the mappings + // :/ how do we deal with that? + // ctx.mappings.insert_resolved_name(expr, resolved); + + // For empty types, do we perform a lookup in ctx.types or should the + // toplevel instead insert a name in ctx.values? (like it currently does) } void @@ -136,11 +150,20 @@ Late::visit (AST::PathInExpression &expr) // do we emit it in `get`? auto label = ctx.labels.resolve_path (expr.get_segments ()); - auto value = ctx.values.resolve_path (expr.get_segments ()); +} + +void +Late::visit (AST::TypePath &type) +{ + // should we add type path resolution in `ForeverStack` directly? Since it's + // quite more complicated. + // maybe we can overload `resolve_path` to only do + // typepath-like path resolution? that sounds good + + auto resolved = ctx.types.get (type.get_segments ().back ()->as_string ()); - rust_debug ("[ARTHUR] label: %d", label ? *label : -1); - rust_debug ("[ARTHUR] value: %d", value ? *value : -1); + ctx.map_usage (type.get_node_id (), *resolved); } } // namespace Resolver2_0 diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h b/gcc/rust/resolve/rust-late-name-resolver-2.0.h index f54bbf2eea4..15940d053ae 100644 --- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h +++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h @@ -45,6 +45,7 @@ public: // resolutions void visit (AST::IdentifierExpr &) override; void visit (AST::PathInExpression &) override; + void visit (AST::TypePath &) override; private: /* Setup Rust's builtin types (u8, i32, !...) in the resolver */ 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 From patchwork Tue Jan 30 12:06:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892847 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=LTH9I/KL; 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 4TPPbN4rJhz23gZ for ; Tue, 30 Jan 2024 23:28:32 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A9B36386C59E for ; Tue, 30 Jan 2024 12:28:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id AE6A53857BBD for ; Tue, 30 Jan 2024 12:11:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE6A53857BBD 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 AE6A53857BBD Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616706; cv=none; b=O3mvoPp48LiLY+7H0j3mYR3aGmmyBdTCHRURARykEF7twg4gS8rnEWr0bw8u6gv7Ll31eQ5Id9ohGPvR/v3Xfg22YdCeOcycva8CfupNUmv6ZDITPTD5MY3aCugbBvsf+w6HtliRCggoLZX6afpsOlZPCLT24XKfv1aZt2ogBEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616706; c=relaxed/simple; bh=GyOCtN1nI3fsNEIJ29hgyTjw2Ha1yrjAh2NplTYbg4Y=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=goN7AuIFM1/CsxDtzuHT0ttYHxuFpBsMfc2Yxe/UjD/irS0aNksr6HmQelvimTVcgSlkUdLEByjUJwRv9rbUXWIMpxM34Grxi+FVXOwtXpX3SbQ5gZMzo+Eoij7kPk5ls8zMh9RpIFfQgy64A/upN6jeaTjamdw5+QKVH8NOioA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-33ae53eb5a8so1724757f8f.3 for ; Tue, 30 Jan 2024 04:11:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616680; x=1707221480; 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=BKw4sa3FTLYF2rhnjQmhSXdN1b9XclNq5ftM6eb8W9Q=; b=LTH9I/KL9LozJkXLRVOVu3EHxVcgaH3RNSk9sDE4iTD5ZFluYJOO2OTx6saT4BOzue GieB8HIUmb9HRNwm7wdRthJAboDTgDwqUKxHRk/bp6q1LE1A8CS0ggrE8wL8107dwoHf AVcyKyHzg34AIlPoNAY6qaMuBY1GZgewagH+ESb0qidt+eJV28yZ/4l9KKEp3RabcHYg xPf8J3Mq5ntWEKW+8XsJq+nSbWKj4ZeGFFvUWhTlImqj2FXDwAhivKovaQ8VyY8oPI9q zAvuVfaOq04IZfzUdvqMxh7w0l7FPFBIeltHZjCZAYbT2itHWGjBEHWE0C6Ov1egkW+X 0ZwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616680; x=1707221480; 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=BKw4sa3FTLYF2rhnjQmhSXdN1b9XclNq5ftM6eb8W9Q=; b=PeEg+sSjixyOxl9GKvcbssTYJnbrzj7qsHA86e2+mYNj+curIdFx6qHG3YVseOzNup 56uA40iW6gyIw/DURvR0lj3PKNRsY5u6e6DAYcdKRWpluKaI0LD8RQGCigWbiSns9WXj k9+XnlDAAdVZMtFnb0c/A3RVPOXzCcsjkQenPro8glW48KVhJoW46+GKbzOBM1AWDQU6 hBTcXXMO5olAZXOjO8TDWRW86udUiIqLbpDc/Slllh/782xJE2g4+FBDrIBGdXjV90nG bylSoN1uzP9+VBF6NqKuW5teVP56zwE0jamsaaNtNMDFT1hCqN2EQepLUPNU0rSiJ6L9 HiGw== X-Gm-Message-State: AOJu0YxfoiLq4Q1fzBZMxKSSgFEzZD1GW3pYxFB4ameBznVqpfJZbs8K 0A9uVi1JflFKJPKLhdubUhorSklK9cYr8ygMhyxddc7xUcwQJyXk+zdrqerdAkAjEi6ywwhCD2a ITw== X-Google-Smtp-Source: AGHT+IG8YGXgjWBu8GKetMO/W4lRqcT541+XQR+Gu21eauJznh3+mbruLXOVfGyfJluo+5hzYjakqQ== X-Received: by 2002:adf:f2c2:0:b0:337:7b14:d9fc with SMTP id d2-20020adff2c2000000b003377b14d9fcmr6410169wrp.12.1706616680671; Tue, 30 Jan 2024 04:11:20 -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.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:19 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 040/101] gccrs: toplevel: Add comment about running the collector twice Date: Tue, 30 Jan 2024 13:06:56 +0100 Message-ID: <20240130121026.807464-43-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-toplevel-name-resolver-2.0.cc (TopLevel::insert_or_error_out): Add documentation comment. (TopLevel::go): Likewise. --- gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc index fbded3e49e1..b9d0bc7c0ac 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc @@ -43,6 +43,9 @@ TopLevel::insert_or_error_out (const Identifier &identifier, const T &node, if (!result) { + // can we do something like check if the node id is the same? if it is the + // same, it's not an error, just the resolver running multiple times? + rich_location rich_loc (line_table, loc); rich_loc.add_range (node_locations[result.error ().existing]); @@ -54,6 +57,11 @@ TopLevel::insert_or_error_out (const Identifier &identifier, const T &node, void TopLevel::go (AST::Crate &crate) { + // we do not include builtin types in the top-level definition collector, as + // they are not used until `Late`. furthermore, we run this visitor multiple + // times in a row in a fixed-point fashion, so it would make the code + // responsible for this ugly and perfom a lot of error checking. + for (auto &item : crate.items) item->accept_vis (*this); } From patchwork Tue Jan 30 12:06:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892865 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=FDlzqANL; 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 4TPPj03KSXz23fD for ; Tue, 30 Jan 2024 23:33:24 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5A63E3875DC3 for ; Tue, 30 Jan 2024 12:33:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id CE65C3857C4F for ; Tue, 30 Jan 2024 12:11:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CE65C3857C4F 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 CE65C3857C4F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::334 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616704; cv=none; b=arC6/ODmP3labLutxh4DQc4CjOdsazwWvxIJI2UDgni2mBpI3IB/LgZ3dlouFF3fcLczCK2fwNEmrgb+yi+d5PQ45b7rfFG5stVKFFTWdBGkwrCkM7gmdegkSUuRcHzZ7IJqvvxVU6w5FfQPzMFiKsi2/tDrFCbG8dyTlBGFoXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616704; c=relaxed/simple; bh=PmfPeuH5NLplIoxJAssKVKIrciuumXAtRat8e7zWGAg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=w/s2D69i8QI0efq7w9IXfevqlWDobLplhjQWie9RjSrSLMXuEkB9CulrCPYn71xKXGjFxYAZ5qWJmAkiwOvIE+1UafQgbiWw+Z9xMOoN9YCeLbMEAfG1olarO/8GFz094y5l4q1ca046GfaJn8kMVWR6ikOGsnfQPcpZh14jhUM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40e76626170so43132975e9.2 for ; Tue, 30 Jan 2024 04:11:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616681; x=1707221481; 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=RSKeSm8i2kDsD+WvFTdI1bJdiVZWWv27HP1DXec1GVI=; b=FDlzqANLVdOwwSP6ioEZ8XN3dz1HezGuJQYOkNvZihNKRh/3JYxSbBTBGR4MAdcMy6 /SRHVuhrOtfApDZTlQMiYpnLJkK3vfOS9x+Oy2qHdFukG1WkFJbmFkyiXlim+3HbIRgG /2hhmJ7e+9D6ChY5MdtNlTcD9iTv5H3eozx7dPcMCfAneQ2PWp35Ac6kskTjvRUWqSAg 6gf576qt8f2Jo8CTBq0xmuPPFv4kSG4IktDG/dow89nieoigk+Uo2I0PU2yUPl1j+r/g VLzjNRq2tHVPHC/tMlR+SggAY3yEWsGV3TR0Av+EtiIlxt1NnEnarTV07U34mEbx/MpO 3bMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616681; x=1707221481; 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=RSKeSm8i2kDsD+WvFTdI1bJdiVZWWv27HP1DXec1GVI=; b=YyVvZkL4I9XO4ADeAzoIzQnteVLkVXthEGeKAW/yyvFZwhZUy936kO72jqJlwvPFF6 xrSOkKkjVxiFHSXV3uYWCo1axuHmfcbS415m5vpUSDS3x4p8GPodKXcAqwJR6EJ67xDt o6IrVeCik4NZbaUZLpKuRYxWTyPYMLxn6X9KKkK5FMie5Bd5+oz8LpqbpvLNAuz/lEk3 p1JqRg4wh8PDYgRvXGqa+lYxYFvHHWyCMzfsODCMS+9fo47qjtsrLSev2mSQJC78veKL GxE2pXdqFokhni2v1VM8sY9f/NI5HOvv0y4yXJP72BEYbD8GwKpyID0Si79nhPNqbiD1 GwMQ== X-Gm-Message-State: AOJu0YzXUEC6NhTnBxk2pE51mOzw1ho9ylDN1ubbk6MIgXj2cRTdMU0/ 76oygchHVo1P+udNSepZyCmYSSqpRUYnyEZ6iDzAZCCQtGHMpEY37Ikg35xL3wne7ucCVr25CcF 4yw== X-Google-Smtp-Source: AGHT+IGuXnGsvoZT6hgqMV/OpGkVL0WXD6VTAFDfhKF43yXozKScTh/En4N+uqaOMBJAqNw34JaRLg== X-Received: by 2002:a05:600c:3547:b0:40e:f5d0:8517 with SMTP id i7-20020a05600c354700b0040ef5d08517mr4938948wmq.33.1706616681040; Tue, 30 Jan 2024 04:11:21 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:20 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 041/101] gccrs: ast: Add NodeId to UseTree base class Date: Tue, 30 Jan 2024 13:06:57 +0100 Message-ID: <20240130121026.807464-44-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.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, 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: * ast/rust-item.h (class UseTree): Add `node_id` member. --- gcc/rust/ast/rust-item.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 2c0e45962ce..3480d126bc0 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -940,6 +940,7 @@ protected: class UseTree { location_t locus; + NodeId node_id; public: enum Kind @@ -975,6 +976,7 @@ public: virtual Kind get_kind () const = 0; location_t get_locus () const { return locus; } + NodeId get_node_id () const { return node_id; } virtual void accept_vis (ASTVisitor &vis) = 0; @@ -982,7 +984,9 @@ protected: // Clone function implementation as pure virtual method virtual UseTree *clone_use_tree_impl () const = 0; - UseTree (location_t locus) : locus (locus) {} + UseTree (location_t locus) + : locus (locus), node_id (Analysis::Mappings::get ()->get_next_node_id ()) + {} }; // Use tree with a glob (wildcard) operator @@ -1182,7 +1186,7 @@ public: Kind get_kind () const override { return Rebind; } - SimplePath get_path () const + const SimplePath &get_path () const { rust_assert (has_path ()); return path; From patchwork Tue Jan 30 12:06:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892852 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=KGvKMqO+; 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 4TPPcv4qqhz23gZ for ; Tue, 30 Jan 2024 23:29:51 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AD404386D60C for ; Tue, 30 Jan 2024 12:29:49 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 92A8A3857C75 for ; Tue, 30 Jan 2024 12:11:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 92A8A3857C75 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 92A8A3857C75 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::431 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616707; cv=none; b=oClxFTq3tO1I9eYWaEJfV2z34+GMOfZhlPQEQceXOtlduhrlaGA2rZ6T/hEDP7VkaFkxWQ9qTZczQTDjm5WUzE8PovCJW6P8G0perO3roe8ZM3xOhDlofOaFnI3oOzVu9dk1OytmrfnRnOZgTf5yNC6wn+RR7pkn0nduTh8arC4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616707; c=relaxed/simple; bh=xs9f1opJG14W66KpdyrMyv4M+XcqDzLAmhyrRRQngLQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=DKM4/itnm7Du6oShr34jcnwyIhKmO18/SbcmE7joqVwARuYbHkRqcu6ZDxb9tRE0wMEqP55wNI2FTwyq3uHNF4LhmLM7EKwN/sX2XuLQGyL1ixk9r5v7atealnkoOZ5RRxvoqr8yRW/yR2FwzRW4C321DxtKMoSV2BQK0wljtCM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-33af4a0beb3so1012526f8f.2 for ; Tue, 30 Jan 2024 04:11:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616682; x=1707221482; 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=vC0IqHsdvNqG39SxHbTKsLNCs01Stc22RvKKxGNwd70=; b=KGvKMqO+woVg91Nz/yLl8wgKlZ0liKtUUJscfRTfutIgRqMKBP+froRLAPGVq3ssSA l83bCJzvnlnyna1Hag2Y92hhlM9UGjjO5ck/zU7I5XDCDdxLdNo4PouPIrJkouESQkE1 4nL97W8UVuJwnKNINOH0JdxRDLBk/yYt1MLPlaUO8/ZkYIQYiV641uJ8WdiVi2w6Yhfi 5PoHqwIWHjldkxpRWatHHjO359CFTMlLfnzF+2kL8XFWJGdFCeEvnUuJ5j0BVjACwmQI w+DcJtC8jyI828sA3fEYDr/UdMd8CuubBAxGF+nBg00NyonXJpbycuxEOEZUwFPVvPH3 drFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616682; x=1707221482; 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=vC0IqHsdvNqG39SxHbTKsLNCs01Stc22RvKKxGNwd70=; b=O6rVq7Y1S0CD2LFJIservrpin+LYDldrf1j0Cl3EIH9f1hBsWkOpUNKt51hQtWYLf3 sX7OLrRMRR6M2Kxpx4HVjkdqfjB06P388nsGnhZzpn24b3dInmhjrlkTp9akgaj/wY55 f1E9iAEQaSdW7kWCAkXD6ixw3RAq5HrRzUKxd5nkDbW9MGc5Q1xx5eP1LXmXI9un1OXk S3mo2IVz+DXxGjeuWa+fxLorHl0WRAFZ1/MtuhZCxmUugsAmtnQFuHw+zx2ov1Tbx9wD ES85OnXxSdjw1a0DL/ka4x86to/M1yhdlg95CEgI0xS7Yb7i1ab84KfPzXjpAy+67y6A Gs8g== X-Gm-Message-State: AOJu0Yz0GUAIyXLM8+tL3X6eXOyzgoFfvqM1PQX9kGZ/BaWvgFNh01jU p9XI3hsiw0mhsMXT/13GstLbHXoM8EPi/IaFrOM0ZNOh8ychoFdOZmuEmCj/oDvScyOgqSK3H7y 1Qw== X-Google-Smtp-Source: AGHT+IFFzrTL2wT0EkYDLwIWAQXtdN8FQ0qDin05+eSoHNsjD6FFhpqCFyNWCk/zLTX7Gw75BwhOLg== X-Received: by 2002:a5d:4412:0:b0:33a:eb5c:aa25 with SMTP id z18-20020a5d4412000000b0033aeb5caa25mr4670219wrq.23.1706616682096; Tue, 30 Jan 2024 04:11:22 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:21 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 042/101] gccrs: early: Move `use` declaration resolving to TopLevel Date: Tue, 30 Jan 2024 13:06:58 +0100 Message-ID: <20240130121026.807464-45-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.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, 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-early-name-resolver-2.0.cc (Early::visit): Remove visitors. * resolve/rust-early-name-resolver-2.0.h: Likewise. --- gcc/rust/resolve/rust-early-name-resolver-2.0.cc | 16 ---------------- gcc/rust/resolve/rust-early-name-resolver-2.0.h | 5 +---- 2 files changed, 1 insertion(+), 20 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 48bb4c68d26..a5d5b191c88 100644 --- a/gcc/rust/resolve/rust-early-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.cc @@ -188,22 +188,6 @@ Early::visit (AST::MacroInvocation &invoc) mappings->insert_macro_invocation (invoc, rules_def); } -void -Early::visit (AST::UseDeclaration &use) -{} - -void -Early::visit (AST::UseTreeRebind &use) -{} - -void -Early::visit (AST::UseTreeList &use) -{} - -void -Early::visit (AST::UseTreeGlob &use) -{} - void Early::visit_attributes (std::vector &attrs) { 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 46c4b936866..d9f985fe575 100644 --- a/gcc/rust/resolve/rust-early-name-resolver-2.0.h +++ b/gcc/rust/resolve/rust-early-name-resolver-2.0.h @@ -50,10 +50,7 @@ public: void visit (AST::Module &) override; void visit (AST::MacroInvocation &) override; - void visit (AST::UseDeclaration &) override; - void visit (AST::UseTreeRebind &) override; - void visit (AST::UseTreeList &) override; - void visit (AST::UseTreeGlob &) override; + void visit (AST::Function &) override; void visit (AST::StructStruct &) override; From patchwork Tue Jan 30 12:06: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: 1892875 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=X2Hj9FDc; 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 4TPPln44sdz23dQ for ; Tue, 30 Jan 2024 23:35:49 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3E13D3830B6C for ; Tue, 30 Jan 2024 12:35:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 776EF3857C62 for ; Tue, 30 Jan 2024 12:11:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 776EF3857C62 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 776EF3857C62 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616715; cv=none; b=D2398w0atJ4nyop5Su9C3uesfP0hLjzGozh433NSWW9r3nNbQb9RFXCEfqSvmUPNL7C2WmpAehipfI80zod3kO061RwY9bfE2rtCp/cK1HOYms4NTQO+Jl21lHi5AcAPoVMKDgOuzGDp4l5LDjz9rf18AZb0sJnkAl5dqzZT+7k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616715; c=relaxed/simple; bh=BVKJ8sACXVsmhFc//7BqHY5D2+2LOSvczYxW6em1ET8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=qZ0YF7O8xeLHz+xhZRMY/3X85VGrHM489gSQ7ByH+BWRkO3W68lv/X33SMfm5yidQRhY0AOOswlcBnygrrUxLhqDMaAoqdyvJBIyFnrswB713R0qkGkzRUeDzflsWueE5BkXZ1RxVClm09ytQkXbUBO2LKhSLYeS9k5YQYMDYZo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-33ae7681d03so1637310f8f.1 for ; Tue, 30 Jan 2024 04:11:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616682; x=1707221482; 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=wGS4ALiOUPQYlG2nSV3vFitujulFJ0ez2ghcKPHcTGI=; b=X2Hj9FDcRFTP+nqNQIGLYYOV8riEIuIuz3OA7rM269Gm5DQhhA45YFkwmXFR8GQJ4b eEkilMipSE7p80t54XcndCbUM+DRtmoaufN1Aj5YXCQv+Ed8ayUZNDG1jDGyGdz6OgqY bnubyUrFWbXESZQch1WQ66HAWf1I285B3GLyRDpxfE8n8nzqz1lHjkBTAwb+S23rKfIy E/wJfQ1354H3wjFVPRQo9b8XNa+CI1Td/dPbpI+5qU48enynHZj41fdePQc2v8ByTozi FpBDV/RMRAAo8UFfxLyfcLthP8uZfHcDWj3FGeEXTesbFp+nEESH9hNSrFJ8vwdsIo3n iqGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616682; x=1707221482; 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=wGS4ALiOUPQYlG2nSV3vFitujulFJ0ez2ghcKPHcTGI=; b=TjK2cKk2jNh1/kisgxOj+07EAc7PirolLdTckpbhvmnp7rMU14NiTx5b+3f0o08Eac 3NN7nw/746VwK60t898q49GZe2eE9j1AKy0AxS9lCCMb3/fepIcSFQz7bNarX5U0ABq4 HwSXMSwWswMN2z+CpbVpPj7WBlQhq35tQM/bmS5iVJWXRhf4qP3JIaen3I2NvwhdSqNr oAqRYJNlBtpQkm4g8tgTxqFnFCGvo7nNrRz8zNm0kV0jELYMDabNTENVYfuMapTMwmJF uebJMrJI+wsELYp5sFAfRDqij3LHkpDB9JjB4QLD63HUNn6bBo4jV12c5t9VMO4gDnU+ MhQw== X-Gm-Message-State: AOJu0YzDgnSg8p5ySt7fMuo48VHqi/1y7zbTL64eMFjwjE6AAoR979IK 1e5acHoD2Vop5d4iZDNu9rgCtSGMxUIxCqEw8SAj3hAkVIoOxGdaoqlj0iKgYOJG89pronp2Wcj Ngw== X-Google-Smtp-Source: AGHT+IGig/rqVithMSgU7aKWeOyH5T1lTPcrCLpN1oio8uIqQIIcwV4ic/RiT05/YzhaIW1n897UIQ== X-Received: by 2002:a5d:4d01:0:b0:337:bfe8:5bfd with SMTP id z1-20020a5d4d01000000b00337bfe85bfdmr5158861wrt.50.1706616682519; Tue, 30 Jan 2024 04:11:22 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:22 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 043/101] gccrs: toplevel: Resolve `use` declarations Date: Tue, 30 Jan 2024 13:06:59 +0100 Message-ID: <20240130121026.807464-46-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.2 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, 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-toplevel-name-resolver-2.0.cc (TopLevel::insert_or_error_out): New functions. (TopLevel::handle_use_dec): New function. (flatten_rebind): Likewise. (flatten_list): Likewise. (flatten_glob): Likewise. (flatten): Likewise. (TopLevel::visit): Visit various `use` declaration nodes. * resolve/rust-toplevel-name-resolver-2.0.h: Declare functions and visitors. --- .../rust-toplevel-name-resolver-2.0.cc | 187 +++++++++++++++++- .../resolve/rust-toplevel-name-resolver-2.0.h | 11 ++ 2 files changed, 194 insertions(+), 4 deletions(-) diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc index b9d0bc7c0ac..46113a8a46b 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.cc @@ -17,6 +17,7 @@ // . #include "rust-toplevel-name-resolver-2.0.h" +#include "optional.h" #include "rust-ast-full.h" #include "rust-hir-map.h" #include "rust-attribute-values.h" @@ -33,11 +34,16 @@ void TopLevel::insert_or_error_out (const Identifier &identifier, const T &node, Namespace ns) { - auto loc = node.get_locus (); - auto node_id = node.get_node_id (); + insert_or_error_out (identifier, node.get_locus (), node.get_node_id (), ns); +} +void +TopLevel::insert_or_error_out (const Identifier &identifier, + const location_t &locus, const NodeId &node_id, + Namespace ns) +{ // keep track of each node's location to provide useful errors - node_locations.emplace (node_id, loc); + node_locations.emplace (node_id, locus); auto result = ctx.insert (identifier, node_id, ns); @@ -46,7 +52,7 @@ TopLevel::insert_or_error_out (const Identifier &identifier, const T &node, // can we do something like check if the node id is the same? if it is the // same, it's not an error, just the resolver running multiple times? - rich_location rich_loc (line_table, loc); + rich_location rich_loc (line_table, locus); rich_loc.add_range (node_locations[result.error ().existing]); rust_error_at (rich_loc, ErrorCode::E0428, "%qs defined multiple times", @@ -308,5 +314,178 @@ TopLevel::visit (AST::ConstantItem &const_item) ctx.scoped (Rib::Kind::ConstantItem, const_item.get_node_id (), expr_vis); } +bool +TopLevel::handle_use_dec (AST::SimplePath path) +{ + // TODO: Glob imports can get shadowed by regular imports and regular items. + // So we need to store them in a specific way in the ForeverStack - which can + // also probably be used by labels and macros etc. Like store it as a + // `Shadowable(NodeId)` instead of just a `NodeId` + + auto locus = path.get_final_segment ().get_locus (); + auto declared_name = path.get_final_segment ().as_string (); + + // in what namespace do we perform path resolution? All of them? see which one + // matches? Error out on ambiguities? + // so, apparently, for each one that matches, add it to the proper namespace + // :( + + auto found = false; + + auto resolve_and_insert = [this, &found, &declared_name, + locus] (Namespace ns, + const AST::SimplePath &path) { + tl::optional resolved = tl::nullopt; + + // FIXME: resolve_path needs to return an `expected` so + // that we can improve it with hints or location or w/ever. and maybe + // only emit it the first time. + switch (ns) + { + case Namespace::Values: + resolved = ctx.values.resolve_path (path.get_segments ()); + break; + case Namespace::Types: + resolved = ctx.types.resolve_path (path.get_segments ()); + break; + case Namespace::Macros: + resolved = ctx.macros.resolve_path (path.get_segments ()); + break; + case Namespace::Labels: + // TODO: Is that okay? + rust_unreachable (); + } + + // FIXME: Ugly + (void) resolved.map ([this, &found, &declared_name, locus, ns] (NodeId id) { + found = true; + + // what do we do with the id? + insert_or_error_out (declared_name, locus, id, ns); + + return id; + }); + }; + + // do this for all namespaces (even Labels?) + + resolve_and_insert (Namespace::Values, path); + resolve_and_insert (Namespace::Types, path); + resolve_and_insert (Namespace::Macros, path); + + // TODO: No labels? No, right? + + return found; +} + +static void +flatten_rebind (const AST::UseTreeRebind &glob, + std::vector &paths); +static void +flatten_list (const AST::UseTreeList &glob, + std::vector &paths); +static void +flatten_glob (const AST::UseTreeGlob &glob, + std::vector &paths); + +static void +flatten (const AST::UseTree *tree, std::vector &paths) +{ + switch (tree->get_kind ()) + { + case AST::UseTree::Rebind: { + auto rebind = static_cast (tree); + flatten_rebind (*rebind, paths); + break; + } + case AST::UseTree::List: { + auto list = static_cast (tree); + flatten_list (*list, paths); + break; + } + case AST::UseTree::Glob: { + rust_sorry_at (tree->get_locus (), "cannot resolve glob imports yet"); + auto glob = static_cast (tree); + flatten_glob (*glob, paths); + break; + } + break; + } +} + +static void +flatten_rebind (const AST::UseTreeRebind &rebind, + std::vector &paths) +{ + auto path = rebind.get_path (); + + // FIXME: Do we want to emplace the rebind here as well? + if (rebind.has_identifier ()) + { + auto rebind_path = path; + auto new_seg = rebind.get_identifier (); + + // Add the identifier as a new path + rebind_path.get_segments ().back () + = AST::SimplePathSegment (new_seg.as_string (), UNDEF_LOCATION); + + paths.emplace_back (rebind_path); + } + else + { + paths.emplace_back (path); + } +} + +static void +flatten_list (const AST::UseTreeList &list, std::vector &paths) +{ + auto prefix = AST::SimplePath::create_empty (); + if (list.has_path ()) + prefix = list.get_path (); + + for (const auto &tree : list.get_trees ()) + { + auto sub_paths = std::vector (); + flatten (tree.get (), sub_paths); + + for (auto &sub_path : sub_paths) + { + auto new_path = prefix; + std::copy (sub_path.get_segments ().begin (), + sub_path.get_segments ().end (), + std::back_inserter (new_path.get_segments ())); + + paths.emplace_back (new_path); + } + } +} + +static void +flatten_glob (const AST::UseTreeGlob &glob, std::vector &paths) +{ + if (glob.has_path ()) + paths.emplace_back (glob.get_path ()); +} + +void +TopLevel::visit (AST::UseDeclaration &use) +{ + auto paths = std::vector (); + + // FIXME: How do we handle `use foo::{self}` imports? Some beforehand cleanup? + // How do we handle module imports in general? Should they get added to all + // namespaces? + + const auto &tree = use.get_tree (); + flatten (tree.get (), paths); + + for (auto &path : paths) + if (!handle_use_dec (path)) + rust_error_at (path.get_final_segment ().get_locus (), ErrorCode::E0433, + "could not resolve import %qs", + path.as_string ().c_str ()); +} + } // namespace Resolver2_0 } // namespace Rust diff --git a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h index 95187d7b3fd..996899b0848 100644 --- a/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h +++ b/gcc/rust/resolve/rust-toplevel-name-resolver-2.0.h @@ -53,6 +53,9 @@ private: template void insert_or_error_out (const Identifier &identifier, const T &node, Namespace ns); + void insert_or_error_out (const Identifier &identifier, + const location_t &locus, const NodeId &id, + Namespace ns); // FIXME: Do we move these to our mappings? std::unordered_map node_locations; @@ -73,6 +76,14 @@ private: void visit (AST::Union &union_item) override; void visit (AST::ConstantItem &const_item) override; void visit (AST::ExternCrate &crate) override; + + // FIXME: Documentation + // Call this on all the paths of a UseDec - so each flattened path in a + // UseTreeList for example + // FIXME: Should that return `found`? + bool handle_use_dec (AST::SimplePath path); + + void visit (AST::UseDeclaration &use) override; }; } // namespace Resolver2_0 From patchwork Tue Jan 30 12:07:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892870 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=JcaZb38k; 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 4TPPkW6WHBz23fD for ; Tue, 30 Jan 2024 23:34:43 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DA6FC3839391 for ; Tue, 30 Jan 2024 12:34:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id A487E3857BB0 for ; Tue, 30 Jan 2024 12:11:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A487E3857BB0 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 A487E3857BB0 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616707; cv=none; b=TngmyX2x5CUPOL/E9usi7FpQJKKLzkzKlecMnseKj6mZL7NnIJIemqgBZN4bvUa1Xk+4DmQ21kabtLYAXc91EqO0VW9LHJmgLGNCYyT4bj3O9IIw07hCAA1MXcanaBrHbUGVUwnefmwUDCnsBXiQ4XHKbIbbvxWt0a4SBmLdwDU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616707; c=relaxed/simple; bh=yPKXpPxnOQTpbHUDamMl/Ml582TbJ6WIuLmAB5cbXaM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FrpVu3qdA2tLg9/GtVwo6LKOQoNa2bvso/j3J2TQNSstFwViEA8/mc5u+fqcgXkZFGUUiER/MgRwQXmMh+jGagMKKQg91IzD/dv0rw7k/Rt0+JlPaahofssTIip2/v3BGHH1cwWLLhJkqMoD8ReMeI43SWJTD9iVZAFrdbGqA4Q= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-40eac352733so45203385e9.0 for ; Tue, 30 Jan 2024 04:11:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616683; x=1707221483; 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=F073MiJkCiGqDD6228no/Xdl2CrJSgpaQ9S47fRZZgE=; b=JcaZb38klQWwm4rPDPUbxcwOZ38II34de3Kmg3d6tV3caMDYWt73v5wJU5ekv7200s f/Th+LqT/TcY18DErUFBU0nIIEN2EbDrd8Sn0Zqsz6rD4rwqIwDTbCmn3JoVxtj5R+v0 EHWvyjskc3Xb0LQH2XYI+qw92LyVO7eAel3MtECZ/nEOP5sT1Rt8IRK86Yb2qUheeXqF fjlPAcdLOGCPIbc8RdAR9ykgjXOILIc29lebdqMzG7+fJHbUUcbrLN8EKZbVS5nOhEal 48A8pIqM65ZWVszALgbnlgtt2Ge6WZA8EO0zPXhaewLRGIQiKG/196KMoOE7lyIuibz0 uiqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616683; x=1707221483; 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=F073MiJkCiGqDD6228no/Xdl2CrJSgpaQ9S47fRZZgE=; b=BTII68T7xV/sTOXsIwlrYjnlnSPFyeD6nPR+6McpzHGUeBYcD4PHZnyGxZSY0oVVq8 7X2aqMiKwv7K6GsS9AhTGpsE7xHozrAAmQve97JHbEAztFfHTHRWIgXQXyWfr7Yzzgv2 LYehq9pIugramTx8mUbWb+6A2K0uifu6o/Gs/S5Z4v0ob7aBTXi5JSsr3A1YD3j/JG2B +SVVz082J/cb6sk0lokIzTfHezSVbeehXoCMUf/XnHzn0De7OlAeUXVcpk2CreeqOPL4 jGXJZQ71r4hReEXYNhKIkgkYieLssu43f8HmMI0Xzkt7yPzbmo7ioV6P9PYfs0CjXVju srcQ== X-Gm-Message-State: AOJu0YxvHjSREnTActj/pLh3Oms++vDjFVb3zB2W2UKocrtKOLXlySAf rt2fg2cBUplIVVRc0HmrNZJMSxrDh0OANAB5c5eTYrxLgIZKMR0m8KNqsr0pBdLySAhbQz1oGfV RCw== X-Google-Smtp-Source: AGHT+IHz/5/6KdgPJTAmPzQVF2RZp1ZWSGwOYhyKaQmrq90MYrtZmYhdJWJQVHZEzcGFEDB3KRoYbA== X-Received: by 2002:a05:600c:4fce:b0:40e:fc23:4010 with SMTP id o14-20020a05600c4fce00b0040efc234010mr2502711wmq.12.1706616682908; Tue, 30 Jan 2024 04:11:22 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:22 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [COMMITTED 044/101] gccrs: Create base class for TupleStructItems and TuplePatternItems Date: Tue, 30 Jan 2024 13:07:00 +0100 Message-ID: <20240130121026.807464-47-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: Owen Avery gcc/rust/ChangeLog: * hir/tree/rust-hir-pattern.h (class TupleItems): New. (class TupleStructItems): Inherit from TupleItems. (class TuplePatternItems): Likewise. Signed-off-by: Owen Avery --- gcc/rust/hir/tree/rust-hir-pattern.h | 47 ++++++++++++++-------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/gcc/rust/hir/tree/rust-hir-pattern.h b/gcc/rust/hir/tree/rust-hir-pattern.h index 33025bfdb6b..e65a62f20a8 100644 --- a/gcc/rust/hir/tree/rust-hir-pattern.h +++ b/gcc/rust/hir/tree/rust-hir-pattern.h @@ -777,8 +777,8 @@ protected: } }; -// Base abstract class for patterns used in TupleStructPattern -class TupleStructItems : public FullVisitable +// Base abstract class for TupleStructItems and TuplePatternItems +class TupleItems : public FullVisitable { public: enum ItemType @@ -787,25 +787,38 @@ public: RANGED, }; - virtual ~TupleStructItems () {} + virtual ~TupleItems () {} // TODO: should this store location data? // Unique pointer custom clone function - std::unique_ptr clone_tuple_struct_items () const + std::unique_ptr clone_tuple_items () const { - return std::unique_ptr (clone_tuple_items_impl ()); + return std::unique_ptr (clone_tuple_items_impl ()); } + virtual ItemType get_item_type () const = 0; + virtual std::string as_string () const = 0; - virtual void accept_vis (HIRFullVisitor &vis) = 0; +protected: + // pure virtual clone implementation + virtual TupleItems *clone_tuple_items_impl () const = 0; +}; - virtual ItemType get_item_type () const = 0; +// Base abstract class for patterns used in TupleStructPattern +class TupleStructItems : public TupleItems +{ +public: + // Unique pointer custom clone function + std::unique_ptr clone_tuple_struct_items () const + { + return std::unique_ptr (clone_tuple_items_impl ()); + } protected: // pure virtual clone implementation - virtual TupleStructItems *clone_tuple_items_impl () const = 0; + virtual TupleStructItems *clone_tuple_items_impl () const override = 0; }; // Class for non-ranged tuple struct pattern patterns @@ -1011,32 +1024,18 @@ protected: }; // Base abstract class representing TuplePattern patterns -class TuplePatternItems : public FullVisitable +class TuplePatternItems : public TupleItems { public: - enum ItemType - { - MULTIPLE, - RANGED, - }; - - virtual ~TuplePatternItems () {} - - // TODO: should this store location data? - // Unique pointer custom clone function std::unique_ptr clone_tuple_pattern_items () const { return std::unique_ptr (clone_tuple_items_impl ()); } - virtual std::string as_string () const = 0; - - virtual ItemType get_item_type () const = 0; - protected: // pure virtual clone implementation - virtual TuplePatternItems *clone_tuple_items_impl () const = 0; + virtual TuplePatternItems *clone_tuple_items_impl () const override = 0; }; // Class representing TuplePattern patterns where there are multiple patterns From patchwork Tue Jan 30 12:07: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: 1892857 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=hVdIb35q; 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 4TPPf849Ktz23fD for ; Tue, 30 Jan 2024 23:30:56 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8CABA386C586 for ; Tue, 30 Jan 2024 12:30:54 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 867DD3857C4D for ; Tue, 30 Jan 2024 12:11:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 867DD3857C4D 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 867DD3857C4D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::433 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616710; cv=none; b=T2SPG6tS/mvuQ8yX/WkG9tPZZgfDNi7qwJ+v9Dub1paW1pQfIHYVXrxQ1X9F9B5sh+pCNvyxgICtYeb3nS2X4X+EcvPBTiDI7+2YCCc9wG+5QJ+Ef50ij6mYW0eTaKsjILPouhcEbAhmJyjpbbacDywg+QzSYs+6iVG/ShHhCc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616710; c=relaxed/simple; bh=7k7mn6p3lrl2ihACY7vMxG71UCBRpmbrae3GAaT5gH0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TVYxM4x2Orvp4f3mirT8jVc1IbR7Id9KM6r7lsLpHrfaGeIOzp10co7H8AT4olYOPwBrIiTOMVo9IZeAc4+IbHDq+O2PABsjqnIQGFXtbCtZRBe9Pd30ru/p0V3OQJrgkYcFDWnQ+68eSLw9/hNXCbc2U5ucjV9l4dRYrH+WQt0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-33ae4205ad8so2009278f8f.2 for ; Tue, 30 Jan 2024 04:11:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616684; x=1707221484; 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=q9oMAxsEtHW0+XB5LokHl9xydjw6XePdJYl8XMqhRK8=; b=hVdIb35qvIJnx0BxAbaDY9Mwwa9U4sJHe1/H00WBbj+fDPQp3VDe5TC886uXoGVbph GbLX8hRKd7ix5STCnvSYoaEIZq9tfZVAav+l+1hj4XMq54u+mwuCRLhV+yl9HiC6bKTP oUw4kVD+MIKZR+ocHmNvwOCoELwi7lotxqHXn5RAHHcwXNKzJgJn5i9QCLocnnjlgtz5 kmK6ojdLRwoeC7SREx75wRTq2B59cSTRhVIvm2IG5wXr0wTKB34TAT4lKIMYjYPxLiy+ kTBOVjLc2GgMWC4o3eiB5lRXmSKggyPJvvtTS9kZejf1fVG53YUQyrIm47/oe/frV7ox xXCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616684; x=1707221484; 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=q9oMAxsEtHW0+XB5LokHl9xydjw6XePdJYl8XMqhRK8=; b=aQN1oOfJ7uR2Qi4H2Sf2wC1RWx66XqSDrjO2XY3/PY/BmE+RHdYBks+P+v7xUfWOlb 9NMdw5o4s7NBRLabZNqxlxIRwaOt8xgXvNOXEix0FiLhYlu39VBpwdHFQR0BhYL1opCE 4v5+PjPhGv8MxA38ywonKGvS3E2MHGwJzoqkaOlLchU7z1A8yFFShPLAt4/Kx5ZqHl8s uaRds5Cw94nYhtUlymiy4BkTT3uUm1H+VlOgkA08lfFsSR+g5f2A4JtLU6HgOs3AmZ5p rOu0UgaWsERCJCofAhYNxWsNq1t2excY1Qc+eGqs110tiD0GrtzQUQNcTzOhpAr1c/aE Ak7A== X-Gm-Message-State: AOJu0YynjxaWS5VplOJu3mbo9z7zxjY3TIKB6XV3p6H4LEO6DN+QXGWu kJeEG6agVTtkj92BzbPx47rCNksslFoUkdl61yC6bSqorpNOfvHJTpE50EgTvGpul8xbC3ZS8RN 4zw== X-Google-Smtp-Source: AGHT+IELSa0EqUhjwejr8MB6WzX22ajSashhT5PgNXzLwH/JFytab6Zu1jeeOUWQUMSlvjyiO17bsA== X-Received: by 2002:adf:fecc:0:b0:33a:e89f:1dc6 with SMTP id q12-20020adffecc000000b0033ae89f1dc6mr4240599wrs.29.1706616684156; Tue, 30 Jan 2024 04:11:24 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:23 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 045/101] gccrs: Add unsafety member to modules Date: Tue, 30 Jan 2024 13:07:01 +0100 Message-ID: <20240130121026.807464-48-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: Pierre-Emmanuel Patry The rust syntax allows unsafe module even if those are rejected at a later stage. gcc/rust/ChangeLog: * ast/rust-item.h: Add safety status to Modules in the AST. * parse/rust-parse-impl.h (Parser::parse_module): Adapt constructors. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/ast/rust-item.h | 13 ++++++++----- gcc/rust/parse/rust-parse-impl.h | 8 +++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 3480d126bc0..6c3715e1eeb 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -736,6 +736,7 @@ private: Identifier module_name; location_t locus; ModuleKind kind; + Unsafety safety; // Name of the file including the module std::string outer_filename; @@ -766,11 +767,12 @@ public: // Unloaded module constructor Module (Identifier module_name, Visibility visibility, - std::vector outer_attrs, location_t locus, + std::vector outer_attrs, location_t locus, Unsafety safety, std::string outer_filename, std::vector module_scope) : VisItem (std::move (visibility), std::move (outer_attrs)), module_name (module_name), locus (locus), kind (ModuleKind::UNLOADED), - outer_filename (outer_filename), inner_attrs (std::vector ()), + safety (safety), outer_filename (outer_filename), + inner_attrs (std::vector ()), items (std::vector> ()), module_scope (std::move (module_scope)) {} @@ -779,18 +781,19 @@ public: Module (Identifier name, location_t locus, std::vector> items, Visibility visibility = Visibility::create_error (), + Unsafety safety = Unsafety::Normal, std::vector inner_attrs = std::vector (), std::vector outer_attrs = std::vector ()) : VisItem (std::move (visibility), std::move (outer_attrs)), module_name (name), locus (locus), kind (ModuleKind::LOADED), - outer_filename (std::string ()), inner_attrs (std::move (inner_attrs)), - items (std::move (items)) + safety (safety), outer_filename (std::string ()), + inner_attrs (std::move (inner_attrs)), items (std::move (items)) {} // Copy constructor with vector clone Module (Module const &other) : VisItem (other), module_name (other.module_name), locus (other.locus), - kind (other.kind), inner_attrs (other.inner_attrs), + kind (other.kind), safety (other.safety), inner_attrs (other.inner_attrs), module_scope (other.module_scope) { // We need to check whether we are copying a loaded module or an unloaded diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 53b3839db37..2e24a66123b 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -22,6 +22,7 @@ /* DO NOT INCLUDE ANYWHERE - this is automatically included with rust-parse.h * This is also the reason why there are no include guards. */ +#include "rust-common.h" #include "rust-item.h" #include "rust-token.h" #define INCLUDE_ALGORITHM @@ -2446,8 +2447,8 @@ Parser::parse_module (AST::Visibility vis, // Construct an external module return std::unique_ptr ( new AST::Module (std::move (name), std::move (vis), - std::move (outer_attrs), locus, lexer.get_filename (), - inline_module_stack)); + std::move (outer_attrs), locus, Unsafety::Normal, + lexer.get_filename (), inline_module_stack)); case LEFT_CURLY: { lexer.skip_token (); @@ -2503,7 +2504,8 @@ Parser::parse_module (AST::Visibility vis, return std::unique_ptr ( new AST::Module (std::move (name), locus, std::move (items), - std::move (vis), std::move (inner_attrs), + std::move (vis), Unsafety::Normal, + std::move (inner_attrs), std::move (outer_attrs))); // module name? } default: From patchwork Tue Jan 30 12:07:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892862 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=KCLw4eCz; 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 4TPPgT0QXjz23fD for ; Tue, 30 Jan 2024 23:32:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 09C8D3870881 for ; Tue, 30 Jan 2024 12:32:03 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 8690E385782D for ; Tue, 30 Jan 2024 12:11:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8690E385782D 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 8690E385782D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616712; cv=none; b=hRfgkh/ojEObyuvQBqNaRVBtAQJuDfUFOpCtuMmr3L66vYCLi2B7k8FIEXb0axgfMO7gWCAQgWdcnc0pV7ntiAW7XT99hLnBZ8aNlh1hmx1Rp/VeOKzcGDnUjapDuMi9AHgeGzUPTpH9NflOWa1z7OEBSPehVxfSBemnR6+Kxus= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616712; c=relaxed/simple; bh=NYOKnVWnKhuvmoZGlMgKSFSfqUCcGPbjfw86tAxUk7w=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Mca85TKAiONgEhiXodJSwW9aKHHySIq5B4gSUdwFNmJFvtop03JPzLYsE40QoI07NNQLtNsx2PmH2n6vkQW1b8UUYIHeLViXf7xxfVYJEBf0/dQ5pHx+/rVYhV8ykGXGJlnsxERG5A2szWmX2qiD4vS4MzhWReVeeO9YDvoSvrM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-33ae3be1c37so1526878f8f.0 for ; Tue, 30 Jan 2024 04:11:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616684; x=1707221484; 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=va+LYfijWme9/ALyMlaIBEYoWp8IPMW9d86uzJ8zUvw=; b=KCLw4eCz6MsAeiyd9X/a0Z4m5jduafUBwQK0mJz6WNYdki0ng+96bwQ56dgT7KX5CR X0I6Q9PqxZxZlEjsU1a6lHGS+0M++Drn1/+/FRyWsBzHbaps0Xho5sRocU89mlwXLQcc PtQ35PpvnPQHQIqOlKcTbnQyVUB6jTO8ZwJSz2CZTQrpG8sYWuzr7lN4v2+sMGh7fjGL jAC/f49IFgloehgrGEVSjImGYPCsSYmrELql3/vfjpcrHKg0uJaFy3YpRGyi+Kcz9Qjv NpP8VszKfRySFSsBZ1hIgf6d45WN8eMGgmxFmw1Ce4cYgLMUy9uW7al9E9agwvIMtYYb 4Qmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616684; x=1707221484; 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=va+LYfijWme9/ALyMlaIBEYoWp8IPMW9d86uzJ8zUvw=; b=ppyzzwbLj6/GtSJRppFHY3b68MlHROq2QB3Ln0ozjM5mWX7xREMMIk08KI7CKRfghG s0TtyIOZlP2kXUdBCCX9KEmOvD/p+UNyZA8vaCL6Fs3Lotm9wUX3+ODncDTu2LjyCvt1 eSwoFOu0VXp5dHlcjkNHPEokPPrnP0o+oZWd37BJbJWTg35qu/lR7FRLjbqhFZfFlPxc WurKDQF2K/idE1q8gP/hCgxTUmLI8jbdBcEczZnBFFwzr/qhvV4x32a5jl8vmBmnontD k/oXp1fsL3yWP24j++rhBEqavuPN2+tBqY7S5c26ap4kGX0z3pusp6kKnr6gUuRktXo9 IgWQ== X-Gm-Message-State: AOJu0YwRhlWHVX83NWdg6aFNg3P+nrzw5TYVvrzpcp+DkDJAP13ERLro CC0XSelQwnOGDsSUEIHLS9C8yd/M11WNUAlxPtZA36CMMzbB67v3TxzMvvM6shKeYB9aNUgUCS8 haw== X-Google-Smtp-Source: AGHT+IGWGcUNTuQC25ZfvP+JbP3gDwijZa0cT1CKusz1GJcZz07NfbTBsLwyCDOeQxPIHGIvIY8kpw== X-Received: by 2002:a5d:4a92:0:b0:33a:de67:fbb0 with SMTP id o18-20020a5d4a92000000b0033ade67fbb0mr1229656wrq.6.1706616684580; Tue, 30 Jan 2024 04:11:24 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:24 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 046/101] gccrs: Parse module safety Date: Tue, 30 Jan 2024 13:07:02 +0100 Message-ID: <20240130121026.807464-49-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.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, 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: Pierre-Emmanuel Patry Unsafe module are rejected at a later stage but could not be parsed properly. This commit changes the parser in order to allow unsafe module in the AST. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_vis_item): Dispatch to parse module when meeting an unsafe module. (Parser::parse_module): Set unsafe status when the parser encounter an unsafe keyword. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/parse/rust-parse-impl.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 2e24a66123b..8087e0c2b94 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -1418,6 +1418,8 @@ Parser::parse_vis_item (AST::AttrVec outer_attrs) return parse_function (std::move (vis), std::move (outer_attrs)); case IMPL: return parse_impl (std::move (vis), std::move (outer_attrs)); + case MOD: + return parse_module (std::move (vis), std::move (outer_attrs)); default: add_error ( Error (t->get_locus (), @@ -2427,6 +2429,13 @@ std::unique_ptr Parser::parse_module (AST::Visibility vis, AST::AttrVec outer_attrs) { + Unsafety safety = Unsafety::Normal; + if (lexer.peek_token ()->get_id () == UNSAFE) + { + safety = Unsafety::Unsafe; + skip_token (UNSAFE); + } + location_t locus = lexer.peek_token ()->get_locus (); skip_token (MOD); @@ -2447,7 +2456,7 @@ Parser::parse_module (AST::Visibility vis, // Construct an external module return std::unique_ptr ( new AST::Module (std::move (name), std::move (vis), - std::move (outer_attrs), locus, Unsafety::Normal, + std::move (outer_attrs), locus, safety, lexer.get_filename (), inline_module_stack)); case LEFT_CURLY: { lexer.skip_token (); @@ -2504,8 +2513,7 @@ Parser::parse_module (AST::Visibility vis, return std::unique_ptr ( new AST::Module (std::move (name), locus, std::move (items), - std::move (vis), Unsafety::Normal, - std::move (inner_attrs), + std::move (vis), safety, std::move (inner_attrs), std::move (outer_attrs))); // module name? } default: From patchwork Tue Jan 30 12:07:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892891 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=gMkmYAi2; 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 4TPPrW0SqZz23dQ for ; Tue, 30 Jan 2024 23:39:55 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E53CA386C580 for ; Tue, 30 Jan 2024 12:39:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 04F353858030 for ; Tue, 30 Jan 2024 12:11:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 04F353858030 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 04F353858030 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616717; cv=none; b=LHddiDQU91tE5j5FX9OdHcrrOWbxJ53+Cgw/GErY5u6pWflm9FM+3NR9Ii9NFWt4nkD/Apnshx9lcGsL5CrkhlOihmWbSoQm/MUnRX6ETIxOsPa5TUg0U1kH2ps0+RmbE74bnhzcczOscMYPK4MVVvmZqtlZWIQMQm56Bkjbm4Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616717; c=relaxed/simple; bh=00nRjnHHJq9fBu0ZaHV3VwDZTOTf5fE0DHaZ1dHL9ho=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Iw6ea5lZDEg+ZgPa0MkMJrSGXHYb2T/iuYjjhoRHOIXAX2KVSjF9PqFdcpOcfqHE3pEDmLpQphc0wouqsBbjQ/Co6GHX3JY2nJekQVNgZd7P55Efa8jMVXiMiJYndbLcHJllGEz7KctpG2OcYLNogJWnC7sR6APoaB8u0nQKkSc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-33af4b34e2cso886292f8f.1 for ; Tue, 30 Jan 2024 04:11:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616685; x=1707221485; 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=ZH4vvIuF+7pTIw66MvBZAdzSsMEAsHlBYHth5nnlIsI=; b=gMkmYAi2hv6tqg7bD0WqV0WNFMR/IJ+stDiPbQK9n9vLnv5l4yBnGiHBTaMfajEvjy 16Ec64BkjIXaeq8lxXuv0o29P9/hyeEM6XHBXdbkMUk/48vdK5qXXR84r8ooYPRIIico Svuxf7VCVn1Z9UsFvADEuavWbYelgqE/mQ4WYrhfQ/nOpGOS1StZBZ5qRtTS25670Gl3 tS6DzvHdamCUUvoI29FGvBiXyDkLK1DqJsu7OEy084pNu75HXGkthN9Vd24v3hwGTmUJ 5q1PHYbfofJe3zM4FPIop53FxYV2bAGXGyoQ6c/oj+ZC2zjVtGjDRYMFMmU7hujkhIS2 5Q2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616685; x=1707221485; 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=ZH4vvIuF+7pTIw66MvBZAdzSsMEAsHlBYHth5nnlIsI=; b=OFLf915SQyJeDDhbh9pe1pT6eu5aSnRTSn1zz6ky/frMK48hrMiVB4lUaWZniaBVY7 hgTOnhi2k2iSkqcffyMxXLWMV3kcJvsNl8G0rqAKphYUOGzjudw9ekjU2mFbhsrBHqco QOY8EiryB1Muj9tBztADaH0m82GD8mJWZzN4G/R/6ozr6d3dfwEE7c1VL0dJxcAQEfDo YPvTKF3GWEnfxxmwmhUZ6M+6n/1nBAalSWQlw9Yw9NI35AxmTF3w6It4vvvImZ20CEx9 Tqg87cSOPhFxha4h9vVR7cSzwtk2/FGAscTpiDpSpVr4iLhLFOnESDYGF/NMLop2O20q 7jCw== X-Gm-Message-State: AOJu0YwFkU/xJjmODBda5SkLaRbz/F1psN6ndbsqbUiRHSLkC9kdDFSo NVyyo0rGoGuVl3zxVZFoihxqbOMp7EAkzjYl8bKfWp/ATiZ1QOkJI2LlxWvCAk/qdM5g0eU3LBc 5SQ== X-Google-Smtp-Source: AGHT+IFgRh7a4Ybe+dAqDvUc/LRR4b+eCqbdS2WTexe4f/R2/HWCd18Kw7dsnoHWnRggjILM3NmYvg== X-Received: by 2002:a5d:6d82:0:b0:33a:fe2f:6c96 with SMTP id l2-20020a5d6d82000000b0033afe2f6c96mr482588wrs.8.1706616685556; Tue, 30 Jan 2024 04:11:25 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:24 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 047/101] gccrs: Emit an error on unsafe modules Date: Tue, 30 Jan 2024 13:07:03 +0100 Message-ID: <20240130121026.807464-50-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, KAM_SHORT, 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: Pierre-Emmanuel Patry An error should be emitted on unsafe modules during the AST validation pass as the syntax allows those even though they're not alowed later down the line. gcc/rust/ChangeLog: * ast/rust-item.h: Add safety getter to modules. * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Check a module's safety and emit an error when meeting an unsafe module. * checks/errors/rust-ast-validation.h: Add function prototype. * parse/rust-parse-impl.h (Parser::parse_module): Move the module locus to the first token instead of the mod keyword. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/ast/rust-item.h | 2 ++ gcc/rust/checks/errors/rust-ast-validation.cc | 10 ++++++++++ gcc/rust/checks/errors/rust-ast-validation.h | 1 + gcc/rust/parse/rust-parse-impl.h | 3 ++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 6c3715e1eeb..3bf023b3c5a 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -840,6 +840,8 @@ public: // Returns the kind of the module enum ModuleKind get_kind () const { return kind; } + Unsafety get_unsafety () const { return safety; } + // TODO: think of better way to do this - mutable getter seems dodgy const std::vector &get_inner_attrs () const { return inner_attrs; } std::vector &get_inner_attrs () { return inner_attrs; } diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index dad7f5edded..4b209908f9e 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -17,6 +17,7 @@ // . #include "rust-ast-validation.h" +#include "rust-common.h" #include "rust-diagnostics.h" #include "rust-item.h" #include "rust-keyword-values.h" @@ -136,4 +137,13 @@ ASTValidation::visit (AST::Trait &trait) AST::ContextualASTVisitor::visit (trait); } +void +ASTValidation::visit (AST::Module &module) +{ + if (module.get_unsafety () == Unsafety::Unsafe) + rust_error_at (module.get_locus (), "module cannot be declared unsafe"); + + AST::ContextualASTVisitor::visit (module); +} + } // namespace Rust diff --git a/gcc/rust/checks/errors/rust-ast-validation.h b/gcc/rust/checks/errors/rust-ast-validation.h index 1052168ea72..01d923ceff3 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.h +++ b/gcc/rust/checks/errors/rust-ast-validation.h @@ -34,6 +34,7 @@ public: void check (AST::Crate &crate) { AST::ContextualASTVisitor::visit (crate); } + virtual void visit (AST::Module &module); virtual void visit (AST::ConstantItem &const_item); virtual void visit (AST::Lifetime &lifetime); virtual void visit (AST::LoopLabel &label); diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 8087e0c2b94..f83cc122c89 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -2429,6 +2429,8 @@ std::unique_ptr Parser::parse_module (AST::Visibility vis, AST::AttrVec outer_attrs) { + location_t locus = lexer.peek_token ()->get_locus (); + Unsafety safety = Unsafety::Normal; if (lexer.peek_token ()->get_id () == UNSAFE) { @@ -2436,7 +2438,6 @@ Parser::parse_module (AST::Visibility vis, skip_token (UNSAFE); } - location_t locus = lexer.peek_token ()->get_locus (); skip_token (MOD); const_TokenPtr module_name = expect_token (IDENTIFIER); From patchwork Tue Jan 30 12:07:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892880 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=Aj3UWzM/; 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 4TPPnB5cwMz23dQ for ; Tue, 30 Jan 2024 23:37:02 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B70B6386D62C for ; Tue, 30 Jan 2024 12:37:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by sourceware.org (Postfix) with ESMTPS id CF0803857C6B for ; Tue, 30 Jan 2024 12:11:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CF0803857C6B 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 CF0803857C6B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::232 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616716; cv=none; b=YmZHIeCrQHtE9hqlGo6R1vqNID482cpmtZ2aiPkBWdoKUSCEjWvq8FJO572UdjaUKHBTo4KlX1x6Zd8uCYhWHnDmPP/klTdokHWwI+YG5iCllNBUzmvIcr84LOhYnc2OBEwGOTMvlAVSu//TYikFgCeo75uRp8GEfbWw3c/anXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616716; c=relaxed/simple; bh=oMoyf80rbmNBAZ77dXgUqcDOvDVJbdUSKWvMsyEfsjQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TG9HWLLb/0T1uHiuHC1e/Lf4Ia4IJ5U3lpUORZr+bIyH5bO/Twc2BCDBuOgLfnep05dgL6o/4yDOT8HQXF0DX/iQ40kwDulJsJPWK2IbuWscOxyXlm1+hGeRS34397efF1mvHpvuSu+4SD/a7Sa8hTPZ/TnhV105iwZKTzAFGPU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2cf4fafa386so42062041fa.1 for ; Tue, 30 Jan 2024 04:11:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616686; x=1707221486; 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=EBcdqOZbA5r0AWMzgecOwbUYrIlseKC+LN85LsPlD/A=; b=Aj3UWzM/mphRvlRULiXmG436CB8vexXB3fPTSjdZUVZR87jGsi68w4QVhHsvbiEjl0 Kw/KJ9OzcWT2ADfW62VoCfaZutKahmzADCJdFHKrXXGF11kHw5YgflhZLbvj3NhfrLph NtMREuArcnPveuXvobXUMZAQawEQYsEZGAQl0IUfLVkEa+yQJiJW5/4Qgnmp+70DHn+o egkapVNLXzAFH16KHl3xz1d5aq5rrZtC++kFBYo1T2vfHZkNj/Jk0zSYGR4gjpp6l6QB hca24ZQn5I1rm1JdCKSfMniR8dhRWdp+OhRNjg9+v2Uc2XMbKcMGf7VD97O8S7PSX2Cf kOqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616686; x=1707221486; 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=EBcdqOZbA5r0AWMzgecOwbUYrIlseKC+LN85LsPlD/A=; b=jYKwSVuociUVq5rtWDLAh8OEb5hB42HBu/yazeTna7LVQJ4S1A2hV2VOA+sVcRT4wX 3e/XqgnWzn2VyyeNL2hWKBQKWxKtYUwz8bepaiyFe4Go+5Arvs3uER5PTLoSa5GDsgBH S2zmJoePDOJX4C95hDjdMAy0GzC+xdBE5jA3LmntoqVMk+A089Wzt/J5+hwQ7DeXD3uT Srh7tf9a8rrAUeM/LtrD1eyRNeYgY6qiZhI7VLg8htv+aKUgiR1W4Vkq9IY0TRjHAuvQ oP/KhhP+CQJqtQPu42e6fw5e1FcNBXUz/6GLzIUrrQRi5nv2MmGTG9IwX2KGAn9viu1K L7Vg== X-Gm-Message-State: AOJu0Yw7aWQ5qR21KTJfccgTN+0PV77iwKNTOaBdqgKKbghLzZF9SsUZ x1703ZoJfCeba+mCheK7mFuD10hl21IZsTmXBvNeymQWroufFyVEBU21mbfQi5hAfFmCqEBnw7/ Hkw== X-Google-Smtp-Source: AGHT+IF0iy/kEhmhdYIYm6wPBUnZh4r3kvLKBEv4RGTLq+3acJHlaJohkOs6nzXjRJ8d+iabn2twgw== X-Received: by 2002:a2e:8342:0:b0:2cf:433c:b3e with SMTP id l2-20020a2e8342000000b002cf433c0b3emr5320591ljh.8.1706616686184; Tue, 30 Jan 2024 04:11:26 -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.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:25 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 048/101] gccrs: Add a regression test for unsafe module validation Date: Tue, 30 Jan 2024 13:07:04 +0100 Message-ID: <20240130121026.807464-51-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.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, 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: Pierre-Emmanuel Patry Add a new test to check for unsafe modules during AST validation pass. gcc/testsuite/ChangeLog: * rust/compile/unsafe_module.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- gcc/testsuite/rust/compile/unsafe_module.rs | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 gcc/testsuite/rust/compile/unsafe_module.rs diff --git a/gcc/testsuite/rust/compile/unsafe_module.rs b/gcc/testsuite/rust/compile/unsafe_module.rs new file mode 100644 index 00000000000..74bc170be5b --- /dev/null +++ b/gcc/testsuite/rust/compile/unsafe_module.rs @@ -0,0 +1,2 @@ +unsafe mod toto {} +// { dg-error "module cannot be declared unsafe" "" { target *-*-* } .-1 } From patchwork Tue Jan 30 12:07:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892831 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=gt1hC2VB; 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 4TPPWB6rR6z23dQ for ; Tue, 30 Jan 2024 23:24:54 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DA383385E830 for ; Tue, 30 Jan 2024 12:24:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 351413857C53 for ; Tue, 30 Jan 2024 12:11:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 351413857C53 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 351413857C53 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616719; cv=none; b=dSzXuBND0ogVQ1OS0VTVW4laU9i1HOSzrWfXCDJt6XDjePxUdH7NoDSMMHnuzHSevBWjtv1lcD0CgnmbhlLykeJlOvkV/rFmW0V7us3KcFYOtDZfJ/s2MWQb1UY7/DRWS6C1rLKwIECO+ckwkjPwW9ncMx9kXDFX4LAg6f4rNSg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616719; c=relaxed/simple; bh=muSG+mnMwyjYEBCCsIh5pSUVpgtWCtuAdvhiU/IKaS8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Ghq2QfojdpmoghF8PDEO9Z5z/90uUQvnvZNLmgScN0kjb9K3XT0RD/fD81Lg2v2nvAFwJV/ea7zZPbjeF13USYPMfWhgAAGo6Q0sZBBaE2mo9vcepFw1Ebe17RFlAQ//0jfzkH+03i3j5F1LROUrimW6jcl8og+wrDZko8KUyR0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-33af40493f4so1005881f8f.3 for ; Tue, 30 Jan 2024 04:11:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616687; x=1707221487; 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=9GQw+X1oqOP859F5/qSRO7FfkR9Dk6k7ONV6/zfxrVE=; b=gt1hC2VBRjoYXXLNW2nxdtQI4zUZNAqdvy1ZlxmCVO5NLuZGlM0Hn1buHPHrrtkjO6 J/SCS0mAbU8Br8Cac2aBiry09i3/YzhqBhg+KQFtyUUOKVSg5SXAdNIAnGm1mkRJ8MQ1 HXMvUlLqXyXvcnqWGrvIRyGwPI3erFzN1Z6feLsW0YrlLkbM0BL11UaHrZfGZFs1cQ1O bkGgXl7i6ZbSeLWAURPdnmH7m14tpz+GtEUDZ3ceHcIGJOaXL0BtkHi7j928vGKrU4vY DeyuHets6kIKAs9LXyvaX/VAzPSLVpQoXcImL6/WL521jxVwvjY0LxY+niyDUfqR99Xj I7JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616687; x=1707221487; 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=9GQw+X1oqOP859F5/qSRO7FfkR9Dk6k7ONV6/zfxrVE=; b=u7jGUQfk5WLuqV40DIOn1Mk4tev1r7G1bxIw+HEZ8BO346zU15P0OC946fCWM0pxNF 9mlpAUDmM0qXjt6xEv5WfkTHbn4Ha6L/BkKn3cv//1kY4sR73Qqr+isWw6wfo0EH6Y8i gtPX2jxPeA8FE8caar6Kx6LRuXehEfEf/RGQwf+D53m570xSTDNeQvgrkqRP731Tn68G DQERzUtNsVlFTjpbAH3OpCYaYJRnOx/Vgj8zKbbCjXteaAdQO5EtM7EMUMzJ15vVGhon QKFbY1qb5TCZP8asMtY1lLV8xOO2c+LFmw3iEwgGPeiksduw1q6fzx/6gdg6lb60ywSi 92vg== X-Gm-Message-State: AOJu0YxM1tEC0coZIsh+r673a8sIN64iHp/MlDxafa4Nl16SZOu24NiM ufCuOtUTUkZq5dPKFD8ZuocNR4xCbxJSxp+Tqg3jkyjDYQUCmLsPmYQOF+qEs8CTxbuJ80yOVsg lhQ== X-Google-Smtp-Source: AGHT+IGQQBc7E8wIn6YtJpi3/ySO2EQ3yLgghANY+O8zkpeaw/UGRZJG1Yd7m6wpXnX40LLcb/y7nQ== X-Received: by 2002:adf:f5c8:0:b0:33a:e544:ecc7 with SMTP id k8-20020adff5c8000000b0033ae544ecc7mr5091416wrp.9.1706616686829; Tue, 30 Jan 2024 04:11:26 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:26 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [COMMITTED 049/101] gccrs: Remove backend dependancy on resolution rib information Date: Tue, 30 Jan 2024 13:07:05 +0100 Message-ID: <20240130121026.807464-52-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.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, 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: Philip Herron When making more desugaring for the HIR we can need to add new Let bindings which will require namesolution information but also rib information for which block the let binding is associated which was very unnessecary. This patch simply updates the BLOCK_CONTEXT of the current scope as we are compiling and encounter HIR::LetStmts instead of trying to do it all upfront which lots of wierd checks gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::compile_locals_for_block): removed * backend/rust-compile-base.h: update header * backend/rust-compile-block.cc (CompileBlock::visit): remove old logic * backend/rust-compile-expr.cc (CompileExpr::generate_closure_function): likewise * backend/rust-compile-stmt.cc (CompileStmt::visit): likewise * backend/rust-compile-var-decl.h: ensure we setup tuple bindings correctly Signed-off-by: Philip Herron --- gcc/rust/backend/rust-compile-base.cc | 51 +----------------- gcc/rust/backend/rust-compile-base.h | 3 -- gcc/rust/backend/rust-compile-block.cc | 13 +---- gcc/rust/backend/rust-compile-expr.cc | 5 +- gcc/rust/backend/rust-compile-stmt.cc | 16 ++++-- gcc/rust/backend/rust-compile-var-decl.h | 69 +++++++++++++++++++----- 6 files changed, 71 insertions(+), 86 deletions(-) diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index ae9f6707b72..fcab75bef1c 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -564,35 +564,6 @@ HIRCompileBase::indirect_expression (tree expr, location_t locus) return build_fold_indirect_ref_loc (locus, expr); } -std::vector -HIRCompileBase::compile_locals_for_block (Context *ctx, Resolver::Rib &rib, - tree fndecl) -{ - std::vector locals; - for (auto it : rib.get_declarations ()) - { - NodeId node_id = it.first; - HirId ref = UNKNOWN_HIRID; - if (!ctx->get_mappings ()->lookup_node_to_hir (node_id, &ref)) - continue; - - // we only care about local patterns - HIR::Pattern *pattern = ctx->get_mappings ()->lookup_hir_pattern (ref); - if (pattern == nullptr) - continue; - - // lookup the type - TyTy::BaseType *tyty = nullptr; - if (!ctx->get_tyctx ()->lookup_type (ref, &tyty)) - continue; - - // compile the local - tree type = TyTyResolveCompile::compile (ctx, tyty); - CompileVarDecl::compile (fndecl, type, pattern, locals, ctx); - } - return locals; -} - void HIRCompileBase::compile_function_body (tree fndecl, HIR::BlockExpr &function_body, @@ -750,21 +721,11 @@ HIRCompileBase::compile_function ( if (!Backend::function_set_parameters (fndecl, param_vars)) return error_mark_node; - // lookup locals - 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); - - std::vector locals - = compile_locals_for_block (ctx, *rib, fndecl); - tree enclosing_scope = NULL_TREE; location_t start_location = function_body->get_locus (); location_t end_location = function_body->get_end_locus (); - tree code_block = Backend::block (fndecl, enclosing_scope, locals, + tree code_block = Backend::block (fndecl, enclosing_scope, {} /*locals*/, start_location, end_location); ctx->push_block (code_block); @@ -820,7 +781,6 @@ HIRCompileBase::compile_constant_item ( tree fndecl = Backend::function (compiled_fn_type, ident, "", 0, locus); TREE_READONLY (fndecl) = 1; - std::vector locals; tree enclosing_scope = NULL_TREE; location_t start_location = const_value_expr->get_locus (); location_t end_location = const_value_expr->get_locus (); @@ -830,16 +790,9 @@ HIRCompileBase::compile_constant_item ( = static_cast (const_value_expr); start_location = function_body->get_locus (); end_location = function_body->get_end_locus (); - - Resolver::Rib *rib = nullptr; - bool ok = ctx->get_resolver ()->find_name_rib ( - function_body->get_mappings ().get_nodeid (), &rib); - rust_assert (ok); - - locals = compile_locals_for_block (ctx, *rib, fndecl); } - tree code_block = Backend::block (fndecl, enclosing_scope, locals, + tree code_block = Backend::block (fndecl, enclosing_scope, {} /*locals*/, start_location, end_location); ctx->push_block (code_block); diff --git a/gcc/rust/backend/rust-compile-base.h b/gcc/rust/backend/rust-compile-base.h index 65291234b23..c5816584c72 100644 --- a/gcc/rust/backend/rust-compile-base.h +++ b/gcc/rust/backend/rust-compile-base.h @@ -145,9 +145,6 @@ protected: static bool mark_addressable (tree, location_t); - static std::vector - compile_locals_for_block (Context *ctx, Resolver::Rib &rib, tree fndecl); - static tree named_constant_expression (tree type_tree, const std::string &name, tree const_val, location_t location); diff --git a/gcc/rust/backend/rust-compile-block.cc b/gcc/rust/backend/rust-compile-block.cc index 83ecc672592..10a70999773 100644 --- a/gcc/rust/backend/rust-compile-block.cc +++ b/gcc/rust/backend/rust-compile-block.cc @@ -42,20 +42,9 @@ CompileBlock::visit (HIR::BlockExpr &expr) tree fndecl = fnctx.fndecl; location_t start_location = expr.get_locus (); location_t end_location = expr.get_end_locus (); - auto body_mappings = expr.get_mappings (); - - Resolver::Rib *rib = nullptr; - if (!ctx->get_resolver ()->find_name_rib (body_mappings.get_nodeid (), &rib)) - { - rust_fatal_error (expr.get_locus (), "failed to setup locals per block"); - return; - } - - std::vector locals - = compile_locals_for_block (ctx, *rib, fndecl); tree enclosing_scope = ctx->peek_enclosing_scope (); - tree new_block = Backend::block (fndecl, enclosing_scope, locals, + tree new_block = Backend::block (fndecl, enclosing_scope, {} /*locals*/, start_location, end_location); ctx->push_block (new_block); diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 870ecab5ba0..e0917f68660 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -2310,7 +2310,6 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr, bool is_block_expr = function_body->get_expression_type () == HIR::Expr::ExprType::Block; - std::vector locals = {}; if (is_block_expr) { auto body_mappings = function_body->get_mappings (); @@ -2319,8 +2318,6 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr, = ctx->get_resolver ()->find_name_rib (body_mappings.get_nodeid (), &rib); rust_assert (ok); - - locals = compile_locals_for_block (ctx, *rib, fndecl); } tree enclosing_scope = NULL_TREE; @@ -2333,7 +2330,7 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr, end_location = body->get_end_locus (); } - tree code_block = Backend::block (fndecl, enclosing_scope, locals, + tree code_block = Backend::block (fndecl, enclosing_scope, {} /*locals*/, start_location, end_location); ctx->push_block (code_block); diff --git a/gcc/rust/backend/rust-compile-stmt.cc b/gcc/rust/backend/rust-compile-stmt.cc index c006f4ace62..e7ba370eb8e 100644 --- a/gcc/rust/backend/rust-compile-stmt.cc +++ b/gcc/rust/backend/rust-compile-stmt.cc @@ -19,6 +19,8 @@ #include "rust-compile-pattern.h" #include "rust-compile-stmt.h" #include "rust-compile-expr.h" +#include "rust-compile-type.h" +#include "rust-compile-var-decl.h" namespace Rust { namespace Compile { @@ -44,10 +46,6 @@ CompileStmt::visit (HIR::ExprStmt &stmt) void CompileStmt::visit (HIR::LetStmt &stmt) { - // nothing to do - if (!stmt.has_init_expr ()) - return; - HIR::Pattern &stmt_pattern = *stmt.get_pattern (); HirId stmt_id = stmt_pattern.get_mappings ().get_hirid (); @@ -60,6 +58,16 @@ CompileStmt::visit (HIR::LetStmt &stmt) return; } + // setup var decl nodes + fncontext fnctx = ctx->peek_fn (); + tree fndecl = fnctx.fndecl; + tree translated_type = TyTyResolveCompile::compile (ctx, ty); + CompileVarDecl::compile (fndecl, translated_type, &stmt_pattern, ctx); + + // nothing to do + if (!stmt.has_init_expr ()) + return; + tree init = CompileExpr::Compile (stmt.get_init_expr ().get (), ctx); // FIXME use error_mark_node, check that CompileExpr returns error_mark_node // on failure and make this an assertion diff --git a/gcc/rust/backend/rust-compile-var-decl.h b/gcc/rust/backend/rust-compile-var-decl.h index 370e939cd0c..45ca01d4f70 100644 --- a/gcc/rust/backend/rust-compile-var-decl.h +++ b/gcc/rust/backend/rust-compile-var-decl.h @@ -30,11 +30,12 @@ class CompileVarDecl : public HIRCompileBase, public HIR::HIRPatternVisitor using HIR::HIRPatternVisitor::visit; public: - static void compile (tree fndecl, tree translated_type, HIR::Pattern *pattern, - std::vector &locals, Context *ctx) + static std::vector compile (tree fndecl, tree translated_type, + HIR::Pattern *pattern, Context *ctx) { - CompileVarDecl compiler (ctx, fndecl, translated_type, locals); + CompileVarDecl compiler (ctx, fndecl, translated_type); pattern->accept_vis (compiler); + return compiler.vars; } void visit (HIR::IdentifierPattern &pattern) override @@ -42,15 +43,58 @@ public: if (!pattern.is_mut ()) translated_type = Backend::immutable_type (translated_type); - Bvariable *var - = Backend::local_variable (fndecl, pattern.get_identifier ().as_string (), - translated_type, NULL /*decl_var*/, - pattern.get_locus ()); + tree bind_tree = ctx->peek_enclosing_scope (); + std::string identifier = pattern.get_identifier ().as_string (); + tree decl + = build_decl (pattern.get_locus (), VAR_DECL, + Backend::get_identifier_node (identifier), translated_type); + DECL_CONTEXT (decl) = fndecl; + + gcc_assert (TREE_CODE (bind_tree) == BIND_EXPR); + tree block_tree = BIND_EXPR_BLOCK (bind_tree); + gcc_assert (TREE_CODE (block_tree) == BLOCK); + DECL_CHAIN (decl) = BLOCK_VARS (block_tree); + BLOCK_VARS (block_tree) = decl; + BIND_EXPR_VARS (bind_tree) = BLOCK_VARS (block_tree); + + rust_preserve_from_gc (decl); + Bvariable *var = new Bvariable (decl); HirId stmt_id = pattern.get_mappings ().get_hirid (); ctx->insert_var_decl (stmt_id, var); - locals.push_back (var); + vars.push_back (var); + } + + void visit (HIR::TuplePattern &pattern) override + { + switch (pattern.get_items ()->get_item_type ()) + { + case HIR::TuplePatternItems::ItemType::MULTIPLE: { + rust_assert (TREE_CODE (translated_type) == RECORD_TYPE); + auto &items = static_cast ( + *pattern.get_items ()); + + size_t offs = 0; + for (auto &sub : items.get_patterns ()) + { + tree sub_ty = error_mark_node; + tree field = TYPE_FIELDS (translated_type); + for (size_t i = 0; i < offs; i++) + { + field = DECL_CHAIN (field); + gcc_assert (field != NULL_TREE); + } + sub_ty = TREE_TYPE (field); + CompileVarDecl::compile (fndecl, sub_ty, sub.get (), ctx); + offs++; + } + } + break; + + default: + break; + } } // Empty visit for unused Pattern HIR nodes. @@ -62,21 +106,18 @@ public: void visit (HIR::ReferencePattern &) override {} void visit (HIR::SlicePattern &) override {} void visit (HIR::StructPattern &) override {} - void visit (HIR::TuplePattern &) override {} void visit (HIR::TupleStructPattern &) override {} void visit (HIR::WildcardPattern &) override {} private: - CompileVarDecl (Context *ctx, tree fndecl, tree translated_type, - std::vector &locals) - : HIRCompileBase (ctx), fndecl (fndecl), translated_type (translated_type), - locals (locals) + CompileVarDecl (Context *ctx, tree fndecl, tree translated_type) + : HIRCompileBase (ctx), fndecl (fndecl), translated_type (translated_type) {} tree fndecl; tree translated_type; - std::vector &locals; + std::vector vars; }; } // namespace Compile From patchwork Tue Jan 30 12:07:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892867 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=f9XLDx2R; 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 4TPPjM1KR5z23fD for ; Tue, 30 Jan 2024 23:33:43 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1ECEC386EC5F for ; Tue, 30 Jan 2024 12:33:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id 51AC43857B94 for ; Tue, 30 Jan 2024 12:11:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 51AC43857B94 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 51AC43857B94 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616720; cv=none; b=p0T/9GD/E94WUqgarhAd1TGPbsgMzD0bhxgNMI3uqc3LwO+l0HC7cpRFRp+TxohQD//cZ/L1mQbKKRfUk0qep5XkRh9JKSjGRbuMe2Co+c3aHFBLZPvPTmxM5m7JAsuYlnfENX72KOYxmQhQ8rXWtbhljPgjo6Up0bh3CrTJ6OE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616720; c=relaxed/simple; bh=8qnxuxIPqs9VFhApEK9K7HTMhvi5o+J6NuIczvaRW7A=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=j8FB0XM1btMpfmONBaSTGzs/HSvbSWfqHCxG9Yrkf9GGVo7YJOaEhJXoVMAY/6Ie168ZdqZ9rvqpdoQ7sMTp2FrpIdVxc/Bdv7aSjmsUbbs9Ck+fm821G5ahHbhgoyoUiKa+8HX8/g4cFdKxjempCYaH2sKr/unuJgRaZYmCCPw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-51120e285f6so44101e87.2 for ; Tue, 30 Jan 2024 04:11:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616687; x=1707221487; 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=BHJWowi8D0l7QMwpZo+lP25+Y+BYCP/pZpmnk1kK5XQ=; b=f9XLDx2RhoYx2NrdQkQoK03BrwGRmZELjHD1ons+S23/hJCyEtVVd0DM6gNdxsleld NGNWtsSs1zEpx0lzkrNcvhnAWLySRgDfcmrg6gKm72ByBiesu7xxCR8ATuTYpoOaLHJ7 WkInRc01cixihP4UAX9T9v8H82vSfc61XPez8E97nP+4hW2S3eioK1GdfkChXeD/juwW yzZTxZm+6wJ216wymxyCDibz7zxQxk12Z2nFXvetHhYPx3Y7C/kUpXw//duch1uBGDUT Lzd67J6SVDs114J7DhwTQdYH0WB34TZgS1La9pmNvZnYYGSxamU4vhNRV+XTWOTE6kyz rL0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616687; x=1707221487; 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=BHJWowi8D0l7QMwpZo+lP25+Y+BYCP/pZpmnk1kK5XQ=; b=LnsVaQoJrDXragEu6YZCkLM/t0jjlkoKuRmO6pWBxFn5atOQS7RIVj3S/jKT5OJS9T rHWgusz99K37QNbmtI4qKNdmAGy38sCGaEQ++fY2e2CPOT5kXo9TM+XwmCFXF7aNOGWp kfiiJ6E9Xn9ekWVzrSIMeOafYp83POFAAeb5w1DM0ZDBY2gVbcnZAj8gWWhUEuFgGCaP KFCHREHV0bYn0CbxYGJxehOQD4PDUsgTtn1Zabz3bawF96QrvLRSGBDWCM+VhV10vGKt 6Wg+mPW06t6jepCvXM5x2lVWbUTsSnFreFjs5lgFEzxIcz4Rip2lbO49hIbMa3mIb5Kw Up3w== X-Gm-Message-State: AOJu0YyvXDXxVmNygNwOFhf2N8zK83QJ9uQOeCSLj9R3zJRceQh446sk TNzqdbgWO8eokLZYhhR8bGDG6sJQWolunCTJLclNtC8gbbkph3ju0+g6oRo//esDCbqvxy4x78r 86A== X-Google-Smtp-Source: AGHT+IGXPjJQwkwzHDZAJMogRweDmoRP7J41qwuZqplarvwEnUpkI4e+fik3tES0rWDKM/8rZIpBeA== X-Received: by 2002:a05:6512:1599:b0:510:286b:8882 with SMTP id bp25-20020a056512159900b00510286b8882mr6555781lfb.3.1706616687511; Tue, 30 Jan 2024 04:11:27 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:27 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [COMMITTED 050/101] gccrs: Remove class AST::InherentImplItem Date: Tue, 30 Jan 2024 13:07:06 +0100 Message-ID: <20240130121026.807464-53-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: Owen Avery gcc/rust/ChangeLog: * ast/rust-ast-full-decls.h (class InherentImplItem): Remove. * ast/rust-ast.h (class InherentImplItem): Remove. (class SingleASTNode): Store pointer to AssociatedItem instead of InherentImplItem. * ast/rust-ast.cc (SingleASTNode::SingleASTNode): Use clone_associated_item instead of clone_inherent_impl_item. (SingleASTNode::operator=): Likewise. * ast/rust-item.h (class InherentImpl): Use AssociatedItem rather than InherentImplItem. (class Function): Likewise. (class ConstantItem): Likewise. * ast/rust-macro.h (class MacroInvocation): Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * parse/rust-parse-impl.h (Parser::parse_impl): Likewise. (Parser::parse_inherent_impl_item): Likewise. (Parser::parse_inherent_impl_function_or_method): Likewise. * parse/rust-parse.h (Parser::parse_inherent_impl_item): Likewise. (Parser::parse_inherent_impl_function_or_method): Likewise. Signed-off-by: Owen Avery --- gcc/rust/ast/rust-ast-full-decls.h | 1 - gcc/rust/ast/rust-ast.cc | 4 ++-- gcc/rust/ast/rust-ast.h | 22 +++------------------- gcc/rust/ast/rust-item.h | 18 ++++++++++-------- gcc/rust/ast/rust-macro.h | 2 +- gcc/rust/expand/rust-expand-visitor.cc | 2 +- gcc/rust/parse/rust-parse-impl.h | 8 ++++---- gcc/rust/parse/rust-parse.h | 4 ++-- 8 files changed, 23 insertions(+), 38 deletions(-) diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h index e2d05bae0c4..5bfaaa8ba3c 100644 --- a/gcc/rust/ast/rust-ast-full-decls.h +++ b/gcc/rust/ast/rust-ast-full-decls.h @@ -52,7 +52,6 @@ class GenericParam; class LifetimeParam; class ConstGenericParam; class TraitItem; -class InherentImplItem; class TraitImplItem; struct Crate; class PathExpr; diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 43820d38e28..17f82d67430 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -64,7 +64,7 @@ SingleASTNode::SingleASTNode (SingleASTNode const &other) break; case IMPL: - impl_item = other.impl_item->clone_inherent_impl_item (); + impl_item = other.impl_item->clone_associated_item (); break; case TRAIT_IMPL: @@ -104,7 +104,7 @@ SingleASTNode::operator= (SingleASTNode const &other) break; case IMPL: - impl_item = other.impl_item->clone_inherent_impl_item (); + impl_item = other.impl_item->clone_associated_item (); break; case TRAIT_IMPL: diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 4049e4d2607..b193c67c69e 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1687,22 +1687,6 @@ public: location_t get_locus () const override { return locus; } }; -/* Abstract base class for items used within an inherent impl block (the impl - * name {} one) */ -class InherentImplItem : virtual public AssociatedItem -{ -protected: - // Clone function implementation as pure virtual method - virtual InherentImplItem *clone_associated_item_impl () const override = 0; - -public: - // Unique pointer custom clone function - std::unique_ptr clone_inherent_impl_item () const - { - return std::unique_ptr (clone_associated_item_impl ()); - } -}; - // Abstract base class for items used in a trait impl class TraitImplItem : virtual public AssociatedItem { @@ -1860,7 +1844,7 @@ private: std::unique_ptr stmt; std::unique_ptr external_item; std::unique_ptr trait_item; - std::unique_ptr impl_item; + std::unique_ptr impl_item; std::unique_ptr trait_impl_item; std::unique_ptr type; @@ -1885,7 +1869,7 @@ public: : kind (TRAIT), trait_item (std::move (item)) {} - SingleASTNode (std::unique_ptr item) + SingleASTNode (std::unique_ptr item) : kind (IMPL), impl_item (std::move (item)) {} @@ -1959,7 +1943,7 @@ public: return std::move (external_item); } - std::unique_ptr take_impl_item () + std::unique_ptr take_impl_item () { rust_assert (!is_error ()); return std::move (impl_item); diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 3bf023b3c5a..b34aca0d56c 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -1285,7 +1285,9 @@ protected: class LetStmt; // Rust function declaration AST node -class Function : public VisItem, public InherentImplItem, public TraitImplItem +class Function : public VisItem, + virtual public AssociatedItem, + public TraitImplItem { FunctionQualifiers qualifiers; Identifier function_name; @@ -2308,7 +2310,7 @@ protected: /* "Constant item" AST node - used for constant, compile-time expressions * within module scope (like constexpr) */ class ConstantItem : public VisItem, - public InherentImplItem, + virtual public AssociatedItem, public TraitImplItem { // either has an identifier or "_" - maybe handle in identifier? @@ -3408,7 +3410,7 @@ protected: class InherentImpl : public Impl { // bool has_impl_items; - std::vector> impl_items; + std::vector> impl_items; public: std::string as_string () const override; @@ -3417,7 +3419,7 @@ public: bool has_impl_items () const { return !impl_items.empty (); } // Mega-constructor - InherentImpl (std::vector> impl_items, + InherentImpl (std::vector> impl_items, std::vector> generic_params, std::unique_ptr trait_type, WhereClause where_clause, Visibility vis, std::vector inner_attrs, @@ -3433,7 +3435,7 @@ public: { impl_items.reserve (other.impl_items.size ()); for (const auto &e : other.impl_items) - impl_items.push_back (e->clone_inherent_impl_item ()); + impl_items.push_back (e->clone_associated_item ()); } // Overloaded assignment operator with vector clone @@ -3443,7 +3445,7 @@ public: impl_items.reserve (other.impl_items.size ()); for (const auto &e : other.impl_items) - impl_items.push_back (e->clone_inherent_impl_item ()); + impl_items.push_back (e->clone_associated_item ()); return *this; } @@ -3455,11 +3457,11 @@ public: void accept_vis (ASTVisitor &vis) override; // TODO: think of better way to do this - const std::vector> &get_impl_items () const + const std::vector> &get_impl_items () const { return impl_items; } - std::vector> &get_impl_items () + std::vector> &get_impl_items () { return impl_items; } diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index b3fdcf71417..41c21cffa95 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -599,7 +599,7 @@ class MacroInvocation : public TypeNoBounds, public Item, public TraitItem, public TraitImplItem, - public InherentImplItem, + virtual public AssociatedItem, public ExternalItem, public ExprWithoutBlock { diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc index 3f598b7f21c..1745af06174 100644 --- a/gcc/rust/expand/rust-expand-visitor.cc +++ b/gcc/rust/expand/rust-expand-visitor.cc @@ -1180,7 +1180,7 @@ ExpandVisitor::visit (AST::InherentImpl &impl) if (impl.has_where_clause ()) expand_where_clause (impl.get_where_clause ()); - std::function (AST::SingleASTNode)> + std::function (AST::SingleASTNode)> extractor = [] (AST::SingleASTNode node) { return node.take_impl_item (); }; expand_macro_children (MacroExpander::ContextType::IMPL, diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index f83cc122c89..a9af7dc3f38 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -5388,12 +5388,12 @@ Parser::parse_impl (AST::Visibility vis, AST::AttrVec inner_attrs = parse_inner_attributes (); // parse inherent impl items - std::vector> impl_items; + std::vector> impl_items; const_TokenPtr t = lexer.peek_token (); while (t->get_id () != RIGHT_CURLY) { - std::unique_ptr impl_item + std::unique_ptr impl_item = parse_inherent_impl_item (); if (impl_item == nullptr) @@ -5512,7 +5512,7 @@ Parser::parse_impl (AST::Visibility vis, // Parses a single inherent impl item (item inside an inherent impl block). template -std::unique_ptr +std::unique_ptr Parser::parse_inherent_impl_item () { // parse outer attributes (if they exist) @@ -5629,7 +5629,7 @@ Parser::parse_inherent_impl_item () // InherentImplItem is this specialisation of the template while TraitImplItem // will be the other. template -std::unique_ptr +std::unique_ptr Parser::parse_inherent_impl_function_or_method ( AST::Visibility vis, AST::AttrVec outer_attrs) { diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index d3718467b48..4291e4198a5 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -170,7 +170,7 @@ public: std::unique_ptr parse_type (bool save_errors = true); std::unique_ptr parse_external_item (); std::unique_ptr parse_trait_item (); - std::unique_ptr parse_inherent_impl_item (); + std::unique_ptr parse_inherent_impl_item (); std::unique_ptr parse_trait_impl_item (); AST::PathInExpression parse_path_in_expression (); std::vector> parse_lifetime_params (); @@ -348,7 +348,7 @@ private: std::unique_ptr parse_impl (AST::Visibility vis, AST::AttrVec outer_attrs); - std::unique_ptr + std::unique_ptr parse_inherent_impl_function_or_method (AST::Visibility vis, AST::AttrVec outer_attrs); std::unique_ptr From patchwork Tue Jan 30 12:07:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892894 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=AV6YGX5W; 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 4TPPsr19Znz23gZ for ; Tue, 30 Jan 2024 23:41:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2D3423831E31 for ; Tue, 30 Jan 2024 12:41:02 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 01D2C3857BA4 for ; Tue, 30 Jan 2024 12:11:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 01D2C3857BA4 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 01D2C3857BA4 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::329 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616722; cv=none; b=Q+s/KP7Yp5G7Uqwj4itcvZxZNcLKDOniYMSNO/cUITZHya0IUYFgn7hExEaqmNrTuVFhH78BJ/wR2DaSEYtQZciX3B2h6clNhqLbT/nH0p3qbjRJ+Auqetmzw9x3Hr2TAJTkdii5544+rO5oja+BF6s6bH11IGQpgnMWbSrcLHs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616722; c=relaxed/simple; bh=ZZiU6ir37XgyF9L68GEEOPIt6WSIFhkr+k2BJitye68=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=llSODf1fHaZs0IOnYtlk6biGZMrxWFEaRbo0OvPlm3eo+o1SxTEnWxBywbx440VdYaoKKBawhGfF4+XvB+DQM3n4NQmsQ8CnziFM66miROVt+BVkNS9wjZahQKhb+yzbmuTQQMBqp2QO0wPrkOU51HPYjM23IN5H5I827MFS7qY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-40ef64d8955so18169575e9.3 for ; Tue, 30 Jan 2024 04:11:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616688; x=1707221488; 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=68WMY4jrcyoPhBn1QT8vXv+k/05gWCRQvjPh9e/caLg=; b=AV6YGX5W37mRXCRBRbI1h0AkQUz5gVr0YJtEzO4R6WCnJ5XCVEhDmvON3R8jMlDZ2+ 3YYvVQ+J1UCnqEdsXzLCzzjYJgPw7jBbkoefAv61+R+zZy1YLwkIEeSI2+XAP5Ucue/b 2VBZerSLWINC7BD/btZkVr3dVDqWWpt1F0Gs9u/kdSio8vUMNr+QVaOkIuhgZMdBk/nt 1z11u44cdmBl5x7DiTilODfF80hJG0WAWiNly3A9HoyUv2bwhF/cmEhsEmPQ+nPP3KJn Nzjc2rrzZMYdj9Ej+jJJ7JlxRv840tO3rCMXat1pPTA71RATtwEx3L3ohGcSfTLiyicC Hlwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616688; x=1707221488; 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=68WMY4jrcyoPhBn1QT8vXv+k/05gWCRQvjPh9e/caLg=; b=Ypr/FfwgUmhiGbMfiXBuOw+QZaT4d4zi1xJGUV167GZHR61xQvcp/Gfx01l9A8t1ml 2nuyA6CFea0v4opPfSzUsX1bTWAxqe0gEHujOZ9rkVjSTbXLhUoiDXi8gf7PGdk8vIr5 fFti7Nkh9Izpk0pYLEot3Q/P9yRRT3uhzi6fd4QKkRMYTDmxU+n+4TSvbNhsNISn/z4/ OgnSgdcje3uRZDs6XUFFgbzEHGoQs0pCQAXZV6/F9CPqBzSVsq9bPxpeEOLWhY5Q+6Kn q+QsiIE74Dpr1HADB82kTgzVCKyDNEJI0ytHb6fOU35CJYSVBd7gAxwosNq7BUsU8o3Q nqsg== X-Gm-Message-State: AOJu0YyrCPeL9FTK5IlckNfcJ1Yjoju9N2YQ5o6QxVsrSXqf5wtLEzby Hfl65/xZ6MyLhGon+Qk8/ykUK1bvbfSfV88eX9Fy99Naa2SNEWSl9lWM7Vys/rFmrOgjF3x2ueL GRA== X-Google-Smtp-Source: AGHT+IFFyShpNSfihWXBqpvGmQI6YYi+2CQwAinT/OMTqbO3795LodbN3pOUEVQt8udMOnBuXUk+dg== X-Received: by 2002:adf:cd03:0:b0:33a:fc8c:1dc9 with SMTP id w3-20020adfcd03000000b0033afc8c1dc9mr918422wrm.32.1706616687965; Tue, 30 Jan 2024 04:11:27 -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.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:27 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 051/101] gccrs: Split async and const function qualifiers Date: Tue, 30 Jan 2024 13:07:07 +0100 Message-ID: <20240130121026.807464-54-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.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, 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: Pierre-Emmanuel Patry A function cannot be both async and const, however this should not be handled in the parser but rather at a later stage in the compiler. This commit change the AsyncConstStatus in the AST and the HIR to allows a function to be both async and const. gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (AstBuilder::fn_qualifiers): Change constructor to match the new arguments. * ast/rust-ast-collector.cc (TokenCollector::visit): Change behavior to handle both const and async specifiers at the same time. * ast/rust-ast.cc (FunctionQualifiers::as_string): Likewise. * ast/rust-item.h (class FunctionQualifiers): Remove AsyncConstStatus and replace it with both Async and Const status. Also change the safety arguments to use an enum instead of a boolean. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_qualifiers): Update constructor call. * hir/tree/rust-hir-item.h: Add Const and Async status, remove AsyncConstStatus, update the constructor. * hir/tree/rust-hir.cc (FunctionQualifiers::as_string): Update with the new status. * parse/rust-parse-impl.h (Parser::parse_function_qualifiers): Update constructor call. * util/rust-common.h (enum Mutability): Make an enum class. (enum class): Add Async and Const enum class to avoid booleans. (enum Unsafety): Change to an enum class. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/ast/rust-ast-builder.cc | 2 +- gcc/rust/ast/rust-ast-collector.cc | 16 +++------- gcc/rust/ast/rust-ast.cc | 21 ++++--------- gcc/rust/ast/rust-item.h | 22 ++++++++------ gcc/rust/hir/rust-ast-lower-base.cc | 3 +- gcc/rust/hir/tree/rust-hir-item.h | 14 +++++---- gcc/rust/hir/tree/rust-hir.cc | 25 ++++------------ gcc/rust/parse/rust-parse-impl.h | 46 +++++++++++++++++------------ gcc/rust/util/rust-common.h | 16 ++++++++-- 9 files changed, 80 insertions(+), 85 deletions(-) diff --git a/gcc/rust/ast/rust-ast-builder.cc b/gcc/rust/ast/rust-ast-builder.cc index e2d3eea6c58..fd6f519fa25 100644 --- a/gcc/rust/ast/rust-ast-builder.cc +++ b/gcc/rust/ast/rust-ast-builder.cc @@ -46,7 +46,7 @@ AstBuilder::tuple_idx (std::string receiver, int idx) FunctionQualifiers AstBuilder::fn_qualifiers () { - return FunctionQualifiers (loc, AsyncConstStatus::NONE, false); + return FunctionQualifiers (loc, Async::No, Const::No, Unsafety::Normal); } PathExprSegment diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc index 3e3a959578e..647724bec11 100644 --- a/gcc/rust/ast/rust-ast-collector.cc +++ b/gcc/rust/ast/rust-ast-collector.cc @@ -317,18 +317,10 @@ TokenCollector::visit (FunctionQualifiers &qualifiers) // `const`? `async`? `unsafe`? (`extern` Abi?)? // unsafe? (extern Abi?)? - switch (qualifiers.get_const_status ()) - { - case NONE: - break; - case CONST_FN: - push (Rust::Token::make (CONST, qualifiers.get_locus ())); - break; - case ASYNC_FN: - push (Rust::Token::make (ASYNC, qualifiers.get_locus ())); - break; - } - + if (qualifiers.is_async ()) + push (Rust::Token::make (ASYNC, qualifiers.get_locus ())); + if (qualifiers.is_const ()) + push (Rust::Token::make (CONST, qualifiers.get_locus ())); if (qualifiers.is_unsafe ()) push (Rust::Token::make (UNSAFE, qualifiers.get_locus ())); if (qualifiers.is_extern ()) diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 17f82d67430..607f07955d4 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -2333,22 +2333,11 @@ FunctionQualifiers::as_string () const { std::string str; - switch (const_status) - { - case NONE: - // do nothing - break; - case CONST_FN: - str += "const "; - break; - case ASYNC_FN: - str += "async "; - break; - default: - return "ERROR_MARK_STRING: async-const status failure"; - } - - if (has_unsafe) + if (is_async ()) + str += "async "; + if (is_const ()) + str += "const "; + if (is_unsafe ()) str += "unsafe "; if (has_extern) diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index b34aca0d56c..9a83f3d5981 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -533,19 +533,20 @@ public: // Qualifiers for function, i.e. const, unsafe, extern etc. class FunctionQualifiers { - AsyncConstStatus const_status; - bool has_unsafe; + Async async_status; + Const const_status; + Unsafety unsafe_status; bool has_extern; std::string extern_abi; location_t locus; public: - FunctionQualifiers (location_t locus, AsyncConstStatus const_status, - bool has_unsafe, bool has_extern = false, + FunctionQualifiers (location_t locus, Async async_status, Const const_status, + Unsafety unsafe_status, bool has_extern = false, std::string extern_abi = std::string ()) - : const_status (const_status), has_unsafe (has_unsafe), - has_extern (has_extern), extern_abi (std::move (extern_abi)), - locus (locus) + : async_status (async_status), const_status (const_status), + unsafe_status (unsafe_status), has_extern (has_extern), + extern_abi (std::move (extern_abi)), locus (locus) { if (!this->extern_abi.empty ()) { @@ -556,11 +557,14 @@ public: std::string as_string () const; - AsyncConstStatus get_const_status () const { return const_status; } - bool is_unsafe () const { return has_unsafe; } + bool is_unsafe () const { return unsafe_status == Unsafety::Unsafe; } bool is_extern () const { return has_extern; } + bool is_const () const { return const_status == Const::Yes; } + bool is_async () const { return async_status == Async::Yes; } std::string get_extern_abi () const { return extern_abi; } bool has_abi () const { return !extern_abi.empty (); } + Const get_const_status () const { return const_status; } + Async get_async_status () const { return async_status; } location_t get_locus () const { return locus; } }; diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc index f5eed256a5e..f8438557707 100644 --- a/gcc/rust/hir/rust-ast-lower-base.cc +++ b/gcc/rust/hir/rust-ast-lower-base.cc @@ -721,7 +721,8 @@ ASTLoweringBase::lower_qualifiers (const AST::FunctionQualifiers &qualifiers) "invalid ABI: found %qs", extern_abi.c_str ()); } - return HIR::FunctionQualifiers (qualifiers.get_const_status (), unsafety, + return HIR::FunctionQualifiers (qualifiers.get_async_status (), + qualifiers.get_const_status (), unsafety, has_extern, abi); } diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h index 6cd41892e49..f72d8c8b050 100644 --- a/gcc/rust/hir/tree/rust-hir-item.h +++ b/gcc/rust/hir/tree/rust-hir-item.h @@ -481,24 +481,26 @@ public: struct FunctionQualifiers { private: - AsyncConstStatus const_status; + Async async_status; + Const const_status; Unsafety unsafety; bool has_extern; ABI abi; public: - FunctionQualifiers (AsyncConstStatus const_status, Unsafety unsafety, + FunctionQualifiers (Async async_status, Const const_status, Unsafety unsafety, bool has_extern, ABI abi) - : const_status (const_status), unsafety (unsafety), has_extern (has_extern), - abi (abi) + : async_status (async_status), const_status (const_status), + unsafety (unsafety), has_extern (has_extern), abi (abi) {} std::string as_string () const; - AsyncConstStatus get_status () const { return const_status; } + Const get_const_status () const { return const_status; } - bool is_const () const { return const_status == AsyncConstStatus::CONST_FN; } + bool is_const () const { return const_status == Const::Yes; } bool is_unsafe () const { return unsafety == Unsafety::Unsafe; } + bool is_async () const { return async_status == Async::Yes; } ABI get_abi () const { return abi; } }; diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc index 66f626ba845..fb0a9c388ae 100644 --- a/gcc/rust/hir/tree/rust-hir.cc +++ b/gcc/rust/hir/tree/rust-hir.cc @@ -1947,25 +1947,12 @@ FunctionQualifiers::as_string () const { std::string str; - switch (const_status) - { - case NONE: - // do nothing - break; - case CONST_FN: - str += "const "; - break; - case ASYNC_FN: - str += "async "; - break; - default: - return "ERROR_MARK_STRING: async-const status failure"; - } - - if (unsafety == Unsafety::Unsafe) - { - str += "unsafe "; - } + if (is_const ()) + str += "const "; + if (is_async ()) + str += "async "; + if (is_unsafe ()) + str += "unsafe "; if (has_extern) { diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index a9af7dc3f38..a1ad4f11993 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -24,6 +24,7 @@ #include "rust-common.h" #include "rust-item.h" +#include "rust-common.h" #include "rust-token.h" #define INCLUDE_ALGORITHM #include "rust-diagnostics.h" @@ -2987,33 +2988,40 @@ template AST::FunctionQualifiers Parser::parse_function_qualifiers () { - AsyncConstStatus const_status = NONE; - bool has_unsafe = false; + Async async_status = Async::No; + Const const_status = Const::No; + Unsafety unsafe_status = Unsafety::Normal; bool has_extern = false; std::string abi; + const_TokenPtr t; + location_t locus; // Check in order of const, unsafe, then extern - const_TokenPtr t = lexer.peek_token (); - location_t locus = t->get_locus (); - switch (t->get_id ()) + for (int i = 0; i < 2; i++) { - case CONST: - lexer.skip_token (); - const_status = CONST_FN; - break; - case ASYNC: - lexer.skip_token (); - const_status = ASYNC_FN; - break; - default: - // const status is still none - break; + t = lexer.peek_token (); + locus = t->get_locus (); + + switch (t->get_id ()) + { + case CONST: + lexer.skip_token (); + const_status = Const::Yes; + break; + case ASYNC: + lexer.skip_token (); + async_status = Async::Yes; + break; + default: + // const status is still none + break; + } } if (lexer.peek_token ()->get_id () == UNSAFE) { lexer.skip_token (); - has_unsafe = true; + unsafe_status = Unsafety::Unsafe; } if (lexer.peek_token ()->get_id () == EXTERN_KW) @@ -3030,8 +3038,8 @@ Parser::parse_function_qualifiers () } } - return AST::FunctionQualifiers (locus, const_status, has_unsafe, has_extern, - std::move (abi)); + return AST::FunctionQualifiers (locus, async_status, const_status, + unsafe_status, has_extern, std::move (abi)); } // Parses generic (lifetime or type) params inside angle brackets (optional). diff --git a/gcc/rust/util/rust-common.h b/gcc/rust/util/rust-common.h index fc8ba6e1e58..299ae71e909 100644 --- a/gcc/rust/util/rust-common.h +++ b/gcc/rust/util/rust-common.h @@ -25,18 +25,30 @@ namespace Rust { -enum Mutability +enum class Mutability { Imm, Mut }; -enum Unsafety +enum class Unsafety { Unsafe, Normal }; +enum class Const +{ + Yes, + No, +}; + +enum class Async +{ + Yes, + No +}; + enum BoundPolarity { RegularBound, From patchwork Tue Jan 30 12:07:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892839 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=chqv7woo; 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 4TPPYK1B4fz23gZ for ; Tue, 30 Jan 2024 23:26:45 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 214A73860763 for ; Tue, 30 Jan 2024 12:26:43 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 2DB533857BB6 for ; Tue, 30 Jan 2024 12:11:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2DB533857BB6 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 2DB533857BB6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616718; cv=none; b=IiMuogSaAAowYbsXT0PxIHbVwtsJmT7edbca2JJsnjzstlWsX1GORBGYD0V4zLTUooO4g+GaYi+LTu5+XzR6kZoGpZoLFrWqqtqtEQKaQ5N9Uw1N2VnnxYTyKyYp98T7oIYFA5XkLj7YkAkfZGF2j+FLwfB0EfuOPc1ui7XD0XM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616718; c=relaxed/simple; bh=+ah8tuaPA+wFxJBJTGEGj5BFQHG7C4ylbpyBQVwsG1A=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jm+gkReempDHmbLXDKgGpnfjulWKGzLRn1+rrGBSfGDyW/eNm/pc3F1AVL7s+/a3ftQfnDqikfHsCy6ku41rna6udqAYBu2/mykGYXp9yBiOn3cu/3kiTW74WhaCuPXaLvKLGHVWxcKvd/ZwirpSoJ6Fyab/CaEclP3Uu+oPzCA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-40fafced243so1222535e9.0 for ; Tue, 30 Jan 2024 04:11:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616688; x=1707221488; 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=XB5QG9cWh2i6OpCmTXIuUTmITF/AOB6Rg1JfUAMV5Ho=; b=chqv7wooJY+g2CmM+he2JIsYhMEujhjKCs4ye9VVMszMFyy4TzS1ohXR0GPQ6M4K7y EuzLLMZnBOFrjmFDMnk1QyeMv1KsEMPtD9mSf84WwrxMk+dYpMcDpyIzKOxEtU0QCias qHL0rwJq7OEPNindEp4f0UiPUZiDtXdpxK8vtB0W4chkKvakk0YwuuOU4Jf4k4L3UBFE nKHZNElf1m0bRH0l1hepu1FkDqTADbW4ymHcz2KKgvv0SL2YIz9gZXCYT3CFPEGpY7Sa 1E3lohOaKnJbz9mHqS5F5B/5/bPHVf1jOOPGT3zm397YZmkf2imhXIbLH0BKj5kJCsQ8 m5Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616688; x=1707221488; 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=XB5QG9cWh2i6OpCmTXIuUTmITF/AOB6Rg1JfUAMV5Ho=; b=qNhGPwEVvxTriYTRSFkdfaLV+Z/SPit4wuS5FMNlM7m5KxR4bgm7045sF+KBNf28u4 2qhj8lLhOqubtUmRKrejApwLVwEbtg6UO7BUuBigZ7ngXXhfa/dSKehMTT9yy5ZbDJ2i FjhdF9XviPq++VEhw2jK+OG7pY9VMk2g8+N9qn+KrfSCrown2WpnlZVxBRKBlOzn1IYP V2Lnflq4LuMVF/EYihduksudcDHvt5LTQx+FuQ1sNBHghN5ikTIJqPWhfU0l4+WHYHVD gvsc+6YhdJ3E5hVoqst5pqb56CGdbVHMu7cERocpLm2QLouyzBtt+zjxNFFtg1GgG8VK PT5w== X-Gm-Message-State: AOJu0Yx1+h27U80t7o1fm1U5qAPgLWgfuoNvpz1PP+xGGBeMm8MlF2W8 /9sLlckVvW7C42Z+4zPgz30Pk6Olih8xQ+CkvGMZzqTnAVCcOSiInVG4oS0/qExMv68zuQxtBMk VUA== X-Google-Smtp-Source: AGHT+IHPYax4e7hJQ+gaxbLu7IAOdce1zAJLD3gabPJ9Hl5V55Dyzgq5ajL+IvTTGRwhn3fhy6HgPg== X-Received: by 2002:a5d:6483:0:b0:33a:f9fe:9db with SMTP id o3-20020a5d6483000000b0033af9fe09dbmr1720284wri.14.1706616688362; Tue, 30 Jan 2024 04:11:28 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:28 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 052/101] gccrs: Allow const and async specifiers in functions Date: Tue, 30 Jan 2024 13:07:08 +0100 Message-ID: <20240130121026.807464-55-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.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, 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: Pierre-Emmanuel Patry We need to account for const specifiers in async parsing as const can be used in the syntax before the async keyword. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_vis_item): Allow parsing async items in const. (Parser::parse_async_item): Account for const offset during async lookahead. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/parse/rust-parse-impl.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index a1ad4f11993..acceec302a2 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -1383,6 +1383,8 @@ Parser::parse_vis_item (AST::AttrVec outer_attrs) return parse_const_item (std::move (vis), std::move (outer_attrs)); case UNSAFE: case EXTERN_KW: + case ASYNC: + return parse_async_item (std::move (vis), std::move (outer_attrs)); case FN_KW: return parse_function (std::move (vis), std::move (outer_attrs)); default: @@ -1445,7 +1447,9 @@ std::unique_ptr Parser::parse_async_item (AST::Visibility vis, AST::AttrVec outer_attrs) { - const_TokenPtr t = lexer.peek_token (); + auto offset = (lexer.peek_token ()->get_id () == CONST) ? 1 : 0; + const_TokenPtr t = lexer.peek_token (offset); + if (Session::get_instance ().options.get_edition () == CompileOptions::Edition::E2015) { @@ -1456,7 +1460,7 @@ Parser::parse_async_item (AST::Visibility vis, "to use %, switch to Rust 2018 or later")); } - t = lexer.peek_token (1); + t = lexer.peek_token (offset + 1); switch (t->get_id ()) { From patchwork Tue Jan 30 12:07:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892843 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=T7sCr2Vd; 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 4TPPZm38Hsz23gZ for ; Tue, 30 Jan 2024 23:28:00 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 44AD53861848 for ; Tue, 30 Jan 2024 12:27:58 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by sourceware.org (Postfix) with ESMTPS id 283D83857C77 for ; Tue, 30 Jan 2024 12:11:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 283D83857C77 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 283D83857C77 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::235 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616723; cv=none; b=RMKuo+d8Qab89jdh5oX4QuYIGBmfZ5bCHwhC5Hq7nAz8Y9ww6YzVed9wPySluKVtFjpz75j/7WNKezkamygzTmrzQBv5k4u5dDD6cil0S/phBTHVdGq/B3WHBdgFdLcHC3FqHTldF5dOd1iN138SeJXfalaAUt+MWrqaFPNsUhw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616723; c=relaxed/simple; bh=8v13uMTZBQOezwuk9WKqu20abwbWli1uKfWQQWKsMOM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=qM7hJ3jFeHtLETM1UyijiimVkVbYMakFXNu//S/V+B460QAwvjd7/kEhWjSR38PnUvtLhjYn5F7c1/0e5tTjBfZenCiwHZ1Ztd238rEgqVeRAZDm8Vi1/TakyvHdaepBRt8/bZiSRSFhwvMfKrNiKNX/ljmbTW6VdSDY7Zwb0Qo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2cf3a0b2355so46403941fa.0 for ; Tue, 30 Jan 2024 04:11:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616689; x=1707221489; 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=Q5KCibpANi3i0FkYg0XOm/2drj/+e8CsnR0CuD4DLh8=; b=T7sCr2Vdg64RPteP9ixA4SZP6AhZh3kogF663Hfi9AlMzSTcHPoqC9c0n5hqT1QLSe HvD5LpqfNPmYH0c2VLBY3Ry57lDbH8mSm+I0fI5XcIJPtV5YOyB0MAp4kbo3TUO2GwgZ ofKi0f+mUhBVHAaCbYtnl56jOZeuQ14JrMU1cKDReNr2k9pqz5Sn58VJn6KTPIEwOVu9 2NXRl22H68+3r+m/zo5NyLTUJlphHoL+0AZDGvKewpoiVZOSJwWo8XcaoqCUmEJP4I1H +Vv/+pZ2cZqLn1RM4dFZ1GvbKm+NrlsExeTmlUJpEvdAzcThAwocTT8fTZGtbCZ/YK6a tjhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616689; x=1707221489; 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=Q5KCibpANi3i0FkYg0XOm/2drj/+e8CsnR0CuD4DLh8=; b=RaIzKlvkg1kwSexTyKFfdupDmR8k0fKF3yFM0heMI/Dt4KOjiuyyrgxkzjJthaTV4v FQfCU/bc6+kdPc2BDa1VTE64bxuaeN02hWqyh/2xMa/CVxqGEs0taKt85vWcsKF7Gt+H j1yKxdckMo85TkNyEZHNIOBtChdpzUnGW8YEYi+S+K+74m3G4xUTBpxpleinEA+/Sox7 XCu6a1DPMgDx+FGE8yPZ4QiZRZrJJMnHe5kTNJpRj0dOkHtp0fKm3LHiVDOGQ6ljEdCs 6tarv2qags604XLvC6I64J3Xj7COebAVcv2acp0PXsAoKibNgxwEffV4HMNXK8CJze1F ivVg== X-Gm-Message-State: AOJu0YxPPwAE9NWQ3rDzg09cv5bVNWxFL4n2cYc14L/3jwTFPiYJ8f9A tFBBYskE1SdhyBlZ6V5sYSr4/e7Sp2rbBioDlHWA/AMhsPaF82K3UYkJ9D2WApvtv8m/jcPgHzO 9UA== X-Google-Smtp-Source: AGHT+IEf5pUA6DoPdvFfjpGHug6NvzY+0NSr/S8xnS0qDOCN18xhCp4r6T0R8Q4aCn6bCFTzeczK6A== X-Received: by 2002:a05:651c:128d:b0:2cf:4e53:7c38 with SMTP id 13-20020a05651c128d00b002cf4e537c38mr5520259ljc.22.1706616689465; Tue, 30 Jan 2024 04:11:29 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:28 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 053/101] gccrs: Add async const function ast validation pass Date: Tue, 30 Jan 2024 13:07:09 +0100 Message-ID: <20240130121026.807464-56-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: Pierre-Emmanuel Patry Add a check during AST validation pass to ensure functions are either const or async but not both. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add async const check. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/checks/errors/rust-ast-validation.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index 4b209908f9e..54276e8fd59 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -98,6 +98,11 @@ ASTValidation::visit (AST::Function &function) std::set valid_context = {Context::INHERENT_IMPL, Context::TRAIT_IMPL}; + const auto &qualifiers = function.get_qualifiers (); + if (qualifiers.is_async () && qualifiers.is_const ()) + rust_error_at (function.get_locus (), + "functions cannot be both % and %"); + if (valid_context.find (context.back ()) == valid_context.end () && function.has_self_param ()) rust_error_at ( From patchwork Tue Jan 30 12:07:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892837 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=e5HNvQDx; 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 4TPPXb4kFWz23gZ for ; Tue, 30 Jan 2024 23:26:07 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9788E385F009 for ; Tue, 30 Jan 2024 12:26:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 8004C38582A6 for ; Tue, 30 Jan 2024 12:11:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8004C38582A6 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 8004C38582A6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::332 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616724; cv=none; b=O1ZtMafGjUjkFoV/Zi1fuOKbD2v1FGEZf6s0FC64dTREGrKjgKdeqS1S0HyTKJvVJQXXwOZR0n3+ofTYkcIRZeT4oaXq4K2OOw0kh+qfuWOxpnrlBEOZGtDPrPW7ZnbfK7cE6vi2GRFRI9gMQVODpTM0jTjPd0tXBesKlWSY62g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616724; c=relaxed/simple; bh=yVvkHiRzwQKV9Fl7/XGRtedUq79De0jo2gWYu0Uyq4g=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=fJFTpxhHBBRpAeSS1uPSdp8kfXoiWIZABNt0kEkEui1ECZm8CwrgHvfif/hK1oiXXyDv9MH1qDZAa0y3zOhbZYM0dhYKXBIXQEqAnobxl+QkQ7VZlAULjttmkNJ3kFh8QgIxSE0W+FHdiHFDTqWU/fXmS8ltdSF0wI8ArmKv92Y= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40e800461baso52295755e9.3 for ; Tue, 30 Jan 2024 04:11:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616690; x=1707221490; 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=zGSQwzUjaZKBQ14ZBTttX51N4Wpcz1KGCOvrt+VaPHA=; b=e5HNvQDx3csdSMOE3+pGrMF+nq8DYXRrboNSF2IJnjjFV5aZKRNGm1nLeT9+l0rmSG mBlP/rQJjf/6GQKvMTRKyHANWBlEhGVPEUXxstmNtzYDQuJJZ1OD5hpkPuULIDurjMQ9 GbEqvXMIeA7Cyn6QbDqLwsBlUgf60msshYkG9/+z1hBC7gfzr5/N/O76grJP+A65N0yt q49pwdOhuZm7aeR2dhBK4onB9XtliY+cCksemDzHJoEz1fF5eZTti0keJOR/lk1bRMCv WLNJwAJxeo/l34cikEVZPLFdAtMM8Hh3aNK8EGgB5yqPjL1VqTo2gGyZOogahGoVhAwP 3jhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616690; x=1707221490; 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=zGSQwzUjaZKBQ14ZBTttX51N4Wpcz1KGCOvrt+VaPHA=; b=i0czj8YsLxdRzprkmKGoSPArfkLja9GMoY8Cqa728zYZV8nzqXEt65paePbL1A4Z68 /PTmj1KzYopHNlvKYCkjbkH+wJCVEAdO4ywW+OU5ksfNIDE6hTaoDc5QpckIHOUURxUr s++4oBn2WyNZ211s5lTS932Lt1Ed5fiBD3uHIqd6dhuGbrHT9rsHUuvi7OB4CLJ2OUgT ys4goAnWMwJ6atdLBWlLAPASUmAgJXGFCYlb7RttKq6bXzzQOOnBUVSdORLe5CC90a5B guygKjXCyeGahBbds0IFRrw6xzYEIHo4QjTAGYxSYRzgkMLEs5CsU4hv/MdDTyloyjbL gIzQ== X-Gm-Message-State: AOJu0YzptTcdND7MpmlTb0VYvbJBX2LohuRSyFDzhckSXkmyB/ZPwIjU 4NzaIWXZjw56h7xw9n/tYOnszvDpAjDZ40kYxCelrilqph3VAsAvjSbcU+Lvf2wdynz95wF48iO 5CA== X-Google-Smtp-Source: AGHT+IFGFvuZvSOU4hcOlNdeetoDiWrhvXC0m6eCxusTnx+Hjo8T44+t7D6O8nkyNB9/YXWrgWtBCA== X-Received: by 2002:a5d:4582:0:b0:337:c4c7:97cc with SMTP id p2-20020a5d4582000000b00337c4c797ccmr5807016wrq.33.1706616690103; Tue, 30 Jan 2024 04:11:30 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:29 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 054/101] gccrs: Add a regression test for async const functions Date: Tue, 30 Jan 2024 13:07:10 +0100 Message-ID: <20240130121026.807464-57-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: Pierre-Emmanuel Patry Functions that are both async and const shall be rejected during the AST validation pass. This new test highlight this behavior. gcc/testsuite/ChangeLog: * rust/compile/const_async_function.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- gcc/testsuite/rust/compile/const_async_function.rs | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 gcc/testsuite/rust/compile/const_async_function.rs diff --git a/gcc/testsuite/rust/compile/const_async_function.rs b/gcc/testsuite/rust/compile/const_async_function.rs new file mode 100644 index 00000000000..fb1c4dd4c1d --- /dev/null +++ b/gcc/testsuite/rust/compile/const_async_function.rs @@ -0,0 +1,3 @@ +// { dg-additional-options "-frust-edition=2018" } +const async fn weird_function() {} +// { dg-error "functions cannot be both .const. and .async." "" { target *-*-* } .-1 } From patchwork Tue Jan 30 12:07:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892887 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=UBtk281J; 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 4TPPpy2Ylkz23dQ for ; Tue, 30 Jan 2024 23:38:34 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 54E09386C58E for ; Tue, 30 Jan 2024 12:38:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 2EFF33857C7D for ; Tue, 30 Jan 2024 12:11:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2EFF33857C7D 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 2EFF33857C7D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616725; cv=none; b=f9g2+pR64dJDSjju9z1aA8IIBv+yii999XuVaYuYno+GLOtUXFkRoEfrrVpu75iwDjl4w2NjAedBJQNnTisXYEa2Vxg26SACA5Qrxe6ESXj6fg9FZhX7tHP9TvQyNAd3ljSlDCdn/ENm6qL4q1uBV+3UZA9U/VBI58XBMHBIwq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616725; c=relaxed/simple; bh=fCJ+dW56/eRjZRX3mdZZWthnOSE8tDh/d3d1gJzSSsQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=HvUiBjLkCuSagugw44S5gYHDcoi61knMvkB2GB0kYKZUo6c1eXR0hLYR5TOdCST60fMnE5yN4o7Ti8zbM6DUVbgoEAZakAKRmwzcgCtLvIemc/A+ovN8LWjA2l872GL4y9bQg2BEsvbJRLGkne0wA2pDtlGieoh3Q5A63xcCrZA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-337cc8e72f5so3029358f8f.1 for ; Tue, 30 Jan 2024 04:11:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616691; x=1707221491; 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=l6q8oLIWHaJf3t7j5fmWON5mJxrap4cF6WFh9DxU2ss=; b=UBtk281JBqcyOfrYSqTWjMHtvxQbEd/S70lDKDvQ+lf1WoHqqUxYrkRedoBBxiMmCE zdaSzb8h4dBSoek5jOq20Ks380N8kqDycVcPuS8KPngle+SgOs2ohoDuyibemz/qZHWL oYk2EXvbJbgyvmZZrOJy3lKU8r0hRUibBot4MjxsiUChaYKjvjwYU8bapsmjJ2Aief3v pSF5vv9KLW9uTBzYG4gm9fhVXk9jRrtRzjCxrYF9z1u0uuqdwH4/1I+Mwk+1sofOFDdA /zgLKtyGBlPiT0DekuOrxKT3+NWplfWm7xY6qqr9/Fczj991jM1+kakNHj4u1JEWkeu8 Ikkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616691; x=1707221491; 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=l6q8oLIWHaJf3t7j5fmWON5mJxrap4cF6WFh9DxU2ss=; b=iU95yxaPoKIBDg8mkqcg+c5dRaMVfpOtojW+YQ1KUjnQ14BA1YernehzqlRMSSMO3c 3ugBYC5th+u3cfvYTDwFDEB+9rWo+Y//a3LZXqKbHGfWKH4NF+jUTLElR7L5u1SYPn8q FEUmW6sCuCb2rDTI+K97/N/MTE/cjaKBqxSDK0l7Bwhm4OPzzOuupTSuG0tzCtOlhmg9 NiE8G4hy3hGDw0w3Zeruz8c2+AZp6e8rmwTZa+Z2oVJwb/qvuD6stZlmxC9VzVvIjkEb RBozc7VTamh/5wGPZMtnE/C/r645yqOddxaLjUc/JbNgCTW1fHE+4YcAXVKdMOsgBe7A nv/Q== X-Gm-Message-State: AOJu0YyRlg5TqPMZc4XV+PBgdg6Eok7w/a+MR+5CR6JITmharLMB7d+1 75+V7ew676t8su9Azr9DBUltx7q8FGUEXf1wIhL3+o1RgH9lU8AD2ynRUp5J/znWjAVgdSZDJDC 6UQ== X-Google-Smtp-Source: AGHT+IGcGfJvSCP3bq6Ltorz3H8N+OPKDmiHTuMrV4BXya6Ipz07syAXrWlgTQ7qT/4uZxbVDzE+nw== X-Received: by 2002:adf:ea51:0:b0:33a:e89f:1dc5 with SMTP id j17-20020adfea51000000b0033ae89f1dc5mr4753581wrn.23.1706616690779; Tue, 30 Jan 2024 04:11:30 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:30 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 055/101] gccrs: Add AST validation check for const in trait Date: Tue, 30 Jan 2024 13:07:11 +0100 Message-ID: <20240130121026.807464-58-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.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, 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: Pierre-Emmanuel Patry Add a new check in AST validation pass that checks that no function declaration in traits are declared const. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add const check. * checks/errors/rust-ast-validation.h: Add visit function prototype. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/checks/errors/rust-ast-validation.cc | 10 ++++++++++ gcc/rust/checks/errors/rust-ast-validation.h | 1 + 2 files changed, 11 insertions(+) diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index 54276e8fd59..2743eb0ca29 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -117,6 +117,16 @@ ASTValidation::visit (AST::Function &function) AST::ContextualASTVisitor::visit (function); } +void +ASTValidation::visit (AST::TraitFunctionDecl &decl) +{ + const auto &qualifiers = decl.get_qualifiers (); + + if (context.back () == Context::TRAIT && qualifiers.is_const ()) + rust_error_at (decl.get_identifier ().get_locus (), ErrorCode::E0379, + "functions in traits cannot be declared const"); +} + void ASTValidation::visit (AST::Trait &trait) { diff --git a/gcc/rust/checks/errors/rust-ast-validation.h b/gcc/rust/checks/errors/rust-ast-validation.h index 01d923ceff3..963357f86cd 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.h +++ b/gcc/rust/checks/errors/rust-ast-validation.h @@ -42,6 +42,7 @@ public: virtual void visit (AST::Union &item); virtual void visit (AST::Function &function); virtual void visit (AST::Trait &trait); + virtual void visit (AST::TraitFunctionDecl &decl); }; } // namespace Rust From patchwork Tue Jan 30 12:07:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892841 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=cFoecqCu; 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 4TPPYx4t9pz23gZ for ; Tue, 30 Jan 2024 23:27:17 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AE273386182A for ; Tue, 30 Jan 2024 12:27:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id ECF623857836 for ; Tue, 30 Jan 2024 12:11:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ECF623857836 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 ECF623857836 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::334 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616724; cv=none; b=UAUqQA1yAj09gU3Yi+g7BdhInBXyOqAlGRk1J3QYXFmt7O41Zlb/uDeKfZq230o0L5ABMqZ2mbE5i5k+mAsCl2plOk34lCEGR/yD7Xj79WftxvZfBEDtu4G1Whuf+3evYUGVNqMyQHqLJH6p/Y8UR9ADdqRwUZZlcOKQ0570Ifo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616724; c=relaxed/simple; bh=V7czSTVoqPl51lZHeMXKLlzlUXwI+n+9+yMwDwFJ3TU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XSlr+yzfFbihzFgc9YWEQTU7maUf/eW17pwKgNVpkjjhUIOveL98eHvqCqchhzvBlDnS4OeCByx0lxcjX/9mhAu+Cq67E5fvvIh3dQxNSUwQg964hbzQu+Ph+JDtNYwQB9onjysihWW4JjCkFhHutYLStGkihCnlsZBnAKGZm4Y= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40e8fec0968so45790265e9.1 for ; Tue, 30 Jan 2024 04:11:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616691; x=1707221491; 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=u/zjFdpS3HIGkvLW5b/FbM6P4gzpWMJd7LGHLfZRe3A=; b=cFoecqCutytLATXxWe1TO0trrVREB7UOBxqpAC/oe6M2bmz4lYjzFl43LBrRBwcJSi QQKZsttfEzIacNoUk5ZC7IGpO8tH+qixGWh5p5Y5ekiLI4RyVXY8+mEMOxXKAhO5QytG OSAWZwKPEPZNMtX+dMBBUn15SWNqf09WiUHH2dEP6tqZ+lcFeVC3fh1rmdUsyZTLPj0m 4LY8cgGzpjUxX9UgL4d1UZJxJQ6oZEUBgILYM3jUI8Fjyl/OIElf7s+x1Gpv/sK/UoVE BltwBVesCnVwvmza6rDLZUa3k1uCj08m4AIjhEYe3jTGM8EWodzAqFKFcMSmmrgrsOHK Fieg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616691; x=1707221491; 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=u/zjFdpS3HIGkvLW5b/FbM6P4gzpWMJd7LGHLfZRe3A=; b=JNmM7+dsUrKnMkUhUiGg4jfgSIQgIw48+rCL49OwEZ+oBveCFqYV7p9w+nvsgsycH7 Qi2la9GqX7bujBWuL4HUc8F0LWzWoi8nEA0zLY/w3vcFbRLAME1PRBcpEYKXBYCrkmDf Ao9XKNgRWfh85kyTo8RpChOwNMJVL6e/MeRLXFZIKZ2uCcbvv9z4BtVfE4qeS9g7/PzH mBrUDerIAk9MryRhxJPp/9fbnDyhTaMdPp/7PnhVSdL6geoCKNMl0WEXXu6dTYzzBihT Bml+FnTvkKKblWHJ1UvjBygSU8J8mZzZeLjjYDIJLRrX2+hBMEMcYNSI6srzdGsVh3+o t+2Q== X-Gm-Message-State: AOJu0Yxabt4hHWr+WULH/OzK02UhgzaRMdT69cot1VHXNilswpmr5K+G q04ASqiyg6Ax5PunjMR57OgUlerkCf0Wx5UJI/OT4AmrS8gectLvyUMd0Gbv/VXkALWtJkKaxY1 Eig== X-Google-Smtp-Source: AGHT+IH/Q97d5pmODaxscVWprzYZlH3g0TSiDKW/4VEgMspY99/fr+ePvl9twcAMNbKXTYpdvej6+Q== X-Received: by 2002:a05:600c:1391:b0:40e:a479:fed1 with SMTP id u17-20020a05600c139100b0040ea479fed1mr7512817wmf.7.1706616691575; Tue, 30 Jan 2024 04:11:31 -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.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:31 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 056/101] gccrs: Add regression test for const fn in trait Date: Tue, 30 Jan 2024 13:07:12 +0100 Message-ID: <20240130121026.807464-59-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.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, 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: Pierre-Emmanuel Patry Const fn declaration in trait declarations shall emit an error. This new test highlight this behavior. gcc/testsuite/ChangeLog: * rust/compile/const_trait_fn.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- gcc/testsuite/rust/compile/const_trait_fn.rs | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 gcc/testsuite/rust/compile/const_trait_fn.rs diff --git a/gcc/testsuite/rust/compile/const_trait_fn.rs b/gcc/testsuite/rust/compile/const_trait_fn.rs new file mode 100644 index 00000000000..cff2f5f096e --- /dev/null +++ b/gcc/testsuite/rust/compile/const_trait_fn.rs @@ -0,0 +1,4 @@ +trait Osterkz { + const fn x(); + // { dg-error "functions in traits cannot be declared const .E0379." "" { target *-*-* } .-1 } +} From patchwork Tue Jan 30 12:07:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892898 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=THt3UyXD; 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 4TPPvR5gVzz23gZ for ; Tue, 30 Jan 2024 23:42:27 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C8F8F386EC15 for ; Tue, 30 Jan 2024 12:42:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id B1344385770D for ; Tue, 30 Jan 2024 12:11:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B1344385770D 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 B1344385770D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::332 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616725; cv=none; b=sZ71YNxkmBDWZTD6tEWxXH9LcwZq2nXhmjFVChNAyx/TLNjhGD4FhCepkwK+5Mri7EqGMAyAtFCWmW7gYMh23kBSYp4pdCOUpajAP95guYTOZnfFArWu84FpAsRoFfae4IeS35W9q6zBMsFRXvj5eLIchEY+UzMwu3p+M1QXPJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616725; c=relaxed/simple; bh=ctd8ivjFMtrALJ3zsFFRd4Bj5Sg7cn/kM96vKfhu5jc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xGER4WCMgnhuZ69eu8plUV0D11uayGb8124q9tyVyTdvRfJFCJwQj3jk+W1zm5i2pQvWZL8yNUOPihthu74tgp0rePSc5Sp11auDRNfTj0KsXBaWhQ0UKHMWwItTnIslswi4/gjiHDWdCAa/mLr48dgi8+b7eeZoImqn5xFeong= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40e5afc18f5so41946525e9.3 for ; Tue, 30 Jan 2024 04:11:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616692; x=1707221492; 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=HEJuZnnuKQuxQNKOVvXiYIxb18W3B/fbTUp/CKwGKHk=; b=THt3UyXDRqro8Yt/+FIFDkocJ3EfJ3PHMo0iH2Tw3bhhn76iDQXzmonjFvdlPbDVVn 4GNSaQO/eBxJPnZoaPvqH9Q+Dqr8X8AQ5bXyBlAra9MnbOdeFmqgY1jCU/GVd+9BvlWZ tS04+H97TRGjjST24H3HfJxZxmxhI2meysrDEU0wj07LbF4Lkn1JkfL/ZWewQGApplM8 KKlPk6SZ5V55vxzbMMm0VhNFDCmCVdzCcu0nSxLjrQcT2nby0CwNXLgLkkDd8jBQW8Aj WCiq2Ag1JyX8IvlMlVK/YiaaYGzaCJhcE486XGqwc346LzsyVJAl+iGr3RkL1Xsd3T/S GXeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616692; x=1707221492; 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=HEJuZnnuKQuxQNKOVvXiYIxb18W3B/fbTUp/CKwGKHk=; b=uAERCooX3pY6HCKbS7lkuy3HmcHGoDf7zlW/FdFMTIpi5O93BTJ5ALQE0cPU9zZzUq MN3zOCzUVAlxwipu0tEKJeF+xeVeDtlv1e06oypU14k8RIpQ78/I60sviTEM/5VKE5Rk eNpb2LqXePXUPnG8RW3cCoyIce7qcvDs2w1cOiAOyJJSOxXAy6rRDXnjQH1cs6wFZFJO ggIEjOjEGltgNKSsUowGEVxTyuYrRo06Z2oE9mNzuM0+ew058c5L9RRQXon+Zmk0ov8A amVtuPW900vbANHVVvgamtF24xWC36CdslQN/Yxx6mkXIcyqrKWTfTtuMnZQEMT0nAqK 0Fzw== X-Gm-Message-State: AOJu0YyGGi+/OsNVctd0AqPH27d7HkLuUePzRkwCk+REiiEcQneVv4FN JH/0jRHhP5bodS/8MhSDLWTosL2axHJd52mnu0ERRDf1/iimdXmFkCZKgBJUtzVSeITMFry54xw 9hA== X-Google-Smtp-Source: AGHT+IF7K47OamPaw/rzs0I2dSRRtdrjsLkAk2Pzf/m8gRtllRWspI804D5ewd1s961hOYGn6I4SFw== X-Received: by 2002:a5d:62cc:0:b0:33a:f4b4:8023 with SMTP id o12-20020a5d62cc000000b0033af4b48023mr3158076wrv.7.1706616692247; Tue, 30 Jan 2024 04:11:32 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:31 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 057/101] gccrs: Make feature gate visitor inherit from default one Date: Tue, 30 Jan 2024 13:07:13 +0100 Message-ID: <20240130121026.807464-60-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: Pierre-Emmanuel Patry The feature gating behavior may be shortened and kept cleaner using the default visitor. This means less maintenance on visit functions as the traversal is shared by multiple visitors. gcc/rust/ChangeLog: * checks/errors/rust-feature-gate.cc (FeatureGate::visit): Add a visit function for the crate level. (FeatureGate::check): Add call to crate visit. * checks/errors/rust-feature-gate.h (class FeatureGate): Remove now useless visit functions (traversal only). Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/checks/errors/rust-feature-gate.cc | 37 +++++---------------- gcc/rust/checks/errors/rust-feature-gate.h | 7 ++-- 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc b/gcc/rust/checks/errors/rust-feature-gate.cc index a531d0370f0..3c943022f05 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.cc +++ b/gcc/rust/checks/errors/rust-feature-gate.cc @@ -18,11 +18,18 @@ #include "rust-feature-gate.h" #include "rust-abi.h" +#include "rust-ast-visitor.h" namespace Rust { void FeatureGate::check (AST::Crate &crate) +{ + visit (crate); +} + +void +FeatureGate::visit (AST::Crate &crate) { valid_features.clear (); @@ -56,12 +63,7 @@ FeatureGate::check (AST::Crate &crate) } } - auto &items = crate.items; - for (auto it = items.begin (); it != items.end (); it++) - { - auto &item = *it; - item->accept_vis (*this); - } + AST::DefaultASTVisitor::visit (crate); } void @@ -103,10 +105,7 @@ FeatureGate::visit (AST::ExternBlock &block) gate (Feature::Name::INTRINSICS, block.get_locus (), "intrinsics are subject to change"); } - for (const auto &item : block.get_extern_items ()) - { - item->accept_vis (*this); - } + AST::DefaultASTVisitor::visit (block); } void @@ -129,24 +128,6 @@ FeatureGate::visit (AST::MacroRulesDefinition &rules_def) check_rustc_attri (rules_def.get_outer_attrs ()); } -void -FeatureGate::visit (AST::InherentImpl &impl) -{ - for (const auto &item : impl.get_impl_items ()) - { - item->accept_vis (*this); - } -} - -void -FeatureGate::visit (AST::TraitImpl &impl) -{ - for (const auto &item : impl.get_impl_items ()) - { - item->accept_vis (*this); - } -} - void FeatureGate::visit (AST::Function &function) { diff --git a/gcc/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h index 1ebd3c9e05f..8d1a26a1361 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.h +++ b/gcc/rust/checks/errors/rust-feature-gate.h @@ -25,12 +25,15 @@ namespace Rust { -class FeatureGate : public AST::ASTVisitor +class FeatureGate : public AST::DefaultASTVisitor { public: FeatureGate () {} + using AST::DefaultASTVisitor::visit; + void check (AST::Crate &crate); + void visit (AST::Crate &crate) override; void visit (AST::Token &tok) override {} void visit (AST::DelimTokenTree &delim_tok_tree) override {} @@ -127,8 +130,6 @@ public: void visit (AST::TraitItemConst &item) override {} void visit (AST::TraitItemType &item) override {} void visit (AST::Trait &trait) override {} - void visit (AST::InherentImpl &impl) override; - void visit (AST::TraitImpl &impl) override; void visit (AST::ExternalTypeItem &item) override; void visit (AST::ExternalStaticItem &item) override {} void visit (AST::ExternalFunctionItem &item) override {} From patchwork Tue Jan 30 12:07:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892849 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=W58308Z1; 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 4TPPcJ0dlBz23gZ for ; Tue, 30 Jan 2024 23:29:20 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 17D033865C27 for ; Tue, 30 Jan 2024 12:29:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id BAD8A385801A for ; Tue, 30 Jan 2024 12:11:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BAD8A385801A 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 BAD8A385801A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::234 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616725; cv=none; b=wjlWlMIsPeO5Bi15Oedu57vuBhbv95hi7tiCycatsWjdgd6pJm9UbjjosHd7F9B+CaoONDjvCh+eSHXoVk6B8rg3pvVo1CVa0QHYAgfpFCXObGC8WHBw0zJL5Yf2HggR8bxdtvqiJ4lXJW29TY06hwp/03UtIZTLeFO6db/BZxo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616725; c=relaxed/simple; bh=vI0nC77DU745OOodzBq8iDL/r56DwZjCvrxtJA9ZRg8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=kI26Sz1LQnbNOq6S74MbeAxfX7Ahjt5CELyAtwHhpyU8kG9L+y1AVywsjavIDpXoWqlTziCBVKjQtlkJuP2baK3vTe/tQ8B87bmnYQAqyIo21P92Ls7DMPjA8Z+zVbtDVMWppRT6DBjd8fIt+/uuZO8Jf0r0lQakqmjLfj30/u0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2d060055201so2358211fa.1 for ; Tue, 30 Jan 2024 04:11:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616693; x=1707221493; 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=U+ZbQJtu9PXtNZ/eLFhTSP1+v9FXgAXJcaa0OWBRMPo=; b=W58308Z1kQdpJDh+oH3Bg49HRvd7y9YmTtekfJ9iGHDI+0Wu6N/XCIkWxXq5LSx4rA r74RXEIfibGlOSJyLfXtktNzePl33/WfWL0Rr7Qz1G5ekdhS3u2bRQrx5gH2YFwB7DCq ynThWEFGEMXqasmKRLudUR03+YNOkJ+o7fa0GNRG+Li4OhxywE3lxACEnNBY+wyHhy2J /TmjgdAQ9BulWWNQbOFTYYoP2RxraxYrO713JzKkGt9cnljf3dBwnKUPhnsXfIH/ConL Na9LKufpotVkBKSZ6KMZtloap18NCs6wQyWhOoKDiIOzQba5EK2h3nIrt660prdDRYeI mCrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616693; x=1707221493; 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=U+ZbQJtu9PXtNZ/eLFhTSP1+v9FXgAXJcaa0OWBRMPo=; b=X9RHyvT9OHo5sbo+M1NUzqqOS3pdSN8adUu8odxtlTgjRDALZ7jePa/4REUhHx1XAk X3khU+/hj7Nh6ItADXVd7jYQlYEZV4R6fVjXXF7we8QEfmnxkw2vb3DaK33WXZWKRRgO ullu7QHuWk7sg+7wb4G5ge6U3vzcaF9Kr0qJLghskTyMhpbg327HWUzEfSnKnIhDzTMr XabyzSuYAlD5VoRSobWZqC473ugRW8YYPHAmhx2vCyoWebq/r5gUVbqhTlM0GiQPkfgy GUzUcdmrP1AnRN1b7NoUoDwneFxEYOt1u92tFHCNUQvEEGLISWSoEO5FPCMapBx4TUBS WtlA== X-Gm-Message-State: AOJu0YwNLdDPuCwKhZ92xhrJYj+ro8mIeqCSjkkC/XkPUQDyl/WX2VbO QrhDOhv40xHHX7bGDxpZFxdDz1zrWysCZ88/71B5ls75v7o6IY2Vx2V+SObVML8yYNxu/hNpYiZ KrQ== X-Google-Smtp-Source: AGHT+IGC61Kw/XBqD7gsLfS0cBBep9ALaMbb+TqDAJgBifjeNAuZThmXi7IBN3TRq6y/c/kZ/j4CDQ== X-Received: by 2002:a2e:3618:0:b0:2cc:dc54:871e with SMTP id d24-20020a2e3618000000b002ccdc54871emr5275979lja.24.1706616692979; Tue, 30 Jan 2024 04:11:32 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:32 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 058/101] gccrs: Change the attribute checker visitor to default one Date: Tue, 30 Jan 2024 13:07:14 +0100 Message-ID: <20240130121026.807464-61-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.2 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, 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: Pierre-Emmanuel Patry Make the attribute checker visitor inherit from the default visitor in order to keep visit behavior shared. gcc/rust/ChangeLog: * util/rust-attributes.cc (AttributeChecker::visit): Add visit function for crates. * util/rust-attributes.h (class AttributeChecker): Update function prototypes. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/util/rust-attributes.cc | 23 ++- gcc/rust/util/rust-attributes.h | 319 ++++++++++++++++--------------- 2 files changed, 171 insertions(+), 171 deletions(-) diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index 981bc738d6c..a1e23082e88 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -16,6 +16,7 @@ // along with GCC; see the file COPYING3. If not see // . +#include "rust-ast-visitor.h" #include "rust-system.h" #include "rust-session-manager.h" #include "rust-attributes.h" @@ -94,6 +95,12 @@ AttributeChecker::AttributeChecker () {} void AttributeChecker::go (AST::Crate &crate) +{ + visit (crate); +} + +void +AttributeChecker::visit (AST::Crate &crate) { check_attributes (crate.get_inner_attrs ()); @@ -468,8 +475,8 @@ AttributeChecker::visit (AST::BlockExpr &expr) check_proc_macro_non_root (item->get_outer_attrs (), item->get_locus ()); } - stmt->accept_vis (*this); } + AST::DefaultASTVisitor::visit (expr); } void @@ -512,12 +519,6 @@ void AttributeChecker::visit (AST::ReturnExpr &) {} -void -AttributeChecker::visit (AST::UnsafeBlockExpr &expr) -{ - expr.get_block_expr ()->accept_vis (*this); -} - void AttributeChecker::visit (AST::LoopExpr &) {} @@ -582,8 +583,8 @@ AttributeChecker::visit (AST::Module &module) for (auto &item : module.get_items ()) { check_proc_macro_non_root (item->get_outer_attrs (), item->get_locus ()); - item->accept_vis (*this); } + AST::DefaultASTVisitor::visit (module); } void @@ -754,16 +755,14 @@ void AttributeChecker::visit (AST::InherentImpl &impl) { check_proc_macro_non_function (impl.get_outer_attrs ()); - for (auto &item : impl.get_impl_items ()) - item->accept_vis (*this); + AST::DefaultASTVisitor::visit (impl); } void AttributeChecker::visit (AST::TraitImpl &impl) { check_proc_macro_non_function (impl.get_outer_attrs ()); - for (auto &item : impl.get_impl_items ()) - item->accept_vis (*this); + AST::DefaultASTVisitor::visit (impl); } void diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h index 9db371e81c6..eecc4c0050b 100644 --- a/gcc/rust/util/rust-attributes.h +++ b/gcc/rust/util/rust-attributes.h @@ -77,7 +77,7 @@ private: * as checking the "arguments" or input given to these attributes, making sure * it is appropriate and valid. */ -class AttributeChecker : public AST::ASTVisitor +class AttributeChecker : public AST::DefaultASTVisitor { public: AttributeChecker (); @@ -88,6 +88,7 @@ public: void go (AST::Crate &crate); private: + using AST::DefaultASTVisitor::visit; /* Check the validity of a given attribute */ void check_attribute (const AST::Attribute &attribute); @@ -95,178 +96,178 @@ private: void check_attributes (const AST::AttrVec &attributes); // rust-ast.h - void visit (AST::Token &tok); - void visit (AST::DelimTokenTree &delim_tok_tree); - void visit (AST::AttrInputMetaItemContainer &input); - void visit (AST::IdentifierExpr &ident_expr); - void visit (AST::Lifetime &lifetime); - void visit (AST::LifetimeParam &lifetime_param); - void visit (AST::ConstGenericParam &const_param); + void visit (AST::Crate &crate) override; + void visit (AST::Token &tok) override; + void visit (AST::DelimTokenTree &delim_tok_tree) override; + void visit (AST::AttrInputMetaItemContainer &input) override; + void visit (AST::IdentifierExpr &ident_expr) override; + void visit (AST::Lifetime &lifetime) override; + void visit (AST::LifetimeParam &lifetime_param) override; + void visit (AST::ConstGenericParam &const_param) override; // rust-path.h - void visit (AST::PathInExpression &path); - void visit (AST::TypePathSegment &segment); - void visit (AST::TypePathSegmentGeneric &segment); - void visit (AST::TypePathSegmentFunction &segment); - void visit (AST::TypePath &path); - void visit (AST::QualifiedPathInExpression &path); - void visit (AST::QualifiedPathInType &path); + void visit (AST::PathInExpression &path) override; + void visit (AST::TypePathSegment &segment) override; + void visit (AST::TypePathSegmentGeneric &segment) override; + void visit (AST::TypePathSegmentFunction &segment) override; + void visit (AST::TypePath &path) override; + void visit (AST::QualifiedPathInExpression &path) override; + void visit (AST::QualifiedPathInType &path) override; // rust-expr.h - void visit (AST::LiteralExpr &expr); - void visit (AST::AttrInputLiteral &attr_input); - void visit (AST::AttrInputMacro &attr_input); - void visit (AST::MetaItemLitExpr &meta_item); - void visit (AST::MetaItemPathLit &meta_item); - void visit (AST::BorrowExpr &expr); - void visit (AST::DereferenceExpr &expr); - void visit (AST::ErrorPropagationExpr &expr); - void visit (AST::NegationExpr &expr); - void visit (AST::ArithmeticOrLogicalExpr &expr); - void visit (AST::ComparisonExpr &expr); - void visit (AST::LazyBooleanExpr &expr); - void visit (AST::TypeCastExpr &expr); - void visit (AST::AssignmentExpr &expr); - void visit (AST::CompoundAssignmentExpr &expr); - void visit (AST::GroupedExpr &expr); - void visit (AST::ArrayElemsValues &elems); - void visit (AST::ArrayElemsCopied &elems); - void visit (AST::ArrayExpr &expr); - void visit (AST::ArrayIndexExpr &expr); - void visit (AST::TupleExpr &expr); - void visit (AST::TupleIndexExpr &expr); - void visit (AST::StructExprStruct &expr); - void visit (AST::StructExprFieldIdentifier &field); - void visit (AST::StructExprFieldIdentifierValue &field); - void visit (AST::StructExprFieldIndexValue &field); - void visit (AST::StructExprStructFields &expr); - void visit (AST::StructExprStructBase &expr); - void visit (AST::CallExpr &expr); - void visit (AST::MethodCallExpr &expr); - void visit (AST::FieldAccessExpr &expr); - void visit (AST::ClosureExprInner &expr); - void visit (AST::BlockExpr &expr); - void visit (AST::ClosureExprInnerTyped &expr); - void visit (AST::ContinueExpr &expr); - void visit (AST::BreakExpr &expr); - void visit (AST::RangeFromToExpr &expr); - void visit (AST::RangeFromExpr &expr); - void visit (AST::RangeToExpr &expr); - void visit (AST::RangeFullExpr &expr); - void visit (AST::RangeFromToInclExpr &expr); - void visit (AST::RangeToInclExpr &expr); - void visit (AST::ReturnExpr &expr); - void visit (AST::UnsafeBlockExpr &expr); - void visit (AST::LoopExpr &expr); - void visit (AST::WhileLoopExpr &expr); - void visit (AST::WhileLetLoopExpr &expr); - void visit (AST::ForLoopExpr &expr); - void visit (AST::IfExpr &expr); - void visit (AST::IfExprConseqElse &expr); - void visit (AST::IfLetExpr &expr); - void visit (AST::IfLetExprConseqElse &expr); - void visit (AST::MatchExpr &expr); - void visit (AST::AwaitExpr &expr); - void visit (AST::AsyncBlockExpr &expr); + void visit (AST::LiteralExpr &expr) override; + void visit (AST::AttrInputLiteral &attr_input) override; + void visit (AST::AttrInputMacro &attr_input) override; + void visit (AST::MetaItemLitExpr &meta_item) override; + void visit (AST::MetaItemPathLit &meta_item) override; + void visit (AST::BorrowExpr &expr) override; + void visit (AST::DereferenceExpr &expr) override; + void visit (AST::ErrorPropagationExpr &expr) override; + void visit (AST::NegationExpr &expr) override; + void visit (AST::ArithmeticOrLogicalExpr &expr) override; + void visit (AST::ComparisonExpr &expr) override; + void visit (AST::LazyBooleanExpr &expr) override; + void visit (AST::TypeCastExpr &expr) override; + void visit (AST::AssignmentExpr &expr) override; + void visit (AST::CompoundAssignmentExpr &expr) override; + void visit (AST::GroupedExpr &expr) override; + void visit (AST::ArrayElemsValues &elems) override; + void visit (AST::ArrayElemsCopied &elems) override; + void visit (AST::ArrayExpr &expr) override; + void visit (AST::ArrayIndexExpr &expr) override; + void visit (AST::TupleExpr &expr) override; + void visit (AST::TupleIndexExpr &expr) override; + void visit (AST::StructExprStruct &expr) override; + void visit (AST::StructExprFieldIdentifier &field) override; + void visit (AST::StructExprFieldIdentifierValue &field) override; + void visit (AST::StructExprFieldIndexValue &field) override; + void visit (AST::StructExprStructFields &expr) override; + void visit (AST::StructExprStructBase &expr) override; + void visit (AST::CallExpr &expr) override; + void visit (AST::MethodCallExpr &expr) override; + void visit (AST::FieldAccessExpr &expr) override; + void visit (AST::ClosureExprInner &expr) override; + void visit (AST::BlockExpr &expr) override; + void visit (AST::ClosureExprInnerTyped &expr) override; + void visit (AST::ContinueExpr &expr) override; + void visit (AST::BreakExpr &expr) override; + void visit (AST::RangeFromToExpr &expr) override; + void visit (AST::RangeFromExpr &expr) override; + void visit (AST::RangeToExpr &expr) override; + void visit (AST::RangeFullExpr &expr) override; + void visit (AST::RangeFromToInclExpr &expr) override; + void visit (AST::RangeToInclExpr &expr) override; + void visit (AST::ReturnExpr &expr) override; + void visit (AST::LoopExpr &expr) override; + void visit (AST::WhileLoopExpr &expr) override; + void visit (AST::WhileLetLoopExpr &expr) override; + void visit (AST::ForLoopExpr &expr) override; + void visit (AST::IfExpr &expr) override; + void visit (AST::IfExprConseqElse &expr) override; + void visit (AST::IfLetExpr &expr) override; + void visit (AST::IfLetExprConseqElse &expr) override; + void visit (AST::MatchExpr &expr) override; + void visit (AST::AwaitExpr &expr) override; + void visit (AST::AsyncBlockExpr &expr) override; // rust-item.h - void visit (AST::TypeParam ¶m); - void visit (AST::LifetimeWhereClauseItem &item); - void visit (AST::TypeBoundWhereClauseItem &item); - void visit (AST::Module &module); - void visit (AST::ExternCrate &crate); - void visit (AST::UseTreeGlob &use_tree); - void visit (AST::UseTreeList &use_tree); - void visit (AST::UseTreeRebind &use_tree); - void visit (AST::UseDeclaration &use_decl); - void visit (AST::Function &function); - void visit (AST::TypeAlias &type_alias); - void visit (AST::StructStruct &struct_item); - void visit (AST::TupleStruct &tuple_struct); - void visit (AST::EnumItem &item); - void visit (AST::EnumItemTuple &item); - void visit (AST::EnumItemStruct &item); - void visit (AST::EnumItemDiscriminant &item); - void visit (AST::Enum &enum_item); - void visit (AST::Union &union_item); - void visit (AST::ConstantItem &const_item); - void visit (AST::StaticItem &static_item); - void visit (AST::TraitItemFunc &item); - void visit (AST::TraitItemMethod &item); - void visit (AST::TraitItemConst &item); - void visit (AST::TraitItemType &item); - void visit (AST::Trait &trait); - void visit (AST::InherentImpl &impl); - void visit (AST::TraitImpl &impl); - void visit (AST::ExternalTypeItem &item); - void visit (AST::ExternalStaticItem &item); - void visit (AST::ExternalFunctionItem &item); - void visit (AST::ExternBlock &block); + void visit (AST::TypeParam ¶m) override; + void visit (AST::LifetimeWhereClauseItem &item) override; + void visit (AST::TypeBoundWhereClauseItem &item) override; + void visit (AST::Module &module) override; + void visit (AST::ExternCrate &crate) override; + void visit (AST::UseTreeGlob &use_tree) override; + void visit (AST::UseTreeList &use_tree) override; + void visit (AST::UseTreeRebind &use_tree) override; + void visit (AST::UseDeclaration &use_decl) override; + void visit (AST::Function &function) override; + void visit (AST::TypeAlias &type_alias) override; + void visit (AST::StructStruct &struct_item) override; + void visit (AST::TupleStruct &tuple_struct) override; + void visit (AST::EnumItem &item) override; + void visit (AST::EnumItemTuple &item) override; + void visit (AST::EnumItemStruct &item) override; + void visit (AST::EnumItemDiscriminant &item) override; + void visit (AST::Enum &enum_item) override; + void visit (AST::Union &union_item) override; + void visit (AST::ConstantItem &const_item) override; + void visit (AST::StaticItem &static_item) override; + void visit (AST::TraitItemFunc &item) override; + void visit (AST::TraitItemMethod &item) override; + void visit (AST::TraitItemConst &item) override; + void visit (AST::TraitItemType &item) override; + void visit (AST::Trait &trait) override; + void visit (AST::InherentImpl &impl) override; + void visit (AST::TraitImpl &impl) override; + void visit (AST::ExternalTypeItem &item) override; + void visit (AST::ExternalStaticItem &item) override; + void visit (AST::ExternalFunctionItem &item) override; + void visit (AST::ExternBlock &block) override; // rust-macro.h - void visit (AST::MacroMatchFragment &match); - void visit (AST::MacroMatchRepetition &match); - void visit (AST::MacroMatcher &matcher); - void visit (AST::MacroRulesDefinition &rules_def); - void visit (AST::MacroInvocation ¯o_invoc); - void visit (AST::MetaItemPath &meta_item); - void visit (AST::MetaItemSeq &meta_item); - void visit (AST::MetaWord &meta_item); - void visit (AST::MetaNameValueStr &meta_item); - void visit (AST::MetaListPaths &meta_item); - void visit (AST::MetaListNameValueStr &meta_item); + void visit (AST::MacroMatchFragment &match) override; + void visit (AST::MacroMatchRepetition &match) override; + void visit (AST::MacroMatcher &matcher) override; + void visit (AST::MacroRulesDefinition &rules_def) override; + void visit (AST::MacroInvocation ¯o_invoc) override; + void visit (AST::MetaItemPath &meta_item) override; + void visit (AST::MetaItemSeq &meta_item) override; + void visit (AST::MetaWord &meta_item) override; + void visit (AST::MetaNameValueStr &meta_item) override; + void visit (AST::MetaListPaths &meta_item) override; + void visit (AST::MetaListNameValueStr &meta_item) override; // rust-pattern.h - void visit (AST::LiteralPattern &pattern); - void visit (AST::IdentifierPattern &pattern); - void visit (AST::WildcardPattern &pattern); - void visit (AST::RestPattern &pattern); - // void visit(RangePatternBound& bound); - void visit (AST::RangePatternBoundLiteral &bound); - void visit (AST::RangePatternBoundPath &bound); - void visit (AST::RangePatternBoundQualPath &bound); - void visit (AST::RangePattern &pattern); - void visit (AST::ReferencePattern &pattern); - // void visit(StructPatternField& field); - void visit (AST::StructPatternFieldTuplePat &field); - void visit (AST::StructPatternFieldIdentPat &field); - void visit (AST::StructPatternFieldIdent &field); - void visit (AST::StructPattern &pattern); - // void visit(TupleStructItems& tuple_items); - void visit (AST::TupleStructItemsNoRange &tuple_items); - void visit (AST::TupleStructItemsRange &tuple_items); - void visit (AST::TupleStructPattern &pattern); - // void visit(TuplePatternItems& tuple_items); - void visit (AST::TuplePatternItemsMultiple &tuple_items); - void visit (AST::TuplePatternItemsRanged &tuple_items); - void visit (AST::TuplePattern &pattern); - void visit (AST::GroupedPattern &pattern); - void visit (AST::SlicePattern &pattern); - void visit (AST::AltPattern &pattern); + void visit (AST::LiteralPattern &pattern) override; + void visit (AST::IdentifierPattern &pattern) override; + void visit (AST::WildcardPattern &pattern) override; + void visit (AST::RestPattern &pattern) override; + // void visit(RangePatternBound& bound) override; + void visit (AST::RangePatternBoundLiteral &bound) override; + void visit (AST::RangePatternBoundPath &bound) override; + void visit (AST::RangePatternBoundQualPath &bound) override; + void visit (AST::RangePattern &pattern) override; + void visit (AST::ReferencePattern &pattern) override; + // void visit(StructPatternField& field) override; + void visit (AST::StructPatternFieldTuplePat &field) override; + void visit (AST::StructPatternFieldIdentPat &field) override; + void visit (AST::StructPatternFieldIdent &field) override; + void visit (AST::StructPattern &pattern) override; + // void visit(TupleStructItems& tuple_items) override; + void visit (AST::TupleStructItemsNoRange &tuple_items) override; + void visit (AST::TupleStructItemsRange &tuple_items) override; + void visit (AST::TupleStructPattern &pattern) override; + // void visit(TuplePatternItems& tuple_items) override; + void visit (AST::TuplePatternItemsMultiple &tuple_items) override; + void visit (AST::TuplePatternItemsRanged &tuple_items) override; + void visit (AST::TuplePattern &pattern) override; + void visit (AST::GroupedPattern &pattern) override; + void visit (AST::SlicePattern &pattern) override; + void visit (AST::AltPattern &pattern) override; // rust-stmt.h - void visit (AST::EmptyStmt &stmt); - void visit (AST::LetStmt &stmt); - void visit (AST::ExprStmt &stmt); + void visit (AST::EmptyStmt &stmt) override; + void visit (AST::LetStmt &stmt) override; + void visit (AST::ExprStmt &stmt) override; // rust-type.h - void visit (AST::TraitBound &bound); - void visit (AST::ImplTraitType &type); - void visit (AST::TraitObjectType &type); - void visit (AST::ParenthesisedType &type); - void visit (AST::ImplTraitTypeOneBound &type); - void visit (AST::TraitObjectTypeOneBound &type); - void visit (AST::TupleType &type); - void visit (AST::NeverType &type); - void visit (AST::RawPointerType &type); - void visit (AST::ReferenceType &type); - void visit (AST::ArrayType &type); - void visit (AST::SliceType &type); - void visit (AST::InferredType &type); - void visit (AST::BareFunctionType &type); - void visit (AST::FunctionParam ¶m); - void visit (AST::VariadicParam ¶m); - void visit (AST::SelfParam ¶m); + void visit (AST::TraitBound &bound) override; + void visit (AST::ImplTraitType &type) override; + void visit (AST::TraitObjectType &type) override; + void visit (AST::ParenthesisedType &type) override; + void visit (AST::ImplTraitTypeOneBound &type) override; + void visit (AST::TraitObjectTypeOneBound &type) override; + void visit (AST::TupleType &type) override; + void visit (AST::NeverType &type) override; + void visit (AST::RawPointerType &type) override; + void visit (AST::ReferenceType &type) override; + void visit (AST::ArrayType &type) override; + void visit (AST::SliceType &type) override; + void visit (AST::InferredType &type) override; + void visit (AST::BareFunctionType &type) override; + void visit (AST::FunctionParam ¶m) override; + void visit (AST::VariadicParam ¶m) override; + void visit (AST::SelfParam ¶m) override; }; } // namespace Analysis From patchwork Tue Jan 30 12:07:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892854 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=FEIcVAap; 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 4TPPdc1jKSz23fD for ; Tue, 30 Jan 2024 23:30:28 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 25AD5386D600 for ; Tue, 30 Jan 2024 12:30:26 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id B9B02385802E for ; Tue, 30 Jan 2024 12:11:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9B02385802E 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 B9B02385802E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::431 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616730; cv=none; b=KCHc7Qniu/mwx5CbWaIKTrzJ1iOP+mdM/KOcx5pOxb4k7tjdYdAkvVRZfrefRTaXWnyZzGucMlok6csUlNpzvyvTBfxWlz7jVBHMjbHmD54Ne/D2+OJSKQ+l40sOpX9OzjDcYmGWCYbFO6TAwDBYapVv/EaNnTaEdMf0QANohgo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616730; c=relaxed/simple; bh=aO2H4sP6uzPGIG0NI0XWZv00SakH8GZqBduONAROSD4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=p5lrQmliBDcftYbm4GlETNHtewXRqzVbkETyErSGDhUY6cuBDDo9OuD7edspRaEs3jKOUfd2p6mc/btyJA+DAicaDglebtfDzuBMploSU0/8Zjfzj5ychIVePc8Y98lpokiD5CDmpdF4RybH2qoZVd6UvHruK5RGfyHpwqJXsQs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-33ae42033e2so2236598f8f.1 for ; Tue, 30 Jan 2024 04:11:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616694; x=1707221494; 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=YpLYrVNGo6qs0BE3pJO6Mzkut7n94ffKE+C5wY9BJSU=; b=FEIcVAapaH1ArOErP1y+n1tjGVrKBWMR0WYLeNu7AXCDTfWQ3aTOIOjFAHFhBmPtbJ Qw80UydJLXw2Mo5YnRGlKn1M0NtAHws3A2iWAER7af9JYT2yqowjB7qrn9krfSfETX2F iL8WXmyEpMHnd/dxaUh0NKknGAKE0kOgRSonFrO2w9GeohVWZ7EeVpPKBmoGcSpxzyM+ 1hh/6p9iknicqQo62pmnN34Q1TOfxAglfeXu4mWB+bPw7Ew24tjJR+T0gOpJAX6HHqye VUOIU2JXAzGr7z5lPHSqrwH1nuum/Qy3yFSKsKdDetWUn/2vAv5fjK1EtfhFPIclss8t jU7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616694; x=1707221494; 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=YpLYrVNGo6qs0BE3pJO6Mzkut7n94ffKE+C5wY9BJSU=; b=CF0PPBP4MBpGBLitLCcN0Zh1CT0uDPsoQNbjmAZEu+bPwpNxWrpXre8BVd25n8qzn8 urUcvIfD5voMv8aij721h+TZtRgGIx/LmPOPsOQHGpxj81hbkwTBdEpchfe7VviC0I8Z p+AL7qIxQqicUEbndi8vvL8ysKojvwZ87bgt5hi0+gRZG6o2Zx1sE7N/8vZq3GODY3ZN ru677eyfPvOF4wHTv5B8p5TtBYHm1/ilVKgnSxp4xXiej/QoPrbbHkd9SoDEJDkbJXrT b1h81O1w3E+EYDH3F2ar975TOlLZ5oM7bg+Kri4juwSw1BiWI6VKDTg/zXgSlAAE5JxU WZ0A== X-Gm-Message-State: AOJu0YzeeVfejuFx3nhFZ/y5XDcLtn7aWntem3WdQ7bVSGO/h+mczQ0s b/aMKR6HrJf0OSjXoK4ljhT2tcGSuKU6oP4WJLJYEN/qTf+SB7CRYja7kgOAuL7+sa1cIyPXt9T WZg== X-Google-Smtp-Source: AGHT+IFlD4ZNnL8YSgOdQEDQhM2pIdzUsLCl/fZ9/ftwsqikgctU8JX0dDR6yyCTT2iffJfkKXOiWw== X-Received: by 2002:adf:cd10:0:b0:33a:e52b:b70a with SMTP id w16-20020adfcd10000000b0033ae52bb70amr5675764wrm.52.1706616693868; Tue, 30 Jan 2024 04:11:33 -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.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:33 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 059/101] gccrs: Make early name resolver inherit from default one Date: Tue, 30 Jan 2024 13:07:15 +0100 Message-ID: <20240130121026.807464-62-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.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, 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: Pierre-Emmanuel Patry Many visit functions in the early name resolver are just plain old traversal visit functions like the ones from the default visitor. gcc/rust/ChangeLog: * resolve/rust-early-name-resolver.cc (EarlyNameResolver::resolve_generic_args): Move function. (EarlyNameResolver::resolve_qualified_path_type): Likewise. (EarlyNameResolver::visit): Add a top level visit function for crate and remove duplicated code. * resolve/rust-early-name-resolver.h (class EarlyNameResolver): Update overriden function list. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/resolve/rust-early-name-resolver.cc | 683 +------------------ gcc/rust/resolve/rust-early-name-resolver.h | 94 +-- 2 files changed, 28 insertions(+), 749 deletions(-) diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc index 38a16408436..422dd92e462 100644 --- a/gcc/rust/resolve/rust-early-name-resolver.cc +++ b/gcc/rust/resolve/rust-early-name-resolver.cc @@ -79,6 +79,31 @@ EarlyNameResolver::EarlyNameResolver () void EarlyNameResolver::go (AST::Crate &crate) +{ + visit (crate); +} + +void +EarlyNameResolver::resolve_generic_args (AST::GenericArgs &generic_args) +{ + for (auto &arg : generic_args.get_generic_args ()) + arg.accept_vis (*this); + + for (auto &arg : generic_args.get_binding_args ()) + arg.get_type ()->accept_vis (*this); +} + +void +EarlyNameResolver::resolve_qualified_path_type (AST::QualifiedPathType &path) +{ + path.get_type ()->accept_vis (*this); + + if (path.has_as_clause ()) + path.get_as_type_path ().accept_vis (*this); +} + +void +EarlyNameResolver::visit (AST::Crate &crate) { std::vector> new_items; auto items = crate.take_items (); @@ -106,29 +131,6 @@ EarlyNameResolver::go (AST::Crate &crate) }); } -void -EarlyNameResolver::resolve_generic_args (AST::GenericArgs &generic_args) -{ - for (auto &arg : generic_args.get_generic_args ()) - arg.accept_vis (*this); - - for (auto &arg : generic_args.get_binding_args ()) - arg.get_type ()->accept_vis (*this); -} - -void -EarlyNameResolver::resolve_qualified_path_type (AST::QualifiedPathType &path) -{ - path.get_type ()->accept_vis (*this); - - if (path.has_as_clause ()) - path.get_as_type_path ().accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::Token &) -{} - void EarlyNameResolver::visit (AST::DelimTokenTree &) {} @@ -141,10 +143,6 @@ void EarlyNameResolver::visit (AST::IdentifierExpr &) {} -void -EarlyNameResolver::visit (AST::Lifetime &) -{} - void EarlyNameResolver::visit (AST::LifetimeParam &) {} @@ -163,10 +161,6 @@ EarlyNameResolver::visit (AST::PathInExpression &path) resolve_generic_args (segment.get_generic_args ()); } -void -EarlyNameResolver::visit (AST::TypePathSegment &) -{} - void EarlyNameResolver::visit (AST::TypePathSegmentGeneric &segment) { @@ -174,22 +168,6 @@ EarlyNameResolver::visit (AST::TypePathSegmentGeneric &segment) resolve_generic_args (segment.get_generic_args ()); } -void -EarlyNameResolver::visit (AST::TypePathSegmentFunction &segment) -{ - for (auto &type : segment.get_type_path_function ().get_params ()) - type->accept_vis (*this); - - segment.get_type_path_function ().get_return_type ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::TypePath &path) -{ - for (auto &seg : path.get_segments ()) - seg->accept_vis (*this); -} - void EarlyNameResolver::visit (AST::QualifiedPathInExpression &path) { @@ -229,117 +207,6 @@ void EarlyNameResolver::visit (AST::MetaItemPathLit &) {} -void -EarlyNameResolver::visit (AST::BorrowExpr &expr) -{ - expr.get_borrowed_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::DereferenceExpr &expr) -{ - expr.get_dereferenced_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::ErrorPropagationExpr &expr) -{ - expr.get_propagating_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::NegationExpr &expr) -{ - expr.get_negated_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::ArithmeticOrLogicalExpr &expr) -{ - expr.get_left_expr ()->accept_vis (*this); - expr.get_right_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::ComparisonExpr &expr) -{ - expr.get_left_expr ()->accept_vis (*this); - expr.get_right_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::LazyBooleanExpr &expr) -{ - expr.get_left_expr ()->accept_vis (*this); - expr.get_right_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::TypeCastExpr &expr) -{ - expr.get_casted_expr ()->accept_vis (*this); - expr.get_type_to_cast_to ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::AssignmentExpr &expr) -{ - expr.get_left_expr ()->accept_vis (*this); - expr.get_right_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::CompoundAssignmentExpr &expr) -{ - expr.get_left_expr ()->accept_vis (*this); - expr.get_right_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::GroupedExpr &expr) -{ - expr.get_expr_in_parens ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::ArrayElemsValues &elems) -{ - for (auto &expr : elems.get_values ()) - expr->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::ArrayElemsCopied &elems) -{ - elems.get_elem_to_copy ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::ArrayExpr &expr) -{ - expr.get_array_elems ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::ArrayIndexExpr &expr) -{ - expr.get_array_expr ()->accept_vis (*this); - expr.get_index_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::TupleExpr &expr) -{ - for (auto &elem : expr.get_tuple_elems ()) - elem->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::TupleIndexExpr &expr) -{ - expr.get_tuple_expr ()->accept_vis (*this); -} - void EarlyNameResolver::visit (AST::StructExprStruct &) {} @@ -348,61 +215,10 @@ void EarlyNameResolver::visit (AST::StructExprFieldIdentifier &) {} -void -EarlyNameResolver::visit (AST::StructExprFieldIdentifierValue &field) -{ - field.get_value ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::StructExprFieldIndexValue &field) -{ - field.get_value ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::StructExprStructFields &expr) -{ - for (auto &field : expr.get_fields ()) - field->accept_vis (*this); -} - void EarlyNameResolver::visit (AST::StructExprStructBase &) {} -void -EarlyNameResolver::visit (AST::CallExpr &expr) -{ - expr.get_function_expr ()->accept_vis (*this); - for (auto ¶m : expr.get_params ()) - param->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::MethodCallExpr &expr) -{ - expr.get_receiver_expr ()->accept_vis (*this); - for (auto ¶m : expr.get_params ()) - param->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::FieldAccessExpr &expr) -{ - expr.get_receiver_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::ClosureExprInner &expr) -{ - expr.get_definition_expr ()->accept_vis (*this); - - for (auto ¶m : expr.get_params ()) - if (param.has_type_given ()) - param.get_type ()->accept_vis (*this); -} - void EarlyNameResolver::visit (AST::BlockExpr &expr) { @@ -415,95 +231,14 @@ EarlyNameResolver::visit (AST::BlockExpr &expr) }); } -void -EarlyNameResolver::visit (AST::ClosureExprInnerTyped &expr) -{ - expr.get_definition_block ()->accept_vis (*this); - - for (auto ¶m : expr.get_params ()) - param.get_type ()->accept_vis (*this); -} - void EarlyNameResolver::visit (AST::ContinueExpr &) {} -void -EarlyNameResolver::visit (AST::BreakExpr &expr) -{ - if (expr.has_break_expr ()) - expr.get_break_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::RangeFromToExpr &expr) -{ - expr.get_from_expr ()->accept_vis (*this); - expr.get_to_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::RangeFromExpr &expr) -{ - expr.get_from_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::RangeToExpr &expr) -{ - expr.get_to_expr ()->accept_vis (*this); -} - void EarlyNameResolver::visit (AST::RangeFullExpr &) {} -void -EarlyNameResolver::visit (AST::RangeFromToInclExpr &expr) -{ - expr.get_from_expr ()->accept_vis (*this); - expr.get_to_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::RangeToInclExpr &expr) -{ - expr.get_to_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::ReturnExpr &expr) -{ - if (expr.has_returned_expr ()) - expr.get_returned_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::UnsafeBlockExpr &expr) -{ - expr.get_block_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::LoopExpr &expr) -{ - expr.get_loop_block ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::WhileLoopExpr &expr) -{ - expr.get_predicate_expr ()->accept_vis (*this); - expr.get_loop_block ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::WhileLetLoopExpr &expr) -{ - expr.get_scrutinee_expr ()->accept_vis (*this); - expr.get_loop_block ()->accept_vis (*this); -} - void EarlyNameResolver::visit (AST::ForLoopExpr &expr) { @@ -514,21 +249,6 @@ EarlyNameResolver::visit (AST::ForLoopExpr &expr) }); } -void -EarlyNameResolver::visit (AST::IfExpr &expr) -{ - expr.get_condition_expr ()->accept_vis (*this); - expr.get_if_block ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::IfExprConseqElse &expr) -{ - expr.get_condition_expr ()->accept_vis (*this); - expr.get_if_block ()->accept_vis (*this); - expr.get_else_block ()->accept_vis (*this); -} - void EarlyNameResolver::visit (AST::IfLetExpr &expr) { @@ -538,14 +258,6 @@ EarlyNameResolver::visit (AST::IfLetExpr &expr) [&expr, this] () { expr.get_if_block ()->accept_vis (*this); }); } -void -EarlyNameResolver::visit (AST::IfLetExprConseqElse &expr) -{ - expr.get_value_expr ()->accept_vis (*this); - expr.get_if_block ()->accept_vis (*this); - expr.get_else_block ()->accept_vis (*this); -} - void EarlyNameResolver::visit (AST::MatchExpr &expr) { @@ -567,39 +279,10 @@ EarlyNameResolver::visit (AST::MatchExpr &expr) }); } -void -EarlyNameResolver::visit (AST::AwaitExpr &expr) -{ - expr.get_awaited_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::AsyncBlockExpr &expr) -{ - expr.get_block_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::TypeParam ¶m) -{ - for (auto &bound : param.get_type_param_bounds ()) - bound->accept_vis (*this); - - if (param.has_type ()) - param.get_type ()->accept_vis (*this); -} - void EarlyNameResolver::visit (AST::LifetimeWhereClauseItem &) {} -void -EarlyNameResolver::visit (AST::TypeBoundWhereClauseItem &item) -{ - for (auto &bound : item.get_type_param_bounds ()) - bound->accept_vis (*this); -} - void EarlyNameResolver::visit (AST::Module &module) { @@ -655,141 +338,14 @@ void EarlyNameResolver::visit (AST::UseDeclaration &) {} -void -EarlyNameResolver::visit (AST::Function &function) -{ - if (function.has_generics ()) - for (auto &generic : function.get_generic_params ()) - generic->accept_vis (*this); - - for (auto &p : function.get_function_params ()) - p->accept_vis (*this); - - if (function.has_return_type ()) - function.get_return_type ()->accept_vis (*this); - - function.get_definition ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::TypeAlias &type_alias) -{ - type_alias.get_type_aliased ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::StructStruct &struct_item) -{ - for (auto &field : struct_item.get_fields ()) - field.get_field_type ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::TupleStruct &tuple_struct) -{ - for (auto &field : tuple_struct.get_fields ()) - field.get_field_type ()->accept_vis (*this); -} - void EarlyNameResolver::visit (AST::EnumItem &) {} -void -EarlyNameResolver::visit (AST::EnumItemTuple &item) -{ - for (auto &field : item.get_tuple_fields ()) - field.get_field_type ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::EnumItemStruct &item) -{ - for (auto &field : item.get_struct_fields ()) - field.get_field_type ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::EnumItemDiscriminant &item) -{ - item.get_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::Enum &enum_item) -{ - for (auto &generic : enum_item.get_generic_params ()) - generic->accept_vis (*this); - - for (auto &variant : enum_item.get_variants ()) - variant->accept_vis (*this); -} - void EarlyNameResolver::visit (AST::Union &) {} -void -EarlyNameResolver::visit (AST::ConstantItem &const_item) -{ - const_item.get_type ()->accept_vis (*this); - if (const_item.has_expr ()) - const_item.get_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::StaticItem &static_item) -{ - static_item.get_type ()->accept_vis (*this); - static_item.get_expr ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::TraitItemFunc &item) -{ - auto &decl = item.get_trait_function_decl (); - - if (decl.has_return_type ()) - decl.get_return_type ()->accept_vis (*this); - - for (auto &generic : decl.get_generic_params ()) - generic->accept_vis (*this); - - for (auto &p : decl.get_function_params ()) - p->accept_vis (*this); - - if (item.has_definition ()) - item.get_definition ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::TraitItemMethod &item) -{ - // FIXME: Can we factor this with the above function? - auto &decl = item.get_trait_method_decl (); - - if (decl.has_return_type ()) - decl.get_return_type ()->accept_vis (*this); - - for (auto &generic : decl.get_generic_params ()) - generic->accept_vis (*this); - - for (auto &p : decl.get_function_params ()) - p->accept_vis (*this); - - if (item.has_definition ()) - item.get_definition ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::TraitItemConst &item) -{ - item.get_type ()->accept_vis (*this); - - if (item.has_expr ()) - item.get_expr ()->accept_vis (*this); -} - void EarlyNameResolver::visit (AST::TraitItemType &) {} @@ -840,26 +396,6 @@ EarlyNameResolver::visit (AST::ExternalTypeItem &item) // nothing to do? } -void -EarlyNameResolver::visit (AST::ExternalStaticItem &item) -{ - item.get_type ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::ExternalFunctionItem &item) -{ - for (auto &generic : item.get_generic_params ()) - generic->accept_vis (*this); - - for (auto ¶m : item.get_function_params ()) - if (!param.is_variadic ()) - param.get_type ()->accept_vis (*this); - - if (item.has_return_type ()) - item.get_return_type ()->accept_vis (*this); -} - void EarlyNameResolver::visit (AST::ExternBlock &block) { @@ -869,10 +405,6 @@ EarlyNameResolver::visit (AST::ExternBlock &block) }); } -void -EarlyNameResolver::visit (AST::MacroMatchFragment &) -{} - void EarlyNameResolver::visit (AST::MacroMatchRepetition &) {} @@ -991,10 +523,6 @@ void EarlyNameResolver::visit (AST::MetaItemSeq &) {} -void -EarlyNameResolver::visit (AST::MetaWord &) -{} - void EarlyNameResolver::visit (AST::MetaNameValueStr &) {} @@ -1007,25 +535,6 @@ void EarlyNameResolver::visit (AST::MetaListNameValueStr &) {} -void -EarlyNameResolver::visit (AST::LiteralPattern &) -{} - -void -EarlyNameResolver::visit (AST::IdentifierPattern &pattern) -{ - if (pattern.has_pattern_to_bind ()) - pattern.get_pattern_to_bind ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::WildcardPattern &) -{} - -void -EarlyNameResolver::visit (AST::RestPattern &) -{} - void EarlyNameResolver::visit (AST::RangePatternBoundLiteral &) {} @@ -1038,31 +547,6 @@ void EarlyNameResolver::visit (AST::RangePatternBoundQualPath &) {} -void -EarlyNameResolver::visit (AST::RangePattern &pattern) -{ - pattern.get_lower_bound ()->accept_vis (*this); - pattern.get_upper_bound ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::ReferencePattern &pattern) -{ - pattern.get_referenced_pattern ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::StructPatternFieldTuplePat &field) -{ - field.get_index_pattern ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::StructPatternFieldIdentPat &field) -{ - field.get_ident_pattern ()->accept_vis (*this); -} - void EarlyNameResolver::visit (AST::StructPatternFieldIdent &) {} @@ -1071,22 +555,6 @@ void EarlyNameResolver::visit (AST::StructPattern &) {} -void -EarlyNameResolver::visit (AST::TupleStructItemsNoRange &tuple_items) -{ - for (auto &pattern : tuple_items.get_patterns ()) - pattern->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::TupleStructItemsRange &tuple_items) -{ - for (auto &pattern : tuple_items.get_lower_patterns ()) - pattern->accept_vis (*this); - for (auto &pattern : tuple_items.get_upper_patterns ()) - pattern->accept_vis (*this); -} - void EarlyNameResolver::visit (AST::TupleStructPattern &pattern) { @@ -1103,70 +571,6 @@ EarlyNameResolver::visit (AST::TupleStructPattern &pattern) pattern.get_items ()->accept_vis (*this); } -void -EarlyNameResolver::visit (AST::TuplePatternItemsMultiple &tuple_items) -{ - for (auto &pattern : tuple_items.get_patterns ()) - pattern->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::TuplePatternItemsRanged &tuple_items) -{ - for (auto &pattern : tuple_items.get_lower_patterns ()) - pattern->accept_vis (*this); - for (auto &pattern : tuple_items.get_upper_patterns ()) - pattern->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::TuplePattern &pattern) -{ - pattern.get_items ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::GroupedPattern &pattern) -{ - pattern.get_pattern_in_parens ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::SlicePattern &pattern) -{ - for (auto &item : pattern.get_items ()) - item->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::AltPattern &pattern) -{ - for (auto &alt : pattern.get_alts ()) - alt->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::EmptyStmt &) -{} - -void -EarlyNameResolver::visit (AST::LetStmt &stmt) -{ - if (stmt.has_type ()) - stmt.get_type ()->accept_vis (*this); - - if (stmt.has_init_expr ()) - stmt.get_init_expr ()->accept_vis (*this); - - stmt.get_pattern ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::ExprStmt &stmt) -{ - stmt.get_expr ()->accept_vis (*this); -} - void EarlyNameResolver::visit (AST::TraitBound &) {} @@ -1195,10 +599,6 @@ void EarlyNameResolver::visit (AST::TupleType &) {} -void -EarlyNameResolver::visit (AST::NeverType &) -{} - void EarlyNameResolver::visit (AST::RawPointerType &) {} @@ -1219,38 +619,5 @@ void EarlyNameResolver::visit (AST::InferredType &) {} -void -EarlyNameResolver::visit (AST::BareFunctionType &type) -{ - for (auto ¶m : type.get_function_params ()) - param.get_type ()->accept_vis (*this); - - if (type.has_return_type ()) - type.get_return_type ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::VariadicParam ¶m) -{ - if (param.has_pattern ()) - param.get_pattern ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::FunctionParam ¶m) -{ - param.get_pattern ()->accept_vis (*this); - param.get_type ()->accept_vis (*this); -} - -void -EarlyNameResolver::visit (AST::SelfParam ¶m) -{ - if (param.has_type ()) - param.get_type ()->accept_vis (*this); - if (param.has_lifetime ()) - param.get_lifetime ().accept_vis (*this); -} - } // namespace Resolver } // namespace Rust diff --git a/gcc/rust/resolve/rust-early-name-resolver.h b/gcc/rust/resolve/rust-early-name-resolver.h index cebc6e4b5af..bf62ec15ffb 100644 --- a/gcc/rust/resolve/rust-early-name-resolver.h +++ b/gcc/rust/resolve/rust-early-name-resolver.h @@ -27,7 +27,7 @@ namespace Rust { namespace Resolver { -class EarlyNameResolver : public AST::ASTVisitor +class EarlyNameResolver : public AST::DefaultASTVisitor { public: EarlyNameResolver (); @@ -35,6 +35,7 @@ public: void go (AST::Crate &crate); private: + using AST::DefaultASTVisitor::visit; /** * Execute a lambda within a scope. This is equivalent to calling * `enter_scope` before your code and `exit_scope` after. This ensures @@ -126,18 +127,14 @@ private: */ void resolve_qualified_path_type (AST::QualifiedPathType &path); - virtual void visit (AST::Token &tok); + virtual void visit (AST::Crate &crate); virtual void visit (AST::DelimTokenTree &delim_tok_tree); virtual void visit (AST::AttrInputMetaItemContainer &input); virtual void visit (AST::IdentifierExpr &ident_expr); - virtual void visit (AST::Lifetime &lifetime); virtual void visit (AST::LifetimeParam &lifetime_param); virtual void visit (AST::ConstGenericParam &const_param); virtual void visit (AST::PathInExpression &path); - virtual void visit (AST::TypePathSegment &segment); virtual void visit (AST::TypePathSegmentGeneric &segment); - virtual void visit (AST::TypePathSegmentFunction &segment); - virtual void visit (AST::TypePath &path); virtual void visit (AST::QualifiedPathInExpression &path); virtual void visit (AST::QualifiedPathInType &path); virtual void visit (AST::LiteralExpr &expr); @@ -145,124 +142,45 @@ private: virtual void visit (AST::AttrInputMacro &attr_input); virtual void visit (AST::MetaItemLitExpr &meta_item); virtual void visit (AST::MetaItemPathLit &meta_item); - virtual void visit (AST::BorrowExpr &expr); - virtual void visit (AST::DereferenceExpr &expr); - virtual void visit (AST::ErrorPropagationExpr &expr); - virtual void visit (AST::NegationExpr &expr); - virtual void visit (AST::ArithmeticOrLogicalExpr &expr); - virtual void visit (AST::ComparisonExpr &expr); - virtual void visit (AST::LazyBooleanExpr &expr); - virtual void visit (AST::TypeCastExpr &expr); - virtual void visit (AST::AssignmentExpr &expr); - virtual void visit (AST::CompoundAssignmentExpr &expr); - virtual void visit (AST::GroupedExpr &expr); - virtual void visit (AST::ArrayElemsValues &elems); - virtual void visit (AST::ArrayElemsCopied &elems); - virtual void visit (AST::ArrayExpr &expr); - virtual void visit (AST::ArrayIndexExpr &expr); - virtual void visit (AST::TupleExpr &expr); - virtual void visit (AST::TupleIndexExpr &expr); virtual void visit (AST::StructExprStruct &expr); virtual void visit (AST::StructExprFieldIdentifier &field); - virtual void visit (AST::StructExprFieldIdentifierValue &field); - virtual void visit (AST::StructExprFieldIndexValue &field); - virtual void visit (AST::StructExprStructFields &expr); virtual void visit (AST::StructExprStructBase &expr); - virtual void visit (AST::CallExpr &expr); - virtual void visit (AST::MethodCallExpr &expr); - virtual void visit (AST::FieldAccessExpr &expr); - virtual void visit (AST::ClosureExprInner &expr); virtual void visit (AST::BlockExpr &expr); - virtual void visit (AST::ClosureExprInnerTyped &expr); virtual void visit (AST::ContinueExpr &expr); - virtual void visit (AST::BreakExpr &expr); - virtual void visit (AST::RangeFromToExpr &expr); - virtual void visit (AST::RangeFromExpr &expr); - virtual void visit (AST::RangeToExpr &expr); virtual void visit (AST::RangeFullExpr &expr); - virtual void visit (AST::RangeFromToInclExpr &expr); - virtual void visit (AST::RangeToInclExpr &expr); - virtual void visit (AST::ReturnExpr &expr); - virtual void visit (AST::UnsafeBlockExpr &expr); - virtual void visit (AST::LoopExpr &expr); - virtual void visit (AST::WhileLoopExpr &expr); - virtual void visit (AST::WhileLetLoopExpr &expr); virtual void visit (AST::ForLoopExpr &expr); - virtual void visit (AST::IfExpr &expr); - virtual void visit (AST::IfExprConseqElse &expr); virtual void visit (AST::IfLetExpr &expr); - virtual void visit (AST::IfLetExprConseqElse &expr); virtual void visit (AST::MatchExpr &expr); - virtual void visit (AST::AwaitExpr &expr); - virtual void visit (AST::AsyncBlockExpr &expr); - virtual void visit (AST::TypeParam ¶m); virtual void visit (AST::LifetimeWhereClauseItem &item); - virtual void visit (AST::TypeBoundWhereClauseItem &item); virtual void visit (AST::Module &module); virtual void visit (AST::ExternCrate &crate); virtual void visit (AST::UseTreeGlob &use_tree); virtual void visit (AST::UseTreeList &use_tree); virtual void visit (AST::UseTreeRebind &use_tree); virtual void visit (AST::UseDeclaration &use_decl); - virtual void visit (AST::Function &function); - virtual void visit (AST::TypeAlias &type_alias); - virtual void visit (AST::StructStruct &struct_item); - virtual void visit (AST::TupleStruct &tuple_struct); virtual void visit (AST::EnumItem &item); - virtual void visit (AST::EnumItemTuple &item); - virtual void visit (AST::EnumItemStruct &item); - virtual void visit (AST::EnumItemDiscriminant &item); - virtual void visit (AST::Enum &enum_item); virtual void visit (AST::Union &union_item); - virtual void visit (AST::ConstantItem &const_item); - virtual void visit (AST::StaticItem &static_item); - virtual void visit (AST::TraitItemFunc &item); - virtual void visit (AST::TraitItemMethod &item); - virtual void visit (AST::TraitItemConst &item); virtual void visit (AST::TraitItemType &item); virtual void visit (AST::Trait &trait); virtual void visit (AST::InherentImpl &impl); virtual void visit (AST::TraitImpl &impl); virtual void visit (AST::ExternalTypeItem &item); - virtual void visit (AST::ExternalStaticItem &item); - virtual void visit (AST::ExternalFunctionItem &item); virtual void visit (AST::ExternBlock &block); - virtual void visit (AST::MacroMatchFragment &match); virtual void visit (AST::MacroMatchRepetition &match); virtual void visit (AST::MacroMatcher &matcher); virtual void visit (AST::MacroRulesDefinition &rules_def); virtual void visit (AST::MacroInvocation ¯o_invoc); virtual void visit (AST::MetaItemPath &meta_item); virtual void visit (AST::MetaItemSeq &meta_item); - virtual void visit (AST::MetaWord &meta_item); virtual void visit (AST::MetaNameValueStr &meta_item); virtual void visit (AST::MetaListPaths &meta_item); virtual void visit (AST::MetaListNameValueStr &meta_item); - virtual void visit (AST::LiteralPattern &pattern); - virtual void visit (AST::IdentifierPattern &pattern); - virtual void visit (AST::WildcardPattern &pattern); - virtual void visit (AST::RestPattern &pattern); virtual void visit (AST::RangePatternBoundLiteral &bound); virtual void visit (AST::RangePatternBoundPath &bound); virtual void visit (AST::RangePatternBoundQualPath &bound); - virtual void visit (AST::RangePattern &pattern); - virtual void visit (AST::ReferencePattern &pattern); - virtual void visit (AST::StructPatternFieldTuplePat &field); - virtual void visit (AST::StructPatternFieldIdentPat &field); virtual void visit (AST::StructPatternFieldIdent &field); virtual void visit (AST::StructPattern &pattern); - virtual void visit (AST::TupleStructItemsNoRange &tuple_items); - virtual void visit (AST::TupleStructItemsRange &tuple_items); virtual void visit (AST::TupleStructPattern &pattern); - virtual void visit (AST::TuplePatternItemsMultiple &tuple_items); - virtual void visit (AST::TuplePatternItemsRanged &tuple_items); - virtual void visit (AST::TuplePattern &pattern); - virtual void visit (AST::GroupedPattern &pattern); - virtual void visit (AST::SlicePattern &pattern); - virtual void visit (AST::AltPattern &pattern); - virtual void visit (AST::EmptyStmt &stmt); - virtual void visit (AST::LetStmt &stmt); - virtual void visit (AST::ExprStmt &stmt); virtual void visit (AST::TraitBound &bound); virtual void visit (AST::ImplTraitType &type); virtual void visit (AST::TraitObjectType &type); @@ -270,17 +188,11 @@ private: virtual void visit (AST::ImplTraitTypeOneBound &type); virtual void visit (AST::TraitObjectTypeOneBound &type); virtual void visit (AST::TupleType &type); - virtual void visit (AST::NeverType &type); virtual void visit (AST::RawPointerType &type); virtual void visit (AST::ReferenceType &type); virtual void visit (AST::ArrayType &type); virtual void visit (AST::SliceType &type); virtual void visit (AST::InferredType &type); - virtual void visit (AST::BareFunctionType &type); - - virtual void visit (AST::VariadicParam &type); - virtual void visit (AST::FunctionParam &type); - virtual void visit (AST::SelfParam &type); }; } // namespace Resolver From patchwork Tue Jan 30 12:07:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892872 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=XqQ3tswT; 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 4TPPkq4hlgz23fD for ; Tue, 30 Jan 2024 23:34:59 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8E50A3838A20 for ; Tue, 30 Jan 2024 12:34:57 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 9366C385802D for ; Tue, 30 Jan 2024 12:11:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9366C385802D 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 9366C385802D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616727; cv=none; b=WFebNWPIjrA8jRwMp3cLXOSNbAghfjTMD5st9L2KwvW3tKtur6hIFY1x8DvULJiBgndqW8Ns6tII/taMaMNuRsBlHhZpqxKcm8JtvvF3A9fx46tWXhzLGUeZuy6Z6YS/a5b+NNUKGgOaIckVf7y/y+uvCqaaZxsUq7pqaN+/mEw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616727; c=relaxed/simple; bh=KtxSWAupXIJSiOQPyfK6qIHYKG6VKrbVS0bGq/fgqjg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=JRz52FlDEYeF5rvxvQy50f/wA8eD73lSbsmI80EuT6YOh8ZixEU6lT8RNC2tEsjIlTGi2wowXxH6+MzYSI9w9MMrD5LvEiZWlw/clf4VPVXn4bCGbZ8SE3l/3cVj2Q4lZ20Wisc6/iGznuK9tsjHg3HkbIwEX+Uatj9OpeRmp/A= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-33ae5e7d787so2238085f8f.1 for ; Tue, 30 Jan 2024 04:11:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616694; x=1707221494; 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=9QxpTEozgH686BVLd/cOLpok6UD5ZCckfCIErw2PR8k=; b=XqQ3tswTSs5IHCePfIgl0L+E9imRxdBKpH7i6c4qWEhogtQgwL7InoWc/1m27N4iUu 49OMFLyjNzIZ19erPpwUZ5zNCFVyYnLJR+HsbWQ1NiI/2PG5nZ7pkkx1xuV9iM7UhcQc kSMSmSMNtnE2u/8MrrvfrWFqlUX5inaiPwDme/VVmqckpYoNAaKhd6iO6BmCGPMqPD60 mgQRszSMe3Aj1hrQNDff1OKQOfkx1tsg0b6xQJ9LeYLtlOYOjo0qvNPDPVJOk74A36JW +/sTB69odyyYSG5N1zmtstEtp8BUfZ71jJvUbhJqBXqg8BT6qVaYrCpChQVHQkE0d+a1 h9LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616694; x=1707221494; 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=9QxpTEozgH686BVLd/cOLpok6UD5ZCckfCIErw2PR8k=; b=Vhxg4aR+L+ZxsZuGiy9TKpVbuV6PnjSbCLH6QrLIRMA5tfVsqvIsOmoLd3AjorTdRY 9MH6C8WQmxHVSohPbNvsH61XcX77p/jCnR2ec3KWLumOOe0VTSZ30BEPhvLQ2Ps8ACBp 1XdwWjVG6EYO2gcz2xr1u6XD5JiCQEvtoiTAsgfHzv/0W/03xivTBCcktHH57MlHuMA4 8VjJQhAd0u8Dgo3FqjvkpBM6JxhqAKkscg9UOiC/6Ca7DjQUEdcR9wOssOEdOKOxgvmX nwJ45Vb06ipEz/4N/MolUpTjy1xON3pzVaiTC5ltub0KySNJmZc0wkC24n6Ifc2/3C/F rgKw== X-Gm-Message-State: AOJu0Yx9WxUvus0KgJldsQc4siYG3E5a7VJzUIJ+Ck2vG0KbK/tOBXdQ Q7ew+FA0mH2BOTMfiN5ivrUmAFKzwR+NhJdSHa7a6r/CeNLxuBftWfTsbxa3Ay1j2tjk4URAMF8 Mog== X-Google-Smtp-Source: AGHT+IFDoxa6SH0fHuwDXCuGH1of60biPcO2gLnH6JsRSVFhfryzdzy8E/NhoVgaRD9c4ygtaaFgMg== X-Received: by 2002:a5d:548b:0:b0:33a:fe1f:4ba6 with SMTP id h11-20020a5d548b000000b0033afe1f4ba6mr348108wrv.25.1706616694546; Tue, 30 Jan 2024 04:11:34 -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.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:34 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 060/101] gccrs: Add multiple regression test in name resolution Date: Tue, 30 Jan 2024 13:07:16 +0100 Message-ID: <20240130121026.807464-63-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.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, 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: Pierre-Emmanuel Patry Local variables and functions or global variables have different resolution when binded to a variable. This was not covered before, even though it was handled by the new name resolution. This commit highlight this behavior from the new name resolution mechanism. gcc/testsuite/ChangeLog: * rust/compile/name_resolution11.rs: New test. * rust/compile/name_resolution12.rs: New test. * rust/compile/name_resolution13.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- gcc/testsuite/rust/compile/name_resolution11.rs | 7 +++++++ gcc/testsuite/rust/compile/name_resolution12.rs | 10 ++++++++++ gcc/testsuite/rust/compile/name_resolution13.rs | 9 +++++++++ 3 files changed, 26 insertions(+) create mode 100644 gcc/testsuite/rust/compile/name_resolution11.rs create mode 100644 gcc/testsuite/rust/compile/name_resolution12.rs create mode 100644 gcc/testsuite/rust/compile/name_resolution13.rs diff --git a/gcc/testsuite/rust/compile/name_resolution11.rs b/gcc/testsuite/rust/compile/name_resolution11.rs new file mode 100644 index 00000000000..a464d2a0fd3 --- /dev/null +++ b/gcc/testsuite/rust/compile/name_resolution11.rs @@ -0,0 +1,7 @@ +// { dg-additional-options "-frust-name-resolution-2.0 -frust-compile-until=lowering" } +fn foo() { + let b = 10; + fn bar() { + let a = foo; + } +} diff --git a/gcc/testsuite/rust/compile/name_resolution12.rs b/gcc/testsuite/rust/compile/name_resolution12.rs new file mode 100644 index 00000000000..9cce31ceb5c --- /dev/null +++ b/gcc/testsuite/rust/compile/name_resolution12.rs @@ -0,0 +1,10 @@ +// { dg-additional-options "-frust-name-resolution-2.0 -frust-compile-until=lowering" } + +const TOTO: i32 = 10; + +fn foo() { + let b = 10; + fn bar() { + let e = TOTO; + } +} diff --git a/gcc/testsuite/rust/compile/name_resolution13.rs b/gcc/testsuite/rust/compile/name_resolution13.rs new file mode 100644 index 00000000000..52a152bf51a --- /dev/null +++ b/gcc/testsuite/rust/compile/name_resolution13.rs @@ -0,0 +1,9 @@ +// { dg-additional-options "-frust-name-resolution-2.0 -frust-compile-until=lowering" } + +fn foo() { + let b = 10; + fn bar() { + let c = b; + // { dg-error "cannot find value .b. in this scope .E0425." "" { target *-*-* } .-1 } + } +} From patchwork Tue Jan 30 12:07:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892848 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=fgTejVix; 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 4TPPbX2jjbz23gZ for ; Tue, 30 Jan 2024 23:28:40 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 512313861870 for ; Tue, 30 Jan 2024 12:28:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 535FC3857C72 for ; Tue, 30 Jan 2024 12:11:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 535FC3857C72 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 535FC3857C72 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616727; cv=none; b=w90IxPAN+s3CiJeJzxEK/hRhvYEaHi4hJ6OK/13Nxa5c/oYQgI7ILDwYQFmvYcZWjkjx/LhMSwtIllvq3nFOK2KSPB078CdUpfzJdr+AHexuLupR2lk8MnG6lPMBh/zht6ux1GC9m8ZyS+JGxbH1KLiWy4kVXmpJbc782bMVdlM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616727; c=relaxed/simple; bh=Y5qkHh5jh9NgYb5AKVtFtUUucPySOMeLv/Q6vtpE9zQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=uD6W/zyniXNOOJtdJe/xrenH/vz1eBk4h71Z+H0AUsWfSbB+JZ8xAAKJXFtXDEz/W9xsJQk1hNXnKSv7fKsGRmDDw7WdDc//f/5U3nupBz+1vCd24XQHY99lG61fvK3vJXi2ichhes3fBGlyclQAppd6TTRyMA3R4YlfntXj4j0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-33aef64f702so1046917f8f.3 for ; Tue, 30 Jan 2024 04:11:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616695; x=1707221495; 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=NRqFV56hw77hRj3Vc9d6CkW4HL1dZuf6cyuqoZHuZLQ=; b=fgTejVixk7wK7VwFJBAeyf6TvKHnsBtRlF/1hwbDRYVLvHfXnPQLHflFxBRZlNEfzQ At9S05rM8mUGQYMh8JjYssiW05OVYxMYC41bqWFIOsGAG2KZqHRRe97gbBoAqpPwjAMJ psf3d07E4VF89S87zincjXhn2XSIKi5WdFUJaphRXP7ddL650wxDK+7lshjw5op5piC+ ObnLTgGfCZFzYc+StrVgpwWxR9Rd7vgHQt0pw0eBQQAj6sra48B7MD8or6EnN/C4fILX vaWIkfJMTHE2xhqmxgNvmemK2aftMt/7PZT65bqh6KZFZF6oJaTP7wP/1fPtOz1inbSg kx+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616695; x=1707221495; 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=NRqFV56hw77hRj3Vc9d6CkW4HL1dZuf6cyuqoZHuZLQ=; b=ryaC97Y8Ywsnr2sOz5+RJ0/OPTybTtB+wXF9imtEfL0BzLouNHDyztMEc5PaRAIV0f a/UwRcyAE1zNu28XctPVQosBaOU1iyGxog3NVxyadcth5dSW/UiW1vHKk2Tm+VNPtG9F gnmCEQqgtGhdtstjEALOsofDsVRxRgYOnsPHBJf7o5u8AUppVv4wg06fcWPMWelobnQJ 3dS3qkzClwr4ir/jyhW+7zl2bH0hsF68eATdlB+321LMCBBPxEjVe2V7iQl++v9Yyxy7 eR9aU7faByI7F0bmrRzpJBcCQTwlwUU91mPSBapeTMbodbsjKMZp6TaxAK3OIBf6o2DT IJZQ== X-Gm-Message-State: AOJu0YwKObMyAMj3pN6sCf1p4X+yq7ZQ4Kwb4GF7MAmjOLvquDCHcZzr zxxfEq43Z8Wo76JNZQBhlRqLKOGBDp7/6L6CYJ2aRdc7Nrd46XVlrJCkmhgVM3Osc4hPif8xj2d GJA== X-Google-Smtp-Source: AGHT+IGtiiAR0bM2mwPYdn1hN336nVlQhzEOzxarTCi+kD37xlax6tzN6NIi+AhqxfQz1v9CHEkBiA== X-Received: by 2002:adf:f34f:0:b0:33a:e672:a1e4 with SMTP id e15-20020adff34f000000b0033ae672a1e4mr5621499wrp.5.1706616695470; Tue, 30 Jan 2024 04:11:35 -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.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:34 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 061/101] gccrs: Add execution test for name resolution 2.0 Date: Tue, 30 Jan 2024 13:07:17 +0100 Message-ID: <20240130121026.807464-64-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=-13.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, 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: Pierre-Emmanuel Patry We already have some compile tests but it lacked an execution test to ensure everything compiles correctly to the correct value. gcc/testsuite/ChangeLog: * rust/execute/torture/name_resolution.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- .../rust/execute/torture/name_resolution.rs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 gcc/testsuite/rust/execute/torture/name_resolution.rs diff --git a/gcc/testsuite/rust/execute/torture/name_resolution.rs b/gcc/testsuite/rust/execute/torture/name_resolution.rs new file mode 100644 index 00000000000..749218352d6 --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/name_resolution.rs @@ -0,0 +1,24 @@ +// { dg-additional-options "-frust-name-resolution-2.0" } +// { dg-output "Value is 10\r*\n" } + +const BAZ: i32 = 10; + +extern "C" { + fn printf(s: *const i8, ...); +} + +fn foo() { + fn bar() { + let e = BAZ; + unsafe { + printf("Value is %i\n" as *const str as *const i8, e); + } + } + + bar(); +} + +fn main() -> i32 { + foo(); + 0 +} From patchwork Tue Jan 30 12:07:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892863 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=K7UJmHo+; 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 4TPPgX6PW0z23fD for ; Tue, 30 Jan 2024 23:32:08 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D6D49386F432 for ; Tue, 30 Jan 2024 12:32:06 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id AA5FE3857B83 for ; Tue, 30 Jan 2024 12:11:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AA5FE3857B83 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 AA5FE3857B83 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616735; cv=none; b=C730tOnKK9ycFGsOi6UopdCxYSjlHJr8YnMT+7ODipLjyWlYADzFU69Qx9/ooWimi6YLBazgzl2onCvS304tVZDGKlg5d9KSQDZqu7jhJUrDthWhkTzgEt/NyftbLmbABF98lXtDqa+H8H0iuwHTMysulwA5AuAXFemdvfxzMC4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616735; c=relaxed/simple; bh=K3O0XWr4vho+6n/DB5PEktfoM4VgaNBAr3FnitrdPKg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TCG73eglZ5cWlRG80nPTPMc4y0LEaOiqYr06SMdYi2AmvdNFFn5rYDsGe2YMA8a7USJfF5JFQysgmIya7s5pL6QpoSMKllTSFAXmkbH0SjWcQ+OrOLFk0ZQoJRIuA+60V0P8CSBb0zyBbJL/gYMIzfK/BobY7+bnsrRa8VZX9dk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-33ae4205ad8so2009423f8f.2 for ; Tue, 30 Jan 2024 04:11:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616696; x=1707221496; 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=3EkNSh0m0U1J8MQDp6z2G26r1f5+x3wHw7ItH4T4/Nw=; b=K7UJmHo+9/FtpfDUfuMwtrKHpSYMJj9BXVZgIr0IRQVSpg59La4bLAbljz6HjRInFX zjkozK2VarX1vHIX8BgBVooXndqxrxuRnHkijv8NAuiXlRkE9eUv5hofiBo2BTBKesN+ PVifUkviK14ceFzwp/3H3z2EiJjWstNhu0g/KHnt/IkEOxywytYx0mNMLdcNP0kng/vw O15r0R8iu7IRBm3llYifUSTRS+1aNI0Rv49gCZoNuEn0+TR4fSWpSlRaZJ6BHCd24sRY enjdDCMUTw8T1tnDmidXHUuEb+PXjxIg4FAu8MyOHKM+MKZnt3cavAr9Wp9HFRXsIsPs PzPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616696; x=1707221496; 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=3EkNSh0m0U1J8MQDp6z2G26r1f5+x3wHw7ItH4T4/Nw=; b=EcMnDMfnjEwlbBdlt/s3TyOby7bfImPqCGPNGKrXiDZgR7W5/30GbJTRFCxAXOrQbY hcjsR0jf0ilRlvIGSfFJPe3AGPi50eb1vIEmgeddLbTnABeB4/r1ryVF9knrHet+I+hB C4GU8ASdq8WWuArhS0nVmPWE4ZvQ1J+sdgHwyjP8WCT5yIJ2htihYQPqfSsARAtgsCrH GxttQ9sXPkFzR6eqVBnNrVx9Pixh4qQfRc9Pm1akSPfY+WdqWpNGNQSIf9JcWSnnsNmv JxCsvuIidwTnCIcOC/eT7qcOFPJoxMnnwhRNBM+ZTP7yelG69agECdSW2KiWkJBhsJYp ZMDA== X-Gm-Message-State: AOJu0Yy4JITfAqYMNWtL6TkNgUvDI16s2WnDZvlWFyj2U1+LiXh+CxYJ SmQdfkLHjDFJesuM2QNkvifF3j/869h/CEnqMM7eENWjAJ6kCWUPnogpPyyHQnbHJ81888p5Ab5 qRQ== X-Google-Smtp-Source: AGHT+IFVurQ0sSqraQJgJzQz3JScksFdn6lEfRRhXZ622Gb9B+uWJPNp3T5wS2Dw9X1ywKnC3E69YA== X-Received: by 2002:a5d:6d82:0:b0:337:33a:c880 with SMTP id l2-20020a5d6d82000000b00337033ac880mr4465350wrs.26.1706616696138; Tue, 30 Jan 2024 04:11:36 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:35 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 062/101] gccrs: Make function bodies truly optional Date: Tue, 30 Jan 2024 13:07:18 +0100 Message-ID: <20240130121026.807464-65-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.2 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, 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: Pierre-Emmanuel Patry Missing body on a function should be rejected at a later stage in the compiler, not during parsing. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Adapt defintion getter. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * hir/rust-ast-lower-implitem.h: Likewise. * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise. * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Likewise. * resolve/rust-ast-resolve-stmt.h: Likewise. * resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise. * util/rust-attributes.cc (AttributeChecker::visit): Likewise. * parse/rust-parse-impl.h: Allow empty function body during parsing. * ast/rust-ast.cc (Function::Function): Constructor now take an optional for the body. (Function::operator=): Adapt to new optional member. (Function::as_string): Likewise. * ast/rust-item.h (class Function): Make body optional and do not rely on nullptr anymore. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/ast/rust-ast-collector.cc | 7 +- gcc/rust/ast/rust-ast-visitor.cc | 3 +- gcc/rust/ast/rust-ast.cc | 24 +++-- gcc/rust/ast/rust-item.h | 13 +-- gcc/rust/expand/rust-cfg-strip.cc | 16 ++-- gcc/rust/expand/rust-expand-visitor.cc | 8 +- gcc/rust/hir/rust-ast-lower-implitem.h | 2 +- gcc/rust/hir/rust-ast-lower-item.cc | 2 +- gcc/rust/parse/rust-parse-impl.h | 105 ++++++++++------------ gcc/rust/resolve/rust-ast-resolve-item.cc | 2 +- gcc/rust/resolve/rust-ast-resolve-stmt.h | 2 +- gcc/rust/resolve/rust-default-resolver.cc | 3 +- gcc/rust/util/rust-attributes.cc | 3 +- 13 files changed, 92 insertions(+), 98 deletions(-) diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc index 647724bec11..d5a98f1ccc7 100644 --- a/gcc/rust/ast/rust-ast-collector.cc +++ b/gcc/rust/ast/rust-ast-collector.cc @@ -1730,11 +1730,10 @@ TokenCollector::visit (Function &function) if (function.has_where_clause ()) visit (function.get_where_clause ()); - auto &block = function.get_definition (); - if (!block) - push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION)); + if (function.has_body ()) + visit (*function.get_definition ()); else - visit (block); + push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION)); newline (); } diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc index 4ec5c7cf1d0..230a152b05b 100644 --- a/gcc/rust/ast/rust-ast-visitor.cc +++ b/gcc/rust/ast/rust-ast-visitor.cc @@ -777,7 +777,8 @@ DefaultASTVisitor::visit (AST::Function &function) if (function.has_return_type ()) visit (function.get_return_type ()); visit (function.get_where_clause ()); - visit (function.get_definition ()); + if (function.has_body ()) + visit (*function.get_definition ()); } void diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 607f07955d4..b9096032d41 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -18,6 +18,7 @@ along with GCC; see the file COPYING3. If not see . */ #include "rust-ast.h" +#include "optional.h" #include "rust-system.h" #include "rust-ast-full.h" #include "rust-diagnostics.h" @@ -1100,8 +1101,10 @@ Function::Function (Function const &other) return_type = other.return_type->clone_type (); // guard to prevent null dereference (only required if error state) - if (other.function_body != nullptr) - function_body = other.function_body->clone_block_expr (); + if (other.has_body ()) + function_body = other.function_body.value ()->clone_block_expr (); + else + function_body = tl::nullopt; generic_params.reserve (other.generic_params.size ()); for (const auto &e : other.generic_params) @@ -1131,10 +1134,10 @@ Function::operator= (Function const &other) return_type = nullptr; // guard to prevent null dereference (only required if error state) - if (other.function_body != nullptr) - function_body = other.function_body->clone_block_expr (); + if (other.has_body ()) + function_body = other.function_body.value ()->clone_block_expr (); else - function_body = nullptr; + function_body = tl::nullopt; generic_params.reserve (other.generic_params.size ()); for (const auto &e : other.generic_params) @@ -1221,15 +1224,8 @@ Function::as_string () const str += "\n"; - // DEBUG: null pointer check - if (function_body == nullptr) - { - rust_debug ( - "something really terrible has gone wrong - null pointer function " - "body in function."); - return "NULL_POINTER_MARK"; - } - str += function_body->as_string () + "\n"; + if (has_body ()) + str += function_body.value ()->as_string () + "\n"; return str; } diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 9a83f3d5981..a995273de12 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -1299,7 +1299,7 @@ class Function : public VisItem, std::vector> function_params; std::unique_ptr return_type; WhereClause where_clause; - std::unique_ptr function_body; + tl::optional> function_body; location_t locus; bool is_default; @@ -1323,14 +1323,16 @@ public: return function_params.size () > 0 && function_params[0]->is_self (); } + bool has_body () const { return function_body.has_value (); } + // Mega-constructor with all possible fields Function (Identifier function_name, FunctionQualifiers qualifiers, std::vector> generic_params, std::vector> function_params, std::unique_ptr return_type, WhereClause where_clause, - std::unique_ptr function_body, Visibility vis, - std::vector outer_attrs, location_t locus, - bool is_default = false) + tl::optional> function_body, + Visibility vis, std::vector outer_attrs, + location_t locus, bool is_default = false) : VisItem (std::move (vis), std::move (outer_attrs)), qualifiers (std::move (qualifiers)), function_name (std::move (function_name)), @@ -1390,9 +1392,8 @@ public: } // TODO: is this better? Or is a "vis_block" better? - std::unique_ptr &get_definition () + tl::optional> &get_definition () { - rust_assert (function_body != nullptr); return function_body; } diff --git a/gcc/rust/expand/rust-cfg-strip.cc b/gcc/rust/expand/rust-cfg-strip.cc index fd115654618..089520182ac 100644 --- a/gcc/rust/expand/rust-cfg-strip.cc +++ b/gcc/rust/expand/rust-cfg-strip.cc @@ -2031,13 +2031,17 @@ CfgStrip::visit (AST::Function &function) /* body should always exist - if error state, should have returned * before now */ // can't strip block itself, but can strip sub-expressions - auto &block_expr = function.get_definition (); - block_expr->accept_vis (*this); - if (block_expr->is_marked_for_strip ()) - rust_error_at (block_expr->get_locus (), - "cannot strip block expression in this position - outer " - "attributes not allowed"); + if (function.has_body ()) + { + auto &block_expr = function.get_definition ().value (); + block_expr->accept_vis (*this); + if (block_expr->is_marked_for_strip ()) + rust_error_at (block_expr->get_locus (), + "cannot strip block expression in this position - outer " + "attributes not allowed"); + } } + void CfgStrip::visit (AST::TypeAlias &type_alias) { diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc index 1745af06174..ad473c2dcb0 100644 --- a/gcc/rust/expand/rust-expand-visitor.cc +++ b/gcc/rust/expand/rust-expand-visitor.cc @@ -1001,8 +1001,9 @@ ExpandVisitor::visit (AST::UseDeclaration &use_decl) void ExpandVisitor::visit (AST::Function &function) { - visit_inner_using_attrs (function, - function.get_definition ()->get_inner_attrs ()); + if (function.has_body ()) + visit_inner_using_attrs ( + function, function.get_definition ().value ()->get_inner_attrs ()); for (auto ¶m : function.get_generic_params ()) visit (param); @@ -1014,7 +1015,8 @@ ExpandVisitor::visit (AST::Function &function) if (function.has_where_clause ()) expand_where_clause (function.get_where_clause ()); - visit (function.get_definition ()); + if (function.has_body ()) + visit (*function.get_definition ()); } void diff --git a/gcc/rust/hir/rust-ast-lower-implitem.h b/gcc/rust/hir/rust-ast-lower-implitem.h index 096a30e1e42..6f904dde19f 100644 --- a/gcc/rust/hir/rust-ast-lower-implitem.h +++ b/gcc/rust/hir/rust-ast-lower-implitem.h @@ -168,7 +168,7 @@ public: bool terminated = false; std::unique_ptr function_body = std::unique_ptr ( - ASTLoweringBlock::translate (function.get_definition ().get (), + ASTLoweringBlock::translate (function.get_definition ()->get (), &terminated)); auto crate_num = mappings->get_current_crate (); diff --git a/gcc/rust/hir/rust-ast-lower-item.cc b/gcc/rust/hir/rust-ast-lower-item.cc index 8d6ab7cd350..2895872f336 100644 --- a/gcc/rust/hir/rust-ast-lower-item.cc +++ b/gcc/rust/hir/rust-ast-lower-item.cc @@ -446,7 +446,7 @@ ASTLoweringItem::visit (AST::Function &function) bool terminated = false; std::unique_ptr function_body = std::unique_ptr ( - ASTLoweringBlock::translate (function.get_definition ().get (), + ASTLoweringBlock::translate (function.get_definition ()->get (), &terminated)); auto crate_num = mappings->get_current_crate (); diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index acceec302a2..52766afd9c4 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -23,6 +23,7 @@ * This is also the reason why there are no include guards. */ #include "rust-common.h" +#include "rust-expr.h" #include "rust-item.h" #include "rust-common.h" #include "rust-token.h" @@ -2976,14 +2977,21 @@ Parser::parse_function (AST::Visibility vis, // parse where clause - if exists AST::WhereClause where_clause = parse_where_clause (); - // parse block expression - std::unique_ptr block_expr = parse_block_expr (); + tl::optional> body = tl::nullopt; + if (lexer.peek_token ()->get_id () == SEMICOLON) + lexer.skip_token (); + else + { + std::unique_ptr block_expr = parse_block_expr (); + if (block_expr != nullptr) + body = std::move (block_expr); + } return std::unique_ptr ( new AST::Function (std::move (function_name), std::move (qualifiers), std::move (generic_params), std::move (function_params), std::move (return_type), std::move (where_clause), - std::move (block_expr), std::move (vis), + std::move (body), std::move (vis), std::move (outer_attrs), locus)); } @@ -5710,49 +5718,33 @@ Parser::parse_inherent_impl_function_or_method ( // parse where clause (optional) AST::WhereClause where_clause = parse_where_clause (); - // parse function definition (in block) - semicolon not allowed + tl::optional> body = tl::nullopt; if (lexer.peek_token ()->get_id () == SEMICOLON) + lexer.skip_token (); + else { - Error error (lexer.peek_token ()->get_locus (), - "%s declaration in inherent impl not allowed - must have " - "a definition", - is_method ? "method" : "function"); - add_error (std::move (error)); + auto result = parse_block_expr (); - lexer.skip_token (); - return nullptr; - } - std::unique_ptr body = parse_block_expr (); - if (body == nullptr) - { - Error error (lexer.peek_token ()->get_locus (), - "could not parse definition in inherent impl %s definition", - is_method ? "method" : "function"); - add_error (std::move (error)); + if (result == nullptr) + { + Error error ( + lexer.peek_token ()->get_locus (), + "could not parse definition in inherent impl %s definition", + is_method ? "method" : "function"); + add_error (std::move (error)); - skip_after_end_block (); - return nullptr; + skip_after_end_block (); + return nullptr; + } + body = std::move (result); } - // do actual if instead of ternary for return value optimisation - if (is_method) - { - return std::unique_ptr ( - new AST::Function (std::move (ident), std::move (qualifiers), - std::move (generic_params), - std::move (function_params), std::move (return_type), - std::move (where_clause), std::move (body), - std::move (vis), std::move (outer_attrs), locus)); - } - else - { - return std::unique_ptr ( - new AST::Function (std::move (ident), std::move (qualifiers), - std::move (generic_params), - std::move (function_params), std::move (return_type), - std::move (where_clause), std::move (body), - std::move (vis), std::move (outer_attrs), locus)); - } + return std::unique_ptr ( + new AST::Function (std::move (ident), std::move (qualifiers), + std::move (generic_params), std::move (function_params), + std::move (return_type), std::move (where_clause), + std::move (body), std::move (vis), + std::move (outer_attrs), locus)); } // Parses a single trait impl item (item inside a trait impl block). @@ -5960,27 +5952,24 @@ Parser::parse_trait_impl_function_or_method ( "successfully parsed where clause in function or method trait impl item"); // parse function definition (in block) - semicolon not allowed - if (lexer.peek_token ()->get_id () == SEMICOLON) - { - Error error ( - lexer.peek_token ()->get_locus (), - "%s declaration in trait impl not allowed - must have a definition", - is_method ? "method" : "function"); - add_error (std::move (error)); + tl::optional> body = tl::nullopt; - lexer.skip_token (); - return nullptr; - } - std::unique_ptr body = parse_block_expr (); - if (body == nullptr) + if (lexer.peek_token ()->get_id () == SEMICOLON) + lexer.skip_token (); + else { - Error error (lexer.peek_token ()->get_locus (), - "could not parse definition in trait impl %s definition", - is_method ? "method" : "function"); - add_error (std::move (error)); + auto result = parse_block_expr (); + if (result == nullptr) + { + Error error (lexer.peek_token ()->get_locus (), + "could not parse definition in trait impl %s definition", + is_method ? "method" : "function"); + add_error (std::move (error)); - skip_after_end_block (); - return nullptr; + skip_after_end_block (); + return nullptr; + } + body = std::move (result); } return std::unique_ptr ( diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index eaee5bc8606..60eca5b13c7 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -616,7 +616,7 @@ ResolveItem::visit (AST::Function &function) } // resolve the function body - ResolveExpr::go (function.get_definition ().get (), path, cpath); + ResolveExpr::go (function.get_definition ()->get (), path, cpath); resolver->get_name_scope ().pop (); resolver->get_type_scope ().pop (); diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h index 293c98fd6f2..f9aa93ba7c4 100644 --- a/gcc/rust/resolve/rust-ast-resolve-stmt.h +++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h @@ -378,7 +378,7 @@ public: } // resolve the function body - ResolveExpr::go (function.get_definition ().get (), path, cpath); + ResolveExpr::go (function.get_definition ()->get (), path, cpath); resolver->get_name_scope ().pop (); resolver->get_type_scope ().pop (); diff --git a/gcc/rust/resolve/rust-default-resolver.cc b/gcc/rust/resolve/rust-default-resolver.cc index 1ab174b6caa..c1ed3cea113 100644 --- a/gcc/rust/resolve/rust-default-resolver.cc +++ b/gcc/rust/resolve/rust-default-resolver.cc @@ -77,7 +77,8 @@ DefaultResolver::visit (AST::Function &function) } } - function.get_definition ()->accept_vis (*this); + if (function.has_body ()) + function.get_definition ().value ()->accept_vis (*this); }; ctx.scoped (Rib::Kind::Function, function.get_node_id (), def_fn); diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index a1e23082e88..3c296b565f5 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -667,7 +667,8 @@ AttributeChecker::visit (AST::Function &fun) else if (result.name == "no_mangle") check_no_mangle_function (attribute, fun); } - fun.get_definition ()->accept_vis (*this); + if (fun.has_body ()) + fun.get_definition ().value ()->accept_vis (*this); } void From patchwork Tue Jan 30 12:07:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892905 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=gekQagey; 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 4TPPxJ4BQMz23gZ for ; Tue, 30 Jan 2024 23:44:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92D3338323DA for ; Tue, 30 Jan 2024 12:44:02 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 11B193857C5A for ; Tue, 30 Jan 2024 12:11:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 11B193857C5A 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 11B193857C5A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::431 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616738; cv=none; b=nILxz6nWUBZhS6XwfzDibzjNfROM4E2xwaVO5FmQlI0NAeIa4qWLC2aRa/Lfh8m6+TJegLSDzGEvBGS3y9++dMIUXkylyy8A5Z4bPZXfo7F6oIJjTfnMu0/kxLti43TO9gUt/C3lSVKqpnbBWUPsZHTaUcCwXqaaa2S3h27ZNE0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616738; c=relaxed/simple; bh=UoJRc1bkZHjxdnrsydb3aUnoPpkT44TombNUGjiUXU4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=PTHFr/1nL0IxXRe4EVHEmV1Yv8hN3nZONMoLp4E0DJHtYttrrfRbH8OsaL2yPbdS7M0P9mcLp7bGYKKeI9zXebPz/O6P/Q4lklfbACSZn8Q+oqkGJZ2WVxOax8jvxgRi4joB+bdOm4bvfxRRotzmAYiQsNyL3Y+FTxSlPsbIRvs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-339289fead2so3051117f8f.3 for ; Tue, 30 Jan 2024 04:11:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616701; x=1707221501; 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=nB5Y/pE8eC3pgLib4epj/PNs7fzwaFqAJ5cV6cRW1jg=; b=gekQageyQZGd9aopp4pyZaKyK47wp0hYyCx8I/feFlbe0z0hlPOZnx1Ro6IhjvbowW 2MUDwC+uC7b4zJejTh7hMlw/Tu98uZKzZqtzri6+x1qFWtC+L3iWRkTFC9NbKMRb9klv IrDxwrPGHmlF0u1oRvHKVol2hIQkFX6yWcQKfNYKANbAU0lnxM5lCG86KIPOnZ6H7/tc I60GBxu5Z/k0QG0eVlKuJuqwQ1nntpVfRsaYI4KVGPMyrd0arMUQzp9oa2Hxumr+j0A1 mr2kwW4IXfRWmHu11vebPSiCX3vrWxhoCGIiMvJpm1MQgxaLdvCyK6YbJgN5HJnA9YLv 0QVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616701; x=1707221501; 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=nB5Y/pE8eC3pgLib4epj/PNs7fzwaFqAJ5cV6cRW1jg=; b=ic3XLcaID2Ds0g+gC3UYJ6C0gv8Uxhr60dhWhTDZYEnL6a1yCJYvPMepoauCJG3Tku 2cAotBvAnoyZN4x/JymP4LAoxkidtDzvp6US7dst0vnoMnbpVgRQ5dDD0eA92qo9LaRH 3aQabDIBT/F8Fw8QF6QRpRKCkw+oh4eU4NQQvmh8KcW4z5+0Fg+aheV+85Qh35SI7qRy pTSPNn0hx4032yy0/6zy+kc9zmtAQBLgJwfAJ0Xn5G6k1DH2eX2w0MDbP2SaG9cx9EET QJ4ld3H7T7Akg3/1ZaWKHuaPa5FsLPb3qSbYHk6hfjTyJNzAhSvd62XkqA4WWT4Nntaa njkA== X-Gm-Message-State: AOJu0Yy85KU0n2FIUyXoet8YNKytt3z5rAZpaRzTzbK7713eBXVlO7BT oJFeMaW+Knc2y723gQxyO7X2+/eG2D4eQSZZDnCw0AIuq5hjxmIvXI4X1PC9ILxoMh/FBHB4TCb yeQ== X-Google-Smtp-Source: AGHT+IE6FmQC8N9+SH37rbe961+Lzua7X2XyZMZys2wR+dd3cCMwhWhjdEOnsGYTRDeAVv+Une+1rQ== X-Received: by 2002:adf:d1cf:0:b0:33a:eda2:baf7 with SMTP id b15-20020adfd1cf000000b0033aeda2baf7mr4267073wrd.63.1706616696619; Tue, 30 Jan 2024 04:11:36 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:36 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 063/101] gccrs: Add validation for functions without body Date: Tue, 30 Jan 2024 13:07:19 +0100 Message-ID: <20240130121026.807464-66-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.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, 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: Pierre-Emmanuel Patry Add checks in the ast validation pass to error out with functions (either free or associated) without a definition. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add a validation check and emit an error depending on the context. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/checks/errors/rust-ast-validation.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index 2743eb0ca29..6fb142c7845 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -109,6 +109,16 @@ ASTValidation::visit (AST::Function &function) function.get_self_param ()->get_locus (), "% parameter is only allowed in associated functions"); + if (!function.has_body ()) + { + if (context.back () == Context::INHERENT_IMPL + || context.back () == Context::TRAIT_IMPL) + rust_error_at (function.get_locus (), + "associated function in % without body"); + else if (context.back () != Context::TRAIT) + rust_error_at (function.get_locus (), "free function without a body"); + } + if (function.is_variadic ()) rust_error_at ( function.get_function_params ().back ()->get_locus (), From patchwork Tue Jan 30 12:07:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892890 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=EOd50Tvq; 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 4TPPrQ4Mmlz23dQ for ; Tue, 30 Jan 2024 23:39:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E4853875DFB for ; Tue, 30 Jan 2024 12:39:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 6A8173857C79 for ; Tue, 30 Jan 2024 12:11:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6A8173857C79 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 6A8173857C79 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::431 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616727; cv=none; b=dF7E3I1DXLi7insR0InPAqP537hsXf4JWTKxAlkBh/Bh9vl4wsUkxkB3SWsvGfBAtcqCDvOZp0VRLN5ofu5qsSDLlhC42jDzmacllZbaoJNQ/XqP3LD4k6J7yvzz1K+Mqed002lVmD+7YdV7CYwkuwjuUOrCRiZp6EXGh+skKF8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616727; c=relaxed/simple; bh=eq7IBo/lpEMkBfsicakGZ41Mgu3FWfx1YuVMjP7ZaRo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Al9EKP9np8BlN59m04tAxPFT3ibG052jnHQ41Y8jeqWFCFOzzb3Dgqx9dYzVQFbKyf2Xyuq5oJbTDVrvp7O5EA6VEjYUlZF8DN9BOb40DJZbmaJHJ2qk8BlZkteBju1oGYf37lyJzHPcM7xIB++UGG4OBlegrkRgdmXR1MUv95o= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-33ae4eb360aso2240350f8f.0 for ; Tue, 30 Jan 2024 04:11:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616697; x=1707221497; 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=qT4BM4QggUDd/mriRzEn6ZypenFxQPkGzA1q4EIkPuc=; b=EOd50TvqRH19pdWB2FgV3eDcPTXQnU9iLSUfLG/lJWmMt4L1rSBHT6sqcVTmasylDc jsYYB0AkWQ1Ti6QxfHqeQiI2ceIwmEq9qC35BEEASuFErpqriUNeRtcHHYjYqxnbB8u1 +LPCaSGIbz7alc6cPPV77xsCh44LAKmNNJg7EKDFARCQuHn58PRMPio/2ebzqN8BBQCm ZFinDPqHkhSdLDggsuTSjLARK4U9knoZ1SjhPJteom6WmfOpEBZzN7pIKvbypJVnUeVG avi3tytqroyd0pI3rpE6iul6SCvH9L5/Q1oXJOBiIOnqX2iQ+e9H7QT3jQNn+2K7kND9 +7yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616697; x=1707221497; 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=qT4BM4QggUDd/mriRzEn6ZypenFxQPkGzA1q4EIkPuc=; b=UFdlMZMQuPQmzcH6o+MPLhmJcnQqWGTXWt9+ZF/7NuwV2QySXL6aYempuo9F7YhpsO XfFGCGN5TYSWxrrzZwgOH/V4qLhh1ass4rnn38wIIe9Q2OAdD3mg8nI8UJthWY+DYKAh UYD/IxRei2jjcfmr9AAOrAs/gPMrXP4wZeLztw813wELYjQXtYJCpLpqQ0xdTyvUwy6S 79h67cQ0goGa43T4L1dfW3rvHmBEMs8brnWtjAKbmJt50hqNQBlg/efS0sElCdmRnqzG zJ65JrCnms3Hv4VnP3N37BaDN1q3Lt0utEsRxNpMiLw+h+/CX6R66ipordopGfjiQ8eT EPLw== X-Gm-Message-State: AOJu0YyxSganSIOpB+7tn7DQXOGEJyTCoNt8pXWYVPZWF+tgsPt7KNak CVzkzlKzCwgR0sLRIfRepsNh60I83Kf5f/OVH0iMmgVky9j2U7OBGSiucoJTTQhG9TDhTCvsmuy Yrw== X-Google-Smtp-Source: AGHT+IGDLxQ+FPvj9MDFPSxtt1PMrDtkJGDSrdpEhWFgiz+uljF7Byx9xSCTtbMpImxBfMG+iSwKZQ== X-Received: by 2002:a5d:60ca:0:b0:337:c93d:d815 with SMTP id x10-20020a5d60ca000000b00337c93dd815mr5382324wrt.35.1706616697071; Tue, 30 Jan 2024 04:11:37 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:36 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 064/101] gccrs: Add a regression test for function body check Date: Tue, 30 Jan 2024 13:07:20 +0100 Message-ID: <20240130121026.807464-67-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: Pierre-Emmanuel Patry Function body check emit an error message when a required function body is missing. gcc/testsuite/ChangeLog: * rust/compile/functions_without_body.rs: New test. Signed-off-by: Pierre-Emmanuel Patry --- .../rust/compile/functions_without_body.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 gcc/testsuite/rust/compile/functions_without_body.rs diff --git a/gcc/testsuite/rust/compile/functions_without_body.rs b/gcc/testsuite/rust/compile/functions_without_body.rs new file mode 100644 index 00000000000..36ddea52161 --- /dev/null +++ b/gcc/testsuite/rust/compile/functions_without_body.rs @@ -0,0 +1,21 @@ +struct MyStruct; + +trait X {} + +fn test_a(); +// { dg-error "free function without a body" "" { target *-*-* } .-1 } + +impl MyStruct { + fn test_b() + // { dg-error "associated function in .impl. without body" "" { target *-*-* } .-1 } + where + T: Copy; + + fn test_c(); + // { dg-error "associated function in .impl. without body" "" { target *-*-* } .-1 } +} + +impl X for MyStruct { + fn test_d(); + // { dg-error "associated function in .impl. without body" "" { target *-*-* } .-1 } +} From patchwork Tue Jan 30 12:07:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892853 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=Xjltkihu; 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 4TPPcy2q0Nz23gZ for ; Tue, 30 Jan 2024 23:29:54 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 614EB3864C69 for ; Tue, 30 Jan 2024 12:29:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 500583857BBE for ; Tue, 30 Jan 2024 12:11:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 500583857BBE 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 500583857BBE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::331 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616732; cv=none; b=IzN1H8kuyQ9ZAIKf1DwEs4CMXDQDYDI/LC0jv5PJgwueEZJOcQFFlhtDR+2N6rKEQiBNrn/SnIpKiArJ48SvbVSTJqrMN3ezf8yv8DPZk+LK57LbMS+bCaeOpYzu3s12XZ4y0+x1DV4c4oUyUr4An02fIFN8pCP9CTROQVr9ayk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616732; c=relaxed/simple; bh=Ds39LoDLj+M3gQei3jOkd99C0LenJ1lfmk8dWl27ock=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=b1SFAN7pOj8tfOkyiwmOiC42DW0GDh+c35st7PSARpWm7cqiwb5DFEatiVjql9eRu3jD/CcHmRXz/6tuKt9G4I75Lj+bmtpWB1Oab+pc2DQLIqM73dNiH6qoBzM6FO/n27rgc3lne+rIZvT59vVfoneG1o/02LbM2n9n7qh0FGY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-40ef64d8955so18171315e9.3 for ; Tue, 30 Jan 2024 04:11:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616698; x=1707221498; 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=33Q1RklMH1x9+FInnB0kn2J5J5csXIpLWJpJhfDOmIo=; b=Xjltkihua3BjipfuJhgr1J+b3W+pvhWXt8eaNSJ8z94gmrs7dJhoMIq/8v9qsc0rSH sNc7f3pxCy1EreNUwm3mFvxokvYgompYjbfDUdAgG6FhamXeMa5nAx1GdJMyi28Z9KJN tdu1KpZ6AiP3OZDhpIaNDrWQpb6Zb3cXsCDtP8aC6cQjQcSQTOfIs3TCm5hqDjoAdxr9 NHgCnXSeFLpPzU6jitpAg+hHj2UdpRelhQI+TZ9FXQCwgQgAZPUBb3tGVb1Ygzfc0Zg1 3GFFKautuSjWQ9yh3GfnODrLs0a95pejk61+VkIfILB/iyc+W11wA/BB08WjIEDqqxCZ JyHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616698; x=1707221498; 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=33Q1RklMH1x9+FInnB0kn2J5J5csXIpLWJpJhfDOmIo=; b=sjZdRH1cxe3LXIM/fORDMVduwQONaZvELCWmEOPXcQZmep10xQwTtmpSVRTv5VZGBg BfMy9HkZkxS488BN8Nq0BAB7PIvpa0mx2hxiY4T2e842b39n7D+nmJLIIRG5YG5H6W0S BHdToyQcDscrizbg4mOFLbaEDjQxrg1mM0qtIeKfXwBlnae28fEuv+2LrBX0FQz7qpMb 3I3yIA0Ss+7zS7mRa+VWisTpLNR2sm7XmC5SnWyogJ8HSAjgTM6CPALEDfYanhAXvRKY GXank+l2vsBE0cJvPIa1gyhA8zB9HhwGPbU2X06WQKb3gAPhQtMl/Nq3w+p2cg6Hy1b5 7OTw== X-Gm-Message-State: AOJu0YwxvA4BlKIiQrkxaS4N0S5OQj+/ZZbnXWtLEZDW89JTFNMj16Vu eeijosb2qpHLBdpTpEFr+rxA56gUVHd3mkgIYuzm70H4Y/xS5+fZ2+j64l1odEXM8Flr8eaVazq EUg== X-Google-Smtp-Source: AGHT+IEjOWXg0e7RWGrahhTv3+ps3vbwuM5F7EqaTzlsg2aGoadrfNkZs9Rvsy3g59d/jef8OpzqYQ== X-Received: by 2002:a05:600c:4f92:b0:40e:6650:b883 with SMTP id n18-20020a05600c4f9200b0040e6650b883mr6661161wmq.18.1706616697722; Tue, 30 Jan 2024 04:11:37 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:37 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Nobel Singh Subject: [COMMITTED 065/101] gccrs: Generate error for const trait functions Date: Tue, 30 Jan 2024 13:07:21 +0100 Message-ID: <20240130121026.807464-68-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.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, 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: Nobel Singh Fixes issue #2040 Add check to assure that a function cant be declared const inside trait impl blocks. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add check for const funtion. gcc/testsuite/ChangeLog: * rust/compile/issue-2040.rs: New test. Signed-off-by: Nobel Singh --- gcc/rust/checks/errors/rust-ast-validation.cc | 4 ++++ gcc/testsuite/rust/compile/issue-2040.rs | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/rust/compile/issue-2040.rs diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index 6fb142c7845..cd197fc1ea7 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -103,6 +103,10 @@ ASTValidation::visit (AST::Function &function) rust_error_at (function.get_locus (), "functions cannot be both % and %"); + if (qualifiers.is_const () && context.back () == Context::TRAIT_IMPL) + rust_error_at (function.get_locus (), ErrorCode::E0379, + "functions in traits cannot be declared const"); + if (valid_context.find (context.back ()) == valid_context.end () && function.has_self_param ()) rust_error_at ( diff --git a/gcc/testsuite/rust/compile/issue-2040.rs b/gcc/testsuite/rust/compile/issue-2040.rs new file mode 100644 index 00000000000..fbac168b9f3 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2040.rs @@ -0,0 +1,12 @@ +trait Foo { + fn f() -> u32; +} + +impl Foo for u32 { + const fn f() -> u32 { + // { dg-error "functions in traits cannot be declared const" "" { target *-*-* } .-1 } + 22 + } +} + +fn main() {} From patchwork Tue Jan 30 12:07:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892858 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=btYYT3oi; 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 4TPPfB4TH6z23fD for ; Tue, 30 Jan 2024 23:30:58 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 928EC3870C23 for ; Tue, 30 Jan 2024 12:30:56 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 53CB2385782A for ; Tue, 30 Jan 2024 12:11:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 53CB2385782A 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 53CB2385782A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616733; cv=none; b=XvZZuvKchTG8Jl/0vxJvBkq1EsslLieec6AH5N6aNlonPg8mnijd949uVRI3Aax+W87SY/9CjELlv5faK9vFUPWb8XSZdlWXMedIVTZpl5JOeoHF87y0YLOVjLa80Y1AnjVF0bvnSmMRVDEnCRBN0MjA3jBw/nJNxUz0Vn5Ro9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616733; c=relaxed/simple; bh=qNRaAWE5Hrg1K3UyVIoqPO/I+RNMn0osnPHKSkccWxU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FFJXZAtRWo9VHrPCAfeT6jVDyHGENoxvmsceZpa+M4viI93bue5OWaFB5MbesvQrl3p2GrK+cRW9z/KIfz1AFPtJAkTMpVfyDPnBA6VsKJH9Cds54ATdKEaNQOAgk2TZMnvS5DId5rGNn+bMxiHMTgrRglVlSnH4q3A1KxX4EiI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-3394b892691so2129837f8f.1 for ; Tue, 30 Jan 2024 04:11:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616698; x=1707221498; 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=7xZhBKU4DLD2oiNzGr23H8qWI0cAHkl/1jme2PufIfo=; b=btYYT3oiZO8kujhvddMPe/RHbDptrKOHyAHVqjGf/DIhnYw4nI/b7Djd4kYhdYv8vY E00zTms4IWwe6oPCyO2z7GDiS8gQazLgoy+aHQRASUUlmZjtJNI8iclwkKHyodXLfOAZ jLny9Kb6bor46o5jfxa98Ftej9c1hjCXMz+ju68XCY3gY4edgXlZbv4EEyAXNvTnhwTp yi+2aaxwDFZPsLb7YcWDJwKlcLnroin9ip/8ns1af6OgdPBdXqM680sTw/OMpIOkjS95 RpMFyhgS2xakqniMecdWQrH8mnwDC/vAXnQQtPYb+IVIkdtdcuOU8BbjTTCR7HM1VsJT MiWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616698; x=1707221498; 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=7xZhBKU4DLD2oiNzGr23H8qWI0cAHkl/1jme2PufIfo=; b=CCPSInA8G4+nULyAPp2dfEWCeJU1Ty+AV4h9lGUEVdfmM3lpVD+JRVuwPXWU+H80gS eJoEv+TvHSGsEsvxCOLoTE/MFeKMWuS5Cx9Okr2Pekjj8vpMKr8L5H9RD3su7jj28eE1 993sH54ga2dq4gi1lQdMLr2hK3WwXCzj3etqdmAhCRll8u7/u4jXU6vG0tXfSXc0ykc/ CqZOwa27H/8Vc8YhwW1lS+lBtuf+g7u0swDnWzFWMp2snggQWkVX5q+ccMdhCeS6FDm0 hTyLPZf5Fb3d0tQTI8YvIUyp6BStUmwze6JeTSrIwPbLKeY3s5EgfZSAKWVOsSy/AIYr V7uQ== X-Gm-Message-State: AOJu0YzIwCoZA++zvPj9i5JAmZv2UxajV7YFmlXPbcG7SLAYb9IDLJQL N4aZWakULmneFkkbsorXGgfSJm9MmIGH+5SdpqlGnxQxinxAQXw4ty6ySnx6hzG9/OCoHmWe8hN 7RQ== X-Google-Smtp-Source: AGHT+IFRBSKADbGGuAKmSauotEtUMMg3gnO3buwSkOJoqzS8QuqnbLEgnLj5y3nRAaPCRfkhSdf+QQ== X-Received: by 2002:a5d:68d0:0:b0:33a:eb5a:8d00 with SMTP id p16-20020a5d68d0000000b0033aeb5a8d00mr1309800wrw.26.1706616698243; Tue, 30 Jan 2024 04:11:38 -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.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:38 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Kushal Pal Subject: [COMMITTED 066/101] gccrs: Renamed `WIN64` to `WIN_64` Date: Tue, 30 Jan 2024 13:07:22 +0100 Message-ID: <20240130121026.807464-69-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.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, 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: Kushal Pal Fixes issue #2768 gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::setup_abi_options): Renamed `WIN64` to `WIN_64` * util/rust-abi.cc (get_abi_from_string): Likewise (get_string_from_abi): Likewise * util/rust-abi.h (enum ABI): Likewise Signed-off-by: Kushal Pal --- gcc/rust/backend/rust-compile-base.cc | 2 +- gcc/rust/util/rust-abi.cc | 4 ++-- gcc/rust/util/rust-abi.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index fcab75bef1c..984492f6607 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -463,7 +463,7 @@ HIRCompileBase::setup_abi_options (tree fndecl, ABI abi) break; - case Rust::ABI::WIN64: + case Rust::ABI::WIN_64: abi_tree = get_identifier ("ms_abi"); break; diff --git a/gcc/rust/util/rust-abi.cc b/gcc/rust/util/rust-abi.cc index 05739e16660..d17402e163e 100644 --- a/gcc/rust/util/rust-abi.cc +++ b/gcc/rust/util/rust-abi.cc @@ -40,7 +40,7 @@ get_abi_from_string (const std::string &abi) else if (abi.compare ("sysv64") == 0) return Rust::ABI::SYSV64; else if (abi.compare ("win64") == 0) - return Rust::ABI::WIN64; + return Rust::ABI::WIN_64; return Rust::ABI::UNKNOWN; } @@ -64,7 +64,7 @@ get_string_from_abi (Rust::ABI abi) return "fastcall"; case Rust::ABI::SYSV64: return "sysv64"; - case Rust::ABI::WIN64: + case Rust::ABI::WIN_64: return "win64"; case Rust::ABI::UNKNOWN: diff --git a/gcc/rust/util/rust-abi.h b/gcc/rust/util/rust-abi.h index d794cc35fb3..a0180ed4d95 100644 --- a/gcc/rust/util/rust-abi.h +++ b/gcc/rust/util/rust-abi.h @@ -30,7 +30,7 @@ enum ABI CDECL, STDCALL, FASTCALL, - WIN64, + WIN_64, SYSV64 }; From patchwork Tue Jan 30 12:07:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892859 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=hDfh7Jps; 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 4TPPfz1RHDz23fD for ; Tue, 30 Jan 2024 23:31:39 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2708A3870C1A for ; Tue, 30 Jan 2024 12:31:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 630E43858035 for ; Tue, 30 Jan 2024 12:11:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 630E43858035 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 630E43858035 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::331 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616736; cv=none; b=xO+vMWqzKSMJ4VzogOngfFpGClRglULAbro5dVcGMz3e/BNrRVZApSd05IwsoiDpjZO1s+DYB8t5yQn0c70OedmM2+05ySuez3buiVU2uRTCrr0SrtJcyPXCOJepxT6G1TLVpBuDfcq+TfQiNPp6t13qnwWqhX3zeY3OYASrCW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616736; c=relaxed/simple; bh=DwBYR8cuuXgveMtrMsLMZbGMNvhuOSQmGjUGr1WPzvg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=GIH182XPU6NJh0zTMMoJT75RoMbIe8I+ybcZTtchDq94crlsmMAXelRiW9nZjwLpGcxtDLBLwk7D6bspQdj4tGPBiaRgpmb1HB+dV8QJ7nQJ4Z/q6Se6YjdmseDsNoWpR+PPXwxFzedtIuHpKl83KlHEujieo/a13u/xljCCFj8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-40e800461baso52297785e9.3 for ; Tue, 30 Jan 2024 04:11:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616699; x=1707221499; 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=Cr6v9HAe0eMnOCnoOMKwuWt8DY5FCq6TDq/GFYqg2rE=; b=hDfh7JpsnlR4K442T5YMAX1EsUQGAbyi4HQXgXE/Txmxoy0Dwl536wA4v3zmZPzZWm M9v7WqHlqVlvCz6jEyc/u9Xyi3ujkbnXySITihbmi03wEKbcJ1YHQpCVqnF4Osu/qdJL qQ0NRwF07EAZh1pQAPqgjCrAaqR9qK1cDeqcCdioPMWUp8weIh+bBh0Ivp26upyzzkTs dtrpe7yQNp2n6oFRYpYJmqBrBHzAEl4LAl6nuemjKn8SKN6zEg4k7f/oJApCCn3/bDKc d+t69skc4Mkv+TjGtEt13SC2VKMJSlCzION028etJkymTqhbzjPDNTix7IH04hLA80Cr ySeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616699; x=1707221499; 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=Cr6v9HAe0eMnOCnoOMKwuWt8DY5FCq6TDq/GFYqg2rE=; b=X3iKwewYK3K3f/Nq2WUOhi4uMDzqF5XVbpp6/Ih+1Z2sue5fIwIzfqfpIMdF/uTaH8 PXVAyVeOFNeY3iDnEbHamgQSqv7W62DLxhY+qmW1MLDNzDGtUir1ToE27dHz92yQ54zL vLyP6mIF4gSZGshnnkqsJWxE9Sv9JzmcddBWARmEde99O1/FavFagJ/0Rp1UHWIgxdB+ 4yha1zDIu43htZPkU3hMOz6Xb3niZ/WUnwycFYdiU4yZonXWPL//pUuzAJjWgvpfXtku qFXRtyd35HrDQZ3kylRxpo9LRUNqY5967wfDVST0qu3nflfrIkTbNtp62DrQP8sIRrUQ h/Bw== X-Gm-Message-State: AOJu0Yy8+xO1mH9aSBfD+u5itOfM+HPERe7gWkLX9U9d6uM18d7wVrb1 YEMpbDmOSoFKyvI3u9p7pAVCUmyGdJQjm9iDImeO6t61Ir1hqGB+rMJKBnocRoYN6U4lWswSYNX BZA== X-Google-Smtp-Source: AGHT+IG391r49AGdOD74RwbuGoeNPtUWS7GSCNt8RrS4qQ05eXw5H5GeHWqC4UaL0Hk33VaCBHP8bw== X-Received: by 2002:a5d:5850:0:b0:33a:fc5e:caf1 with SMTP id i16-20020a5d5850000000b0033afc5ecaf1mr1149424wrf.27.1706616699734; Tue, 30 Jan 2024 04:11:39 -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.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:38 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [COMMITTED 067/101] gccrs: Allow enabling lang_items and no_core features Date: Tue, 30 Jan 2024 13:07:23 +0100 Message-ID: <20240130121026.807464-70-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.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, 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: Owen Avery gcc/rust/ChangeLog: * checks/errors/rust-feature.cc (Feature::name_hash_map): Add entries for Name::LANG_ITEMS and Name::NO_CORE. * checks/errors/rust-feature.h (Feature::Name::LANG_ITEMS): New. (Feature::Name::NO_CORE): New. gcc/testsuite/ChangeLog: * rust/compile/sized-stub.rs: New test. Signed-off-by: Owen Avery --- gcc/rust/checks/errors/rust-feature.cc | 2 ++ gcc/rust/checks/errors/rust-feature.h | 2 ++ gcc/testsuite/rust/compile/sized-stub.rs | 6 ++++++ 3 files changed, 10 insertions(+) create mode 100644 gcc/testsuite/rust/compile/sized-stub.rs diff --git a/gcc/rust/checks/errors/rust-feature.cc b/gcc/rust/checks/errors/rust-feature.cc index 88649f14e60..c12710ae2e1 100644 --- a/gcc/rust/checks/errors/rust-feature.cc +++ b/gcc/rust/checks/errors/rust-feature.cc @@ -56,6 +56,8 @@ const std::map Feature::name_hash_map = { // later Rust versions {"optin_builtin_traits", Feature::Name::AUTO_TRAITS}, {"extern_types", Feature::Name::EXTERN_TYPES}, + {"lang_items", Feature::Name::LANG_ITEMS}, + {"no_core", Feature::Name::NO_CORE}, }; // namespace Rust tl::optional diff --git a/gcc/rust/checks/errors/rust-feature.h b/gcc/rust/checks/errors/rust-feature.h index 4ff059c6167..e6bc2362e39 100644 --- a/gcc/rust/checks/errors/rust-feature.h +++ b/gcc/rust/checks/errors/rust-feature.h @@ -43,6 +43,8 @@ public: DECL_MACRO, AUTO_TRAITS, EXTERN_TYPES, + LANG_ITEMS, + NO_CORE, }; const std::string &as_string () { return m_name_str; } diff --git a/gcc/testsuite/rust/compile/sized-stub.rs b/gcc/testsuite/rust/compile/sized-stub.rs new file mode 100644 index 00000000000..4e89b1fb134 --- /dev/null +++ b/gcc/testsuite/rust/compile/sized-stub.rs @@ -0,0 +1,6 @@ +#![feature(lang_items)] +#![feature(no_core)] +#![no_core] + +#[lang = "sized"] +trait Sized {} From patchwork Tue Jan 30 12:07: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: 1892877 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=U0olPwQJ; 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 4TPPm83zgHz23dQ for ; Tue, 30 Jan 2024 23:36:08 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 76E443838A21 for ; Tue, 30 Jan 2024 12:36:06 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 7D1563857BAD for ; Tue, 30 Jan 2024 12:11:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7D1563857BAD 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 7D1563857BAD Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::432 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616738; cv=none; b=Vp73pGK38DqTioRT1Pf9KKX6asrdtiy2Zz8IQvN6BDVRTN+xOBWwmEgu6ruhHXyd834Fm2LBUzz0SqK0CVyeahdws6TtwLRKYYj+vLplWY9L2GF3GQmJko3q9GOI/oIXiABYLsWdeQTjdaIYYK8TIa8uT2OufJ/uouZ3xO25JDY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616738; c=relaxed/simple; bh=ZwjhKhFyjoPMjh1VWYkCjAaq2d4KGySSxDhtNCW08PI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=gJu6L16RWsKxDK0oarx7lb99xrWcDMHejai447X7mbgtgOqOqHOFKA8kU2+qG6qBp3uOIPNFBpYhiDym6TZwbdnYM9k7Uj3bZihvpfPE0FAdhNCvUveTx4CBNrk+OPF6Kl1g8nuU42UzB7fQZmAQYXTPtWhScof34WVWq7BDego= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-33aeb088324so1539605f8f.2 for ; Tue, 30 Jan 2024 04:11:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616700; x=1707221500; 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=0C+NFwYpGtvMPOYsz8QVeEIKqOTKiJf3NeT0BjTLhKE=; b=U0olPwQJ42lcILLaj6p4JCjDrIwinYtB4mnlzCt9SsXT6qjBGCf5oZdAV18YpXykpK YeQBn7yhRUzE4lXGBa/kB336vkW+p9Xw8M7J9YEq5SInHFYpJwcoZtYTa53Mo9G7czZF I3Dd/AxEJRBRV7nnqHv3WrVDn9+TGOocoYUylZVGqvJNyi1CiJ9Zrgp5h/PTh4xqS+4I cOnHG4Bji2spZCksj/HlQP5+pmMEp4xZR6aeQIMZ7FS0WhOZoYLAsYEPAjXBUXnnL6eN UQka7Xuq2bmhBppq5tePhUljh8z5T8sSFMOpLdnfA3R3iWFQ1oY1DLQAaEi2LarT98FR 6KjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616700; x=1707221500; 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=0C+NFwYpGtvMPOYsz8QVeEIKqOTKiJf3NeT0BjTLhKE=; b=CRV2IBfW8fPLh+7XEeM9YO9bGvqe+XBg+k5xGZyGfVkocapo/cPD3ydKypxtJGGiR4 DiBOhsatk1TO7PXDE4lXChtNiSnnx12oikFNCSzbhDU/frOUTNJKkBK2LZpLjgV3GEtw alj5f5Ep4QrxCxQUtE+a1QYyC7xprs/A9FFwLbokeBxfnuhFAA1nWCLH4TbF4FnMmpJa 9dyzj1y63AhfbSdMRA2wAe2468T2EJvM6Z+i1UxRh/xrWKPjOJYNucUluzCFSaqyM6pJ +L1e4yAkJdMtU3xNFzkwFI8+BmOjf2xSSXohhjmfvzF6kU96VpaU5AUDfJLj4+iTTd8W X53Q== X-Gm-Message-State: AOJu0Yxk3khf3gXzXn3EEgQ0RFmOeTi2lXoRbKj09eB48+TomZISK+zw eXUZfknAAy+R2aI4XZL5BwPyyvLkoecI5ldq0xTtF3q3YVgOJ9GWT9ZbFfOv9GWIIVr1bXcn3lu n6w== X-Google-Smtp-Source: AGHT+IFxhEx2s7/wHAa/hSkNJfDAHRPREoDJ1b1iZE/ffZhuFEdAjVQatpTl/eNR0vIkrd/1qzb4Xw== X-Received: by 2002:a5d:64eb:0:b0:33a:e712:96b0 with SMTP id g11-20020a5d64eb000000b0033ae71296b0mr1463012wri.52.1706616700432; Tue, 30 Jan 2024 04:11:40 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:40 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 068/101] gccrs: Make default resolver inherit from default visitor Date: Tue, 30 Jan 2024 13:07:24 +0100 Message-ID: <20240130121026.807464-71-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: Pierre-Emmanuel Patry The default resolver put some scope in place but mostly has traversal functions similar to the default ast visitor, making it inherit from the default visitor allows us to avoid code duplication. gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove duplicated functions. * resolve/rust-default-resolver.h (class DefaultResolver): Make the default resolver inherit from the default visitor. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/resolve/rust-default-resolver.cc | 240 +--------------------- gcc/rust/resolve/rust-default-resolver.h | 44 +--- 2 files changed, 5 insertions(+), 279 deletions(-) diff --git a/gcc/rust/resolve/rust-default-resolver.cc b/gcc/rust/resolve/rust-default-resolver.cc index c1ed3cea113..ab4d5e8b70d 100644 --- a/gcc/rust/resolve/rust-default-resolver.cc +++ b/gcc/rust/resolve/rust-default-resolver.cc @@ -18,6 +18,7 @@ #include "rust-default-resolver.h" #include "rust-ast-full.h" +#include "rust-ast-visitor.h" #include "rust-item.h" namespace Rust { @@ -148,26 +149,11 @@ DefaultResolver::visit (AST::StructStruct &type) // we also can't visit `StructField`s by default, so there's nothing to do - // correct? or should we do something like - for (auto &field : type.get_fields ()) - field.get_field_type ()->accept_vis (*this); + AST::DefaultASTVisitor::visit (type); // FIXME: ??? } -void -DefaultResolver::visit (AST::TupleStruct &type) -{ - for (auto &field : type.get_fields ()) - field.get_field_type ()->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::Union &type) -{ - for (auto &field : type.get_variants ()) - field.get_field_type ()->accept_vis (*this); -} - void DefaultResolver::visit (AST::Enum &type) { @@ -182,118 +168,6 @@ DefaultResolver::visit (AST::Enum &type) variant_fn, type.get_identifier ()); } -void -DefaultResolver::visit (AST::BorrowExpr &expr) -{ - expr.get_borrowed_expr ()->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::DereferenceExpr &expr) -{ - expr.get_dereferenced_expr ()->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::ErrorPropagationExpr &expr) -{ - expr.get_propagating_expr ()->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::NegationExpr &expr) -{ - expr.get_negated_expr ()->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::ArithmeticOrLogicalExpr &expr) -{ - expr.get_left_expr ()->accept_vis (*this); - expr.get_right_expr ()->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::ComparisonExpr &expr) -{ - expr.get_left_expr ()->accept_vis (*this); - expr.get_right_expr ()->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::LazyBooleanExpr &expr) -{ - expr.get_left_expr ()->accept_vis (*this); - expr.get_right_expr ()->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::TypeCastExpr &expr) -{ - expr.get_type_to_cast_to ()->accept_vis (*this); - expr.get_casted_expr ()->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::AssignmentExpr &expr) -{ - expr.get_left_expr ()->accept_vis (*this); - expr.get_right_expr ()->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::CompoundAssignmentExpr &expr) -{ - expr.get_left_expr ()->accept_vis (*this); - expr.get_right_expr ()->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::GroupedExpr &expr) -{ - expr.get_expr_in_parens ()->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::ArrayElemsValues &array) -{ - for (auto &value : array.get_values ()) - value->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::ArrayElemsCopied &array) -{ - array.get_elem_to_copy ()->accept_vis (*this); - array.get_num_copies ()->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::ArrayExpr &expr) -{ - expr.get_array_elems ()->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::ArrayIndexExpr &expr) -{ - expr.get_array_expr ()->accept_vis (*this); - expr.get_index_expr ()->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::TupleExpr &expr) -{ - for (auto &element : expr.get_tuple_elems ()) - element->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::TupleIndexExpr &expr) -{ - expr.get_tuple_expr ()->accept_vis (*this); -} - void DefaultResolver::visit (AST::StructExprFieldIdentifierValue &) {} @@ -302,28 +176,6 @@ void DefaultResolver::visit (AST::StructExprFieldIndexValue &) {} -void -DefaultResolver::visit (AST::CallExpr &expr) -{ - expr.get_function_expr ()->accept_vis (*this); - for (auto ¶m : expr.get_params ()) - param->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::MethodCallExpr &expr) -{ - expr.get_receiver_expr ()->accept_vis (*this); - for (auto ¶m : expr.get_params ()) - param->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::FieldAccessExpr &expr) -{ - expr.get_receiver_expr ()->accept_vis (*this); -} - void DefaultResolver::visit (AST::ClosureExprInner &) {} @@ -336,13 +188,6 @@ void DefaultResolver::visit (AST::ContinueExpr &expr) {} -void -DefaultResolver::visit (AST::BreakExpr &expr) -{ - if (expr.has_break_expr ()) - expr.get_break_expr ()->accept_vis (*this); -} - void DefaultResolver::visit (AST::RangeFromToExpr &expr) {} @@ -355,10 +200,6 @@ void DefaultResolver::visit (AST::RangeToExpr &expr) {} -void -DefaultResolver::visit (AST::RangeFullExpr &expr) -{} - void DefaultResolver::visit (AST::RangeFromToInclExpr &expr) {} @@ -415,28 +256,6 @@ void DefaultResolver::visit (AST::AsyncBlockExpr &expr) {} -void -DefaultResolver::visit (AST::LetStmt &let_stmt) -{ - let_stmt.get_pattern ()->accept_vis (*this); - - if (let_stmt.has_type ()) - let_stmt.get_type ()->accept_vis (*this); - - if (let_stmt.has_init_expr ()) - let_stmt.get_init_expr ()->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::ExprStmt &stmt) -{ - stmt.get_expr ()->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::Token &) -{} - void DefaultResolver::visit (AST::DelimTokenTree &) {} @@ -449,10 +268,6 @@ void DefaultResolver::visit (AST::IdentifierExpr &expr) {} -void -DefaultResolver::visit (AST::Lifetime &) -{} - void DefaultResolver::visit (AST::LifetimeParam &) {} @@ -465,10 +280,6 @@ void DefaultResolver::visit (AST::PathInExpression &) {} -void -DefaultResolver::visit (AST::TypePathSegment &) -{} - void DefaultResolver::visit (AST::TypePathSegmentGeneric &) {} @@ -513,10 +324,6 @@ void DefaultResolver::visit (AST::StructExprStruct &) {} -void -DefaultResolver::visit (AST::StructExprFieldIdentifier &) -{} - void DefaultResolver::visit (AST::StructExprStructFields &) {} @@ -623,10 +430,6 @@ void DefaultResolver::visit (AST::ExternalFunctionItem &) {} -void -DefaultResolver::visit (AST::MacroMatchFragment &) -{} - void DefaultResolver::visit (AST::MacroMatchRepetition &) {} @@ -651,14 +454,6 @@ void DefaultResolver::visit (AST::MetaItemSeq &) {} -void -DefaultResolver::visit (AST::MetaWord &) -{} - -void -DefaultResolver::visit (AST::MetaNameValueStr &) -{} - void DefaultResolver::visit (AST::MetaListPaths &) {} @@ -667,29 +462,6 @@ void DefaultResolver::visit (AST::MetaListNameValueStr &) {} -void -DefaultResolver::visit (AST::LiteralPattern &) -{} - -void -DefaultResolver::visit (AST::IdentifierPattern &pattern) -{ - if (pattern.has_pattern_to_bind ()) - pattern.get_pattern_to_bind ()->accept_vis (*this); -} - -void -DefaultResolver::visit (AST::WildcardPattern &) -{} - -void -DefaultResolver::visit (AST::RestPattern &) -{} - -void -DefaultResolver::visit (AST::RangePatternBoundLiteral &) -{} - void DefaultResolver::visit (AST::RangePatternBoundPath &) {} @@ -790,10 +562,6 @@ void DefaultResolver::visit (AST::TupleType &) {} -void -DefaultResolver::visit (AST::NeverType &) -{} - void DefaultResolver::visit (AST::RawPointerType &) {} @@ -810,10 +578,6 @@ void DefaultResolver::visit (AST::SliceType &) {} -void -DefaultResolver::visit (AST::InferredType &) -{} - void DefaultResolver::visit (AST::BareFunctionType &) {} diff --git a/gcc/rust/resolve/rust-default-resolver.h b/gcc/rust/resolve/rust-default-resolver.h index 49255d3bc26..20dbff8e110 100644 --- a/gcc/rust/resolve/rust-default-resolver.h +++ b/gcc/rust/resolve/rust-default-resolver.h @@ -32,9 +32,11 @@ namespace Resolver2_0 { * visiting each node's subnodes - a block's statements, a function call's * arguments... */ -class DefaultResolver : public AST::ASTVisitor +class DefaultResolver : public AST::DefaultASTVisitor { public: + using AST::DefaultASTVisitor::visit; + virtual ~DefaultResolver () {} // First, our lexical scope expressions - these visit their sub nodes, always @@ -51,41 +53,17 @@ public: // type dec nodes, which visit their fields or variants by default void visit (AST::StructStruct &); - void visit (AST::TupleStruct &); - void visit (AST::Union &); void visit (AST::Enum &); // Visitors that visit their expression node(s) - void visit (AST::BorrowExpr &); - void visit (AST::DereferenceExpr &); - void visit (AST::ErrorPropagationExpr &); - void visit (AST::NegationExpr &); - void visit (AST::ArithmeticOrLogicalExpr &); - void visit (AST::ComparisonExpr &); - void visit (AST::LazyBooleanExpr &); - void visit (AST::TypeCastExpr &); - void visit (AST::AssignmentExpr &); - void visit (AST::CompoundAssignmentExpr &); - void visit (AST::GroupedExpr &); - void visit (AST::ArrayElemsValues &); - void visit (AST::ArrayElemsCopied &); - void visit (AST::ArrayExpr &); - void visit (AST::ArrayIndexExpr &); - void visit (AST::TupleExpr &); - void visit (AST::TupleIndexExpr &); void visit (AST::StructExprFieldIdentifierValue &); void visit (AST::StructExprFieldIndexValue &); - void visit (AST::CallExpr &); - void visit (AST::MethodCallExpr &); - void visit (AST::FieldAccessExpr &); void visit (AST::ClosureExprInner &); void visit (AST::ClosureExprInnerTyped &); void visit (AST::ContinueExpr &); - void visit (AST::BreakExpr &); void visit (AST::RangeFromToExpr &); void visit (AST::RangeFromExpr &); void visit (AST::RangeToExpr &); - void visit (AST::RangeFullExpr &); void visit (AST::RangeFromToInclExpr &); void visit (AST::RangeToInclExpr &); void visit (AST::ReturnExpr &); @@ -100,19 +78,14 @@ public: void visit (AST::MatchExpr &); void visit (AST::AwaitExpr &); void visit (AST::AsyncBlockExpr &); - void visit (AST::LetStmt &); - void visit (AST::ExprStmt &); // Leaf visitors, which do nothing by default - void visit (AST::Token &); void visit (AST::DelimTokenTree &); void visit (AST::AttrInputMetaItemContainer &); void visit (AST::IdentifierExpr &); - void visit (AST::Lifetime &); void visit (AST::LifetimeParam &); void visit (AST::ConstGenericParam &); void visit (AST::PathInExpression &); - void visit (AST::TypePathSegment &); void visit (AST::TypePathSegmentGeneric &); void visit (AST::TypePathSegmentFunction &); void visit (AST::TypePath &); @@ -124,7 +97,6 @@ public: void visit (AST::MetaItemLitExpr &); void visit (AST::MetaItemPathLit &); void visit (AST::StructExprStruct &); - void visit (AST::StructExprFieldIdentifier &); void visit (AST::StructExprStructFields &); void visit (AST::StructExprStructBase &); void visit (AST::TypeParam &); @@ -149,22 +121,14 @@ public: void visit (AST::ExternalTypeItem &); void visit (AST::ExternalStaticItem &); void visit (AST::ExternalFunctionItem &); - void visit (AST::MacroMatchFragment &); void visit (AST::MacroMatchRepetition &); void visit (AST::MacroMatcher &); void visit (AST::MacroRulesDefinition &); void visit (AST::MacroInvocation &); void visit (AST::MetaItemPath &); void visit (AST::MetaItemSeq &); - void visit (AST::MetaWord &); - void visit (AST::MetaNameValueStr &); void visit (AST::MetaListPaths &); void visit (AST::MetaListNameValueStr &); - void visit (AST::LiteralPattern &); - void visit (AST::IdentifierPattern &); - void visit (AST::WildcardPattern &); - void visit (AST::RestPattern &); - void visit (AST::RangePatternBoundLiteral &); void visit (AST::RangePatternBoundPath &); void visit (AST::RangePatternBoundQualPath &); void visit (AST::RangePattern &); @@ -190,12 +154,10 @@ public: void visit (AST::ImplTraitTypeOneBound &); void visit (AST::TraitObjectTypeOneBound &); void visit (AST::TupleType &); - void visit (AST::NeverType &); void visit (AST::RawPointerType &); void visit (AST::ReferenceType &); void visit (AST::ArrayType &); void visit (AST::SliceType &); - void visit (AST::InferredType &); void visit (AST::BareFunctionType &); void visit (AST::FunctionParam &); void visit (AST::VariadicParam &); From patchwork Tue Jan 30 12:07:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892868 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=bCcDvntd; 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 4TPPjR2KHJz23fD for ; Tue, 30 Jan 2024 23:33:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 57C6438346A7 for ; Tue, 30 Jan 2024 12:33:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id AB0C03857BAF for ; Tue, 30 Jan 2024 12:11:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AB0C03857BAF 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 AB0C03857BAF Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616739; cv=none; b=lPUeQ5akXSdHoZuJxCbDpaTjE4PqWvJ99horuGIxHmHo++wqBM5oM4Ha5UvW+3DMt8nSbDPaKcusjnO3yYi7vajHcRQqvkjBUSuE9jRlK4Yppmx1ZAjMxuPUE6ejKTdkFfZxC4w21q0MTmXFXrRTRyhGYcMq4CvwVNic4dA+AQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616739; c=relaxed/simple; bh=tf0GT9VSYm5LevtW9xyoBnIx6EVcAYVnklRRGaxgZbk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nWXxJiVG/MSddwf9PPfxqcrFOzpjm2zfHCaOykdZPcjH7zphGMCDSx1oGMgH8T5T5c41rfyh2ynErJDxEdLtBDyflnBwmGlCHZcO547lpjtuSblYs30FE8pElqBA7LoVr2wPWU1h9pi//5xKmKenZGRZ1YYxOWS2WnnymHhXBkk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-40e8fec0968so45791825e9.1 for ; Tue, 30 Jan 2024 04:11:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616701; x=1707221501; 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=HaLPl/1UYgjZBJUsxd1HKA8vweBEEm9KCTWBCuRQYck=; b=bCcDvntdMjJlVPAb30RTItaXbRLKzzcjPlWrYT+/iRZWiwMFJtCf6tlyslqxS417Ua s7SVpMo/jNUlBL0RhYMIXHqdm4ISnodZKbAKt/5ff52DQ/yLmZiOqC8Fg+nQSO9rOtcs WDC+aAs+6GnvQu43X+ZQ0XDdJMvwbImGuRBENbTpYkglOQ+kuZLFp+5FkJnmUOvujOR7 Bp9sVMskdUA3P1mf0hHFCqfQQLhU7At5S0BNiEKaBoEVlv+7SKsrOBW/Bu7eBnHSZVmA Y9EN3yn2fJ+nB70co5Pc/C1yD7ydY/bTU57AKbkx5fmZIYf7ZPel7z1qcmIOGZHAjMre Vj0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616701; x=1707221501; 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=HaLPl/1UYgjZBJUsxd1HKA8vweBEEm9KCTWBCuRQYck=; b=e8agiCFn+OOEirlZG8kkPZs8nBaO83KrX2hN2lnpmBVmOU86mL4VNWFaYV/LzJ1Nej 21rMu3q9gw4nxGBkNz2MvAw75GcFYyqWVjuV/ODLriUiU5cbv6jwNYmVIcku03Q/QkSq 6U4Vo7wxIAzh6n+yuFHcM4uYDixAkz0BudmVTy8BQSco/BQ5LdizJJMaLb8CjA2CH+x2 KG6WXR2IEDdVync9CLhCR4yzeQ38MshTIHhcw9QSqauLMb8VdN0elFtWtruUQX6RMuJm Nhr3G6v8lzYGmPVikzGWzC5zTF8Hdc8Cfa7h88U03BEx8ox2HjtnhvjZjpQYZTohk9bB /X+w== X-Gm-Message-State: AOJu0YyFkoqBdIzAJdMfo4ZGGIFUxhpQYevn8udnJI07XR7VXnIipB0F XmSN8yrwS3g3OYphY4641YQ3oLSNizoTCFqf+fYHzRsQrnrzrd4lLmPnjlCUWexTFR+aPD4/q2n c2w== X-Google-Smtp-Source: AGHT+IH9Jf65BlNvZzxcKCKQpy6wN23r9sKpatoXwMMUDSLJ2vfRq0uX7UT/QmliH4bGfXwmNBRUBQ== X-Received: by 2002:a05:600c:a082:b0:40e:e703:b1ec with SMTP id jh2-20020a05600ca08200b0040ee703b1ecmr7115758wmb.24.1706616700993; Tue, 30 Jan 2024 04:11:40 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:40 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 069/101] gccrs: Make expand visitor inherit from default visitor Date: Tue, 30 Jan 2024 13:07:25 +0100 Message-ID: <20240130121026.807464-72-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: Pierre-Emmanuel Patry Many visit functions in the expand visitor simply visit their components like the default visitor. Making the expand visitor inherit from the default visitor allows us to keep all visitor in sync without having to change every visitor. gcc/rust/ChangeLog: * expand/rust-expand-visitor.cc (ExpandVisitor::go): Add call to visit on the crate. (ExpandVisitor::visit): Remove some visit functions in favor of their default visitor counterpart. * expand/rust-expand-visitor.h (class ExpandVisitor): Inherit from default visitor and remove now useless function prototypes. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/expand/rust-expand-visitor.cc | 492 +------------------------ gcc/rust/expand/rust-expand-visitor.h | 82 +---- 2 files changed, 9 insertions(+), 565 deletions(-) diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc index ad473c2dcb0..a60c4728926 100644 --- a/gcc/rust/expand/rust-expand-visitor.cc +++ b/gcc/rust/expand/rust-expand-visitor.cc @@ -39,7 +39,7 @@ is_builtin (AST::Attribute &attr) void ExpandVisitor::go (AST::Crate &crate) { - expand_inner_items (crate.items); + visit (crate); } static std::unique_ptr @@ -474,8 +474,10 @@ ExpandVisitor::expand_trait_method_decl (AST::TraitMethodDecl &decl) } void -ExpandVisitor::visit (AST::Token &) -{} +ExpandVisitor::visit (AST::Crate &crate) +{ + expand_inner_items (crate.items); +} void ExpandVisitor::visit (AST::DelimTokenTree &) @@ -489,10 +491,6 @@ void ExpandVisitor::visit (AST::IdentifierExpr &ident_expr) {} -void -ExpandVisitor::visit (AST::Lifetime &) -{} - void ExpandVisitor::visit (AST::LifetimeParam &) {} @@ -516,10 +514,6 @@ ExpandVisitor::visit (AST::PathInExpression &path) expand_generic_args (segment.get_generic_args ()); } -void -ExpandVisitor::visit (AST::TypePathSegment &) -{} - void ExpandVisitor::visit (AST::TypePathSegmentGeneric &segment) {} @@ -536,13 +530,6 @@ ExpandVisitor::visit (AST::TypePathSegmentFunction &segment) maybe_expand_type (type_path_function.get_return_type ()); } -void -ExpandVisitor::visit (AST::TypePath &path) -{ - for (auto &segment : path.get_segments ()) - visit (segment); -} - void ExpandVisitor::visit (AST::QualifiedPathInExpression &path) { @@ -585,30 +572,12 @@ void ExpandVisitor::visit (AST::MetaItemPathLit &) {} -void -ExpandVisitor::visit (AST::BorrowExpr &expr) -{ - visit (expr.get_borrowed_expr ()); -} - -void -ExpandVisitor::visit (AST::DereferenceExpr &expr) -{ - visit (expr.get_dereferenced_expr ()); -} - void ExpandVisitor::visit (AST::ErrorPropagationExpr &expr) { visit (expr.get_propagating_expr ()); } -void -ExpandVisitor::visit (AST::NegationExpr &expr) -{ - visit (expr.get_negated_expr ()); -} - void ExpandVisitor::visit (AST::ArithmeticOrLogicalExpr &expr) { @@ -630,14 +599,6 @@ ExpandVisitor::visit (AST::LazyBooleanExpr &expr) maybe_expand_expr (expr.get_right_expr ()); } -void -ExpandVisitor::visit (AST::TypeCastExpr &expr) -{ - visit (expr.get_casted_expr ()); - - visit (expr.get_type_to_cast_to ()); -} - void ExpandVisitor::visit (AST::AssignmentExpr &expr) { @@ -658,84 +619,10 @@ ExpandVisitor::visit (AST::GroupedExpr &expr) maybe_expand_expr (expr.get_expr_in_parens ()); } -void -ExpandVisitor::visit (AST::ArrayElemsValues &elems) -{ - for (auto &elem : elems.get_values ()) - visit (elem); -} - -void -ExpandVisitor::visit (AST::ArrayElemsCopied &elems) -{ - visit (elems.get_elem_to_copy ()); - visit (elems.get_num_copies ()); -} - -void -ExpandVisitor::visit (AST::ArrayExpr &expr) -{ - visit (expr.get_array_elems ()); -} - -void -ExpandVisitor::visit (AST::ArrayIndexExpr &expr) -{ - visit (expr.get_array_expr ()); - visit (expr.get_index_expr ()); -} - -void -ExpandVisitor::visit (AST::TupleExpr &expr) -{ - for (auto &element : expr.get_tuple_elems ()) - visit (element); -} - -void -ExpandVisitor::visit (AST::TupleIndexExpr &expr) -{ - visit (expr.get_tuple_expr ()); - - // We can't have macro invocations for tuple indexes, right? Need a test! -} - void ExpandVisitor::visit (AST::StructExprStruct &expr) {} -void -ExpandVisitor::visit (AST::StructExprFieldIdentifier &) -{} - -void -ExpandVisitor::visit (AST::StructExprFieldIdentifierValue &field) -{ - visit (field.get_value ()); -} - -void -ExpandVisitor::visit (AST::StructExprFieldIndexValue &field) -{ - visit (field.get_value ()); -} - -void -ExpandVisitor::visit (AST::StructExprStructFields &expr) -{ - for (auto &field : expr.get_fields ()) - visit (field); - - if (expr.has_struct_base ()) - visit (expr.get_struct_base ().get_base_struct ()); -} - -void -ExpandVisitor::visit (AST::StructExprStructBase &expr) -{ - visit (expr.get_struct_base ().get_base_struct ()); -} - void ExpandVisitor::visit (AST::CallExpr &expr) { @@ -754,12 +641,6 @@ ExpandVisitor::visit (AST::MethodCallExpr &expr) maybe_expand_expr (param); } -void -ExpandVisitor::visit (AST::FieldAccessExpr &expr) -{ - visit (expr.get_receiver_expr ()); -} - void ExpandVisitor::visit (AST::ClosureExprInner &expr) { @@ -792,93 +673,6 @@ void ExpandVisitor::visit (AST::ContinueExpr &expr) {} -void -ExpandVisitor::visit (AST::BreakExpr &expr) -{ - if (expr.has_break_expr ()) - visit (expr.get_break_expr ()); -} - -void -ExpandVisitor::visit (AST::RangeFromToExpr &expr) -{ - visit (expr.get_from_expr ()); - visit (expr.get_to_expr ()); -} - -void -ExpandVisitor::visit (AST::RangeFromExpr &expr) -{ - visit (expr.get_from_expr ()); -} - -void -ExpandVisitor::visit (AST::RangeToExpr &expr) -{ - visit (expr.get_to_expr ()); -} - -void -ExpandVisitor::visit (AST::RangeFullExpr &) -{} - -void -ExpandVisitor::visit (AST::RangeFromToInclExpr &expr) -{ - visit (expr.get_from_expr ()); - visit (expr.get_to_expr ()); -} - -void -ExpandVisitor::visit (AST::RangeToInclExpr &expr) -{ - visit (expr.get_to_expr ()); -} - -void -ExpandVisitor::visit (AST::ReturnExpr &expr) -{ - if (expr.has_returned_expr ()) - visit (expr.get_returned_expr ()); -} - -void -ExpandVisitor::visit (AST::UnsafeBlockExpr &expr) -{ - visit (expr.get_block_expr ()); -} - -void -ExpandVisitor::visit (AST::LoopExpr &expr) -{ - visit (expr.get_loop_block ()); -} - -void -ExpandVisitor::visit (AST::WhileLoopExpr &expr) -{ - visit (expr.get_predicate_expr ()); - visit (expr.get_loop_block ()); -} - -void -ExpandVisitor::visit (AST::WhileLetLoopExpr &expr) -{ - for (auto &pattern : expr.get_patterns ()) - visit (pattern); - - visit (expr.get_scrutinee_expr ()); - visit (expr.get_loop_block ()); -} - -void -ExpandVisitor::visit (AST::ForLoopExpr &expr) -{ - visit (expr.get_pattern ()); - visit (expr.get_iterator_expr ()); - visit (expr.get_loop_block ()); -} - void ExpandVisitor::visit (AST::IfExpr &expr) { @@ -932,18 +726,6 @@ ExpandVisitor::visit (AST::MatchExpr &expr) } } -void -ExpandVisitor::visit (AST::AwaitExpr &expr) -{ - visit (expr.get_awaited_expr ()); -} - -void -ExpandVisitor::visit (AST::AsyncBlockExpr &expr) -{ - visit (expr.get_block_expr ()); -} - void ExpandVisitor::visit (AST::TypeParam ¶m) { @@ -967,17 +749,6 @@ ExpandVisitor::visit (AST::TypeBoundWhereClauseItem &item) visit (bound); } -void -ExpandVisitor::visit (AST::Module &module) -{ - if (module.get_kind () == AST::Module::ModuleKind::LOADED) - { - visit_inner_attrs (module); - for (auto &item : module.get_items ()) - visit (item); - } -} - void ExpandVisitor::visit (AST::ExternCrate &crate) {} @@ -1019,12 +790,6 @@ ExpandVisitor::visit (AST::Function &function) visit (*function.get_definition ()); } -void -ExpandVisitor::visit (AST::TypeAlias &type_alias) -{ - visit (type_alias.get_type_aliased ()); -} - void ExpandVisitor::visit (AST::StructStruct &struct_item) { @@ -1071,16 +836,6 @@ ExpandVisitor::visit (AST::EnumItemDiscriminant &item) maybe_expand_expr (item.get_expr ()); } -void -ExpandVisitor::visit (AST::Enum &enum_item) -{ - for (auto &generic : enum_item.get_generic_params ()) - visit (generic); - - for (auto &variant : enum_item.get_variants ()) - variant->accept_vis (*this); -} - void ExpandVisitor::visit (AST::Union &union_item) { @@ -1134,13 +889,6 @@ ExpandVisitor::visit (AST::TraitItemConst &const_item) maybe_expand_expr (const_item.get_expr ()); } -void -ExpandVisitor::visit (AST::TraitItemType &item) -{ - for (auto &type : item.get_type_param_bounds ()) - visit (type); -} - void ExpandVisitor::visit (AST::Trait &trait) { @@ -1256,11 +1004,6 @@ ExpandVisitor::visit (AST::ExternBlock &block) block.get_extern_items (), extractor); } -// I don't think it would be possible to strip macros without expansion -void -ExpandVisitor::visit (AST::MacroMatchFragment &) -{} - void ExpandVisitor::visit (AST::MacroMatchRepetition &) {} @@ -1281,14 +1024,6 @@ void ExpandVisitor::visit (AST::MetaItemSeq &) {} -void -ExpandVisitor::visit (AST::MetaWord &) -{} - -void -ExpandVisitor::visit (AST::MetaNameValueStr &) -{} - void ExpandVisitor::visit (AST::MetaListPaths &) {} @@ -1297,152 +1032,16 @@ void ExpandVisitor::visit (AST::MetaListNameValueStr &) {} -void -ExpandVisitor::visit (AST::LiteralPattern &) -{} - -void -ExpandVisitor::visit (AST::IdentifierPattern &pattern) -{ - if (pattern.has_pattern_to_bind ()) - visit (pattern.get_pattern_to_bind ()); -} - -void -ExpandVisitor::visit (AST::WildcardPattern &) -{} - -void -ExpandVisitor::visit (AST::RestPattern &) -{} - -void -ExpandVisitor::visit (AST::RangePatternBoundLiteral &) -{} - -void -ExpandVisitor::visit (AST::RangePatternBoundPath &bound) -{ - visit (bound.get_path ()); -} - -void -ExpandVisitor::visit (AST::RangePatternBoundQualPath &bound) -{ - visit (bound.get_qualified_path ()); -} - -void -ExpandVisitor::visit (AST::RangePattern &pattern) -{ - visit (pattern.get_lower_bound ()); - visit (pattern.get_upper_bound ()); -} - -void -ExpandVisitor::visit (AST::ReferencePattern &pattern) -{ - visit (pattern.get_referenced_pattern ()); -} - -void -ExpandVisitor::visit (AST::StructPatternFieldTuplePat &field) -{ - visit (field.get_index_pattern ()); -} - -void -ExpandVisitor::visit (AST::StructPatternFieldIdentPat &field) -{ - visit (field.get_ident_pattern ()); -} - void ExpandVisitor::visit (AST::StructPatternFieldIdent &field) {} -void -ExpandVisitor::visit (AST::StructPattern &pattern) -{ - visit (pattern.get_path ()); - - for (auto &inner : - pattern.get_struct_pattern_elems ().get_struct_pattern_fields ()) - visit (inner); -} - -void -ExpandVisitor::visit (AST::TupleStructItemsNoRange &tuple_items) -{ - for (auto &pattern : tuple_items.get_patterns ()) - visit (pattern); -} - -void -ExpandVisitor::visit (AST::TupleStructItemsRange &tuple_items) -{ - for (auto &lower_pattern : tuple_items.get_lower_patterns ()) - visit (lower_pattern); - for (auto &upper_pattern : tuple_items.get_upper_patterns ()) - visit (upper_pattern); -} - -void -ExpandVisitor::visit (AST::TupleStructPattern &pattern) -{ - visit (pattern.get_path ()); - - if (pattern.has_items ()) - visit (pattern.get_items ()); -} - -void -ExpandVisitor::visit (AST::TuplePatternItemsMultiple &tuple_items) -{ - for (auto &pattern : tuple_items.get_patterns ()) - visit (pattern); -} - -void -ExpandVisitor::visit (AST::TuplePatternItemsRanged &tuple_items) -{ - for (auto &pattern : tuple_items.get_lower_patterns ()) - visit (pattern); - for (auto &pattern : tuple_items.get_upper_patterns ()) - visit (pattern); -} - -void -ExpandVisitor::visit (AST::TuplePattern &pattern) -{ - if (pattern.has_tuple_pattern_items ()) - visit (pattern.get_items ()); -} - void ExpandVisitor::visit (AST::GroupedPattern &pattern) { visit (pattern.get_pattern_in_parens ()); } -void -ExpandVisitor::visit (AST::SlicePattern &pattern) -{ - for (auto &item : pattern.get_items ()) - visit (item); -} - -void -ExpandVisitor::visit (AST::AltPattern &pattern) -{ - for (auto &alt : pattern.get_alts ()) - visit (alt); -} - -void -ExpandVisitor::visit (AST::EmptyStmt &) -{} - void ExpandVisitor::visit (AST::LetStmt &stmt) { @@ -1461,83 +1060,6 @@ ExpandVisitor::visit (AST::ExprStmt &stmt) maybe_expand_expr (stmt.get_expr ()); } -void -ExpandVisitor::visit (AST::TraitBound &bound) -{ - visit (bound.get_type_path ()); -} - -void -ExpandVisitor::visit (AST::ImplTraitType &type) -{ - for (auto &bound : type.get_type_param_bounds ()) - visit (bound); -} - -void -ExpandVisitor::visit (AST::TraitObjectType &type) -{ - for (auto &bound : type.get_type_param_bounds ()) - visit (bound); -} - -void -ExpandVisitor::visit (AST::ParenthesisedType &type) -{ - visit (type.get_type_in_parens ()); -} - -void -ExpandVisitor::visit (AST::ImplTraitTypeOneBound &type) -{ - visit (type.get_trait_bound ()); -} - -void -ExpandVisitor::visit (AST::TraitObjectTypeOneBound &type) -{ - visit (type.get_trait_bound ()); -} - -void -ExpandVisitor::visit (AST::TupleType &type) -{ - for (auto &elem : type.get_elems ()) - visit (elem); -} - -void -ExpandVisitor::visit (AST::NeverType &) -{} - -void -ExpandVisitor::visit (AST::RawPointerType &type) -{ - visit (type.get_type_pointed_to ()); -} - -void -ExpandVisitor::visit (AST::ReferenceType &type) -{ - visit (type.get_type_referenced ()); -} - -void -ExpandVisitor::visit (AST::ArrayType &type) -{ - visit (type.get_elem_type ()); -} - -void -ExpandVisitor::visit (AST::SliceType &type) -{ - visit (type.get_elem_type ()); -} - -void -ExpandVisitor::visit (AST::InferredType &) -{} - void ExpandVisitor::visit (AST::BareFunctionType &type) { @@ -1550,10 +1072,6 @@ ExpandVisitor::visit (AST::BareFunctionType &type) visit (type.get_return_type ()); } -void -ExpandVisitor::visit (AST::VariadicParam ¶m) -{} - void ExpandVisitor::visit (AST::FunctionParam ¶m) { diff --git a/gcc/rust/expand/rust-expand-visitor.h b/gcc/rust/expand/rust-expand-visitor.h index 74f2673655f..bae9b0f8fa5 100644 --- a/gcc/rust/expand/rust-expand-visitor.h +++ b/gcc/rust/expand/rust-expand-visitor.h @@ -37,7 +37,7 @@ is_derive (AST::Attribute &attr); bool is_builtin (AST::Attribute &attr); -class ExpandVisitor : public AST::ASTVisitor +class ExpandVisitor : public AST::DefaultASTVisitor { public: ExpandVisitor (MacroExpander &expander) : expander (expander) {} @@ -45,6 +45,8 @@ public: /* Expand all of the macro invocations currently contained in a crate */ void go (AST::Crate &crate); + using AST::DefaultASTVisitor::visit; + /* Maybe expand a macro invocation in lieu of an expression */ void maybe_expand_expr (std::unique_ptr &expr); @@ -186,21 +188,18 @@ public: maybe_expand_type (type); } - void visit (AST::Token &) override; + void visit (AST::Crate &crate) override; void visit (AST::DelimTokenTree &) override; void visit (AST::AttrInputMetaItemContainer &) override; void visit (AST::IdentifierExpr &ident_expr) override; - void visit (AST::Lifetime &) override; void visit (AST::LifetimeParam &) override; void visit (AST::ConstGenericParam &) override; void visit (AST::MacroInvocation ¯o_invoc) override; void visit (AST::PathInExpression &path) override; - void visit (AST::TypePathSegment &) override; void visit (AST::TypePathSegmentGeneric &segment) override; void visit (AST::TypePathSegmentFunction &segment) override; - void visit (AST::TypePath &path) override; void visit (AST::QualifiedPathInExpression &path) override; void visit (AST::QualifiedPathInType &path) override; @@ -209,84 +208,49 @@ public: void visit (AST::AttrInputMacro &) override; void visit (AST::MetaItemLitExpr &) override; void visit (AST::MetaItemPathLit &) override; - void visit (AST::BorrowExpr &expr) override; - void visit (AST::DereferenceExpr &expr) override; void visit (AST::ErrorPropagationExpr &expr) override; - void visit (AST::NegationExpr &expr) override; void visit (AST::ArithmeticOrLogicalExpr &expr) override; void visit (AST::ComparisonExpr &expr) override; void visit (AST::LazyBooleanExpr &expr) override; - void visit (AST::TypeCastExpr &expr) override; void visit (AST::AssignmentExpr &expr) override; void visit (AST::CompoundAssignmentExpr &expr) override; void visit (AST::GroupedExpr &expr) override; - void visit (AST::ArrayElemsValues &elems) override; - void visit (AST::ArrayElemsCopied &elems) override; - void visit (AST::ArrayExpr &expr) override; - void visit (AST::ArrayIndexExpr &expr) override; - void visit (AST::TupleExpr &expr) override; - void visit (AST::TupleIndexExpr &expr) override; void visit (AST::StructExprStruct &expr) override; - void visit (AST::StructExprFieldIdentifier &) override; - void visit (AST::StructExprFieldIdentifierValue &field) override; - void visit (AST::StructExprFieldIndexValue &field) override; - void visit (AST::StructExprStructFields &expr) override; - void visit (AST::StructExprStructBase &expr) override; void visit (AST::CallExpr &expr) override; void visit (AST::MethodCallExpr &expr) override; - void visit (AST::FieldAccessExpr &expr) override; void visit (AST::ClosureExprInner &expr) override; void visit (AST::BlockExpr &expr) override; void visit (AST::ClosureExprInnerTyped &expr) override; void visit (AST::ContinueExpr &expr) override; - void visit (AST::BreakExpr &expr) override; - void visit (AST::RangeFromToExpr &expr) override; - void visit (AST::RangeFromExpr &expr) override; - void visit (AST::RangeToExpr &expr) override; - void visit (AST::RangeFullExpr &) override; - void visit (AST::RangeFromToInclExpr &expr) override; - void visit (AST::RangeToInclExpr &expr) override; - void visit (AST::ReturnExpr &expr) override; - void visit (AST::UnsafeBlockExpr &expr) override; - void visit (AST::LoopExpr &expr) override; - void visit (AST::WhileLoopExpr &expr) override; - void visit (AST::WhileLetLoopExpr &expr) override; - void visit (AST::ForLoopExpr &expr) override; void visit (AST::IfExpr &expr) override; void visit (AST::IfExprConseqElse &expr) override; void visit (AST::IfLetExpr &expr) override; void visit (AST::IfLetExprConseqElse &expr) override; void visit (AST::MatchExpr &expr) override; - void visit (AST::AwaitExpr &expr) override; - void visit (AST::AsyncBlockExpr &expr) override; void visit (AST::TypeParam ¶m) override; void visit (AST::LifetimeWhereClauseItem &) override; void visit (AST::TypeBoundWhereClauseItem &item) override; - void visit (AST::Module &module) override; void visit (AST::ExternCrate &crate) override; void visit (AST::UseTreeGlob &) override; void visit (AST::UseTreeList &) override; void visit (AST::UseTreeRebind &) override; void visit (AST::UseDeclaration &use_decl) override; void visit (AST::Function &function) override; - void visit (AST::TypeAlias &type_alias) override; void visit (AST::StructStruct &struct_item) override; void visit (AST::TupleStruct &tuple_struct) override; void visit (AST::EnumItem &item) override; void visit (AST::EnumItemTuple &item) override; void visit (AST::EnumItemStruct &item) override; void visit (AST::EnumItemDiscriminant &item) override; - void visit (AST::Enum &enum_item) override; void visit (AST::Union &union_item) override; void visit (AST::ConstantItem &const_item) override; void visit (AST::StaticItem &static_item) override; void visit (AST::TraitItemFunc &item) override; void visit (AST::TraitItemMethod &item) override; void visit (AST::TraitItemConst &item) override; - void visit (AST::TraitItemType &item) override; void visit (AST::Trait &trait) override; void visit (AST::InherentImpl &impl) override; void visit (AST::TraitImpl &impl) override; @@ -296,58 +260,20 @@ public: void visit (AST::ExternBlock &block) override; // I don't think it would be possible to strip macros without expansion - void visit (AST::MacroMatchFragment &) override; void visit (AST::MacroMatchRepetition &) override; void visit (AST::MacroMatcher &) override; void visit (AST::MacroRulesDefinition &rules_def) override; void visit (AST::MetaItemPath &) override; void visit (AST::MetaItemSeq &) override; - void visit (AST::MetaWord &) override; - void visit (AST::MetaNameValueStr &) override; void visit (AST::MetaListPaths &) override; void visit (AST::MetaListNameValueStr &) override; - void visit (AST::LiteralPattern &) override; - void visit (AST::IdentifierPattern &pattern) override; - void visit (AST::WildcardPattern &) override; - void visit (AST::RestPattern &) override; - void visit (AST::RangePatternBoundLiteral &) override; - void visit (AST::RangePatternBoundPath &bound) override; - void visit (AST::RangePatternBoundQualPath &bound) override; - void visit (AST::RangePattern &pattern) override; - void visit (AST::ReferencePattern &pattern) override; - void visit (AST::StructPatternFieldTuplePat &field) override; - void visit (AST::StructPatternFieldIdentPat &field) override; void visit (AST::StructPatternFieldIdent &field) override; - void visit (AST::StructPattern &pattern) override; - void visit (AST::TupleStructItemsNoRange &tuple_items) override; - void visit (AST::TupleStructItemsRange &tuple_items) override; - void visit (AST::TupleStructPattern &pattern) override; - void visit (AST::TuplePatternItemsMultiple &tuple_items) override; - void visit (AST::TuplePatternItemsRanged &tuple_items) override; - void visit (AST::TuplePattern &pattern) override; void visit (AST::GroupedPattern &pattern) override; - void visit (AST::SlicePattern &pattern) override; - void visit (AST::AltPattern &pattern) override; - void visit (AST::EmptyStmt &) override; void visit (AST::LetStmt &stmt) override; void visit (AST::ExprStmt &stmt) override; - void visit (AST::TraitBound &bound) override; - void visit (AST::ImplTraitType &type) override; - void visit (AST::TraitObjectType &type) override; - void visit (AST::ParenthesisedType &type) override; - void visit (AST::ImplTraitTypeOneBound &type) override; - void visit (AST::TraitObjectTypeOneBound &type) override; - void visit (AST::TupleType &type) override; - void visit (AST::NeverType &) override; - void visit (AST::RawPointerType &type) override; - void visit (AST::ReferenceType &type) override; - void visit (AST::ArrayType &type) override; - void visit (AST::SliceType &type) override; - void visit (AST::InferredType &) override; void visit (AST::BareFunctionType &type) override; - void visit (AST::VariadicParam &type) override; void visit (AST::FunctionParam &type) override; void visit (AST::SelfParam &type) override; From patchwork Tue Jan 30 12:07: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: 1892895 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=FtngFyTd; 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 4TPPt74F0Lz23gZ for ; Tue, 30 Jan 2024 23:41:19 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8ECAE387087F for ; Tue, 30 Jan 2024 12:41:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 4B3A83858018 for ; Tue, 30 Jan 2024 12:11:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4B3A83858018 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 4B3A83858018 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::430 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616744; cv=none; b=ujLCFOMdDwM23m+14eBWU1bkLfjXgFK4TmQBeoe1GwUbtcStIkHePZg+Kph4OylvL3fArIeWPruHmgzDfjYAiEoXgzIVAgVEiUddkhxpZfM/oX97mj0wVrssEI3mZh1LCzgT7BPjD4zrKHVorlm2aGl7jkWfLTEkuN7txmgPL9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616744; c=relaxed/simple; bh=PF36s/5UbaQT/sqeuX7MWHoi5NROSrFoXobBPqMMKjI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=UQrSlzzSfXY47pW5VSE5gSSdPrk8rH8mdiIKNF6vvgo/sAX4ZJpL7Fc+PADVVCzyj653UjdCbz5E73ssA/j6lbJOfISSx3R5pL7XzWGSat/+l/1bbB3B3XFPHAA/DoO8QNpbdee2XaYcH3qHcNhqus6+dJPkjhZt/OwjnfWCJ44= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-33af4a0beb3so1012772f8f.2 for ; Tue, 30 Jan 2024 04:11:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616702; x=1707221502; 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=svHQW4ZOVr6UpVSxIdTwdOyoaG05ULdYbmLhY0VfzL0=; b=FtngFyTdMB+v/NNmlkRts5aU3vGg2fzurzK9Bql2fRAMghLqQprEGzz42BCtTv6JQQ 3361o3X+6q1FNtbNCueekPmSToGpMoFV+TQoYcZmLGr5ZQRC/4RV23PqtA/1NeM2r9Wl AvLEiRUlAqbLcfnXSK4NETlO7Yzl05RHsLnXw0fhMQx0UjRDAMuMiA+GDyJjiGPT/lBd H4mMAA7a6UJEKnqqUFlH1e6PGr7UNtmxucD4yxNMkdIFItIDmnJZqNObxakviK7QQAZ6 GJMJK4V4tfZaJCoxbeLg0TEA+fD1MMuoNwluVsL04tL0abUDR+rfF1DnBcpF9GnaYyOe nH/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616702; x=1707221502; 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=svHQW4ZOVr6UpVSxIdTwdOyoaG05ULdYbmLhY0VfzL0=; b=tUkZT/zvOU/8UUHKirVRaFnS9x+aIOXexXuXyNg24pVV+Eo1SUHJB4NQRK12m8UAOR wjLMEEeZFrMW53yCAPxdYuo5Py6SeucUS118/NDYXHlmg+qQX/mSrnLyIw9HEtIYCtWP Zo4rVdSqnM3nAOqbdOjM5veTQ2Av50vYKrWph7bHurEiJbtinoc2NgOWkDyYUvAUCpIg NIBb+mwVcEOPaEzUykmJnI0z2tCCIGmKx1iSJuwjV7REc2SROSFIfZk+5uWYYx62g200 xryjR5dOyaMm4EqSu7Fena+lPQCBxrbaa5siysBuSFvWprzCM0u3IClx4SihdP9G3bwO Ua8A== X-Gm-Message-State: AOJu0YylhwEjcvs64Z+eK4xVPHwjTTn3U82G62k2VOm840U3PbdeUzks oDS5K0p1YqImLLsDzZeso+kzf9PEETvgINrZ1fCNXgc3HPMbsJNy2vSPpwQ6fYioPzuT7JL83dr D0A== X-Google-Smtp-Source: AGHT+IG51tXpqSgQBT/LRoGgrjw9IYJmTqyRfI7bdtev7NBpUU8ouRywFQs2fs3EW9EzBhJEiULv/A== X-Received: by 2002:adf:d1e6:0:b0:33a:fd45:341 with SMTP id g6-20020adfd1e6000000b0033afd450341mr740530wrd.30.1706616701579; Tue, 30 Jan 2024 04:11:41 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:41 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Pierre-Emmanuel Patry Subject: [COMMITTED 070/101] gccrs: Change cfg stripper to use default visitor Date: Tue, 30 Jan 2024 13:07:26 +0100 Message-ID: <20240130121026.807464-73-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.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, 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: Pierre-Emmanuel Patry Cfg visitor used it's own visit patterns, this made the code longer than required. gcc/rust/ChangeLog: * expand/rust-cfg-strip.cc (CfgStrip::visit): Change calls from visitor to default visitor. (CfgStrip::go): Add call to visit crate. * expand/rust-cfg-strip.h (class CfgStrip): Update prototypes and remove empty ones. * ast/rust-ast-visitor.cc: add WhereClause condition check. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/ast/rust-ast-visitor.cc | 30 +- gcc/rust/expand/rust-cfg-strip.cc | 722 ++++++++---------------------- gcc/rust/expand/rust-cfg-strip.h | 52 +-- 3 files changed, 228 insertions(+), 576 deletions(-) diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc index 230a152b05b..586570377aa 100644 --- a/gcc/rust/ast/rust-ast-visitor.cc +++ b/gcc/rust/ast/rust-ast-visitor.cc @@ -776,7 +776,8 @@ DefaultASTVisitor::visit (AST::Function &function) visit (param); if (function.has_return_type ()) visit (function.get_return_type ()); - visit (function.get_where_clause ()); + if (function.has_where_clause ()) + visit (function.get_where_clause ()); if (function.has_body ()) visit (*function.get_definition ()); } @@ -788,7 +789,8 @@ DefaultASTVisitor::visit (AST::TypeAlias &type_alias) visit (type_alias.get_visibility ()); for (auto &generic : type_alias.get_generic_params ()) visit (generic); - visit (type_alias.get_where_clause ()); + if (type_alias.has_where_clause ()) + visit (type_alias.get_where_clause ()); visit (type_alias.get_type_aliased ()); } @@ -807,7 +809,8 @@ DefaultASTVisitor::visit (AST::StructStruct &struct_item) visit (struct_item.get_visibility ()); for (auto &generic : struct_item.get_generic_params ()) visit (generic); - visit (struct_item.get_where_clause ()); + if (struct_item.has_where_clause ()) + visit (struct_item.get_where_clause ()); for (auto &field : struct_item.get_fields ()) visit (field); } @@ -827,7 +830,8 @@ DefaultASTVisitor::visit (AST::TupleStruct &tuple_struct) visit (tuple_struct.get_visibility ()); for (auto &generic : tuple_struct.get_generic_params ()) visit (generic); - visit (tuple_struct.get_where_clause ()); + if (tuple_struct.has_where_clause ()) + visit (tuple_struct.get_where_clause ()); for (auto &field : tuple_struct.get_fields ()) visit (field); } @@ -869,7 +873,8 @@ DefaultASTVisitor::visit (AST::Enum &enum_item) visit (enum_item.get_visibility ()); for (auto &generic : enum_item.get_generic_params ()) visit (generic); - visit (enum_item.get_where_clause ()); + if (enum_item.has_where_clause ()) + visit (enum_item.get_where_clause ()); for (auto &item : enum_item.get_variants ()) visit (item); } @@ -881,7 +886,8 @@ DefaultASTVisitor::visit (AST::Union &union_item) visit (union_item.get_visibility ()); for (auto &generic : union_item.get_generic_params ()) visit (generic); - visit (union_item.get_where_clause ()); + if (union_item.has_where_clause ()) + visit (union_item.get_where_clause ()); for (auto &variant : union_item.get_variants ()) visit (variant); } @@ -978,7 +984,8 @@ DefaultASTVisitor::visit (AST::Trait &trait) for (auto &generic : trait.get_generic_params ()) visit (generic); - visit (trait.get_where_clause ()); + if (trait.has_where_clause ()) + visit (trait.get_where_clause ()); for (auto &bound : trait.get_type_param_bounds ()) visit (bound); @@ -995,7 +1002,8 @@ DefaultASTVisitor::visit (AST::InherentImpl &impl) for (auto &generic : impl.get_generic_params ()) visit (generic); - visit (impl.get_where_clause ()); + if (impl.has_where_clause ()) + visit (impl.get_where_clause ()); visit (impl.get_type ()); visit_inner_attrs (impl); for (auto &item : impl.get_impl_items ()) @@ -1010,7 +1018,8 @@ DefaultASTVisitor::visit (AST::TraitImpl &impl) for (auto &generic : impl.get_generic_params ()) visit (generic); - visit (impl.get_where_clause ()); + if (impl.has_where_clause ()) + visit (impl.get_where_clause ()); visit (impl.get_type ()); visit_inner_attrs (impl); for (auto &item : impl.get_impl_items ()) @@ -1048,7 +1057,8 @@ DefaultASTVisitor::visit (AST::ExternalFunctionItem &item) for (auto &generic : item.get_generic_params ()) visit (generic); - visit (item.get_where_clause ()); + if (item.has_where_clause ()) + visit (item.get_where_clause ()); for (auto ¶m : item.get_function_params ()) visit (param); diff --git a/gcc/rust/expand/rust-cfg-strip.cc b/gcc/rust/expand/rust-cfg-strip.cc index 089520182ac..22f3127f587 100644 --- a/gcc/rust/expand/rust-cfg-strip.cc +++ b/gcc/rust/expand/rust-cfg-strip.cc @@ -18,6 +18,7 @@ #include "rust-cfg-strip.h" #include "rust-ast-full.h" +#include "rust-ast-visitor.h" #include "rust-session-manager.h" #include "rust-attribute-values.h" @@ -134,6 +135,12 @@ expand_cfg_attrs (AST::AttrVec &attrs) void CfgStrip::go (AST::Crate &crate) +{ + visit (crate); +} + +void +CfgStrip::visit (AST::Crate &crate) { // expand crate cfg_attr attributes expand_cfg_attrs (crate.inner_attrs); @@ -147,17 +154,15 @@ CfgStrip::go (AST::Crate &crate) auto &items = crate.items; + AST::DefaultASTVisitor::visit (crate); for (auto it = items.begin (); it != items.end ();) { auto &item = *it; - item->accept_vis (*this); - if (item->is_marked_for_strip ()) it = items.erase (it); else it++; } - // expand module attributes? } @@ -420,25 +425,11 @@ CfgStrip::maybe_strip_trait_method_decl (AST::TraitMethodDecl &decl) maybe_strip_where_clause (decl.get_where_clause ()); } -void -CfgStrip::visit (AST::Token &) -{ - // shouldn't require? -} -void -CfgStrip::visit (AST::DelimTokenTree &) -{ - // shouldn't require? -} -void -CfgStrip::visit (AST::AttrInputMetaItemContainer &) -{ - // shouldn't require? -} void CfgStrip::visit (AST::IdentifierExpr &ident_expr) { // strip test based on outer attrs + AST::DefaultASTVisitor::visit (ident_expr); expand_cfg_attrs (ident_expr.get_outer_attrs ()); if (fails_cfg_with_expand (ident_expr.get_outer_attrs ())) { @@ -446,21 +437,6 @@ CfgStrip::visit (AST::IdentifierExpr &ident_expr) return; } } -void -CfgStrip::visit (AST::Lifetime &) -{ - // shouldn't require? -} -void -CfgStrip::visit (AST::LifetimeParam &) -{ - // supposedly does not require - cfg does nothing -} -void -CfgStrip::visit (AST::ConstGenericParam &) -{ - // likewise -} void CfgStrip::visit (AST::MacroInvocation ¯o_invoc) @@ -497,11 +473,7 @@ CfgStrip::visit (AST::PathInExpression &path) maybe_strip_generic_args (segment.get_generic_args ()); } } -void -CfgStrip::visit (AST::TypePathSegment &) -{ - // shouldn't require -} + void CfgStrip::visit (AST::TypePathSegmentGeneric &segment) { @@ -515,11 +487,11 @@ CfgStrip::visit (AST::TypePathSegmentGeneric &segment) void CfgStrip::visit (AST::TypePathSegmentFunction &segment) { + AST::DefaultASTVisitor::visit (segment); auto &type_path_function = segment.get_type_path_function (); for (auto &type : type_path_function.get_params ()) { - type->accept_vis (*this); if (type->is_marked_for_strip ()) rust_error_at (type->get_locus (), "cannot strip type in this position"); @@ -528,24 +500,19 @@ CfgStrip::visit (AST::TypePathSegmentFunction &segment) if (type_path_function.has_return_type ()) { auto &return_type = type_path_function.get_return_type (); - return_type->accept_vis (*this); if (return_type->is_marked_for_strip ()) rust_error_at (return_type->get_locus (), "cannot strip type in this position"); } } -void -CfgStrip::visit (AST::TypePath &path) -{ - // this shouldn't strip any segments, but can strip inside them - for (auto &segment : path.get_segments ()) - segment->accept_vis (*this); -} + void CfgStrip::visit (AST::QualifiedPathInExpression &path) { // initial strip test based on outer attrs + AST::DefaultASTVisitor::visit (path); + expand_cfg_attrs (path.get_outer_attrs ()); if (fails_cfg_with_expand (path.get_outer_attrs ())) { @@ -561,14 +528,14 @@ CfgStrip::visit (AST::QualifiedPathInExpression &path) maybe_strip_generic_args (segment.get_generic_args ()); } } + void CfgStrip::visit (AST::QualifiedPathInType &path) { maybe_strip_qualified_path_type (path.get_qualified_path_type ()); // this shouldn't strip any segments, but can strip inside them - for (auto &segment : path.get_segments ()) - segment->accept_vis (*this); + AST::DefaultASTVisitor::visit (path); } void @@ -582,29 +549,11 @@ CfgStrip::visit (AST::LiteralExpr &expr) return; } } -void -CfgStrip::visit (AST::AttrInputLiteral &) -{ - // shouldn't require? -} -void -CfgStrip::visit (AST::AttrInputMacro &) -{ - // shouldn't require? -} -void -CfgStrip::visit (AST::MetaItemLitExpr &) -{ - // shouldn't require? -} -void -CfgStrip::visit (AST::MetaItemPathLit &) -{ - // shouldn't require? -} + void CfgStrip::visit (AST::BorrowExpr &expr) { + AST::DefaultASTVisitor::visit (expr); // initial strip test based on outer attrs expand_cfg_attrs (expr.get_outer_attrs ()); if (fails_cfg_with_expand (expr.get_outer_attrs ())) @@ -617,7 +566,6 @@ CfgStrip::visit (AST::BorrowExpr &expr) * allowed to have external attributes in this position so can't be * stripped. */ auto &borrowed_expr = expr.get_borrowed_expr (); - borrowed_expr->accept_vis (*this); if (borrowed_expr->is_marked_for_strip ()) rust_error_at (borrowed_expr->get_locus (), "cannot strip expression in this position - outer " @@ -647,6 +595,8 @@ CfgStrip::visit (AST::DereferenceExpr &expr) void CfgStrip::visit (AST::ErrorPropagationExpr &expr) { + AST::DefaultASTVisitor::visit (expr); + // initial strip test based on outer attrs expand_cfg_attrs (expr.get_outer_attrs ()); if (fails_cfg_with_expand (expr.get_outer_attrs ())) @@ -659,7 +609,6 @@ CfgStrip::visit (AST::ErrorPropagationExpr &expr) * allowed to have external attributes in this position so can't be * stripped. */ auto &propagating_expr = expr.get_propagating_expr (); - propagating_expr->accept_vis (*this); if (propagating_expr->is_marked_for_strip ()) rust_error_at (propagating_expr->get_locus (), "cannot strip expression in this position - outer " @@ -668,6 +617,7 @@ CfgStrip::visit (AST::ErrorPropagationExpr &expr) void CfgStrip::visit (AST::NegationExpr &expr) { + AST::DefaultASTVisitor::visit (expr); // initial strip test based on outer attrs expand_cfg_attrs (expr.get_outer_attrs ()); if (fails_cfg_with_expand (expr.get_outer_attrs ())) @@ -680,7 +630,6 @@ CfgStrip::visit (AST::NegationExpr &expr) * allowed to have external attributes in this position so can't be * stripped. */ auto &negated_expr = expr.get_negated_expr (); - negated_expr->accept_vis (*this); if (negated_expr->is_marked_for_strip ()) rust_error_at (negated_expr->get_locus (), "cannot strip expression in this position - outer " @@ -689,19 +638,10 @@ CfgStrip::visit (AST::NegationExpr &expr) void CfgStrip::visit (AST::ArithmeticOrLogicalExpr &expr) { + AST::DefaultASTVisitor::visit (expr); /* outer attributes never allowed before these. while cannot strip * two direct descendant expressions, can strip ones below that */ - /* should have no possibility for outer attrs as would be parsed - * with outer expr */ - auto &l_expr = expr.get_left_expr (); - l_expr->accept_vis (*this); - - /* should syntactically not have outer attributes, though this may - * not have worked in practice */ - auto &r_expr = expr.get_right_expr (); - r_expr->accept_vis (*this); - // ensure that they are not marked for strip if (expr.get_left_expr ()->is_marked_for_strip ()) rust_error_at (expr.get_left_expr ()->get_locus (), @@ -713,21 +653,13 @@ CfgStrip::visit (AST::ArithmeticOrLogicalExpr &expr) "cannot strip expression in this position - outer " "attributes not allowed"); } + void CfgStrip::visit (AST::ComparisonExpr &expr) { /* outer attributes never allowed before these. while cannot strip * two direct descendant expressions, can strip ones below that */ - - /* should have no possibility for outer attrs as would be parsed - * with outer expr */ - auto &l_expr = expr.get_left_expr (); - l_expr->accept_vis (*this); - - /* should syntactically not have outer attributes, though this may - * not have worked in practice */ - auto &r_expr = expr.get_right_expr (); - r_expr->accept_vis (*this); + AST::DefaultASTVisitor::visit (expr); // ensure that they are not marked for strip if (expr.get_left_expr ()->is_marked_for_strip ()) @@ -740,21 +672,13 @@ CfgStrip::visit (AST::ComparisonExpr &expr) "cannot strip expression in this position - outer " "attributes not allowed"); } + void CfgStrip::visit (AST::LazyBooleanExpr &expr) { /* outer attributes never allowed before these. while cannot strip * two direct descendant expressions, can strip ones below that */ - - /* should have no possibility for outer attrs as would be parsed - * with outer expr */ - auto &l_expr = expr.get_left_expr (); - l_expr->accept_vis (*this); - - /* should syntactically not have outer attributes, though this may - * not have worked in practice */ - auto &r_expr = expr.get_right_expr (); - r_expr->accept_vis (*this); + AST::DefaultASTVisitor::visit (expr); // ensure that they are not marked for strip if (expr.get_left_expr ()->is_marked_for_strip ()) @@ -767,17 +691,15 @@ CfgStrip::visit (AST::LazyBooleanExpr &expr) "cannot strip expression in this position - outer " "attributes not allowed"); } + void CfgStrip::visit (AST::TypeCastExpr &expr) { /* outer attributes never allowed before these. while cannot strip * direct descendant expression, can strip ones below that */ + AST::DefaultASTVisitor::visit (expr); auto &casted_expr = expr.get_casted_expr (); - /* should have no possibility for outer attrs as would be parsed - * with outer expr */ - casted_expr->accept_vis (*this); - // ensure that they are not marked for strip if (casted_expr->is_marked_for_strip ()) rust_error_at (casted_expr->get_locus (), @@ -786,7 +708,6 @@ CfgStrip::visit (AST::TypeCastExpr &expr) // TODO: strip sub-types of type auto &type = expr.get_type_to_cast_to (); - type->accept_vis (*this); if (type->is_marked_for_strip ()) rust_error_at (type->get_locus (), "cannot strip type in this position"); } @@ -799,16 +720,7 @@ CfgStrip::visit (AST::AssignmentExpr &expr) expr.mark_for_strip (); return; } - - /* should have no possibility for outer attrs as would be parsed - * with outer expr */ - auto &l_expr = expr.get_left_expr (); - l_expr->accept_vis (*this); - - /* should syntactically not have outer attributes, though this may - * not have worked in practice */ - auto &r_expr = expr.get_right_expr (); - r_expr->accept_vis (*this); + AST::DefaultASTVisitor::visit (expr); // ensure that they are not marked for strip if (expr.get_left_expr ()->is_marked_for_strip ()) @@ -826,16 +738,7 @@ CfgStrip::visit (AST::CompoundAssignmentExpr &expr) { /* outer attributes never allowed before these. while cannot strip * two direct descendant expressions, can strip ones below that */ - - /* should have no possibility for outer attrs as would be parsed - * with outer expr */ - auto &l_expr = expr.get_left_expr (); - l_expr->accept_vis (*this); - - /* should syntactically not have outer attributes, though this may - * not have worked in practice */ - auto &r_expr = expr.get_right_expr (); - r_expr->accept_vis (*this); + AST::DefaultASTVisitor::visit (expr); // ensure that they are not marked for strip if (expr.get_left_expr ()->is_marked_for_strip ()) @@ -871,8 +774,9 @@ CfgStrip::visit (AST::GroupedExpr &expr) /* strip any internal sub-expressions - expression itself isn't * allowed to have external attributes in this position so can't be * stripped. */ + AST::DefaultASTVisitor::visit (expr); + auto &inner_expr = expr.get_expr_in_parens (); - inner_expr->accept_vis (*this); if (inner_expr->is_marked_for_strip ()) rust_error_at (inner_expr->get_locus (), "cannot strip expression in this position - outer " @@ -892,10 +796,10 @@ CfgStrip::visit (AST::ArrayElemsCopied &elems) * expressions" according to spec. on the other hand, it would not * make conceptual sense to be able to remove either expression. As * such, not implementing. TODO clear up the ambiguity here */ + AST::DefaultASTVisitor::visit (elems); // only intend stripping for internal sub-expressions auto &copied_expr = elems.get_elem_to_copy (); - copied_expr->accept_vis (*this); if (copied_expr->is_marked_for_strip ()) rust_error_at (copied_expr->get_locus (), "cannot strip expression in this position - outer " @@ -930,8 +834,9 @@ CfgStrip::visit (AST::ArrayExpr &expr) /* assuming you can't strip away the ArrayElems type, but can strip * internal expressions and whatever */ - expr.get_array_elems ()->accept_vis (*this); + AST::DefaultASTVisitor::visit (expr); } + void CfgStrip::visit (AST::ArrayIndexExpr &expr) { @@ -949,15 +854,15 @@ CfgStrip::visit (AST::ArrayIndexExpr &expr) /* strip any internal sub-expressions - expression itself isn't * allowed to have external attributes in this position so can't be * stripped. */ - auto &array_expr = expr.get_array_expr (); - array_expr->accept_vis (*this); + AST::DefaultASTVisitor::visit (expr); + + const auto &array_expr = expr.get_array_expr (); if (array_expr->is_marked_for_strip ()) rust_error_at (array_expr->get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); - auto &index_expr = expr.get_index_expr (); - index_expr->accept_vis (*this); + const auto &index_expr = expr.get_index_expr (); if (index_expr->is_marked_for_strip ()) rust_error_at (index_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1001,16 +906,17 @@ CfgStrip::visit (AST::TupleIndexExpr &expr) return; } + AST::DefaultASTVisitor::visit (expr); /* wouldn't strip this directly (as outer attrs should be * associated with this level), but any sub-expressions would be * stripped. Thus, no need to erase when strip check called. */ auto &tuple_expr = expr.get_tuple_expr (); - tuple_expr->accept_vis (*this); if (tuple_expr->is_marked_for_strip ()) rust_error_at (tuple_expr->get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } + void CfgStrip::visit (AST::StructExprStruct &expr) { @@ -1038,18 +944,15 @@ CfgStrip::visit (AST::StructExprStruct &expr) rust_error_at (struct_name.get_locus (), "cannot strip path in this position"); } -void -CfgStrip::visit (AST::StructExprFieldIdentifier &) -{ - // as no attrs (at moment, at least), no stripping possible -} + void CfgStrip::visit (AST::StructExprFieldIdentifierValue &field) { /* as no attrs possible (at moment, at least), only sub-expression * stripping is possible */ + AST::DefaultASTVisitor::visit (field); + auto &value = field.get_value (); - value->accept_vis (*this); if (value->is_marked_for_strip ()) rust_error_at (value->get_locus (), "cannot strip expression in this position - outer " @@ -1060,8 +963,9 @@ CfgStrip::visit (AST::StructExprFieldIndexValue &field) { /* as no attrs possible (at moment, at least), only sub-expression * stripping is possible */ + AST::DefaultASTVisitor::visit (field); + auto &value = field.get_value (); - value->accept_vis (*this); if (value->is_marked_for_strip ()) rust_error_at (value->get_locus (), "cannot strip expression in this position - outer " @@ -1098,11 +1002,7 @@ CfgStrip::visit (AST::StructExprStructFields &expr) * stripped at top level of struct fields, but I wouldn't think * that they would be, so operating under the assumption that only * sub-expressions can be stripped. */ - for (auto &field : expr.get_fields ()) - { - field->accept_vis (*this); - // shouldn't strip in this - } + AST::DefaultASTVisitor::visit (expr); /* struct base presumably can't be stripped, as the '..' is before * the expression. as such, can only strip sub-expressions. */ @@ -1116,6 +1016,7 @@ CfgStrip::visit (AST::StructExprStructFields &expr) "attributes not allowed"); } } + void CfgStrip::visit (AST::StructExprStructBase &expr) { @@ -1167,8 +1068,9 @@ CfgStrip::visit (AST::CallExpr &expr) /* should not be outer attrs on "function" expression - outer attrs * should be associated with call expr as a whole. only sub-expr * expansion is possible. */ + AST::DefaultASTVisitor::visit (expr); + auto &function = expr.get_function_expr (); - function->accept_vis (*this); if (function->is_marked_for_strip ()) rust_error_at (function->get_locus (), "cannot strip expression in this position - outer " @@ -1194,8 +1096,9 @@ CfgStrip::visit (AST::MethodCallExpr &expr) /* should not be outer attrs on "receiver" expression - outer attrs * should be associated with call expr as a whole. only sub-expr * expansion is possible. */ + AST::DefaultASTVisitor::visit (expr); + auto &receiver = expr.get_receiver_expr (); - receiver->accept_vis (*this); if (receiver->is_marked_for_strip ()) rust_error_at (receiver->get_locus (), "cannot strip expression in this position - outer " @@ -1223,8 +1126,9 @@ CfgStrip::visit (AST::FieldAccessExpr &expr) /* should not be outer attrs on "receiver" expression - outer attrs * should be associated with field expr as a whole. only sub-expr * expansion is possible. */ + AST::DefaultASTVisitor::visit (expr); + auto &receiver = expr.get_receiver_expr (); - receiver->accept_vis (*this); if (receiver->is_marked_for_strip ()) rust_error_at (receiver->get_locus (), "cannot strip expression in this position - outer " @@ -1245,9 +1149,10 @@ CfgStrip::visit (AST::ClosureExprInner &expr) * allowed by spec */ maybe_strip_closure_params (expr.get_params ()); + AST::DefaultASTVisitor::visit (expr); + // can't strip expression itself, but can strip sub-expressions auto &definition_expr = expr.get_definition_expr (); - definition_expr->accept_vis (*this); if (definition_expr->is_marked_for_strip ()) rust_error_at (definition_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1276,13 +1181,13 @@ CfgStrip::visit (AST::BlockExpr &expr) maybe_strip_pointer_allow_strip (expr.get_statements ()); + AST::DefaultASTVisitor::visit (expr); + // strip tail expression if exists - can actually fully remove it if (expr.has_tail_expr ()) { auto &tail_expr = expr.get_tail_expr (); - tail_expr->accept_vis (*this); - if (tail_expr->is_marked_for_strip ()) expr.strip_tail_expr (); } @@ -1303,9 +1208,10 @@ CfgStrip::visit (AST::ClosureExprInnerTyped &expr) * allowed by spec */ maybe_strip_closure_params (expr.get_params ()); + AST::DefaultASTVisitor::visit (expr); + // can't strip return type, but can strip sub-types auto &type = expr.get_return_type (); - type->accept_vis (*this); if (type->is_marked_for_strip ()) rust_error_at (type->get_locus (), "cannot strip type in this position"); @@ -1339,6 +1245,7 @@ CfgStrip::visit (AST::BreakExpr &expr) expr.mark_for_strip (); return; } + AST::DefaultASTVisitor::visit (expr); /* spec does not say that you can have outer attributes on * expression, so assuming you can't. stripping for sub-expressions @@ -1347,8 +1254,6 @@ CfgStrip::visit (AST::BreakExpr &expr) { auto &break_expr = expr.get_break_expr (); - break_expr->accept_vis (*this); - if (break_expr->is_marked_for_strip ()) rust_error_at (break_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1360,13 +1265,7 @@ CfgStrip::visit (AST::RangeFromToExpr &expr) { /* outer attributes never allowed before these. while cannot strip * two direct descendant expressions, can strip ones below that */ - - /* should have no possibility for outer attrs as would be parsed - * with outer expr */ - expr.get_from_expr ()->accept_vis (*this); - /* should syntactically not have outer attributes, though this may - * not have worked in practice */ - expr.get_to_expr ()->accept_vis (*this); + AST::DefaultASTVisitor::visit (expr); // ensure that they are not marked for strip if (expr.get_from_expr ()->is_marked_for_strip ()) @@ -1385,12 +1284,10 @@ CfgStrip::visit (AST::RangeFromExpr &expr) /* outer attributes never allowed before these. while cannot strip * direct descendant expression, can strip ones below that */ + AST::DefaultASTVisitor::visit (expr); /* should have no possibility for outer attrs as would be parsed * with outer expr */ auto &from_expr = expr.get_from_expr (); - - from_expr->accept_vis (*this); - if (from_expr->is_marked_for_strip ()) rust_error_at (from_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1402,34 +1299,23 @@ CfgStrip::visit (AST::RangeToExpr &expr) /* outer attributes never allowed before these. while cannot strip * direct descendant expression, can strip ones below that */ + AST::DefaultASTVisitor::visit (expr); /* should syntactically not have outer attributes, though this may * not have worked in practice */ auto &to_expr = expr.get_to_expr (); - - to_expr->accept_vis (*this); - if (to_expr->is_marked_for_strip ()) rust_error_at (to_expr->get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } -void -CfgStrip::visit (AST::RangeFullExpr &) -{ - // outer attributes never allowed before these, so no stripping -} + void CfgStrip::visit (AST::RangeFromToInclExpr &expr) { /* outer attributes never allowed before these. while cannot strip * two direct descendant expressions, can strip ones below that */ - /* should have no possibility for outer attrs as would be parsed - * with outer expr */ - expr.get_from_expr ()->accept_vis (*this); - /* should syntactically not have outer attributes, though this may - * not have worked in practice */ - expr.get_to_expr ()->accept_vis (*this); + AST::DefaultASTVisitor::visit (expr); // ensure that they are not marked for strip if (expr.get_from_expr ()->is_marked_for_strip ()) @@ -1448,12 +1334,10 @@ CfgStrip::visit (AST::RangeToInclExpr &expr) /* outer attributes never allowed before these. while cannot strip * direct descendant expression, can strip ones below that */ + AST::DefaultASTVisitor::visit (expr); /* should syntactically not have outer attributes, though this may * not have worked in practice */ auto &to_expr = expr.get_to_expr (); - - to_expr->accept_vis (*this); - if (to_expr->is_marked_for_strip ()) rust_error_at (to_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1470,15 +1354,14 @@ CfgStrip::visit (AST::ReturnExpr &expr) return; } + AST::DefaultASTVisitor::visit (expr); + /* spec does not say that you can have outer attributes on * expression, so assuming you can't. stripping for sub-expressions * is the only thing that can be done */ if (expr.has_returned_expr ()) { auto &returned_expr = expr.get_returned_expr (); - - returned_expr->accept_vis (*this); - if (returned_expr->is_marked_for_strip ()) rust_error_at (returned_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1501,9 +1384,10 @@ CfgStrip::visit (AST::UnsafeBlockExpr &expr) return; } + AST::DefaultASTVisitor::visit (expr); + // can't strip block itself, but can strip sub-expressions auto &block_expr = expr.get_block_expr (); - block_expr->accept_vis (*this); if (block_expr->is_marked_for_strip ()) rust_error_at (block_expr->get_locus (), "cannot strip block expression in this position - outer " @@ -1520,9 +1404,10 @@ CfgStrip::visit (AST::LoopExpr &expr) return; } + AST::DefaultASTVisitor::visit (expr); + // can't strip block itself, but can strip sub-expressions auto &loop_block = expr.get_loop_block (); - loop_block->accept_vis (*this); if (loop_block->is_marked_for_strip ()) rust_error_at (loop_block->get_locus (), "cannot strip block expression in this position - outer " @@ -1539,9 +1424,9 @@ CfgStrip::visit (AST::WhileLoopExpr &expr) return; } + AST::DefaultASTVisitor::visit (expr); // can't strip predicate expr itself, but can strip sub-expressions auto &predicate_expr = expr.get_predicate_expr (); - predicate_expr->accept_vis (*this); if (predicate_expr->is_marked_for_strip ()) rust_error_at (predicate_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1549,7 +1434,6 @@ CfgStrip::visit (AST::WhileLoopExpr &expr) // can't strip block itself, but can strip sub-expressions auto &loop_block = expr.get_loop_block (); - loop_block->accept_vis (*this); if (loop_block->is_marked_for_strip ()) rust_error_at (loop_block->get_locus (), "cannot strip block expression in this position - outer " @@ -1566,17 +1450,15 @@ CfgStrip::visit (AST::WhileLetLoopExpr &expr) return; } + AST::DefaultASTVisitor::visit (expr); + for (auto &pattern : expr.get_patterns ()) - { - pattern->accept_vis (*this); - if (pattern->is_marked_for_strip ()) - rust_error_at (pattern->get_locus (), - "cannot strip pattern in this position"); - } + if (pattern->is_marked_for_strip ()) + rust_error_at (pattern->get_locus (), + "cannot strip pattern in this position"); // can't strip scrutinee expr itself, but can strip sub-expressions auto &scrutinee_expr = expr.get_scrutinee_expr (); - scrutinee_expr->accept_vis (*this); if (scrutinee_expr->is_marked_for_strip ()) rust_error_at (scrutinee_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1584,7 +1466,6 @@ CfgStrip::visit (AST::WhileLetLoopExpr &expr) // can't strip block itself, but can strip sub-expressions auto &loop_block = expr.get_loop_block (); - loop_block->accept_vis (*this); if (loop_block->is_marked_for_strip ()) rust_error_at (loop_block->get_locus (), "cannot strip block expression in this position - outer " @@ -1601,16 +1482,15 @@ CfgStrip::visit (AST::ForLoopExpr &expr) return; } + AST::DefaultASTVisitor::visit (expr); // strip sub-patterns of pattern auto &pattern = expr.get_pattern (); - pattern->accept_vis (*this); if (pattern->is_marked_for_strip ()) rust_error_at (pattern->get_locus (), "cannot strip pattern in this position"); // can't strip scrutinee expr itself, but can strip sub-expressions auto &iterator_expr = expr.get_iterator_expr (); - iterator_expr->accept_vis (*this); if (iterator_expr->is_marked_for_strip ()) rust_error_at (iterator_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1618,7 +1498,6 @@ CfgStrip::visit (AST::ForLoopExpr &expr) // can't strip block itself, but can strip sub-expressions auto &loop_block = expr.get_loop_block (); - loop_block->accept_vis (*this); if (loop_block->is_marked_for_strip ()) rust_error_at (loop_block->get_locus (), "cannot strip block expression in this position - outer " @@ -1638,9 +1517,10 @@ CfgStrip::visit (AST::IfExpr &expr) return; } + AST::DefaultASTVisitor::visit (expr); + // can't strip condition expr itself, but can strip sub-expressions auto &condition_expr = expr.get_condition_expr (); - condition_expr->accept_vis (*this); if (condition_expr->is_marked_for_strip ()) rust_error_at (condition_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1648,12 +1528,12 @@ CfgStrip::visit (AST::IfExpr &expr) // can't strip if block itself, but can strip sub-expressions auto &if_block = expr.get_if_block (); - if_block->accept_vis (*this); if (if_block->is_marked_for_strip ()) rust_error_at (if_block->get_locus (), "cannot strip block expression in this position - outer " "attributes not allowed"); } + void CfgStrip::visit (AST::IfExprConseqElse &expr) { @@ -1665,9 +1545,10 @@ CfgStrip::visit (AST::IfExprConseqElse &expr) return; } + AST::DefaultASTVisitor::visit (expr); + // can't strip condition expr itself, but can strip sub-expressions auto &condition_expr = expr.get_condition_expr (); - condition_expr->accept_vis (*this); if (condition_expr->is_marked_for_strip ()) rust_error_at (condition_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1675,7 +1556,6 @@ CfgStrip::visit (AST::IfExprConseqElse &expr) // can't strip if block itself, but can strip sub-expressions auto &if_block = expr.get_if_block (); - if_block->accept_vis (*this); if (if_block->is_marked_for_strip ()) rust_error_at (if_block->get_locus (), "cannot strip block expression in this position - outer " @@ -1683,12 +1563,12 @@ CfgStrip::visit (AST::IfExprConseqElse &expr) // can't strip else block itself, but can strip sub-expressions auto &else_block = expr.get_else_block (); - else_block->accept_vis (*this); if (else_block->is_marked_for_strip ()) rust_error_at (else_block->get_locus (), "cannot strip block expression in this position - outer " "attributes not allowed"); } + void CfgStrip::visit (AST::IfLetExpr &expr) { @@ -1700,17 +1580,15 @@ CfgStrip::visit (AST::IfLetExpr &expr) return; } + AST::DefaultASTVisitor::visit (expr); + for (auto &pattern : expr.get_patterns ()) - { - pattern->accept_vis (*this); - if (pattern->is_marked_for_strip ()) - rust_error_at (pattern->get_locus (), - "cannot strip pattern in this position"); - } + if (pattern->is_marked_for_strip ()) + rust_error_at (pattern->get_locus (), + "cannot strip pattern in this position"); // can't strip value expr itself, but can strip sub-expressions auto &value_expr = expr.get_value_expr (); - value_expr->accept_vis (*this); if (value_expr->is_marked_for_strip ()) rust_error_at (value_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1718,7 +1596,6 @@ CfgStrip::visit (AST::IfLetExpr &expr) // can't strip if block itself, but can strip sub-expressions auto &if_block = expr.get_if_block (); - if_block->accept_vis (*this); if (if_block->is_marked_for_strip ()) rust_error_at (if_block->get_locus (), "cannot strip block expression in this position - outer " @@ -1735,17 +1612,15 @@ CfgStrip::visit (AST::IfLetExprConseqElse &expr) return; } + AST::DefaultASTVisitor::visit (expr); + for (auto &pattern : expr.get_patterns ()) - { - pattern->accept_vis (*this); - if (pattern->is_marked_for_strip ()) - rust_error_at (pattern->get_locus (), - "cannot strip pattern in this position"); - } + if (pattern->is_marked_for_strip ()) + rust_error_at (pattern->get_locus (), + "cannot strip pattern in this position"); // can't strip value expr itself, but can strip sub-expressions auto &value_expr = expr.get_value_expr (); - value_expr->accept_vis (*this); if (value_expr->is_marked_for_strip ()) rust_error_at (value_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1753,7 +1628,6 @@ CfgStrip::visit (AST::IfLetExprConseqElse &expr) // can't strip if block itself, but can strip sub-expressions auto &if_block = expr.get_if_block (); - if_block->accept_vis (*this); if (if_block->is_marked_for_strip ()) rust_error_at (if_block->get_locus (), "cannot strip block expression in this position - outer " @@ -1761,7 +1635,6 @@ CfgStrip::visit (AST::IfLetExprConseqElse &expr) // can't strip else block itself, but can strip sub-expressions auto &else_block = expr.get_else_block (); - else_block->accept_vis (*this); if (else_block->is_marked_for_strip ()) rust_error_at (else_block->get_locus (), "cannot strip block expression in this position - outer " @@ -1786,9 +1659,10 @@ CfgStrip::visit (AST::MatchExpr &expr) return; } + AST::DefaultASTVisitor::visit (expr); + // can't strip scrutinee expr itself, but can strip sub-expressions auto &scrutinee_expr = expr.get_scrutinee_expr (); - scrutinee_expr->accept_vis (*this); if (scrutinee_expr->is_marked_for_strip ()) rust_error_at (scrutinee_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1811,12 +1685,9 @@ CfgStrip::visit (AST::MatchExpr &expr) } for (auto &pattern : match_arm.get_patterns ()) - { - pattern->accept_vis (*this); - if (pattern->is_marked_for_strip ()) - rust_error_at (pattern->get_locus (), - "cannot strip pattern in this position"); - } + if (pattern->is_marked_for_strip ()) + rust_error_at (pattern->get_locus (), + "cannot strip pattern in this position"); /* assuming that guard expression cannot be stripped as * strictly speaking you would have to strip the whole guard to @@ -1825,7 +1696,6 @@ CfgStrip::visit (AST::MatchExpr &expr) if (match_arm.has_match_arm_guard ()) { auto &guard_expr = match_arm.get_guard_expr (); - guard_expr->accept_vis (*this); if (guard_expr->is_marked_for_strip ()) rust_error_at (guard_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1834,7 +1704,6 @@ CfgStrip::visit (AST::MatchExpr &expr) // strip sub-expressions from match cases auto &case_expr = match_case.get_expr (); - case_expr->accept_vis (*this); if (case_expr->is_marked_for_strip ()) rust_error_at (case_expr->get_locus (), "cannot strip expression in this position - outer " @@ -1844,6 +1713,7 @@ CfgStrip::visit (AST::MatchExpr &expr) ++it; } } + void CfgStrip::visit (AST::AwaitExpr &expr) { @@ -1864,6 +1734,7 @@ CfgStrip::visit (AST::AwaitExpr &expr) "cannot strip expression in this position - outer " "attributes not allowed"); } + void CfgStrip::visit (AST::AsyncBlockExpr &expr) { @@ -1875,9 +1746,10 @@ CfgStrip::visit (AST::AsyncBlockExpr &expr) return; } + AST::DefaultASTVisitor::visit (expr); + // can't strip block itself, but can strip sub-expressions auto &block_expr = expr.get_block_expr (); - block_expr->accept_vis (*this); if (block_expr->is_marked_for_strip ()) rust_error_at (block_expr->get_locus (), "cannot strip block expression in this position - outer " @@ -1889,43 +1761,24 @@ CfgStrip::visit (AST::TypeParam ¶m) { // outer attributes don't actually do anything, so ignore them - if (param.has_type_param_bounds ()) - { - // don't strip directly, only components of bounds - for (auto &bound : param.get_type_param_bounds ()) - bound->accept_vis (*this); - } + AST::DefaultASTVisitor::visit (param); - if (param.has_type ()) - { - auto &type = param.get_type (); - type->accept_vis (*this); - - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), - "cannot strip type in this position"); - } -} -void -CfgStrip::visit (AST::LifetimeWhereClauseItem &) -{ - // shouldn't require + if (param.has_type () && param.get_type ()->is_marked_for_strip ()) + rust_error_at (param.get_type ()->get_locus (), + "cannot strip type in this position"); } + void CfgStrip::visit (AST::TypeBoundWhereClauseItem &item) { // for lifetimes shouldn't require + AST::DefaultASTVisitor::visit (item); auto &type = item.get_type (); - type->accept_vis (*this); - if (type->is_marked_for_strip ()) rust_error_at (type->get_locus (), "cannot strip type in this position"); - - // don't strip directly, only components of bounds - for (auto &bound : item.get_type_param_bounds ()) - bound->accept_vis (*this); } + void CfgStrip::visit (AST::Module &module) { @@ -1952,6 +1805,7 @@ CfgStrip::visit (AST::Module &module) // strip items if required maybe_strip_pointer_allow_strip (module.get_items ()); } + void CfgStrip::visit (AST::ExternCrate &extern_crate) { @@ -1970,21 +1824,7 @@ CfgStrip::visit (AST::ExternCrate &extern_crate) extern_crate.get_locus ()); } } -void -CfgStrip::visit (AST::UseTreeGlob &) -{ - // shouldn't require? -} -void -CfgStrip::visit (AST::UseTreeList &) -{ - // shouldn't require? -} -void -CfgStrip::visit (AST::UseTreeRebind &) -{ - // shouldn't require? -} + void CfgStrip::visit (AST::UseDeclaration &use_decl) { @@ -1996,6 +1836,7 @@ CfgStrip::visit (AST::UseDeclaration &use_decl) return; } } + void CfgStrip::visit (AST::Function &function) { @@ -2007,9 +1848,7 @@ CfgStrip::visit (AST::Function &function) return; } - // just expand sub-stuff - can't actually strip generic params themselves - for (auto ¶m : function.get_generic_params ()) - param->accept_vis (*this); + AST::DefaultASTVisitor::visit (function); /* strip function parameters if required - this is specifically * allowed by spec */ @@ -2018,25 +1857,19 @@ CfgStrip::visit (AST::Function &function) if (function.has_return_type ()) { auto &return_type = function.get_return_type (); - return_type->accept_vis (*this); - if (return_type->is_marked_for_strip ()) rust_error_at (return_type->get_locus (), "cannot strip type in this position"); } - if (function.has_where_clause ()) - maybe_strip_where_clause (function.get_where_clause ()); - /* body should always exist - if error state, should have returned * before now */ // can't strip block itself, but can strip sub-expressions if (function.has_body ()) { - auto &block_expr = function.get_definition ().value (); - block_expr->accept_vis (*this); - if (block_expr->is_marked_for_strip ()) - rust_error_at (block_expr->get_locus (), + auto &block_expr = function.get_definition (); + if (block_expr.value ()->is_marked_for_strip ()) + rust_error_at (block_expr.value ()->get_locus (), "cannot strip block expression in this position - outer " "attributes not allowed"); } @@ -2053,18 +1886,13 @@ CfgStrip::visit (AST::TypeAlias &type_alias) return; } - // just expand sub-stuff - can't actually strip generic params themselves - for (auto ¶m : type_alias.get_generic_params ()) - param->accept_vis (*this); - - if (type_alias.has_where_clause ()) - maybe_strip_where_clause (type_alias.get_where_clause ()); + AST::DefaultASTVisitor::visit (type_alias); auto &type = type_alias.get_type_aliased (); - type->accept_vis (*this); if (type->is_marked_for_strip ()) rust_error_at (type->get_locus (), "cannot strip type in this position"); } + void CfgStrip::visit (AST::StructStruct &struct_item) { @@ -2076,12 +1904,7 @@ CfgStrip::visit (AST::StructStruct &struct_item) return; } - // just expand sub-stuff - can't actually strip generic params themselves - for (auto ¶m : struct_item.get_generic_params ()) - param->accept_vis (*this); - - if (struct_item.has_where_clause ()) - maybe_strip_where_clause (struct_item.get_where_clause ()); + AST::DefaultASTVisitor::visit (struct_item); } void CfgStrip::visit (AST::TupleStruct &tuple_struct) @@ -2094,16 +1917,11 @@ CfgStrip::visit (AST::TupleStruct &tuple_struct) return; } - // just expand sub-stuff - can't actually strip generic params themselves - for (auto ¶m : tuple_struct.get_generic_params ()) - param->accept_vis (*this); + AST::DefaultASTVisitor::visit (tuple_struct); /* strip struct fields if required - this is presumably * allowed by spec */ maybe_strip_tuple_fields (tuple_struct.get_fields ()); - - if (tuple_struct.has_where_clause ()) - maybe_strip_where_clause (tuple_struct.get_where_clause ()); } void CfgStrip::visit (AST::EnumItem &item) @@ -2116,6 +1934,7 @@ CfgStrip::visit (AST::EnumItem &item) return; } } + void CfgStrip::visit (AST::EnumItemTuple &item) { @@ -2131,6 +1950,7 @@ CfgStrip::visit (AST::EnumItemTuple &item) * allowed by spec */ maybe_strip_tuple_fields (item.get_tuple_fields ()); } + void CfgStrip::visit (AST::EnumItemStruct &item) { @@ -2146,6 +1966,7 @@ CfgStrip::visit (AST::EnumItemStruct &item) * allowed by spec */ maybe_strip_struct_fields (item.get_struct_fields ()); } + void CfgStrip::visit (AST::EnumItemDiscriminant &item) { @@ -2157,11 +1978,11 @@ CfgStrip::visit (AST::EnumItemDiscriminant &item) return; } + AST::DefaultASTVisitor::visit (item); /* strip any internal sub-expressions - expression itself isn't * allowed to have external attributes in this position so can't be * stripped. */ auto &expr = item.get_expr (); - expr->accept_vis (*this); if (expr->is_marked_for_strip ()) rust_error_at (expr->get_locus (), "cannot strip expression in this position - outer " @@ -2178,12 +1999,7 @@ CfgStrip::visit (AST::Enum &enum_item) return; } - // just expand sub-stuff - can't actually strip generic params themselves - for (auto ¶m : enum_item.get_generic_params ()) - param->accept_vis (*this); - - if (enum_item.has_where_clause ()) - maybe_strip_where_clause (enum_item.get_where_clause ()); + AST::DefaultASTVisitor::visit (enum_item); /* strip enum fields if required - this is presumably * allowed by spec */ @@ -2200,12 +2016,7 @@ CfgStrip::visit (AST::Union &union_item) return; } - // just expand sub-stuff - can't actually strip generic params themselves - for (auto ¶m : union_item.get_generic_params ()) - param->accept_vis (*this); - - if (union_item.has_where_clause ()) - maybe_strip_where_clause (union_item.get_where_clause ()); + AST::DefaultASTVisitor::visit (union_item); /* strip union fields if required - this is presumably * allowed by spec */ @@ -2222,10 +2033,10 @@ CfgStrip::visit (AST::ConstantItem &const_item) return; } + AST::DefaultASTVisitor::visit (const_item); + // strip any sub-types auto &type = const_item.get_type (); - type->accept_vis (*this); - if (type->is_marked_for_strip ()) rust_error_at (type->get_locus (), "cannot strip type in this position"); @@ -2235,7 +2046,6 @@ CfgStrip::visit (AST::ConstantItem &const_item) if (const_item.has_expr ()) { auto &expr = const_item.get_expr (); - expr->accept_vis (*this); if (expr->is_marked_for_strip ()) rust_error_at (expr->get_locus (), "cannot strip expression in this position - outer " @@ -2253,9 +2063,10 @@ CfgStrip::visit (AST::StaticItem &static_item) return; } + AST::DefaultASTVisitor::visit (static_item); + // strip any sub-types auto &type = static_item.get_type (); - type->accept_vis (*this); if (type->is_marked_for_strip ()) rust_error_at (type->get_locus (), "cannot strip type in this position"); @@ -2264,7 +2075,6 @@ CfgStrip::visit (AST::StaticItem &static_item) * allowed to have external attributes in this position so can't be * stripped. */ auto &expr = static_item.get_expr (); - expr->accept_vis (*this); if (expr->is_marked_for_strip ()) rust_error_at (expr->get_locus (), "cannot strip expression in this position - outer " @@ -2283,19 +2093,21 @@ CfgStrip::visit (AST::TraitItemFunc &item) maybe_strip_trait_function_decl (item.get_trait_function_decl ()); + AST::DefaultASTVisitor::visit (item); + if (item.has_definition ()) { /* strip any internal sub-expressions - expression itself isn't * allowed to have external attributes in this position so can't be * stripped. */ auto &block = item.get_definition (); - block->accept_vis (*this); if (block->is_marked_for_strip ()) rust_error_at (block->get_locus (), "cannot strip block expression in this " "position - outer attributes not allowed"); } } + void CfgStrip::visit (AST::TraitItemMethod &item) { @@ -2309,19 +2121,21 @@ CfgStrip::visit (AST::TraitItemMethod &item) maybe_strip_trait_method_decl (item.get_trait_method_decl ()); + AST::DefaultASTVisitor::visit (item); + if (item.has_definition ()) { /* strip any internal sub-expressions - expression itself isn't * allowed to have external attributes in this position so can't be * stripped. */ auto &block = item.get_definition (); - block->accept_vis (*this); if (block->is_marked_for_strip ()) rust_error_at (block->get_locus (), "cannot strip block expression in this " "position - outer attributes not allowed"); } } + void CfgStrip::visit (AST::TraitItemConst &item) { @@ -2333,9 +2147,10 @@ CfgStrip::visit (AST::TraitItemConst &item) return; } + AST::DefaultASTVisitor::visit (item); + // strip any sub-types auto &type = item.get_type (); - type->accept_vis (*this); if (type->is_marked_for_strip ()) rust_error_at (type->get_locus (), "cannot strip type in this position"); @@ -2346,13 +2161,13 @@ CfgStrip::visit (AST::TraitItemConst &item) if (item.has_expression ()) { auto &expr = item.get_expr (); - expr->accept_vis (*this); if (expr->is_marked_for_strip ()) rust_error_at (expr->get_locus (), "cannot strip expression in this position - outer " "attributes not allowed"); } } + void CfgStrip::visit (AST::TraitItemType &item) { @@ -2364,13 +2179,9 @@ CfgStrip::visit (AST::TraitItemType &item) return; } - if (item.has_type_param_bounds ()) - { - // don't strip directly, only components of bounds - for (auto &bound : item.get_type_param_bounds ()) - bound->accept_vis (*this); - } + AST::DefaultASTVisitor::visit (item); } + void CfgStrip::visit (AST::Trait &trait) { @@ -2390,22 +2201,11 @@ CfgStrip::visit (AST::Trait &trait) return; } - // just expand sub-stuff - can't actually strip generic params themselves - for (auto ¶m : trait.get_generic_params ()) - param->accept_vis (*this); - - if (trait.has_type_param_bounds ()) - { - // don't strip directly, only components of bounds - for (auto &bound : trait.get_type_param_bounds ()) - bound->accept_vis (*this); - } - - if (trait.has_where_clause ()) - maybe_strip_where_clause (trait.get_where_clause ()); + AST::DefaultASTVisitor::visit (trait); maybe_strip_pointer_allow_strip (trait.get_trait_items ()); } + void CfgStrip::visit (AST::InherentImpl &impl) { @@ -2425,21 +2225,16 @@ CfgStrip::visit (AST::InherentImpl &impl) return; } - // just expand sub-stuff - can't actually strip generic params themselves - for (auto ¶m : impl.get_generic_params ()) - param->accept_vis (*this); + AST::DefaultASTVisitor::visit (impl); auto &type = impl.get_type (); - type->accept_vis (*this); if (type->is_marked_for_strip ()) rust_error_at (type->get_locus (), "cannot strip type in this position"); - if (impl.has_where_clause ()) - maybe_strip_where_clause (impl.get_where_clause ()); - maybe_strip_pointer_allow_strip (impl.get_impl_items ()); } + void CfgStrip::visit (AST::TraitImpl &impl) { @@ -2459,13 +2254,9 @@ CfgStrip::visit (AST::TraitImpl &impl) return; } - // just expand sub-stuff - can't actually strip generic params themselves - for (auto ¶m : impl.get_generic_params ()) - param->accept_vis (*this); + AST::DefaultASTVisitor::visit (impl); auto &type = impl.get_type (); - type->accept_vis (*this); - if (type->is_marked_for_strip ()) rust_error_at (type->get_locus (), "cannot strip type in this position"); @@ -2475,9 +2266,6 @@ CfgStrip::visit (AST::TraitImpl &impl) rust_error_at (trait_path.get_locus (), "cannot strip typepath in this position"); - if (impl.has_where_clause ()) - maybe_strip_where_clause (impl.get_where_clause ()); - maybe_strip_pointer_allow_strip (impl.get_impl_items ()); } @@ -2505,9 +2293,9 @@ CfgStrip::visit (AST::ExternalStaticItem &item) return; } - auto &type = item.get_type (); - type->accept_vis (*this); + AST::DefaultASTVisitor::visit (item); + auto &type = item.get_type (); if (type->is_marked_for_strip ()) rust_error_at (type->get_locus (), "cannot strip type in this position"); } @@ -2523,9 +2311,7 @@ CfgStrip::visit (AST::ExternalFunctionItem &item) return; } - // just expand sub-stuff - can't actually strip generic params themselves - for (auto ¶m : item.get_generic_params ()) - param->accept_vis (*this); + AST::DefaultASTVisitor::visit (item); /* strip function parameters if required - this is specifically * allowed by spec */ @@ -2545,8 +2331,6 @@ CfgStrip::visit (AST::ExternalFunctionItem &item) if (!param.is_variadic ()) { auto &type = param.get_type (); - param.get_type ()->accept_vis (*this); - if (type->is_marked_for_strip ()) rust_error_at (type->get_locus (), "cannot strip type in this position"); @@ -2565,15 +2349,11 @@ CfgStrip::visit (AST::ExternalFunctionItem &item) if (item.has_return_type ()) { auto &return_type = item.get_return_type (); - return_type->accept_vis (*this); if (return_type->is_marked_for_strip ()) rust_error_at (return_type->get_locus (), "cannot strip type in this position"); } - - if (item.has_where_clause ()) - maybe_strip_where_clause (item.get_where_clause ()); } void @@ -2598,16 +2378,6 @@ CfgStrip::visit (AST::ExternBlock &block) maybe_strip_pointer_allow_strip (block.get_extern_items ()); } -// I don't think it would be possible to strip macros without expansion -void -CfgStrip::visit (AST::MacroMatchFragment &) -{} -void -CfgStrip::visit (AST::MacroMatchRepetition &) -{} -void -CfgStrip::visit (AST::MacroMatcher &) -{} void CfgStrip::visit (AST::MacroRulesDefinition &rules_def) { @@ -2620,30 +2390,6 @@ CfgStrip::visit (AST::MacroRulesDefinition &rules_def) } } -void -CfgStrip::visit (AST::MetaItemPath &) -{} -void -CfgStrip::visit (AST::MetaItemSeq &) -{} -void -CfgStrip::visit (AST::MetaWord &) -{} -void -CfgStrip::visit (AST::MetaNameValueStr &) -{} -void -CfgStrip::visit (AST::MetaListPaths &) -{} -void -CfgStrip::visit (AST::MetaListNameValueStr &) -{} - -void -CfgStrip::visit (AST::LiteralPattern &) -{ - // not possible -} void CfgStrip::visit (AST::IdentifierPattern &pattern) { @@ -2651,27 +2397,14 @@ CfgStrip::visit (AST::IdentifierPattern &pattern) if (!pattern.has_pattern_to_bind ()) return; + AST::DefaultASTVisitor::visit (pattern); + auto &sub_pattern = pattern.get_pattern_to_bind (); - sub_pattern->accept_vis (*this); if (sub_pattern->is_marked_for_strip ()) rust_error_at (sub_pattern->get_locus (), "cannot strip pattern in this position"); } -void -CfgStrip::visit (AST::WildcardPattern &) -{ - // not possible -} -void -CfgStrip::visit (AST::RestPattern &) -{ - // not possible -} -void -CfgStrip::visit (AST::RangePatternBoundLiteral &) -{ - // not possible -} + void CfgStrip::visit (AST::RangePatternBoundPath &bound) { @@ -2681,6 +2414,7 @@ CfgStrip::visit (AST::RangePatternBoundPath &bound) if (path.is_marked_for_strip ()) rust_error_at (path.get_locus (), "cannot strip path in this position"); } + void CfgStrip::visit (AST::RangePatternBoundQualPath &bound) { @@ -2690,18 +2424,13 @@ CfgStrip::visit (AST::RangePatternBoundQualPath &bound) if (path.is_marked_for_strip ()) rust_error_at (path.get_locus (), "cannot strip path in this position"); } -void -CfgStrip::visit (AST::RangePattern &pattern) -{ - // should have no capability to strip lower or upper bounds, only expand - pattern.get_lower_bound ()->accept_vis (*this); - pattern.get_upper_bound ()->accept_vis (*this); -} + void CfgStrip::visit (AST::ReferencePattern &pattern) { + AST::DefaultASTVisitor::visit (pattern); + auto &sub_pattern = pattern.get_referenced_pattern (); - sub_pattern->accept_vis (*this); if (sub_pattern->is_marked_for_strip ()) rust_error_at (sub_pattern->get_locus (), "cannot strip pattern in this position"); @@ -2717,13 +2446,15 @@ CfgStrip::visit (AST::StructPatternFieldTuplePat &field) return; } + AST::DefaultASTVisitor::visit (field); + // strip sub-patterns (can't strip top-level pattern) auto &sub_pattern = field.get_index_pattern (); - sub_pattern->accept_vis (*this); if (sub_pattern->is_marked_for_strip ()) rust_error_at (sub_pattern->get_locus (), "cannot strip pattern in this position"); } + void CfgStrip::visit (AST::StructPatternFieldIdentPat &field) { @@ -2735,9 +2466,9 @@ CfgStrip::visit (AST::StructPatternFieldIdentPat &field) return; } + AST::DefaultASTVisitor::visit (field); // strip sub-patterns (can't strip top-level pattern) auto &sub_pattern = field.get_ident_pattern (); - sub_pattern->accept_vis (*this); if (sub_pattern->is_marked_for_strip ()) rust_error_at (sub_pattern->get_locus (), "cannot strip pattern in this position"); @@ -2753,6 +2484,7 @@ CfgStrip::visit (AST::StructPatternFieldIdent &field) return; } } + void CfgStrip::visit (AST::StructPattern &pattern) { @@ -2780,14 +2512,14 @@ CfgStrip::visit (AST::StructPattern &pattern) elems.strip_etc (); } } + void CfgStrip::visit (AST::TupleStructItemsNoRange &tuple_items) { + AST::DefaultASTVisitor::visit (tuple_items); // can't strip individual patterns, only sub-patterns for (auto &pattern : tuple_items.get_patterns ()) { - pattern->accept_vis (*this); - if (pattern->is_marked_for_strip ()) rust_error_at (pattern->get_locus (), "cannot strip pattern in this position"); @@ -2797,11 +2529,10 @@ CfgStrip::visit (AST::TupleStructItemsNoRange &tuple_items) void CfgStrip::visit (AST::TupleStructItemsRange &tuple_items) { + AST::DefaultASTVisitor::visit (tuple_items); // can't strip individual patterns, only sub-patterns for (auto &lower_pattern : tuple_items.get_lower_patterns ()) { - lower_pattern->accept_vis (*this); - if (lower_pattern->is_marked_for_strip ()) rust_error_at (lower_pattern->get_locus (), "cannot strip pattern in this position"); @@ -2809,14 +2540,13 @@ CfgStrip::visit (AST::TupleStructItemsRange &tuple_items) } for (auto &upper_pattern : tuple_items.get_upper_patterns ()) { - upper_pattern->accept_vis (*this); - if (upper_pattern->is_marked_for_strip ()) rust_error_at (upper_pattern->get_locus (), "cannot strip pattern in this position"); // TODO: quit stripping now? or keep going? } } + void CfgStrip::visit (AST::TupleStructPattern &pattern) { @@ -2826,31 +2556,32 @@ CfgStrip::visit (AST::TupleStructPattern &pattern) if (path.is_marked_for_strip ()) rust_error_at (path.get_locus (), "cannot strip path in this position"); - if (pattern.has_items ()) - pattern.get_items ()->accept_vis (*this); + AST::DefaultASTVisitor::visit (pattern); } + void CfgStrip::visit (AST::TuplePatternItemsMultiple &tuple_items) { + AST::DefaultASTVisitor::visit (tuple_items); + // can't strip individual patterns, only sub-patterns for (auto &pattern : tuple_items.get_patterns ()) { - pattern->accept_vis (*this); - if (pattern->is_marked_for_strip ()) rust_error_at (pattern->get_locus (), "cannot strip pattern in this position"); // TODO: quit stripping now? or keep going? } } + void CfgStrip::visit (AST::TuplePatternItemsRanged &tuple_items) { + AST::DefaultASTVisitor::visit (tuple_items); + // can't strip individual patterns, only sub-patterns for (auto &lower_pattern : tuple_items.get_lower_patterns ()) { - lower_pattern->accept_vis (*this); - if (lower_pattern->is_marked_for_strip ()) rust_error_at (lower_pattern->get_locus (), "cannot strip pattern in this position"); @@ -2858,54 +2589,46 @@ CfgStrip::visit (AST::TuplePatternItemsRanged &tuple_items) } for (auto &upper_pattern : tuple_items.get_upper_patterns ()) { - upper_pattern->accept_vis (*this); - if (upper_pattern->is_marked_for_strip ()) rust_error_at (upper_pattern->get_locus (), "cannot strip pattern in this position"); // TODO: quit stripping now? or keep going? } } -void -CfgStrip::visit (AST::TuplePattern &pattern) -{ - if (pattern.has_tuple_pattern_items ()) - pattern.get_items ()->accept_vis (*this); -} + void CfgStrip::visit (AST::GroupedPattern &pattern) { + AST::DefaultASTVisitor::visit (pattern); // can't strip inner pattern, only sub-patterns auto &pattern_in_parens = pattern.get_pattern_in_parens (); - pattern_in_parens->accept_vis (*this); - if (pattern_in_parens->is_marked_for_strip ()) rust_error_at (pattern_in_parens->get_locus (), "cannot strip pattern in this position"); } + void CfgStrip::visit (AST::SlicePattern &pattern) { + AST::DefaultASTVisitor::visit (pattern); // can't strip individual patterns, only sub-patterns for (auto &item : pattern.get_items ()) { - item->accept_vis (*this); - if (item->is_marked_for_strip ()) rust_error_at (item->get_locus (), "cannot strip pattern in this position"); // TODO: quit stripping now? or keep going? } } + void CfgStrip::visit (AST::AltPattern &pattern) { + AST::DefaultASTVisitor::visit (pattern); // can't strip individual patterns, only sub-patterns for (auto &alt : pattern.get_alts ()) { - alt->accept_vis (*this); - if (alt->is_marked_for_strip ()) rust_error_at (alt->get_locus (), "cannot strip pattern in this position"); @@ -2913,11 +2636,6 @@ CfgStrip::visit (AST::AltPattern &pattern) } } -void -CfgStrip::visit (AST::EmptyStmt &) -{ - // assuming no outer attributes, so nothing can happen -} void CfgStrip::visit (AST::LetStmt &stmt) { @@ -2929,9 +2647,9 @@ CfgStrip::visit (AST::LetStmt &stmt) return; } + AST::DefaultASTVisitor::visit (stmt); // can't strip pattern, but call for sub-patterns auto &pattern = stmt.get_pattern (); - pattern->accept_vis (*this); if (pattern->is_marked_for_strip ()) rust_error_at (pattern->get_locus (), "cannot strip pattern in this position"); @@ -2940,7 +2658,6 @@ CfgStrip::visit (AST::LetStmt &stmt) if (stmt.has_type ()) { auto &type = stmt.get_type (); - type->accept_vis (*this); if (type->is_marked_for_strip ()) rust_error_at (type->get_locus (), @@ -2953,7 +2670,6 @@ CfgStrip::visit (AST::LetStmt &stmt) if (stmt.has_init_expr ()) { auto &init_expr = stmt.get_init_expr (); - init_expr->accept_vis (*this); if (init_expr->is_marked_for_strip ()) rust_error_at (init_expr->get_locus (), @@ -2961,6 +2677,7 @@ CfgStrip::visit (AST::LetStmt &stmt) "attributes not allowed"); } } + void CfgStrip::visit (AST::ExprStmt &stmt) { @@ -2970,9 +2687,9 @@ CfgStrip::visit (AST::ExprStmt &stmt) if (stmt.is_marked_for_strip ()) return; + AST::DefaultASTVisitor::visit (stmt); // strip if expr is to be stripped auto &expr = stmt.get_expr (); - expr->accept_vis (*this); if (expr->is_marked_for_strip ()) { stmt.mark_for_strip (); @@ -2992,93 +2709,66 @@ CfgStrip::visit (AST::TraitBound &bound) rust_error_at (path.get_locus (), "cannot strip type path in this position"); } -void -CfgStrip::visit (AST::ImplTraitType &type) -{ - // don't strip directly, only components of bounds - for (auto &bound : type.get_type_param_bounds ()) - bound->accept_vis (*this); -} -void -CfgStrip::visit (AST::TraitObjectType &type) -{ - // don't strip directly, only components of bounds - for (auto &bound : type.get_type_param_bounds ()) - bound->accept_vis (*this); -} + void CfgStrip::visit (AST::ParenthesisedType &type) { + AST::DefaultASTVisitor::visit (type); // expand but don't strip inner type auto &inner_type = type.get_type_in_parens (); - inner_type->accept_vis (*this); if (inner_type->is_marked_for_strip ()) rust_error_at (inner_type->get_locus (), "cannot strip type in this position"); } -void -CfgStrip::visit (AST::ImplTraitTypeOneBound &type) -{ - // no stripping possible - visit (type.get_trait_bound ()); -} -void -CfgStrip::visit (AST::TraitObjectTypeOneBound &type) -{ - // no stripping possible - visit (type.get_trait_bound ()); -} + void CfgStrip::visit (AST::TupleType &type) { + AST::DefaultASTVisitor::visit (type); // TODO: assuming that types can't be stripped as types don't have outer // attributes for (auto &elem_type : type.get_elems ()) { - elem_type->accept_vis (*this); if (elem_type->is_marked_for_strip ()) rust_error_at (elem_type->get_locus (), "cannot strip type in this position"); } } -void -CfgStrip::visit (AST::NeverType &) -{ - // no stripping possible -} + void CfgStrip::visit (AST::RawPointerType &type) { + AST::DefaultASTVisitor::visit (type); // expand but don't strip type pointed to auto &pointed_type = type.get_type_pointed_to (); - pointed_type->accept_vis (*this); if (pointed_type->is_marked_for_strip ()) rust_error_at (pointed_type->get_locus (), "cannot strip type in this position"); } + void CfgStrip::visit (AST::ReferenceType &type) { + AST::DefaultASTVisitor::visit (type); // expand but don't strip type referenced auto &referenced_type = type.get_type_referenced (); - referenced_type->accept_vis (*this); if (referenced_type->is_marked_for_strip ()) rust_error_at (referenced_type->get_locus (), "cannot strip type in this position"); } + void CfgStrip::visit (AST::ArrayType &type) { + AST::DefaultASTVisitor::visit (type); // expand but don't strip type referenced auto &base_type = type.get_elem_type (); - base_type->accept_vis (*this); if (base_type->is_marked_for_strip ()) rust_error_at (base_type->get_locus (), "cannot strip type in this position"); // same for expression auto &size_expr = type.get_size_expr (); - size_expr->accept_vis (*this); if (size_expr->is_marked_for_strip ()) rust_error_at (size_expr->get_locus (), "cannot strip expression in this position"); @@ -3086,22 +2776,19 @@ CfgStrip::visit (AST::ArrayType &type) void CfgStrip::visit (AST::SliceType &type) { + AST::DefaultASTVisitor::visit (type); // expand but don't strip elem type auto &elem_type = type.get_elem_type (); - elem_type->accept_vis (*this); if (elem_type->is_marked_for_strip ()) rust_error_at (elem_type->get_locus (), "cannot strip type in this position"); } -void -CfgStrip::visit (AST::InferredType &) -{ - // none possible -} + void CfgStrip::visit (AST::BareFunctionType &type) { // seem to be no generics + AST::DefaultASTVisitor::visit (type); // presumably function params can be stripped auto ¶ms = type.get_function_params (); @@ -3118,8 +2805,6 @@ CfgStrip::visit (AST::BareFunctionType &type) } auto &type = param.get_type (); - type->accept_vis (*this); - if (type->is_marked_for_strip ()) rust_error_at (type->get_locus (), "cannot strip type in this position"); @@ -3137,7 +2822,6 @@ CfgStrip::visit (AST::BareFunctionType &type) // In that case, we need to handle AST::TypeNoBounds on top of just // AST::Types auto &return_type = type.get_return_type (); - return_type->accept_vis (*this); if (return_type->is_marked_for_strip ()) rust_error_at (return_type->get_locus (), "cannot strip type in this position"); @@ -3146,22 +2830,14 @@ CfgStrip::visit (AST::BareFunctionType &type) // no where clause, apparently } -void -CfgStrip::visit (AST::VariadicParam &type) -{} - -void -CfgStrip::visit (AST::FunctionParam &type) -{} - void CfgStrip::visit (AST::SelfParam ¶m) { + AST::DefaultASTVisitor::visit (param); + if (param.has_type ()) { auto &type = param.get_type (); - type->accept_vis (*this); - if (type->is_marked_for_strip ()) rust_error_at (type->get_locus (), "cannot strip type in this position"); diff --git a/gcc/rust/expand/rust-cfg-strip.h b/gcc/rust/expand/rust-cfg-strip.h index 32dbee6f780..6b968b31d05 100644 --- a/gcc/rust/expand/rust-cfg-strip.h +++ b/gcc/rust/expand/rust-cfg-strip.h @@ -22,10 +22,12 @@ namespace Rust { // Visitor used to maybe_strip attributes. -class CfgStrip : public AST::ASTVisitor +class CfgStrip : public AST::DefaultASTVisitor { private: public: + using DefaultASTVisitor::visit; + CfgStrip () {} /* Run the AttrVisitor on an entire crate */ @@ -63,29 +65,18 @@ public: } } - void visit (AST::Token &) override; - void visit (AST::DelimTokenTree &) override; - void visit (AST::AttrInputMetaItemContainer &) override; + void visit (AST::Crate &crate) override; void visit (AST::IdentifierExpr &ident_expr) override; - void visit (AST::Lifetime &) override; - void visit (AST::LifetimeParam &) override; - void visit (AST::ConstGenericParam &) override; void visit (AST::MacroInvocation ¯o_invoc) override; void visit (AST::PathInExpression &path) override; - void visit (AST::TypePathSegment &) override; void visit (AST::TypePathSegmentGeneric &segment) override; void visit (AST::TypePathSegmentFunction &segment) override; - void visit (AST::TypePath &path) override; void visit (AST::QualifiedPathInExpression &path) override; void visit (AST::QualifiedPathInType &path) override; void visit (AST::LiteralExpr &expr) override; - void visit (AST::AttrInputLiteral &) override; - void visit (AST::AttrInputMacro &) override; - void visit (AST::MetaItemLitExpr &) override; - void visit (AST::MetaItemPathLit &) override; void visit (AST::BorrowExpr &expr) override; void visit (AST::DereferenceExpr &expr) override; void visit (AST::ErrorPropagationExpr &expr) override; @@ -104,7 +95,6 @@ public: void visit (AST::TupleExpr &expr) override; void visit (AST::TupleIndexExpr &expr) override; void visit (AST::StructExprStruct &expr) override; - void visit (AST::StructExprFieldIdentifier &) override; void visit (AST::StructExprFieldIdentifierValue &field) override; void visit (AST::StructExprFieldIndexValue &field) override; @@ -123,7 +113,6 @@ public: void visit (AST::RangeFromToExpr &expr) override; void visit (AST::RangeFromExpr &expr) override; void visit (AST::RangeToExpr &expr) override; - void visit (AST::RangeFullExpr &) override; void visit (AST::RangeFromToInclExpr &expr) override; void visit (AST::RangeToInclExpr &expr) override; void visit (AST::ReturnExpr &expr) override; @@ -140,13 +129,9 @@ public: void visit (AST::AwaitExpr &expr) override; void visit (AST::AsyncBlockExpr &expr) override; void visit (AST::TypeParam ¶m) override; - void visit (AST::LifetimeWhereClauseItem &) override; void visit (AST::TypeBoundWhereClauseItem &item) override; void visit (AST::Module &module) override; void visit (AST::ExternCrate &crate) override; - void visit (AST::UseTreeGlob &) override; - void visit (AST::UseTreeList &) override; - void visit (AST::UseTreeRebind &) override; void visit (AST::UseDeclaration &use_decl) override; void visit (AST::Function &function) override; void visit (AST::TypeAlias &type_alias) override; @@ -173,24 +158,10 @@ public: void visit (AST::ExternBlock &block) override; // I don't think it would be possible to strip macros without expansion - void visit (AST::MacroMatchFragment &) override; - void visit (AST::MacroMatchRepetition &) override; - void visit (AST::MacroMatcher &) override; void visit (AST::MacroRulesDefinition &rules_def) override; - void visit (AST::MetaItemPath &) override; - void visit (AST::MetaItemSeq &) override; - void visit (AST::MetaWord &) override; - void visit (AST::MetaNameValueStr &) override; - void visit (AST::MetaListPaths &) override; - void visit (AST::MetaListNameValueStr &) override; - void visit (AST::LiteralPattern &) override; void visit (AST::IdentifierPattern &pattern) override; - void visit (AST::WildcardPattern &) override; - void visit (AST::RestPattern &) override; - void visit (AST::RangePatternBoundLiteral &) override; void visit (AST::RangePatternBoundPath &bound) override; void visit (AST::RangePatternBoundQualPath &bound) override; - void visit (AST::RangePattern &pattern) override; void visit (AST::ReferencePattern &pattern) override; void visit (AST::StructPatternFieldTuplePat &field) override; void visit (AST::StructPatternFieldIdentPat &field) override; @@ -201,31 +172,26 @@ public: void visit (AST::TupleStructPattern &pattern) override; void visit (AST::TuplePatternItemsMultiple &tuple_items) override; void visit (AST::TuplePatternItemsRanged &tuple_items) override; - void visit (AST::TuplePattern &pattern) override; void visit (AST::GroupedPattern &pattern) override; void visit (AST::SlicePattern &pattern) override; void visit (AST::AltPattern &pattern) override; - void visit (AST::EmptyStmt &) override; void visit (AST::LetStmt &stmt) override; void visit (AST::ExprStmt &stmt) override; void visit (AST::TraitBound &bound) override; - void visit (AST::ImplTraitType &type) override; - void visit (AST::TraitObjectType &type) override; void visit (AST::ParenthesisedType &type) override; - void visit (AST::ImplTraitTypeOneBound &type) override; - void visit (AST::TraitObjectTypeOneBound &type) override; void visit (AST::TupleType &type) override; - void visit (AST::NeverType &) override; void visit (AST::RawPointerType &type) override; void visit (AST::ReferenceType &type) override; void visit (AST::ArrayType &type) override; void visit (AST::SliceType &type) override; - void visit (AST::InferredType &) override; void visit (AST::BareFunctionType &type) override; - void visit (AST::VariadicParam &type) override; - void visit (AST::FunctionParam &type) override; void visit (AST::SelfParam &type) override; + + template void visit (T &item) + { + DefaultASTVisitor::visit (item); + } }; } // namespace Rust From patchwork Tue Jan 30 12:07:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892904 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=FoK4jJtX; 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 4TPPxC4WpPz23gZ for ; Tue, 30 Jan 2024 23:43:59 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7F787387547B for ; Tue, 30 Jan 2024 12:43:57 +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 8BEC23857705 for ; Tue, 30 Jan 2024 12:11:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8BEC23857705 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 8BEC23857705 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=1706616751; cv=none; b=eM1NMVtJ6uf42/kgxUzw9/4bohO9DXamCOF9zL45vRXm693NVlWTtjsgCzZbwXb6IdDf6QeB9sLHHQkPd01C12EFVWfDUAF+gMzT9jc4LBmGpNPSw8aDeB4CVMlY5jfFlvGECrdhx/BoGbez4uVjMhuA1R07I9bqCiJb0jD9UCY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616751; c=relaxed/simple; bh=SyLSnjGmAd/B8MT0i0weOcH7Ffm9jJaqBV8/roBexOI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=EV0uZ7hvwF5nfxAnJcgNqG+gPG/habHVqDrscqqlqnMWx5O+xwdkeMPL7LLUjplXwdPg5Qpaog2fSdJqi4uGEGCf9kMWNT3yQfgS3FfUrKMU4baQq5P4L11Bv9sxc7ruiPvFebBoeSSOG7WiIxACKLFovQbzjq/QGCG1Ul2lyr4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-40eebe7767cso31014905e9.1 for ; Tue, 30 Jan 2024 04:11:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616703; x=1707221503; 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=lwxEWujRnQIh8vJNgpoR0d7qlGYsvBIdMke/MAVY2w8=; b=FoK4jJtXW40M7UX0Hd/LHtm2aNHl8WrXDyx9N1r278w2KS/Di6ukAYlY1qwAhJpNg7 eSCn/z5MIBNb1pkfKfMPh49JzKs7faIltb9pkO9rVxWIVnAX3AMlotx6Eu31CYXg0m6E BEe78vXPs+QL8Bsfq/9STwIbftd0PXeVY3dOxT9+GfAz3Of3uKrBC5jG7sburf7FvNAq Nq1A2W8ujrE6YcT2V/iqbkcM8xcdV5iZM4wyqz/YpyhXcbj5n2BZVKrZZyNatTWbj7yN 7CoG6JWs+waxMGH7QjtqEHo2wtSLsETa6IE1JG1MPoK+kuqBa9TVYqT7OCbDm5E+RwA6 J6ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616703; x=1707221503; 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=lwxEWujRnQIh8vJNgpoR0d7qlGYsvBIdMke/MAVY2w8=; b=f3YXmc7f46wHEUTmLOnFa91gZU3VTODSNT7enSJHkS8Pu7qTpKle+E7l+BvdjIqhoV KFWhPYkil/g4HA/cvXr4xcJbNV9K7sdzbPi0Jyd0U4dgAZ0z8JQnyFvnqBzHYRfSn+VG Hh5+p3Nu0jdS/Ur7VLZOLIkMqhJtQt4Ma4mVF/ysvNuwiB4iSuR/HwZj0qCMlxfSeWn7 Tt3/+JSRjlFjYxlgZF7aZ7AhCyqBXhcQsTkp1nSkm6HTmrnWg5hiCyJuDxyVHNDkX9cW WOsOjemQ4Dqec/mmDSkTrISc27RxSIveD8b8vHTjdc4pgOi1EZBoq/FGqaxh3a3Om1PW uTtQ== X-Gm-Message-State: AOJu0YzNs3GptWtL09sLcW3fJokiaxGqc6d0I5PZXbHD8yOP+SbfdRpN /8s5Y/QWUXEpjyLNmgk7BGSNIiLAUExcCLpBEvVEMn4JFrDwrKfMDa7402sLRtYy7425Z/oVCdQ 8sA== X-Google-Smtp-Source: AGHT+IErsyxJeDzZGujwGdilVmxbSFWg8zz2DCN4CfTcfNBf9KiJnWwEFqCf3B1GInvaOVV0wFkbDw== X-Received: by 2002:a05:600c:4685:b0:40e:b195:6bf3 with SMTP id p5-20020a05600c468500b0040eb1956bf3mr7869697wmo.2.1706616702332; Tue, 30 Jan 2024 04:11:42 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:41 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen , =?utf-8?q?Marc_Poulhi=C3=A8s?= Subject: [COMMITTED 071/101] gccrs: refactor builtins initialization and attributes Date: Tue, 30 Jan 2024 13:07:27 +0100 Message-ID: <20240130121026.807464-74-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=-13.7 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, SCC_5_SHORT_WORD_LINES, 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 This commit performs builtin initialization in a more "GCC-y" way, similarly to what the D frontend is doing. This way, we no longer have to worry about invalid attributes or types when initializing them by hand. Also add attributes support through LANG_HOOKS_COMMON_ATTRIBUTE_TABLE lang hook. Most of these changes are based on D frontend. gcc/rust/ChangeLog: * Make-lang.in (GRS_OBJS): Add rust-attribs.o. * backend/rust-builtins.cc (builtin_const, builtin_noreturn) (builtin_novops): Remove. (BuiltinsContext::lookup_simple_builtin): Adjust. (BuiltinsContext::setup_overflow_fns): Remove. (BuiltinsContext::define_function_type): Set builtin type to errormark so the builtin is considered unavailable. (BuiltinsContext::setup_math_fns): Remove. (BuiltinsContext::setup_atomic_fns): Remove. (build_c_type_nodes): Refactor based on D frontend. (BuiltinsContext::define_builtin_types): Likewise. (DEF_PRIMITIVE_TYPE): New. (DEF_FUNCTION_TYPE_0): New. (DEF_FUNCTION_TYPE_1): New. (DEF_FUNCTION_TYPE_2): New. (DEF_FUNCTION_TYPE_3): New. (DEF_FUNCTION_TYPE_4): New. (DEF_FUNCTION_TYPE_5): New. (DEF_FUNCTION_TYPE_6): New. (DEF_FUNCTION_TYPE_7): New. (DEF_FUNCTION_TYPE_8): New. (DEF_FUNCTION_TYPE_9): New. (DEF_FUNCTION_TYPE_10): New. (DEF_FUNCTION_TYPE_11): New. (DEF_FUNCTION_TYPE_VAR_0): New. (DEF_FUNCTION_TYPE_VAR_1): New. (DEF_FUNCTION_TYPE_VAR_2): New. (DEF_FUNCTION_TYPE_VAR_3): New. (DEF_FUNCTION_TYPE_VAR_4): New. (DEF_FUNCTION_TYPE_VAR_5): New. (DEF_FUNCTION_TYPE_VAR_6): New. (DEF_FUNCTION_TYPE_VAR_7): New. (DEF_FUNCTION_TYPE_VAR_11): New. (DEF_POINTER_TYPE): New. (BuiltinsContext::setup): Adjust. (BuiltinsContext::define_builtin_attributes): New. (DEF_ATTR_NULL_TREE): New. (DEF_ATTR_INT): New. (DEF_ATTR_STRING): New. (DEF_ATTR_IDENT): New. (DEF_ATTR_TREE_LIST): New. (handle_flags): Remove. (BuiltinsContext::define_builtins): New. (DEF_BUILTIN): New. (BuiltinsContext::define_builtin): Remove. (BuiltinsContext::register_rust_mappings): New. Add all missing builtins. (BuiltinsContext::lookup_gcc_builtin): Adjust. * backend/rust-builtins.h (DEF_PRIMITIVE_TYPE): New. (DEF_FUNCTION_TYPE_0): New. (DEF_FUNCTION_TYPE_1): New. (DEF_FUNCTION_TYPE_2): New. (DEF_FUNCTION_TYPE_3): New. (DEF_FUNCTION_TYPE_4): New. (DEF_FUNCTION_TYPE_5): New. (DEF_FUNCTION_TYPE_6): New. (DEF_FUNCTION_TYPE_7): New. (DEF_FUNCTION_TYPE_8): New. (DEF_FUNCTION_TYPE_9): New. (DEF_FUNCTION_TYPE_10): New. (DEF_FUNCTION_TYPE_11): New. (DEF_FUNCTION_TYPE_VAR_0): New. (DEF_FUNCTION_TYPE_VAR_1): New. (DEF_FUNCTION_TYPE_VAR_2): New. (DEF_FUNCTION_TYPE_VAR_3): New. (DEF_FUNCTION_TYPE_VAR_4): New. (DEF_FUNCTION_TYPE_VAR_5): New. (DEF_FUNCTION_TYPE_VAR_6): New. (DEF_FUNCTION_TYPE_VAR_7): New. (DEF_FUNCTION_TYPE_VAR_11): New. (DEF_POINTER_TYPE): New. (DEF_ATTR_NULL_TREE): New. (DEF_ATTR_INT): New. (DEF_ATTR_STRING): New. (DEF_ATTR_IDENT): New. (DEF_ATTR_TREE_LIST): New. * backend/rust-compile-intrinsic.cc (Intrinsics::compile): Add comment. (op_with_overflow_inner): Adjust. (copy_handler_inner): Adjust. (prefetch_data_handler): Adjust. (build_atomic_builtin_name): Adjust. (atomic_load_handler_inner): Adjust. (uninit_handler): Adjust. (move_val_init_handler): Adjust. (expect_handler_inner): Adjust. * rust-gcc.cc (fetch_overflow_builtins): Adjust. * rust-lang.cc (rust_localize_identifier): Adjust. (LANG_HOOKS_COMMON_ATTRIBUTE_TABLE): New. * rust-attribs.cc: New file. gcc/testsuite/ChangeLog: * rust/compile/torture/intrinsics-4.rs: Adjust. * rust/compile/torture/intrinsics-math.rs: Adjust. * rust/execute/torture/atomic_load.rs: Adjust. * rust/execute/torture/atomic_store.rs: Adjust. * rust/compile/torture/intrinsics-1.rs: Removed. * rust/compile/torture/builtin_abort.rs: New test. * rust/execute/torture/builtin_abort.rs: New test. Signed-off-by: Marc Poulhiès Co-authored-by: Arthur Cohen --- gcc/rust/Make-lang.in | 1 + gcc/rust/backend/rust-builtins.cc | 524 ++++++++++-------- gcc/rust/backend/rust-builtins.h | 118 +++- gcc/rust/backend/rust-compile-intrinsic.cc | 68 ++- gcc/rust/rust-attribs.cc | 370 +++++++++++++ gcc/rust/rust-gcc.cc | 8 +- gcc/rust/rust-lang.cc | 6 + .../rust/compile/torture/builtin_abort.rs | 18 + .../rust/compile/torture/intrinsics-1.rs | 22 - .../rust/compile/torture/intrinsics-4.rs | 2 +- .../rust/compile/torture/intrinsics-math.rs | 80 +-- .../rust/execute/torture/atomic_load.rs | 4 +- .../rust/execute/torture/atomic_store.rs | 4 +- .../rust/execute/torture/builtin_abort.rs | 14 + 14 files changed, 899 insertions(+), 340 deletions(-) create mode 100644 gcc/rust/rust-attribs.cc create mode 100644 gcc/testsuite/rust/compile/torture/builtin_abort.rs delete mode 100644 gcc/testsuite/rust/compile/torture/intrinsics-1.rs create mode 100644 gcc/testsuite/rust/execute/torture/builtin_abort.rs diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index 47cc87750be..b138ba26801 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -64,6 +64,7 @@ gccrs$(exeext): $(GCCRS_D_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a $(LIBDEPS) # The compiler proper, not driver GRS_OBJS = \ rust/rust-lang.o \ + rust/rust-attribs.o \ rust/rust-object-export.o \ rust/rust-linemap.o \ rust/rust-diagnostics.o \ diff --git a/gcc/rust/backend/rust-builtins.cc b/gcc/rust/backend/rust-builtins.cc index cd06379fcb0..1a87f869206 100644 --- a/gcc/rust/backend/rust-builtins.cc +++ b/gcc/rust/backend/rust-builtins.cc @@ -14,15 +14,16 @@ // along with GCC; see the file COPYING3. If not see // . +#include "rust-diagnostics.h" +#include "rust-system.h" #include "rust-builtins.h" +#include "target.h" +#include "stringpool.h" + namespace Rust { namespace Compile { -static const int builtin_const = 1 << 0; -static const int builtin_noreturn = 1 << 1; -static const int builtin_novops = 1 << 2; - BuiltinsContext & BuiltinsContext::get () { @@ -33,280 +34,317 @@ BuiltinsContext::get () bool BuiltinsContext::lookup_simple_builtin (const std::string &name, tree *builtin) { + auto *to_search = &name; + auto it = rust_intrinsic_to_gcc_builtin.find (name); - if (it == rust_intrinsic_to_gcc_builtin.end ()) - return false; + if (it != rust_intrinsic_to_gcc_builtin.end ()) + to_search = &it->second; - return lookup_gcc_builtin (it->second, builtin); + return lookup_gcc_builtin (*to_search, builtin); } BuiltinsContext::BuiltinsContext () { setup (); } +/** + * Define a function type according to `builtin-types.def` + * + * *Heavily* inspired by the D frontend's `def_fn_type` function + */ void -BuiltinsContext::setup_overflow_fns () +BuiltinsContext::define_function_type (Type def_idx, Type ret_idx, + bool is_variadic, size_t n, ...) { - tree overflow_type - = build_varargs_function_type_list (boolean_type_node, NULL_TREE); - - define_builtin ("add_overflow", BUILT_IN_ADD_OVERFLOW, - "__builtin_add_overflow", "add_overflow", overflow_type, 0); - define_builtin ("sub_overflow", BUILT_IN_SUB_OVERFLOW, - "__builtin_sub_overflow", "sub_overflow", overflow_type, 0); - define_builtin ("mul_overflow", BUILT_IN_MUL_OVERFLOW, - "__builtin_mul_overflow", "mul_overflow", overflow_type, 0); + va_list list; + va_start (list, n); + + auto args = std::vector (); + + for (size_t i = 0; i < n; i++) + { + // The argument is an enum Type, but it's promoted to int when passed + // though '...'. + auto arg_idx = va_arg (list, int); + auto arg_type = builtin_types[arg_idx]; + + args.emplace_back (arg_type); + } + + auto return_type = builtin_types[ret_idx]; + if (return_type == error_mark_node) + { + // Mark the builtin as not available. + builtin_types[def_idx] = error_mark_node; + va_end (list); + return; + } + + auto fn_type = NULL_TREE; + if (is_variadic) + fn_type = build_varargs_function_type_array (return_type, n, args.data ()); + else + fn_type = build_function_type_array (return_type, n, args.data ()); + + builtin_types[def_idx] = fn_type; + va_end (list); } -void -BuiltinsContext::setup_math_fns () +// Taken directly from the D frontend +static void +build_c_type_nodes (void) { - tree fn_type_f32_to_f32 - = build_function_type_list (float_type_node, float_type_node, NULL_TREE); - tree fn_type_f64_to_f64 - = build_function_type_list (double_type_node, double_type_node, NULL_TREE); - tree fn_type_f32_f32_to_f32 - = build_function_type_list (float_type_node, float_type_node, - float_type_node, NULL_TREE); - tree fn_type_f64_f64_to_f64 - = build_function_type_list (double_type_node, double_type_node, - double_type_node, NULL_TREE); - tree fn_type_f32_i32_to_f32 - = build_function_type_list (float_type_node, float_type_node, - integer_type_node, NULL_TREE); - tree fn_type_f64_i32_to_f64 - = build_function_type_list (double_type_node, double_type_node, - integer_type_node, NULL_TREE); - - define_builtin ("sqrtf32", BUILT_IN_SQRTF, "__builtin_sqrtf", "sqrtf", - fn_type_f32_to_f32, builtin_const); - define_builtin ("sqrtf64", BUILT_IN_SQRT, "__builtin_sqrt", "sqrt", - fn_type_f64_to_f64, builtin_const); - - define_builtin ("powif32", BUILT_IN_POWIF, "__builtin_powif", "powif", - fn_type_f32_i32_to_f32, builtin_const); - define_builtin ("powif64", BUILT_IN_POWI, "__builtin_powi", "powi", - fn_type_f64_i32_to_f64, builtin_const); - - define_builtin ("sinf32", BUILT_IN_SINF, "__builtin_sinf", "sinf", - fn_type_f32_to_f32, builtin_const); - define_builtin ("sinf64", BUILT_IN_SIN, "__builtin_sin", "sin", - fn_type_f64_to_f64, builtin_const); - - define_builtin ("cosf32", BUILT_IN_COSF, "__builtin_cosf", "cosf", - fn_type_f32_to_f32, builtin_const); - define_builtin ("cosf64", BUILT_IN_COS, "__builtin_cos", "cos", - fn_type_f64_to_f64, builtin_const); - - define_builtin ("powf32", BUILT_IN_POWF, "__builtin_powf", "powf", - fn_type_f32_f32_to_f32, builtin_const); - define_builtin ("powf64", BUILT_IN_POW, "__builtin_pow", "pow", - fn_type_f64_f64_to_f64, builtin_const); - - define_builtin ("expf32", BUILT_IN_EXPF, "__builtin_expf", "expf", - fn_type_f32_to_f32, builtin_const); - define_builtin ("expf64", BUILT_IN_EXP, "__builtin_exp", "exp", - fn_type_f64_to_f64, builtin_const); - - define_builtin ("exp2f32", BUILT_IN_EXP2F, "__builtin_exp2f", "exp2f", - fn_type_f32_to_f32, builtin_const); - define_builtin ("exp2f64", BUILT_IN_EXP2, "__builtin_exp2", "exp2", - fn_type_f64_to_f64, builtin_const); - - define_builtin ("logf32", BUILT_IN_LOGF, "__builtin_logf", "logf", - fn_type_f32_to_f32, builtin_const); - define_builtin ("logf64", BUILT_IN_LOG, "__builtin_log", "log", - fn_type_f64_to_f64, builtin_const); - - define_builtin ("log10f32", BUILT_IN_LOG10F, "__builtin_log10f", "log10f", - fn_type_f32_to_f32, builtin_const); - define_builtin ("log10f64", BUILT_IN_LOG10, "__builtin_log10", "log10", - fn_type_f64_to_f64, builtin_const); - - define_builtin ("log2f32", BUILT_IN_LOG2F, "__builtin_log2f", "log2f", - fn_type_f32_to_f32, builtin_const); - define_builtin ("log2f64", BUILT_IN_LOG2, "__builtin_log2", "log2", - fn_type_f64_to_f64, builtin_const); - - define_builtin ("fmaf32", BUILT_IN_FMAF, "__builtin_fmaf", "fmaf", - fn_type_f32_f32_to_f32, builtin_const); - define_builtin ("fmaf64", BUILT_IN_FMA, "__builtin_fma", "fma", - fn_type_f64_f64_to_f64, builtin_const); - - define_builtin ("fabsf32", BUILT_IN_FABSF, "__builtin_fabsf", "fabsf", - fn_type_f32_to_f32, builtin_const); - define_builtin ("fabsf64", BUILT_IN_FABS, "__builtin_fabs", "fabs", - fn_type_f64_to_f64, builtin_const); - - define_builtin ("minnumf32", BUILT_IN_FMINF, "__builtin_fminf", "fminf", - fn_type_f32_f32_to_f32, builtin_const); - define_builtin ("minnumf64", BUILT_IN_FMIN, "__builtin_fmin", "fmin", - fn_type_f64_f64_to_f64, builtin_const); - - define_builtin ("maxnumf32", BUILT_IN_FMAXF, "__builtin_fmaxf", "fmaxf", - fn_type_f32_f32_to_f32, builtin_const); - define_builtin ("maxnumf64", BUILT_IN_FMAX, "__builtin_fmax", "fmax", - fn_type_f64_f64_to_f64, builtin_const); - - define_builtin ("copysignf32", BUILT_IN_COPYSIGNF, "__builtin_copysignf", - "copysignf", fn_type_f32_f32_to_f32, builtin_const); - define_builtin ("copysignf64", BUILT_IN_COPYSIGN, "__builtin_copysign", - "copysign", fn_type_f64_f64_to_f64, builtin_const); - - define_builtin ("floorf32", BUILT_IN_FLOORF, "__builtin_floorf", "floorf", - fn_type_f32_to_f32, builtin_const); - define_builtin ("floorf64", BUILT_IN_FLOOR, "__builtin_floor", "floor", - fn_type_f64_to_f64, builtin_const); - - define_builtin ("ceilf32", BUILT_IN_CEILF, "__builtin_ceilf", "ceilf", - fn_type_f32_to_f32, builtin_const); - define_builtin ("ceilf64", BUILT_IN_CEIL, "__builtin_ceil", "ceil", - fn_type_f64_to_f64, builtin_const); - - define_builtin ("truncf32", BUILT_IN_TRUNCF, "__builtin_truncf", "truncf", - fn_type_f32_to_f32, builtin_const); - define_builtin ("truncf64", BUILT_IN_TRUNC, "__builtin_trunc", "trunc", - fn_type_f64_to_f64, builtin_const); - - define_builtin ("rintf32", BUILT_IN_RINTF, "__builtin_rintf", "rintf", - fn_type_f32_to_f32, builtin_const); - define_builtin ("rintf64", BUILT_IN_RINT, "__builtin_rint", "rint", - fn_type_f64_to_f64, builtin_const); - - define_builtin ("nearbyintf32", BUILT_IN_NEARBYINTF, "__builtin_nearbyintf", - "nearbyintf", fn_type_f32_to_f32, builtin_const); - define_builtin ("nearbyintf64", BUILT_IN_NEARBYINT, "__builtin_nearbyint", - "nearbyint", fn_type_f64_to_f64, builtin_const); - - define_builtin ("roundf32", BUILT_IN_ROUNDF, "__builtin_roundf", "roundf", - fn_type_f32_to_f32, builtin_const); - define_builtin ("roundf64", BUILT_IN_ROUND, "__builtin_round", "round", - fn_type_f64_to_f64, builtin_const); + string_type_node = build_pointer_type (char_type_node); + const_string_type_node = build_pointer_type ( + build_qualified_type (char_type_node, TYPE_QUAL_CONST)); + + if (strcmp (UINTMAX_TYPE, "unsigned int") == 0) + { + intmax_type_node = integer_type_node; + uintmax_type_node = unsigned_type_node; + } + else if (strcmp (UINTMAX_TYPE, "long unsigned int") == 0) + { + intmax_type_node = long_integer_type_node; + uintmax_type_node = long_unsigned_type_node; + } + else if (strcmp (UINTMAX_TYPE, "long long unsigned int") == 0) + { + intmax_type_node = long_long_integer_type_node; + uintmax_type_node = long_long_unsigned_type_node; + } + else + gcc_unreachable (); + + signed_size_type_node = signed_type_for (size_type_node); + wint_type_node = unsigned_type_node; + pid_type_node = integer_type_node; } +/** + * Define all builtin types in the `builtin_types` array + */ void -BuiltinsContext::setup_atomic_fns () +BuiltinsContext::define_builtin_types () { - auto atomic_store_type - = build_varargs_function_type_list (void_type_node, NULL_TREE); - auto atomic_load_type = [] (tree ret_type_node) { - return build_function_type_list (ret_type_node, - ptr_type_node, // const_ptr_type_node? - integer_type_node, NULL_TREE); + // This is taken directly from the D frontend's handling of builtins + auto va_list_ref_type_node = build_reference_type (va_list_type_node); + auto va_list_arg_type_node = va_list_type_node; + + build_c_type_nodes (); + + auto builtin_type_for_size = [] (int size, bool unsignedp) { + tree type = lang_hooks.types.type_for_size (size, unsignedp); + return type ? type : error_mark_node; }; - // FIXME: These should be the definition for the generic version of the - // atomic_store builtins, but I cannot get them to work properly. Revisit - // later. define_builtin ("atomic_store", BUILT_IN_ATOMIC_STORE, - // "__atomic_store", NULL, - // atomic_store_type, 0); - // define_builtin ("atomic_store_n", BUILT_IN_ATOMIC_STORE_N, - // "__atomic_store_n", - // NULL, atomic_store_type, 0); - - define_builtin ("atomic_store_1", BUILT_IN_ATOMIC_STORE_1, "__atomic_store_1", - NULL, atomic_store_type, 0); - define_builtin ("atomic_store_2", BUILT_IN_ATOMIC_STORE_2, "__atomic_store_2", - NULL, atomic_store_type, 0); - define_builtin ("atomic_store_4", BUILT_IN_ATOMIC_STORE_4, "__atomic_store_4", - NULL, atomic_store_type, 0); - define_builtin ("atomic_store_8", BUILT_IN_ATOMIC_STORE_8, "__atomic_store_8", - NULL, atomic_store_type, 0); - define_builtin ("atomic_store_16", BUILT_IN_ATOMIC_STORE_16, - "__atomic_store_16", NULL, atomic_store_type, 0); - - define_builtin ("atomic_load_1", BUILT_IN_ATOMIC_LOAD_1, "__atomic_load_1", - NULL, atomic_load_type (integer_type_node), 0); - define_builtin ("atomic_load_2", BUILT_IN_ATOMIC_LOAD_2, "__atomic_load_2", - NULL, atomic_load_type (integer_type_node), 0); - define_builtin ("atomic_load_4", BUILT_IN_ATOMIC_LOAD_4, "__atomic_load_4", - NULL, atomic_load_type (integer_type_node), 0); - define_builtin ("atomic_load_8", BUILT_IN_ATOMIC_LOAD_8, "__atomic_load_8", - NULL, atomic_load_type (integer_type_node), 0); +#define DEF_PRIMITIVE_TYPE(ENUM, VALUE) builtin_types[ENUM] = VALUE; +#define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \ + define_function_type (ENUM, RETURN, 0, 0); +#define DEF_FUNCTION_TYPE_1(ENUM, RETURN, A1) \ + define_function_type (ENUM, RETURN, 0, 1, A1); +#define DEF_FUNCTION_TYPE_2(ENUM, RETURN, A1, A2) \ + define_function_type (ENUM, RETURN, 0, 2, A1, A2); +#define DEF_FUNCTION_TYPE_3(ENUM, RETURN, A1, A2, A3) \ + define_function_type (ENUM, RETURN, 0, 3, A1, A2, A3); +#define DEF_FUNCTION_TYPE_4(ENUM, RETURN, A1, A2, A3, A4) \ + define_function_type (ENUM, RETURN, 0, 4, A1, A2, A3, A4); +#define DEF_FUNCTION_TYPE_5(ENUM, RETURN, A1, A2, A3, A4, A5) \ + define_function_type (ENUM, RETURN, 0, 5, A1, A2, A3, A4, A5); +#define DEF_FUNCTION_TYPE_6(ENUM, RETURN, A1, A2, A3, A4, A5, A6) \ + define_function_type (ENUM, RETURN, 0, 6, A1, A2, A3, A4, A5, A6); +#define DEF_FUNCTION_TYPE_7(ENUM, RETURN, A1, A2, A3, A4, A5, A6, A7) \ + define_function_type (ENUM, RETURN, 0, 7, A1, A2, A3, A4, A5, A6, A7); +#define DEF_FUNCTION_TYPE_8(ENUM, RETURN, A1, A2, A3, A4, A5, A6, A7, A8) \ + define_function_type (ENUM, RETURN, 0, 8, A1, A2, A3, A4, A5, A6, A7, A8); +#define DEF_FUNCTION_TYPE_9(ENUM, RETURN, A1, A2, A3, A4, A5, A6, A7, A8, A9) \ + define_function_type (ENUM, RETURN, 0, 9, A1, A2, A3, A4, A5, A6, A7, A8, A9); +#define DEF_FUNCTION_TYPE_10(ENUM, RETURN, A1, A2, A3, A4, A5, A6, A7, A8, A9, \ + A10) \ + define_function_type (ENUM, RETURN, 0, 10, A1, A2, A3, A4, A5, A6, A7, A8, \ + A9, A10); +#define DEF_FUNCTION_TYPE_11(ENUM, RETURN, A1, A2, A3, A4, A5, A6, A7, A8, A9, \ + A10, A11) \ + define_function_type (ENUM, RETURN, 0, 11, A1, A2, A3, A4, A5, A6, A7, A8, \ + A9, A10, A11); +#define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \ + define_function_type (ENUM, RETURN, 1, 0); +#define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, A1) \ + define_function_type (ENUM, RETURN, 1, 1, A1); +#define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, A1, A2) \ + define_function_type (ENUM, RETURN, 1, 2, A1, A2); +#define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, A1, A2, A3) \ + define_function_type (ENUM, RETURN, 1, 3, A1, A2, A3); +#define DEF_FUNCTION_TYPE_VAR_4(ENUM, RETURN, A1, A2, A3, A4) \ + define_function_type (ENUM, RETURN, 1, 4, A1, A2, A3, A4); +#define DEF_FUNCTION_TYPE_VAR_5(ENUM, RETURN, A1, A2, A3, A4, A5) \ + define_function_type (ENUM, RETURN, 1, 5, A1, A2, A3, A4, A5); +#define DEF_FUNCTION_TYPE_VAR_6(ENUM, RETURN, A1, A2, A3, A4, A5, A6) \ + define_function_type (ENUM, RETURN, 1, 6, A1, A2, A3, A4, A5, A6); +#define DEF_FUNCTION_TYPE_VAR_7(ENUM, RETURN, A1, A2, A3, A4, A5, A6, A7) \ + define_function_type (ENUM, RETURN, 1, 7, A1, A2, A3, A4, A5, A6, A7); +#define DEF_FUNCTION_TYPE_VAR_11(ENUM, RETURN, A1, A2, A3, A4, A5, A6, A7, A8, \ + A9, A10, A11) \ + define_function_type (ENUM, RETURN, 1, 11, A1, A2, A3, A4, A5, A6, A7, A8, \ + A9, A10, A11); +#define DEF_POINTER_TYPE(ENUM, TYPE) \ + builtin_types[ENUM] = build_pointer_type (builtin_types[TYPE]); + +#include "builtin-types.def" + +#undef DEF_PRIMITIVE_TYPE +#undef DEF_FUNCTION_TYPE_1 +#undef DEF_FUNCTION_TYPE_2 +#undef DEF_FUNCTION_TYPE_3 +#undef DEF_FUNCTION_TYPE_4 +#undef DEF_FUNCTION_TYPE_5 +#undef DEF_FUNCTION_TYPE_6 +#undef DEF_FUNCTION_TYPE_7 +#undef DEF_FUNCTION_TYPE_8 +#undef DEF_FUNCTION_TYPE_9 +#undef DEF_FUNCTION_TYPE_10 +#undef DEF_FUNCTION_TYPE_11 +#undef DEF_FUNCTION_TYPE_VAR_0 +#undef DEF_FUNCTION_TYPE_VAR_1 +#undef DEF_FUNCTION_TYPE_VAR_2 +#undef DEF_FUNCTION_TYPE_VAR_3 +#undef DEF_FUNCTION_TYPE_VAR_4 +#undef DEF_FUNCTION_TYPE_VAR_5 +#undef DEF_FUNCTION_TYPE_VAR_6 +#undef DEF_FUNCTION_TYPE_VAR_7 +#undef DEF_FUNCTION_TYPE_VAR_11 +#undef DEF_POINTER_TYPE + + builtin_types[Type::BT_LAST] = NULL_TREE; } +/** + * Define all builtin attributes in the `builtin_types` array + */ void -BuiltinsContext::setup () +BuiltinsContext::define_builtin_attributes () + { - setup_math_fns (); - setup_overflow_fns (); - setup_atomic_fns (); - - define_builtin ("unreachable", BUILT_IN_UNREACHABLE, "__builtin_unreachable", - NULL, build_function_type (void_type_node, void_list_node), - builtin_const | builtin_noreturn); - - define_builtin ("abort", BUILT_IN_ABORT, "__builtin_abort", "abort", - build_function_type (void_type_node, void_list_node), - builtin_const | builtin_noreturn); - - define_builtin ("breakpoint", BUILT_IN_TRAP, "__builtin_trap", "breakpoint", - build_function_type (void_type_node, void_list_node), - builtin_const | builtin_noreturn); - - define_builtin ("expect", BUILT_IN_EXPECT, "__builtin_expect", "expect", - build_function_type_list (long_integer_type_node, - long_integer_type_node, - long_integer_type_node, NULL_TREE), - builtin_const); - - define_builtin ("memcpy", BUILT_IN_MEMCPY, "__builtin_memcpy", "memcpy", - build_function_type_list (build_pointer_type (void_type_node), - build_pointer_type (void_type_node), - build_pointer_type (void_type_node), - size_type_node, NULL_TREE), - 0); - - define_builtin ("memset", BUILT_IN_MEMSET, "__builtin_memset", "memset", - build_function_type_list (void_type_node, ptr_type_node, - integer_type_node, size_type_node, - NULL_TREE), - 0); - - define_builtin ("prefetch", BUILT_IN_PREFETCH, "__builtin_prefetch", - "prefetch", - build_varargs_function_type_list ( - build_pointer_type (const_ptr_type_node), NULL_TREE), - builtin_const); + auto *built_in_attributes = builtin_attributes; + +#define DEF_ATTR_NULL_TREE(ENUM) built_in_attributes[(int) ENUM] = NULL_TREE; +#define DEF_ATTR_INT(ENUM, VALUE) \ + built_in_attributes[ENUM] = build_int_cst (NULL_TREE, VALUE); +#define DEF_ATTR_STRING(ENUM, VALUE) \ + built_in_attributes[ENUM] = build_string (strlen (VALUE), VALUE); +#define DEF_ATTR_IDENT(ENUM, STRING) \ + built_in_attributes[ENUM] = get_identifier (STRING); +#define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) \ + built_in_attributes[ENUM] \ + = tree_cons (built_in_attributes[PURPOSE], built_in_attributes[VALUE], \ + built_in_attributes[CHAIN]); +#include "builtin-attrs.def" +#undef DEF_ATTR_NULL_TREE +#undef DEF_ATTR_INT +#undef DEF_ATTR_STRING +#undef DEF_ATTR_IDENT +#undef DEF_ATTR_TREE_LIST } -static void -handle_flags (tree decl, int flags) +/** + * Define all builtin functions during the first initialization of the + * `BuiltinsContext`. + */ +void +BuiltinsContext::define_builtins () { - if (flags & builtin_const) - TREE_READONLY (decl) = 1; - if (flags & builtin_noreturn) - TREE_READONLY (decl) = 1; - if (flags & builtin_novops) - DECL_IS_NOVOPS (decl) = 1; + auto *built_in_attributes = builtin_attributes; + auto build_builtin = [this] (built_in_function fn_code, const char *fn_name, + built_in_class fn_class, tree fn_type, bool both, + bool fallback, tree attributes, bool implicit) { + if (fn_type == error_mark_node) + return; + + static auto to_skip = strlen ("__builtin_"); + + auto libname = fn_name + to_skip; + auto decl = add_builtin_function (fn_name, fn_type, fn_code, fn_class, + fallback ? libname : NULL, attributes); + + set_builtin_decl (fn_code, decl, implicit); + + builtin_functions.insert ({std::string (fn_name), decl}); + }; + +#define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, FALLBACK_P, \ + NONANSI_P, ATTRS, IMPLICIT, COND) \ + if (NAME && COND) \ + build_builtin (ENUM, NAME, CLASS, builtin_types[TYPE], BOTH_P, FALLBACK_P, \ + built_in_attributes[ATTRS], IMPLICIT); +#include "builtins.def" +#undef DEF_BUILTIN } +/** + * Register direct mappings between Rust functions and GCC builtins + */ void -BuiltinsContext::define_builtin (const std::string rust_name, - built_in_function bcode, const char *name, - const char *libname, tree fntype, int flags) +BuiltinsContext::register_rust_mappings () { - tree decl = add_builtin_function (name, fntype, bcode, BUILT_IN_NORMAL, - libname, NULL_TREE); - handle_flags (decl, flags); - set_builtin_decl (bcode, decl, true); - - this->builtin_functions_[name] = decl; - if (libname != NULL) - { - decl = add_builtin_function (libname, fntype, bcode, BUILT_IN_NORMAL, - NULL, NULL_TREE); - handle_flags (decl, flags); + rust_intrinsic_to_gcc_builtin = { + {"sinf32", "__builtin_sinf"}, + {"sqrtf32", "__builtin_sqrtf"}, + {"sqrtf64", "__builtin_sqrt"}, + {"unreachable", "__builtin_unreachable"}, + {"abort", "__builtin_abort"}, + {"sinf64", "__builtin_sin"}, + {"cosf32", "__builtin_cosf"}, + {"cosf64", "__builtin_cos"}, + {"powf32", "__builtin_powf"}, + {"powf64", "__builtin_pow"}, + {"expf32", "__builtin_expf"}, + {"expf64", "__builtin_exp"}, + {"exp2f32", "__builtin_exp2f"}, + {"exp2f64", "__builtin_exp2"}, + {"logf32", "__builtin_logf"}, + {"logf64", "__builtin_log"}, + {"log10f32", "__builtin_log10f"}, + {"log10f64", "__builtin_log10"}, + {"log2f32", "__builtin_log2f"}, + {"log2f64", "__builtin_log2"}, + {"fmaf32", "__builtin_fmaf"}, + {"fmaf64", "__builtin_fma"}, + {"fabsf32", "__builtin_fabsf"}, + {"fabsf64", "__builtin_fabs"}, + {"minnumf32", "__builtin_fminf"}, + {"minnumf64", "__builtin_fmin"}, + {"maxnumf32", "__builtin_fmaxf"}, + {"maxnumf64", "__builtin_fmax"}, + {"copysignf32", "__builtin_copysignf"}, + {"copysignf64", "__builtin_copysign"}, + {"floorf32", "__builtin_floorf"}, + {"floorf64", "__builtin_floor"}, + {"ceilf32", "__builtin_ceilf"}, + {"ceilf64", "__builtin_ceil"}, + {"truncf32", "__builtin_truncf"}, + {"truncf64", "__builtin_trunc"}, + {"rintf32", "__builtin_rintf"}, + {"rintf64", "__builtin_rint"}, + {"nearbyintf32", "__builtin_nearbyintf"}, + {"nearbyintf64", "__builtin_nearbyint"}, + {"roundf32", "__builtin_roundf"}, + {"roundf64", "__builtin_round"}, + }; +} - this->builtin_functions_[libname] = decl; - } +void +BuiltinsContext::setup () +{ + define_builtin_types (); + define_builtin_attributes (); + define_builtins (); - rust_intrinsic_to_gcc_builtin[rust_name] = name; + register_rust_mappings (); } bool BuiltinsContext::lookup_gcc_builtin (const std::string &name, tree *builtin) { - auto it = builtin_functions_.find (name); - if (it == builtin_functions_.end ()) + auto it = builtin_functions.find (name); + if (it == builtin_functions.end ()) return false; *builtin = it->second; diff --git a/gcc/rust/backend/rust-builtins.h b/gcc/rust/backend/rust-builtins.h index c2825107faf..5052edad51e 100644 --- a/gcc/rust/backend/rust-builtins.h +++ b/gcc/rust/backend/rust-builtins.h @@ -21,6 +21,7 @@ #include "rust-tree.h" #include "langhooks.h" #include "tree.h" +#include "selftest.h" namespace Rust { namespace Compile { @@ -75,6 +76,7 @@ namespace Compile { // _ => return None, // }; // Some(cx.get_intrinsic(&llvm_name)) + class BuiltinsContext { public: @@ -83,6 +85,110 @@ public: bool lookup_simple_builtin (const std::string &name, tree *builtin); private: + enum Type + { +#define DEF_PRIMITIVE_TYPE(NAME, V) NAME, +#define DEF_FUNCTION_TYPE_0(NAME, R) NAME, +#define DEF_FUNCTION_TYPE_1(NAME, R, A1) NAME, +#define DEF_FUNCTION_TYPE_2(NAME, R, A1, A2) NAME, +#define DEF_FUNCTION_TYPE_3(NAME, R, A1, A2, A3) NAME, +#define DEF_FUNCTION_TYPE_4(NAME, R, A1, A2, A3, A4) NAME, +#define DEF_FUNCTION_TYPE_5(NAME, R, A1, A2, A3, A4, A5) NAME, +#define DEF_FUNCTION_TYPE_6(NAME, R, A1, A2, A3, A4, A5, A6) NAME, +#define DEF_FUNCTION_TYPE_7(NAME, R, A1, A2, A3, A4, A5, A6, A7) NAME, +#define DEF_FUNCTION_TYPE_8(NAME, R, A1, A2, A3, A4, A5, A6, A7, A8) NAME, +#define DEF_FUNCTION_TYPE_9(NAME, R, A1, A2, A3, A4, A5, A6, A7, A8, A9) NAME, +#define DEF_FUNCTION_TYPE_10(NAME, R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) \ + NAME, +#define DEF_FUNCTION_TYPE_11(NAME, R, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, \ + A11) \ + NAME, +#define DEF_FUNCTION_TYPE_VAR_0(NAME, R) NAME, +#define DEF_FUNCTION_TYPE_VAR_1(NAME, R, A1) NAME, +#define DEF_FUNCTION_TYPE_VAR_2(NAME, R, A1, A2) NAME, +#define DEF_FUNCTION_TYPE_VAR_3(NAME, R, A1, A2, A3) NAME, +#define DEF_FUNCTION_TYPE_VAR_4(NAME, R, A1, A2, A3, A4) NAME, +#define DEF_FUNCTION_TYPE_VAR_5(NAME, R, A1, A2, A3, A4, A5) NAME, +#define DEF_FUNCTION_TYPE_VAR_6(NAME, R, A1, A2, A3, A4, A5, A6) NAME, +#define DEF_FUNCTION_TYPE_VAR_7(NAME, R, A1, A2, A3, A4, A5, A6, A7) NAME, +#define DEF_FUNCTION_TYPE_VAR_11(NAME, R, A1, A2, A3, A4, A5, A6, A7, A8, A9, \ + A10, A11) \ + NAME, +#define DEF_POINTER_TYPE(NAME, TYPE) NAME, + +#include "builtin-types.def" + +#undef DEF_PRIMITIVE_TYPE +#undef DEF_FUNCTION_TYPE_0 +#undef DEF_FUNCTION_TYPE_1 +#undef DEF_FUNCTION_TYPE_2 +#undef DEF_FUNCTION_TYPE_3 +#undef DEF_FUNCTION_TYPE_4 +#undef DEF_FUNCTION_TYPE_5 +#undef DEF_FUNCTION_TYPE_6 +#undef DEF_FUNCTION_TYPE_7 +#undef DEF_FUNCTION_TYPE_8 +#undef DEF_FUNCTION_TYPE_9 +#undef DEF_FUNCTION_TYPE_10 +#undef DEF_FUNCTION_TYPE_11 +#undef DEF_FUNCTION_TYPE_VAR_0 +#undef DEF_FUNCTION_TYPE_VAR_1 +#undef DEF_FUNCTION_TYPE_VAR_2 +#undef DEF_FUNCTION_TYPE_VAR_3 +#undef DEF_FUNCTION_TYPE_VAR_4 +#undef DEF_FUNCTION_TYPE_VAR_5 +#undef DEF_FUNCTION_TYPE_VAR_6 +#undef DEF_FUNCTION_TYPE_VAR_7 +#undef DEF_FUNCTION_TYPE_VAR_11 +#undef DEF_POINTER_TYPE + + BT_LAST, + }; + + enum Attr + { +#define DEF_ATTR_NULL_TREE(ENUM) ENUM, +#define DEF_ATTR_INT(ENUM, VALUE) ENUM, +#define DEF_ATTR_STRING(ENUM, VALUE) ENUM, +#define DEF_ATTR_IDENT(ENUM, STRING) ENUM, +#define DEF_ATTR_TREE_LIST(ENUM, PURPOSE, VALUE, CHAIN) ENUM, + +#include "builtin-attrs.def" + +#undef DEF_ATTR_NULL_TREE +#undef DEF_ATTR_INT +#undef DEF_ATTR_STRING +#undef DEF_ATTR_IDENT +#undef DEF_ATTR_TREE_LIST + + ATTR_LAST, + }; + + /** + * All builtin types, as defined in `builtin-types.def` + * + * This array is filled by the `define_builtin_types` method, during the first + * initialization of the `BuiltinsContext` + */ + tree builtin_types[Type::BT_LAST + 1]; + + /** + * Similarly, this array contains all builtin attributes, as defined in + * `builtin-attr.def` + * + * This array is filled by the `define_builtin_attributes` method, during the + * first initialization of the `BuiltinsContext` + */ + tree builtin_attributes[Attr::ATTR_LAST + 1]; + + void define_function_type (Type def, Type ret, bool is_variadic, size_t n, + ...); + void define_builtin_types (); + void define_builtin_attributes (); + void define_builtins (); + + void register_rust_mappings (); + BuiltinsContext (); void setup_overflow_fns (); @@ -91,20 +197,10 @@ private: void setup (); - // Define a builtin function. BCODE is the builtin function code - // defined by builtins.def. NAME is the name of the builtin function. - // LIBNAME is the name of the corresponding library function, and is - // NULL if there isn't one. FNTYPE is the type of the function. - // CONST_P is true if the function has the const attribute. - // NORETURN_P is true if the function has the noreturn attribute. - void define_builtin (const std::string rust_name, built_in_function bcode, - const char *name, const char *libname, tree fntype, - int flags); - bool lookup_gcc_builtin (const std::string &name, tree *builtin); // A mapping of the GCC built-ins exposed to GCC Rust. - std::map builtin_functions_; + std::map builtin_functions; std::map rust_intrinsic_to_gcc_builtin; }; diff --git a/gcc/rust/backend/rust-compile-intrinsic.cc b/gcc/rust/backend/rust-compile-intrinsic.cc index feaf74dff7b..49ee4c0ead9 100644 --- a/gcc/rust/backend/rust-compile-intrinsic.cc +++ b/gcc/rust/backend/rust-compile-intrinsic.cc @@ -29,6 +29,8 @@ #include "print-tree.h" #include "fold-const.h" #include "langhooks.h" +#include "rust-gcc.h" +#include "rust-constexpr.h" #include "print-tree.h" @@ -243,6 +245,14 @@ static const std::mapget_identifier (), &builtin)) return builtin; @@ -653,17 +664,17 @@ op_with_overflow_inner (Context *ctx, TyTy::FnType *fntype, tree_code op) switch (op) { case PLUS_EXPR: - BuiltinsContext::get ().lookup_simple_builtin ("add_overflow", + BuiltinsContext::get ().lookup_simple_builtin ("__builtin_add_overflow", &overflow_builtin); break; case MINUS_EXPR: - BuiltinsContext::get ().lookup_simple_builtin ("sub_overflow", + BuiltinsContext::get ().lookup_simple_builtin ("__builtin_sub_overflow", &overflow_builtin); break; case MULT_EXPR: - BuiltinsContext::get ().lookup_simple_builtin ("mul_overflow", + BuiltinsContext::get ().lookup_simple_builtin ("__builtin_mul_overflow", &overflow_builtin); break; @@ -749,8 +760,8 @@ copy_handler_inner (Context *ctx, TyTy::FnType *fntype, bool overlaps) = build2 (MULT_EXPR, size_type_node, TYPE_SIZE_UNIT (param_type), count); tree memcpy_raw = nullptr; - BuiltinsContext::get ().lookup_simple_builtin (overlaps ? "memmove" - : "memcpy", + BuiltinsContext::get ().lookup_simple_builtin (overlaps ? "__builtin_memmove" + : "__builtin_memcpy", &memcpy_raw); rust_assert (memcpy_raw); auto memcpy = build_fold_addr_expr_loc (UNKNOWN_LOCATION, memcpy_raw); @@ -797,18 +808,34 @@ prefetch_data_handler (Context *ctx, TyTy::FnType *fntype, Prefetch kind) enter_intrinsic_block (ctx, fndecl); auto addr = Backend::var_expression (args[0], UNDEF_LOCATION); - auto locality = Backend::var_expression (args[1], UNDEF_LOCATION); + + // The core library technically allows you to pass any i32 value as a + // locality, but LLVM will then complain if the value cannot be constant + // evaluated. For now, we ignore the locality argument and instead always + // pass `3` (the most restrictive value). This allows us to still have + // prefetch behavior, just not as granular as expected. In future Rust + // versions, we hope that prefetch intrinsics will be split up according to + // locality, similarly to atomic intrinsics. + // The solution is to try and perform constant folding for the locality + // argument, or instead of creating a new function definition, modify the call + // site directly This has the bad side-effect of creating warnings about + // `unused name - locality`, which we hack away here: + // TODO: Take care of handling locality properly + Backend::var_expression (args[1], UNDEF_LOCATION); + auto rw_flag = make_unsigned_long_tree (kind == Prefetch::Write ? 1 : 0); auto prefetch_raw = NULL_TREE; - auto ok - = BuiltinsContext::get ().lookup_simple_builtin ("prefetch", &prefetch_raw); + auto ok = BuiltinsContext::get ().lookup_simple_builtin ("__builtin_prefetch", + &prefetch_raw); rust_assert (ok); auto prefetch = build_fold_addr_expr_loc (UNKNOWN_LOCATION, prefetch_raw); - auto prefetch_call - = Backend::call_expression (prefetch, {addr, rw_flag, locality}, nullptr, - UNDEF_LOCATION); + auto prefetch_call = Backend::call_expression (prefetch, + {addr, rw_flag, + // locality arg + make_unsigned_long_tree (3)}, + nullptr, UNDEF_LOCATION); TREE_READONLY (prefetch_call) = 0; TREE_SIDE_EFFECTS (prefetch_call) = 1; @@ -833,7 +860,7 @@ build_atomic_builtin_name (const std::string &prefix, location_t locus, // TODO: Can we maybe get the generic version (atomic_store_n) to work... This // would be so much better - std::string result = prefix; + std::string result = "__" + prefix; // + "n"; auto type_name = operand_type->get_name (); if (type_name == "usize" || type_name == "isize") @@ -843,6 +870,13 @@ build_atomic_builtin_name (const std::string &prefix, location_t locus, return ""; } + if (type_name.at (0) == 'i') + { + rust_sorry_at (locus, "atomics are not yet supported for signed " + "integer types (i8, i16, i32, i64, i128)"); + return ""; + } + auto type_size_str = allowed_types.find (type_name); if (!check_for_basic_integer_type ("atomic", locus, operand_type)) @@ -970,6 +1004,7 @@ atomic_load_handler_inner (Context *ctx, TyTy::FnType *fntype, int ordering) TREE_SIDE_EFFECTS (load_call) = 1; ctx->add_statement (return_statement); + finalize_intrinsic_block (ctx, fndecl); return fndecl; @@ -1060,7 +1095,8 @@ uninit_handler (Context *ctx, TyTy::FnType *fntype) // BUILTIN size_of FN BODY BEGIN tree memset_builtin = error_mark_node; - BuiltinsContext::get ().lookup_simple_builtin ("memset", &memset_builtin); + BuiltinsContext::get ().lookup_simple_builtin ("__builtin_memset", + &memset_builtin); rust_assert (memset_builtin != error_mark_node); // call memset with 0x01 and size of the thing see @@ -1123,7 +1159,8 @@ move_val_init_handler (Context *ctx, TyTy::FnType *fntype) tree size = TYPE_SIZE_UNIT (template_parameter_type); tree memcpy_builtin = error_mark_node; - BuiltinsContext::get ().lookup_simple_builtin ("memcpy", &memcpy_builtin); + BuiltinsContext::get ().lookup_simple_builtin ("__builtin_memcpy", + &memcpy_builtin); rust_assert (memcpy_builtin != error_mark_node); src = build_fold_addr_expr_loc (BUILTINS_LOCATION, src); @@ -1157,7 +1194,8 @@ expect_handler_inner (Context *ctx, TyTy::FnType *fntype, bool likely) compile_fn_params (ctx, fntype, fndecl, ¶m_vars); tree expr = Backend::var_expression (param_vars[0], UNDEF_LOCATION); tree expect_fn_raw = nullptr; - BuiltinsContext::get ().lookup_simple_builtin ("expect", &expect_fn_raw); + BuiltinsContext::get ().lookup_simple_builtin ("__builtin_expect", + &expect_fn_raw); rust_assert (expect_fn_raw); auto expect_fn = build_fold_addr_expr_loc (BUILTINS_LOCATION, expect_fn_raw); diff --git a/gcc/rust/rust-attribs.cc b/gcc/rust/rust-attribs.cc new file mode 100644 index 00000000000..134dcf9eeca --- /dev/null +++ b/gcc/rust/rust-attribs.cc @@ -0,0 +1,370 @@ +/* rust-attribs.c -- Rust attributes handling. + Copyright (C) 2015-2023 Free Software Foundation, Inc. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" + +#include "tree.h" +#include "diagnostic.h" +#include "tm.h" +#include "cgraph.h" +#include "toplev.h" +#include "target.h" +#include "common/common-target.h" +#include "stringpool.h" +#include "attribs.h" +#include "varasm.h" +#include "fold-const.h" +#include "opts.h" + +/* Heavily based on the D frontend Only a subset of the attributes found in the + * D frontend have been pulled, the goal being to have the builtin function + * correctly setup. It's possible we may need to add extra attributes in the + * future. + */ + +extern const attribute_spec grs_langhook_common_attribute_table[]; + +/* Internal attribute handlers for built-in functions. */ +static tree +handle_noreturn_attribute (tree *, tree, tree, int, bool *); +static tree +handle_leaf_attribute (tree *, tree, tree, int, bool *); +static tree +handle_const_attribute (tree *, tree, tree, int, bool *); +static tree +handle_malloc_attribute (tree *, tree, tree, int, bool *); +static tree +handle_pure_attribute (tree *, tree, tree, int, bool *); +static tree +handle_novops_attribute (tree *, tree, tree, int, bool *); +static tree +handle_nonnull_attribute (tree *, tree, tree, int, bool *); +static tree +handle_nothrow_attribute (tree *, tree, tree, int, bool *); +static tree +handle_type_generic_attribute (tree *, tree, tree, int, bool *); +static tree +handle_transaction_pure_attribute (tree *, tree, tree, int, bool *); +static tree +handle_returns_twice_attribute (tree *, tree, tree, int, bool *); +static tree +handle_fnspec_attribute (tree *, tree, tree, int, bool *); +static tree +handle_omp_declare_simd_attribute (tree *, tree, tree, int, bool *); + +/* Helper to define attribute exclusions. */ +#define ATTR_EXCL(name, function, type, variable) \ + { \ + name, function, type, variable \ + } + +static const struct attribute_spec::exclusions attr_noreturn_exclusions[] = { + // ATTR_EXCL ("alloc_size", true, true, true), + ATTR_EXCL ("const", true, true, true), + // ATTR_EXCL ("malloc", true, true, true), + ATTR_EXCL ("pure", true, true, true), + ATTR_EXCL ("returns_twice", true, true, true), + ATTR_EXCL (NULL, false, false, false), +}; + +static const struct attribute_spec::exclusions attr_returns_twice_exclusions[] + = { + ATTR_EXCL ("noreturn", true, true, true), + ATTR_EXCL (NULL, false, false, false), +}; + +static const struct attribute_spec::exclusions attr_const_pure_exclusions[] = { + // ATTR_EXCL ("alloc_size", true, true, true), + ATTR_EXCL ("const", true, true, true), + ATTR_EXCL ("noreturn", true, true, true), + ATTR_EXCL ("pure", true, true, true), ATTR_EXCL (NULL, false, false, false)}; + +/* Helper to define an attribute. */ +#define ATTR_SPEC(name, min_len, max_len, decl_req, type_req, fn_type_req, \ + affects_type_identity, handler, exclude) \ + { \ + name, min_len, max_len, decl_req, type_req, fn_type_req, \ + affects_type_identity, handler, exclude \ + } + +/* Table of machine-independent attributes. + For internal use (marking of built-ins) only. */ +const attribute_spec grs_langhook_common_attribute_table[] = { + ATTR_SPEC ("noreturn", 0, 0, true, false, false, false, + handle_noreturn_attribute, attr_noreturn_exclusions), + ATTR_SPEC ("leaf", 0, 0, true, false, false, false, handle_leaf_attribute, + NULL), + ATTR_SPEC ("const", 0, 0, true, false, false, false, handle_const_attribute, + attr_const_pure_exclusions), + ATTR_SPEC ("malloc", 0, 0, true, false, false, false, handle_malloc_attribute, + NULL), + ATTR_SPEC ("returns_twice", 0, 0, true, false, false, false, + handle_returns_twice_attribute, attr_returns_twice_exclusions), + ATTR_SPEC ("pure", 0, 0, true, false, false, false, handle_pure_attribute, + attr_const_pure_exclusions), + ATTR_SPEC ("nonnull", 0, -1, false, true, true, false, + handle_nonnull_attribute, NULL), + ATTR_SPEC ("nothrow", 0, 0, true, false, false, false, + handle_nothrow_attribute, NULL), + ATTR_SPEC ("transaction_pure", 0, 0, false, true, true, false, + handle_transaction_pure_attribute, NULL), + ATTR_SPEC ("no vops", 0, 0, true, false, false, false, + handle_novops_attribute, NULL), + ATTR_SPEC ("type generic", 0, 0, false, true, true, false, + handle_type_generic_attribute, NULL), + ATTR_SPEC ("fn spec", 1, 1, false, true, true, false, handle_fnspec_attribute, + NULL), + ATTR_SPEC ("omp declare simd", 0, -1, true, false, false, false, + handle_omp_declare_simd_attribute, NULL), + ATTR_SPEC (NULL, 0, 0, false, false, false, false, NULL, NULL), +}; + +/* Built-in attribute handlers. + These functions take the arguments: + (tree *node, tree name, tree args, int flags, bool *no_add_attrs) */ + +/* Handle a "noreturn" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_noreturn_attribute (tree *node, tree, tree, int, bool *) +{ + tree type = TREE_TYPE (*node); + + if (TREE_CODE (*node) == FUNCTION_DECL) + TREE_THIS_VOLATILE (*node) = 1; + else if (TREE_CODE (type) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE) + TREE_TYPE (*node) = build_pointer_type ( + build_type_variant (TREE_TYPE (type), TYPE_READONLY (TREE_TYPE (type)), + 1)); + else + gcc_unreachable (); + + return NULL_TREE; +} + +/* Handle a "leaf" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_leaf_attribute (tree *node, tree name, tree, int, bool *no_add_attrs) +{ + if (TREE_CODE (*node) != FUNCTION_DECL) + { + warning (OPT_Wattributes, "%qE attribute ignored", name); + *no_add_attrs = true; + } + if (!TREE_PUBLIC (*node)) + { + warning (OPT_Wattributes, "%qE attribute has no effect", name); + *no_add_attrs = true; + } + + return NULL_TREE; +} + +/* Handle a "const" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_const_attribute (tree *node, tree, tree, int, bool *) +{ + tree type = TREE_TYPE (*node); + + if (TREE_CODE (*node) == FUNCTION_DECL) + TREE_READONLY (*node) = 1; + else if (TREE_CODE (type) == POINTER_TYPE + && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE) + TREE_TYPE (*node) = build_pointer_type ( + build_type_variant (TREE_TYPE (type), 1, + TREE_THIS_VOLATILE (TREE_TYPE (type)))); + else + gcc_unreachable (); + + return NULL_TREE; +} + +/* Handle a "malloc" attribute; arguments as in + struct attribute_spec.handler. */ + +tree +handle_malloc_attribute (tree *node, tree, tree, int, bool *) +{ + gcc_assert (TREE_CODE (*node) == FUNCTION_DECL + && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (*node)))); + DECL_IS_MALLOC (*node) = 1; + return NULL_TREE; +} + +/* Handle a "pure" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_pure_attribute (tree *node, tree, tree, int, bool *) +{ + gcc_assert (TREE_CODE (*node) == FUNCTION_DECL); + DECL_PURE_P (*node) = 1; + return NULL_TREE; +} + +/* Handle a "no vops" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_novops_attribute (tree *node, tree, tree, int, bool *) +{ + gcc_assert (TREE_CODE (*node) == FUNCTION_DECL); + DECL_IS_NOVOPS (*node) = 1; + return NULL_TREE; +} + +/* Helper for nonnull attribute handling; fetch the operand number + from the attribute argument list. */ + +static bool +get_nonnull_operand (tree arg_num_expr, unsigned HOST_WIDE_INT *valp) +{ + /* Verify the arg number is a constant. */ + if (!tree_fits_uhwi_p (arg_num_expr)) + return false; + + *valp = TREE_INT_CST_LOW (arg_num_expr); + return true; +} + +/* Handle the "nonnull" attribute. */ + +static tree +handle_nonnull_attribute (tree *node, tree, tree args, int, bool *) +{ + tree type = *node; + + /* If no arguments are specified, all pointer arguments should be + non-null. Verify a full prototype is given so that the arguments + will have the correct types when we actually check them later. + Avoid diagnosing type-generic built-ins since those have no + prototype. */ + if (!args) + { + gcc_assert (prototype_p (type) || !TYPE_ATTRIBUTES (type) + || lookup_attribute ("type generic", TYPE_ATTRIBUTES (type))); + + return NULL_TREE; + } + + /* Argument list specified. Verify that each argument number references + a pointer argument. */ + for (; args; args = TREE_CHAIN (args)) + { + tree argument; + unsigned HOST_WIDE_INT arg_num = 0, ck_num; + + if (!get_nonnull_operand (TREE_VALUE (args), &arg_num)) + gcc_unreachable (); + + argument = TYPE_ARG_TYPES (type); + if (argument) + { + for (ck_num = 1;; ck_num++) + { + if (!argument || ck_num == arg_num) + break; + argument = TREE_CHAIN (argument); + } + + gcc_assert (argument + && TREE_CODE (TREE_VALUE (argument)) == POINTER_TYPE); + } + } + + return NULL_TREE; +} + +/* Handle a "nothrow" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_nothrow_attribute (tree *node, tree, tree, int, bool *) +{ + gcc_assert (TREE_CODE (*node) == FUNCTION_DECL); + TREE_NOTHROW (*node) = 1; + return NULL_TREE; +} + +/* Handle a "type generic" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_type_generic_attribute (tree *node, tree, tree, int, bool *) +{ + /* Ensure we have a function type. */ + gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE); + + /* Ensure we have a variadic function. */ + gcc_assert (!prototype_p (*node) || stdarg_p (*node)); + + return NULL_TREE; +} + +/* Handle a "transaction_pure" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_transaction_pure_attribute (tree *node, tree, tree, int, bool *) +{ + /* Ensure we have a function type. */ + gcc_assert (TREE_CODE (*node) == FUNCTION_TYPE); + + return NULL_TREE; +} + +/* Handle a "returns_twice" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_returns_twice_attribute (tree *node, tree, tree, int, bool *) +{ + gcc_assert (TREE_CODE (*node) == FUNCTION_DECL); + + DECL_IS_RETURNS_TWICE (*node) = 1; + + return NULL_TREE; +} + +/* Handle a "fn spec" attribute; arguments as in + struct attribute_spec.handler. */ + +tree +handle_fnspec_attribute (tree *, tree, tree args, int, bool *) +{ + gcc_assert (args && TREE_CODE (TREE_VALUE (args)) == STRING_CST + && !TREE_CHAIN (args)); + return NULL_TREE; +} + +/* Handle an "omp declare simd" attribute; arguments as in + struct attribute_spec.handler. */ + +tree +handle_omp_declare_simd_attribute (tree *node, tree, tree, int, bool *) +{ + gcc_assert (TREE_CODE (*node) == FUNCTION_DECL); + return NULL_TREE; +} diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc index 580bda7f00a..f17e19a2dfc 100644 --- a/gcc/rust/rust-gcc.cc +++ b/gcc/rust/rust-gcc.cc @@ -1131,20 +1131,20 @@ fetch_overflow_builtins (ArithmeticOrLogicalOperator op) switch (op) { case ArithmeticOrLogicalOperator::ADD: - builtin_ctx.lookup_simple_builtin ("add_overflow", &builtin); + builtin_ctx.lookup_simple_builtin ("__builtin_add_overflow", &builtin); break; case ArithmeticOrLogicalOperator::SUBTRACT: - builtin_ctx.lookup_simple_builtin ("sub_overflow", &builtin); + builtin_ctx.lookup_simple_builtin ("__builtin_sub_overflow", &builtin); break; case ArithmeticOrLogicalOperator::MULTIPLY: - builtin_ctx.lookup_simple_builtin ("mul_overflow", &builtin); + builtin_ctx.lookup_simple_builtin ("__builtin_mul_overflow", &builtin); break; default: rust_unreachable (); break; }; - builtin_ctx.lookup_simple_builtin ("abort", &abort); + builtin_ctx.lookup_simple_builtin ("__builtin_abort", &abort); rust_assert (abort); rust_assert (builtin); diff --git a/gcc/rust/rust-lang.cc b/gcc/rust/rust-lang.cc index f9bec3f7c1e..8b76ba28ea2 100644 --- a/gcc/rust/rust-lang.cc +++ b/gcc/rust/rust-lang.cc @@ -380,6 +380,8 @@ rust_localize_identifier (const char *ident) return identifier_to_locale (ident); } +extern const attribute_spec grs_langhook_common_attribute_table[]; + /* The language hooks data structure. This is the main interface between the GCC * front-end and the GCC middle-end/back-end. A list of language hooks could be * found in /langhooks.h @@ -400,6 +402,8 @@ rust_localize_identifier (const char *ident) #undef LANG_HOOKS_GIMPLIFY_EXPR #undef LANG_HOOKS_EH_PERSONALITY +#undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE + #define LANG_HOOKS_NAME "GNU Rust" #define LANG_HOOKS_INIT grs_langhook_init #define LANG_HOOKS_OPTION_LANG_MASK grs_langhook_option_lang_mask @@ -420,6 +424,8 @@ rust_localize_identifier (const char *ident) #define LANG_HOOKS_GIMPLIFY_EXPR grs_langhook_gimplify_expr #define LANG_HOOKS_EH_PERSONALITY grs_langhook_eh_personality +#define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE grs_langhook_common_attribute_table + #if CHECKING_P #undef LANG_HOOKS_RUN_LANG_SELFTESTS diff --git a/gcc/testsuite/rust/compile/torture/builtin_abort.rs b/gcc/testsuite/rust/compile/torture/builtin_abort.rs new file mode 100644 index 00000000000..3112cdc67f7 --- /dev/null +++ b/gcc/testsuite/rust/compile/torture/builtin_abort.rs @@ -0,0 +1,18 @@ +// { dg-options "-fdump-tree-original" } + +// { dg-final { scan-assembler-not "__builtin_abort\[^\"\]" } } +// { dg-final { scan-tree-dump "__builtin_abort" "original" } } + +#![feature(rustc_attrs)] +#![feature(intrinsics)] + +mod intrinsics { + extern "rust-intrinsic" { + pub fn abort() -> !; + } +} + +pub fn main () -> i32 { + abort(); + 0 +} diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-1.rs b/gcc/testsuite/rust/compile/torture/intrinsics-1.rs deleted file mode 100644 index 6704c0210d1..00000000000 --- a/gcc/testsuite/rust/compile/torture/intrinsics-1.rs +++ /dev/null @@ -1,22 +0,0 @@ -// { dg-additional-options -fdump-tree-original } - -#![feature(intrinsics)] - -extern "rust-intrinsic" { - pub fn sqrtf32(x: f32) -> f32; - pub fn sinf32(x: f32) -> f32; -} - -fn main() { - unsafe fn foo() { - let mut f32; - - f32 = sqrtf32(5f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_sqrtf \(5\.0e\+0\);$} 1 original } } - - f32 = sinf32(39f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_sinf \(3\.9e\+1\);$} 1 original } } - } - - unsafe { foo() }; -} diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-4.rs b/gcc/testsuite/rust/compile/torture/intrinsics-4.rs index 1f6c0d6608a..3d26e999b9e 100644 --- a/gcc/testsuite/rust/compile/torture/intrinsics-4.rs +++ b/gcc/testsuite/rust/compile/torture/intrinsics-4.rs @@ -67,7 +67,7 @@ extern "rust-intrinsic" { } fn main() { - let mut dst = 15; + let mut dst = 15u32; let new_value = 14; unsafe { diff --git a/gcc/testsuite/rust/compile/torture/intrinsics-math.rs b/gcc/testsuite/rust/compile/torture/intrinsics-math.rs index fb329baafdd..42acdde1494 100644 --- a/gcc/testsuite/rust/compile/torture/intrinsics-math.rs +++ b/gcc/testsuite/rust/compile/torture/intrinsics-math.rs @@ -69,104 +69,104 @@ fn main() { let mut f64; f32 = sqrtf32(1f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_sqrtf \(1\.0e\+0\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_sqrt. \(.*.*1\.0e\+0\);$} 1 original } } f64 = sqrtf64(2f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_sqrt \(2\.0e\+0\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_sqrt.? \(.*2\.0e\+0\);$} 1 original } } f32 = sinf32(39f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_sinf \(3\.9e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_sin. \(.*3\.9e\+1\);$} 1 original } } f64 = sinf64(40f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_sin \(4\.0e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_sin.? \(.*4\.0e\+1\);$} 1 original } } f32 = cosf32(5f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_cosf \(5\.0e\+0\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_cos. \(.*5\.0e\+0\);$} 1 original } } f64 = cosf64(6f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_cos \(6\.0e\+0\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_cos.? \(.*6\.0e\+0\);$} 1 original } } f32 = powf32(7f32, 8f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_powf \(7\.0e\+0, 8\.0e\+0\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_pow. \(.*7\.0e\+0, .*8\.0e\+0\);$} 1 original } } f64 = powf64(9f64, 10f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_pow \(9\.0e\+0, 1\.0e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_pow.? \(.*9\.0e\+0, .*1\.0e\+1\);$} 1 original } } f32 = expf32(11f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_expf \(1\.1e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_exp. \(.*1\.1e\+1\);$} 1 original } } f64 = expf64(12f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_exp \(1\.2e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_exp.? \(.*1\.2e\+1\);$} 1 original } } f32 = exp2f32(13f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_expf \(1\.1e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_exp. \(.*1\.1e\+1\);$} 1 original } } f64 = exp2f64(14f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_exp \(1\.2e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_exp.? \(.*1\.2e\+1\);$} 1 original } } f32 = logf32(15f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_logf \(1\.5e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_log. \(.*1\.5e\+1\);$} 1 original } } f64 = logf64(16f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_log \(1\.6e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_log.? \(.*1\.6e\+1\);$} 1 original } } f32 = log10f32(17f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_log10f \(1\.7e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_log10. \(.*1\.7e\+1\);$} 1 original } } f64 = log10f64(18f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_log10 \(1\.8e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_log10.? \(.*1\.8e\+1\);$} 1 original } } f32 = log2f32(19f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_log2f \(1\.9e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_log2. \(.*1\.9e\+1\);$} 1 original } } f64 = log2f64(20f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_log2 \(2\.0e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_log2.? \(.*2\.0e\+1\);$} 1 original } } f32 = fmaf32(21f32, 22f32, 23f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_fmaf \(2\.1e\+1, 2\.2e\+1, 2\.3e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_fma. \(.*2\.1e\+1, .*2\.2e\+1, .*2\.3e\+1\);$} 1 original } } f64 = fmaf64(24f64, 25f64, 26f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_fma \(2\.4e\+1, 2\.5e\+1, 2\.6e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_fma.? \(.*2\.4e\+1, .*2\.5e\+1, .*2\.6e\+1\);$} 1 original } } f32 = fabsf32(27f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_fabsf \(2\.7e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_fabs. \(.*2\.7e\+1\);$} 1 original } } f64 = fabsf64(28f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_fabs \(2\.8e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_fabs.? \(.*2\.8e\+1\);$} 1 original } } f32 = minnumf32(29f32, 30f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_fminf \(2\.9e\+1, 3\.0e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_fmin. \(.*2\.9e\+1, .*3\.0e\+1\);$} 1 original } } f64 = minnumf64(31f64, 32f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_fmin \(3\.1e\+1, 3\.2e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_fmin.? \(.*3\.1e\+1, .*3\.2e\+1\);$} 1 original } } f32 = maxnumf32(33f32, 34f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_fmaxf \(3\.3e\+1, 3\.4e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_fmax. \(.*3\.3e\+1, .*3\.4e\+1\);$} 1 original } } f64 = maxnumf64(35f64, 36f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_fmax \(3\.5e\+1, 3\.6e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_fmax.? \(.*3\.5e\+1, .*3\.6e\+1\);$} 1 original } } f32 = copysignf32(37f32, 38f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_copysignf \(3\.7e\+1, 3\.8e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_copysign. \(.*3\.7e\+1, .*3\.8e\+1\);$} 1 original } } f64 = copysignf64(39f64, 40f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_copysign \(3\.9e\+1, 4\.0e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_copysign.? \(.*3\.9e\+1, .*4\.0e\+1\);$} 1 original } } f32 = floorf32(41f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_floorf \(4\.1e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_floor. \(.*4\.1e\+1\);$} 1 original } } f64 = floorf64(42f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_floor \(4\.2e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_floor.? \(.*4\.2e\+1\);$} 1 original } } f32 = ceilf32(43f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_ceilf \(4\.3e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_ceil. \(.*4\.3e\+1\);$} 1 original } } f64 = ceilf64(44f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_ceil \(4\.4e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_ceil.? \(.*4\.4e\+1\);$} 1 original } } f32 = truncf32(45f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_truncf \(4\.5e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_trunc. \(.*4\.5e\+1\);$} 1 original } } f64 = truncf64(46f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_trunc \(4\.6e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_trunc.? \(.*4\.6e\+1\);$} 1 original } } f32 = rintf32(47f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_rintf \(4\.7e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_rint. \(.*4\.7e\+1\);$} 1 original } } f64 = rintf64(48f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_rint \(4\.8e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_rint.? \(.*4\.8e\+1\);$} 1 original } } f32 = nearbyintf32(49f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_nearbyintf \(4\.9e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_nearbyint. \(.*4\.9e\+1\);$} 1 original } } f64 = nearbyintf64(50f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_nearbyint \(5\.0e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_nearbyint.? \(.*5\.0e\+1\);$} 1 original } } f32 = roundf32(51f32); - // { dg-final { scan-tree-dump-times {(?n)f32 = __builtin_roundf \(5\.1e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f32 .* __builtin_round. \(.*5\.1e\+1\);$} 1 original } } f64 = roundf64(52f64); - // { dg-final { scan-tree-dump-times {(?n)f64 = __builtin_round \(5\.2e\+1\);$} 1 original } } + // { dg-final { scan-tree-dump-times {(?n)f64 .* __builtin_round.? \(.*5\.2e\+1\);$} 1 original } } } unsafe { foo() }; diff --git a/gcc/testsuite/rust/execute/torture/atomic_load.rs b/gcc/testsuite/rust/execute/torture/atomic_load.rs index b66c4641424..11da8484494 100644 --- a/gcc/testsuite/rust/execute/torture/atomic_load.rs +++ b/gcc/testsuite/rust/execute/torture/atomic_load.rs @@ -66,14 +66,14 @@ extern "rust-intrinsic" { pub fn atomic_load_unordered(src: *const T) -> T; } -fn main() -> i32 { +fn main() -> u32 { let one; let two; let three; let four; unsafe { - let mut src = 1; + let mut src = 1u32; one = atomic_load_seqcst(&src); src = 2; diff --git a/gcc/testsuite/rust/execute/torture/atomic_store.rs b/gcc/testsuite/rust/execute/torture/atomic_store.rs index dcbb2a90f19..1b46678ba38 100644 --- a/gcc/testsuite/rust/execute/torture/atomic_store.rs +++ b/gcc/testsuite/rust/execute/torture/atomic_store.rs @@ -66,8 +66,8 @@ extern "rust-intrinsic" { pub fn atomic_store_unordered(dst: *mut T, val: T); } -fn main() -> i32 { - let mut dst = 15; +fn main() -> u32 { + let mut dst = 15u32; let one; let two; let three; diff --git a/gcc/testsuite/rust/execute/torture/builtin_abort.rs b/gcc/testsuite/rust/execute/torture/builtin_abort.rs new file mode 100644 index 00000000000..9f2d8c2d9f3 --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/builtin_abort.rs @@ -0,0 +1,14 @@ +// { dg-shouldfail "abort should stop the program" } +#![feature(rustc_attrs)] +#![feature(intrinsics)] + +mod intrinsics { + extern "rust-intrinsic" { + pub fn abort() -> !; + } +} + +pub fn main () -> i32 { + abort(); + 0 +} From patchwork Tue Jan 30 12:07:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892908 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=PANJxFjn; 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 4TPPyv0YnZz23gc for ; Tue, 30 Jan 2024 23:45:27 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 01E303831E37 for ; Tue, 30 Jan 2024 12:45:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id 3A3433857B9D for ; Tue, 30 Jan 2024 12:11:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3A3433857B9D 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 3A3433857B9D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616743; cv=none; b=XttSexENEj6DK3XgUqWl7VpmutrEHo71DZIpnQy8eXf7sRfYn7jxurCbEvA92izF/Iz1IDiKwcQ83RQBRlRaZzeug/7b+21kBY00MB6V2t1+TJk39svCMtigL+dAqNYeR1CsfXtwS2F11Cko/mkIEGKn2LvQnLHuSEERQ3VueZg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616743; c=relaxed/simple; bh=AlrBgbIzwOz/dsUBJ9lGWp/ivNJicnFjb05dFDdxKBk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=fjVqKgG0FWH/EzMwq2T0f1gDe6TcTBhWwydDW789685dReE19j4gIgf6ycwiaOkfu9rMZl7709LXtS0MaZETziOSR4Y+TxBPA4MYB1hLEh1eXhrtmVjQMKSr9PIRHkusn4JkZwv4zI7Q35VQEMCojdGrno8KZA6G2dSFUpYgULw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-51117bfd452so1693479e87.3 for ; Tue, 30 Jan 2024 04:11:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616703; x=1707221503; 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=xRFapfmaqT8Fwfh6VKPWHVph7SfMdQ5TBMshjeLpkmw=; b=PANJxFjnio1d6MRZ1JbLgPA0Ps1z/oC0pS3opnI2WBCadT9qctAOj/Ka4QaCGrvP+n IpIZrP5j60hgX8Yq6KssdFudZ7v4aNvqW+ye0Je27PcJVyDS/N2AfugmsAw0H0aAuJy7 5p6nEQcDvnTbKwd1shc66jmJjWQalTqRI6vZHUgyJpnt9nZ0z9boo6HQ2LeM/0GtlIdr UeGtOP4w/1YBB6060O//HOXCVM1cyWML/zGvyZrdTEaQSjufWIzYcV4FJGW7tOSUmKjA dxrGRPIibBmu8TzfJx++DJhleuZjTQMREFaf2buOWEWnwXLjE0+DHu0DDbhX95akja6j ZLyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616703; x=1707221503; 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=xRFapfmaqT8Fwfh6VKPWHVph7SfMdQ5TBMshjeLpkmw=; b=qwXD83YdmgkM+c2dBvj4LJIr9c/6ZpKEG0vm95tyIAEcTXgLzMrICfzoqD1I2lguJ7 j41t7DCRnu0M5hFNawGQYzbPzb1BIJRsAtbF4KCL8MZZL41ZbaLtzA9LRnasDLiuw0ef jjILhZpzKFQWrrqVKQX/8vy5Zlb9A8zwPlldq3K1IiKGgVthA8KCgnphetX3p0RQ0jHY //gO+U5lMQricB7q5FplI0BZP/UiUOAKHuIKP7M1pyV3fXrwZMp/p5zxl95nEXR/2Kmb MIuFjEKWzED203Vz6ZNbQsA5/2j8uFRsZojWRHsn2Z/iqeaFmerzjHjsBBfGrtjrkxxw ZatA== X-Gm-Message-State: AOJu0Yz1FyNiL+ODISaKoqp1riYc41peqjTxpDn8v9Rwn5klvYxGb3wR /0O36igWzAKetDJf/TZMTA5hMNce8pDFHSPzL9Oc1wmKkkdT7qAFIUzHYU8ouDClCCbfAt5KgDy Z9g== X-Google-Smtp-Source: AGHT+IFL3hPsJ1gNGrYnv/HWvPJhKguomauIiSAKj+yNNkV2DRdjCcsd20n4JTZ1klIjmZS5MTGBvQ== X-Received: by 2002:ac2:562e:0:b0:50e:cbf3:8f73 with SMTP id b14-20020ac2562e000000b0050ecbf38f73mr6863890lff.52.1706616702978; Tue, 30 Jan 2024 04:11:42 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:42 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 072/101] gccrs: HIR: add missing getters Date: Tue, 30 Jan 2024 13:07:28 +0100 Message-ID: <20240130121026.807464-75-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.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, 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: Jakub Dupak gcc/rust/ChangeLog: * hir/tree/rust-hir-item.h: Ad lifetime getter. * hir/tree/rust-hir-path.h: Make getter const ref. * hir/tree/rust-hir.h: Const ref and new getter. Signed-off-by: Jakub Dupak --- gcc/rust/hir/tree/rust-hir-item.h | 2 ++ gcc/rust/hir/tree/rust-hir-path.h | 4 ++++ gcc/rust/hir/tree/rust-hir.h | 7 ++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h index f72d8c8b050..74450786e89 100644 --- a/gcc/rust/hir/tree/rust-hir-item.h +++ b/gcc/rust/hir/tree/rust-hir-item.h @@ -443,6 +443,8 @@ public: // Returns whether the self-param has a valid lifetime. bool has_lifetime () const { return !lifetime.is_error (); } + const Lifetime &get_lifetime () const { return lifetime; } + // Returns whether the self-param is in an error state. bool is_error () const { return self_kind == ImplicitSelfKind::NONE; } diff --git a/gcc/rust/hir/tree/rust-hir-path.h b/gcc/rust/hir/tree/rust-hir-path.h index 9fe126a56a8..0566e2e2a1c 100644 --- a/gcc/rust/hir/tree/rust-hir-path.h +++ b/gcc/rust/hir/tree/rust-hir-path.h @@ -218,6 +218,10 @@ public: std::string as_string () const; std::vector &get_lifetime_args () { return lifetime_args; } + const std::vector &get_lifetime_args () const + { + return lifetime_args; + } std::vector > &get_type_args () { return type_args; } diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h index 0f2d52256d2..f66f53fbd20 100644 --- a/gcc/rust/hir/tree/rust-hir.h +++ b/gcc/rust/hir/tree/rust-hir.h @@ -572,7 +572,10 @@ public: void accept_vis (HIRFullVisitor &vis) override; - std::string get_name () const { return lifetime_name; } + WARN_UNUSED_RESULT const std::string &get_name () const + { + return lifetime_name; + } AST::Lifetime::LifetimeType get_lifetime_type () const { @@ -662,6 +665,8 @@ public: // Returns whether the lifetime param has any lifetime bounds. bool has_lifetime_bounds () const { return !lifetime_bounds.empty (); } + std::vector &get_lifetime_bounds () { return lifetime_bounds; } + // Returns whether the lifetime param has an outer attribute. bool has_outer_attribute () const { return !outer_attr.is_empty (); } From patchwork Tue Jan 30 12:07:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892873 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=S4JrGes5; 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 4TPPl743KSz23dQ for ; Tue, 30 Jan 2024 23:35:15 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 50EEA386F474 for ; Tue, 30 Jan 2024 12:35:13 +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 71CFC3858017 for ; Tue, 30 Jan 2024 12:11:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 71CFC3858017 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 71CFC3858017 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=1706616743; cv=none; b=UFAUYqB+PKJfvopj0/CYQtbBMy9srWBOqKwwKWexsG84ZdnOedXB57Pbz9NLDhaRxNDmkDIS7EBqZUtYOKEnkqW26Zgkq5/+vAiZir/XHs4uuYn+Y1jV67Ou5NPCwJa0nXnLSBTdKE7MSXU5vqP7mHN/DviAqa5IjTkOOc+oYY8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616743; c=relaxed/simple; bh=S3YOwqCCm7c9QkMUjB0W0uh7Vv9XBCHq2z2NabdiB8g=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=NdgZMpXfvunHnZaFVi0co7d3zy70u9WXkd3039+rRqWTk2E+LM5B5aLUQf4yxpd7L5EiPCe2G/v8wgao/2bebs+0iLQ273VaxhPy+lmYv8F1VJdM5fAXoGOqrnwObBjshkcDia79SfL76s/57VXsEPmRKlmjVBkMTJdq0RSk8LA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-339289fead2so3051147f8f.3 for ; Tue, 30 Jan 2024 04:11:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616703; x=1707221503; 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=0C9XpHC39uwf4sZaqAE1bofGBEGjgpd5Qp6/+m01U90=; b=S4JrGes5SVA8zY5758NzwzHIsAzZUuDPZ9rXgOZxx5lYbYBHzYaw93QLfBYQws0ZIS ZNJREG66EhfjnG1CY5H9CWIRNEuwgdU7j1fsrG7nNIfaRaIFEH4lqUPdlDe6tFWHCoAl aI2cbcQZFfCW5AI+UM1Fu3kGCbRRqQ9gQSjg/KdLIfOi5oCWbg/EItq3AYw7tIcqWPt3 YX48qsfG8m/Ebpy+2p+bSP2+sSDEdmwHemupQKyciNU5jifUtC//LedSFsS5YiR6I6Cb Kl2WoJNSwgGK1ZoYVZB1nCM7acVDzfJ0k9Fp1U4XYDAiO7oadWCwitzfpfk93jBn6O1x Ra+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616703; x=1707221503; 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=0C9XpHC39uwf4sZaqAE1bofGBEGjgpd5Qp6/+m01U90=; b=IYzS54fjQ1Dw8aYCnaIFF5IsaX9Rnkq4P3c7JQIEurZ6RKAJxuWBHDlXRWUMWXeWOI a/5KsifqdY+J2AndjQT6rlZJDl6k4OrREVoiwjudfXfR4T+YEbPpmjvtJ/Z8SzIP7KAa zAXmA8ycS4YAkuN0+jtPP1L8KdebIXLcPCJF/9A44n8hclwrWzU3TFOZWk8pLcw7TC5v 6afz3q71MS+ZPaqfk/JCkCTp44jNNuSE8q6PG2P3oteoF+lgU1Y0SF0XeYwy5+ovBgMq cGhtU6sY3GMUdfUNp7Hfj8hEYY2kE9EWmKDebFcba1Vm+vRPEnC+uTp/IS1j6MkTp9W1 kVBA== X-Gm-Message-State: AOJu0YyYbKAx52cZBT8jLl4RU5utQYyJSTEOCKsKciWlbaSna8G6TPPW 9ydV1118GnQiwB6sWTQm5bpES/XAj7Bco7eSEPXjaH0Wi6JXRy8eSIFdg7VTO/WH5sGk0n/yp19 p9w== X-Google-Smtp-Source: AGHT+IGbDMUK3+wOBuQ4pzfUlzw1/43sIaPGjRKeBOxPKuprTxQwe73wonHBu5Nelcggxe4z0ckJBA== X-Received: by 2002:a05:6000:184d:b0:33a:f27d:c05 with SMTP id c13-20020a056000184d00b0033af27d0c05mr4037438wri.15.1706616703380; Tue, 30 Jan 2024 04:11:43 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:43 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 073/101] gccrs: TyTy: Fix missed nodiscard Date: Tue, 30 Jan 2024 13:07:29 +0100 Message-ID: <20240130121026.807464-76-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.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, 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: Jakub Dupak gcc/rust/ChangeLog: * typecheck/rust-tyty.h: Fix nodiscard to warn unused. Signed-off-by: Jakub Dupak --- gcc/rust/typecheck/rust-tyty.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 8bfa83da8d8..da4b901724d 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -177,7 +177,7 @@ public: virtual BaseType *clone () const = 0; // Check if TyTy::BaseType is of a specific type. - template [[nodiscard]] bool is () const + template WARN_UNUSED_RESULT bool is () const { static_assert (std::is_base_of::value, "Can only safely cast to TyTy types."); From patchwork Tue Jan 30 12:07:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892910 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=Lj725FSA; 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 4TPQ1W204bz23fD for ; Tue, 30 Jan 2024 23:47:43 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 514FF384CBB7 for ; Tue, 30 Jan 2024 12:47:41 +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 47DB3385771D for ; Tue, 30 Jan 2024 12:11:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 47DB3385771D 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 47DB3385771D 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=1706616749; cv=none; b=DG1CyWU1FyRHt/6FLA8yigC7fBmSaAVz5AUlibKxjflf5jPHmAyFYReX5fVlDMu5KZjwCSz6okiocCT6yM/59ygY6dOFsnsDfBXU67TrwgXuLbRSv3gmT6U622QPw3S0dMlHkZk/KvukLq9njNgN2/zjU1Kc2mwSalDINDvkML8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616749; c=relaxed/simple; bh=RGk69GUgqWBGj6naMDjZCTGTN3doxnH6LyRz1tyB8e8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=teDjAbFbGHue7V891ez1VY4QILc2Tx2RoNbtM76UUvrSVQ+LJCAQjoO4mKmwiGd55qaDoPiOnAfuKM2+jW2dX9l57lYGwTJrgxqEb9TCyKua9kLAO3Y4McNpw0ova2NR2BihGpttKY8ndtq9wjXy6Dws44UZHCbXFOtja/Fw+xY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-40fafced243so1225155e9.0 for ; Tue, 30 Jan 2024 04:11:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616704; x=1707221504; 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=nHOOgBmNlsLC5XTuJaLvTqwZfi6D0yvLIM3UiV9Oo4Q=; b=Lj725FSALJVYH29DtYdMxB6bbY5XVxj71eBpT8Y8olanV3OpYIV1Lvakuu1WagpbBj t/gckKW44I7xEnYOPYlVnbHfpoLsjDtORdMPT7MyxPKt+fBmArNsO5PvHHx4Ejy+6uLS d4LPYZ/LJGhjCV6wX4NNtOaeIRbUISgPpc67Ge+zzYfwJczPdiGy3FaaAy72jcLY5hQ1 kMjo3xl0D+Ut1hRHXER40OJIPfDZLTLm+h7OVh44d1HtpVrm5J4Dwcqfz6aaOi1n+/UN MCfHYPl4y+Of8olBLCFp2tPuWhhmg73PNZ4G1ZB2R6nmx1VmSt9RITiWOJew5CtB4kAs SsSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616704; x=1707221504; 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=nHOOgBmNlsLC5XTuJaLvTqwZfi6D0yvLIM3UiV9Oo4Q=; b=wgyPR1n0ACFDwYpJSFZ0ufN9+IlTzaRb5Z+o9+ib6I9Nc/HLGgGHStZAxyCh+bxQKd xKb5csGzWBGIrfs7A5B+TH1hYcgR0JcPM48gMtlnpqaMvdCz5co0Xtktx4XY/20WYhg2 ZdoLQqI4ioybv31HnM2hsJbiYBuJ5+JAqQAUPjTg8JcE7+9gipAggUJAcDLNvje5ZEcS kD6oYaR/19nKLrmpYCBNoBtyGIojV7b/eXJChqtt15fDKeLMtjkVhSez+7iKhPlLlAcU 5SHGpGmRE1MK+i1kI90Pk+64h/rbFSBru6BeCrvIq/IJMiAJjU1sUNXubnpYihKWdkB+ rDRg== X-Gm-Message-State: AOJu0YzI/sWOnT9IYSBVS9eyPFE3CJS1PSylxAuA+fs4FPJzhYAyTSqd 5sv+JbwthuABs13r+SDg8pqmQxFV0o7F/BJCcfrTtmyib8XPeGfpZEKyuQLJv8Y44JL+wS2xIj5 5UQ== X-Google-Smtp-Source: AGHT+IF2B7SsAAnfqyNNhFoCaERRYk8xnaZ/+PDiyUKd+I2/T6dvCsEfkKZwbtkFwuprRv/lgCdflw== X-Received: by 2002:a05:6000:184d:b0:33a:f27d:c05 with SMTP id c13-20020a056000184d00b0033af27d0c05mr4037486wri.15.1706616704668; Tue, 30 Jan 2024 04:11:44 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:43 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 074/101] gccrs: BIR: Fix missed nodiscard Date: Tue, 30 Jan 2024 13:07:30 +0100 Message-ID: <20240130121026.807464-77-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.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, 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: Jakub Dupak gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-builder-internal.h: Replace nodiscard. * checks/errors/borrowck/rust-bir-place.h: Replace nodiscard. Signed-off-by: Jakub Dupak --- gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h | 4 ++-- gcc/rust/checks/errors/borrowck/rust-bir-place.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h index f33eb075244..cd611514776 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h @@ -261,12 +261,12 @@ protected: // CFG helpers protected: // HIR resolution helpers template - [[nodiscard]] TyTy::BaseType *lookup_type (T &hir_node) const + WARN_UNUSED_RESULT TyTy::BaseType *lookup_type (T &hir_node) const { return lookup_type (hir_node.get_mappings ().get_hirid ()); } - [[nodiscard]] TyTy::BaseType *lookup_type (HirId hirid) const + WARN_UNUSED_RESULT TyTy::BaseType *lookup_type (HirId hirid) const { TyTy::BaseType *type = nullptr; bool ok = ctx.tyctx.lookup_type (hirid, &type); diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-place.h b/gcc/rust/checks/errors/borrowck/rust-bir-place.h index 66b131dee1a..8c2df47c11d 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-place.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir-place.h @@ -148,9 +148,9 @@ public: 0); } - [[nodiscard]] PlaceId lookup_or_add_path (Place::Kind kind, - TyTy::BaseType *tyty, - PlaceId parent, size_t id = 0) + WARN_UNUSED_RESULT PlaceId lookup_or_add_path (Place::Kind kind, + TyTy::BaseType *tyty, + PlaceId parent, size_t id = 0) { PlaceId current = 0; if (parent < places.size ()) From patchwork Tue Jan 30 12:07:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892909 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=NYpjlj7A; 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 4TPQ0G6MRpz23fD for ; Tue, 30 Jan 2024 23:46:38 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A6041387541F for ; Tue, 30 Jan 2024 12:46:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id C2E8F385770F for ; Tue, 30 Jan 2024 12:11:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C2E8F385770F 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 C2E8F385770F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::430 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616745; cv=none; b=QYJODck+SKTshqUEywr6hVbpEo2xTqdad3MnjXyFqXNzUAv6Q1kfc0oGzED7/pbjVeO4ySEfMhv+iD+psWdlcaXqrqjKgz/K3QnDmZjxXqGaerKPVrvcpqnN7iHTYhla+UjLv7gy6vyqNJ3P3tvNQvh7pd3Ns6KPE/AYMhu4uIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616745; c=relaxed/simple; bh=SmYWCNOh62qQLiYJos6SzaJp5FTuQvoVPlirWor1HJ0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Ev27vw7FQIlKI6HjysjmSOPzVNvkOVgUHcZ0j4LA+/9uDt6ofHlnPaUH4ycybHERHFhCypsgRA+MplIZmSTh7QGGbM2EN04yY+qcCuDv04bNVTXGWVuAcVEk627lL9aTtpH5xSdn8fb0v5/qZINon2iUv1MMGztRKGvBIniHCVE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3394b892691so2129926f8f.1 for ; Tue, 30 Jan 2024 04:11:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616705; x=1707221505; 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=1BUHStVa7bCrP5affO7AgJPGu/x7+mpr7WEi5uG/BCo=; b=NYpjlj7AOfRoM7csvD6331QJ1cNiQFWWjCmm5KCYzO+gWqHLoUYcp3H8ODTtAXajc7 sXdGGNi3Fd+DU0RN1sGUwv52c2rPAYH7lrtNtarJ+R0JPQ6Ty2ozHLI7W9YNUDn3OgJd 0vGtVi1qFztDOiqjI/KEjMjIlRB1AyH1YEbD4KCYP/HDxr3esDeV+bY0oIBsAwj6cuRg ca0em+D94VAZBiQPoY8wsGp+mVeSS1xNUIlSB5eA/GO5UgwfmqyQv+G5ZlfLzbxAbz6G Lqh9n6zLw19O6ZlRXSYP+pkWHZWgt/KK1HMA7YlEqyUBPdfAyl00WLyWN2+METa9bu8l InVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616705; x=1707221505; 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=1BUHStVa7bCrP5affO7AgJPGu/x7+mpr7WEi5uG/BCo=; b=nKtZR5VGKElKkRT3xeCev8jU/G6FhxmBzvAmsWsrHvnZJPmhLcaXyuilw8A2dZ5cl7 L4WjqmNUMlh94TawYrEWkjEJ+dN8V/LsK+DanChpzbDqi1qr5SeBj8gqI/syTH9+5uvC pZdwOK92HT0N3r3tEwWkgmuV3FApOLMuAnfwAoQhPmf5h0KNTn/L0G3Uxm+cLvYRAlf2 5xM13qrCysVfgiq116NpFVIrW/Ir9v/PapcS227nDp1ZUeCslsIRfEXTe/v+JmyTJ+d9 TzQdoqRNfWffmQD9eGbg5bajIya2bikjLxKGQj1gtXyku3/c074D8HiiXhx1Y47BTvY5 oXuw== X-Gm-Message-State: AOJu0YwAEdWqoSEq8Gy7eQvT1CYkk87WXDJzOtDk6BBCOaz9OxEbVJCM W7A8TwCh3c3ctjPsKxjBd6RuVqpsNa2rqEmQWapVCpt+vzm+z6fb/2PCO4KDRYlSo4HsBHFxv5N gJQ== X-Google-Smtp-Source: AGHT+IEHvfnGI7L9Tfy0W1QeiuSclYvXubf/1qdResRqHXwC06qacbjqj0D/sd5iJ5fvBTJBcY8w1Q== X-Received: by 2002:a5d:640d:0:b0:33a:ded0:c309 with SMTP id z13-20020a5d640d000000b0033aded0c309mr1324318wru.13.1706616705290; Tue, 30 Jan 2024 04:11:45 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:44 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 075/101] gccrs: TyTy: refactor to new API Date: Tue, 30 Jan 2024 13:07:31 +0100 Message-ID: <20240130121026.807464-78-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.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, 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: Jakub Dupak gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Refactor. Signed-off-by: Jakub Dupak --- gcc/rust/typecheck/rust-hir-type-check-type.cc | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc index 62a17769c3f..951920138cb 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc @@ -442,14 +442,9 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset, root_tyty = lookup; // this enforces the proper get_segments checks to take place - bool is_adt = root_tyty->get_kind () == TyTy::TypeKind::ADT; - if (is_adt) - { - const TyTy::ADTType &adt - = *static_cast (root_tyty); - if (adt.is_enum ()) - return root_tyty; - } + auto *maybe_adt = root_tyty->try_as (); + if (maybe_adt && maybe_adt->is_enum ()) + return root_tyty; } return root_tyty; From patchwork Tue Jan 30 12:07:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892888 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=cEy+jZ62; 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 4TPPqW57Hlz23dQ for ; Tue, 30 Jan 2024 23:39:03 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A37DA387085F for ; Tue, 30 Jan 2024 12:39:01 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id 0BDB9385770C for ; Tue, 30 Jan 2024 12:11:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0BDB9385770C 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 0BDB9385770C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::229 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616752; cv=none; b=nd/UVBLiC+tiIEjc5qVXSA3x0yQLuZf4jM33LczeLESvBnxmsdaFDAc3rDy7LuPDwLmsMcdCVbDXiFtbtTYvpKkLuhCcsiIpbEKC+khEOuJeRp0DSTtxxVCBd7P05I9j/IwUYKSBOWTmePFoEtJh5VN/EuC9vBujAyQQ9wYg5V0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616752; c=relaxed/simple; bh=ihdr6rRuy4wV49af+fws74wwJmUv73aB9dnjLfLUdpU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nM1WsJtwKQFHGGMEG6NKKDbCe3or3UJyF3fbjY7U9wKBt8poffk17PaXlZe1Bd0HZuRYd2YRCDIggqNP+KQMWU5d8YXYNDvpVa51XPBijbp6ykHw6k9HoxLtSkN7a4QU3WaIcxTFXbNkvTV7eSCwNDB/VXTnlrd6RRRsNEy6Yd8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x229.google.com with SMTP id 38308e7fff4ca-2cf45305403so37547241fa.2 for ; Tue, 30 Jan 2024 04:11:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616706; x=1707221506; 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=xm79gVUEsRKM7CogFIXiy9FFbQ7byyhI1qwMqADHFrU=; b=cEy+jZ62f3vYgwWnFx4/NT3326bWLliT20yKPFxuDFL+ubQ+J/nkFofIVtmV9hXcLP UNuHLGklmrRBnqoInSNXy08xXPsf0d8b0NvuMCA6XrLVvSF6Pi7h/uYkAnlZU5g2SWEe gD9xUS8RKqIVYOWabprTkOpY6bIBNp09oPpnhlV7MYkM5QleBkiIKX0HTpctADlOuoED Rq2srDo+QMKvmVpWYVniYtfiWUyp7tHpC34rzHWkBwHUVnXarOsUAgGS+jBhkLzj/1nI AQO2EbTV+jMJN3kDrMc5oYlEMV7w1AHmmXVyipbjpRZWtzomfoeicL/DR/nkrewy3ASp luGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616706; x=1707221506; 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=xm79gVUEsRKM7CogFIXiy9FFbQ7byyhI1qwMqADHFrU=; b=rEkeB+cAgBhAsqVzciBbLLhpY9BEfHHPgAecoRAWc5PldhShW4zaQhfu82iX3CUZ4S +N7DZXF1yRYNiaMbRNWq90H2R+qKxhEiZ09vsn/DZW4D7ZO0CvRUhH5IlFwRx8rkKT86 f7t1iB4XyoUATMwttIs0Nc29ht8katZHdCz80tLiCHt4MtIo1/4Jk0Hgf1p+PjJstHS1 7//QZt5B2iKMXlKM3aOp0TVcDYvylp9E4QW6CqvHdHit4EBhSi3wSzWaBwV7PewZfJRo dY5lRdUdblYMHdvCVJsNO9r44zhYk30ZNMthdeDrqu6I2DtA4ZdTx+yJxamXtGFqM/qU z9Tw== X-Gm-Message-State: AOJu0YwS1fQpiVXVjek5kZ+OOqvBEo/GkJFbLKMTAkWBZIBjCMBqrV9t Z5/dN1hVsY2TyvCbBrChtp1tMSGcW76M0gN0imEpKKjqd6GoAa0cgKh+NQjTFeJ2dGqndFjvrsT d7Q== X-Google-Smtp-Source: AGHT+IGKS06PtHldBLCHBMxwG4XTieYWMbVWDZbv1QG8N7T7kHNIxhhvuWMLNm8niTTPTwfvALIxfg== X-Received: by 2002:a2e:9417:0:b0:2cf:1752:e0fc with SMTP id i23-20020a2e9417000000b002cf1752e0fcmr5491391ljh.42.1706616705998; Tue, 30 Jan 2024 04:11:45 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:45 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 076/101] gccrs: TyTy: Common interface for fucntion-like types Date: Tue, 30 Jan 2024 13:07:32 +0100 Message-ID: <20240130121026.807464-79-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, URIBL_SBL_A 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: Jakub Dupak gcc/rust/ChangeLog: * typecheck/rust-tyty.h (class ClosureType): Inherit interface. (class FnPtr): Inherit interface. (class FnType): Inherit interface. (class CallableTypeInterface): New interface. (BaseType::is): Detect interface members API. Signed-off-by: Jakub Dupak --- gcc/rust/typecheck/rust-tyty.h | 116 ++++++++++++++++++++++++++++----- 1 file changed, 98 insertions(+), 18 deletions(-) diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index da4b901724d..6ce760df66e 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -38,6 +38,10 @@ class AssociatedImplTrait; } // namespace Resolver namespace TyTy { +class ClosureType; +class FnPtr; +class FnType; +class CallableTypeInterface; // https://rustc-dev-guide.rust-lang.org/type-inference.html#inference-variables // https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/enum.TyKind.html#variants @@ -242,6 +246,22 @@ protected: Analysis::Mappings *mappings; }; +/** Unified interface for all function-like types. */ +class CallableTypeInterface : public BaseType +{ +public: + explicit CallableTypeInterface (HirId ref, HirId ty_ref, TypeKind kind, + RustIdent ident, + std::set refs = std::set ()) + : BaseType (ref, ty_ref, kind, ident, refs) + {} + + WARN_UNUSED_RESULT virtual size_t get_num_params () const = 0; + WARN_UNUSED_RESULT virtual BaseType * + get_param_type_at (size_t index) const = 0; + WARN_UNUSED_RESULT virtual BaseType *get_return_type () const = 0; +}; + class InferType : public BaseType { public: @@ -736,7 +756,7 @@ private: ReprOptions repr; }; -class FnType : public BaseType, public SubstitutionRef +class FnType : public CallableTypeInterface, public SubstitutionRef { public: static constexpr auto KIND = TypeKind::FNDEF; @@ -751,7 +771,7 @@ public: std::vector> params, BaseType *type, std::vector subst_refs, std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::FNDEF, ident, refs), + : CallableTypeInterface (ref, ref, TypeKind::FNDEF, ident, refs), SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), params (std::move (params)), type (type), flags (flags), @@ -766,7 +786,7 @@ public: std::vector> params, BaseType *type, std::vector subst_refs, std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::FNDEF, ident, refs), + : CallableTypeInterface (ref, ty_ref, TypeKind::FNDEF, ident, refs), SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), params (params), type (type), flags (flags), identifier (identifier), @@ -832,8 +852,6 @@ public: return params.at (idx); } - BaseType *get_return_type () const { return type; } - BaseType *clone () const final override; FnType * @@ -842,6 +860,21 @@ public: ABI get_abi () const { return abi; } uint8_t get_flags () const { return flags; } + WARN_UNUSED_RESULT size_t get_num_params () const override + { + return params.size (); + } + + WARN_UNUSED_RESULT BaseType *get_param_type_at (size_t index) const override + { + return param_at (index).second; + } + + WARN_UNUSED_RESULT BaseType *get_return_type () const override + { + return type; + } + private: std::vector> params; BaseType *type; @@ -851,33 +884,50 @@ private: ABI abi; }; -class FnPtr : public BaseType +class FnPtr : public CallableTypeInterface { public: static constexpr auto KIND = TypeKind::FNPTR; FnPtr (HirId ref, location_t locus, std::vector params, TyVar result_type, std::set refs = std::set ()) - : BaseType (ref, ref, TypeKind::FNPTR, - {Resolver::CanonicalPath::create_empty (), locus}, refs), + : CallableTypeInterface (ref, ref, TypeKind::FNPTR, + {Resolver::CanonicalPath::create_empty (), locus}, + refs), params (std::move (params)), result_type (result_type) {} FnPtr (HirId ref, HirId ty_ref, location_t locus, std::vector params, TyVar result_type, std::set refs = std::set ()) - : BaseType (ref, ty_ref, TypeKind::FNPTR, - {Resolver::CanonicalPath::create_empty (), locus}, refs), + : CallableTypeInterface (ref, ty_ref, TypeKind::FNPTR, + {Resolver::CanonicalPath::create_empty (), locus}, + refs), params (params), result_type (result_type) {} std::string get_name () const override final { return as_string (); } - BaseType *get_return_type () const { return result_type.get_tyty (); } + WARN_UNUSED_RESULT size_t get_num_params () const override + { + return params.size (); + } + + WARN_UNUSED_RESULT BaseType *get_param_type_at (size_t index) const override + { + return params.at (index).get_tyty (); + } + + WARN_UNUSED_RESULT BaseType *get_return_type () const override + { + return result_type.get_tyty (); + } + const TyVar &get_var_return_type () const { return result_type; } size_t num_params () const { return params.size (); } - BaseType *param_at (size_t idx) const { return params.at (idx).get_tyty (); } + // DEPRECATED: Use get_param_type_at + BaseType *param_at (size_t idx) const { return get_param_type_at (idx); } void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; @@ -898,19 +948,19 @@ private: TyVar result_type; }; -class ClosureType : public BaseType, public SubstitutionRef +class ClosureType : public CallableTypeInterface, public SubstitutionRef { public: static constexpr auto KIND = TypeKind::CLOSURE; - ClosureType (HirId ref, DefId id, RustIdent ident, - TyTy::TupleType *parameters, TyVar result_type, + ClosureType (HirId ref, DefId id, RustIdent ident, TupleType *parameters, + TyVar result_type, std::vector subst_refs, std::set captures, std::set refs = std::set (), std::vector specified_bounds = std::vector ()) - : BaseType (ref, ref, TypeKind::CLOSURE, ident, refs), + : CallableTypeInterface (ref, ref, TypeKind::CLOSURE, ident, refs), SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), parameters (parameters), result_type (std::move (result_type)), id (id), @@ -922,13 +972,13 @@ public: } ClosureType (HirId ref, HirId ty_ref, RustIdent ident, DefId id, - TyTy::TupleType *parameters, TyVar result_type, + TupleType *parameters, TyVar result_type, std::vector subst_refs, std::set captures, std::set refs = std::set (), std::vector specified_bounds = std::vector ()) - : BaseType (ref, ty_ref, TypeKind::CLOSURE, ident, refs), + : CallableTypeInterface (ref, ty_ref, TypeKind::CLOSURE, ident, refs), SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), parameters (parameters), result_type (std::move (result_type)), id (id), @@ -942,6 +992,21 @@ public: void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; + WARN_UNUSED_RESULT size_t get_num_params () const override + { + return parameters->num_fields (); + } + + WARN_UNUSED_RESULT BaseType *get_param_type_at (size_t index) const override + { + return parameters->get_field (index); + } + + WARN_UNUSED_RESULT BaseType *get_return_type () const override + { + return result_type.get_tyty (); + } + std::string as_string () const override; std::string get_name () const override final { return as_string (); } @@ -1495,6 +1560,21 @@ private: DefId item; }; +template <> +WARN_UNUSED_RESULT inline bool +BaseType::is () const +{ + auto kind = this->get_kind (); + return kind == FNPTR || kind == FNDEF || kind == CLOSURE; +} + +template <> +WARN_UNUSED_RESULT inline bool +BaseType::is () const +{ + return this->is (); +} + } // namespace TyTy } // namespace Rust From patchwork Tue Jan 30 12:07:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892882 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=QDO3PUzO; 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 4TPPnx5DLJz23dQ for ; Tue, 30 Jan 2024 23:37:41 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B717B386F812 for ; Tue, 30 Jan 2024 12:37:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 7278B3858014 for ; Tue, 30 Jan 2024 12:11:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7278B3858014 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 7278B3858014 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::432 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616748; cv=none; b=TEbSKIOkt7txtdFJ+Ms1k82cTozNbEL8Bde8BX13OC2vq3NYK8zyN7T0mWD++Iq7WdXaJt4hmB4bJDv3wT8RgIBwQBKZ17M+cc/gUCPX72vnIV/Ix/eoYkxsc9ZH+q3obgkXh5rBNiMTWLd18aeD6WyIOWJj8AueqlcB6TkX+p4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616748; c=relaxed/simple; bh=2XF/Y3sgZjX6r70VvOG9SocX1lMF8PISH21OwbdgADo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ncYslH9qXuu47FTExZWN6fMYVPSZz71l90PW7wRvuxDXvJIT5TSC4BtGLdz/lb3Tvm//j2x99mAnFCyo6HAToBAECYsdB1zuN5Gm0O9ARTT/al+pWQOtcBCbhNnPElC5fYmEFnGJ7HDRN06P+XaOPmP0cQmwbJmAEVoQ2GO1fdE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3392b12dd21so2802198f8f.0 for ; Tue, 30 Jan 2024 04:11:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616706; x=1707221506; 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=c5ar4ANHt3rVdOEEMWvgAQjfr27lyOrmBWniB8yo1S0=; b=QDO3PUzOaZLVyjNciKAGxLozJb7V4VPxHrMMBmCM9/2HqIbhSupBKpgNalAjubWryu m5w077wO1WafOKaa4XaUua9rDJ2SPCkCgHNtRsCb03KDCMdYpVV6aLO8y7Te84Uww6Zl 4XK67Nzai8AS24JkgdjKkYk9QJCrh91Lx72wtrqVbVjXcTJXN9jpp0jkkqH1wJX2U7gg /k0uNzWOVTfEEJs1FPqF1oJ4Y0iKsXQPnTkzaXGgZxe8QWYhE4LhsSpjkIN74QDMXBFw oyzO8XLa+Q2Oa4VRLS60kK7uKQG8X6EtpPlOYCecQlvTL1CX7aMSGp8Hmb2mBt8ScknR uphg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616706; x=1707221506; 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=c5ar4ANHt3rVdOEEMWvgAQjfr27lyOrmBWniB8yo1S0=; b=OXF7XeYNXNbMX5c8iZEEd0xPUJwnvqJlF38YgJ3Vb6gS8JP8Wbj32NzOO2WXhGVMsQ AA/OLINFfDmtWXuilm3uRjkQVNkqurNMgG1q/oxtsE+HifwZBtJ/CaTYhys50irC5MyM PZUiqCcNTxWOLM/ISesMN4QhiB+L/7Z30dwYWgWCqgawKQYNveqn7adC2Omq2bKno+3k 9/QOsDq0FPVsu7QOy6qz9/608k5Gn75W2cI1fGNLdBWpWoTzWlGQHs0KR1U52kk8oB23 5JKCVN+m0uHR7iJOsWjUJJOgNpiA7kFEDgk6xS60k0+eT2ms6hkgA9P4nls7mqsPEHSn s/4A== X-Gm-Message-State: AOJu0YzZUSWmLJxsneZ99QBFPoDpugkx4s5wVOwiufO4BotZzeSTSK0r XyBKRs7OQ8nN9n1Wm9clkOOXBkOtcs6Z1BtMJ2UPGj7iSOv4vxvVA0zw2YHY0u4J0OU7ALAvhPY fBQ== X-Google-Smtp-Source: AGHT+IF6Wqjopt43XHpOMkwkyEEiBwsixWqBX7KxMrZ60EB6B0yCAgUbgCQbkxaWJYPl6rfjDM+rtA== X-Received: by 2002:a05:6000:cc5:b0:337:6948:1309 with SMTP id dq5-20020a0560000cc500b0033769481309mr5704393wrb.38.1706616706440; Tue, 30 Jan 2024 04:11:46 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:46 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 077/101] gccrs: TyTy: SubstitutionRef cast specialization Date: Tue, 30 Jan 2024 13:07:33 +0100 Message-ID: <20240130121026.807464-80-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.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, 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: Jakub Dupak Allows skipping parent check when casting. gcc/rust/ChangeLog: * typecheck/rust-tyty.h (BaseType::is): Cast API. (SubstitutionRef>): Cast API. (BaseType::as): Cast API. (BaseType::try_as): Cast API. Signed-off-by: Jakub Dupak --- gcc/rust/typecheck/rust-tyty.h | 78 ++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 6ce760df66e..2ed407ee169 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -1575,6 +1575,84 @@ BaseType::is () const return this->is (); } +template <> +WARN_UNUSED_RESULT inline bool +BaseType::is () const +{ + auto kind = this->get_kind (); + return kind == FNPTR || kind == FNDEF || kind == CLOSURE || kind == ADT + || kind == PROJECTION; +} + +template <> +WARN_UNUSED_RESULT inline bool +BaseType::is () const +{ + return this->is (); +} + +template <> +WARN_UNUSED_RESULT inline SubstitutionRef * +BaseType::as () +{ + auto kind = this->get_kind (); + switch (kind) + { + case FNDEF: + return static_cast (this); + case CLOSURE: + return static_cast (this); + case ADT: + return static_cast (this); + case PROJECTION: + return static_cast (this); + default: + rust_unreachable (); + } +} + +template <> +WARN_UNUSED_RESULT inline const SubstitutionRef * +BaseType::as () const +{ + auto kind = this->get_kind (); + switch (kind) + { + case FNDEF: + return static_cast (this); + case CLOSURE: + return static_cast (this); + case ADT: + return static_cast (this); + case PROJECTION: + return static_cast (this); + default: + rust_unreachable (); + } +} + +template <> +WARN_UNUSED_RESULT inline SubstitutionRef * +BaseType::try_as () +{ + if (this->is ()) + { + return this->as (); + } + return nullptr; +} + +template <> +WARN_UNUSED_RESULT inline const SubstitutionRef * +BaseType::try_as () const +{ + if (this->is ()) + { + return this->as (); + } + return nullptr; +} + } // namespace TyTy } // namespace Rust From patchwork Tue Jan 30 12:07:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892900 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=GJa/sIf3; 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 4TPPvq0LCHz23gc for ; Tue, 30 Jan 2024 23:42:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E45FC3838A14 for ; Tue, 30 Jan 2024 12:42:44 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id A6D003857BAA for ; Tue, 30 Jan 2024 12:11:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A6D003857BAA 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 A6D003857BAA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616749; cv=none; b=QcKJMxtJgADxtXBztkLXtRHQTqv62XdwcFYVk847dE4++K6ECKWWbUG97bodXkFNSgu1GzKIi6zG9X3YkpuVPio7XZoV3hUvZN8wFIi/y/bNE4Wa0IgVtWBDWGonnxMRqieqi4GQehFQLLRg47tCvGiEs2VAn2FCPuC/inEM4/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616749; c=relaxed/simple; bh=ZDDDeYum+sKZI6SaElWJGnYJoREDqsJz90r8YyjZdMQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=w5M1B46lHpMVRY4BLcAdWbLQfkhZ02JwY44Pp/EfcD0AADJREriYL8KjGLsfcIKFvo1f5WfcY9l9UhzOpk0fle6SFHoKVRFhUW+g9gthPxu/JL06ASERC34TVfYevfNg2zigJQqVNRdI14nRfna8w2jm8vf0nOuU3bnzGCRV7FA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-40e7065b692so42213315e9.3 for ; Tue, 30 Jan 2024 04:11:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616707; x=1707221507; 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=V1kTLZD/OXfg/UsP4JQkkO4nO5Ahvz0W1byIfbhioUU=; b=GJa/sIf3r2b84/pYWuS9L+1fHxjExK+Vb1iwXh3Nh36r1TmhLV6TMALNWmBYkJXb+l AHLILdKNQRib7k0t5MOo+Qb32F1dp6pXFzkt7EIUOFUBW0Q9xIhoW1Nn2DOIS4qpJrJT iQBBiNTvf3UAAIOsh68J01K0kssxLameT68fe6uS83xYXBZNynBdnJg7ZJcpa6C3uVbY HO7ksUeXE87BIKFW6Uv1qt11LWl/2w4LsZvBYv+9I5uGm04CWI1pEGD8f8VVGv586q6K wk0a3PEXb8WjKbmBIDub0A+CkujTZOy3DT5Hbx8P2W8gVb3OC0NUYlAus0DiXvvwnxW3 2LKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616707; x=1707221507; 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=V1kTLZD/OXfg/UsP4JQkkO4nO5Ahvz0W1byIfbhioUU=; b=O003BWMqnUppSRtI5J+U+5hDDy6Fy6kIpqlbdeQJgadHKKSfOkPKkYLZ3ZF8006s7w 4yhG97jDNVUEzlozlocjgKs4bHK7T89QU9YNIfQ+I26F09WGRZDEAYux0NzLZXzFacub XpvovwIkGKDAIhSF8CLxE/mdoP/5nVV60/V5O7HdW7VE8L6V4GzAZaaMSMj+sprXwJg5 4/MM7tjyHuaLPyqwU865HQ9FQjBlz77F8QI9r/vqY507A7o+5Ud14kvqQ58f3y0gd9AY SApf5Q5R0WNHQQPmvXoUaRlAEbq0Hc+CVCmiGUNlIgTAG+ibzaAQML3W/DbIzuXjXBh/ XcrQ== X-Gm-Message-State: AOJu0YzVFbaT6gVTt+PUkkmYL24Iac306NL+WUOVhctksdA88xCqf247 S08UQ/Lq1Jx0lWut7gI8v2pgekp06+d1Bgha/BUMGBtZoaQma1xhA3h74PnvPnG27G+apJINo46 fBw== X-Google-Smtp-Source: AGHT+IE8yx2ZMENsCHFuXwboc24K9OflR7QEOpMsh9yndFt03s7fyUKwfzZ0Wpr3nrFqXesb+XRpkg== X-Received: by 2002:a5d:59a6:0:b0:33a:fdb8:c600 with SMTP id p6-20020a5d59a6000000b0033afdb8c600mr540430wrr.10.1706616707093; Tue, 30 Jan 2024 04:11:47 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:46 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 078/101] gccrs: BIR: Cleanup Date: Tue, 30 Jan 2024 13:07:34 +0100 Message-ID: <20240130121026.807464-81-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.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, 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: Jakub Dupak gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-place.h: Cleanup. * checks/errors/borrowck/rust-borrow-checker.h: Cleanup. Signed-off-by: Jakub Dupak --- gcc/rust/checks/errors/borrowck/rust-bir-place.h | 2 +- gcc/rust/checks/errors/borrowck/rust-borrow-checker.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-place.h b/gcc/rust/checks/errors/borrowck/rust-bir-place.h index 8c2df47c11d..523c2f6ec90 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-place.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir-place.h @@ -211,7 +211,7 @@ public: auto lookup = lookup_variable (id); if (lookup != INVALID_PLACE) return lookup; - places.push_back ( + add_place ( {Place::VARIABLE, id, {}, is_type_copy (tyty), false, NO_LIFETIME, tyty}); return places.size () - 1; }; diff --git a/gcc/rust/checks/errors/borrowck/rust-borrow-checker.h b/gcc/rust/checks/errors/borrowck/rust-borrow-checker.h index 549af3560e9..e1a3f191c87 100644 --- a/gcc/rust/checks/errors/borrowck/rust-borrow-checker.h +++ b/gcc/rust/checks/errors/borrowck/rust-borrow-checker.h @@ -30,7 +30,8 @@ class BorrowChecker public: explicit BorrowChecker (bool enable_dump_bir) - : enable_dump_bir (enable_dump_bir){}; + : enable_dump_bir (enable_dump_bir) + {} /** Perform borrow-checking using polonius on an entire crate */ void go (HIR::Crate &crate); From patchwork Tue Jan 30 12:07:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892883 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=Kb5Q9o6E; 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 4TPPp322nHz23dQ for ; Tue, 30 Jan 2024 23:37:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 21BEE386D605 for ; Tue, 30 Jan 2024 12:37:45 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id E6CA33857B97 for ; Tue, 30 Jan 2024 12:11:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E6CA33857B97 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 E6CA33857B97 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616755; cv=none; b=Xo7pr0pI4h5kMA2AFLThaQZGlpaagzHn/SMZVTY+Wlu5pP+MCIoQfoeA//u3VBo0mKkqs2uQ8RbZ0yxgRgAxssa05G5z0ZE5gXpF9a4F4CW3shaqe1GGryxYe8cY+cDsEGqpepuShliksIOpCY10iz1x1HoIG90oKuLmLStNwes= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616755; c=relaxed/simple; bh=eF70jmtYtBKboAvdli2mQum0OvM6rWgKaGYE44Aqr0Y=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=We8dnWfeQzyP/mdgRkkhZVhVO0BLihSvhtK0dlK6vR/29V6eRntD/DnDVCMuLZjqZEKJfSTC0YK51JgtM21qceUCcl99vFrgo8OChnmFfsqEydYiHcXWtFnj9FCXLzhHLFPk3GQdq/Da4W05aGNJdQEnUXi6U6ZOSI1mFP75uac= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-40faff092a2so525895e9.2 for ; Tue, 30 Jan 2024 04:11:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616708; x=1707221508; 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=Xy1jbWBq/jS2DmecsSURumawZ9HzroE4Y1MAgZtpQHM=; b=Kb5Q9o6EgJVWHzL7+bg/Rb8nbldARaN1E3OHhvxbk8bk6MrEWSdVLmE8Ac2hpQSB/x L68R/01tna5hM213TCajUK9IbyItI71xA1SSuS/e01Op2eQLxTsSpXIFc4fyQZ9jxfFm eZBZHSDi430LVNBAo8+DmASHvq4qaGPFGRhSce+qUZ+XIfJV/VkBOY1kp3HNQyrOQoC8 8CqZiJrUtxjgxtZJLF0xXdgL3lmQxwSaUyscq4kFEIrXUk+1FzZKzvLkgPcmtOs/32h/ +radK5k1iagHlzy103aIUREAAPbqbVoe3FjVpqHfA4PxXN5PN46peRED9C/ZropvwLhw ByAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616708; x=1707221508; 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=Xy1jbWBq/jS2DmecsSURumawZ9HzroE4Y1MAgZtpQHM=; b=iUatp56Lim+ypwYIPgDaPTUOwP9NtIbqQasmQAWns2T7VfIJc0mR7uX2+h7eBlhLN6 +YPk92HdK1It0avzHw6OnkPk6N94nMcRkX15WqVRrCbL2TnhUI4ELIvkPW8UF7LvTVXA AJ7/X/jG8+PDDmOjUKFFSXikRKXuInwaLeK0H/f0orJfup6UbnQYul3OF6n9qsZwvgXU op6cBASboYMEk/XJN9O97fdru7XQtlEA4G4eE/QbmhU4PtiiJqpqGJfzlYOEJwpVKP4X E7wwX3A/G388p69ruexeEDasyJnn5mHQTF516PqKgMx3PsXRyereO4BFxc28I9kfegmE cDbQ== X-Gm-Message-State: AOJu0YzGMCzUTpIi5PtSZLEbIpENoFfuc8oRBebAPxiJ3xJu9xNvG9eb eN+/n2v5yUQ2DPPj9dLnbpzGwIr6xLx6tDmrSAPF8JkOjcOBmlhz9hfSG6l8AQKApT+X0jhW30D kIw== X-Google-Smtp-Source: AGHT+IE00U2IqdMfR+UglHCbetvcCv1p9buI1AaBe/W8AN54LS5cI8RtNzEqHPRy/AOpmiwJAMO1zg== X-Received: by 2002:a05:6000:1565:b0:33a:f0c5:2a00 with SMTP id 5-20020a056000156500b0033af0c52a00mr3880791wrz.61.1706616707905; Tue, 30 Jan 2024 04:11:47 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:47 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Raiki Tamura Subject: [COMMITTED 079/101] gccrs: split rust-mangle.cc into two files Date: Tue, 30 Jan 2024 13:07:35 +0100 Message-ID: <20240130121026.807464-82-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, KAM_SHORT, 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: Raiki Tamura gcc/rust/ChangeLog: * Make-lang.in: Add .o files * backend/rust-mangle.cc (struct V0Path): moved to splitted files (v0_path): Likewise. (legacy_mangle_name): Likewise. (legacy_mangle_canonical_path): Likewise. (legacy_hash): Likewise. (v0_tuple_prefix): Likewise. (v0_numeric_prefix): Likewise. (v0_simple_type_prefix): Likewise. (v0_complex_type_prefix): Likewise. (v0_integer_62): Likewise. (v0_opt_integer_62): Likewise. (v0_disambiguator): Likewise. (v0_type_prefix): Likewise. (v0_generic_args): Likewise. (v0_identifier): Likewise. (v0_type_path): Likewise. (v0_function_path): Likewise. (v0_scope_path): Likewise. (v0_crate_path): Likewise. (v0_inherent_or_trait_impl_path): Likewise. (v0_closure): Likewise. (legacy_mangle_item): Likewise. (v0_mangle_item): Likewise. * backend/rust-mangle.h (legacy_mangle_item): Likewise. (v0_mangle_item): Likewise. * backend/rust-mangle-legacy.cc: New file. * backend/rust-mangle-v0.cc: New file. Signed-off-by: Raiki Tamura --- gcc/rust/Make-lang.in | 2 + gcc/rust/backend/rust-mangle-legacy.cc | 164 +++++++ gcc/rust/backend/rust-mangle-v0.cc | 508 +++++++++++++++++++ gcc/rust/backend/rust-mangle.cc | 648 +------------------------ gcc/rust/backend/rust-mangle.h | 8 + 5 files changed, 700 insertions(+), 630 deletions(-) create mode 100644 gcc/rust/backend/rust-mangle-legacy.cc create mode 100644 gcc/rust/backend/rust-mangle-v0.cc diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index b138ba26801..bdaef41c419 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -85,6 +85,8 @@ GRS_OBJS = \ rust/rust-session-manager.o \ rust/rust-compile.o \ rust/rust-mangle.o \ + rust/rust-mangle-v0.o \ + rust/rust-mangle-legacy.o \ rust/rust-compile-resolve-path.o \ rust/rust-macro-expand.o \ rust/rust-cfg-strip.o \ diff --git a/gcc/rust/backend/rust-mangle-legacy.cc b/gcc/rust/backend/rust-mangle-legacy.cc new file mode 100644 index 00000000000..fd0ba1b3745 --- /dev/null +++ b/gcc/rust/backend/rust-mangle-legacy.cc @@ -0,0 +1,164 @@ +// Copyright (C) 2020-2023 Free Software Foundation, Inc. + +// This file is part of GCC. + +// GCC is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3, or (at your option) any later +// version. + +// GCC is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. + +// You should have received a copy of the GNU General Public License +// along with GCC; see the file COPYING3. If not see +// . + +#include "rust-mangle.h" +#include "fnv-hash.h" +#include "rust-unicode.h" +#include "rust-diagnostics.h" +#include "rust-system.h" +#include + +namespace Rust { +namespace Compile { + +const std::string kLegacySymbolPrefix = "_ZN"; +static const std::string kLegacySymbolDelim = "E"; +static const std::string kLegacyGenericDelim = "$C$"; +static const std::string kLegacySubstBegin = "$LT$"; +static const std::string kLegacySubstEnd = "$GT$"; +static const std::string kLegacySpace = "$u20$"; +static const std::string kLegacyRef = "$RF$"; +static const std::string kLegacyPtr = "$BP$"; +static const std::string kLegacyLeftSqParen = "$u5b$"; // [ +static const std::string kLegacyRightSqParen = "$u5d$"; // ] +static const std::string kLegacyLeftBrace = "$u7b$"; // { +static const std::string kLegacyRightBrace = "$u7d$"; // } +static const std::string kQualPathBegin = "_" + kLegacySubstBegin; +static const std::string kLegacyComma = "$C$"; + +static std::string +legacy_mangle_name (const std::string &name) +{ + // example + // <&T as core::fmt::Debug>::fmt: + // _ZN42_$LT$$RF$T$u20$as$u20$core..fmt..Debug$GT$3fmt17h6dac924c0051eef7E + // replace all white space with $ and & with RF + // + // ::fooA: + // _ZN43_$LT$example..Bar$u20$as$u20$example..A$GT$4fooA17hfc615fa76c7db7a0E: + // + // core::ptr::const_ptr::::cast: + // _ZN4core3ptr9const_ptr33_$LT$impl$u20$$BP$const$u20$T$GT$4cast17hb79f4617226f1d55E: + // + // core::ptr::const_ptr::::as_ptr: + // _ZN4core3ptr9const_ptr43_$LT$impl$u20$$BP$const$u20$$u5b$T$u5d$$GT$6as_ptr17he16e0dcd9473b04fE: + // + // example::Foo::new: + // _ZN7example12Foo$LT$T$GT$3new17h9a2aacb7fd783515E: + // + // >::call + // _ZN74_$LT$example..Identity$u20$as$u20$example..FnLike$LT$$RF$T$C$$RF$T$GT$$GT$4call17ha9ee58935895acb3E + + tl::optional utf8_name = Utf8String::make_utf8_string (name); + rust_assert (utf8_name.has_value ()); + std::vector chars = utf8_name.value ().get_chars (); + std::string buffer; + for (size_t i = 0; i < chars.size (); i++) + { + std::string m; + Codepoint c = chars.at (i); + + if (c == ' ') + m = kLegacySpace; + else if (c == '&') + m = kLegacyRef; + else if (i == 0 && c == '<') + m = kQualPathBegin; + else if (c == '<') + m = kLegacySubstBegin; + else if (c == '>') + m = kLegacySubstEnd; + else if (c == '*') + m = kLegacyPtr; + else if (c == '[') + m = kLegacyLeftSqParen; + else if (c == ']') + m = kLegacyRightSqParen; + else if (c == '{') + m = kLegacyLeftBrace; + else if (c == '}') + m = kLegacyRightBrace; + else if (c == ',') + m = kLegacyComma; + else if (c == ':') + { + rust_assert (i + 1 < chars.size ()); + rust_assert (chars.at (i + 1) == ':'); + i++; + m = ".."; + } + else if (c.is_ascii ()) + // ASCII + m.push_back (c.value); + else + { + // Non-ASCII + std::stringstream escaped; + escaped << std::hex << "$u" << c.value << "$"; + m += escaped.str (); + } + buffer += m; + } + + return std::to_string (buffer.size ()) + buffer; +} + +static std::string +legacy_mangle_canonical_path (const Resolver::CanonicalPath &path) +{ + std::string buffer; + for (size_t i = 0; i < path.size (); i++) + { + auto &seg = path.get_seg_at (i); + buffer += legacy_mangle_name (seg.second); + } + return buffer; +} + +// rustc uses a sip128 hash for legacy mangling, but an fnv 128 was quicker to +// implement for now +static std::string +legacy_hash (const std::string &fingerprint) +{ + Hash::FNV128 hasher; + hasher.write ((const unsigned char *) fingerprint.c_str (), + fingerprint.size ()); + + uint64_t hi, lo; + hasher.sum (&hi, &lo); + + char hex[16 + 1]; + memset (hex, 0, sizeof hex); + snprintf (hex, sizeof hex, "%08" PRIx64 "%08" PRIx64, lo, hi); + + return "h" + std::string (hex, sizeof (hex) - 1); +} + +std::string +legacy_mangle_item (const TyTy::BaseType *ty, + const Resolver::CanonicalPath &path) +{ + const std::string hash = legacy_hash (ty->mangle_string ()); + const std::string hash_sig = legacy_mangle_name (hash); + + return kLegacySymbolPrefix + legacy_mangle_canonical_path (path) + hash_sig + + kLegacySymbolDelim; +} + +} // namespace Compile +} // namespace Rust diff --git a/gcc/rust/backend/rust-mangle-v0.cc b/gcc/rust/backend/rust-mangle-v0.cc new file mode 100644 index 00000000000..634ccb07aa4 --- /dev/null +++ b/gcc/rust/backend/rust-mangle-v0.cc @@ -0,0 +1,508 @@ +// Copyright (C) 2020-2023 Free Software Foundation, Inc. + +// This file is part of GCC. + +// GCC is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3, or (at your option) any later +// version. + +// GCC is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. + +// You should have received a copy of the GNU General Public License +// along with GCC; see the file COPYING3. If not see +// . + +#include "rust-mangle.h" +#include "optional.h" +#include "rust-base62.h" +#include "rust-diagnostics.h" +#include "rust-system.h" +#include "rust-tyty.h" +#include "rust-unicode.h" +#include "rust-punycode.h" +#include "rust-compile-type.h" +#include + +namespace Rust { +namespace Compile { + +struct V0Path +{ + std::string prefix = ""; + // Used for "N" + std::string ns = ""; + std::string path = ""; + // Used for "N" and "C" + std::string ident = ""; + std::string disambiguator = ""; + // Used for "M" and "X" + std::string impl_path = ""; + std::string impl_type = ""; + std::string trait_type = ""; + // Used for generic types + std::string generic_postfix = ""; + std::string generic_prefix = ""; + + std::string as_string () const + { + if (prefix == "N") + return generic_prefix + prefix + ns + path + disambiguator + ident + + generic_postfix; + else if (prefix == "M") + return prefix + impl_path + impl_type; + else if (prefix == "X") + return prefix + impl_type + trait_type; + else if (prefix == "C") + return prefix + disambiguator + ident; + else + rust_unreachable (); + } +}; + +static std::string +v0_path (Rust::Compile::Context *ctx, const TyTy::BaseType *ty, + const Resolver::CanonicalPath &path); + +static std::string +v0_tuple_prefix (const TyTy::BaseType *ty) +{ + if (ty->is_unit ()) + return "u"; + + // FIXME: ARTHUR: Add rest of algorithm + return ""; +} + +static std::string +v0_numeric_prefix (const TyTy::BaseType *ty) +{ + static const std::map num_prefixes = { + {"i8", "a"}, {"u8", "h"}, {"i16", "s"}, {"u16", "t"}, + {"i32", "l"}, {"u32", "m"}, {"i64", "x"}, {"u64", "y"}, + {"isize", "i"}, {"usize", "j"}, {"f32", "f"}, {"f64", "d"}, + }; + + auto ty_kind = ty->get_kind (); + auto ty_str = ty->as_string (); + auto numeric_iter = num_prefixes.end (); + + // Special numeric types + if (ty_kind == TyTy::TypeKind::ISIZE) + return "i"; + else if (ty_kind == TyTy::TypeKind::USIZE) + return "j"; + + numeric_iter = num_prefixes.find (ty_str); + if (numeric_iter != num_prefixes.end ()) + return numeric_iter->second; + + rust_unreachable (); +} + +static std::string +v0_simple_type_prefix (const TyTy::BaseType *ty) +{ + switch (ty->get_kind ()) + { + case TyTy::TypeKind::BOOL: + return "b"; + case TyTy::TypeKind::CHAR: + return "c"; + case TyTy::TypeKind::STR: + return "e"; + case TyTy::TypeKind::NEVER: + return "z"; + + // Placeholder types + case TyTy::TypeKind::ERROR: // Fallthrough + case TyTy::TypeKind::INFER: // Fallthrough + case TyTy::TypeKind::PLACEHOLDER: // Fallthrough + case TyTy::TypeKind::PARAM: + // FIXME: TyTy::TypeKind::BOUND is also a valid variant in rustc + return "p"; + + case TyTy::TypeKind::TUPLE: + return v0_tuple_prefix (ty); + + case TyTy::TypeKind::UINT: // Fallthrough + case TyTy::TypeKind::INT: // Fallthrough + case TyTy::TypeKind::FLOAT: // Fallthrough + case TyTy::TypeKind::ISIZE: // Fallthrough + case TyTy::TypeKind::USIZE: + return v0_numeric_prefix (ty); + + default: + return ""; + } + + rust_unreachable (); +} + +static std::string +v0_complex_type_prefix (Context *ctx, const TyTy::BaseType *ty) +{ + // FIXME: ref, slice, dyn, etc. + // TODO: generics + switch (ty->get_kind ()) + { + case TyTy::TypeKind::ADT: { + const TyTy::ADTType *adt = static_cast (ty); + return v0_path (ctx, ty, adt->get_ident ().path); + } + break; + default: + return ""; + } +} + +// Returns an underscore-terminated base62 integer. +// This corresponds to the `` grammar in the v0 mangling RFC: +// - 0 is encoded as "_" +// - any other value is encoded as itself minus one in base 62, followed by +// "_" +static std::string +v0_integer_62 (uint64_t x) +{ + std::stringstream s; + if (x > 0) + s << base62_integer (x - 1); + + s << "_"; + return s.str (); +} + +// Returns a tag-prefixed base62 integer when the +// integer is greater than 0: +// - 0 is encoded as "" (nothing) +// - any other value is encoded as + v0_integer_62(itself), that is +// + base62(itself - 1) + '_' +static std::string +v0_opt_integer_62 (std::string tag, uint64_t x) +{ + if (x > 0) + { + return tag + v0_integer_62 (x); + } + return ""; +} + +static std::string +v0_disambiguator (uint64_t dis) +{ + return v0_opt_integer_62 ("s", dis); +} + +static std::string +v0_type_prefix (Context *ctx, const TyTy::BaseType *ty) +{ + std::string ty_prefix; + + ty_prefix = v0_simple_type_prefix (ty); + if (!ty_prefix.empty ()) + return ty_prefix; + + ty_prefix = v0_complex_type_prefix (ctx, ty); + if (!ty_prefix.empty ()) + return ty_prefix; + + rust_unreachable (); +} + +static std::string +v0_generic_args (Context *ctx, const TyTy::BaseType *ty) +{ + std::stringstream ss; + const TyTy::FnType *fnty = static_cast (ty); + TyTy::SubstitutionArgumentMappings &subst_ref + = const_cast (fnty)->get_substitution_arguments (); + for (TyTy::SubstitutionArg &map : subst_ref.get_mappings ()) + { + ss << v0_type_prefix (ctx, map.get_tyty ()); + } + return ss.str (); +} + +// Returns an mangled identifier. This corresponds to the +// `` grammar in the v0 mangling RFC. +static std::string +v0_identifier (const std::string &identifier) +{ + std::stringstream mangled; + // The grammar for unicode identifier is contained in + // , right under the one. If the + // identifier contains unicode values, then an extra "u" needs to be added to + // the mangling string and `punycode` must be used to encode the characters. + + if (!is_ascii_only (identifier)) + mangled << "u"; + + tl::optional uident_opt + = Utf8String::make_utf8_string (identifier); + rust_assert (uident_opt.has_value ()); + tl::optional punycode_opt + = encode_punycode (uident_opt.value ()); + rust_assert (punycode_opt.has_value ()); + + std::string punycode = punycode_opt.value (); + + // remove a tailing hyphen + if (punycode.back () == '-') + punycode.pop_back (); + + // replace a hyphen in punycode with a underscore + std::replace (punycode.begin (), punycode.end (), '-', '_'); + + mangled << std::to_string (punycode.size ()); + + // Add extra '_' + if (punycode[0] == '_' || ('0' <= punycode[0] && punycode[0] <= '9')) + mangled << "_"; + + mangled << punycode; + return mangled.str (); +} + +static V0Path +v0_type_path (V0Path path, std::string ident) +{ + V0Path v0path; + v0path.prefix = "N"; + v0path.ns = "t"; + v0path.path = path.as_string (); + v0path.ident = ident; + // TODO: Need ? + return v0path; +} + +static V0Path +v0_function_path (V0Path path, Rust::Compile::Context *ctx, + const TyTy::BaseType *ty, HIR::Function *fn, + std::string ident) +{ + V0Path v0path; + v0path.prefix = "N"; + v0path.ns = "v"; + v0path.path = path.as_string (); + v0path.ident = ident; + if (!fn->get_generic_params ().empty ()) + { + v0path.generic_prefix = "I"; + v0path.generic_postfix = v0_generic_args (ctx, ty) + "E"; + } + return v0path; +} + +static V0Path +v0_scope_path (V0Path path, std::string ident, std::string ns) +{ + V0Path v0path; + v0path.prefix = "N"; + v0path.ns = ns; + v0path.path = path.as_string (); + v0path.ident = ident; + return v0path; +} + +static V0Path +v0_crate_path (CrateNum crate_num, std::string ident) +{ + V0Path v0path; + v0path.prefix = "C"; + v0path.disambiguator = v0_disambiguator (crate_num); + v0path.ident = ident; + return v0path; +} + +static V0Path +v0_inherent_or_trait_impl_path (Rust::Compile::Context *ctx, + HIR::ImplBlock *impl_block) +{ + V0Path v0path; + bool ok; + + // lookup impl type + TyTy::BaseType *impl_ty = nullptr; + ok = ctx->get_tyctx ()->lookup_type ( + impl_block->get_type ()->get_mappings ().get_hirid (), &impl_ty); + rust_assert (ok); + + // FIXME: dummy value for now + v0path.impl_path = "C5crate"; + v0path.impl_type = v0_type_prefix (ctx, impl_ty); + + if (impl_block->has_trait_ref ()) + { + // trait impl: X + v0path.prefix = "X"; + + TyTy::BaseType *trait_ty = nullptr; + ok = ctx->get_tyctx ()->lookup_type ( + impl_block->get_trait_ref ()->get_mappings ().get_hirid (), &trait_ty); + rust_assert (ok); + + v0path.trait_type = v0_type_prefix (ctx, trait_ty); + } + else + // inherent impl: M + v0path.prefix = "M"; + + return v0path; +} + +static V0Path +v0_closure (V0Path path, HirId closure) +{ + V0Path v0path; + v0path.prefix = "N"; + v0path.ns = "C"; + v0path.disambiguator = v0_disambiguator (closure); + v0path.path = path.as_string (); + v0path.ident = "0"; + return v0path; +} + +static std::string +v0_path (Rust::Compile::Context *ctx, const TyTy::BaseType *ty, + const Resolver::CanonicalPath &cpath) +{ + auto mappings = Analysis::Mappings::get (); + + V0Path v0path = {}; + + cpath.iterate_segs ([&] (const Resolver::CanonicalPath &seg) { + HirId hir_id; + bool ok = mappings->lookup_node_to_hir (seg.get_node_id (), &hir_id); + if (!ok) + { + // FIXME: generic arg in canonical path? (e.g. in crate::S) + rust_unreachable (); + } + + HirId parent_impl_id = UNKNOWN_HIRID; + HIR::ImplItem *impl_item + = mappings->lookup_hir_implitem (hir_id, &parent_impl_id); + HIR::TraitItem *trait_item = mappings->lookup_hir_trait_item (hir_id); + HIR::Item *item = mappings->lookup_hir_item (hir_id); + HIR::Expr *expr = mappings->lookup_hir_expr (hir_id); + + if (impl_item != nullptr) + { + switch (impl_item->get_impl_item_type ()) + { + case HIR::ImplItem::FUNCTION: { + HIR::Function *fn = static_cast (impl_item); + v0path = v0_function_path (v0path, ctx, ty, fn, + v0_identifier (seg.get ())); + } + break; + case HIR::ImplItem::CONSTANT: + v0path = v0_scope_path (v0path, v0_identifier (seg.get ()), "v"); + break; + default: + rust_internal_error_at (UNDEF_LOCATION, "Attempt to mangle '%s'", + cpath.get ().c_str ()); + break; + } + } + else if (trait_item != nullptr) + { + switch (trait_item->get_item_kind ()) + { + case HIR::TraitItem::FUNC: { + HIR::Function *fn = static_cast (impl_item); + v0path = v0_function_path (v0path, ctx, ty, fn, + v0_identifier (seg.get ())); + } + break; + case HIR::TraitItem::CONST: + v0path = v0_scope_path (v0path, v0_identifier (seg.get ()), "v"); + break; + default: + rust_internal_error_at (UNDEF_LOCATION, "Attempt to mangle '%s'", + cpath.get ().c_str ()); + break; + } + } + else if (item != nullptr) + switch (item->get_item_kind ()) + { + case HIR::Item::ItemKind::Function: { + HIR::Function *fn = static_cast (item); + v0path = v0_function_path (v0path, ctx, ty, fn, + v0_identifier (seg.get ())); + } + break; + case HIR::Item::ItemKind::Module: + v0path = v0_scope_path (v0path, v0_identifier (seg.get ()), "t"); + break; + case HIR::Item::ItemKind::Trait: // FIXME: correct? + case HIR::Item::ItemKind::Static: + case HIR::Item::ItemKind::Constant: + v0path = v0_scope_path (v0path, v0_identifier (seg.get ()), "v"); + break; + case HIR::Item::ItemKind::Struct: + case HIR::Item::ItemKind::Enum: + case HIR::Item::ItemKind::Union: + v0path = v0_type_path (v0path, v0_identifier (seg.get ())); + break; + case HIR::Item::ItemKind::Impl: + // Trait impl or inherent impl. + { + HIR::ImplBlock *impl_block = static_cast (item); + v0path = v0_inherent_or_trait_impl_path (ctx, impl_block); + } + break; + case HIR::Item::ItemKind::ExternBlock: + case HIR::Item::ItemKind::ExternCrate: + case HIR::Item::ItemKind::UseDeclaration: + case HIR::Item::ItemKind::TypeAlias: + case HIR::Item::ItemKind::EnumItem: // FIXME: correct? + rust_internal_error_at (UNDEF_LOCATION, "Attempt to mangle '%s'", + cpath.get ().c_str ()); + break; + } + else if (expr != nullptr) + { + rust_assert (expr->get_expression_type () + == HIR::Expr::ExprType::Closure); + // Use HIR ID as disambiguator. + v0path = v0_closure (v0path, hir_id); + } + else + // Not HIR item, impl item, trait impl item, nor expr. Assume a crate. + v0path + = v0_crate_path (cpath.get_crate_num (), v0_identifier (seg.get ())); + + return true; + }); + + return v0path.as_string (); +} + +std::string +v0_mangle_item (Rust::Compile::Context *ctx, const TyTy::BaseType *ty, + const Resolver::CanonicalPath &path) +{ + rust_debug ("Start mangling: %s", path.get ().c_str ()); + + // TODO: get Instanciating CrateNum + // auto mappings = Analysis::Mappings::get (); + // std::string crate_name; + // bool ok = mappings->get_crate_name (path.get_crate_num (), crate_name); + // rust_assert (ok); + + std::stringstream mangled; + mangled << "_R"; + mangled << v0_path (ctx, ty, path); + + rust_debug ("=> %s", mangled.str ().c_str ()); + + return mangled.str (); +} + +} // namespace Compile +} // namespace Rust diff --git a/gcc/rust/backend/rust-mangle.cc b/gcc/rust/backend/rust-mangle.cc index e1c9e9427c5..53ed6b54527 100644 --- a/gcc/rust/backend/rust-mangle.cc +++ b/gcc/rust/backend/rust-mangle.cc @@ -1,640 +1,28 @@ -#include "rust-mangle.h" -#include "fnv-hash.h" -#include "optional.h" -#include "rust-base62.h" -#include "rust-unicode.h" -#include "rust-diagnostics.h" -#include "rust-hir-full-decls.h" -#include "rust-hir-item.h" -#include "rust-hir-type-bounds.h" -#include "rust-system.h" -#include "rust-tyty-subst.h" -#include "rust-tyty.h" -#include "rust-unicode.h" -#include "rust-punycode.h" -#include "rust-hir.h" -#include "rust-compile-type.h" -#include - -// FIXME: Rename those to legacy_* -static const std::string kMangledSymbolPrefix = "_ZN"; -static const std::string kMangledSymbolDelim = "E"; -static const std::string kMangledGenericDelim = "$C$"; -static const std::string kMangledSubstBegin = "$LT$"; -static const std::string kMangledSubstEnd = "$GT$"; -static const std::string kMangledSpace = "$u20$"; -static const std::string kMangledRef = "$RF$"; -static const std::string kMangledPtr = "$BP$"; -static const std::string kMangledLeftSqParen = "$u5b$"; // [ -static const std::string kMangledRightSqParen = "$u5d$"; // ] -static const std::string kMangledLeftBrace = "$u7b$"; // { -static const std::string kMangledRightBrace = "$u7d$"; // } -static const std::string kQualPathBegin = "_" + kMangledSubstBegin; -static const std::string kMangledComma = "$C$"; - -namespace Rust { -namespace Compile { - -Mangler::MangleVersion Mangler::version = MangleVersion::LEGACY; - -struct V0Path -{ - std::string prefix = ""; - // Used for "N" - std::string ns = ""; - std::string path = ""; - // Used for "N" and "C" - std::string ident = ""; - std::string disambiguator = ""; - // Used for "M" and "X" - std::string impl_path = ""; - std::string impl_type = ""; - std::string trait_type = ""; - // Used for generic types - std::string generic_postfix = ""; - std::string generic_prefix = ""; - - std::string as_string () const - { - if (prefix == "N") - return generic_prefix + prefix + ns + path + disambiguator + ident - + generic_postfix; - else if (prefix == "M") - return prefix + impl_path + impl_type; - else if (prefix == "X") - return prefix + impl_type + trait_type; - else if (prefix == "C") - return prefix + disambiguator + ident; - else - rust_unreachable (); - } -}; - -static std::string -v0_path (Rust::Compile::Context *ctx, const TyTy::BaseType *ty, - const Resolver::CanonicalPath &path); - -static std::string -legacy_mangle_name (const std::string &name) -{ - // example - // <&T as core::fmt::Debug>::fmt: - // _ZN42_$LT$$RF$T$u20$as$u20$core..fmt..Debug$GT$3fmt17h6dac924c0051eef7E - // replace all white space with $ and & with RF - // - // ::fooA: - // _ZN43_$LT$example..Bar$u20$as$u20$example..A$GT$4fooA17hfc615fa76c7db7a0E: - // - // core::ptr::const_ptr::::cast: - // _ZN4core3ptr9const_ptr33_$LT$impl$u20$$BP$const$u20$T$GT$4cast17hb79f4617226f1d55E: - // - // core::ptr::const_ptr::::as_ptr: - // _ZN4core3ptr9const_ptr43_$LT$impl$u20$$BP$const$u20$$u5b$T$u5d$$GT$6as_ptr17he16e0dcd9473b04fE: - // - // example::Foo::new: - // _ZN7example12Foo$LT$T$GT$3new17h9a2aacb7fd783515E: - // - // >::call - // _ZN74_$LT$example..Identity$u20$as$u20$example..FnLike$LT$$RF$T$C$$RF$T$GT$$GT$4call17ha9ee58935895acb3E - - tl::optional utf8_name = Utf8String::make_utf8_string (name); - rust_assert (utf8_name.has_value ()); - std::vector chars = utf8_name.value ().get_chars (); - std::string buffer; - for (size_t i = 0; i < chars.size (); i++) - { - std::string m; - Codepoint c = chars.at (i); - - if (c == ' ') - m = kMangledSpace; - else if (c == '&') - m = kMangledRef; - else if (i == 0 && c == '<') - m = kQualPathBegin; - else if (c == '<') - m = kMangledSubstBegin; - else if (c == '>') - m = kMangledSubstEnd; - else if (c == '*') - m = kMangledPtr; - else if (c == '[') - m = kMangledLeftSqParen; - else if (c == ']') - m = kMangledRightSqParen; - else if (c == '{') - m = kMangledLeftBrace; - else if (c == '}') - m = kMangledRightBrace; - else if (c == ',') - m = kMangledComma; - else if (c == ':') - { - rust_assert (i + 1 < chars.size ()); - rust_assert (chars.at (i + 1) == ':'); - i++; - m = ".."; - } - else if (c.is_ascii ()) - // ASCII - m.push_back (c.value); - else - { - // Non-ASCII - std::stringstream escaped; - escaped << std::hex << "$u" << c.value << "$"; - m += escaped.str (); - } - buffer += m; - } - - return std::to_string (buffer.size ()) + buffer; -} - -static std::string -legacy_mangle_canonical_path (const Resolver::CanonicalPath &path) -{ - std::string buffer; - for (size_t i = 0; i < path.size (); i++) - { - auto &seg = path.get_seg_at (i); - buffer += legacy_mangle_name (seg.second); - } - return buffer; -} - -// rustc uses a sip128 hash for legacy mangling, but an fnv 128 was quicker to -// implement for now -static std::string -legacy_hash (const std::string &fingerprint) -{ - Hash::FNV128 hasher; - hasher.write ((const unsigned char *) fingerprint.c_str (), - fingerprint.size ()); - - uint64_t hi, lo; - hasher.sum (&hi, &lo); - - char hex[16 + 1]; - memset (hex, 0, sizeof hex); - snprintf (hex, sizeof hex, "%08" PRIx64 "%08" PRIx64, lo, hi); - - return "h" + std::string (hex, sizeof (hex) - 1); -} - -static std::string -v0_tuple_prefix (const TyTy::BaseType *ty) -{ - if (ty->is_unit ()) - return "u"; - - // FIXME: ARTHUR: Add rest of algorithm - return ""; -} - -static std::string -v0_numeric_prefix (const TyTy::BaseType *ty) -{ - static const std::map num_prefixes = { - {"i8", "a"}, {"u8", "h"}, {"i16", "s"}, {"u16", "t"}, - {"i32", "l"}, {"u32", "m"}, {"i64", "x"}, {"u64", "y"}, - {"isize", "i"}, {"usize", "j"}, {"f32", "f"}, {"f64", "d"}, - }; - - auto ty_kind = ty->get_kind (); - auto ty_str = ty->as_string (); - auto numeric_iter = num_prefixes.end (); - - // Special numeric types - if (ty_kind == TyTy::TypeKind::ISIZE) - return "i"; - else if (ty_kind == TyTy::TypeKind::USIZE) - return "j"; - - numeric_iter = num_prefixes.find (ty_str); - if (numeric_iter != num_prefixes.end ()) - return numeric_iter->second; - - rust_unreachable (); -} - -static std::string -v0_simple_type_prefix (const TyTy::BaseType *ty) -{ - switch (ty->get_kind ()) - { - case TyTy::TypeKind::BOOL: - return "b"; - case TyTy::TypeKind::CHAR: - return "c"; - case TyTy::TypeKind::STR: - return "e"; - case TyTy::TypeKind::NEVER: - return "z"; - - // Placeholder types - case TyTy::TypeKind::ERROR: // Fallthrough - case TyTy::TypeKind::INFER: // Fallthrough - case TyTy::TypeKind::PLACEHOLDER: // Fallthrough - case TyTy::TypeKind::PARAM: - // FIXME: TyTy::TypeKind::BOUND is also a valid variant in rustc - return "p"; - - case TyTy::TypeKind::TUPLE: - return v0_tuple_prefix (ty); - - case TyTy::TypeKind::UINT: // Fallthrough - case TyTy::TypeKind::INT: // Fallthrough - case TyTy::TypeKind::FLOAT: // Fallthrough - case TyTy::TypeKind::ISIZE: // Fallthrough - case TyTy::TypeKind::USIZE: // Fallthrough - return v0_numeric_prefix (ty); - - default: - return ""; - } - - rust_unreachable (); -} - -static std::string -v0_complex_type_prefix (Context *ctx, const TyTy::BaseType *ty) -{ - // FIXME: ref, slice, dyn, etc. - // TODO: generics - switch (ty->get_kind ()) - { - case TyTy::TypeKind::ADT: { - const TyTy::ADTType *adt = static_cast (ty); - return v0_path (ctx, ty, adt->get_ident ().path); - } - break; - default: - return ""; - } -} - -// Returns an underscore-terminated base62 integer. -// This corresponds to the `` grammar in the v0 mangling RFC: -// - 0 is encoded as "_" -// - any other value is encoded as itself minus one in base 62, followed by -// "_" -static std::string -v0_integer_62 (uint64_t x) -{ - std::stringstream s; - if (x > 0) - s << base62_integer (x - 1); - - s << "_"; - return s.str (); -} - -// Returns a tag-prefixed base62 integer when the -// integer is greater than 0: -// - 0 is encoded as "" (nothing) -// - any other value is encoded as + v0_integer_62(itself), that is -// + base62(itself - 1) + '_' -static std::string -v0_opt_integer_62 (std::string tag, uint64_t x) -{ - if (x > 0) - { - return tag + v0_integer_62 (x); - } - return ""; -} - -static std::string -v0_disambiguator (uint64_t dis) -{ - return v0_opt_integer_62 ("s", dis); -} - -static std::string -v0_type_prefix (Context *ctx, const TyTy::BaseType *ty) -{ - std::string ty_prefix; - - ty_prefix = v0_simple_type_prefix (ty); - if (!ty_prefix.empty ()) - return ty_prefix; - - ty_prefix = v0_complex_type_prefix (ctx, ty); - if (!ty_prefix.empty ()) - return ty_prefix; - - rust_unreachable (); -} - -static std::string -v0_generic_args (Context *ctx, const TyTy::BaseType *ty) -{ - std::stringstream ss; - const TyTy::FnType *fnty = static_cast (ty); - TyTy::SubstitutionArgumentMappings &subst_ref - = const_cast (fnty)->get_substitution_arguments (); - for (TyTy::SubstitutionArg &map : subst_ref.get_mappings ()) - { - ss << v0_type_prefix (ctx, map.get_tyty ()); - } - return ss.str (); -} - -// Returns an mangled identifier. This corresponds to the -// `` grammar in the v0 mangling RFC. -static std::string -v0_identifier (const std::string &identifier) -{ - std::stringstream mangled; - // The grammar for unicode identifier is contained in - // , right under the one. If the - // identifier contains unicode values, then an extra "u" needs to be added to - // the mangling string and `punycode` must be used to encode the characters. - - if (!is_ascii_only (identifier)) - mangled << "u"; - - tl::optional uident_opt - = Utf8String::make_utf8_string (identifier); - rust_assert (uident_opt.has_value ()); - tl::optional punycode_opt - = encode_punycode (uident_opt.value ()); - rust_assert (punycode_opt.has_value ()); - - std::string punycode = punycode_opt.value (); - - // remove a tailing hyphen - if (punycode.back () == '-') - punycode.pop_back (); +// Copyright (C) 2020-2023 Free Software Foundation, Inc. - // replace a hyphen in punycode with a underscore - std::replace (punycode.begin (), punycode.end (), '-', '_'); +// This file is part of GCC. - mangled << std::to_string (punycode.size ()); +// GCC is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3, or (at your option) any later +// version. - // Add extra '_' - if (punycode[0] == '_' || ('0' <= punycode[0] && punycode[0] <= '9')) - mangled << "_"; - - mangled << punycode; - return mangled.str (); -} - -static V0Path -v0_type_path (V0Path path, std::string ident) -{ - V0Path v0path; - v0path.prefix = "N"; - v0path.ns = "t"; - v0path.path = path.as_string (); - v0path.ident = ident; - // TODO: Need ? - return v0path; -} - -static V0Path -v0_function_path (V0Path path, Rust::Compile::Context *ctx, - const TyTy::BaseType *ty, HIR::Function *fn, - std::string ident) -{ - V0Path v0path; - v0path.prefix = "N"; - v0path.ns = "v"; - v0path.path = path.as_string (); - v0path.ident = ident; - if (!fn->get_generic_params ().empty ()) - { - v0path.generic_prefix = "I"; - v0path.generic_postfix = v0_generic_args (ctx, ty) + "E"; - } - return v0path; -} - -static V0Path -v0_scope_path (V0Path path, std::string ident, std::string ns) -{ - V0Path v0path; - v0path.prefix = "N"; - v0path.ns = ns; - v0path.path = path.as_string (); - v0path.ident = ident; - return v0path; -} - -static V0Path -v0_crate_path (CrateNum crate_num, std::string ident) -{ - V0Path v0path; - v0path.prefix = "C"; - v0path.disambiguator = v0_disambiguator (crate_num); - v0path.ident = ident; - return v0path; -} - -static V0Path -v0_inherent_or_trait_impl_path (Rust::Compile::Context *ctx, - HIR::ImplBlock *impl_block) -{ - V0Path v0path; - bool ok; +// GCC is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. - // lookup impl type - TyTy::BaseType *impl_ty = nullptr; - ok = ctx->get_tyctx ()->lookup_type ( - impl_block->get_type ()->get_mappings ().get_hirid (), &impl_ty); - rust_assert (ok); +// You should have received a copy of the GNU General Public License +// along with GCC; see the file COPYING3. If not see +// . - // FIXME: dummy value for now - v0path.impl_path = "C5crate"; - v0path.impl_type = v0_type_prefix (ctx, impl_ty); - - if (impl_block->has_trait_ref ()) - { - // trait impl: X - v0path.prefix = "X"; - - TyTy::BaseType *trait_ty = nullptr; - ok = ctx->get_tyctx ()->lookup_type ( - impl_block->get_trait_ref ()->get_mappings ().get_hirid (), &trait_ty); - rust_assert (ok); - - v0path.trait_type = v0_type_prefix (ctx, trait_ty); - } - else - // inherent impl: M - v0path.prefix = "M"; - - return v0path; -} - -static V0Path -v0_closure (V0Path path, HirId closure) -{ - V0Path v0path; - v0path.prefix = "N"; - v0path.ns = "C"; - v0path.disambiguator = v0_disambiguator (closure); - v0path.path = path.as_string (); - v0path.ident = "0"; - return v0path; -} - -static std::string -v0_path (Rust::Compile::Context *ctx, const TyTy::BaseType *ty, - const Resolver::CanonicalPath &cpath) -{ - auto mappings = Analysis::Mappings::get (); - - V0Path v0path = {}; - - cpath.iterate_segs ([&] (const Resolver::CanonicalPath &seg) { - HirId hir_id; - bool ok = mappings->lookup_node_to_hir (seg.get_node_id (), &hir_id); - if (!ok) - { - // FIXME: generic arg in canonical path? (e.g. in crate::S) - rust_unreachable (); - } - - HirId parent_impl_id = UNKNOWN_HIRID; - HIR::ImplItem *impl_item - = mappings->lookup_hir_implitem (hir_id, &parent_impl_id); - HIR::TraitItem *trait_item = mappings->lookup_hir_trait_item (hir_id); - HIR::Item *item = mappings->lookup_hir_item (hir_id); - HIR::Expr *expr = mappings->lookup_hir_expr (hir_id); - - if (impl_item != nullptr) - { - switch (impl_item->get_impl_item_type ()) - { - case HIR::ImplItem::FUNCTION: { - HIR::Function *fn = static_cast (impl_item); - v0path = v0_function_path (v0path, ctx, ty, fn, - v0_identifier (seg.get ())); - } - break; - case HIR::ImplItem::CONSTANT: - v0path = v0_scope_path (v0path, v0_identifier (seg.get ()), "v"); - break; - default: - rust_internal_error_at (UNDEF_LOCATION, "Attempt to mangle '%s'", - cpath.get ().c_str ()); - break; - } - } - else if (trait_item != nullptr) - { - switch (trait_item->get_item_kind ()) - { - case HIR::TraitItem::FUNC: { - HIR::Function *fn = static_cast (impl_item); - v0path = v0_function_path (v0path, ctx, ty, fn, - v0_identifier (seg.get ())); - } - break; - case HIR::TraitItem::CONST: - v0path = v0_scope_path (v0path, v0_identifier (seg.get ()), "v"); - break; - default: - rust_internal_error_at (UNDEF_LOCATION, "Attempt to mangle '%s'", - cpath.get ().c_str ()); - break; - } - } - else if (item != nullptr) - switch (item->get_item_kind ()) - { - case HIR::Item::ItemKind::Function: { - HIR::Function *fn = static_cast (item); - v0path = v0_function_path (v0path, ctx, ty, fn, - v0_identifier (seg.get ())); - } - break; - case HIR::Item::ItemKind::Module: - v0path = v0_scope_path (v0path, v0_identifier (seg.get ()), "t"); - break; - case HIR::Item::ItemKind::Trait: // FIXME: correct? - case HIR::Item::ItemKind::Static: - case HIR::Item::ItemKind::Constant: - v0path = v0_scope_path (v0path, v0_identifier (seg.get ()), "v"); - break; - case HIR::Item::ItemKind::Struct: - case HIR::Item::ItemKind::Enum: - case HIR::Item::ItemKind::Union: - v0path = v0_type_path (v0path, v0_identifier (seg.get ())); - break; - case HIR::Item::ItemKind::Impl: - // Trait impl or inherent impl. - { - HIR::ImplBlock *impl_block = static_cast (item); - v0path = v0_inherent_or_trait_impl_path (ctx, impl_block); - } - break; - case HIR::Item::ItemKind::ExternBlock: - case HIR::Item::ItemKind::ExternCrate: - case HIR::Item::ItemKind::UseDeclaration: - case HIR::Item::ItemKind::TypeAlias: - case HIR::Item::ItemKind::EnumItem: // FIXME: correct? - rust_internal_error_at (UNDEF_LOCATION, "Attempt to mangle '%s'", - cpath.get ().c_str ()); - break; - } - else if (expr != nullptr) - { - rust_assert (expr->get_expression_type () - == HIR::Expr::ExprType::Closure); - // Use HIR ID as disambiguator. - v0path = v0_closure (v0path, hir_id); - } - else - { - // Not HIR item, impl item, trait impl item, nor expr. Assume a crate. - - // std::string crate_name; - // bool ok = mappings->get_crate_name (path.get_crate_num (), - // crate_name); rust_assert (ok); rust_assert (crate_name == seg.get()); - - v0path - = v0_crate_path (cpath.get_crate_num (), v0_identifier (seg.get ())); - } - - return true; - }); - - return v0path.as_string (); -} - -static std::string -legacy_mangle_item (const TyTy::BaseType *ty, - const Resolver::CanonicalPath &path) -{ - const std::string hash = legacy_hash (ty->mangle_string ()); - const std::string hash_sig = legacy_mangle_name (hash); - - return kMangledSymbolPrefix + legacy_mangle_canonical_path (path) + hash_sig - + kMangledSymbolDelim; -} - -static std::string -v0_mangle_item (Rust::Compile::Context *ctx, const TyTy::BaseType *ty, - const Resolver::CanonicalPath &path) -{ - rust_debug ("Start mangling: %s", path.get ().c_str ()); - - // auto mappings = Analysis::Mappings::get (); - // std::string crate_name; - // bool ok = mappings->get_crate_name (path.get_crate_num (), crate_name); - // rust_assert (ok); - - std::stringstream mangled; - mangled << "_R"; - mangled << v0_path (ctx, ty, path); +#include "rust-mangle.h" +#include "rust-system.h" - rust_debug ("=> %s", mangled.str ().c_str ()); +namespace Rust { +namespace Compile { - return mangled.str (); -} +Mangler::MangleVersion Mangler::version = MangleVersion::LEGACY; std::string Mangler::mangle_item (Rust::Compile::Context *ctx, const TyTy::BaseType *ty, diff --git a/gcc/rust/backend/rust-mangle.h b/gcc/rust/backend/rust-mangle.h index 09329bb9923..2a84b6b1dea 100644 --- a/gcc/rust/backend/rust-mangle.h +++ b/gcc/rust/backend/rust-mangle.h @@ -49,6 +49,14 @@ private: static enum MangleVersion version; }; +std::string +legacy_mangle_item (const TyTy::BaseType *ty, + const Resolver::CanonicalPath &path); + +std::string +v0_mangle_item (Rust::Compile::Context *ctx, const TyTy::BaseType *ty, + const Resolver::CanonicalPath &path); + } // namespace Compile } // namespace Rust #endif // RUST_MANGLE_H From patchwork Tue Jan 30 12:07:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892878 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=NB08mh7D; 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 4TPPmW6fktz23dQ for ; Tue, 30 Jan 2024 23:36:27 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E22183831E18 for ; Tue, 30 Jan 2024 12:36:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 27F133857703 for ; Tue, 30 Jan 2024 12:11:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 27F133857703 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 27F133857703 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::430 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616752; cv=none; b=I73vll7aGuBQ80WSDxHF9RClgcKeYkBEG5+xpzN0tVSMrknoBFLPLR5n7qZ6RZOzQ4q1yjDXpgd83Zd+mRIrmYJO1b8lJCveuzXlyQKjQvNnEm0QgRKLxeXHlCNamXQpBmxTs/FAIdLtzQHDeS+pejsOUviWKQHR5+/opsZDv2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616752; c=relaxed/simple; bh=Oryf2McI92zK637H17zyjaqQDSbSU1VdAe6mRMQC8aU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ebY76YifQa0vc2+qZvorN+7WUaixqZGQr2kJSpVq+jnqm9mC+DWJx7zO7INhmdL7hv+tTGqwlcuqEapFOH6HkVs0lPvGa+uFXcvUq3dswG0lh9C9PpIl7cs2fqu+nk5aDcR/J6y2hRIyFDGGVnKjMsiygP/PLoB7T84QYUbfGJk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-33934567777so3029553f8f.1 for ; Tue, 30 Jan 2024 04:11:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616708; x=1707221508; 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=4R6u5jkYTU/KEs35fo0qJ3pdkJyWNIDcMjpHEmpqNP0=; b=NB08mh7DeO+7OaRuKtKCdElRLX8rsAObhCk3OV4gvAF/5u3b8x5xluaoz/9wf7TNTT fp7ENFf/H5kvfmx7V4Amo6ajK+OI+GYmNxeN5vzz8mrw3NT5DQwWYAmQc/LTuMbiq6j7 oi53Fvm9I2IGJ026Xe/RkeKg41HNzF+KmF9Am6VNeYbNHFNPYw+rDhNly0zyQHHIPIpq CdbDkJcdyX864FUEN6wCnuiXgsGjdrr9bz6YewnROG73BB8lwVYvswTvcfs/4FNXhQSS 99nZZFE1/+/cPj5n2zJvT7CgwwDWRviyHhuEIQNtNHoIkzNE8HVwy+BI/ldJZrJ3iezl zHoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616708; x=1707221508; 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=4R6u5jkYTU/KEs35fo0qJ3pdkJyWNIDcMjpHEmpqNP0=; b=UjXcJIxuFJh+zAPVRUtkpwWY+apKrdK8De8c3ELcjusp4rq4pGLs1IXnuWoL42QQ9R irXwbhZ05zyNDtBa3RV0cgmJNOjXb2LFu3a+2rRSY+p2dBbBGFQLl9Q5jfKPooFKYKHU W5Y7/Lm1+UkgztjmVWCLQlj27bTc+Np5feqpFDXC88gDJNA0bwdBdfqofDWPdRrCs9PU UnKSdsbTgWhwIc1I4bz1YABuIVZLr0Rbh5uPO6nLx9s0aRuL6DkCLoDoUgMSuSXed0Cl +A82+dUhSDIaJ0dPqu+0eD8/PaIkd7HKYUWTHjlO4bPmLlh3EjcW6+rn7vtHttWjBMbC zatA== X-Gm-Message-State: AOJu0Yy5pH+Ky+zw7F9DyyyhcdlPk3CLZQO2WixHXrk9OHEwgEpPnY6O FlmyuzjmchXtBrwOUxk/3u5jmwMHy7dnll/irvTqokhI36tguuNPi3eCYZZP3/FsnJYY805wQro otQ== X-Google-Smtp-Source: AGHT+IGXLqGtCBhRdlNH1AKNWFoTnnLH4B9LcLZ4kA5lVBcYczLe0jP7WC3Z5Zu/opHAPEi+SbbSjQ== X-Received: by 2002:adf:e311:0:b0:337:c4c1:a3af with SMTP id b17-20020adfe311000000b00337c4c1a3afmr6112199wrj.35.1706616708738; Tue, 30 Jan 2024 04:11:48 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:48 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Kushal Pal Subject: [COMMITTED 080/101] gccrs: Handle `async` qualifier inside trait Date: Tue, 30 Jan 2024 13:07:36 +0100 Message-ID: <20240130121026.807464-83-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.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, 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: Kushal Pal Fixes #2778 gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_trait_impl_item): Handled `async` items Signed-off-by: Kushal Pal --- gcc/rust/parse/rust-parse-impl.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 52766afd9c4..378b9ada5ed 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -5784,6 +5784,8 @@ Parser::parse_trait_impl_item () // function or method return parse_trait_impl_function_or_method (visibility, std::move (outer_attrs)); + case ASYNC: + return parse_async_item (visibility, std::move (outer_attrs)); case CONST: // lookahead to resolve production - could be function/method or const // item From patchwork Tue Jan 30 12:07:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892913 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=DjeABG0v; 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 4TPQ325SHdz23gc for ; Tue, 30 Jan 2024 23:49:02 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 99D5D386483A for ; Tue, 30 Jan 2024 12:49:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id AFF493857712 for ; Tue, 30 Jan 2024 12:11:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AFF493857712 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 AFF493857712 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::329 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616755; cv=none; b=GIY9LkvCcN+dr01+nv/gPOwKPcqSUvVNfhcvVTZ9yftfHj24Vo46a8VxAytCK5fOPFY13CekW7a+Cb8iCqrYm5jbBqD3YUSsAY5TIQp24f3dmShEKIEd2NQQp22I2V4xHnq7FIMCY/UkEAoFSzkAq6S7uAP4uvASMV7ShjFBHTM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616755; c=relaxed/simple; bh=JDGFYD/XD8zgA0vk8AQ9CI+ljipxYg5B1XmpqYksP2o=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=sCC1bOhaRwu/NQ+w4jz24/5rm4bHNUevbRd8HFWFxC5GbJuBo0YoSRca5F6VC1CjTd2iQbXrK+vdxNiz1x5Mf8JRDTfStooV/VKX8L9mNPbpK8+vPlzx+7wrUloneIF5is8sBI2/VrbcWTqzqEvH3PhM33IW10DQBHxJemJzeZQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-40e5afc18f5so41949755e9.3 for ; Tue, 30 Jan 2024 04:11:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616709; x=1707221509; 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=fTlsG0U+P+xPeCbxGECUsEuoD2TRCDBbPHKYwC7Rj0w=; b=DjeABG0vhDhBUQG8onCvzF6GkVFcN0fT5ShyRr43qZTWl3ZwTU4zoi96dfua8xBTbc JIV55BzJylmb9GQoCuNtpQw+v7yW2X/aMWS1f6BUiYi8ATveZ7IytSF+8eVamFxsGG8s SYJ4FR0qM/YjBl+yqETZls9PQrxD1x3ZH9DVsWLWBhJorq5HE3M9u7mC+dqvoacc861v yDIubRsJWy5iRdve9i7t/O1XZm5dnO72gtv4GyW3EhHQ2YgB2YYgkGelnQ8BuN3+3Lck 7t5sengCjPCTtADA+06yIJKNxB1kN3ji9EzARXeUtfOjyxR/Snv5BFa5tHqQeScrnL2o pnXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616709; x=1707221509; 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=fTlsG0U+P+xPeCbxGECUsEuoD2TRCDBbPHKYwC7Rj0w=; b=JKy0Zi/7Yi8a/lQAiItoelJ7C6NMpf5K7F986ygZS/E8RXs7k3kWxBsDC2k61tPiVT CLCKS/NNGmHvLb2MFZZea8tgiip69g7TCo8XXdp3CKJb6hpu36P5I/fwMd0qS/Ua5A0t Dp5mDmdtnGySSQS76SvQOpACJopd+y/cwbX9BFEmxwkcb7TfgtlUWgvbtnMqvyV3yynj kDyHxtTHNElFUZSOB50aAqUma6OWLM/74W/CObaryC58moEUUoMrd4O2pzusILLFFVST quNgfWr3epE5ZEHArMJLqSvwVocrI6KUJh5yF6dQl0DuYWKVTmDlrZ2pdwMNZ/Y+I3Zv E8fw== X-Gm-Message-State: AOJu0YwVc5Y0vpjz+MD82br8d7oXVKTK3ApSrJJTlgDQBM/u/5e3Uvji ONlNzHbG31pfP87whjiSPCcY6dmA8GO7nVenqS69YC9I/OuK6ycelnPzQT50hRXmPemT17UfqA+ A0w== X-Google-Smtp-Source: AGHT+IHx8bsT752hNnhZr3v/jHRpydWw9MPY/X3lZad9CLWYzg4rAE0p7iOWMHY/XUQ4qxTibCSYcQ== X-Received: by 2002:adf:ea0b:0:b0:33a:e6dc:2e98 with SMTP id q11-20020adfea0b000000b0033ae6dc2e98mr5355938wrm.5.1706616709407; Tue, 30 Jan 2024 04:11:49 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:48 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Kushal Pal Subject: [COMMITTED 081/101] gccrs: Generate error for `async` trait fucntions Date: Tue, 30 Jan 2024 13:07:37 +0100 Message-ID: <20240130121026.807464-84-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: Kushal Pal Fixes #2767 gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Added check for `async` function inside trait. gcc/testsuite/ChangeLog: * rust/compile/issue-2767.rs: New test. Signed-off-by: Kushal Pal --- gcc/rust/checks/errors/rust-ast-validation.cc | 5 +++++ gcc/testsuite/rust/compile/issue-2767.rs | 13 +++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 gcc/testsuite/rust/compile/issue-2767.rs diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index cd197fc1ea7..b50e9cdf858 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -107,6 +107,11 @@ ASTValidation::visit (AST::Function &function) rust_error_at (function.get_locus (), ErrorCode::E0379, "functions in traits cannot be declared const"); + // may change soon + if (qualifiers.is_async () && context.back () == Context::TRAIT_IMPL) + rust_error_at (function.get_locus (), ErrorCode::E0706, + "functions in traits cannot be declared %"); + if (valid_context.find (context.back ()) == valid_context.end () && function.has_self_param ()) rust_error_at ( diff --git a/gcc/testsuite/rust/compile/issue-2767.rs b/gcc/testsuite/rust/compile/issue-2767.rs new file mode 100644 index 00000000000..9e7e0f983d2 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2767.rs @@ -0,0 +1,13 @@ +// { dg-additional-options "-frust-edition=2018" } +trait Foo { + fn f() -> u32; +} + +impl Foo for u32 { + async fn f() -> u32 { + // { dg-error "functions in traits cannot be declared .async." "" { target *-*-* } .-1 } + 22 + } +} + +fn main() {} From patchwork Tue Jan 30 12:07:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892864 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=M0U+uaZw; 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 4TPPhT1Qg4z23fD for ; Tue, 30 Jan 2024 23:32:57 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1BDF1385E000 for ; Tue, 30 Jan 2024 12:32:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 93A7B3857709 for ; Tue, 30 Jan 2024 12:11:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 93A7B3857709 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 93A7B3857709 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616754; cv=none; b=Z3fzfYcKiA0tH/iH+cgbU0pQChVGcM55l1r+s8D+YRbRhIxtEng4t2uEwcOZoyWKl1g3s33p2fv+xR1wkQxjW0fuQvY3/d/s93z3mGZ3ZsrrQye2aaAFvx7OTKHqui/0WSIwOLyKDfn19VLpumbQTqSEVPtr17vifNg22Br8kJA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616754; c=relaxed/simple; bh=oNX+2jrKTJkYQVjf8aKAJTOZDIoY6kwjk0y3fXjLYYQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ovqFi6xJ+jF8SW24MEcuqdJqk8g3fVum3sCbefrKK7U3cyh83v7jxjGMbRFJoH1ACPNFzaaA7n2N5vmX7EXYgE0lf6o6SA2bSENx8mhOZlg4TStnIUQotsc6HdXeXpQyrjHpssTbn1nnvqiiqgGkRi9w9V9LlksJrtt0KcBvfUU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-33929364bdaso2693204f8f.2 for ; Tue, 30 Jan 2024 04:11:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616710; x=1707221510; 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=SK4wuJ0WnqVoZ8MJRdmhnZwHJ1R1DRwZs66E4CruSAU=; b=M0U+uaZwVnQRZCm4Ey5Z3b5iObGbl6JLHhYTqPkr8h1Kj6/uQwZtX93zZvwFQjobJA lpFLUoJcPeoYWHWx5fkxQ8MDQwgxBD6Tceudo4WsqWhc65RtSOhKmTu3nvMitCJEYeiP e+tPaznXdL7NE+BbXHgMA5/+BMGIAmvmV6sRQ/uUE01q+qy9CbDp6E8WpXi15+JOskop /ER/Ag0gvFYW7yuIC7PD4Ma5yWndUliw6Ak8CPvFWron3gb+lJShKhVueb1dSBhn/Wq4 4QZvsj6CimgZrCzP8jzZ5tUNFkNdlmEft0MQ+ExXBN8bcMf+gtADWyA1JSFcm6Uhtcu8 MrYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616710; x=1707221510; 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=SK4wuJ0WnqVoZ8MJRdmhnZwHJ1R1DRwZs66E4CruSAU=; b=XTFF6mFqQbU8qI3pdfmgPCoGbCiZ08RNPg8PwbRAlhz26iy/hUhY2B6AP3AeqC6fko D2ETzAzFYiUruvc1aQ7j5MH9CpGRwxu17Ko4vlmKIPxqNkHvAMeqoFVjj9eyIqXkCFGd gAfIHNIxvcfoUXc0O5lpO2pGD1UR3O9NWGQoukr2/xdJtR4MItPYY/ttQskldZHgT0f5 GLX9IAR2bhOjPuoo3tYa5IJv/WwgjuUhR8auUTS8UXycCW6Pnk4XfoR344yKmlzZBaTq ShF09GVdNX+1bnADeZIYqAXixgq8QercmvA8WlnRroUJEB0HZkO85U7MIdhWPrKRsehH PxcA== X-Gm-Message-State: AOJu0YwhlgKbqzZRvFIGecj8t1N4g/+F2MVwjHNCrMkCRSTkQV+LzOQK 51B+wPljsJYgmGAjzKg9lsU4QlFXKreZgKOWANJED+Mw/D/YiaS/TK2yUrBUK8O3YsBcvaT3VNH ZlQ== X-Google-Smtp-Source: AGHT+IHUBGl2Qv+vojAwXNxYLRJuViMtzW8Izt5TZLbJB5+2vo1zs+EmixInI4qrjIpLKUPIFa6g8w== X-Received: by 2002:a5d:6383:0:b0:33a:ed8c:1a6a with SMTP id p3-20020a5d6383000000b0033aed8c1a6amr3921776wru.64.1706616710058; Tue, 30 Jan 2024 04:11:50 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:49 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 082/101] gccrs: ast: Fix lifetime type parsing Date: Tue, 30 Jan 2024 13:07:38 +0100 Message-ID: <20240130121026.807464-85-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.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, 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: Jakub Dupak There was a mismatch whether lifetime 'static is parsed as "static" or "'static". gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::lifetime_from_token): Fix matched pattern. Signed-off-by: Jakub Dupak --- gcc/rust/parse/rust-parse-impl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 378b9ada5ed..90bc2e214e4 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -4158,11 +4158,11 @@ Parser::lifetime_from_token (const_TokenPtr tok) location_t locus = tok->get_locus (); std::string lifetime_ident = tok->get_str (); - if (lifetime_ident == "'static") + if (lifetime_ident == "static") { return AST::Lifetime (AST::Lifetime::STATIC, "", locus); } - else if (lifetime_ident == "'_") + else if (lifetime_ident == "_") { return AST::Lifetime (AST::Lifetime::WILDCARD, "", locus); } From patchwork Tue Jan 30 12:07:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892889 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=LXY11vOu; 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 4TPPqw4BXYz23dQ for ; Tue, 30 Jan 2024 23:39:24 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 918D4386D609 for ; Tue, 30 Jan 2024 12:39:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 0845B38582A1 for ; Tue, 30 Jan 2024 12:11:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0845B38582A1 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 0845B38582A1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::434 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616756; cv=none; b=CUkTMMrKTWGYVi70Tt70Wa1cJf5gF3gqUa2K/M3XMbZk5h/mrRWVvNrzaS5SnNsxb5w6HK4K7v5FVq6aIRuX/IdFrRx2/+N42ddANy2mMUP/8Dlcl/q50cNDQs9MH+DKA++UYKtTIaYH+k09jN180s4qrVKHlJcLVCrTiYfTYNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616756; c=relaxed/simple; bh=B4ADjOzKdm3sYx0AaonWIbwdt6jbi9atqLgpk8PdbCo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=HGoLmODq/MP/mhK4/537KsbhiAR+trk42hU4dFW+39IB5YMZlhQkZtA1XcSWKIfP+hG1KikJcajqk/AjqPoZlgSmlBlWFYmUwf/iiJ65o3DWpW0gP1i3lFNKR+dquvOduyPKBrY/ElQ/+DazE2UrhsIZycHV9NNtKMEuJ7gXcNE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-33ae2d80b70so1860343f8f.0 for ; Tue, 30 Jan 2024 04:11:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616710; x=1707221510; 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=INjL0mXwk11RZ5qYUshsl68a1MU/pQHo+PS67zkndzA=; b=LXY11vOupJF3dbMyrLbR6r5ZKWJ8S3F6//WxbMVQKMYUtMhS/M2Y7+4nqSNz+9Iw5x WpsIoGQDh6R38LCWVCv9KRVqgHAU5Ov1W+u5EqMlqGbjLDUsEBQ9UfJ0d4eqpdNKmZh1 XvLIsVpgAD4In47rCe9qwUOJWzuRJsLBG+FlKXdQrXjWBBLexaph1GkWuzcGsibD/uVa Ii5w6Ee5SQxVLmDAMpXnprE9O7Zs1/GltFcZQ1IiwooclJoEfH0AMcQQSROqGqrF1RxG nIwc6izW3eOgzm41cjCY5MqWdPxY+RkVRrvs32TTPtdC8mLpz2qMkoeD7vas6ePxgCbh 8AFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616710; x=1707221510; 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=INjL0mXwk11RZ5qYUshsl68a1MU/pQHo+PS67zkndzA=; b=AbXmVDg/wDUpww0Xvp45fZh6CKz2fkWoxlBcGHYcpPlTs8Ka/R953jUxxE+MJ0oMju Jv+hSzbUFuvAVTf7XHIIi6wXBN/oYPA2d4xWocjTsQCGLvpkgOaXYpwz/buyvmi0Eu6R lv5qsREs3fhqZABpYJU6pH3m0q3w5t3foBjFZydWJr0A4xUkSLXpnqQ2mNwLb1daKx/u YEkNH1E7hF0++lyCQG/r9/MmhmwSD56sxcW0YzLB+vDDT19kdJjBEI0khLaek1z4zhaY J+6sGnTdjSnU+NSwJRhCnuaqnbtgrvasrdFKalLIE++J186p8rNuwxk7iUDyUht2kvwB ztgw== X-Gm-Message-State: AOJu0YxFXrk1y4anTpj0KqIZZnLLL2ydF2vL7zaNT8hvatoaOCTwhiFK 1G8o47LF+mGx77XbiwkKrxzKi5bTsHi7ONgdMhn41VGa31N94uOWpvENpF02wRgS4jDZAHTj4qQ S0w== X-Google-Smtp-Source: AGHT+IGlUEnYmL0/iWvJBaQdZN8pHWpG8rDTo0oaO5KY1oix5mgNHD2jONe8J4oRJlL52nGaluNGdg== X-Received: by 2002:a5d:588a:0:b0:33a:f41e:f68b with SMTP id n10-20020a5d588a000000b0033af41ef68bmr4261432wrf.25.1706616710525; Tue, 30 Jan 2024 04:11:50 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:50 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 083/101] gccrs: ast: Unify explicitly and implicitly elided lifettimes Date: Tue, 30 Jan 2024 13:07:39 +0100 Message-ID: <20240130121026.807464-86-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.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, 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: Jakub Dupak gcc/rust/ChangeLog: * ast/rust-ast.h: Elided lifetime static constructor * ast/rust-type.h: Default lifetime to elided. * parse/rust-parse-impl.h (Parser::parse_lifetime_param): Use elided lifetime. (Parser::parse_lifetime): Use elided lifetime/ (Parser::lifetime_from_token): Use elided lifetime. (Parser::parse_self_param): Use elided lifetime. (Parser::parse_reference_type_inner): Use elided lifetime. Signed-off-by: Jakub Dupak --- gcc/rust/ast/rust-ast.h | 2 ++ gcc/rust/ast/rust-type.h | 2 +- gcc/rust/parse/rust-parse-impl.h | 10 ++++------ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index b193c67c69e..a45085489e8 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1512,6 +1512,8 @@ public: // Creates an "error" lifetime. static Lifetime error () { return Lifetime (NAMED, ""); } + static Lifetime elided () { return Lifetime (WILDCARD, ""); } + // Returns true if the lifetime is in an error state. bool is_error () const { diff --git a/gcc/rust/ast/rust-type.h b/gcc/rust/ast/rust-type.h index 1637367791c..91a9d2f5999 100644 --- a/gcc/rust/ast/rust-type.h +++ b/gcc/rust/ast/rust-type.h @@ -547,7 +547,7 @@ public: // Constructor ReferenceType (bool is_mut, std::unique_ptr type_no_bounds, - location_t locus, Lifetime lifetime = Lifetime::error ()) + location_t locus, Lifetime lifetime = Lifetime::elided ()) : lifetime (std::move (lifetime)), has_mut (is_mut), type (std::move (type_no_bounds)), locus (locus) {} diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 90bc2e214e4..0e2cfce1e19 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -3470,8 +3470,6 @@ Parser::parse_lifetime_param () return AST::LifetimeParam::create_error (); } lexer.skip_token (); - /* TODO: does this always create a named lifetime? or can a different type - * be made? */ AST::Lifetime lifetime (AST::Lifetime::NAMED, lifetime_tok->get_str (), lifetime_tok->get_locus ()); @@ -4141,10 +4139,9 @@ AST::Lifetime Parser::parse_lifetime () { const_TokenPtr lifetime_tok = lexer.peek_token (); - // create error lifetime if doesn't exist if (lifetime_tok->get_id () != LIFETIME) { - return AST::Lifetime::error (); + return AST::Lifetime::elided (); } lexer.skip_token (); @@ -4164,6 +4161,7 @@ Parser::lifetime_from_token (const_TokenPtr tok) } else if (lifetime_ident == "_") { + // Explicitly and implicitly elided lifetimes follow the same rules. return AST::Lifetime (AST::Lifetime::WILDCARD, "", locus); } else @@ -7177,7 +7175,7 @@ tl::expected, ParseSelfError> Parser::parse_self_param () { bool has_reference = false; - AST::Lifetime lifetime = AST::Lifetime::error (); + AST::Lifetime lifetime = AST::Lifetime::elided (); location_t locus = lexer.peek_token ()->get_locus (); @@ -9837,7 +9835,7 @@ std::unique_ptr Parser::parse_reference_type_inner (location_t locus) { // parse optional lifetime - AST::Lifetime lifetime = AST::Lifetime::error (); + AST::Lifetime lifetime = AST::Lifetime::elided (); if (lexer.peek_token ()->get_id () == LIFETIME) { lifetime = parse_lifetime (); From patchwork Tue Jan 30 12:07:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892869 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=HkBJ9FAR; 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 4TPPk32yMSz23fD for ; Tue, 30 Jan 2024 23:34:19 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 45660386D60E for ; Tue, 30 Jan 2024 12:34:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id EE3953857839 for ; Tue, 30 Jan 2024 12:11:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EE3953857839 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 EE3953857839 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::436 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616763; cv=none; b=g53xaWCYHybwec3oiba8IA0brJoH/qNp2K3ujjsezMTYPVif8yOIt/0ydcxuJvFUmbsFG1Mn7AQaVRqzg/acTD4Navt+gFLSaTR8lwFgk6AjYQwKwiHCu4v2uBrQudwpe+QRFZyYxkeS0MwdNGmO5R17FLTlBtX3L5a79/JG7m8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616763; c=relaxed/simple; bh=WQeaKoMZ0XC9Duhk/KKrzQ1d+2MTz0jXu3xHclgxsYQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=MkvI9Pi7Zvl6j2y1qxYlomxJfVywe+kAgDrCU08rAc3Qq21x8M3NDYgsXlEC3QPV0l1nOoDq77SpZ37/d385r1b/dhyZr3cNd89/se0tNvYJIZZcJnmbG3LipVf3BM3Flo4+L7gDBGV1S3FTAedny86D0Wl/Ef2Y0lanEoWGSoc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-33aeb088324so1539677f8f.2 for ; Tue, 30 Jan 2024 04:11:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616711; x=1707221511; 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=ab4EMeg2V1GNvrF4isGq5h3MQhKi7yi0KGUuDXlyvfQ=; b=HkBJ9FARAvoPT2E0fnaS3/0mlZA+C8tKhJbkytoX8Z8ApsuZOfv55T25mxNRQZzrVA NTkw9/xD//TvGfRcPEmfG4xvFWM1FGMjBGMghpr/4PbILfJfQCTgXDVEEkigUVpnpuj4 9kGpeyyjFCzEQqmb4z4UaJXdEDCOujuqe7MC9waUbWvTUa5bQRSez9q3fUmO3gbpugyo 7S58LTlsbFK7Zq9eYug130zmmkYSxf8x3BSZcLggUqoHWpKbNlbqhrb83ICHXteKjGKs //YcwF8Z6QTGlrdbp8IcmBvItzpPSrYa9zTUknyH2SDaEulvzY/LAN/FC6QIEYfRdU1r IwDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616711; x=1707221511; 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=ab4EMeg2V1GNvrF4isGq5h3MQhKi7yi0KGUuDXlyvfQ=; b=aofaq1tpOVmLaCqL1lzQZfdBOoL/eJMA0fb3rA5+iEq6ULV0cr341eiEFEGgFNCdU0 E4/SP+Sn+cu1qNQkYLrYQpkMGS+0JSd3Z2UkU8aLN2A4way1FM3YjusGLw1qXqfhSjsY G73mepxAtAKFZBqhugOUYK8CYr54tXncRmafinOFyizOmFIihEd2UJkVaEwmTdHnNDos 5DHQykxL6BPencXauoTK7eBDyBpe/PV/oMovb7uSXAPIsNI04uyWYPswxgAaJ0BBFy+K fZ4/yt0xg4QsE3QLEG9aqLHA3komfpAvNWb4Cz4wdLHdmEI7MHadinEM9Guh4eGUKD52 pN1Q== X-Gm-Message-State: AOJu0YyL7wRWQ1SI0bVyz0dlsV8z7Wtfa7Y4nX9+aOCqJTcd1x9O9wgs BRGgIQmkhM2pNoIM6hQE89ibL61zdKuNRehBXKRzSYJgPgpp0Fp1EiQGGYWZNUhuKDkIALECqkk rGg== X-Google-Smtp-Source: AGHT+IE1aExu1Tf9kA5nZBXZ0vtnKrY69++DqmnTtU8Ap0PkToC2pkX3bdSkIZjPF1qb+cwnS/6aiw== X-Received: by 2002:a5d:6746:0:b0:337:c4d8:a570 with SMTP id l6-20020a5d6746000000b00337c4d8a570mr5400537wrw.11.1706616710931; Tue, 30 Jan 2024 04:11:50 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:50 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 084/101] gccrs: ast: Full lifetime elision handling Date: Tue, 30 Jan 2024 13:07:40 +0100 Message-ID: <20240130121026.807464-87-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.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, 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: Jakub Dupak gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_generic_param): Lifetime elision control. (Parser::parse_lifetime_where_clause_item): Lifetime elision control. (Parser::parse_type_param_bound): Lifetime elision control. (Parser::parse_lifetime_bounds): Lifetime elision control. (Parser::parse_lifetime): Lifetime elision control. (Parser::parse_path_generic_args): Lifetime elision control. (Parser::parse_self_param): Lifetime elision control. (Parser::parse_break_expr): Lifetime elision control. (Parser::parse_continue_expr): Lifetime elision control. (Parser::parse_reference_type_inner): Lifetime elision control. * parse/rust-parse.h: Lifetime elision control. Signed-off-by: Jakub Dupak --- gcc/rust/parse/rust-parse-impl.h | 25 +++++++++++++------------ gcc/rust/parse/rust-parse.h | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 0e2cfce1e19..dfa2762c5c3 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -3099,7 +3099,7 @@ Parser::parse_generic_param (EndTokenPred is_end_token) switch (token->get_id ()) { case LIFETIME: { - auto lifetime = parse_lifetime (); + auto lifetime = parse_lifetime (false); if (lifetime.is_error ()) { rust_error_at ( @@ -3808,7 +3808,7 @@ template std::unique_ptr Parser::parse_lifetime_where_clause_item () { - AST::Lifetime lifetime = parse_lifetime (); + AST::Lifetime lifetime = parse_lifetime (false); if (lifetime.is_error ()) { // TODO: error here? @@ -4001,7 +4001,7 @@ Parser::parse_type_param_bound () { case LIFETIME: return std::unique_ptr ( - new AST::Lifetime (parse_lifetime ())); + new AST::Lifetime (parse_lifetime (false))); case LEFT_PAREN: case QUESTION_MARK: case FOR: @@ -4075,7 +4075,7 @@ Parser::parse_lifetime_bounds () while (true) { - AST::Lifetime lifetime = parse_lifetime (); + AST::Lifetime lifetime = parse_lifetime (false); // quick exit for parsing failure if (lifetime.is_error ()) @@ -4105,7 +4105,7 @@ Parser::parse_lifetime_bounds (EndTokenPred is_end_token) while (!is_end_token (lexer.peek_token ()->get_id ())) { - AST::Lifetime lifetime = parse_lifetime (); + AST::Lifetime lifetime = parse_lifetime (false); if (lifetime.is_error ()) { @@ -4136,12 +4136,13 @@ Parser::parse_lifetime_bounds (EndTokenPred is_end_token) * existing. */ template AST::Lifetime -Parser::parse_lifetime () +Parser::parse_lifetime (bool allow_elided) { const_TokenPtr lifetime_tok = lexer.peek_token (); if (lifetime_tok->get_id () != LIFETIME) { - return AST::Lifetime::elided (); + return (allow_elided) ? AST::Lifetime::elided () + : AST::Lifetime::error (); } lexer.skip_token (); @@ -6606,7 +6607,7 @@ Parser::parse_path_generic_args () location_t locus = t->get_locus (); while (!is_right_angle_tok (t->get_id ())) { - AST::Lifetime lifetime = parse_lifetime (); + AST::Lifetime lifetime = parse_lifetime (false); if (lifetime.is_error ()) { // not necessarily an error @@ -7227,7 +7228,7 @@ Parser::parse_self_param () // now test whether it has a lifetime if (lexer.peek_token ()->get_id () == LIFETIME) { - lifetime = parse_lifetime (); + lifetime = parse_lifetime (true); // something went wrong somehow if (lifetime.is_error ()) @@ -7763,7 +7764,7 @@ Parser::parse_break_expr (AST::AttrVec outer_attrs, AST::Lifetime label = AST::Lifetime::error (); if (lexer.peek_token ()->get_id () == LIFETIME) { - label = parse_lifetime (); + label = parse_lifetime (false); } // parse break return expression if it exists @@ -7794,7 +7795,7 @@ Parser::parse_continue_expr (AST::AttrVec outer_attrs, AST::Lifetime label = AST::Lifetime::error (); if (lexer.peek_token ()->get_id () == LIFETIME) { - label = parse_lifetime (); + label = parse_lifetime (false); } return std::unique_ptr ( @@ -9838,7 +9839,7 @@ Parser::parse_reference_type_inner (location_t locus) AST::Lifetime lifetime = AST::Lifetime::elided (); if (lexer.peek_token ()->get_id () == LIFETIME) { - lifetime = parse_lifetime (); + lifetime = parse_lifetime (true); if (lifetime.is_error ()) { Error error (lexer.peek_token ()->get_locus (), diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index 4291e4198a5..3fc86206de7 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -303,7 +303,7 @@ private: std::vector parse_lifetime_bounds (); template std::vector parse_lifetime_bounds (EndTokenPred is_end_token); - AST::Lifetime parse_lifetime (); + AST::Lifetime parse_lifetime (bool allow_elided); AST::Lifetime lifetime_from_token (const_TokenPtr tok); std::unique_ptr parse_external_type_item (AST::Visibility vis, AST::AttrVec outer_attrs); From patchwork Tue Jan 30 12:07:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892907 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=JArz0/FP; 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 4TPPyv0YJ0z23fD for ; Tue, 30 Jan 2024 23:45:27 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 014713831E35 for ; Tue, 30 Jan 2024 12:45:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 3F8993857BB8 for ; Tue, 30 Jan 2024 12:11:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3F8993857BB8 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 3F8993857BB8 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616764; cv=none; b=TR3BjZ2S/HoMQRT5UprmgXF3jKJFDqApSwW8zlKsftIwwmEhSyN7i99qh9FV5nI7Se09VdDrHwK9D3/NNoQ6Bz1Xb2TLXGuxhasi6Jfeyoh/xaYT86kecv1KV8g9AdArw8rLAsCRTfWdMzBmz8beOsTJUy7Q2bcLmAd3bLQQjio= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616764; c=relaxed/simple; bh=Y+kcoDI1zOueopKbI0KEGaxoL7e1q7A4uGA7/RNpdHg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=mtztmC4FwyW+GDODLP9JOgRYj66lzXww79LMLfRUvHQ8A5tIrhpwzBANudCYLIqIWwn8AVN/D2SDYscOH4ZA8exrsDoQTa3DY/y9anjb+hhmptuJcDtyBpsxykpAxfHMIrtSjfGA8I8gZg/Ry5vpYD1cmrOwc7zP37mhM/3OIKY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-33aef64f702so1047040f8f.3 for ; Tue, 30 Jan 2024 04:11:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616711; x=1707221511; 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=Xed2XFYivzbzeF4tBDYVFzJJNlIXCDve9cqXc60iRa4=; b=JArz0/FPxwrS2k7Rb73fo2Q4wcKOQjPttMvmefghmvYMaM/tDRsKvDmv6kDFGjasab lv1X95E27+i37k2B/mwGq4jQR7hPWWAW01/yIhkoRS8zW2V4pIJJZisIClAGQG2gKguU sPExCgScK+FWcIsk+ZBnz+wt9EanJKcHhTHjOcUlLpXiUlRUvl9zt8AJBD8EP5puTHUi aY9KqLwyycmM4h60l2va3S697INanlY4BG41fvDBiGpVjvINQ6QaESHABCn/tqq2LvHi 2FdzkFAlLft/9fMjSFU8AAE3MZ/8QqlWTpLMKw9VCYQI3VicVv7DSSqHROhWXFnbVu6I aYEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616712; x=1707221512; 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=Xed2XFYivzbzeF4tBDYVFzJJNlIXCDve9cqXc60iRa4=; b=QqxPWv3Hdy0qnT8evK9YD8MKUV13opaW7g/yrPA03EVv1wsiWOtizWE26vlz4N9AWj VW25ig5qx8LR+k8KYfggqIAltTgaWwf2tx6aABfHvJ6A0LYs/9LVFU6swD1k4szAgOTH cScdm4c4BoJVOiL+QS75CFvQ1REoOJGjh/rNl2dAedzvGjlRXuwcn4Rdnu8OtWnlyB+S he5Y+8c9hd+vS6TgNZwGM53gVIKtkmgXjvAjavHGnZ12huL/M8aZ8z0ywa9BNL1JhVgz VV9bndx0rCP8x0LY/qgHOfIwKNnABBLhuSmtDqCoMs6MBB1FA5+/wohEN1wPmyQ42BRQ 9oTg== X-Gm-Message-State: AOJu0YyL650dfNsEgzOPdPSegiO7fbxEsvB1dCrlw2fU6nx65v53Gf1Y 7SU6sMgzyzJWj5E4fjlTmYRkoug99UdYDxjJykUEwWph53yntFn+9AaaRbogSlE0A9sALOR2hkL 3XQ== X-Google-Smtp-Source: AGHT+IGStdeb2Ymxnqz2ONlaKH+mY+rxu7O6qI+eJf2N1j1rPyyDZhoN8CZKe9hY7VSYM3QHSUG2/Q== X-Received: by 2002:adf:fc12:0:b0:33a:eda8:3370 with SMTP id i18-20020adffc12000000b0033aeda83370mr4174692wrr.24.1706616711734; Tue, 30 Jan 2024 04:11:51 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:51 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 085/101] gccrs: ast: Infer static lifetime for const and static items Date: Tue, 30 Jan 2024 13:07:41 +0100 Message-ID: <20240130121026.807464-88-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.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, 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: Jakub Dupak (probably incomplete propagation) gcc/rust/ChangeLog: * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_lifetime): Propagate static requirement. * hir/rust-ast-lower-base.h: Propagate static requirement. * hir/rust-ast-lower-implitem.h: Propagate static requirement. * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Propagate static requirement. * hir/rust-ast-lower-type.cc (ASTLoweringType::translate): Propagate static requirement. (ASTLoweringType::visit): Propagate static requirement. * hir/rust-ast-lower-type.h: Propagate static requirement. Signed-off-by: Jakub Dupak --- gcc/rust/hir/rust-ast-lower-base.cc | 14 ++++++++++--- gcc/rust/hir/rust-ast-lower-base.h | 3 ++- gcc/rust/hir/rust-ast-lower-implitem.h | 3 ++- gcc/rust/hir/rust-ast-lower-item.cc | 5 +++-- gcc/rust/hir/rust-ast-lower-type.cc | 28 +++++++++++++++++--------- gcc/rust/hir/rust-ast-lower-type.h | 12 +++++++++-- 6 files changed, 46 insertions(+), 19 deletions(-) diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc index f8438557707..748cec74829 100644 --- a/gcc/rust/hir/rust-ast-lower-base.cc +++ b/gcc/rust/hir/rust-ast-lower-base.cc @@ -530,16 +530,24 @@ ASTLoweringBase::visit (AST::SelfParam ¶m) {} HIR::Lifetime -ASTLoweringBase::lower_lifetime (AST::Lifetime &lifetime) +ASTLoweringBase::lower_lifetime (AST::Lifetime &lifetime, + bool default_to_static_lifetime) { + auto lifetime_type = lifetime.get_lifetime_type (); + if (lifetime_type == AST::Lifetime::WILDCARD && default_to_static_lifetime) + { + // If compiling in a static context. + lifetime_type = AST::Lifetime::STATIC; + } + auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, lifetime.get_node_id (), mappings->get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID); mappings->insert_node_to_hir (mapping.get_nodeid (), mapping.get_hirid ()); - return HIR::Lifetime (mapping, lifetime.get_lifetime_type (), - lifetime.get_lifetime_name (), lifetime.get_locus ()); + return HIR::Lifetime (mapping, lifetime_type, lifetime.get_lifetime_name (), + lifetime.get_locus ()); } HIR::LoopLabel diff --git a/gcc/rust/hir/rust-ast-lower-base.h b/gcc/rust/hir/rust-ast-lower-base.h index d52afd3421f..8da11750d18 100644 --- a/gcc/rust/hir/rust-ast-lower-base.h +++ b/gcc/rust/hir/rust-ast-lower-base.h @@ -264,7 +264,8 @@ protected: Analysis::Mappings *mappings; Analysis::BuiltinAttributeMappings *attr_mappings; - HIR::Lifetime lower_lifetime (AST::Lifetime &lifetime); + HIR::Lifetime lower_lifetime (AST::Lifetime &lifetime, + bool default_to_static_lifetime = false); HIR::LoopLabel lower_loop_label (AST::LoopLabel &loop_label); diff --git a/gcc/rust/hir/rust-ast-lower-implitem.h b/gcc/rust/hir/rust-ast-lower-implitem.h index 6f904dde19f..81dae14cdca 100644 --- a/gcc/rust/hir/rust-ast-lower-implitem.h +++ b/gcc/rust/hir/rust-ast-lower-implitem.h @@ -88,7 +88,8 @@ public: { HIR::Visibility vis = translate_visibility (constant.get_visibility ()); - HIR::Type *type = ASTLoweringType::translate (constant.get_type ().get ()); + HIR::Type *type + = ASTLoweringType::translate (constant.get_type ().get (), true); HIR::Expr *expr = ASTLoweringExpr::translate (constant.get_expr ().get ()); auto crate_num = mappings->get_current_crate (); diff --git a/gcc/rust/hir/rust-ast-lower-item.cc b/gcc/rust/hir/rust-ast-lower-item.cc index 2895872f336..7ef556fee0d 100644 --- a/gcc/rust/hir/rust-ast-lower-item.cc +++ b/gcc/rust/hir/rust-ast-lower-item.cc @@ -351,7 +351,7 @@ ASTLoweringItem::visit (AST::StaticItem &var) { HIR::Visibility vis = translate_visibility (var.get_visibility ()); - HIR::Type *type = ASTLoweringType::translate (var.get_type ().get ()); + HIR::Type *type = ASTLoweringType::translate (var.get_type ().get (), true); HIR::Expr *expr = ASTLoweringExpr::translate (var.get_expr ().get ()); auto crate_num = mappings->get_current_crate (); @@ -372,7 +372,8 @@ ASTLoweringItem::visit (AST::ConstantItem &constant) { HIR::Visibility vis = translate_visibility (constant.get_visibility ()); - HIR::Type *type = ASTLoweringType::translate (constant.get_type ().get ()); + HIR::Type *type + = ASTLoweringType::translate (constant.get_type ().get (), true); HIR::Expr *expr = ASTLoweringExpr::translate (constant.get_expr ().get ()); auto crate_num = mappings->get_current_crate (); diff --git a/gcc/rust/hir/rust-ast-lower-type.cc b/gcc/rust/hir/rust-ast-lower-type.cc index 5388f2139ce..5cea71f83a2 100644 --- a/gcc/rust/hir/rust-ast-lower-type.cc +++ b/gcc/rust/hir/rust-ast-lower-type.cc @@ -180,9 +180,9 @@ ASTLowerQualifiedPathInType::visit (AST::QualifiedPathInType &path) } HIR::Type * -ASTLoweringType::translate (AST::Type *type) +ASTLoweringType::translate (AST::Type *type, bool default_to_static_lifetime) { - ASTLoweringType resolver; + ASTLoweringType resolver (default_to_static_lifetime); type->accept_vis (resolver); rust_assert (resolver.translated != nullptr); @@ -222,7 +222,8 @@ ASTLoweringType::visit (AST::BareFunctionType &fntype) } HIR::Type *param_type - = ASTLoweringType::translate (param.get_type ().get ()); + = ASTLoweringType::translate (param.get_type ().get (), + default_to_static_lifetime); HIR::MaybeNamedParam p (param.get_name (), kind, std::unique_ptr (param_type), @@ -234,7 +235,8 @@ ASTLoweringType::visit (AST::BareFunctionType &fntype) if (fntype.has_return_type ()) { return_type - = ASTLoweringType::translate (fntype.get_return_type ().get ()); + = ASTLoweringType::translate (fntype.get_return_type ().get (), + default_to_static_lifetime); } auto crate_num = mappings->get_current_crate (); @@ -254,7 +256,8 @@ ASTLoweringType::visit (AST::TupleType &tuple) std::vector> elems; for (auto &e : tuple.get_elems ()) { - HIR::Type *t = ASTLoweringType::translate (e.get ()); + HIR::Type *t + = ASTLoweringType::translate (e.get (), default_to_static_lifetime); elems.push_back (std::unique_ptr (t)); } @@ -283,7 +286,8 @@ void ASTLoweringType::visit (AST::ArrayType &type) { HIR::Type *translated_type - = ASTLoweringType::translate (type.get_elem_type ().get ()); + = ASTLoweringType::translate (type.get_elem_type ().get (), + default_to_static_lifetime); HIR::Expr *array_size = ASTLoweringExpr::translate (type.get_size_expr ().get ()); @@ -301,10 +305,12 @@ ASTLoweringType::visit (AST::ArrayType &type) void ASTLoweringType::visit (AST::ReferenceType &type) { - HIR::Lifetime lifetime = lower_lifetime (type.get_lifetime ()); + HIR::Lifetime lifetime + = lower_lifetime (type.get_lifetime (), default_to_static_lifetime); HIR::Type *base_type - = ASTLoweringType::translate (type.get_base_type ().get ()); + = ASTLoweringType::translate (type.get_base_type ().get (), + default_to_static_lifetime); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, type.get_node_id (), @@ -322,7 +328,8 @@ void ASTLoweringType::visit (AST::RawPointerType &type) { HIR::Type *base_type - = ASTLoweringType::translate (type.get_type_pointed_to ().get ()); + = ASTLoweringType::translate (type.get_type_pointed_to ().get (), + default_to_static_lifetime); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, type.get_node_id (), @@ -343,7 +350,8 @@ void ASTLoweringType::visit (AST::SliceType &type) { HIR::Type *base_type - = ASTLoweringType::translate (type.get_elem_type ().get ()); + = ASTLoweringType::translate (type.get_elem_type ().get (), + default_to_static_lifetime); auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, type.get_node_id (), diff --git a/gcc/rust/hir/rust-ast-lower-type.h b/gcc/rust/hir/rust-ast-lower-type.h index 8194a9ace5e..ed90c17bb0f 100644 --- a/gcc/rust/hir/rust-ast-lower-type.h +++ b/gcc/rust/hir/rust-ast-lower-type.h @@ -63,7 +63,8 @@ class ASTLoweringType : public ASTLoweringBase using Rust::HIR::ASTLoweringBase::visit; public: - static HIR::Type *translate (AST::Type *type); + static HIR::Type *translate (AST::Type *type, + bool default_to_static_lifetime = false); void visit (AST::BareFunctionType &fntype) override; void visit (AST::TupleType &tuple) override; @@ -79,7 +80,14 @@ public: void visit (AST::TraitObjectType &type) override; private: - ASTLoweringType () : ASTLoweringBase (), translated (nullptr) {} + ASTLoweringType (bool default_to_static_lifetime) + : ASTLoweringBase (), + default_to_static_lifetime (default_to_static_lifetime), + translated (nullptr) + {} + + /** Used when compiling const and static items. */ + bool default_to_static_lifetime; HIR::Type *translated; }; From patchwork Tue Jan 30 12:07:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892892 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=OIeZPT13; 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 4TPPrr2xd4z23gZ for ; Tue, 30 Jan 2024 23:40:12 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5D90D3870C18 for ; Tue, 30 Jan 2024 12:40:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id DC903385771B for ; Tue, 30 Jan 2024 12:11:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DC903385771B 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 DC903385771B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::434 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616762; cv=none; b=QF6SujnsNb9bu6ootr7xA+pGn4NSf8xUYWuVhPNyITHRz4qeHLVdL+wtaVuFYfC/ki1BDGdvrle/BucAOOQ4miTXiORbHwJyEvKnTE7+6m7HetBL0yy2tBB/DFKhcrLJU+RNFQsVMdB3RZxxvTXroeXAHyaaSacOCx9ZVqwxbZ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616762; c=relaxed/simple; bh=SwsdehIIXopaxo95WKAxUaBuDLIxl19sNBc8bxv0Ww4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tTayHOFjM9ZMlQtbnoXMOXtbvJWzkXZEDV9jVsk3u48Z6UFT45WaASUnu1Q0D9Payx8QY+DXShZRu09ylQj2edhJyCGFMlHyLnL8EFoAwIcNZY2nrYA680LSFPuWT3vR0GfHRY5okGr5XDi9giCzZ6roe0c80qsgeQOe+QJ4F6g= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-33ae6f4fd78so1765550f8f.1 for ; Tue, 30 Jan 2024 04:11:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616712; x=1707221512; 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=8nxhuSYmYUi2biIvpUSM4Sr3ZLCRrNYtsBtLZk3rGpg=; b=OIeZPT13b8BTY6/yXp1RRT9qZfJG9k5EO7GsT6U2dKgdFHulpxCDgkeIK3AbFWE6eS A+3fjSLg3daV9+73Tdc4o52W6h+cjFvgy5JnmWOry1HRWbsjTgv1n+752MbYQ+Gbk+9w kdnjL+CSkdFHY7o5IuJe4RclNyzYBbaW1opE5/h5DZDhI6g3gv5a+f0MeYOi3cTSQ3PH FWopIUQ4Tbv/IIUNdLvkBLNgD3MAf/o4k/YQfthDyQouVOResGmaclPOc7n/unOMeHLd YvVQSKOBROlb9iv/fycFZ5zJDQ+L00qZ0wpM8M5aYitb4alUz7dqCR10qv5fugTlkEup ypXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616712; x=1707221512; 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=8nxhuSYmYUi2biIvpUSM4Sr3ZLCRrNYtsBtLZk3rGpg=; b=Rv36ewoP8PL1WUO2fLSxPjt/i8fQ+BvJURUROgntssVqz4VUjmxX5vI/N9Sie0Oufa hwNabQYunL/PPHhScsWi53CcpC/ky0QacM48+47pF6GOJBC/PIBfqqTkQbh1lEUzuWLW eGQVGc5KaI1x/Iw7eHHTULmcwBaMn6PWqp7kPxhDF9IH06NutIkRaVV0kzp/s5I3ArbK +ARDbZ/4wT2ALrcAQW1li+prQ6Yi44B28wmriwfWJG8GMn0PBO5NtA0zECnh9JKq/nC6 ms+VurJN/sNXsb622C1uNE2AbFSLlmZELhnYJKNRbdWHHrQCM6NGTETSvvHo701HHEtN AycQ== X-Gm-Message-State: AOJu0YztbJ66vtzOmaEpFHCktYX84ovQQSF8XGAQoRbQbRDESb2o7def LtSezoFUgKiSAEKSZLFNKUQYpACjp7VxtR7HuQgBd5fEnQ3rKrtz8mQBlgf0OI+q8XNZ4ZVrFC/ ykw== X-Google-Smtp-Source: AGHT+IF7U2yuVdLqnXQDbqHJqzWLrp43V7qCIswE5rbW8oTq803iJV21Avzzr/mo6du1qr/HKVqC+g== X-Received: by 2002:a5d:6a0f:0:b0:33a:e7aa:2fd5 with SMTP id m15-20020a5d6a0f000000b0033ae7aa2fd5mr4053252wru.58.1706616712085; Tue, 30 Jan 2024 04:11:52 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:51 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 086/101] gccrs: ast: Lower 'for' lifetimes Date: Tue, 30 Jan 2024 13:07:42 +0100 Message-ID: <20240130121026.807464-89-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.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, 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: Jakub Dupak gcc/rust/ChangeLog: * hir/rust-ast-lower-type.cc (ASTLoweringType::visit): For lifetimes. Signed-off-by: Jakub Dupak --- gcc/rust/hir/rust-ast-lower-type.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gcc/rust/hir/rust-ast-lower-type.cc b/gcc/rust/hir/rust-ast-lower-type.cc index 5cea71f83a2..a0178ebf490 100644 --- a/gcc/rust/hir/rust-ast-lower-type.cc +++ b/gcc/rust/hir/rust-ast-lower-type.cc @@ -199,6 +199,13 @@ ASTLoweringType::visit (AST::BareFunctionType &fntype) { bool is_variadic = false; std::vector lifetime_params; + for (auto &lifetime_param : fntype.get_for_lifetimes ()) + { + auto generic_param = ASTLowerGenericParam::translate (&lifetime_param); + lifetime_params.push_back ( + *static_cast (generic_param)); + } + HIR::FunctionQualifiers qualifiers = lower_qualifiers (fntype.get_function_qualifiers ()); From patchwork Tue Jan 30 12:07:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892896 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=cOKDsyj3; 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 4TPPtB52hLz23gZ for ; Tue, 30 Jan 2024 23:41:22 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7F7D3385E45E for ; Tue, 30 Jan 2024 12:41:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 4AF3B3857708 for ; Tue, 30 Jan 2024 12:11:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4AF3B3857708 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 4AF3B3857708 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::436 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616765; cv=none; b=YrMQ1hCrbyDZbpKSbLT7jYY+uAYMR3lszoUmSIDhLc7hiKOpE9bjLGOPrx0b+7OOUX6vJgQW7PxKfiN3h7RXQm9md/B6YSy3P/rkKo3xkw0yjV8BFjzq5aHaBchke16uspvr6yFVuyZ7wWm2MEg/46+D43Dclz1Z4h7juI6MWEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616765; c=relaxed/simple; bh=irBJwNhO1l3ARJPuyLTROgho9tbJ40AQ8Zi8AFDQ6Jw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=BFEIdftyu5XX/C6hUJyq5FDEoHCyXzK1Dibil4b0uo1KPnYtIX6Fr+nrGbXIqYAgYw95BP++XtB7hZ2BLiwwps+BVTMCng4OpUAJyJKpDGnhbN2o9YwAg9BXXssC21LUzXXsV4XEo+vQp4sO4750gT2cHvSY6G8nLznSAMXK/CE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-33af3c7ef60so1152349f8f.0 for ; Tue, 30 Jan 2024 04:11:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616713; x=1707221513; 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=+V0ES9rIlpfph/NGd5qjXXQp2pTd9XhCqRBek8WS8jk=; b=cOKDsyj3ZN8hXZs/j/IPd8VcZYS8fhBFJS79TGuhvLhppSWRzh/ms1Dca0OzuMCq0E XUseS5A9Rnec0hSQ00TQXZX2c5vMp9CB+8vxnD2CwoVYQL11wryvgT02lsBh1ysYFDkg FvDmEos/U/pO6pJBOLCx3SXVOAIPxdMjC06vtNLRdfs9pr1cbrTu4eQMludr7LikMRBh OdzJKFpofwpkecDcqBY/UFTH8Q+gjOOgGA/gmIWuL41NZbF2wpwPYRUbCi6yqWtqvNk5 VKn1zw5xlcGof33SDf3AmrdMF6MyUfCcgXZDw2BCUXV2lUl9v+E6QxcsNA7ub3cpJkPV ISgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616713; x=1707221513; 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=+V0ES9rIlpfph/NGd5qjXXQp2pTd9XhCqRBek8WS8jk=; b=Runpv629Rkeo/TGkBsEaAUrscKPS2Q52ts3obzZpxZHprfxsNk3amuF8zBS5OPfIuj 9kZzM+pD8i4/R7VYH6YJ98X9kwpe5B0vZaHYpkYLv6iV34JLgCq1Mm+6CJeO9iBWPfM0 Nv+HfPo0kpsNTo90ERYzYAb5gihdiofOb+8wOFwQmTGI3GbBemPqtocLG0KMlnkEbogZ aQZxALB0KyVB6C5cRJ8S6BQIdPlLqNu4D/fV+YM1xbRtL0IcH7dTZqHPP4tU5+Swsftj R86PgKbFvfDeAST6H7b37vC4VJuxFpwdtrHT31a+C16JM+6y7tw8/vs6fo+UvT1MJi5F zdJw== X-Gm-Message-State: AOJu0YwLKj1BipKZTuyxOHnhZWGT2UTGedB40g8cDO4v2fEkaIIZzrmA SqX5zVV/M3xL3zelsP/MQMrprJSoBgLxDoiz2I70bni9hYK/mQOHsFxD05rywT4kAzQbyYLAuSv rgA== X-Google-Smtp-Source: AGHT+IHYssxNgPH5xqlaty5iajl/rdVUq2pbaUKg2ivaLtAiwEPvw02uVJZJqi7OGACBQ0kQ1Gw7Tw== X-Received: by 2002:a5d:510f:0:b0:33a:e7de:aa8b with SMTP id s15-20020a5d510f000000b0033ae7deaa8bmr4448042wrt.26.1706616712489; Tue, 30 Jan 2024 04:11:52 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:52 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 087/101] gccrs: TyTy: Refactor FnType deprecated API Date: Tue, 30 Jan 2024 13:07:43 +0100 Message-ID: <20240130121026.807464-90-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.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, 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: Jakub Dupak gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): Use new API. * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Use new API. * typecheck/rust-tyty-cmp.h: Remove old API. * typecheck/rust-tyty.cc (FnPtr::is_equal): Use new API. * typecheck/rust-tyty.h: Remove old API. * typecheck/rust-unify.cc (UnifyRules::expect_fnptr): Use new API. Signed-off-by: Jakub Dupak --- gcc/rust/backend/rust-compile-expr.cc | 2 +- gcc/rust/typecheck/rust-tyty-call.cc | 2 +- gcc/rust/typecheck/rust-tyty-cmp.h | 6 +++--- gcc/rust/typecheck/rust-tyty.cc | 2 +- gcc/rust/typecheck/rust-tyty.h | 3 --- gcc/rust/typecheck/rust-unify.cc | 6 +++--- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index e0917f68660..596b848849e 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -1198,7 +1198,7 @@ CompileExpr::visit (HIR::CallExpr &expr) if (base->get_kind () == TyTy::TypeKind::FNPTR) { const TyTy::FnPtr *fn = static_cast (base); - *result = fn->param_at (index); + *result = fn->get_param_type_at (index); return true; } diff --git a/gcc/rust/typecheck/rust-tyty-call.cc b/gcc/rust/typecheck/rust-tyty-call.cc index 31afe046a13..a28780bcac3 100644 --- a/gcc/rust/typecheck/rust-tyty-call.cc +++ b/gcc/rust/typecheck/rust-tyty-call.cc @@ -271,7 +271,7 @@ TypeCheckCallExpr::visit (FnPtr &type) for (auto &argument : call.get_arguments ()) { location_t arg_locus = argument->get_locus (); - BaseType *fnparam = type.param_at (i); + BaseType *fnparam = type.get_param_type_at (i); auto argument_expr_tyty = Resolver::TypeCheckExpr::Resolve (argument.get ()); if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR) diff --git a/gcc/rust/typecheck/rust-tyty-cmp.h b/gcc/rust/typecheck/rust-tyty-cmp.h index 6d4bc16bf6e..98ff1dc664e 100644 --- a/gcc/rust/typecheck/rust-tyty-cmp.h +++ b/gcc/rust/typecheck/rust-tyty-cmp.h @@ -800,8 +800,8 @@ public: for (size_t i = 0; i < base->num_params (); i++) { - auto this_param = base->param_at (i); - auto other_param = type.param_at (i); + auto this_param = base->get_param_type_at (i); + auto other_param = type.get_param_type_at (i); if (!this_param->can_eq (other_param, emit_error_flag)) { BaseCmp::visit (type); @@ -830,7 +830,7 @@ public: for (size_t i = 0; i < base->num_params (); i++) { - auto this_param = base->param_at (i); + auto this_param = base->get_param_type_at (i); auto other_param = type.param_at (i).second; if (!this_param->can_eq (other_param, emit_error_flag)) { diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index e9b42ebebee..f1789f008a0 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -2123,7 +2123,7 @@ FnPtr::is_equal (const BaseType &other) const for (size_t i = 0; i < num_params (); i++) { - if (!param_at (i)->is_equal (*other2.param_at (i))) + if (!get_param_type_at (i)->is_equal (*other2.get_param_type_at (i))) return false; } return true; diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index 2ed407ee169..b04048f400d 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -926,9 +926,6 @@ public: size_t num_params () const { return params.size (); } - // DEPRECATED: Use get_param_type_at - BaseType *param_at (size_t idx) const { return get_param_type_at (idx); } - void accept_vis (TyVisitor &vis) override; void accept_vis (TyConstVisitor &vis) const override; diff --git a/gcc/rust/typecheck/rust-unify.cc b/gcc/rust/typecheck/rust-unify.cc index 3027f099739..8b43380cc59 100644 --- a/gcc/rust/typecheck/rust-unify.cc +++ b/gcc/rust/typecheck/rust-unify.cc @@ -1009,8 +1009,8 @@ UnifyRules::expect_fnptr (TyTy::FnPtr *ltype, TyTy::BaseType *rtype) for (size_t i = 0; i < ltype->num_params (); i++) { - auto a = ltype->param_at (i); - auto b = type.param_at (i); + auto a = ltype->get_param_type_at (i); + auto b = type.get_param_type_at (i); auto unified_param = UnifyRules::Resolve (TyTy::TyWithLocation (a), @@ -1058,7 +1058,7 @@ UnifyRules::expect_fnptr (TyTy::FnPtr *ltype, TyTy::BaseType *rtype) for (size_t i = 0; i < ltype->num_params (); i++) { - auto this_param = ltype->param_at (i); + auto this_param = ltype->get_param_type_at (i); auto other_param = type.param_at (i).second; auto unified_param From patchwork Tue Jan 30 12:07:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892933 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=VJqSEiYh; 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 4TPQ7f3q6yz23dQ for ; Tue, 30 Jan 2024 23:53:02 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 862EA3860753 for ; Tue, 30 Jan 2024 12:53:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id E52CA3858437 for ; Tue, 30 Jan 2024 12:11:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E52CA3858437 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 E52CA3858437 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616767; cv=none; b=ux5+bnwPIwHwSVS9MvARMONXNH8ynSaLb7jyCE8a5KCcdtRcr8mw+2FlnSgicPho/6cPwONX33kIl22J+tnySBXuif0qItC/sQmXf7hXU20WgYze+RbcRuf7JsHQEMojHFDxYtXBTv0leDw1w7PqiFqumf3gfr5JGshCEAWN1Ig= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616767; c=relaxed/simple; bh=ZN0rvn8in8ZMbV5vZetI+gc+H51uej32P4tuU6SOCIo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=rI0z4A4GXN6Bp/UWKKOzXFZoN76MxvmzbetHFEMJpeY1iA8lscZ1p/THWxy80uiiPieueX3FGoAvjiGWke5JT+2wQ4BCVPjTs0wfVFYaCxzfn7hC9uM9FhYH6Ku7sC4polDXlxGSzRfzpHkZjQSPlyfzpvcPgfjM0Qe2TPwKOac= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-33af4a0beb3so1012938f8f.2 for ; Tue, 30 Jan 2024 04:11:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616713; x=1707221513; 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=ImOjUA18ADzQV3sCjjzF2siEn4ZR/3JrQmRxSl8A3jA=; b=VJqSEiYh/m0Z0k8HhBpgMiIw8fS32RBq/5VXYZPw4sJlbAVRWrq1TEx2S8sx5Z9jp3 +7iAVXPMmTRQYpXaZecYdB4N1aLWlP+THkU0yJbt2ZqATQ74qfUNMCFvlRAvfhHxhK4h vWQh9Ox6Wr8KoX0I1hGU8r+XzguRUythpyTcnEpFUJXMu73NFJaQ3vPkW513LylVt2o0 fg97z4VBBfhGoRoDsuMBK7SXfV2hMNkShemn5pHsS0AlBZVrRRS9s+iabgLhu8U1Ig1T anC+cr/mBKmMnL4BKH01rgBu+5gRsExsEEz6ew/lngkKf+OASIuu9gm/PWmcERQHBHkt iMCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616713; x=1707221513; 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=ImOjUA18ADzQV3sCjjzF2siEn4ZR/3JrQmRxSl8A3jA=; b=EfSiRxRBMMY80nzWWsbS4W674MbTmKO5dTBzoLoVUlTWmkPNQ0ePhT4oW1g7Rcw/jY hRBNh81cjKEQ5twUSiPCMK88gqrpVTUKhPb9zjGK5VLYsPs8dUfgo8GJxbwpdQZ9OKfp xJTzh3bCQTqrAsJl3jVVpbC4Bp9Q1f9CR2F9ta7rn5ZGAogOI08LDWSHxwfvgRI7vX5B VjLhT8BhKp/cCBkehVFNhufb5QOwV/EBDsriU/hBf8FpfWLCjPjzFf715SuA4XZsPRkZ bS6QZhlh3oHaWuHbt5R528VlIKTOWS3zY7ykasjmmIjF3Kq1I8qdiI3bplfGDVKcc+LE PAiA== X-Gm-Message-State: AOJu0YxuEgHraljZ+3XnXKsLhCGhwXvB39gsgKsqsGU1jhPhc2Z+waEv nMWSf95imBX7vCOu63x3MJAlTFl5/Qd4Ji/Y+WeBTNkEn8E1YnDaMGRJY589FLulqviKjD1cVjh NSA== X-Google-Smtp-Source: AGHT+IFAFp7a6cPlE+p/I6AR5DySMYELf1pNh6JlOgmNppDdDr1QEkX6D2eVIXXpP8rIgBwckDH+xg== X-Received: by 2002:a05:6000:1542:b0:33a:ed2c:fea0 with SMTP id 2-20020a056000154200b0033aed2cfea0mr4326901wry.1.1706616712904; Tue, 30 Jan 2024 04:11:52 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:52 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Nirmal Patel Subject: [COMMITTED 088/101] gccrs: Handle newlines during string parsing while lexing Date: Tue, 30 Jan 2024 13:07:44 +0100 Message-ID: <20240130121026.807464-91-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.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, 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: Nirmal Patel If newline strings are encountered while lexing, the lexer now handles newline characters by incrementing current line number. This provides correct line number when displaying errors. If the lexer encounters end of file before string end, then it will use the start of the string as the location to an report error. gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::parse_byte_string): Handle newline while parsing byte strings (Lexer::parse_string): Handle newline while parsing strings Signed-off-by: Nirmal Patel --- gcc/rust/lex/rust-lex.cc | 40 ++++++++++++++----- gcc/testsuite/rust/compile/issue-2187.rs | 11 +++++ .../rust/execute/torture/issue-2187.rs | 23 +++++++++++ 3 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/rust/compile/issue-2187.rs create mode 100644 gcc/testsuite/rust/execute/torture/issue-2187.rs diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index 5bff2d9125c..6fc336d97e0 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -1766,13 +1766,15 @@ Lexer::parse_byte_string (location_t loc) std::string str; str.reserve (16); // some sensible default - int length = 1; current_char = peek_input (); + const location_t string_begin_locus = get_current_location (); + while (current_char != '"' && !current_char.is_eof ()) { if (current_char == '\\') { + int length = 1; auto escape_length_pair = parse_escape ('"'); char output_char = std::get<0> (escape_length_pair); @@ -1784,18 +1786,25 @@ Lexer::parse_byte_string (location_t loc) if (output_char != 0 || !std::get<2> (escape_length_pair)) str += output_char; + current_column += length; + continue; } - length++; + current_column++; + if (current_char.value == '\n') + { + current_line++; + current_column = 1; + // tell line_table that new line starts + start_line (current_line, max_column_hint); + } str += current_char; skip_input (); current_char = peek_input (); } - current_column += length; - if (current_char == '"') { current_column++; @@ -1805,7 +1814,7 @@ Lexer::parse_byte_string (location_t loc) } else if (current_char.is_eof ()) { - rust_error_at (get_current_location (), "unended byte string literal"); + rust_error_at (string_begin_locus, "unended byte string literal"); return Token::make (END_OF_FILE, get_current_location ()); } else @@ -1996,14 +2005,17 @@ Lexer::parse_string (location_t loc) std::string str; str.reserve (16); // some sensible default - int length = 1; current_char = peek_input (); + const location_t string_begin_locus = get_current_location (); + // FIXME: This fails if the input ends. How do we check for EOF? while (current_char.value != '"' && !current_char.is_eof ()) { if (current_char.value == '\\') { + int length = 1; + // parse escape auto utf8_escape_pair = parse_utf8_escape (); current_char = std::get<0> (utf8_escape_pair); @@ -2016,21 +2028,28 @@ Lexer::parse_string (location_t loc) if (current_char != Codepoint (0) || !std::get<2> (utf8_escape_pair)) str += current_char.as_string (); + current_column += length; + // FIXME: should remove this but can't. // `parse_utf8_escape` does not update `current_char` correctly. current_char = peek_input (); continue; } - length++; + current_column++; + if (current_char.value == '\n') + { + current_line++; + current_column = 1; + // tell line_table that new line starts + start_line (current_line, max_column_hint); + } str += current_char; skip_input (); current_char = peek_input (); } - current_column += length; - if (current_char.value == '"') { current_column++; @@ -2040,7 +2059,7 @@ Lexer::parse_string (location_t loc) } else if (current_char.is_eof ()) { - rust_error_at (get_current_location (), "unended string literal"); + rust_error_at (string_begin_locus, "unended string literal"); return Token::make (END_OF_FILE, get_current_location ()); } else @@ -2049,7 +2068,6 @@ Lexer::parse_string (location_t loc) } str.shrink_to_fit (); - loc += length - 1; return Token::make_string (loc, std::move (str)); } diff --git a/gcc/testsuite/rust/compile/issue-2187.rs b/gcc/testsuite/rust/compile/issue-2187.rs new file mode 100644 index 00000000000..deef417a668 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2187.rs @@ -0,0 +1,11 @@ +const A: &'static u8 = b" +"; +const B: &'static str = b" +"; +const C: &'static u8 = " +"; +const D: &'static str = " +"; +ERROR_TIME +// { dg-error "unrecognised token" "" { target *-*-* } .-1 } +// { dg-error "failed to parse item in crate" "" { target *-*-* } .-2 } diff --git a/gcc/testsuite/rust/execute/torture/issue-2187.rs b/gcc/testsuite/rust/execute/torture/issue-2187.rs new file mode 100644 index 00000000000..b5312575041 --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/issue-2187.rs @@ -0,0 +1,23 @@ +/* { dg-output "L1\n\L2\nL3\nL4" } */ +extern "C" { + fn printf(s: *const i8, ...); +} + +fn main() -> i32 { + let A = b"L1 +L2\0"; + let B = "L3 +L4\0"; + + unsafe { + let a = "%s\n\0"; + let b = a as *const str; + let c = b as *const i8; + + printf(c, A); + printf(c, B); + } + + 0 +} + From patchwork Tue Jan 30 12:07:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892923 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=CP+THBjL; 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 4TPQ4s2jZrz23dQ for ; Tue, 30 Jan 2024 23:50:37 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 53A883870C29 for ; Tue, 30 Jan 2024 12:50:35 +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 135333857715 for ; Tue, 30 Jan 2024 12:11:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 135333857715 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 135333857715 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=1706616766; cv=none; b=ivxbCVyKePDiqLJ3Mo4nFeW3qKtYn6RxQF+dx90KELi14YmD5DO5lTRgVtZIgX19QYMwhsz7peFdYaMrHFtRp4GbgL3mZu+7ONwWA8QQUxq1kPoncNWTiW9oVvzjGYh2nhohk5W9zIVsKfdJS+d08XG8fdDwP1QEb6tC/9WdCog= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616766; c=relaxed/simple; bh=WLmEbuZuCNSzxnWiTdJoX7lGY8hInPsouNyCN9PkNvY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hf1Rr9PzDbj+KktubztlUVVnV2B19aNhqjLmahc/EBzqB+CEm2F+DBhFhn3emD5JitVtGgUj+943F3dgSn/oW7WpNdfqK776HUyBDCSHBuZE6r7aCYhU18fx7HdOjyDvo8p9rePVJFSxB6Dh/klZNLfxyA9z9KvevLA5JJxxbmM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-40eebe7767cso31016615e9.1 for ; Tue, 30 Jan 2024 04:11:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616714; x=1707221514; 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=UHRqBOxOtqWYWRSwQg/aqnHJ0bDUu14A9mOmF+1PYW8=; b=CP+THBjL/6Aq+Wp5G/YTAg0AaNgr9pQBNs6FV3BUX2yD5M2Cn0kw9kda7es/Y4XvYd EYcN2qibUM8h69AiZlQDIGWXku/jkQ6GgqzMsowJ+YEVhFgjBlbjcAawZ+r6BRZqJpmk 25h/IbnYW/DYuLVu4QTBjy7CEj7XfhtidrscDKIsl0k8D4uwQPSL54ERyL4pxCaM45yv QhauAWRCqO7h5mlWUDBER2MODx3hsChgPe6jgW1avbCunWHp1/1XtDeGGJgG6a0HtD9b QUu5aHgo7t9qDjhusQbZMl+UF066MrsC5Zwc6OwvVpOobu1ea6K0+SPbL5wziR2lHN+f yN1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616714; x=1707221514; 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=UHRqBOxOtqWYWRSwQg/aqnHJ0bDUu14A9mOmF+1PYW8=; b=KlKr0BuAYt6ge8OUVKqn77eeKx8IWLtF1Og/lbvWRJTjM7Y4/Sw+fcicGTUrh0mZ2Y rz827y1Rg8RLYhYiFUq6nKvz0tp52f0+owm32bHLqsn7CmVPQkeRyrFEvvxdP5zdxofc CfuEHeHV1IS0m+jE9MxXlO5G/U9u3za21lNOGYIfb7YSvXfbSLY6CbCtufDJJzN7vA+N izzVIRcYo921oV6xmSV1Jtqvqt1o5ITmeeVZTkba27o15mpjNs/1XVxe8p33nQXwJinN kPNWMfxaZCoC5muiCggPD73m3XkCw3BnbKWx1Oljj4ch7AbX5W4fQxDTqm6iqXj1AVjK nynw== X-Gm-Message-State: AOJu0YyPIHOFGA2qfrFXOwD2pmaR+m6wRTb2Yism92suE3T8bqNZ13IS 8eYSL5P2poxVYaKnBKrae3V2YwYN5I91I2E7RzdnNWKOpAGIe6ibjRu8k3a4dnwTC42d9xhdL4t XSA== X-Google-Smtp-Source: AGHT+IEuFg1/xFxTbIDVM0enewBY2jNVo8P2aA1xyqld+s9aow9WACHowPX2gimJxOnynFQ/dfAOOw== X-Received: by 2002:a5d:53c5:0:b0:339:39c3:d274 with SMTP id a5-20020a5d53c5000000b0033939c3d274mr6953363wrw.36.1706616714182; Tue, 30 Jan 2024 04:11:54 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:53 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Kushal Pal Subject: [COMMITTED 089/101] gccrs: Handle `async` functions in traits Date: Tue, 30 Jan 2024 13:07:45 +0100 Message-ID: <20240130121026.807464-92-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.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, 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: Kushal Pal Fixes #2785 gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Added check for `async` functions inside trait. * parse/rust-parse-impl.h (Parser::parse_trait_item): Added switch-case for ASYNC token. gcc/testsuite/ChangeLog: * rust/compile/issue-2785.rs: New test. Signed-off-by: Kushal Pal --- gcc/rust/checks/errors/rust-ast-validation.cc | 13 ++++++++++--- gcc/rust/parse/rust-parse-impl.h | 1 + gcc/testsuite/rust/compile/issue-2785.rs | 9 +++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/rust/compile/issue-2785.rs diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index b50e9cdf858..0ed5d060894 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -141,9 +141,16 @@ ASTValidation::visit (AST::TraitFunctionDecl &decl) { const auto &qualifiers = decl.get_qualifiers (); - if (context.back () == Context::TRAIT && qualifiers.is_const ()) - rust_error_at (decl.get_identifier ().get_locus (), ErrorCode::E0379, - "functions in traits cannot be declared const"); + if (context.back () == Context::TRAIT) + { + // may change soon + if (qualifiers.is_async ()) + rust_error_at (decl.get_identifier ().get_locus (), ErrorCode::E0706, + "functions in traits cannot be declared %"); + if (qualifiers.is_const ()) + rust_error_at (decl.get_identifier ().get_locus (), ErrorCode::E0379, + "functions in traits cannot be declared const"); + } } void diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index dfa2762c5c3..3055a3959cf 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -5096,6 +5096,7 @@ Parser::parse_trait_item () // else, fallthrough to function // TODO: find out how to disable gcc "implicit fallthrough" error gcc_fallthrough (); + case ASYNC: case UNSAFE: case EXTERN_KW: case FN_KW: { diff --git a/gcc/testsuite/rust/compile/issue-2785.rs b/gcc/testsuite/rust/compile/issue-2785.rs new file mode 100644 index 00000000000..08f6346f60b --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2785.rs @@ -0,0 +1,9 @@ +// { dg-additional-options "-frust-edition=2018" } +trait Foo { + async fn foo(){} + // { dg-error "functions in traits cannot be declared .async." "" { target *-*-* } .-1 } + async fn bar(); + // { dg-error "functions in traits cannot be declared .async." "" { target *-*-* } .-1 } +} + +fn main() {} From patchwork Tue Jan 30 12:07:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892928 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=UMRAaMoD; 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 4TPQ6B3Vgqz23dQ for ; Tue, 30 Jan 2024 23:51:46 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 80750386C5A2 for ; Tue, 30 Jan 2024 12:51:44 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id E89283857C64 for ; Tue, 30 Jan 2024 12:11:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E89283857C64 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 E89283857C64 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::332 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616767; cv=none; b=XYDmHrXJSafd5BdV/OvxZsfSsSbrQmJAwqRHLjQg8D/NThZO5iWW05QcmO2QNIg8pGlFVzwNWNjzTkSBQS1hOQ5WmRLRJzgZJIVFlt2UpYr5lra30uyKm0WF5onqEuYyqK6dutUwK+oIqv6SyIMZ1Scz86+uc8c1NQtCEYJ5Td4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616767; c=relaxed/simple; bh=1jj14OqzUd2gkwwq/FD9ePfhbgQfQAbYyI3q+iGA2xQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=petJU0R7UZB7ynyhqPyYX8R8o4jEKX5QtNN+AFDKyawWo++jk4X9zp9b4Af8q+cDZmNr/D3RR8ZH3Nde/3VLTrTqb+grrHhLDKttej+l7gJOZjxhr6MUta3UE7B8HvoYpgmjKlZSUJh2/aYXEWIu/V6MXbOYm2qcAB5bXHei3ZI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40e76626170so43137875e9.2 for ; Tue, 30 Jan 2024 04:11:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616715; x=1707221515; 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=TwUYhoaMGkQI89BvsFruBOH5ISWv4+v8oUQOR8vln8E=; b=UMRAaMoDSRIcZYXFUg+ul79XI4He4kull42g6N+FcgLr2lQrCYkdkRiXW/waxZrSM8 zk8wtDZObw8J1dnSwr6CLn97Kf6oHa4pf+ZFLS15MQFhtq3Vsr5hLEQuoXTCIzFx+pO1 EJzxWnk0JsknTjDDXHjQc6YZfYWHIRH0r/4yPihMe6p4FxHKtdsWs+Nbb7u5m4yjN9cr l2pi8b0uRRxHq+3sJshxn7v+zXFH/sM2rxAWoyQxSJSzUhPcI0FENrRgDNyKYvC9qF7Z 79ZoW2FLvMUwoRUIdan4P0rgSeXzEAj341vjRD6XKqXMcWrdfdHtshcm2Cpf81RXVafu SMxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616715; x=1707221515; 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=TwUYhoaMGkQI89BvsFruBOH5ISWv4+v8oUQOR8vln8E=; b=pIxAkTSSvni7ULL6hnD+2i8rcYmH392ij7g5pk8wX6zuaFAiYYzy9jAiUhqOlf4Ipy hQPwoFOis04wMb3nS4vUENgWpYs8K9IvB8YH4x1GYH0gCOVIsVynXDgr1ForppOuUWtf Qas0AhDmfFvmyNLZNlqydjcEpveZ7nDfAgdoFdwDdqwuZnSwgKioxidXyqoBZNIg4u9k yQNCb/CGviBNDuPxxPhgTNSmmUtQUJzfHiHivUPpcgBRDZmsw+7FTsluTA3p1NqtNmIu xmvyC0e+9ekjls/qiwX94NBRrZGpymR+GwR5JCrWDHxST4aNiBi8MQN/iD1lTIMgcYQw RyFw== X-Gm-Message-State: AOJu0Yx4950KtxmB/JMPl0zgFk2bb6lo+PHEovZzaVkHEXHs1A6Rl37w EzTBr17OLAmzjuoPnWX0lNK2xR1xEGA4sCfM43aJTJbtdAdh6IemgVDKa4/0Q0Tj3pwL1MBN1yX fDw== X-Google-Smtp-Source: AGHT+IErG5vyrEH3DNgITLHORwAEyZyNHDo8s2y+8bnpwJlTiR0oYWAHBwNYOzUpseBXWigXuNQybg== X-Received: by 2002:a05:600c:3143:b0:40e:b195:6bdb with SMTP id h3-20020a05600c314300b0040eb1956bdbmr7935945wmo.2.1706616714825; Tue, 30 Jan 2024 04:11:54 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:54 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Kushal Pal Subject: [COMMITTED 090/101] gccrs: Fix inconsistent formatting Date: Tue, 30 Jan 2024 13:07:46 +0100 Message-ID: <20240130121026.807464-93-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.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, 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: Kushal Pal gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Enclose const in single quotes. gcc/testsuite/ChangeLog: * rust/compile/const_trait_fn.rs: Enclose const in single quotes. Signed-off-by: Kushal Pal --- gcc/rust/checks/errors/rust-ast-validation.cc | 2 +- gcc/testsuite/rust/compile/const_trait_fn.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index 0ed5d060894..ccb071f74b0 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -149,7 +149,7 @@ ASTValidation::visit (AST::TraitFunctionDecl &decl) "functions in traits cannot be declared %"); if (qualifiers.is_const ()) rust_error_at (decl.get_identifier ().get_locus (), ErrorCode::E0379, - "functions in traits cannot be declared const"); + "functions in traits cannot be declared %"); } } diff --git a/gcc/testsuite/rust/compile/const_trait_fn.rs b/gcc/testsuite/rust/compile/const_trait_fn.rs index cff2f5f096e..41bba3b5335 100644 --- a/gcc/testsuite/rust/compile/const_trait_fn.rs +++ b/gcc/testsuite/rust/compile/const_trait_fn.rs @@ -1,4 +1,4 @@ trait Osterkz { const fn x(); - // { dg-error "functions in traits cannot be declared const .E0379." "" { target *-*-* } .-1 } + // { dg-error "functions in traits cannot be declared .const." "" { target *-*-* } .-1 } } From patchwork Tue Jan 30 12:07:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892874 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=SP1k9FfG; 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 4TPPlM3PcSz23dQ for ; Tue, 30 Jan 2024 23:35:27 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4BA45386D61F for ; Tue, 30 Jan 2024 12:35:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 4ED0F3857728 for ; Tue, 30 Jan 2024 12:11:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4ED0F3857728 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 4ED0F3857728 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616771; cv=none; b=dN9qSxCQwnKPFjwYZr+i1YtpAaFxDwgKTkBIWa6Fu8N5nEY5U4pTUp5XerNKF3DPa3u0OHiNgdb1OTNypfEeIGM6IerdRznZ2Jl/HAeG7uPtRl6z6jEOJfvITKDgHoX9VEW5tyHacsKDaGHe6AvwwpgVxVYYX+f5/gAdrmOx5WY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616771; c=relaxed/simple; bh=clU+cbOvB/WJLKNqgKSLulW7CNlZKYsbCuw1KG+qPDE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=wjb4ZkdLPQMR2xvB+p1hmJnVHVGceoQhKl/g65ZE3d7dGb/ukVatdv2iykktsBHA08LHqQN5l8GYM4wawM4xLGggOt0wMBRVkwKTiVXCkLpzWYjbXvfVFSqaAflM28bk3oztqJHDHV7j7WonNIQ6GucjzIOUtrVAWsQnzTcJsO4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-33934567777so3029647f8f.1 for ; Tue, 30 Jan 2024 04:11:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616715; x=1707221515; 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=R/Zvf/9U+8sG3wZO2cPIvZBL9MVjRAAvW6Reqcow5k8=; b=SP1k9FfGcw8TQm27DUNY4mijoDHEShX5EGaYUP+sRgoKpOgSTS1NV40MyrOj1rkpyt ipkswf2ToG14Mb3RQ+fQe2qUImvcg3NEkak3XIim3kcUclF3xBL6L6wKzavqwKK6KBlG 4UtyB1KGH8KAOIIm+Gwinvb7J0SLtJkoQlJh41Gtp3HJhayT7lCpiUyRNDgSJxNDYTQA yTkC4BpKzrZ8lGnvkl0a0UnkCQWlgguiUJOkov21AkDsWyBVQOq1kWZC7/TcXLIQrpUD 2aUWdoeSzRkIlkOJPnXoUkkDpz57FrT0gnyCSjav0n6CqH/1OtiTQ6+C+fVIGEL4XQAW C2mQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616715; x=1707221515; 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=R/Zvf/9U+8sG3wZO2cPIvZBL9MVjRAAvW6Reqcow5k8=; b=e13FRRYPHsN7eLZGBBWLsgFNqc5f2SOrld3S3ZJAlvnp+bFysA/D6TdbC4+hLZ6r32 cBa6IcOyYqlwQXJB8n4/+TXdzUq6WhSnsGWB1PY7rNszpEa7QJ3epq4W0BLQEZ5U72cg 7OVm/lcl0pM/CZA+Q2q4PyS34TlCCopB6fVM4j7R0JVknVIm4vXo2pNRbQfJ3KiT7nT4 BB0xPzGCf50KJcO4qC6RAct1PgsgsIGc0/cHPfVpQPhfXx/1uHJjmilcMX2LKfBkqVPJ 1HmZSziKQz5XDNVB+7mZX5f3ily4x41bzCMk//adganrFONJ+k8/tEPXnURvyYNqY1Cf eUYA== X-Gm-Message-State: AOJu0YyttnQ1k8fdvEbmnmfQdMetcm/pGTLvJioyvOhc1cwm+go+QEu/ 12Y0dnUEqxU0YETOnC557lzQ8Uxx7vF86spFpQyv7Qp0apZSmVzPTzypSRk+b+wbfA1D4x94GXo Q4A== X-Google-Smtp-Source: AGHT+IEyN2x9ivP9MMCqQxWhcn8GCuZZZAOlULTdwikknESk8LHioZo/37Wq/RknpJV8gZCtDT9ZPg== X-Received: by 2002:adf:e311:0:b0:337:c4c1:a3af with SMTP id b17-20020adfe311000000b00337c4c1a3afmr6112398wrj.35.1706616715474; Tue, 30 Jan 2024 04:11: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.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:55 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Kushal Pal Subject: [COMMITTED 091/101] gccrs: Handle `async` keyword for regular implementations Date: Tue, 30 Jan 2024 13:07:47 +0100 Message-ID: <20240130121026.807464-94-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.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, 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: Kushal Pal Fixes #2788 gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_inherent_impl_item): Added switch-case for ASYNC token. gcc/testsuite/ChangeLog: * rust/compile/issue-2788.rs: New test. Signed-off-by: Kushal Pal --- gcc/rust/parse/rust-parse-impl.h | 1 + gcc/testsuite/rust/compile/issue-2788.rs | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 gcc/testsuite/rust/compile/issue-2788.rs diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 3055a3959cf..c14c75ce70d 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -5600,6 +5600,7 @@ Parser::parse_inherent_impl_item () return nullptr; } } + case ASYNC: case EXTERN_KW: case UNSAFE: case FN_KW: diff --git a/gcc/testsuite/rust/compile/issue-2788.rs b/gcc/testsuite/rust/compile/issue-2788.rs new file mode 100644 index 00000000000..b3828fca6cb --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2788.rs @@ -0,0 +1,10 @@ +// { dg-additional-options "-frust-compile-until=lowering" } +struct Foo { + arg_1: u32, + arg_2: i32, +} + +impl Foo { + async fn asynchronous_function_1(&self) {} + async fn asynchronous_function_2() {} +} From patchwork Tue Jan 30 12:07:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892899 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=hwI0eMz7; 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 4TPPvq09HFz23gZ for ; Tue, 30 Jan 2024 23:42:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C60C13876073 for ; Tue, 30 Jan 2024 12:42:44 +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 D6138385771E for ; Tue, 30 Jan 2024 12:11:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D6138385771E 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 D6138385771E 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=1706616770; cv=none; b=vMFgAAGiDY3pryt9HVhSNNVQUVjgKRjEhPH28E2DlSdjmVfhFo4CodkadKsf360pDn3IZJ4Y8FC+VzofMMtn9NSis2nczk7PWGjmjg8W0EkKmpUh7hRo6jaaSsu+P+FuKpf5q/oWoQy5dUcBXLDYgaBYBRVJq+lYmublfa548hg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616770; c=relaxed/simple; bh=W/eNrUTjA9yGL3yIuT3HJ0iuzdEsJnSvG6ddDA2QAzo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=rjIWi+aqGwegXtejbVSzs0gA7bmmSPau9/NUd8cijXZLjjTBn4EiOvUw+ATFtXJSTZ1tUCES8h9+HEYAU97br/F3NzgmMXegpNqx6ojk0jNMD3cLJ239OuGqJ5yaqLrmlVQ69j5vFgFM7FA7NJbKP/cg18RBK3j59Mu+ddkKric= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-33ae38df9d2so2196141f8f.3 for ; Tue, 30 Jan 2024 04:11:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616716; x=1707221516; 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=lOmWXrEA7rElFzwR7/qpv7vdpn7q7q1coKah38tLd50=; b=hwI0eMz7tC7cZbTruWW6foRUkrnffJwjtVJFQ7KixEGIKYz3IAsUb3thc98k3jpxRH +Nvhyy2rbLrqhxFuN9jUum4m80wAVwJQjnL+AKAbIKsTE5D2YVYkyqTc7+82gqpse9sQ fkIk+XO67AJLOhrDL140fSPZr8CVvPIR/SK3eo/SMPqAgBX4fKEpOwEaOY+hpQCV92y9 +wyZM2hYvB3voOrrIeNZ9mYizN0+mwEXCO28YCQsO+MvdthSCmBapaWFnAnZQQ0Bdo92 bZ5vSU9MVms36RBZOcoswMo+1qA9hYlc9+W8lT/8qKWNgZ1vxIgejyogJRIfoAy90VWS Ntnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616716; x=1707221516; 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=lOmWXrEA7rElFzwR7/qpv7vdpn7q7q1coKah38tLd50=; b=cUaH+G7gtIgCYuknKYJ9a3Xoiufp6LTAqpHyGv3vss5qIkKvNW8NtAekIRBDTCTj2Y lsZOZGeeNMtBB2/u+/Vc6Mm42ifsTi9aNdtJjgIQKjk9Z1040890/GwfMB9SjVgaxiry eGQOjqYXa3qY6UfJGdbIwN0qtUVRtPcC4reKszkJq3L1qaEJFV2vHR7MFLBSbb6D42tK W1E8yB2FzgpjuZHddaBP8+LjUKWPpAuW2W2coZvb/hhXoh2wRAQJ1TiDYh2/BNqcdzpN F4Bue+IMch5ldiUOut4pOO4wTsQUHaTtcqCluUXEbuoSSE4wj5D1LsmJsYCaLAHuutG3 IbLA== X-Gm-Message-State: AOJu0YzjYE+bqfG1k4+4WkC3HyqSTG9pV4kctnEm3i5AkvkSpukI6mCo 9qgVWujGNUW/2PyMpx2rx9HGi3GK2WmuBThJ21hEbYmmfS7pWBuVdJEXFkMCOiX3uoXInCzlbex PBQ== X-Google-Smtp-Source: AGHT+IG533/rLKuFTHF16k/MolaCMej/lCOJu9WgF9WbQjXyaxAnIdZELjmGN0BPH6TxxSisIGozGA== X-Received: by 2002:a5d:6b12:0:b0:339:3a25:6d70 with SMTP id v18-20020a5d6b12000000b003393a256d70mr5802163wrw.66.1706616716165; Tue, 30 Jan 2024 04:11:56 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:55 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Robert Goss Subject: [COMMITTED 092/101] gccrs: Add improved error when a field is redefined in a struct constructor Date: Tue, 30 Jan 2024 13:07:48 +0100 Message-ID: <20240130121026.807464-95-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.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, 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: Robert Goss Fixes #2381 If a struct type is initialized with one of it's fields repeated it will currently issue an error at the use site. However we would like to give the rust error code and (like rustc) show both the specifications for the field to help the user diagnose the issue. We move the check after the index for the field has been established so we can look up if the field has already been defined and get it's location. We update the visit method to return if it has handled an error otherwise we then output a second fatal error as not all the field in the specification have been processed. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-struct-field.h: Allow visit to return a bool * typecheck/rust-hir-type-check-struct.cc: Improve check of repeat fields gcc/testsuite/ChangeLog: * rust/compile/repeated_constructor_fields.rs: Added case with constructor field repeated Signed-off-by: Robert Goss --- .../rust-hir-type-check-struct-field.h | 6 +- .../typecheck/rust-hir-type-check-struct.cc | 90 +++++++++++++------ .../compile/repeated_constructor_fields.rs | 10 +++ 3 files changed, 74 insertions(+), 32 deletions(-) create mode 100644 gcc/testsuite/rust/compile/repeated_constructor_fields.rs diff --git a/gcc/rust/typecheck/rust-hir-type-check-struct-field.h b/gcc/rust/typecheck/rust-hir-type-check-struct-field.h index 923c7077f28..31d2896d0bb 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-struct-field.h +++ b/gcc/rust/typecheck/rust-hir-type-check-struct-field.h @@ -35,9 +35,9 @@ public: protected: void resolve (HIR::StructExprStructFields &struct_expr); - void visit (HIR::StructExprFieldIdentifierValue &field); - void visit (HIR::StructExprFieldIndexValue &field); - void visit (HIR::StructExprFieldIdentifier &field); + bool visit (HIR::StructExprFieldIdentifierValue &field); + bool visit (HIR::StructExprFieldIndexValue &field); + bool visit (HIR::StructExprFieldIdentifier &field); private: TypeCheckStructExpr (HIR::Expr *e); diff --git a/gcc/rust/typecheck/rust-hir-type-check-struct.cc b/gcc/rust/typecheck/rust-hir-type-check-struct.cc index f2dd8b6aa6e..56aa3d869a4 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-struct.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-struct.cc @@ -102,19 +102,26 @@ TypeCheckStructExpr::resolve (HIR::StructExprStructFields &struct_expr) switch (field->get_kind ()) { case HIR::StructExprField::StructExprFieldKind::IDENTIFIER: - visit (static_cast (*field.get ())); + ok = visit ( + static_cast (*field.get ())); break; case HIR::StructExprField::StructExprFieldKind::IDENTIFIER_VALUE: - visit ( + ok = visit ( static_cast (*field.get ())); break; case HIR::StructExprField::StructExprFieldKind::INDEX_VALUE: - visit (static_cast (*field.get ())); + ok = visit ( + static_cast (*field.get ())); break; } + if (!ok) + { + return; + } + if (resolved_field_value_expr == nullptr) { rust_fatal_error (field->get_locus (), @@ -238,16 +245,9 @@ TypeCheckStructExpr::resolve (HIR::StructExprStructFields &struct_expr) resolved = struct_def; } -void +bool TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifierValue &field) { - auto it = fields_assigned.find (field.field_name.as_string ()); - if (it != fields_assigned.end ()) - { - rust_fatal_error (field.get_locus (), "used more than once"); - return; - } - size_t field_index; TyTy::StructFieldType *field_type; bool ok = variant->lookup_field (field.field_name.as_string (), &field_type, @@ -255,7 +255,20 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifierValue &field) if (!ok) { rust_error_at (field.get_locus (), "unknown field"); - return; + return true; + } + + auto it = adtFieldIndexToField.find (field_index); + if (it != adtFieldIndexToField.end ()) + { + rich_location repeat_location (line_table, field.get_locus ()); + auto prev_field_locus = it->second->get_locus (); + repeat_location.add_range (prev_field_locus); + + rust_error_at (repeat_location, ErrorCode::E0062, + "field %<%s%> specified more than once", + field.field_name.as_string ().c_str ()); + return false; } TyTy::BaseType *value = TypeCheckExpr::Resolve (field.get_value ().get ()); @@ -273,18 +286,14 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifierValue &field) fields_assigned.insert (field.field_name.as_string ()); adtFieldIndexToField[field_index] = &field; } + + return true; } -void +bool TypeCheckStructExpr::visit (HIR::StructExprFieldIndexValue &field) { std::string field_name (std::to_string (field.get_tuple_index ())); - auto it = fields_assigned.find (field_name); - if (it != fields_assigned.end ()) - { - rust_fatal_error (field.get_locus (), "used more than once"); - return; - } size_t field_index; TyTy::StructFieldType *field_type; @@ -292,7 +301,20 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIndexValue &field) if (!ok) { rust_error_at (field.get_locus (), "unknown field"); - return; + return true; + } + + auto it = adtFieldIndexToField.find (field_index); + if (it != adtFieldIndexToField.end ()) + { + rich_location repeat_location (line_table, field.get_locus ()); + auto prev_field_locus = it->second->get_locus (); + repeat_location.add_range (prev_field_locus); + + rust_error_at (repeat_location, ErrorCode::E0062, + "field %<%s%> specified more than once", + field_name.c_str ()); + return false; } TyTy::BaseType *value = TypeCheckExpr::Resolve (field.get_value ().get ()); @@ -310,18 +332,13 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIndexValue &field) fields_assigned.insert (field_name); adtFieldIndexToField[field_index] = &field; } + + return true; } -void +bool TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifier &field) { - auto it = fields_assigned.find (field.get_field_name ().as_string ()); - if (it != fields_assigned.end ()) - { - rust_fatal_error (field.get_locus (), "used more than once"); - return; - } - size_t field_index; TyTy::StructFieldType *field_type; bool ok = variant->lookup_field (field.get_field_name ().as_string (), @@ -329,7 +346,20 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifier &field) if (!ok) { rust_error_at (field.get_locus (), "unknown field"); - return; + return true; + } + + auto it = adtFieldIndexToField.find (field_index); + if (it != adtFieldIndexToField.end ()) + { + rich_location repeat_location (line_table, field.get_locus ()); + auto prev_field_locus = it->second->get_locus (); + repeat_location.add_range (prev_field_locus); + + rust_error_at (repeat_location, ErrorCode::E0062, + "field %<%s%> specified more than once", + field.get_field_name ().as_string ().c_str ()); + return false; } // we can make the field look like a path expr to take advantage of existing @@ -358,6 +388,8 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifier &field) fields_assigned.insert (field.get_field_name ().as_string ()); adtFieldIndexToField[field_index] = &field; } + + return true; } } // namespace Resolver diff --git a/gcc/testsuite/rust/compile/repeated_constructor_fields.rs b/gcc/testsuite/rust/compile/repeated_constructor_fields.rs new file mode 100644 index 00000000000..729001b6e3c --- /dev/null +++ b/gcc/testsuite/rust/compile/repeated_constructor_fields.rs @@ -0,0 +1,10 @@ +struct Foo { + x: i32, +} + +fn main() { + let x = Foo { + x: 0, + x: 0, // { dg-error "field 'x' specified more than once" } + }; +} From patchwork Tue Jan 30 12:07:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892903 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=Sr+cbF6N; 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 4TPPxB0Gfwz23gZ for ; Tue, 30 Jan 2024 23:43:58 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C6109386F808 for ; Tue, 30 Jan 2024 12:43:55 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 05465385772B for ; Tue, 30 Jan 2024 12:11:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 05465385772B 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 05465385772B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::434 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616773; cv=none; b=c0PBrShYDNLzTo85oEt4tKXX78if/C7OumsGzRQCrJAYXymZn92FGEH9vdQQlKk94+CxUdZZvbbzfH8DGxxAFjnY2ZKFVBXI9CnPSXhlSWrBYjM05xAAbpRngMOzOABtXQCVZCwiFSLjL0ff+IOHUX0dQcFwOOqgdVIjQjOgKuc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616773; c=relaxed/simple; bh=vCxFZSPTW+ykoRr/P6jhVLvC3eO1SFwaKltRh1N42Ew=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=D7WP2CRM8TEENhSp9bJF0GE+iXC4rU5TQ7g0TH1dVIMJJBAt8vKhZGLiypyL4rDxPaf+NGFd/XnIqU1VjaZRTGBiu8dNtWlSbwnAyvPHqZ8VFOetjF0mcWAsChmo4cW4uHORJ5d4cF/nBIGWmrEdz6CdQNONWNJJpI0z9Ybtp1U= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-33af40493f4so1006078f8f.3 for ; Tue, 30 Jan 2024 04:11:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616717; x=1707221517; 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=rIl4sUgeF7lBVV18Twl5+mzytH36KT82hzDudQWjV4Q=; b=Sr+cbF6NKxAgXlGaMpCczj8Cfs12teLARQUQ+F0BF3m8hWH9NfP/o793HjW0rGNHwE ABaZ7kPt95xubkMixFEx0YtxeYTrfYgcNZ4H/9es2Syo0iy1F/Jw5V1nPpsIwxLPUAVR +sIzh4k8y5FX6Ba1KdeKwQpz7NuNeel2AMSKrkdWu+esK10VVGgk0pxR8+sEAURUwH7w 8SfNKnRFYm1Nhd7mr5wADDERCSPHw3vVPYvIj4mi81UgGgRmvAms64y3907Ax2xTtG3e wWI5b5Xhk6lIBSTU5u9c2mGQZXMZ2nrI1nYCoHLByXJv5lttGghmDaek6iTkEI6zaN+b Ysig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616717; x=1707221517; 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=rIl4sUgeF7lBVV18Twl5+mzytH36KT82hzDudQWjV4Q=; b=CXlSrwCs1/UG6v7+z4oApC3bPNls7uxzORVususFmaC3IgZxersxHYULD2netOlJGW JUKHqnKn+MNbVzglGjcj7oysDjs/o5tKZiwEFaQjXZ4uKlt16A0ATzw/nExSoG/PRKDw 8GoT592LVXAaxz4ylrgWP1NFbmREBUUoALZEfLtXPssZH6zyNYbM/cfiSdPDwHNGk3Zu VGR+ZQHc9FNfKSmPPbSxxeQB+4kVXngTfKAnuOhRT9C7VnBRRGfqU4oz/E8w619oSC4P ENFktuO4gRklaNRwSK6hoQkflxLZzNRzuV0uToOS1fY8uBgAL7IvzMT7MVATCdbsplRn 5n6A== X-Gm-Message-State: AOJu0Yz3aVlOPexoSuaH9MnlqkxGyAXzHwufiZiJUObrpXIdnctPjLJp UfUFNw4heJmuwqlx/JfSEvwGRRuu2Ed0CQ/kTvlN5PdfrTJxYdL9LryuaaAsQ4DeQDh6dQJdZRq bUw== X-Google-Smtp-Source: AGHT+IFNXCi2bLlL7UE6P6XcGfgQYl08veoLm8+4WHFVxoBOKvt0sZvSu1vHbANz9+3XtXmAOzrHZA== X-Received: by 2002:adf:a446:0:b0:33a:e6f2:4a37 with SMTP id e6-20020adfa446000000b0033ae6f24a37mr4614106wra.63.1706616716917; Tue, 30 Jan 2024 04:11:56 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:56 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [COMMITTED 093/101] gccrs: Unify storage of associated items in SingleASTNode Date: Tue, 30 Jan 2024 13:07:49 +0100 Message-ID: <20240130121026.807464-96-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.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, 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: Owen Avery gcc/rust/ChangeLog: * ast/rust-ast-fragment.cc (Fragment::assert_single_fragment): Update. * ast/rust-ast.h (class TraitImplItem): Move definition before that of TraitItem. (class TraitItem): Inherit from TraitImplItem instead of AssociatedItem. (class SingleASTNode): Unify handling of associated items. (SingleASTNode::take_assoc_item): Move from... (SingleASTNode::take_impl_item): ...here, but leave stub calling take_assoc_item behind. (SingleASTNode::take_trait_item): Cast associated item to TraitItem. (SingleASTNode::take_trait_impl_item): Cast associated item to TraitImplItem. * ast/rust-ast.cc (SingleASTNode::SingleASTNode): Unify handling of associated items. (SingleASTNode::operator=): Likewise. (SingleASTNode::accept_vis): Likewise. (SingleASTNode::is_error): Likewise. (SingleASTNode::as_string): Likewise. * ast/rust-item.h (class Function): Remove direct inheritence from AssociatedItem. (class ConstantItem): Likewise. * ast/rust-macro.h (class MacroInvocation): Remove direct inheritence from AssociatedItem and TraitImplItem. --- gcc/rust/ast/rust-ast-fragment.cc | 4 +- gcc/rust/ast/rust-ast.cc | 52 +++++-------------------- gcc/rust/ast/rust-ast.h | 63 ++++++++++++++----------------- gcc/rust/ast/rust-item.h | 8 +--- gcc/rust/ast/rust-macro.h | 2 - 5 files changed, 42 insertions(+), 87 deletions(-) diff --git a/gcc/rust/ast/rust-ast-fragment.cc b/gcc/rust/ast/rust-ast-fragment.cc index e7574519465..d8bf4aa213b 100644 --- a/gcc/rust/ast/rust-ast-fragment.cc +++ b/gcc/rust/ast/rust-ast-fragment.cc @@ -153,14 +153,12 @@ void Fragment::assert_single_fragment (SingleASTNode::NodeType expected) const { static const std::map str_map = { - {SingleASTNode::NodeType::IMPL, "impl"}, + {SingleASTNode::NodeType::ASSOC_ITEM, "associated item"}, {SingleASTNode::NodeType::ITEM, "item"}, {SingleASTNode::NodeType::TYPE, "type"}, {SingleASTNode::NodeType::EXPRESSION, "expr"}, {SingleASTNode::NodeType::STMT, "stmt"}, {SingleASTNode::NodeType::EXTERN, "extern"}, - {SingleASTNode::NodeType::TRAIT, "trait"}, - {SingleASTNode::NodeType::TRAIT_IMPL, "trait impl"}, }; auto actual = nodes[0].get_kind (); diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index b9096032d41..360a9ceb6db 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -60,16 +60,8 @@ SingleASTNode::SingleASTNode (SingleASTNode const &other) external_item = other.external_item->clone_external_item (); break; - case TRAIT: - trait_item = other.trait_item->clone_trait_item (); - break; - - case IMPL: - impl_item = other.impl_item->clone_associated_item (); - break; - - case TRAIT_IMPL: - trait_impl_item = other.trait_impl_item->clone_trait_impl_item (); + case ASSOC_ITEM: + assoc_item = other.assoc_item->clone_associated_item (); break; case TYPE: @@ -100,16 +92,8 @@ SingleASTNode::operator= (SingleASTNode const &other) external_item = other.external_item->clone_external_item (); break; - case TRAIT: - trait_item = other.trait_item->clone_trait_item (); - break; - - case IMPL: - impl_item = other.impl_item->clone_associated_item (); - break; - - case TRAIT_IMPL: - trait_impl_item = other.trait_impl_item->clone_trait_impl_item (); + case ASSOC_ITEM: + assoc_item = other.assoc_item->clone_associated_item (); break; case TYPE: @@ -140,16 +124,8 @@ SingleASTNode::accept_vis (ASTVisitor &vis) external_item->accept_vis (vis); break; - case TRAIT: - trait_item->accept_vis (vis); - break; - - case IMPL: - impl_item->accept_vis (vis); - break; - - case TRAIT_IMPL: - trait_impl_item->accept_vis (vis); + case ASSOC_ITEM: + assoc_item->accept_vis (vis); break; case TYPE: @@ -171,12 +147,8 @@ SingleASTNode::is_error () return stmt == nullptr; case EXTERN: return external_item == nullptr; - case TRAIT: - return trait_item == nullptr; - case IMPL: - return impl_item == nullptr; - case TRAIT_IMPL: - return trait_impl_item == nullptr; + case ASSOC_ITEM: + return assoc_item == nullptr; case TYPE: return type == nullptr; } @@ -198,12 +170,8 @@ SingleASTNode::as_string () const return "Stmt: " + stmt->as_string (); case EXTERN: return "External Item: " + external_item->as_string (); - case TRAIT: - return "Trait Item: " + trait_item->as_string (); - case IMPL: - return "Impl Item: " + impl_item->as_string (); - case TRAIT_IMPL: - return "Trait Impl Item: " + trait_impl_item->as_string (); + case ASSOC_ITEM: + return "Associated Item: " + assoc_item->as_string (); case TYPE: return "Type: " + type->as_string (); } diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index a45085489e8..256a527118a 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1657,8 +1657,22 @@ public: virtual location_t get_locus () const = 0; }; +// Abstract base class for items used in a trait impl +class TraitImplItem : public AssociatedItem +{ +protected: + virtual TraitImplItem *clone_associated_item_impl () const override = 0; + +public: + // Unique pointer custom clone function + std::unique_ptr clone_trait_impl_item () const + { + return std::unique_ptr (clone_associated_item_impl ()); + } +}; + // Item used in trait declarations - abstract base class -class TraitItem : virtual public AssociatedItem +class TraitItem : public TraitImplItem { protected: TraitItem (location_t locus) @@ -1689,20 +1703,6 @@ public: location_t get_locus () const override { return locus; } }; -// Abstract base class for items used in a trait impl -class TraitImplItem : virtual public AssociatedItem -{ -protected: - virtual TraitImplItem *clone_associated_item_impl () const override = 0; - -public: - // Unique pointer custom clone function - std::unique_ptr clone_trait_impl_item () const - { - return std::unique_ptr (clone_associated_item_impl ()); - } -}; - // Abstract base class for an item used inside an extern block class ExternalItem : public Visitable { @@ -1831,9 +1831,7 @@ public: ITEM, STMT, EXTERN, - TRAIT, - IMPL, - TRAIT_IMPL, + ASSOC_ITEM, TYPE, }; @@ -1845,9 +1843,7 @@ private: std::unique_ptr item; std::unique_ptr stmt; std::unique_ptr external_item; - std::unique_ptr trait_item; - std::unique_ptr impl_item; - std::unique_ptr trait_impl_item; + std::unique_ptr assoc_item; std::unique_ptr type; public: @@ -1867,16 +1863,8 @@ public: : kind (EXTERN), external_item (std::move (item)) {} - SingleASTNode (std::unique_ptr item) - : kind (TRAIT), trait_item (std::move (item)) - {} - SingleASTNode (std::unique_ptr item) - : kind (IMPL), impl_item (std::move (item)) - {} - - SingleASTNode (std::unique_ptr trait_impl_item) - : kind (TRAIT_IMPL), trait_impl_item (std::move (trait_impl_item)) + : kind (ASSOC_ITEM), assoc_item (std::move (item)) {} SingleASTNode (std::unique_ptr type) @@ -1936,7 +1924,8 @@ public: std::unique_ptr take_trait_item () { rust_assert (!is_error ()); - return std::move (trait_item); + return std::unique_ptr ( + static_cast (assoc_item.release ())); } std::unique_ptr take_external_item () @@ -1945,16 +1934,22 @@ public: return std::move (external_item); } - std::unique_ptr take_impl_item () + std::unique_ptr take_assoc_item () { rust_assert (!is_error ()); - return std::move (impl_item); + return std::move (assoc_item); + } + + std::unique_ptr take_impl_item () + { + return take_assoc_item (); } std::unique_ptr take_trait_impl_item () { rust_assert (!is_error ()); - return std::move (trait_impl_item); + return std::unique_ptr ( + static_cast (assoc_item.release ())); } std::unique_ptr take_type () diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index a995273de12..5b9eb64560d 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -1289,9 +1289,7 @@ protected: class LetStmt; // Rust function declaration AST node -class Function : public VisItem, - virtual public AssociatedItem, - public TraitImplItem +class Function : public VisItem, public TraitImplItem { FunctionQualifiers qualifiers; Identifier function_name; @@ -2314,9 +2312,7 @@ protected: /* "Constant item" AST node - used for constant, compile-time expressions * within module scope (like constexpr) */ -class ConstantItem : public VisItem, - virtual public AssociatedItem, - public TraitImplItem +class ConstantItem : public VisItem, public TraitImplItem { // either has an identifier or "_" - maybe handle in identifier? // bool identifier_is_underscore; diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index 41c21cffa95..bcf5b0b5a99 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -598,8 +598,6 @@ class MacroInvocation : public TypeNoBounds, public Pattern, public Item, public TraitItem, - public TraitImplItem, - virtual public AssociatedItem, public ExternalItem, public ExprWithoutBlock { From patchwork Tue Jan 30 12:07:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892893 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=ZEpFiPRf; 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 4TPPsD4SBBz23gZ for ; Tue, 30 Jan 2024 23:40:32 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A0BA03871025 for ; Tue, 30 Jan 2024 12:40:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by sourceware.org (Postfix) with ESMTPS id 6DA643857716 for ; Tue, 30 Jan 2024 12:11:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6DA643857716 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 6DA643857716 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616773; cv=none; b=gWbCU4INjokW+h2pKipOBE49jAJ+zuBgSk5RzYkeHCUt+JEwKAYWv9olcIg1xUzKCSu7cRHV6htL6golx1VMJUjZNeetLKR1X3TC5U76Yi9W9c7GXKABE28Y2L9cviaE+oN4/YsFEbBIGu6pPZUbUDfzh7HayR3KGLqqmc/4HRc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616773; c=relaxed/simple; bh=OLEqzupl614tw1W8mb6UXx17WjxZ++OXnN6CzYxMTBc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=HUEV1kQhVQZE8fAg+zYx/G+raL72u0iqb4L1m1pGVZcUZ45KXXLBtfZO4ataxpUvM/L58DleOAbTOK4RokmEUCe3t05Di0s+QKtBWrfTvBvEXuIiGkcM9WKTPAAEncBi9j96XEjLp1IwjYPgJn3F2isHS3xVeFjACPhcE6O3c2M= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-40ed356a6ecso34580725e9.2 for ; Tue, 30 Jan 2024 04:11:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616717; x=1707221517; 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=esOFYPKaxJQOXgEgz4hAIPNYbgdWqyYspTIk9OInHdA=; b=ZEpFiPRf9SQ4g/fw314mL2ysMjnFlCDDFHPVygnk2QVI8do2t5JPQwA/HfSnuDlZUp 90JsoXjUN/DExSMUadAo9pmlY0TEnvb34AUrxBArI1h8+YPu5K+eLMQx91In+Btvgy7E oSwfmtELE0PuuhlNNktaWBJGR6i9vVbxN3yodoSR8GlSfXya1xziGGBoIsFj9wq2t+To tK23jc9RYaKC30RWm7LZjXJEW8iNpqVbVtQVLfXPykNNcT77y7nCSaCjNt/Fzw5Bml2e 0Z3WagFv3Zy2Lq0W+2hF9Irf2128It4c/gEZsjn7Cw0DBnE6LBBLapJoM89fn7Pmqxg0 dCzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616717; x=1707221517; 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=esOFYPKaxJQOXgEgz4hAIPNYbgdWqyYspTIk9OInHdA=; b=b9/+Fx62ILayaXi55hdmKuaDI6OJ3N8d3Ekzvg0AlsJnNNmOLwp9X7cnD0XDflNiQG BkoJc4oaZjgdarV8aBfV/WdT/0YgOTn/uqtkxmwmR2QeioZidZOfzpuNRJUun0mayMDt EMw839BhOYr7JtM27au0d11fDrv3fWM7O2VnIu+E05JVdqO0lTETKd2rrJ8CESPs/8cn w3c6Mfrw9suHIyRB0u3hFPFk2+h4q5HWfstRNlfruaOynNtWDgB9wi/WzD8tS2E3Np2Z YCp22etfFXjiC2oond+YH0u31dWQHEXUCBnDFc1dL/LBwfCnQGIX+0/4SHeB/dxJrOd/ Hmsg== X-Gm-Message-State: AOJu0Yzs1wCyrL/A67RakpKZggqNcqZ1r0b14umh90ixhGu6XvDPVsWm jgPkolw3evA7Yc/6ETILqdXHSCz7hP/2fjpNlHsJ1GAj6bADqEZHzuBFTPAC1vXwVh+a1tR3XV1 xQw== X-Google-Smtp-Source: AGHT+IF5ayHYseqY/SCVhsvryPON5UKHwE7MLDsNge2bwUa7PLH70sLwDJWilVzKhVx2sZpK6fx4nQ== X-Received: by 2002:a05:6000:1888:b0:33a:f12d:61c3 with SMTP id a8-20020a056000188800b0033af12d61c3mr3927204wri.68.1706616717364; Tue, 30 Jan 2024 04:11: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.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:57 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Kushal Pal Subject: [COMMITTED 094/101] gccrs: Added newline to get more readable lexdump Date: Tue, 30 Jan 2024 13:07:50 +0100 Message-ID: <20240130121026.807464-97-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.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, 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: Kushal Pal Fixes #2783 gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::dump_and_skip): Changed " " to '\n' Signed-off-by: Kushal Pal --- gcc/rust/lex/rust-lex.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/rust/lex/rust-lex.cc b/gcc/rust/lex/rust-lex.cc index 6fc336d97e0..bf6bf4c8446 100644 --- a/gcc/rust/lex/rust-lex.cc +++ b/gcc/rust/lex/rust-lex.cc @@ -240,7 +240,7 @@ Lexer::dump_and_skip (int n) + std::string (tok->get_type_hint_str ())) : "") << " "; - out << Linemap::location_to_string (loc) << " "; + out << Linemap::location_to_string (loc) << '\n'; } token_queue.skip (0); From patchwork Tue Jan 30 12:07:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892879 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=BpVgl5Sy; 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 4TPPml5m0Cz23dQ for ; Tue, 30 Jan 2024 23:36:39 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF35738313BE for ; Tue, 30 Jan 2024 12:36:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by sourceware.org (Postfix) with ESMTPS id 2D17C3857718 for ; Tue, 30 Jan 2024 12:12:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2D17C3857718 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 2D17C3857718 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616773; cv=none; b=v50SL9EPHIlHB93JCGtKAHiUr3Bap3CmjveL7jqip8Kjr9qtUxYrdZR2iDmz8RvrH188yj7ofowh3C4slRF91+Mn6bB+VQWzw9MbYk5J1t8Lb8/sBBz0oFnO2SXnzF/lQ/ytVo+LB2rG4FoYZ4iCn9UMoHedIfVQEIWCJMrOAyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616773; c=relaxed/simple; bh=BFCfJmOm2qeAh9EgumKD9HGhOrM/uBGLJwXGKeyyA/E=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=eK1X72bc5eTwnAwErxP3R9fRiZNRKyQ5zsvON9bpuo4/zn7ataxsnOu4qrczmtlgXpD7x7g8xG/nnnvZd+j7rGLG581dnvR9RFe1D5kjC6SScUEVysd5bsclk5e+SYqmJNT+wBiAMJV8wULZ/9JJeqKyhdgLp8+r7rEwlLlNpnA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-5110c166d70so3743120e87.1 for ; Tue, 30 Jan 2024 04:12:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616718; x=1707221518; 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=MKYBdaX818/047ocgc/c+pLoepzIebHxqy8BzhLGbNI=; b=BpVgl5Sy0UiQ9UNL0HlW1TNs5MyhMZJGfUiKr4MC3emy2reC7qh1USh4TFlaYD7MPa LPE1/N01IJkobvVYcjV+DRSeIYiorYMv9EBEx6YAMnYMP2ZlokAPDXh64N8mMzt4LElZ 9+JBxTb1SlvAq+8RgX3RZA7xQN0SS1Z44hsfSNreAZA8gtVX6W2FTAktMPIZ42jFJSfL p8LfgC5QhYWcu4TAI6IMGNKNPcHUi3tBYla0T6/olHzNldl/EqqCxk9zEf7nLIegJU92 B+uwaMavEtPqfNSwi3cBeB64O1y50EgJ/d3r0UFnjNSP4XsYdcG3GVIOOysjvtFwQKhS vteQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616718; x=1707221518; 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=MKYBdaX818/047ocgc/c+pLoepzIebHxqy8BzhLGbNI=; b=Z7BRCD/w8oXsMpG3/8EaooOC1LwqCtlyFRCLmtNCiW+vrvvsizb+38x0+rVNBsueqt ENa933fWQjjvLSd6q7ogsM1CeAJY1SZa8mWn7WaFN2Yvn7FYDgYD+SkqAOKsqp4JOqiF PpEuBaWzfPzEmNSgDCU7Y49aOVJN8/sbyCD0il74QW6AjVUyyMcN/FVM3jOhIeToGY4m y88Qop3bz5uuswp1aB0iityaVTd4nwxziYOev5iw/ajFBABx4oH1GU+53ZusyKund30l lFR/Og/aneOZ73p6cC9eLM3CmWMNkWrSPg/7ExXfnM/TxkpANrKHy/+dVVHUDOyKAnCr Q6eA== X-Gm-Message-State: AOJu0YzSB8CRnW04hOZc3RroM3NA0HtGJOqbcwzmdXogP8Gga8dEhpQm 63QYEq8ObpLxIV5O/JSxLk+nYqAC0dnZb40FudwAaoKuTxr4ct+iQk7Ix3CTTRDja0XTYhUHM+y 9YA== X-Google-Smtp-Source: AGHT+IGcPVQ9bE17p+4Ip17mhKwW5HNLGaklAbVOK3Gy2dPto37dEddx2Pp2ySPPTunJndVaden4jw== X-Received: by 2002:a19:2d43:0:b0:510:2367:1bca with SMTP id t3-20020a192d43000000b0051023671bcamr5507180lft.4.1706616717751; Tue, 30 Jan 2024 04:11: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.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:57 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 095/101] gccrs: Test: fix missing lifetime in a test Date: Tue, 30 Jan 2024 13:07:51 +0100 Message-ID: <20240130121026.807464-98-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=-12.7 required=5.0 tests=BAYES_00, BODY_8BITS, 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: Jakub Dupak This test did not compile with rustc. gcc/testsuite/ChangeLog: * rust/compile/torture/utf8_identifiers.rs: add mising lifetime Signed-off-by: Jakub Dupak --- gcc/testsuite/rust/compile/torture/utf8_identifiers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gcc/testsuite/rust/compile/torture/utf8_identifiers.rs b/gcc/testsuite/rust/compile/torture/utf8_identifiers.rs index eeee01c95cf..696fcc0a3d8 100644 --- a/gcc/testsuite/rust/compile/torture/utf8_identifiers.rs +++ b/gcc/testsuite/rust/compile/torture/utf8_identifiers.rs @@ -1,7 +1,7 @@ #[lang = "sized"] pub trait Sized {} -pub fn f() { +pub fn f<'かに>() { let crab = (); let Κάβουρας = 0.001; From patchwork Tue Jan 30 12:07:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892906 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=bBtCoTJa; 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 4TPPyk5QpSz23fD for ; Tue, 30 Jan 2024 23:45:18 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BF0EC38393B8 for ; Tue, 30 Jan 2024 12:45:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id CD6403857722 for ; Tue, 30 Jan 2024 12:12:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CD6403857722 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 CD6403857722 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616775; cv=none; b=r8a4aOO129igf+wjiFk548LoHjAHC+6yUZOC9KySklCixhCpLMZVSrB6CGwzPeizYP3sNETYTHLxauwzqnuaY6V+HdBSmEJ5qm9OdS43xnfJrCO9Y7CvPJ8LQomz8qTkvfbz3qmVW7NLRz6vrQUlPOknDw2UaOCQ//hiswYtycg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616775; c=relaxed/simple; bh=BbZT06Wyh0LNElHxaJSdP6W81PvlRZzmCuL4xsbB71Q=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=dvJpuLQEtD+PQhD9xwWJlzUQKuTI8ylHldDhKp66cwtO3ogLeq80a2QVD/7QPMnCGEAkGgxN3AzMhfxrqqi4umoh99qgUH+holULcaGXZn+V1eExLn75vSKqsO5Jq9oBMNij+8hFQhqg7BU0mRQxCaHkpqd2aMhsHuG831gTXes= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-40ef6bbb61fso17344575e9.1 for ; Tue, 30 Jan 2024 04:12:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616718; x=1707221518; 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=gqP0D+eKaqDsX+09aT8DebNlqQZnKLBDu1l86xZVAvQ=; b=bBtCoTJaBjAOT4iK4/iTlkwIAik2AXhy58zMKmlscGed6ss0sqAkaQe0TTYVK9tcvZ XdxcvuUu9Nbo+H5ZFogAJn+OtpWKitJYK/LegJzeEgLU2LnAZjZ8PoyvcssBVgjPZc5C xUG6N5XIClhPe5/bGaJk4jUQxzNdHLhUeMY0vI8T6xOSi1V80FdqpcIP4TK/5EbWaJl0 u/KblB5KrH1i2RFN03BYea/1GFWD0fgi3XFr1kQ39NJpax6/YovYqzVDpegaxfG+jHD3 GnMRg1KaCsz0Iyt+hju9DeX1tnaMJbGCkljXaRHa88CdFRDTJBrpfyLa7jk1FmtabEPv PDAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616718; x=1707221518; 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=gqP0D+eKaqDsX+09aT8DebNlqQZnKLBDu1l86xZVAvQ=; b=bM7zQ/hvgeibQu2QZ7DLQt/UROCLJB/uNPt5+aNQf95H7MpWo6l1nkK/Y/bzE4M0pV ws2PYgxJvLHbHoWy/lxYd7+tRIgppSMLvN771IVE83FHRHZ1dyq9K1NvAQIXEmzGAOob r62eBL4DF5aBnNRVCDkY8zDewSfxyWevwlj7PtmN7A1+mAgE1Bf9Kz/T+cmL1M96ajid cKE415yuZzqs72Zi53lBxDXTExP+eGD71Dzzhcn3SyFmJkMPdYSBs2H7Ji5Rp1BuP+QH 4s0PHsqlw2qEEzby6aRwvGFR6Q36S+nvz0oTjneVgT/oKaEPfjYa97wR2r/BPOdErr+Z QJtg== X-Gm-Message-State: AOJu0YwWqzc52Q4tXFxl8gaLt184k/xdwor/teNedP7Pjj7oMSJgZ1tG KQHSe09Bd1UhpHLhZtPSRqYPYzH4A4/gSYoll494hPBl9IS+xdq6YTpWLWhWIla8Rkx0nADKzGD f0g== X-Google-Smtp-Source: AGHT+IGfESPyER3aPvsj0AGBXUJZiIGE0A+op6ySd4kWnr2RNXtPGDsPXfr7A28VFmniv3oMWQYn8g== X-Received: by 2002:adf:dd92:0:b0:33a:f3a5:37d1 with SMTP id x18-20020adfdd92000000b0033af3a537d1mr2976810wrl.29.1706616718157; Tue, 30 Jan 2024 04:11:58 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:57 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 096/101] gccrs: AST: Fix for lifetime parsing Date: Tue, 30 Jan 2024 13:07:52 +0100 Message-ID: <20240130121026.807464-99-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: Jakub Dupak gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_where_clause): fix parsing (Parser::parse_where_clause_item): fix parsing (Parser::parse_type_bound_where_clause_item): fix parsing (Parser::parse_trait_bound): fix parsing * parse/rust-parse.h: fix parsing Signed-off-by: Jakub Dupak --- gcc/rust/parse/rust-parse-impl.h | 37 ++++++++++++++++++++------------ gcc/rust/parse/rust-parse.h | 6 ++++-- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index c14c75ce70d..7ea7276dc94 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -3756,6 +3756,10 @@ Parser::parse_where_clause () * so won't be here */ std::vector> where_clause_items; + std::vector for_lifetimes; + if (lexer.peek_token ()->get_id () == FOR) + for_lifetimes = parse_for_lifetimes (); + /* HACK: where clauses end with a right curly or semicolon or equals in all * uses currently */ const_TokenPtr t = lexer.peek_token (); @@ -3763,7 +3767,7 @@ Parser::parse_where_clause () && t->get_id () != EQUAL) { std::unique_ptr where_clause_item - = parse_where_clause_item (); + = parse_where_clause_item (for_lifetimes); if (where_clause_item == nullptr) { @@ -3791,7 +3795,8 @@ Parser::parse_where_clause () * commas. */ template std::unique_ptr -Parser::parse_where_clause_item () +Parser::parse_where_clause_item ( + const std::vector &outer_for_lifetimes) { // shitty cheat way of determining lifetime or type bound - test for // lifetime @@ -3800,7 +3805,7 @@ Parser::parse_where_clause_item () if (t->get_id () == LIFETIME) return parse_lifetime_where_clause_item (); else - return parse_type_bound_where_clause_item (); + return parse_type_bound_where_clause_item (outer_for_lifetimes); } // Parses a lifetime where clause item. @@ -3834,12 +3839,10 @@ Parser::parse_lifetime_where_clause_item () // Parses a type bound where clause item. template std::unique_ptr -Parser::parse_type_bound_where_clause_item () +Parser::parse_type_bound_where_clause_item ( + const std::vector &outer_for_lifetimes) { - // parse for lifetimes, if it exists - std::vector for_lifetimes; - if (lexer.peek_token ()->get_id () == FOR) - for_lifetimes = parse_for_lifetimes (); + std::vector for_lifetimes = outer_for_lifetimes; std::unique_ptr type = parse_type (); if (type == nullptr) @@ -3853,6 +3856,13 @@ Parser::parse_type_bound_where_clause_item () return nullptr; } + if (lexer.peek_token ()->get_id () == FOR) + { + auto for_lifetimes_inner = parse_for_lifetimes (); + for_lifetimes.insert (for_lifetimes.end (), for_lifetimes_inner.begin (), + for_lifetimes_inner.end ()); + } + // parse type param bounds if they exist std::vector> type_param_bounds = parse_type_param_bounds (); @@ -4029,6 +4039,11 @@ Parser::parse_trait_bound () location_t locus = lexer.peek_token ()->get_locus (); + /* parse optional `for lifetimes`. */ + std::vector for_lifetimes; + if (lexer.peek_token ()->get_id () == FOR) + for_lifetimes = parse_for_lifetimes (); + // handle trait bound being in parentheses if (lexer.peek_token ()->get_id () == LEFT_PAREN) { @@ -4043,12 +4058,6 @@ Parser::parse_trait_bound () lexer.skip_token (); } - /* parse for lifetimes, if it exists (although empty for lifetimes is ok to - * handle this) */ - std::vector for_lifetimes; - if (lexer.peek_token ()->get_id () == FOR) - for_lifetimes = parse_for_lifetimes (); - // handle TypePath AST::TypePath type_path = parse_type_path (); diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index 3fc86206de7..02f90217fc2 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -288,11 +288,13 @@ private: std::unique_ptr parse_function_param (); std::unique_ptr parse_function_return_type (); AST::WhereClause parse_where_clause (); - std::unique_ptr parse_where_clause_item (); + std::unique_ptr parse_where_clause_item ( + const std::vector &global_for_lifetimes); std::unique_ptr parse_lifetime_where_clause_item (); std::unique_ptr - parse_type_bound_where_clause_item (); + parse_type_bound_where_clause_item ( + const std::vector &global_for_lifetimes); std::vector parse_for_lifetimes (); template std::vector> From patchwork Tue Jan 30 12:07:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892938 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=CxDKtrRk; 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 4TPQ8w2GcFz23dQ for ; Tue, 30 Jan 2024 23:54:08 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 470793870896 for ; Tue, 30 Jan 2024 12:54:06 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id B516D3857729 for ; Tue, 30 Jan 2024 12:12:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B516D3857729 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 B516D3857729 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616775; cv=none; b=iic04YKCDBPV5q5/nn61Ky1/k5CJhGBYT/fWIEPNPX/mm6twulJoihmR9fQbv0/B4Diyv//4EcjU9v6iafhlnK5k8KmjbOM2lYxBmGrSepAVARWHD3otbgB/uzVsEIuBzFyHtm1nybeq62Due0oHaxR6R0qEopoWIuzeIzYj2GA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616775; c=relaxed/simple; bh=GYFIXQqA76iGlkyus+RoxHBsrq0N7RaEQ+AYtrO+nKY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=VZkihUAaILI2d6m27YyroCqhdMeqWXZ9RPnp5JHgp2ITPVEO7c29cilkJwaRgD1NPHa+oEDXyoacNJuVeGflyAvlEafE2ot4f4S08YRcit+0OhgBVrlQRocIhT8M/Z3sygomE6yTG7FDDe6moPQjk5dRPh90arEKmcX3LFfg6A0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-33adec41b55so3617784f8f.0 for ; Tue, 30 Jan 2024 04:12:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616718; x=1707221518; 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=fWctQIQWuXNo2W2D7XmPH/C4uTQo2S8lFrAjloL8E0E=; b=CxDKtrRkF4HPAHtM983TjwtfGyK0GeHbnjkHV32n+Gl8vWxo7+BKO1EsCHR9PKMQQ8 4+LhT0X6Owxo5bOhu+CBvNfkSs5EvEuU5eNkxfMFroNyVwEPvsNEg/fc//N6WjGWhEyP GYbsxRHrRm3PTPthFf2AIzspVROnzBt/YINJCMTRlrcmvuBFP+r137mkMhwJMU25cG9d lFiOn4tLHOdmFWuvdetxedmsYyS0cGnZujUWgzu7GE2wGACW6CtPfgml99PzqIJNA+pA 2Irrywteze2rJ4jgJ3mmXBmCVqLehXURX+aWqd7Bq271LURTTVex9bWCIY2KG1e6w56T 3q5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616718; x=1707221518; 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=fWctQIQWuXNo2W2D7XmPH/C4uTQo2S8lFrAjloL8E0E=; b=GOWnqOy4xbdhpffs98wjZmtyCeLSh7o5/VDu/W/c5Q2PrvIeDasKfD7rDnMq35dulN u6mC+y4apNmYYXpJoE9nfGOSHbsB860gEki0HlsLM/NB0RNNOKUAnyMDljnUxo7Je9FW Ax0Yo3LiQ3Hi04NMnWYB/89AzzR7MxfSEDmeyIW67tOHzUGR8/tN7X8XcwyODeRxKcIl XDdTxGzes94O/L1bJ+0jIxo8/aJ2vmk8YyL4ugXyPRO2R2nXpjDbClnr4Lz9warWUJAI AQ2tbFo4qUGo2OFFG3bvT+aCrwVrzpl6oQiCrE330XQlfSinlQivftoJrBcpP0es4pcg Fy+Q== X-Gm-Message-State: AOJu0YxCZCJM2Ghs11XsBUHMMjJJfv2NfxU67ZkUcxjqHlVk5Qdn1Euw NXs65MJDjZRQMp/Cd1gvC+t0JVGlGVzQ+okwwJ6AKy05MaPzFvSrC1tHrCeDrxr+Bc9qIu8bbEp Bpw== X-Google-Smtp-Source: AGHT+IGlZcXKFyn/6dPiMcoJEzmGq8XdHZebK/ihl6Atv49/4VMB76GwljCfiD8yD6/f/kFiJocvpw== X-Received: by 2002:a05:6000:78d:b0:33a:f681:699e with SMTP id bu13-20020a056000078d00b0033af681699emr1883574wrb.21.1706616718560; Tue, 30 Jan 2024 04:11:58 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:58 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 097/101] gccrs: AST: Fix for lifetime lowering Date: Tue, 30 Jan 2024 13:07:53 +0100 Message-ID: <20240130121026.807464-100-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.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, 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: Jakub Dupak gcc/rust/ChangeLog: * hir/rust-ast-lower-type.cc (ASTLoweringTypeBounds::visit): fix for lifetimes (ASTLowerWhereClauseItem::visit): fix for lifetimes Signed-off-by: Jakub Dupak --- gcc/rust/hir/rust-ast-lower-type.cc | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/gcc/rust/hir/rust-ast-lower-type.cc b/gcc/rust/hir/rust-ast-lower-type.cc index a0178ebf490..504ca051f59 100644 --- a/gcc/rust/hir/rust-ast-lower-type.cc +++ b/gcc/rust/hir/rust-ast-lower-type.cc @@ -529,8 +529,13 @@ ASTLoweringTypeBounds::translate (AST::TypeParamBound *type) void ASTLoweringTypeBounds::visit (AST::TraitBound &bound) { - // FIXME - std::vector lifetimes; + std::vector for_lifetimes; + for (auto &lifetime_param : bound.get_for_lifetimes ()) + { + auto generic_param = ASTLowerGenericParam::translate (&lifetime_param); + for_lifetimes.push_back ( + *static_cast (generic_param)); + } AST::TypePath &ast_trait_path = bound.get_type_path (); HIR::TypePath *trait_path = ASTLowerTypePath::translate (ast_trait_path); @@ -543,8 +548,9 @@ ASTLoweringTypeBounds::visit (AST::TraitBound &bound) BoundPolarity polarity = bound.has_opening_question_mark () ? BoundPolarity::AntiBound : BoundPolarity::RegularBound; - translated = new HIR::TraitBound (mapping, *trait_path, bound.get_locus (), - bound.is_in_parens (), polarity); + translated + = new HIR::TraitBound (mapping, *trait_path, bound.get_locus (), + bound.is_in_parens (), polarity, for_lifetimes); } void @@ -596,6 +602,13 @@ ASTLowerWhereClauseItem::visit (AST::TypeBoundWhereClauseItem &item) // FIXME std::vector for_lifetimes; + for (auto &lifetime_param : item.get_for_lifetimes ()) + { + auto generic_param = ASTLowerGenericParam::translate (&lifetime_param); + for_lifetimes.push_back ( + *static_cast (generic_param)); + } + std::unique_ptr bound_type = std::unique_ptr ( ASTLoweringType::translate (item.get_type ().get ())); From patchwork Tue Jan 30 12:07:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892911 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=XRIZ1bST; 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 4TPQ2P0zrkz23fD for ; Tue, 30 Jan 2024 23:48:29 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 246C13864C64 for ; Tue, 30 Jan 2024 12:48:27 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id A9BD738582BF for ; Tue, 30 Jan 2024 12:12:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A9BD738582BF 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 A9BD738582BF Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::334 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616778; cv=none; b=Os9Wz6z41qVcYQP7wTkbjSuprxeYeppdsYC6SFf74SZCqwvJfz24K0lEhguD3ay+ltw/X9OS33+3xHtyXvoD7CfWSruinWUBCN/BCgO9a2sJRkXEry90JBagswRbAPHpbtBmxOvZy7kYJuv9h4ejw74smxsYshVNpu9gMGXuaB8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616778; c=relaxed/simple; bh=vGuZogYQZprs3muuw9lexLSUA+ED5TsRF59EvwE6Uic=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=BjreEoWCvOAK+vZTxGtWLCCJDsVoNq96XatN4ORy/3Ipi0s2sPIlQm9PjLc6n47zZz1WiqyYtcXmchxJVSn/qmNYsPtujyTbgXAJ7YB/WPyvyTHs6rnXNXW1V/edAPTKydboMTdyomnOPCv/kt3xmZwb0IG1qRbkhJveYF/SIlw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40fafd3ebb5so1119905e9.2 for ; Tue, 30 Jan 2024 04:12:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616719; x=1707221519; 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=Fr6NPO8uw0iG/mBx4SWdamYfDF+YFH1P+EvCx8X3wH4=; b=XRIZ1bSTJ669Am1AE/kYeX4pRL1i3plgmJmMMIVi9OI11o8u6fcgI/UOzYYWmtRQJD PRsLWW+K2uz4dvjntyEsIyGwaED3N6JELfXJK4s6KcDbTYWaKHqSuI8iVuguudrFdTtN umRPr5VQo6Yw7a24URLDyoJhYpJElATFdOqf2h4b9rVleU3uIjQdsORZxZ0WWPfAXn/D 2Z2bVVZdVXll67l66j4uj+dJSBTcRpdh1rCbcRScMLs1NySpmpSLxDWSoxnZ/wYPvnPE aOCo8NuHnyainFga4YMrGcTonofvVRzsgDzb8wpOLpwnxLLUUScEyq2M4G/y6M/JfsQn 7A4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616719; x=1707221519; 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=Fr6NPO8uw0iG/mBx4SWdamYfDF+YFH1P+EvCx8X3wH4=; b=VEZdH4TIwYwjauBZXRa0dEjiB5OcS4W/U0T/HYH0w9m4q7dPJUYKT+p0xHlNjd1Zro oOaCkS+YEb/X29TD5WGtipyEUO7i7axcLFswXKsmfF/EcyvPkLR4bnz7voBEItij63Em O3ayKyMl1nl1nNvIxD4wF+4YclQ+W3ZW6U5LbIYZwZoF+8CLGyhvovl9qPcwu/HXVgHQ ephXlbsZLbEDJXMVMh2bl2cvdjPrAMRcB8JsSlEct/Kg5JGQpfce6s2xrPKPDCOTQuTr UrpBHRk1BQsG2f34dR9j7Y4ttvFSQXq/6chJQbqWXANU305ncfx72hP/LxwuXHo+IN8s IM6g== X-Gm-Message-State: AOJu0Yy4pI7wdKdZE40yOSr2Pomw5KFO732jQ4E0nhyHK0uZTFjbP2VQ fiOLy6vtqE0Z1DouyIBGdLuSbyia4D6/4nf/cwSDcB17hR4zgD26IJX/wCUlFn54OUDjvC80S0w ZKQ== X-Google-Smtp-Source: AGHT+IE5S2DXcp5Shst/RsMJRznyb5/bpEEzV0XzMU74pQIZnlc82UfaCS5sUVUUB+n/yWXDK42BUQ== X-Received: by 2002:adf:f982:0:b0:33a:fe6a:482 with SMTP id f2-20020adff982000000b0033afe6a0482mr119280wrr.32.1706616718902; Tue, 30 Jan 2024 04:11:58 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:58 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Jakub Dupak Subject: [COMMITTED 098/101] gccrs: Test: check implemented for lifetime handling Date: Tue, 30 Jan 2024 13:07:54 +0100 Message-ID: <20240130121026.807464-101-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.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, 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: Jakub Dupak gcc/testsuite/ChangeLog: * rust/compile/for_lifetimes.rs: New test. Signed-off-by: Jakub Dupak --- gcc/testsuite/rust/compile/for_lifetimes.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 gcc/testsuite/rust/compile/for_lifetimes.rs diff --git a/gcc/testsuite/rust/compile/for_lifetimes.rs b/gcc/testsuite/rust/compile/for_lifetimes.rs new file mode 100644 index 00000000000..26469624298 --- /dev/null +++ b/gcc/testsuite/rust/compile/for_lifetimes.rs @@ -0,0 +1,19 @@ +// { dg-additional-options "-frust-compile-until=typecheck" } + +fn function_pointer_as_argument(f: for<'a> fn(&'a i32) -> &'a i32) -> i32 { + 0 +} + +fn function_pointer_as_return() -> for<'a> fn(&'a i32) -> &'a i32 { +} + +// https://doc.rust-lang.org/reference/trait-bounds.html + +trait Fn {} +fn call_on_ref_zero(f: F) where for<'a> F: Fn(&'a i32) {} + +fn call_on_ref_zero2(f: F) where F: for<'a> Fn(&'a i32) {} + +trait Trait<'a, T: 'a> {} + +impl<'a, T> Trait<'a, T> for &'a T {} \ No newline at end of file From patchwork Tue Jan 30 12:07: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: 1892897 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=J+bTFMgE; 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 4TPPtc5tp9z23gZ for ; Tue, 30 Jan 2024 23:41:43 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6BC7D3861878 for ; Tue, 30 Jan 2024 12:41:41 +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 B22E63857439 for ; Tue, 30 Jan 2024 12:12:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B22E63857439 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 B22E63857439 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=1706616782; cv=none; b=qx+a5wByJqV93ecYmYBl5HF/im8ONKYdV9YAvBio5jcnD2yRtDR5DswJFGnhqGvOhYbPpL3cCfTK+dtDMm+fZhyRC99Jhzu1rdDktmlTkQ+lJKFbtox0Q5iB/EnYucIKT2SbGmy7XPtZZB2ZQY2UqZS6HR393Hbs6QI58qnMpAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616782; c=relaxed/simple; bh=RzmgAQKgltTr23Dl3fY6lYrdyCZmq54zIkyGctm19yM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=iqV4pPlB9GP4ZcYK0jt/vE00Y6GnBDM/0Rc9j/FVUk5sxwwEo7ijUka5Q0kHbYVb6XRlYZsl3ehiw+V8h2yARmhIEDnnnVTqHD4aALcMQaS6bwUqEdGRJX04TMkkmZXroLedNFX26X77RkD8bRdXHCJrtop/BzIT/f+b0mAf8Qk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-40fafd3ebb5so1119995e9.2 for ; Tue, 30 Jan 2024 04:12:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616719; x=1707221519; 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=FnzcZnqzwBWuKXiP4x5Vhxld3d3kFDfelIyKnfZd6B8=; b=J+bTFMgEHlXXiWjX7shXRmbYul5x9lF+U/rFMJ8iBUEAvT2dLTCMYngTRdxaEYq4RX 5SlqJi8prf6M1HbtcxTKyZDkIjJg69ACKgZLy90OJDyzj4MZM68mbVvywpQGOEr42Vo9 81/W2JRkLXNjSsOPiVnGCJcc8gD9C1b/FTP033GEYhUZje2Rccv9d5FfVO1G6CAttjyC i6yeDKq4aVOOUEGRgHmRz2iRwEzEjmC+0g6oEp6AiQfdSGqOo1jcCOYqNeultwz6odpb ARACm8NaWIIiXjznuQNdWUe5y6wt8ZmWb8Irx7ggYzGoKisUBbNpHuSJFa/dyc6C5BIz efIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616719; x=1707221519; 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=FnzcZnqzwBWuKXiP4x5Vhxld3d3kFDfelIyKnfZd6B8=; b=U2MbvPchctCVT0jizKjVIjeK2rUmPI4WaE8Ae7GxjbQ64qiE9JEewf2Rnzsj/STVOo jYayO02EzFKqZsFKB2S1WZEy9uAZG9LaHANin1BBVe53QsaG0IAdApfvhrIuu74x8ZNk mb+hiSJOwuRkC3sn1SgwbpYBmV1M0nwIU0jCLQWxXrBT0H8Rjk8tiDiXZOXtW8Yr6iQv ymabZCI+Y9k/e38p2xIu457b+7zoB3nB91O0LrigYshRLOQY3TR+/HfpCvq4Kr+qtOrc /8mwMs0oKlOiQ9VgUD4c4ajpCS2mkg0gEIhOYfYS2iRmBs+8lG+huP+eTVZm9jo3fBuT YNGQ== X-Gm-Message-State: AOJu0YxyU5JQkIOGPvuHCkjV3Ib7lWSjeW7uaRb/z6877pGEtjrQCAc1 zNqoSlckDCA3BtMtbvX40r+ay2454uHsuJiKAyLz0P/6kR+kRNnclE/18VJsk7jhwUUXP/1sigm wTw== X-Google-Smtp-Source: AGHT+IEKgkAb+coDxrGoaIs3Z0ISYEgDxYRXhe/oITBJYLnEdQmVDr8HKlNKdiYDyCw4nlYyu5vOrg== X-Received: by 2002:adf:a446:0:b0:33a:e6f2:4a48 with SMTP id e6-20020adfa446000000b0033ae6f24a48mr5956172wra.64.1706616719544; Tue, 30 Jan 2024 04:11:59 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:59 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Robert Goss Subject: [COMMITTED 099/101] gccrs: Add improved error when no fields in initializer Date: Tue, 30 Jan 2024 13:07:55 +0100 Message-ID: <20240130121026.807464-102-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.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, 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: Robert Goss If a struct type with a variant that has fields is initialized with some fields the expression HIR StructExprStructFields is checked that all the fields are assigned. However, if no fields are initialized the HIR StructExprStruct is generated. This doesn't check if the struct is a unit during typechekc and only fails at the compile stage with a ICE. Add a check at the typecheck stage that makes sure the struct does not have a variant with fields and give an error message based on the rustc one. We have also updated the message given in the case where one field was present to list the missing fields and match more closely the new message. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit) Add additional check * typecheck/rust-hir-type-check-struct-field.h: A helper method to make error added * typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve) Update message gcc/testsuite/ChangeLog: * rust/compile/missing_constructor_fields.rs: Added case with no initializers Signed-off-by: Robert Goss --- .../typecheck/rust-hir-type-check-expr.cc | 18 +++++++ .../rust-hir-type-check-struct-field.h | 9 ++++ .../typecheck/rust-hir-type-check-struct.cc | 48 +++++++++++++++++-- .../compile/missing_constructor_fields.rs | 6 ++- 4 files changed, 76 insertions(+), 5 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 030e5f1b63c..43d183f7a59 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -1017,6 +1017,24 @@ TypeCheckExpr::visit (HIR::StructExprStruct &struct_expr) return; } + TyTy::ADTType *adt = static_cast (struct_path_ty); + for (auto variant : adt->get_variants ()) + { + if (!variant->get_fields ().empty ()) + { + std::vector field_names; + for (auto &field : variant->get_fields ()) + field_names.push_back (field->get_name ()); + Error missing_fields_error + = TypeCheckStructExpr::make_missing_field_error ( + struct_expr.get_locus (), field_names, + struct_path_ty->get_name ()); + // We might want to return or handle these in the future emit for now. + missing_fields_error.emit (); + return; + } + } + infered = struct_path_ty; } diff --git a/gcc/rust/typecheck/rust-hir-type-check-struct-field.h b/gcc/rust/typecheck/rust-hir-type-check-struct-field.h index 31d2896d0bb..792eebf3ff5 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-struct-field.h +++ b/gcc/rust/typecheck/rust-hir-type-check-struct-field.h @@ -25,6 +25,9 @@ #include "rust-tyty.h" namespace Rust { + +struct Error; + namespace Resolver { class TypeCheckStructExpr : public TypeCheckBase @@ -32,6 +35,12 @@ class TypeCheckStructExpr : public TypeCheckBase public: static TyTy::BaseType *Resolve (HIR::StructExprStructFields *expr); + // Helper for making any errors + static Error + make_missing_field_error (location_t locus, + const std::vector &missing_field_names, + const std::string &struct_name); + protected: void resolve (HIR::StructExprStructFields &struct_expr); diff --git a/gcc/rust/typecheck/rust-hir-type-check-struct.cc b/gcc/rust/typecheck/rust-hir-type-check-struct.cc index 56aa3d869a4..d2977ac8ea8 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-struct.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-struct.cc @@ -142,7 +142,16 @@ TypeCheckStructExpr::resolve (HIR::StructExprStructFields &struct_expr) } // check the arguments are all assigned and fix up the ordering - if (fields_assigned.size () != variant->num_fields ()) + std::vector missing_field_names; + for (auto &field : variant->get_fields ()) + { + auto it = fields_assigned.find (field->get_name ()); + if (it == fields_assigned.end ()) + { + missing_field_names.push_back (field->get_name ()); + } + } + if (!missing_field_names.empty ()) { if (struct_def->is_union ()) { @@ -156,8 +165,12 @@ TypeCheckStructExpr::resolve (HIR::StructExprStructFields &struct_expr) } else if (!struct_expr.has_struct_base ()) { - rust_error_at (struct_expr.get_locus (), ErrorCode::E0063, - "constructor is missing fields"); + Error missing_fields_error + = make_missing_field_error (struct_expr.get_locus (), + missing_field_names, + struct_path_ty->get_name ()); + // We might want to return or handle these in the future emit for now. + missing_fields_error.emit (); return; } else @@ -392,5 +405,34 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifier &field) return true; } +Error +TypeCheckStructExpr::make_missing_field_error ( + location_t locus, const std::vector &missing_field_names, + const std::string &struct_name) +{ + // Message plurality depends on size + if (missing_field_names.size () == 1) + { + return Error (locus, ErrorCode::E0063, + "missing field %s in initializer of %qs", + missing_field_names[0].c_str (), struct_name.c_str ()); + } + // Make comma separated string for display + std::stringstream display_field_names; + bool first = true; + for (auto &name : missing_field_names) + { + if (!first) + { + display_field_names << ", "; + } + first = false; + display_field_names << name; + } + return Error (locus, ErrorCode::E0063, + "missing fields %s in initializer of %qs", + display_field_names.str ().c_str (), struct_name.c_str ()); +} + } // namespace Resolver } // namespace Rust diff --git a/gcc/testsuite/rust/compile/missing_constructor_fields.rs b/gcc/testsuite/rust/compile/missing_constructor_fields.rs index 9d492101fbd..6e3965b5687 100644 --- a/gcc/testsuite/rust/compile/missing_constructor_fields.rs +++ b/gcc/testsuite/rust/compile/missing_constructor_fields.rs @@ -6,5 +6,7 @@ struct Foo { } fn main() { - let x = Foo { x: 0 , y:1 }; // { dg-error "constructor is missing fields" } -} \ No newline at end of file + let z = Foo { x: 0 , y:1 }; // { dg-error "missing field z in initializer of 'Foo'" } + let xz = Foo { y:1 }; // { dg-error "missing fields x, z in initializer of 'Foo'" } + let xyz = Foo { }; // { dg-error "missing fields x, y, z in initializer of 'Foo'" } +} From patchwork Tue Jan 30 12:07:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892901 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=CvV9n336; 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 4TPPw069kLz23gc for ; Tue, 30 Jan 2024 23:42:56 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DB80C386EC5F for ; Tue, 30 Jan 2024 12:42:54 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id C99E83857730 for ; Tue, 30 Jan 2024 12:12:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C99E83857730 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 C99E83857730 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616781; cv=none; b=B68xnK71hPfaR3o3Auz0fLnPe9/toQ8wu8ISS3lVtHNzoREySVDWMXPbTA4+SSO9odTaJGMUKfNR/ffnDsAcCzD9+O/Ws9ZMfNWIqw9Yt8xItesLoRbC35HKKbzH2EfD7b6BDSEG8up143jyKrAzoitnZmcDqfA4WBy3yBxTLRw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616781; c=relaxed/simple; bh=r8e7g3DdBZoKCXzrIO6qvkfYpO0m8Ii39hz2BAj21Ws=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xq87OZB3beogznqGCKPh4c9v98b982NzoOKkxVfUfbqakua5HNbE+MdPVEWJEw52yZ1+Aj615JV5dnWgGx8dCpF1LFh7Tcdd7qt/vp8p/9UMb4Op6liMap7zO66Ve8sNfGpoqLQumGQhwcnsm4nJJx0eOFP+KnfeMo7wKNk1ZUI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-337d05b8942so3298012f8f.3 for ; Tue, 30 Jan 2024 04:12:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616720; x=1707221520; 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=mQv1uk9NwV34NhLXI89aFCvZYI3S70uFrCuNj94Y9e4=; b=CvV9n336z5xspM+EwYbIGctTbQE2Q4FaPsAE2rmfiEFaeYbfsHGQl8RhFm3GcGmGe7 5KhRaBukHPdF3vk6NW4MfB8OjQW9jROgX3qcj2iMWwvEaHpTnOTkWIBX8BnMLmry5dxR LGj4uTX19Sn7wda/p6ZGZdA1hc/rDiXXIkxFn4QRvdtc2rvhoETYXq4FCpyUzv5VqKbd pJ1DD2upQVhTFtP34LKV/v3nDBmHa54CZ18qTniYpsJURgTKmeWZSOLFVtjZjBf0iKdY i3Atfuw4A435w3+r2Er42H/KCUF9qev3Eoi0Z8UKu/tbcsjP5TroP+DowvfR4MzO6B87 Ut1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616720; x=1707221520; 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=mQv1uk9NwV34NhLXI89aFCvZYI3S70uFrCuNj94Y9e4=; b=s31r9AgmhrjVR3psrxe6K4nss0kduISj6WawNqIS56IYTp2vuzJSien6wAmo56Ar+W QV1aTB2Po+mljW3mMj9RAQFkTtHa2AgrDcoaOrz/DVUFQd4qlybxySpfTFxO4498CNvl t0gEjykeNTRg0YEpuaypt5T9w+gDlG5bfUz/VWT9Mqe6SmoyWG4oDSq2aUwTOmt00paZ TRz6v2coKT7RARj1ZUlMQ8mHahHQFO6k1Cwoy/Kd3yaU4snbjqDfsC1Yg6W5izl3jKDz TXPgJpUaZbr7WRj4cqHllYZDE+Lcq59NrE7/0uEC0rfjD27syr3M+mg+EKPjkh8Fk4bE jBMw== X-Gm-Message-State: AOJu0Yx+uU8QOZFmO4dVGk9EZBPk5+gOrqpWSD5yy2UseKiyh+1ujFnQ QHxnlekhKtbRqlR2KFRfFZ4ZTwujkIQBgxR2Dm6rcQ6v9qXjprPYcMFoL+eisoU/FzxH7lugU6f K2w== X-Google-Smtp-Source: AGHT+IEx7e2rXrYQu15IhFmc9p8LwqVpYqE7f4kPZtbC4BJYVNhDV+OZSMAzQ5ZlcmigzAvqz48ubg== X-Received: by 2002:a5d:678a:0:b0:33a:e38d:f944 with SMTP id v10-20020a5d678a000000b0033ae38df944mr6590513wru.60.1706616720036; Tue, 30 Jan 2024 04:12:00 -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.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:11:59 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Owen Avery Subject: [COMMITTED 100/101] gccrs: Remove TraitImplItem Date: Tue, 30 Jan 2024 13:07:56 +0100 Message-ID: <20240130121026.807464-103-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.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, 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: Owen Avery gcc/rust/ChangeLog: * ast/rust-ast-full-decls.h (class TraitImplItem): Remove forward declaration. (class AssociatedItem): Add forward declaration. * ast/rust-ast.h (class TraitImplItem): Remove. (class TraitItem): Inherit from AssociatedItem. (SingleASTNode::take_trait_impl_item): Return std::unique_ptr instead of std::unique_ptr. * ast/rust-item.h (class Function): Inherit from AssociatedItem instead of TraitImplItem. (class TypeAlias): Likewise. (class ConstantItem): Likewise. (class TraitImpl): Store items as AssociatedItem. * expand/rust-derive-clone.cc (DeriveClone::clone_fn): Return std::unique_ptr. (DeriveClone::clone_impl): Take std::unique_ptr. * expand/rust-derive-clone.h (DeriveClone::clone_fn): Return std::unique_ptr. (DeriveClone::clone_impl): Take std::unique_ptr. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Handle changes to SingleASTNode::take_trait_impl_item. * parse/rust-parse-impl.h (Parser::parse_impl): Parse TraitImpl as containing AssociatedItem. (Parser::parse_trait_impl_item): Return std::unique_ptr. (Parser::parse_trait_impl_function_or_method): Likewise. * parse/rust-parse.h (Parser::parse_trait_impl_item): Return std::unique_ptr. (Parser::parse_trait_impl_function_or_method): Likewise. Signed-off-by: Owen Avery --- gcc/rust/ast/rust-ast-full-decls.h | 2 +- gcc/rust/ast/rust-ast.h | 22 +++------------------- gcc/rust/ast/rust-item.h | 18 +++++++++--------- gcc/rust/expand/rust-derive-clone.cc | 8 ++++---- gcc/rust/expand/rust-derive-clone.h | 4 ++-- gcc/rust/expand/rust-expand-visitor.cc | 2 +- gcc/rust/parse/rust-parse-impl.h | 8 ++++---- gcc/rust/parse/rust-parse.h | 4 ++-- 8 files changed, 26 insertions(+), 42 deletions(-) diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h index 5bfaaa8ba3c..0f95149a214 100644 --- a/gcc/rust/ast/rust-ast-full-decls.h +++ b/gcc/rust/ast/rust-ast-full-decls.h @@ -52,7 +52,7 @@ class GenericParam; class LifetimeParam; class ConstGenericParam; class TraitItem; -class TraitImplItem; +class AssociatedItem; struct Crate; class PathExpr; diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 256a527118a..e96ac349733 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1657,22 +1657,8 @@ public: virtual location_t get_locus () const = 0; }; -// Abstract base class for items used in a trait impl -class TraitImplItem : public AssociatedItem -{ -protected: - virtual TraitImplItem *clone_associated_item_impl () const override = 0; - -public: - // Unique pointer custom clone function - std::unique_ptr clone_trait_impl_item () const - { - return std::unique_ptr (clone_associated_item_impl ()); - } -}; - // Item used in trait declarations - abstract base class -class TraitItem : public TraitImplItem +class TraitItem : public AssociatedItem { protected: TraitItem (location_t locus) @@ -1945,11 +1931,9 @@ public: return take_assoc_item (); } - std::unique_ptr take_trait_impl_item () + std::unique_ptr take_trait_impl_item () { - rust_assert (!is_error ()); - return std::unique_ptr ( - static_cast (assoc_item.release ())); + return take_assoc_item (); } std::unique_ptr take_type () diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 5b9eb64560d..1553f29ad2d 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -1289,7 +1289,7 @@ protected: class LetStmt; // Rust function declaration AST node -class Function : public VisItem, public TraitImplItem +class Function : public VisItem, public AssociatedItem { FunctionQualifiers qualifiers; Identifier function_name; @@ -1436,7 +1436,7 @@ protected: }; // Rust type alias (i.e. typedef) AST node -class TypeAlias : public VisItem, public TraitImplItem +class TypeAlias : public VisItem, public AssociatedItem { Identifier new_type_name; @@ -2312,7 +2312,7 @@ protected: /* "Constant item" AST node - used for constant, compile-time expressions * within module scope (like constexpr) */ -class ConstantItem : public VisItem, public TraitImplItem +class ConstantItem : public VisItem, public AssociatedItem { // either has an identifier or "_" - maybe handle in identifier? // bool identifier_is_underscore; @@ -3484,7 +3484,7 @@ class TraitImpl : public Impl TypePath trait_path; // bool has_impl_items; - std::vector> impl_items; + std::vector> impl_items; public: std::string as_string () const override; @@ -3494,7 +3494,7 @@ public: // Mega-constructor TraitImpl (TypePath trait_path, bool is_unsafe, bool has_exclam, - std::vector> impl_items, + std::vector> impl_items, std::vector> generic_params, std::unique_ptr trait_type, WhereClause where_clause, Visibility vis, std::vector inner_attrs, @@ -3513,7 +3513,7 @@ public: { impl_items.reserve (other.impl_items.size ()); for (const auto &e : other.impl_items) - impl_items.push_back (e->clone_trait_impl_item ()); + impl_items.push_back (e->clone_associated_item ()); } // Overloaded assignment operator with vector clone @@ -3526,7 +3526,7 @@ public: impl_items.reserve (other.impl_items.size ()); for (const auto &e : other.impl_items) - impl_items.push_back (e->clone_trait_impl_item ()); + impl_items.push_back (e->clone_associated_item ()); return *this; } @@ -3541,11 +3541,11 @@ public: bool is_exclam () const { return has_exclam; } // TODO: think of better way to do this - const std::vector> &get_impl_items () const + const std::vector> &get_impl_items () const { return impl_items; } - std::vector> &get_impl_items () + std::vector> &get_impl_items () { return impl_items; } diff --git a/gcc/rust/expand/rust-derive-clone.cc b/gcc/rust/expand/rust-derive-clone.cc index cc198eecf5d..01226e4f913 100644 --- a/gcc/rust/expand/rust-derive-clone.cc +++ b/gcc/rust/expand/rust-derive-clone.cc @@ -43,7 +43,7 @@ DeriveClone::clone_call (std::unique_ptr &&to_clone) * fn clone(&self) -> Self { } * */ -std::unique_ptr +std::unique_ptr DeriveClone::clone_fn (std::unique_ptr &&clone_expr) { auto block = std::unique_ptr ( @@ -57,7 +57,7 @@ DeriveClone::clone_fn (std::unique_ptr &&clone_expr) std::vector> params; params.push_back (std::move (self)); - return std::unique_ptr ( + return std::unique_ptr ( new Function ({"clone"}, builder.fn_qualifiers (), /* generics */ {}, /* function params */ std::move (params), std::move (big_self_type), WhereClause::create_empty (), @@ -73,7 +73,7 @@ DeriveClone::clone_fn (std::unique_ptr &&clone_expr) * */ std::unique_ptr -DeriveClone::clone_impl (std::unique_ptr &&clone_fn, +DeriveClone::clone_impl (std::unique_ptr &&clone_fn, std::string name) { // should that be `$crate::core::clone::Clone` instead? @@ -81,7 +81,7 @@ DeriveClone::clone_impl (std::unique_ptr &&clone_fn, segments.emplace_back (builder.type_path_segment ("Clone")); auto clone = TypePath (std::move (segments), loc); - auto trait_items = std::vector> (); + auto trait_items = std::vector> (); trait_items.emplace_back (std::move (clone_fn)); return std::unique_ptr ( diff --git a/gcc/rust/expand/rust-derive-clone.h b/gcc/rust/expand/rust-derive-clone.h index dcb88f9468a..1009247e882 100644 --- a/gcc/rust/expand/rust-derive-clone.h +++ b/gcc/rust/expand/rust-derive-clone.h @@ -49,7 +49,7 @@ private: * fn clone(&self) -> Self { } * */ - std::unique_ptr clone_fn (std::unique_ptr &&clone_expr); + std::unique_ptr clone_fn (std::unique_ptr &&clone_expr); /** * Create the Clone trait implementation for a type @@ -59,7 +59,7 @@ private: * } * */ - std::unique_ptr clone_impl (std::unique_ptr &&clone_fn, + std::unique_ptr clone_impl (std::unique_ptr &&clone_fn, std::string name); virtual void visit_struct (StructStruct &item); diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc index a60c4728926..dad2417eac4 100644 --- a/gcc/rust/expand/rust-expand-visitor.cc +++ b/gcc/rust/expand/rust-expand-visitor.cc @@ -957,7 +957,7 @@ ExpandVisitor::visit (AST::TraitImpl &impl) if (impl.has_where_clause ()) expand_where_clause (impl.get_where_clause ()); - std::function (AST::SingleASTNode)> + std::function (AST::SingleASTNode)> extractor = [] (AST::SingleASTNode node) { return node.take_trait_impl_item (); }; diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 7ea7276dc94..c622ed7bc97 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -5492,12 +5492,12 @@ Parser::parse_impl (AST::Visibility vis, AST::AttrVec inner_attrs = parse_inner_attributes (); // parse trait impl items - std::vector> impl_items; + std::vector> impl_items; const_TokenPtr t = lexer.peek_token (); while (t->get_id () != RIGHT_CURLY) { - std::unique_ptr impl_item + std::unique_ptr impl_item = parse_trait_impl_item (); if (impl_item == nullptr) @@ -5759,7 +5759,7 @@ Parser::parse_inherent_impl_function_or_method ( // Parses a single trait impl item (item inside a trait impl block). template -std::unique_ptr +std::unique_ptr Parser::parse_trait_impl_item () { // parse outer attributes (if they exist) @@ -5836,7 +5836,7 @@ Parser::parse_trait_impl_item () * smaller ones and prevents duplication of logic. Strictly, this parses a * function or method item inside a trait impl item block. */ template -std::unique_ptr +std::unique_ptr Parser::parse_trait_impl_function_or_method ( AST::Visibility vis, AST::AttrVec outer_attrs) { diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index 02f90217fc2..34397540321 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -171,7 +171,7 @@ public: std::unique_ptr parse_external_item (); std::unique_ptr parse_trait_item (); std::unique_ptr parse_inherent_impl_item (); - std::unique_ptr parse_trait_impl_item (); + std::unique_ptr parse_trait_impl_item (); AST::PathInExpression parse_path_in_expression (); std::vector> parse_lifetime_params (); AST::Visibility parse_visibility (); @@ -353,7 +353,7 @@ private: std::unique_ptr parse_inherent_impl_function_or_method (AST::Visibility vis, AST::AttrVec outer_attrs); - std::unique_ptr + std::unique_ptr parse_trait_impl_function_or_method (AST::Visibility vis, AST::AttrVec outer_attrs); std::unique_ptr From patchwork Tue Jan 30 12:07:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 1892884 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=UlQtnk/V; 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 4TPPpV37s4z23dQ for ; Tue, 30 Jan 2024 23:38:10 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6D14A3831E36 for ; Tue, 30 Jan 2024 12:38:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 56B7D3857731 for ; Tue, 30 Jan 2024 12:12:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 56B7D3857731 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 56B7D3857731 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::432 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616782; cv=none; b=ZSfmQhTWT3A+wd+L4EaqKealLnCJM5fBBWOFnjq5ZHs9uO5jTgBsiPbu4Yms9i85YSy4DFJKJzD/vRuf1l5LAediDCKrxD+xaXMBbRHq8hNPEMnSvMqckEF4HVMaDPpEjl9PHZ1OiR3wDWPiT6T51tSoUjl8PCnTlgbauOcH71c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706616782; c=relaxed/simple; bh=n5PTnWOeEvyeSnTJG65pYS2PFartb12WnWjOXjHvUEc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=IBBgpy4WyPUKRMQxApKEKJjsmC8EHzsmWMrK68+to2iy7s1f0YNZaLuA7xN426Smo6Ufba5xtxcORAEUGGf313HX60BAFRd6iNjbWYMvCy5uCAagK3meVTGNeC6i5ySUCmL7PVhp8mnpP0HyJ7hl/KvkQF2XNqYNq00EuG5oPaY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-33ae74e5394so1286115f8f.3 for ; Tue, 30 Jan 2024 04:12:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1706616720; x=1707221520; 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=T26TFjSRJTXXAm4/FTewxtu2dTAQIfHbyVx+Ih7LfLk=; b=UlQtnk/Vxb29kwKoX3KItG/y9upO6ytLeXMdONAMvdcIV0NKprncD7WrqkKCVwBHWY ZiWbaSurnvwF0jWzGi7AH/6qkytz7vcqzKmNuQKpARqpX7g99oHy5zO2JVhfayzAClQG popApAiyTgUkQCDRkvjQ81PjB9ohCqlrfnabWsmS/zOTIenUgo9iKehQpI51Gvvf+A5g 7tayWFHH/VNh/ksxn9H+RJys341NXSpeDY5oQ3+73b+zYvrQWm5jEenHPdMPGYFpL2VK HlZ3Xu6oJZeYrqQqS5ggqIvchZ6kSrBW99iFc/TxEKDOrmAV+T3n368c+Si0sxEawqGi VhfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706616720; x=1707221520; 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=T26TFjSRJTXXAm4/FTewxtu2dTAQIfHbyVx+Ih7LfLk=; b=TVgWmXzzBbDei9tjBL8azTPMECBvgH0BNQ1WZrq0e6s+t8eNcX3iW3vdYYdRyfQc7p IMOe8Nk0nFlxPl3yq4ZRlbrOMkIxIcYN0ZASNa6aEaOldT43tKDRNCsPsFAihJt3aMgu iGZO+Gw13wCdpMAyj6t0HAgmcJLmTyyiCwn+esOfQX4b2LcJpcHhpPN1TlEqAxwGS+3k u99TrcPbA26iSKZbGlHKZihZr9OyImw0gU8+a7fGhnnq4fimjWKuRoYFoaCRPID5k07m LHjmVO5EQTnyKjtq6Y6TSvfJfs//dh5i9Ua88SMq3g5IJGz90iKNqXqeorcVZV2n3aoi 0dTw== X-Gm-Message-State: AOJu0YwxQqaiEjG8+rSdgissohLdDC6l511xSz7gHPMrNc/jCBbsQUmZ Pfkyul2C5bIR7N6BShfdK8NqUIRvwgTYmk2hW/Hzyvb/ME+7uJE6hGcb9JEttiub+Vb1MX1lE2M NEA== X-Google-Smtp-Source: AGHT+IHvlOllJMbTzOnkbgUXKktlyAoDPTxYG0eOazyqkaQUC3xnVlb3UC7tIx26d1tFxIAzHZbL8Q== X-Received: by 2002:adf:ce91:0:b0:33a:f85a:6caa with SMTP id r17-20020adfce91000000b0033af85a6caamr1359079wrn.20.1706616720402; Tue, 30 Jan 2024 04:12:00 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id f9-20020a056000036900b00339307d9d31sm10569894wrf.112.2024.01.30.04.12.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 04:12:00 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [COMMITTED 101/101] gccrs: Fix output line ending patterns. Date: Tue, 30 Jan 2024 13:07:57 +0100 Message-ID: <20240130121026.807464-104-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.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, 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/testsuite/ChangeLog: * rust/execute/torture/builtin_macros1.rs: Fix output pattern. * rust/execute/torture/coercion3.rs: Likewise. * rust/execute/torture/issue-2080.rs: Likewise. * rust/execute/torture/issue-2179.rs: Likewise. * rust/execute/torture/issue-2180.rs: Likewise. * rust/execute/torture/iter1.rs: Likewise. --- gcc/testsuite/rust/execute/torture/builtin_macros1.rs | 2 +- gcc/testsuite/rust/execute/torture/coercion3.rs | 2 +- gcc/testsuite/rust/execute/torture/issue-2080.rs | 2 +- gcc/testsuite/rust/execute/torture/issue-2179.rs | 2 +- gcc/testsuite/rust/execute/torture/issue-2180.rs | 2 +- gcc/testsuite/rust/execute/torture/iter1.rs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gcc/testsuite/rust/execute/torture/builtin_macros1.rs b/gcc/testsuite/rust/execute/torture/builtin_macros1.rs index f5dcbd6423c..04d00581897 100644 --- a/gcc/testsuite/rust/execute/torture/builtin_macros1.rs +++ b/gcc/testsuite/rust/execute/torture/builtin_macros1.rs @@ -1,4 +1,4 @@ -// { dg-output "rust/execute/torture/builtin_macros1.rs\r*" } +// { dg-output "rust/execute/torture/builtin_macros1.rs\r*\n" } #![feature(rustc_attrs)] #[rustc_builtin_macro] diff --git a/gcc/testsuite/rust/execute/torture/coercion3.rs b/gcc/testsuite/rust/execute/torture/coercion3.rs index e88338ae2f3..0686056de4e 100644 --- a/gcc/testsuite/rust/execute/torture/coercion3.rs +++ b/gcc/testsuite/rust/execute/torture/coercion3.rs @@ -1,4 +1,4 @@ -// { dg-output "123\n" } +// { dg-output "123\r*\n" } #[lang = "sized"] pub trait Sized {} diff --git a/gcc/testsuite/rust/execute/torture/issue-2080.rs b/gcc/testsuite/rust/execute/torture/issue-2080.rs index dbdbf41ff92..5fdf911efe1 100644 --- a/gcc/testsuite/rust/execute/torture/issue-2080.rs +++ b/gcc/testsuite/rust/execute/torture/issue-2080.rs @@ -1,4 +1,4 @@ -// { dg-output "hello world: gccrs\n" } +// { dg-output "hello world: gccrs\r*\n" } // { dg-additional-options "-w" } static TEST_1: &str = "gccrs"; static TEST_2: i32 = 123; diff --git a/gcc/testsuite/rust/execute/torture/issue-2179.rs b/gcc/testsuite/rust/execute/torture/issue-2179.rs index 86ed11f51c5..8a5ec1bf32e 100644 --- a/gcc/testsuite/rust/execute/torture/issue-2179.rs +++ b/gcc/testsuite/rust/execute/torture/issue-2179.rs @@ -1,4 +1,4 @@ -// { dg-output "123\n" } +// { dg-output "123\r*\n" } #[lang = "sized"] pub trait Sized {} diff --git a/gcc/testsuite/rust/execute/torture/issue-2180.rs b/gcc/testsuite/rust/execute/torture/issue-2180.rs index beed69620a0..6bd71720e48 100644 --- a/gcc/testsuite/rust/execute/torture/issue-2180.rs +++ b/gcc/testsuite/rust/execute/torture/issue-2180.rs @@ -1,4 +1,4 @@ -// { dg-output "123\n" } +// { dg-output "123\r*\n" } #[lang = "sized"] pub trait Sized {} diff --git a/gcc/testsuite/rust/execute/torture/iter1.rs b/gcc/testsuite/rust/execute/torture/iter1.rs index 08f06456e36..c3b6c7bc3f8 100644 --- a/gcc/testsuite/rust/execute/torture/iter1.rs +++ b/gcc/testsuite/rust/execute/torture/iter1.rs @@ -1,4 +1,4 @@ -// { dg-output "1\n2\n" } +// { dg-output "1\r*\n2\r*\n" } #![feature(intrinsics)] pub use option::Option::{self, None, Some};