Skip to content

Commit

Permalink
Use SRM's TypeName parser in ILLink (#103740)
Browse files Browse the repository at this point in the history
This replaces the type name parser we copied from corert with the one
in System.Reflection.Metadata.

Adds a test for resolving escaped type names, shared by ILLink and
Native AOT. To support this testcase, the test infra also uses
TypeNameResolver. The ILLink tests use it via IVT, and the Native AOT
tests use it by including source files. The sources have been factored
a little to make it possible to use just the TypeNameResolver from
NativeAot without pulling in other components of ILLink.
  • Loading branch information
sbomer committed Jun 25, 2024
1 parent edf4ad4 commit afe6fbd
Show file tree
Hide file tree
Showing 30 changed files with 315 additions and 1,581 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

namespace ILCompiler.Logging
{

public sealed partial class DocumentationSignatureGenerator
internal sealed partial class DocumentationSignatureGenerator
{
/// <summary>
/// A visitor that generates the part of the documentation comment after the initial type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
<ProjectReference Include="../ILCompiler.RyuJit/ILCompiler.RyuJit.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="$(ToolsProjectRoot)illink/src/linker/Linker/TypeNameResolver.cs" />
<Compile Include="$(ToolsProjectRoot)illink/src/linker/Linker/ITryResolve.cs" />
<Compile Include="$(ToolsProjectRoot)illink/src/linker/Linker/ModuleDefinitionExtensions.cs" />
<Compile Include="$(LibrariesProjectRoot)/Common/src/System/Reflection/Metadata/TypeNameHelpers.cs" />
<Compile Include="$(LibrariesProjectRoot)/Common/src/System/Text/ValueStringBuilder.cs" />
</ItemGroup>

<ItemGroup>
<RuntimeHostConfigurationOption Include="Mono.Linker.Tests.RuntimeBinDirectory">
<Value>$(RuntimeBinDir)</Value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class LinkedMethodEntity : LinkedEntity
}

private readonly BaseAssemblyResolver originalsResolver;
private readonly TypeNameResolver originalsTypeNameResolver;
private readonly ReaderParameters originalReaderParameters;
private readonly AssemblyDefinition originalAssembly;
private readonly TrimmedTestCaseResult testResult;
Expand Down Expand Up @@ -69,6 +70,7 @@ public AssemblyChecker (
TrimmedTestCaseResult testResult)
{
this.originalsResolver = originalsResolver;
this.originalsTypeNameResolver = new TypeNameResolver (new TestResolver (), new TestAssemblyNameResolver (originalsResolver));
this.originalReaderParameters = originalReaderParameters;
this.originalAssembly = original;
this.testResult = testResult;
Expand Down Expand Up @@ -1468,7 +1470,9 @@ internal IEnumerable<string> VerifyLinkingOfOtherAssemblies (AssemblyDefinition
}

var expectedTypeName = checkAttrInAssembly.ConstructorArguments[1].Value.ToString ()!;
var expectedType = originalTargetAssembly.MainModule.GetType(expectedTypeName);
if (!originalsTypeNameResolver.TryResolveTypeName (originalTargetAssembly, expectedTypeName, out TypeReference? expectedTypeRef, out _))
Assert.Fail($"Could not resolve original type `{expectedTypeName}' in assembly {assemblyName}");
TypeDefinition expectedType = expectedTypeRef.Resolve ();
linkedMembersInAssembly.TryGetValue(new AssemblyQualifiedToken(expectedType), out LinkedEntity? linkedTypeEntity);
MetadataType? linkedType = linkedTypeEntity?.Entity as MetadataType;

Expand Down
1 change: 0 additions & 1 deletion src/tools/illink/external/corert/README.md

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit afe6fbd

Please sign in to comment.