transpile: Translate enums in switch as their own type instead of integers - #1817
Conversation
dc3e839 to
099f867
Compare
ahomescu
left a comment
There was a problem hiding this comment.
This needs a rebase, but CI should pass now.
84cf432 to
eb10415
Compare
|
I think there might be one codegen bug here: for this C code the transpiled Rust code fails to compile. Let me know if you reproduce it. |
a896bfd to
fd1a4f7
Compare
|
Yeah I could reproduce it. Fixed now, I hope. |
af4031b to
9c0e27d
Compare
|
This needs another rebase. |
fw-immunant
left a comment
There was a problem hiding this comment.
A few small nits.
The first is commented inline on transpile: Add expected type for enums in `SwitchCases`, and the other is that I'm not a big fan of transpile: Make `target_type_id` parameter of `convert_expr_with_cast` optional: it adds a branch to the function that makes the function not do what it says on the tin, which isn't what any of the existing callers want. Where transpile: Translate enums in `switch` as their own type instead of integers changes calls from convert_expr to the new convert_expr_with_cast, I'd prefer if it changed them to a new function (e.g. "convert_expr_possibly_casting" or such) that does that dispatch to either convert_expr or the old convert_expr_with_cast.
Otherwise, this LGTM and is a really clean idiomaticity win. Thanks for taking the numerous steps to make this improved translation happen!
This also seems to want a rebase now.
|
I've now added |
fw-immunant
left a comment
There was a problem hiding this comment.
Looks great now, thanks!
can_propagate_castfunction, elide some more casts #1770casetranslation #1776casestatements do not preserve enum constants #1775Enum constant names are now preserved in match arms where present, which significantly improves code fidelity.