Skip to content

Commit 699b0ae

Browse files
Implement DiagnosticName in NativeAOT code (#63271)
When `DiagnosticName` was introduced into the type system, I didn't want to deal with it and compiled it out of the NativeAOT version of the type system. In order to have a single ILCompiler.TypeSystem assembly that can be used with both crossgen2 and ILC, this needs to be implemented. I've also reduced the number of diffs between ILCompiler.TypeSystem.csproj and ILCompiler.TypeSystem.ReadyToRun.csproj.
1 parent c8f3b36 commit 699b0ae

23 files changed

+323
-37
lines changed

src/coreclr/tools/Common/TypeSystem/Common/GenericParameterDesc.Diagnostic.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ public abstract partial class GenericParameterDesc
1111
/// <summary>
1212
/// Gets the name of the generic parameter as defined in the metadata. This must not throw
1313
/// </summary>
14-
public abstract string DiagnosticName { get; }
14+
public virtual string DiagnosticName
15+
{
16+
get
17+
{
18+
return string.Concat("T", Index.ToStringInvariant());
19+
}
20+
}
1521
}
1622
}

src/coreclr/tools/Common/TypeSystem/IL/Stubs/AssemblyGetExecutingAssemblyMethodThunk.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ public override string Name
4444
}
4545
}
4646

47+
public override string DiagnosticName
48+
{
49+
get
50+
{
51+
return $"GetExecutingAssembly_{ExecutingAssembly.GetName().Name}";
52+
}
53+
}
54+
4755
public override TypeDesc OwningType
4856
{
4957
get;

src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ public override string Name
7979
}
8080
}
8181

82+
public override string DiagnosticName
83+
{
84+
get
85+
{
86+
return "CalliMarshallingMethodThunk";
87+
}
88+
}
89+
8290
public override PInvokeMetadata GetPInvokeMethodMetadata()
8391
{
8492
// Return PInvokeAttributes.PreserveSig to circumvent marshalling required checks

src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@ public override string Name
237237
}
238238
}
239239

240+
public override string DiagnosticName
241+
{
242+
get
243+
{
244+
return NamePrefix + "__" + DelegateType.DiagnosticName;
245+
}
246+
}
247+
240248
public override MethodIL EmitIL()
241249
{
242250
return PInvokeILEmitter.EmitIL(this, default(PInvokeILEmitterConfiguration), _interopStateManager);

src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ protected FieldDesc FunctionPointerField
9090
return SystemDelegateType.GetKnownField("m_functionPointer");
9191
}
9292
}
93+
94+
public sealed override string DiagnosticName
95+
{
96+
get
97+
{
98+
return Name;
99+
}
100+
}
93101
}
94102

95103
/// <summary>
@@ -779,5 +787,13 @@ public override string Name
779787
return "GetThunk";
780788
}
781789
}
790+
791+
public override string DiagnosticName
792+
{
793+
get
794+
{
795+
return "GetThunk";
796+
}
797+
}
782798
}
783799
}

src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,14 @@ public override string Name
308308
}
309309
}
310310

311+
public override string DiagnosticName
312+
{
313+
get
314+
{
315+
return Name;
316+
}
317+
}
318+
311319
public override MethodIL EmitIL()
312320
{
313321
ILEmitter emitter = new ILEmitter();

src/coreclr/tools/Common/TypeSystem/IL/Stubs/EnumThunks.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ public override string Name
6464
}
6565
}
6666

67+
public override string DiagnosticName
68+
{
69+
get
70+
{
71+
return "GetHashCode";
72+
}
73+
}
74+
6775
public override bool IsVirtual
6876
{
6977
get
@@ -147,6 +155,14 @@ public override string Name
147155
}
148156
}
149157

158+
public override string DiagnosticName
159+
{
160+
get
161+
{
162+
return "Equals";
163+
}
164+
}
165+
150166
public override bool IsVirtual
151167
{
152168
get

src/coreclr/tools/Common/TypeSystem/IL/Stubs/ForwardDelegateCreationThunk.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ public override string Name
7575
}
7676
}
7777

78+
public override string DiagnosticName
79+
{
80+
get
81+
{
82+
return "ForwardDelegateCreationStub__" + DelegateType.DiagnosticName;
83+
}
84+
}
85+
7886
/// <summary>
7987
/// This thunk creates a delegate from a native function pointer
8088
/// by first creating a PInvokeDelegateWrapper from the function pointer

src/coreclr/tools/Common/TypeSystem/IL/Stubs/MethodBaseGetCurrentMethodThunk.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ public override string Name
4444
}
4545
}
4646

