Repository navigation
[dotnet-linker] Don't unconditionally preserve smart enum conversions in trimmed assemblies. - #26486
Conversation
β¦ in trimmed assemblies. `PreserveSmartEnumConversionsStep` has two ways of preserving the smart enum conversion methods: * Inject a `[DynamicDependency]` attribute on the method that references the smart enum. This is conditional: the conversion methods only survive if the referencing method survives. * Emit an ILLink root descriptor file. This preserves the conversion methods unconditionally, and is required when we can't modify the assembly (hot reload). Which one to use was decided by the global `HotReloadCompatibleBuild` option, which defaults to true for all debug builds. That meant that every smart enum referenced anywhere in the platform assembly was preserved unconditionally, which in turn kept a lot of code alive that should have been trimmed away (15+ extra namespaces surviving in the platform assembly, which made us link with the corresponding frameworks). Assemblies with `AssemblyAction.Link` are being trimmed, so they're not hot reloadable and can safely be modified - this is the same condition we already use in `RemoveUserResourcesSubStep`, `ListExportedSymbols` and `InlineDlfcnMethodsStep`. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ef04d7c1-e5e3-4244-ac92-f7341ddac90e
There was a problem hiding this comment.
Pull request overview
Adjusts PreserveSmartEnumConversionsStep so smart-enum conversion methods are only preserved unconditionally (via an ILLink root-descriptor XML) when the referencing assembly canβt be modified due to Hot Reload constraints, instead of using a global Hot Reload setting that caused over-preservation in trimmed platform assemblies.
Changes:
- Make the XML-descriptor decision depend on the referencing assemblyβs
AssemblyAction(avoid XML preservation forAssemblyAction.Linkassemblies). - Move the XML-preservation decision into the per-condition loop so mixed scenarios (some assemblies modifiable, some not) are handled correctly.
- Emit the XML descriptor only when it has collected entries (no longer gated by a global flag at end-of-step).
π‘ Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
β¦embly behavior. The Hot Reload code path in `PreserveSmartEnumConversionsStep` now only kicks in for assemblies that aren't trimmed, so update `HotReloadCompatibleBuildTest` to build the test assembly as a non-trimmed (copy) assembly. Also add `HotReloadCompatibleBuildTrimmedAssemblyTest`, which verifies that [DynamicDependency] attributes are injected into trimmed assemblies even when $(HotReloadCompatibleBuild) is enabled. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Linked assemblies use conditional smart enum dependencies even in hot-reload-compatible prepare builds, so unused platform smart enums should not survive linking. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
β API diff for current PR / commitNET (empty diffs)β API diff vs stableNET (empty diffs)βΉοΈ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
π [CI Build #83e09a4] Test results πTest resultsβ All tests passed on VSTS: test results. π All 205 tests passed π Tests countsβ
assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS testsβ
Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
|
@dalexsoto stamp |
PreserveSmartEnumConversionsStephas two ways of preserving the smart enum conversion methods:[DynamicDependency]attribute on the method that references the smart enum. This is conditional: the conversion methods only survive if the referencing method survives.Which one to use was decided by the global
HotReloadCompatibleBuildoption, which defaults to true for all debug builds. That meant that every smart enum referenced anywhere in the platform assembly was preserved unconditionally, which in turn kept a lot of code alive that should have been trimmed away (15+ extra namespaces surviving in the platform assembly, which made us link with the corresponding frameworks).Assemblies with
AssemblyAction.Linkare being trimmed, so they're not hot reloadable and can safely be modified - this is the same condition we already use inRemoveUserResourcesSubStep,ListExportedSymbolsandInlineDlfcnMethodsStep.Verified by inspecting a Full-linked
Microsoft.iOS.dll: the number of surviving namespaces went from 19 down to 6.π€ Pull request created by Copilot