[dotnet-linker] Gate the TypeMap proxy-attribute workaround to .NET 10 only. Fixes #25276#26018
[dotnet-linker] Gate the TypeMap proxy-attribute workaround to .NET 10 only. Fixes #25276#26018rolfbjarne wants to merge 2 commits into
Conversation
…0 only The workaround for dotnet/runtime#127004 (adding the proxy type's attribute to the source type so ILLink's TypeMapHandler keeps the TypeMapAssociation) is no longer needed once the ILLink fix is available. The fix is only present in .NET 11+, so keep the workaround for .NET 10 and only stop applying it for .NET 11+: * In TrimmableRegistrarStep, only add the proxy attribute to the source type when targeting .NET 10 or earlier. * In TypeMaps (runtime), only read the workaround attribute from the source type for .NET 10 or earlier (gated with !NET11_0_OR_GREATER). Fixes #25276. 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.
…indClass
When looking up the Objective-C class for a managed type, the trimmable
static registrar's FindClass looked up the *closed* generic type (e.g.
UIGestureRecognizer.Callback<UITapGestureRecognizer>) in the type maps.
However, generic types are registered using their generic type definition
(the maps are keyed by the *open* generic type, e.g. Callback`1), so the
lookup failed and the runtime tried to fall back to the dynamic registrar
(which has been linked away), throwing MT8026:
Can't register the class UIKit.UIGestureRecognizer+Callback`1[[UIKit.UITapGestureRecognizer, ...]] when the dynamic registrar has been linked away.
This was previously masked by the workaround for
dotnet/runtime#127004: reading the proxy attribute
directly off the closed generic type (Type.GetCustomAttribute) returns the
attribute stamped on the open generic definition, so the lookup happened to
succeed. Once that workaround was gated off for .NET 11+ (commit
d255353), the missing generic-type-definition reduction was exposed,
causing MT8026 (and, depending on timing, a NullReferenceException in
UIGestureRecognizer.OnDispose during finalization of an uninitialized
UITapGestureRecognizer).
Mirror the reduction already done in the non-trimmable FindClass path
(which does `if (type.IsGenericType) type = type.GetGenericTypeDefinition ()`).
Verified with:
make build run-bare -C tests/monotouch-test/dotnet/MacCatalyst \
TEST_VARIATION='trimmable-static-registrar-all-optimizations-linkall|release' CONFIG=Release \
RUN_ARGUMENTS="--test=MonoTouchFixtures.UIKit.GestureRecognizerTest.GenericCallbackTest"
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 22caaaa0-7267-4c5e-8c22-58e5b04e9f42
✅ 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 #70fb83f] Test results 🔥Test results❌ Tests failed on VSTS: test results 3 tests crashed, 1 tests failed, 174 tests passed. Failures❌ dotnettests tests (macOS)🔥 Failed catastrophically on VSTS: test results - dotnettests_macos (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 (MacCatalyst)1 tests failed, 14 tests passed.Failed tests
Html Report (VSDrops) Download ❌ linker tests (macOS)🔥 Failed catastrophically on VSTS: test results - linker_macos (no summary found). 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 |
The workaround for dotnet/runtime#127004 (adding the
proxy type's attribute to the source type so ILLink's TypeMapHandler keeps the
TypeMapAssociation) is no longer needed once the ILLink fix is available.
The fix is only present in .NET 11+, so keep the workaround for .NET 10 and only
stop applying it for .NET 11+:
TrimmableRegistrarStep, only add the proxy attribute to the source typewhen targeting .NET 10 or earlier.
TypeMaps(runtime), only read the workaround attribute from the sourcetype for .NET 10 or earlier (gated with
!NET11_0_OR_GREATER).A separate validation-only PR targeting
net11.0(not to be merged) confirmsthe TypeMap tests still pass on .NET 11 with the workaround disabled.
Fixes #25276
🤖 Pull request created by Copilot