Skip to content

refactor: Simplify validate_subtree#2969

Merged
acl-cqc merged 6 commits intomainfrom
acl/refactor/validate_subtree
Mar 23, 2026
Merged

refactor: Simplify validate_subtree#2969
acl-cqc merged 6 commits intomainfrom
acl/refactor/validate_subtree

Conversation

@acl-cqc
Copy link
Copy Markdown
Contributor

@acl-cqc acl-cqc commented Mar 19, 2026

...now that all FuncDefns are at top level.

closes #2346.

Most of this was done by agentic AI...it worked ok! (Maybe the naming could be better? And I wonder if it has put in too many "obvious" comments)

Also fix unconnected ports in the non_cfg_ancestor test: the new validate_subtree checks nodes in a different order so was hitting these first.

acl-cqc added 5 commits March 18, 2026 18:11
"refactor the validate_subtree method using the fact that FuncDefns are always children of the module_root to turn validate_subtree into an outer loop over module children and an inner loop over the descendants of each FuncDefn using it's var_decls"
"simplify validate_subtree in that only FuncDefn's have descendants, asserting that any other node has no children"
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 74.07407% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.88%. Comparing base (39d047f) to head (98602e0).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
hugr-core/src/hugr/validate.rs 81.81% 4 Missing ⚠️
hugr-core/src/builder/dataflow.rs 40.00% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2969   +/-   ##
=======================================
  Coverage   83.87%   83.88%           
=======================================
  Files         267      268    +1     
  Lines       52941    52949    +8     
  Branches    46857    46861    +4     
=======================================
+ Hits        44404    44415   +11     
+ Misses       6268     6266    -2     
+ Partials     2269     2268    -1     
Flag Coverage Δ
python 88.84% <ø> (+0.04%) ⬆️
rust 83.23% <74.07%> (+<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.

@acl-cqc acl-cqc changed the title Simplify validate subtree refactor: Simplify validate_subtree Mar 19, 2026
@acl-cqc acl-cqc marked this pull request as ready for review March 19, 2026 16:18
@acl-cqc acl-cqc requested a review from a team as a code owner March 19, 2026 16:18
@acl-cqc acl-cqc requested a review from ss2165 March 19, 2026 16:18
/// Error in a [`ExtensionOp`] serialized as an [Opaque].
///
/// [ExtensionOp]: crate::ops::ExtensionOp
/// [`ExtensionOp`]: crate::ops::ExtensionOp
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is your agent enjoying fixing unrelated things?

Copy link
Copy Markdown
Contributor Author

@acl-cqc acl-cqc Mar 20, 2026

Choose a reason for hiding this comment

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

Haha! No, turns out the old [ExtensionOp]: ... was not actually doing anything at all and could have been removed, because the reference in the text of the comment is and was [`ExtensionOp`] - which was working instead because we use ExtensionOp at the top of the file. Agent thought it was being clever and removed the file-level import and broke the docs...which I fixed by hand

};
match op_type {
OpType::ExtensionOp(ext_op) => validate_ext(ext_op)?,
OpType::ExtensionOp(ext_op) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also an unrelated simplification?

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.

Yes but one I asked it to do specifically as a separate step when I saw that the validate_ext closure was only used once

Comment on lines +881 to +882
b_child.finish_with_outputs([b_child_in_wire])?;
let b_child_2 = b.dfg_builder(Signature::new([], [Type::UNIT]), [])?;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

not sure whether the signature changes here are related? Was the test wrong before?

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.

Yeah, I should have mentioned, see inidividual commit comments. The refactor makes validate_subtree process nodes in a different order, so we start hitting UnconnectedPort errors first, rather than the desired nonlocal-edge-error. So I had to fix the ports in order to make the test return the right error...

@acl-cqc acl-cqc requested a review from ss2165 March 20, 2026 18:56
@acl-cqc acl-cqc added this pull request to the merge queue Mar 23, 2026
Merged via the queue into main with commit 5932222 Mar 23, 2026
31 of 32 checks passed
@acl-cqc acl-cqc deleted the acl/refactor/validate_subtree branch March 23, 2026 17:33
@hugrbot hugrbot mentioned this pull request Mar 23, 2026
@hugrbot hugrbot mentioned this pull request Mar 31, 2026
github-merge-queue bot pushed a commit that referenced this pull request Mar 31, 2026
## 🤖 New release

* `hugr-model`: 0.26.1 -> 0.27.0 (✓ API compatible changes)
* `hugr-core`: 0.26.1 -> 0.27.0 (✓ API compatible changes)
* `hugr-llvm`: 0.26.1 -> 0.27.0 (✓ API compatible changes)
* `hugr-persistent`: 0.5.1 -> 0.6.0 (✓ API compatible changes)
* `hugr`: 0.26.1 -> 0.27.0 (✓ API compatible changes)
* `hugr-cli`: 0.26.1 -> 0.27.0 (✓ API compatible changes)

<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.27.0](hugr-core-v0.26.1...hugr-core-v0.27.0)
- 2026-03-31

### Bug Fixes

- Use valid identifiers when constructing AST model
([#2973](#2973))
- Panic on constant folding with opaque consts
([#2986](#2986))

### New Features

- *(py)* Allow missing ext versions ExtensionDesc metadata
([#2979](#2979))
- [**breaking**] Deprecate JSON serialization format
([#2991](#2991))
- [**breaking**] Bump public `portgraph` dependency to `0.16.0`
([#2998](#2998))

### Refactor

- Simplify validate_subtree
([#2969](#2969))
- further cleanups to SiblingSubgraph + generalize over trait
HugrConvexChecker
([#2957](#2957))
</blockquote>

## `hugr-llvm`

<blockquote>

##
[0.27.0](hugr-llvm-v0.26.1...hugr-llvm-v0.27.0)
- 2026-03-31

### New Features

- *(hugr-llvm)* Emit rounding operation for `FloatOps::fround` extension
ops ([#2949](#2949))
</blockquote>

## `hugr-persistent`

<blockquote>

##
[0.6.0](hugr-persistent-v0.5.1...hugr-persistent-v0.6.0)
- 2026-03-31

### New Features

- [**breaking**] Deprecate JSON serialization format
([#2991](#2991))
</blockquote>

## `hugr`

<blockquote>

##
[0.27.0](hugr-v0.26.1...hugr-v0.27.0)
- 2026-03-31

### Bug Fixes

- Use valid identifiers when constructing AST model
([#2973](#2973))
- Panic on constant folding with opaque consts
([#2986](#2986))

### New Features

- *(py)* Allow missing ext versions ExtensionDesc metadata
([#2979](#2979))
- [**breaking**] Bump public `portgraph` dependency to `0.16.0`
([#2998](#2998))
- [**breaking**] Deprecate JSON serialization format
([#2991](#2991))

### Refactor

- Simplify validate_subtree
([#2969](#2969))
- further cleanups to SiblingSubgraph + generalize over trait
HugrConvexChecker
([#2957](#2957))
</blockquote>

## `hugr-cli`

<blockquote>

##
[0.27.0](hugr-cli-v0.26.1...hugr-cli-v0.27.0)
- 2026-03-31

### Bug Fixes

- Do extension resolution on exts loaded by hugr-cli
([#2987](#2987))

### New Features

- *(py)* Allow missing ext versions ExtensionDesc metadata
([#2979](#2979))
- [**breaking**] Deprecate JSON serialization format
([#2991](#2991))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

---------

Co-authored-by: Agustín Borgna <[email protected]>
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.

Refactor: simplify validate_subtree

2 participants