https://gcc.gnu.org/g:b401e72ba547d2fa595e13f119e3e5e337afc0d9

commit b401e72ba547d2fa595e13f119e3e5e337afc0d9
Author: Philip Herron <herron.phi...@googlemail.com>
Date:   Mon May 26 19:30:45 2025 +0100

    gccrs: Fix non canonical type bug with tuples
    
    When working on rpit we needed to change to use a monomorphized clone of
    the result of function calls. This ended up causing a verify gimple issue
    with tuples because:
    
      fn test<A, B>(a: A, b: B) -> (A, B)
    
    When passing for example:
    
      let a = test::<i32, i32> (123, 456) -> (A=i32, B=i32)
    
    The resulting gimple types became:
    
      const struct (A=i32, B=i32) vs struct (i32, i32)
    
    We removed the VIEW_CONVERT_EXPR support to auto fix this stuff a good
    while ago because it hides these kinds of issues because the type hasher
    included the A=i32, B=i32 vs the i32, i32 name so updating this to use
    get_name instead keeps the naming the same as well as the fields meaning
    these types are 100% equivilant and therefore no conversion is required.
    This only occurs because tuples are not named types we should really add
    more rust specific info on our gimple TYPES.
    
    gcc/rust/ChangeLog:
    
            * backend/rust-compile-type.cc (TyTyResolveCompile::visit): use 
get_name
            * typecheck/rust-tyty.cc (TupleType::get_name): likewise
    
    Signed-off-by: Philip Herron <herron.phi...@googlemail.com>

Diff:
---
 gcc/rust/backend/rust-compile-type.cc | 2 +-
 gcc/rust/typecheck/rust-tyty.cc       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-type.cc 
b/gcc/rust/backend/rust-compile-type.cc
index 5be2b9e317e4..903d0ce85416 100644
--- a/gcc/rust/backend/rust-compile-type.cc
+++ b/gcc/rust/backend/rust-compile-type.cc
@@ -454,7 +454,7 @@ TyTyResolveCompile::visit (const TyTy::TupleType &type)
     }
 
   tree struct_type_record = Backend::struct_type (fields);
-  translated = Backend::named_type (type.as_string (), struct_type_record,
+  translated = Backend::named_type (type.get_name (), struct_type_record,
                                    type.get_ident ().locus);
 }
 
diff --git a/gcc/rust/typecheck/rust-tyty.cc b/gcc/rust/typecheck/rust-tyty.cc
index 4da51ffdbfd1..09a9b97354be 100644
--- a/gcc/rust/typecheck/rust-tyty.cc
+++ b/gcc/rust/typecheck/rust-tyty.cc
@@ -1992,7 +1992,7 @@ TupleType::get_name () const
   std::string fields_buffer;
   for (const TyVar &field : get_fields ())
     {
-      fields_buffer += field.get_tyty ()->as_string ();
+      fields_buffer += field.get_tyty ()->get_name ();
       bool has_next = (i + 1) < get_fields ().size ();
       fields_buffer += has_next ? ", " : "";
       i++;

Reply via email to