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!: Extension requires a version #1367

Merged
merged 6 commits into from
Jul 29, 2024
Merged

feat!: Extension requires a version #1367

merged 6 commits into from
Jul 29, 2024

Conversation

ss2165
Copy link
Member

@ss2165 ss2165 commented Jul 25, 2024

Closes #1357

BREAKING CHANGE: Extension::new now requires a Version argument. Extension::new_with_reqs replaced with with_reqs which takes self (chain with new).

@ss2165 ss2165 requested a review from a team as a code owner July 25, 2024 15:35
@ss2165 ss2165 requested a review from acl-cqc July 25, 2024 15:35
Copy link

codecov bot commented Jul 25, 2024

Codecov Report

Attention: Patch coverage is 98.27586% with 1 line in your changes missing coverage. Please review.

Project coverage is 87.71%. Comparing base (1218d21) to head (8824b7a).
Report is 2 commits behind head on main.

Files Patch % Lines
hugr-core/src/extension.rs 98.07% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1367      +/-   ##
==========================================
+ Coverage   87.64%   87.71%   +0.06%     
==========================================
  Files         113      113              
  Lines       20030    20059      +29     
  Branches    17764    17793      +29     
==========================================
+ Hits        17556    17594      +38     
+ Misses       1699     1691       -8     
+ Partials      775      774       -1     
Flag Coverage Δ
python 91.52% <ø> (ø)

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.

@ss2165 ss2165 removed the request for review from acl-cqc July 25, 2024 15:39
@ss2165 ss2165 marked this pull request as draft July 25, 2024 15:39
@ss2165 ss2165 marked this pull request as ready for review July 25, 2024 16:11
@ss2165 ss2165 requested a review from acl-cqc July 25, 2024 16:12
@@ -3,6 +3,7 @@
//! TODO: YAML declaration and parsing. This should be similar to a plugin
//! system (outside the `types` module), which also parses nested [`OpDef`]s.

pub use semver::Version;
Copy link
Member Author

Choose a reason for hiding this comment

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

pub so downstream crates don't need to add a semver dependency

BREAKING CHANGE: `Extension::new` now requires a `Version` argument. `Extension::new_with_reqs` replaced with `with_reqs` which takes `self` (chain with `new`).
Copy link
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.

Generally great, thanks @ss2165, tho a few questions in comments.

