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
Implement typed dictionaries #78656
base: master
Are you sure you want to change the base?
Implement typed dictionaries #78656
Conversation
307a874
to
09af208
Compare
I would prefer:
Just |
09af208
to
847943a
Compare
@lufog Great point! I adjusted the code to handle exactly that, but it revealed some other pitfalls in the process (mainly the process of transfering container types from one DataType to another) so I'll have to iron that out before showing off a new version In the meantime I've added documentation descriptions & made it possible to use a constructor to make a typed dictionary in GDScript, much like typed arrays |
847943a
to
bf74f2e
Compare
8b50554
to
6c41e2e
Compare
GDScript tests implemented! They're largely lifted from the tests given to typed Arrays so more specialization will be required, but they're a solid starting point to see what's awry off the bat Namely, typed arrays seem to be instantiating with null keys & values, though they're recognized as typed. I'm not quite sure yet where the incorrect implementation is happening, but that's my current focus as it very well may be the linchpin of the editor errors |
6c41e2e
to
f3dd0cc
Compare
With typed arrays, we have the variance problem: var typed: Array[int] = [1, 2, 3, 4]
var as_untyped: Array = typed
as_untyped[0] = "string" # silently fails at runtime I guess the same problem exists here, but for both keys and values? |
Yes, but it's still a hole in the type system. I understand the desire to pass typed arrays to APIs accepting untyped ones, and for reading, this is completely sound. The covariance violation occurs when writing to an My question is, is the same covariance conversion ("upcast") planned for dictionaries on each of the generic parameters? That is:
And if yes, are we fully aware of the pitfalls? |
However, this is not directly related to the PR. PRs of this kind tend to garner large numbers of comments that are difficult to navigate. If you'd like to discuss this, I suggest the |
Thanks! My point was not to discuss typed arrays, but the covariance problem regarding dictionaries, and what conversions we allow (see above). As such it's quite on-topic I believe. |
f3dd0cc
to
fad2a93
Compare
The holes in the type system certainly have been a bit of a headache to navigate, but attempting to overhaul that system as a whole is probably a bit beyond this PR (at least as I initially envisioned it). This is more about setting up the system that currently exists to dictionaries, warts and all. If the current implementation were to somehow inhibit the ability to implement typed dictionaries in the first place, then changes to the system would make sense On that note, I've figured out why variants were appearing as null & not changing when swapping types, so both those fixes are in place. As it stands, the two biggest remaining issues are:
|
39e959b
to
56daf46
Compare
c398aff
to
38c8e89
Compare
Would it be in the scope (or goal) of this PR to add type information to existing dictionaries? Such as
I would imagine this would have some overlap with #76843 if such is the case. As those properties aren't even guaranteed. |
It would break compatibility to do so imo so not guaranteed |
It wouldn't be in scope for this PR, but it can be discussed as a follow-up to it. |
38c8e89
to
809a3ed
Compare
For Dictionaries with a precise type schema, but with multiple different types, a struct would likely make more sense. godotengine/godot-proposals#7903 |
9c815ef
to
ce8f386
Compare
f2a4f52
to
c2b6af7
Compare
Looks like the C# editor is failing to build? |
c2b6af7
to
f36145c
Compare
Looks like all tests are passing... Can someone review this ASAP? It'd be awesome to have in 4.3, afaik feature freeze hasn't hit yet |
There are still open variance problems with I'm not sure if it's wise to rush an implementation as long as we don't have a proper strategy for this (unless people agree that this is not an issue worth addressing). |
I'd say "not worth addressing". I'm biased, though: I'm positive I'm not going to have trouble with it, and I desperately want to be able to tell the inspector what kind of object I want to put into my dictionaries. (The proposal this PR is addressing is one of several prospective language upgrades I've been watching with great interest because they eliminate a lot of unnecessary busywork and complexity from my work on Fleet Ops and should allow me to continue development.) |
I agree with @DaloLorn . This feels like the kind of thing that's just... part of how the language works, and if/when it does get addressed, it'd make more sense to do at the same time as Arrays. There are exponentially more problems solved short-term and long-term than if we wait for every possible issue to be resolved. The covariance thing feels really nitpicky, and not like the kind of think 90% of users will worry about. IMO it should be pushed as it is, Covariance is its own issue that needs to be resolved in its own discussion. This is just about getting statically typed dictionaries to finally be in the engine |
b12d8f2
to
ead5931
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only checked the part that I know best (ie EditorPropertyDictionary
)
29aa374
to
c33d20c
Compare
This comment was marked as outdated.
This comment was marked as outdated.
c33d20c
to
441815b
Compare
441815b
to
5327805
Compare
This aims to add the ability to bind typed dictionaries to script & GDScript. The implementation takes heavy inspiration from the existing typed array format.
The primary difference is the ability to specify type for just a key, leaving the value as typeless much like current dictionaries.Both key and value need their types specified for typed dictionaries, withVariant
allowing for a typeless equivalent.Syntax
Editor
Issues
All core issues are resolved!
There are a fair number of areas that still require fixes, in addition to whatever lingering bugs/errors there are. In particular:Variant
text appears as white instead of green in GDSCript if used as the value:[] operator
); it throws an error if attempting to do so in runtime & does recognize invalid keys when creating a dictionary initiallycontainer_element_type
being a list now instead of a single item. (This is inexperience with the engine on my end, dunno if it needs something special to memdelete array entries)Closes godotengine/godot-proposals#56