47+
public override string DiagnosticName
48+
{
49+
get
50+
{
51+
return Method.DiagnosticName;
52+
}
53+
}
54+
4755
public override TypeDesc OwningType
4856
{
4957
get

src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ public override string Name
126126
}
127127
}
128128

129+
public override string DiagnosticName
130+
{
131+
get
132+
{
133+
return NamePrefix + "__" + ManagedType.DiagnosticName;
134+
}
135+
}
136+
129137
private Marshaller[] InitializeMarshallers()
130138
{
131139
Debug.Assert(_interopStateManager != null);

src/coreclr/tools/Common/TypeSystem/IL/Stubs/TypeGetTypeMethodThunk.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ public override string Name
4141
}
4242
}
4343

44+
public override string DiagnosticName
45+
{
46+
get
47+
{
48+
return $"{_helperMethod.DiagnosticName}_{Signature.Length}_{DefaultAssemblyName}";
49+
}
50+
}
51+
4452
public override TypeDesc OwningType
4553
{
4654
get;

src/coreclr/tools/Common/TypeSystem/IL/Stubs/ValueTypeGetFieldHelperMethodOverride.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,13 @@ public override string Name
149149
return "__GetFieldHelper";
150150
}
151151
}
152+
153+
public override string DiagnosticName
154+
{
155+
get
156+
{
157+
return "__GetFieldHelper";
158+
}
159+
}
152160
}
153161
}

src/coreclr/tools/Common/TypeSystem/IL/TypeSystemContext.GeneratedAssembly.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ public override string Name
8989
get;
9090
}
9191

92+
public override string DiagnosticName
93+
{
94+
get
95+
{
96+
return Name;
97+
}
98+
}
99+
92100
public override string Namespace
93101
{
94102
get
@@ -97,6 +105,14 @@ public override string Namespace
97105
}
98106
}
99107

108+
public override string DiagnosticNamespace
109+
{
110+
get
111+
{
112+
return "Internal.CompilerGenerated";
113+
}
114+
}
115+
100116
public override int GetHashCode()
101117
{
102118
if (_hashcode != 0)

src/coreclr/tools/Common/TypeSystem/Interop/IL/InlineArrayType.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ public override string Name
3535
}
3636
}
3737

38+
public override string DiagnosticName
39+
{
40+
get
41+
{
42+
return "_InlineArray__" + ElementType.DiagnosticName + "__" + Length;
43+
}
44+
}
45+
3846
public override string Namespace
3947
{
4048
get
@@ -43,6 +51,14 @@ public override string Namespace
4351
}
4452
}
4553

54+
public override string DiagnosticNamespace
55+
{
56+
get
57+
{
58+
return Namespace;
59+
}
60+
}
61+
4662
public override Instantiation Instantiation
4763
{
4864
get
@@ -320,6 +336,14 @@ public override string Name
320336
}
321337
}
322338

339+
public override string DiagnosticName
340+
{
341+
get
342+
{
343+
return Name;
344+
}
345+
}
346+
323347
public override MethodSignature Signature
324348
{
325349
get

src/coreclr/tools/Common/TypeSystem/Interop/IL/NativeStructType.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ public override string Name
2828
}
2929
}
3030

31+
public override string DiagnosticName
32+
{
33+
get
34+
{
35+
return "__NativeType__" + ManagedStructType.DiagnosticName;
36+
}
37+
}
38+
3139
public override string Namespace
3240
{
3341
get
@@ -36,6 +44,14 @@ public override string Namespace
3644
}
3745
}
3846

47+
public override string DiagnosticNamespace
48+
{
49+
get
50+
{
51+
return "Internal.CompilerGenerated";
52+
}
53+
}
54+
3955
public override PInvokeStringFormat PInvokeStringFormat
4056
{
4157
get

src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapper.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ public override string Name
3535
}
3636
}
3737

38+
public override string DiagnosticName
39+
{
40+
get
41+
{
42+
return "PInvokeDelegateWrapper__" + DelegateType.DiagnosticName;
43+
}
44+
}
45+
3846
public override string Namespace
3947
{
4048
get
@@ -43,6 +51,14 @@ public override string Namespace
4351
}
4452
}
4553

54+
public override string DiagnosticNamespace
55+
{
56+
get
57+
{
58+
return "Internal.CompilerGenerated";
59+
}
60+
}
61+
4662
public override bool IsExplicitLayout
4763
{
4864
get

src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapperConstructor.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ public override string Name
3333
}
3434
}
3535

36+
public override string DiagnosticName
37+
{
38+
get
39+
{
40+
return ".ctor";
41+
}
42+
}
43+
3644
private MethodSignature _signature;
3745
public override MethodSignature Signature
3846
{

0 commit comments

Comments
 (0)