Repository navigation
Conversation
slozier
approved these changes
Oct 24, 2026
slozier
left a comment
Contributor
There was a problem hiding this comment.
Looks good to me! Thanks!
| SetTarget(target); | ||
| Thread.MemoryBarrier(); | ||
| while (context.EnableTracing != tracing) { | ||
| tracing = context.EnableTracing; |
Contributor
There was a problem hiding this comment.
Lots of reading context.EnableTracing (and another one at the top of UpdateDelegate). Any chance of things getting out of sync (seems unlikely but doesn't hurt to ask).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug: switching tracing on or off (
sys.settrace) updates the target of every code object, but other writers of the target are not synchronized with that switch: the adaptive compiler's completion callbacks, the background precompile of class bodies, compilation on first use inMakeClassandFunctionCode.Call, and -X:Debugfunction definitions.A delegate built for the previous mode could thus become the target after the switch and stay until the next one, e.g. a class body that runs untraced while tracing is on.
These writers now set the target through
FunctionCode.PublishTarget, which skips a delegate built for a mode that is no longer current (it stays in its cache for when the mode switches back) and checks the mode again after setting the target, repeating the switch's update if the mode changed meanwhile.SetTracechanges the mode with an interlocked operation, so the new mode is visible before any code is updated for it.Under
-X:Debugthis also fixes functions defined while tracing is on, which always got their normal delegate and were not traced.