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

Core: Migrate typed container logic #96741

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Repiteo
Copy link
Contributor

@Repiteo Repiteo commented Sep 9, 2024

This PR aims to significantly streamline the use of typed arrays/dictionaries across the repo by making their include chains much more reasonable. Instead of requiring dedicated files, they're instead declared right in the base files for each respective container. The templated logic is handled in variant.h, similar to how it's already handling array iterator functions. Because everything is now consolidated into a single location, this entirely removes the need to forward-declare the structs in various classes or require including the typed header with extra baggage; within reason, anything can just use typed containers right away.

As part of the transition, this PR also integrates the ideas originally conceived in #88567: consolidating the typed container templates to a single instance. This was done with constexpr to allow for conditional checks right in the templates themselves, but the biggest improvement since then was to handle this logic in variant.h rather than type_info.h. While I still fully believe that a refactor of type_info.h is an inevitability in the near-ish future, that's not required for this scenario that only concerns itself with mapping types to Variant::Type.

The main other thing this PR does is explicitly disallow TypedArray<Variant> and TypedDictionary<Variant, Variant> by declaring them as undefined behavior. This won't likely be something that we stick with long-term, but for now their specifics simply haven't been discussed and, unlike GDScript, they would behave differently than the base containers. Whether this will have an actual impact is anyone's guess, but this was already adding static conditional logic to a system that was fundamentally incompatible with it previously, so no harm done.

@Repiteo Repiteo force-pushed the core/typed-container-migration branch from 2ddb82f to ab869ab Compare September 10, 2024 15:08
@Repiteo
Copy link
Contributor Author

Repiteo commented Sep 10, 2024

Made another minor addition because I couldn't justify an entirely separate PR for it: ArrayPrivate/DictionaryPrivate are now nested within the base classes. This'll slightly cleanup the global namespace, while keeping the private containers functionally identical.

Copy link
Contributor

@RadiantUwU RadiantUwU 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 to me, makes typed collections be more directly used by Variant.

@@ -41,8 +41,7 @@
#include "core/variant/dictionary.h"
#include "core/variant/variant.h"

class ArrayPrivate {
public:
struct Array::ArrayPrivate {
Copy link
Contributor

Choose a reason for hiding this comment

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

OK, Private collection headers moved inside their collections.

@@ -199,4 +199,13 @@ class Array {
~Array();
};

template <typename T>
class TypedArray : public Array {
Copy link
Contributor

Choose a reason for hiding this comment

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

Typed collections have been moved inside their generic collection headers.

// This is for typed containers.

template <typename T>
struct PtrToArg<TypedArray<T>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Variants can now be casted directly to their internal typed collections.

@Repiteo Repiteo force-pushed the core/typed-container-migration branch 3 times, most recently from 3295642 to c63cf08 Compare September 15, 2024 15:13
@Repiteo Repiteo force-pushed the core/typed-container-migration branch from c63cf08 to 0ab9667 Compare October 9, 2024 14:40
@Repiteo Repiteo requested a review from a team as a code owner October 9, 2024 14:40
@Repiteo Repiteo removed the request for review from a team October 16, 2024 17:53
@Repiteo Repiteo force-pushed the core/typed-container-migration branch from 0ab9667 to 0add01b Compare October 16, 2024 17:56
@Repiteo Repiteo requested review from a team as code owners October 16, 2024 17:56
@Repiteo Repiteo removed request for a team October 23, 2024 15:10
• Dedicated typed container files entirely removed
• Typed container classes now defined in their base headers; methods declared in `variant.h`
• Consolidate to a single template for both typed containers, thanks to `constexpr`
• Nest private containers in their base classes
@Repiteo Repiteo force-pushed the core/typed-container-migration branch from 0add01b to 0bbc059 Compare November 26, 2024 03:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants