From 603781b63f21527b9bf5e61495a45ed44883bb7a Mon Sep 17 00:00:00 2001 From: Milos Kotlar Date: Fri, 7 Jun 2024 13:21:41 +0200 Subject: [PATCH] Enable dedup optimization in FullAOT mode only (#20687) ## Description This PR enables the dedup optimization in FullAOT mode only. The optimization can only run in FullAOT mode with complete application context. Without it, the AOT compiler may fail to collect all generic instances, and the runtime can't find them as they are searched in the dedup assembly. ## Changes This PR updates the SDK targets to enable dedup optimization in FullAOT mode only. This change doesn't depend on any runtime changes. ## Verification This PR also introduces partial AOT tests. They inspect the bundle for `aot-instances.dll`, which shouldn't be generated in a partial AOT compilation setup. Additionally, basic functionality is tested by asserting at app startup. ## Additional notes This change should be backported to .NET 8 as well. Fixes https://github.com/dotnet/runtime/issues/99248 --- dotnet/targets/Xamarin.Shared.Sdk.targets | 7 ++-- tests/dotnet/UnitTests/ProjectTest.cs | 40 +++++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index eb60a1bf595..3747342219a 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -1096,8 +1096,9 @@ <_AOTInputDirectory>$(_IntermediateNativeLibraryDir)aot-input/ <_AOTOutputDirectory>$(_IntermediateNativeLibraryDir)aot-output/ - <_IsDedupEnabled Condition="'$(_IsDedupEnabled)' == ''">true - <_DedupAssembly Condition="'$(_RunAotCompiler)' == 'true' And '$(IsMacEnabled)' == 'true' And '$(_IsDedupEnabled)' == 'true'">$(IntermediateOutputPath)aot-instances.dll + + <_IsDedupEnabled Condition="'$(_IsDedupEnabled)' == '' And '$(_RunAotCompiler)' == 'true' And '$(MtouchInterpreter)' == '' And '$(IsMacEnabled)' == 'true'">true + <_DedupAssembly Condition="'$(_IsDedupEnabled)' == 'true'">$(IntermediateOutputPath)aot-instances.dll <_LibMonoLinkMode Condition="'$(_LibMonoLinkMode)' == '' And '$(_PlatformName)' == 'MacCatalyst'">static @@ -1219,7 +1220,7 @@