Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Validate Extensions using hierarchy, ignore input_extensions, RIP inference #1142

Merged
merged 35 commits into from
Jun 11, 2024

Conversation

acl-cqc
Copy link
Contributor

@acl-cqc acl-cqc commented May 30, 2024

This is probably phase 1 of 4, later steps being

So, this PR updates validation to ignore the input_extensions, and removes the inference algorithm that would set them. There were a few complications:

  • A lot of tests create a DFGBuilder with an empty delta, then put things in it that have extension requirements. The inference algorithm figures out that this is all OK if it can just put that extension-requirement on the input_extensions to the DFG node (root) itself. So this might be a call for input_extensions - they do reduce the need for Infer extension-requirements for nested DFGs #640 a bit.
    • We can see roughly how painful life is (without delta-inference nor input-extensions) looking at the various extra extension-deltas I've had to specify here
    • I think that given we are under the feature flag at the moment, we are OK to continue, however the need for Infer extension-requirements for nested DFGs #640 is now somewhat increased, so discussion there strongly encouraged, please! :)
  • TailLoop turned out not to have an extension-delta, where it clearly needs one (just as DataflowBlock and others). Also there was an implementation of OpParent for it, whereas in fact we needed DataflowParent as that would also have got us the ValidateOp for free. This all in 08bb5a5.
  • Another bug in DataflowBlock::inner_signature, and some others.

....That is to say, in some ways this validation scheme is stricter than what we had; there is both the slight flexibility that input_extensions gave us in mis-specifying deltas, and that this scheme's simplicity makes it much harder to accidentally omit cases from validation....

I've also kept Hugr::infer_extensions around as a no-op rather than remove it and later bring it back (in #640). Maybe we should remove it, but that would be a breaking change....OTOH I've removed validate_with_extension_closure and in theory we could have that (a closure containing deltas for nested DFGs) too...

BREAKING CHANGE: TailLoop node and associated builder functions now require specifying an ExtensionSet; extension/validate.rs deleted; some changes to Hugrs validated/rejected when the extension_inference feature flag is turned on

@acl-cqc acl-cqc changed the title Validate Extensions using hierarchy (ignore input_extensions) feat!: Validate Extensions using hierarchy (ignore input_extensions) May 30, 2024
Copy link

codecov bot commented May 30, 2024

Codecov Report

Attention: Patch coverage is 94.53925% with 16 lines in your changes missing coverage. Please review.

Project coverage is 86.68%. Comparing base (15c3ea9) to head (546ced4).
Report is 2 commits behind head on main.

Files Patch % Lines
hugr-core/src/hugr/validate/test.rs 93.37% 3 Missing and 8 partials ⚠️
hugr-core/src/builder/tail_loop.rs 81.81% 0 Missing and 2 partials ⚠️
hugr-core/src/hugr/validate.rs 91.30% 2 Missing ⚠️
hugr-core/src/ops/constant.rs 85.71% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1142      +/-   ##
==========================================
- Coverage   87.09%   86.68%   -0.42%     
==========================================
  Files          97       94       -3     
  Lines       19297    17808    -1489     
  Branches    18432    16942    -1490     
==========================================
- Hits        16807    15437    -1370     
+ Misses       1636     1601      -35     
+ Partials      854      770      -84     
Flag Coverage Δ
python 89.37% <100.00%> (+0.01%) ⬆️
rust 86.54% <94.52%> (-0.45%) ⬇️

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.

@acl-cqc acl-cqc requested review from croyzor and ss2165 May 30, 2024 15:48
@acl-cqc acl-cqc marked this pull request as ready for review May 30, 2024 15:48
@acl-cqc acl-cqc requested a review from a team as a code owner May 30, 2024 15:48
@acl-cqc acl-cqc changed the title feat!: Validate Extensions using hierarchy (ignore input_extensions) feat!: Validate Extensions using hierarchy, ignore input_extensions, RIP inference May 31, 2024
@@ -865,11 +864,158 @@ fn test_polymorphic_load() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

#[test]
/// Validation errors in a controlflow subgraph.
fn cfg_children_restrictions() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've moved this out of extension_tests as it has nothing to do with extensions

// /->->\
// | |
// Entry -> Middle -> Exit
fn cfg_connections() -> Result<(), Box<dyn std::error::Error>> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one is kinda new, but also has a kinda connection with one I've removed

#[rstest]
#[case(make_bb, |bb: &mut DFGWrapper<_,_>, outs| bb.make_tuple(outs))]
#[case(make_tailloop, |tl: &mut DFGWrapper<_,_>, outs| tl.make_break(tl.loop_signature().unwrap().clone(), outs))]
fn bb_extension_mismatch<T>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note the <T> here is inferred, so we never have to write it, but is different for make_bb and make_tuple, so switching between the two internally is more awkward than one might think. That type inference allows this is a nice side effect of rstest case :)

Copy link
Member

@ss2165 ss2165 left a comment

Choose a reason for hiding this comment

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

looks great thanks 👍

@acl-cqc acl-cqc added this pull request to the merge queue Jun 11, 2024
Merged via the queue into main with commit 8bec8e9 Jun 11, 2024
22 checks passed
@acl-cqc acl-cqc deleted the extension_hierarchy branch June 11, 2024 18:02
This was referenced Jun 11, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jun 12, 2024
Following #1142 the `input_extensions` are unused, so remove the storage
for them

BREAKING CHANGE: * `add_child_op`(`_with_parent`), etc., gone; use
`add_child_node`(`_with_parent`) with an (impl Into-)OpType.
* `get_nodetype` gone - use `get_optype`.
* `NodeType` gone - use `OpType` directly. 
* Various (Into<)Option<ExtensionSet> params removed from builder
methods especially {cfg_,dfg_}builder.
* `input_extensions` removed from serialization schema.
github-merge-queue bot pushed a commit that referenced this pull request Jun 14, 2024
Removes the conditional test skip introduced in
#1168 (comment), now that
#1142 is merged.
@hugrbot hugrbot mentioned this pull request Jun 28, 2024
@hugrbot hugrbot mentioned this pull request Jun 28, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jul 1, 2024
## 🤖 New release
* `hugr`: 0.5.1 -> 0.6.0
* `hugr-core`: 0.2.0 -> 0.3.0
* `hugr-passes`: 0.2.0 -> 0.3.0
* `hugr-cli`: 0.1.1 -> 0.1.2

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

## `hugr`
<blockquote>

## 0.6.0 (2024-06-28)

### Bug Fixes

- SimpleReplacement panic on multiports
([#1191](#1191))
- Add some validation for const nodes
([#1222](#1222))
- Cfg not validating entry/exit types
([#1229](#1229))
- `extract_hugr` not removing root node ports
([#1239](#1239))

### Documentation

- Fix documentation of `ValidationError::ConstTypeError`
([#1227](#1227))

### Features

- CircuitBuilder::add_constant
([#1168](#1168))
- [**breaking**] Make the rewrite errors more useful
([#1174](#1174))
- [**breaking**] Validate Extensions using hierarchy, ignore
input_extensions, RIP inference
([#1142](#1142))
- [**breaking**] Infer extension deltas for Case, Cfg, Conditional,
DataflowBlock, Dfg, TailLoop
([#1195](#1195))
- Helper functions for requesting inference, use with builder in tests
([#1219](#1219))

### Refactor

- [**breaking**] FunctionBuilder takes impl Into<PolyFuncType>
([#1220](#1220))
- [**breaking**] Remove NodeType and input_extensions
([#1183](#1183))
</blockquote>

## `hugr-core`
<blockquote>

## 0.3.0 (2024-06-28)

### Bug Fixes

- SimpleReplacement panic on multiports
([#1191](#1191))
- Add some validation for const nodes
([#1222](#1222))
- Cfg not validating entry/exit types
([#1229](#1229))
- `extract_hugr` not removing root node ports
([#1239](#1239))

### Documentation

- Fix documentation of `ValidationError::ConstTypeError`
([#1227](#1227))

### Features

- CircuitBuilder::add_constant
([#1168](#1168))
- [**breaking**] Make the rewrite errors more useful
([#1174](#1174))
- [**breaking**] Validate Extensions using hierarchy, ignore
input_extensions, RIP inference
([#1142](#1142))
- [**breaking**] Infer extension deltas for Case, Cfg, Conditional,
DataflowBlock, Dfg, TailLoop
([#1195](#1195))
- Helper functions for requesting inference, use with builder in tests
([#1219](#1219))

### Refactor

- [**breaking**] Remove NodeType and input_extensions
([#1183](#1183))
- [**breaking**] FunctionBuilder takes impl Into<PolyFuncType>
([#1220](#1220))
</blockquote>

## `hugr-passes`
<blockquote>

## 0.3.0 (2024-06-28)

### Features

- [**breaking**] Validate Extensions using hierarchy, ignore
input_extensions, RIP inference
([#1142](#1142))
- Helper functions for requesting inference, use with builder in tests
([#1219](#1219))

</blockquote>

## `hugr-cli`
<blockquote>

## 0.1.1 (2024-06-07)

### Features

- Reexport `clap::Parser` and `clap_verbosity_flag::Level` from hugr_cli
([#1146](#1146))

### Refactor

- Move binary to hugr-cli
([#1134](#1134))
</blockquote>


</p></details>

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

---------

Co-authored-by: Douglas Wilson <[email protected]>
@hugrbot hugrbot mentioned this pull request Jul 1, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jul 3, 2024
🤖 I have created a release *beep* *boop*
---


##
[0.3.0](hugr-py-v0.2.1...hugr-py-v0.3.0)
(2024-07-03)


### ⚠ BREAKING CHANGES

* * `add_child_op`(`_with_parent`), etc., gone; use
`add_child_node`(`_with_parent`) with an (impl Into-)OpType.
    * `get_nodetype` gone - use `get_optype`.
    * `NodeType` gone - use `OpType` directly. 
    * Various (Into<)Option<ExtensionSet> params removed from builder
    methods especially {cfg_,dfg_}builder.
    * `input_extensions` removed from serialization schema.
* the Signature class is gone, but it's not clear how or why you might
have been using it...
* TailLoop node and associated builder functions now require specifying
an ExtensionSet; extension/validate.rs deleted; some changes to Hugrs
validated/rejected when the `extension_inference` feature flag is turned
on
* Type::validate takes extra bool (allow_rowvars); renamed
{FunctionType, PolyFuncType}::(validate=>validate_var_len).

### Features

* Allow "Row Variables" declared as List&lt;Type&gt;
([#804](#804))
([3ea4834](3ea4834))
* **hugr-py:** add builders for Conditional and TailLoop
([#1210](#1210))
([43569a4](43569a4))
* **hugr-py:** add CallIndirect, LoadFunction, Lift, Alias
([#1218](#1218))
([db09193](db09193)),
closes [#1213](#1213)
* **hugr-py:** add values and constants
([#1203](#1203))
([f7ea178](f7ea178)),
closes [#1202](#1202)
* **hugr-py:** automatically add state order edges for inter-graph edges
([#1165](#1165))
([5da06e1](5da06e1))
* **hugr-py:** builder for function definition/declaration and call
([#1212](#1212))
([af062ea](af062ea))
* **hugr-py:** builder ops separate from serialised ops
([#1140](#1140))
([342eda3](342eda3))
* **hugr-py:** CFG builder
([#1192](#1192))
([c5ea47f](c5ea47f)),
closes [#1188](#1188)
* **hugr-py:** define type hierarchy separate from serialized
([#1176](#1176))
([10f4c42](10f4c42))
* **hugr-py:** only require input type annotations when building
([#1199](#1199))
([2bb079f](2bb079f))
* **hugr-py:** python hugr builder
([#1098](#1098))
([23408b5](23408b5))
* **hugr-py:** store children in node weight
([#1160](#1160))
([1cdaeed](1cdaeed)),
closes [#1159](#1159)
* **hugr-py:** ToNode interface to treat builders as nodes
([#1193](#1193))
([1da33e6](1da33e6))
* Validate Extensions using hierarchy, ignore input_extensions, RIP
inference ([#1142](#1142))
([8bec8e9](8bec8e9))


### Bug Fixes

* Add some validation for const nodes
([#1222](#1222))
([c05edd3](c05edd3))
* **hugr-py:** more ruff lints + fix some typos
([#1246](#1246))
([f158384](f158384))
* **py:** get rid of pydantic config deprecation warnings
([#1084](#1084))
([52fcb9d](52fcb9d))


### Documentation

* **hugr-py:** add docs link to README
([#1259](#1259))
([d2a9148](d2a9148))
* **hugr-py:** build and publish docs
([#1253](#1253))
([902fc14](902fc14))
* **hugr-py:** docstrings for builder
([#1231](#1231))
([3e4ac18](3e4ac18))


### Code Refactoring

* Remove "Signature" from hugr-py
([#1186](#1186))
([65718f7](65718f7))
* Remove NodeType and input_extensions
([#1183](#1183))
([ea5213d](ea5213d))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: hugrbot <[email protected]>
Co-authored-by: Seyon Sivarajah <[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.

Can't define a circuit with constant parameters
3 participants