From 699b0ae0593e524e1f231e60bf03dd735ecb5d0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Mon, 3 Jan 2022 15:03:03 +0900 Subject: [PATCH] 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. --- .../Common/GenericParameterDesc.Diagnostic.cs | 8 +- ...AssemblyGetExecutingAssemblyMethodThunk.cs | 8 ++ .../IL/Stubs/CalliMarshallingMethodThunk.cs | 8 ++ .../Stubs/DelegateMarshallingMethodThunk.cs | 8 ++ .../TypeSystem/IL/Stubs/DelegateThunks.cs | 16 +++ .../IL/Stubs/DynamicInvokeMethodThunk.cs | 8 ++ .../Common/TypeSystem/IL/Stubs/EnumThunks.cs | 16 +++ .../IL/Stubs/ForwardDelegateCreationThunk.cs | 8 ++ .../Stubs/MethodBaseGetCurrentMethodThunk.cs | 8 ++ .../IL/Stubs/StructMarshallingThunk.cs | 8 ++ .../IL/Stubs/TypeGetTypeMethodThunk.cs | 8 ++ .../ValueTypeGetFieldHelperMethodOverride.cs | 8 ++ .../IL/TypeSystemContext.GeneratedAssembly.cs | 16 +++ .../TypeSystem/Interop/IL/InlineArrayType.cs | 24 ++++ .../TypeSystem/Interop/IL/NativeStructType.cs | 16 +++ .../Interop/IL/PInvokeDelegateWrapper.cs | 16 +++ .../IL/PInvokeDelegateWrapperConstructor.cs | 8 ++ .../CompilerTypeSystemContext.BoxedTypes.cs | 20 +++- ...ompilerTypeSystemContext.IntefaceThunks.cs | 9 ++ .../AppContextInitializerMethod.cs | 8 ++ .../StartupCode/NativeLibraryStartupMethod.cs | 8 ++ .../StartupCode/StartupCodeMainMethod.cs | 16 +++ .../ILCompiler.TypeSystem.csproj | 107 ++++++++++++------ 23 files changed, 323 insertions(+), 37 deletions(-) diff --git a/src/coreclr/tools/Common/TypeSystem/Common/GenericParameterDesc.Diagnostic.cs b/src/coreclr/tools/Common/TypeSystem/Common/GenericParameterDesc.Diagnostic.cs index 8af9193966818..7e8df4304dfd5 100644 --- a/src/coreclr/tools/Common/TypeSystem/Common/GenericParameterDesc.Diagnostic.cs +++ b/src/coreclr/tools/Common/TypeSystem/Common/GenericParameterDesc.Diagnostic.cs @@ -11,6 +11,12 @@ public abstract partial class GenericParameterDesc /// /// Gets the name of the generic parameter as defined in the metadata. This must not throw /// - public abstract string DiagnosticName { get; } + public virtual string DiagnosticName + { + get + { + return string.Concat("T", Index.ToStringInvariant()); + } + } } } diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AssemblyGetExecutingAssemblyMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AssemblyGetExecutingAssemblyMethodThunk.cs index ab0e8eee97858..ce1d69716a7b9 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AssemblyGetExecutingAssemblyMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/AssemblyGetExecutingAssemblyMethodThunk.cs @@ -44,6 +44,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return $"GetExecutingAssembly_{ExecutingAssembly.GetName().Name}"; + } + } + public override TypeDesc OwningType { get; diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.cs index 73b8645e85594..bdbd7b67998f4 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/CalliMarshallingMethodThunk.cs @@ -79,6 +79,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return "CalliMarshallingMethodThunk"; + } + } + public override PInvokeMetadata GetPInvokeMethodMetadata() { // Return PInvokeAttributes.PreserveSig to circumvent marshalling required checks diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.cs index a81809c419303..276f7dc4a42fc 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateMarshallingMethodThunk.cs @@ -237,6 +237,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return NamePrefix + "__" + DelegateType.DiagnosticName; + } + } + public override MethodIL EmitIL() { return PInvokeILEmitter.EmitIL(this, default(PInvokeILEmitterConfiguration), _interopStateManager); diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs index 5725a062a086e..2d76523052ecd 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs @@ -90,6 +90,14 @@ protected FieldDesc FunctionPointerField return SystemDelegateType.GetKnownField("m_functionPointer"); } } + + public sealed override string DiagnosticName + { + get + { + return Name; + } + } } /// @@ -779,5 +787,13 @@ public override string Name return "GetThunk"; } } + + public override string DiagnosticName + { + get + { + return "GetThunk"; + } + } } } diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs index 90ce50f8425ca..de076f3b8cbff 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/DynamicInvokeMethodThunk.cs @@ -308,6 +308,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return Name; + } + } + public override MethodIL EmitIL() { ILEmitter emitter = new ILEmitter(); diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/EnumThunks.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/EnumThunks.cs index a44161e6fa354..dc8fba49876af 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/EnumThunks.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/EnumThunks.cs @@ -64,6 +64,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return "GetHashCode"; + } + } + public override bool IsVirtual { get @@ -147,6 +155,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return "Equals"; + } + } + public override bool IsVirtual { get diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ForwardDelegateCreationThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ForwardDelegateCreationThunk.cs index e93d385a0ffcf..fd1e907f84403 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ForwardDelegateCreationThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ForwardDelegateCreationThunk.cs @@ -75,6 +75,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return "ForwardDelegateCreationStub__" + DelegateType.DiagnosticName; + } + } + /// /// This thunk creates a delegate from a native function pointer /// by first creating a PInvokeDelegateWrapper from the function pointer diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/MethodBaseGetCurrentMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/MethodBaseGetCurrentMethodThunk.cs index d75feac0fe9bd..82a729dc3eb2d 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/MethodBaseGetCurrentMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/MethodBaseGetCurrentMethodThunk.cs @@ -44,6 +44,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return Method.DiagnosticName; + } + } + public override TypeDesc OwningType { get diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.cs index cf346c0685217..2751290f0c91e 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/StructMarshallingThunk.cs @@ -126,6 +126,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return NamePrefix + "__" + ManagedType.DiagnosticName; + } + } + private Marshaller[] InitializeMarshallers() { Debug.Assert(_interopStateManager != null); diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/TypeGetTypeMethodThunk.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/TypeGetTypeMethodThunk.cs index be09098c5dab6..b1a32586bef3f 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/TypeGetTypeMethodThunk.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/TypeGetTypeMethodThunk.cs @@ -41,6 +41,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return $"{_helperMethod.DiagnosticName}_{Signature.Length}_{DefaultAssemblyName}"; + } + } + public override TypeDesc OwningType { get; diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ValueTypeGetFieldHelperMethodOverride.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ValueTypeGetFieldHelperMethodOverride.cs index a324de7bb222b..a5cfa2db42e5e 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ValueTypeGetFieldHelperMethodOverride.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/ValueTypeGetFieldHelperMethodOverride.cs @@ -149,5 +149,13 @@ public override string Name return "__GetFieldHelper"; } } + + public override string DiagnosticName + { + get + { + return "__GetFieldHelper"; + } + } } } diff --git a/src/coreclr/tools/Common/TypeSystem/IL/TypeSystemContext.GeneratedAssembly.cs b/src/coreclr/tools/Common/TypeSystem/IL/TypeSystemContext.GeneratedAssembly.cs index a01beba3cea86..1a289f651f107 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/TypeSystemContext.GeneratedAssembly.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/TypeSystemContext.GeneratedAssembly.cs @@ -89,6 +89,14 @@ public override string Name get; } + public override string DiagnosticName + { + get + { + return Name; + } + } + public override string Namespace { get @@ -97,6 +105,14 @@ public override string Namespace } } + public override string DiagnosticNamespace + { + get + { + return "Internal.CompilerGenerated"; + } + } + public override int GetHashCode() { if (_hashcode != 0) diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/IL/InlineArrayType.cs b/src/coreclr/tools/Common/TypeSystem/Interop/IL/InlineArrayType.cs index 6462c6ee2c59c..4cf06e8b6bfb4 100644 --- a/src/coreclr/tools/Common/TypeSystem/Interop/IL/InlineArrayType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Interop/IL/InlineArrayType.cs @@ -35,6 +35,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return "_InlineArray__" + ElementType.DiagnosticName + "__" + Length; + } + } + public override string Namespace { get @@ -43,6 +51,14 @@ public override string Namespace } } + public override string DiagnosticNamespace + { + get + { + return Namespace; + } + } + public override Instantiation Instantiation { get @@ -320,6 +336,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return Name; + } + } + public override MethodSignature Signature { get diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/IL/NativeStructType.cs b/src/coreclr/tools/Common/TypeSystem/Interop/IL/NativeStructType.cs index d20d6fafcc0dc..bf5e0c6ef3d7b 100644 --- a/src/coreclr/tools/Common/TypeSystem/Interop/IL/NativeStructType.cs +++ b/src/coreclr/tools/Common/TypeSystem/Interop/IL/NativeStructType.cs @@ -28,6 +28,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return "__NativeType__" + ManagedStructType.DiagnosticName; + } + } + public override string Namespace { get @@ -36,6 +44,14 @@ public override string Namespace } } + public override string DiagnosticNamespace + { + get + { + return "Internal.CompilerGenerated"; + } + } + public override PInvokeStringFormat PInvokeStringFormat { get diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapper.cs b/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapper.cs index 78cbe796e397f..dcc2fbff41c06 100644 --- a/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapper.cs +++ b/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapper.cs @@ -35,6 +35,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return "PInvokeDelegateWrapper__" + DelegateType.DiagnosticName; + } + } + public override string Namespace { get @@ -43,6 +51,14 @@ public override string Namespace } } + public override string DiagnosticNamespace + { + get + { + return "Internal.CompilerGenerated"; + } + } + public override bool IsExplicitLayout { get diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapperConstructor.cs b/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapperConstructor.cs index 6917c71f656e4..2e138f6098c7f 100644 --- a/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapperConstructor.cs +++ b/src/coreclr/tools/Common/TypeSystem/Interop/IL/PInvokeDelegateWrapperConstructor.cs @@ -33,6 +33,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return ".ctor"; + } + } + private MethodSignature _signature; public override MethodSignature Signature { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.BoxedTypes.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.BoxedTypes.cs index 8be62c3d9950d..39a6bf3490beb 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.BoxedTypes.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.BoxedTypes.cs @@ -259,7 +259,8 @@ private partial class BoxedValueType : MetadataType, INonEmittableType public override string Name => "Boxed_" + ValueTypeRepresented.Name; public override string Namespace => ValueTypeRepresented.Namespace; - + public override string DiagnosticName => "Boxed_" + ValueTypeRepresented.DiagnosticName; + public override string DiagnosticNamespace => ValueTypeRepresented.DiagnosticNamespace; public override Instantiation Instantiation => ValueTypeRepresented.Instantiation; public override PInvokeStringFormat PInvokeStringFormat => PInvokeStringFormat.AutoClass; public override bool IsExplicitLayout => false; @@ -411,6 +412,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return _targetMethod.DiagnosticName + "_Unbox"; + } + } + public override MethodIL EmitIL() { if (_owningType.ValueTypeRepresented.IsByRefLike) @@ -487,6 +496,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return _targetMethod.DiagnosticName + "_Unbox"; + } + } + public override MethodIL EmitIL() { if (_owningType.ValueTypeRepresented.IsByRefLike) @@ -574,6 +591,7 @@ public ValueTypeInstanceMethodWithHiddenParameter(MethodDesc methodRepresented) public override TypeDesc OwningType => _methodRepresented.OwningType; public override string Name => _methodRepresented.Name; + public override string DiagnosticName => _methodRepresented.DiagnosticName; public override MethodSignature Signature { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.IntefaceThunks.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.IntefaceThunks.cs index ad558ae43bf51..06c13c51e6d8d 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.IntefaceThunks.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/CompilerTypeSystemContext.IntefaceThunks.cs @@ -194,6 +194,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return _targetMethod.DiagnosticName; + } + } + public MethodDesc BaseMethod => _targetMethod; public string Prefix => $"__InstantiatingStub_{_interfaceIndex}_"; @@ -274,6 +282,7 @@ public DefaultInterfaceMethodImplementationWithHiddenParameter(MethodDesc method public override TypeDesc OwningType => _owningType; public override string Name => _methodRepresented.Name; + public override string DiagnosticName => _methodRepresented.DiagnosticName; public override MethodSignature Signature { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/AppContextInitializerMethod.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/AppContextInitializerMethod.cs index d4b53340b5530..ed40a5f6fcc75 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/AppContextInitializerMethod.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/AppContextInitializerMethod.cs @@ -54,6 +54,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return "SetAppContextSwitches"; + } + } + public override MethodIL EmitIL() { ILEmitter emitter = new ILEmitter(); diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/NativeLibraryStartupMethod.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/NativeLibraryStartupMethod.cs index 7138804bb2313..4240af2427d15 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/NativeLibraryStartupMethod.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/NativeLibraryStartupMethod.cs @@ -48,6 +48,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return "NativeLibraryStartup"; + } + } + public override MethodIL EmitIL() { ILEmitter emitter = new ILEmitter(); diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/StartupCodeMainMethod.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/StartupCodeMainMethod.cs index b18b943549134..2c91f888c4dc0 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/StartupCodeMainMethod.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/StartupCodeMainMethod.cs @@ -53,6 +53,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return "StartupCodeMain"; + } + } + public override MethodIL EmitIL() { ILEmitter emitter = new ILEmitter(); @@ -229,6 +237,14 @@ public override string Name } } + public override string DiagnosticName + { + get + { + return "MainMethodWrapper"; + } + } + public override MethodSignature Signature { get diff --git a/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj b/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj index 4aa53fd19c5e1..a638f7310d052 100644 --- a/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj +++ b/src/coreclr/tools/aot/ILCompiler.TypeSystem/ILCompiler.TypeSystem.csproj @@ -9,6 +9,8 @@ x64;x86 AnyCPU false + true + $(DefineConstants);DISABLE_UNMANAGED_PDB_SYMBOLS