Skip to content

Commit cecaa02

Browse files
committed
Switch AOT compilers to use AssemblyNameInfo
1 parent 0fb0188 commit cecaa02

File tree

40 files changed

+170
-216
lines changed

40 files changed

+170
-216
lines changed

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/MetadataReaderExtensions.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,10 @@ private static RuntimeAssemblyName CreateRuntimeAssemblyNameFromMetadata(
120120
ByteCollection publicKeyOrToken,
121121
global::Internal.Metadata.NativeFormat.AssemblyFlags assemblyFlags)
122122
{
123-
AssemblyNameFlags assemblyNameFlags = AssemblyNameFlags.None;
124-
if (0 != (assemblyFlags & global::Internal.Metadata.NativeFormat.AssemblyFlags.PublicKey))
125-
assemblyNameFlags |= AssemblyNameFlags.PublicKey;
126-
if (0 != (assemblyFlags & global::Internal.Metadata.NativeFormat.AssemblyFlags.Retargetable))
127-
assemblyNameFlags |= AssemblyNameFlags.Retargetable;
128-
int contentType = ((int)assemblyFlags) & 0x00000E00;
129-
assemblyNameFlags |= (AssemblyNameFlags)contentType;
123+
AssemblyNameFlags assemblyNameFlags = (AssemblyNameFlags)(assemblyFlags & (
124+
global::Internal.Metadata.NativeFormat.AssemblyFlags.PublicKey |
125+
global::Internal.Metadata.NativeFormat.AssemblyFlags.Retargetable |
126+
global::Internal.Metadata.NativeFormat.AssemblyFlags.ContentTypeMask));
130127

131128
ArrayBuilder<byte> keyOrTokenArrayBuilder = default;
132129
foreach (byte b in publicKeyOrToken)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Internal.TypeSystem
5+
{
6+
// Dummy implementation of AssemlyNameInfo for runtime type system
7+
public abstract class AssemblyNameInfo
8+
{
9+
public abstract string FullName { get; }
10+
}
11+
}

src/coreclr/nativeaot/System.Private.TypeLoader/src/System.Private.TypeLoader.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@
255255
<Compile Include="Internal\Runtime\TypeLoader\TypeSystemContextFactory.cs" />
256256
<Compile Include="Internal\Runtime\TypeLoader\TypeSystemExtensions.cs" />
257257
<Compile Include="Internal\Runtime\TypeLoader\WellKnownTypeExtensions.cs" />
258+
<Compile Include="Internal\TypeSystem\AssemblyNameInfo.Dummy.cs" />
258259
<Compile Include="Internal\TypeSystem\ArrayMethod.Runtime.cs" />
259260
<Compile Include="Internal\TypeSystem\CanonTypes.Runtime.cs" />
260261
<Compile Include="Internal\TypeSystem\DefType.Runtime.cs" />

src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public IReadOnlyDictionary<string, string> ReferenceFilePaths
9898
set;
9999
}
100100

101-
public override ModuleDesc ResolveAssembly(System.Reflection.AssemblyName name, bool throwIfNotFound)
101+
public override ModuleDesc ResolveAssembly(AssemblyNameInfo name, bool throwIfNotFound)
102102
{
103103
// TODO: catch typesystem BadImageFormatException and throw a new one that also captures the
104104
// assembly name that caused the failure. (Along with the reason, which makes this rather annoying).

src/coreclr/tools/Common/Compiler/ProcessLinkerXmlBase.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ protected virtual void ProcessXml(bool ignoreResource)
128128

129129
protected virtual AllowedAssemblies AllowedAssemblySelector { get => _owningModule != null ? AllowedAssemblies.ContainingAssembly : AllowedAssemblies.AnyAssembly; }
130130

131-
private bool ShouldProcessAllAssemblies(XPathNavigator nav, [NotNullWhen(false)] out AssemblyName? assemblyName)
131+
private bool ShouldProcessAllAssemblies(XPathNavigator nav, [NotNullWhen(false)] out AssemblyNameInfo? assemblyName)
132132
{
133133
assemblyName = null;
134134
if (GetFullName(nav) == AllAssembliesFullName)
@@ -147,7 +147,7 @@ protected virtual void ProcessAssemblies(XPathNavigator nav)
147147

148148
// Errors for invalid assembly names should show up even if this element will be
149149
// skipped due to feature conditions.
150-
bool processAllAssemblies = ShouldProcessAllAssemblies(assemblyNav, out AssemblyName? name);
150+
bool processAllAssemblies = ShouldProcessAllAssemblies(assemblyNav, out AssemblyNameInfo? name);
151151
if (processAllAssemblies && !_globalAttributeRemoval)
152152
{
153153
#if !READYTORUN
@@ -175,7 +175,7 @@ protected virtual void ProcessAssemblies(XPathNavigator nav)
175175
if (_owningModule.Assembly.GetName().Name != name!.Name)
176176
{
177177
#if !READYTORUN
178-
LogWarning(assemblyNav, DiagnosticId.AssemblyWithEmbeddedXmlApplyToAnotherAssembly, _owningModule.Assembly.GetName().Name ?? "", name.ToString());
178+
LogWarning(assemblyNav, DiagnosticId.AssemblyWithEmbeddedXmlApplyToAnotherAssembly, _owningModule.Assembly.GetName().Name, name.FullName);
179179
#endif
180180
continue;
181181
}
@@ -188,7 +188,7 @@ protected virtual void ProcessAssemblies(XPathNavigator nav)
188188
if (assembly == null)
189189
{
190190
#if !READYTORUN
191-
LogWarning(assemblyNav, DiagnosticId.XmlCouldNotResolveAssembly, name!.Name ?? "");
191+
LogWarning(assemblyNav, DiagnosticId.XmlCouldNotResolveAssembly, name!.Name);
192192
#endif
193193
continue;
194194
}
@@ -499,9 +499,9 @@ protected virtual void ProcessProperty(TypeDesc type, XPathNavigator nav, object
499499

500500
protected virtual void ProcessProperty(TypeDesc type, PropertyPseudoDesc property, XPathNavigator nav, object? customData, bool fromSignature) { }
501501

502-
protected virtual AssemblyName GetAssemblyName(XPathNavigator nav)
502+
protected virtual AssemblyNameInfo GetAssemblyName(XPathNavigator nav)
503503
{
504-
return new AssemblyName(GetFullName(nav));
504+
return AssemblyNameInfo.Parse(GetFullName(nav));
505505
}
506506

507507
protected static string GetFullName(XPathNavigator nav)

src/coreclr/tools/Common/Internal/Metadata/NativeFormat/NativeFormatReaderCommonGen.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace Internal.Metadata.NativeFormat
1616
{
17+
// Internal clone of System.Reflection.AssemblyFlags from System.Reflection.Metadata
1718
[Flags]
1819
#if SYSTEM_PRIVATE_CORELIB
1920
[CLSCompliant(false)]
@@ -26,13 +27,12 @@ public enum AssemblyFlags : uint
2627
/// The implementation of this assembly used at runtime is not expected to match the version seen at compile time.
2728
Retargetable = 0x100,
2829

29-
/// Reserved.
30-
DisableJITcompileOptimizer = 0x4000,
30+
/// Content type mask. Masked bits correspond to values of System.Reflection.AssemblyContentType
31+
ContentTypeMask = 0x00000e00,
3132

32-
/// Reserved.
33-
EnableJITcompileTracking = 0x8000,
3433
} // AssemblyFlags
3534

35+
// Internal clone of System.Reflection.AssemblyHashAlgorithm from System.Reflection.Metadata
3636
#if SYSTEM_PRIVATE_CORELIB
3737
[CLSCompliant(false)]
3838
#endif

src/coreclr/tools/Common/TypeSystem/Common/IAssemblyDesc.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.Reflection;
4+
using System.Reflection.Metadata;
55

66
namespace Internal.TypeSystem
77
{
@@ -13,6 +13,6 @@ public interface IAssemblyDesc
1313
/// <summary>
1414
/// Gets the assembly name.
1515
/// </summary>
16-
AssemblyName GetName();
16+
AssemblyNameInfo GetName();
1717
}
1818
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.Reflection;
4+
using System.Reflection.Metadata;
55

66
namespace Internal.TypeSystem
77
{
88
public interface IModuleResolver
99
{
10-
ModuleDesc ResolveAssembly(AssemblyName name, bool throwIfNotFound = true);
10+
ModuleDesc ResolveAssembly(AssemblyNameInfo name, bool throwIfNotFound = true);
1111
ModuleDesc ResolveModule(IAssemblyDesc referencingModule, string fileName, bool throwIfNotFound = true);
1212
}
1313
}

src/coreclr/tools/Common/TypeSystem/Common/TypeSystemContext.Resolution.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Diagnostics;
7-
using System.Reflection;
7+
using System.Reflection.Metadata;
88

99
using Internal.NativeFormat;
1010

@@ -24,7 +24,7 @@ protected void InitializeSystemModule(ModuleDesc systemModule)
2424
SystemModule = systemModule;
2525
}
2626

27-
public virtual ModuleDesc ResolveAssembly(AssemblyName name, bool throwIfNotFound = true)
27+
public virtual ModuleDesc ResolveAssembly(AssemblyNameInfo name, bool throwIfNotFound = true)
2828
{
2929
if (throwIfNotFound)
3030
throw new NotSupportedException();

src/coreclr/tools/Common/TypeSystem/Common/Utilities/CustomAttributeTypeNameParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private TypeDesc GetSimpleType(TypeName typeName)
109109
ModuleDesc module = _module;
110110
if (topLevelTypeName.AssemblyName != null)
111111
{
112-
module = _context.ResolveAssembly(typeName.AssemblyName.ToAssemblyName(), throwIfNotFound: _throwIfNotFound);
112+
module = _context.ResolveAssembly(typeName.AssemblyName, throwIfNotFound: _throwIfNotFound);
113113
if (module == null)
114114
return null;
115115
}

0 commit comments

Comments
 (0)