bazel: encapsulate the representation of NestedSet

Before, NestedSet exposed its representation far and wide
in ways obvious (getChildrenUnsafe) and subtle (downcasting
NestedSetView.identity()).

This change encapsulates the representation of NestedSet,
allowing it to be improved in future. It also documents the
data type's conceptual model.

The API has changed as follows:

- NestedSetView is deleted. Its split, getDirect, and getTransitive
  methods have been moved to NestedSet itself, since they have
  always been well defined by the core abstraction.
  getDirect is now getLeaves and getTransitive is getNonLeaves.

- NestedSetView.identifier is gone. Instead, NestedSet.Node is a
  truly opaque identifier for a node in the graph's internal
  representation. It provides only the hash and equals operations.
  (It might seem more logical for getLeaves/NonLeaves to be defined
  over Nodes, returning Nodes, but in practice no client seems
  to need that.)

- NestedSet.getChildrenUnsafe is replaced by forEachElement,
  which provides the pruned traversal needed by [redacted;
  see b/157992832]. Unfortunately it still
  exposes the internal node to the 'prune' callback, violating
  encapsulation, though it is much less invasive than before.
  Functionally, this  method could be completely replaced
  by NestedSetVisitor or by use of Node, but performance may
  be a concern. Will address in a follow-up.

- Delete childrenToString.

- The public API no longer mentions "children".

Also, delete rawChildren() and expose NestedSet.children to the package.

This is a preparatory cleanup for CL 310551947, which will
represent the depth of the graph in the graph, obviating the
problem of set flattening throwing unchecked exceptions at
surprising times, the catching of which creates a bad dependency
from the Starlark interpreter to NestedSet.

PiperOrigin-RevId: 315079199
24 files changed
tree: a0dcf2aa8f9238e559c435b54704139da1a1f906
  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