Skip to content

ci: enforce standard-library includes with misc-include-cleaner - #1078

Open
manuzhang wants to merge 1 commit into
apache:mainfrom
manuzhang:ci/include-cleaner
Open

manuzhang wants to merge 1 commit into
apache:mainfrom
manuzhang:ci/include-cleaner

Conversation

@manuzhang

Copy link
Copy Markdown
Member

What

Re-enables clang-tidy's misc-include-cleaner, scoped to standard-library headers only.

Why

#820 enabled the check unscoped and #708 removed it five days later because it demanded a direct include for every project symbol (iceberg::Result, iceberg::Status, ...) that an already-included project header provides, which blocked CI with long include lists. Since then nothing checks includes, and review of #1066 found regressions of this shape: history_table.cc drops <vector> but still uses std::vector, and the new metadata_scan.cc uses std::vector, std::shared_ptr, std::unique_ptr, std::string and std::make_unique without <vector>, <memory> or <string>. Both compile only because metadata_scan.h happens to include those headers.

How

misc-include-cleaner.IgnoreHeaders lists iceberg/.* and every third-party header family, so the only diagnostics left are:

  • a std:: symbol (or int64_t, size_t, ...) used without a direct include of its standard header
  • a standard header that is included but not used

With cpp-linter already running clang-tidy 22 on changed lines, this needs no new workflow or tooling.

Measured on main

Running the scoped check over every library and test source with the same clang-tidy version CI uses (22.1.8):

Category Warnings Files
std symbol used without its header 2271 303
std header included but unused 29 19
project / third-party header (ignored by this config) 2622 –

Unscoped, the check would emit all 4922; scoped, the project-header half disappears entirely.

The pre-existing standard-library gaps are not fixed here. Because cpp-linter runs with --lines-changed-only=true, they only surface on lines a PR touches, so the codebase converges incrementally and this PR stays a config-only change. A one-shot cleanup with clang-tidy --fix is possible as a follow-up if preferred.

Verified against #1066

Running the new config on that branch reports the missing <vector> in history_table.cc and the five missing standard headers in metadata_scan.cc, and nothing else in those files. One caveat: the std::vector use in history_table.cc is on a line #1066 did not change, so CI's changed-lines mode would report only the metadata_scan.cc findings. Catching include removals whose use sites are untouched would require whole-file linting of changed files, which is a separate decision.

🤖 Generated with Claude Code

Re-enable clang-tidy's misc-include-cleaner, scoped to standard-library
headers only. Project headers under iceberg/ and all third-party headers
are listed in IgnoreHeaders, so the check no longer demands a direct
include for every symbol an already-included project header provides,
which is the noise that led to its removal in apache#708.

What remains is the class of regression seen in apache#1066: a source file
drops <vector> or <memory> while still using std::vector or
std::unique_ptr, and compiles only because a project header happens to
pull the standard header in transitively.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 1, 2026 15:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The .clang-tidy exclusions omit zlib and platform headers, allowing non-standard headers to trigger diagnostics despite the intended standard-library-only scope.

1 open issue
What changed in this PR

Re-enables misc-include-cleaner in the existing clang-tidy setup, aiming to enforce standard-library include hygiene incrementally without restoring project-header noise.

Changes:

  • Enables missing- and unused-include diagnostics.
  • Adds exclusions for Iceberg and third-party headers while leaving the changed-lines-only CI workflow unchanged.
File Description
.clang-tidy Enables include checking and configures header exclusions intended to limit diagnostics to standard-library headers.

Review effort: Balanced

Comment thread .clang-tidy
# not demand a direct include for every symbol that an already-included
# project header provides (the noise that led to its removal in #708).
- key: misc-include-cleaner.IgnoreHeaders
value: 'iceberg/.*;arrow/.*;avro/.*;aws/.*;benchmark/.*;cpr/.*;curl/.*;gmock/.*;gtest/.*;nanoarrow/.*;nlohmann/.*;openssl/.*;parquet/.*;roaring/.*;spdlog/.*;sqlpp23/.*;thrift/.*;libpq-fe\.h;mysql\.h;sqlite3\.h;utf8proc\.h;zlib\.h'

This branch has not been deployed

No deployments
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