-
Notifications
You must be signed in to change notification settings - Fork 5k
Use Unsafe.BitCast
for generic span casting
#109136
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
Conversation
cc: @fanyang-mono |
d55b468
to
f488388
Compare
@MihuBot -mono |
The bot doesn't support mono |
Tagging subscribers to this area: @dotnet/area-meta |
One of our main focuses currently is to reduce unsafe code in the repo (ideally, with zero performance impact, but we might tolerate small regressions in favor of memory safety), see #94941. This change seems to replace one unsafe pattern with another. Or in case of |
|
All of our uses of "unsafe" constructs are safe; otherwise they'd be bugs to be fixed. The desire to reduce the reliance on such constructs is to reduce the possibility that we might make a mistake, allowing normal runtime protections to be in effect. |
Alternative to dotnet#109136
I've tried just making MemoryMarshal use BitCast internally but that gives 0 diffs anyway so not sure either of the changes makes sense. |
Something similar has already been tried: #100750 |
Let's not move forward with this for now - it is replacing one unsafe API with another. I agree that BitCast might be a tiny bit more safer, but it looks uglier and more verbose and, like I said, still is unsafe |
Related:
MemoryMarshal.Cast
for same type #100750where T : allows ref struct
in runtime #102795