From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id C8C813898C77; Thu, 6 Oct 2022 20:06:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C8C813898C77 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665086778; bh=+/jtcFY4gCfzv/wNxC+C0+Mg/fOMKZ7Uvt8cjDrSaA8=; h=From:To:Subject:Date:From; b=Jbi2ZZWqVhkRtkGIocAdvURmURzv/7R3se/oLfGGHa9wAf4cQrBSiPFMq6cWckb47 lJI57r//xNTEZeQK5tNq52VlN+SOz5DhiRPlRXae6+ZpAPwYR5xoNQmu2IaTigNb9O iebvPp6C2d56yUgmaOMcaTmP4hnuDUnatubHS2cI= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] Track DefId on ADT variants X-Act-Checkin: gcc X-Git-Author: Philip Herron X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: adaf4561d63f08714f8c289bef0f4c5649fb6829 X-Git-Newrev: fc746fd620118f91bb8bfc139c7be3fb2356e820 Message-Id: <20221006200618.C8C813898C77@sourceware.org> Date: Thu, 6 Oct 2022 20:06:18 +0000 (GMT) List-Id: https://gcc.gnu.org/g:fc746fd620118f91bb8bfc139c7be3fb2356e820 commit fc746fd620118f91bb8bfc139c7be3fb2356e820 Author: Philip Herron Date: Wed Oct 5 17:22:43 2022 +0100 Track DefId on ADT variants 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. Diff: --- gcc/rust/typecheck/rust-hir-type-check-enumitem.cc | 4 ++++ gcc/rust/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 59b58a2f109..b695ced34f1 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 ade6ab72053..de994e60dd4 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 cad1a1d01de..acbeb9c441b 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;