aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-05-07 16:39:28 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-05-07 16:52:06 +0100
commit9428db632815386ea6e6c994e92c9aabf00abb35 (patch)
tree78a6dc418daacdf1323eeeba70319018dab42540 /gcc
parent9fdb4b6aff586a1dece32f03f53aa6ea2837e7e4 (diff)
downloadgcc-9428db632815386ea6e6c994e92c9aabf00abb35.zip
gcc-9428db632815386ea6e6c994e92c9aabf00abb35.tar.gz
gcc-9428db632815386ea6e6c994e92c9aabf00abb35.tar.bz2
We need to monomorphize tuples as well as ADT's
When we have generic data types or types that can contain type parameters we need to make sure to avoid duplicating record types and abusing structural equality rules in GCC. We do this by looking for already compiled types that the item is equal to so they refer to the canoncial record type. Fixes #415
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-context.h10
-rw-r--r--gcc/testsuite/rust.test/compile/generics26.rs21
-rw-r--r--gcc/testsuite/rust.test/compile/generics27.rs16
3 files changed, 42 insertions, 5 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index 11e791c..bdc9eca 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -66,7 +66,7 @@ public:
bool lookup_compiled_types (HirId id, ::Btype **type,
const TyTy::BaseType *ref = nullptr)
{
- if (ref != nullptr && ref->has_subsititions_defined ())
+ if (ref != nullptr)
{
for (auto it = mono.begin (); it != mono.end (); it++)
{
@@ -393,7 +393,8 @@ public:
return;
}
- bool ok = ctx->lookup_compiled_types (type.get_ty_ref (), &translated);
+ bool ok
+ = ctx->lookup_compiled_types (type.get_ty_ref (), &translated, &type);
if (ok)
return;
@@ -402,8 +403,7 @@ public:
for (size_t i = 0; i < type.num_fields (); i++)
{
TyTy::BaseType *field = type.get_field (i);
- Btype *compiled_field_ty
- = TyTyCompile::compile (ctx->get_backend (), field);
+ Btype *compiled_field_ty = TyTyResolveCompile::compile (ctx, field);
Backend::Btyped_identifier f (std::to_string (i), compiled_field_ty,
ctx->get_mappings ()->lookup_location (
@@ -418,7 +418,7 @@ public:
type.get_ty_ref ()));
ctx->push_type (named_struct);
- ctx->insert_compiled_type (type.get_ty_ref (), named_struct);
+ ctx->insert_compiled_type (type.get_ty_ref (), named_struct, &type);
translated = named_struct;
}
diff --git a/gcc/testsuite/rust.test/compile/generics26.rs b/gcc/testsuite/rust.test/compile/generics26.rs
new file mode 100644
index 0000000..522e16f
--- /dev/null
+++ b/gcc/testsuite/rust.test/compile/generics26.rs
@@ -0,0 +1,21 @@
+// github issue #415
+fn test<A, B>(a: A, b: B) -> (A, B) {
+ (a, b)
+}
+
+fn main() {
+ let a = test::<i32, i32>(123, 456);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let b = test::<f32, f32>(123f32, 456f32);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let c = test::<_, _>(123, 456f32);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let d = test(true, 1234);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let e = test((123, false), 123f32);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}
diff --git a/gcc/testsuite/rust.test/compile/generics27.rs b/gcc/testsuite/rust.test/compile/generics27.rs
new file mode 100644
index 0000000..9871638
--- /dev/null
+++ b/gcc/testsuite/rust.test/compile/generics27.rs
@@ -0,0 +1,16 @@
+// github issue #415
+fn test<A>(a: &A) -> &A {
+ a
+}
+
+fn main() {
+ let a = 123;
+ let b = &a;
+ let c = test(b);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+
+ let a = 123f32;
+ let b = &a;
+ let c = test(b);
+ // { dg-warning "unused name" "" { target *-*-* } .-1 }
+}