Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename stripPrefix= to strip_prefix= #24019

Closed
wants to merge 2 commits into from

Conversation

jmillikin
Copy link
Contributor

Fixes #16496

@github-actions github-actions bot added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. awaiting-review PR is awaiting review from an assigned reviewer labels Oct 17, 2024
Copy link
Contributor

@tetromino tetromino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you really wish to change the builtin method annotation mechanism, you'd want to (1) add error handling for both old and new parameter names being used in the same call; (2) add error handling for an old parameter name matching either a current or old name of another parameter; (3) add tests to verify all above; (4) run a microbenchmark to check if performance was affected (since getParameterIndex is very frequently used iirc). This would be a lot of work - and it's not clear to me that the work would be worth it, considering that only 2 functions would benefit!

Instead, I'd suggest undoing the annotation changes, and simply adding an extra parameter to the 2 affected functions. Make the new param documented (but make sure to mention the old name in the doc string!), make the old param undocumented, and add a check to make sure that at most 1 of the two parameters is set.

@jmillikin jmillikin force-pushed the rename-strip-prefix branch 2 times, most recently from 2287b82 to 1de5ea0 Compare October 17, 2024 04:18
@jmillikin
Copy link
Contributor Author

jmillikin commented Oct 17, 2024

There's been multiple PRs over the years to try fixing that issue by adding a new parameter:

Doing it with an alias might be slightly more lines of code, but the chances of success seem higher.


If you really wish to change the builtin method annotation mechanism, you'd want to (1) add error handling for both old and new parameter names being used in the same call;

Done. The error checking was actually already there, but I added a test and ensured the error message would consistently refer to the current parameter name.

(2) add error handling for an old parameter name matching either a current or old name of another parameter;

Done. There were no pre-existing checks for duplicate parameter names, so I figured the best spot to implement that would be in the annotation processor.

(3) add tests to verify all above;

Done.

(4) run a microbenchmark to check if performance was affected (since getParameterIndex is very frequently used iirc).

I adjusted the code so it'll only look for an old parameter name if one was detected at the time MethodDescriptor was created.

If more performance is needed in getParameterIndex(), then it might be worth changing that code to use a HashMap instead of a linear search.

@fmeum
Copy link
Collaborator

fmeum commented Oct 17, 2024

A linear search could very well be faster than a HashMap for the case of few parameters (the common case). The additional branch may still have an impact on performance, especially since it also increases the byte code size of the method.

While this can all be ruled out by benchmarks, I also don't think that this migration is worth adding features to the Starlark interpreter. At some point, we may even want to get rid of the old parameter entirely, potentially backed by a bazel_feature.

The old PRs failed because they either weren't backwards compatible or failed to attract attention by reviewers. I can promise that won't happen this time. :⁠-⁠)

@jmillikin jmillikin closed this Oct 17, 2024
@jmillikin jmillikin force-pushed the rename-strip-prefix branch from 1de5ea0 to 1d022f4 Compare October 17, 2024 10:56
@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Oct 17, 2024
@jmillikin jmillikin reopened this Oct 17, 2024
@github-actions github-actions bot added the awaiting-review PR is awaiting review from an assigned reviewer label Oct 17, 2024
@jmillikin
Copy link
Contributor Author

Today I learned that GitHub will automatically close pull requests if the author accidentally pushes without committing.

Branch updated so it effects the rename using a new strip_prefix parameter, renaming and hiding stripPrefix.

@jmillikin jmillikin force-pushed the rename-strip-prefix branch from 02305e9 to 4ed6fb1 Compare October 17, 2024 11:11
Copy link
Collaborator

@fmeum fmeum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@tetromino tetromino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

I took the liberty of rewording the doc string addition a little bit, to mention that the old name may still be used but is now deprecated.

@tetromino
Copy link
Contributor

@meteorcloudy - I've imported the patch internally and sent it to you for review

@github-actions github-actions bot removed the awaiting-review PR is awaiting review from an assigned reviewer label Oct 18, 2024
@jmillikin jmillikin deleted the rename-strip-prefix branch October 18, 2024 09:44
@fmeum
Copy link
Collaborator

fmeum commented Oct 18, 2024

@bazel-io fork 8.0.0

bazel-io pushed a commit to bazel-io/bazel that referenced this pull request Oct 18, 2024
Fixes bazelbuild#16496

Closes bazelbuild#24019.

RELNOTES: The stripPrefix parameter of repository_ctx.download_and_extract()
and repository_ctx.extract() has been renamed to strip_prefix; the deprecated
stripPrefix name remains usable for compatibility.
PiperOrigin-RevId: 687224164
Change-Id: Iffaba2e65c049a2ff8bb98d1fba52e0bba9e5a02
github-merge-queue bot pushed a commit that referenced this pull request Oct 18, 2024
Fixes #16496

Closes #24019.

RELNOTES: The stripPrefix parameter of
repository_ctx.download_and_extract()
and repository_ctx.extract() has been renamed to strip_prefix; the
deprecated
stripPrefix name remains usable for compatibility.
PiperOrigin-RevId: 687224164
Change-Id: Iffaba2e65c049a2ff8bb98d1fba52e0bba9e5a02

Commit
49d7bb6

Co-authored-by: Alexandre Rostovtsev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent naming convention in rctx.download_and_extract for stripPrefix
3 participants