Skip to content

Share some array code between CoreCLR and NativeAOT #116903

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

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

Conversation

huoyaoyuan
Copy link
Member

Shares the major logic of Copy and Clear, cleared some others.

Using coreclr behavior has source of truth. NativeAOT didn't support primitive widen for enum->enum.

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 22, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jun 22, 2025
{
if (array == null)
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
int rank = this.GetMethodTable()->MultiDimensionalArrayRank;
Copy link
Member

Choose a reason for hiding this comment

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

You have update this to match CoreCLR impl. Should it be moved to shared part as well?

Copy link
Member

Choose a reason for hiding this comment

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

It is ok to pay the extra addition for non-zero lower bounds, even though they are not supported in native aot currently.

If we want to avoid it, we can introduce a static bool IsNonZeroLowerBoundSupported property on Array that return returns true on CoreCLR and false on NAOT, and use it to avoid the unnecessary addition.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, then GetLowerBound/GetUpperBound/GetLength can be unified too.

@filipnavara
Copy link
Member

Good job. At least the System.Tests.ArrayTests.Copy_SourceAndDestinationPointers_ThrowsArrayTypeMismatchException test failure on windows/osx-arm64 seems relevant.

@huoyaoyuan
Copy link
Member Author

At least the System.Tests.ArrayTests.Copy_SourceAndDestinationPointers_ThrowsArrayTypeMismatchException test failure on windows/osx-arm64 seems relevant.

Yes I've mentioned it, I'm having trouble for running nativeaot tests locally, or mapping the throwing offset to code.

@filipnavara
Copy link
Member

Not sure if it helps but in debug build it asserts here:

  Process terminated. Assertion failed.
  we expect type definitions here
     at System.Diagnostics.DebugProvider.Fail(String, String) + 0x50
     at System.Diagnostics.Debug.Fail(String, String) + 0x5c
     at System.Diagnostics.Debug.Assert(Boolean, String, String) + 0x48
     at System.Diagnostics.Debug.Assert(Boolean, String) + 0x2c
     at Internal.Runtime.MethodTable.get_NonArrayBaseType() + 0x80
     at Internal.Runtime.WellKnownEETypes.IsSystemObject(MethodTable*) + 0x48
     at System.Array.CanAssignArrayType(Array sourceArray, Array destinationArray) + 0x2f4
     at System.Array.CopyImpl(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable) + 0x34c
     at System.Array.Copy(Array sourceArray, Array destinationArray, Int32 length) + 0x260
     at System.Tests.ArrayTests.<>c.<Copy_SourceAndDestinationPointers_ThrowsArrayTypeMismatchException>b__69_2() + 0x50
     at Xunit.Assert.RecordException(Action) + 0x54
     at System.Runtime!<BaseAddress>+0x295a608
     at System.Tests.ArrayTests.Copy_SourceAndDestinationPointers_ThrowsArrayTypeMismatchException() + 0x288

@huoyaoyuan
Copy link
Member Author

OK, I was thinking no exception was thrown and the pointer types passed assignment test, and figuring out which line passes. Thanks for pointing out the failing stack trace.

@huoyaoyuan
Copy link
Member Author

I see. I was trying to use filter and dotnet test instead of dotnet build -t:test for aot test. It seems that the testing command is different for aot. Now I can reproduce at local.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-coreclr community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants