From patchwork Thu Aug 1 14:56: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: 1967755 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=FH8YA6IU; 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 4WZXYn2RYDz1ybV for ; Fri, 2 Aug 2024 01:14:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7F22E386183D for ; Thu, 1 Aug 2024 15:14:19 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by sourceware.org (Postfix) with ESMTPS id 0E9E9385E827 for ; Thu, 1 Aug 2024 14:59:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0E9E9385E827 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 0E9E9385E827 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::532 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524375; cv=none; b=n6q8N9DHBZT3gp0BMoYHJrIbIV/a3wz9mePU4TFIRZvncyMIKKwHkY98tzhG2TYVyXX9UEnXmV34N9Jtt0RiI07tBr2FkTdQXLWFN0NMtLgk9+j+8c7TgJGk2Krvfakz9ySpubQgwOsE0E5HRakJI97Xx1yifeFUij4/MNPzEek= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524375; c=relaxed/simple; bh=VcArT6R+fP5GnJ2bLu7mx9a8jLufcFAAa+yDwxKyWkU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=m2vpnLorxq7uXAdZm73mexWTTVlWT8b5Vxu4ChqwX9LDg8ijOjTmBxQ+EEYMBXHpZ9DX6jgucpnQQAXtuUbKfxMHTi5CLtN+tjRODtMFlUamhlh4ulW7aVf/RMTVN834VkxR+tgcIv4VQrAa4zXKX+XqfQ3hH6sF6aNYlsVTsaU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5a2ffc3447fso9394146a12.1 for ; Thu, 01 Aug 2024 07:59:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1722524344; x=1723129144; 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=ueRlnsJCVm2GCeODtp/P0S9frsjf0v8cBGDcP+n5KWo=; b=FH8YA6IU36XR4oIqYAuYDiJwO5dyFo+IqHH766FiaE5VAN8ME0yWbl5lO4O1cVcMtq di0GU68JbPGjQj9/qEIfQJ/IqA3yQIuVHIQd9+srzpBcfafSuqeRVloymWaawXLDmdgT Tn2wADPCDq8koij3oxyD25TsBvFE+jgMQUEY8sqsUNP4XejSSP7bzcBwPL9meS78gidi 7mymPKwpG9KxJUjAQLs7/Vj8qMFx/l5iLsIm9v+7X/wq+DUog3JTFjPFV527yLt1/6T0 r0vMaM+LnaRJ24A6guzsQVh8/JjxBPjYXHAZEoDhmi2jbHI8Fx/L8pNqgtSEZkvlvbu+ BHgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524344; x=1723129144; 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=ueRlnsJCVm2GCeODtp/P0S9frsjf0v8cBGDcP+n5KWo=; b=IpR2+pO/Rn9wA37dilof6CNQjykoBJDVDiAfyVm4ajuXvik8yYa17P7EtwtBpdhPQs dRfkfNxB6sBTzLyuh59LW3ditzvvq3izuQrCB2NrPD084JPc8XboYNLWQWVJ2DvurFeM upyOExmu+1lMsP1jL4Mz6holv+Cf4nc6IsSi4B1OvmUsn7hDIQtR6ksZ98SqPIohS4tu NKXHAtbzOX+c3GYtXjpEhDEJ8fkDPZNYR/NtgUNtPU50Ry0cn7WS0kB6tLEUqVA3J5KB i8ymQPtsLCUh8/zdhJOdR+3HTr/QLQxF2cwANwxd0y6CjHi6mbxSmJqxf7UBU90jvtNQ oerQ== X-Gm-Message-State: AOJu0YyNZvlyXJoyALR5/EVPHvOxamLqWvI5JUeWf377W0nDYTQP3vnR dK7xU2iLF3uJjI0SyxS9oadBSR7A9dVR3yIGqFgAg2tBxRA9rx+Y5mR3S795lD0NUYjZhbsfPw0 aK4qv X-Google-Smtp-Source: AGHT+IEdgLWLyZAosfIQuM7PB22l0ZK9FitOCTBjJyI7vMaYnU91bumineABT5rF/Wr6SqqVkTssJg== X-Received: by 2002:a50:eac1:0:b0:5a3:b866:eaee with SMTP id 4fb4d7f45d1cf-5b7f36f8a50mr482022a12.7.1722524344225; Thu, 01 Aug 2024 07:59:04 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 07:59:03 -0700 (PDT) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, 0xn4utilus Subject: [PATCH 042/125] gccrs: Remove dead code associated with `AST::ExternalFunctionItem` Date: Thu, 1 Aug 2024 16:56:38 +0200 Message-ID: <20240801145809.366388-44-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: * ast/rust-ast-collector.cc (TokenCollector::visit): Remove dead code. * ast/rust-ast-collector.h: Likewise. * ast/rust-ast-full-decls.h (class ExternalFunctionItem): Likewise. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast-visitor.h: Likewise. * ast/rust-ast.cc (ExternalFunctionItem::as_string): Likewise. (ExternalFunctionItem::accept_vis): Likewise. * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Likewise. * checks/errors/rust-ast-validation.h: Likewise. * checks/errors/rust-feature-gate.h: Likewise. * expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise. * expand/rust-cfg-strip.h: Likewise. * expand/rust-derive.h: Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * expand/rust-expand-visitor.h: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h: Likewise. * metadata/rust-export-metadata.cc (ExportContext::emit_function): Likewise. * parse/rust-parse-impl.h: Likewise. * parse/rust-parse.h: Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-base.h: Likewise. * resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise. * resolve/rust-default-resolver.h: Likewise. * util/rust-attributes.cc (AttributeChecker::visit): Likewise. * util/rust-attributes.h: Likewise. gcc/testsuite/ChangeLog: * rust/compile/extern_func_with_body.rs: New test. Signed-off-by: 0xn4utilus --- gcc/rust/ast/rust-ast-collector.cc | 25 ------- gcc/rust/ast/rust-ast-collector.h | 1 - gcc/rust/ast/rust-ast-full-decls.h | 1 - gcc/rust/ast/rust-ast-visitor.cc | 18 ----- gcc/rust/ast/rust-ast-visitor.h | 2 - gcc/rust/ast/rust-ast.cc | 69 ------------------- gcc/rust/checks/errors/rust-ast-validation.cc | 19 ----- gcc/rust/checks/errors/rust-ast-validation.h | 1 - gcc/rust/checks/errors/rust-feature-gate.h | 1 - gcc/rust/expand/rust-cfg-strip.cc | 56 --------------- gcc/rust/expand/rust-cfg-strip.h | 1 - gcc/rust/expand/rust-derive.h | 1 - gcc/rust/expand/rust-expand-visitor.cc | 17 ----- gcc/rust/expand/rust-expand-visitor.h | 1 - gcc/rust/hir/rust-ast-lower-base.cc | 3 - gcc/rust/hir/rust-ast-lower-base.h | 1 - gcc/rust/metadata/rust-export-metadata.cc | 41 +---------- gcc/rust/parse/rust-parse-impl.h | 62 ----------------- gcc/rust/parse/rust-parse.h | 2 - gcc/rust/resolve/rust-ast-resolve-base.cc | 4 -- gcc/rust/resolve/rust-ast-resolve-base.h | 1 - gcc/rust/resolve/rust-default-resolver.cc | 4 -- gcc/rust/resolve/rust-default-resolver.h | 1 - gcc/rust/util/rust-attributes.cc | 4 -- gcc/rust/util/rust-attributes.h | 1 - .../rust/compile/extern_func_with_body.rs | 5 ++ 26 files changed, 7 insertions(+), 335 deletions(-) create mode 100644 gcc/testsuite/rust/compile/extern_func_with_body.rs diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc index 744d0eb9d28..eb03dccaf84 100644 --- a/gcc/rust/ast/rust-ast-collector.cc +++ b/gcc/rust/ast/rust-ast-collector.cc @@ -2084,31 +2084,6 @@ TokenCollector::visit (ExternalStaticItem &item) push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION)); } -void -TokenCollector::visit (ExternalFunctionItem &function) -{ - visit_items_as_lines (function.get_outer_attrs ()); - visit (function.get_visibility ()); - - auto id = function.get_identifier ().as_string (); - - 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 ()); - push (Rust::Token::make (LEFT_PAREN, UNDEF_LOCATION)); - - visit_items_joined_by_separator (function.get_function_params ()); - - push (Rust::Token::make (RIGHT_PAREN, UNDEF_LOCATION)); - if (function.has_return_type ()) - { - push (Rust::Token::make (RETURN_TYPE, UNDEF_LOCATION)); - visit (function.get_return_type ()); - } - push (Rust::Token::make (SEMICOLON, UNDEF_LOCATION)); -} - void TokenCollector::visit (ExternBlock &block) { diff --git a/gcc/rust/ast/rust-ast-collector.h b/gcc/rust/ast/rust-ast-collector.h index ec695ef5b31..fdc99bb7086 100644 --- a/gcc/rust/ast/rust-ast-collector.h +++ b/gcc/rust/ast/rust-ast-collector.h @@ -333,7 +333,6 @@ public: void visit (TraitImpl &impl); void visit (ExternalTypeItem &item); void visit (ExternalStaticItem &item); - void visit (ExternalFunctionItem &item); void visit (ExternBlock &block); // rust-macro.h diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h index 8d5c8dbc821..dd982c448e0 100644 --- a/gcc/rust/ast/rust-ast-full-decls.h +++ b/gcc/rust/ast/rust-ast-full-decls.h @@ -203,7 +203,6 @@ class ExternalItem; class ExternalTypeItem; class ExternalStaticItem; class NamedFunctionParam; -class ExternalFunctionItem; class ExternBlock; // rust-macro.h diff --git a/gcc/rust/ast/rust-ast-visitor.cc b/gcc/rust/ast/rust-ast-visitor.cc index 697c2726309..de4242afeb5 100644 --- a/gcc/rust/ast/rust-ast-visitor.cc +++ b/gcc/rust/ast/rust-ast-visitor.cc @@ -1004,24 +1004,6 @@ DefaultASTVisitor::visit (AST::NamedFunctionParam ¶m) visit (param.get_type ()); } -void -DefaultASTVisitor::visit (AST::ExternalFunctionItem &item) -{ - visit_outer_attrs (item); - visit (item.get_visibility ()); - for (auto &generic : item.get_generic_params ()) - visit (generic); - - if (item.has_where_clause ()) - visit (item.get_where_clause ()); - - for (auto ¶m : item.get_function_params ()) - visit (param); - - if (item.has_return_type ()) - visit (item.get_return_type ()); -} - void DefaultASTVisitor::visit (AST::ExternBlock &block) { diff --git a/gcc/rust/ast/rust-ast-visitor.h b/gcc/rust/ast/rust-ast-visitor.h index c5c9a025ba6..622e7f766a3 100644 --- a/gcc/rust/ast/rust-ast-visitor.h +++ b/gcc/rust/ast/rust-ast-visitor.h @@ -164,7 +164,6 @@ public: // virtual void visit(ExternalItem& item) = 0; virtual void visit (ExternalTypeItem &type) = 0; virtual void visit (ExternalStaticItem &item) = 0; - virtual void visit (ExternalFunctionItem &item) = 0; virtual void visit (ExternBlock &block) = 0; // rust-macro.h @@ -338,7 +337,6 @@ protected: virtual void visit (AST::TraitImpl &impl) override; virtual void visit (AST::ExternalTypeItem &item) override; virtual void visit (AST::ExternalStaticItem &item) override; - virtual void visit (AST::ExternalFunctionItem &item) override; virtual void visit (AST::ExternBlock &block) override; virtual void visit (AST::MacroMatchFragment &match) override; virtual void visit (AST::MacroMatchRepetition &match) override; diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc index 5d661989904..6eb3394c146 100644 --- a/gcc/rust/ast/rust-ast.cc +++ b/gcc/rust/ast/rust-ast.cc @@ -2974,69 +2974,6 @@ ExternalStaticItem::as_string () const return str; } -std::string -ExternalFunctionItem::as_string () const -{ - // outer attributes - std::string str = append_attributes (outer_attrs, OUTER); - - // start visibility on new line and with a space - str += "\n" + visibility.as_string () + " "; - - str += "fn "; - - // add name - str += item_name.as_string (); - - // generic params - str += "\n Generic params: "; - if (generic_params.empty ()) - { - str += "none"; - } - else - { - for (const auto ¶m : generic_params) - { - // DEBUG: null pointer check - if (param == nullptr) - { - rust_debug ( - "something really terrible has gone wrong - null pointer " - "generic param in external function item."); - return "NULL_POINTER_MARK"; - } - - str += "\n " + param->as_string (); - } - } - - // function params - str += "\n Function params: "; - if (function_params.empty ()) - { - str += "none"; - } - else - { - for (const auto ¶m : function_params) - str += "\n " + param.as_string (); - } - - // add type on new line - str += "\n (return) Type: " - + (has_return_type () ? return_type->as_string () : "()"); - - // where clause - str += "\n Where clause: "; - if (has_where_clause ()) - str += where_clause.as_string (); - else - str += "none"; - - return str; -} - std::string NamedFunctionParam::as_string () const { @@ -4866,12 +4803,6 @@ ExternalStaticItem::accept_vis (ASTVisitor &vis) vis.visit (*this); } -void -ExternalFunctionItem::accept_vis (ASTVisitor &vis) -{ - vis.visit (*this); -} - void ExternBlock::accept_vis (ASTVisitor &vis) { diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index f5a97b0d350..d1edb890ae6 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -64,25 +64,6 @@ ASTValidation::visit (AST::ConstantItem &const_item) AST::ContextualASTVisitor::visit (const_item); } -void -ASTValidation::visit (AST::ExternalFunctionItem &item) -{ - auto ¶ms = item.get_function_params (); - - if (params.size () == 1 && params[0].is_variadic ()) - rust_error_at ( - params[0].get_locus (), - "C-variadic function must be declared with at least one named argument"); - - for (auto it = params.begin (); it != params.end (); it++) - if (it->is_variadic () && it + 1 != params.end ()) - rust_error_at ( - it->get_locus (), - "%<...%> must be the last argument of a C-variadic function"); - - AST::ContextualASTVisitor::visit (item); -} - void ASTValidation::visit (AST::Union &item) { diff --git a/gcc/rust/checks/errors/rust-ast-validation.h b/gcc/rust/checks/errors/rust-ast-validation.h index 641fb26f089..53352c1a64e 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.h +++ b/gcc/rust/checks/errors/rust-ast-validation.h @@ -38,7 +38,6 @@ public: virtual void visit (AST::ConstantItem &const_item); 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/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h index ef7449aa581..481b5a53061 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.h +++ b/gcc/rust/checks/errors/rust-feature-gate.h @@ -130,7 +130,6 @@ public: void visit (AST::Trait &trait) 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; void visit (AST::MacroMatchFragment &match) override {} void visit (AST::MacroMatchRepetition &match) override {} diff --git a/gcc/rust/expand/rust-cfg-strip.cc b/gcc/rust/expand/rust-cfg-strip.cc index 2b51a890247..923015fa05e 100644 --- a/gcc/rust/expand/rust-cfg-strip.cc +++ b/gcc/rust/expand/rust-cfg-strip.cc @@ -2195,62 +2195,6 @@ CfgStrip::visit (AST::ExternalStaticItem &item) rust_error_at (type->get_locus (), "cannot strip type in this position"); } -void -CfgStrip::visit (AST::ExternalFunctionItem &item) -{ - // strip test based on outer attrs - expand_cfg_attrs (item.get_outer_attrs ()); - if (fails_cfg_with_expand (item.get_outer_attrs ())) - { - item.mark_for_strip (); - return; - } - - AST::DefaultASTVisitor::visit (item); - - /* strip function parameters if required - this is specifically - * allowed by spec */ - auto ¶ms = item.get_function_params (); - for (auto it = params.begin (); it != params.end ();) - { - auto ¶m = *it; - - auto ¶m_attrs = param.get_outer_attrs (); - expand_cfg_attrs (param_attrs); - if (fails_cfg_with_expand (param_attrs)) - { - it = params.erase (it); - continue; - } - - if (!param.is_variadic ()) - { - auto &type = param.get_type (); - if (type->is_marked_for_strip ()) - rust_error_at (type->get_locus (), - "cannot strip type in this position"); - } - - // increment if nothing else happens - ++it; - } - /* NOTE: these are extern function params, which may have different - * rules and restrictions to "normal" function params. So expansion - * handled separately. */ - - /* TODO: assuming that variadic nature cannot be stripped. If this - * is not true, then have code here to do so. */ - - if (item.has_return_type ()) - { - auto &return_type = item.get_return_type (); - - if (return_type->is_marked_for_strip ()) - rust_error_at (return_type->get_locus (), - "cannot strip type in this position"); - } -} - void CfgStrip::visit (AST::ExternBlock &block) { diff --git a/gcc/rust/expand/rust-cfg-strip.h b/gcc/rust/expand/rust-cfg-strip.h index a3931823ab1..4a8e6041ff2 100644 --- a/gcc/rust/expand/rust-cfg-strip.h +++ b/gcc/rust/expand/rust-cfg-strip.h @@ -150,7 +150,6 @@ public: 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; // I don't think it would be possible to strip macros without expansion diff --git a/gcc/rust/expand/rust-derive.h b/gcc/rust/expand/rust-derive.h index f953c3decbf..cbe5bbbcbea 100644 --- a/gcc/rust/expand/rust-derive.h +++ b/gcc/rust/expand/rust-derive.h @@ -166,7 +166,6 @@ private: virtual void visit (TraitImpl &impl) override final{}; virtual void visit (ExternalTypeItem &type) override final{}; virtual void visit (ExternalStaticItem &item) override final{}; - virtual void visit (ExternalFunctionItem &item) override final{}; virtual void visit (ExternBlock &block) override final{}; virtual void visit (MacroMatchFragment &match) override final{}; virtual void visit (MacroMatchRepetition &match) override final{}; diff --git a/gcc/rust/expand/rust-expand-visitor.cc b/gcc/rust/expand/rust-expand-visitor.cc index bd49fd91092..6c1efb1d2e0 100644 --- a/gcc/rust/expand/rust-expand-visitor.cc +++ b/gcc/rust/expand/rust-expand-visitor.cc @@ -922,23 +922,6 @@ ExpandVisitor::visit (AST::ExternalStaticItem &static_item) maybe_expand_type (static_item.get_type ()); } -void -ExpandVisitor::visit (AST::ExternalFunctionItem &item) -{ - for (auto ¶m : item.get_generic_params ()) - visit (param); - - for (auto ¶m : item.get_function_params ()) - if (!param.is_variadic ()) - maybe_expand_type (param.get_type ()); - - if (item.has_return_type ()) - maybe_expand_type (item.get_return_type ()); - - if (item.has_where_clause ()) - expand_where_clause (item.get_where_clause ()); -} - void ExpandVisitor::visit (AST::ExternBlock &block) { diff --git a/gcc/rust/expand/rust-expand-visitor.h b/gcc/rust/expand/rust-expand-visitor.h index f40b5773fc1..034aeede2f4 100644 --- a/gcc/rust/expand/rust-expand-visitor.h +++ b/gcc/rust/expand/rust-expand-visitor.h @@ -252,7 +252,6 @@ public: 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; // I don't think it would be possible to strip macros without expansion diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc index 54c05208e7b..ff6ef25a348 100644 --- a/gcc/rust/hir/rust-ast-lower-base.cc +++ b/gcc/rust/hir/rust-ast-lower-base.cc @@ -345,9 +345,6 @@ void ASTLoweringBase::visit (AST::ExternalStaticItem &) {} void -ASTLoweringBase::visit (AST::ExternalFunctionItem &) -{} -void ASTLoweringBase::visit (AST::ExternBlock &) {} diff --git a/gcc/rust/hir/rust-ast-lower-base.h b/gcc/rust/hir/rust-ast-lower-base.h index 7b0ce375f83..c19e9c03b5f 100644 --- a/gcc/rust/hir/rust-ast-lower-base.h +++ b/gcc/rust/hir/rust-ast-lower-base.h @@ -186,7 +186,6 @@ public: // virtual void visit(ExternalItem& item); virtual void visit (AST::ExternalTypeItem &item); virtual void visit (AST::ExternalStaticItem &item); - virtual void visit (AST::ExternalFunctionItem &item); virtual void visit (AST::ExternBlock &block); // rust-macro.h diff --git a/gcc/rust/metadata/rust-export-metadata.cc b/gcc/rust/metadata/rust-export-metadata.cc index a946c67422d..589511ef9ce 100644 --- a/gcc/rust/metadata/rust-export-metadata.cc +++ b/gcc/rust/metadata/rust-export-metadata.cc @@ -93,46 +93,9 @@ ExportContext::emit_function (const HIR::Function &fn) // FIXME assert that this is actually an AST::Function AST::Function &function = static_cast (vis_item); - // we can emit an extern block with abi of "rust" - Identifier item_name = function.get_function_name (); - - // always empty for extern linkage - AST::WhereClause where_clause = AST::WhereClause::create_empty (); - std::vector> generic_params; - - AST::Visibility vis = function.get_visibility (); - std::unique_ptr return_type - = std::unique_ptr (nullptr); - if (function.has_return_type ()) - { - return_type = function.get_return_type ()->clone_type (); - } - - std::vector function_params; - for (auto &p : function.get_function_params ()) - { - if (p->is_variadic () || p->is_self ()) - rust_unreachable (); - auto param = static_cast (p.get ()); - std::string name = param->get_pattern ()->as_string (); - std::unique_ptr param_type - = param->get_type ()->clone_type (); - - AST::NamedFunctionParam np (name, std::move (param_type), {}, - param->get_locus ()); - function_params.push_back (std::move (np)); - } - - AST::ExternalItem *external_item - = new AST::ExternalFunctionItem (item_name, {} /* generic_params */, - std::move (return_type), where_clause, - std::move (function_params), vis, - function.get_outer_attrs (), - function.get_locus ()); - std::vector> external_items; - external_items.push_back ( - std::unique_ptr (external_item)); + external_items.push_back (std::unique_ptr ( + static_cast (&function))); AST::ExternBlock extern_block (get_string_from_abi (Rust::ABI::RUST), std::move (external_items), diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 26b24150f7a..b6c2ca3fc0c 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -6034,68 +6034,6 @@ Parser::parse_named_function_params ( return params; } -template -std::unique_ptr -Parser::parse_external_function_item ( - AST::Visibility vis, AST::AttrVec outer_attrs) -{ - location_t locus = lexer.peek_token ()->get_locus (); - - // parse extern function declaration item - // skip function token - lexer.skip_token (); - - // parse identifier - const_TokenPtr ident_tok = expect_token (IDENTIFIER); - if (ident_tok == nullptr) - { - skip_after_semicolon (); - return nullptr; - } - Identifier ident{ident_tok}; - - // parse (optional) generic params - std::vector> generic_params - = parse_generic_params_in_angles (); - - if (!skip_token (LEFT_PAREN)) - { - skip_after_semicolon (); - return nullptr; - } - - // parse parameters - std::vector function_params - = parse_named_function_params ( - [] (TokenId id) { return id == RIGHT_PAREN; }); - - if (!skip_token (RIGHT_PAREN)) - { - skip_after_semicolon (); - return nullptr; - } - - // parse (optional) return type - std::unique_ptr return_type = parse_function_return_type (); - - // parse (optional) where clause - AST::WhereClause where_clause = parse_where_clause (); - - if (!skip_token (SEMICOLON)) - { - // skip somewhere? - return nullptr; - } - - function_params.shrink_to_fit (); - - return std::unique_ptr ( - new AST::ExternalFunctionItem ( - std::move (ident), std::move (generic_params), std::move (return_type), - std::move (where_clause), std::move (function_params), std::move (vis), - std::move (outer_attrs), locus)); -} - // Parses a single extern block item (static or function declaration). template std::unique_ptr diff --git a/gcc/rust/parse/rust-parse.h b/gcc/rust/parse/rust-parse.h index cdddfa6dff9..c00bf9c7e2e 100644 --- a/gcc/rust/parse/rust-parse.h +++ b/gcc/rust/parse/rust-parse.h @@ -310,8 +310,6 @@ private: AST::Lifetime lifetime_from_token (const_TokenPtr tok); std::unique_ptr parse_external_type_item (AST::Visibility vis, AST::AttrVec outer_attrs); - std::unique_ptr - parse_external_function_item (AST::Visibility vis, AST::AttrVec outer_attrs); AST::NamedFunctionParam parse_named_function_param (); template std::vector diff --git a/gcc/rust/resolve/rust-ast-resolve-base.cc b/gcc/rust/resolve/rust-ast-resolve-base.cc index 5a9f54fc7f1..1ef162d37e0 100644 --- a/gcc/rust/resolve/rust-ast-resolve-base.cc +++ b/gcc/rust/resolve/rust-ast-resolve-base.cc @@ -430,10 +430,6 @@ void ResolverBase::visit (AST::ExternalStaticItem &) {} -void -ResolverBase::visit (AST::ExternalFunctionItem &) -{} - void ResolverBase::visit (AST::ExternBlock &) {} diff --git a/gcc/rust/resolve/rust-ast-resolve-base.h b/gcc/rust/resolve/rust-ast-resolve-base.h index 3b4d28618e4..648243b6fb6 100644 --- a/gcc/rust/resolve/rust-ast-resolve-base.h +++ b/gcc/rust/resolve/rust-ast-resolve-base.h @@ -135,7 +135,6 @@ public: void visit (AST::ExternalTypeItem &); void visit (AST::ExternalStaticItem &); - void visit (AST::ExternalFunctionItem &); void visit (AST::ExternBlock &); void visit (AST::MacroMatchFragment &); diff --git a/gcc/rust/resolve/rust-default-resolver.cc b/gcc/rust/resolve/rust-default-resolver.cc index c99f2f64331..789cc4eef42 100644 --- a/gcc/rust/resolve/rust-default-resolver.cc +++ b/gcc/rust/resolve/rust-default-resolver.cc @@ -492,10 +492,6 @@ void DefaultResolver::visit (AST::ExternalStaticItem &) {} -void -DefaultResolver::visit (AST::ExternalFunctionItem &) -{} - void DefaultResolver::visit (AST::MacroMatchRepetition &) {} diff --git a/gcc/rust/resolve/rust-default-resolver.h b/gcc/rust/resolve/rust-default-resolver.h index 20458ede7bc..97ad6d78be3 100644 --- a/gcc/rust/resolve/rust-default-resolver.h +++ b/gcc/rust/resolve/rust-default-resolver.h @@ -118,7 +118,6 @@ public: void visit (AST::TraitItemType &); void visit (AST::ExternalTypeItem &); void visit (AST::ExternalStaticItem &); - void visit (AST::ExternalFunctionItem &); void visit (AST::MacroMatchRepetition &); void visit (AST::MacroMatcher &); void visit (AST::MacroRulesDefinition &); diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc index 715e9a0b361..eac29808299 100644 --- a/gcc/rust/util/rust-attributes.cc +++ b/gcc/rust/util/rust-attributes.cc @@ -766,10 +766,6 @@ void AttributeChecker::visit (AST::ExternalStaticItem &) {} -void -AttributeChecker::visit (AST::ExternalFunctionItem &) -{} - void AttributeChecker::visit (AST::ExternBlock &block) { diff --git a/gcc/rust/util/rust-attributes.h b/gcc/rust/util/rust-attributes.h index d78ab0b3319..f557b2d46b3 100644 --- a/gcc/rust/util/rust-attributes.h +++ b/gcc/rust/util/rust-attributes.h @@ -199,7 +199,6 @@ private: 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 diff --git a/gcc/testsuite/rust/compile/extern_func_with_body.rs b/gcc/testsuite/rust/compile/extern_func_with_body.rs new file mode 100644 index 00000000000..180c4340c31 --- /dev/null +++ b/gcc/testsuite/rust/compile/extern_func_with_body.rs @@ -0,0 +1,5 @@ +extern "C" { + fn myfun0(a:i32,...) {} + // { dg-error "cannot have a body" "" { target *-*-* } .-1 } +} +