-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 Label
s in display form in Args
#21702
Conversation
efd5fa4
to
1dea68c
Compare
ec8a22c
to
f3aa519
Compare
@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 Edit: I will add unit test coverage for the new Args logic if you agree with the overall approach. |
671986c
to
21296d7
Compare
@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. |
Sorry for the delay. Can you sync to pick up de4bcb1? I suspect you might have non-trivial merge conflicts. Then I'll review. |
@justinhorvitz I resolved the conflicts. |
There was a problem hiding this 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.
src/main/java/com/google/devtools/build/lib/analysis/starlark/Args.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/starlark/Args.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/starlark/Args.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/starlark/Args.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/starlark/Args.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/analysis/starlark/StarlarkCustomCommandLine.java
Outdated
Show resolved
Hide resolved
+ " 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" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
I fixed the test failure, the remaining one appears to be by chance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
@bazel-io fork 7.2.0 |
...est/java/com/google/devtools/build/lib/starlark/StarlarkRuleImplementationFunctionsTest.java
Outdated
Show resolved
Hide resolved
`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`.
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
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
`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
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
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
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
Label
s added toArgs
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 thanFile
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:
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'sarguments
.Work towards #20486