xamarin-macios/tools/dotnet-linker/Steps
Rolf Bjarne Kvinge ff707c145e
[dotnet-linker] Trim away the static constructor for protocol interfaces if we're registering protocols in the static registrar. (#21012)
When we implemented support for using default interface members for binding protocols, we also unintentionally introduced a size regression. This happened because we now tell the linker to keep all methods in a protocol interface, thus all the corresponding types end up marked as well, etc.

This had an additional side effect: depending on the types that weren't linked away anymore, the App Store could flag an app, saying that additional entitlements is needed. This is what's happening in #21002: the App Store detects that the app references the `application:didRegisterForRemoteNotificationsWithDeviceToken:` selector [1] (from the method `RegisteredForRemoteNotifications` on `IUIApplicationDelegate`) and tells the developer they probably need the push notification entitlement.

The good news is that we don't need these protocol interface methods at runtime if the optimization to register protocols with the static registrar is enabled (which it is by default).

In this PR I teach the optimizer to remove the DynamicDependency attributes keeping these protocol interface methods from being trimmed out.

## Size improvements

* monotouch-test build for Release/ios-arm64 shrinks by [2.9mb (-2.6%)](https://gist.github.com/rolfbjarne/5e8ca6ea6854dc4a46f8e838dff11e6b)
* A very simple app (tests/dotnet/MySimpleApp) shrinks by [176kb (-0.3%)](https://gist.github.com/rolfbjarne/f0e062900528eb499fd96d124d18376f)

[1]: This is somewhat speculative, but it's probably not far from what the App Store actually does.

Fixes #21002.
2024-09-02 15:02:10 +02:00
..
AttributeIteratorBaseStep.cs [dotnet-linker] Enable nullability in numerous files. (#18184) 2023-05-04 07:50:32 +02:00
ClassHandleRewriterStep.cs [dotnet] Test integration (#18543) 2023-10-17 10:29:12 -04:00
CollectAssembliesStep.cs [dotnet-linker] Enable nullability in numerous files. (#18184) 2023-05-04 07:50:32 +02:00
CollectUnmarkedMembers.cs [dotnet-linker] Trim away the static constructor for protocol interfaces if we're registering protocols in the static registrar. (#21012) 2024-09-02 15:02:10 +02:00
ComputeAOTArguments.cs [net8.0] Merge main into net8.0. 2023-05-11 11:54:37 +02:00
ComputeNativeBuildFlagsStep.cs Do not include -dead_strip when native linking a NativeAOT object file (#18553) 2023-07-13 10:57:37 -04:00
ConfigurationAwareMarkHandler.cs [dotnet-linker] Enable nullability in numerous files. (#18184) 2023-05-04 07:50:32 +02:00
ConfigurationAwareStep.cs [dotnet-linker] Don't do anything in ManagedRegistrarStep unless the current registrar mode is 'ManagedStatic'. 2023-05-11 12:21:53 +02:00
ConfigurationAwareSubStep.cs [dotnet-linker] Enable nullability in numerous files. (#18184) 2023-05-04 07:50:32 +02:00
DoneStep.cs [dotnet-linker] Enable nullability in numerous files. (#18184) 2023-05-04 07:50:32 +02:00
DotNetSubStepDispatcher.cs [dotnet-linker] Enable nullability in numerous files. (#18184) 2023-05-04 07:50:32 +02:00
ExceptionalMarkHandler.cs [dotnet-linker] Enable nullability in numerous files. (#18184) 2023-05-04 07:50:32 +02:00
ExtractBindingLibrariesStep.cs [msbuild/dotnet] Automatically link with Swift's system libraries if a binding project has the IsSwift=true property. (#20546) 2024-05-20 20:17:29 +02:00
GatherFrameworksStep.cs [dotnet-linker] Enable nullability in numerous files. (#18184) 2023-05-04 07:50:32 +02:00
GenerateMainStep.cs Clean up globalization custom logic 2023-09-06 18:03:32 +02:00
GenerateReferencesStep.cs [tools] Don't require a LinkWith attributes to find Objective-C classes in assemblies. (#20479) 2024-05-01 08:31:47 +02:00
LoadNonSkippedAssembliesStep.cs Reenable dedup optimization for all AOT modes (#20936) 2024-07-25 19:50:21 -04:00
ManagedRegistrarLookupTablesStep.cs NativeAOT: Mark module constructors in MSR (#19097) 2023-09-27 12:38:01 -04:00
ManagedRegistrarStep.cs [net8.0] Remove workarounds for SDK and runtime bugs (#18830) 2023-09-15 07:43:38 +02:00
MarkDispatcher.cs [dotnet-linker] Enable nullability in numerous files. (#18184) 2023-05-04 07:50:32 +02:00
PostSweepDispatcher.cs [dotnet-linker] Enable nullability in numerous files. (#18184) 2023-05-04 07:50:32 +02:00
PreMarkDispatcher.cs [dotnet-linker] Trim away the static constructor for protocol interfaces if we're registering protocols in the static registrar. (#21012) 2024-09-02 15:02:10 +02:00
PreOutputDispatcher.cs [dotnet-linker] Enable nullability in numerous files. (#18184) 2023-05-04 07:50:32 +02:00
PreserveBlockCodeHandler.cs Change all null checking expressions to use 'is' and 'is not'. (#18176) 2023-05-05 17:52:19 +02:00
RegistrarStep.cs [dotnet] Integrate class handle rewriting into static registrar process. (#18456) 2023-06-23 10:12:35 -04:00
RemoveAttributesStep.cs [dotnet-linker] Enable nullability in numerous files. (#18184) 2023-05-04 07:50:32 +02:00
SetBeforeFieldInitStep.cs [dotnet-linker] Trim away the static constructor for protocol interfaces if we're registering protocols in the static registrar. (#21012) 2024-09-02 15:02:10 +02:00
StoreAttributesStep.cs [registrar] We might link the [Protocol] attribute away, so store it for later reference by the static registrar 2023-05-11 13:10:31 +02:00