aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-resolve-path.cc
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2025-01-07 18:15:37 +0000
committerPhilip Herron <philip.herron@embecosm.com>2025-01-10 09:04:48 +0000
commit806166db9db83bee816d169a13ab9992de9d66a0 (patch)
tree95c64de3b2e7753ff85e7aa001d2316f8144d9e2 /gcc/rust/backend/rust-compile-resolve-path.cc
parent1eaf085607f39111370e2c485ca819da7e14dfd1 (diff)
downloadgcc-806166db9db83bee816d169a13ab9992de9d66a0.zip
gcc-806166db9db83bee816d169a13ab9992de9d66a0.tar.gz
gcc-806166db9db83bee816d169a13ab9992de9d66a0.tar.bz2
gccrs: cleanup our enum type layout to be closer to rustc
This changes our enum type layout so for example: enum Foo { A, B, C(char), D { x: i32, y: i32 }, } Used to get layed out like this in gccrs: union { struct A { int RUST$ENUM$DISR; }; struct B { int RUST$ENUM$DISR; }; struct C { int RUST$ENUM$DISR; char __0; }; struct D { int RUST$ENUM$DISR; i64 x; i64 y; }; } This has some issues notably with the constexpr because this is just a giant union it means its not simple to constify what enum variant we are looking at because the discriminant is a mess. This now gets layed out as: struct { int RUST$ENUM$DISR; union { struct A { }; struct B { }; struct C { char __0; }; struct D { i64 x; i64 y; }; } payload; } This layout is much cleaner and allows for our constexpr to work properly. gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): new layout * backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit): likewise (CompilePatternBindings::visit): likewise * backend/rust-compile-resolve-path.cc: likewise * backend/rust-compile-type.cc (TyTyResolveCompile::visit): implement new layout * rust-gcc.cc (constructor_expression): get rid of useless assert Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-resolve-path.cc')
-rw-r--r--gcc/rust/backend/rust-compile-resolve-path.cc5
1 files changed, 3 insertions, 2 deletions
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc
index 5f6ba7c..049b0d8 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -86,8 +86,9 @@ ResolvePathRef::attempt_constructor_expression_lookup (
tree folded_discrim_expr = fold_expr (discrim_expr_node);
tree qualifier = folded_discrim_expr;
- return Backend::constructor_expression (compiled_adt_type, true, {qualifier},
- union_disriminator, expr_locus);
+ // false for is enum but this is an enum but we have a new layout
+ return Backend::constructor_expression (compiled_adt_type, false, {qualifier},
+ -1, expr_locus);
}
tree