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!: Replace GATs with impl Iterator returns (RPITIT) on HugrView #1660

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aborgna-q
Copy link
Collaborator

@aborgna-q aborgna-q commented Nov 15, 2024

This will simplify the update to the next portgraph release (which also moved to RPITIT), avoiding the need to use boxes around iterators to be able to name them.

  • drops the dependency on context-iterators

BREAKING CHANGE: Removed HugrView associated iterator types, replaced with impl Iterator returns.

@aborgna-q aborgna-q requested a review from a team as a code owner November 15, 2024 13:51
Copy link

codecov bot commented Nov 15, 2024

Codecov Report

Attention: Patch coverage is 77.77778% with 34 lines in your changes missing coverage. Please review.

Project coverage is 85.55%. Comparing base (e63878f) to head (212cca8).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
hugr-core/src/hugr/views/descendants.rs 10.00% 18 Missing ⚠️
hugr-core/src/hugr/views/sibling.rs 85.00% 9 Missing ⚠️
hugr-core/src/hugr/views/petgraph.rs 37.50% 5 Missing ⚠️
hugr-core/src/hugr/views.rs 92.30% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1660      +/-   ##
==========================================
+ Coverage   85.51%   85.55%   +0.03%     
==========================================
  Files         136      136              
  Lines       25264    25325      +61     
  Branches    22176    22237      +61     
==========================================
+ Hits        21605    21667      +62     
+ Misses       2455     2453       -2     
- Partials     1204     1205       +1     
Flag Coverage Δ
python 92.42% <ø> (ø)
rust 84.60% <77.77%> (+0.04%) ⬆️

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.

@hugrbot
Copy link
Collaborator

hugrbot commented Nov 15, 2024

This PR contains breaking changes to the public Rust API.
Please deprecate the old API instead (if possible), or mark the PR with a ! to indicate a breaking change.

cargo-semver-checks summary

--- failure trait_removed_associated_type: trait's associated type was removed ---

Description:
A public trait's associated type was removed or renamed.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.36.0/src/lints/trait_removed_associated_type.ron

Failed in:
associated type HugrView::Nodes, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:44
associated type HugrView::NodePorts, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:49
associated type HugrView::Children, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:54
associated type HugrView::Neighbours, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:59
associated type HugrView::PortLinks, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:64
associated type HugrView::NodeConnections, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:69
associated type HugrView::Nodes, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:44
associated type HugrView::NodePorts, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:49
associated type HugrView::Children, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:54
associated type HugrView::Neighbours, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:59
associated type HugrView::PortLinks, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:64
associated type HugrView::NodeConnections, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:69
associated type HugrView::Nodes, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:44
associated type HugrView::NodePorts, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:49
associated type HugrView::Children, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:54
associated type HugrView::Neighbours, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:59
associated type HugrView::PortLinks, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:64
associated type HugrView::NodeConnections, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views.rs:69

--- failure trait_removed_associated_type: trait's associated type was removed ---

Description:
A public trait's associated type was removed or renamed.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.36.0/src/lints/trait_removed_associated_type.ron

Failed in:
associated type CfgNodeMap::Iterator, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-passes/src/nest_cfgs.rs:72

@aborgna-q aborgna-q changed the title feat: Replace GATs with impl Iterator returns (RPITIT) on HugrView feat!: Replace GATs with impl Iterator returns (RPITIT) on HugrView Nov 15, 2024
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.

🙏

@@ -40,36 +37,6 @@ use itertools::Either;
/// A trait for inspecting HUGRs.
/// For end users we intend this to be superseded by region-specific APIs.
pub trait HugrView: HugrInternals {
/// An Iterator over the nodes in a Hugr(View)
Copy link
Member

Choose a reason for hiding this comment

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

🙌

.nodes()
.with_context(self)
.map_with_context(|n, &wrapper| HugrNodeRef::from_node(n, wrapper.hugr))
Box::new(
Copy link
Member

Choose a reason for hiding this comment

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

I'm surprised this is not tested

@@ -251,6 +223,16 @@ pub struct SiblingMut<'g, Root = Node> {
_phantom: std::marker::PhantomData<Root>,
}

impl<'g, Root> SiblingMut<'g, Root> {
Copy link
Member

Choose a reason for hiding this comment

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

is this a drive-by? unrelated?

&self,
node: Node,
port: impl Into<Port>,
) -> impl Iterator<Item = (Node, Port)> + Clone {
// Need to filter only to links inside the sibling graph
Copy link
Member

Choose a reason for hiding this comment

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

this comment now works better at the bottom of the function

}

fn node_connections(&self, node: Node, other: Node) -> Self::NodeConnections<'_> {
fn node_connections(&self, node: Node, other: Node) -> impl Iterator<Item = [Port; 2]> + Clone {
// Need to filter only to connections inside the sibling graph
SiblingGraph::<'_, Node>::new_unchecked(self.hugr, self.root)
Copy link
Member

Choose a reason for hiding this comment

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

would some of these methods also benefit from the portgraph based implementation seen in linked_ports

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.

3 participants