-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Open
Description
Championed proposal: dotnet/csharplang#7431
Speclet: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-12.0/inline-arrays.md
Feature branch: https://github.com/dotnet/roslyn/tree/features/InlineArrays
Compiler
- language version
- runtime support required
*_RuntimeSupport - update compiler test plan
- as local
- as parameter including
ref,in,out - as return type
- as field or property
- in
class,struct - as
ref,ref readonlyfield
- in
- in array
- in span
- as type argument
- inline array type
- non-generic, generic
- multiple attributes
InlineArrayType_04_MultipleAttributes -
Length <= 0InlineArrayType_*_WrongLength - no fields
InlineArrayType_09_NoFields - multiple fields (including from event, property, primary constructor)
InlineArrayType_08_MoreThanOneField -
staticfieldsInlineArrayType_*StaticField* -
reffieldInlineArrayType_*_RefField -
class,interface,delegate,enum - nested
structInlineArrayType_31_Nested,InlineArrayType_*_Generic -
ref struct - retargeting
InlineArrayType_18_Retargeting -
[StructLayout(...)] - with explicit indexer
-
[Required]attribute on element field
- inline array element type
- inline array
-
ref struct(error) - pointer
InlineArrayType_30_UnsupportedElementType
- conversions
Conversion_*- implicit conversion to
Span<T>for writable variables only - implicit conversion to
ReadOnlySpan<T>for variables only - no conversion for values
Conversion_Value_* - standard conversion (participates in user-defined conversion)
Conversion_Standard_*
- implicit conversion to
- element access:
inlineArray[index]- arg type:
- implicitly convertible to
int -
dynamicElementAccess_Dynamic_Variable_01 -
System.Index
- implicitly convertible to
-
index < 0,index >= Lengthwith constants and non-constants,intandSystem.IndexElementAccess_Bounds_* -
ref,in,outindex (error)RefOutInIndex - element access of writable variable
ElementAccess_Variable_*-
intandSystem.Index - as value,
ref,ref readonly - ref safety
-
- element access of readonly variable (including readonly context)
ElementAccess_*ReadOnlyContext_*-
intandSystem.Index - as value,
ref,ref readonly - ref safety
-
- element access of value
ElementAccess_Value_*-
intandSystem.Index - as value,
ref,ref readonly - ref safety
-
- within
asyncmethodsElementAccess_Await_* - in object initializer
ElementAccess_ObjectInitializer_* - explicit indexer ignored
*_IndexerIsIgnored_*
- arg type:
- slice:
inlineArray[range]-
start < 0,end >= Lengthwith constants and non-constantsSlice_Bounds_* - slice of writable variable
Slice_Variable_*- element access as value,
ref,ref readonly - ref safety
- element access as value,
- slice of readonly variable (including readonly context)
Slice_ReadOnlyContext_*- element access as value,
ref,ref readonly - ref safety
- element access as value,
- slice of value (error)
- within
asyncmethodsSlice_Await_* - omit slice call if range is a constant and start is
0 - explicit
Slice()method ignored*_SliceMethodIsIgnored_*
-
- indexer: prefer
intoverIndexoverRangeAccess_ArgumentType_* - as
foreachcollectionForeach_*- writable variables, readonly variables, values
-
foreach ... ref,foreach ... ref readonly -
await foreach - in
asyncmethodForeach_InAsync_*
- conditional access
*_ConditionalAccess_*-
inlineArray?[i]whereiisint,Index,Range -
type?InlineArray[i]wheretypeisclass,struct,iisint,Index,Range
-
- list pattern
is [..](error)ListPattern - collection literals Support inline arrays with collection literals #68927
- as collection literal target type
- as collection literal spread element
- in expression tree (error)
- element access
ElementAccess_ExpressionTree_01 - conversion
Conversion_ExpressionTree_01
- element access
- definite assignment
DefiniteAssignment_*- unassigned vs.
new() - 1 element vs. > 1 element
-
= default; - definite assignment errors for element access
- definite assignment errors for slice
- definite assignment errors for implicit conversions to spans
- definite assignment errors within inline array type
- unassigned vs.
- nullable analysis
NullableAnalysis_* - missing types and methods
MissingHelper_*-
Span<T>,ReadOnlySpan<T> -
System.Index,System.Range -
MemoryMarshal.*,Unsafe.*
-
-
PrivateImplementationDetailsmethods created as neededPrivateImplementationDetails_*-
InlineArrayAsSpan(),...AsReadOnlySpan() -
InlineArrayElementRef(),...RefReadOnly()
-
- attribute cycles
CycleThroughAttributes_* - Test element access with an int variable as an index
- Test with types and members synthesizing fields
Public API
IDE
- IOperation
- CFG
- EE Support inline arrays in EE #68926
- view elements in Watch window
- evaluate element access, slice
- EnC: Inline Arrays #69245
- Compiler crashes when emitting EnC delta for assembly with synthesized inline array types #69398
Reactions are currently unavailable