Skip to content

fix(RFC): adapt borrowed callback calling conventions - #2511

Draft
ss2165 wants to merge 2 commits into
mainfrom
codex/fix-generic-borrowed-callbacks-2486
Draft

ss2165 wants to merge 2 commits into
mainfrom
codex/fix-generic-borrowed-callbacks-2486

Conversation

@ss2165

@ss2165 ss2165 commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Exploratory callback-adapter implementation produced by Codex, left as a draft for a compiler developer to assess and pick up. Preserves borrowed function signatures and inserts adapters where callback calling conventions differ, with separate copyability and droppability checks.

Clearing borrowing flags during specialization broke mutation/write-back in mem_swap and Option.swap. Named and specialized callbacks, nested callbacks, and tracing pass locally with the adapter approach; dynamically captured function adaptation still depends on experimental closure support and is not established as emulator-ready.

Local checks: 2,198 passed, 25 skipped, 13 expected failures; notebook and pytket circuit modules were excluded after process crashes. Ruff and mypy passed. This is an investigation handoff, not a production-ready fix.

Closes #2486

@ss2165
ss2165 requested a balanced review from Copilot November 10, 2026 10:58
@ss2165
ss2165 removed the request for review from Copilot November 10, 2026 10:59
@ss2165 ss2165 changed the title fix: normalize borrowed callback inputs during specialization fix: adapt borrowed callback calling conventions Nov 10, 2026
@ss2165 ss2165 changed the title fix: adapt borrowed callback calling conventions fix(RFC): adapt borrowed callback calling conventions Nov 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectguppylang
Branchcodex/fix-generic-borrowed-callbacks-2486
TestbedLinux
Click to view all benchmark results
Benchmarkhugr_bytesBenchmark Result
bytes x 1e3
(Result Δ%)
Upper Boundary
bytes x 1e3
(Limit %)
hugr_nodesBenchmark Result
nodes
(Result Δ%)
Upper Boundary
nodes
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_compile📈 view plot
🚷 view threshold
59.84 x 1e3
(0.00%)Baseline: 59.84 x 1e3
60.44 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
4,514.00
(0.00%)Baseline: 4,514.00
4,559.14
(99.01%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
26.87 x 1e3
(0.00%)Baseline: 26.87 x 1e3
27.14 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
1,182.00
(0.00%)Baseline: 1,182.00
1,193.82
(99.01%)
tests/benchmarks/test_queue_push_pop.py::test_queue_push_benchmark_compile📈 view plot
🚷 view threshold
6.70 x 1e3
(0.00%)Baseline: 6.70 x 1e3
6.77 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
279.00
(0.00%)Baseline: 279.00
281.79
(99.01%)
tests/benchmarks/test_queue_push_pop.py::test_queue_push_pop_benchmark_compile📈 view plot
🚷 view threshold
9.22 x 1e3
(0.00%)Baseline: 9.22 x 1e3
9.31 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
371.00
(0.00%)Baseline: 371.00
374.71
(99.01%)
🐰 View full continuous benchmarking report in Bencher

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.00000% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.35%. Comparing base (333d10d) to head (810747e).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
.../src/guppylang_internals/compiler/expr_compiler.py 81.63% 9 Missing ⚠️
...pylang-internals/src/guppylang_internals/tys/ty.py 73.68% 5 Missing ⚠️
...ls/src/guppylang_internals/checker/expr_checker.py 95.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2511      +/-   ##
==========================================
- Coverage   93.36%   93.35%   -0.02%     
==========================================
  Files         167      167              
  Lines       16950    17146     +196     
==========================================
+ Hits        15826    16007     +181     
- Misses       1124     1139      +15     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed

codspeed Bot commented Nov 10, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 7 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 11 untouched benchmarks


Comparing codex/fix-generic-borrowed-callbacks-2486 (810747e) with main (7b24318)

Open in CodSpeed

This branch has not been deployed

No deployments
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.

[Bug]: Generic borrowed callbacks fail compilation with copyable arguments

2 participants