Skip to content

Conversation

@acl-cqc
Copy link
Contributor

@acl-cqc acl-cqc commented May 14, 2025

Accessors ::func_name, ::func_name_mut, ::signature, ::signature_mut.

Constructor ::new takes name + sig using impl Into.

BREAKING CHANGE: construction, destruction, and field access should use new methods

@acl-cqc acl-cqc requested a review from ss2165 May 14, 2025 09:24
@acl-cqc acl-cqc requested a review from a team as a code owner May 14, 2025 09:24
Comment on lines +66 to +67
/// Create a new instance with the given name and signature
pub fn new(name: impl Into<String>, signature: impl Into<PolyFuncType>) -> Self {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Couldn't we just add new_public now, since it's what it's effectively doing?

Copy link
Member

Choose a reason for hiding this comment

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

I think new is the right move now since the semantics of "public" are not defined yet, we can deprecate it when adding new_public and new_private which will indicate downstream that changes are required because linters will complain (even though it will be non-breaking)

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 don't think it is. Quite a lot of code (e.g. dataflow analyses) takes an explicit list of entry points rather than assuming functions are public/private. Moreover, public functions not child of the Module, will likely become illegal...

Seyon suggests that we can deprecate this when adding new_private/new_public, which sounds good to me.

@hugrbot
Copy link
Collaborator

hugrbot commented May 14, 2025

This PR contains breaking changes to the public Rust API.

cargo-semver-checks summary

--- failure enum_missing: pub enum removed or renamed ---

Description:
A publicly-visible enum cannot be imported by its prior path. A `pub use` may have been removed, or the enum itself may have been renamed or removed entirely.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/enum_missing.ron

Failed in:
enum hugr_core::hugr::patch::simple_replace::InvalidReplacement, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views/sibling_subgraph.rs:804

--- failure enum_variant_missing: pub enum variant removed or renamed ---

Description:
A publicly-visible enum has at least one variant that is no longer available under its prior name. It may have been renamed or removed entirely.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/enum_variant_missing.ron

Failed in:
variant InvalidSubgraphBoundary::MismatchedOutputPort, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/views/sibling_subgraph.rs:888

--- failure inherent_method_missing: pub method removed or renamed ---

Description:
A publicly-visible method or associated fn is no longer available under its prior name. It may have been renamed or removed entirely.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/inherent_method_missing.ron

Failed in:
SimpleReplacement::new_unchecked, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/patch/simple_replace.rs:38
SimpleReplacement::try_new, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/patch/simple_replace.rs:49
SimpleReplacement::new_unchecked, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/patch/simple_replace.rs:38
SimpleReplacement::try_new, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/patch/simple_replace.rs:49
SimpleReplacement::new_unchecked, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/patch/simple_replace.rs:38
SimpleReplacement::try_new, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/patch/simple_replace.rs:49
SimpleReplacement::new_unchecked, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/patch/simple_replace.rs:38
SimpleReplacement::try_new, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/hugr/patch/simple_replace.rs:49

--- failure method_requires_different_generic_type_params: method now requires a different number of generic type parameters ---

Description:
A method now requires a different number of generic type parameters than it used to. Uses of this method that supplied the previous number of generic types will be broken.
      ref: https://doc.rust-lang.org/reference/items/generics.html
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/method_requires_different_generic_type_params.ron

Failed in:
hugr_core::hugr::patch::simple_replace::SimpleReplacement::map_host_output takes 1 generic types instead of 0, in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/hugr/patch/simple_replace.rs:341
hugr_core::hugr::patch::SimpleReplacement::map_host_output takes 1 generic types instead of 0, in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/hugr/patch/simple_replace.rs:341
hugr_core::hugr::SimpleReplacement::map_host_output takes 1 generic types instead of 0, in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/hugr/patch/simple_replace.rs:341
hugr_core::SimpleReplacement::map_host_output takes 1 generic types instead of 0, in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/hugr/patch/simple_replace.rs:341

--- failure struct_pub_field_missing: pub struct's pub field removed or renamed ---

Description:
A publicly-visible struct has at least one public field that is no longer available under its prior name. It may have been renamed or removed entirely.
      ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/struct_pub_field_missing.ron

Failed in:
field name of struct FuncDefn, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/ops/module.rs:59
field signature of struct FuncDefn, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/ops/module.rs:61
field name of struct FuncDefn, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/ops/module.rs:59
field signature of struct FuncDefn, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/ops/module.rs:61
field name of struct FuncDecl, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/ops/module.rs:97
field signature of struct FuncDecl, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/ops/module.rs:99
field name of struct FuncDecl, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/ops/module.rs:97
field signature of struct FuncDecl, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/ops/module.rs:99

--- failure struct_pub_field_now_doc_hidden: pub struct field is now #[doc(hidden)] ---

Description:
A pub field of a pub struct is now marked #[doc(hidden)] and is no longer part of the public API.
      ref: https://doc.rust-lang.org/rustdoc/write-documentation/the-doc-attribute.html#hidden
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/struct_pub_field_now_doc_hidden.ron

Failed in:
field FuncDefn.name in file /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/ops/module.rs:56
field FuncDefn.signature in file /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/ops/module.rs:56
field FuncDefn.name in file /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/ops/module.rs:56
field FuncDefn.signature in file /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/ops/module.rs:56
field FuncDecl.name in file /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/ops/module.rs:122
field FuncDecl.signature in file /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/ops/module.rs:122
field FuncDecl.name in file /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/ops/module.rs:122
field FuncDecl.signature in file /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/ops/module.rs:122

@acl-cqc acl-cqc changed the title feat!: Mark FuncDefn #[non_exhaustive], add ::new feat!: Hide FuncDefn/cl name field, add ::func_name() and ::new(...) May 14, 2025
@acl-cqc
Copy link
Contributor Author

acl-cqc commented May 14, 2025

I'm not really persuaded about hiding names so happy to revert those commits. Is there any point to non_exhaustive if name is private?

@aborgna-q
Copy link
Collaborator

No, if there's at least one private field then non_exhaustive is a no-op.

@acl-cqc acl-cqc changed the title feat!: Hide FuncDefn/cl name field, add ::func_name() and ::new(...) feat!: Hide FuncDefn/cl fields, add accessors and ::new(...) May 14, 2025
&self.name
}

