]> git.ipfire.org Git - thirdparty/gcc.git/commit
gccrs: Fix generic argument tracking
authorPhilip Herron <herron.philip@googlemail.com>
Tue, 20 Jun 2023 15:39:25 +0000 (16:39 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:46:28 +0000 (18:46 +0100)
commit5189a22a14c99b9d56c4ce14d7b4d8206caf8dd2
treea538e8ac7a86a8abc53ced717328eedfa84f18f2
parent4476c9a8e386575c272c96a7e9383b011f273d77
gccrs: Fix generic argument tracking

When we do generic argument substitution we creating mappings of the
HIR::GenericArgs argument to the TyTy::SubstitutionParam as a pointer. So
for example when we have Generic Parameters <Self, T> and arguments <T, U>

  T0: Arguments: <Self=T, T=U>
  T1: Self -> replaced-with T
  T2: Arguments: <T=T, T=U>
  T3: T maps back to the replace Self->T
  T4: Arguments <T=T, T=T>

Which is wrong but because we do a string comparison to find the argument
mapping we cant reply on the pointer to the origin parameter mapping as
the parameter will be updated resulting in bad mappings.

This patch changes the Argument mappings to track the _original_ parameter
type so that lookup's for the mappings use this symbol instead not the
updated ones during substitution.

Addresses #1893

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments):
simplify lookup of the respective predicate
* typecheck/rust-tyty-subst.cc (SubstitutionArg::SubstitutionArg): track original parameter
(SubstitutionArg::operator=): update copy ctor
(SubstitutionArg::get_param_ty): use original param
(SubstitutionArg::as_string): update as_string
* typecheck/rust-tyty-subst.h: add new private field

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/typecheck/rust-hir-type-check-path.cc
gcc/rust/typecheck/rust-tyty-subst.cc
gcc/rust/typecheck/rust-tyty-subst.h