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

Change uses of SplitTransitionProvider to TransitionFactory. #7833

Closed

Conversation

katre
Copy link
Member

@katre katre commented Mar 25, 2019

Removed SplitTransitionProvider.

Part of #7814.

@katre katre requested a review from lberki as a code owner March 25, 2019 19:43
@jin jin added the team-Configurability platforms, toolchains, cquery, select(), config transitions label Mar 25, 2019
Copy link
Contributor

@lberki lberki 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 in principle, but I'm somewhat wary of adding unnecessary abstractions (including classes and methods). Approving on the assumption that these flags and classes will have a good reason to exist, put please keep YAGNI in mind. It's better to add abstractions when you need them instead of preemptively.

*
* <p>For starlark defined rule class transitions, see {@link StarlarkRuleTransitionProvider}.
*
* <p>TODO(bazel-team): Consider allowing dependency-typed attributes to actually return providers
* instead of just labels (see {@link SkylarkAttributesCollection#addAttribute}).
*/
public class StarlarkAttributeTransitionProvider implements SplitTransitionProvider {
public class StarlarkAttributeTransitionProvider
implements TransitionFactory<RuleTransitionData>, SplitTransitionProviderApi {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: rename SplitTransitionProviderApi to TransitionFactoryApi. After all, the class is not a SplitTransitionProvider anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll leave it up to @juliexxia whether to rename, she was discussing a future plan to separate starlark patch and split transitions.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is confusing to me too. What's the purpose of SplitTransitionProviderApi? It looks like just an empty interface to expose SplitTransitionProvider to Starlark? And what does it mean to say isSplit() is true below?

My understanding is this may or may not be a split. So for the scenarios where it isn't a split what do those words mean?

(I guess this is mostly a question for @juliexxia).

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 how it stands makes sense for this PR. I can always do clean up later.

Currently all Starlark transitions attached to attributes (i.e., StarlarkAttributeTransitionProvider transitions) are natively treated like SplitTransitions. This isn't something that's exposed to the user (i.e. if you return a map instead of a map of maps, that works just fine), just something that was done so we didn't have to handle patch and split transitions here.

SplitTransitionProviderApi was originally introduced for the benefit of exposing MultiArchSplitTransitionProvider to Starlark. That's it's only use case other than this. So SplitTransitionProviderApi is still technically the truth. And TransitionFactory seems to obscure the difference between split and patch transitions - @katre as a catch up question, are those both going to fall under this? I think it's mostly important in regards to the restriction that split transitions can't be attached directly to rules.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, TransitionFactory can produce both PatchTransition or SplitTransition. I had considered making it generic in which type it returns (so the signature would become TransitionFactory<PatchTransition, RuleTransitionData>), but

  1. This ends up being cumbersome to use, and
  2. The actual usage would be that Attribute has TransitionFactory<?, RuleTransitionData> so the difference isn't meaningful.

Actual code that cares can check the value of TransitionFactory.isSplit to see if the factory thinks it's returning a SplitTransition or not.

*
* <p>For starlark defined rule class transitions, see {@link StarlarkRuleTransitionProvider}.
*
* <p>TODO(bazel-team): Consider allowing dependency-typed attributes to actually return providers
* instead of just labels (see {@link SkylarkAttributesCollection#addAttribute}).
*/
public class StarlarkAttributeTransitionProvider implements SplitTransitionProvider {
public class StarlarkAttributeTransitionProvider
implements TransitionFactory<RuleTransitionData>, SplitTransitionProviderApi {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is confusing to me too. What's the purpose of SplitTransitionProviderApi? It looks like just an empty interface to expose SplitTransitionProvider to Starlark? And what does it mean to say isSplit() is true below?

My understanding is this may or may not be a split. So for the scenarios where it isn't a split what do those words mean?

(I guess this is mostly a question for @juliexxia).


@Override
public void repr(SkylarkPrinter printer) {
printer.append("<transition object>");
Copy link
Contributor

Choose a reason for hiding this comment

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

How do these get printed in Starlark with this method removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Only starlark transitions need to be printed from Starlark, and they all implement SplitTransitionProviderApi (and so have a repr method).

@gregestren
Copy link
Contributor

Looks good in principle, but I'm somewhat wary of adding unnecessary abstractions (including classes and methods). Approving on the assumption that these flags and classes will have a good reason to exist, put please keep YAGNI in mind. It's better to add abstractions when you need them instead of preemptively.

As @jcater said, we had a lot of discussion about exactly this. In an ideal world I 100% agree. But given the limitations of how these need to be applied the hope is this can consolidate the different abstractions we already have.

Preconditions.checkArgument(attributeMap instanceof ConfiguredAttributeMapper);
return new FunctionSplitTransition(
starlarkDefinedConfigTransition, (ConfiguredAttributeMapper) attributeMap);
}

@Override
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this method used? Like I mentioned above, StarlarkAttributeTransitions are always SplitTransitions according to native code (for now, I suppose this distinction could be made more clear) but might not actually map to multiple output BuildOptions in practice.

Copy link
Member Author

Choose a reason for hiding this comment

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

Callers of TransitionFactory that care whether the transition is a PatchTransition or a SplitTransition can use this to distinguish. It's about the return type and the intent, not on how many actual splits are produced.

Ideally at some point we should unify these further, but I'm not working on that immediately.

*
* <p>For starlark defined rule class transitions, see {@link StarlarkRuleTransitionProvider}.
*
* <p>TODO(bazel-team): Consider allowing dependency-typed attributes to actually return providers
* instead of just labels (see {@link SkylarkAttributesCollection#addAttribute}).
*/
public class StarlarkAttributeTransitionProvider implements SplitTransitionProvider {
public class StarlarkAttributeTransitionProvider
implements TransitionFactory<RuleTransitionData>, SplitTransitionProviderApi {
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 how it stands makes sense for this PR. I can always do clean up later.

Currently all Starlark transitions attached to attributes (i.e., StarlarkAttributeTransitionProvider transitions) are natively treated like SplitTransitions. This isn't something that's exposed to the user (i.e. if you return a map instead of a map of maps, that works just fine), just something that was done so we didn't have to handle patch and split transitions here.

SplitTransitionProviderApi was originally introduced for the benefit of exposing MultiArchSplitTransitionProvider to Starlark. That's it's only use case other than this. So SplitTransitionProviderApi is still technically the truth. And TransitionFactory seems to obscure the difference between split and patch transitions - @katre as a catch up question, are those both going to fall under this? I think it's mostly important in regards to the restriction that split transitions can't be attached directly to rules.

Copy link
Contributor

@juliexxia juliexxia left a comment

Choose a reason for hiding this comment

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

lgtm!

@bazel-io bazel-io closed this in 0a9e1ed Mar 27, 2019
@katre katre deleted the tf-02b-remove-split-transition-provide branch April 3, 2019 20:38
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants