Skip to content

fix: preserve barriers and static array outputs in comptime - #2263

Open
trvto wants to merge 1 commit into
mainfrom
tt/comptime-barrier
Open

trvto wants to merge 1 commit into
mainfrom
tt/comptime-barrier

Conversation

@trvto

@trvto trvto commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

closes #1190
closes #1189

This PR adds support for using barriers with values produced or manipulated inside guppy.comptime.

It applies the same tracing behavior to array output calls, allowing arrays containing static values to remain static after the call and avoiding unnecessary borrow/repacking operations.

Changes:

  • Implement BarrierChecker.compute_input_flags, marking every barrier argument as Inout.

    • Supports linear arguments such as qubits and also preserves dependencies for dynamic, copyable values so barrier operations remain present in the compiled HUGR.
  • Add an opt-in preserves_static_inout_values property to custom call checkers.

    • The default is False, preserving existing custom-function behavior.
    • When enabled, tracing reconnects dynamic values to the call outputs while retaining static Python values.
  • Enable static inout preservation for:

    • barrier
    • array output overloads
  • Update packed-value reconstruction to:

    • propagate static-value preservation through tuples, structs, and arrays;
    • update the backing wire of dynamic enum values without replacing their Python wrapper.
  • Add array-output tests covering static and mixed static/dynamic arrays.

Motivation:

Previously, passing a linear value such as a qubit to barrier inside guppy.comptime failed because the custom checker did not implement compute_input_flags. Dynamic copyable inputs also need to be treated as inout values so the barrier remains connected to the surrounding dataflow and is not eliminated from the compiled HUGR.

Some inout operations, such as array output, should also preserve static Python values instead of replacing them with runtime output representations. The new checker property allows for this.

@trvto
trvto requested a review from a team as a code owner September 1, 2026 12:24
@trvto
trvto requested a review from mark-koch September 1, 2026 12:24
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectguppylang
Branchtt/comptime-barrier
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
62.10 x 1e3
(0.00%)Baseline: 62.10 x 1e3
62.72 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
4,585.00
(0.00%)Baseline: 4,585.00
4,630.85
(99.01%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
27.83 x 1e3
(0.00%)Baseline: 27.83 x 1e3
28.11 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
1,301.00
(0.00%)Baseline: 1,301.00
1,314.01
(99.01%)
tests/benchmarks/test_queue_push_pop.py::test_queue_push_benchmark_compile📈 view plot
🚷 view threshold
7.24 x 1e3
(0.00%)Baseline: 7.24 x 1e3
7.32 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
310.00
(0.00%)Baseline: 310.00
313.10
(99.01%)
tests/benchmarks/test_queue_push_pop.py::test_queue_push_pop_benchmark_compile📈 view plot
🚷 view threshold
9.91 x 1e3
(0.00%)Baseline: 9.91 x 1e3
10.01 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
411.00
(0.00%)Baseline: 411.00
415.11
(99.01%)
🐰 View full continuous benchmarking report in Bencher

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.28%. Comparing base (1f76a78) to head (88a4bc9).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2263   +/-   ##
=======================================
  Coverage   93.28%   93.28%           
=======================================
  Files         160      160           
  Lines       15378    15392   +14     
=======================================
+ Hits        14345    14359   +14     
  Misses       1033     1033           

☔ 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-hq

codspeed-hq Bot commented Sep 1, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 11 untouched benchmarks


Comparing tt/comptime-barrier (88a4bc9) with main (efcf084)

Open in CodSpeed

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.

custom checker varargs functions fail in comptime with unhelpful error Support varags functions in comptime

2 participants