Skip to content

Commit b6f0b6d

Browse files
committed
[stdlib][docs] Describe availability macros in the stdlib programmer's manual
1 parent 5fead14 commit b6f0b6d

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

docs/StandardLibraryProgrammersManual.md

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,34 +298,63 @@ Just like access control modifiers, we prefer to put `@available` attributes on
298298
299299
```swift
300300
// 😢👎
301-
@available(macOS 10.6, iOS 10, watchOS 3, tvOS 12, *)
301+
@available(SwiftStdlib 5.2, *)
302302
extension String {
303303
public func blanch() { ... }
304304
public func roast() { ... }
305305
}
306306
307307
// 🥲👍
308308
extension String {
309-
@available(macOS 10.6, iOS 10, watchOS 3, tvOS 12, *)
309+
@available(SwiftStdlib 5.2, *)
310310
public func blanch() { ... }
311311
312-
@available(macOS 10.6, iOS 10, watchOS 3, tvOS 12, *)
312+
@available(SwiftStdlib 5.2, *)
313313
public func roast() { ... }
314314
}
315315
```
316316
317317
This coding style is enforced by the ABI checker -- it will complain if an extension member declaration that needs an availability doesn't have it directly attached.
318318
319-
Features under development that haven't been released yet must be marked with the placeholder version number `9999`. This special version is always considered available in custom builds of the Swift toolchain (including development snapshots), but not in any ABI-stable production release.
319+
This repository defines a set of availability macros (of the form `SwiftStdlib x.y`) that map Swift Stdlib releases to the OS versions that shipped them, for all ABI stable platforms. The following two definitions are equivalent, but the second one is less error-prone, so we prefer that:
320320
321321
```swift
322+
extension String {
323+
// 😵‍💫👎
324+
@available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *)
325+
public func fiddle() { ... }
326+
327+
// 😎👍
328+
@available(SwiftStdlib 5.2, *)
329+
public func fiddle() { ... }
330+
}
331+
```
332+
333+
(Mistakes in the OS version number list are very easy to miss during review, but can have major ABI consequences.)
334+
335+
This is especially important for newly introduced APIs, where the corresponding OS releases may not even be known yet.
336+
337+
Features under development that haven't shipped yet must be marked as available in the placeholder OS version `9999`. This special version is always considered available in custom builds of the Swift toolchain (including development snapshots), but not in any ABI-stable production release.
338+
339+
Never explicitly spell out such placeholder availability -- instead, use the `SwiftStdlib` macro corresponding to the Swift version we're currently working on:
340+
341+
```swift
342+
// 😵‍💫👎
322343
@available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *)
323344
public struct FutureFeature {
324345
...
325346
}
347+
348+
// 😎👍
349+
@available(SwiftStdlib 6.3, *) // Or whatever
350+
public struct FutureFeature {
351+
...
352+
}
326353
```
327354
328-
On these platforms, the Swift Standard Library ships as an integrated part of the operating system; as such, it is the platform owners' responsibility to update these placeholder version numbers to actual versions as part of their release process.
355+
This way, platform owners can easily update declarations to the correct set of version numbers by simply changing the definition of the macro, rather than having to update each individual declaration.
356+
357+
If we haven't defined a version number for the "next" Swift release yet, please use the special placeholder version `SwiftStdlib 9999`, which always expands to 9999 versions. Declarations that use this version will need to be manually updated once we decide on the corresponding Swift version number.
329358
330359
## Internals
331360

0 commit comments

Comments
 (0)