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

Convert values to Starlark values when concating string_list_dict type #23424

Conversation

lior10r
Copy link
Contributor

@lior10r lior10r commented Aug 26, 2024

Convert values to Starlark values when concating string_list_dict type.

This is because Dict checks that all the values put in it are Starlark valid values. But string_list_dict value is of type List, when Java's List isn't a Starlark value.

Fixes #23065

My first PR to bazel 🤩 Would love you to review the PR.
Checked that the test didn't pass before the change and did after it.

@github-actions github-actions bot added the awaiting-review PR is awaiting review from an assigned reviewer label Aug 26, 2024
@iancha1992 iancha1992 added team-Configurability platforms, toolchains, cquery, select(), config transitions team-Starlark-Interpreter Issues involving the Starlark interpreter used by Bazel labels Aug 26, 2024
@fmeum fmeum requested a review from tetromino August 28, 2024 10:26
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.

Thank you for your contribution! I had reviewed #15075 two years ago - and had failed to notice the problem.

My main concern with the cast() call is that (1) it introduces a completely unnecessary temporary Dict object per each concatenated map, and (2) the semantics of Type.concat - as far as I can tell - don't require the returned value to be a subclass of StarlarkValue (compare Type.ListType.concat, which returns an ImmutableList, not a StarlarkList).

So instead, can we use a plain ordinary ImmutableMap.Builder?

      ImmutableMap.Builder<KeyT, ValueT> builder = ImmutableMap.builder();
      for (Map<KeyT, ValueT> map : iterable) {
        builder.putAll(map);
      }
      return builder.buildKeepingLast();

@tetromino tetromino added awaiting-user-response Awaiting a response from the author and removed team-Configurability platforms, toolchains, cquery, select(), config transitions awaiting-review PR is awaiting review from an assigned reviewer labels Aug 28, 2024
@lior10r lior10r force-pushed the fix-bazel-crash-select-string-list-dict branch from 0720678 to 9be44a8 Compare August 30, 2024 15:55
@lior10r
Copy link
Contributor Author

lior10r commented Aug 30, 2024

Thanks for the review, this is really the better solution for the problem.
I thought maybe adding another test that recreates the scenario that I posted on the issue. What do you think about it? if yes, where should I add it to?

@tetromino
Copy link
Contributor

Thanks for the review, this is really the better solution for the problem. I thought maybe adding another test that recreates the scenario that I posted on the issue. What do you think about it? if yes, where should I add it to?

@lior10r - that's an excellent idea. I would suggest adding such a test as a new method to src/test/java/com/google/devtools/build/lib/analysis/ConfigurableAttributesTest.java

Dict type.

This is because Dict checks that all the values put in it are Starlark
valid values. But string_list_dict value is of type List<String>, when
Java's List isn't a Starlark value.

Also added some tests.

Fixes bazelbuild#23065
@lior10r lior10r force-pushed the fix-bazel-crash-select-string-list-dict branch from 9be44a8 to dfcf5a0 Compare September 8, 2024 11:35
@lior10r lior10r requested a review from a team as a code owner September 8, 2024 11:35
@lior10r lior10r requested review from aranguyen and removed request for a team September 8, 2024 11:35
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.

Thanks for the test, looks good! I apologize for missing notification about the last commit.

@tetromino tetromino added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-user-response Awaiting a response from the author labels Sep 10, 2024
@tetromino
Copy link
Contributor

@bazel-io fork 7.4.0

@github-actions github-actions bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Sep 11, 2024
bazel-io pushed a commit to bazel-io/bazel that referenced this pull request Sep 11, 2024
Convert values to Starlark values when concating string_list_dict type.

This is because Dict checks that all the values put in it are Starlark valid values. But string_list_dict value is of type List<String>, when Java's List isn't a Starlark value.

Fixes bazelbuild#23065

My first PR to bazel 🤩 Would love you to review the PR.
 Checked that the test didn't pass before the change and did after it.

Closes bazelbuild#23424.

PiperOrigin-RevId: 673463108
Change-Id: Ib2cdce7d94243f4e3bda23203a196fee4e766189
github-merge-queue bot pushed a commit that referenced this pull request Sep 11, 2024
…dict type (#23603)

Convert values to Starlark values when concating string_list_dict type.

This is because Dict checks that all the values put in it are Starlark
valid values. But string_list_dict value is of type List<String>, when
Java's List isn't a Starlark value.

Fixes #23065

My first PR to bazel 🤩 Would love you to review the PR.
 Checked that the test didn't pass before the change and did after it.

Closes #23424.

PiperOrigin-RevId: 673463108
Change-Id: Ib2cdce7d94243f4e3bda23203a196fee4e766189

Commit
f1f8d58

---------

Co-authored-by: Lior Gorelik <[email protected]>
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-Starlark-Interpreter Issues involving the Starlark interpreter used by Bazel
Projects
None yet
3 participants