X Tutup
Skip to content

Core: Fix missing includes in type_info.h#111561

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
StarryWorm:core/variant-includes-rework
Oct 14, 2025
Merged

Core: Fix missing includes in type_info.h#111561
Repiteo merged 1 commit intogodotengine:masterfrom
StarryWorm:core/variant-includes-rework

Conversation

@StarryWorm
Copy link
Contributor

@StarryWorm StarryWorm commented Oct 12, 2025

Added includes for variant.h and object.h to type_info.h.

These were missing but due to type_info.h always being included after class_db.h wherever it was included, the Variant and Object classes would be defined and would let it compile.
This made removing class_db.h in many places impossible as it would break type_info.h.

Old version of the PR Reworks the include chains in core/variant.

Changes:

  • Added includes for variant.h and object.h to type_info.h. These were missing but due to type_info.h always being included after class_db.h wherever it was included, the Variant and Object classes would be defined and would let it compile. This made removing class_db.h in many places impossible as it would break type_info.h
    • This will likely come at a performance cost, since the total # of includes by type_info.h goes from 4 to 70
    • See rocket chat discussion
  • Following up on that, class_db.h was removed from variant_construct.h, variant_destruct.h, variant_op.h, variant_setget.h, and dictionary.h.
    • This results in the core/variant being theoretically completely decoupled from class_db.h
  • Migrated some includes from *.h to *.cpp as they are only needed there in those cases.
  • variant_construct.h was very bloated in terms of includes, this has been fixed
  • Various removals and purely-transitive-to-direct replacements. Also added some explicit includes in some places which accessed it only transitively.

My machine is too slow and unpredictable to measure compile-time difference between this and master, so I can't provide those stats.

@StarryWorm StarryWorm requested a review from a team as a code owner October 12, 2025 18:00
@StarryWorm StarryWorm force-pushed the core/variant-includes-rework branch from 4a7dc56 to 0ef0ee2 Compare October 12, 2025 19:45
@StarryWorm
Copy link
Contributor Author

StarryWorm commented Oct 12, 2025

File include analysis:

  • dictionary.cpp 93 -> 93 (+0)
  • type_info.h 4 -> 70 (+66)
  • variant_call.cpp 94 -> 93 (-1)
  • variant_construct.cpp 94 -> 76 (-18)
  • variant_destruct.cpp 82 -> 72 (-10)
  • variant.cpp 106 -> 102 (-4)
  • variant_op.cpp 83 -> 75 (-8)
  • variant_parser.cpp 110 -> 110 (+0)
  • variant_setget.cpp 90 -> 90 (+0)
  • variant_utility.cpp 106 -> 97 (-9)
    Total: -50 (excluding type_info.h), +16 (including type_info.h)

class_db.h was included in all files excluding type_info.h.
It is no longer included in variant_construct.cpp, variant_destruct.cpp, variant_op.cpp (-3 includes).
Still remains in:

  • dictionary.cpp through container_type_validate.h ... through resource.h and refcounted.h
  • variant_call.cpp through marshalls.h ... through refcounted.h
  • variant_op.cpp through resource.h
  • variant_parser.cpp through resource.h and refcounted.h
  • variant_setget.cpp through resource.h and refcounted.h
  • variant_utility.cpp through resource.h and refcounted.h

@StarryWorm
Copy link
Contributor Author

StarryWorm commented Oct 12, 2025

#111567 is the first step towards finishing the delineation from class_db.h for the entirety of core/variant
#111573 is the second step

Looks like there will always be an issue with container_type_validate.h though, which also means dictionary.cpp

Copy link
Member

@Ivorforce Ivorforce left a comment

Choose a reason for hiding this comment

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

The type_info.h change makes sense to me, those includes missing is a compile problem waiting to happen.

Regarding the variant_ files, it seems that the headers are only included from the source files. So while it normally makes sense to remove includes from headers, in this case I don't think it will have an effect since the headers only affect the corresponding .cpp file.

So although we definitely want to address the class_db.h include problem somehow, I don't think these changes will bring us closer to this goal.

@StarryWorm
Copy link
Contributor Author

I agree that these changes will likely have minimal (if any) performance benefits. The justification of "delineating from class_db.h" may thus be considered misguided.
However, I would say these changes are still worth doing, since they clean up the headers for the variant_ files, which are currently bloated. They were bloated due to type_info.h not having its required include, but since that gets fixed by this PR, I would argue that bundling together the bloat removal is the correct thing to do.

Let me know if you would like me to split the PR into one that focuses solely on type_info.h and a second (if even) that focuses on the subsequential clean-up.

@Ivorforce
Copy link
Member

Ivorforce commented Oct 14, 2025

I agree that these changes will likely have minimal (if any) performance benefits. The justification of "delineating from class_db.h" may thus be considered misguided. However, I would say these changes are still worth doing, since they clean up the headers for the variant_ files, which are currently bloated. They were bloated due to type_info.h not having its required include, but since that gets fixed by this PR, I would argue that bundling together the bloat removal is the correct thing to do.

Let me know if you would like me to split the PR into one that focuses solely on type_info.h and a second (if even) that focuses on the subsequential clean-up.

I think we should merge the type_info.h changes, to avoid potential future build problems.
But the other changes to variant_ files are not as relevant. I agree the includes are a bit messy, but every change we make to the codebase has some risk to cause regressions (e.g. break builds for modules), so we should have a good reason to merge the change. Since the variant_ changes won't have an effect on build time, and won't bring us closer to isolating ClassDB, I don't think they qualify.

@StarryWorm StarryWorm force-pushed the core/variant-includes-rework branch from 0ef0ee2 to c17e765 Compare October 14, 2025 15:12
@StarryWorm StarryWorm changed the title Core: Rework includes in core/variant/ Core: Fix missing includes in type_info.h Oct 14, 2025
@StarryWorm StarryWorm requested a review from Ivorforce October 14, 2025 15:15
@StarryWorm
Copy link
Contributor Author

Changes to type_info.h have been isolated and are now the only thing included in the PR.
Updated PR title and description to reflect the change.

Copy link
Member

@Ivorforce Ivorforce left a comment

Choose a reason for hiding this comment

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

I've confirmed that both includes are required in the file, and that this fixes compilation of a .cpp file that only includes type_info.h.
Thanks for adjusting with the feedback!

PS. I still hope that in the future, we could have a CI check that catches this type of problem early.

@Ivorforce Ivorforce modified the milestones: 4.x, 4.6 Oct 14, 2025
@Ivorforce Ivorforce added bug and removed enhancement labels Oct 14, 2025
@StarryWorm
Copy link
Contributor Author

So do I... Hopefully the daily runner proposal gets approved and that gets included in there.
I might try and run a similar check as you proposed on my machine and start opening PRs for any issues that I find. I expect new files to not have this issue (maybe extremely rarely they might), so that work should be "enough" for now.

@Repiteo Repiteo merged commit a364d6a into godotengine:master Oct 14, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Oct 14, 2025

Thanks!

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.

4 participants

X Tutup