Skip to content

Commit e4bbf7e

Browse files
Handle calls to shared generic interfaces from shared generic code (#117210)
- The implementation uses the true LDVIRTFTN path for this. Since it thunks to using function pointer the perf is likely not ideal, but we will need a new generic dictionary entry kind to make this simple, and I'd like to avoid making that change to unblock progress here - This expensive path was probably fine for use with virtual generic methods, but regular interface dispatch shouldn't be this expensive, so we'll want to fix this later
1 parent ecdfb14 commit e4bbf7e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/coreclr/interpreter/compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2888,7 +2888,7 @@ void InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool re
28882888
break;
28892889

28902890
case CORINFO_VIRTUALCALL_LDVIRTFTN:
2891-
if (callInfo.sig.sigInst.methInstCount != 0)
2891+
if ((callInfo.sig.sigInst.methInstCount != 0) || (m_compHnd->getClassAttribs(resolvedCallToken.hClass) & CORINFO_FLG_SHAREDINST))
28922892
{
28932893
assert(extraParamArgLocation == INT_MAX);
28942894
// We should not have a type argument for the ldvirtftn path since we don't know

src/tests/JIT/interpreter/Interpreter.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,7 @@ private static Type LoadType<T>()
18891889
return typeof(T);
18901890
}
18911891

1892-
class GenericClass<T>
1892+
class GenericClass<T> : IGeneric<T>
18931893
{
18941894
public Type GetTypeOfTInstance()
18951895
{
@@ -1899,6 +1899,11 @@ public static Type GetTypeOfTStatic()
18991899
{
19001900
return typeof(T);
19011901
}
1902+
1903+
Type IGeneric<T>.Method()
1904+
{
1905+
return typeof(T);
1906+
}
19021907
}
19031908

19041909
public static bool TestSharedGenerics_IsInst<T>(object o)
@@ -2216,6 +2221,11 @@ public static bool TestSharedGenerics_CallsTo()
22162221
return true;
22172222
}
22182223

2224+
interface IGeneric<T>
2225+
{
2226+
Type Method();
2227+
}
2228+
22192229
public static bool TestGenerics_CallsFrom<T>()
22202230
{
22212231
if (LoadType<T>() != typeof(T))
@@ -2227,6 +2237,9 @@ public static bool TestGenerics_CallsFrom<T>()
22272237
if (GenericClass<T>.GetTypeOfTStatic() != typeof(T))
22282238
return false;
22292239

2240+
if (((IGeneric<T>)new GenericClass<T>()).Method() != typeof(T))
2241+
return false;
2242+
22302243
return true;
22312244
}
22322245

0 commit comments

Comments
 (0)