-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Create a frozen dictionary type. #22166
base: master
Are you sure you want to change the base?
Conversation
This type is hashable, and thus can be used in a depset.
Note: I haven't added any test cases yet, both because I first want approval that it's the right thing to do before going to the effort of making test cases, and because I don't know where the right place is to put my test cases. |
For your use case, can you instead use struct? child = FooInfo(
something = struct(foo = "bar"),
children = depset([])
)
... |
Struct does indeed work for this specific use case. However:
|
Interesting point. Then I guess the design dimensions here are:
|
I'm a little confused by your use of the word
I think
I certainly wouldn't be opposed to a language spec change. I filed bazelbuild/starlark#272 a while back.
I'd personally be a fan of deeply frozen (moving the checkHashable check to the constructor), I just thought that might be contentious.
I don't think so. The only difference here is that we add a new builtin method, and that shouldn't be incompatible with anything. If I write
I'd personally go with no. I think that for the most part, a user doesn't really need to distinguish between a
I originally added a field to the regular |
Yes, typo, sorry! I was considering this feature in the context of a native set type which users have also been asking for for a while, and whether we'd need a frozenset in addition to a mutable set - and mistyped. |
Hey @matts1, do you care to explain more what you're doing, to avoid AB problem? I've seen tree-like structures in the rules before and they were often an anti-pattern. That's because the targets already form a dag and often it's possible to use that without copying that structure in the providers. Once you copy the structure into providers, it's really painful to process since Starlark doesn't have recursion and it's hard to visit them. aspects can for example do much better job visiting dags. But there are some cases that are not well covered and complex providers seem necessary atm. |
I ran into this problem for rules_directory while trying to generate a tree for a directory within a single rule. I had discussions in the starlark team chat last week. The tldr is that it seemed like this isn't especially high priority, and there would be better ways to do it (by resolving the todo to use checkhashable instead of isimmutable and fixing an existing bug with cyclic hashing crashing bazel) |
This type is hashable, and thus can be used in a depset.
I'm trying to solve the following use case, which is very common when creating tree-like structures.