Skip to content

Moved infix::calculate() from writers.cc, fixed problem with Ref lookups - #207

Open
matteB10 wants to merge 4 commits into
microsoft:mainfrom
matteB10:infix/small_fix
Open

Moved infix::calculate() from writers.cc, fixed problem with Ref lookups #207
matteB10 wants to merge 4 commits into
microsoft:mainfrom
matteB10:infix/small_fix

Conversation

@matteB10

Copy link
Copy Markdown
Contributor
  1. Moved the Rewriter infix::calculate into its own file, calculate.cc to decouple and keep code coverage measures separate.
  2. Updated the exists and can_replace action functions. We discovered that the old can_replace failed 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 called can_replace on the Ref node instead of its Ident child. Since generated Ref nodes don’t always share the same location as their Ident, the rule never matched. The updated version fixes this by applying the check directly to the Ident node.

Copilot AI left a comment

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.

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) from writers.cc into the new calculate.cc.
  • Updated exists / can_replace usage so the predicate is applied to the Ident child instead of the Ref node.
  • Updated the infix sample build targets to compile and link the new calculate.cc file.

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_file is 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 the wf_to_file already used by to_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);

@mjp41 Matthew Parkinson (mjp41) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, can you fix the copilot comments please.

Comment thread samples/infix/calculate.cc Outdated
Removed duplicate wf_to_file definition after Matt's comment
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.

3 participants