Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 16, 2026

Description

The C# compiler now supports the ExtendedLayoutAttribute. Migrated CStruct and CUnion type definitions from IL to C# where possible, keeping types that require both StructLayout and ExtendedLayout attributes in IL.

Changes

CStruct.cs

  • Added 9 type definitions using [ExtendedLayout(ExtendedLayoutKind.CStruct)]
  • Includes types with primitive fields, reference fields, nested types (with explicit [StructLayout(LayoutKind.Auto)] on NestedAutoLayoutType), empty structs, and byref-like structs

CUnion.cs

  • Added 9 type definitions using [ExtendedLayout(ExtendedLayoutKind.CUnion)]
  • Includes types with primitive fields, reference fields, nested unions, empty unions, and byref-like unions

ExtendedLayoutTypes.il

  • Retained 9 types that must remain in IL:
    • 3 invalid type examples that cannot be expressed in valid C#:
      • NoExtendedAttributeOnType - tests missing attribute
      • InlineArrayOnExtendedLayout - tests invalid attribute combination
      • ExtendedLayoutInvalidKind - tests invalid enum value
    • 6 types requiring both ExtendedLayout and StructLayout/FieldOffset attributes:
      • CStructWithOffsets, CStructWithSize, CStructWithPack
      • CUnionWithOffsets, CUnionWithSize, CUnionWithPack

Example migration:

// Before (IL):
// .class flags(0x18) public value beforefieldinit CUnionMixedSizes
// {
//     .custom instance void [System.Runtime]System.Runtime.InteropServices.ExtendedLayoutAttribute::.ctor(...) = {
//         int32(0x00000001) // CUnion
//     }
//     .field public uint8 byteField
//     .field public int64 longField
// }

// After (C#):
[ExtendedLayout(ExtendedLayoutKind.CUnion)]
public struct CUnionMixedSizes
{
    public byte byteField;
    public short shortField;
    public int intField;
    public long longField;
}

All existing tests remain unchanged - they reference the same type names, now defined in C# where possible and in IL where dual attributes are required.

Original prompt

A C# compiler that supports the new ExtendedLayout attribute has recently been merged into this repo. Please update the ExtendedLayout test suite to use this attribute in C#. In particular, move all types defined in the CStruct section into CStruct.cs and define the types in C#. Do the same for the types in the CUnion section. Please leave the types in the "Invalid type examples" in IL.


💡 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 changed the title [WIP] Update ExtendedLayout test suite to use new attribute Migrate ExtendedLayout test types from IL to C# Jan 16, 2026
Copilot AI requested a review from jkoritzinsky January 16, 2026 19:58
@jkoritzinsky
Copy link
Member

@copilot address the feedback from my review

Copy link
Contributor Author

Copilot AI commented Jan 16, 2026

@copilot address the feedback from my review

Addressed all review feedback in e97f014

Copilot AI requested a review from jkoritzinsky January 16, 2026 20:06
@jkoritzinsky jkoritzinsky marked this pull request as ready for review January 16, 2026 20:40
Copilot AI review requested due to automatic review settings January 16, 2026 20:40
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 migrates ExtendedLayout test type definitions from IL to C# now that the C# compiler supports the ExtendedLayoutAttribute. The migration moves type definitions to C# where possible while retaining IL types that require features C# cannot express.

Changes:

  • Migrated 9 CStruct types and 9 CUnion types from IL to C# using the ExtendedLayoutAttribute
  • Retained 9 IL types that require dual attributes or test invalid type scenarios
  • Added shared helper types (NestedSequentialType, NestedAutoLayoutType) in CStruct.cs for use across both test files

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
ExtendedLayoutTypes.il Removed migrated types; retained invalid test types and types requiring both ExtendedLayout and StructLayout/FieldOffset attributes
CStruct.cs Added 9 CStruct type definitions and 2 shared nested helper types using ExtendedLayoutAttribute
CUnion.cs Added 9 CUnion type definitions using ExtendedLayoutAttribute

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants