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

Extract ScriptInstance into its own file to simplify includes #81388

Conversation

YuriSizov
Copy link
Contributor

Two issues

First of all, every time we want to use GDVIRTUAL* macros, we need to include two files: gdvirtual.gen.inc and script_language.h. The only reason for the second file, as far as I can see, is because macros need a definition for ScriptInstance. ScriptInstance is a plain C++ class, so not only is the extra inclusion annoying, it's also excessive.

Second, we can't use GDVIRTUAL* macros in Resource. I think this is because of the circular dependency between it and the contents of script_language.h, which in turn tries to include Resource. At least, that's the problem that is immediately obvious, but there might be some other limitations, since @reduz believed that Resources can't use GDVIRTUAL for some reason (see #67080).

Solution

So I tried to divorce ScriptInstance from the rest of script_language.h, to simplify the includes. I also added an include for this simple file directly into the gdvirtual.gen.inc generator. This allows to include only gdvirtual.gen.inc when we need the macros. Simpler!

The divorce didn't cause any obvious issues, a bit surprisingly, so I went ahead and removed excessive includes of script_language.h wherever possible. This, of course, had a cascading effect on the codebase, which is full of indirect dependencies. I fixed everything until it started to compile locally. I think the end result here is that compile times should improve, which is also nice. Faster!

I haven't tried if this actually unblocks #67080 or if there are further problems. I leave it as an exercise for my colleagues 🙃 Now, let's see if it compiles on CI!

This allows to include script_instance.h directly in the
generated gdvirtual.gen.inc, and remove excessive includes
from the codebase.

This should also allow Resource to use GDVIRTUAL macros,
which wasn't possible previously due to a circular dependency.
@YuriSizov YuriSizov force-pushed the core-gdvirtual-but-less-confused-about-itself branch from 74716db to d8ff69d Compare September 6, 2023 20:54
@YuriSizov YuriSizov requested a review from a team as a code owner September 6, 2023 20:54
@Mickeon
Copy link
Contributor

Mickeon commented Sep 6, 2023

I can confirm after testing that this PR does address the issue described.

Copy link
Member

@akien-mga akien-mga 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 sense to split the classes to separate files if it helps reduce circular dependencies.

@akien-mga akien-mga merged commit 7663c69 into godotengine:master Sep 7, 2023
@akien-mga
Copy link
Member

Thanks!

@YuriSizov YuriSizov deleted the core-gdvirtual-but-less-confused-about-itself branch September 8, 2023 10:00
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.

3 participants