Skip to content

Conversation

@VSadov
Copy link
Member

@VSadov VSadov commented Jul 13, 2025

Fixes: #110962

Specifying .size on an InlineArray struct only brings confusion to whether it applies to the element or to thr entire instance. It Either result is a fairly niche scenario and can be achieved via defining wrapping structs.

Notes:

  • .size is disallowed in either sequential or auto layouts.
  • .pack is allowed. Unlike .size, there is no ambiguity with .pack - it has no effect in structs with all fields having the same type, regardless of 1 or N fields.

@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 Jul 13, 2025
@jkotas jkotas added area-TypeSystem-coreclr and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jul 13, 2025
@VSadov VSadov marked this pull request as ready for review July 14, 2025 15:26
@Copilot Copilot AI review requested due to automatic review settings July 14, 2025 15:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR disallows inline arrays annotated with an explicit size by enforcing runtime checks and updating related resources and tests.

  • Added new loader IL and C# tests for explicit-size inline arrays
  • Implemented explicit-size checks in both Mono (class-init.c) and CoreCLR (methodtablebuilder.cpp, MetadataFieldLayoutAlgorithm.cs)
  • Introduced new resource strings and exception IDs for inline-array explicit-size errors

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/tests/Loader/classloader/InlineArray/InvalidCSharpInlineArray.il Added IL test for explicit-size inline array
src/tests/Loader/classloader/InlineArray/InlineArrayInvalid.csproj Set test priority for invalid inline array tests
src/tests/Loader/classloader/InlineArray/InlineArrayInvalid.cs Added ExplicitSize_Fails Xunit test
src/mono/mono/metadata/class-init.c Added explicit-size inline-array failure callback
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx Added resource string for explicit-size inline-array error
src/coreclr/vm/methodtablebuilder.cpp Throw exception for explicit-size inline-array in method table
src/coreclr/tools/Common/TypeSystem/Common/Properties/Resources.resx Added resource for type-system inline-array explicit-size
src/coreclr/tools/Common/TypeSystem/Common/MetadataFieldLayoutAlgorithm.cs Checked for explicit-size inline-array during layout computation
src/coreclr/tools/Common/TypeSystem/Common/ExceptionStringID.cs Added exception string ID for inline-array explicit-size
src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/TypeLoaderExceptionHelper.cs Mapped TypeSystem exception to resource string
src/coreclr/dlls/mscorrc/resource.h Defined new resource ID for explicit-size inline-array error
src/coreclr/dlls/mscorrc/mscorrc.rc Added message text for explicit-size inline-array error

@VSadov VSadov requested review from jkotas and removed request for steveisok, thaystg and vitek-karas July 14, 2025 20:57
@jkotas
Copy link
Member

jkotas commented Jul 14, 2025

Does this need to be marked as a breaking change?

@VSadov
Copy link
Member Author

VSadov commented Jul 14, 2025

Does this need to be marked as a breaking change?

This can break some existing program (if such exist), so technically yes.

@VSadov VSadov added the breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. label Jul 14, 2025
@dotnet-policy-service dotnet-policy-service bot added the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Jul 14, 2025
@dotnet-policy-service
Copy link
Contributor

dotnet-policy-service bot commented Jul 14, 2025

Added needs-breaking-change-doc-created label because this PR has the breaking-change label.

When you commit this breaking change:

  1. Create and link to this PR and the issue a matching issue in the dotnet/docs repo using the breaking change documentation template, then remove this needs-breaking-change-doc-created label.
  2. Ask a committer to mail the .NET Breaking Change Notification DL.

Tagging @dotnet/compat for awareness of the breaking change.

@VSadov
Copy link
Member Author

VSadov commented Jul 17, 2025

/ba-g cryptography failures on musl, wasm timing out

@VSadov VSadov merged commit 8415c8c into dotnet:main Jul 17, 2025
146 of 154 checks passed
@VSadov
Copy link
Member Author

VSadov commented Jul 17, 2025

Thanks!

@VSadov VSadov deleted the inlSize branch July 17, 2025 08:04
@VSadov
Copy link
Member Author

VSadov commented Jul 17, 2025

Breaking change issue - dotnet/docs#47435

@github-actions github-actions bot locked and limited conversation to collaborators Aug 16, 2025
@ericstj ericstj removed the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Oct 2, 2025
@ericstj
Copy link
Member

ericstj commented Oct 2, 2025

Removing needs-breaking-change-doc-created label as this PR already has a documentation issue: dotnet/docs#47435

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-TypeSystem-coreclr breaking-change Issue or PR that represents a breaking API or functional change over a prerelease.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InlineArray reports wrong size when struct size is specified

3 participants