Skip to content

[tools] Convert IsARM64CallingConvention optimization to a trimmer feature switch Fixes #26105#26141

Draft
rolfbjarne wants to merge 2 commits into
mainfrom
dev/rolf/issue-26105-convert-isarm64callingconvention-optimiz-46c258
Draft

[tools] Convert IsARM64CallingConvention optimization to a trimmer feature switch Fixes #26105#26141
rolfbjarne wants to merge 2 commits into
mainfrom
dev/rolf/issue-26105-convert-isarm64callingconvention-optimiz-46c258

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Replace the hand-written IL rewrite that inlined ObjCRuntime.Runtime.IsARM64CallingConvention with an ILLink trimmer feature switch (ObjCRuntime.Runtime.IsARM64CallingConvention), mirroring the DynamicRegistrationSupported / IsManagedStaticRegistrar approach.

  • Keep ObjCRuntime.Runtime.IsARM64CallingConvention as a public field (changing it to a property would be a binary breaking change); Runtime.cs is unchanged.
  • Substitute the field's value (and stub the GetIsARM64CallingConvention helper) via the 'ObjCRuntime.Runtime.IsARM64CallingConvention' feature switch, so the trimmer inlines reads of the field into constants and removes the native architecture detection - exactly replicating the previous hand-written IL optimization. The expected preservedapis files are therefore unchanged.
  • Add the substitution entries to the four ILLink.Substitutions.*.xml files.
  • Xamarin.Shared.Sdk.targets: set the feature switch based on whether the RuntimeIdentifier ends with "-arm64".
  • Remove the old optimizer plumbing (OptimizeGeneratedCode.cs, Target.cs, CoreOptimizeGeneratedCode.cs, OptimizeGeneratedCodeStep.cs) and disable the inline-is-arm64-calling-convention optimization flag (kept for compatibility), mirroring inline-intptr-size.
  • Keep the IL-checking in the linker test (it verifies the trimmer actually inlines the field value); the only change is that reads are now inlined regardless of [BindingImpl (BindingImplOptions.Optimizable)], since the trimmer (not the old custom optimizer) does the inlining.
  • Update the docs.

Fixes #26105

🤖 Pull request created by Copilot

…ature switch

Replace the hand-written IL rewrite that inlined
ObjCRuntime.Runtime.IsARM64CallingConvention with an ILLink trimmer feature
switch (ObjCRuntime.Runtime.IsARM64CallingConvention), mirroring the
DynamicRegistrationSupported / IsManagedStaticRegistrar approach.

- Keep ObjCRuntime.Runtime.IsARM64CallingConvention as a public field (changing
  it to a property would be a binary breaking change); Runtime.cs is unchanged.
- Substitute the field's value (and stub the GetIsARM64CallingConvention helper)
  via the 'ObjCRuntime.Runtime.IsARM64CallingConvention' feature switch, so the
  trimmer inlines reads of the field into constants and removes the native
  architecture detection - exactly replicating the previous hand-written IL
  optimization. The expected preservedapis files are therefore unchanged.
- Add the substitution entries to the four ILLink.Substitutions.*.xml files.
- Xamarin.Shared.Sdk.targets: set the feature switch based on whether the
  RuntimeIdentifier ends with "-arm64".
- Remove the old optimizer plumbing (OptimizeGeneratedCode.cs, Target.cs,
  CoreOptimizeGeneratedCode.cs, OptimizeGeneratedCodeStep.cs) and disable the
  inline-is-arm64-calling-convention optimization flag (kept for compatibility),
  mirroring inline-intptr-size.
- Keep the IL-checking in the linker test (it verifies the trimmer actually
  inlines the field value); the only change is that reads are now inlined
  regardless of [BindingImpl (BindingImplOptions.Optimizable)], since the
  trimmer (not the old custom optimizer) does the inlining.
- Update the docs.

Fixes #26105

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the ObjCRuntime.Runtime.IsARM64CallingConvention inlining optimization from the custom OptimizeGeneratedCode IL rewrite to an ILLink trimmer feature switch, aligning it with existing feature-switch based optimizations (e.g., dynamic registration support). This reduces custom linker plumbing while still ensuring the field read is folded into a constant for architecture-specific builds.

Changes:

  • Removed the custom linker optimizer logic that rewrote Runtime.IsARM64CallingConvention and GetIsARM64CallingConvention into constants.
  • Added ILLink substitutions for Runtime.IsARM64CallingConvention (field) and Runtime.GetIsARM64CallingConvention (method) gated on the ObjCRuntime.Runtime.IsARM64CallingConvention feature switch.
  • Set the new feature switch from MSBuild based on whether $(RuntimeIdentifier) ends with -arm64, and updated linker tests + documentation accordingly.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tools/linker/OptimizeGeneratedCode.cs Removes the old custom IL rewrite for IsARM64CallingConvention.
tools/linker/CoreOptimizeGeneratedCode.cs Stops passing the old per-ABI inlining value into the optimizer.
tools/dotnet-linker/OptimizeGeneratedCodeStep.cs Stops passing the old per-ABI inlining value into the optimizer.
tools/common/Target.cs Removes the ABI-based computation for the old inlining optimization.
tools/common/Optimizations.cs Keeps the optimization flag for compatibility, but disables platform applicability and removes “enabled by default” behavior.
tests/linker/BaseOptimizeGeneratedCodeTest.cs Updates the test expectations: field reads should now be constant-folded regardless of [BindingImpl(Optimizable)].
src/ILLink.Substitutions.iOS.xml Adds field + method substitutions driven by the new feature switch.
src/ILLink.Substitutions.tvOS.xml Adds field + method substitutions driven by the new feature switch.
src/ILLink.Substitutions.macOS.xml Adds field + method substitutions driven by the new feature switch.
src/ILLink.Substitutions.MacCatalyst.xml Adds field + method substitutions driven by the new feature switch.
dotnet/targets/Xamarin.Shared.Sdk.targets Introduces MSBuild logic to set ObjCRuntime.Runtime.IsARM64CallingConvention based on the RID architecture.
docs/website/optimizations.md Documents the switch-based approach and updates the legacy --optimize option behavior.

Comment thread dotnet/targets/Xamarin.Shared.Sdk.targets
Comment thread docs/website/optimizations.md Outdated
@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 81a8fc660082a2948ac9b38829fcd1f5732f8189 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🔥 [CI Build #81a8fc6] Test results 🔥

Test results

❌ Tests failed on VSTS: test results

3 tests crashed, 18 tests failed, 181 tests passed.

Failures

❌ dotnettests tests (iOS)

🔥 Failed catastrophically on VSTS: test results - dotnettests_ios (no summary found).

Html Report (VSDrops) Download

❌ dotnettests tests (MacCatalyst)

🔥 Failed catastrophically on VSTS: test results - dotnettests_maccatalyst (no summary found).

Html Report (VSDrops) Download

❌ framework tests

🔥 Failed catastrophically on VSTS: test results - framework (no summary found).

Html Report (VSDrops) Download

❌ linker tests (iOS)

3 tests failed, 12 tests passed.

Failed tests

  • link all/iOS - simulator/Debug: Failed
  • link all/iOS - simulator/Debug (don't bundle original resources): Failed
  • trimmode link/iOS - simulator/Debug: Failed

Html Report (VSDrops) Download

❌ linker tests (MacCatalyst)

3 tests failed, 12 tests passed.

Failed tests

  • link all/Mac Catalyst/Debug: Failed (Test run failed.
    Tests run: 95 Passed: 84 Inconclusive: 0 Failed: 1 Ignored: 10)
  • link all/Mac Catalyst/Debug (don't bundle original resources): Failed (Test run failed.
    Tests run: 95 Passed: 84 Inconclusive: 0 Failed: 1 Ignored: 10)
  • trimmode link/Mac Catalyst/Debug: Failed (Test run failed.
    Tests run: 132 Passed: 128 Inconclusive: 0 Failed: 1 Ignored: 3)

Html Report (VSDrops) Download

❌ linker tests (macOS)

4 tests failed, 17 tests passed.

Failed tests

  • link all/macOS/Debug: Failed (Test run failed.
    Tests run: 92 Passed: 81 Inconclusive: 0 Failed: 1 Ignored: 10)
  • link all/macOS/Debug (PrepareAssemblies, CoreCLR, Trimmable Static Registrar): Failed (Test run failed.
    Tests run: 92 Passed: 81 Inconclusive: 0 Failed: 1 Ignored: 10)
  • link all/macOS/Debug (don't bundle original resources): Failed (Test run failed.
    Tests run: 92 Passed: 81 Inconclusive: 0 Failed: 1 Ignored: 10)
  • trimmode link/macOS/Debug: Failed (Test run failed.
    Tests run: 119 Passed: 116 Inconclusive: 0 Failed: 1 Ignored: 2)

Html Report (VSDrops) Download

❌ linker tests (tvOS)

3 tests failed, 12 tests passed.

Failed tests

  • link all/tvOS - simulator/Debug: Failed
  • link all/tvOS - simulator/Debug (don't bundle original resources): Failed
  • trimmode link/tvOS - simulator/Debug: Failed

Html Report (VSDrops) Download

❌ Tests on macOS Monterey (12) tests

1 tests failed, 4 tests passed.

Failed tests

  • macOS/osx-x64 linkall: Failed (exit code 1)
    • [FAIL] IsARM64CallingConvention : optimizable: no ldsfld instruction
  • macOS/osx-arm64 linkall: Failed (exit code 1)
    • [FAIL] IsARM64CallingConvention : optimizable: no ldsfld instruction
  • MacCatalyst/maccatalyst-x64 linkall: Failed (exit code 1)
    • [FAIL] IsARM64CallingConvention : optimizable: no ldsfld instruction
  • MacCatalyst/maccatalyst-arm64 linkall: Failed (exit code 1)
    • [FAIL] IsARM64CallingConvention : optimizable: no ldsfld instruction

Html Report (VSDrops) Download

❌ Tests on macOS Ventura (13) tests

1 tests failed, 4 tests passed.

Failed tests

  • macOS/osx-x64 linkall: Failed (exit code 1)
    • [FAIL] IsARM64CallingConvention : optimizable: no ldsfld instruction
  • macOS/osx-arm64 linkall: Failed (exit code 1)
    • [FAIL] IsARM64CallingConvention : optimizable: no ldsfld instruction
  • MacCatalyst/maccatalyst-x64 linkall: Failed (exit code 1)
    • [FAIL] IsARM64CallingConvention : optimizable: no ldsfld instruction
  • MacCatalyst/maccatalyst-arm64 linkall: Failed (exit code 1)
    • [FAIL] IsARM64CallingConvention : optimizable: no ldsfld instruction

Html Report (VSDrops) Download

❌ Tests on macOS Sonoma (14) tests

1 tests failed, 4 tests passed.

Failed tests

  • macOS/osx-x64 linkall: Failed (exit code 1)
    • [FAIL] IsARM64CallingConvention : optimizable: no ldsfld instruction
  • MacCatalyst/maccatalyst-x64 linkall: Failed (exit code 1)
    • [FAIL] IsARM64CallingConvention : optimizable: no ldsfld instruction

Html Report (VSDrops) Download

❌ Tests on macOS Sequoia (15) tests

1 tests failed, 4 tests passed.

Failed tests

  • macOS/osx-x64 linkall: Failed (exit code 1)
    • [FAIL] IsARM64CallingConvention : optimizable: no ldsfld instruction
  • macOS/osx-arm64 linkall: Failed (exit code 1)
    • [FAIL] IsARM64CallingConvention : optimizable: no ldsfld instruction
  • MacCatalyst/maccatalyst-x64 linkall: Failed (exit code 1)
    • [FAIL] IsARM64CallingConvention : optimizable: no ldsfld instruction
  • MacCatalyst/maccatalyst-arm64 linkall: Failed (exit code 1)
    • [FAIL] IsARM64CallingConvention : optimizable: no ldsfld instruction

Html Report (VSDrops) Download

❌ Tests on macOS Tahoe (26) tests

1 tests failed, 4 tests passed.

Failed tests

  • macOS/osx-x64 linkall: Failed (exit code 1)
    • [FAIL] IsARM64CallingConvention : optimizable: no ldsfld instruction
  • macOS/osx-arm64 linkall: Failed (exit code 1)
    • [FAIL] IsARM64CallingConvention : optimizable: no ldsfld instruction
  • MacCatalyst/maccatalyst-x64 linkall: Failed (exit code 1)
    • [FAIL] IsARM64CallingConvention : optimizable: no ldsfld instruction
  • MacCatalyst/maccatalyst-arm64 linkall: Failed (exit code 1)
    • [FAIL] IsARM64CallingConvention : optimizable: no ldsfld instruction

Html Report (VSDrops) Download

Successes

✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 4 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 19 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 19 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 19 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: 81a8fc660082a2948ac9b38829fcd1f5732f8189 [PR build]

…operty

Addresses a PR review comment: IsARM64CallingConvention is a public field,
not a property.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Convert IsARM64CallingConvention optimization to a trimmer feature switch

3 participants