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

Add exec_group_compatible_with attribute #24964

Closed

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Jan 18, 2025

This change implements the Per-target execution platform constraints for exec groups proposal by adding the exec_group_compatible_with attribute. It differs from the proposal in its accepted from in two ways:

  • During the implementation of the proposal, it was discovered that the test exec group always inherits toolchain requirements and constraints from the default exec group. This behavior makes it impossible to apply additional constraints to the default exec group via exec_compatible_with without also applying them to the test exec group. This preexisting behavior has mostly undesirable consequences: In a multi- or cross-platform build, where exec constraints matter, tests actions and build actions are unlikely to ever be bound to the same toolchain requirements as tests actions don't consume toolchains directly and their intended execution platform is usually closer to the target platform.
  • The proposal also includes the plan to have exec_compatible_with apply to all non-test exec groups and renaming the default execution group to default. This PR does not implement this change as it makes it easier to accidentally apply execution constraints too broadly as can currently happen with tags with --incompatible_allow_tags_propagation (e.g. tags = ["no-remote"] on a test also applies this restriction to the action compiling the test). More fine-grained primitives for adding constraints pose less of a risk.

Fixes #23202
Fixes #23802

RELNOTES: The new exec_group_compatible_with attribute on all rules accepts a dictionary mapping exec group names to lists of additional constraints to request from the exec group's execution platform.

RELNOTES[INC]: Constraints and toolchain requirements added to the default exec group, for example via the toolchains parameter of the rule function or the exec_compatible_with attribute on all rules, no longer apply to the test exec group, which contains the test action on test rules. Instead, use exec_group_compatible_with to apply constraints and/or define an explicit test exec group with toolchain requirements on test rules that require it.

@fmeum fmeum force-pushed the 23802-add-exec-group-compatible-with branch 2 times, most recently from 3df50ad to b54072a Compare January 19, 2025 10:32
@keith
Copy link
Member

keith commented Jan 22, 2025

on this reproducer: #23202 (comment) w/ this change (and the exec_properties one) I get this crash:

FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.RuntimeException: Unrecoverable error while evaluating node '' (requested by nodes ':all, excludedSubdirs=[], filteringPolicy=com.google.devtools.build.lib.pkgcache.FilteringPolicies$FilterManual@7dab797e')
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:551)
        at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:435)
        at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1577)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1489)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:2071)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2033)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:187)
Caused by: net.starlark.java.eval.Starlark$UncheckedEvalException: InvalidStarlarkValueException thrown during Starlark evaluation (an initializer)
        at <starlark>.cc_test(<builtin>:0)
        at <starlark>.<toplevel>(/tmp/repro/BUILD.bazel:30)
Caused by: net.starlark.java.eval.Starlark$InvalidStarlarkValueException: invalid Starlark value: class java.util.ArrayList
        at net.starlark.java.eval.Starlark.checkValid(Starlark.java:136)
        at net.starlark.java.eval.Dict.lambda$copyOf$0(Dict.java:454)
        at com.google.common.collect.SingletonImmutableBiMap.forEach(SingletonImmutableBiMap.java:70)
        at net.starlark.java.eval.Dict.copyOf(Dict.java:451)
        at net.starlark.java.eval.Starlark.fromJava(Starlark.java:217)
        at com.google.devtools.build.lib.packages.Attribute$StarlarkComputedDefaultTemplate.computeValue(Attribute.java:1471)
        at com.google.devtools.build.lib.packages.Attribute$StarlarkComputedDefaultTemplate$1.compute(Attribute.java:1425)
        at com.google.devtools.build.lib.packages.Attribute$ComputationStrategy.computeValuesForAllCombinations(Attribute.java:1228)
        at com.google.devtools.build.lib.packages.Attribute$StarlarkComputedDefaultTemplate.computePossibleValues(Attribute.java:1446)
        at com.google.devtools.build.lib.packages.RuleClass.populateDefaultRuleAttributeValues(RuleClass.java:2438)
        at com.google.devtools.build.lib.packages.RuleClass.populateRuleAttributeValues(RuleClass.java:2208)
        at com.google.devtools.build.lib.packages.RuleClass.createRule(RuleClass.java:2158)
        at com.google.devtools.build.lib.packages.RuleFactory.createRule(RuleFactory.java:106)
        at com.google.devtools.build.lib.packages.RuleFactory.createAndAddRule(RuleFactory.java:141)
        at com.google.devtools.build.lib.analysis.starlark.StarlarkRuleClassFunctions$StarlarkRuleFunction.call(StarlarkRuleClassFunctions.java:1754)
        at net.starlark.java.eval.StarlarkCallable.fastcall(StarlarkCallable.java:87)
        at net.starlark.java.eval.Starlark.fastcall(Starlark.java:804)
        at net.starlark.java.eval.Eval.evalFastcall(Eval.java:821)
        at net.starlark.java.eval.Eval.evalCall(Eval.java:678)
        at net.starlark.java.eval.Eval.eval(Eval.java:547)
        at net.starlark.java.eval.Eval.exec(Eval.java:288)
        at net.starlark.java.eval.Eval.execStatements(Eval.java:83)
        at net.starlark.java.eval.Eval.execFunctionBody(Eval.java:67)
        at net.starlark.java.eval.StarlarkFunction.callWithArguments(StarlarkFunction.java:225)
        at net.starlark.java.eval.StarlarkFunction.positionalOnlyCall(StarlarkFunction.java:209)
        at net.starlark.java.eval.Starlark.positionalOnlyCall(Starlark.java:872)
        at net.starlark.java.eval.Starlark.execFileProgram(Starlark.java:1195)
        at com.google.devtools.build.lib.packages.PackageFactory.executeBuildFileImpl(PackageFactory.java:416)
        at com.google.devtools.build.lib.packages.PackageFactory.executeBuildFile(PackageFactory.java:377)
        at com.google.devtools.build.lib.skyframe.PackageFunction.loadPackage(PackageFunction.java:1188)
        at com.google.devtools.build.lib.skyframe.PackageFunction.compute(PackageFunction.java:539)
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:471)
        at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:435)
        at java.base/java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1577)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:507)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1489)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:2071)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:2033)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:187)

i looked into this a bit last week and I believe it's because this function

return Dict.copyOf(mutability, (Map<?, ?>) x);
needs some sort of "deep copy" in this case, but I couldn't figure that out so I can't say for sure

@fmeum fmeum force-pushed the 23802-add-exec-group-compatible-with branch from 8528676 to c943de3 Compare January 22, 2025 12:30
@keith
Copy link
Member

keith commented Jan 22, 2025

verified on the latest commits here it works with this repro case now!

@fmeum
Copy link
Collaborator Author

fmeum commented Jan 26, 2025

Currently stacked on #24979

@fmeum fmeum marked this pull request as ready for review January 26, 2025 13:08
@fmeum fmeum requested review from a team, gregestren and fweikert as code owners January 26, 2025 13:08
@github-actions github-actions bot added team-Performance Issues for Performance teams team-Configurability platforms, toolchains, cquery, select(), config transitions team-Remote-Exec Issues and PRs for the Execution (Remote) team team-Documentation Documentation improvements that cannot be directly linked to other team labels awaiting-review PR is awaiting review from an assigned reviewer labels Jan 26, 2025
@fmeum fmeum requested a review from katre January 26, 2025 13:08
for (Map.Entry<?, ?> e : map.entrySet()) {
dict.put(e.getKey(), Starlark.fromJava(e.getValue(), null));
}
map.forEach((key, value) -> dict.put(key, Starlark.fromJava(value, null)));
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 is a drive-by improvement to avoid creating and retaining an entry set.

Copy link
Member

@katre katre left a comment

Choose a reason for hiding this comment

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

I've reviewed the documentation changes (great!) and the non-test code changes. I'd like to ask you to split those further, to make import and history easier to read, but overall everything looks good.

I'll review the test changes once those are split out.

fmeum added 2 commits January 28, 2025 16:03
This makes `exec_properties` such as `no-remote-exec` effective for the main test spawn, where it previously only affected post-processing spawns such as test XML generation.
@fmeum fmeum force-pushed the 23802-add-exec-group-compatible-with branch from 5b96980 to b206ce2 Compare January 28, 2025 15:34
@fmeum fmeum force-pushed the 23802-add-exec-group-compatible-with branch from b206ce2 to 91a43af Compare January 28, 2025 15:36
@fmeum
Copy link
Collaborator Author

fmeum commented Jan 28, 2025

I split up all changes above #24979 into five commits that can be reviewed and merged independently (in order).

Since stacked CLs are much easier than stacking PRs on GitHub, could you convert the commits into separate CLs during import? If not, let me know and I can send five separate stacked PRs.

@katre
Copy link
Member

katre commented Jan 28, 2025

Sounds good, I'll try to import separately.

I agree that Github's workflow for stacked PRs is terrible.

Copy link
Member

@katre katre left a comment

Choose a reason for hiding this comment

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

One small nit, let me know if you want to fix it or if I should handle on import.

fmeum added 2 commits January 28, 2025 16:56
This change implements the [Per-target execution platform constraints for exec groups](https://docs.google.com/document/d/1u4zP5MLU3HOt-qlyiNnlxcu4SqOB5tnm32v02vLnd5U/edit) proposal by adding the `exec_group_compatible_with` attribute.

RELNOTES: The new exec_group_compatible_with attribute on all rules accepts a dictionary mapping exec group names to lists of additional constraints to request from the exec group's execution platform.
RELNOTES[INC]: Constraints and toolchain requirements added to the default exec group, for example via the toolchains parameter of the rule function or the exec_compatible_with attribute on all rules, no longer apply to the test exec group, which contains the test action on test rules. Instead, use exec_group_compatible_with to apply constraints and/or define an explicit test exec group with toolchain requirements on test rules that require it.
In addition to documenting the new attribute, existing documented best practices around exec constraints also need to change.
@fmeum fmeum force-pushed the 23802-add-exec-group-compatible-with branch from 91a43af to 5527039 Compare January 28, 2025 15:56
@katre
Copy link
Member

katre commented Jan 28, 2025

Once tests pass I'll start importing these: @gregestren and @fweikert, if you have any comments please add them.

copybara-service bot pushed a commit that referenced this pull request Jan 30, 2025
Part of #24964. Fixes #7989.

PiperOrigin-RevId: 721394994
Change-Id: Ie07d41af5151b496f99c93c2366c2480b9e7ecff
copybara-service bot pushed a commit that referenced this pull request Jan 30, 2025
Part of #24964.

PiperOrigin-RevId: 721429916
Change-Id: Ia473061bf78f283a35eb575097d7f6af5edf81f7
copybara-service bot pushed a commit that referenced this pull request Jan 30, 2025
This change implements the [Per-target execution platform constraints for exec groups](https://docs.google.com/document/d/1u4zP5MLU3HOt-qlyiNnlxcu4SqOB5tnm32v02vLnd5U/edit) proposal by adding the `exec_group_compatible_with` attribute.

Part of #24964.

RELNOTES: The new exec_group_compatible_with attribute on all rules accepts a dictionary mapping exec group names to lists of additional constraints to request from the exec group's execution platform.
PiperOrigin-RevId: 721529975
Change-Id: Ibcd6e9772684272d48a39907eaa9f7503fbaaa6c
copybara-service bot pushed a commit that referenced this pull request Jan 31, 2025
Part of #24964.

RELNOTES[INC]: Constraints and toolchain requirements added to the default exec group, for example via the toolchains parameter of the rule function or the exec_compatible_with attribute on all rules, no longer apply to the test exec group, which contains the test action on test rules. Instead, use exec_group_compatible_with to apply constraints and/or define an explicit test exec group with toolchain requirements on test rules that require it.

PiperOrigin-RevId: 721834175
Change-Id: I8504ff1a08a643ed35a7282f09f6d6faf75d574c
@copybara-service copybara-service bot closed this in dc6ff69 Feb 3, 2025
@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Feb 3, 2025
@fmeum fmeum deleted the 23802-add-exec-group-compatible-with branch February 3, 2025 19:07
@meteorcloudy
Copy link
Member

@fmeum
Copy link
Collaborator Author

fmeum commented Feb 4, 2025

I can work on a fix for Stardoc @tetromino

@fmeum
Copy link
Collaborator Author

fmeum commented Feb 4, 2025

I sent bazelbuild/stardoc#279

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 team-Documentation Documentation improvements that cannot be directly linked to other team labels team-Performance Issues for Performance teams team-Remote-Exec Issues and PRs for the Execution (Remote) team
Projects
None yet
4 participants