From 73ac7c5a1eca2db1c95ae5b7c3ee9f206ce9aa9d Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Thu, 15 Jul 2021 11:12:57 +0100 Subject: Impl items should have a DefID This adds DefId mappings for impl items, this is a building block where the TyTy::FnType will include the DefId of the respective function, which will simplify the backend a bit in relation to optional trait functions with a body. --- gcc/rust/hir/rust-ast-lower-implitem.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'gcc') diff --git a/gcc/rust/hir/rust-ast-lower-implitem.h b/gcc/rust/hir/rust-ast-lower-implitem.h index b08a166..9fa65a5 100644 --- a/gcc/rust/hir/rust-ast-lower-implitem.h +++ b/gcc/rust/hir/rust-ast-lower-implitem.h @@ -70,13 +70,14 @@ public: mappings->get_next_hir_id (crate_num), mappings->get_next_localdef_id (crate_num)); - translated = new HIR::TypeAlias (mapping, alias.get_new_type_name (), - std::move (generic_params), - std::move (where_clause), - std::unique_ptr (existing_type), - std::move (vis), alias.get_outer_attrs (), - alias.get_locus ()); + auto type_alias = new HIR::TypeAlias ( + mapping, alias.get_new_type_name (), std::move (generic_params), + std::move (where_clause), std::unique_ptr (existing_type), + std::move (vis), alias.get_outer_attrs (), alias.get_locus ()); + translated = type_alias; + + mappings->insert_defid_mapping (mapping.get_defid (), type_alias); mappings->insert_hir_implitem (mapping.get_crate_num (), mapping.get_hirid (), parent_impl_id, translated); @@ -104,6 +105,7 @@ public: constant.get_locus ()); translated = translated_constant; + mappings->insert_defid_mapping (mapping.get_defid (), translated_constant); mappings->insert_hir_implitem (mapping.get_crate_num (), mapping.get_hirid (), parent_impl_id, translated); @@ -177,6 +179,7 @@ public: std::move (vis), function.get_outer_attrs (), HIR::SelfParam::error (), locus); + mappings->insert_defid_mapping (mapping.get_defid (), fn); mappings->insert_hir_implitem (mapping.get_crate_num (), mapping.get_hirid (), parent_impl_id, fn); mappings->insert_location (crate_num, mapping.get_hirid (), @@ -257,6 +260,7 @@ public: std::move (vis), method.get_outer_attrs (), std::move (self_param), locus); + mappings->insert_defid_mapping (mapping.get_defid (), mth); mappings->insert_hir_implitem (mapping.get_crate_num (), mapping.get_hirid (), parent_impl_id, mth); mappings->insert_location (crate_num, mapping.get_hirid (), -- cgit v1.1 From ea04a9ff1d0ed60332298ee07d94c1c73384b21f Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Thu, 15 Jul 2021 13:47:24 +0100 Subject: Add DefId mappings to TyTy::FnType This adds the def id to trait items and nested items, this will help with optional trait item compilation. --- gcc/rust/hir/rust-ast-lower-implitem.h | 8 ++++---- gcc/rust/hir/rust-ast-lower-stmt.h | 2 +- gcc/rust/typecheck/rust-hir-type-check-implitem.h | 1 + gcc/rust/typecheck/rust-hir-type-check-stmt.h | 1 + gcc/rust/typecheck/rust-hir-type-check-toplevel.h | 1 + gcc/rust/typecheck/rust-hir-type-check.cc | 1 + gcc/rust/typecheck/rust-tyty.cc | 2 +- gcc/rust/typecheck/rust-tyty.h | 22 ++++++++++++++++------ 8 files changed, 26 insertions(+), 12 deletions(-) (limited to 'gcc') diff --git a/gcc/rust/hir/rust-ast-lower-implitem.h b/gcc/rust/hir/rust-ast-lower-implitem.h index 9fa65a5..6e4c0b1 100644 --- a/gcc/rust/hir/rust-ast-lower-implitem.h +++ b/gcc/rust/hir/rust-ast-lower-implitem.h @@ -362,7 +362,7 @@ public: auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, func.get_node_id (), mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); + mappings->get_next_localdef_id (crate_num)); translated = new HIR::TraitItemFunc (mapping, std::move (decl), @@ -426,7 +426,7 @@ public: auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, method.get_node_id (), mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); + mappings->get_next_localdef_id (crate_num)); translated = new HIR::TraitItemFunc (mapping, std::move (decl), @@ -445,7 +445,7 @@ public: auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, constant.get_node_id (), mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); + mappings->get_next_localdef_id (crate_num)); translated = new HIR::TraitItemConst (mapping, constant.get_identifier (), std::unique_ptr (type), @@ -461,7 +461,7 @@ public: auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, type.get_node_id (), mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); + mappings->get_next_localdef_id (crate_num)); translated = new HIR::TraitItemType (mapping, type.get_identifier (), diff --git a/gcc/rust/hir/rust-ast-lower-stmt.h b/gcc/rust/hir/rust-ast-lower-stmt.h index 771c3ad..9df6b74 100644 --- a/gcc/rust/hir/rust-ast-lower-stmt.h +++ b/gcc/rust/hir/rust-ast-lower-stmt.h @@ -283,7 +283,7 @@ public: auto crate_num = mappings->get_current_crate (); Analysis::NodeMapping mapping (crate_num, function.get_node_id (), mappings->get_next_hir_id (crate_num), - UNKNOWN_LOCAL_DEFID); + mappings->get_next_localdef_id (crate_num)); mappings->insert_location (crate_num, function_body->get_mappings ().get_hirid (), diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.h b/gcc/rust/typecheck/rust-hir-type-check-implitem.h index d6c3aed..5f6fcd9 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-implitem.h +++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.h @@ -135,6 +135,7 @@ public: } auto fnType = new TyTy::FnType (function.get_mappings ().get_hirid (), + function.get_mappings ().get_defid (), function.get_function_name (), function.is_method (), std::move (params), ret_type, std::move (substitutions)); diff --git a/gcc/rust/typecheck/rust-hir-type-check-stmt.h b/gcc/rust/typecheck/rust-hir-type-check-stmt.h index 3655d96..ba821ca 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-stmt.h +++ b/gcc/rust/typecheck/rust-hir-type-check-stmt.h @@ -276,6 +276,7 @@ public: } auto fnType = new TyTy::FnType (function.get_mappings ().get_hirid (), + function.get_mappings ().get_defid (), function.get_function_name (), false, std::move (params), ret_type, std::move (substitutions)); diff --git a/gcc/rust/typecheck/rust-hir-type-check-toplevel.h b/gcc/rust/typecheck/rust-hir-type-check-toplevel.h index 45bf6f3..dd3dd75 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-toplevel.h +++ b/gcc/rust/typecheck/rust-hir-type-check-toplevel.h @@ -229,6 +229,7 @@ public: } auto fnType = new TyTy::FnType (function.get_mappings ().get_hirid (), + function.get_mappings ().get_defid (), function.get_function_name (), false, std::move (params), ret_type, std::move (substitutions)); diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc b/gcc/rust/typecheck/rust-hir-type-check.cc index acfc022..cb2896c 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.cc +++ b/gcc/rust/typecheck/rust-hir-type-check.cc @@ -498,6 +498,7 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const } return new TyTy::FnType (fn.get_mappings ().get_hirid (), + fn.get_mappings ().get_defid (), function.get_function_name (), function.is_method (), std::move (params), ret_type, substitutions); } diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc index ba98212..ab47310 100644 --- a/gcc/rust/typecheck/rust-tyty.cc +++ b/gcc/rust/typecheck/rust-tyty.cc @@ -715,7 +715,7 @@ FnType::clone () cloned_params.push_back ( std::pair (p.first, p.second->clone ())); - return new FnType (get_ref (), get_ty_ref (), get_identifier (), + return new FnType (get_ref (), get_ty_ref (), get_id (), get_identifier (), is_method_flag, std::move (cloned_params), get_return_type ()->clone (), clone_substs (), get_combined_refs ()); diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h index d85b8a8..e2f1595 100644 --- a/gcc/rust/typecheck/rust-tyty.h +++ b/gcc/rust/typecheck/rust-tyty.h @@ -929,7 +929,7 @@ private: class FnType : public BaseType, public SubstitutionRef { public: - FnType (HirId ref, std::string identifier, bool is_method, + FnType (HirId ref, DefId id, std::string identifier, bool is_method, std::vector > params, BaseType *type, std::vector subst_refs, std::set refs = std::set ()) @@ -937,10 +937,14 @@ public: SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), params (std::move (params)), type (type), is_method_flag (is_method), - identifier (identifier) - {} + identifier (identifier), id (id) + { + LocalDefId local_def_id = id & DEF_ID_LOCAL_DEF_MASK; + rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID); + } - FnType (HirId ref, HirId ty_ref, std::string identifier, bool is_method, + FnType (HirId ref, HirId ty_ref, DefId id, std::string identifier, + bool is_method, std::vector > params, BaseType *type, std::vector subst_refs, std::set refs = std::set ()) @@ -948,8 +952,11 @@ public: SubstitutionRef (std::move (subst_refs), SubstitutionArgumentMappings::error ()), params (params), type (type), is_method_flag (is_method), - identifier (identifier) - {} + identifier (identifier), id (id) + { + LocalDefId local_def_id = id & DEF_ID_LOCAL_DEF_MASK; + rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID); + } void accept_vis (TyVisitor &vis) override; @@ -974,6 +981,8 @@ public: return is_method_flag; } + DefId get_id () const { return id; } + // get the Self type for the method BaseType *get_self_type () const { @@ -1026,6 +1035,7 @@ private: BaseType *type; bool is_method_flag; std::string identifier; + DefId id; }; class FnPtr : public BaseType -- cgit v1.1