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

ILC error when using a function pointer type nested under a generic type #81117

Closed
steveharter opened this issue Jan 24, 2023 · 5 comments · Fixed by #81147 or #81344
Closed

ILC error when using a function pointer type nested under a generic type #81117

steveharter opened this issue Jan 24, 2023 · 5 comments · Fixed by #81147 or #81344

Comments

@steveharter
Copy link
Member

steveharter commented Jan 24, 2023

Although a function pointer type can't be a generic type parameter, it can be an element type of an array, which the array type can then be a generic type parameter. Doing that causes a publish error (works on CoreClr and Mono at runtime).

Attempting to public this:

Console.WriteLine("Before");
Type t = typeof(Tuple<delegate*<void>[]>);
Console.WriteLine("Success");
Console.WriteLine(t);

results in:

2>"C:\Users\sharter\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.2\tools\\ilc" @"obj\Release\net7.0\win-x64\native\ConsoleApp109.ilc.rsp"
2>Failed to load type 'Void (Boolean ByRef)[]' from assembly '?'
2>Internal.TypeSystem.TypeSystemException+TypeLoadException: Failed to load type 'Void (Boolean ByRef)[]' from assembly '?'
2>   at Internal.TypeSystem.ThrowHelper.ThrowTypeLoadException(ExceptionStringID, String, String) in /_/src/coreclr/tools/Common/TypeSystem/Common/ThrowHelper.cs:line 17
2>   at Internal.TypeSystem.ThrowHelper.ThrowTypeLoadException(ExceptionStringID, TypeDesc) in /_/src/coreclr/tools/Common/TypeSystem/Common/ThrowHelper.Common.cs:line 51
2>   at ILCompiler.DependencyAnalysis.EETypeNode..ctor(NodeFactory, TypeDesc) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs:line 82
2>   at ILCompiler.DependencyAnalysis.NodeFactory.CreateNecessaryTypeNode(TypeDesc) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs:line 514
2>   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey, Func`2)
2>   at ILCompiler.DependencyAnalysis.GenericCompositionNode.GetData(NodeFactory, Boolean ) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/GenericCompositionNode.cs:line 90
2>   at ILCompiler.DependencyAnalysis.ObjectNode.GetStaticDependencies(NodeFactory) in /_/src/coreclr/tools/Common/Compiler/DependencyAnalysis/ObjectNode.cs:line 60
2>   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependenciesImpl(DependencyNodeCore`1) in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 181
2>   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependencies(DependencyNodeCore`1) in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 221
2>   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ProcessMarkStack() in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 256
2>   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes() in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 307
2>   at ILCompiler.ILScanner.ILCompiler.IILScanner.Scan() in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs:line 140
2>   at ILCompiler.Program.<Run>g__RunScanner|73_4(<>c__DisplayClass73_0&) in /_/src/coreclr/tools/aot/ILCompiler/Program.cs:line 884
2>   at ILCompiler.Program.Run(String[]) in /_/src/coreclr/tools/aot/ILCompiler/Program.cs:line 866
2>   at ILCompiler.Program.Main(String[]) in /_/src/coreclr/tools/aot/ILCompiler/Program.cs:line 1150

See this for more detail:
https://github.com/dotnet/runtime/pull/81006/files/f76c75dff31537a28208060c734dee688265039e#r1085734728

UPDATE: after additional test failures, there is a simpler repo: typeof(delegate*<void>[]);

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jan 24, 2023
@ghost
Copy link

ghost commented Jan 24, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

Although a function pointer type can't be a generic type parameter, it can be an element type of an array, which the array type can then be a generic type parameter. Doing that causes a publish error (works on CoreClr and Mono at runtime).

Attempting to public this:

Console.WriteLine("Before");
Type t = typeof(Tuple<delegate*<void>[]>);
Console.WriteLine("Success");
Console.WriteLine(t);

results in:

2>"C:\Users\sharter\.nuget\packages\runtime.win-x64.microsoft.dotnet.ilcompiler\7.0.2\tools\\ilc" @"obj\Release\net7.0\win-x64\native\ConsoleApp109.ilc.rsp"
2>Failed to load type 'Void (Boolean ByRef)[]' from assembly '?'
2>Internal.TypeSystem.TypeSystemException+TypeLoadException: Failed to load type 'Void (Boolean ByRef)[]' from assembly '?'
2>   at Internal.TypeSystem.ThrowHelper.ThrowTypeLoadException(ExceptionStringID, String, String) in /_/src/coreclr/tools/Common/TypeSystem/Common/ThrowHelper.cs:line 17
2>   at Internal.TypeSystem.ThrowHelper.ThrowTypeLoadException(ExceptionStringID, TypeDesc) in /_/src/coreclr/tools/Common/TypeSystem/Common/ThrowHelper.Common.cs:line 51
2>   at ILCompiler.DependencyAnalysis.EETypeNode..ctor(NodeFactory, TypeDesc) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs:line 82
2>   at ILCompiler.DependencyAnalysis.NodeFactory.CreateNecessaryTypeNode(TypeDesc) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs:line 514
2>   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey, Func`2)
2>   at ILCompiler.DependencyAnalysis.GenericCompositionNode.GetData(NodeFactory, Boolean ) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/GenericCompositionNode.cs:line 90
2>   at ILCompiler.DependencyAnalysis.ObjectNode.GetStaticDependencies(NodeFactory) in /_/src/coreclr/tools/Common/Compiler/DependencyAnalysis/ObjectNode.cs:line 60
2>   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependenciesImpl(DependencyNodeCore`1) in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 181
2>   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependencies(DependencyNodeCore`1) in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 221
2>   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ProcessMarkStack() in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 256
2>   at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes() in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 307
2>   at ILCompiler.ILScanner.ILCompiler.IILScanner.Scan() in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs:line 140
2>   at ILCompiler.Program.<Run>g__RunScanner|73_4(<>c__DisplayClass73_0&) in /_/src/coreclr/tools/aot/ILCompiler/Program.cs:line 884
2>   at ILCompiler.Program.Run(String[]) in /_/src/coreclr/tools/aot/ILCompiler/Program.cs:line 866
2>   at ILCompiler.Program.Main(String[]) in /_/src/coreclr/tools/aot/ILCompiler/Program.cs:line 1150

See this for more detail:
https://github.com/dotnet/runtime/pull/81006/files/f76c75dff31537a28208060c734dee688265039e#r1085734728

Author: steveharter
Assignees: -
Labels:

area-NativeAOT-coreclr

Milestone: -

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jan 25, 2023
@ghost ghost removed in-pr There is an active PR which will close this issue when it is merged untriaged New issue has not been triaged by the area owner labels Jan 25, 2023
@steveharter
Copy link
Member Author

@MichalStrehovsky this still occurs for typeof(delegate*<void>[]);

@MichalStrehovsky
Copy link
Member

@MichalStrehovsky this still occurs for typeof(delegate*<void>[]);

I can't repro that. Do you have the latest main? Is the stack the same?

I could believe you can hit it with a different stack - when C# added function pointers, we did enough work to make things not crash, but since the runtime behaviors were undefined, we just whack everything to IntPtr and it's possible there's another place that doesn't whack it.

@steveharter
Copy link
Member Author

I can't repro that. Do you have the latest main? Is the stack the same?

I did sync to main after your change.

Here was the last error in CI (tests since then have been commented out):

EXEC : error : Failed to load type 'Void (Boolean ByRef)[]' from assembly '?' [D:\a\_work\1\s\src\libraries\System.Runtime\tests\System.Runtime.Tests.csproj::TargetFramework=net8.0-windows]
##[error]EXEC(0,0): error : (NETCORE_ENGINEERING_TELEMETRY=Build) Failed to load type 'Void (Boolean ByRef)[]' from assembly '?'
  Internal.TypeSystem.TypeSystemException+TypeLoadException: Failed to load type 'Void (Boolean ByRef)[]' from assembly '?'
     at Internal.TypeSystem.ThrowHelper.ThrowTypeLoadException(ExceptionStringID id, String typeName, String assemblyName) in /_/src/coreclr/tools/Common/TypeSystem/Common/ThrowHelper.cs:line 17
     at ILCompiler.DependencyAnalysis.EETypeNode..ctor(NodeFactory factory, TypeDesc type) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs:line 89
     at ILCompiler.DependencyAnalysis.NodeFactory.CreateNecessaryTypeNode(TypeDesc type) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs:line 514
     at Internal.TypeSystem.LockFreeReaderHashtable`2.CreateValueAndEnsureValueIsInTable(TKey key) in /_/src/coreclr/tools/Common/TypeSystem/Common/Utilities/LockFreeReaderHashtable.cs:line 562
     at ILCompiler.DependencyAnalysis.NodeFactory.NecessaryTypeSymbol(TypeDesc type) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs:line 589
     at ILCompiler.DependencyAnalysis.GenericCompositionNode.GetDehydratableData(NodeFactory factory, Boolean relocsOnly) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/GenericCompositionNode.cs:line 95
     at ILCompiler.DependencyAnalysis.DehydratableObjectNode.GetData(NodeFactory factory, Boolean relocsOnly) in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/DehydratableObjectNode.cs:line 19
     at ILCompiler.DependencyAnalysis.ObjectNode.GetStaticDependencies(NodeFactory factory) in /_/src/coreclr/tools/Common/Compiler/DependencyAnalysis/ObjectNode.cs:line 59
     at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependenciesImpl(DependencyNodeCore`1 node) in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 182
     at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.GetStaticDependencies(DependencyNodeCore`1 node) in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 222
     at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ProcessMarkStack() in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 257
     at ILCompiler.DependencyAnalysisFramework.DependencyAnalyzer`2.ComputeMarkedNodes() in /_/src/coreclr/tools/aot/ILCompiler.DependencyAnalysisFramework/DependencyAnalyzer.cs:line 308
     at ILCompiler.ILScanner.ILCompiler.IILScanner.Scan() in /_/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs:line 140
     at ILCompiler.Program.<Run>g__RunScanner|3_0(<>c__DisplayClass3_0&) in /_/src/coreclr/tools/aot/ILCompiler/Program.cs:line 416
     at ILCompiler.Program.Run() in /_/src/coreclr/tools/aot/ILCompiler/Program.cs:line 396
     at ILCompiler.ILCompilerRootCommand.<>c__DisplayClass200_0.<.ctor>b__0(InvocationContext context) in /_/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs:line 269
D:\a\_work\1\s\artifacts\bin\coreclr\windows.arm64.Release\build\Microsoft.NETCore.Native.targets(281,5): error MSB3073: The command ""D:\a\_work\1\s\artifacts\bin\coreclr\windows.arm64.Release\x64\ilc\\ilc" @"D:\a\_work\1\s\artifacts\obj\System.Runtime.Tests\Release\net8.0-windows\native\System.Runtime.Tests.ilc.rsp"" exited with code 1. [D:\a\_work\1\s\src\libraries\System.Runtime\tests\System.Runtime.Tests.csproj::TargetFramework=net8.0-windows]

The commented out areas are here: https://github.com/dotnet/runtime/pull/81006/files#diff-bb1e2397e5ebf8ae1c225d15c3155863faf5091de2a3c0f74e47c4f5e280a57b

           // NOTE: commented out due to compiler issue on NativeAOT: #81117
            //public static volatile Tuple<delegate*<out bool, void>[]> _arrayGenericFcnPtr;

            // NOTE: commented out due to compiler issue on NativeAOT: #81117
            //public static void M_ArrayOpenGenericFcnPtr<T>(T t, delegate*<out bool, void>[] fp) { }

            // NOTE: commented out due to compiler issue on NativeAOT: #81117
            //public delegate*
            //<
            //    delegate*<int>, // p0
            //    delegate*       // p1
            //    <
            //        delegate*<byte>, // p0
            //        delegate*<int>,  // p1
            //        delegate* unmanaged[Cdecl]<long>, // p2
            //        void // ret
            //    >,
            //    bool // ret
            //>[] Property_FcnPtr_Complex { get; }

MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this issue Jan 30, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jan 30, 2023
@MichalStrehovsky
Copy link
Member

Yep, this was from a different spot than typeof. Hopefully #81344 will address all the remaining issues.

@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jan 30, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Mar 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants