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

[7.2.0] Automatically map paths in Args#map_each #22322

Merged
merged 1 commit into from May 10, 2024

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented May 10, 2024

When path mapping is enabled, File objects accessed in a user-supplied callback passed to Args#map_each automatically have their paths mapped.

Automatic rewriting is preferable to e.g. passing a rewriter object into the callback: All paths emitted into command lines must be rewritten with path mapping as inputs and outputs are staged at the mapped locations, so the user would need to manually map all paths - there is no choice. As an added benefit, the automatic rewriting ensures that existing rules relying on map_each do not need to be modified to use path mapping.

This is a reland of 955b31e, which got rolled back due to a 7% CPU time increase on a benchmark caused by frequent comparisons of equal but not reference equal StarlarkSemantics used as keys in the StarlarkClassDescriptor cache in CallUtils. Instead of overriding equals and hashCode for PathMapper, this change subclasses StarlarkSemantics to provide a different, reference equal instance as the cache key. This is safe since the value associated with the path_mapper key does not affect the availability of any Starlark field or method, just the behavior of their implementations.

Work towards #6526

Closes #21952.

PiperOrigin-RevId: 629546010
Change-Id: Ib21fa2371a28a02f0c868523b410c5a40c2c6c82

Closes #22221

@fmeum fmeum requested a review from a team as a code owner May 10, 2024 15:59
@github-actions github-actions bot added awaiting-review PR is awaiting review from an assigned reviewer team-Configurability Issues for Configurability team team-Performance Issues for Performance teams labels May 10, 2024
@keertk keertk self-requested a review May 10, 2024 16:01
@keertk
Copy link
Member

keertk commented May 10, 2024

@fmeum could you take a look at the failures please?

When path mapping is enabled, `File` objects accessed in a user-supplied callback passed to `Args#map_each` automatically have their paths mapped.

Automatic rewriting is preferable to e.g. passing a rewriter object into the callback: All paths emitted into command lines must be rewritten with path mapping as inputs and outputs are staged at the mapped locations, so the user would need to manually map all paths - there is no choice. As an added benefit, the automatic rewriting ensures that existing rules relying on `map_each` do not need to be modified to use path mapping.

This is a reland of 955b31e, which got rolled back due to a 7% CPU time increase on a benchmark caused by frequent comparisons of equal but not reference equal `StarlarkSemantics` used as keys in the `StarlarkClassDescriptor` cache in `CallUtils`. Instead of overriding `equals` and `hashCode` for `PathMapper`, this change subclasses `StarlarkSemantics` to provide a different, reference equal instance as the cache key. This is safe since the value associated with the `path_mapper` key does not affect the availability of any Starlark field or method, just the behavior of their implementations.

Work towards bazelbuild#6526

Closes bazelbuild#21952.

PiperOrigin-RevId: 629546010
Change-Id: Ib21fa2371a28a02f0c868523b410c5a40c2c6c82

Closes bazelbuild#22221
@fmeum
Copy link
Collaborator Author

fmeum commented May 10, 2024

@fmeum could you take a look at the failures please?

Should be fixed

@keertk keertk enabled auto-merge May 10, 2024 17:18
@keertk keertk requested review from gregestren and aranguyen and removed request for keertk May 10, 2024 17:18
@keertk keertk added this pull request to the merge queue May 10, 2024
Merged via the queue into bazelbuild:release-7.2.0 with commit d4d852c May 10, 2024
32 checks passed
@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label May 10, 2024
@fmeum fmeum deleted the 22221-map-each branch May 11, 2024 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Configurability Issues for Configurability team team-Performance Issues for Performance teams
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants