bazel syntax: simplify SkylarkNestedSet type rules

Previously, StarlarkNestedSet would compute the "intersection"
of the existing type and the type of each new element.
Now, it checks that they match exactly.

Already in Starlark, the expression depset([1, 2, "three"]) fails
because the set commits to integers after the first value
and rejects the string because their intersection is "object".
I could not find any place where the intersection was interesting.
One might expect tuple + list to intersect to sequence, but
lists are not valid elements. (The approach of inferring "the"
type from a value seems problematic. Ideally all SkylarkNestedSets
would have their types determined explicitly.)

The check that rejects dicts and lists is now done by checkValidDictKey,
just like in Dict. (This avoids another call to intersection).
The real requirement is that values are hashable, not immutable.

In SkylarkType:
- eliminate the only external uses of canBeCastTo and getType.
- eliminate the STRING_PAIR concept. It seems a little arbitrary:
  just because the first element is a pair doesn't mean all elements
  need be tuples of length 2.
- lock down nearly all of the API, which I plan to redesign
  to solve two problems:

  1) StarlarkType values should act as well-typed converter functions
     for arbitrary values. Users should be able to write:
       List<String> list = convert(myvar, stringListType, "myvar")
     and get a correctly typed result or a high-quality error such as
     "for myvar[3]: got int, want string".

  2) StarlarkType should enable deep checks, unlike Class checks
     which are shallow though shallow checks should be possible too:
       SkylarkType<List<?>> ANY_LIST
     would not visit the list elements.

  A SkylarkType would thus act like a "reified generic" type descriptor.

PiperOrigin-RevId: 281811861
10 files changed
tree: 8b599e673293f674150557dbf716f2fe381dde70
  1. .bazelci/
  2. examples/
  3. scripts/
  4. site/
  5. src/
  6. third_party/
  7. tools/
  8. .bazelrc
  9. .gitattributes
  10. .gitignore
  11. AUTHORS
  12. BUILD
  13. CHANGELOG.md
  14. CODEOWNERS
  15. combine_distfiles.py
  16. combine_distfiles_to_tar.sh
  17. compile.sh
  18. CONTRIBUTING.md
  19. CONTRIBUTORS
  20. distdir.bzl
  21. ISSUE_TEMPLATE.md
  22. LICENSE
  23. README.md
  24. WORKSPACE
README.md

Bazel

{Fast, Correct} - Choose two

Build and test software of any size, quickly and reliably.

  • Speed up your builds and tests: Bazel rebuilds only what is necessary. With advanced local and distributed caching, optimized dependency analysis and parallel execution, you get fast and incremental builds.

  • One tool, multiple languages: Build and test Java, C++, Android, iOS, Go, and a wide variety of other language platforms. Bazel runs on Windows, macOS, and Linux.

  • Scalable: Bazel helps you scale your organization, codebase, and continuous integration solution. It handles codebases of any size, in multiple repositories or a huge monorepo.

  • Extensible to your needs: Easily add support for new languages and platforms with Bazel's familiar extension language. Share and re-use language rules written by the growing Bazel community.

Getting Started

Documentation

Contributing to Bazel

See CONTRIBUTING.md

Build status