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

Track nested meta-tracing states. #1582

Merged
merged 1 commit into from
Feb 5, 2025
Merged

Conversation

ltratt
Copy link
Contributor

@ltratt ltratt commented Feb 4, 2025

Previously we -- well, this one is entirely my fault, so "I"! -- tracked per-thread meta-tracing state as a single MTThreadState that we updates as necessary. This doesn't work when we have nested execution, tracing and the like, as the bug in #1571 highlighted.

This commit moves us to a stack of MTThreadStates. The basic idea is that the stack always has at least one element: Interpreting. As we go through other states, we push / pop as appropriate. The test below (from Edd and Lukas) fails on master but is fixed by this commit.

The implementation is a bit more awkward than one might hope as naive implementations either:

  1. Spread lots of knowledge about the stack around the code. That's a disaster waiting to happen.
  2. Run into borrow checker problems.

This commit gets around this in two phases:

  1. We pass closures to MTThread which can peek at the current MTThreadState (which isn't Copy!).
  2. Those closures return the "things" we need to update outside that context.

This is a bit awkward, and perhaps there's a better API, but this one is at least safe.

Fixes #1571.

ykrt/src/mt.rs Outdated Show resolved Hide resolved
@vext01
Copy link
Contributor

vext01 commented Feb 5, 2025

I'm OK with this, but @ptersilie should have a look before we merge.

@ptersilie
Copy link
Contributor

Looks good to me.

@vext01
Copy link
Contributor

vext01 commented Feb 5, 2025

If you are ready @ltratt, please squash.

Previously we -- well, this one is entirely my fault, so "I"! -- tracked
per-thread meta-tracing state as a single `MTThreadState` that we updates as
necessary. This doesn't work when we have nested execution, tracing and
the like, as the bug in ykjit#1571 highlighted.

This commit moves us to a stack of `MTThreadState`s. The basic idea is
that the stack always has at least one element: `Interpreting`. As we go
through other states, we push / pop as appropriate. The test below (from
Edd and Lukas) fails on `master` but is fixed by this commit.

The implementation is a bit more awkward than one might hope as naive implementations either:

  1. Spread lots of knowledge about the stack around the code. That's a
     disaster waiting to happen.
  2. Run into borrow checker problems.

This commit gets around this in two phases:

  1. We pass closures to `MTThread` which can peek at the current
     `MTThreadState` (which isn't `Copy`!).
  2. Those closures return the "things" we need to update outside that
     context.

This is a bit awkward, and perhaps there's a better API, but this one is
at least safe.

Co-authored-by: Edd Barrett <[email protected]>
Co-authored-by: Lukas Diekmann <[email protected]>
@ltratt
Copy link
Contributor Author

ltratt commented Feb 5, 2025

Squashed.

@vext01 vext01 added this pull request to the merge queue Feb 5, 2025
Merged via the queue into ykjit:master with commit f2ecc1b Feb 5, 2025
2 checks passed
@ltratt ltratt deleted the nested_execution branch February 6, 2025 08:07
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.

meta_framegap.lua deopt crash
3 participants