diff options
author | Philip Herron <herron.philip@googlemail.com> | 2025-01-07 18:15:37 +0000 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-21 12:56:55 +0100 |
commit | f821a513843baabed8a39601bbc714558110b748 (patch) | |
tree | e5d4bc66d8c721905324d63be3a84b5e25363ee2 /gcc/rust/backend/rust-compile-resolve-path.cc | |
parent | 2fa9719068774ab7ec5ed4cbe95cfe30fa94dbb1 (diff) | |
download | gcc-f821a513843baabed8a39601bbc714558110b748.zip gcc-f821a513843baabed8a39601bbc714558110b748.tar.gz gcc-f821a513843baabed8a39601bbc714558110b748.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.cc | 5 |
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 31ebbf1..69599cc 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 |