Skip to content

Commit

Permalink
Make things compile
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalStrehovsky committed Nov 5, 2020
1 parent 89a5e85 commit 6daf5d3
Show file tree
Hide file tree
Showing 16 changed files with 625 additions and 381 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Internal.TypeSystem;
using Internal.TypeSystem.Ecma;

namespace ILCompiler.Dataflow
{
static class DiagnosticUtilities
{
internal static Origin GetMethodParameterFromIndex(MethodDesc method, int parameterIndex)
{
int declaredParameterIndex;
if (!method.Signature.IsStatic)
{
if (parameterIndex == 0)
return new MethodOrigin(method);

declaredParameterIndex = parameterIndex - 1;
}
else
declaredParameterIndex = parameterIndex;

return new ParameterOrigin(method, declaredParameterIndex);
}

internal static string GetParameterNameForErrorMessage(ParameterOrigin origin)
{
return $"#{origin.Index}";
}

internal static string GetMethodSignatureDisplayName(MethodDesc method)
{
return method.GetDisplayName();
}

internal static string GetGenericParameterDeclaringMemberDisplayName(GenericParameterOrigin origin)
{
var param = (EcmaGenericParameter)origin.GenericParameter;
var parent = param.Module.GetObject(param.MetadataReader.GetGenericParameter(param.Handle).Parent);
if (parent is MethodDesc m)
return m.GetDisplayName();
else
return ((TypeDesc)parent).GetDisplayName();
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Internal.TypeSystem;
using Internal.TypeSystem.Ecma;

using MethodAttributes = System.Reflection.MethodAttributes;
using FieldAttributes = System.Reflection.FieldAttributes;
using TypeAttributes = System.Reflection.TypeAttributes;

namespace ILCompiler.Dataflow
{
static class EcmaExtensions
{
public static bool IsPublic(this MethodDesc method)
{
return method.GetTypicalMethodDefinition() is EcmaMethod ecmaMethod
&& (ecmaMethod.Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
}

public static bool IsPublic(this FieldDesc field)
{
return field.GetTypicalFieldDefinition() is EcmaField ecmaField
&& (ecmaField.Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Public;
}

public static bool IsPrivate(this MethodDesc method)
{
return method.GetTypicalMethodDefinition() is EcmaMethod ecmaMethod
&& (ecmaMethod.Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
}

public static bool IsPrivate(this FieldDesc field)
{
return field.GetTypicalFieldDefinition() is EcmaField ecmaField
&& (ecmaField.Attributes & FieldAttributes.FieldAccessMask) == FieldAttributes.Private;
}

public static bool IsNestedPublic(this MetadataType mdType)
{
return mdType.GetTypeDefinition() is EcmaType ecmaType
&& (ecmaType.Attributes & TypeAttributes.VisibilityMask) == TypeAttributes.NestedPublic;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public FlowAnnotations(Logger logger, ILProvider ilProvider)

public bool RequiresDataflowAnalysis(MethodDesc method)
{
Debug.Assert(method.IsTypicalMethodDefinition);
method = method.GetTypicalMethodDefinition();
return GetAnnotations(method.OwningType).TryGetAnnotation(method, out _);
}

public bool RequiresDataflowAnalysis(FieldDesc field)
{
Debug.Assert(field.IsTypicalFieldDefinition);
field = field.GetTypicalFieldDefinition();
return GetAnnotations(field.OwningType).TryGetAnnotation(field, out _);
}

Expand All @@ -49,7 +49,7 @@ public bool RequiresDataflowAnalysis(GenericParameterDesc genericParameter)
/// <param name="parameterIndex">Parameter index in the IL sense. Parameter 0 on instance methods is `this`.</param>
public DynamicallyAccessedMemberTypes GetParameterAnnotation(MethodDesc method, int parameterIndex)
{
Debug.Assert(method.IsTypicalMethodDefinition);
method = method.GetTypicalMethodDefinition();

if (GetAnnotations(method.OwningType).TryGetAnnotation(method, out var annotation) && annotation.ParameterAnnotations != null)
{
Expand All @@ -61,7 +61,7 @@ public DynamicallyAccessedMemberTypes GetParameterAnnotation(MethodDesc method,

public DynamicallyAccessedMemberTypes GetReturnParameterAnnotation(MethodDesc method)
{
Debug.Assert(method.IsTypicalMethodDefinition);
method = method.GetTypicalMethodDefinition();

if (GetAnnotations(method.OwningType).TryGetAnnotation(method, out var annotation))
{
Expand All @@ -73,7 +73,7 @@ public DynamicallyAccessedMemberTypes GetReturnParameterAnnotation(MethodDesc me

public DynamicallyAccessedMemberTypes GetFieldAnnotation(FieldDesc field)
{
Debug.Assert(field.IsTypicalFieldDefinition);
field = field.GetTypicalFieldDefinition();

if (GetAnnotations(field.OwningType).TryGetAnnotation(field, out var annotation))
{
Expand Down Expand Up @@ -249,7 +249,7 @@ protected override TypeAnnotations CreateValueFromKey(TypeDesc key)
if (pa == DynamicallyAccessedMemberTypes.None)
continue;

if (!IsTypeInterestingForDataflow(method.Signature[parameter.SequenceNumber]))
if (!IsTypeInterestingForDataflow(method.Signature[parameter.SequenceNumber - 1]))
{
_logger.LogWarning(
$"Parameter #{parameter.SequenceNumber} of method '{method.GetDisplayName()}' has 'DynamicallyAccessedMembersAttribute', but that attribute can only be applied to parameters of type 'System.Type' or 'System.String'",
Expand Down Expand Up @@ -318,7 +318,7 @@ protected override TypeAnnotations CreateValueFromKey(TypeDesc key)
FieldDesc backingFieldFromSetter = null;

// Propagate the annotation to the setter method
MethodDesc setMethod = property.Setter;
MethodDesc setMethod = property.SetMethod;
if (setMethod != null)
{

Expand Down Expand Up @@ -355,7 +355,7 @@ protected override TypeAnnotations CreateValueFromKey(TypeDesc key)
FieldDesc backingFieldFromGetter = null;

// Propagate the annotation to the getter method
MethodDesc getMethod = property.Getter;
MethodDesc getMethod = property.GetMethod;
if (getMethod != null)
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ private void HandleCall(
callingMethodBody,
calledMethod,
opcode,
offset,
methodParams,
out methodReturnValue);

Expand Down Expand Up @@ -929,6 +930,7 @@ public abstract bool HandleCall(
MethodIL callingMethodBody,
MethodDesc calledMethod,
ILOpcode operation,
int offset,
ValueNodeList methodParams,
out ValueNode methodReturnValue);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Internal.TypeSystem;
using Internal.TypeSystem.Ecma;

namespace ILCompiler.Dataflow
{
internal abstract class Origin
{
}

class MethodReturnOrigin : Origin
{
public MethodDesc Method { get; }

public MethodReturnOrigin(MethodDesc method)
{
Method = method;
}

public string GetDisplayName() => Method.GetDisplayName();
}

class ParameterOrigin : Origin
{
public MethodDesc Method { get; }
public int Index { get; }

public ParameterOrigin(MethodDesc method, int index)
{
Method = method;
Index = index;
}

public string GetDisplayName() => Method.GetDisplayName();
}

class MethodOrigin : Origin
{
public MethodDesc Method { get; }

public MethodOrigin(MethodDesc method)
{
Method = method;
}

public string GetDisplayName() => Method.GetDisplayName();
}

class FieldOrigin : Origin
{
public FieldDesc Field { get; }

public FieldOrigin(FieldDesc field)
{
Field = field;
}

public string GetDisplayName() => Field.GetDisplayName();
}

class GenericParameterOrigin : Origin
{
public GenericParameterDesc GenericParameter { get; }

public string Name => GenericParameter.Name;

public GenericParameterOrigin(GenericParameterDesc genericParam)
{
GenericParameter = genericParam;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
The dataflow analysis logic originates from IL Linker: http://github.com/mono/linker.

The purpose of this logic is to analyze dynamic behavior of the compiled code to make things like reflection work. This is done by analyzing the IL and reading dataflow annotations.

Let's try to keep this in sync. The ReferenceSource contains sources at the time of porting.

It should be updated whenever we take fixes from IL linker.
Loading

0 comments on commit 6daf5d3

Please sign in to comment.