Skip to content

Commit

Permalink
[dotnet-linker] Add a CollectUnmarkedMembersStep that will keep linke…
Browse files Browse the repository at this point in the history
…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
rolfbjarne authored and mandel-macaque committed Oct 21, 2020
1 parent 2d85331 commit 50dd4f9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 0 additions & 2 deletions tests/xharness/Jenkins/TestVariationsFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ IEnumerable<TestData> GetTestData (RunTestTask test)
case "iPhoneSimulator":
switch (test.TestName) {
case "monotouch-test":
if (test.TestProject.IsDotNetProject)
ignore = true;
// The default is to run monotouch-test with the dynamic registrar (in the simulator), so that's already covered
yield return new TestData { Variation = "Debug (LinkSdk)", Debug = true, Profiling = false, LinkMode = "LinkSdk", Ignored = ignore };
yield return new TestData { Variation = "Debug (static registrar)", MTouchExtraArgs = "--registrar:static", Debug = true, Profiling = false, Undefines = "DYNAMIC_REGISTRAR", Ignored = ignore };
Expand Down
3 changes: 3 additions & 0 deletions tools/dotnet-linker/SetupStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ protected override void Process ()
prelink_substeps.Add (new OptimizeGeneratedCodeSubStep ());
prelink_substeps.Add (new MarkNSObjects ());
prelink_substeps.Add (new PreserveSmartEnumConversionsSubStep ());
prelink_substeps.Add (new CollectUnmarkedMembersSubStep ());

post_sweep_substeps.Add (new RemoveAttributesStep ());
}

Steps.Add (new LoadNonSkippedAssembliesStep ());
Expand Down
37 changes: 37 additions & 0 deletions tools/dotnet-linker/Steps/CollectUnmarkedMembers.cs
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 ());
}
}
}
}
}

0 comments on commit 50dd4f9

Please sign in to comment.