Skip to content

Remove unneeded clones in converter and rules - #371

Merged
nunoplopes merged 15 commits into
Cpp2Rust:masterfrom
lucic71:computed_expr_type
Sep 15, 2026
Merged

nunoplopes merged 15 commits into
Cpp2Rust:masterfrom
lucic71:computed_expr_type

Conversation

@lucic71

@lucic71 lucic71 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

This PR removes unneeded clones in converter by calling SetValueFreshness/computed_expr_type_/SetFreshType on every fressh-value-producing path. It asserts that computed_expr_type_ is not Unknown after a conversion to make sure that we did not miss any path.

PendingDeref carries freshness separately. Producers of PendingDeref set freshness and consumers act based on that. I also added ComputedExprType::Pending because freshness is unknown until the consumer of PendingDeref sets it.

This PR also removes unneeded clones in rules using the Access IR attribute. Rules no longer clone their arguments. The preprocessor infers how each argument is used: borrow, borrow_mut, move, take. A move (let s = a0) consumes the argument, and it's cloned if it's not already fresh. A borrow usage (a0.len()) is never cloned.

Besides removing unneeded clones, on the converter side, this fixes #363. On the rules side, rule-preprocessor infers the access type of each argument automatically instead on relying on the rule author to encode it properly. This caught a bug in std::vector::push_back(T&&): the rule argument took the argument by value and cloned it, instead of moving it.

@nunoplopes
nunoplopes merged commit 6485b0a into Cpp2Rust:master Sep 15, 2026
9 checks passed
@lucic71
lucic71 deleted the computed_expr_type branch September 15, 2026 16:04
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.

Freshness is not tracked correctly

2 participants