Self-contained headers and no include cycles #4

Closed
UnflavoredMeson/Primal_Plus_Plus
opened 2026-11-24 20:15:48 +00:00 by UnflavoredMeson · 0 comments
Owner

Why

A header that compiles only after another one was included breaks as soon as include order changes, and cycles make the layers of S1 impossible to enforce. CommonHeaders.h expands to about 130,000 lines; headers that include what they use compile faster and say what they depend on.

Decided

  • Every header compiles alone; there are no include cycles.
  • CommonHeaders.h is an umbrella that only includes. The headers it includes (Id.h, Vector.h, FreeList.h, Math.h, ...) use CommonDefinitions.h and PrimitiveTypes.h and never include it back.
  • New headers, and headers a task touches, include what they use. .cpp files may keep the umbrella. No pass.
  • Checks: a CMake header_check target (one translation unit per header) and Tools/check_include_cycles.py.

Read first

  • Preferences, "Comments and headers" and "Containers and headers".
  • Engine/Common/CommonHeaders.h on master.

Steps

  • 1. Write the header_check target and run it. Note which headers fail and why.
  • 2. Split CommonDefinitions.h out of CommonHeaders.h and fix the failing headers.
  • 3. Write Tools/check_include_cycles.py and fix the cycles it finds.
  • 4. Add both checks to the script from S0-03.

Done when

  • cmake --build --preset linux-debug --target header_check passes.
  • check_include_cycles.py reports no cycles.

Claude can help with

  • Writing check_include_cycles.py from your description of what it should report.
  • Finding the include that each failing header is missing.

Learn

  • What "include what you use" costs and saves.
  • How a cycle between two headers shows up as a confusing "incomplete type" error.
## Why A header that compiles only after another one was included breaks as soon as include order changes, and cycles make the layers of S1 impossible to enforce. `CommonHeaders.h` expands to about 130,000 lines; headers that include what they use compile faster and say what they depend on. ## Decided - Every header compiles alone; there are no include cycles. - `CommonHeaders.h` is an umbrella that only includes. The headers it includes (`Id.h`, `Vector.h`, `FreeList.h`, `Math.h`, ...) use `CommonDefinitions.h` and `PrimitiveTypes.h` and never include it back. - New headers, and headers a task touches, include what they use. `.cpp` files may keep the umbrella. No pass. - Checks: a CMake `header_check` target (one translation unit per header) and `Tools/check_include_cycles.py`. ## Read first - [Preferences](https://forgejo.unflavoredmeson.com/UnflavoredMeson/Primal_Plus_Plus/wiki/Preferences), "Comments and headers" and "Containers and headers". - `Engine/Common/CommonHeaders.h` on `master`. ## Steps - [x] 1. Write the `header_check` target and run it. Note which headers fail and why. - [x] 2. Split `CommonDefinitions.h` out of `CommonHeaders.h` and fix the failing headers. - [x] 3. Write `Tools/check_include_cycles.py` and fix the cycles it finds. - [x] 4. Add both checks to the script from S0-03. ## Done when - [x] `cmake --build --preset linux-debug --target header_check` passes. - [x] `check_include_cycles.py` reports no cycles. ## Claude can help with - Writing `check_include_cycles.py` from your description of what it should report. - Finding the include that each failing header is missing. ## Learn - What "include what you use" costs and saves. - How a cycle between two headers shows up as a confusing "incomplete type" error.
Sign in to join this conversation.
No description provided.