Skip to content

transpile: Deduplicate in/decrement operator handling - #1921

Merged
ahomescu merged 6 commits into
immunant:masterfrom
Rua:indecrement-operator-refactor
Jul 27, 2026
Merged

transpile: Deduplicate in/decrement operator handling#1921
ahomescu merged 6 commits into
immunant:masterfrom
Rua:indecrement-operator-refactor

Conversation

@Rua

@Rua Rua commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

The code for post-increment basically reimplements part of the pre-increment code as well as parts of the compound assignment code. This PR deduplicates that by introducing a new common function, and also makes pre-increment emit a Rust compound assignment when it can, resulting in cleaner output.

@Rua
Rua force-pushed the indecrement-operator-refactor branch from b14efc8 to 11dbc42 Compare July 24, 2026 15:09
bar = (bar as ::core::ffi::c_int + 1) as Bar;
let c2rust_fresh0 = foo;
foo = foo.wrapping_add(1);
foo = (foo as ::core::ffi::c_uint).wrapping_add(1) as Foo;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did these extra casts come from?

@Rua Rua Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are produced the same way as they are for regular compound assignment foo += 1. Specifically, the compute_lhs_type_id and compute_res_type_id, which specify when a compound assignment has its arithmetic/logic operator performed using a different type from its LHS operand.

In this case, the casts are superfluous, but that is because convert_cast_from_enum and convert_cast_to_enum unconditionally cast. a589bee (as part of #1620) is meant to fix that.

@ahomescu
ahomescu merged commit be8a6c3 into immunant:master Jul 27, 2026
11 checks passed
@Rua
Rua deleted the indecrement-operator-refactor branch July 28, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants