diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-04-12 09:50:56 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-12 09:50:56 +0000 |
commit | c1a022385f5ed99b579e373d37cec389433e93f4 (patch) | |
tree | 11d8928918796afb88de93d53c0cf21eb167e990 /gcc/rust/backend | |
parent | 68458036c81d141a3899ac4e6ec6ddf0fdfde174 (diff) | |
parent | 0e686c0fe01ef29be1c08fb8440caf76c9fb66d9 (diff) | |
download | gcc-c1a022385f5ed99b579e373d37cec389433e93f4.zip gcc-c1a022385f5ed99b579e373d37cec389433e93f4.tar.gz gcc-c1a022385f5ed99b579e373d37cec389433e93f4.tar.bz2 |
Merge #1086
1086: Slice support r=philberty a=philberty
Please see the commit a8de089969cb45199008027cd8d1b80dff25746f for
a long explanation of what's going on in the patch. Unfortunately, I have not been
able to split this patch up anymore since supporting slices exposed many bugs
in the implementation of generics in general never main the missing support for
generic associated types.
Fixes #849
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.cc | 19 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile.cc | 18 |
2 files changed, 16 insertions, 21 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 49a6f2f..2128f25 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -747,8 +747,9 @@ CompileExpr::resolve_method_address (TyTy::FnType *fntype, HirId ref, auto root = receiver->get_root (); std::vector<Resolver::PathProbeCandidate> candidates - = Resolver::PathProbeType::Probe (root, segment, true, false, true); - + = Resolver::PathProbeType::Probe (root, segment, true /* probe_impls */, + false /* probe_bounds */, + true /* ignore_mandatory_trait_items */); if (candidates.size () == 0) { // this means we are defaulting back to the trait_item if @@ -776,12 +777,22 @@ CompileExpr::resolve_method_address (TyTy::FnType *fntype, HirId ref, rust_assert (candidates.size () == 1); auto &candidate = candidates.at (0); rust_assert (candidate.is_impl_candidate ()); + rust_assert (candidate.ty->get_kind () == TyTy::TypeKind::FNDEF); + TyTy::FnType *candidate_call = static_cast<TyTy::FnType *> (candidate.ty); HIR::ImplItem *impl_item = candidate.item.impl.impl_item; - if (!fntype->has_subsititions_defined ()) + if (!candidate_call->has_subsititions_defined ()) return CompileInherentImplItem::Compile (impl_item, ctx); - return CompileInherentImplItem::Compile (impl_item, ctx, fntype); + TyTy::BaseType *monomorphized = candidate_call; + if (candidate_call->needs_generic_substitutions ()) + { + TyTy::BaseType *infer_impl_call + = candidate_call->infer_substitions (expr_locus); + monomorphized = infer_impl_call->unify (fntype); + } + + return CompileInherentImplItem::Compile (impl_item, ctx, monomorphized); } } diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index 9e2c5b3..bd782b0 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -38,7 +38,6 @@ CompileCrate::~CompileCrate () {} void CompileCrate::Compile (HIR::Crate &crate, Context *ctx) - { CompileCrate c (crate, ctx); c.go (); @@ -383,26 +382,11 @@ HIRCompileBase::compute_address_for_trait_item ( = self_bound->lookup_associated_item (ref->get_identifier ()); rust_assert (!associated_self_item.is_error ()); - // apply any generic arguments from this predicate TyTy::BaseType *mono1 = associated_self_item.get_tyty_for_receiver (self); - TyTy::BaseType *mono2 = nullptr; - if (predicate->has_generic_args ()) - { - mono2 = associated_self_item.get_tyty_for_receiver ( - self, predicate->get_generic_args ()); - } - else - { - mono2 = 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); - rust_assert (mono2 != nullptr); - rust_assert (mono2->get_kind () == TyTy::TypeKind::FNDEF); - TyTy::FnType *assocated_item_ty2 = static_cast<TyTy::FnType *> (mono2); - // 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 ()) @@ -434,7 +418,7 @@ HIRCompileBase::compute_address_for_trait_item ( { TyTy::SubstitutionArgumentMappings mappings = assocated_item_ty1->solve_missing_mappings_from_this ( - *assocated_item_ty2, *lookup_fntype); + *trait_item_fntype, *lookup_fntype); lookup_fntype = lookup_fntype->handle_substitions (mappings); } |