-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gccrs: cleanup our enum type layout to be closer to rustc #3357
base: master
Are you sure you want to change the base?
Conversation
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 <[email protected]>
our gdb output looks much better with this too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar enough with all details here to provide an appropriate review but it looks great and I couldn't find anything to say.
I wonder if this would fix one failing test in #3299
HIR::Expr &discrim_expr = variant->get_discriminant (); | ||
tree discrim_expr_node = CompileExpr::Compile (discrim_expr, ctx); | ||
tree folded_discrim_expr = fold_expr (discrim_expr_node); | ||
tree qualifier = folded_discrim_expr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why we need that variable ? Could we use folded_discrim_expr
directly or rename it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good find will fix
This changes our enum type layout so for example:
Used to get layed out like this in gccrs:
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:
This layout is much cleaner and allows for our constexpr to work properly.
gcc/rust/ChangeLog: