Moved infix::calculate() from writers.cc, fixed problem with Ref lookups - #207
Open
matteB10 wants to merge 4 commits into
Open
Moved infix::calculate() from writers.cc, fixed problem with Ref lookups #207matteB10 wants to merge 4 commits into
matteB10 wants to merge 4 commits into
Conversation
Copilot started reviewing on behalf of
Matthew Parkinson (mjp41)
September 1, 2026 07:01
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the infix sample’s infix::calculate() rewriter out of writers.cc into a dedicated translation unit (calculate.cc) and fixes symbol-table lookup predicates so Ref replacement checks are applied to the Ident node (avoiding location-mismatch issues seen during fuzzing).
Changes:
- Moved the
infix::calculate()rewriter implementation (and its passes) fromwriters.ccinto the newcalculate.cc. - Updated
exists/can_replaceusage so the predicate is applied to theIdentchild instead of theRefnode. - Updated the infix sample build targets to compile and link the new
calculate.ccfile.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| samples/infix/writers.cc | Removes calculate() and the maths/cleanup pass implementation from the writer compilation unit. |
| samples/infix/CMakeLists.txt | Adds calculate.cc to both infix and infix_trieste targets. |
| samples/infix/calculate.cc | Introduces the extracted calculate() rewriter and updates the lookup predicates to operate on Ident. |
Suppressed comments (1)
samples/infix/calculate.cc:191
wf_to_fileis defined in this file but never referenced. Since the infix sample targets compile with-Werror, this unused variable is likely to break the build. It also duplicates thewf_to_filealready used byto_file()in writers.cc, so it can be removed from calculate.cc.
const auto wf_to_file =
infix::wf
| (Top <<= File)
| (File <<= Path * Calculation)
;
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| return std::stod(text); | ||
| } | ||
|
|
||
| inline const auto MathsOp = T(Add) / T(Subtract) / T(Multiply) / T(Divide); |
Matthew Parkinson (mjp41)
approved these changes
Sep 1, 2026
Matthew Parkinson (mjp41)
left a comment
Member
There was a problem hiding this comment.
LGTM, can you fix the copilot comments please.
Removed duplicate wf_to_file definition after Matt's comment
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.
Rewriterinfix::calculateinto its own file, calculate.cc to decouple and keep code coverage measures separate.existsandcan_replaceaction functions. We discovered that the oldcan_replacefailed to find any replaceable identifers during fuzzing, including when using --gen-bound to generate variables with symbol‑table bindings. The issue turned out to be that the rule calledcan_replaceon theRefnode instead of itsIdentchild. Since generatedRefnodes don’t always share the same location as theirIdent, the rule never matched. The updated version fixes this by applying the check directly to theIdentnode.