-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Representation of function pointer types in the reflection stack #11354
Comments
@MichalStrehovsky marked future. |
Do you know off the top of your head how complicated it is to do the first one? |
No, I didn't look into it beyond trying that single line and being happy that I didn't have to add any extra work to .NET Native/CoreRT backlog at that time. |
Sample syntax below - here's a method that takes a function pointer of type public unsafe static void M(delegate*<int, void> ptr) {
} |
We should do this for 5.0 since function pointers support is being added imminently. |
I hope the "we should do this for 5.0" still applies and we're tracking this as part of the overall function pointers work. |
At the moment it's not currently funded for 5.0 - it's more of a stretch goal. If it's blocking you let us know and we can mark it as such. Then we can pull resources from other things to address it. |
Yeah this is pretty impactful since I'm wanting to freeze these objects and it is not possible to find which are fnptrs arrays. I'm ok if I can work around it somehow but I don't think I'm able to. |
@GrabYourPitchforks I see you self-assigned this, does this mean it'll happen in 5.0?! |
Still not funded, but I'm growing increasingly worried that if we don't address it in 5.0 it'll be too difficult to address in 6.0 due to compat. So going to see if we can slam this in at the last minute. It'll definitely be a roller coaster. :) |
Now that 5.0 has released, and I'm switching my functions that used to take IntPtr to function pointers, I'm running into this issue. I have the following interface (simplified of course)
I'm generating at runtime using Reflection.Emit an implementation of this interface. However, with function pointers, this does not seem possible. When I iterate the parameters of that function, the parameter just shows up as an IntPtr, with now way to detect its a function pointer. If I generate the function using IntPtr, the signature doesn't match, and the importer fails with a TypeLoadException basically that the interface is not implemented. |
CoreCLR and Mono reflection stacks represent function pointers differently today. For examle, |
Moving to 8.0; we need to update the API and design based on feedback from #71516. |
FWIW the jit currently mis-optimizes some cases involving function type comparison. The fix is in #72136 where the jit will defer to the runtime to decide what sort of optimizations can apply. If/when the runtime type for function pointers changes those new bits of jit interface can potentially be revised to enable a little more optimization. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
What's the status of this? I hope |
Currently a design is being created. The reflection features for 8.0 are tracked here.
This will be covered in the design. Here's the current section: System.PointerThe System.Reflection.Pointer class is useful to pass a pointer address and type together and was introduced to pass a pointer using reflection APIs which are based on passing arrays of There is no proposal here to either extend |
The design is ready for review at dotnet/designs#282 |
Closing; implemented in #81006 |
dotnet/csharplang#1951 discusses adding function pointer types to the C# language. The CLR has supported these for a while, but there are areas (such as the reflection stack), where function pointer types are weird/unhandled.
While this will just be a corner area of the C# language, we should probably at least track this:
ldtoken method explicit instance int32 *(int32)
not to return the token ofSystem.IntPtr
?System.Reflection.Pointer
to reflection invoke methods that take/return function pointers?The text was updated successfully, but these errors were encountered: