Skip to content

[release/11.0.1xx] [dotnet-linker] Preserve explicit interface implementations with ldtoken helpers. - #27480

Open
rolfbjarne wants to merge 2 commits into
release/11.0.1xxfrom
dev/rolf/backport-27352-to-11-0
Open

rolfbjarne wants to merge 2 commits into
release/11.0.1xxfrom
dev/rolf/backport-27352-to-11-0

Conversation

@rolfbjarne

@rolfbjarne rolfbjarne commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 14c03ce4af83894725e4de21ea06db79783f107c

Dimension Assessment Rationale
Change confidence 8/10 ↑ Release build and forwarder tests passed; the legacy case detects reverting the CopyUsed-to-Save change.
↓ The test did not isolate the effect of explicit forwarder marking; link-all wasn't run locally.
Diagnosis confidence 9/10 ↑ The source issue describes how generic interface documentation IDs fail to resolve in ILLink and ILC.
Evidence fit 8/10 ↑ The source issue connects the parsing failure to Preserve on a generic interface implementation.
↓ The reported Realm scenario was not reproduced locally.

Some explicit interface implementations cannot be preserved reliably through their documentation signatures when the interface type is generic. This change emits private helpers with ldtoken references instead, including constraint-matched generic helpers so NativeAOT retains generic method instantiations.

The helpers are rooted with DynamicDependency, explicit properties and events are preserved through their accessors, generated names avoid user members, and declaring assemblies are saved when helpers are added to referenced assemblies.

Adds assembly-preparer and end-to-end coverage for generic methods, overloads, constraints, individual [Preserve], accessors, helper-name collisions, and cross-assembly targets.

Fixes dotnet/runtime#137350.

Backport notes: tools/dotnet-linker/AppBundleRewriter.cs conflicted in SaveAssembly. This branch still has the code that marks type forwarders before an assembly's action is changed to Save; main removed it in #26777, which isn't backported. This backport keeps that code and applies the source change to its condition (Copy → Copy or CopyUsed) so CopyUsed assemblies that are saved also keep their type forwarders. The forwarder test also covers the legacy linker with and without a rewrite.

Backport of #27352.

🤖 Pull request created by Copilot

…ken helpers. (#27352)

Some explicit interface implementations cannot be preserved reliably through their documentation signatures when the interface type is generic. This change emits private helpers with ldtoken references instead, including constraint-matched generic helpers so NativeAOT retains generic method instantiations.

The helpers are rooted with DynamicDependency, explicit properties and events are preserved through their accessors, generated names avoid user members, and declaring assemblies are saved when helpers are added to referenced assemblies.

Adds assembly-preparer and end-to-end coverage for generic methods, overloads, constraints, individual [Preserve], accessors, helper-name collisions, and cross-assembly targets.

Fixes dotnet/runtime#137350.

🤖 Pull request created by Copilot

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Rolf Bjarne Kvinge <rokvin@microsoft.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 18:06
@rolfbjarne rolfbjarne added backported copilot ready-to-review This PR is ready to review/merge. labels Nov 26, 2026
dalexsoto
dalexsoto previously approved these changes Nov 26, 2026

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.

🟡 Changes recommended

The new test bypasses the legacy linker’s backport-specific forwarder-marking branch, leaving rewritten CopyUsed assemblies’ forwarder preservation unverified; add coverage with PrepareAssemblies=false.

1 open issue
What changed in this PR

Backports explicit-interface preservation fixes to .NET 11’s Apple tooling, replacing unreliable generic-interface documentation signatures with ldtoken helpers.

Changes:

  • Adds dependency-rooted helpers with matching generic constraints and accessor preservation.
  • Handles referenced-assembly saves, CopyUsed type roots, and legacy type-forwarder preservation.
  • Adds preparation and end-to-end tests for generic implementations, helper-name collisions, and assembly retention.
File Description
tools/​dotnet-linker/​ApplyPreserveAttributeStep.cs Uses helper signatures and roots types in untrimmed assemblies.
tools/​dotnet-linker/​AppBundleRewriter.cs Generates preservation helpers and updates assembly-save handling.
tests/​linker/​link all/​ExplicitInterfaceTest.cs Adds reflection-based tests for preserved explicit implementations.
tests/​dotnet/​UnitTests/​PrepareAssembliesTest.cs Tests CopyUsed retention and type-forwarder behavior.
tests/​assembly-preparer/​ApplyPreserveAttributeTests.cs Checks helper generation, constraints, collisions, and cross-assembly saves.

Review effort: Balanced

@MauiBot

MauiBot commented Nov 26, 2026

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: d384fcb90284a9c4308312be624089f62b68658f [PR build]

@MauiBot

MauiBot commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #d384fcb] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 269 tests passed 🎉

Tests counts

✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download
✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): 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
✅ framework: All 2 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 7 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 31 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 31 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 31 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 25 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 25 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 25 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

✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Golden Gate (27): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

✅ Linux build succeeded

Pipeline on Agent
Hash: d384fcb90284a9c4308312be624089f62b68658f [PR build]

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 26, 2026 21:45

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.

🔵 Needs a closer look

New null-forgiving operators violate the review rules and need explicit null checks and consistent nullability modeling while preserving the auto-property required by the accessor test.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Low severity Replace null-forgiving operators with explicit null handling

tests/​linker/​link all/​ExplicitInterfaceTest.cs:65

🤖 💡 Nullable — The new null-forgiving operators conflict with .github/skills/code-review/references/review-rules.md:84. Use explicit null checks for constructed values, reflection results, and paths; for the initially unset generic property, model nullability consistently while retaining the auto-property needed by the accessor-preservation test. The same issue occurs in this file at lines 86, 167, 172–174 and in tests/assembly-preparer/ApplyPreserveAttributeTests.cs:259.

[!NOTE]
AI-generated by GitHub Copilot.

1 resolved since last review

Review effort: Balanced

@MauiBot

MauiBot commented Nov 26, 2026

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: 14c03ce4af83894725e4de21ea06db79783f107c [PR build]

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backported copilot ready-to-review This PR is ready to review/merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants