csharplang icon indicating copy to clipboard operation
csharplang copied to clipboard

[Proposal]: Inline arrays (VS 17.7, .NET 8)

Open jcouv opened this issue 2 years ago • 5 comments

Inline arrays

  • [x] Proposed
  • [x] Prototype: Done
  • [x] Implementation: Done
  • [ ] Specification: Not Started

Summary

This feature recognizes the special meaning of the [InlineArray] attribute, allows indexing into such inline array types and enumerating their elements.

See https://github.com/dotnet/csharplang/blob/main/proposals/csharp-12.0/inline-arrays.md

Design meetings

https://github.com/dotnet/csharplang/blob/main/meetings/2024/LDM-2024-06-17.md#inline-arrays-as-record-structs

jcouv avatar Aug 08 '23 21:08 jcouv

Is there a proposal to allow initializing an InlineArray using a collection expression? Right now the only way (I think) is to use CopyTo from a span, I couldn't find any discussion on that.

alrz avatar Jan 07 '25 11:01 alrz

There is not currently. It was dropped due to lack of time. A proposal could be raised! It would have to deal with what to do with spreads into a fixed-length collection. Silently under-initialize? Silently lose items? Throw? Disallow all spreads? Disallow spreads unless compiler can guarantee their length at compile time?

jnm2 avatar Jan 07 '25 17:01 jnm2

I think it would be constrained by all the conditions that currently allows the compiler to lower a collection expression to an inline array?

alrz avatar Jan 07 '25 17:01 alrz

@alrz This is currently not specced, it's all compiler optimization, and the compiler silently falls back to using heap types if inline arrays aren't considered most performant to involve. The spec would need to specify how the user's experience meets this process for the first time when an inline array is required.

jnm2 avatar Jan 07 '25 17:01 jnm2

I'm locking this issue as all of our issues should be locked in the new repo organization; apologies that it wasn't locked already. Feel free to start a discussion to continue this topic.

333fred avatar Jan 07 '25 17:01 333fred