Skip to content

Commit

Permalink
Implement DiagnosticName in NativeAOT code (#63271)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MichalStrehovsky committed Jan 3, 2022
1 parent c8f3b36 commit 699b0ae
Show file tree
Hide file tree
Showing 23 changed files with 323 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ public abstract partial class GenericParameterDesc
/// <summary>
/// Gets the name of the generic parameter as defined in the metadata. This must not throw
/// </summary>
public abstract string DiagnosticName { get; }
public virtual string DiagnosticName
{
get
{
return string.Concat("T", Index.ToStringInvariant());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public override string Name
}
}

public override string DiagnosticName
{
get
{
return $"GetExecutingAssembly_{ExecutingAssembly.GetName().Name}";
}
}

public override TypeDesc OwningType
{
get;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions src/coreclr/tools/Common/TypeSystem/IL/Stubs/DelegateThunks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ protected FieldDesc FunctionPointerField
return SystemDelegateType.GetKnownField("m_functionPointer");
}
}

public sealed override string DiagnosticName
{
get
{
return Name;
}
}
}

/// <summary>
Expand Down Expand Up @@ -779,5 +787,13 @@ public override string Name
return "GetThunk";
}
}

public override string DiagnosticName
{
get
{
return "GetThunk";
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ public override string Name
}
}

public override string DiagnosticName
{
get
{
return Name;
}
}

public override MethodIL EmitIL()
{
ILEmitter emitter = new ILEmitter();
Expand Down
16 changes: 16 additions & 0 deletions src/coreclr/tools/Common/TypeSystem/IL/Stubs/EnumThunks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ public override string Name
}
}

public override string DiagnosticName
{
get
{
return "GetHashCode";
}
}

public override bool IsVirtual
{
get
Expand Down Expand Up @@ -147,6 +155,14 @@ public override string Name
}
}

public override string DiagnosticName
{
get
{
return "Equals";
}
}

public override bool IsVirtual
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ public override string Name
}
}

public override string DiagnosticName
{
get
{
return "ForwardDelegateCreationStub__" + DelegateType.DiagnosticName;
}
}

/// <summary>
/// This thunk creates a delegate from a native function pointer
/// by first creating a PInvokeDelegateWrapper from the function pointer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public override string Name
}
}

public override string DiagnosticName
{
get
{
return Method.DiagnosticName;
}
}

public override TypeDesc OwningType
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ public override string Name
}
}

public override string DiagnosticName
{
get
{
return NamePrefix + "__" + ManagedType.DiagnosticName;
}
}

private Marshaller[] InitializeMarshallers()
{
Debug.Assert(_interopStateManager != null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public override string Name
}
}

public override string DiagnosticName
{
get
{
return $"{_helperMethod.DiagnosticName}_{Signature.Length}_{DefaultAssemblyName}";
}
}

public override TypeDesc OwningType
{
get;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,13 @@ public override string Name
return "__GetFieldHelper";
}
}

public override string DiagnosticName
{
get
{
return "__GetFieldHelper";
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ public override string Name
get;
}

public override string DiagnosticName
{
get
{
return Name;
}
}

public override string Namespace
{
get
Expand All @@ -97,6 +105,14 @@ public override string Namespace
}
}

public override string DiagnosticNamespace
{
get
{
return "Internal.CompilerGenerated";
}
}

public override int GetHashCode()
{
if (_hashcode != 0)
Expand Down
24 changes: 24 additions & 0 deletions src/coreclr/tools/Common/TypeSystem/Interop/IL/InlineArrayType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public override string Name
}
}

public override string DiagnosticName
{
get
{
return "_InlineArray__" + ElementType.DiagnosticName + "__" + Length;
}
}

public override string Namespace
{
get
Expand All @@ -43,6 +51,14 @@ public override string Namespace
}
}

public override string DiagnosticNamespace
{
get
{
return Namespace;
}
}

public override Instantiation Instantiation
{
get
Expand Down Expand Up @@ -320,6 +336,14 @@ public override string Name
}
}

public override string DiagnosticName
{
get
{
return Name;
}
}

public override MethodSignature Signature
{
get
Expand Down
16 changes: 16 additions & 0 deletions src/coreclr/tools/Common/TypeSystem/Interop/IL/NativeStructType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public override string Name
}
}

public override string DiagnosticName
{
get
{
return "__NativeType__" + ManagedStructType.DiagnosticName;
}
}

public override string Namespace
{
get
Expand All @@ -36,6 +44,14 @@ public override string Namespace
}
}

public override string DiagnosticNamespace
{
get
{
return "Internal.CompilerGenerated";
}
}

public override PInvokeStringFormat PInvokeStringFormat
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public override string Name
}
}

public override string DiagnosticName
{
get
{
return "PInvokeDelegateWrapper__" + DelegateType.DiagnosticName;
}
}

public override string Namespace
{
get
Expand All @@ -43,6 +51,14 @@ public override string Namespace
}
}

public override string DiagnosticNamespace
{
get
{
return "Internal.CompilerGenerated";
}
}

public override bool IsExplicitLayout
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public override string Name
}
}

public override string DiagnosticName
{
get
{
return ".ctor";
}
}

private MethodSignature _signature;
public override MethodSignature Signature
{
Expand Down
Loading

0 comments on commit 699b0ae

Please sign in to comment.