bazel: incompatible_remove_rule_name_parameter
There are semantic problems with using rule(name=..., ...)
instead of using name = rule(...)
on the top-level, because there can be multiple rules with the same name exported from a single bzl
file.
We decided to remove name
parameter from the rule
call.
Expected timeline:
- Flip the flag with Bazel release 6.0.0
- Remove the flag and implementation from Bazel@HEAD in Q4 2022.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (11 by maintainers)
Commits related to this issue
- Remove use of rule.name from cc_test The pair (resolved .bzl label, rule class name) ought to uniquely identify a starlark-defined rule class. Related: https://github.com/bazelbuild/bazel/issues/163... — committed to bazelbuild/bazel by comius 2 years ago
- Flip default value of incompatible_remove_rule_name_parameter RELNOTES[INC]: name parameter is removed from rule call (https://github.com/bazelbuild/bazel/issues/16301) PiperOrigin-RevId: 477141270 ... — committed to bazelbuild/bazel by comius 2 years ago
- Automated rollback of commit 59e51fe625f485dc664928ae0ad93035808779f3. *** Reason for rollback *** Breaking CI projects *** Original change description *** Flip default value of incompatible_remov... — committed to bazelbuild/bazel by a-googler 2 years ago
- Rollforward of https://github.com/bazelbuild/bazel/commit/59e51fe625f485dc664928ae0ad93035808779f3: Flip default value of incompatible_remove_rule_name_parameter RELNOTES[INC]: name parameter is remo... — committed to bazelbuild/bazel by comius 2 years ago
- Remove use of rule.name from cc_test The pair (resolved .bzl label, rule class name) ought to uniquely identify a starlark-defined rule class. Related: https://github.com/bazelbuild/bazel/issues/163... — committed to aiuto/bazel by comius 2 years ago
- Flip default value of incompatible_remove_rule_name_parameter RELNOTES[INC]: name parameter is removed from rule call (https://github.com/bazelbuild/bazel/issues/16301) PiperOrigin-RevId: 477141270 ... — committed to aiuto/bazel by comius 2 years ago
- Automated rollback of commit 59e51fe625f485dc664928ae0ad93035808779f3. *** Reason for rollback *** Breaking CI projects *** Original change description *** Flip default value of incompatible_remov... — committed to aiuto/bazel by a-googler 2 years ago
- Rollforward of https://github.com/bazelbuild/bazel/commit/59e51fe625f485dc664928ae0ad93035808779f3: Flip default value of incompatible_remove_rule_name_parameter RELNOTES[INC]: name parameter is remo... — committed to aiuto/bazel by comius 2 years ago
- Release 6.0.0-pre.20221007.4 (2022-10-20) Baseline: 5d0e5a7ba415b981390bf9579da644e1065b2a36 Cherry picks: + 512d9b5cf784cc4450baf50362ab3d88cd815184: Automated rollback of commit 2190... — committed to bazelbuild/bazel by a-googler 2 years ago
- Release 6.0.0 (2022-12-19) Baseline: d60ce2c7c86393638c77698c00c2168a7a936a53 Cherry picks: + 490f8badf4f6f4ae8b96697f08267fdb083ccf5f: kshyanashree is the release manager of 6.0.0 + 4e6... — committed to bazelbuild/bazel by a-googler 2 years ago
- chore(deps): update dependency bazel to v6 (#83) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Updat... — committed to cgrindel/rules_swift_package_manager by renovate[bot] 2 years ago
- Release 6.0.0 (2022-12-19) Baseline: d60ce2c7c86393638c77698c00c2168a7a936a53 Cherry picks: + 490f8badf4f6f4ae8b96697f08267fdb083ccf5f: kshyanashree is the release manager of 6.0.0 + 4e6... — committed to joomcode/bazel by a-googler 2 years ago
- Release 6.0.0 (2022-12-19) Baseline: d60ce2c7c86393638c77698c00c2168a7a936a53 Cherry picks: + 490f8badf4f6f4ae8b96697f08267fdb083ccf5f: kshyanashree is the release manager of 6.0.0 + 4e6... — committed to bazelbuild/bazel by a-googler 2 years ago
- Release 7.0.0-pre.20230417.1 (2023-04-25) Baseline: 0a47a1fb04efef598376d4ee7b383add1febcc6c Incompatible changes: - Removing java_common.javac_jar Starlark call. - native.existing_rule now ret... — committed to bazelbuild/bazel by a-googler a year ago
- Release 7.0.0-pre.20230417.1 (2023-04-25) Baseline: 0a47a1fb04efef598376d4ee7b383add1febcc6c Incompatible changes: - Removing java_common.javac_jar Starlark call. - native.existing_rule now ret... — committed to fweikert/bazel by a-googler a year ago
The
rule.name
was never designed to support “anonymous rules” or to fix problems how rule classes are defined. I can see how it became useful, but I think those uses still look very 'workaroundish". There is also the problem that the name appears in queries and is used by the tools to recognize the rule - only the name part, not the ‘bzl’ file the rule is in.I believe the problems you’re stating need be addressed and they need to be addressed holistically.
rule.name
accidentally solves them, but only partially. This will make the complete solution more difficult. And the implementation has other problems I mentioned before.Sorry, but it’s going away.
The status quo ante causes serious user confusion and frequent problems where rule authors do not realize that the name given to the left hand side of the rule assignment is part of that rule’s public API no matter how many underscores they put in front of it or how many layers of macros they bury it in. This causes real problems when rule authors refactor their rules and think that the “public” macro is the only relevant aspect.
While this fact exists in the documentation, it is hidden and obscure.
The issue I believe @cpsauer intended to link to is https://github.com/bazelbuild/bazel/issues/14673.
[Hopping in since tagged. Thanks @fmeum.]
I’d like to second that there’s a valuable, fairly broad use case that’d be hampered by the removal of the ability to have “anonymous” rules.
#14673 has all the good details, including a short example, but basically this enabled clean, higher order functions wrapping rule creation. In that case, and with fmeum’s rules_meta, they were enabling easy rule reuse while adding custom configuration to the build graph. More generally, it seems a bit of a bummer to remove the power of higher order functions around rules.
One quick fix might be to automatically export all otherwise-unexported rules under a hash, eliminating the error case completely? Or, to retain the error for true mistakes, to only do so when it has been captured by a function? Or perhaps there’s a more direct way to implement exporting captured rules namelessly?
[@fmeum, am I right that one could work around a removal of lambda-rule functionality manually by returning both the rule and macro to the user, with the instructions to store the rule in an arbitrarily-named, unused variable? Kinda gross to have to expose the implementation like that through the interface…but at least that might not make it a totally hard blocker for rules_meta.]
[Tagging also @gregestren, since he’d been involved in #14673, has thought about this way more than I have, and might be interested. Maybe there are also other, separate solutions in the works that he’d know about.]