Skip to content

Commit 96ef47b

Browse files
Include method instantiation MethodTables in compilation (#66984)
* Include method instantiation MethodTables in compilation We'll need to load the `MethodTable` so that we can search for it in GVM tables. * Regression test
1 parent 970a7e2 commit 96ef47b

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NativeLayoutVertexNode.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,9 @@ private IEnumerable<DependencyListEntry> GetGenericVirtualMethodDependencies(Nod
253253
{
254254
var dependencies = (DependencyList)base.GetStaticDependencies(factory);
255255

256-
dependencies.Add(factory.GVMDependencies(_method.GetCanonMethodTarget(CanonicalFormKind.Specific)), "Potential generic virtual method call");
256+
MethodDesc canonMethod = _method.GetCanonMethodTarget(CanonicalFormKind.Specific);
257+
258+
dependencies.Add(factory.GVMDependencies(canonMethod), "Potential generic virtual method call");
257259

258260
// Variant generic virtual method calls at runtime might need to build the concrete version of the
259261
// type we could be dispatching on to find the appropriate GVM entry.
@@ -262,6 +264,11 @@ private IEnumerable<DependencyListEntry> GetGenericVirtualMethodDependencies(Nod
262264
GenericTypesTemplateMap.GetTemplateTypeDependencies(ref dependencies, factory, _method.OwningType.ConvertToCanonForm(CanonicalFormKind.Specific));
263265
}
264266

267+
foreach (TypeDesc instArg in canonMethod.Instantiation)
268+
{
269+
dependencies.Add(factory.MaximallyConstructableType(instArg), "Type we need to look up for GVM dispatch");
270+
}
271+
265272
return dependencies;
266273
}
267274

src/tests/nativeaot/SmokeTests/UnitTests/Generics.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ internal static int Run()
4444
TestGenericRecursionFromNpgsql.Run();
4545
TestRecursionInGenericVirtualMethods.Run();
4646
TestRecursionThroughGenericLookups.Run();
47+
TestGvmLookupDependency.Run();
4748
#if !CODEGEN_CPP
4849
TestNullableCasting.Run();
4950
TestVariantCasting.Run();
@@ -3147,4 +3148,24 @@ public static void Run()
31473148
new RangeHandler<object>().Write(default);
31483149
}
31493150
}
3151+
3152+
static class TestGvmLookupDependency
3153+
{
3154+
struct SmallCat<T> { }
3155+
3156+
interface ITechnique
3157+
{
3158+
void CatSlaps<T>() { /* Cannot reference T or it stops testing the thing it should */ }
3159+
}
3160+
3161+
struct Technique : ITechnique { }
3162+
3163+
static void CatConcepts<T, U>() where T : ITechnique => default(T).CatSlaps<SmallCat<U>>();
3164+
3165+
public static void Run()
3166+
{
3167+
CatConcepts<Technique, int>();
3168+
CatConcepts<Technique, object>();
3169+
}
3170+
}
31503171
}

0 commit comments

Comments
 (0)