Skip to content

Commit aa88863

Browse files
committed
gccrs: track DefId on ADT Types this could be useful information
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): track DefId of origin * typecheck/rust-tyty.cc (BaseType::monomorphized_clone): likewise (ADTType::ADTType): likewise (ADTType::get_id): likewise (ADTType::clone): likewise * typecheck/rust-tyty.h: likewise Signed-off-by: Philip Herron <[email protected]>
1 parent d93efa7 commit aa88863

File tree

3 files changed

+65
-29
lines changed

3 files changed

+65
-29
lines changed

gcc/rust/typecheck/rust-hir-type-check-item.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl)
232232
= parse_repr_options (attrs, struct_decl.get_locus ());
233233

234234
auto *type = new TyTy::ADTType (
235+
struct_decl.get_mappings ().get_defid (),
235236
struct_decl.get_mappings ().get_hirid (),
236237
struct_decl.get_mappings ().get_hirid (),
237238
struct_decl.get_identifier ().as_string (), ident,
@@ -314,6 +315,7 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl)
314315
= parse_repr_options (attrs, struct_decl.get_locus ());
315316

316317
auto *type = new TyTy::ADTType (
318+
struct_decl.get_mappings ().get_defid (),
317319
struct_decl.get_mappings ().get_hirid (),
318320
struct_decl.get_mappings ().get_hirid (),
319321
struct_decl.get_identifier ().as_string (), ident,
@@ -376,7 +378,8 @@ TypeCheckItem::visit (HIR::Enum &enum_decl)
376378

377379
// multi variant ADT
378380
auto *type
379-
= new TyTy::ADTType (enum_decl.get_mappings ().get_hirid (),
381+
= new TyTy::ADTType (enum_decl.get_mappings ().get_defid (),
382+
enum_decl.get_mappings ().get_hirid (),
380383
enum_decl.get_mappings ().get_hirid (),
381384
enum_decl.get_identifier ().as_string (), ident,
382385
TyTy::ADTType::ADTKind::ENUM, std::move (variants),
@@ -447,7 +450,8 @@ TypeCheckItem::visit (HIR::Union &union_decl)
447450
std::move (fields)));
448451

449452
auto *type
450-
= new TyTy::ADTType (union_decl.get_mappings ().get_hirid (),
453+
= new TyTy::ADTType (union_decl.get_mappings ().get_defid (),
454+
union_decl.get_mappings ().get_hirid (),
451455
union_decl.get_mappings ().get_hirid (),
452456
union_decl.get_identifier ().as_string (), ident,
453457
TyTy::ADTType::ADTKind::UNION, std::move (variants),

gcc/rust/typecheck/rust-tyty.cc

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ BaseType::monomorphized_clone () const
638638
for (auto &variant : adt->get_variants ())
639639
cloned_variants.push_back (variant->monomorphized_clone ());
640640

641-
return new ADTType (adt->get_ref (), adt->get_ty_ref (),
641+
return new ADTType (adt->get_id (), adt->get_ref (), adt->get_ty_ref (),
642642
adt->get_identifier (), adt->ident,
643643
adt->get_adt_kind (), cloned_variants,
644644
adt->clone_substs (), adt->get_repr_options (),
@@ -1621,6 +1621,43 @@ VariantDef::get_ident () const
16211621

16221622
// ADTType
16231623

1624+
ADTType::ADTType (DefId id, HirId ref, std::string identifier, RustIdent ident,
1625+
ADTKind adt_kind, std::vector<VariantDef *> variants,
1626+
std::vector<SubstitutionParamMapping> subst_refs,
1627+
SubstitutionArgumentMappings generic_arguments,
1628+
RegionConstraints region_constraints, std::set<HirId> refs)
1629+
: BaseType (ref, ref, TypeKind::ADT, ident, refs),
1630+
SubstitutionRef (std::move (subst_refs), std::move (generic_arguments),
1631+
region_constraints),
1632+
id (id), identifier (identifier), variants (variants), adt_kind (adt_kind)
1633+
{}
1634+
1635+
ADTType::ADTType (DefId id, HirId ref, HirId ty_ref, std::string identifier,
1636+
RustIdent ident, ADTKind adt_kind,
1637+
std::vector<VariantDef *> variants,
1638+
std::vector<SubstitutionParamMapping> subst_refs,
1639+
SubstitutionArgumentMappings generic_arguments,
1640+
RegionConstraints region_constraints, std::set<HirId> refs)
1641+
: BaseType (ref, ty_ref, TypeKind::ADT, ident, refs),
1642+
SubstitutionRef (std::move (subst_refs), std::move (generic_arguments),
1643+
region_constraints),
1644+
id (id), identifier (identifier), variants (variants), adt_kind (adt_kind)
1645+
{}
1646+
1647+
ADTType::ADTType (DefId id, HirId ref, HirId ty_ref, std::string identifier,
1648+
RustIdent ident, ADTKind adt_kind,
1649+
std::vector<VariantDef *> variants,
1650+
std::vector<SubstitutionParamMapping> subst_refs,
1651+
ReprOptions repr,
1652+
SubstitutionArgumentMappings generic_arguments,
1653+
RegionConstraints region_constraints, std::set<HirId> refs)
1654+
: BaseType (ref, ty_ref, TypeKind::ADT, ident, refs),
1655+
SubstitutionRef (std::move (subst_refs), std::move (generic_arguments),
1656+
region_constraints),
1657+
id (id), identifier (identifier), variants (variants), adt_kind (adt_kind),
1658+
repr (repr)
1659+
{}
1660+
16241661
void
16251662
ADTType::accept_vis (TyVisitor &vis)
16261663
{
@@ -1702,14 +1739,20 @@ ADTType::is_equal (const BaseType &other) const
17021739
return true;
17031740
}
17041741

1742+
DefId
1743+
ADTType::get_id () const
1744+
{
1745+
return id;
1746+
}
1747+
17051748
BaseType *
17061749
ADTType::clone () const
17071750
{
17081751
std::vector<VariantDef *> cloned_variants;
17091752
for (auto &variant : variants)
17101753
cloned_variants.push_back (variant->clone ());
17111754

1712-
return new ADTType (get_ref (), get_ty_ref (), identifier, ident,
1755+
return new ADTType (get_id (), get_ref (), get_ty_ref (), identifier, ident,
17131756
get_adt_kind (), cloned_variants, clone_substs (),
17141757
get_repr_options (), used_arguments,
17151758
get_region_constraints (), get_combined_refs ());

gcc/rust/typecheck/rust-tyty.h

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -686,45 +686,31 @@ class ADTType : public BaseType, public SubstitutionRef
686686
BaseType *repr = nullptr;
687687
};
688688

689-
ADTType (HirId ref, std::string identifier, RustIdent ident, ADTKind adt_kind,
690-
std::vector<VariantDef *> variants,
689+
ADTType (DefId id, HirId ref, std::string identifier, RustIdent ident,
690+
ADTKind adt_kind, std::vector<VariantDef *> variants,
691691
std::vector<SubstitutionParamMapping> subst_refs,
692692
SubstitutionArgumentMappings generic_arguments
693693
= SubstitutionArgumentMappings::error (),
694694
RegionConstraints region_constraints = RegionConstraints{},
695-
std::set<HirId> refs = std::set<HirId> ())
696-
: BaseType (ref, ref, TypeKind::ADT, ident, refs),
697-
SubstitutionRef (std::move (subst_refs), std::move (generic_arguments),
698-
region_constraints),
699-
identifier (identifier), variants (variants), adt_kind (adt_kind)
700-
{}
695+
std::set<HirId> refs = std::set<HirId> ());
701696

702-
ADTType (HirId ref, HirId ty_ref, std::string identifier, RustIdent ident,
703-
ADTKind adt_kind, std::vector<VariantDef *> variants,
697+
ADTType (DefId id, HirId ref, HirId ty_ref, std::string identifier,
698+
RustIdent ident, ADTKind adt_kind,
699+
std::vector<VariantDef *> variants,
704700
std::vector<SubstitutionParamMapping> subst_refs,
705701
SubstitutionArgumentMappings generic_arguments
706702
= SubstitutionArgumentMappings::error (),
707703
RegionConstraints region_constraints = RegionConstraints{},
708-
std::set<HirId> refs = std::set<HirId> ())
709-
: BaseType (ref, ty_ref, TypeKind::ADT, ident, refs),
710-
SubstitutionRef (std::move (subst_refs), std::move (generic_arguments),
711-
region_constraints),
712-
identifier (identifier), variants (variants), adt_kind (adt_kind)
713-
{}
704+
std::set<HirId> refs = std::set<HirId> ());
714705

715-
ADTType (HirId ref, HirId ty_ref, std::string identifier, RustIdent ident,
716-
ADTKind adt_kind, std::vector<VariantDef *> variants,
706+
ADTType (DefId id, HirId ref, HirId ty_ref, std::string identifier,
707+
RustIdent ident, ADTKind adt_kind,
708+
std::vector<VariantDef *> variants,
717709
std::vector<SubstitutionParamMapping> subst_refs, ReprOptions repr,
718710
SubstitutionArgumentMappings generic_arguments
719711
= SubstitutionArgumentMappings::error (),
720712
RegionConstraints region_constraints = RegionConstraints{},
721-
std::set<HirId> refs = std::set<HirId> ())
722-
: BaseType (ref, ty_ref, TypeKind::ADT, ident, refs),
723-
SubstitutionRef (std::move (subst_refs), std::move (generic_arguments),
724-
region_constraints),
725-
identifier (identifier), variants (variants), adt_kind (adt_kind),
726-
repr (repr)
727-
{}
713+
std::set<HirId> refs = std::set<HirId> ());
728714

729715
ADTKind get_adt_kind () const { return adt_kind; }
730716

@@ -755,6 +741,8 @@ class ADTType : public BaseType, public SubstitutionRef
755741
return identifier + subst_as_string ();
756742
}
757743

744+
DefId get_id () const;
745+
758746
BaseType *clone () const final override;
759747

760748
size_t number_of_variants () const { return variants.size (); }
@@ -800,6 +788,7 @@ class ADTType : public BaseType, public SubstitutionRef
800788
handle_substitions (SubstitutionArgumentMappings &mappings) override final;
801789

802790
private:
791+
DefId id;
803792
std::string identifier;
804793
std::vector<VariantDef *> variants;
805794
ADTType::ADTKind adt_kind;

0 commit comments

Comments
 (0)