-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dotnet-linker] Add a CollectUnmarkedMembersStep that will keep linke…
…d away types around for the static registrar. (#9722) The static registrar may need access to types that have been linked away, so store unmarked types so that the static registrar can access them later. This also makes all the monotouch-test variations green, so enable them all. Fixes this monotouch-test when all optimizations are enabled: MonoTouchFixtures.ObjCRuntime.RegistrarTest [FAIL] TestProtocolRegistration : UIApplicationDelegate/17669 Expected: True But was: False at MonoTouchFixtures.ObjCRuntime.RegistrarTest.TestProtocolRegistration() in xamarin-macios/tests/monotouch-test/ObjCRuntime/RegistrarTest.cs:line 1350
- Loading branch information
1 parent
2d85331
commit 50dd4f9
Showing
3 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Collections.Generic; | ||
|
||
using Mono.Cecil; | ||
using Mono.Linker.Steps; | ||
|
||
namespace Xamarin.Linker { | ||
// The static registrar may need access to information that has been linked away, | ||
// in particular types and interfaces, so we need to store those somewhere | ||
// so that the static registrar can access them. | ||
public class CollectUnmarkedMembersSubStep : ConfigurationAwareSubStep { | ||
Dictionary<TypeDefinition, List<TypeDefinition>> ProtocolImplementations => Configuration.DerivedLinkContext.ProtocolImplementations; | ||
|
||
public override SubStepTargets Targets { | ||
get { | ||
return SubStepTargets.Type; | ||
} | ||
} | ||
|
||
public override void ProcessType (TypeDefinition type) | ||
{ | ||
if (!Annotations.IsMarked (type)) | ||
LinkContext.AddLinkedAwayType (type); | ||
|
||
if (type.HasInterfaces) { | ||
foreach (var iface in type.Interfaces) { | ||
if (Annotations.IsMarked (iface)) | ||
continue; | ||
|
||
// This interface might be removed, so save it | ||
if (!ProtocolImplementations.TryGetValue (type, out var list)) | ||
ProtocolImplementations [type] = list = new List<TypeDefinition> (); | ||
list.Add (iface.InterfaceType.Resolve ()); | ||
} | ||
} | ||
} | ||
} | ||
} |