Visitar URL original
[registrar] Specialize inherited generic exports. Fixes #14899 by rolfbjarne · Pull Request #27302 · dotnet/macios · GitHub
Skip to content

[registrar] Specialize inherited generic exports. Fixes #14899 - #27302

Draft
rolfbjarne wants to merge 4 commits into
mainfrom
dev/rolf/closed-generic-trampolines
Draft

rolfbjarne wants to merge 4 commits into
mainfrom
dev/rolf/closed-generic-trampolines

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Add the specialize-generic-registrations optimization for non-generic NSObject subclasses that inherit exported methods from generic base classes. It adds forwarding methods to these subclasses so the static registrar can generate dedicated native entry points. Objective-C calls then no longer look up the generic method each time.

The optimization preserves virtual dispatch and marshalling attributes. It is off by default because it adds code, but --optimize=all enables it. Reloadable assemblies in Hot Reload-compatible builds are left unchanged.

Add tests for assembly preparation, trimming, and Objective-C dispatch. A monotouch performance test compares calls to inherited generic exports with a non-generic baseline, with and without all optimizations enabled.

Fixes #14899

🤖 Pull request created by Copilot

rolfbjarne and others added 4 commits November 11, 2026 10:39
Add the opt-in specialize-generic-registrations optimization. Emit closed forwarding methods before registration and trimming so all static registrars can use their existing non-generic callback paths instead of resolving an inherited generic export on each native invocation.

Preserve virtual dispatch, closed parameter and return types, and effective property/protocol marshalling attributes. Use shared generic helpers for inaccessible exports, and leave reloadable assemblies unchanged. Wire both assembly preparation and direct ILLink processing, document the code-size tradeoff, and cover the generated metadata and callbacks with regression tests.

Fixes #14899

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Build and run a trimmed macOS app with generic registration specialization enabled, both with assembly preparation and with direct ILLink processing. Confirm that closed forwarding methods survive trimming and that native calls preserve virtual hash overrides, closed generic parameter/return conversion, and private exported methods.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Check that all optimizations bring inherited generic exports within 20% of a non-generic baseline, while ordinary native static registration remains slower. Use warmed-up, alternating samples and their median to limit timing noise. Skip optimized-mode checks for reloadable assemblies.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Read pre-trim attributes from the prepared assemblies so postprocessing can recover generated exports. Reuse the registrar and register new forwarders directly to avoid duplicate diagnostics, then filter trimmed APIs before rewriting native class handles.

Let deeper subclasses inherit specialized entry points instead of generating them again. Strengthen the existing dispatch tests to cover stripped attributes, native static registration and virtual calls through inherited forwarders, and lengthen performance samples.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@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: 05766da7bb116b1e0c65038e0a3b8ee465863c7e [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #05766da] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 217 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 1 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
✅ linker (iOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 21 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 21 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 20 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: 05766da7bb116b1e0c65038e0a3b8ee465863c7e [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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emit specialized native method for methods in a closed subclass over a generic type

2 participants