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

Fix marking of nested type forwarders #2385

Merged
merged 1 commit into from
Nov 22, 2021
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
14 changes: 13 additions & 1 deletion src/linker/Linker.Steps/MarkStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ protected override void ProcessTypeReference (TypeReference type)
protected override void ProcessExportedType (ExportedType exportedType)
{
markingHelpers.MarkExportedType (exportedType, assembly.MainModule, new DependencyInfo (DependencyKind.ExportedType, assembly));
markingHelpers.MarkForwardedScope (new TypeReference (exportedType.Namespace, exportedType.Name, assembly.MainModule, exportedType.Scope));
markingHelpers.MarkForwardedScope (CreateTypeReferenceForExportedTypeTarget (exportedType));
}

protected override void ProcessExtra ()
Expand All @@ -1456,6 +1456,18 @@ protected override void ProcessExtra ()
markingHelpers.MarkForwardedScope (typeReference);
}
}

TypeReference CreateTypeReferenceForExportedTypeTarget (ExportedType exportedType)
{
TypeReference? declaringTypeReference = null;
if (exportedType.DeclaringType != null) {
declaringTypeReference = CreateTypeReferenceForExportedTypeTarget (exportedType.DeclaringType);
}

return new TypeReference (exportedType.Namespace, exportedType.Name, assembly.MainModule, exportedType.Scope) {
DeclaringType = declaringTypeReference
};
}
}

void ProcessModuleType (AssemblyDefinition assembly)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
.class extern ForwardedNestedType
{
.class extern 'Mono.Linker.Tests.Cases.TypeForwarding.Dependencies.ImplementationLibrary'
.class extern 'Mono.Linker.Tests.Cases.TypeForwarding.Dependencies.AnotherImplementationClass'
}

.module 'NestedForwarderLibrary.dll'
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
.class extern ForwardedNestedType
{
.class extern 'Mono.Linker.Tests.Cases.TypeForwarding.Dependencies.ImplementationLibrary'
.class extern 'Mono.Linker.Tests.Cases.TypeForwarding.Dependencies.AnotherImplementationClass'
}

.module 'NestedForwarderLibrary_2.dll'
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ namespace Mono.Linker.Tests.Cases.TypeForwarding
[SetupLinkerAction ("copyused", "NestedForwarderLibrary")]
[SetupLinkerAction ("copyused", "Implementation")]

// https://github.com/dotnet/linker/issues/2359
// One of the type forwarders in NestedForwarderLibrary will not be kept.
// Which one depends on order.
//[KeptTypeInAssembly ("NestedForwarderLibrary.dll", typeof (ImplementationLibrary.ForwardedNestedType))]
//[KeptTypeInAssembly ("NestedForwarderLibrary.dll", typeof (AnotherImplementationClass.ForwardedNestedType))]
//[KeptTypeInAssembly ("NestedForwarderLibrary_2.dll", typeof (ImplementationLibrary.ForwardedNestedType))]
//[KeptTypeInAssembly ("NestedForwarderLibrary_2.dll", typeof (AnotherImplementationClass.ForwardedNestedType))]
[KeptTypeInAssembly ("NestedForwarderLibrary.dll", typeof (ImplementationLibrary.ForwardedNestedType))]
[KeptTypeInAssembly ("NestedForwarderLibrary.dll", typeof (AnotherImplementationClass.ForwardedNestedType))]
[KeptTypeInAssembly ("NestedForwarderLibrary_2.dll", typeof (ImplementationLibrary.ForwardedNestedType))]
[KeptTypeInAssembly ("NestedForwarderLibrary_2.dll", typeof (AnotherImplementationClass.ForwardedNestedType))]
[KeptTypeInAssembly ("Implementation.dll", typeof (ImplementationLibrary.ForwardedNestedType))]
[KeptTypeInAssembly ("Implementation.dll", typeof (AnotherImplementationClass.ForwardedNestedType))]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ namespace Mono.Linker.Tests.Cases.TypeForwarding
[SetupLinkerAction ("link", "NestedForwarderLibrary")]
[SetupLinkerAction ("link", "Implementation")]

// https://github.com/dotnet/linker/issues/2359
// One of the type forwarders in NestedForwarderLibrary will not be kept.
// Which one depends on order.
//[KeptTypeInAssembly ("NestedForwarderLibrary.dll", typeof (ImplementationLibrary.ForwardedNestedType))]
//[KeptTypeInAssembly ("NestedForwarderLibrary.dll", typeof (AnotherImplementationClass.ForwardedNestedType))]
//[KeptTypeInAssembly ("NestedForwarderLibrary_2.dll", typeof (ImplementationLibrary.ForwardedNestedType))]
//[KeptTypeInAssembly ("NestedForwarderLibrary_2.dll", typeof (AnotherImplementationClass.ForwardedNestedType))]
[KeptTypeInAssembly ("NestedForwarderLibrary.dll", typeof (ImplementationLibrary.ForwardedNestedType))]
[KeptTypeInAssembly ("NestedForwarderLibrary.dll", typeof (AnotherImplementationClass.ForwardedNestedType))]
[KeptTypeInAssembly ("NestedForwarderLibrary_2.dll", typeof (ImplementationLibrary.ForwardedNestedType))]
[KeptTypeInAssembly ("NestedForwarderLibrary_2.dll", typeof (AnotherImplementationClass.ForwardedNestedType))]
[KeptTypeInAssembly ("Implementation.dll", typeof (ImplementationLibrary.ForwardedNestedType))]
[KeptTypeInAssembly ("Implementation.dll", typeof (AnotherImplementationClass.ForwardedNestedType))]

Expand Down