Skip to content

fix(errors): error on loading polymorphic function - #2213

Open
acl-cqc wants to merge 2 commits into
mainfrom
acl/check_poly_load
Open

acl-cqc wants to merge 2 commits into
mainfrom
acl/check_poly_load

Conversation

@acl-cqc

@acl-cqc acl-cqc commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

(Stumbled across this while investigating another issue, but nonetheless this seems an improvement.)

Currently if you assign a polymorphic function to a variable you get an error during compilation, not checking. Turned out we didn't have a test of this at all, so have added one...

(See new tests in first commit which are passing on main)

In a couple of cases this leads to checking issuing a different error, and of course we never get to the one that would be issued later in compilation, so detecting the error earlier leads to a change in message.

I reason that assignment is the only case where we care:

  • If the poly-function is used as an argument, type inference will be used, and infer an instantiation. We could do this for assignment (i.e. to find an instantiation where the variable is used only monomorphically), e.g. perhaps by searching across the basic block, so maybe Type inference doesn't work across basic blocks #707 is in fact an understatement (type inference doesn't even work across a single BB yet...)
  • For a top-level expression (foo where that's a poly-function), we don't need to find an instantiation, so it seems fine not to.


Help: Consider adding type annotations to coerce them into opaque function
values: `baz: Function[[?T], ?T] = ...`
| ^^^ Polymorphic functions as dynamic higher-order values are not

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I mean, maybe this test is entirely redundant given the new one in poly_callable.py ?

@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectguppylang
Branchacl/check_poly_load
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.30%. Comparing base (ec1e2e4) to head (304b55b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2213      +/-   ##
==========================================
+ Coverage   93.29%   93.30%   +0.01%     
==========================================
  Files         160      160              
  Lines       15261    15270       +9     
==========================================
+ Hits        14238    14248      +10     
+ Misses       1023     1022       -1     

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

@acl-cqc
acl-cqc marked this pull request as ready for review August 17, 2026 13:23
@acl-cqc
acl-cqc requested a review from a team as a code owner August 17, 2026 13:23
@acl-cqc
acl-cqc requested a review from croyzor August 17, 2026 13:23
@codspeed-hq

codspeed-hq Bot commented Aug 17, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 11 untouched benchmarks


Comparing acl/check_poly_load (304b55b) with main (5fb7ce4)

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.

2 participants