Repository navigation
Evaluate try_emplace arguments before checking the key - #583
Open
perfloop-agent wants to merge 2 commits into
Open
perfloop-agent wants to merge 2 commits into
perfloop-agent wants to merge 2 commits into
Conversation
Signed-off-by: Perfloop Agent <agent@perfloop.ai> Signed-off-by: Tomás Senart <ts@perfloop.ai>
Signed-off-by: Perfloop Agent <agent@perfloop.ai> Signed-off-by: Tomás Senart <ts@perfloop.ai>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Evaluate
std::map::try_emplace(key, args...)arguments before the key lookup, even when the key already exists, while keeping mapped-object construction conditional on insertion. This fixes skipped argument side effects for lvalue and const keys in both refcount and unsafe output.The rules IR
initfragment gains an optionalconditionalflag, detected from its position in the rule body. The converter uses it to bind argument effects before expanding the rule body without eagerly constructing the stored value. Reference binding andstd::moveforwarding are preserved: arguments are not copied or moved from on a key hit, and insertion retains the C++ copy/move behavior.The binding also works in global initializers and with assignment, compound assignment, prefix increment, comma and conditional expressions. Modified lvalue arguments remain addressable without repeating their operand effects.
Testing
The two new unit tests,
tests/unit/map_try_emplace.cppandtests/unit/map_try_emplace_lvalues.cpp, run in both output models. They check argument evaluation, conditional construction, reference binding, copy/move behavior, global initialization and modified lvalue arguments against native C++. The existing-key increment case fails without the fix in both models.The full Linux lit suite in Release reports 1,156 passed, 14 expected failures and no unexpected failures with the change; the unpatched base reports 1,152 passed, 14 expected failures and no unexpected failures. Existing expected outputs are unchanged.
The changed C++ files pass clang-format. The rule preprocessor passes rustfmt and Clippy with warnings denied.
Coverage does not establish the rvalue-key overload or exception unwinding.
Case and evidence
Made by Perfloop. Human sponsor: Tomás Senart. To ask for a change, comment or review in plain words. How Perfloop handles pull requests.