Runtime: 清理死代码

创建于 2017-04-05  ·  152评论  ·  资料来源: dotnet/runtime

在为我们的 .NETCoreApp 二进制文件启用单声道链接器后,它发现了许多我们有死代码的地方。

这些分为 3 类。

  1. 真正的死代码,在程序集中的任何地方都没有使用。

    • 这个可以删

  2. 在程序集的一个版本中使用的源文件,但不是全部。 一些项目使用源的公共源文件,但不是全部。

    • 这些可以更好地分解,拆分以在需要时提供最少的资源。 或者,它们可能包含真正的死代码。

  3. 仅编译时源。 在调用 IL 时表示为文字且未公开公开的内部常量。

    • 这些必须保留。

差异

  • [ ] [Microsoft.CSharp](http://tempcoverage.blob.core.windows.net/report2/Microsoft.CSharp.diff.html) ( csv )
  • [ ] [Microsoft.VisualBasic](http://tempcoverage.blob.core.windows.net/report2/Microsoft.VisualBasic.diff.html) ( csv )
  • [x] [System.Collections.Concurrent](http://tempcoverage.blob.core.windows.net/report2/System.Collections.Concurrent.diff.html) ( csv )
  • [x] [System.Collections](http://tempcoverage.blob.core.windows.net/report2/System.Collections.diff.html) ( csv ) - PR dotnet/corefx#19140 by @YoupHulsebos
  • [x] [System.Collections.Immutable](http://tempcoverage.blob.core.windows.net/report2/System.Collections.Immutable.diff.html) ( csv ) - @YoupHulsebos在 https 中没有删除任何内容: //github.com/dotnet/corefx/issues/17905#issuecomment-298154133
  • [x] [System.Collections.NonGeneric](http://tempcoverage.blob.core.windows.net/report2/System.Collections.NonGeneric.diff.html) ( csv ) - @YoupHulsebos在 https 中没有删除任何内容: //github.com/dotnet/corefx/issues/17905#issuecomment-298154133
  • [x] [System.Collections.Specialized](http://tempcoverage.blob.core.windows.net/report2/System.Collections.Specialized.diff.html) ( csv )
  • [x] [System.ComponentModel.Annotations](http://tempcoverage.blob.core.windows.net/report2/System.ComponentModel.Annotations.diff.html) ( csv ) @norek
  • [x] [System.ComponentModel](http://tempcoverage.blob.core.windows.net/report2/System.ComponentModel.diff.html) ( csv )@norek
  • [x] [System.ComponentModel.EventBasedAsync](http://tempcoverage.blob.core.windows.net/report2/System.ComponentModel.EventBasedAsync.diff.html) ( csv )@norek
  • [x] [System.ComponentModel.Primitives](http://tempcoverage.blob.core.windows.net/report2/System.ComponentModel.Primitives.diff.html) ( csv )@norek
  • [x] [System.ComponentModel.TypeConverter](http://tempcoverage.blob.core.windows.net/report2/System.ComponentModel.TypeConverter.diff.html) ( csv )@norek
  • [x] [System.Console](http://tempcoverage.blob.core.windows.net/report2/System.Console.diff.html) ( csv )
  • [x] [System.Data.Common](http://tempcoverage.blob.core.windows.net/report2/System.Data.Common.diff.html) ( csv ) - 在 dotnet/corefx#19141 中由 @ 修复YoupHulsebos
  • [x] [System.Diagnostics.Debug](http://tempcoverage.blob.core.windows.net/report2/System.Diagnostics.Debug.diff.html) ( csv )
  • [x] [System.Diagnostics.DiagnosticSource](http://tempcoverage.blob.core.windows.net/report2/System.Diagnostics.DiagnosticSource.diff.html) ( csv )
  • [x] [System.Diagnostics.FileVersionInfo](http://tempcoverage.blob.core.windows.net/report2/System.Diagnostics.FileVersionInfo.diff.html) ( csv )
  • [x] [System.Diagnostics.Process](http://tempcoverage.blob.core.windows.net/report2/System.Diagnostics.Process.diff.html) ( csv )
  • [x] [System.Diagnostics.StackTrace](http://tempcoverage.blob.core.windows.net/report2/System.Diagnostics.StackTrace.diff.html) ( csv )
  • [x] [System.Diagnostics.TextWriterTraceListener](http://tempcoverage.blob.core.windows.net/report2/System.Diagnostics.TextWriterTraceListener.diff.html) ( csv )
  • [x] [System.Diagnostics.Tools](http://tempcoverage.blob.core.windows.net/report2/System.Diagnostics.Tools.diff.html) ( csv )
  • [x] [System.Diagnostics.TraceSource](http://tempcoverage.blob.core.windows.net/report2/System.Diagnostics.TraceSource.diff.html) ( csv )
  • [x] [System.Diagnostics.Tracing](http://tempcoverage.blob.core.windows.net/report2/System.Diagnostics.Tracing.diff.html) ( csv )
  • [x] [System.Drawing.Primitives](http://tempcoverage.blob.core.windows.net/report2/System.Drawing.Primitives.diff.html) ( csv )
  • [ ] [System.IO.Compression](http://tempcoverage.blob.core.windows.net/report2/System.IO.Compression.diff.html) ( csv )
  • [x] [System.IO.Compression.ZipFile](http://tempcoverage.blob.core.windows.net/report2/System.IO.Compression.ZipFile.diff.html) ( csv )
  • [ ] [System.IO.FileSystem.AccessControl](http://tempcoverage.blob.core.windows.net/report2/System.IO.FileSystem.AccessControl.diff.html) ( csv )
  • [ ] [System.IO.FileSystem](http://tempcoverage.blob.core.windows.net/report2/System.IO.FileSystem.diff.html) ( csv )
  • [x] [System.IO.FileSystem.DriveInfo](http://tempcoverage.blob.core.windows.net/report2/System.IO.FileSystem.DriveInfo.diff.html) ( csv )
  • [x] [System.IO.FileSystem.Watcher](http://tempcoverage.blob.core.windows.net/report2/System.IO.FileSystem.Watcher.diff.html) ( csv )
  • [x] [System.IO.IsolatedStorage](http://tempcoverage.blob.core.windows.net/report2/System.IO.IsolatedStorage.diff.html) ( csv )
  • [x] [System.IO.MemoryMappedFiles](http://tempcoverage.blob.core.windows.net/report2/System.IO.MemoryMappedFiles.diff.html) ( csv )
  • [x] [System.IO.Pipes](http://tempcoverage.blob.core.windows.net/report2/System.IO.Pipes.diff.html) ( csv )
  • [x] [System.Linq](http://tempcoverage.blob.core.windows.net/report2/System.Linq.diff.html) ( csv ) - 无需删除,https://github.com/dotnet /corefx/issues/17905#issuecomment-294286344 by @JonHanna
  • [x] [System.Linq.Expressions](http://tempcoverage.blob.core.windows.net/report2/System.Linq.Expressions.diff.html) ( csv )
  • [x] [System.Linq.Parallel](http://tempcoverage.blob.core.windows.net/report2/System.Linq.Parallel.diff.html) ( csv ) - 在 dotnet/corefx#19143 中由 @ 修复YoupHulsebos
  • [x] [System.Linq.Queryable](http://tempcoverage.blob.core.windows.net/report2/System.Linq.Queryable.diff.html) ( csv ) - 无需删除 - https://github .com/dotnet/corefx/issues/17905#issuecomment-294286344 @JonHanna
  • [ ] [System.Net.Http](http://tempcoverage.blob.core.windows.net/report2/System.Net.Http.diff.html) ( csv )
  • [ ] [System.Net.HttpListener](http://tempcoverage.blob.core.windows.net/report2/System.Net.HttpListener.diff.html) ( csv )
  • [x] [System.Net.Mail](http://tempcoverage.blob.core.windows.net/report2/System.Net.Mail.diff.html) ( csv ) - 在 dotnet/corefx#19532 中由 @ 修复埃尔米亚尔
  • [x] [System.Net.NameResolution](http://tempcoverage.blob.core.windows.net/report2/System.Net.NameResolution.diff.html) ( csv )
  • [ ] [System.Net.NetworkInformation](http://tempcoverage.blob.core.windows.net/report2/System.Net.NetworkInformation.diff.html) ( csv )
  • [x] [System.Net.Ping](http://tempcoverage.blob.core.windows.net/report2/System.Net.Ping.diff.html) ( csv )
  • [ ] [System.Net.Primitives](http://tempcoverage.blob.core.windows.net/report2/System.Net.Primitives.diff.html) ( csv )
  • [ ] [System.Net.Requests](http://tempcoverage.blob.core.windows.net/report2/System.Net.Requests.diff.html) ( csv )
  • [ ] [System.Net.Security](http://tempcoverage.blob.core.windows.net/report2/System.Net.Security.diff.html) ( csv )
  • [x] [System.Net.ServicePoint](http://tempcoverage.blob.core.windows.net/report2/System.Net.ServicePoint.diff.html) ( csv )
  • [ ] [System.Net.Sockets](http://tempcoverage.blob.core.windows.net/report2/System.Net.Sockets.diff.html) ( csv )
  • [ ] [System.Net.WebClient](http://tempcoverage.blob.core.windows.net/report2/System.Net.WebClient.diff.html) ( csv )
  • [ ] [System.Net.WebHeaderCollection](http://tempcoverage.blob.core.windows.net/report2/System.Net.WebHeaderCollection.diff.html) ( csv )
  • [x] [System.Net.WebProxy](http://tempcoverage.blob.core.windows.net/report2/System.Net.WebProxy.diff.html) ( csv )
  • [ ] [System.Net.WebSockets.Client](http://tempcoverage.blob.core.windows.net/report2/System.Net.WebSockets.Client.diff.html) ( csv )
  • [ ] [System.Net.WebSockets](http://tempcoverage.blob.core.windows.net/report2/System.Net.WebSockets.diff.html) ( csv )
  • [x] [System.Numerics.Vectors](http://tempcoverage.blob.core.windows.net/report2/System.Numerics.Vectors.diff.html) ( csv )
  • [x] [System.ObjectModel](http://tempcoverage.blob.core.windows.net/report2/System.ObjectModel.diff.html) ( csv )
  • [ ] [System.Private.DataContractSerialization](http://tempcoverage.blob.core.windows.net/report2/System.Private.DataContractSerialization.diff.html) ( csv )
  • [ ] [System.Private.Uri](http://tempcoverage.blob.core.windows.net/report2/System.Private.Uri.diff.html) ( csv )
  • [x] [System.Private.Xml](http://tempcoverage.blob.core.windows.net/report2/System.Private.Xml.diff.html) ( csv )
  • [x] [System.Private.Xml.Linq](http://tempcoverage.blob.core.windows.net/report2/System.Private.Xml.Linq.diff.html) ( csv )
  • [x] [System.Reflection.DispatchProxy](http://tempcoverage.blob.core.windows.net/report2/System.Reflection.DispatchProxy.diff.html) ( csv )
  • [x] [System.Reflection.Metadata](http://tempcoverage.blob.core.windows.net/report2/System.Reflection.Metadata.diff.html) ( csv )
  • [x] [System.Reflection.TypeExtensions](http://tempcoverage.blob.core.windows.net/report2/System.Reflection.TypeExtensions.diff.html) ( csv )
  • [x] [System.Resources.Writer](http://tempcoverage.blob.core.windows.net/report2/System.Resources.Writer.diff.html) ( csv )
  • [x] [System.Runtime.CompilerServices.VisualC](http://tempcoverage.blob.core.windows.net/report2/System.Runtime.CompilerServices.VisualC.diff.html) ( csv )
  • [ ] [System.Runtime](http://tempcoverage.blob.core.windows.net/report2/System.Runtime.diff.html) ( csv )
  • [x] [System.Runtime.Extensions](http://tempcoverage.blob.core.windows.net/report2/System.Runtime.Extensions.diff.html) ( csv )
  • [x] [System.Runtime.InteropServices](http://tempcoverage.blob.core.windows.net/report2/System.Runtime.InteropServices.diff.html) ( csv )
  • [x] [System.Runtime.InteropServices.RuntimeInformation](http://tempcoverage.blob.core.windows.net/report2/System.Runtime.InteropServices.RuntimeInformation.diff.html) ( csv )
  • [x] [System.Runtime.Numerics](http://tempcoverage.blob.core.windows.net/report2/System.Runtime.Numerics.diff.html) ( csv )
  • [x] [System.Runtime.Serialization.Formatters](http://tempcoverage.blob.core.windows.net/report2/System.Runtime.Serialization.Formatters.diff.html) ( csv ) - 在 dotnet/corefx 中修复#19148 @yaelkeemink
  • [ ] [System.Runtime.Serialization.Primitives](http://tempcoverage.blob.core.windows.net/report2/System.Runtime.Serialization.Primitives.diff.html) ( csv )
  • [ ] [System.Security.AccessControl](http://tempcoverage.blob.core.windows.net/report2/System.Security.AccessControl.diff.html) ( csv )
  • [ ] [System.Security.Claims](http://tempcoverage.blob.core.windows.net/report2/System.Security.Claims.diff.html) ( csv )
  • [] [System.Security.Cryptography.Algorithms](http://tempcoverage.blob.core.windows.net/report2/System.Security.Cryptography.Algorithms.diff.html) ( csv ) @mccbraxton
  • [ ] [System.Security.Cryptography.Cng](http://tempcoverage.blob.core.windows.net/report2/System.Security.Cryptography.Cng.diff.html) ( csv )
  • [ ] [System.Security.Cryptography.Csp](http://tempcoverage.blob.core.windows.net/report2/System.Security.Cryptography.Csp.diff.html) ( csv )
  • [ ] [System.Security.Cryptography.Encoding](http://tempcoverage.blob.core.windows.net/report2/System.Security.Cryptography.Encoding.diff.html) ( csv )
  • [ ] [System.Security.Cryptography.OpenSsl](http://tempcoverage.blob.core.windows.net/report2/System.Security.Cryptography.OpenSsl.diff.html) ( csv )
  • [x] [System.Security.Cryptography.Primitives](http://tempcoverage.blob.core.windows.net/report2/System.Security.Cryptography.Primitives.diff.html) ( csv )
  • [x] [System.Security.Cryptography.X509Certificates](http://tempcoverage.blob.core.windows.net/report2/System.Security.Cryptography.X509Certificates.diff.html) ( csv ) - 在 dotnet/corefx 中修复#19144 @yaelkeemink
  • [x] [System.Security.Principal](http://tempcoverage.blob.core.windows.net/report2/System.Security.Principal.diff.html) ( csv ) - 无需删除
  • [x] [Microsoft.Win32.Primitives](http://tempcoverage.blob.core.windows.net/report2/Microsoft.Win32.Primitives.diff.html) ( csv )
  • [x] [Microsoft.Win32.Registry](http://tempcoverage.blob.core.windows.net/report2/Microsoft.Win32.Registry.diff.html) ( csv )
  • [ ] [Microsoft.XmlSerializer.Generator](http://tempcoverage.blob.core.windows.net/report2/Microsoft.XmlSerializer.Generator.diff.html) ( csv )
  • [x] [System.Security.Principal.Windows](http://tempcoverage.blob.core.windows.net/report2/System.Security.Principal.Windows.diff.html) ( csv ) - dotnet/corefx#18267
  • [x] [System.Text.RegularExpressions](http://tempcoverage.blob.core.windows.net/report2/System.Text.RegularExpressions.diff.html) ( csv ) - dotnet/corefx#18134
  • [x] [System.Threading](http://tempcoverage.blob.core.windows.net/report2/System.Threading.diff.html) ( csv ) - dotnet/corefx#18134
  • [x] [System.Threading.Overlapped](http://tempcoverage.blob.core.windows.net/report2/System.Threading.Overlapped.diff.html) ( csv ) - dotnet/corefx#18134
  • [x] [System.Threading.Tasks.Dataflow](http://tempcoverage.blob.core.windows.net/report2/System.Threading.Tasks.Dataflow.diff.html) ( csv ) - dotnet/corefx#17998
  • [x] [System.Threading.Tasks.Extensions](http://tempcoverage.blob.core.windows.net/report2/System.Threading.Tasks.Extensions.diff.html) ( csv ) - 无需删除
  • [x] [System.Threading.Tasks.Parallel](http://tempcoverage.blob.core.windows.net/report2/System.Threading.Tasks.Parallel.diff.html) ( csv ) - 无需删除
  • [x] [System.Threading.Thread](http://tempcoverage.blob.core.windows.net/report2/System.Threading.Thread.diff.html) ( csv ) - 没有什么可删除的
  • [x] [System.Transactions.Local](http://tempcoverage.blob.core.windows.net/report2/System.Transactions.Local.diff.html) ( csv )
  • [x] [System.Web.HttpUtility](http://tempcoverage.blob.core.windows.net/report2/System.Web.HttpUtility.diff.html) ( csv ) - 无需删除
  • [x] [System.Xml.XPath.XDocument](http://tempcoverage.blob.core.windows.net/report2/System.Xml.XPath.XDocument.diff.html) ( csv ) - 无需删除

背景

报告是通过启用 ILLink(来自 codegen 团队 /cc @erozenfeld 的单链接器构建)和比较输出生成的。

差异来自 Windows 构建,并且仅限于作为 NETCore.App 一部分的程序集。

启用链接器后,它将在程序集的对象文件夹中生成一个“PreTrim”文件夹,例如<corefx>\bin\obj\AnyOS.AnyCPU.Debug\Microsoft.CSharp\netstandard\PreTrim\Microsoft.CSharp.dll

要启用修剪程序集的中央副本,您可以设置属性BinPlaceILLinkTrimAssembly=true ,这会将所有预先修剪和修剪的程序集复制到 bin 下的文件夹: <corefx>\bin\ILLinkTrimAssembly\netcoreapp-Windows_NT-Debug-x64

要生成此问题中链接的报告,您必须拥有 AsmDiff.exe 工具的副本。 此工具尚不可用于核心,请参阅 (https://github.com/dotnet/buildtools/issues/1420)。 如果您拥有该工具的桌面版本,则可以通过设置AsmDiffCmd=<pathToAsmDiff.exe>来启用报告

在合并 https://github.com/dotnet/corefx/pull/17825 后,通过使用ILLinkTrimAssembly=true构建,可以为任何项目(不仅仅是 NETCore.App 中的项目)启用链接器。

如何处理图书馆

选择一个图书馆并记下您将要处理的内容。

打开上述库的 html 报告。 寻找红色线条。 这些理论上已经死了。 在此 repo 的src文件夹中搜索代码并将其删除。 继续浏览库的报告并删除所有这样的死代码。

但也有一些特殊情况:

  1. 这是一个很常见的。 任何带有“const”的东西,请忽略。 这些都是编译器内联的字段,我们希望将它们保留在源代码中。 通常是整数和字符串。
  2. “类 SR”中的任何“静态字符串”都是特殊的。 您必须在 .resx 文件中找到匹配的条目并将其删除,而不是编辑 C# 文件。 库的 .resx 文件位于src\<library>\src\Resources\strings.resx中。 执行此操作后,构建将重新生成 SR。 忽略“class SR”中的任何其他内容——有几种方法可能会显示为已死。
  3. 忽略任何私有的无参数构造函数。 我们在代码中包含这些以防止意外实例化类,我们希望将它们保留在代码中。
  4. 如果没有其他构造函数,则忽略任何公共无参数构造函数。 这些都不是真的。
  5. 一些代码不会在库的文件夹下,它会在 src\common 中。 这段代码实际上可能没有死,因为另一个库可能会使用它。 理想情况下,使用 grep 查看树中是否有其他人使用它——如果是,可以将其删除。 或者,忽略它,我们可以稍后再做一遍。
  6. 如果代码仅用于 Unix、UAP 等,请不要删除它。 它很可能没有死。 您可以通过被例如#if uap包围或在 .csproj 文件中具有条件(例如'$(TargetGroup)' == 'uap'" )来判断它是否属于这种类型

从库中删除死代码后,确保它可以构建(在库的“src”文件夹中运行“msbuild”)。 如果没有,请向后退。 如果它确实构建,接下来检查测试构建并通过(在“tests”文件夹中运行“msbuild /t:buildandtest”)。 如果他们不这样做,请再次追溯您的步骤。

如果一切看起来都不错,您可以为图书馆提出 PR。 当 PR 进入时,我们可以在这里检查它。

area-Meta easy enhancement untriaged up-for-grabs

所有152条评论

这是一个以字节为单位按降序列出差异的表格。 XML 已经有问题了

| | | |
|------------------------------------------------- ------|---------------|------------|
| 图书馆 | 删除的字节 | % 减少 |
| 总计 | 1221632 | 7.62% |
| Microsoft.XmlSerializer.Generator.dll | 392704 | 46.29% |
| System.Private.Xml.dll - dotnet/runtime#20506 | 93696 | 2.54% |
| System.Net.Http.dll | 42496 | 12.89% |
| System.Private.DataContractSerialization.dll | 39936 | 4.40% |
| System.ComponentModel.TypeConverter.dll | 36352 | 10.71% |
| System.Data.Common.dll | 36352 | 2.97% |
| System.IO.FileSystem.dll | 32768 | 26.56% |
| System.Net.HttpListener.dll | 32256 | 9.39% |
| System.Runtime.Extensions.dll | 31744 | 12.20% |
| System.Net.Mail.dll | 28672 | 10.81% |
| System.Net.Security.dll | 24064 | 9.73% |
| System.Security.Cryptography.X509Certificates.dll | 23552 | 15.13% |
| System.Net.WebSockets.Client.dll | 22016 | 27.22% |
| System.Net.Primitives.dll | 20992 | 21.58% |
| System.Net.Requests.dll | 20480 | 11.56% |
| System.IO.FileSystem.DriveInfo.dll | 18944 | 47.44% |
| System.Transactions.Local.dll | 17920 | 9.70% |
| System.Net.NetworkInformation.dll | 17408 | 15.45% |
| System.Net.NameResolution.dll | 15360 | 28.30% |
| System.Net.WebHeaderCollection.dll | 14336 | 34.57% |
| System.Net.Sockets.dll | 12288 | 5.35% |
| System.IO.FileSystem.Watcher.dll | 11776 | 28.40% |
| System.IO.Compression.dll | 11264 | 7.83% |
| System.Security.Cryptography.Algorithms.dll | 10240 | 7.04% |
| System.Threading.dll | 10240 | 15.15% |
| System.IO.Pipes.dll | 9728 | 14.18% |
| System.Diagnostics.Process.dll | 9216 | 7.83% |
| System.Security.Cryptography.Encoding.dll | 9216 | 22.22% |
| System.IO.MemoryMappedFiles.dll | 8704 | 19.77% |
| System.Security.Cryptography.Csp.dll | 8704 | 9.83% |
| System.Security.AccessControl.dll | 8192 | 7.69% |
| System.Security.Cryptography.Cng.dll | 7680 | 7.04% |
| System.Collections.dll | 7168 | 5.88% |
| System.Net.Ping.dll | 7168 | 15.05% |
| System.Console.dll | 6656 | 7.51% |
| System.Linq.Expressions.dll | 6656 | 1.03% |
| System.Security.Principal.Windows.dll | 6656 | 9.29% |
| Microsoft.Win32.Registry.dll | 6144 | 12.77% |
| System.Private.Uri.dll | 6144 | 5.41% |
| System.Net.WebClient.dll | 5632 | 8.27% |
| System.Private.Xml.Linq.dll | 5632 | 3.37% |
| Microsoft.CSharp.dll | 4096 | 0.78% |
| System.ComponentModel.Primitives.dll | 4096 | 16.00% |
| System.Reflection.Metadata.dll | 4096 | 0.81% |
| System.Threading.Tasks.Dataflow.dll | 4096 | 1.86% |
| System.Diagnostics.StackTrace.dll | 3584 | 20.59% |
| System.IO.FileSystem.AccessControl.dll | 3584 | 12.96% |
| System.Linq.Parallel.dll | 3584 | 1.41% |
| System.Text.RegularExpressions.dll | 3584 | 2.59% |
| System.IO.IsolatedStorage.dll | 3072 | 8.00% |
| System.Threading.Overlapped.dll | 3072 | 28.57% |
| System.Security.Claims.dll | 2560 | 5.32% |
| Microsoft.VisualBasic.dll | 2048 | 1.05% |
| System.Collections.Concurrent.dll | 2048 | 2.03% |
| System.Collections.NonGeneric.dll | 2048 | 4.44% |
| System.Diagnostics.TraceSource.dll | 2048 | 4.08% |
| System.Diagnostics.Tracing.dll | 2048 | 11.11% |
| System.Runtime.InteropServices.RuntimeInformation.dll | 2048 | 16.00% |
| System.Threading.Tasks.Parallel.dll | 2048 | 4.17% |
| Microsoft.Win32.Primitives.dll | 第1536章 17.65% |
| System.Collections.Specialized.dll | 第1536章 3.66% |
| System.ComponentModel.Annotations.dll | 第1536章 1.94% |
| System.Diagnostics.FileVersionInfo.dll | 第1536章 10.71% |
| System.Reflection.DispatchProxy.dll | 第1536章 5.36% |
| System.Resources.Writer.dll | 第1536章 7.69% |
| System.Runtime.Serialization.Formatters.dll | 第1536章 1.10% |
| System.Threading.Thread.dll | 第1536章 6.82% |
| System.ComponentModel.EventBasedAsync.dll | 1024 | 5.71% |
| System.Drawing.Primitives.dll | 1024 | 2.30% |
| System.IO.Compression.ZipFile.dll | 1024 | 6.90% |
| System.Linq.dll | 1024 | 0.69% |
| System.Linq.Queryable.dll | 1024 | 1.60% |
| System.Net.ServicePoint.dll | 1024 | 6.25% |
| System.ObjectModel.dll | 1024 | 2.63% |
| System.Runtime.InteropServices.dll | 1024 | 4.17% |
| System.Runtime.Numerics.dll | 1024 | 1.41% |
| System.Runtime.Serialization.Primitives.dll | 1024 | 7.69% |
| System.Security.Cryptography.Primitives.dll | 1024 | 2.41% |
| System.AppContext.dll | 512 | 8.33% |
| System.Collections.Immutable.dll | 512 | 0.26% |
| System.Diagnostics.DiagnosticSource.dll | 512 | 1.69% |
| System.Diagnostics.TextWriterTraceListener.dll | 512 | 4.35% |
| System.Globalization.Extensions.dll | 512 | 7.14% |
| System.Net.WebProxy.dll | 512 | 4.55% |
| System.Net.WebSockets.dll | 512 | 2.50% |
| System.Numerics.Vectors.dll | 512 | 0.32% |
| System.Reflection.Primitives.dll | 512 | 7.14% |
| System.Reflection.TypeExtensions.dll | 512 | 3.57% |
| System.Runtime.dll | 512 | 1.43% |
| System.Security.Cryptography.OpenSsl.dll | 512 | 6.25% |
| System.Xml.XmlSerializer.dll | 512 | 5.56% |
| System.Xml.XPath.XDocument.dll | 512 | 6.67% |

对于新的贡献者来说,这是一个非常容易解决的问题。 只需打开其中一个 htm 文件,然后删除标记为红色的源。

一个明显的问题是生成的SR类几乎总是有几个未使用的成员,并且它出现在我们的所有(或至少大多数)程序集中。 如果我们弄清楚如何解决这个问题,那可以给我们一些简单的全局改进。

我还看到在某些情况下会出现private const字段。 它们由该类的实现使用,但显然不可见或在外部使用。 尝试“修复”这些问题可能不值得。

如果使用private const字段的类实现可通过程序集外部可见的入口点访问,则不会删除这些字段。

据推测,如果任何库具有内部可见性(例如用于单元测试),我们会看到误报,对吧?

如果程序集具有 InternalsVisibleTo,则所有内部都被视为根。

行。 我认为在少数情况下测试使用反射来获取内部信息。 但是当我们运行测试时,这些会很快被发现。

@梅利诺

一个明显的问题是生成的 SR 类几乎总是有几个未使用的成员,并且它出现在我们的所有(或至少大多数)程序集中。 如果我们弄清楚如何解决这个问题,那可以给我们一些简单的全局改进。

我已经在 2 月删除了 100 条死弦。 剩下的将很少。 我认为这些是引用字符串的方法本身被修剪的情况。 在这种情况下,当然需要修剪 resx。

@danmosemsft我指的是始终在生成的文件中发出的这个成员块:

C# internal static string Format(string resourceFormat, object p1); internal static string Format(string resourceFormat, object p1, object p2); internal static string Format(string resourceFormat, object p1, object p2, object p3); internal static string Format(string resourceFormat, params object[] args);

通常(至少从我的简短浏览😄),只使用第一个,偶尔使用第二个。 在我点击的一些中,这是最大的差异部分。

行。 我认为在少数情况下测试使用反射来获取内部信息。 但是当我们运行测试时,这些会很快被发现。

我已经介绍了其中的大部分内容: https ://github.com/dotnet/corefx/pull/17825/commits/2277db969616a5ad4fd9f4a8118a3b4030ff62d3

我们已经内循环和外循环干净了。

Dataflow 的报告System.Threading.Tasks.Dataflow.Internal.Threading命名空间中的类型已失效。 这不是真的,它们在默认配置中已经失效,但是还有其他配置使用它们。 有关我提议的更改,请参阅https://github.com/dotnet/corefx/pull/17912

可能还有其他类似的类型吗? 有什么应该对他们做的吗?

此报告仅适用于 Windows 上的 NETCoreApp。 另一个配置可能仍在使用它们,如果有人试图完全删除它们,那么 -allConfigurations 构建会捕获它们。 对于这样的情况,您可以通过 if-def'ing/拆分源来改进 NETCoreApp 配置,正如我在上面第 2 项中提到的那样。 这看起来像您在 dotnet/corefx#17912 中所做的

如果您有兴趣识别我们未运行链接器的其他配置的差异,您可以使用我在背景部分中列出的详细信息打开它。 一旦 PR 被合并,这会更容易,所以你可能只想等待。

@erozenfeld我们不想仅仅因为它们被编译器内联而删除任何常量,因为这会失去代码的清晰度。 但是有些 const 确实已经死了,而那些我们可能确实想要删除。

例如,在http://tempcoverage.blob.core.windows.net/report2/System.ComponentModel.TypeConverter.diff.html中,整个VSStandardCommands都被标记为已死。 有些是可见的(通过public class StandardCommands ),并且只是内联。 但有些确实已经死了,例如cmdidThisWindow

很高兴能够看到哪些属于后一类。

是的,我们不能从源代码中删除编译器内联的 const。 ILLink 在 msil 上运行,无法区分真正的死常量和已死的常量,因为它已在各处内联。

它还将任何私有默认构造函数标记为已死,我们一般不希望将其删除,因为它们很容易防止任何意外的无参数构造。 出于同样的原因,我认为这是不可避免的。 据我所知,它们在编译后没有任何目的。

根据上面的讨论标记为“容易”。 我计划为这个问题指出一些首次贡献者。

如果有人选择文件,请在这个问题上说出来,以避免重复工作。

@danmosemsft你想在这里添加你发送给供应商的方法吗? 也许将它添加到顶帖是最好的,除了所有例外/要避免的事情......

@karelz完成

我粗略地看了一下差异。 它们里面有太多的噪音——我很难找到任何简单且可操作的东西。 我们能否从差异(常量、私有无参数构造函数……)中过滤掉噪音,让它只有简单的可操作项?

您可以打开 CSV 并应用您喜欢的任何过滤器。

摆弄主 CSV 以查看 /src/common 中的哪些代码实际上已经死了会很好。

@erozenfeld我可能在这里遗漏了一些东西。 它在http://tempcoverage.blob.core.windows.net/report2/System.Reflection.DispatchProxy.diff.html中说EventAccessorInfo.InterfaceRaiseMethod已死,但它是在构造函数中设置的,它本身不是死的。
https://github.com/dotnet/corefx/blob/master/src/System.Reflection.DispatchProxy/src/System/Reflection/DispatchProxyGenerator.cs#L919

删除抢购很容易,我认为它还没有准备好(如果您认为我错了,请随时更改)

我看不出它是怎么准备好的,说明很清楚......我认为这是一个很好的介绍。 无论如何,供应商人员将开始使用它。 我已经做了一些并检查了许多已经干净的。

它错误地标记为死的其他东西:在运行时通过 SR.GetResourceString("...") 加载的字符串。 不幸的是还有一些例如return SR.GetResourceString("PropertyCategory" + value, null);

这必须在代码审查中被抓住。

从略读线程来看,结果中似乎存在噪音问题。 再说一次,我感觉不是很强烈——随意把它翻过来;-)

没关系 :)

在 System.Transactions.Local 中,有一些代码目前没有被访问,但是一旦我们完成了支持分布式事务的工作,其中的一部分最终会被访问。 我不愿简单地删除此代码。

我已经删除了 Microsoft.CSharp 中标识的一些死代码以及更多(分析没有发现例如ExpressionBinder.BindPtrToArray根据 dotnet/corefx#17948 已死),其余的在我的作为我对该程序集的持续重构的一部分。

@danmosemsft关于 EventAccessorInfo.InterfaceRaiseMethod:据说 get_InterfaceRaiseMethod 已死,并且由于没有 set_InterfaceRaiseMethod,因此该属性已死。 构造函数中的代码设置编译器生成的支持字段k__BackingField 和 ILLink 保留该字段。

@jimcarley有道理,我检查了上面的 S.Transactions.Local 。 我想如果有一些零碎的东西实际上已经死了,你可能想在某个时候删除它们。

@JonHanna如果您认为 ILLink 应该能够发现该代码已死,我会让@erozenfeld知道。

@danmosemsft如果可以的话,我会印象深刻,我只是说这里提到的位已经是我打算进行的删除的子集,因此将涵盖列表中的该项目。

@danmosemsft @JonHanna ILLink 不会尝试在方法中查找无法访问的代码。 如果一个方法是可达的,它假定方法中的所有指令都是可达的。

为了其他人的利益:另一个案例离线,其中一个 int 字段被标记为已死的构造函数分配。 然而,该字段正在其他地方被读取,并且一旦该构造函数被删除,编译器就会警告该字段永远不会被设置。 读者正在阅读默认值。 在这种情况下,需要在移除死设置器时显式初始化该字段。

@erozenfeld这段代码似乎死了: https ://github.com/dotnet/corefx/compare/master...danmosemsft :dead.xml?expand=1
但没有被标记为死亡。 它在 IL(结构中的字段)中。 ILLink 是否特别避免从结构中删除字段,以防它们在互操作中使用?

在这种特殊情况下,字段在隐式静态构造函数中初始化,因此它们似乎确实在 IL 中使用。 要将它们检测为死代码,ILLink 必须:

  • 检测到字段是在静态构造函数中分配的,并且该值未在其他任何地方使用
  • 这些字段的分配没有副作用
  • 重写静态构造函数的方法体以移除这些字段的赋值,但保持其他所有内容不变。

啊——当然。

我注意到这些,因为它们在https://github.com/dotnet/corefx/pull/18395/files .. 其他发现有各种死的常量(当然 ILLink 无法分辨,因为它显示了所有常量死了)和一些只有人类才能分辨的初始化没有副作用。 ILLink 应该找不到任何东西。

@huanwu SGEN 工具有 400KB 的死代码。
删除所有这些是否合理还是正在进行中,您将使用此代码?

请参阅http://tempcoverage.blob.core.windows.net/report2/Microsoft.XmlSerializer.Generator.diff.html

在 System.Linq 和 System.Linq.Queryable 中,唯一标记的代码是在该项目中使用同一类的其他方法的公共文件中使用的常量或方法,因此它们不需要进一步的工作。

我刚刚使用我编写的工具识别了一些死代码 - 请参阅https://github.com/dotnet/corefx/pull/18395。 我使用您的代码作为输入数据来验证我的代码。

过去,我对 Roslyn (18.5 kloc) 进行了大规模删除,该删除擅长识别不应该死的代码 - 请参阅https://github.com/dotnet/roslyn/pull/17630 上的评论。 ie 只用在调试器中,由于有回归,测试执行不完整,应该有条件地编译。

@JonHanna谢谢! 用您的信息更新的热门帖子。

dotnet/corefx#18414 删除了 S.Linq.Expressions 中的大部分相关死代码。 除了常量等之外,如果移植当前不支持的功能(包括一个有问题的功能),仍然有一些可能变得相关,所以现在最好不要做进一步的事情。

听起来不错,它已在列表中选中。 其余大部分只需要最少的清理。 SGEN 是主要的例外( @huanwu ,请参阅上面的问题)

@zhenlan上面关于 Microsoft.XmlSerializer.Generator.dll 的问题——它有 400KB 的死代码(!)......这个代码是暂时死的,还是你完成了这项工作并且有人可以删除它? 我可以要求供应商做大部分工作,很有可能。 让我知道。

@danmosemsft这些不是死代码。 大多数代码与 System.Private.Xml 共享。 如果您查看项目文件https://github.com/dotnet/corefx/blob/master/src/Microsoft.XmlSerializer.Generator/src/Microsoft.XmlSerializer.Generator.csproj ,您会发现大部分代码文件位于$(SourceDir)SystemXml序列化

@huanwu即使我们不能从 repo 中删除代码(因为它被其他人使用)如果代码没有在这个程序集中使用,我们理想情况下不会将它编译到程序集中。
反射感知代码生成
XmlSerializationWriterCodeGen
XmlSerializationCodeGen
似乎都是死班。 理想情况下,它们可以移动到自己的代码文件中,这样它们就只在需要的地方编译。

ReflectionAwareCodeGen 实际上在#if XMLSERIALIZERGENERATOR内,所以如果它在这个程序集中已经死了,它可能完全死了。

此外,大多数字符串在此二进制文件中未使用。

如果这个代码在这个程序集中死掉了,那将节省 400KB,那么它是非常值得做的。

@danmosemsft ,我可能不完全理解死代码是如何确定的,但感觉有些不对劲。

例如,差异文件Microsoft.XmlSerializer.GeneratorReflectionAwareCodeGen标记为红色,从工具的角度来看,我将其解释为死代码。 但是,它显然用在Microsoft.XmlSerializer.Generator here中。 你能帮忙澄清一下吗?

好的,我看到该工具实际上将整个 *CodeGen 链标记为死代码。 请忽略我之前的问题,让我解释一下。 Microsoft.XmlSerializer.Generator 项目刚刚进行了初始签入。 有些代码只是暂时失效。 当我们完成更多工作时,将使用它们。 当我们接近代码完成时,也许我们可以再次运行该工具?

@zhenlan这正是我的假设。 代码完成实际上是上周 :) 也许这是一个 DCR。 还有很多事情要做吗?

@danmosemsft是的,你认为是对的 :)

Microsoft.XmlSerializer.Generator (Sgen) 是一个 CLI 工具,它不作为 .NET Core 的一部分提供。 对于 Sgen 与 S.Private.Xml 共享的代码部分,我认为除了错误修复之外没有任何大的差距,我们的目标是 ZBB 的 5/10。 对于仅在 Sgen 下的部分代码,还有更多的功能工作要做,但由于发布工具不同,我们应该有更多的余地。 希望这可以澄清。

@erozenfeld剩余的大部分可删除代码可能是没有人使用的常见共享文件的一部分。 如果不手动分析每一个或对 CSV 进行一些烦人的连接,就不可能清理该代码。 是否有一些直接的方法可以在整个程序集上运行 ILLink,合并在多个程序集中使用的文件,这样我们就可以获得其中一个 HTML 报告来显示公共代码中的死区?

我们还希望在产品代码(例如 PathInternal.cs)中编译某些测试时合并测试程序集。 还有 Unix 的,因为它们当然使用通用代码。

@danmosemsft我的工具可以做到这一点。 即在整个代码库上运行它,自动删除包括误报在内的行,重复构建和恢复然后测试。 最后将它推送到我的 Github 帐户并创建一个拉取请求。 可能涉及相当多的工作,所以除非它被使用,否则不要尝试。 有关子集的结果,请参见https://github.com/dotnet/corefx/pull/18395

@danmosemsft

是否有一些直接的方法可以在整个程序集上运行 ILLink,合并在多个程序集中使用的文件,这样我们就可以获得其中一个 HTML 报告来显示公共代码中的死区?

不,没有直接的方法可以做到这一点。 ILLink 对程序集进行操作,而不是用于生成它们的源文件。

@erozenfeld我不认为那是我的意思。 我不希望 ILLink 对资源进行操作。 但是现在任何在二进制 X 中显示为死的共享源都不能轻易删除,因为它们可能被二进制 Y 或 Z 使用。如果理论上我们所有的库都编译到一个大 dll 中,比如 ILMerge 或类似的运行,适当地修复 pdb 后,我们可以删除任何显示为死的公共代码。 我的问题是 ILMerge 是否可以将程序集合并为一个,然后对该程序集运行闭包分析。

@danmosemsft不,ILLink 不能像 ILMerge 那样将程序集合并为一个。 我不知道 ILMerge 如何处理程序集之间的冲突名称。 如果您在程序集 A 中具有类 NC,在程序集 B 中具有类 NC,则通常需要在合并时保留两者(并重命名一个或两个),除非您可以证明它们在深层意义上是相同的。

明白了。 好吧,也许将来会出现一种方法。 没什么大不了的。

我还想到,它可以通过对 CSV 的一些处理来完成......

所有这些数据现在可能已经过时了。 如果您想在这方面做更多工作,我们可能应该重新运行报告。 您可以在上面的背景部分找到有关执行此操作的说明。

在 System.Collections.Immutable 和 System.Collections.NonGeneric 中,唯一标记的代码是使用的常量或通用文件中的方法,其中在该项目中使用了同一类的其他方法,因此它们不需要进一步的工作。

谢谢@YoupHulsebos ,顶帖已更新。

在 System.IO.FileSystem.Watcher 和 System.Security.Cryptography.Primitives 中,唯一标记的代码是使用的常量或通用文件中的方法,其中在该项目中使用了同一类的其他方法,因此它们不需要进一步的工作。

@yaelkeemink感谢更新的复选框。

你好,
作为第一次贡献者,如果可以的话,我想处理System.Net.Mail库!

好的,谢谢! 前进。 如果您遇到任何障碍,请在此处联系我们以提交新问题(并标记我以进行路由)。

我为 System.Net.Mail 创建了一个拉取请求并签署了协议。

谢谢@Ermiar! 使用 PR 链接更新的热门问题。

第一次来这里 - 我将采取以下措施:

System.IO.FileSystem.DriveInfo
System.IO.FileSystem.Watcher

🗄

太棒了,欢迎加入@garfbradaz!
当您提交 PR 时让我们知道,我们会更新置顶帖子( @ViktorHofer今天可以帮忙吗?)

当然。

@garfbradaz请确保在删除可能的死代码后运行桌面和核心项目中的所有测试。
您可以通过首先运行来做到这一点:
build.cmdbuild.cmd -framework:netfx来自 corefx 根目录,然后像这样运行各个测试项目:
msbuild /t:RebuildAndTestmsbuild /t:RebuildAndTest /p:TargetGroup=netfx

如果您需要帮助,请随时与我联系。 谢谢你的帮助!

谢谢@ViktorHofer / @karelz - 慢慢耕耘

有一个误报:dotnet/corefx#19826 是通过在此问题上的提交 81506698 删除的代码实现的。 尽管该方法目前已“死”,但必须在那里将 DbProviderFactories 从完整的 .NET 中带回。 所以如果dotnet/corefx#19826的PR被合并,它就会复活。

第一次投稿,我想试试 System.Linq.Expressions。

伟大的@mccbraxton! 如果您需要任何帮助,请联系我。

@mccbraxton似乎 System.Linq.Expressions 已经清理干净了。 你想再拿一块吗?

@ViktorHofer你是对的 - 一定读错了。 System.Security.Cryptography.Algorithms 怎么样?

看起来挺好的! 我把你加到表里了。 请确保不要删除任何目标使用的代码。 谢谢你的帮助!

dotnet/corefx#18162 负责处理 Microsoft.CSharp 报告中真正死去的内容。

你好这里的新贡献者,我可以使用 System.ComponentModel.*

谢谢@norek 加油

您好,下面是 System.ComponentModel 的摘要。

  • root - 没有什么可删除的
  • .Annotations - 没有什么可删除的
  • .EventBasedAsync - 没有什么可删除的
  • .Primitives - 标记为已死但不是
  • .TypeConverters - 我删除了一些代码。 但是我对 != 运算符感到困惑-它被标记为已死,但我不知道您的所有编码约定-也应该删除吗?

我正在查看列表,发现 System.Diagnostics 中的死代码 - StackTraceSymbols被标记为死,但解决方案 exlorer 中此类的名称是StackTraceSymbols.CoreCLR.cs 。 我在已关闭的问题中发现:dotnet/corefx#19368
它死了还是没有?

@mikem8361你拥有 SDStackTraceSymbols 吗?

我拥有它,它不是死代码。 System.Private.CoreLib 使用反射来加载此程序集并引用此类。

因此 coreclr 可以在未处理的异常堆栈跟踪上打印源/行号信息。

@mikem8361感谢您提供的信息。 看起来它受 illinktrim.xml 保护:

<linker>
  <assembly fullname="System.Diagnostics.StackTrace">
    <!-- used by System.Private.CoreLib StackTrace code to load portable pdbs for the runtime diagnostic stack trace to get source/line info -->
    <type fullname="System.Diagnostics.StackTraceSymbols" required="true" />
  </assembly>
</linker>

@ericstj @erozenfeld我们可以修复 ILLink 发出的 CSV,以便在我们强制它保留代码时它不会将代码显示为死代码吗?

我们拥有的 CSV 只是修剪后的差异,因此它们没有明确植根的东西。 此问题中链接的数据不是实时的。 这是我打开问题时的一次性运行。 我怀疑如果您查看实时信息,它将不再显示为差异。

大家好,我是第一次投稿。 我想试试 System.Net.Http 和 System.Net.HttpListener。

@soapdogg去吧..

@AlexGhiondea如前所述

你好。 我可以拿Microsoft.VisulaBasic吗?

@satano当然,继续。 看起来只有几位要删除(根据我上面的文章,所有 const 字段和无参数 ctor 都需要保留)。 也许你也可以做 CSharp?

由于完成了上述分析,还有一些库是新的......

好的,我会做 CSharp 和 VisualBasic。

Microsoft.VisualBasic的 PR 已准备就绪。

关于Microsoft.CSharp - diff 文件中的所有红色内容都已删除。 所以只需在问题中标记它。

我们是将这个问题留给初学者,还是我可以继续?

@satano您能找到删除红色差异的更改吗?
可以继续,我们不会只为初学者保存它。

我不知道是不是全部,但这里删除了一些东西: https ://github.com/dotnet/corefx/commit/3eb339702e2fcdf924b50c2e32d7e9e02395e52f

@JonHanna甚至在这里说https://github.com/dotnet/corefx/issues/17905#issuecomment -291924301

我将从顶部继续。 所以接下来我会选择System.IO.CompressionSystem.IO.FileSystem.AccessControlSystem.IO.FileSystem

@satano去吧 - 无需征求许可,如果其他人正在寻找,他们会在这里发布。

对于某人来说,一个有趣的“元问题”是是否有一种方法可以使用相同的链接器工具来查找没有人使用的通用代码。 如果从 srccommon 中提取的类仅被库部分使用,则在此分析中它将显示为已死,但不会被删除,因为另一个库可能正在将其拉入并使用它。 我在想是否有办法合并程序集,然后在它们上运行链接器。 @erozenfeld我们可以使用链接器进行合并,然后在结果中找到死代码吗?

ILLink 当前无法合并程序集。 这是我们正在考虑在未来添加的内容。 还有其他工具可以做到这一点: https ://github.com/Microsoft/ILMerge 和https://github.com/gluck/il-repack虽然我不确定他们是否按照我们想要的方式处理这种情况。 他们可能会也可能不会意识到名称冲突的类型/方法/字段代表相同的实体。

我将继续使用System.Net.HttpSystem.Net.HttpListenerSystem.Net.NetworkInformation

我将一个接一个地拿走整个System.Net.*

继续其余的: System.Private.*System.Runtime.*System.Security.*

@karelz

......你能找到删除红色差异的变化吗?

dotnet/corefx#18162

嗯......也许是时候审查这个问题并关闭它了?

此项目中的死代码已被删除并合并:

  • Microsoft.CSharp(如上文评论中所述,之前已经完成)
  • Microsoft.VisualBasic
  • System.IO.压缩
  • System.IO.文件系统
  • System.IO.FileSystem.AccessControl
  • System.Net.Http
  • System.Net.HttpListener
  • System.Net.NetworkInformation
  • System.Net.Primitives
  • System.Net.Requests
  • System.Net.安全
  • System.Net.Sockets
  • System.Net.WebClient
  • System.Net.WebSocket.Client
  • System.Private.DataContractSerialization
  • System.Private.Uri
  • 系统.安全.密码学.Cng
  • 系统.安全.密码学.Csp

我还查看了其他项目,其中没有什么可做的:

  • System.Net.WebHeaderCollection
  • System.Net.WebSockets
  • 系统运行时
  • System.Runtime.Serialization.Primitives
  • System.Security.AccessControl
  • System.Security.Claims
  • 系统.安全.密码学.算法
  • 系统安全密码学编码
  • System.Security.Cryptography.OpenSsl

所以剩下的唯一项目是Microsoft.XmlSerializer.Generator 。 它有大部分死代码,但正如这里的一些评论中提到的,那里正在进行一项工作——据我所知。

这个问题完成了吗? 如果没有,我可以拿System.Console吗?

@Iroca88当然。 请注意,上面链接的转储现在可能有点过时了。

谢谢@danmosemsft ,有什么关于获取新转储的建议吗? 否则,我将从上面提供的转储开始。

顺便说一句:是@lroca88 ,我将第一个字母(L)大写以避免这种混淆:)

@Lroca88顶部的帖子解释了如何访问修剪和预修剪的组件。 为了区分它们,我们使用了一个似乎不公开的工具。 您可以同时使用 Ilspy 之类的反编译器,并对结果进行文本比较。 那可能会奏效。

我将运行最近的差异并分享它。 敬请关注。

这是最新的:

  • [ ] [Microsoft.CSharp](http://tempcoverage.blob.core.windows.net/report3/Microsoft.CSharp.diff.html) ( csv )
  • [ ] [Microsoft.VisualBasic](http://tempcoverage.blob.core.windows.net/report3/Microsoft.VisualBasic.diff.html) ( csv )
  • [ ] [Microsoft.Win32.Primitives](http://tempcoverage.blob.core.windows.net/report3/Microsoft.Win32.Primitives.diff.html) ( csv )
  • [ ] [Microsoft.Win32.Registry](http://tempcoverage.blob.core.windows.net/report3/Microsoft.Win32.Registry.diff.html) ( csv )
  • [ ] [System.Collections.Concurrent](http://tempcoverage.blob.core.windows.net/report3/System.Collections.Concurrent.diff.html) ( csv )
  • [ ] [System.Collections](http://tempcoverage.blob.core.windows.net/report3/System.Collections.diff.html) ( csv )
  • [ ] [System.Collections.Immutable](http://tempcoverage.blob.core.windows.net/report3/System.Collections.Immutable.diff.html) ( csv )
  • [ ] [System.Collections.NonGeneric](http://tempcoverage.blob.core.windows.net/report3/System.Collections.NonGeneric.diff.html) ( csv )
  • [ ] [System.Collections.Specialized](http://tempcoverage.blob.core.windows.net/report3/System.Collections.Specialized.diff.html) ( csv )
  • [ ] [System.ComponentModel.Annotations](http://tempcoverage.blob.core.windows.net/report3/System.ComponentModel.Annotations.diff.html) ( csv )
  • [ ] [System.ComponentModel](http://tempcoverage.blob.core.windows.net/report3/System.ComponentModel.diff.html) ( csv )
  • [ ] [System.ComponentModel.EventBasedAsync](http://tempcoverage.blob.core.windows.net/report3/System.ComponentModel.EventBasedAsync.diff.html) ( csv )
  • [ ] [System.ComponentModel.Primitives](http://tempcoverage.blob.core.windows.net/report3/System.ComponentModel.Primitives.diff.html) ( csv )
  • [ ] [System.ComponentModel.TypeConverter](http://tempcoverage.blob.core.windows.net/report3/System.ComponentModel.TypeConverter.diff.html) ( csv )
  • [ ] [System.Console](http://tempcoverage.blob.core.windows.net/report3/System.Console.diff.html) ( csv )
  • [ ] [System.Data.Common](http://tempcoverage.blob.core.windows.net/report3/System.Data.Common.diff.html) ( csv )
  • [ ] [System.Diagnostics.DiagnosticSource](http://tempcoverage.blob.core.windows.net/report3/System.Diagnostics.DiagnosticSource.diff.html) ( csv )
  • [ ] [System.Diagnostics.FileVersionInfo](http://tempcoverage.blob.core.windows.net/report3/System.Diagnostics.FileVersionInfo.diff.html) ( csv )
  • [ ] [System.Diagnostics.Process](http://tempcoverage.blob.core.windows.net/report3/System.Diagnostics.Process.diff.html) ( csv )
  • [ ] [System.Diagnostics.StackTrace](http://tempcoverage.blob.core.windows.net/report3/System.Diagnostics.StackTrace.diff.html) ( csv )
  • [ ] [System.Diagnostics.TextWriterTraceListener](http://tempcoverage.blob.core.windows.net/report3/System.Diagnostics.TextWriterTraceListener.diff.html) ( csv )
  • [ ] [System.Diagnostics.Tools](http://tempcoverage.blob.core.windows.net/report3/System.Diagnostics.Tools.diff.html) ( csv )
  • [ ] [System.Diagnostics.TraceSource](http://tempcoverage.blob.core.windows.net/report3/System.Diagnostics.TraceSource.diff.html) ( csv )
  • [ ] [System.Diagnostics.Tracing](http://tempcoverage.blob.core.windows.net/report3/System.Diagnostics.Tracing.diff.html) ( csv )
  • [ ] [System.Drawing.Primitives](http://tempcoverage.blob.core.windows.net/report3/System.Drawing.Primitives.diff.html) ( csv )
  • [ ] [System.IO.Compression.Brotli](http://tempcoverage.blob.core.windows.net/report3/System.IO.Compression.Brotli.diff.html) ( csv )
  • [ ] [System.IO.Compression](http://tempcoverage.blob.core.windows.net/report3/System.IO.Compression.diff.html) ( csv )
  • [ ] [System.IO.Compression.ZipFile](http://tempcoverage.blob.core.windows.net/report3/System.IO.Compression.ZipFile.diff.html) ( csv )
  • [ ] [System.IO.FileSystem.AccessControl](http://tempcoverage.blob.core.windows.net/report3/System.IO.FileSystem.AccessControl.diff.html) ( csv )
  • [ ] [System.IO.FileSystem](http://tempcoverage.blob.core.windows.net/report3/System.IO.FileSystem.diff.html) ( csv )
  • [ ] [System.IO.FileSystem.DriveInfo](http://tempcoverage.blob.core.windows.net/report3/System.IO.FileSystem.DriveInfo.diff.html) ( csv )
  • [ ] [System.IO.FileSystem.Watcher](http://tempcoverage.blob.core.windows.net/report3/System.IO.FileSystem.Watcher.diff.html) ( csv )
  • [ ] [System.IO.IsolatedStorage](http://tempcoverage.blob.core.windows.net/report3/System.IO.IsolatedStorage.diff.html) ( csv )
  • [ ] [System.IO.MemoryMappedFiles](http://tempcoverage.blob.core.windows.net/report3/System.IO.MemoryMappedFiles.diff.html) ( csv )
  • [ ] [System.IO.Pipes](http://tempcoverage.blob.core.windows.net/report3/System.IO.Pipes.diff.html) ( csv )
  • [ ] [System.Linq](http://tempcoverage.blob.core.windows.net/report3/System.Linq.diff.html) ( csv )
  • [ ] [System.Linq.Expressions](http://tempcoverage.blob.core.windows.net/report3/System.Linq.Expressions.diff.html) ( csv )
  • [ ] [System.Linq.Parallel](http://tempcoverage.blob.core.windows.net/report3/System.Linq.Parallel.diff.html) ( csv )
  • [ ] [System.Linq.Queryable](http://tempcoverage.blob.core.windows.net/report3/System.Linq.Queryable.diff.html) ( csv )
  • [ ] [System.Memory](http://tempcoverage.blob.core.windows.net/report3/System.Memory.diff.html) ( csv )
  • [ ] [System.Net.Http](http://tempcoverage.blob.core.windows.net/report3/System.Net.Http.diff.html) ( csv )
  • [ ] [System.Net.HttpListener](http://tempcoverage.blob.core.windows.net/report3/System.Net.HttpListener.diff.html) ( csv )
  • [ ] [System.Net.Mail](http://tempcoverage.blob.core.windows.net/report3/System.Net.Mail.diff.html) ( csv )
  • [ ] [System.Net.NameResolution](http://tempcoverage.blob.core.windows.net/report3/System.Net.NameResolution.diff.html) ( csv )
  • [ ] [System.Net.NetworkInformation](http://tempcoverage.blob.core.windows.net/report3/System.Net.NetworkInformation.diff.html) ( csv )
  • [ ] [System.Net.Ping](http://tempcoverage.blob.core.windows.net/report3/System.Net.Ping.diff.html) ( csv )
  • [ ] [System.Net.Primitives](http://tempcoverage.blob.core.windows.net/report3/System.Net.Primitives.diff.html) ( csv )
  • [ ] [System.Net.Requests](http://tempcoverage.blob.core.windows.net/report3/System.Net.Requests.diff.html) ( csv )
  • [ ] [System.Net.Security](http://tempcoverage.blob.core.windows.net/report3/System.Net.Security.diff.html) ( csv )
  • [ ] [System.Net.ServicePoint](http://tempcoverage.blob.core.windows.net/report3/System.Net.ServicePoint.diff.html) ( csv )
  • [ ] [System.Net.Sockets](http://tempcoverage.blob.core.windows.net/report3/System.Net.Sockets.diff.html) ( csv )
  • [ ] [System.Net.WebClient](http://tempcoverage.blob.core.windows.net/report3/System.Net.WebClient.diff.html) ( csv )
  • [ ] [System.Net.WebHeaderCollection](http://tempcoverage.blob.core.windows.net/report3/System.Net.WebHeaderCollection.diff.html) ( csv )
  • [ ] [System.Net.WebProxy](http://tempcoverage.blob.core.windows.net/report3/System.Net.WebProxy.diff.html) ( csv )
  • [ ] [System.Net.WebSockets.Client](http://tempcoverage.blob.core.windows.net/report3/System.Net.WebSockets.Client.diff.html) ( csv )
  • [ ] [System.Net.WebSockets](http://tempcoverage.blob.core.windows.net/report3/System.Net.WebSockets.diff.html) ( csv )
  • [ ] [System.Numerics.Vectors](http://tempcoverage.blob.core.windows.net/report3/System.Numerics.Vectors.diff.html) ( csv )
  • [ ] [System.ObjectModel](http://tempcoverage.blob.core.windows.net/report3/System.ObjectModel.diff.html) ( csv )
  • [ ] [System.Private.DataContractSerialization](http://tempcoverage.blob.core.windows.net/report3/System.Private.DataContractSerialization.diff.html) ( csv )
  • [ ] [System.Private.Uri](http://tempcoverage.blob.core.windows.net/report3/System.Private.Uri.diff.html) ( csv )
  • [ ] [System.Private.Xml](http://tempcoverage.blob.core.windows.net/report3/System.Private.Xml.diff.html) ( csv )
  • [ ] [System.Private.Xml.Linq](http://tempcoverage.blob.core.windows.net/report3/System.Private.Xml.Linq.diff.html) ( csv )
  • [ ] [System.Reflection.DispatchProxy](http://tempcoverage.blob.core.windows.net/report3/System.Reflection.DispatchProxy.diff.html) ( csv )
  • [ ] [System.Reflection.Metadata](http://tempcoverage.blob.core.windows.net/report3/System.Reflection.Metadata.diff.html) ( csv )
  • [ ] [System.Reflection.TypeExtensions](http://tempcoverage.blob.core.windows.net/report3/System.Reflection.TypeExtensions.diff.html) ( csv )
  • [ ] [System.Resources.Writer](http://tempcoverage.blob.core.windows.net/report3/System.Resources.Writer.diff.html) ( csv )
  • [ ] [System.Runtime.CompilerServices.VisualC](http://tempcoverage.blob.core.windows.net/report3/System.Runtime.CompilerServices.VisualC.diff.html) ( csv )
  • [ ] [System.Runtime](http://tempcoverage.blob.core.windows.net/report3/System.Runtime.diff.html) ( csv )
  • [ ] [System.Runtime.Extensions](http://tempcoverage.blob.core.windows.net/report3/System.Runtime.Extensions.diff.html) ( csv )
  • [ ] [System.Runtime.InteropServices](http://tempcoverage.blob.core.windows.net/report3/System.Runtime.InteropServices.diff.html) ( csv )
  • [ ] [System.Runtime.InteropServices.RuntimeInformation](http://tempcoverage.blob.core.windows.net/report3/System.Runtime.InteropServices.RuntimeInformation.diff.html) ( csv )
  • [ ] [System.Runtime.InteropServices.WindowsRuntime](http://tempcoverage.blob.core.windows.net/report3/System.Runtime.InteropServices.WindowsRuntime.diff.html) ( csv )
  • [ ] [System.Runtime.Numerics](http://tempcoverage.blob.core.windows.net/report3/System.Runtime.Numerics.diff.html) ( csv )
  • [ ] [System.Runtime.Serialization.Formatters](http://tempcoverage.blob.core.windows.net/report3/System.Runtime.Serialization.Formatters.diff.html) ( csv )
  • [ ] [System.Runtime.Serialization.Primitives](http://tempcoverage.blob.core.windows.net/report3/System.Runtime.Serialization.Primitives.diff.html) ( csv )
  • [ ] [System.Security.AccessControl](http://tempcoverage.blob.core.windows.net/report3/System.Security.AccessControl.diff.html) ( csv )
  • [ ] [System.Security.Claims](http://tempcoverage.blob.core.windows.net/report3/System.Security.Claims.diff.html) ( csv )
  • [ ] [System.Security.Cryptography.Algorithms](http://tempcoverage.blob.core.windows.net/report3/System.Security.Cryptography.Algorithms.diff.html) ( csv )
  • [ ] [System.Security.Cryptography.Cng](http://tempcoverage.blob.core.windows.net/report3/System.Security.Cryptography.Cng.diff.html) ( csv )
  • [ ] [System.Security.Cryptography.Csp](http://tempcoverage.blob.core.windows.net/report3/System.Security.Cryptography.Csp.diff.html) ( csv )
  • [ ] [System.Security.Cryptography.Encoding](http://tempcoverage.blob.core.windows.net/report3/System.Security.Cryptography.Encoding.diff.html) ( csv )
  • [ ] [System.Security.Cryptography.OpenSsl](http://tempcoverage.blob.core.windows.net/report3/System.Security.Cryptography.OpenSsl.diff.html) ( csv )
  • [ ] [System.Security.Cryptography.Primitives](http://tempcoverage.blob.core.windows.net/report3/System.Security.Cryptography.Primitives.diff.html) ( csv )
  • [ ] [System.Security.Cryptography.X509Certificates](http://tempcoverage.blob.core.windows.net/report3/System.Security.Cryptography.X509Certificates.diff.html) ( csv )
  • [ ] [System.Security.Principal](http://tempcoverage.blob.core.windows.net/report3/System.Security.Principal.diff.html) ( csv )
  • [ ] [System.Security.Principal.Windows](http://tempcoverage.blob.core.windows.net/report3/System.Security.Principal.Windows.diff.html) ( csv )
  • [ ] [System.Text.RegularExpressions](http://tempcoverage.blob.core.windows.net/report3/System.Text.RegularExpressions.diff.html) ( csv )
  • [ ] [System.Threading](http://tempcoverage.blob.core.windows.net/report3/System.Threading.diff.html) ( csv )
  • [ ] [System.Threading.Overlapped](http://tempcoverage.blob.core.windows.net/report3/System.Threading.Overlapped.diff.html) ( csv )
  • [ ] [System.Threading.Tasks.Dataflow](http://tempcoverage.blob.core.windows.net/report3/System.Threading.Tasks.Dataflow.diff.html) ( csv )
  • [ ] [System.Threading.Tasks.Parallel](http://tempcoverage.blob.core.windows.net/report3/System.Threading.Tasks.Parallel.diff.html) ( csv )
  • [ ] [System.Threading.Thread](http://tempcoverage.blob.core.windows.net/report3/System.Threading.Thread.diff.html) ( csv )
  • [ ] [System.Transactions.Local](http://tempcoverage.blob.core.windows.net/report3/System.Transactions.Local.diff.html) ( csv )
  • [ ] [System.ValueTuple](http://tempcoverage.blob.core.windows.net/report3/System.ValueTuple.diff.html) ( csv )
  • [ ] [System.Web.HttpUtility](http://tempcoverage.blob.core.windows.net/report3/System.Web.HttpUtility.diff.html) ( csv )
  • [ ] [System.Xml.XPath.XDocument](http://tempcoverage.blob.core.windows.net/report3/System.Xml.XPath.XDocument.diff.html) ( csv )

酷,我正在为旧列表苦苦挣扎! 🔨

@Lroca88一定要阅读有关如何执行此通行证的顶级帖子提示,以免造成一些混乱..

哎呀。 我错过了 dotnet/corefx#26491 中 Microsoft.CSharp 中的两个新孤立位。 我很快就会明白的。

在新列表中,System.Runtime、System.Web.HttpUtility、System.Linq 和 System.Linq.Queryable 仅具有未真正失效的常量和一些共享代码。 System.Linq.Expressions 具有调试视图中使用的那些和一些项目以及与特定编译器常量一起使用的资源,因此应删除,因此可以将这五个全部选中。

我已将@JonHanna审查的库和我审查的库合并到一个列表中。 我会在时间允许的情况下不断更新列表,如果有人想在此列表中添加项目,请随时 ping 我!

图书馆 | 审核人 | 地位
-- | -- | --
Microsoft.CSharp (csv) | @乔汉娜| dotnet/corefx#27104
Microsoft.VisualBasic (csv) | @Lroca88 | 没有什么可删除的
Microsoft.Win32.Primitives (csv) | @Lroca88 | 没有什么可删除的
Microsoft.Win32.Registry (csv) | @Lroca88 | 没有什么可删除的
System.Collections.Concurrent (csv) | @Lroca88 | 没有什么可删除的
System.Collections (csv) | @Lroca88 | 没有什么可删除的
System.Runtime (csv) | @乔汉娜| 没有什么可删除的
System.Web.HttpUtility (csv) | @乔汉娜| 没有什么可删除的
System.Linq (csv) | @乔汉娜| 没有什么可删除的
System.Linq.Queryable (csv) | @乔汉娜| 没有什么可删除的

谢谢@Lroca88

没有很多死代码让我感到惊讶。 但是,如顶部所述,此过程无法确定 srccommon 中的代码是否已死(因为它可能在一个程序集中显示为已死,但在另一个程序集中却没有)。 如果您有兴趣找到解决该问题的方法,您可能会发现更多死代码。 例如,也许可以 ILMerge 程序集,然后对它们运行死代码分析。 或者,对 CSV 进行后期处理以找到在所有这些文件中都已失效的公共代码可能会更容易。 @ericstj你有想法吗?

我很高兴帮助@danmosemsft
我同意你关于改进这个过程的观点,从我的评论来看,标记最多的代码并没有死,要么是常量,要么是你之前所说的经常在另一个程序集中使用。 在我看来,查看这些误报会使搜索变得有点乏味。

不幸的是,我不知道如何执行 ILMerge 和死代码分析或后处理 CSV。 我愿意学习/合作,如果你们想花一些时间辅导我:)

我们在哪里? OP 是否与已完成的课程保持同步,还是我们现在应该取消此评论

@MisinformedDNA - 请使用https://github.com/dotnet/corefx/issues/17905#issuecomment -365349091

我不知道如何执行 ILMerge 和死代码分析或后处理 CSV。 我愿意学习/合作,如果你们想花一些时间辅导我:)

我也不知道,必须思考/实验。 现在我正在全力以赴关闭 2.1 版本,所以这将不得不稍等一下😺

我编写了一个脚本来加载所有 CSV,然后过滤到最可操作的那些。 我提出了 3,942 个问题/机会。

我现在打算查看每个问题并采取适当的行动。 如果您愿意,可以在https://github.com/MisinformedDNA/corefx/tree/clean-dead-code关注我的进度并留下反馈

很好,期待看到这个@MisinformedDNA。

我发现死代码分析存在问题,表明该工具存在问题或缺陷。

该报告说可以删除以下内容:

    Friend Enum vbErrors
        ObjNotSet = 91
        IllegalFor = 92
    End Enum

但是这些枚举在其他地方被引用,所以让我们看看一个可能的分支:

    ' Enum cannot be accessed, so Function cannot be hit
    ' But the dead code analysis did not show this as removable!!
    Friend Shared Function VbMakeIllegalForException() As System.Exception
        Return VbMakeExceptionEx(vbErrors.IllegalFor, GetResourceString(SR.ID92)) 
    End Function

    ' The chain continues:

    ' VbMakeIllegalForException() cannot be hit, so first "If" cannot be true, but the rest of the Function *could* still be hit
    Public Shared Function ForNextCheckObj(ByVal counter As Object, ByVal loopObj As Object, ByRef counterResult As Object) As Boolean
        Dim loopFor As ForLoopControl
        If loopObj Is Nothing Then
            Throw VbMakeIllegalForException()
        End If
        If counter Is Nothing Then
            Throw New NullReferenceException(GetResourceString(SR.Argument_InvalidNullValue1, "Counter"))
        End If
        loopFor = CType(loopObj, ForLoopControl)
        ... cut for brevity
    End Function

逻辑把我带到了第一个“如果”语句永远不正确的地方。 但是那个“If”语句是一个null检查,所以我们必须假设有人会传入null并且有一个用于确定死代码的缺失案例。 如果在确定死代码方面存在(或更多)问题,那么一个或多个枚举可能毕竟不是死代码。

tldr:总结

问题 1:为什么 VbMakeIllegalForException没有标记为删除,即使它不可能调用标记删除的枚举。
问题 2:为什么测试用例在确定死代码时,没有为所有适用参数传入空值?

@ericstj

枚举值可能已内联在 msil 中,因此该工具看不到它们。 常量也是如此。 在这些情况下,不应对源代码做任何事情。

我刚刚删除了System.Data.Common的死代码,$ build.cmd src\System.Data.Common成功完成。 现在到现在为止,我的印象是我只需要在我所在的库中工作,如果构建和测试通过,那么我很高兴。 但是我还是决定做一个完整的构建,我很高兴我做到了,因为我遇到了很多错误。

以下是一些示例错误:

SystemDataSqlClientSqlCommandBuilder.cs(277,17):错误 CS0117:“ADP”不包含“RemoveStringQuotes”的定义 [D:ReposcorefxsrcSystem.Data.SqlClientsrcSystem.Data.SqlClient.csproj]
SystemDataProviderBaseDbConnectionPool.cs(984,33):错误 CS0117:“ADP”不包含“SetCurrentTransaction”的定义 [D:ReposcorefxsrcSystem.Data.SqlClientsrcSystem.Data.SqlClient.csproj]
D:ReposcorefxsrcCommonsrcSystemDataProviderBaseDbMetaDataFactory.cs(409,21):错误 CS0117:“ADP”不包含“IsEmptyArray”的定义 [D:ReposcorefxsrcSystem.Data.SqlClientsrcSystem.Data.SqlClient.csproj]
SystemDataCommonDbConnectionStringCommon.cs(180,27):错误 CS0117:“ADP”不包含“InvalidConnectionOptionValue”的定义 [D:ReposcorefxsrcSystem.Data.SqlClientsrcSystem.Data.SqlClient.csproj]

丢失的成员都在System.Data.Common.diff.html中明确指定要删除,但它们不仅会导致子类中的错误,而且这些子类没有差异文件或有关联的程序集,如System.Data.SqlClient

上面显示的第一个错误链接到公共方法SqlCommandBuilder.UnquoteIdentifier 。 所以我看不出如何在不改变其他类的情况下从System.Data.Common ADP.RemoveStringQuotes删除 ADP.RemoveStringQuotes 。

我应该如何处理这些? 任何想法为什么它们被标记为删除?

@anipik你能在这里帮助@misinformeddna吗?

@MisinformedDNA您将始终必须构建整个存储库并为所有库运行测试,因为一个库可能直接依赖于其他库(A使用B中的某种类型)或间接依赖。 (A 使用 B 中的某种类型,而 B 使用 C 中的某种类型)
函数ADP.removeStringQuotesisemptyarraysetTransaction中没有任何内容仅特定于 ApaterUtil 或 System.Data.Common ,因此我们可以将其移至sqlCommandBuilder.cs作为私有静态方法。 他们只是在操纵论点。 如果您可以将我指向出现此故障的分支,我可以帮助您解决其他故障。

您上面提到的所有方法都是internal static methods ,它们不再在它们定义的程序集中使用。
内部成员通常不打算在它们定义的程序集之外使用。 但在某些情况下,我们通过使用“Internals Visible To”属性来做到这一点。

@danmosemsft正在将这些内部功能移动到它们最适合使用的程序集中?

这是我正在处理的分支: https ://github.com/MisinformedDNA/corefx/tree/clean-dead-code

如前所述,死代码分析表明ADP.RemoveStringQuotes System.Data.Common可以被删除。 但是,由于ADP被标记internal ,分析器可能假设它没有在程序集之外使用。 我不确定它是否在寻找InternalsVisibleTo属性,但如果它确实没有关系,因为这里没有使用它。 相反,它是通过链接文件共享的。

<Compile Include="$(CommonPath)\System\Data\Common\AdapterUtil.cs">
    <Link>System\Data\Common\AdapterUtil.cs</Link>
</Compile>

我假设分析器将不同的ADP类视为单独的类型,而不是共享类型,因为它们本质上是重复的。 因此,虽然删除RemoveStringQuotes对于System.Data.Common是正确的做法,但在考虑与其链接的其他项目时,这是不正确的做法。

除非分析器可以确定所有这些类都来自同一个文件,否则我们将永远认为我们在其中一些文件中有死代码。

除非有人有更好的建议,否则我将开始将这些方法添加回代码中。

@MisinformedDNA我和@danmosemsft离线谈论了这个。 另一种可能的方法是使 ADP 类局部化。 然后您可以将此功能移动到这些库中。

我提交了我的第一个 PR,但其中 2 个构建失败了。 两次构建失败似乎都表明超时。 我应该采取什么措施来解决这个问题?

https://github.com/dotnet/corefx/pull/28795

我会看看 System.Private.Uri

这是我编写的一个应用程序,用于下载所有文件,将它们组合起来,然后过滤掉所有可能误报的文件。 希望它对其他人有所帮助。

@ericstj重新生成数据是否有意义,以便我们更清楚地了解我们在哪里?

从以下命名空间开始:

  • System.Collections.Specialized

    • CompatibleComparer 只有 2 个属性,但文件在 src/common 中,使用范围更广。

  • System.Diagnostics.DiagnosticSource
  • System.Diagnostics.FileVersionInfo
  • System.Diagnostics.Process
  • System.Diagnostics.StackTrace
  • System.Diagnostics.TextWriterTraceListener
  • 系统.诊断.工具
  • System.Diagnostics.TraceSource
  • 系统.诊断.追踪

我已经重新生成了数据。 这是一个新列表,我不想覆盖那里的内容,以防人们发现它相关。

  • [ ] [Microsoft.CSharp](http://tempcoverage.blob.core.windows.net/report4/Microsoft.CSharp.diff.html) ( csv )
  • [ ] [Microsoft.VisualBasic](http://tempcoverage.blob.core.windows.net/report4/Microsoft.VisualBasic.diff.html) ( csv )
  • [ ] [Microsoft.Win32.Primitives](http://tempcoverage.blob.core.windows.net/report4/Microsoft.Win32.Primitives.diff.html) ( csv )
  • [ ] [Microsoft.Win32.Registry](http://tempcoverage.blob.core.windows.net/report4/Microsoft.Win32.Registry.diff.html) ( csv )
  • [ ] [System.Collections.Concurrent](http://tempcoverage.blob.core.windows.net/report4/System.Collections.Concurrent.diff.html) ( csv )
  • [ ] [System.Collections](http://tempcoverage.blob.core.windows.net/report4/System.Collections.diff.html) ( csv )
  • [ ] [System.Collections.Immutable](http://tempcoverage.blob.core.windows.net/report4/System.Collections.Immutable.diff.html) ( csv )
  • [ ] [System.Collections.NonGeneric](http://tempcoverage.blob.core.windows.net/report4/System.Collections.NonGeneric.diff.html) ( csv )
  • [ ] [System.Collections.Specialized](http://tempcoverage.blob.core.windows.net/report4/System.Collections.Specialized.diff.html) ( csv )
  • [ ] [System.ComponentModel.Annotations](http://tempcoverage.blob.core.windows.net/report4/System.ComponentModel.Annotations.diff.html) ( csv )
  • [ ] [System.ComponentModel](http://tempcoverage.blob.core.windows.net/report4/System.ComponentModel.diff.html) ( csv )
  • [ ] [System.ComponentModel.EventBasedAsync](http://tempcoverage.blob.core.windows.net/report4/System.ComponentModel.EventBasedAsync.diff.html) ( csv )
  • [ ] [System.ComponentModel.Primitives](http://tempcoverage.blob.core.windows.net/report4/System.ComponentModel.Primitives.diff.html) ( csv )
  • [ ] [System.ComponentModel.TypeConverter](http://tempcoverage.blob.core.windows.net/report4/System.ComponentModel.TypeConverter.diff.html) ( csv )
  • [ ] [System.Console](http://tempcoverage.blob.core.windows.net/report4/System.Console.diff.html) ( csv )
  • [ ] [System.Data.Common](http://tempcoverage.blob.core.windows.net/report4/System.Data.Common.diff.html) ( csv )
  • [ ] [System.Diagnostics.DiagnosticSource](http://tempcoverage.blob.core.windows.net/report4/System.Diagnostics.DiagnosticSource.diff.html) ( csv )
  • [ ] [System.Diagnostics.FileVersionInfo](http://tempcoverage.blob.core.windows.net/report4/System.Diagnostics.FileVersionInfo.diff.html) ( csv )
  • [ ] [System.Diagnostics.Process](http://tempcoverage.blob.core.windows.net/report4/System.Diagnostics.Process.diff.html) ( csv )
  • [ ] [System.Diagnostics.StackTrace](http://tempcoverage.blob.core.windows.net/report4/System.Diagnostics.StackTrace.diff.html) ( csv )
  • [ ] [System.Diagnostics.TextWriterTraceListener](http://tempcoverage.blob.core.windows.net/report4/System.Diagnostics.TextWriterTraceListener.diff.html) ( csv )
  • [ ] [System.Diagnostics.Tools](http://tempcoverage.blob.core.windows.net/report4/System.Diagnostics.Tools.diff.html) ( csv )
  • [ ] [System.Diagnostics.TraceSource](http://tempcoverage.blob.core.windows.net/report4/System.Diagnostics.TraceSource.diff.html) ( csv )
  • [ ] [System.Diagnostics.Tracing](http://tempcoverage.blob.core.windows.net/report4/System.Diagnostics.Tracing.diff.html) ( csv )
  • [ ] [System.Drawing.Primitives](http://tempcoverage.blob.core.windows.net/report4/System.Drawing.Primitives.diff.html) ( csv )
  • [x] [System.IO.Compression.Brotli](http://tempcoverage.blob.core.windows.net/report4/System.IO.Compression.Brotli.diff.html) ( csv )
  • [ ] [System.IO.Compression](http://tempcoverage.blob.core.windows.net/report4/System.IO.Compression.diff.html) ( csv )
  • [ ] [System.IO.Compression.ZipFile](http://tempcoverage.blob.core.windows.net/report4/System.IO.Compression.ZipFile.diff.html) ( csv )
  • [ ] [System.IO.FileSystem.AccessControl](http://tempcoverage.blob.core.windows.net/report4/System.IO.FileSystem.AccessControl.diff.html) ( csv )
  • [ ] [System.IO.FileSystem](http://tempcoverage.blob.core.windows.net/report4/System.IO.FileSystem.diff.html) ( csv )
  • [x] [System.IO.FileSystem.DriveInfo](http://tempcoverage.blob.core.windows.net/report4/System.IO.FileSystem.DriveInfo.diff.html) ( csv )
  • [ ] [System.IO.FileSystem.Watcher](http://tempcoverage.blob.core.windows.net/report4/System.IO.FileSystem.Watcher.diff.html) ( csv )
  • [ ] [System.IO.IsolatedStorage](http://tempcoverage.blob.core.windows.net/report4/System.IO.IsolatedStorage.diff.html) ( csv )
  • [ ] [System.IO.MemoryMappedFiles](http://tempcoverage.blob.core.windows.net/report4/System.IO.MemoryMappedFiles.diff.html) ( csv )
  • [x] [System.IO.Pipes](http://tempcoverage.blob.core.windows.net/report4/System.IO.Pipes.diff.html) ( csv )
  • [ ] [System.Linq](http://tempcoverage.blob.core.windows.net/report4/System.Linq.diff.html) ( csv )
  • [ ] [System.Linq.Expressions](http://tempcoverage.blob.core.windows.net/report4/System.Linq.Expressions.diff.html) ( csv )
  • [ ] [System.Linq.Parallel](http://tempcoverage.blob.core.windows.net/report4/System.Linq.Parallel.diff.html) ( csv )
  • [ ] [System.Linq.Queryable](http://tempcoverage.blob.core.windows.net/report4/System.Linq.Queryable.diff.html) ( csv )
  • [ ] [System.Memory](http://tempcoverage.blob.core.windows.net/report4/System.Memory.diff.html) ( csv )
  • [ ] [System.Net.Http](http://tempcoverage.blob.core.windows.net/report4/System.Net.Http.diff.html) ( csv )
  • [ ] [System.Net.HttpListener](http://tempcoverage.blob.core.windows.net/report4/System.Net.HttpListener.diff.html) ( csv )
  • [ ] [System.Net.Mail](http://tempcoverage.blob.core.windows.net/report4/System.Net.Mail.diff.html) ( csv )
  • [ ] [System.Net.NameResolution](http://tempcoverage.blob.core.windows.net/report4/System.Net.NameResolution.diff.html) ( csv )
  • [ ] [System.Net.NetworkInformation](http://tempcoverage.blob.core.windows.net/report4/System.Net.NetworkInformation.diff.html) ( csv )
  • [ ] [System.Net.Ping](http://tempcoverage.blob.core.windows.net/report4/System.Net.Ping.diff.html) ( csv )
  • [ ] [System.Net.Primitives](http://tempcoverage.blob.core.windows.net/report4/System.Net.Primitives.diff.html) ( csv )
  • [ ] [System.Net.Requests](http://tempcoverage.blob.core.windows.net/report4/System.Net.Requests.diff.html) ( csv )
  • [ ] [System.Net.Security](http://tempcoverage.blob.core.windows.net/report4/System.Net.Security.diff.html) ( csv )
  • [ ] [System.Net.ServicePoint](http://tempcoverage.blob.core.windows.net/report4/System.Net.ServicePoint.diff.html) ( csv )
  • [ ] [System.Net.Sockets](http://tempcoverage.blob.core.windows.net/report4/System.Net.Sockets.diff.html) ( csv )
  • [ ] [System.Net.WebClient](http://tempcoverage.blob.core.windows.net/report4/System.Net.WebClient.diff.html) ( csv )
  • [ ] [System.Net.WebHeaderCollection](http://tempcoverage.blob.core.windows.net/report4/System.Net.WebHeaderCollection.diff.html) ( csv )
  • [ ] [System.Net.WebProxy](http://tempcoverage.blob.core.windows.net/report4/System.Net.WebProxy.diff.html) ( csv )
  • [ ] [System.Net.WebSockets.Client](http://tempcoverage.blob.core.windows.net/report4/System.Net.WebSockets.Client.diff.html) ( csv )
  • [ ] [System.Net.WebSockets](http://tempcoverage.blob.core.windows.net/report4/System.Net.WebSockets.diff.html) ( csv )
  • [ ] [System.Numerics.Vectors](http://tempcoverage.blob.core.windows.net/report4/System.Numerics.Vectors.diff.html) ( csv )
  • [ ] [System.ObjectModel](http://tempcoverage.blob.core.windows.net/report4/System.ObjectModel.diff.html) ( csv )
  • [ ] [System.Private.DataContractSerialization](http://tempcoverage.blob.core.windows.net/report4/System.Private.DataContractSerialization.diff.html) ( csv )
  • [ ] [System.Private.Uri](http://tempcoverage.blob.core.windows.net/report4/System.Private.Uri.diff.html) ( csv )
  • [ ] [System.Private.Xml](http://tempcoverage.blob.core.windows.net/report4/System.Private.Xml.diff.html) ( csv )
  • [ ] [System.Private.Xml.Linq](http://tempcoverage.blob.core.windows.net/report4/System.Private.Xml.Linq.diff.html) ( csv )
  • [ ] [System.Reflection.DispatchProxy](http://tempcoverage.blob.core.windows.net/report4/System.Reflection.DispatchProxy.diff.html) ( csv )
  • [ ] [System.Reflection.Metadata](http://tempcoverage.blob.core.windows.net/report4/System.Reflection.Metadata.diff.html) ( csv )
  • [ ] [System.Reflection.TypeExtensions](http://tempcoverage.blob.core.windows.net/report4/System.Reflection.TypeExtensions.diff.html) ( csv )
  • [ ] [System.Resources.Writer](http://tempcoverage.blob.core.windows.net/report4/System.Resources.Writer.diff.html) ( csv )
  • [ ] [System.Runtime.CompilerServices.VisualC](http://tempcoverage.blob.core.windows.net/report4/System.Runtime.CompilerServices.VisualC.diff.html) ( csv )
  • [ ] [System.Runtime](http://tempcoverage.blob.core.windows.net/report4/System.Runtime.diff.html) ( csv )
  • [ ] [System.Runtime.Extensions](http://tempcoverage.blob.core.windows.net/report4/System.Runtime.Extensions.diff.html) ( csv )
  • [ ] [System.Runtime.InteropServices](http://tempcoverage.blob.core.windows.net/report4/System.Runtime.InteropServices.diff.html) ( csv )
  • [ ] [System.Runtime.InteropServices.RuntimeInformation](http://tempcoverage.blob.core.windows.net/report4/System.Runtime.InteropServices.RuntimeInformation.diff.html) ( csv )
  • [ ] [System.Runtime.InteropServices.WindowsRuntime](http://tempcoverage.blob.core.windows.net/report4/System.Runtime.InteropServices.WindowsRuntime.diff.html) ( csv )
  • [ ] [System.Runtime.Numerics](http://tempcoverage.blob.core.windows.net/report4/System.Runtime.Numerics.diff.html) ( csv )
  • [ ] [System.Runtime.Serialization.Formatters](http://tempcoverage.blob.core.windows.net/report4/System.Runtime.Serialization.Formatters.diff.html) ( csv )
  • [ ] [System.Runtime.Serialization.Primitives](http://tempcoverage.blob.core.windows.net/report4/System.Runtime.Serialization.Primitives.diff.html) ( csv )
  • [ ] [System.Runtime.WindowsRuntime.UI.Xaml](http://tempcoverage.blob.core.windows.net/report4/System.Runtime.WindowsRuntime.UI.Xaml.diff.html) ( csv )
  • [ ] [System.Security.AccessControl](http://tempcoverage.blob.core.windows.net/report4/System.Security.AccessControl.diff.html) ( csv )
  • [ ] [System.Security.Claims](http://tempcoverage.blob.core.windows.net/report4/System.Security.Claims.diff.html) ( csv )
  • [ ] [System.Security.Cryptography.Algorithms](http://tempcoverage.blob.core.windows.net/report4/System.Security.Cryptography.Algorithms.diff.html) ( csv )
  • [ ] [System.Security.Cryptography.Cng](http://tempcoverage.blob.core.windows.net/report4/System.Security.Cryptography.Cng.diff.html) ( csv )
  • [ ] [System.Security.Cryptography.Csp](http://tempcoverage.blob.core.windows.net/report4/System.Security.Cryptography.Csp.diff.html) ( csv )
  • [ ] [System.Security.Cryptography.Encoding](http://tempcoverage.blob.core.windows.net/report4/System.Security.Cryptography.Encoding.diff.html) ( csv )
  • [ ] [System.Security.Cryptography.OpenSsl](http://tempcoverage.blob.core.windows.net/report4/System.Security.Cryptography.OpenSsl.diff.html) ( csv )
  • [ ] [System.Security.Cryptography.Primitives](http://tempcoverage.blob.core.windows.net/report4/System.Security.Cryptography.Primitives.diff.html) ( csv )
  • [ ] [System.Security.Cryptography.X509Certificates](http://tempcoverage.blob.core.windows.net/report4/System.Security.Cryptography.X509Certificates.diff.html) ( csv )
  • [ ] [System.Security.Principal](http://tempcoverage.blob.core.windows.net/report4/System.Security.Principal.diff.html) ( csv )
  • [ ] [System.Security.Principal.Windows](http://tempcoverage.blob.core.windows.net/report4/System.Security.Principal.Windows.diff.html) ( csv )
  • [ ] [System.Text.RegularExpressions](http://tempcoverage.blob.core.windows.net/report4/System.Text.RegularExpressions.diff.html) ( csv )
  • [ ] [System.Threading](http://tempcoverage.blob.core.windows.net/report4/System.Threading.diff.html) ( csv )
  • [ ] [System.Threading.Overlapped](http://tempcoverage.blob.core.windows.net/report4/System.Threading.Overlapped.diff.html) ( csv )
  • [ ] [System.Threading.Tasks.Dataflow](http://tempcoverage.blob.core.windows.net/report4/System.Threading.Tasks.Dataflow.diff.html) ( csv )
  • [ ] [System.Threading.Tasks.Parallel](http://tempcoverage.blob.core.windows.net/report4/System.Threading.Tasks.Parallel.diff.html) ( csv )
  • [ ] [System.Threading.Thread](http://tempcoverage.blob.core.windows.net/report4/System.Threading.Thread.diff.html) ( csv )
  • [ ] [System.Transactions.Local](http://tempcoverage.blob.core.windows.net/report4/System.Transactions.Local.diff.html) ( csv )
  • [ ] [System.Web.HttpUtility](http://tempcoverage.blob.core.windows.net/report4/System.Web.HttpUtility.diff.html) ( csv )
  • [ ] [System.Xml.XPath.XDocument](http://tempcoverage.blob.core.windows.net/report4/System.Xml.XPath.XDocument.diff.html) ( csv )

谢谢埃里克!

检查了以下内容:

  • System.IO.Compression.Brotli
  • System.IO.Compression.ZipFile
  • System.IO.FileSystem.DriveInfo
  • System.IO.IsolatedStorage
  • System.IO.MemoryMappedFiles
  • System.IO.管道
  • 系统内存

清理死代码:
System.Diagnostics.DiagnosticSource
System.Diagnostics.FileVersionInfo
System.Diagnostics.Process
System.Diagnostics.StackTrace
System.Diagnostics.TextWriterTraceListener
系统.诊断.工具
System.Diagnostics.TraceSource
系统.诊断.追踪
System.Drawing.Primitives

dotnet/corefx#33095

我想将清理 System.IO.Compression 作为我的第一个贡献。

开始帖子System.Console中标记为完成,但在重新生成的数据中未标记。 我发现只需要清除一些SR的字符串。
那么, @ericstj ,这是一种错误,还是我可以看看其他库并修复这些小的死代码?

概括

我创建了一个小工具,可以从这些数据中删除一些无用的东西。


它删除:

  1. 所有标记为红色的 const 。

这是一个很常见的。 任何带有“const”的东西,请忽略。 这些都是编译器内联的字段,我们希望将它们保留在源代码中。 通常是整数和字符串。

  1. 所有未标记为红色的内容(该代码未死)。

它仍然是:

  1. 任何包含死代码的嵌套级别类或结构。 它有助于更​​快地找到该代码。
  2. 所有可以删除的SR的字符串。 但是SR的方法也没有被删除,请注意。

“类 SR”中的任何“静态字符串”都是特殊的。 您必须在 .resx 文件中找到匹配的条目并将其删除,而不是编辑 C# 文件。 库的 .resx 文件位于 srcsrcResourcesstrings.resx。 执行此操作后,构建将重新生成 SR。 忽略“class SR”中的任何其他内容——有几种方法可能会显示为已死。

  1. 只有一个无参数构造函数的类。 它有助于避免对他们做任何事情。

忽略任何私有的无参数构造函数。 我们在代码中包含这些以防止意外实例化类,我们希望将它们保留在代码中。

如果没有其他构造函数,则忽略任何公共无参数构造函数。 这些都不是真的。


还:

您可以在此处找到已清除的文件。 更新数据后提及我,我会更新。

@ericstj删除internal enum是否安全?

使用该工具后,我检查了所有程序集。 其中一些没有任何死代码。
更新后的列表如下所示。 我将链接更改为 htmlpreview 以从工具的存储库中清除文件。 希望没有人会介意。

那么, @ericstj ,这是一种错误,还是我可以看看其他库并修复这些小的死代码?

重新生成差异时,我开始重新清除所有内容。 执行死代码差异的机制过于手动。 它使用内部工具进行装配差异。

@ericstj删除内部枚举是否安全?

这取决于对该内部枚举做了什么。 由于编译器将其源引用转换为整数文字,因此枚举通常会在二进制文件中显示为已死。 您可能会发现源可能仍然需要它。

只是一些关于我们如何使这个死代码清理更好的体验的一些想法,更稳定地向前发展。

  1. 将差异工具添加到打开。 我一直在使用内部的 AsmDiff。 我们可以将其开源或在现有库(SRM、CCI 或 Cecil)之上创建新的东西。
  2. 允许项目选择加入这种无死代码验证并抑制工具遗漏的内容。
  3. 通过将启发式方法放入不同和/或过滤规则中来迭代 2。
  4. 一旦我们在工具中有足够的功能,为整个 repo 启用它,提交我们允许死代码的基线,并且永远不必再次回到这个问题😄

今天,我们用于摇树死代码的机制是在二进制文件上运行的链接器。 因此,为了将其映射回源,我们将其输出与输入进行比较并发出 id。 我过去与链接器人员讨论过的另一件事是发出更多的日志记录,这些日志记录可以更直接地映射回我们的开发人员关心的事情。 它也在 PDB 上运行,因此它在技术上拥有所有源代码和行信息。

@ericstj在技​​术上可以在 corelib 上运行吗? 我注意到 corelib 中有一个死方法,毫无疑问还有更多。 当然,考虑到来自 VM 的所有回调,它需要小心

@danmosemsft作为 coreclr 构建的一部分,它已经在 System.Private.Corelib.dll 上运行。 您注意到没有被删除的死方法是什么?

@ericstj我想我们可以关闭它?

我认为这已经完成了。 非常感谢所有为改进我们的代码库做出贡献的人!

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

bencz picture bencz  ·  3评论

iCodeWebApps picture iCodeWebApps  ·  3评论

matty-hall picture matty-hall  ·  3评论

nalywa picture nalywa  ·  3评论

Timovzl picture Timovzl  ·  3评论