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

Fix issues with path mapping in map_each functions #22227

Closed
wants to merge 2 commits into from

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented May 3, 2024

Fixes the following issues with path mapping applied to map_each functions:

  • Action keys could be stale if an action implementation switches from hard-coded artifact strings to Files mapped at execution time. This commit introduces a special PathMapper instance for fingerprinting, see the long comment on PathMappers.FOR_FINGERPRINTING. It includes a number of tests to verify that neither too much nor too little is mapped during action key computation.
  • The Starlark objects representing mapped artifact roots didn't have the correct semantics for equality and ordered comparisons. They are now unequal to unmapped roots.
  • When not using path mapping, the StarlarkSemantics of a thread used to evaluate map_each callbacks is not modified.

These changes require splitting PathMappers out of analysis_cluster and also make StrippingPathMapper a subclass of PathMapper instead of using an anonymous one.

@fmeum fmeum changed the title Fix semantics Fix issues with path mapping in map_each functions May 3, 2024
@fmeum fmeum marked this pull request as ready for review May 3, 2024 12:34
@fmeum fmeum requested review from a team and lberki as code owners May 3, 2024 12:34
@fmeum fmeum requested review from katre and aranguyen and removed request for a team, lberki and katre May 3, 2024 12:34
@github-actions github-actions bot added team-Performance Issues for Performance teams team-Configurability platforms, toolchains, cquery, select(), config transitions team-Rules-Java Issues for Java rules awaiting-review PR is awaiting review from an assigned reviewer labels May 3, 2024
@fmeum fmeum removed team-Performance Issues for Performance teams team-Rules-Java Issues for Java rules labels May 3, 2024
Copy link
Contributor

@aranguyen aranguyen left a comment

Choose a reason for hiding this comment

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

@fmeum thank you for the pr and I'm so sorry for the late review. I added a few questions and just have a general concern with having a distinct PathMapper just for fingerprinting and a different PathMapper? for mapping the command line inputs & for usage on the executors. I don't have a good suggestion to solve the issue at the moment but would like to discuss this further in one of our next meetings

Do we have reported failures that are related to this? It would be great to have these documented.

I LGTM this for now to get this imported and tested internally in parallel.

* <li>Unconditionally using {@link StrippingPathMapper} can result in stale action keys when an
* action is opted out of path mapping at execution time due to input path collisions after
* stripping. See path_mapping_test for an example.
* <li>Using {@link PathMapper#NOOP} does not distinguish between map_each results built from
Copy link
Contributor

Choose a reason for hiding this comment

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

is this because FileApi.getExecPathStringForStarlark still needed for things that are not opted in with map_each? Just wondering if we can merge them to get rid of the difference in behavior

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We can't get rid of the difference in this situation since File#path only returns the correct result when used in a map_each callback. If someone e.g. keeps paths as strings around in providers and then migrates to artifacts to become compatible with path mapping, they may run into this staleness (without this fix).

* the input depsets of all actions that opt into path mapping and also increases CPU usage.
* <li>Unconditionally using {@link StrippingPathMapper} can result in stale action keys when an
* action is opted out of path mapping at execution time due to input path collisions after
* stripping. See path_mapping_test for an example.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a real use case for this one? How did you discover this issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This issue is more of an edge case and I only discovered it when I tried to think through whether our fingerprinting scheme is sound in all cases.

@aranguyen aranguyen 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 Jul 18, 2024
@sgowroji
Copy link
Member

Hello @fmeum, Could you please resolve the  above code conflicts. Thanks!

@fmeum
Copy link
Collaborator Author

fmeum commented Jul 18, 2024

@sgowroji I resolved the conflicts

@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 Jul 30, 2024
@fmeum fmeum deleted the fix-semantics branch July 30, 2024 07:14
@fmeum
Copy link
Collaborator Author

fmeum commented Jul 30, 2024

@bazel-io flag

@bazel-io bazel-io added the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Jul 30, 2024
@iancha1992
Copy link
Member

@bazel-io fork 7.4.0

@bazel-io bazel-io removed the potential release blocker Flagged by community members using "@bazel-io flag". Should be added to a release blocker milestone label Jul 31, 2024
@nikhilkalige
Copy link
Contributor

@fmeum Is this a necessary fix to try various C++ path mapping changes in upcoming 7.3 release?

@fmeum
Copy link
Collaborator Author

fmeum commented Jul 31, 2024

@nikhilkalige No, the basics work without it. See #22658 for the exact missing features.

fmeum added a commit to fmeum/bazel that referenced this pull request Aug 22, 2024
Fixes the following issues with path mapping applied to `map_each` functions:
* Action keys could be stale if an action implementation switches from hard-coded artifact strings to `File`s mapped at execution time. This commit introduces a special `PathMapper` instance for fingerprinting, see the long comment on `PathMappers.FOR_FINGERPRINTING`. It includes a number of tests to verify that neither too much nor too little is mapped during action key computation.
* The Starlark objects representing mapped artifact roots didn't have the correct semantics for equality and ordered comparisons. They are now unequal to unmapped roots.
* When not using path mapping, the `StarlarkSemantics` of a thread used to evaluate `map_each` callbacks is not modified.

These changes require splitting `PathMappers` out of `analysis_cluster` and also make `StrippingPathMapper` a subclass of `PathMapper` instead of using an anonymous one.

Closes bazelbuild#22227.

PiperOrigin-RevId: 657449600
Change-Id: If949d23acab163cb192ea3af1baeb7a3caca7339
github-merge-queue bot pushed a commit that referenced this pull request Sep 12, 2024
Fixes the following issues with path mapping applied to `map_each`
functions:
* Action keys could be stale if an action implementation switches from
hard-coded artifact strings to `File`s mapped at execution time. This
commit introduces a special `PathMapper` instance for fingerprinting,
see the long comment on `PathMappers.FOR_FINGERPRINTING`. It includes a
number of tests to verify that neither too much nor too little is mapped
during action key computation.
* The Starlark objects representing mapped artifact roots didn't have
the correct semantics for equality and ordered comparisons. They are now
unequal to unmapped roots.
* When not using path mapping, the `StarlarkSemantics` of a thread used
to evaluate `map_each` callbacks is not modified.

These changes require splitting `PathMappers` out of `analysis_cluster`
and also make `StrippingPathMapper` a subclass of `PathMapper` instead
of using an anonymous one.

Closes #22227.

PiperOrigin-RevId: 657449600
Change-Id: If949d23acab163cb192ea3af1baeb7a3caca7339

Closes #22227
@iancha1992
Copy link
Member

The changes in this PR have been included in Bazel 7.4.0 RC1. Please test out the release candidate and report any issues as soon as possible.
If you're using Bazelisk, you can point to the latest RC by setting USE_BAZEL_VERSION=7.4.0rc1. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Configurability platforms, toolchains, cquery, select(), config transitions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants