Skip to content

ir.Method specialization on func.Invoke containing immutable known constants - #735

Merged
zhenrongliew merged 18 commits into
mainfrom
dl/method-specialize
Nov 9, 2026
Merged

zhenrongliew merged 18 commits into
mainfrom
dl/method-specialize

Conversation

@zhenrongliew

Copy link
Copy Markdown
Collaborator

Closes #734

Adds a Specialize pass that clones a method with call-site constants baked into its body and rewrites the call to pass only the remaining arguments. The original method is left untouched and still callable.

Design

SpecializeInvoke (rewrite rule) matches func.Invoke, reads one constant fact per operand, and swaps the call. Dropping an operand removes a use; it is DCE's decision to remove it if applicable.

Specialize (pass) owns constant propagation, the key policy, the cache, the budget, the worklist, and backedge cleanup.

Cache, Key & Budget

On argument values, positionally: (method, (key₀ … keyₙ)). So foo(3, x) and foo(x, 3) yield different specializations, while foo(b=x, a=3) normalizes to the same key as foo(3, x) and shares a specialization.

_constant_key admits only: scalars, complex, range, and recursively tuple/frozenset/IList. Mutable values stay parameters.

max_specializations (default 32) per method. At the limit the call falls back to the original method rather creating new specializations.

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.2
Preview removed because the pull request was closed.
2026-11-09 20:54 UTC

@github-actions

github-actions Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

☂️ Code Coverage

current status: ✅

Overall Coverage

Statements Covered Coverage Threshold Status
12891 11717 91% 0% 🟢

New Files

File Coverage Status
src/kirin/passes/specialize.py 94% 🟢
src/kirin/rewrite/specialize_invoke.py 96% 🟢
TOTAL 95% 🟢

Modified Files

File Coverage Status
src/kirin/passes/_init_.py 100% 🟢
src/kirin/rewrite/_init_.py 100% 🟢
TOTAL 100% 🟢

updated for commit: 30c37bf by action🐍

@codecov

codecov Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.06528% with 20 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/kirin/passes/specialize.py 93.54% 18 Missing ⚠️
src/kirin/rewrite/specialize_invoke.py 96.42% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@zhenrongliew
zhenrongliew marked this pull request as draft September 23, 2026 15:10
@zhenrongliew
zhenrongliew marked this pull request as ready for review October 26, 2026 20:21
Copilot AI balanced review requested due to automatic review settings October 26, 2026 20:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

Copilot AI balanced review requested due to automatic review settings November 5, 2026 22:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 5, 2026 22:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Comment thread src/kirin/passes/specialize.py Resolved
Comment thread src/kirin/passes/specialize.py Resolved
Comment thread src/kirin/passes/specialize.py Resolved
Comment thread src/kirin/passes/specialize.py Resolved
Comment thread src/kirin/passes/specialize.py Resolved
Copilot AI balanced review requested due to automatic review settings November 9, 2026 19:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 9, 2026 19:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 9, 2026 19:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Comment thread src/kirin/passes/specialize.py Resolved
Comment thread src/kirin/passes/specialize.py Resolved
Co-authored-by: alexcgatea <AGatea@quera.com>
Copilot AI balanced review requested due to automatic review settings November 9, 2026 20:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copilot AI balanced review requested due to automatic review settings November 9, 2026 20:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@alexcgatea alexcgatea 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.

LGTM. Thanks for addressing my concerns!

@zhenrongliew
zhenrongliew merged commit 4ff3474 into main Nov 9, 2026
12 checks passed
@zhenrongliew
zhenrongliew deleted the dl/method-specialize branch November 9, 2026 20:53
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.

Specialization of ir.Method

3 participants