Skip to content

Commit e60db07

Browse files
Emit instantiated types as external references if possible (#105816)
Fixes #105397. The repro case hits an interesting problem in native layout - we emit the `IEnumerable<IEnumerable<double?>>` type as a constructed type, however the components of it are only generated as necessary. Because native layout expresses it as a decomposed instantiation, we're not able to find the type because the component of it is not constructed and we don't really keep track of those. This can be fixed by simply not generating types as composed out of various components.
1 parent 30b34e6 commit e60db07

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public EETypeNode(NodeFactory factory, TypeDesc type)
9191
else if (type.IsCanonicalSubtype(CanonicalFormKind.Any))
9292
Debug.Assert((this is CanonicalEETypeNode) || (this is NecessaryCanonicalEETypeNode));
9393

94+
Debug.Assert(!type.IsGenericParameter);
9495
Debug.Assert(!type.IsRuntimeDeterminedSubtype);
9596
_type = type;
9697
_optionalFieldsNode = new EETypeOptionalFieldsNode(this);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ internal sealed class NativeLayoutMethodLdTokenVertexNode : NativeLayoutMethodEn
232232
protected override string GetName(NodeFactory factory) => "NativeLayoutMethodLdTokenVertexNode_" + factory.NameMangler.GetMangledMethodName(_method);
233233

234234
public NativeLayoutMethodLdTokenVertexNode(NodeFactory factory, MethodDesc method)
235-
: base(factory, method, 0)
235+
: base(factory, method, method.IsRuntimeDeterminedExactMethod || method.IsGenericMethodDefinition ? 0 : MethodEntryFlags.CreateInstantiatedSignature)
236236
{
237237
}
238238

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ internal static int Run()
5858
Test99198Regression.Run();
5959
Test102259Regression.Run();
6060
Test104913Regression.Run();
61+
Test105397Regression.Run();
6162
TestInvokeMemberCornerCaseInGenerics.Run();
6263
TestRefAny.Run();
6364
TestNullableCasting.Run();
@@ -3629,6 +3630,31 @@ public static void Run()
36293630
}
36303631
}
36313632

3633+
class Test105397Regression
3634+
{
3635+
interface IEnumerable<T> { }
3636+
3637+
interface ITest<TResult>
3638+
{
3639+
TReturn UsingDatabaseResult<TState, TReturn>(TState state, Func<TResult, TState, TReturn> @using);
3640+
}
3641+
class Test<TResult> : ITest<TResult>
3642+
{
3643+
public TReturn UsingDatabaseResult<TState, TReturn>(TState state, Func<TResult, TState, TReturn> @using)
3644+
{
3645+
return default;
3646+
}
3647+
}
3648+
3649+
struct GenStruct<T> { }
3650+
3651+
public static void Run()
3652+
{
3653+
ITest<object> t = new Test<object>();
3654+
t.UsingDatabaseResult<IEnumerable<IEnumerable<GenStruct<double>>>, int>(null, (x, y) => 1);
3655+
}
3656+
}
3657+
36323658
class TestInvokeMemberCornerCaseInGenerics
36333659
{
36343660
class Generic<T>

0 commit comments

Comments
 (0)