[dotnet-linker] Only override NSObjectProxyAttribute.LookupUnmanagedFunction when the type actually has any UnmanagedCallersOnly methods to look up. - #26364
Conversation
…Function` when the type actually has any `UnmanagedCallersOnly` methods to look up. Only override `NSObjectProxyAttribute.LookupUnmanagedFunction` when the type actually has any `UnmanagedCallersOnly` methods to look up. The method is now virtual instead of abstract, and the base implementation returns `IntPtr.Zero`, which is exactly what the generated override did for types without any such methods. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 6aeeddfd-3bd8-4129-ad90-7292860c4b66
There was a problem hiding this comment.
Pull request overview
This PR reduces the size of trimmable static registrar type map assemblies by only emitting NSObjectProxyAttribute.LookupUnmanagedFunction overrides for proxy types that actually need to resolve any UnmanagedCallersOnly trampolines. It does this by making LookupUnmanagedFunction virtual with a default IntPtr.Zero implementation, and then skipping override emission when there are no entry points to look up.
Changes:
- Make
NSObjectProxyAttribute.LookupUnmanagedFunctionvirtual with a default implementation returningIntPtr.Zero. - Update the trimmable registrar step to only generate
LookupUnmanagedFunctionwhen there are anyUnmanagedCallersOnlyentry points for the proxied type.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tools/dotnet-linker/Steps/TrimmableRegistrarStep.cs | Only emits a LookupUnmanagedFunction override when UnmanagedCallersOnly trampolines exist for the proxy type. |
| src/ObjCRuntime/TypeMaps.cs | Changes LookupUnmanagedFunction from abstract to virtual, with a default IntPtr.Zero implementation to support skipping overrides. |
| @@ -485,30 +485,31 @@ void addPostAction (AssemblyDefinition assembly, Action<AssemblyDefinition> acti | |||
| } | |||
|
|
|||
| var ucos = uco.OrderBy (v => v.UnmanagedCallersOnlyEntryPoint).ToList (); | |||
✅ 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 |
🔥 [CI Build #d76b78b] Test results 🔥Test results❌ Tests failed on VSTS: test results 0 tests crashed, 6 tests failed, 197 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 ❌ monotouch tests (MacCatalyst)1 tests failed, 17 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (macOS)1 tests failed, 18 tests passed.Failed tests
Html Report (VSDrops) Download Successes✅ assembly-processing: 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 |
|
Only override
NSObjectProxyAttribute.LookupUnmanagedFunctionwhen the type actually has anyUnmanagedCallersOnlymethods to look up. The method is now virtual instead of abstract, and the base implementation returnsIntPtr.Zero, which is exactly what the generated override did for types without any such methods.Copilot-Session: 6aeeddfd-3bd8-4129-ad90-7292860c4b66