From 730db0f903f4460c72e9e9e32dd847d13e82366f Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Tue, 14 Jul 2026 17:59:03 -0700 Subject: [PATCH] Reduce Clang header exposure in lower library (#7511) Remove clang/CodeGen/ModuleBuilder.h from toolchain/lower/file_context.h to reduce transitive dependencies. Forward declare clang::CodeGenerator and clang::FunctionDecl instead. Add an explicit include of ModuleBuilder.h to context.cpp where the complete types are required. Assisted-by: Antigravity with Gemini --- toolchain/lower/context.cpp | 1 + toolchain/lower/context.h | 4 ++++ toolchain/lower/file_context.h | 7 +++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/toolchain/lower/context.cpp b/toolchain/lower/context.cpp index 4b01daa48251..db8b4a165f2d 100644 --- a/toolchain/lower/context.cpp +++ b/toolchain/lower/context.cpp @@ -5,6 +5,7 @@ #include "toolchain/lower/context.h" #include "clang/Basic/SourceManager.h" +#include "clang/CodeGen/ModuleBuilder.h" #include "common/check.h" #include "common/growing_range.h" #include "common/raw_string_ostream.h" diff --git a/toolchain/lower/context.h b/toolchain/lower/context.h index 74819ed6f8f5..6a61f04ac2b1 100644 --- a/toolchain/lower/context.h +++ b/toolchain/lower/context.h @@ -20,6 +20,10 @@ #include "toolchain/sem_ir/ids.h" #include "toolchain/sem_ir/inst_namer.h" +namespace clang { +class CodeGenerator; +} + namespace Carbon::Lower { class FileContext; diff --git a/toolchain/lower/file_context.h b/toolchain/lower/file_context.h index e634901100fe..b135a2f517ff 100644 --- a/toolchain/lower/file_context.h +++ b/toolchain/lower/file_context.h @@ -5,8 +5,6 @@ #ifndef CARBON_TOOLCHAIN_LOWER_FILE_CONTEXT_H_ #define CARBON_TOOLCHAIN_LOWER_FILE_CONTEXT_H_ -#include "clang/CodeGen/ModuleBuilder.h" -#include "clang/Lex/PreprocessorOptions.h" #include "toolchain/lower/context.h" #include "toolchain/lower/specific_coalescer.h" #include "toolchain/lower/type.h" @@ -15,6 +13,11 @@ #include "toolchain/sem_ir/ids.h" #include "toolchain/sem_ir/inst_namer.h" +namespace clang { +class CodeGenerator; +class FunctionDecl; +} // namespace clang + namespace Carbon::Lower { // Information about how a given function declaration is lowered.