Skip to content

Erase compiled functions from every thread's compile cache - #4940

Merged
zcbenz merged 2 commits into
ml-explore:mainfrom
KavinP21:fix-compile-erase-all-thread-caches
Nov 28, 2026
Merged

zcbenz merged 2 commits into
ml-explore:mainfrom
KavinP21:fix-compile-erase-all-thread-caches

Conversation

@KavinP21

Copy link
Copy Markdown
Contributor

The compile cache is per thread, but compiled functions only remembered one cache to clean up. Releasing a function used by multiple threads could leave stale entries that a new function at the same address would reuse, producing incorrect results. This patch tracks every cache the function was traced in, removes its entries from all of them on release, and adds a test.

Fixes #4933

  • ☑️ I understand it is strictly prohibited to use AI to write PR description
  • AI usage disclosure: I used Claude Code to write the patch and tests, which I reviewed and ran locally. I wrote this PR description myself.

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would you mind rebasing the PR on main branch to solve the conflict with #4953?

@KavinP21
KavinP21 force-pushed the fix-compile-erase-all-thread-caches branch from d1c3993 to b086ae4 Compare November 26, 2026 23:45
@KavinP21

Copy link
Copy Markdown
Contributor Author

Would you mind rebasing the PR on main branch to solve the conflict with #4953?

Sure. I just rebased on the latest main. The conflict should be resolved now.

@zcbenz zcbenz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for the late review, so I think we can not accept this PR because it is unsafe to free compiled function in another thread as it might be being used.

@zcbenz zcbenz closed this Nov 28, 2026
@zcbenz

zcbenz commented Nov 28, 2026

Copy link
Copy Markdown
Member

Hmm after thinking more about this I think might be able to work.

@zcbenz zcbenz reopened this Nov 28, 2026
This patch removes the function’s entries from every cache it was traced in instead of just one
@zcbenz
zcbenz force-pushed the fix-compile-erase-all-thread-caches branch from b086ae4 to 51a5c9a Compare November 28, 2026 10:51
@zcbenz
zcbenz force-pushed the fix-compile-erase-all-thread-caches branch from 51a5c9a to f20424a Compare November 28, 2026 10:55
@zcbenz
zcbenz force-pushed the fix-compile-erase-all-thread-caches branch from f20424a to 209d399 Compare November 28, 2026 11:14
@zcbenz
zcbenz merged commit b304055 into ml-explore:main Nov 28, 2026
24 checks passed
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.

[BUG] mx.compile reuses a freed function's trace on threads that called it before the last caller

2 participants