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

refactor!: remove Value::Tuple #1255

Merged
merged 3 commits into from
Jul 3, 2024
Merged

refactor!: remove Value::Tuple #1255

merged 3 commits into from
Jul 3, 2024

Conversation

ss2165
Copy link
Member

@ss2165 ss2165 commented Jul 2, 2024

Closes #1206

uses new serialisation intermediary to keep serialized Tuple backwards compatibility

Snaps updated because a tuple-like sum always uses tuple display now

BREAKING CHANGE: Value::Tuple removed. Value::Sum now holds a standalone struct Sum

@ss2165 ss2165 requested a review from a team as a code owner July 2, 2024 13:21
@ss2165 ss2165 requested review from croyzor and doug-q and removed request for croyzor July 2, 2024 13:21
Copy link

codecov bot commented Jul 2, 2024

Codecov Report

Attention: Patch coverage is 97.12230% with 4 lines in your changes missing coverage. Please review.

Project coverage is 87.05%. Comparing base (8f08b8c) to head (689ed6a).
Report is 1 commits behind head on main.

Files Patch % Lines
hugr-core/src/ops/constant.rs 97.67% 3 Missing ⚠️
hugr-core/src/types.rs 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1255      +/-   ##
==========================================
+ Coverage   86.98%   87.05%   +0.06%     
==========================================
  Files         102      102              
  Lines       19108    19223     +115     
  Branches    17015    17130     +115     
==========================================
+ Hits        16622    16734     +112     
- Misses       1709     1713       +4     
+ Partials      777      776       -1     
Flag Coverage Δ
rust 86.54% <97.12%> (+0.07%) ⬆️

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.

uses new serialisation intermediary to keep serialized Tuple backwards compatibility

BREAKING: `Value::Sum` now holds a standalone struct `Sum`
Copy link
Collaborator

@doug-q doug-q left a comment

Choose a reason for hiding this comment

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

This is great. I especially like SumSerial. Could you add a small test that deserialises json with both Sums and Values serialised the old way?

Self {
tag: value.tag,
values: value.values,
sum_type: Some(value.sum_type),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
sum_type: Some(value.sum_type),
(value.sum_type.num_variants() > 1).then_some(value.sum_type),

Copy link
Member Author

Choose a reason for hiding this comment

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

this is schema breaking - Sums are not allowed to have null sum_type

(we won't be generating serialised "Tuple" from the rust any longer, I think to do that we would need to implement Serialize for Value manually, which is annoying).

I'm happy with this compromise, but to really keep the "serialised tuple" optimisation I think we would want to rethink the serialised schema

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, that is annoying.

#[serde(default)]
tag: usize,
#[serde(rename = "vs")]
values: Vec<Value>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we could omit this when it is empty. Value::unary_unit_sum would then omit all fields! Relevant for values of any unary sum type. Perhaps this would be better as a future improvement.

sum_type.check_type(*tag, values)?;
Ok(())
}
}
}

/// If value is a sum with a single row variant, return the row.
pub fn as_tuple(&self) -> Option<&[Value]> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you should add this method to Sum as well, and delegate to that here.

@ss2165 ss2165 requested a review from doug-q July 3, 2024 11:21
@ss2165 ss2165 enabled auto-merge July 3, 2024 11:21
@ss2165 ss2165 added this pull request to the merge queue Jul 3, 2024
Merged via the queue into main with commit b965202 Jul 3, 2024
20 checks passed
@ss2165 ss2165 deleted the ss/no-tuple branch July 3, 2024 14:05
@hugrbot hugrbot mentioned this pull request Jul 3, 2024
github-merge-queue bot pushed a commit that referenced this pull request Jul 10, 2024
## 🤖 New release
* `hugr`: 0.6.1 -> 0.7.0
* `hugr-core`: 0.3.1 -> 0.4.0
* `hugr-passes`: 0.3.0 -> 0.4.0
* `hugr-cli`: 0.1.2 -> 0.1.3

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

## `hugr`
<blockquote>

## 0.7.0 (2024-07-10)

### Bug Fixes

- Bring back input_extensions serialized field in rust NodeSer
([#1275](#1275))
- [**breaking**] `ops::Module` now empty struct rather than unit struct
([#1271](#1271))

### Features

- Add `force_order` pass.
([#1285](#1285))
- [**breaking**] `MakeOpDef` has new `extension` method.
([#1266](#1266))

### Refactor

- [**breaking**] Remove `Value::Tuple`
([#1255](#1255))
- [**breaking**] Rename `HugrView` function type methods + simplify
behaviour ([#1265](#1265))

### Styling

- Change "serialise" etc to "serialize" etc.
([#1251](#1251))

### Testing

- Add a test for [#1257](#1257)
([#1260](#1260))
</blockquote>

## `hugr-core`
<blockquote>

## 0.4.0 (2024-07-10)

### Bug Fixes

- Bring back input_extensions serialized field in rust NodeSer
([#1275](#1275))
- [**breaking**] `ops::Module` now empty struct rather than unit struct
([#1271](#1271))

### Features

- [**breaking**] `MakeOpDef` has new `extension` method.
([#1266](#1266))

### Refactor

- [**breaking**] Remove `Value::Tuple`
([#1255](#1255))
- [**breaking**] Rename `HugrView` function type methods + simplify
behaviour ([#1265](#1265))

### Styling

- Change "serialise" etc to "serialize" etc.
([#1251](#1251))

### Testing

- Add a test for [#1257](#1257)
([#1260](#1260))
</blockquote>

## `hugr-passes`
<blockquote>

## 0.4.0 (2024-07-10)

### Features

- Add `force_order` pass.
([#1285](#1285))

### Refactor

- [**breaking**] Remove `Value::Tuple`
([#1255](#1255))
</blockquote>

## `hugr-cli`
<blockquote>

## 0.1.3 (2024-07-10)

### Styling

- Change "serialise" etc to "serialize" etc.
([#1251](#1251))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/MarcoIeni/release-plz/).
@hugrbot hugrbot mentioned this pull request Jul 11, 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.

Remove Value::Tuple
2 participants