From patchwork Thu Aug 1 14:56: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: 1967754 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=bEd1zMwL; 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 4WZXYf37jMz1ydq for ; Fri, 2 Aug 2024 01:14:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ADCEE3864C65 for ; Thu, 1 Aug 2024 15:14:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by sourceware.org (Postfix) with ESMTPS id B5CCF3860778 for ; Thu, 1 Aug 2024 14:59:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B5CCF3860778 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 B5CCF3860778 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::52a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524372; cv=none; b=olaoJHqwWrAcDmyl9+NXoSMyTtsMBO/XT2fAI5aYZPGd55ZCyHPM2UdoTWBuBPTOctRu56ptG1kdpNqIdP5ypk2SBomSGibwA6WKPih6hSqFCuUA3q7wTz6XcLHvzdo8yaVJ2OM2BF7lUjZOdAKdp4khiHPEC8uUqYUwptdGycw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524372; c=relaxed/simple; bh=2XDqVXsb6RYafBaSES0kODX/IHfMe0WCTHatNOcofyE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=K0LqgGcZDmze5PWZZdsVmfPVK6bqIszEkD3WetjPHdENU9bCy5koWLTKPH6UHpzpdoIAU9df09dXc3/+wQn/BaqPpzWOqZeF8FKMffkv8zk8lYsOsuID2hB2jpx2EB3AqwLH8Bd0JC8nNFHpsy7BSbkunBL4VYrFlGj3wu0qC8I= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-5a2ffc34722so4084053a12.0 for ; Thu, 01 Aug 2024 07:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1722524343; x=1723129143; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3zXQBvTfUWAfXUkIk+Em1g9eiGTawgUL26DLNYSrVBk=; b=bEd1zMwLkcD3ccRxp9kYLdWLx0f+kR5g0o9D6wMt8ZJB9UMSDbgYmYNKIOaX9H0i1H EGzwdNKQ1P/YSNMQ1SBXFzN6VvDr9NqMJy//UkZHteZAwmFFgv08DHokxwKNre5VuYEc aWFhh9IMolOc6f4BHazvpkmLyYqMwGgL+HRNGBwf36Zogu3HOtFRSpUj8rP63GUqr5Jo yGBzuIRDvsnVz/FfYQKE9KRBV4xEuAHEuUTD3/z+mHi1Y5OH9P6l9B+ICjLctfhcqTD5 k2gHfkB3IH1EWD97f9gw2SuWjPkEU2QwP/jJgtXc1HrZhXN/6AxEbziiElbjksLAhXv3 I+BA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524343; x=1723129143; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3zXQBvTfUWAfXUkIk+Em1g9eiGTawgUL26DLNYSrVBk=; b=iOYGTjsQnq7+PWxfrOg3itaAjOQW0yLyiLao3Bri2QoproYqJ8kuVVin9AYCFCjVK2 C5XI37WKJQKWA8bNu5A1e76AIHoCh/RSaIceMA3WTmPjj2RZhEyVCrh4I+8btdi0XVOJ zpsqsUlt9nKQ0jJP1L0z/1nr//6xMXvh45LPbfR8J56WlXyNyQ9V7R/xnWNOh2dyrgXj Ayz8sPWSMHsK/Kb7XqHNreIE1Ik+eLDPMkpIs5t6OoBHSO1e8H3dHKPOen3DrBIyJ2Mh ppOQpIpsCZkhqRe5Fo9QZ/Ghl9E4HAXzWHxZraQQcfrWA7DWrLXPHTbkz9AzlCMLkCEq YAOQ== X-Gm-Message-State: AOJu0YxtX2Pwib2OmnOOoc7WHSTPLHI+AJL7IMU310zIIWaJFku5oaog UNwbh6LCvAIflemckqIpGQ17x0rRI7r7mhPy4CrCCLo2E+kLHbaDsF/2uf6hJK423qpM4xUVgQl c7hFu X-Google-Smtp-Source: AGHT+IGnaWVS2T78bnYqUleY9C8I7TQdgzPQrLU43hTQCQ3CBIvvFDrmuvZ+mgfXgdsDMCZZ+sXYjQ== X-Received: by 2002:a05:6402:40c5:b0:594:4d7e:1b6b with SMTP id 4fb4d7f45d1cf-5b77c28e112mr1876387a12.5.1722524342816; Thu, 01 Aug 2024 07:59:02 -0700 (PDT) Received: from platypus.lan ([2a04:cec2:9:dc84:3622:6733:ff49:ee91]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5ac63590592sm10252456a12.25.2024.08.01.07.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 07:59:02 -0700 (PDT) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, 0xn4utilus Subject: [PATCH 041/125] gccrs: Update resolver to use `AST::Function` instead of `AST::ExternalFunctionItem` Date: Thu, 1 Aug 2024 16:56:37 +0200 Message-ID: <20240801145809.366388-43-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240801145809.366388-2-arthur.cohen@embecosm.com> References: <20240801145809.366388-2-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org From: 0xn4utilus gcc/rust/ChangeLog: * checks/errors/rust-feature-gate.cc (FeatureGate::visit): Check if function is_external or not. * hir/rust-ast-lower-extern.h: Use AST::Function instead of AST::ExternalFunctionItem. * parse/rust-parse-impl.h (Parser::parse_external_item): Likewise. (Parser::parse_pattern): Fix clang format. * resolve/rust-ast-resolve-implitem.h: Likewise. * resolve/rust-ast-resolve-item.cc (ResolveExternItem::visit): Likewise. * resolve/rust-ast-resolve-item.h: Likewise. * resolve/rust-default-resolver.cc (DefaultResolver::visit): Check if param has_pattern before using get_pattern. Signed-off-by: 0xn4utilus --- gcc/rust/checks/errors/rust-feature-gate.cc | 3 ++- gcc/rust/hir/rust-ast-lower-extern.h | 23 +++++++++++++++----- gcc/rust/parse/rust-parse-impl.h | 7 +++--- gcc/rust/resolve/rust-ast-resolve-implitem.h | 4 ++-- gcc/rust/resolve/rust-ast-resolve-item.cc | 16 +++++++++----- gcc/rust/resolve/rust-ast-resolve-item.h | 2 +- gcc/rust/resolve/rust-default-resolver.cc | 3 ++- 7 files changed, 39 insertions(+), 19 deletions(-) diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc b/gcc/rust/checks/errors/rust-feature-gate.cc index 3c943022f05..33bbfa1ec51 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.cc +++ b/gcc/rust/checks/errors/rust-feature-gate.cc @@ -131,7 +131,8 @@ FeatureGate::visit (AST::MacroRulesDefinition &rules_def) void FeatureGate::visit (AST::Function &function) { - check_rustc_attri (function.get_outer_attrs ()); + if (!function.is_external ()) + check_rustc_attri (function.get_outer_attrs ()); } void diff --git a/gcc/rust/hir/rust-ast-lower-extern.h b/gcc/rust/hir/rust-ast-lower-extern.h index f9e067c8e95..ad7d75422d6 100644 --- a/gcc/rust/hir/rust-ast-lower-extern.h +++ b/gcc/rust/hir/rust-ast-lower-extern.h @@ -65,7 +65,7 @@ public: item.get_outer_attrs (), item.get_locus ()); } - void visit (AST::ExternalFunctionItem &function) override + void visit (AST::Function &function) override { std::vector > where_clause_items; HIR::WhereClause where_clause (std::move (where_clause_items)); @@ -88,12 +88,25 @@ public: std::vector function_params; for (auto it = begin; it != end; it++) { + auto param = static_cast (it->get ()); + + if (param->is_variadic () || param->is_self ()) + continue; + auto param_kind = param->get_pattern ()->get_pattern_kind (); + + rust_assert (param_kind == AST::Pattern::Kind::Identifier + || param_kind == AST::Pattern::Kind::Wildcard); + auto param_ident = static_cast ( + param->get_pattern ().get ()); + Identifier param_name = param_kind == AST::Pattern::Kind::Identifier + ? param_ident->get_ident () + : std::string ("_"); + HIR::Type *param_type - = ASTLoweringType::translate (it->get_type ().get ()); - Identifier param_name = it->get_name (); + = ASTLoweringType::translate (param->get_type ().get ()); auto crate_num = mappings->get_current_crate (); - Analysis::NodeMapping mapping (crate_num, it->get_node_id (), + Analysis::NodeMapping mapping (crate_num, param->get_node_id (), mappings->get_next_hir_id (crate_num), mappings->get_next_localdef_id ( crate_num)); @@ -109,7 +122,7 @@ public: mappings->get_next_localdef_id (crate_num)); translated = new HIR::ExternalFunctionItem ( - mapping, function.get_identifier (), std::move (generic_params), + mapping, function.get_function_name (), std::move (generic_params), std::unique_ptr (return_type), std::move (where_clause), std::move (function_params), is_variadic, std::move (vis), function.get_outer_attrs (), function.get_locus ()); diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index c8a87a11766..26b24150f7a 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -6165,8 +6165,7 @@ Parser::parse_external_item () std::move (outer_attrs), locus)); } case FN_KW: - return parse_external_function_item (std::move (vis), - std::move (outer_attrs)); + return parse_function (std::move (vis), std::move (outer_attrs), true); case TYPE: return parse_external_type_item (std::move (vis), @@ -10476,7 +10475,9 @@ Parser::parse_pattern () { lexer.skip_token (); alts.push_back (parse_pattern_no_alt ()); - } while (lexer.peek_token ()->get_id () == PIPE); + } + + while (lexer.peek_token ()->get_id () == PIPE); /* alternates */ return std::unique_ptr ( diff --git a/gcc/rust/resolve/rust-ast-resolve-implitem.h b/gcc/rust/resolve/rust-ast-resolve-implitem.h index 4f4d2893f83..fa344effe67 100644 --- a/gcc/rust/resolve/rust-ast-resolve-implitem.h +++ b/gcc/rust/resolve/rust-ast-resolve-implitem.h @@ -189,11 +189,11 @@ public: item->accept_vis (resolver); }; - void visit (AST::ExternalFunctionItem &function) override + void visit (AST::Function &function) override { auto decl = CanonicalPath::new_seg (function.get_node_id (), - function.get_identifier ().as_string ()); + function.get_function_name ().as_string ()); auto path = prefix.append (decl); resolver->get_name_scope ().insert ( diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 743657bc421..a3f27b3e4a0 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -1009,11 +1009,12 @@ ResolveExternItem::go (AST::ExternalItem *item, const CanonicalPath &prefix, } void -ResolveExternItem::visit (AST::ExternalFunctionItem &function) +ResolveExternItem::visit (AST::Function &function) { NodeId scope_node_id = function.get_node_id (); - auto decl = CanonicalPath::new_seg (function.get_node_id (), - function.get_identifier ().as_string ()); + auto decl + = CanonicalPath::new_seg (function.get_node_id (), + function.get_function_name ().as_string ()); auto path = prefix.append (decl); auto cpath = canonical_prefix.append (decl); @@ -1038,9 +1039,12 @@ ResolveExternItem::visit (AST::ExternalFunctionItem &function) // we make a new scope so the names of parameters are resolved and shadowed // correctly - for (auto ¶m : function.get_function_params ()) - if (!param.is_variadic ()) - ResolveType::go (param.get_type ().get ()); + for (auto &it : function.get_function_params ()) + if (!it->is_variadic ()) + { + auto param = static_cast (it.get ()); + ResolveType::go (param->get_type ().get ()); + } // done resolver->get_name_scope ().pop (); diff --git a/gcc/rust/resolve/rust-ast-resolve-item.h b/gcc/rust/resolve/rust-ast-resolve-item.h index e397ffdfe8b..0133d2ca27f 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.h +++ b/gcc/rust/resolve/rust-ast-resolve-item.h @@ -111,7 +111,7 @@ public: static void go (AST::ExternalItem *item, const CanonicalPath &prefix, const CanonicalPath &canonical_prefix); - void visit (AST::ExternalFunctionItem &function) override; + void visit (AST::Function &function) override; void visit (AST::ExternalStaticItem &item) override; private: diff --git a/gcc/rust/resolve/rust-default-resolver.cc b/gcc/rust/resolve/rust-default-resolver.cc index 28f04a10839..c99f2f64331 100644 --- a/gcc/rust/resolve/rust-default-resolver.cc +++ b/gcc/rust/resolve/rust-default-resolver.cc @@ -62,7 +62,8 @@ DefaultResolver::visit (AST::Function &function) if (p->is_variadic ()) { auto param = static_cast (p.get ()); - param->get_pattern ()->accept_vis (*this); + if (param->has_pattern ()) + param->get_pattern ()->accept_vis (*this); } else if (p->is_self ()) {