-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Implement compiler support for System.Runtime.InteropServices.ExtendedLayoutAttribute #78741
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
base: main
Are you sure you want to change the base?
Changes from all commits
72be215
140c7f8
00c5e58
23b2105
8da6a1b
838698c
3857e79
4468b16
0e2370a
ffc2a59
98922c4
9797dbe
a610c4b
57f5c77
fd4d41f
91e5314
e873123
23be26d
97c9d07
7317277
bfafeef
a918ed4
e97e4d9
f7343d6
6f08876
9900fe3
7451867
ccdbb3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| System.Runtime.InteropServices.ExtendedLayoutAttribute Compiler Support | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to this PR: will the F# compiler need to be updated as well? Consider filing an issue |
||
| ======================================================================= | ||
|
|
||
| The .NET runtime team is introducing a new attribute, `System.Runtime.InteropServices.ExtendedLayoutAttribute`, which will allow the runtime team to provide additional layout options for types, primarily for interop scenarios. | ||
| To provide the user experience requested by the runtime team, the C# and VB compilers will have the following support for this attribute: | ||
|
|
||
| - If a type has the `ExtendedLayoutAttribute` applied, the compiler will emit the `TypeAttributes.ExtendedLayout` value in the type's `TypeAttributes` flags. | ||
jaredpar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - If a type has the `ExtendedLayoutAttribute` applied, the compiler will not allow the `StructLayoutAttribute` to be applied to the type. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to this PR: The linked API proposal wasn't updated to clarify that ExtendedLayout attribute implies StructLayout(Extended). The code samples still show explicit [StructLayout(Extended)]. |
||
| - (C# compiler only) If a type has the `ExtendedLayoutAttribute` applied, the compiler will not allow the `InlineArrayAttribute` to be applied to the type. | ||
| - Within the Roslyn compiler, the `ITypeSymbol` for a type with the `ExtendedLayoutAttribute` applied will have the following behavior: | ||
| - The `Layout` property will return a `TypeLayout` instance with the `LayoutKind` set to `Extended` (`1`), `Size` set to `0` and `Pack` set to `0`. | ||
| - A type that is embedded in an assembly (using the `NoPia` technology) will have the `ExtendedLayoutAttribute` preserved on the embedded type. | ||
|
|
||
| The Roslyn compiler will not have knowledge of the specific options available on the `ExtendedLayoutAttribute`, as these options will be defined by the runtime team and may expand over time. The compiler will not attempt to detect invalid field types for specific layout options. The runtime team may add analyzers in the future to handle these scenarios. | ||
|
|
||
| The compiler will only recognize the presence of the attribute and its implications for the type symbol's `LayoutKind` and the emitted attribute. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2724,7 +2724,7 @@ internal ImmutableArray<Diagnostic> GetUnusedFieldWarnings(CancellationToken can | |
| handledUnreadFields.Add(field); | ||
| } | ||
|
|
||
| if (containingType.HasStructLayoutAttribute || containingType.HasInlineArrayAttribute(out _)) | ||
| if (containingType.HasStructLayoutAttribute || containingType.HasExtendedLayoutAttribute || containingType.HasInlineArrayAttribute(out _)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's another usage of |
||
| { | ||
| continue; | ||
| } | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding an entry to https://github.com/dotnet/roslyn/blob/main/docs/Language%20Feature%20Status.md for this feature.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jkoritzinsky Add the following line beneath "extension indexers" in the feature status page.
| [ExtendedLayoutAttribute](https://github.com/dotnet/runtime/issues/100896) | main | [Merged into 18.3](https://github.com/dotnet/roslyn/pull/78741) | [jkoritzinsky](https://github.com/jkoritzinsky) | [333fred](https://github.com/333fred), [jcouv](https://github.com/jcouv) | | |