Hello Swift community,
The second review of SE-0453: Vector, a fixed-size array concluded on December 17, 2024. The Language Steering Group has decided to accept this proposal with modifications. In addition to a couple small API changes, this type will be introduced with the name InlineArray
.
API Changes
The following proposed initializer:
public init<E: Error>(with next: (Index) throws(E) -> Element) throws(E)
will drop the argument label and be introduced as init(_:)
Additionally, it was pointed out in review that the subscripts on InlineArray
were different than those on Span
. The Language Steering Group agreed that InlineArray
should adopt the missing subscripts from Span
.
On Naming
The Language Steering Group had a long discussion about the naming of this type and considered both the principles and concrete alternatives that were brought up in the review thread and via private feedback. We settled on the name InlineArray
for the following reasons.
Regarding the name Vector
, the Group broadly agreed with the arguments that the mismatch in meaning of 'vector' between Swift and some other peer languages like C++ and Rust would be unfortunate. We were also receptive to arguments that this was not synonymous enough with mathematical vectors to justify the name on those grounds alone. Given this, we considered what other names than Vector
might be suitable for this type.
The Language Steering Group did not feel that it was inappropriate for users to conceptualize this as an 'array' type in a colloquial sense. We agreed with the argument that 'fixed-size array' accurately captured much of the behavior of this type, even considering its relationship with the potential 'array' types that we may want to support in the future.
Nonetheless, this type does differ from the vanilla Array
type in ways which we felt were important to communicate in the name of the type. Top of mind for the Language Steering Group was the behavior of this type regarding copies: namely, that this type is eagerly copied rather than being copy-on-write which carries substantial performance implications. The Group felt that the Inline
- prefix captured the salient aspects of how this type's storage is organized.
Many reviewers felt that FixedSizeArray
was the most obvious and straightforward name for this type, and the Group was sympathetic to this argument. However, we did not feel this name (or its variants such as FixedArray
) sufficiently called out the potential performance issues discussed in the prior paragraph (one could, of course, have a fixed-size array with out-of-line storage and copy-on-write behavior more like Array
). Moreover, the Group feels the fixed-size nature of this array will be sufficiently apparent from both from the fact that the generic count
parameter appears in the type signature, and from the fact that one will get a compiler error as soon as there's any attempt to actually use a size changing operation—the fixed-size property of this type is not something it's really possible to meaningfully 'get wrong' compared to its performance characteristics.
The Group also discussed alternative, pithy names for the type that could become a new term of art, but in the end did not find a compelling solution along those lines. In particular, each option seemed like it would invite just as much (if not more) clarification than Vector
along the lines of "NewTermOfArt
, an inline fixed-sized array."
As always, thank you to everyone for your thoughtful participation in these reviews. This was a long but productive discussion, and your contributions help to make Swift a better language.
Freddy Kellison-Linn
Review Manager