Skip to content

Commit

Permalink
Make some methods of illink public that we need to call. (#90689)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvoorhe authored Aug 17, 2023
1 parent fdfccf8 commit 374b111
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
36 changes: 30 additions & 6 deletions src/tools/illink/src/linker/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,24 @@
<Left>ref/net8.0/illink.dll</Left>
<Right>lib/net8.0/illink.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Mono.Linker.MethodDefinitionExtensions</Target>
<Left>ref/net8.0/illink.dll</Left>
<Right>lib/net8.0/illink.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Mono.Linker.MethodIL</Target>
<Left>ref/net8.0/illink.dll</Left>
<Right>lib/net8.0/illink.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Mono.Linker.MethodReferenceExtensions</Target>
<Left>ref/net8.0/illink.dll</Left>
<Right>lib/net8.0/illink.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0001</DiagnosticId>
<Target>T:Mono.Linker.ModuleDefinitionExtensions</Target>
Expand Down Expand Up @@ -1279,6 +1291,18 @@
<Left>ref/net8.0/illink.dll</Left>
<Right>lib/net8.0/illink.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Mono.Linker.LinkContext.FatalError(System.String,System.Int32,System.Exception,System.String,System.Nullable{Mono.Linker.MessageOrigin})</Target>
<Left>ref/net8.0/illink.dll</Left>
<Right>lib/net8.0/illink.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Mono.Linker.LinkContext.FatalError(System.String,System.Int32,System.String,System.Nullable{Mono.Linker.MessageOrigin})</Target>
<Left>ref/net8.0/illink.dll</Left>
<Right>lib/net8.0/illink.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Mono.Linker.LinkContext.FlushCachedWarnings</Target>
Expand Down Expand Up @@ -1345,6 +1369,12 @@
<Left>ref/net8.0/illink.dll</Left>
<Right>lib/net8.0/illink.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Mono.Linker.LinkContext.get_EmbeddedXmlInfo</Target>
<Left>ref/net8.0/illink.dll</Left>
<Right>lib/net8.0/illink.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Mono.Linker.LinkContext.get_EnableReducedTracing</Target>
Expand Down Expand Up @@ -1524,12 +1554,6 @@
<Target>M:Mono.Linker.LinkContext.get_Tracer</Target>
<Left>ref/net8.0/illink.dll</Left>
<Right>lib/net8.0/illink.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Mono.Linker.LinkContext.get_EmbeddedXmlInfo</Target>
<Left>ref/net8.0/illink.dll</Left>
<Right>lib/net8.0/illink.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
Expand Down
27 changes: 27 additions & 0 deletions src/tools/illink/src/linker/Linker/LinkContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,33 @@ public void LogError (MessageOrigin? origin, DiagnosticId id, params string[] ar
LogMessage (error);
}

/// <summary>
/// Throws a LinkerFatalErrorException
/// </summary>
/// <param name="text">Humanly readable message describing the error</param>
/// <param name="code">Unique error ID. Please see https://github.com/dotnet/runtime/blob/main/docs/tools/illink/error-codes.md
/// for the list of errors and possibly add a new one</param>
/// <param name="subcategory">Optionally, further categorize this error</param>
/// <param name="origin">Filename, line, and column where the error was found</param>
public static void FatalError (string text, int code, string subcategory = MessageSubCategory.None, MessageOrigin? origin = null)
{
throw new LinkerFatalErrorException (MessageContainer.CreateErrorMessage (text, code, subcategory, origin));
}

/// <summary>
/// Throws a LinkerFatalErrorException
/// </summary>
/// <param name="text">Humanly readable message describing the error</param>
/// <param name="code">Unique error ID. Please see https://github.com/dotnet/runtime/blob/main/docs/tools/illink/error-codes.md
/// for the list of errors and possibly add a new one</param>
/// <param name="subcategory">Optionally, further categorize this error</param>
/// <param name="origin">Filename, line, and column where the error was found</param>
/// <param name="innerException">Optional, an inner exception</param>
public static void FatalError (string text, int code, Exception innerException, string subcategory = MessageSubCategory.None, MessageOrigin? origin = null)
{
throw new LinkerFatalErrorException (MessageContainer.CreateErrorMessage (text, code, subcategory, origin), innerException);
}

public void FlushCachedWarnings ()
{
_cachedWarningMessageContainers.Sort ();
Expand Down
10 changes: 5 additions & 5 deletions src/tools/illink/src/linker/Linker/MethodDefinitionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Mono.Linker
{
[SuppressMessage ("ApiDesign", "RS0030:Do not used banned APIs", Justification = "This class provides wrapper methods around the banned Parameters property")]
internal static class MethodDefinitionExtensions
public static class MethodDefinitionExtensions
{
public static bool IsDefaultConstructor (this MethodDefinition method)
{
Expand Down Expand Up @@ -107,7 +107,7 @@ public static void ClearDebugInformation (this MethodDefinition method)
/// Returns null if <paramref name="index"/> is not a valid parameter index for <paramref name="method"/>.
/// <see cref="GetParameter(MethodDefinition, ParameterIndex)"/> for a non-nullable version if you know the index is valid.
/// </summary>
public static ParameterProxy? TryGetParameter (this MethodDefinition method, ParameterIndex index)
internal static ParameterProxy? TryGetParameter (this MethodDefinition method, ParameterIndex index)
{
if (method.GetParametersCount () <= (int) index || (int) index < 0)
return null;
Expand All @@ -119,7 +119,7 @@ public static void ClearDebugInformation (this MethodDefinition method)
/// Throws if <paramref name="index"/> is not a valid parameter index for <paramref name="method"/>.
/// <see cref="TryGetParameter(MethodDefinition, ParameterIndex)"/> for a non-throwing version if you're not sure the parameter exists on the method.
/// </summary>
public static ParameterProxy GetParameter (this MethodDefinition method, ParameterIndex index)
internal static ParameterProxy GetParameter (this MethodDefinition method, ParameterIndex index)
{
if (method.TryGetParameter (index) is not ParameterProxy param)
throw new InvalidOperationException ($"Cannot get parameter #{(int) index} of method {method.GetDisplayName ()} with {method.GetParametersCount ()} parameters");
Expand All @@ -129,7 +129,7 @@ public static ParameterProxy GetParameter (this MethodDefinition method, Paramet
/// <summary>
/// Returns a foreach-enumerable collection of the parameters pushed onto the stack before the method call (including the implicit 'this' parameter)
/// </summary>
public static ParameterProxyEnumerable GetParameters (this MethodDefinition method)
internal static ParameterProxyEnumerable GetParameters (this MethodDefinition method)
{
int implicitThisOffset = method.HasImplicitThis () ? 1 : 0;
return new ParameterProxyEnumerable (0, method.Parameters.Count + implicitThisOffset, method);
Expand All @@ -138,7 +138,7 @@ public static ParameterProxyEnumerable GetParameters (this MethodDefinition meth
/// <summary>
/// Returns a list of ParameterProxy representing the parameters listed in the "Parameters" metadata section (i.e. not including the implicit 'this' parameter)
/// </summary>
public static ParameterProxyEnumerable GetMetadataParameters (this MethodDefinition method)
internal static ParameterProxyEnumerable GetMetadataParameters (this MethodDefinition method)
{
int implicitThisOffset = method.HasImplicitThis () ? 1 : 0;
return new ParameterProxyEnumerable (implicitThisOffset, method.Parameters.Count + implicitThisOffset, method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Mono.Linker
{
internal static class MethodReferenceExtensions
public static class MethodReferenceExtensions
{
public static string GetDisplayName (this MethodReference method)
{
Expand Down

0 comments on commit 374b111

Please sign in to comment.