Skip to content

feat: InlineFunctionsPass supports "Always" annotation that errors if unsatisfiable#1449

Open
acl-cqc wants to merge 44 commits into
mainfrom
acl/inline
Open

feat: InlineFunctionsPass supports "Always" annotation that errors if unsatisfiable#1449
acl-cqc wants to merge 44 commits into
mainfrom
acl/inline

Conversation

@acl-cqc

@acl-cqc acl-cqc commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

Intended as precursor to #1532: this adds the "Always" option only, but takes into account in its own pass, which raises an error if it cannot obey all the annotations.

Python interface is very WIP, not sure I've grokked everything there yet.

@aborgna-q aborgna-q force-pushed the ab/hugr-0.26.0 branch 10 times, most recently from cb4d32c to 2b29cdb Compare March 18, 2026 17:25
Base automatically changed from ab/hugr-0.26.0 to main March 19, 2026 10:33
@codecov

codecov Bot commented Mar 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.43147% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.85%. Comparing base (1281928) to head (489d479).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
tket/src/passes/inline_funcs.rs 95.85% 7 Missing and 1 partial ⚠️
tket-py/tket/metadata.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1449      +/-   ##
==========================================
+ Coverage   85.29%   85.85%   +0.56%     
==========================================
  Files         191      194       +3     
  Lines       30355    30927     +572     
  Branches    28986    29518     +532     
==========================================
+ Hits        25890    26552     +662     
+ Misses       3240     3108     -132     
- Partials     1225     1267      +42     
Flag Coverage Δ
python 91.92% <75.00%> (+0.15%) ⬆️
qis-compiler 92.70% <ø> (+0.11%) ⬆️
rust 85.56% <95.85%> (+0.57%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

Comment thread tket-py/test/test_pass.py Outdated
Comment thread tket-py/test/test_pass.py Outdated
@acl-cqc acl-cqc requested a review from aborgna-q May 12, 2026 14:29
@acl-cqc acl-cqc marked this pull request as ready for review May 12, 2026 14:29
@acl-cqc acl-cqc requested a review from a team as a code owner May 12, 2026 14:29

@aborgna-q aborgna-q left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some comments, mostly about differentiating the two passes.

Although from the technical side it makes sense to have two of them (we need to do different kinds of traversals for each), I struggle to justify having the split passes from the user point of view.
When would I want to "inline some of the annotated functions, but not the others that I've also annotated"?

Comment thread tket-py/test/test_pass.py Outdated
Comment thread tket-py/tket/metadata.py
Comment thread tket/src/passes/inline_always.rs Outdated
Comment thread tket/src/passes/inline_funcs.rs Outdated
Comment thread tket/src/metadata.rs Outdated
@acl-cqc acl-cqc changed the title feat: add inlining annotation + pass feat: InlineFunctionsPass supports "Always" annotation that errors if unsatisfiable Jun 23, 2026
@acl-cqc acl-cqc requested a review from aborgna-q June 23, 2026 15:54
@acl-cqc

acl-cqc commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Some comments, mostly about differentiating the two passes.

Although from the technical side it makes sense to have two of them (we need to do different kinds of traversals for each), I struggle to justify having the split passes from the user point of view. When would I want to "inline some of the annotated functions, but not the others that I've also annotated"?

Yeah, totally agree. Have merged the two. I didn't really go looking for common code and I imagine there must be at least some but see how you think this looks now?

Ok(())
}

fn inline_always_scoped<H: HugrMut>(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Add method docs

Comment thread tket/src/passes/inline_funcs.rs Outdated
Ok(())
}

fn cycles<'a, N: Copy>(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Docs

Comment thread tket/src/metadata.rs Outdated
/// Always inline calls to this function.
///
/// If this cannot be done, an error will be raised.
Always,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The semver checks are failing because this was added before all existing variants, and changed their inner tag id.
It also breaks the Ord derive.

Can you move the new variant to the end?
Alternatively, do

    Always = 2,
    BestEffort = 0,

Comment thread tket/src/passes/inline_funcs.rs Outdated
for child in hugr.children(parent) {
if hugr.first_child(child).is_some() {
parents.push_back(child);
} else if hugr.get_optype(child).is_call()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We're not handling LoadFunctions here, even though the reachable_always logic above does add them

OpType::Call(_) | OpType::LoadFunction(_) => hugr.static_source(n),
_ => None,

@acl-cqc acl-cqc Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's a really good point, thank you! Should ignore LoadFunction edges when looking for cycles, as they can't be inlined (yet we push them onto to_inline, ooops); and not delete functions with LoadFunctions remaining. Quite a few bugs there, which tests including LoadFunction would have spotted.... I've updated code but not added the tests. I think we'll have to let this one slip to a later release....it is non-breaking after all.

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