fix: reuse generated operation functions - #1995
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1995 +/- ##
==========================================
- Coverage 87.18% 87.17% -0.01%
==========================================
Files 201 201
Lines 31957 32010 +53
Branches 30377 30430 +53
==========================================
+ Hits 27861 27905 +44
- Misses 2891 2892 +1
- Partials 1205 1213 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
🟢 Approval recommended
The implementation consistently reuses inserted definitions and includes targeted regression coverage.
Pull request overview
Reuses cached lowering functions to prevent duplicate private function definitions and excessive LLVM memory use.
Changes:
- Adds templates for calling existing HUGR functions.
- Inserts each cached lowering function once.
- Adds repeated-operation and barrier regressions.
File summaries
| File | Description |
|---|---|
tket/src/passes/utils/unpack_container/op_function_map.rs |
Inserts cached definitions once and registers direct calls. |
tket/src/passes/utils/unpack_container.rs |
Tests shared generic lowering functions. |
tket/src/passes/replace_types.rs |
Adds existing-function call templates. |
tket-qsystem/src/extension/qsystem/barrier.rs |
Tests shared wrapped-barrier functions. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
This looks like a bug in This PR adds a new NodeTemplate::CallFunction, but I’m wondering if we should fix |
|
Yes, See also Quantinuum/hugr#2766, but note that for the moment QSystemRebasePass has a Possibly You can also link in FuncDecls to call for each op, then construct the body that you want only if some FuncDecl was actually added, if constructing the body is expensive, but this do-compilation-faster has not seemed worth the complexity so far. |
There was a problem hiding this comment.
🟡 Changes recommended
Public helper names are not unique for every cached operation shape, causing linker signature conflicts.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Balanced
Summary
OpFunctionMapdefinitions public while HUGR linking runsNodeTemplate::call_to_functionsoOnMultiDefn::UseTargetcoalesces repeated definitionsRoot cause
OpFunctionMapcached one generated HUGR per operation shape, but its replacement template embedded a private function HUGR at every call site. Name linking only coalesces public definitions, soOnMultiDefn::UseTargethad no effect and repeated barriers produced thousands of equivalent wrapper functions. Wide wrappers then amplified LLVM IPSCCP memory use.The fix belongs in
func_as_node_template: cached helpers are now linker-visible when passed through the existingcall_to_functionpath.QSystemRebasePassalready records pre-existing public functions and hides newly introduced helpers after lowering, so the final HUGR retains private linkage without adding a parallel call-template mechanism.Validation
cargo check -p tket -p tket-qsystemcargo test -p tket --lib(604 passed, 2 ignored)cargo test -p tket-qsystem --lib(167 passed, 1 ignored)just check: formatting, Ruff, mypy, Cargo check/docs, and pg-libs tests passed; the full local gate remains blocked by unrelated existing nightly Clippy findings and macOS hugrenv@rpathresolution in aggregate nextest/Python discoverygit diff --check origin/main...HEAD