bazel syntax: stop using concurrent.Immutable annotation

The @Immutable annotation specifies that it is for documentation only.
Historically lib.syntax has violated this contract by using the presence
of the annotation as an indication that values of the annotated class
should be considered immutable to Starlark (EvalUtils.isImmutable).

This change adds an explicit override of StarkarkValue.isImmutable to
every class annotated @Immutable. This is more verbose, but clearer
and less magical. In particular, it is obvious that isImmutable is
inherited, whereas I suspect few people memorized whether the
effect of @Immutable was inherited. (It was not.) It also means
there is one mechanism, not two, for expressing Starlark immutability.

(Longer term, I would like to merge isImmutable into isHashable, because
that is isImmutable's only purpose. But things are currently very
inconsistent: for example, you can't hash a list, even if frozen, but
you can hash a struct containing a frozen list, because the isHashable
recursive case checks immutability, not hashability.)

This change required a manual audit, combined with some throwaway static
and dynamic checks. It is possible that I have missed at least one place,
which will manifest as an unexpected "unhashable: foo" error.
I will keep an eye out for regressions. (I am sheriff this week.)

Also:
- Revert the hack added to Immutable that causes the annotations
  to be retained at run time.
- lib.syntax now uses the JSR305 Immutable annotation in the few
  places where it matters, so it no longer depends on lib.concurrent.

RELNOTES: N/A
PiperOrigin-RevId: 312085384
63 files changed
tree: eb097ffcc5fcb16b6850d05285334243ee32dcda
  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