Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dotnet-linker] Add a CollectUnmarkedMembersStep that will keep linked away types around for the static registrar. #9722

Merged
merged 2 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions tools/dotnet-linker/SetupStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ 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 ());
}
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 ());
}
}
}
}
}