Skip to content

Evaluate rule arguments with side effects even when the rule ignores them - #693

Merged
nunoplopes merged 2 commits into
Cpp2Rust:masterfrom
perfloop-oss:perfloop-pr-open-pd01njbexb
Dec 2, 2026
Merged

nunoplopes merged 2 commits into
Cpp2Rust:masterfrom
perfloop-oss:perfloop-pr-open-pd01njbexb

Conversation

@perfloop-agent

Copy link
Copy Markdown
Contributor

Mapped calls can silently skip side effects when a rule ignores an operand, in both refcount and unsafe output. For example, pick(a, &calls).size() must call pick even though the array-size rule expands to a constant. With a one-element array and calls = 0, the size is correctly translated as 1, but calls stays 0 instead of becoming 1.

Omitted side-effectful operands are bound before expanding the rule body, using the existing temporary-binding machinery. Preceding operand values are captured before those effects can change what they read. Global initializers get an expansion-local binding context when an omitted operand is bound, while retaining the existing init-fragment path.

Operands that Clang itself drops stay dropped: compile-time constants such as the 0 in o < 0, and operands of builtins Clang folds, such as __builtin_expect(1, ++n).

The new tests/unit/mapped_unused_args.cpp covers global initialization, array and temporary receivers, evaluation order and preceding-value snapshots, a pointer operand passed to nanf, and pure/folded controls. Generated output is unchanged for every existing test; the new test passes in both refcount and unsafe output.

Converter run time on tests/unit/operator_three_way.cpp, which runs the changed code but not the fixed case, did not change measurably over 48 paired runs: the difference (base minus change; positive is faster) was −5.0 to +8.8 ms in refcount output and −3.6 to +7.0 ms in unsafe output.

cc @nunoplopes

Case and evidence


Made by Perfloop. Human sponsor: Tomás Senart.

Signed-off-by: Perfloop Agent <agent@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai>
@nunoplopes
nunoplopes merged commit 51c51f2 into Cpp2Rust:master Dec 2, 2026
8 of 9 checks passed
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