Skip to content

feat: InlineFunctionsPass#1524

Merged
cqc-alec merged 4 commits intomainfrom
ab/inline-funcs
Apr 21, 2026
Merged

feat: InlineFunctionsPass#1524
cqc-alec merged 4 commits intomainfrom
ab/inline-funcs

Conversation

@aborgna-q
Copy link
Copy Markdown
Collaborator

@aborgna-q aborgna-q commented Apr 17, 2026

Adds a pass definition that calls the already-defined function inlining tool.

This version uses a simple heuristic to choose when to inline:

  • Function must not be on a cycle of the call-graph (i.e. it's not recursive).
  • The function definition must have a limited number of nodes (defaults to <= 64 descendants).

We can add better heuristicts in the future, and check for inline hints.
This is a first version to help with simple optimization cases.

Note that the inlined funcDefs are not removed. RemoveDeadFuncsPass can be called afterwards to remove what's not needed.

We should also add this as a first step in NormalizeGuppy

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 82.65306% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.80%. Comparing base (a7f40bb) to head (08019c6).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
tket/src/passes/inline_funcs.rs 78.26% 14 Missing and 1 partial ⚠️
tket-py/tket/passes/__init__.py 90.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1524      +/-   ##
==========================================
- Coverage   83.82%   83.80%   -0.03%     
==========================================
  Files         187      188       +1     
  Lines       28954    29032      +78     
  Branches    27875    27928      +53     
==========================================
+ Hits        24271    24330      +59     
- Misses       3522     3540      +18     
- Partials     1161     1162       +1     
Flag Coverage Δ
python 92.32% <93.10%> (-0.01%) ⬇️
qis-compiler 91.66% <ø> (ø)
rust 83.46% <78.26%> (-0.03%) ⬇️

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.

@aborgna-q aborgna-q marked this pull request as ready for review April 17, 2026 16:23
@aborgna-q aborgna-q requested a review from a team as a code owner April 17, 2026 16:23
@aborgna-q aborgna-q requested review from cqc-alec and doug-q and removed request for doug-q April 17, 2026 16:23
Copy link
Copy Markdown
Collaborator

@cqc-alec cqc-alec left a comment

Choose a reason for hiding this comment

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

Thanks, just small comments.

Comment thread tket/src/passes.rs

// Inline function calls.
pub mod inline_funcs;
pub use inline_funcs::InlineFunctionsPass;
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.

Maybe this should be called something like InlineSmallFunctionsPass, since the name suggests that it inlines all functions.

Copy link
Copy Markdown
Collaborator 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 we want to limit ourselves to only small functions here.

The max_size limit is the simplest of the heuristics we could apply.

We may want to add alternatives in the future that decide based on the function types or something else.

We'll also want to add the option to inline functions based on inline hints in their metadata.

I think I'll add an InlineHeuristic enum instead of the max_size flag.

Do you have an alternative name suggestion that also works for different heuristics?

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.

Sounds good to me. I think the name is fine if it is referring to a general heuristic.

- remove_redundant_order_edges: Whether to remove redundant order edges.
"""

def inline_functions(
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.

Maybe rename to inline_small_functions? Alternatively we could have max_inline_size be optional and if not set inline all functions?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'd like to have the default behaviour be useful. I don't think "inline everything" is something users will want to do most of the time.

See my comment about a Heuristics enum below. I'll add an All variant.

Comment thread tket-py/test/test_pass.py
Comment thread tket/src/passes/inline_funcs.rs Outdated
@aborgna-q
Copy link
Copy Markdown
Collaborator Author

Added the heuristic enum, and a flag for following inline hints.
(The inline hint metadata will come in a separate PR, but we can at least stabilize the pass API now).

I'm using Protocols for the python heuristics, since python enums can't carry data. Not sure if I love this design, but it works.

@aborgna-q aborgna-q requested a review from cqc-alec April 20, 2026 14:38
Copy link
Copy Markdown
Collaborator

@cqc-alec cqc-alec left a comment

Choose a reason for hiding this comment

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

LGTM

@aborgna-q aborgna-q added this pull request to the merge queue Apr 20, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 20, 2026
@cqc-alec cqc-alec added this pull request to the merge queue Apr 21, 2026
Merged via the queue into main with commit f40dcef Apr 21, 2026
24 checks passed
@cqc-alec cqc-alec deleted the ab/inline-funcs branch April 21, 2026 08:23
This was referenced Apr 21, 2026
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