/// Sets the name of the function (as per [Self::func_name])
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Sets the name of the function (as per [Self::func_name])
/// Allows mutating the name of the function (as per [Self::func_name])

}
}

/// The name of the function (not, the name of the Op)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// The name of the function (not, the name of the Op)
/// The name of the function (not the name of the Op)

/// The name of the function (not, the name of the Op)
pub fn func_name(&self) -> &String {
&self.name
}
Copy link
Member

Choose a reason for hiding this comment

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

matching func_name_mut?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, so this lead to spotting #2215

@acl-cqc acl-cqc requested a review from ss2165 May 14, 2025 11:20
@acl-cqc acl-cqc added this pull request to the merge queue May 14, 2025
Merged via the queue into main with commit 0280eb2 May 14, 2025
25 checks passed
@acl-cqc acl-cqc deleted the acl/funcdefn_non_exhaustive branch May 14, 2025 13:11
@hugrbot hugrbot mentioned this pull request May 14, 2025
@codecov
Copy link

codecov bot commented May 14, 2025

Codecov Report

Attention: Patch coverage is 90.69767% with 12 lines in your changes missing coverage. Please review.

Project coverage is 82.00%. Comparing base (5108297) to head (109af97).
Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
hugr-core/src/ops/module.rs 91.66% 3 Missing ⚠️
hugr-core/src/builder/dataflow.rs 77.77% 1 Missing and 1 partial ⚠️
hugr-core/src/extension/resolution/types_mut.rs 83.33% 2 Missing ⚠️
hugr-core/src/hugr/views.rs 0.00% 2 Missing ⚠️
hugr-core/src/builder/module.rs 92.30% 0 Missing and 1 partial ⚠️
hugr-llvm/src/emit.rs 66.66% 0 Missing and 1 partial ⚠️
hugr-passes/src/replace_types.rs 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2213      +/-   ##
==========================================
- Coverage   82.10%   82.00%   -0.10%     
==========================================
  Files         230      230              
  Lines       40943    40940       -3     
  Branches    37044    37041       -3     
==========================================
- Hits        33616    33574      -42     
- Misses       5363     5398      +35     
- Partials     1964     1968       +4     
Flag Coverage Δ
python 85.63% <ø> (ø)
rust 81.62% <90.69%> (-0.11%) ⬇️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This was referenced May 14, 2025
@hugrbot hugrbot mentioned this pull request May 29, 2025
@hugrbot hugrbot mentioned this pull request May 29, 2025
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.

5 participants