-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@@ -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; |
There was a problem hiding this comment.
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`).
There was a problem hiding this 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.
hugr-core/src/extension.rs
Outdated
@@ -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(); |
There was a problem hiding this comment.
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; | ||
} |
There was a problem hiding this comment.
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
)
hugr-core/src/extension.rs
Outdated
types: Default::default(), | ||
values: Default::default(), | ||
operations: Default::default(), | ||
} | ||
} | ||
|
||
/// Creates a new extension with the given name and requirements. |
There was a problem hiding this comment.
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
hugr-core/src/extension/simple_op.rs
Outdated
@@ -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)); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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....
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added remove
## 🤖 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>
Closes #1357
BREAKING CHANGE:
Extension::new
now requires aVersion
argument.Extension::new_with_reqs
replaced withwith_reqs
which takesself
(chain withnew
).