From patchwork Tue Feb 21 12:00:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arthur Cohen X-Patchwork-Id: 59960 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1825509wrn; Tue, 21 Feb 2023 04:09:14 -0800 (PST) X-Google-Smtp-Source: AK7set8PbevG8s0E2cBlucjY6bHpqwtpI9A4YizQ71rmRZjHYL8UQFiBQHKBDQ8MF3+9nKv/2JQr X-Received: by 2002:a17:906:50f:b0:8b1:2ebf:386c with SMTP id j15-20020a170906050f00b008b12ebf386cmr11559674eja.11.1676981354809; Tue, 21 Feb 2023 04:09:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676981354; cv=none; d=google.com; s=arc-20160816; b=uO5T3IKia+2qw0uwLXIw6avsIUe+bVit8Um1teqjQwSK7tRJVm9do1lkqWRrUCZk/B pjn6xtuzcgHVI9cSXQBx43YHr3uWEhEmI9M7XtpF2NtZQQP8653997/6A7Frvu7BhCqz ubWZLjtlypAZbklQtWCJA5PiL6Frv/8Qg/zVYA9xWrPc9pmrxa5291ix8GoBboWdXQM7 cr/2fBFaTpfuF4Q1vo7VZRI693K0SanxymCQJChHTJVAyj/qnlVJwDUfShFnYA4evRSF 6diZuGo1o/l4EuJs1XUP9UTxAvMeTQPEPm4QNW/ut9DsefGXlnP//rw6zPbdJBOeNbHQ UEgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dmarc-filter :delivered-to; bh=4utmg1NwcPV2YkYr1y4pmt6K18H/2biGjSbd2PxHTOo=; b=Q2+sjn9hya3+qwCK0L4blMUh2dS36A2w928AgOyrsSUDB4Re7gkCvnkXTTbVF3rIk9 kDWbdNrCWeJFiPozgXfwYzjhNRPUGF7WV/2Vr0aUkhQcKRKlAnZYfIaIyod+tU631Rbr JDf+pjHV9IbTknk4itVo2o/jrOBwccBGKQgBCZH/IIhGoqCD6cxd+qHHvB2vRVdHjcrJ R7KqjJCdYBUdbKXU0xeWrURujVW7tN9CGXxQqoF/it73RA132d9waqfOax2u1/Fqo25i ozrFrMZU63XSvrXh7Af7hpoPup7k/4uG2fnXZoxnvzzRSIVYBpYCnamRAPtVcqYd+Uix A7jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=TaKPY4aG; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id bp14-20020a170907918e00b008e21a3323d0si716215ejb.673.2023.02.21.04.09.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:09:14 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=TaKPY4aG; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 905BC389838E for ; Tue, 21 Feb 2023 12:05:17 +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 5CE3A384F486 for ; Tue, 21 Feb 2023 12:03:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5CE3A384F486 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wr1-x42c.google.com with SMTP id o4so4163325wrs.4 for ; Tue, 21 Feb 2023 04:03:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; 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=4utmg1NwcPV2YkYr1y4pmt6K18H/2biGjSbd2PxHTOo=; b=TaKPY4aGAMHt/zYIyoKGpUl0pCEU1swWhPsNtPfzp/nXDdWY7ZxeRuCughBAmSemvq C4ZOGRVQ/MIp+8WnQwJPGjU+VZKfFAlUGtn053HlzWwB0xc4rqGGKterNhd+DzSQrvj7 K4m4L7FVTA12n93sEx925NUkSc2Xe0IKjKmR2oOPJ/Q9h1HQAopDAdWuGYw9KblWMdZc G8cM/cRFwT7aZn0cSNYbgB4CGFe6VtwHjFSUQ+7P3GkvYZPzGUPa3drUB0FIzeuIDT9F F0C3E9/23mc+n6ViD7tUngAT8AxXDLmXCJOmn2IwOaNdZvaNLn71gl867GGxGdiKB2JD 5fdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=4utmg1NwcPV2YkYr1y4pmt6K18H/2biGjSbd2PxHTOo=; b=JfTZhmDbr17yO99176o5TtnFNpCcReifBpKiXFCiHv+bgrdFViXpMaaUYBJutVkO7d q4gbtuqdGeh/SJV4or55VceLoWVqGUZQkjY/N0ucov89pWByNtJZqs2jMbzcSRtOTFN2 +HDJo61QdCMxVwjCLVE610XRAsNpRvIHwIQ2p1vdUta51rP2HVAPL8ay9Kmb4im9DPB5 8k0G3QfnfQMp2XxIYHDUGfCPRXhoDPZ97x49MPtPMeo/McToVs2ZJwYf0lODX6wgLr3i mxKSTd0afwkBySf8O+YNNPnFx8VckPB6h9Qws4Bvl2SKbw/ieM2jDLpyElPigB/e+CKn zk3w== X-Gm-Message-State: AO0yUKU1lXYepxB/EJDnSpOuH/4SFamKOJNwQw6wAYaVYRAVwUOnP2pj AecFOjMNDj66AYEDJeHozuqU/IbRIdHHTZNvjQ== X-Received: by 2002:a5d:4105:0:b0:2c5:5eff:5c81 with SMTP id l5-20020a5d4105000000b002c55eff5c81mr3682839wrp.38.1676981011534; Tue, 21 Feb 2023 04:03:31 -0800 (PST) Received: from platypus.localdomain ([62.23.166.218]) by smtp.gmail.com with ESMTPSA id c15-20020adffb4f000000b002c55b0e6ef1sm5013811wrs.4.2023.02.21.04.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 04:03:31 -0800 (PST) From: arthur.cohen@embecosm.com To: gcc-patches@gcc.gnu.org Cc: gcc-rust@gcc.gnu.org, Philip Herron Subject: [committed 009/103] gccrs: Track DefId on ADT variants Date: Tue, 21 Feb 2023 13:00:59 +0100 Message-Id: <20230221120230.596966-10-arthur.cohen@embecosm.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230221120230.596966-1-arthur.cohen@embecosm.com> References: <20230221120230.596966-1-arthur.cohen@embecosm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.4 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=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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: arthur.cohen@embecosm.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758442401272483763?= X-GMAIL-MSGID: =?utf-8?q?1758442401272483763?= From: Philip Herron We must track the DefID on variants for algebraic data types as this will allow us to enforce unique'ness on path queries relating to this. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::visit): Adjust VariantDef ctor calls with DefID. * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Likewise. * typecheck/rust-tyty.h (VariantDef): Add defid parameter to ctor. --- .../typecheck/rust-hir-type-check-enumitem.cc | 4 ++++ .../typecheck/rust-hir-type-check-item.cc | 9 +++++--- gcc/rust/typecheck/rust-tyty.h | 22 ++++++++++--------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc index dd3cb12d17b..30db967f4e0 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc @@ -82,6 +82,7 @@ TypeCheckEnumItem::visit (HIR::EnumItem &item) RustIdent ident{*canonical_path, item.get_locus ()}; variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (), + item.get_mappings ().get_defid (), item.get_identifier (), ident, discim_expr); } @@ -111,6 +112,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemDiscriminant &item) RustIdent ident{*canonical_path, item.get_locus ()}; variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (), + item.get_mappings ().get_defid (), item.get_identifier (), ident, item.get_discriminant_expression ().get ()); } @@ -159,6 +161,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item) RustIdent ident{*canonical_path, item.get_locus ()}; variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (), + item.get_mappings ().get_defid (), item.get_identifier (), ident, TyTy::VariantDef::VariantType::TUPLE, discim_expr, fields); @@ -206,6 +209,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item) RustIdent ident{*canonical_path, item.get_locus ()}; variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (), + item.get_mappings ().get_defid (), item.get_identifier (), ident, TyTy::VariantDef::VariantType::STRUCT, discrim_expr, fields); diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc index e39dd537d6e..af1e39670ce 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-item.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc @@ -125,7 +125,8 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl) // its a single variant ADT std::vector variants; variants.push_back (new TyTy::VariantDef ( - struct_decl.get_mappings ().get_hirid (), struct_decl.get_identifier (), + struct_decl.get_mappings ().get_hirid (), + struct_decl.get_mappings ().get_defid (), struct_decl.get_identifier (), ident, TyTy::VariantDef::VariantType::TUPLE, nullptr, std::move (fields))); // Process #[repr(X)] attribute, if any @@ -179,7 +180,8 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl) // its a single variant ADT std::vector variants; variants.push_back (new TyTy::VariantDef ( - struct_decl.get_mappings ().get_hirid (), struct_decl.get_identifier (), + struct_decl.get_mappings ().get_hirid (), + struct_decl.get_mappings ().get_defid (), struct_decl.get_identifier (), ident, TyTy::VariantDef::VariantType::STRUCT, nullptr, std::move (fields))); // Process #[repr(X)] attribute, if any @@ -273,7 +275,8 @@ TypeCheckItem::visit (HIR::Union &union_decl) // there is only a single variant std::vector variants; variants.push_back (new TyTy::VariantDef ( - union_decl.get_mappings ().get_hirid (), union_decl.get_identifier (), + union_decl.get_mappings ().get_hirid (), + union_decl.get_mappings ().get_defid (), union_decl.get_identifier (), ident, TyTy::VariantDef::VariantType::STRUCT, nullptr, std::move (fields))); TyTy::BaseType *type diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index e3cf4d667c7..a033fcad6c9 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -1063,9 +1063,9 @@ public: return ""; } - VariantDef (HirId id, std::string identifier, RustIdent ident, + VariantDef (HirId id, DefId defid, std::string identifier, RustIdent ident, HIR::Expr *discriminant) - : id (id), identifier (identifier), ident (ident), + : id (id), defid (defid), identifier (identifier), ident (ident), discriminant (discriminant) { @@ -1073,11 +1073,11 @@ public: fields = {}; } - VariantDef (HirId id, std::string identifier, RustIdent ident, + VariantDef (HirId id, DefId defid, std::string identifier, RustIdent ident, VariantType type, HIR::Expr *discriminant, std::vector fields) - : id (id), identifier (identifier), ident (ident), type (type), - discriminant (discriminant), fields (fields) + : id (id), defid (defid), identifier (identifier), ident (ident), + type (type), discriminant (discriminant), fields (fields) { rust_assert ( (type == VariantType::NUM && fields.empty ()) @@ -1085,8 +1085,8 @@ public: } VariantDef (const VariantDef &other) - : id (other.id), identifier (other.identifier), ident (other.ident), - type (other.type), discriminant (other.discriminant), + : id (other.id), defid (other.defid), identifier (other.identifier), + ident (other.ident), type (other.type), discriminant (other.discriminant), fields (other.fields) {} @@ -1105,7 +1105,7 @@ public: static VariantDef &get_error_node () { static VariantDef node - = VariantDef (UNKNOWN_HIRID, "", + = VariantDef (UNKNOWN_HIRID, UNKNOWN_DEFID, "", {Resolver::CanonicalPath::create_empty (), Linemap::unknown_location ()}, nullptr); @@ -1116,6 +1116,7 @@ public: bool is_error () const { return get_id () == UNKNOWN_HIRID; } HirId get_id () const { return id; } + DefId get_defid () const { return defid; } VariantType get_variant_type () const { return type; } bool is_data_variant () const { return type != VariantType::NUM; } @@ -1211,7 +1212,7 @@ public: for (auto &f : fields) cloned_fields.push_back ((StructFieldType *) f->clone ()); - return new VariantDef (id, identifier, ident, type, discriminant, + return new VariantDef (id, defid, identifier, ident, type, discriminant, cloned_fields); } @@ -1221,7 +1222,7 @@ public: for (auto &f : fields) cloned_fields.push_back ((StructFieldType *) f->monomorphized_clone ()); - return new VariantDef (id, identifier, ident, type, discriminant, + return new VariantDef (id, defid, identifier, ident, type, discriminant, cloned_fields); } @@ -1229,6 +1230,7 @@ public: private: HirId id; + DefId defid; std::string identifier; RustIdent ident; VariantType type;