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

Reject hashing of frozen mutable types #8980

Closed
wants to merge 1 commit into from

Conversation

Quarz0
Copy link
Contributor

@Quarz0 Quarz0 commented Jul 25, 2019

Related: #7800

When this flag is enabled, freezing a mutable object will no longer make
it hashable.

RELNOTES: Flag `--incompatible_disallow_hashing_frozen_mutables` is
added. See bazelbuild#7800
@@ -355,7 +355,7 @@ public void unsafeShallowFreeze() {
*/
public void put(K key, V value, Location loc, Mutability mutability) throws EvalException {
checkMutable(loc, mutability);
EvalUtils.checkValidDictKey(key);
EvalUtils.checkValidDictKey(key, null);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that this function (put) is only used here: https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/analysis/skylark/FunctionTransitionUtil.java#L178
However, I couldn't find a way to get environment here and passing null will just assume the flag is false.

@Quarz0
Copy link
Contributor Author

Quarz0 commented Jul 25, 2019

I also tried to reject frozen types in SkylarkNestedSet by replacing isImmutable by isHashable here: https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/syntax/SkylarkNestedSet.java#L236

But also due to the incompatible flag I couldn't find a way to pass the environment.

@aiuto aiuto removed their request for review July 25, 2019 13:34
@laurentlb laurentlb removed the request for review from dslomov July 25, 2019 14:06
@laurentlb
Copy link
Contributor

@brandjon, I think you were familiar with this area (hashability). Do you want to take a look at the change?

@jin jin added the team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. label Jul 25, 2019
Copy link
Contributor

@laurentlb laurentlb left a comment

Choose a reason for hiding this comment

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

lgtm


reporter.removeHandler(failFastHandler);
getConfiguredTarget("//test:r");
assertContainsEvent("unhashable type: 'tuple'");
Copy link
Member

Choose a reason for hiding this comment

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

This error message is a bit confusing, implying that tuples are never hashable. Would it be feasible to change it to mention the actual unhashable type within this PR? The similar error in Python is "unhashable type: 'dict'".

Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to submit this PR first (and hopefully be included in Bazel 0.29) and iterate later.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is really the object that is unhashable rather than the type, how about changing the message to
"unhashable object of type: dict"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

btw the same happens, regardless of this PR, if you try something like {([],): None} you will also get the same error unhashable type: 'tuple'.
I could still fix it in this PR by modifying the SkylarkValue interface to get the mutable/hashable object type within an immutable structure (like tuple), but I'm not sure if that's the best way to do so.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like @aiuto's suggestion.

* Flag: `--incompatible_disallow_hashing_frozen_mutables`
* Default: `false`
* Tracking issue: [#7800](https://github.com/bazelbuild/bazel/issues/7800)

Copy link
Contributor

Choose a reason for hiding this comment

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

fyi, I'm removing this page. Instead we just use GitHub issues to track the changes.

@bazel-io bazel-io closed this in 06c420d Aug 1, 2019
brandjon pushed a commit that referenced this pull request Aug 1, 2019
Related: #7800

Closes #8980.

PiperOrigin-RevId: 261150154
@philwo philwo added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Jun 15, 2020
@philwo philwo removed the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants