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

Trim input build settings after transition #13971

Closed

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Sep 10, 2021

By convention, BuildOptions should not contain Starlark build settings
that are set to their default values. However, if a Starlark transition
has a build setting as an input, the value of that setting has to be
added to the input BuildOptions temporarily so that it can be read by
the transition.

Before this commit, if a build setting was an input but not an output of
a transition, its default value remained in the BuildOptions and could
cause action conflicts. With this commit, all build settings rather than
only output build settings are trimmed post-transition if they are set
to their default value.

Fixes #12888.

Copy link
Contributor

@gregestren gregestren left a comment

Choose a reason for hiding this comment

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

Just for posterity, do you see any conceptual risks or blemishes to this change? Or does it look fully "elegant"?

I suspect the latter but want to sanity check with you.

@gregestren
Copy link
Contributor

@sdtwigg relevant to your transition naming refactoring plans.

@sdtwigg
Copy link
Contributor

sdtwigg commented Sep 24, 2021

This looks good and is a reasonable idea conceptually.

@gregestren can you verify that this 'sits in the right place' wrt where you added Starlark transition caching?

@fmeum fmeum force-pushed the trim-default-starlark-settings branch 2 times, most recently from 10d8b83 to fd79299 Compare September 25, 2021 18:47
@fmeum fmeum changed the title Trim default-valued build settings after Starlark transition Trim input build settings after transition Sep 25, 2021
@fmeum
Copy link
Collaborator Author

fmeum commented Sep 25, 2021

Just for posterity, do you see any conceptual risks or blemishes to this change? Or does it look fully "elegant"?

I suspect the latter but want to sanity check with you.

It didn't feel that fully elegant and that's because it used the wrong approach - I missed that there already was logic that was trimming default values, just not all of them. In hindsight that is obvious: If it weren't the case, all no-op transitions would have caused action conflicts (rather than only those with input-only build settings).

I updated the PR and would now call it fully "elegant".

@fmeum fmeum force-pushed the trim-default-starlark-settings branch from fd79299 to a4cd39c Compare September 25, 2021 18:56
@gregestren
Copy link
Contributor

@gregestren can you verify that this 'sits in the right place' wrt where you added Starlark transition caching?

Yes. This code only triggers when the transition is actually being executed, and its output is prepared. Caching should purely wrap around that.

@gregestren
Copy link
Contributor

It didn't feel that fully elegant and that's because it used the wrong approach - I missed that there already was logic that was trimming default values, just not all of them. In hindsight that is obvious: If it weren't the case, all no-op transitions would have caused action conflicts (rather than only those with input-only build settings).

I updated the PR and would now call it fully "elegant".

Very nice catch! And indeed much simpler this round. Thanks for that update. And solid test coverage.

Copy link
Contributor

@gregestren gregestren left a comment

Choose a reason for hiding this comment

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

Re: #12888 (comment), can you confirm the return {} code path also get this optimization? Maybe a test case for that too?

By convention, BuildOptions should not contain Starlark build settings
that are set to their default values. However, if a Starlark transition
has a build setting as an input, the value of that setting has to be
added to the input BuildOptions temporarily so that it can be read by
the transition.

Before this commit, if a build setting was an input but not an output of
a transition, its default value remained in the BuildOptions and could
cause action conflicts. With this commit, all build settings rather than
only output build settings are trimmed post-transition if they are set
to their default value.

Fixes bazelbuild#12888.
@fmeum fmeum force-pushed the trim-default-starlark-settings branch from a4cd39c to c417fe3 Compare September 28, 2021 16:13
@fmeum
Copy link
Collaborator Author

fmeum commented Sep 28, 2021

Re: #12888 (comment), can you confirm the return {} code path also get this optimization? Maybe a test case for that too?

I added a test case verifying that input build settings are trimmed even for return {} transitions. Is that what you meant?

@sdtwigg
Copy link
Contributor

sdtwigg commented Sep 28, 2021

LGTM on my end.

PS: Really like how elegant it is now :D

@gregestren
Copy link
Contributor

Re: #12888 (comment), can you confirm the return {} code path also get this optimization? Maybe a test case for that too?

I added a test case verifying that input build settings are trimmed even for return {} transitions. Is that what you meant?

Yes. Thank you.

@bazel-io bazel-io closed this in 5e57e84 Sep 28, 2021
fmeum added a commit to fmeum/bazel that referenced this pull request Mar 6, 2022
Starlark transition logic temporarily explicitly sets all input build
settings of a transition to their defaults. Since bazelbuild#13971, these values
are cleared after the transition. However, since then they have also
been subject to type validation, which is not only unnecessary, but
also breaks in the special case of a string build setting with
allow_multiple.

With this commit, input-only build settings are unconditionally
stripped from the post-transition BuildOptions and do not undergo
validation. This is made possible by a refactoring of
`StarlarkTransition#validate` that extracts the validation logic into a
separate function and also improves some variable names.
fmeum added a commit to fmeum/bazel that referenced this pull request Mar 8, 2022
Starlark transition logic temporarily explicitly sets all input build
settings of a transition to their defaults. Since bazelbuild#13971, these values
are cleared after the transition. However, since then they have also
been subject to type validation, which is not only unnecessary, but
also breaks in the special case of a string build setting with
allow_multiple.

With this commit, input-only build settings at their literal default
values are removed from the post-transition BuildOptions without going
through validation. This is made possible by a refactoring of
`StarlarkTransition#validate` that extracts the validation logic into a
separate function and also improves some variable names.
bazel-io pushed a commit that referenced this pull request Mar 14, 2022
Starlark transition logic temporarily explicitly sets all input build
settings of a transition to their defaults. Since #13971, these values
are cleared after the transition. However, since then they have also
been subject to type validation, which is not only unnecessary, but
also breaks in the special case of a string build setting with
allow_multiple.

With this commit, input-only build settings are unconditionally
stripped from the post-transition BuildOptions and do not undergo
validation. This is made possible by a refactoring of
`StarlarkTransition#validate` that extracts the validation logic into a
separate function and also improves some variable names.

Fixes #14894

Closes #14972.

PiperOrigin-RevId: 434589143
fmeum added a commit to fmeum/bazel that referenced this pull request Mar 15, 2022
Starlark transition logic temporarily explicitly sets all input build
settings of a transition to their defaults. Since bazelbuild#13971, these values
are cleared after the transition. However, since then they have also
been subject to type validation, which is not only unnecessary, but
also breaks in the special case of a string build setting with
allow_multiple.

With this commit, input-only build settings are unconditionally
stripped from the post-transition BuildOptions and do not undergo
validation. This is made possible by a refactoring of
`StarlarkTransition#validate` that extracts the validation logic into a
separate function and also improves some variable names.

Fixes bazelbuild#14894

Closes bazelbuild#14972.

PiperOrigin-RevId: 434589143
Wyverald pushed a commit that referenced this pull request Mar 15, 2022
Starlark transition logic temporarily explicitly sets all input build
settings of a transition to their defaults. Since #13971, these values
are cleared after the transition. However, since then they have also
been subject to type validation, which is not only unnecessary, but
also breaks in the special case of a string build setting with
allow_multiple.

With this commit, input-only build settings are unconditionally
stripped from the post-transition BuildOptions and do not undergo
validation. This is made possible by a refactoring of
`StarlarkTransition#validate` that extracts the validation logic into a
separate function and also improves some variable names.

Fixes #14894

Closes #14972.

PiperOrigin-RevId: 434589143
@fmeum fmeum deleted the trim-default-starlark-settings branch November 23, 2022 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes team-Configurability platforms, toolchains, cquery, select(), config transitions type: bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build failure caused by no-op starlark transition (friction between Starlark None and java null)
3 participants