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

Detect extension staleness due root module name/version change #22123

Closed
wants to merge 3 commits into from

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Apr 25, 2024

Fixes #22121

@github-actions github-actions bot added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. awaiting-review PR is awaiting review from an assigned reviewer labels Apr 25, 2024
@fmeum
Copy link
Collaborator Author

fmeum commented Apr 25, 2024

@bazel-io fork 7.2.0

@Wyverald
Copy link
Member

Wyverald commented Apr 25, 2024

Alternative idea: at https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/bazel/bzlmod/SingleExtensionEvalFunction.java;drc=6f48f1c2b3bb73768b9ff15ce6698e21eddc503a;l=224 , hash the entire usagesValue instead. (or at least, also hash the abridged modules.) That seems to be a less intrusive and more foolproof change: all information that the extension has access to comes from the usagesValue anyway.

@fmeum
Copy link
Collaborator Author

fmeum commented Apr 25, 2024

The whole value would be too much as it contains repo mappings, but hashing in the abridged modules is a great idea.

@fmeum fmeum force-pushed the 22121-module-name branch 2 times, most recently from 9eb6c5c to 7383021 Compare April 26, 2024 12:57
@fmeum
Copy link
Collaborator Author

fmeum commented Apr 26, 2024

I implemented the new approach, PTAL.

@fmeum
Copy link
Collaborator Author

fmeum commented Apr 26, 2024

@jin The only failing test is for Skyfocus. It looks like it can result in certain Skyframe nodes missing after the build that are contained in the transitive closure of RepositoryMappingValue.key(RepositoryName.MAIN), which is requested by every build. Do I need to make any changes to the working set logic to keep this value in the graph?

try {
depGraphValue = (BazelDepGraphValue) evaluator.getExistingValue(BazelDepGraphValue.KEY);
} catch (InterruptedException e) {
// Not thrown in Bazel.
Copy link
Member

Choose a reason for hiding this comment

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

what does this mean? Is it thrown in Blaze?

Copy link
Collaborator Author

@fmeum fmeum Apr 29, 2024

Choose a reason for hiding this comment

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

It's not thrown in Bazel because the in-memory graph implementation doesn't declare this checked exception. It's presumably thrown by Blaze's graph impl, but then the code in this PR doesn't touch any Blaze code.

Maybe I should just rethrow this unchecked? Handling it with an exit code when it can't happen also doesn't feel right. If it does indeed happen some day, we should learn about it.

Copy link
Member

Choose a reason for hiding this comment

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

you could work around this by calling evaluator.getInMemoryGraph().getIfPresent(...).

But I think this value is now unnecessary -- you could just remove it since it's no longer used

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is needed to learn of extensions that are no longer used anywhere. This was found by tests.

Copy link
Collaborator Author

@fmeum fmeum Apr 30, 2024

Choose a reason for hiding this comment

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

For some reason the graph maintained by the MemoizingEvaluator instance I was holding onto became empty due to Skyfocus. Instead, I'm now holding on to the SkyframeExecutor, which seems to work. Looks like something in Skyfocus is switching out the evaluator after the build - I don't understand where or why this happening, but I won't complain if the tests pass.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nvm, found the cause now:

@fmeum fmeum requested a review from Wyverald April 29, 2024 15:16
}
@Nullable LockFileModuleExtension.WithFactors newExtensionInfo,
BazelDepGraphValue depGraphValue) {
if (!depGraphValue.getExtensionUsagesTable().containsRow(moduleExtensionId)) {
Copy link
Member

Choose a reason for hiding this comment

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

couldn't you just read this out of moduleResolutionEvent as before (old line 216)? unless we're looking to stop using that event and switch to using depGraphValue anyway

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that's going to happen in the follow-up PR anyway (which will get even more values from Skyframe).

@Wyverald Wyverald added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Apr 30, 2024
@copybara-service copybara-service bot closed this in 42423e0 May 3, 2024
@github-actions github-actions bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label May 3, 2024
@fmeum fmeum deleted the 22121-module-name branch May 3, 2024 06:32
Wyverald pushed a commit that referenced this pull request May 7, 2024
Fixes #22121

Closes #22123.

PiperOrigin-RevId: 630277746
Change-Id: I893a69b0048e933554f515684c6ab1fdae541c0b
Wyverald pushed a commit that referenced this pull request May 7, 2024
Fixes #22121

Closes #22123.

PiperOrigin-RevId: 630277746
Change-Id: I893a69b0048e933554f515684c6ab1fdae541c0b
github-merge-queue bot pushed a commit that referenced this pull request May 7, 2024
#22282)

Fixes #22121

Closes #22123.

PiperOrigin-RevId: 630277746
Change-Id: I893a69b0048e933554f515684c6ab1fdae541c0b

Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
Kila2 pushed a commit to Kila2/bazel that referenced this pull request May 13, 2024
Fixes bazelbuild#22121

Closes bazelbuild#22123.

PiperOrigin-RevId: 630277746
Change-Id: I893a69b0048e933554f515684c6ab1fdae541c0b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Module extension isn't rerun when root MODULE.bazel's module is changed
2 participants