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!: ComposablePass trait allowing sequencing and validation #1895

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

acl-cqc
Copy link
Contributor

@acl-cqc acl-cqc commented Jan 28, 2025

We have several "passes" atm: monomorphization, dead function removal, constant folding. Each has its own code to allow setting a validation level (before and after that pass).

This PR adds the ability chain (sequence) passes;, and to add validation before+after any pass or sequence; and commons up validation code. The top-level constant_fold_pass (etc.) functions are left as wrappers that do a single pass with validation only in test.

TODO: no actual tests of sequencing yet, heh! Maybe we could combine, hmmm, monomorphization followed by constant folding?

BREAKING CHANGE: quite a lot of calls to current pass routines will break, specific cases include (a) with_validation_level should be done by wrapping a ValidatingPass around the receiver; (b) XXXPass::run() requires use ...ComposablePass (however, such calls will cease to do any validation).

@hugrbot
Copy link
Collaborator

hugrbot commented Jan 28, 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.39.0/src/lints/enum_missing.ron

Failed in:
enum hugr_passes::MonomorphizeError, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-passes/src/monomorphize.rs:282
enum hugr_passes::validation::ValidationLevel, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-passes/src/validation.rs:16
enum hugr_passes::validation::ValidatePassError, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-passes/src/validation.rs:28
enum hugr_passes::const_fold::ConstFoldError, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-passes/src/const_fold.rs:40

--- 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.39.0/src/lints/enum_variant_missing.ron

Failed in:
variant RemoveDeadFuncsError::ValidationError, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-passes/src/dead_funcs.rs:31

--- 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.39.0/src/lints/inherent_method_missing.ron

Failed in:
ConstantFoldPass::validation_level, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-passes/src/const_fold.rs:48
RemoveDeadFuncsPass::validation_level, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-passes/src/dead_funcs.rs:73
MonomorphizePass::validation_level, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-passes/src/monomorphize.rs:290

--- 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.39.0/src/lints/method_requires_different_generic_type_params.ron

Failed in:
hugr_passes::const_fold::ConstantFoldPass::run takes 0 generic types instead of 1, in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-passes/src/const_fold.rs:115
hugr_passes::RemoveDeadFuncsPass::run takes 0 generic types instead of 1, in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-passes/src/dead_funcs.rs:87
hugr_passes::MonomorphizePass::run takes 0 generic types instead of 1, in /home/runner/work/hugr/hugr/PR_BRANCH/hugr-passes/src/monomorphize.rs:263

--- failure module_missing: pub module removed or renamed ---

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

Failed in:
mod hugr_passes::validation, previously in file /home/runner/work/hugr/hugr/BASELINE_BRANCH/hugr-passes/src/validation.rs:1

Copy link

codecov bot commented Jan 29, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 50 lines in your changes missing coverage. Please review.

Project coverage is 86.52%. Comparing base (d6b8681) to head (dab7039).

Files with missing lines Patch % Lines
hugr-passes/src/composable.rs 33.33% 38 Missing and 6 partials ⚠️
hugr-passes/src/monomorphize.rs 77.77% 1 Missing and 3 partials ⚠️
hugr-passes/src/const_fold.rs 97.67% 1 Missing ⚠️
hugr-passes/src/dead_funcs.rs 95.65% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1895      +/-   ##
==========================================
- Coverage   86.56%   86.52%   -0.04%     
==========================================
  Files         195      195              
  Lines       35724    35736      +12     
  Branches    32537    32549      +12     
==========================================
- Hits        30925    30922       -3     
- Misses       3012     3027      +15     
  Partials     1787     1787              
Flag Coverage Δ
python 92.34% <ø> (ø)
rust 85.95% <66.66%> (-0.05%) ⬇️

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.

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.

2 participants