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

incompatible_depset_union: Disallow union operator on depsets #5817

Closed
c-parsons opened this issue Aug 8, 2018 · 8 comments
Closed

incompatible_depset_union: Disallow union operator on depsets #5817

c-parsons opened this issue Aug 8, 2018 · 8 comments
Assignees
Labels
incompatible-change Incompatible/breaking change P1 I'll work on this now. (Assignee required)

Comments

@c-parsons
Copy link
Contributor

This is a tracking issue for offering a migration solution for
--incompatible_depset_union

Using +, | or .union on depsets is deprecated. Users should use the new
constructor instead (see https://docs.bazel.build/versions/master/skylark/depsets.html)

@c-parsons c-parsons self-assigned this Aug 8, 2018
@dslomov dslomov changed the title Disallow union operator on depsets incompatible_depset_union: Disallow union operator on depsets Oct 31, 2018
@dslomov dslomov added the incompatible-change Incompatible/breaking change label Oct 31, 2018
@dslomov
Copy link
Contributor

dslomov commented Oct 31, 2018

What is missing for migration: migration docs, length of migration window. After these are done, please add "migration-ready" label.

@laurentlb laurentlb added P1 I'll work on this now. (Assignee required) team-Starlark and removed category: extensibility > skylark labels Nov 21, 2018
@davido
Copy link
Contributor

davido commented Jan 9, 2019

@laurentlb @c-parsons

It turns out that depset union feature is used very frequently in Gerrit Build tool chain. For example when running latest buildifier (0.20.0) in warn mode, we get this (on stable-2.14 branch in gerrit tree):

gerrit $ find . \( -name BUILD -o -name "*.bzl" \) -print | xargs buildifier --lint=warn
./tools/bzl/javadoc.bzl:23: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/javadoc.bzl:24: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/gwt.bzl:204: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/gwt.bzl:205: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/gwt.bzl:208: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/gwt.bzl:210: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/pkg_war.bzl:81: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/pkg_war.bzl:83: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/pkg_war.bzl:92: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/pkg_war.bzl:104: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/pkg_war.bzl:106: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/js.bzl:146: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/js.bzl:150: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/js.bzl:153: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/js.bzl:157: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/js.bzl:198: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/js.bzl:246: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/js.bzl:250: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/js.bzl:254: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/classpath.bzl:5: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/classpath.bzl:6: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)
./tools/bzl/classpath.bzl:8: depset-union: Depsets should be joined using the depset constructor. (https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#depset-union)

It also seems that at least in context of Polymer/Closure custom rules, that were written by @hanwen , it is not really trivial to avoid/re-write usage of depset-union feature.

I wonder if someone from Bazel team could help us to resolve those usages? Or give us more time and postpone deprecation of that feature? Or even re-consider and abandon the deprecation entirely?

Thanks!

@hanwen
Copy link
Contributor

hanwen commented Jan 9, 2019

AFAICT, this is just a syntactic change, where we can change

a.union(b)

to

a = depset(transitive = [a ,b])

@dslomov
Copy link
Contributor

dslomov commented Jan 9, 2019

Is it something we could easily implement in buildifier @c-parsons @vladmos ?

@laurentlb
Copy link
Contributor

Hanwen's solution is the simplest fix.

However, in many cases, the depsets are not properly used. For example, using union or + in a loop can lead to performance issues (https://docs.bazel.build/versions/master/skylark/performance.html#use-depsets).

If we update the code automatically, most users won't have the chance to look at the code and decide if it's a good thing to do.

For example,

d = depset()
for item in mylist:
  d += item.field

may be instead transformed to:

d = depset(transitive = [item.field for item in mylist])

xingao267 added a commit to bazelbuild/rules_docker that referenced this issue Jan 11, 2019
* Fix Bazel incompatible issues.

Some refs:
- bazelbuild/bazel#5817
bazel-io pushed a commit that referenced this issue Apr 25, 2019
Progress towards #5817

RELNOTES: None.
PiperOrigin-RevId: 245242309
bazel-io pushed a commit that referenced this issue Apr 25, 2019
Progress towards #5817

RELNOTES: None.
PiperOrigin-RevId: 245265538
@c4urself
Copy link
Contributor

c4urself commented May 29, 2019

Truly don't understand this change, if the workaround is a = depset(transitive=[a, b]) why not just make that the implementation for .union() or + behind the scenes instead of making people jump through hoops every few releases with these nonsensical changes. Python is the inspiration for Skylark and these changes are making everyone write/change more code for no reason (less Pythonic, more Javaesque)...

@laurentlb
Copy link
Contributor

laurentlb commented May 29, 2019

Let me expand from my previous comment. Each call to depset has a cost. The goal is to make that cost more obvious for users. We did this change because the old behavior was the cause of lots of performance issues.

Old code (now forbidden):

all_deps = depset()
for dep in ctx.attr.deps:
    all_deps = all_deps + dep.files

Discouraged fix:

all_deps = depset()
for dep in ctx.attr.deps:
    all_deps = depset(transitive = [all_deps, dep.files])

Recommended fix:

all_deps = depset(transitive = [dep.files for dep in ctx.attr.deps])

In some cases, keeping the loop is useful (e.g. if you have a condition or complex constructs). You can also accumulate the dependencies in a list, before constructing the depset:

deps_builder = []
for dep in ctx.attr.deps:
    deps_builder.append(dep.files)

all_deps = depset(transitive = deps_builder)

For a Python user, the old code might look fine and many people were writing this kind of code. If you blindly replace .union by its equivalent, the problem is more apparent. You are creating lots of depsets (it will be slow to iterate on those). The suggested fix is not longer and performs better.

So the design decision was made to prevent this tempting error.

@c4urself
Copy link
Contributor

Hmm, that last example makes a lot more sense to me -- will update to that, thanks for the quick reply!

celskeggs pushed a commit to sipb/homeworld that referenced this issue Sep 3, 2019
Multiple changes rolled out to Bazel break our compatibility with the
latest version:
 - bazelbuild/bazel#5817
 - bazelbuild/bazel#5818
 - bazelbuild/bazel#5825

Update our version of zip_file to be compatible with these changes.
celskeggs pushed a commit to sipb/homeworld that referenced this issue Sep 4, 2019
Multiple changes rolled out to Bazel break our compatibility with the
latest version:
 - bazelbuild/bazel#5817
 - bazelbuild/bazel#5818
 - bazelbuild/bazel#5825

Update our version of zip_file to be compatible with these changes.
regisd added a commit to jflex-de/jflex that referenced this issue Nov 5, 2019
* Fix #570. Build broken on Cirrus by upgrade to Bazel v1.0
  * The `single_file` attribute has been replaced by `allow_single_file`.
    Use **bazel_rules** v4 which fixed this. jflex-de/bazel_rules#13
  * add `--incompatible_depset_union=false`
    bazel_pandoc ProdriveTechnologies/bazel-pandoc#6 needs to update for incompatible_depset_union bazelbuild/bazel#5817
  * Use ProdriveTechnologies/bazel-latex#26 because `run_lualatex.py` is not executable
  * In deps, use `https` rather than `http`
* Fix build broken on Travis due to upgrade to Xenial
  * Use openjdk11 because whatever I ask for, that's what I get.
  * Upgrade maven-compiler-plugin to 3.8.0 to fix _class file has wrong version 55.0, should be 53.0_
  * Fix maven-compiler-plugin config for ErrorProne
  * Fix config of maven-javadoc-plugin for newer JDK. https://bugs.openjdk.java.net/browse/JDK-8212233
  * In aggregated sources, update to JDK8 because Xenial doesn't support JDK7 anymore.
    Add manual dep on **javax-annotations.jar** because because JDK8 doesn't provide it anymore.
  * Remove the task that builds the docs because `\tightlist` is not known. #571
regisd pushed a commit to jflex-de/jflex that referenced this issue Nov 5, 2019
Author: Régis Décamps <regisd@google.com>
Date:   Tue Nov 5 11:16:01 2019 +0100

    Fix the build (#569)

    * Fix #570. Build broken on Cirrus by upgrade to Bazel v1.0
      * The `single_file` attribute has been replaced by `allow_single_file`.
        Use **bazel_rules** v4 which fixed this. jflex-de/bazel_rules#13
      * add `--incompatible_depset_union=false`
        bazel_pandoc ProdriveTechnologies/bazel-pandoc#6 needs to update for incompatible_depset_union bazelbuild/bazel#5817
      * Use ProdriveTechnologies/bazel-latex#26 because `run_lualatex.py` is not executable
      * In deps, use `https` rather than `http`
    * Fix build broken on Travis due to upgrade to Xenial
      * Use openjdk11 because whatever I ask for, that's what I get.
      * Upgrade maven-compiler-plugin to 3.8.0 to fix _class file has wrong version 55.0, should be 53.0_
      * Fix maven-compiler-plugin config for ErrorProne
      * Fix config of maven-javadoc-plugin for newer JDK. https://bugs.openjdk.java.net/browse/JDK-8212233
      * In aggregated sources, update to JDK8 because Xenial doesn't support JDK7 anymore.
        Add manual dep on **javax-annotations.jar** because because JDK8 doesn't provide it anymore.
      * Remove the task that builds the docs because `\tightlist` is not known. #571

Updated from target/jflex-parent-1.8.0-SNAPSHOT-sources.jar
bazel-io pushed a commit that referenced this issue Nov 29, 2019
It has been deprecated for a long time.
#5817

RELNOTES: None.
PiperOrigin-RevId: 283060975
wchargin added a commit to tensorflow/tensorboard that referenced this issue Dec 4, 2019
Summary:
The `+`, `+=`, and `|` operators on depsets, as well as `depset.union`,
are deprecated due to performance problems:
<bazelbuild/bazel#5817>

As of a recent Bazel commit, `.union` is removed is removed entirely, so
the operators may be soon on the chopping block:
<bazelbuild/bazel@693963f>

This commit removes remaining uses from TensorBoard.

Google-internal source: <http://cl/283060975> (thanks, @laurentlb!).

Test Plan:
Running `bazel run //tensorboard` still works.

Co-authored-by: Laurent Le Brun <laurentlb@google.com>
wchargin-branch: remove-depset-union
wchargin added a commit to tensorflow/tensorboard that referenced this issue Dec 4, 2019
Summary:
The `+`, `+=`, and `|` operators on depsets, as well as `depset.union`,
are deprecated due to performance problems:
<bazelbuild/bazel#5817>

As of a recent Bazel commit, `.union` is removed is removed entirely, so
the operators may be soon on the chopping block:
<bazelbuild/bazel@693963f>

This commit removes remaining uses from TensorBoard.

Google-internal source: <http://cl/283060975> (thanks, @laurentlb!).

Test Plan:
Running `bazel run //tensorboard` still works.

Co-authored-by: Laurent Le Brun <laurentlb@google.com>
wchargin-branch: remove-depset-union
bazel-io pushed a commit that referenced this issue Mar 27, 2020
#5817

RELNOTES: The flag `--incompatible_depset_union` is removed.
PiperOrigin-RevId: 303325924
luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this issue Sep 4, 2022
    It has been deprecated for a long time.
    bazelbuild/bazel#5817

    RELNOTES: None.
    PiperOrigin-RevId: 283060975
luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this issue Sep 4, 2022
    Fixes bazelbuild/bazel#5817

    RELNOTES[INC]: --incompatible_depset_union is enabled by default.

    PiperOrigin-RevId: 245411420
luca-digrazia pushed a commit to luca-digrazia/DatasetCommitsDiffSearch that referenced this issue Sep 4, 2022
    Progress towards bazelbuild/bazel#5817

    RELNOTES: None.
    PiperOrigin-RevId: 245242309
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
incompatible-change Incompatible/breaking change P1 I'll work on this now. (Assignee required)
Projects
None yet
Development

No branches or pull requests

7 participants