Skip to content

tree: remove includes that nothing in the file uses - #4438

Merged
BsAtHome merged 1 commit into
LinuxCNC:masterfrom
grandixximo:unused-includes
Aug 22, 2026
Merged

tree: remove includes that nothing in the file uses#4438
BsAtHome merged 1 commit into
LinuxCNC:masterfrom
grandixximo:unused-includes

Conversation

@grandixximo

@grandixximo grandixximo commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

104 #include lines across 82 files, of 30 distinct in-tree headers, that provide nothing the including file mentions. Removals only, no additions and no moves.

This is the sweep referred to in #4411, held back until #4425 landed.

How they were found. Take the names each in-tree header declares, macros, typedefs, tags, prototypes, extern variables and enum members, and check whether any of them appears in the file that includes it. That heuristic is going to be wrong somewhere, so nothing rests on it: 209 candidates came out, all 209 were removed at once, the tree was built, and whatever failed had its include put back. What is here is what survived a build with all of them gone together, --with-realtime=uspace, no errors and no warnings.

That build does not cover everything. Five of the files are outside what a uspace configuration compiles, so those were read by hand instead, and two keep their include: rtai_ulapi.c needs rtapi_rtai_shm_wrap.h, which declares nothing itself and only wraps rtai_shm.h, and fifousr.c takes FIFO_KEY and FIFO_SIZE from an anonymous enum in its own common.h.

What it buys. Against current master, scripts/include-dep-report.py goes from 137 directory edges and 1287 cross-directory include sites to 131 and 1213.

The cycles do not move: still 3, covering 9 directories and 18 edges. I think that is the honest result and worth stating plainly. Dead includes inflate the picture, they are not what holds the knots together. The three remaining cycles are interface questions, not stray includes.

The ones that repeat are rtapi_math.h 21 times, rtapi_string.h 15, config.h 10, block.h 7, rtapi_slab.h and rtapi_mutex.h 6 each.

@BsAtHome

Copy link
Copy Markdown
Contributor

But there seems to be a misalignment now for RTAI, that needed a removed include.

104 #include lines across 82 files, of 30 distinct in-tree headers.  None of
them provides a name the including file mentions.

Found by taking the names each in-tree header declares, macros, typedefs,
tags, prototypes, extern variables and enum members, and checking whether any
of them appears in the file that includes it.  A heuristic that size is going
to be wrong somewhere, so nothing here rests on it: every candidate was then
put to the compiler.  209 came out of the heuristic, all 209 were removed at
once and the tree built, the files that failed had their includes put back,
and this is what survived a build with all of them gone together.  Configured
--with-realtime=uspace, no errors and no warnings.

That build does not cover everything.  Five of the files are outside what a
uspace configuration compiles, so they were read by hand instead, and two of
them kept their include: rtai_ulapi.c needs rtapi_rtai_shm_wrap.h, which
declares nothing itself and only wraps rtai_shm.h, and fifousr.c takes
FIFO_KEY and FIFO_SIZE from an anonymous enum in its own common.h.

The ones that repeat are rtapi_math.h 21 times, rtapi_string.h 15, config.h
10, block.h 7, rtapi_slab.h and rtapi_mutex.h 6 each.

An include costs nothing to leave in place, which is why these accumulated,
but it is not free to a reader or to a dependency graph: each one asserts a
relationship between two directories that turns out not to exist.
@grandixximo

Copy link
Copy Markdown
Contributor Author

rip-rtai caught two, and it caught them because my check could not: the compiler pass ran --with-realtime=uspace, so the five files that configuration does not build were never tested. Two of them needed their include, both for a reason a name scan cannot see, a header that declares nothing itself and an anonymous enum.

Restored, the other three read by hand. 104 removals across 82 files now, directory edges unchanged at 131.

@BsAtHome
BsAtHome merged commit ce5c689 into LinuxCNC:master Aug 22, 2026
17 checks passed
@grandixximo
grandixximo deleted the unused-includes branch August 22, 2026 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants