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

Remove RawArrayData #110902

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

MichalPetryka
Copy link
Contributor

Removes RawArrayData and makes Array reflect the actual runtime layout instead.

Makes code a bit safer by removing Unsafe.As usages with invalid types.

cc @EgorBo @tannergooding I ended up doing this after the discussion on Discord
cc @jkotas There was one CoreCLR assert here due to array MT creation not setting the field count, I made it set it here in debug to avoid that and any perf impact in release, is that okay to do?

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Dec 23, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Dec 23, 2024
@MichalPetryka
Copy link
Contributor Author

@MihuBot

// This field should be the first field in Array as the runtime/compilers depend on it
private int _numComponents;
#pragma warning restore
internal uint RawLength; // Array._numComponents padded to IntPtr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should follow dotnet/runtime naming conventions for fields.

@jkotas
Copy link
Member

jkotas commented Dec 23, 2024

@jkotas There was one CoreCLR assert here due to array MT creation not setting the field count, I made it set it here in debug to avoid that and any perf impact in release, is that okay to do?

I do not see a problem with this performance wise. However, I expect that there is going to be a long tail of places that are not prepared to handle fields on array type. Some of them may be outside dotnet/runtime. There may be more straightforward (less breaking) ways to get rid of RawArrayData. For example, call object.GetRawData() and cast it to the array layout? Or introduce JIT intrinsics for raw length and raw array data getters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community-contribution Indicates that the PR has been added by a community member needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants