Merge pull request #107587 from Ivorforce/static-assert-includes

Add `STATIC_ASSERT_INCOMPLETE_TYPE` to enforce include minimality.
This commit is contained in:
Thaddeus Crews 2025-10-01 17:54:08 -05:00
commit 25de1a353a
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
4 changed files with 26 additions and 0 deletions

View file

@ -634,6 +634,7 @@ if env["strict_checks"]:
# Run SCU file generation script if in a SCU build. # Run SCU file generation script if in a SCU build.
if env["scu_build"]: if env["scu_build"]:
env.Append(CPPDEFINES=["SCU_BUILD_ENABLED"])
max_includes_per_scu = 8 max_includes_per_scu = 8
if env.dev_build: if env.dev_build:
max_includes_per_scu = 1024 max_includes_per_scu = 1024

View file

@ -30,6 +30,8 @@
#include "ustring.h" #include "ustring.h"
STATIC_ASSERT_INCOMPLETE_TYPE(class, Dictionary);
#include "core/crypto/crypto_core.h" #include "core/crypto/crypto_core.h"
#include "core/math/color.h" #include "core/math/color.h"
#include "core/math/math_funcs.h" #include "core/math/math_funcs.h"

View file

@ -439,3 +439,23 @@ inline constexpr bool is_zero_constructible_v = is_zero_constructible<T>::value;
#define GODOT_MSVC_WARNING_POP #define GODOT_MSVC_WARNING_POP
#define GODOT_MSVC_WARNING_PUSH_AND_IGNORE(m_warning) #define GODOT_MSVC_WARNING_PUSH_AND_IGNORE(m_warning)
#endif #endif
template <typename T, typename = void>
struct is_fully_defined : std::false_type {};
template <typename T>
struct is_fully_defined<T, std::void_t<decltype(sizeof(T))>> : std::true_type {};
template <typename T>
constexpr bool is_fully_defined_v = is_fully_defined<T>::value;
#ifndef SCU_BUILD_ENABLED
/// Enforces the requirement that a class is not fully defined.
/// This can be used to reduce include coupling and keep compile times low.
/// The check must be made at the top of the corresponding .cpp file of a header.
#define STATIC_ASSERT_INCOMPLETE_TYPE(m_keyword, m_type) \
m_keyword m_type; \
static_assert(!is_fully_defined_v<m_type>, #m_type " was unexpectedly fully defined. Please check the include hierarchy of '" __FILE__ "' and remove includes that resolve the " #m_keyword ".");
#else
#define STATIC_ASSERT_INCOMPLETE_TYPE(m_keyword, m_type)
#endif

View file

@ -30,6 +30,9 @@
#include "array.h" #include "array.h"
STATIC_ASSERT_INCOMPLETE_TYPE(class, Dictionary);
STATIC_ASSERT_INCOMPLETE_TYPE(class, String);
#include "container_type_validate.h" #include "container_type_validate.h"
#include "core/math/math_funcs.h" #include "core/math/math_funcs.h"
#include "core/object/script_language.h" #include "core/object/script_language.h"