Wednesday, October 29, 2025

Swift 6.2

Holly Borla:

InlineArray is a new fixed-size array with inline storage for elements, which can be stored on the stack or directly within other types without additional heap allocation.

[…]

The new Span type offers safe, direct access to contiguous memory. Span maintains memory safety by ensuring the memory remains valid while you’re using it.

[…]

Swift 6.2 introduces opt-in strict memory safety, which flags uses of unsafe constructs, so you can replace them with safe alternatives or explicitly acknowledge them in source code.

[…]

Swift 6.2 significantly improves clean build times for projects that use macro-based APIs.

Most of these proposals have been previously discussed here. Strict memory safety is in SE-0458:

This proposal introduces an opt-in strict memory safety checking mode that identifies all uses of unsafe behavior within the given module. There are several parts to this change:

  • A compiler flag -strict-memory-safety that enables warnings for all uses of unsafe constructs within a given module. All warnings will be in the diagnostic group StrictMemorySafety, enabling precise control over memory-safety-related warnings per SE-0443. When strict memory safety is enabled, the StrictMemorySafety feature will be set: #if hasFeature(StrictMemorySafety) can be used to detect when Swift code is being compiled in this mode.
  • An attribute @unsafe that indicates that a declaration is unsafe to use. Such declarations may use unsafe constructs within their signatures.
  • A corresponding attribute @safe that indicates that a declaration whose signature contains unsafe constructs is actually safe to use. For example, the withUnsafeBufferPointer method on Array has an unsafe type in its signature (self), but is actually safe to use because it handles safety for the unsafe buffer pointer it vends to its closure argument. The closure itself will need to handle the unsafety when using that unsafe buffer pointer.
  • An unsafe expression that marks any use of unsafe constructs in an expression, much like try and await.
  • Standard library annotations to identify unsafe declarations.

SE-0477:

A new string interpolation syntax for providing a default string when interpolating an optional value.

Keith Harrison:

One issue is that I’ve been unable to get this to work with localization. The problem seems to be that LocalizedStringKey doesn't’t support the default value parameter.

Paul Hudson (Mastodon, Hacker News):

SE-0451 dramatically expands the range of characters we can use to create identifiers – the names of variables, functions, enum cases and similar – so we can name them pretty much however we want when placed inside backticks.

[…]

SE-0459 makes the type returned by enumerated() conform to Collection.

[…]

SE-0479 extends Swift’s key paths to support methods alongside the existing support for properties and subscripts, which, along with SE-0438 introduced in Swift 6.1, promises to round out what key paths can do.

[…]

SE-0419 introduces a new Backtrace struct, which is capable of capturing data about the call stack of our app at any given moment – the exact sequence of function calls leading up to the current point.

[…]

SE-0448 expands Swift’s regular expression support to include lookbehind assertions, which allow us to check if a specific pattern appears immediately before the current position in the string, without including it in the matched text.

[…]

It’s SE-0476, which introduces a new @abi attribute that makes it easier for ABI-stable library authors to make changes to their libraries without breaking things.

Matt Gallagher (CwlDemangle):

It looks like Swift 6.2 will finally let us access the built-in Swift demangling so we can turn runtime mangled names into something human readable without resorting to half-assed third party libraries (like my own CwlDemangle).

Technically, the demangling is part of the new Backtrace API but it offers SymbolicatedBacktrace.Symbol with a lazily evaluated name that performs demangling on the rawName.

It doesn’t expose DemangleOptions but it’s a huge improvement.

Swift 6.2 also includes some other big features, which I’m going to write separate posts about:

Previously:

1 Comment RSS · Twitter · Mastodon


So InlineArray is not a RandomAccessCollection and only available in appleOS 26. What a silly language. It’s laughably limited: https://forums.swift.org/t/compiler-crash-with-inlinearray/82807

Leave a Comment