[dotnet-linker] Use [DynamicDependency] attributes instead of manual marking when optimizing generated code.#24979
Conversation
…marking when optimizing generated code. This makes it easier to move this code out of a custom linker step in the future. Also simplify a few things: * There's no need to compute whether the code is optimizable, because the result is never used. * Unify code to determine whether the InlineIsARM64CallingConvention optimization is to be applied. * Any code that modifies the current assembly now returns a boolean saying so (so that we know if the current assembly has to be saved). Contributes towards #17693.
There was a problem hiding this comment.
Pull request overview
This PR migrates the “binding optimizer” from a MarkHandler-based approach toward an AssemblyModifierStep (pre-mark) flow, aligning with the longer-term goal of reducing reliance on custom linker steps and enabling future trimmer/NativeAOT scenarios.
Changes:
- Introduces a new
OptimizeGeneratedCodeStep(assembly modifier) and wires it into the SDK targets behind a DynamicDependency-based switch. - Refactors
OptimizeGeneratedCodeHandlerto use a sharedOptimizeGeneratedCodeDatacontext and to report whether IL was modified. - Extends
AssemblyModifierStepwith aProcessMethodhook + helper to iterate methods, and updates smart-enum preservation to use the helper.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/linker/CoreOptimizeGeneratedCode.cs | Refactors optimizer logic to be data-driven/static and adds modification tracking + shared data carrier. |
| tools/dotnet-linker/Steps/AssemblyModifierStep.cs | Adds method-level processing hook and helper (ProcessMethods) for modifier steps. |
| tools/dotnet-linker/PreserveSmartEnumConversionsStep.cs | Simplifies type processing by reusing ProcessMethods and overrides the new method hook. |
| tools/dotnet-linker/OptimizeGeneratedCodeStep.cs | New pre-mark step that runs the generated code optimizer as an assembly modifier. |
| tools/common/Target.cs | Centralizes the ABI-specific “inline ARM64 calling convention” determination and caches it. |
| dotnet/targets/Xamarin.Shared.Sdk.targets | Adds build properties and conditions to choose between the old MarkHandler and new pre-mark step. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [CI Build #065c042] Build passed (Build packages) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [CI Build #065c042] Build passed (Build macOS tests) ✅Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
🔥 [CI Build #065c042] Test results 🔥Test results❌ Tests failed on VSTS: test results 0 tests crashed, 19 tests failed, 137 tests passed. Failures❌ dotnettests tests (iOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ dotnettests tests (MacCatalyst)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ dotnettests tests (macOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ dotnettests tests (tvOS)1 tests failed, 0 tests passed.Failed tests
Html Report (VSDrops) Download ❌ linker tests4 tests failed, 40 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (iOS)2 tests failed, 9 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (MacCatalyst)3 tests failed, 12 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (macOS)3 tests failed, 9 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (tvOS)2 tests failed, 9 tests passed.Failed tests
Html Report (VSDrops) Download ❌ windows tests1 tests failed, 2 tests passed.Failed tests
Html Report (VSDrops) Download Successes✅ cecil: 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 |
…kcode' into dev/rolf/use-dynamic-dependency-attributes-optimizegeneratedcode
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #b6ae4b2] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ 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 |
This makes it easier to move this code out of a custom linker step in the future.
Also simplify a few things:
is never used.
is to be applied.
that we know if the current assembly has to be saved).
Contributes towards #17693.