-
Notifications
You must be signed in to change notification settings - Fork 509
NotImplementedException thrown when trying to compile with function pointers #8199
Comments
Are you using function pointers? ( https://github.com/dotnet/csharplang/blob/master/proposals/function-pointers.md ) corert/src/ILCompiler.Compiler/src/Compiler/MetadataManager.cs Lines 662 to 663 in 343a4ac
|
..yeah that will be it. I was told they were supported by someone else, apologies cc @reflectronic 😒 |
@MichalStrehovsky, is there an existing issue tracking function pointer support? Seems like it might be worth it given the language support being added and the runtime support being extended ( |
That shouldn't be too hard to fix or workaround, this code is responsible for detecting if it's permitted to reflect upon that. CoreRT supports |
@john-h-k do you have sample code that triggers this? And how did you compile it 😅 ? I'm using latest VS2019 preview and .NET 5.0 Preview 4 but this isn't recognized but sharplab on roslyn master branch compiles it. |
The sample code is just a method that takes a funcptr. I used the preview tooling on roslyn's MyGet feed Specifically
|
It's basically as simple as: <PropertyGroup>
<RestoreSources>
https://api.nuget.org/v3/index.json;
https://dotnet.myget.org/F/roslyn/api/v3/index.json;
</RestoreSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="3.7.0-3.20302.9" />
</ItemGroup> Noting that |
I'm using <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>preview</LangVersion>
<RestoreSources>
https://api.nuget.org/v3/index.json;
https://dotnet.myget.org/F/roslyn/api/v3/index.json;
https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json;
</RestoreSources>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.DotNet.ILCompiler" Version="1.0.0-alpha-*" />
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="3.7.0-3.20302.9">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project> and using System;
namespace ConsoleApp92
{
unsafe class Program
{
public static void Log()
{
Console.WriteLine("Works!");
}
public static void Test(delegate*<void> del)
{
del();
}
static void Main(string[] args)
{
delegate*<void> a1 = &Log; // Log()
Test(a1);
}
}
} which compiles fine with
|
Ah, i've got it, |
This code is responsible for figuring out whether the type is potentially visible from reflection. Types that are not visible from reflection can have more optimizations applied to them.
Nope, it will probably just come down to a bug or two. Most of the system is aware of them (the place that is throwing is aware too, I was just lazy to implement the ~10 lines to handle it. @Suchiman The method needs to be non-virtual generic to trigger the bug. |
Is it basically just |
The fix will be to cast to a |
@MichalStrehovsky oh here's another one corert/src/ILCompiler.Compiler/src/Compiler/DependencyAnalysis/NativeLayoutVertexNode.cs Lines 382 to 384 in 343a4ac
|
That one you can probably hit with: class P
{
static Type Gimme<T>() => typeof(delegate*<T>);
static void Main()
{
typeof(P).GetMethod("Gimme").MakeGenericMethod(typeof(object)).Invoke(null, Array.Empty<Type>();
}
} The fix for that right now would be just to pretend it's an IntPtr, but that might change depending on how dotnet/runtime#11354 turns out. |
I actually did hit it with this code, i still didn't manage to hit the original issue in of this case 😆 using System;
unsafe class Program
{
static void Log()
{
Console.WriteLine("Works!");
}
static void Test<T>(delegate*<void> del)
{
del();
}
static void Main(string[] args)
{
delegate*<void> a1 = &Log; // Log()
Test<string>(a1);
}
} |
I try to build my project as the samples suggest (The project doesn't use reflection anywhere, unless 'REFLECTION' is defined which it isn't here).
I get this output with absolutely nothing else
The text was updated successfully, but these errors were encountered: