bazel syntax: simplify StarlarkMutable

A sequence may be mutable (list) or not (tuple, range).
This change breaks the subclass relationship between Sequence
and StarlarkMutable so that Tuple and RangeList do not implement it.

This change also deletes the StarlarkMutable abstract base classes
(BaseMutableWrapper, MutableCollection, BaseMutableList, MutableMap), partly
because they would now require Mutable and non-Mutable variants,
but more importantly because, through getContentsUnsafe, they force
inefficiency on all concrete implementations: either the internal representation
must itself be a List, which adds another allocation and indirection, or
getContentsUnsafe must lazily allocate a List wrapper, which generates
unnecessary garbage. A follow-up change will move the accessor methods
down into list and tuple and specialize them to the representation.

Pushing MutableMap down into Dict caused it to have two methods named get,
one annotated and one not. This exposed a bug in which
SkylarkInterfaceUtils.getSkylarkCallable gets confused
as two which method has the annotation.
For now I renamed Dict.get to get2 as the fix is slightly tricky.

StarlarkMutable's lock and unlock methods were in effect moved to EvalUtils.
Its isImmutable and isHashable methods are left abstract. They are
easy enough for subclasses to implement.

The StarlarkMutable class was effectively a "mix in", a base class that one
extends to get some help with implementation. Mixins are not a good
fit with single-inheritance OO languages. This change makes it an interface
with a default implementation of its sole remaining method, checkMutability,
that subclasses should really not override.

Also:
- update the two flavors (mutable/immutable) of Args
- delete mutability methods of RangeList and Tuple.
- delete SHALLOW_IMMUTABLE, which is no longer needed.
- remove unused Mutability from test of serialization.
- add some TODOs.
PiperOrigin-RevId: 280466438
10 files changed
tree: 67e8afbdada19fa3b7a4cf8111ef580989d6dc27
  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