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

[NativeAOT] Fix transforming [Preserve] into [DynamicDependency] for generic types and generic methods #18854

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions tools/dotnet-linker/AppBundleRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,19 @@ public FieldReference GetFieldReference (AssemblyDefinition assembly, TypeRefere
}
}

public MethodReference DynamicDependencyAttribute_ctor__String_String_String {
get {
return GetMethodReference (CorlibAssembly,
System_Diagnostics_CodeAnalysis_DynamicDependencyAttribute,
".ctor",
".ctor(String,String,String)",
isStatic: false,
System_String,
System_String,
System_String);
}
}

public MethodReference RuntimeTypeHandle_Equals {
get {
if (configuration.Application.XamarinRuntime == XamarinRuntime.MonoVM) {
Expand Down Expand Up @@ -1246,12 +1259,27 @@ public void ClearCurrentAssembly ()

public CustomAttribute CreateDynamicDependencyAttribute (string memberSignature, TypeDefinition type)
{
if (type.HasGenericParameters) {
var typeName = Xamarin.Utils.DocumentationComments.GetSignature (type);
var assemblyName = type.Module.Assembly.Name.Name;
return CreateDynamicDependencyAttribute (memberSignature, typeName, assemblyName);
}

var attribute = new CustomAttribute (DynamicDependencyAttribute_ctor__String_Type);
attribute.ConstructorArguments.Add (new CustomAttributeArgument (System_String, memberSignature));
attribute.ConstructorArguments.Add (new CustomAttributeArgument (System_Type, type));
return attribute;
}

public CustomAttribute CreateDynamicDependencyAttribute (string memberSignature, string typeName, string assemblyName)
{
var attribute = new CustomAttribute (DynamicDependencyAttribute_ctor__String_String_String);
attribute.ConstructorArguments.Add (new CustomAttributeArgument (System_String, memberSignature));
attribute.ConstructorArguments.Add (new CustomAttributeArgument (System_String, typeName));
attribute.ConstructorArguments.Add (new CustomAttributeArgument (System_String, assemblyName));
return attribute;
}

public CustomAttribute CreateDynamicDependencyAttribute (DynamicallyAccessedMemberTypes memberTypes, TypeDefinition type)
{
var attribute = new CustomAttribute (DynamicDependencyAttribute_ctor__DynamicallyAccessedMemberTypes_Type);
Expand Down
18 changes: 17 additions & 1 deletion tools/dotnet-linker/DocumentionComments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static string GetSignature (IMetadataTokenProvider member)
public static string GetSignature (TypeDefinition type)
{
if (type.IsNested)
return type.Name;
return type.FullName.Replace ('/', '.');
return type.FullName;
}

Expand All @@ -41,6 +41,11 @@ public static string GetSignature (MethodDefinition method)
{
var sb = new StringBuilder ();
sb.Append (method.Name.Replace ('.', '#'));

if (method.HasGenericParameters) {
sb.Append ($"``{method.GenericParameters.Count}");
}

sb.Append ('(');
for (var i = 0; i < method.Parameters.Count; i++) {
if (i > 0)
Expand Down Expand Up @@ -74,6 +79,17 @@ static void WriteTypeSignature (StringBuilder sb, TypeReference type)
return;
}

if (type is GenericParameter gp) {
if (gp.Type == GenericParameterType.Type) {
sb.Append ('`');
} else {
sb.Append ("``");
}

sb.Append (gp.Position.ToString ());
return;
}

sb.Append (type.FullName.Replace ('/', '.'));
}
}
Expand Down