bazel syntax: hide BaseFunction and matchSignature

commit c568d844b6c73160273e60096fa9507d6755acde replaced most uses of BaseFunction with StarlarkCallable,
which abstracts all function-like values. This change removes BaseFunction
from the API, and a follow-up will merge it into its sole remaining subclass, StarlarkFunction.

Most of the classes that implemented BaseFunction did so only for its
trivial toString, repr, and isImmutable methods, which have been copied
as needed, and in some cases tweaked.

SkylarkProvider formerly used BaseFunction and matchSignature
to match arguments to schema fields, but provider instantiation can be
done more efficiently by permuting the argument array directly, without
allocating any hash tables or indeed any additional memory at all.
Thanks to Murali Ganapathy for the algorithm.
This also unifies the schemaful and schemaless cases.

This sets the stage for removing FunctionSignature from the API.
Its only remaining uses are in the doc tools.

---

Also, this CL causes ParamDescriptor to no longer use SkylarkType internally
to validate arguments and to describe types for error messages.
Parameter types are now represented as a union of Class symbols.
Validation uses instanceof. Error messages are produced using
getDataTypeNameFromClass.

The reason this change is bundled in this CL is that SkylarkType.of
(a conceptual mess) uses fragile heuristics to decide whether a value is
a "function" based on whether it implements BaseFunction; this breaks
when changed to use StarlarkCallable.

Type errors in the function call machinery now report only what they test,
that is, the top-level constructor: "want list", not "want list of strings".
The old messages were a bit of a lie because the call would happily accept
lists of other types unless the function implementation performed an explicit
element type check. Such checks continue to produce detailed errors:
"got list of X, want list of Y".

The 'generic1' annotation no longer affects the interpreter;
it is purely for documentation.

The only remaining use of SkylarkType is for Depsets.
A follow-up change will make the necessary renamings and simplifications.

PiperOrigin-RevId: 307424087
31 files changed
tree: dd9d35cd3861175d77f939438d05fa8e5ed8747b
  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