Swift 6.2
InlineArrayis 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
Spantype 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-safetythat enables warnings for all uses of unsafe constructs within a given module. All warnings will be in the diagnostic groupStrictMemorySafety, enabling precise control over memory-safety-related warnings per SE-0443. When strict memory safety is enabled, theStrictMemorySafetyfeature will be set:#if hasFeature(StrictMemorySafety)can be used to detect when Swift code is being compiled in this mode.- An attribute
@unsafethat indicates that a declaration is unsafe to use. Such declarations may use unsafe constructs within their signatures.- A corresponding attribute
@safethat indicates that a declaration whose signature contains unsafe constructs is actually safe to use. For example, thewithUnsafeBufferPointermethod onArrayhas 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
unsafeexpression that marks any use of unsafe constructs in an expression, much liketryandawait.- Standard library annotations to identify unsafe declarations.
A new string interpolation syntax for providing a default string when interpolating an optional value.
One issue is that I’ve been unable to get this to work with localization. The problem seems to be that
LocalizedStringKeydoesn'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 toCollection.[…]
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
Backtracestruct, 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
@abiattribute that makes it easier for ABI-stable library authors to make changes to their libraries without breaking things.
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
BacktraceAPI but it offersSymbolicatedBacktrace.Symbolwith a lazily evaluatednamethat performs demangling on therawName.It doesn’t expose
DemangleOptionsbut it’s a huge improvement.
Swift 6.2 also includes some other big features, which I’m going to write separate posts about:
Previously:
- Xcode 26
- Swift Proposal: weak let
- Swift Testing Proposal: Exit Tests
- Lifetime Dependencies in Swift 6.2 and Beyond
- Swift 6.1
- Swift Proposal: InlineArray
- Swift Proposal: Precise Control Flags Over Compiler Warnings
- Swift for C++ Practitioners
- On-Crash Backtraces in Swift
- Demangling Swift With Swift
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