From patchwork Thu Aug 1 14:56: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: 1967742 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=MkWiTsno; 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 4WZXTb5y0kz1ydq for ; Fri, 2 Aug 2024 01:10:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 218FD385DDE3 for ; Thu, 1 Aug 2024 15:10:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by sourceware.org (Postfix) with ESMTPS id C4E16385EC2A for ; Thu, 1 Aug 2024 14:58:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C4E16385EC2A 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 C4E16385EC2A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::531 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524346; cv=none; b=tsBZW8A5COINVfI1Zkv5tM4ZNBopQW1ZQge8zLJlgv8t9Dl8EY8TQ5gBoY92CRk3/ZYgfdjJ34bQfVJILJz9OFvrV7v8r5F3tpqvEmQ+b9fnfWUBjswyKGWJ59dTKvoCZ/UhGc4RSsXkYwLPCLqsbeYGbPEPSiC0MYgfycosboY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722524346; c=relaxed/simple; bh=rFvtC2lpEhARi+dHyNGEZbaopIZR5i09SBC82/N3GlQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=m38e73EsnDEwuQ2kKZeGn1Utb22qrJE5YdBPXzAAuFBOl8ddLBAh1aQJnJTEEzoTxgQbCuv07DFNNckmRzt4GSb2WbMHjuM1rxoMS2ZpSE8Ucpf6ytGgQjrLwtJb5BL+daQfsVeihYJ1Hm0LB6CGZ8eRDeaYxmLsmpwrE2Iv0uo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-595856e2336so3666832a12.1 for ; Thu, 01 Aug 2024 07:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1722524331; x=1723129131; 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=I3veqADKNKQzQsY2yxbLCNO7YDPuL5VxVOzeGicvcB4=; b=MkWiTsnoVIQSOiBHKxKB9dyozbGBMC+ug0jEgNioL9KcneS5r8zTkF98DL8EDxOMGM hnYeyXtPQws0lJmT49tnTr+g+CmvesZcSuqmGJpfcOBESeAn+AzcSFXoml3y6WvYc9GL DSo8msdpjbTNkPWU3gw8CfUZOQURQBZRHs0aB9+m7B04KS7QrDNAKeb4F8yCatwZyRR/ aWtCWxtbY+KMZTfSqGg4SmIdllmT1wOgTidf1CFl+nSEVCC0cy3+RlFhw+u0bNlv7ump QNzKSXbpMprL9PT3XxOvFgQIINk2bAusBg2+mEAA5NMQRgxLGhdIXBKMf8ROq2tML5ub +6LQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722524331; x=1723129131; 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=I3veqADKNKQzQsY2yxbLCNO7YDPuL5VxVOzeGicvcB4=; b=e+tv7scD9uabO2pm+aqiucEv4G48LRIeponW9fn5xvZIBRm2Evy4E9HhOe5ZF++IyE xBbx4A5cxVPXZnNUe+WfPBWJjrFqA8Yb44Wjeb0//vjiSLH/RX0H9PVVs4tZChCLJNpq arX8FvGfVkMX0riMER6I/aGrkT+tTBqlJutLyLiJmEOIKajzqFsAcqDh5YCvN615LLq5 T7cuYoah2qtI7uV2g6M5zOe2yDnGFwzryN2QxwK7RNnnTf0U2FYRWvZlyiMVi2kEUB4w 0vB8XW/Cb58cegpRbCykyPEapaq6bCyT3K6M8TokNlOlez4LsUzkawnBjBqScQMr9eUY M/vQ== X-Gm-Message-State: AOJu0Yx1m/VTP3gZcvBcVdnuG8ezji1Ne1FAdBCALaKyCWuKUeU8X3FZ FHA7AZCMAuC9jTfNrz6F/LfSMewSCWB1QoSnUVSsrP9wSYkPftt+HKHEv2xyV/lBEEUIIYqnmnp 8HYXe X-Google-Smtp-Source: AGHT+IH3hJzdxRTrp2JXS7uK/srxCHnp5+8qNi3ySqdTJGQQUabnxJeaVIy+6ac7johe1XlEP7IOjA== X-Received: by 2002:a05:6402:5108:b0:57d:40e3:2a71 with SMTP id 4fb4d7f45d1cf-5b77c28e541mr1448903a12.6.1722524330745; Thu, 01 Aug 2024 07:58:50 -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.58.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Aug 2024 07:58:50 -0700 (PDT) From: Arthur Cohen To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Arthur Cohen Subject: [PATCH 025/125] gccrs: hir: Add ExternalTypeItem node Date: Thu, 1 Aug 2024 16:56:21 +0200 Message-ID: <20240801145809.366388-27-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=-13.9 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_FILL_THIS_FORM_SHORT 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 gcc/rust/ChangeLog: * hir/tree/rust-hir-item.h (class ExternalTypeItem): New class. * hir/tree/rust-hir.cc (ExternalTypeItem::as_string): Likewise. * backend/rust-compile-extern.h: Add base for handling HIR::ExternalTypeItem node. * checks/errors/borrowck/rust-bir-builder-struct.h: Likewise. * checks/errors/borrowck/rust-function-collector.h: Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-const-checker.h: Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.h: Likewise. * hir/rust-ast-lower-extern.h: Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * hir/rust-hir-dump.h: Likewise. * hir/tree/rust-hir-full-decls.h (class ExternalTypeItem): Likewise. * hir/tree/rust-hir-visitor.h: Likewise. (ExternalTypeItem::accept_vis): Likewise. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit): Likewise. * typecheck/rust-hir-type-check-implitem.h: Likewise. --- gcc/rust/backend/rust-compile-extern.h | 7 + .../errors/borrowck/rust-bir-builder-struct.h | 1 + .../errors/borrowck/rust-function-collector.h | 1 + gcc/rust/checks/errors/rust-const-checker.cc | 4 + gcc/rust/checks/errors/rust-const-checker.h | 1 + gcc/rust/checks/errors/rust-unsafe-checker.cc | 4 + gcc/rust/checks/errors/rust-unsafe-checker.h | 1 + gcc/rust/hir/rust-ast-lower-extern.h | 5 + gcc/rust/hir/rust-hir-dump.cc | 10 ++ gcc/rust/hir/rust-hir-dump.h | 1 + gcc/rust/hir/tree/rust-hir-full-decls.h | 1 + gcc/rust/hir/tree/rust-hir-item.h | 39 +++++- gcc/rust/hir/tree/rust-hir-visitor.h | 3 + gcc/rust/hir/tree/rust-hir.cc | 25 ++++ .../typecheck/rust-hir-type-check-implitem.cc | 129 ++++++++++++++++++ .../typecheck/rust-hir-type-check-implitem.h | 1 + 16 files changed, 230 insertions(+), 3 deletions(-) diff --git a/gcc/rust/backend/rust-compile-extern.h b/gcc/rust/backend/rust-compile-extern.h index 778553e5b37..b17ac954167 100644 --- a/gcc/rust/backend/rust-compile-extern.h +++ b/gcc/rust/backend/rust-compile-extern.h @@ -22,6 +22,8 @@ #include "rust-compile-base.h" #include "rust-compile-intrinsic.h" #include "rust-compile-type.h" +#include "rust-diagnostics.h" +#include "rust-hir-full-decls.h" namespace Rust { namespace Compile { @@ -152,6 +154,11 @@ public: reference = address_expression (fndecl, ref_locus); } + void visit (HIR::ExternalTypeItem &type) override + { + rust_sorry_at (type.get_locus (), "extern types are not supported yet"); + } + private: CompileExternItem (Context *ctx, TyTy::BaseType *concrete, location_t ref_locus) diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-struct.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder-struct.h index d6390392d7f..6a990e25c43 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-struct.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-struct.h @@ -189,6 +189,7 @@ protected: void visit (HIR::ImplBlock &impl) override { rust_unreachable (); } void visit (HIR::ExternalStaticItem &item) override { rust_unreachable (); } void visit (HIR::ExternalFunctionItem &item) override { rust_unreachable (); } + void visit (HIR::ExternalTypeItem &item) override { rust_unreachable (); } void visit (HIR::ExternBlock &block) override { rust_unreachable (); } void visit (HIR::LiteralPattern &pattern) override { rust_unreachable (); } void visit (HIR::IdentifierPattern &pattern) override { rust_unreachable (); } diff --git a/gcc/rust/checks/errors/borrowck/rust-function-collector.h b/gcc/rust/checks/errors/borrowck/rust-function-collector.h index b19bfdf855e..18f2f5e11d1 100644 --- a/gcc/rust/checks/errors/borrowck/rust-function-collector.h +++ b/gcc/rust/checks/errors/borrowck/rust-function-collector.h @@ -155,6 +155,7 @@ public: void visit (HIR::ImplBlock &impl) override {} void visit (HIR::ExternalStaticItem &item) override {} void visit (HIR::ExternalFunctionItem &item) override {} + void visit (HIR::ExternalTypeItem &item) override {} void visit (HIR::ExternBlock &block) override {} void visit (HIR::LiteralPattern &pattern) override {} void visit (HIR::IdentifierPattern &pattern) override {} diff --git a/gcc/rust/checks/errors/rust-const-checker.cc b/gcc/rust/checks/errors/rust-const-checker.cc index aaf8fc0c3f6..886ae18d314 100644 --- a/gcc/rust/checks/errors/rust-const-checker.cc +++ b/gcc/rust/checks/errors/rust-const-checker.cc @@ -714,6 +714,10 @@ void ConstChecker::visit (ExternalFunctionItem &) {} +void +ConstChecker::visit (ExternalTypeItem &) +{} + void ConstChecker::visit (ExternBlock &block) { diff --git a/gcc/rust/checks/errors/rust-const-checker.h b/gcc/rust/checks/errors/rust-const-checker.h index a645da8b7c0..a9bf087a993 100644 --- a/gcc/rust/checks/errors/rust-const-checker.h +++ b/gcc/rust/checks/errors/rust-const-checker.h @@ -162,6 +162,7 @@ private: virtual void visit (ImplBlock &impl) override; virtual void visit (ExternalStaticItem &item) override; virtual void visit (ExternalFunctionItem &item) override; + virtual void visit (ExternalTypeItem &item) override; virtual void visit (ExternBlock &block) override; virtual void visit (LiteralPattern &pattern) override; virtual void visit (IdentifierPattern &pattern) override; diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc b/gcc/rust/checks/errors/rust-unsafe-checker.cc index 4bad20b58d3..b8c25f9a592 100644 --- a/gcc/rust/checks/errors/rust-unsafe-checker.cc +++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc @@ -783,6 +783,10 @@ void UnsafeChecker::visit (ExternalFunctionItem &) {} +void +UnsafeChecker::visit (ExternalTypeItem &) +{} + void UnsafeChecker::visit (ExternBlock &block) { diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.h b/gcc/rust/checks/errors/rust-unsafe-checker.h index fee4d62fe43..27659f5141a 100644 --- a/gcc/rust/checks/errors/rust-unsafe-checker.h +++ b/gcc/rust/checks/errors/rust-unsafe-checker.h @@ -144,6 +144,7 @@ private: virtual void visit (ImplBlock &impl) override; virtual void visit (ExternalStaticItem &item) override; virtual void visit (ExternalFunctionItem &item) override; + virtual void visit (ExternalTypeItem &item) override; virtual void visit (ExternBlock &block) override; virtual void visit (LiteralPattern &pattern) override; virtual void visit (IdentifierPattern &pattern) override; diff --git a/gcc/rust/hir/rust-ast-lower-extern.h b/gcc/rust/hir/rust-ast-lower-extern.h index cee480bb9ed..e495b16632d 100644 --- a/gcc/rust/hir/rust-ast-lower-extern.h +++ b/gcc/rust/hir/rust-ast-lower-extern.h @@ -114,6 +114,11 @@ public: function.get_outer_attrs (), function.get_locus ()); } + void visit (AST::ExternalTypeItem &type) override + { + rust_sorry_at (type.get_locus (), "extern types are not implemented yet"); + } + private: ASTLoweringExternItem () : translated (nullptr) {} diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc index 2fdf769c0de..38c2db1d6cd 100644 --- a/gcc/rust/hir/rust-hir-dump.cc +++ b/gcc/rust/hir/rust-hir-dump.cc @@ -1999,6 +1999,16 @@ Dump::visit (ExternalFunctionItem &e) end ("ExternalFunctionItem"); } +void +Dump::visit (ExternalTypeItem &e) +{ + begin ("ExternalTypeItem"); + + do_externalitem (e); + + end ("ExternalTypeItem"); +} + void Dump::visit (ExternBlock &e) { diff --git a/gcc/rust/hir/rust-hir-dump.h b/gcc/rust/hir/rust-hir-dump.h index a48394a4bca..6363eb4c604 100644 --- a/gcc/rust/hir/rust-hir-dump.h +++ b/gcc/rust/hir/rust-hir-dump.h @@ -201,6 +201,7 @@ private: virtual void visit (ExternalStaticItem &) override; virtual void visit (ExternalFunctionItem &) override; + virtual void visit (ExternalTypeItem &) override; virtual void visit (ExternBlock &) override; virtual void visit (LiteralPattern &) override; diff --git a/gcc/rust/hir/tree/rust-hir-full-decls.h b/gcc/rust/hir/tree/rust-hir-full-decls.h index 96293ce8314..d01535e75d3 100644 --- a/gcc/rust/hir/tree/rust-hir-full-decls.h +++ b/gcc/rust/hir/tree/rust-hir-full-decls.h @@ -177,6 +177,7 @@ class ExternalItem; class ExternalStaticItem; struct NamedFunctionParam; class ExternalFunctionItem; +class ExternalTypeItem; class ExternBlock; // rust-pattern.h diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h index 1d067fca5be..40093a2ad93 100644 --- a/gcc/rust/hir/tree/rust-hir-item.h +++ b/gcc/rust/hir/tree/rust-hir-item.h @@ -2859,6 +2859,7 @@ public: { Static, Function, + Type, }; virtual ~ExternalItem () {} @@ -3084,11 +3085,13 @@ public: // Copy constructor with clone ExternalFunctionItem (ExternalFunctionItem const &other) - : ExternalItem (other), return_type (other.return_type->clone_type ()), - where_clause (other.where_clause), + : ExternalItem (other), where_clause (other.where_clause), function_params (other.function_params), has_variadics (other.has_variadics) { + if (other.return_type) + return_type = other.return_type->clone_type (); + generic_params.reserve (other.generic_params.size ()); for (const auto &e : other.generic_params) generic_params.push_back (e->clone_generic_param ()); @@ -3098,11 +3101,14 @@ public: ExternalFunctionItem &operator= (ExternalFunctionItem const &other) { ExternalItem::operator= (other); - return_type = other.return_type->clone_type (); + where_clause = other.where_clause; function_params = other.function_params; has_variadics = other.has_variadics; + if (other.return_type) + return_type = other.return_type->clone_type (); + generic_params.reserve (other.generic_params.size ()); for (const auto &e : other.generic_params) generic_params.push_back (e->clone_generic_param ()); @@ -3144,6 +3150,33 @@ protected: } }; +class ExternalTypeItem : public ExternalItem +{ + ExternalTypeItem (Analysis::NodeMapping mappings, Identifier item_name, + Visibility vis, AST::AttrVec outer_attrs, location_t locus) + : ExternalItem (std::move (mappings), std::move (item_name), + std::move (vis), std::move (outer_attrs), locus) + {} + + ExternalTypeItem (ExternalTypeItem const &other) : ExternalItem (other) {} + + ExternalTypeItem (ExternalTypeItem &&other) = default; + ExternalTypeItem &operator= (ExternalTypeItem &&other) = default; + + std::string as_string () const override; + + void accept_vis (HIRFullVisitor &vis) override; + void accept_vis (HIRExternalItemVisitor &vis) override; + + ExternKind get_extern_kind () override { return ExternKind::Type; } + +protected: + ExternalTypeItem *clone_external_item_impl () const override + { + return new ExternalTypeItem (*this); + } +}; + // An extern block HIR node class ExternBlock : public VisItem, public WithInnerAttrs { diff --git a/gcc/rust/hir/tree/rust-hir-visitor.h b/gcc/rust/hir/tree/rust-hir-visitor.h index 4e7a97bd972..ae9d23f2e00 100644 --- a/gcc/rust/hir/tree/rust-hir-visitor.h +++ b/gcc/rust/hir/tree/rust-hir-visitor.h @@ -114,6 +114,7 @@ public: virtual void visit (ImplBlock &impl) = 0; virtual void visit (ExternalStaticItem &item) = 0; virtual void visit (ExternalFunctionItem &item) = 0; + virtual void visit (ExternalTypeItem &item) = 0; virtual void visit (ExternBlock &block) = 0; virtual void visit (LiteralPattern &pattern) = 0; virtual void visit (IdentifierPattern &pattern) = 0; @@ -255,6 +256,7 @@ public: virtual void visit (ExternalStaticItem &) override {} virtual void visit (ExternalFunctionItem &) override {} + virtual void visit (ExternalTypeItem &) override {} virtual void visit (ExternBlock &) override {} virtual void visit (LiteralPattern &) override {} @@ -306,6 +308,7 @@ class HIRExternalItemVisitor public: virtual void visit (ExternalStaticItem &item) = 0; virtual void visit (ExternalFunctionItem &item) = 0; + virtual void visit (ExternalTypeItem &item) = 0; }; class HIRTraitItemVisitor diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc index fb0a9c388ae..3eb8838eb9d 100644 --- a/gcc/rust/hir/tree/rust-hir.cc +++ b/gcc/rust/hir/tree/rust-hir.cc @@ -3256,6 +3256,19 @@ ExternalFunctionItem::as_string () const return str; } +std::string +ExternalTypeItem::as_string () const +{ + std::string str = ExternalItem::as_string (); + + str += "type "; + + // add name + str += get_item_name ().as_string (); + + return str; +} + std::string NamedFunctionParam::as_string () const { @@ -4272,6 +4285,12 @@ ExternalFunctionItem::accept_vis (HIRFullVisitor &vis) vis.visit (*this); } +void +ExternalTypeItem::accept_vis (HIRFullVisitor &vis) +{ + vis.visit (*this); +} + void ExternBlock::accept_vis (HIRFullVisitor &vis) { @@ -4542,6 +4561,12 @@ ExternalFunctionItem::accept_vis (HIRExternalItemVisitor &vis) vis.visit (*this); } +void +ExternalTypeItem::accept_vis (HIRExternalItemVisitor &vis) +{ + vis.visit (*this); +} + void ExternalStaticItem::accept_vis (HIRExternalItemVisitor &vis) { diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc index 6b4141a4270..8a9a3f35a32 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc @@ -17,6 +17,7 @@ // . #include "rust-hir-type-check-implitem.h" +#include "rust-diagnostics.h" #include "rust-hir-type-check-base.h" #include "rust-hir-type-check-type.h" #include "rust-hir-type-check-expr.h" @@ -183,6 +184,134 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function) resolved = fnType; } +void +TypeCheckTopLevelExternItem::visit (HIR::ExternalTypeItem &type) +{ + rust_sorry_at (type.get_locus (), "extern types are not supported yet"); + // auto binder_pin = context->push_clean_lifetime_resolver (); + + // std::vector substitutions; + // if (function.has_generics ()) + // { + // for (auto &generic_param : function.get_generic_params ()) + // { + // switch (generic_param.get ()->get_kind ()) + // { + // case HIR::GenericParam::GenericKind::LIFETIME: + // context->intern_and_insert_lifetime ( + // static_cast (*generic_param) + // .get_lifetime ()); + // // TODO: handle bounds + // break; + // case HIR::GenericParam::GenericKind::CONST: + // // FIXME: Skipping Lifetime and Const completely until better + // // handling. + // break; + + // case HIR::GenericParam::GenericKind::TYPE: { + // auto param_type + // = TypeResolveGenericParam::Resolve (generic_param.get ()); + // context->insert_type (generic_param->get_mappings (), + // param_type); + + // substitutions.push_back (TyTy::SubstitutionParamMapping ( + // static_cast (*generic_param), param_type)); + // } + // break; + // } + // } + // } + + // TyTy::RegionConstraints region_constraints; + // if (function.has_where_clause ()) + // { + // for (auto &where_clause_item : function.get_where_clause ().get_items + // ()) + // { + // ResolveWhereClauseItem::Resolve (*where_clause_item.get (), + // region_constraints); + // } + // } + + // TyTy::BaseType *ret_type = nullptr; + // if (!function.has_return_type ()) + // ret_type + // = TyTy::TupleType::get_unit_type (function.get_mappings ().get_hirid + // ()); + // else + // { + // auto resolved + // = TypeCheckType::Resolve (function.get_return_type ().get ()); + // if (resolved == nullptr) + // { + // rust_error_at (function.get_locus (), + // "failed to resolve return type"); + // return; + // } + + // ret_type = resolved->clone (); + // ret_type->set_ref ( + // function.get_return_type ()->get_mappings ().get_hirid ()); + // } + + // std::vector > params; + // for (auto ¶m : function.get_function_params ()) + // { + // // get the name as well required for later on + // auto param_tyty = TypeCheckType::Resolve (param.get_type ().get ()); + + // // these are implicit mappings and not used + // auto crate_num = mappings->get_current_crate (); + // Analysis::NodeMapping mapping (crate_num, mappings->get_next_node_id + // (), + // mappings->get_next_hir_id (crate_num), + // UNKNOWN_LOCAL_DEFID); + + // HIR::IdentifierPattern *param_pattern + // = new HIR::IdentifierPattern (mapping, param.get_param_name (), + // UNDEF_LOCATION, false, Mutability::Imm, + // std::unique_ptr (nullptr)); + + // params.push_back ( + // std::pair (param_pattern, + // param_tyty)); + + // context->insert_type (param.get_mappings (), param_tyty); + + // // FIXME do we need error checking for patterns here? + // // see https://github.com/Rust-GCC/gccrs/issues/995 + // } + + // uint8_t flags = TyTy::FnType::FNTYPE_IS_EXTERN_FLAG; + // if (function.is_variadic ()) + // { + // flags |= TyTy::FnType::FNTYPE_IS_VARADIC_FLAG; + // if (parent.get_abi () != Rust::ABI::C) + // { + // rust_error_at ( + // function.get_locus (), ErrorCode::E0045, + // "C-variadic function must have C or cdecl calling convention"); + // } + // } + + // RustIdent ident{ + // CanonicalPath::new_seg (function.get_mappings ().get_nodeid (), + // function.get_item_name ().as_string ()), + // function.get_locus ()}; + + // auto fnType = new TyTy::FnType ( + // function.get_mappings ().get_hirid (), + // function.get_mappings ().get_defid (), + // function.get_item_name ().as_string (), ident, flags, parent.get_abi (), + // std::move (params), ret_type, std::move (substitutions), + // TyTy::SubstitutionArgumentMappings::empty ( + // context->get_lifetime_resolver ().get_num_bound_regions ()), + // region_constraints); + + // context->insert_type (function.get_mappings (), fnType); + // resolved = fnType; +} + TypeCheckImplItem::TypeCheckImplItem ( HIR::ImplBlock *parent, TyTy::BaseType *self, std::vector substitutions) diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.h b/gcc/rust/typecheck/rust-hir-type-check-implitem.h index 541b7280c1b..64eb208d15d 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-implitem.h +++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.h @@ -34,6 +34,7 @@ public: void visit (HIR::ExternalStaticItem &item) override; void visit (HIR::ExternalFunctionItem &function) override; + void visit (HIR::ExternalTypeItem &type) override; private: TypeCheckTopLevelExternItem (const HIR::ExternBlock &parent);