From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 1529E384DD1A for ; Tue, 21 Feb 2023 12:03:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1529E384DD1A 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 j2so3981193wrh.9 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=lhjIKPH6CQosVWGimq4b5CICTPNcYIjKgwwgFDGrV4aPUuzZEZzchEAnIOtH5FiXaM 9nbLxdV0ZHm5AnZiwFch1ESuhfgWXbILd65c0Ino0abQ9P3XPoMX/x1wVOrIGmFXJW9R UWIcQUBsw/JsX1IKj8w+RL+h40BZmpbSD/FkU7R3Pc/ZBR5wocsUGjiJGQbTyK1VbMHy WvMDpkJkW3Fm95tU16ig4gWjuvXY++kNVor33ZCgx1h5Y4tjzSDk4ceawmCX5sgmNyZO rpuvt6+urW4jpzniPUA+PMmtSeqZz5rJ7aKq6L5iYGiTSUG3D3qVVbs2YHZWHjJIpj7w HCCg== X-Gm-Message-State: AO0yUKVcwBfZBu9+zBCt/5uhmgYUye02Xk1fHx5A5/Rwh65+tiNQEJto BvrIkPCZYVq334uwpDqIjYlj X-Google-Smtp-Source: AK7set8jID17iSV2sdHVax/Hn5aGg7OS254HCkQRQ6Kg0HVyP1nhIT4TPCAbb/E2IVN5ciNkz1pp4w== 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> Reply-To: arthur.cohen@embecosm.com MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.9 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 List-Id: 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; -- 2.39.1