Remove Unused Includes#127295
Conversation
There was a problem hiding this comment.
Pull request overview
This PR primarily removes a large number of unused/redundant #include directives across CoreCLR, NativeAOT, tooling, and host components, likely aiming to reduce header coupling and improve build hygiene.
Changes:
- Removed unused or transitive
#includedirectives across many C/C++ translation units. - Simplified include sets in VM, JIT, MD, debug, and NativeAOT runtime sources.
- Updated a few tool/source files to use more specific headers (e.g.,
caparser.h).
Show a summary per file
| File | Description |
|---|---|
| src/native/corehost/hostmisc/longfile.windows.cpp | Remove unused include |
| src/coreclr/vm/virtualcallstub.cpp | Remove unused include |
| src/coreclr/vm/typehandle.cpp | Remove unused include (but see opt-restore comment) |
| src/coreclr/vm/tieredcompilation.cpp | Remove unused include |
| src/coreclr/vm/threadsuspend.cpp | Remove unused include |
| src/coreclr/vm/threads.cpp | Remove unused includes |
| src/coreclr/vm/stublink.cpp | Remove unused include |
| src/coreclr/vm/stubhelpers.cpp | Remove unused includes |
| src/coreclr/vm/stdinterfaces_wrapper.cpp | Remove unused include |
| src/coreclr/vm/stdinterfaces.cpp | Remove unused include |
| src/coreclr/vm/runtimehandles.cpp | Remove unused include (but see opt-restore comment) |
| src/coreclr/vm/readytoruninfo.cpp | Remove unused include |
| src/coreclr/vm/qcallentrypoints.cpp | Remove unused includes |
| src/coreclr/vm/prestub.cpp | Remove unused include |
| src/coreclr/vm/precode_portable.cpp | Remove unused include |
| src/coreclr/vm/pgo.cpp | Remove unused include |
| src/coreclr/vm/perfmap.cpp | Remove unused include |
| src/coreclr/vm/peassembly.cpp | Remove unused includes |
| src/coreclr/vm/onstackreplacement.cpp | Remove unused include |
| src/coreclr/vm/multicorejit.cpp | Remove unused include |
| src/coreclr/vm/methodtable.cpp | Remove unused include |
| src/coreclr/vm/method.cpp | Remove unused include |
| src/coreclr/vm/jitinterfacegen.cpp | Remove unused include |
| src/coreclr/vm/interoputil.cpp | Remove unused include |
| src/coreclr/vm/interoplibinterface_comwrappers.cpp | Remove unused includes |
| src/coreclr/vm/interopconverter.cpp | Remove unused include |
| src/coreclr/vm/gchelpers.cpp | Remove optimization pragma includes |
| src/coreclr/vm/finalizerthread.cpp | Remove unused include |
| src/coreclr/vm/fieldmarshaler.cpp | Remove unused include |
| src/coreclr/vm/exceptionhandling.cpp | Remove unused include |
| src/coreclr/vm/dllimport.cpp | Remove unused include |
| src/coreclr/vm/corelib.cpp | Remove unused includes |
| src/coreclr/vm/comutilnative.cpp | Remove unused includes (but see opt-restore comment) |
| src/coreclr/vm/commodule.cpp | Remove unused include |
| src/coreclr/vm/cominterfacemarshaler.cpp | Remove unused include |
| src/coreclr/vm/comcallablewrapper.cpp | Remove unused includes (but see opt-restore comment) |
| src/coreclr/vm/clsload.cpp | Remove unused include |
| src/coreclr/vm/classcompat.cpp | Remove unused includes |
| src/coreclr/vm/class.cpp | Remove unused include |
| src/coreclr/vm/ceeload.cpp | Remove unused include (but see opt-restore comment) |
| src/coreclr/vm/callcounting.cpp | Remove unused include |
| src/coreclr/vm/binder.cpp | Remove unused include |
| src/coreclr/vm/autotrace.cpp | Remove unused include |
| src/coreclr/vm/assembly.cpp | Remove unused includes (but see opt-restore comment) |
| src/coreclr/vm/appdomain.cpp | Remove unused includes |
| src/coreclr/vm/amd64/cgenamd64.cpp | Remove unused include |
| src/coreclr/utilcode/sstring.cpp | Remove unused include |
| src/coreclr/utilcode/rangelist.cpp | Remove unused include |
| src/coreclr/utilcode/log.cpp | Remove unused include |
| src/coreclr/utilcode/hostimpl.cpp | Remove unused include |
| src/coreclr/tools/superpmi/superpmi/streamingsuperpmi.cpp | Remove unused includes |
| src/coreclr/tools/superpmi/superpmi-shim-simple/superpmi-shim-simple.cpp | Remove unused include |
| src/coreclr/tools/superpmi/superpmi-shim-simple/jithost.cpp | Remove unused include |
| src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp | Remove unused includes |
| src/coreclr/tools/superpmi/superpmi-shim-counter/superpmi-shim-counter.cpp | Remove unused include |
| src/coreclr/tools/superpmi/superpmi-shim-counter/jithost.cpp | Remove unused include |
| src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp | Remove unused includes |
| src/coreclr/tools/superpmi/mcs/verbmerge.cpp | Remove unused include |
| src/coreclr/tools/superpmi/mcs/removedup.cpp | Remove unused include |
| src/coreclr/tools/superpmi/mcs/mcs.cpp | Remove unused include |
| src/coreclr/tools/metainfo/mdobj.cpp | Remove unused standard includes |
| src/coreclr/tools/metainfo/mdinfo.cpp | Replace CA helper include with caparser.h |
| src/coreclr/runtime/MiscNativeHelpers.cpp | Remove unused include |
| src/coreclr/nativeaot/Runtime/yieldprocessornormalized.cpp | Remove unused includes |
| src/coreclr/nativeaot/Runtime/windows/PalMinWin.cpp | Remove unused include |
| src/coreclr/nativeaot/Runtime/windows/PalCommon.cpp | Remove unused includes |
| src/coreclr/nativeaot/Runtime/threadstore.cpp | Remove unused includes |
| src/coreclr/nativeaot/Runtime/stressLog.cpp | Remove unused include |
| src/coreclr/nativeaot/Runtime/startup.cpp | Remove unused includes |
| src/coreclr/nativeaot/Runtime/rhassert.cpp | Remove unused include |
| src/coreclr/nativeaot/Runtime/portable.cpp | Remove unused includes |
| src/coreclr/nativeaot/Runtime/interoplibinterface_java.cpp | Remove unused include |
| src/coreclr/nativeaot/Runtime/eventtrace_gcheap.cpp | Remove unused includes |
| src/coreclr/nativeaot/Runtime/eventtrace.cpp | Remove unused includes |
| src/coreclr/nativeaot/Runtime/eventpipeinternal.cpp | Remove unused includes |
| src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp | Remove unused include |
| src/coreclr/nativeaot/Runtime/eventpipe/ds-rt-aot.cpp | Remove unused include |
| src/coreclr/nativeaot/Runtime/event.cpp | Remove unused includes |
| src/coreclr/nativeaot/Runtime/disabledruntimeeventinternal.cpp | Remove unused include |
| src/coreclr/nativeaot/Runtime/UniversalTransitionHelpers.cpp | Remove unused includes |
| src/coreclr/nativeaot/Runtime/TypeManager.cpp | Remove unused includes |
| src/coreclr/nativeaot/Runtime/ThunksMapping.cpp | Remove unused include |
| src/coreclr/nativeaot/Runtime/SyncClean.cpp | Remove unused includes |
| src/coreclr/nativeaot/Runtime/RuntimeInstance.cpp | Remove unused includes |
| src/coreclr/nativeaot/Runtime/RestrictedCallouts.cpp | Remove unused include |
| src/coreclr/nativeaot/Runtime/MiscHelpers.cpp | Remove unused includes |
| src/coreclr/nativeaot/Runtime/MathHelpers.cpp | Remove unused include |
| src/coreclr/nativeaot/Runtime/HandleTableHelpers.cpp | Remove unused include |
| src/coreclr/nativeaot/Runtime/GcStressControl.cpp | Remove unused includes |
| src/coreclr/nativeaot/Runtime/GCHelpers.cpp | Remove unused includes |
| src/coreclr/nativeaot/Runtime/FinalizerHelpers.cpp | Remove unused include |
| src/coreclr/nativeaot/Runtime/EHHelpers.cpp | Remove unused include |
| src/coreclr/nativeaot/Runtime/DebugHeader.cpp | Remove unused include |
| src/coreclr/nativeaot/Runtime/Crst.cpp | Remove unused include |
| src/coreclr/nativeaot/Runtime/AsmOffsetsVerify.cpp | Remove unused include |
| src/coreclr/nativeaot/Bootstrap/main.cpp | Remove unused include |
| src/coreclr/minipal/Windows/memory.cpp | Remove unused standard include |
| src/coreclr/md/runtime/mdinternaldisp.cpp | Remove unused include |
| src/coreclr/md/enc/stgtiggerstream.cpp | Remove unused include |
| src/coreclr/md/compiler/regmeta_vm.cpp | Remove unused include |
| src/coreclr/md/compiler/regmeta_import.cpp | Remove unused include |
| src/coreclr/md/compiler/regmeta_emit.cpp | Remove unused include |
| src/coreclr/md/compiler/regmeta_compilersupport.cpp | Remove unused includes |
| src/coreclr/md/compiler/regmeta.cpp | Remove unused include |
| src/coreclr/md/compiler/custattr_import.cpp | Remove unused includes |
| src/coreclr/jit/simdcodegenxarch.cpp | Remove unused include |
| src/coreclr/jit/promotiondecomposition.cpp | Remove unused include |
| src/coreclr/jit/promotion.cpp | Remove unused include |
| src/coreclr/jit/loopcloning.cpp | Remove unused include |
| src/coreclr/jit/importer.cpp | Remove unused include |
| src/coreclr/jit/ee_il_dll.cpp | Remove unused include |
| src/coreclr/jit/dllmain.cpp | Remove unused include |
| src/coreclr/jit/block.cpp | Remove unused include |
| src/coreclr/interop/interoplib.cpp | Remove unused include |
| src/coreclr/ildasm/windasm.cpp | Remove unused include |
| src/coreclr/ildasm/ildasmpch.cpp | Remove include (now empty TU) |
| src/coreclr/ildasm/dres.cpp | Remove unused include |
| src/coreclr/gcinfo/arraylist.cpp | Remove unused include |
| src/coreclr/gc/vxsort/do_vxsort_avx512.cpp | Remove redundant includes |
| src/coreclr/gc/vxsort/do_vxsort_avx2.cpp | Remove redundant includes |
| src/coreclr/dlls/mscorpe/ceefilegenwriter.cpp | Remove unused include |
| src/coreclr/dlls/mscoree/exports.cpp | Remove unused include |
| src/coreclr/debug/runtimeinfo/runtimeinfo.cpp | Remove unused include |
| src/coreclr/debug/ee/funceval.cpp | Remove unused include |
| src/coreclr/debug/ee/debuggermodule.cpp | Remove unused include |
| src/coreclr/debug/ee/dactable.cpp | Remove unused include |
| src/coreclr/debug/ee/amd64/walker.cpp | Remove unused include |
| src/coreclr/debug/di/dbgtransportmanager.cpp | Remove unused include |
| src/coreclr/debug/debug-pal/win/processdescriptor.cpp | Remove unused includes |
| src/coreclr/debug/daccess/dacfn.cpp | Remove unused include |
| src/coreclr/debug/createdump/main.cpp | Remove unused include |
| src/coreclr/binder/assembly.cpp | Remove unused include |
Copilot's findings
Comments suppressed due to low confidence (1)
src/coreclr/vm/ceeload.cpp:4469
<optsmallperfcritical.h>is included with the comment 'Optimization intended for Module::EnsureActive only', but the corresponding<optdefault.h>restore was removed. This causes subsequent code in the file to be built under the perf-critical optimization settings; re-add the restore include afterModule::EnsureActiveto keep the optimization scope limited as intended.
- Files reviewed: 132/132 changed files
- Comments generated: 5
There was a problem hiding this comment.
Copilot's findings
Comments suppressed due to low confidence (4)
src/coreclr/gc/vxsort/do_vxsort_avx2.cpp:10
- The
vxsort_targets_enable_avx2.h/vxsort_targets_disable.hincludes were removed. These headers push/pop compiler target attributes (e.g.,target("avx2")) so this function is compiled with the required ISA. Without them, the build can fail (unsupported intrinsics) or the function may not be properly isolated to AVX2-capable CPUs. Please restore the enable/disable includes around this implementation.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#include "common.h"
#include "vxsort.h"
#include "machine_traits.avx2.h"
#include "packer.h"
src/coreclr/vm/perfmap.cpp:10
common.hwas removed, but this file includesperfmap.h, which depends on CoreCLR VM types/macros (e.g.,MethodDesc,PCODE, contracts,CrstStatic) that are normally provided viacommon.h. As-is, this is very likely to fail to compile. Please re-add#include "common.h"(typically first) so the required VM definitions are available.
src/coreclr/vm/autotrace.cpp:26common.hwas removed, but this file uses CoreCLR VM infrastructure (CLRConfig,W(...),u16_strlen,FormatInteger,HANDLE, etc.) that is typically made available viacommon.h/the VM PCH. As written, this is likely to fail to compile. Please restore#include "common.h"near the top of the file.
src/coreclr/gc/vxsort/do_vxsort_avx512.cpp:10- The
vxsort_targets_enable_avx512.h/vxsort_targets_disable.hincludes were removed. These headers push/pop compiler target attributes so this function is compiled with AVX-512 enabled. Without them, the build can fail or the function may not be correctly isolated to AVX-512-capable CPUs. Please restore the enable/disable includes around this implementation.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
#include "common.h"
#include "vxsort.h"
#include "machine_traits.avx512.h"
void do_vxsort_avx512 (uint8_t** low, uint8_t** high, uint8_t* range_low, uint8_t* range_high)
- Files reviewed: 131/131 changed files
- Comments generated: 6
There was a problem hiding this comment.
Copilot's findings
Comments suppressed due to low confidence (3)
src/coreclr/ildasm/ildasmpch.cpp:6
ildasmpch.cppis the compilation unit used to build the ildasm precompiled header, but it no longer includesildasmpch.h. Without including the PCH header, PCH generation (and builds that rely on it) may fail. Please restore#include "ildasmpch.h"in this file.
//
// This is just to build the PCH for ildasm
src/coreclr/vm/perfmap.cpp:13
perfmap.hdepends on CoreCLR VM types/macros (e.g.,CrstStatic,_ASSERTE,ARRAY_SIZE) that are normally provided viacommon.h. With thecommon.hinclude removed here, this translation unit may fail to compile (or become dependent on forced includes/PCH behavior) when includingclrconfignocache.h/perfmap.h. Re-add#include "common.h"(or include the specific required headers) before these includes to keep the file self-contained across build configurations.
src/coreclr/vm/autotrace.cpp:26- This file uses many CoreCLR/Win32 types and helpers (
CLRConfig,HANDLE,WCHAR,CreateEventW,FormatInteger, etc.). Withcommon.hremoved, it now has no general runtime header included, which can lead to missing declarations unless the build forcibly includescommon.hfor this TU. Please restore thecommon.hinclude (or add the minimal required headers) to avoid build-config-dependent compilation.
- Files reviewed: 128/130 changed files
- Comments generated: 2
|
Could you please update the PR title and description with what you are trying to achieve? |
|
@moyo1997 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement ( “Agreement” ) is agreed to by the party signing below ( “You” ), 1. Definitions. “Code” means the computer software code, whether in human-readable or machine-executable form, “Project” means any of the projects owned or managed by .NET Foundation and offered under a license “Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any “Submission” means the Code and any other copyrightable material Submitted by You, including any 2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any 3. Originality of Work. You represent that each of Your Submissions is entirely Your 4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else 5. Licenses. a. Copyright License. You grant .NET Foundation, and those who receive the Submission directly b. Patent License. You grant .NET Foundation, and those who receive the Submission directly or c. Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement. 6. Representations and Warranties. You represent that You are legally entitled to grant the above 7. Notice to .NET Foundation. You agree to notify .NET Foundation in writing of any facts or 8. Information about Submissions. You agree that contributions to Projects and information about 9. Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of Washington, and 10. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and .NET Foundation dedicates this Contribution License Agreement to the public domain according to the Creative Commons CC0 1. |
There was a problem hiding this comment.
Copilot's findings
Comments suppressed due to low confidence (1)
src/coreclr/ildasm/ildasmpch.cpp:6
- This file’s comment says it exists "to build the PCH for ildasm", but after removing the
#include "ildasmpch.h"it no longer does that. Either restore the include (if a PCH is still intended) or remove/update this file and any build references so the comment and build intent stay accurate.
//
// This is just to build the PCH for ildasm
- Files reviewed: 124/126 changed files
- Comments generated: 1
There was a problem hiding this comment.
Copilot's findings
Comments suppressed due to low confidence (2)
src/coreclr/vm/comutilnative.cpp:1734
<optsmallperfcritical.h>is still included for the COMInterlocked FCIMPLs, but the<optdefault.h>include that restores default optimization settings was removed. This causes the optimization pragmas (andFPO_ON) to leak into the rest of the file. Please re-add<optdefault.h>after the last COMInterlocked FCIMPL in this block.
src/coreclr/vm/gchelpers.cpp:1600- This hunk removes the
<optsmallperfcritical.h>/<optdefault.h>pair that previously scoped MSVC optimization pragmas forErectWriteBarrier. Those headers are not “unused” includes; they change codegen (optimize-for-speed and frame-pointer omission in non-debug MSVC builds). If the intent is to keepErectWriteBarrierperf-critical, please restore the scoped optimization includes around it; otherwise, consider updating/removing the nearby comment(s) or adding a justification since this can be a measurable perf regression in a very hot path.
- Files reviewed: 122/124 changed files
- Comments generated: 0 new
There was a problem hiding this comment.
Copilot's findings
Comments suppressed due to low confidence (2)
src/coreclr/vm/autotrace.cpp:25
common.hwas removed, but this file uses VM contracts/macros (e.g.,CLRConfig,HANDLE,LPWSTR,STANDARD_VM_CONTRACT) that are typically provided via the CoreCLR precompiled header. As written, this will fail to compile (especially on MSVC with PCH enabled). Add back the appropriate PCH/header include (likelycommon.h) or include the specific headers that define these types/macros before they are used.
src/coreclr/vm/perfmap.cpp:12common.hwas removed before includingperfmap.h.perfmap.hreferences CoreCLR VM types (e.g.,MethodDesc,PCODE,CrstStatic, contracts macros) that are not declared in this file’s current include set, so this will not compile whenFEATURE_PERFMAPis enabled. Add back#include "common.h"(or otherwise ensure the required forward declarations/includes exist beforeperfmap.h).
- Files reviewed: 119/121 changed files
- Comments generated: 0 new
|
I don't think this can be done in a batch way. The native build of the codebase is very complicated, with various different platforms and include tricks. There are false positives like removing the pch file or functionality toggling headers. This shouldn't be done by who is not very familiar to the codebase. |
There was a problem hiding this comment.
Copilot's findings
Comments suppressed due to low confidence (6)
src/coreclr/vm/runtimehandles.cpp:223
#include <optsmallperfcritical.h>is used just above forRuntimeTypeHandle::GetNextIntroducedMethod, but the corresponding#include <optdefault.h>was removed. This will keep the perf-critical optimization pragmas enabled for subsequent methods in this file; please restoreoptdefault.hafter the intended region.
src/coreclr/vm/comcallablewrapper.cpp:1178- This file enables
#include <optsmallperfcritical.h>for the CCW QI helpers, but the matching#include <optdefault.h>afterQIStandardInterfacewas removed. That leaves the optimization pragmas active for the remainder of the file; please restoreoptdefault.hafter the intended perf-critical section.
src/coreclr/vm/perfmap.cpp:12 common.hwas removed, but this translation unit uses VM infrastructure types/macros (e.g.,Volatile,CrstStatic,CLRConfig, contract macros) that are typically provided viacommon.h/the VM PCH. This is likely to cause compile failures; restore#include "common.h"as the first include in the file.
src/coreclr/vm/gchelpers.cpp:1600ErectWriteBarrieris a hot path and previously had anoptsmallperfcritical.h/optdefault.hoptimization bracket. Removing those includes changes compiler optimization settings for this function (and may regress write barrier performance). If the intent is only to remove unused includes, keep the optimization bracket (or replace it with an equivalent pragma).
src/coreclr/vm/autotrace.cpp:26common.hwas removed, but this file uses many VM types/macros (e.g.,HANDLE,WCHAR,CLRConfig, contract macros) that are normally provided viacommon.h/the VM PCH. This will likely break the build (and may also violate the PCH include requirement). Add#include "common.h"back as the first include for this translation unit.
src/coreclr/ildasm/ildasmpch.cpp:6- This file exists to build the ildasm precompiled header, but it no longer includes
ildasmpch.h. With MSVC/Ycthis will typically fail (or produce an empty/incorrect PCH). Restore the#include "ildasmpch.h"in this TU (or adjust the build to generate the PCH elsewhere).
//
// This is just to build the PCH for ildasm
- Files reviewed: 117/119 changed files
- Comments generated: 2
There was a problem hiding this comment.
Copilot's findings
Comments suppressed due to low confidence (2)
src/coreclr/vm/autotrace.cpp:26
autotrace.cppno longer includescommon.h, but the file uses CoreCLR types/macros such asHANDLE,CLRConfig,W(...),ARRAY_SIZE, etc. Withoutcommon.h(or equivalent headers), the file is not self-contained and will only compile if the build forcibly includes the PCH header, which is fragile (e.g., if PCH is disabled for this TU or in other build setups). Consider re-adding#include "common.h"(consistent with mostvm/sources) or explicitly including the specific headers that provide the referenced types/macros.
src/coreclr/ildasm/ildasmpch.cpp:6ildasmpch.cppis documented as the translation unit used to build ILDASM's PCH, but it no longer includesildasmpch.h. If any build configuration compiles this file with a/Yc/PCH-creation expectation, this will fail (or at minimum the comment becomes inaccurate and the PCH may not be generated). Either restore the#include "ildasmpch.h"here or remove/rename this file and its references if ILDASM no longer uses a dedicated PCH TU.
//
// This is just to build the PCH for ildasm
- Files reviewed: 111/113 changed files
- Comments generated: 2
Restore original include styles: - sstring.cpp: keep <minipal/strings.h> (angle brackets) - finalizerthread.cpp, pgo.cpp, readytoruninfo.cpp: keep "dn-stdio.h" (quotes) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- assembly.cpp: Restore #include <optdefault.h> after EnsureLoadLevel to end the perf-critical optimization scope from optsmallperfcritical.h - dbgtransportmanager.cpp: Restore original include order so dbgtransportsession.h comes before dbgtransportmanager.h (the manager header depends on types from the session header) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
No description provided.