Skip to content

[build] Add misc-include-cleaner clang-tidy check for headers - #7054

Open
fhanau wants to merge 1 commit into
mainfrom
felix/080726-include-enforcement
Open

[build] Add misc-include-cleaner clang-tidy check for headers#7054
fhanau wants to merge 1 commit into
mainfrom
felix/080726-include-enforcement

Conversation

@fhanau

@fhanau fhanau commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Reduces transitive include bloat by enforcing that no unused headers are being added.

This only covers header files for now and does not include KJ includes, otherwise the PR would need to be much larger and people would get linter errors more frequently.

Deployment plan: This will require some downstream changes to land, a PR for that will follow soon. I plan to only enable this check for workerd for now and see how things go with that, if people find that it is too much of an annoyance to sometimes be told that they have superfluous headers we can disable it again. But I hope that the check makes sense to developers for the most part and that we can benefit from having includes that make sense and slightly faster compile times (fewer includes means less time spent parsing headers).
If feedback is mostly positive a couple weeks in, we may want to extend this to the downstream repo and to capnproto.

@ask-bonk

ask-bonk Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Model not found: cloudflare-ai-gateway/anthropic/claude-opus-4-6. Did you mean: anthropic/claude-opus-4.5, anthropic/claude-opus-4.6, anthropic/claude-opus-4.7?

github run

@ask-bonk

ask-bonk Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

@fhanau Bonk workflow failed. Check the logs for details.

View workflow run · To retry, trigger Bonk again.

@github-actions

github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown

The generated output of @cloudflare/workers-types matches the snapshot in types/generated-snapshot 🎉

@fhanau
fhanau force-pushed the felix/080726-include-enforcement branch 2 times, most recently from 0eee215 to c7079e5 Compare August 18, 2026 23:25
Reduces transitive include bloat by enforcing that no unused headers are being
added.
@fhanau
fhanau force-pushed the felix/080726-include-enforcement branch from c7079e5 to 1667a06 Compare August 19, 2026 00:05
],
}

HEADER_ONLY_CHECKS = [

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note to self: Improve documentation of HEADER_ONLY_CHECKS before landing this


JsDate::operator kj::Date() const {
return kj::UNIX_EPOCH + (int64_t(inner->ValueOf()) * kj::MILLISECONDS);
return kj::UNIX_EPOCH + (static_cast<int64_t>(inner->ValueOf()) * kj::MILLISECONDS);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why am I fixing clang-tidy checks other than misc-include-cleaner in these files? Previously the jsg-core target was not being covered by clang-tidy as some of its headers can't compile on their own due to header interdependencies that I have not been able to resolve. But with the new no-clang-tidy-headers tag, we can apply clang-tidy to the source files only and get proper coverage for them.

@fhanau
fhanau marked this pull request as ready for review August 19, 2026 00:19
@fhanau
fhanau requested review from a team as code owners August 19, 2026 00:19
@fhanau
fhanau requested review from mikea and npaun August 19, 2026 00:19
@codspeed-hq

codspeed-hq Bot commented Aug 19, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 9.18%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 71 untouched benchmarks
⏩ 129 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
simpleStringBody[Response] 24.8 µs 22.7 µs +9.18%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing felix/080726-include-enforcement (1667a06) with main (84284d8)

Open in CodSpeed

Footnotes

  1. 129 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@npaun

npaun commented Aug 19, 2026

Copy link
Copy Markdown
Member

We're still disabling the check in a number of places. Do you plan to cut down on these in a later PR?

@fhanau

fhanau commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

We're still disabling the check in a number of places. Do you plan to cut down on these in a later PR?

I cleaned up all that I could without significant extra effort:

  • //src/rust/jsg has no-clang-tidy since it has C++ headers that fail to compile on their own due to missing headers for reasons I didn't fully understand (the way wd_rust_crate uses globs for headers is a mess I tried to clean up while working on this, but it also lead to unexpected compile errors). At this point, I'm content with at least not making the existing situation worse
  • //src/workerd/tests:bench-tools needs to have clang-tidy disabled since it pulls in headers from clang-19, which are incompatible with how clang-tidy-22 works (different LLVM versions aren't supposed to be mixed like that I guess). We can only fix this once we update the CI compiler version (might be a good idea anyway, but there's no rush so far). Unfortunately, this might get worse as we try to adopt clang-tidy-23 (which is incompatible with some clang 22 headers), we'll have to see.
  • no-clang-tidy-headers is used for JSG headers as explained in [build] Add misc-include-cleaner clang-tidy check for headers #7054 (comment)
  • This check only runs on headers and does not warn about superfluous includes of KJ headers for reasons I've covered in a comment (avoid needing to make humongous changes). I think this will give us much of the savings in terms of lower compile times while not causing lint checks to fail every time someone has kj/debug.h somewhere it's not needed.

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