@@ -57,10 +58,13 @@ impl ExtensionRegistry {
) -> Result<Self, ExtensionRegistryError> {
let mut exts = BTreeMap::new();
for ext in value.into_iter() {
let ext_v = ext.version().clone();
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks fine, but does look like you could make an empty ExtensionRegistry and then just do value.into_iter().for_each(|e| reg.register(e))

btree_map::Entry::Occupied(mut prev) => {
if prev.get().version() < extension.version() {
*prev.get_mut() = extension;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth a note that ideally we would check the extensions were identical but this is not possible (no Eq)

types: Default::default(),
values: Default::default(),
operations: Default::default(),
}
}

/// Creates a new extension with the given name and requirements.
Copy link
Contributor

Choose a reason for hiding this comment

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

Update this. Maybe better to keep the old requirements and merge in the new ones, rather than replace/drop the old ones, too

@@ -319,7 +319,7 @@ mod test {

lazy_static! {
static ref EXT: Extension = {
let mut e = Extension::new(EXT_ID.clone());
let mut e = Extension::new(EXT_ID.clone(), semver::Version::new(0, 1, 0));
Copy link
Contributor

Choose a reason for hiding this comment

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

consider a test-only impl Extension { fn new(id: ExtensionId) {Self::new(id, TEST_VERSION)} }

@@ -80,9 +80,12 @@ pub const PTR_TYPE_ID: TypeName = TypeName::new_inline("ptr");
const TYPE_PARAMS: [TypeParam; 1] = [TypeParam::Type {
b: TypeBound::Copyable,
}];
/// Extension version.
pub const VERSION: semver::Version = semver::Version::new(0, 1, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I'm less sure what's appropriate for all the std / non-test extensions already in the repo. I guess this is fine.

@@ -178,7 +178,7 @@ mod test {
}

fn extension() -> Extension {
let mut e = Extension::new(EXT_ID);
let mut e = Extension::new(EXT_ID, hugr_core::extension::Version::new(0, 1, 0));
Copy link
Contributor

Choose a reason for hiding this comment

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

super-optional-nit, we're not terribly consistent about using hugr_core::extension::Version vs semver::Version. Possibly this one is right and the others would be better done this way too...

Copy link
Member Author

Choose a reason for hiding this comment

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

I use semver inside the hugr-core crate and hugr_core:: outside

)),
btree_map::Entry::Vacant(ve) => Ok(ve.insert(extension)),
}
}

/// Registers a new extension to the registry, keeping most up to date if extension exists.
///
/// If extension IDs match, the extension with the higher version is kept.
Copy link
Contributor

Choose a reason for hiding this comment

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

I note we are not really doing anything with Semver here (it could be any totally-ordered thing), and I wonder whether this should be the place. Replacing an extension with a breaking-change-upgrade could be problematic; should we

  • have a boolean flag here, allow breaking-change upgrades
  • keep multiple major versions of the extension (a single minor version of each)? I think this will be too difficult because then we'd have to version every reference to an extension.
  • Error on any breaking-change upgrade
  • Do something at Hugr validation time. In which case maybe just the checks we have are sufficient, so maybe the right answer is to do nothing, i.e. leave PR as it stands....

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I think I prefer to keep the logic here simple and flexible and deal with valid
updates etc. elsewhere.

Maybe I should add a "remove" function so the registry is actually fully flexible, and
this is just a utility for update-only changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

added remove

@ss2165 ss2165 added this pull request to the merge queue Jul 29, 2024
Merged via the queue into main with commit b2d4013 Jul 29, 2024
22 checks passed
@ss2165 ss2165 deleted the ss/ext-version branch July 29, 2024 12:51
@hugrbot hugrbot mentioned this pull request Jul 29, 2024
github-merge-queue bot pushed a commit that referenced this pull request Aug 12, 2024
## 🤖 New release
* `hugr`: 0.10.0 -> 0.11.0
* `hugr-core`: 0.7.0 -> 0.8.0
* `hugr-passes`: 0.6.2 -> 0.7.0
* `hugr-cli`: 0.3.0 -> 0.4.0

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

## `hugr`
<blockquote>

## 0.11.0 (2024-08-12)

### Bug Fixes

- [**breaking**] BasicBlockExits should not be `OpTag::DataflowParent`
([#1409](#1409))

### Documentation

- Clarify CustomConst::equal_consts
([#1396](#1396))

### Features

- [**breaking**] Serialised extensions
([#1371](#1371))
- Serialised standard extensions
([#1377](#1377))
- [**breaking**] Update remaining builder methods to "infer by default"
([#1386](#1386))
- Add Eq op to logic extension
([#1398](#1398))
- Improve error message on failed custom op validation
([#1416](#1416))
- [**breaking**] `Extension` requires a version
([#1367](#1367))
</blockquote>

## `hugr-core`
<blockquote>

## 0.8.0 (2024-08-12)

### Bug Fixes

- [**breaking**] BasicBlockExits should not be `OpTag::DataflowParent`
([#1409](#1409))

### Documentation

- Clarify CustomConst::equal_consts
([#1396](#1396))

### Features

- [**breaking**] `Extension` requires a version
([#1367](#1367))
- [**breaking**] Serialised extensions
([#1371](#1371))
- Serialised standard extensions
([#1377](#1377))
- [**breaking**] Update remaining builder methods to "infer by default"
([#1386](#1386))
- Add Eq op to logic extension
([#1398](#1398))
- Improve error message on failed custom op validation
([#1416](#1416))
</blockquote>

## `hugr-passes`
<blockquote>

## 0.7.0 (2024-08-12)

### Features

- [**breaking**] `Extension` requires a version
([#1367](#1367))
</blockquote>

## `hugr-cli`
<blockquote>

## 0.4.0 (2024-08-12)

### Features

- Serialised standard extensions
([#1377](#1377))
- Validate with extra extensions and packages
([#1389](#1389))
- [**breaking**] Move mermaid to own sub-command
([#1390](#1390))
</blockquote>


</p></details>

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

---------

Co-authored-by: Craig Roy <craig.roy@cambridgequantum.com>
@hugrbot hugrbot mentioned this pull request Aug 13, 2024
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.

Add versions to serialised extensions
2 participants