Skip to content

Conversation

@zrho
Copy link
Contributor

@zrho zrho commented Jun 12, 2025

This PR makes core Terms immutable and shareable via reference counting. Terms can now be cheaply copied. To allow for cheap equality checks and hash computations, Terms cache their hash value, making it viable to store Terms as keys in hash tables. A Term can be pattern matched by obtaining a TermEnum via Term::get.

BREAKING CHANGE: Term is changed from an enum to a structure that hides the reference counting machinery. This changes the way that Terms are created and consumed.

@hugrbot
Copy link
Collaborator

hugrbot commented Jun 12, 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::types::type_param::TypeArg, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/types/type_param.rs:68
enum hugr_core::types::TypeArg, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/types/type_param.rs:68
enum hugr_core::types::type_param::TypeParam, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/types/type_param.rs:68
enum hugr_core::types::type_param::Term, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/types/type_param.rs:68
enum hugr_core::types::Term, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/types/type_param.rs:68

--- failure inherent_associated_pub_const_missing: inherent impl's associated pub const removed ---

Description:
An inherent impl's associated public constant is 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.41.0/src/lints/inherent_associated_pub_const_missing.ron

Failed in:
Term::UNIT, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/types/type_param.rs:251
Term::UNIT, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/types/type_param.rs:251
Term::UNIT, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/types/type_param.rs:251
Term::UNIT, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/types/type_param.rs:251
Term::UNIT, previously at /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/types/type_param.rs:251

--- failure inherent_method_const_removed: pub method is no longer const ---

Description:
A publicly-visible method or associated fn is no longer `const` and can no longer be used in a `const` context.
      ref: https://doc.rust-lang.org/reference/const_eval.html
     impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.41.0/src/lints/inherent_method_const_removed.ron

Failed in:
Term::max_nat_type in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/types/type_param.rs:260
Term::bounded_nat_type in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/types/type_param.rs:266
Term::max_nat_type in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/types/type_param.rs:260
Term::bounded_nat_type in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/types/type_param.rs:266
Term::max_nat_type in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/types/type_param.rs:260
Term::bounded_nat_type in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/types/type_param.rs:266
Term::max_nat_type in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/types/type_param.rs:260
Term::bounded_nat_type in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/types/type_param.rs:266
Term::max_nat_type in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/types/type_param.rs:260
Term::bounded_nat_type in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-core/src/types/type_param.rs:266

--- failure pub_module_level_const_missing: pub module-level const is missing ---

Description:
A public const is missing or renamed
      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/pub_module_level_const_missing.ron

Failed in:
LOG_WIDTH_TYPE_PARAM in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-core/src/std_extensions/arithmetic/int_types.rs:72

@codecov
Copy link

codecov bot commented Jun 12, 2025

Codecov Report

❌ Patch coverage is 71.23288% with 189 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.05%. Comparing base (db6c910) to head (6ec627c).
⚠️ Report is 109 commits behind head on main.

Files with missing lines Patch % Lines
hugr-core/src/types/type_param.rs 74.70% 62 Missing and 2 partials ⚠️
...rc/std_extensions/collections/array/array_value.rs 12.50% 12 Missing and 2 partials ⚠️
hugr-core/src/extension/resolution/types_mut.rs 40.00% 11 Missing and 1 partial ⚠️
hugr-llvm/src/extension/int.rs 60.00% 10 Missing ⚠️
hugr-passes/src/replace_types/handlers.rs 65.38% 7 Missing and 2 partials ⚠️
hugr-core/src/import.rs 42.85% 8 Missing ⚠️
hugr-core/src/export.rs 66.66% 6 Missing ⚠️
...e/src/std_extensions/collections/array/array_op.rs 68.42% 2 Missing and 4 partials ⚠️
...src/std_extensions/collections/array/array_scan.rs 60.00% 4 Missing and 2 partials ⚠️
hugr-core/src/types/serialize.rs 87.23% 6 Missing ⚠️
... and 19 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2338      +/-   ##
==========================================
- Coverage   82.14%   82.05%   -0.09%     
==========================================
  Files         244      244              
  Lines       44270    44474     +204     
  Branches    40099    40303     +204     
==========================================
+ Hits        36365    36494     +129     
- Misses       5915     5970      +55     
- Partials     1990     2010      +20     
Flag Coverage Δ
python 85.30% <ø> (ø)
rust 81.72% <71.23%> (-0.10%) ⬇️

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.

@zrho zrho force-pushed the zrho/core-term-arc branch 7 times, most recently from 6f84739 to 5418648 Compare June 14, 2025 15:11
@zrho zrho self-assigned this Jun 16, 2025
@zrho zrho force-pushed the zrho/core-term-arc branch from 5418648 to 112d078 Compare June 16, 2025 12:42
@zrho zrho added the enhancement New feature or request label Jun 16, 2025
@zrho zrho force-pushed the zrho/core-term-arc branch 2 times, most recently from 305351b to 81c5cc3 Compare June 17, 2025 16:47
@zrho zrho force-pushed the zrho/core-term-arc branch from 81c5cc3 to 7721747 Compare June 19, 2025 10:28
@zrho zrho closed this Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants