-
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
UnsafeAccessor
works with AOT but does not work with JIT for a type of Class<float> shape
#108046
Comments
UnsafeAccessor
works with AOT but does not work with JIT for a type of Class<float> shapeUnsafeAccessor
works with AOT but does not work with JIT for a type of Class<float> shape
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
As a workaround you can use generic wrapper for the accessor (not sure what changed in .NET 9 to require that): using System.Runtime.CompilerServices;
using Google.Protobuf.Collections;
var repeatedField = new RepeatedField<float> { 1.0f, 2.0f, 3.0f };
Console.WriteLine(MyAccessor<float>.ArrayRef(repeatedField).Length); // 8
public class MyAccessor<T>
{
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "array")]
public static extern ref T[] ArrayRef(RepeatedField<T> instance);
} |
Thanks, this works the other way around - on 9 but not on 8 (which does not support unsafe accessor generics), so I'm kind of back to square one 😀 I have simplified the example - does not need Protobuf dependency to repro. |
Tagging subscribers to this area: @dotnet/area-system-runtime-compilerservices |
@neon-sunset The solution here is to use an accessor class, as suggested in #108046 (comment). The The documentation for |
Thanks. This is fair, the only question is the discrepancy with NativeAOT 9.0 where it does continue to work. |
Yes, sadly native AOT has a very different Type System API and in this case was written "properly" in .NET 8.0. Since native AOT must be computed at compile time it is much easier to reason about. The check at run-time in CoreCLR was a bit harder and took me longer to wrap my head around "how" to make it work. The lack of support in .NET 8.0 was simply me not having the knowledge to make it work in the timeframe. |
I see, thank you for the explanation. In this case I ended up unintentionally relying on undocumented behavior where the unsafe accessor for |
Description
It appears that
UnsafeAccessor
may not be working on .NET 9 as expected with JIT configuration, but continues to work with NativeAOT.Reproduction Steps
Given simple program created from a default console template:
Expected behavior
> dotnet run -c Release -f net9.0 8
Actual behavior
> dotnet run -c Release net8.0 8
Regression?
Yes
Known Workarounds
Using reflection 😢
Configuration
but did also reproduce with RC.1
Other information
No response
The text was updated successfully, but these errors were encountered: