public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Merge #1121
@ 2022-06-08 12:33 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:33 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:4152743451a73591fa60bc52f0b28447ef4a8878
commit 4152743451a73591fa60bc52f0b28447ef4a8878
Merge: 5b14291b54f ad9e185e15f
Author: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
Date: Tue Apr 19 16:33:48 2022 +0000
Merge #1121
1121: Fix bad projection substitution r=philberty a=philberty
When we have a Trait such as:
```
pub unsafe trait SliceIndex<T> {
type Output;
fn index(self, slice: &T) -> &Self::Output;
}
unsafe impl<T> SliceIndex<[T]> for Range<usize> {
type Output = [T];
fn index(self, slice: &[T]) -> &[T] {
unsafe { &*self.get_unchecked(slice) }
}
}
```
When we need to verify that the impl index is compatible fir SliceIndex we
get the Type info for the trait-item which is:
fn<Self, T> index(self: Self, slice: &T)
-> &<placeholder=projection<T>=[T]>
This projection gets setup and the types are substituted with
Self=Range<usize> and T=[T] which ended up substituting the projection
twice resulting in a recursive slice [T=[T]]. In this case the associated
type is already setup for the placeholder and does not require generic
substitution. This means we added a flag to the substitution generic
arguments mappings to handle this case.
This patch also addressed memory corruption with the TypeBoundPredicate
as part of the debugging of this issue which resulted in a segv when
trying to debug the mappings. The issue was the copy constructors needed
to update the used argument mappings each time since the substitution param
mappings are copied and the addresses no longer exist, valgrind was great
here to find this issue.
Fixes #1120
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diff:
gcc/rust/typecheck/rust-hir-trait-ref.h | 22 ++-
gcc/rust/typecheck/rust-hir-trait-resolve.cc | 4 +-
gcc/rust/typecheck/rust-hir-type-check-implitem.h | 160 +++++++++++-----------
gcc/rust/typecheck/rust-hir-type-check-item.h | 10 +-
gcc/rust/typecheck/rust-hir-type-check.h | 4 +-
gcc/rust/typecheck/rust-substitution-mapper.h | 9 +-
gcc/rust/typecheck/rust-tyty-bounds.cc | 86 ++++++++----
gcc/rust/typecheck/rust-tyty.cc | 18 ++-
gcc/rust/typecheck/rust-tyty.h | 28 ++--
gcc/testsuite/rust/compile/traits9.rs | 3 +-
gcc/testsuite/rust/execute/torture/issue-1120.rs | 123 +++++++++++++++++
11 files changed, 332 insertions(+), 135 deletions(-)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 12:33 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:33 [gcc/devel/rust/master] Merge #1121 Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).