X Tutup
Skip to content

Remove unnecessary cpp files after cleanup#108516

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
KoBeWi:file_graveyard
Nov 14, 2025
Merged

Remove unnecessary cpp files after cleanup#108516
Repiteo merged 1 commit intogodotengine:masterfrom
KoBeWi:file_graveyard

Conversation

@KoBeWi
Copy link
Member

@KoBeWi KoBeWi commented Jul 11, 2025

Inspired by #106293 and #108340

I noticed that some cpp files are effectively useless. Once you cleanup them (remove empty methods etc.), you end up with empty file. The aforementioned PRs had a few such cases.

I decided to go a step further and just delete all similar files. This PR removes cpp files that are either empty after "obvious" cleanup, or have very trivial code (1-2 one-liner methods, no additional dependencies, no special conditions etc.). Most of these files weren't changed in a long time, so it's unlikely the cpp file will become needed eventually. However I can trim this down to the most obvious cases.

@KoBeWi KoBeWi added this to the 4.x milestone Jul 11, 2025
@KoBeWi KoBeWi requested review from a team as code owners July 11, 2025 13:09
@AThousandShips
Copy link
Member

I think this is generally desirable but my concern is the impact of ease of contribution in general without these files, so I's say they server a sufficient purpose if they don't contribute significantly to slow down compilation etc.

For example if the headers are moved and there's an open PR adding something to this the rebase will be harder, if the file exists and is just moved then the change will be largely automatic in git assuming you haven't made too large a change

@vnen
Copy link
Member

vnen commented Jul 11, 2025

The register_types.cpp files are somewhat of a standard in modules. Not sure if they should be removed.

@KoBeWi
Copy link
Member Author

KoBeWi commented Jul 11, 2025

But the ones I wanted to remove here do absolutely nothing.
And I find it weird that they have to exist, even if they are completely empty. (I left copyright header and include, but they aren't aren't needed)

@AThousandShips
Copy link
Member

AThousandShips commented Jul 11, 2025

IMO, given that it's "just" 17 files out of thousands, I'd say it's not worth having a case-by-case basis for this, and we should just have the cpp files, at least for all bound classes, it's a drop in the ocean comparatively and I doubt it has any real effect on anything performance wise, but it makes some contribution less smooth

Also in some cases I'd say there's a benefit of having the static variables stored in cpp to avoid unnecessary mutation of the header

Also repeating with timothyqiu said in dev-chat:

A downside might be that some contributors will tend to add method definitions to the header because they think it's intended to be header-only.

@dagarsar
Copy link
Contributor

For example if the headers are moved and there's an open PR adding something to this the rebase will be harder, if the file exists and is just moved then the change will be largely automatic in git assuming you haven't made too large a change

I guess you can check if there are open PRs with PR's by file. Still doesn't solve the issue of future PRs needing these files though.

@timothyqiu
Copy link
Member

I initially thought that these cpp files only contained empty constructors and static member variable definitions. But it turns out that there are quite a few classes in this PR that have moved their method definitions to the header, thus eliminating the need for the cpp files.

I think we should discuss the circumstances under which it is permissible to define functions in header files separately.

@KoBeWi
Copy link
Member Author

KoBeWi commented Jul 11, 2025

Ok so here's a summary of the removed files, sorted from least to most arguable removal:

servers/rendering/rendering_method.cpp - Empty constructor and destructor.
core/templates/rid_owner.cpp - Single static variable definition.
servers/rendering/rendering_server_globals.cpp - Multiple static variable definitions.
modules/godot_physics_2d/godot_broad_phase_2d.cpp/3d.cpp - Single static variable definition and an empty constructor.
scene/3d/lightmap_probe.cpp - Single empty method.
modules/freetype/register_types.cpp and modules/msdfgen/register_types.cpp - 2 effectively empty methods.
core/templates/command_queue_mt.cpp - Empty destructor and a one-line constructor that initializes single variable.
servers/xr/xr_controller_tracker.cpp - Empty method and a one-line constructor that initializes single variable.
servers/rendering/dummy/storage/texture_storage.cpp - One static variable definition and 2 trivial one-liner methods.
platform/web/ip_web.cpp - 3 empty methods and 2 trivial one-liner methods.
platform/web/net_socket_web.cpp - 2 trivial one-liner methods.
core/math/static_raycaster.cpp - Single static variable definition and one relatively simple method.

By "trivial one-liners" I mean methods that only assign or return a member. Many setters/getters fall under this group; I once brought it up on chat. I don't plan to do a cleanup for this, but we could apply this style going forward (if it's generally agreed).

And yes, in this PR it's a bit forced for the sake of removing files, hence some of the changes are more arguable. Though IMO aside from the static_raycaster.cpp change (which I can revert), and the lightmap_probe.cpp which is being changed for the first time in 5 years, other changes are fine.

Also to give more context, here are some files that could be considered for removal, but I didn't touch them various reasons:
https://github.com/godotengine/godot/blob/master/core/io/net_socket.cpp - This is similar to static_raycaster case, except the method includes an error, making it more "complex".
https://github.com/godotengine/godot/blob/master/core/math/rect2i.cpp - Two very simple methods, but the file has additional includes.
https://github.com/godotengine/godot/blob/master/core/os/thread_safe.cpp - Contains a cpp-only variable.
https://github.com/godotengine/godot/blob/master/core/templates/a_hash_map.cpp - Has additional include.
https://github.com/godotengine/godot/blob/master/core/templates/interpolated_property.cpp - Example of multiple non-trivial one-liner methods.
https://github.com/godotengine/godot/blob/master/misc/dist/ios_xcode/godot_ios/dummy.cpp - I assume it exists for a reason (though looks like something that can be generated?).

@fire fire changed the title Remove unnecessary cpp files Remove unnecessary cpp files after cleanup Jul 11, 2025
@Repiteo
Copy link
Contributor

Repiteo commented Jul 14, 2025

The only hard-requirements for modules are register_types.h, SCsub, and config.py:

godot/methods.py

Lines 237 to 239 in d5cb0f9

`search_path` - a directory path containing modules. The path may point to
a single module, which may have other nested modules. A module must have
"register_types.h", "SCsub", "config.py" files created to be detected.

register_types.cpp being "required" was a consequence of the buildsystem assigning a library to a module unconditionally. By only doing this when build objects exist, header-only modules can indeed be a thing. This is implemented here:

@KoBeWi
Copy link
Member Author

KoBeWi commented Jul 14, 2025

And what about the Web fail? It looks like another case besides the modules.

@Repiteo
Copy link
Contributor

Repiteo commented Jul 14, 2025

And what about the Web fail? It looks like another case besides the modules.

Looks like web hardcodes the .cpp files it compiles instead of globbing; should be fixed by removing these two lines:

godot/platform/web/SCsub

Lines 30 to 31 in f845aee

"ip_web.cpp",
"net_socket_web.cpp",

@Repiteo
Copy link
Contributor

Repiteo commented Jul 15, 2025

Module fix merged; this should be good to go after a rebase!

@Repiteo Repiteo modified the milestones: 4.x, 4.6 Nov 14, 2025
@Repiteo Repiteo merged commit c6fe923 into godotengine:master Nov 14, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Nov 14, 2025

Thanks!

@KoBeWi KoBeWi deleted the file_graveyard branch November 14, 2025 21:49
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.

7 participants

X Tutup