Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Commit

Permalink
Use canonical method IL in scanner's ImportCall (#5686)
Browse files Browse the repository at this point in the history
Simulates what JitInterface operates on.
  • Loading branch information
MichalStrehovsky authored Apr 12, 2018
1 parent 55cb81a commit 657a366
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/ILCompiler.Compiler/src/IL/ILImporter.Scanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Internal.IL
partial class ILImporter
{
private readonly MethodIL _methodIL;
private readonly MethodIL _canonMethodIL;
private readonly ILScanner _compilation;
private readonly ILScanNodeFactory _factory;

Expand Down Expand Up @@ -84,6 +85,8 @@ public ILImporter(ILScanner compilation, MethodDesc method, MethodIL methodIL =

_ilBytes = methodIL.GetILBytes();

_canonMethodIL = methodIL;

// Get the runtime determined method IL so that this works right in shared code
// and tokens in shared code resolve to runtime determined types.
MethodIL uninstantiatiedMethodIL = methodIL.GetMethodILDefinition();
Expand Down Expand Up @@ -266,11 +269,10 @@ private void ImportCasting(ILOpcode opcode, int token)

private void ImportCall(ILOpcode opcode, int token)
{
// Strip runtime determined characteristics off of the method (because that's how RyuJIT operates)
// We get both the canonical and runtime determined form - JitInterface mostly operates
// on the canonical form.
var runtimeDeterminedMethod = (MethodDesc)_methodIL.GetObject(token);
MethodDesc method = runtimeDeterminedMethod;
if (runtimeDeterminedMethod.IsRuntimeDeterminedExactMethod)
method = runtimeDeterminedMethod.GetCanonMethodTarget(CanonicalFormKind.Specific);
var method = (MethodDesc)_canonMethodIL.GetObject(token);

if (method.IsRawPInvoke())
{
Expand Down
25 changes: 25 additions & 0 deletions tests/src/Simple/Generics/Generics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static int Main()
TestFieldAccess.Run();
TestNativeLayoutGeneration.Run();
TestInterfaceVTableTracking.Run();
TestClassVTableTracking.Run();

return 100;
}
Expand Down Expand Up @@ -2121,4 +2122,28 @@ public static void Run()
arr.SetValue(new Gen<Gen<string>>(), new int[] { 0, 0 });
}
}

class TestClassVTableTracking
{
class Unit { }

class Gen<T, U>
{
public virtual int Test()
{
return 42;
}
}

static int Call<T>()
{
return new Gen<T, Unit>().Test();
}

public static void Run()
{
// This only really tests whether we can compile this.
Call<object>();
}
}
}

0 comments on commit 657a366

Please sign in to comment.