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

Stringify Labels in display form in Args #21702

Closed
wants to merge 8 commits into from

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Mar 14, 2024

Labels added to Args are now formatted in display form, which means that they will be repo-relative if referring to the main repo and use an apparent repository name if possible.

Previously, labels were formatted in repo-relative form if referring to the main repo and using canonical repository names exclusively for external repos. At the same time, Args docs explicitly stated that the exact stringification of any type other than File is unspecified. The previous behavior was problematic since it neither always used canonical labels (which could be useful for writing tests that check these labels against an allowlist) nor provided labels that could be included in BUILD files (canonical names are explicitly unstable). Furthermore, whether a label resulted in a string prefixed with a single or two @s already dependended on a user choice, namely the value of --enable_bzlmod.

Thus, this change is not considered to be breaking. It makes it so that existing rulesets relying on default stringification to return a BUILD-file compatible label in WORKSPACE continue to do so with Bzlmod with no code changes.

This change aims to be as memory efficient as possible:

  • Single labels or sequences of labels that reference targets in the main repo incur no memory overhead.
  • Labels referring to external repos as well as NestedSets of labels result in an additional Skyframe dependency for each target using the command line as well as one additional reference (4 bytes) stored in the command line's arguments.

Work towards #20486

@fmeum fmeum force-pushed the 20486-label-args branch 3 times, most recently from efd5fa4 to 1dea68c Compare March 14, 2024 17:57
@fmeum fmeum changed the title 20486 label args Stringify Labels in display form in Args Mar 14, 2024
@fmeum fmeum force-pushed the 20486-label-args branch 3 times, most recently from ec8a22c to f3aa519 Compare March 14, 2024 21:42
@fmeum fmeum requested review from justinhorvitz and Wyverald March 14, 2024 21:44
@fmeum fmeum marked this pull request as ready for review March 14, 2024 21:44
@fmeum fmeum requested a review from a team as a code owner March 14, 2024 21:44
@fmeum fmeum requested review from katre and removed request for a team and katre March 14, 2024 21:44
@github-actions github-actions bot added team-Configurability platforms, toolchains, cquery, select(), config transitions awaiting-review PR is awaiting review from an assigned reviewer labels Mar 14, 2024
@fmeum
Copy link
Collaborator Author

fmeum commented Mar 14, 2024

@justinhorvitz This is my attempt at realizing your suggestions to reduce memory usage while also addressing @Wyverald's concerns about adding yet another method to Label that only has a very niche use case. In fact, this PR adds no new API and instead, in my opinion, improves the so far unspecified default stringification behavior.

Edit: I will add unit test coverage for the new Args logic if you agree with the overall approach.

@fmeum fmeum force-pushed the 20486-label-args branch 2 times, most recently from 671986c to 21296d7 Compare March 14, 2024 21:50
@fmeum
Copy link
Collaborator Author

fmeum commented Mar 14, 2024

@zhengwei143 I am using Java 21 API features in this PR, but it results in compilation failures on Windows arm64. Are you still working on this?

@zhengwei143
Copy link
Contributor

@zhengwei143 I am using Java 21 API features in this PR, but it results in compilation failures on Windows arm64. Are you still working on this?

We've identified this towards the later part of today, 2 parts need that likely need to be fixed:

We'll look into this tomorrow morning.

@justinhorvitz
Copy link
Contributor

Sorry for the delay. Can you sync to pick up de4bcb1? I suspect you might have non-trivial merge conflicts. Then I'll review.

@fmeum fmeum force-pushed the 20486-label-args branch from e96c574 to a902cd5 Compare March 22, 2024 11:20
@fmeum
Copy link
Collaborator Author

fmeum commented Mar 22, 2024

@justinhorvitz I resolved the conflicts.

Copy link
Contributor

@justinhorvitz justinhorvitz left a comment

Choose a reason for hiding this comment

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

Overall approach looks good.

+ " context of the main repository. If possible, the string representation uses the"
+ " apparent name of a repository in favor of the repository's canonical name, which"
+ " makes this representation suited for use in BUILD files. While the exact form of"
+ " the representation is not guaranteed, typical examples are"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it not guaranteed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't want to commit to the full details of how labels are formed: Are we emitting @foo as @foo or @foo//:foo? Do we always return labels with an apparent repo name if there is one for the repo? I could expand on the guarantees if you think that's worthwhile and doesn't unnecessarily constrain us.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should get an opinion from @Wyverald for this documentation. I don't deal with repository mappings much so I'm not sure what to document here. In general documentation that makes it sound like a mystery is concerning to me, so an additional opinion would help.

Copy link
Member

Choose a reason for hiding this comment

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

I don't have strong opinions here; but IMO the things you mentioned --

Are we emitting @foo as @foo or @foo//:foo? Do we always return labels with an apparent repo name if there is one for the repo?

-- are perfectly fine to guarantee. I can't really foresee a situation where we'd want to emit @foo//:foo instead of @foo, or use a canonical label when an apparent one exists.

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 do emit @foo//:foo at the moment though. I could see getting rid of the colon ending up breaking tooling that consumes these labels, so I'm not sure whether that would make it safe to cherry-pick. At the same time, guaranteeing that we never use the shorthand also doesn't seem ideal...

Copy link
Member

Choose a reason for hiding this comment

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

hmm, that's fair. I'll leave it up to your judgment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since the change would be doc only, I'll mentally snooze and revisit it later.

@fmeum fmeum force-pushed the 20486-label-args branch from c22a9f8 to 287d696 Compare March 23, 2024 21:02
@fmeum fmeum requested a review from justinhorvitz March 23, 2024 22:33
@fmeum
Copy link
Collaborator Author

fmeum commented Mar 27, 2024

I fixed the test failure, the remaining one appears to be by chance.

Copy link
Contributor

@justinhorvitz justinhorvitz left a comment

Choose a reason for hiding this comment

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

Looks good!

@fmeum
Copy link
Collaborator Author

fmeum commented Mar 27, 2024

@bazel-io fork 7.2.0

@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 Mar 28, 2024
@fmeum fmeum force-pushed the 20486-label-args branch from c62ee1b to 6bf0fd0 Compare March 29, 2024 23:07
@fmeum fmeum requested a review from Wyverald March 29, 2024 23:07
fmeum added 8 commits March 31, 2024 11:11
`Label`s added to `Args` are now formatted in display form, which means
that they will be repo-relative if referring to the main repo and use an
apparent repository name if possible.

Previously, labels were formatted in repo-relative form if referring to
the main repo and using canonical repository names exclusively for
external repos. At the same time, `Args` docs explicitly stated that
the exact stringification of any type other than `File` is unspecified.
The previous behavior was problematic since it neither always used
canonical labels (which could be useful for writing tests that check
these labels against an allowlist) nor provided labels that could be
included in BUILD files (canonical names are explicitly unstable).
Furthermore, whether a label resulted in a string prefixed with a single
or two `@`s already dependended on a user choice, namely the value of
`--enable_bzlmod`.

Thus, this change is not considered to be breaking. It makes it so that
existing rulesets relying on default stringification to return a BUILD-
file compatible label in WORKSPACE continue to do so with Bzlmod with no
code changes.

This change aims to be as memory efficient as possible:
* Single labels or sequences of labels that reference targets in the
  main repo incur no memory overhead.
* Labels referring to external repos as well as `NestedSet`s of labels
  result in an additional Skyframe dependency for each target using the
  command line as well as one additional reference (4 bytes) stored in
  the command line's `arguments`.
@fmeum fmeum force-pushed the 20486-label-args branch from 6bf0fd0 to 6cc995b Compare March 31, 2024 09:11
@copybara-service copybara-service bot closed this in 9d3a8b0 Apr 1, 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 Apr 1, 2024
@fmeum fmeum deleted the 20486-label-args branch April 1, 2024 22:04
copybara-service bot pushed a commit that referenced this pull request Apr 9, 2024
The change in #21702 only fixed the buildozer fixup messages for `java_*` actions entirely defined in Starlark. This commit makes the analogous change to the remaining native actions.

Related to #20486 and #21702

Closes #21827.

PiperOrigin-RevId: 623253302
Change-Id: Iadc2b0d8ce64f359b921ad7a7c489111a3a29997
iancha1992 pushed a commit to iancha1992/bazel that referenced this pull request Apr 9, 2024
The change in bazelbuild#21702 only fixed the buildozer fixup messages for `java_*` actions entirely defined in Starlark. This commit makes the analogous change to the remaining native actions.

Related to bazelbuild#20486 and bazelbuild#21702

Closes bazelbuild#21827.

PiperOrigin-RevId: 623253302
Change-Id: Iadc2b0d8ce64f359b921ad7a7c489111a3a29997
fmeum added a commit to fmeum/bazel that referenced this pull request Apr 10, 2024
`Label`s added to `Args` are now formatted in display form, which means that they will be repo-relative if referring to the main repo and use an apparent repository name if possible.

Previously, labels were formatted in repo-relative form if referring to the main repo and using canonical repository names exclusively for external repos. At the same time, `Args` docs explicitly stated that the exact stringification of any type other than `File` is unspecified. The previous behavior was problematic since it neither always used canonical labels (which could be useful for writing tests that check these labels against an allowlist) nor provided labels that could be included in BUILD files (canonical names are explicitly unstable). Furthermore, whether a label resulted in a string prefixed with a single or two `@`s already dependended on a user choice, namely the value of `--enable_bzlmod`.

Thus, this change is not considered to be breaking. It makes it so that existing rulesets relying on default stringification to return a BUILD-file compatible label in WORKSPACE continue to do so with Bzlmod with no code changes.

This change aims to be as memory efficient as possible:
* Single labels or sequences of labels that reference targets in the main repo incur no memory overhead.
* Labels referring to external repos as well as `NestedSet`s of labels result in an additional Skyframe dependency for each target using the command line as well as one additional reference (4 bytes) stored in the command line's `arguments`.

Work towards bazelbuild#20486

Closes bazelbuild#21702.

PiperOrigin-RevId: 620925978
Change-Id: I54aa807c41bf783aee223482d2309f5cee2726b5
fmeum added a commit to fmeum/bazel that referenced this pull request Apr 10, 2024
The change in bazelbuild#21702 only fixed the buildozer fixup messages for `java_*` actions entirely defined in Starlark. This commit makes the analogous change to the remaining native actions.

Related to bazelbuild#20486 and bazelbuild#21702

Closes bazelbuild#21827.

PiperOrigin-RevId: 623253302
Change-Id: Iadc2b0d8ce64f359b921ad7a7c489111a3a29997
fmeum added a commit to fmeum/bazel that referenced this pull request Apr 10, 2024
The change in bazelbuild#21702 only fixed the buildozer fixup messages for `java_*` actions entirely defined in Starlark. This commit makes the analogous change to the remaining native actions.

Related to bazelbuild#20486 and bazelbuild#21702

Closes bazelbuild#21827.

PiperOrigin-RevId: 623253302
Change-Id: Iadc2b0d8ce64f359b921ad7a7c489111a3a29997
Kila2 pushed a commit to Kila2/bazel that referenced this pull request May 13, 2024
The change in bazelbuild#21702 only fixed the buildozer fixup messages for `java_*` actions entirely defined in Starlark. This commit makes the analogous change to the remaining native actions.

Related to bazelbuild#20486 and bazelbuild#21702

Closes bazelbuild#21827.

PiperOrigin-RevId: 623253302
Change-Id: Iadc2b0d8ce64f359b921ad7a7c489111a3a29997
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.

4 participants