aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2022-03-16 14:34:26 +0000
committerPhilip Herron <philip.herron@embecosm.com>2022-03-16 14:34:26 +0000
commit56a1571614ab807bfc12a7a43ae4926b2fc1f744 (patch)
tree02e5bfe8e9f9c60c6ffe56b65fdfe2d1fa480fbe /gcc
parent9411c061aaeae0be39c678e0885472c37b112141 (diff)
downloadgcc-56a1571614ab807bfc12a7a43ae4926b2fc1f744.zip
gcc-56a1571614ab807bfc12a7a43ae4926b2fc1f744.tar.gz
gcc-56a1571614ab807bfc12a7a43ae4926b2fc1f744.tar.bz2
Keep track of substitution mappings as part of the TraitReference
The TraitReference wrapper is a class that allows us to work with traits in a query manar. This patch allows us to keep track of the substitution mappings that are defined on the trait. This will always be non-empty since traits always contain an implicit Self type parameter so there is special handling in how we perform monomorphization.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/typecheck/rust-hir-trait-ref.h39
-rw-r--r--gcc/rust/typecheck/rust-hir-trait-resolve.h3
2 files changed, 36 insertions, 6 deletions
diff --git a/gcc/rust/typecheck/rust-hir-trait-ref.h b/gcc/rust/typecheck/rust-hir-trait-ref.h
index 613ed71..4ad0d7b 100644
--- a/gcc/rust/typecheck/rust-hir-trait-ref.h
+++ b/gcc/rust/typecheck/rust-hir-trait-ref.h
@@ -181,19 +181,37 @@ class TraitReference
public:
TraitReference (const HIR::Trait *hir_trait_ref,
std::vector<TraitItemReference> item_refs,
- std::vector<const TraitReference *> super_traits)
+ std::vector<const TraitReference *> super_traits,
+ std::vector<TyTy::SubstitutionParamMapping> substs)
: hir_trait_ref (hir_trait_ref), item_refs (item_refs),
super_traits (super_traits)
- {}
+ {
+ trait_substs.clear ();
+ trait_substs.reserve (substs.size ());
+ for (const auto &p : substs)
+ trait_substs.push_back (p.clone ());
+ }
TraitReference (TraitReference const &other)
- : hir_trait_ref (other.hir_trait_ref), item_refs (other.item_refs)
- {}
+ : hir_trait_ref (other.hir_trait_ref), item_refs (other.item_refs),
+ super_traits (other.super_traits)
+ {
+ trait_substs.clear ();
+ trait_substs.reserve (other.trait_substs.size ());
+ for (const auto &p : other.trait_substs)
+ trait_substs.push_back (p.clone ());
+ }
TraitReference &operator= (TraitReference const &other)
{
hir_trait_ref = other.hir_trait_ref;
item_refs = other.item_refs;
+ super_traits = other.super_traits;
+
+ trait_substs.clear ();
+ trait_substs.reserve (other.trait_substs.size ());
+ for (const auto &p : other.trait_substs)
+ trait_substs.push_back (p.clone ());
return *this;
}
@@ -201,7 +219,10 @@ public:
TraitReference (TraitReference &&other) = default;
TraitReference &operator= (TraitReference &&other) = default;
- static TraitReference error () { return TraitReference (nullptr, {}, {}); }
+ static TraitReference error ()
+ {
+ return TraitReference (nullptr, {}, {}, {});
+ }
bool is_error () const { return hir_trait_ref == nullptr; }
@@ -384,10 +405,18 @@ public:
return is_safe;
}
+ bool trait_has_generics () const { return !trait_substs.empty (); }
+
+ const std::vector<TyTy::SubstitutionParamMapping> &get_trait_substs () const
+ {
+ return trait_substs;
+ }
+
private:
const HIR::Trait *hir_trait_ref;
std::vector<TraitItemReference> item_refs;
std::vector<const TraitReference *> super_traits;
+ std::vector<TyTy::SubstitutionParamMapping> trait_substs;
};
class AssociatedImplTrait
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.h b/gcc/rust/typecheck/rust-hir-trait-resolve.h
index d8df481..7af353a 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.h
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.h
@@ -193,7 +193,8 @@ private:
}
TraitReference trait_object (trait_reference, item_refs,
- std::move (super_traits));
+ std::move (super_traits),
+ std::move (substitutions));
context->insert_trait_reference (
trait_reference->get_mappings ().get_defid (), std::move (trait_object));