Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always create constructed MethodTable for MdArray & co. #103696

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,19 @@ protected override DependencyList ComputeNonRelocationBasedDependencies(NodeFact
if (_type.IsInterface)
dependencies.Add(factory.InterfaceUse(_type.GetTypeDefinition()), "Interface is used");

// Array types that don't have generic interface methods can be created out of thin air
// at runtime by the type loader. We should never emit non-constructed forms of these MethodTables.
// There's similar logic for generic types, but that one is a conditional dependency conditioned
// on the presence of the type loader template for the canonical form of the type.
if (_type.IsArrayTypeWithoutGenericInterfaces())
{
IEETypeNode maximallyConstructableType = factory.MaximallyConstructableType(_type);
if (maximallyConstructableType != this)
{
dependencies.Add(maximallyConstructableType, "Type is template-loadable");
}
}

if (EmitVirtualSlots)
{
if (!_type.IsArrayTypeWithoutGenericInterfaces())
Expand Down
16 changes: 16 additions & 0 deletions src/tests/nativeaot/SmokeTests/Reflection/Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ private static int Main()
TestGenericMethodOnGenericType.Run();
TestIsValueTypeWithoutTypeHandle.Run();
TestMdArrayLoad.Run();
TestMdArrayLoad2.Run();
TestByRefTypeLoad.Run();
TestGenericLdtoken.Run();
TestAbstractGenericLdtoken.Run();
Expand Down Expand Up @@ -2443,6 +2444,21 @@ public static void Run()
}
}

class TestMdArrayLoad2
{
class Atom { }

public static object MakeMdArray<T>() => new T[1,1,1];

public static void Run()
{
var mi = typeof(TestMdArrayLoad2).GetMethod(nameof(MakeMdArray)).MakeGenericMethod(GetAtom());
if (mi.Invoke(null, Array.Empty<object>()) is not Atom[,,])
throw new Exception();
static Type GetAtom() => typeof(Atom);
}
}

class TestByRefTypeLoad
{
class Atom { }
Expand Down
Loading