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

staticdata: Insert backedges recursively #57212

Merged
merged 1 commit into from
Jan 31, 2025
Merged

Conversation

Keno
Copy link
Member

@Keno Keno commented Jan 31, 2025

In the new edges scheme, when we perform constant propagation, we create a dummy CodeInstance that is not inserted into the specializations cache, but instead simply serves as a container for all edges that were encountered during the constant propagation. These CodeInstances are not part of either the internal or external edges list collected during pkgimage generation. As such, while we were verifying edges recursively and would thus catch an invalidation prior to package image reload, we were failing to also insert backedges for these CodeInstance. We were thus failing to invalidate such methods if the method was redefined after re-load of the package image. Fix that by moving the storing of the backedges to the end of the validation code, so that it too happens recursively.

In the new edges scheme, when we perform constant propagation, we create a dummy CodeInstance
that is not inserted into the specializations cache, but instead simply serves as a container
for all edges that were encountered during the constant propagation. These CodeInstances are
not part of either the internal or external edges list collected during pkgimage generation.
As such, while we were verifying edges recursively and would thus catch an invalidation
prior to package image reload, we were failing to also insert backedges for these CodeInstance.
We were thus failing to invalidate such methods if the method was redefined after re-load
of the package image. Fix that by moving the storing of the backedges to the end of the
validation code, so that it too happens recursively.
@Keno Keno requested review from vtjnash and aviatesk January 31, 2025 00:39
Copy link
Member

@aviatesk aviatesk left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this up. The changes look reasonable.
(If anything, verify_method_graph now performs both "verify" and "insert" operations, so it might be good to reflect that in the name, although I also think this might be fine as it is.)

@oscardssmith oscardssmith added bugfix This change fixes an existing bug compiler:precompilation Precompilation of modules labels Jan 31, 2025
@oscardssmith oscardssmith merged commit dbe19e4 into master Jan 31, 2025
9 checks passed
@oscardssmith oscardssmith deleted the kf/missingbackedges branch January 31, 2025 14:36
end
if maxworld == current_world
Base.Compiler.store_backedges(child, child.edges)
@atomic :monotonic child.max_world = typemax(UInt)
Copy link
Member

Choose a reason for hiding this comment

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

The current_world may change while these backedge insertion is occurring. The part of this change that combined these separate atomics checks introduces an unsoundness here. This line needs to be put back into _insert_backedges: first all backedges must be inserted (for the cycle), and then, if the current_world is still the same, it can atomically change max_world => typemax to acknowledge that all of the backedges existed in the current world.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, and you're fine with capping the world age if that happened rather than revalidating?

Copy link
Member

Choose a reason for hiding this comment

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

Well, yeah, we are supposed to revalidate later if we need this code later. We finally have the code for that written now (this file) but haven't finished hooking that up yet.

Keno added a commit that referenced this pull request Feb 1, 2025
Addresses review comment in #57212 (comment).
The key is that the hand-off of responsibility for verification
between the loading code and the ordinary backedge mechanism happens
under the world counter lock to ensure synchronization.
Keno added a commit that referenced this pull request Feb 1, 2025
Addresses review comment in #57212 (comment).
The key is that the hand-off of responsibility for verification
between the loading code and the ordinary backedge mechanism happens
under the world counter lock to ensure synchronization.
Keno added a commit that referenced this pull request Feb 1, 2025
Addresses review comment in #57212 (comment).
The key is that the hand-off of responsibility for verification
between the loading code and the ordinary backedge mechanism happens
under the world counter lock to ensure synchronization.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug compiler:precompilation Precompilation of modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants