aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-06-29 10:13:29 +0100
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 18:46:32 +0100
commitdf7f3413385b5e4b90b1da5058b9fae4b891224c (patch)
tree85ac98ed90a773fb66ce80929872e8ec59870c41
parent671517fc2e28d7b3f8caa2d2d1b26365285d3d99 (diff)
downloadgcc-df7f3413385b5e4b90b1da5058b9fae4b891224c.zip
gcc-df7f3413385b5e4b90b1da5058b9fae4b891224c.tar.gz
gcc-df7f3413385b5e4b90b1da5058b9fae4b891224c.tar.bz2
gccrs: Track associated type generics
This fixes an issue with our qualified type-paths if we point to a generic associated type this needs to either use the placeholder type on the trait reference or use the impl-type but apply the generics. gcc/rust/ChangeLog: * typecheck/rust-hir-trait-reference.h: update prototype * typecheck/rust-hir-trait-resolve.cc: add generic args as an out param * typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): use the generics Signed-off-by: Philip Herron <herron.philip@googlemail.com>
-rw-r--r--gcc/rust/typecheck/rust-hir-trait-reference.h3
-rw-r--r--gcc/rust/typecheck/rust-hir-trait-resolve.cc20
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-type.cc11
3 files changed, 26 insertions, 8 deletions
diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.h b/gcc/rust/typecheck/rust-hir-trait-reference.h
index c0a6f56..440a232 100644
--- a/gcc/rust/typecheck/rust-hir-trait-reference.h
+++ b/gcc/rust/typecheck/rust-hir-trait-reference.h
@@ -253,7 +253,8 @@ public:
TyTy::BaseType *
setup_associated_types (const TyTy::BaseType *self,
- const TyTy::TypeBoundPredicate &bound);
+ const TyTy::TypeBoundPredicate &bound,
+ TyTy::SubstitutionArgumentMappings *args = nullptr);
void reset_associated_types ();
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index a8a026a..f72c6fc 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -434,7 +434,8 @@ AssociatedImplTrait::setup_raw_associated_types ()
TyTy::BaseType *
AssociatedImplTrait::setup_associated_types (
- const TyTy::BaseType *self, const TyTy::TypeBoundPredicate &bound)
+ const TyTy::BaseType *self, const TyTy::TypeBoundPredicate &bound,
+ TyTy::SubstitutionArgumentMappings *args)
{
// compute the constrained impl block generic arguments based on self and the
// higher ranked trait bound
@@ -491,25 +492,27 @@ AssociatedImplTrait::setup_associated_types (
// generate inference variables for these bound arguments so we can compute
// their values
Location locus;
- std::vector<TyTy::SubstitutionArg> args;
+ std::vector<TyTy::SubstitutionArg> subst_args;
for (auto &p : substitutions)
{
if (p.needs_substitution ())
{
TyTy::TyVar infer_var = TyTy::TyVar::get_implicit_infer_var (locus);
- args.push_back (TyTy::SubstitutionArg (&p, infer_var.get_tyty ()));
+ subst_args.push_back (
+ TyTy::SubstitutionArg (&p, infer_var.get_tyty ()));
}
else
{
TyTy::ParamType *param = p.get_param_ty ();
TyTy::BaseType *resolved = param->destructure ();
- args.push_back (TyTy::SubstitutionArg (&p, resolved));
+ subst_args.push_back (TyTy::SubstitutionArg (&p, resolved));
param_mappings[param->get_symbol ()] = resolved->get_ref ();
}
}
- TyTy::SubstitutionArgumentMappings infer_arguments (std::move (args), {},
- locus, param_subst_cb);
+ TyTy::SubstitutionArgumentMappings infer_arguments (std::move (subst_args),
+ {}, locus,
+ param_subst_cb);
TyTy::BaseType *impl_self_infer
= (!associated_self->is_concrete ())
? SubstMapperInternal::Resolve (associated_self, infer_arguments)
@@ -632,6 +635,11 @@ AssociatedImplTrait::setup_associated_types (
resolved_trait_item->associated_type_set (substituted);
}
+ if (args != nullptr)
+ {
+ *args = associated_type_args;
+ }
+
return self_result;
}
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index d309101..c476edf 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -214,6 +214,8 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
}
// we try to look for the real impl item if possible
+ TyTy::SubstitutionArgumentMappings args
+ = TyTy::SubstitutionArgumentMappings::error ();
HIR::ImplItem *impl_item = nullptr;
if (root->is_concrete ())
{
@@ -223,7 +225,8 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
= lookup_associated_impl_block (specified_bound, root);
if (associated_impl_trait != nullptr)
{
- associated_impl_trait->setup_associated_types (root, specified_bound);
+ associated_impl_trait->setup_associated_types (root, specified_bound,
+ &args);
for (auto &i :
associated_impl_trait->get_impl_block ()->get_impl_items ())
@@ -262,6 +265,12 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
return;
}
+ if (!args.is_error ())
+ {
+ // apply the args
+ translated = SubstMapperInternal::Resolve (translated, args);
+ }
+
root_resolved_node_id = impl_item->get_impl_mappings ().get_nodeid ();
}