Skip to content

Comments

Migrate SpanArr inline array from InvalidCSharp*.il to C##123736

Draft
Copilot wants to merge 10 commits intomainfrom
copilot/migrate-valid-csharp-types
Draft

Migrate SpanArr inline array from InvalidCSharp*.il to C##123736
Copilot wants to merge 10 commits intomainfrom
copilot/migrate-valid-csharp-types

Conversation

Copy link
Contributor

Copilot AI commented Jan 28, 2026

Description

This PR migrates the SpanArr inline array type from InvalidCSharpInlineArray.il to C# to reduce maintenance burden and demonstrate language evolution with C# 12+ inline arrays.

After thorough investigation and multiple iterations addressing build failures, only the SpanArr type could be successfully migrated. All other types in the InvalidCSharp*.il files must remain in IL due to either C# language limitations or IL self-referencing constraints.

Changes

Ref Struct Inline Arrays (C# 12+) - InlineArray/InvalidCSharpInlineArray.ilInlineArrayValid.cs

  • SpanArr - ref struct inline array with 100 Span<object> elements

Types Not Migrated

RefFields - C# language limitations:

  • WithRefField, WithRefStructField, WithTypedReferenceField<T>
  • C# doesn't support ref fields to ref structs (CS9050) or TypedReference fields (CS0610)

ByRefLike - IL self-referencing constraints:

  • All types in ByRefLike/InvalidCSharp.il remain unchanged (reverted to original state)
  • Types are referenced directly within the same IL file
  • IL files cannot reference types from C# assemblies being built in parallel

Example

Before (IL):

.class public sequential ansi sealed beforefieldinit SpanArr
    extends [System.Runtime]System.ValueType
{
    .custom instance void [System.Runtime]System.Runtime.CompilerServices.IsByRefLikeAttribute::.ctor()
    .custom instance void [System.Runtime]System.Runtime.CompilerServices.InlineArrayAttribute::.ctor(int32)
    .field public valuetype [System.Runtime]System.Span`1<object> element
}

After (C#):

[InlineArray(LengthConst)]
public ref struct SpanArr
{
    private const int LengthConst = 100;
    public Span<object> element;

    public int Length => LengthConst;

    [UnscopedRef]
    public unsafe Span<object>* At(int index)
    {
        fixed (Span<object>* ptr = &element)
        {
            return ptr + index;
        }
    }
}

Notes

  • Net reduction: 29 lines (47 IL removed, 18 C# added)
  • Only 2 files changed: InvalidCSharpInlineArray.il and InlineArrayValid.cs
  • No test behavior changes - SpanArr maintains identical semantics
  • Intentionally invalid types (explicit layout, zero/negative length, etc.) remain in IL for negative testing

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits January 28, 2026 23:31
… to C#

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Copilot AI changed the title [WIP] Migrate valid C# types from InvalidCSharp*.il files Migrate valid C# types from InvalidCSharp*.il test files Jan 28, 2026
Copilot AI requested a review from jkoritzinsky January 28, 2026 23:42
Copy link
Member

@jkoritzinsky jkoritzinsky left a comment

Choose a reason for hiding this comment

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

@copilot the types that have been moved to C# can be moved out of the InvalidCSharp namespace and into the same namespace as the tests in their corresponding files.

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 29, 2026

@copilot the types that have been moved to C# can be moved out of the InvalidCSharp namespace and into the same namespace as the tests in their corresponding files.

Done. Moved all migrated types to the global namespace in commit ab1d3f1.

@jkoritzinsky
Copy link
Member

@copilot it looks like there are transitive references to some of the types that were defined in InvalidCSharp.ilproj in the ByRefLike test suite. Please fix those failures by moving the requisite types back into IL.

…k to IL

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 17, 2026

@copilot it looks like there are transitive references to some of the types that were defined in InvalidCSharp.ilproj in the ByRefLike test suite. Please fix those failures by moving the requisite typ...

Fixed in commit 93d4d2e. Moved GenericValueType_Over<T>, GenericByRefLike_Over<T>, SimpleInterface, and DefaultInterface back to IL in the InvalidCSharp namespace since they have transitive references from other IL types. Helper types like ByRefLikeType, ByRefLikeTypeWithInterface, RS_DI1, RS_DI2, and RegularValueType remain in C# in the global namespace.

@jkoritzinsky
Copy link
Member

@copilot there's 3 more types referenced from the InvalidCSharp.ilproj library that need to be moved back. Here's the error messages from the build:

##[error]EXEC(0,0): error : Reference to undefined class 'ByRefLikeType' [/__w/1/s/src/tests/Loader/classloader/generics/ByRefLike/InvalidCSharp.ilproj]
EXEC : error : Reference to undefined class 'ByRefLikeType' [/__w/1/s/src/tests/Loader/classloader/generics/ByRefLike/InvalidCSharp.ilproj] [/__w/1/s/src/tests/build.proj]
##[error]EXEC(0,0): error : Reference to undefined class 'ByRefLikeType2' [/__w/1/s/src/tests/Loader/classloader/generics/ByRefLike/InvalidCSharp.ilproj]
EXEC : error : Reference to undefined class 'ByRefLikeType2' [/__w/1/s/src/tests/Loader/classloader/generics/ByRefLike/InvalidCSharp.ilproj] [/__w/1/s/src/tests/build.proj]
##[error]EXEC(0,0): error : Reference to undefined class 'ByRefLikeTypeWithInterface' [/__w/1/s/src/tests/Loader/classloader/generics/ByRefLike/InvalidCSharp.ilproj]
EXEC : error : Reference to undefined class 'ByRefLikeTypeWithInterface' [/__w/1/s/src/tests/Loader/classloader/generics/ByRefLike/InvalidCSharp.ilproj] [/__w/1/s/src/tests/build.proj]
##[error]EXEC(0,0): error : Reference to undefined class 'RegularValueType' [/__w/1/s/src/tests/Loader/classloader/generics/ByRefLike/InvalidCSharp.ilproj]
EXEC : error : Reference to undefined class 'RegularValueType' [/__w/1/s/src/tests/Loader/classloader/generics/ByRefLike/InvalidCSharp.ilproj] [/__w/1/s/src/tests/build.proj]

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 20, 2026

@copilot there's 3 more types referenced from the InvalidCSharp.ilproj library that need to be moved back. Here's the error messages from the build:

...

Fixed in commit 67bb6f52. Moved ByRefLikeType, ByRefLikeType2, ByRefLikeTypeWithInterface, RegularValueType, RS_DI1, and RS_DI2 back to IL. All these types are referenced directly from within the InvalidCSharp.il file itself, so they must remain in IL to avoid undefined reference errors during IL compilation.

@jkoritzinsky
Copy link
Member

@copilot move the types causing the following errors (and any transitive dependencies of them) back to IL:

/__w/1/s/src/tests/Loader/classloader/RefFields/Validate.cs(157,12): error CS9050: A ref field cannot refer to a ref struct. [/__w/1/s/src/tests/Loader/classloader/RefFields/Validate.csproj] [/__w/1/s/src/tests/build.proj]
/__w/1/s/src/tests/Loader/classloader/RefFields/Validate.cs(172,12): error CS0610: Field or property cannot be of type 'TypedReference' [/__w/1/s/src/tests/Loader/classloader/RefFields/Validate.csproj] [/__w/1/s/src/tests/build.proj]

…e not valid in C#

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 20, 2026

@copilot move the types causing the following errors (and any transitive dependencies of them) back to IL:

...

Fixed in commit 1d70f6b. Moved WithRefField, WithRefStructField, and WithTypedReferenceField<T> back to IL. While ref fields are valid in C# 11+, C# doesn't support ref fields that point to ref structs (CS9050) or TypedReference as a field type (CS0610), so these types must remain in IL.

Copy link
Member

Choose a reason for hiding this comment

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

@copilot Revert the changes in this file completely (back to the base branch's state) if we can't move any of the types due to transitive usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 102fe72. Reverted InvalidCSharp.il (ByRefLike) back to the base branch's state.

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants