diff options
author | Philip Herron <herron.philip@googlemail.com> | 2023-03-13 16:49:36 +0000 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2023-03-17 10:34:36 +0000 |
commit | 9ace79ff7ec52b15708469a04b28070bfeed5eb3 (patch) | |
tree | 6c1fa63a24cbd41748c7776670cfe076ca1a12d9 /gcc/rust/backend/rust-compile.cc | |
parent | 85a5abeb3748ef0fc18973e9139d9a18b7809661 (diff) | |
download | gcc-9ace79ff7ec52b15708469a04b28070bfeed5eb3.zip gcc-9ace79ff7ec52b15708469a04b28070bfeed5eb3.tar.gz gcc-9ace79ff7ec52b15708469a04b28070bfeed5eb3.tar.bz2 |
gccrs: Remove solve_missing_mappings_from_this to handle covariants
change how we monomorphize dyn-items when we need to compute the generics
We might have a trait item such as:
impl<'a, T> FnLike<&'a T, &'a T> for Identity {
fn call(&self, arg: &'a T) -> &'a T { ... }
}
Which ended up monomorphized badly to:
const isize & const &
<example::Identity as example::FnLike::<& T, & T>>::call<& isize>
(const struct example::Identity & const self,
const isize & const & const arg)
This is wrong because it turned into a double reference type becasuse this
bug was consistent bugs were not picked up but this is not correct. We now
reuse our type inference infrastructure to solve the parameters instead.
Fixes #1984
gcc/rust/ChangeLog:
* backend/rust-compile.cc: use unify_and instead
* typecheck/rust-tyty-subst.cc (SubstitutionRef::solve_missing_mappings_from_this): remove
* typecheck/rust-tyty-subst.h: update header
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile.cc')
-rw-r--r-- | gcc/rust/backend/rust-compile.cc | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index a01662c..2c46992 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -21,6 +21,8 @@ #include "rust-compile-implitem.h" #include "rust-hir-type-bounds.h" #include "rust-compile-type.h" +#include "rust-substitution-mapper.h" +#include "rust-type-util.h" namespace Rust { namespace Compile { @@ -299,11 +301,6 @@ HIRCompileBase::compute_address_for_trait_item ( = self_bound->lookup_associated_item (ref->get_identifier ()); rust_assert (!associated_self_item.is_error ()); - TyTy::BaseType *mono1 = associated_self_item.get_tyty_for_receiver (self); - rust_assert (mono1 != nullptr); - rust_assert (mono1->get_kind () == TyTy::TypeKind::FNDEF); - TyTy::FnType *assocated_item_ty1 = static_cast<TyTy::FnType *> (mono1); - // Lookup the impl-block for the associated impl_item if it exists HIR::Function *associated_function = nullptr; for (auto &impl_item : associated_impl_block->get_impl_items ()) @@ -333,10 +330,14 @@ HIRCompileBase::compute_address_for_trait_item ( if (lookup_fntype->needs_substitution ()) { - TyTy::SubstitutionArgumentMappings mappings - = assocated_item_ty1->solve_missing_mappings_from_this ( - *trait_item_fntype, *lookup_fntype); - lookup_fntype = lookup_fntype->handle_substitions (mappings); + TyTy::BaseType *infer + = Resolver::SubstMapper::InferSubst (lookup_fntype, Location ()); + infer + = Resolver::unify_site (infer->get_ref (), + TyTy::TyWithLocation (trait_item_fntype), + TyTy::TyWithLocation (infer), Location ()); + rust_assert (infer->get_kind () == TyTy::TypeKind::FNDEF); + lookup_fntype = static_cast<TyTy::FnType *> (infer); } return CompileInherentImplItem::Compile (associated_function, ctx, |