Skip to content

fix: ConstantFold fails when the module contains function declarations#2954

Merged
aborgna-q merged 1 commit intomainfrom
ab/fix-constfold-decl
Mar 17, 2026
Merged

fix: ConstantFold fails when the module contains function declarations#2954
aborgna-q merged 1 commit intomainfrom
ab/fix-constfold-decl

Conversation

@aborgna-q
Copy link
Copy Markdown
Collaborator

No description provided.

@aborgna-q aborgna-q requested a review from acl-cqc March 17, 2026 15:49
@aborgna-q aborgna-q requested a review from a team as a code owner March 17, 2026 15:49
@aborgna-q aborgna-q changed the title fix: ConstantFoild fails when the module contains function declarations fix: ConstantFold fails when the module contains function declarations Mar 17, 2026
@aborgna-q aborgna-q force-pushed the ab/fix-constfold-decl branch from 325fa4b to c7432ea Compare March 17, 2026 15:52
// Cannot prepopulate inputs for module-root; do not `join` with inputs explicitly specified.
continue;
}
if hugr.children(node).next().is_none() {
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.

|| !hugr.get_optype(node).is_func_defn() on the previous?

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.

Or change node == hugr.module_root() to !OpTag.DataflowParent.is_superset(hugr.get_optype(node).tag()) ?

We assume that if it has no children, we cannot do constant-propagation on it....but that is not necessarily the case; inlining a Call preserves its interface. But I don't think there is any situation where a PassScope would have a Call in its preserve_interface except for the call being entrypoint, in which case constant-folding won't do anything.

Copy link
Copy Markdown
Collaborator Author

@aborgna-q aborgna-q Mar 17, 2026

Choose a reason for hiding this comment

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

PassScope::preserve_interface states

Returns a list of nodes, in the subtree beneath [Self::root], for which the pass must preserve the observable semantics (ports, execution behaviour, linking).

That could technically return an arbitrary non-container node, and prepopulate_inputs would fail with any of them.

Copy link
Copy Markdown
Contributor

@acl-cqc acl-cqc left a comment

Choose a reason for hiding this comment

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

Yah, gotta do something, and anything that makes that test not fail sounds good ;-).
(I'm a little skeptical of the "has no children" filter, it is common but it seems a bit of an abuse.)

@aborgna-q aborgna-q enabled auto-merge March 17, 2026 16:13
@aborgna-q aborgna-q added this pull request to the merge queue Mar 17, 2026
Merged via the queue into main with commit de7b9f7 Mar 17, 2026
28 checks passed
@aborgna-q aborgna-q deleted the ab/fix-constfold-decl branch March 17, 2026 16:22
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.85%. Comparing base (1948767) to head (c7432ea).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
hugr-passes/src/const_fold/test.rs 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2954      +/-   ##
==========================================
+ Coverage   83.84%   83.85%   +0.01%     
==========================================
  Files         267      267              
  Lines       52923    52966      +43     
  Branches    46854    46882      +28     
==========================================
+ Hits        44371    44414      +43     
  Misses       6283     6283              
  Partials     2269     2269              
Flag Coverage Δ
python 88.80% <ø> (+0.04%) ⬆️
rust 83.21% <92.85%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

@hugrbot hugrbot mentioned this pull request Mar 17, 2026
github-merge-queue bot pushed a commit that referenced this pull request Mar 19, 2026
## 🤖 New release

* `hugr-model`: 0.26.0 -> 0.26.1
* `hugr-core`: 0.26.0 -> 0.26.1 (✓ API compatible changes)
* `hugr-llvm`: 0.26.0 -> 0.26.1
* `hugr`: 0.26.0 -> 0.26.1 (✓ API compatible changes)
* `hugr-passes`: 0.26.0 -> 0.26.1 (✓ API compatible changes)
* `hugr-cli`: 0.26.0 -> 0.26.1
* `hugr-persistent`: 0.5.0 -> 0.5.1

<details><summary><i><b>Changelog</b></i></summary><p>

## `hugr-model`

<blockquote>

##
[0.26.0](hugr-model-v0.25.7...hugr-model-v0.26.0)
- 2026-03-16

### Testing

- Replace model text snapshots with roundtrip tests
([#2933](#2933))
- Add missing width arg in model-call example
([#2945](#2945))
</blockquote>

## `hugr-core`

<blockquote>

##
[0.26.1](hugr-core-v0.26.0...hugr-core-v0.26.1)
- 2026-03-18

### New Features

- *(hugr-py)* Allow linking packages and modules from Python
([#2947](#2947))

### Refactor

- start cleaning up SiblingSubgraph convexity checking
([#2956](#2956))
</blockquote>

## `hugr-llvm`

<blockquote>

##
[0.26.0](hugr-llvm-v0.25.7...hugr-llvm-v0.26.0)
- 2026-03-16

### New Features

- *(llvm)* [**breaking**] Upgrade to LLVM 21
([#2901](#2901))
- Include private HUGR functions in the local symbol table
([#2831](#2831))
- [**breaking**] TypeRow: add impl From array of Type, remove From<Type>
([#2784](#2784))

### Refactor

- [**breaking**] Remove deprecated Value::Function
([#2928](#2928))
- [**breaking**] Remove deprecated stack_array codegen
([#2929](#2929))
</blockquote>

## `hugr`

<blockquote>

##
[0.26.1](hugr-v0.26.0...hugr-v0.26.1)
- 2026-03-18

### Bug Fixes

- ConstantFold fails when the module contains function declarations
([#2954](#2954))

### New Features

- *(hugr-py)* Allow linking packages and modules from Python
([#2947](#2947))

### Refactor

- start cleaning up SiblingSubgraph convexity checking
([#2956](#2956))
</blockquote>

## `hugr-passes`

<blockquote>

##
[0.26.1](hugr-passes-v0.26.0...hugr-passes-v0.26.1)
- 2026-03-18

### Bug Fixes

- ConstantFold fails when the module contains function declarations
([#2954](#2954))
</blockquote>

## `hugr-cli`

<blockquote>

##
[0.26.0](hugr-cli-v0.25.7...hugr-cli-v0.26.0)
- 2026-03-16

### Documentation

- Move `spec/schema` and `spec/std_extensions` to `resources/`
([#2897](#2897))

### New Features

- [**breaking**] Rename ModelText envelope format to SExpression
([#2927](#2927))
- [**breaking**] TypeRow: add impl From array of Type, remove From<Type>
([#2784](#2784))
</blockquote>

## `hugr-persistent`

<blockquote>

##
[0.5.0](hugr-persistent-v0.4.7...hugr-persistent-v0.5.0)
- 2026-03-16

### New Features

- *(llvm)* [**breaking**] Upgrade to LLVM 21
([#2901](#2901))
- [**breaking**] TypeRow: add impl From array of Type, remove From<Type>
([#2784](#2784))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).
github-merge-queue bot pushed a commit to Quantinuum/tket2 that referenced this pull request Mar 19, 2026
Updates the hugr dependencies to `0.26.0`, and fixes all the breaking
changes.

I only added no-op stubs implementing `WithScope` for the local passes.
We will add the actual implementation in
#1429.

Requires updating LLVM too, so we should merge
#1422 into this PR. We also need
to delete the now removed `stack_array` lowering.

BREAKING CHANGE: Updated public `hugr` dependency to `0.26.0`.

Requires a `hugr-passes 0.26.1` patch release to include
Quantinuum/hugr#2954

---------

Co-authored-by: George Hodgkins <[email protected]>
Co-authored-by: Jake Arkinstall <[email protected]>
This was referenced Mar 23, 2026
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