Repository navigation
[linker] Convert the Runtime.Arch optimization to a trimmer feature switch. Fixes #26106. - #26111
Conversation
…witch. Fixes #26106. Remove the hand-written IL rewrite `ProcessRuntimeArch` (which inlined `ObjCRuntime.Runtime.Arch` - device vs. simulator) and rely on the trimmer instead. The `ObjCRuntime.Runtime.Arch.IsSimulator` feature switch is already wired up in `Xamarin.Shared.Sdk.targets` and already stubs `GetRuntimeArch()`. Add an ILLink `<field>` substitution for the `Arch` static field (keyed on the same feature) so ILLink folds `ldsfld Runtime::Arch` reads to a constant and removes the dead branches - the same net effect as the old step. Also remove the now-unused `Device` field from `OptimizeGeneratedCodeData`, and mark the `inline-runtime-arch` optimization as removed (mirroring `inline-intptr-size`): keep the option name for back-compat but empty its list of valid platforms and drop the default-enable logic. Remove the corresponding entries from the Versions plists and the optimizations documentation. Fixes #26106. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR migrates the ObjCRuntime.Runtime.Arch constant-folding optimization from a custom IL rewrite (OptimizeGeneratedCode) to an ILLink feature-switch-driven field substitution, so the trimmer can fold Runtime.Arch branches during linking/trimming. It also removes the now-obsolete inline-runtime-arch optimization documentation/metadata and updates size/preserved-API baselines to match the new trimming results.
Changes:
- Replace the
Runtime.Archoptimizer step with ILLink<field>substitutions keyed offObjCRuntime.Runtime.Arch.IsSimulator(iOS/tvOS). - Remove the old
ProcessRuntimeArchimplementation and associated plumbing (Deviceflag). - Clean up optimization docs/metadata and refresh expected app-size + preserved-API outputs affected by the trimming change.
Reviewed changes
Copilot reviewed 29 out of 29 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tools/linker/OptimizeGeneratedCode.cs | Removes the custom IL rewrite for Runtime.Arch loads. |
| tools/linker/CoreOptimizeGeneratedCode.cs | Drops passing the now-removed Device flag into optimizer data. |
| tools/dotnet-linker/OptimizeGeneratedCodeStep.cs | Drops passing the now-removed Device flag into optimizer data. |
| tools/common/Optimizations.cs | Marks inline-runtime-arch as removed (platform applicability + defaults adjusted). |
| src/ILLink.Substitutions.tvOS.xml | Adds Runtime.Arch field substitution keyed on Arch.IsSimulator. |
| src/ILLink.Substitutions.iOS.xml | Adds Runtime.Arch field substitution keyed on Arch.IsSimulator. |
| docs/website/optimizations.md | Removes the “Inline Runtime.Arch” optimization documentation section. |
| builds/Versions-tvOS.plist.in | Removes inline-runtime-arch from the published optimizations list. |
| builds/Versions-macOS.plist.in | Removes inline-runtime-arch from the published optimizations list. |
| builds/Versions-MacCatalyst.plist.in | Removes inline-runtime-arch from the published optimizations list. |
| builds/Versions-iOS.plist.in | Removes inline-runtime-arch from the published optimizations list. |
| tests/dotnet/UnitTests/expected/TVOS-NativeAOT-TrimmableStatic-size.txt | Updates expected app size output for tvOS NativeAOT trimmable-static. |
| tests/dotnet/UnitTests/expected/TVOS-NativeAOT-size.txt | Updates expected app size output for tvOS NativeAOT. |
| tests/dotnet/UnitTests/expected/TVOS-MonoVM-size.txt | Updates expected app size output for tvOS MonoVM. |
| tests/dotnet/UnitTests/expected/TVOS-MonoVM-interpreter-size.txt | Updates expected app size output for tvOS interpreter. |
| tests/dotnet/UnitTests/expected/TVOS-MonoVM-interpreter-preservedapis.txt | Updates expected preserved API list for tvOS interpreter. |
| tests/dotnet/UnitTests/expected/MacOSX-NativeAOT-TrimmableStatic-size.txt | Updates expected app size output for macOS NativeAOT trimmable-static. |
| tests/dotnet/UnitTests/expected/MacOSX-NativeAOT-size.txt | Updates expected app size output for macOS NativeAOT. |
| tests/dotnet/UnitTests/expected/MacOSX-CoreCLR-Interpreter-TrimmableStatic-size.txt | Updates expected app size output for macOS CoreCLR interpreter trimmable-static. |
| tests/dotnet/UnitTests/expected/MacOSX-CoreCLR-Interpreter-size.txt | Updates expected app size output for macOS CoreCLR interpreter. |
| tests/dotnet/UnitTests/expected/MacCatalyst-NativeAOT-TrimmableStatic-size.txt | Updates expected app size output for Mac Catalyst NativeAOT trimmable-static. |
| tests/dotnet/UnitTests/expected/MacCatalyst-NativeAOT-size.txt | Updates expected app size output for Mac Catalyst NativeAOT. |
| tests/dotnet/UnitTests/expected/MacCatalyst-MonoVM-size.txt | Updates expected app size output for Mac Catalyst MonoVM. |
| tests/dotnet/UnitTests/expected/MacCatalyst-MonoVM-interpreter-size.txt | Updates expected app size output for Mac Catalyst interpreter. |
| tests/dotnet/UnitTests/expected/iOS-NativeAOT-TrimmableStatic-size.txt | Updates expected app size output for iOS NativeAOT trimmable-static. |
| tests/dotnet/UnitTests/expected/iOS-NativeAOT-size.txt | Updates expected app size output for iOS NativeAOT. |
| tests/dotnet/UnitTests/expected/iOS-MonoVM-size.txt | Updates expected app size output for iOS MonoVM. |
| tests/dotnet/UnitTests/expected/iOS-MonoVM-interpreter-size.txt | Updates expected app size output for iOS interpreter. |
| tests/dotnet/UnitTests/expected/iOS-MonoVM-interpreter-preservedapis.txt | Updates expected preserved API list for iOS interpreter. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ 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 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.
🚀 [CI Build #86b3dd4] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 203 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. [attempt 2] Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
Convert the
Runtime.Archoptimization from the hand-written IL rewrite inOptimizeGeneratedCode(ProcessRuntimeArch, which inlinedObjCRuntime.Runtime.Arch— device vs. simulator) to an ILLink field substitution, so the trimmer folds the constant branch instead.The
ObjCRuntime.Runtime.Arch.IsSimulatorfeature switch is already wired up inXamarin.Shared.Sdk.targets(viaRuntimeHostConfigurationOption) and already stubsGetRuntimeArch(). The only missing piece was theArchstatic field itself: I added a<field>substitution keyed on the same feature so ILLink foldsldsfld ObjCRuntime.Runtime::Archreads to a constant and removes the dead branches — the same net effect as the old step:(Added to
ILLink.Substitutions.iOS.xmland.tvOS.xml; theArchfield only exists on iOS/tvOS, so macOS/Mac Catalyst don't need it.)Additional cleanup:
ProcessRuntimeArchand the"Arch"case inProcessLoadStaticField, plus the now-unusedDevicefield onOptimizeGeneratedCodeDataand its assignments.inline-runtime-archas removed (mirroringinline-intptr-size): kept the option name for back-compat, emptied its list of valid platforms, and dropped the default-enable logic.inline-runtime-archentries from theVersions-*.plist.infiles and the "Inline Runtime.Arch" section fromdocs/website/optimizations.md.Fixes #26106.
🤖 Pull request created by Copilot