aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-07-15 13:47:24 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-07-15 13:49:30 +0100
commitea04a9ff1d0ed60332298ee07d94c1c73384b21f (patch)
treed18a4bc9c72eb9c357d3bf842c5e5e57c414d070
parent73ac7c5a1eca2db1c95ae5b7c3ee9f206ce9aa9d (diff)
downloadgcc-ea04a9ff1d0ed60332298ee07d94c1c73384b21f.zip
gcc-ea04a9ff1d0ed60332298ee07d94c1c73384b21f.tar.gz
gcc-ea04a9ff1d0ed60332298ee07d94c1c73384b21f.tar.bz2
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.
-rw-r--r--gcc/rust/hir/rust-ast-lower-implitem.h8
-rw-r--r--gcc/rust/hir/rust-ast-lower-stmt.h2
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-implitem.h1
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-stmt.h1
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-toplevel.h1
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check.cc1
-rw-r--r--gcc/rust/typecheck/rust-tyty.cc2
-rw-r--r--gcc/rust/typecheck/rust-tyty.h22
8 files changed, 26 insertions, 12 deletions
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<HIR::Type> (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<HIR::Pattern *, BaseType *> (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<std::pair<HIR::Pattern *, BaseType *> > params,
BaseType *type, std::vector<SubstitutionParamMapping> subst_refs,
std::set<HirId> refs = std::set<HirId> ())
@@ -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<std::pair<HIR::Pattern *, BaseType *> > params,
BaseType *type, std::vector<SubstitutionParamMapping> subst_refs,
std::set<HirId> refs = std::set<HirId> ())
@@ -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