Skip to content

Commit 92227ad

Browse files
committed
AST: Introduce the Swift, anyAppleOS, and DriverKit platform kinds.
This change just stages in a few new platform kinds, without fully adding support for them yet. - The `Swift` platform represents availability of the Swift runtime across all platforms that support an ABI stable Swift runtime (see the pitch at https://forums.swift.org/t/pitch-swift-runtime-availability/82742). - The `anyAppleOS` platform is an experimental platform that represents all of Apple's operating systems. This is intended to simplify writing availability for Apple's platforms by taking advantage of the new unified OS versioning system announced at WWDC 2025. - The `DriverKit` platform corresponds to Apple DriverKit which is already supported by LLVM.
1 parent 9c9f6b7 commit 92227ad

File tree

9 files changed

+83
-2
lines changed

9 files changed

+83
-2
lines changed

include/swift/AST/PlatformKinds.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ AVAILABILITY_PLATFORM(visionOSApplicationExtension, "application extensions for
3434
AVAILABILITY_PLATFORM(macOSApplicationExtension, "application extensions for macOS")
3535
AVAILABILITY_PLATFORM(macCatalyst, "Mac Catalyst")
3636
AVAILABILITY_PLATFORM(macCatalystApplicationExtension, "application extensions for Mac Catalyst")
37+
AVAILABILITY_PLATFORM(DriverKit, "DriverKit")
38+
/// A meta-platform representing the built-in Swift runtime.
39+
AVAILABILITY_PLATFORM(Swift, "Swift")
40+
/// A meta-platform for Apple operating systems with unified versioning.
41+
AVAILABILITY_PLATFORM(anyAppleOS, "any Apple OS")
3742
AVAILABILITY_PLATFORM(FreeBSD, "FreeBSD")
3843
AVAILABILITY_PLATFORM(OpenBSD, "OpenBSD")
3944
AVAILABILITY_PLATFORM(Windows, "Windows")

lib/AST/PlatformKindUtils.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ swift::basePlatformForExtensionPlatform(PlatformKind Platform) {
115115
case PlatformKind::tvOS:
116116
case PlatformKind::watchOS:
117117
case PlatformKind::visionOS:
118+
case PlatformKind::DriverKit:
119+
case PlatformKind::Swift:
120+
case PlatformKind::anyAppleOS:
118121
case PlatformKind::FreeBSD:
119122
case PlatformKind::OpenBSD:
120123
case PlatformKind::Windows:
@@ -159,6 +162,11 @@ static bool isPlatformActiveForTarget(PlatformKind Platform,
159162
case PlatformKind::visionOS:
160163
case PlatformKind::visionOSApplicationExtension:
161164
return Target.isXROS();
165+
case PlatformKind::DriverKit:
166+
return Target.isDriverKit();
167+
case PlatformKind::Swift:
168+
case PlatformKind::anyAppleOS:
169+
return Target.isOSDarwin();
162170
case PlatformKind::OpenBSD:
163171
return Target.isOSOpenBSD();
164172
case PlatformKind::FreeBSD:
@@ -292,6 +300,11 @@ swift::tripleOSTypeForPlatform(PlatformKind platform) {
292300
case PlatformKind::visionOS:
293301
case PlatformKind::visionOSApplicationExtension:
294302
return llvm::Triple::XROS;
303+
case PlatformKind::DriverKit:
304+
return llvm::Triple::DriverKit;
305+
case PlatformKind::Swift:
306+
case PlatformKind::anyAppleOS:
307+
return std::nullopt;
295308
case PlatformKind::FreeBSD:
296309
return llvm::Triple::FreeBSD;
297310
case PlatformKind::OpenBSD:
@@ -332,6 +345,9 @@ bool swift::isPlatformSPI(PlatformKind Platform) {
332345
case PlatformKind::watchOSApplicationExtension:
333346
case PlatformKind::visionOS:
334347
case PlatformKind::visionOSApplicationExtension:
348+
case PlatformKind::DriverKit:
349+
case PlatformKind::Swift:
350+
case PlatformKind::anyAppleOS:
335351
case PlatformKind::OpenBSD:
336352
case PlatformKind::FreeBSD:
337353
case PlatformKind::Windows:

lib/ClangImporter/ClangImporter.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,6 +2561,14 @@ PlatformAvailability::PlatformAvailability(const LangOptions &langOpts)
25612561
case PlatformKind::visionOSApplicationExtension:
25622562
break;
25632563

2564+
case PlatformKind::DriverKit:
2565+
deprecatedAsUnavailableMessage = "";
2566+
break;
2567+
2568+
case PlatformKind::Swift:
2569+
case PlatformKind::anyAppleOS:
2570+
llvm_unreachable("Unexpected platform");
2571+
25642572
case PlatformKind::FreeBSD:
25652573
deprecatedAsUnavailableMessage = "";
25662574
break;
@@ -2616,6 +2624,13 @@ bool PlatformAvailability::isPlatformRelevant(StringRef name) const {
26162624
return name == "xros" || name == "xros_app_extension" ||
26172625
name == "visionos" || name == "visionos_app_extension";
26182626

2627+
case PlatformKind::DriverKit:
2628+
return name == "driverkit";
2629+
2630+
case PlatformKind::Swift:
2631+
case PlatformKind::anyAppleOS:
2632+
break; // Unexpected
2633+
26192634
case PlatformKind::FreeBSD:
26202635
return name == "freebsd";
26212636

@@ -2693,6 +2708,15 @@ bool PlatformAvailability::treatDeprecatedAsUnavailable(
26932708
// No deprecation filter on xrOS
26942709
return false;
26952710

2711+
case PlatformKind::DriverKit:
2712+
// No deprecation filter on DriverKit
2713+
// FIXME: [availability] This should probably have a value.
2714+
return false;
2715+
2716+
case PlatformKind::Swift:
2717+
case PlatformKind::anyAppleOS:
2718+
break; // Unexpected
2719+
26962720
case PlatformKind::FreeBSD:
26972721
// No deprecation filter on FreeBSD
26982722
return false;

lib/IRGen/TBDGen.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,12 @@ getLinkerPlatformId(OriginallyDefinedInAttr::ActiveVersion Ver,
245245
switch(Ver.Platform) {
246246
case swift::PlatformKind::none:
247247
llvm_unreachable("cannot find platform kind");
248+
case swift::PlatformKind::DriverKit:
249+
llvm_unreachable("not used for this platform");
250+
case swift::PlatformKind::Swift:
251+
llvm_unreachable("not used for this platform");
252+
case PlatformKind::anyAppleOS:
253+
llvm_unreachable("not used for this platform");
248254
case swift::PlatformKind::FreeBSD:
249255
llvm_unreachable("not used for this platform");
250256
case swift::PlatformKind::OpenBSD:
@@ -253,6 +259,7 @@ getLinkerPlatformId(OriginallyDefinedInAttr::ActiveVersion Ver,
253259
llvm_unreachable("not used for this platform");
254260
case swift::PlatformKind::Android:
255261
llvm_unreachable("not used for this platform");
262+
256263
case swift::PlatformKind::iOS:
257264
case swift::PlatformKind::iOSApplicationExtension:
258265
if (target && target->isMacCatalystEnvironment())

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,14 @@ class DeclAndTypePrinter::Implementation
18211821
case PlatformKind::visionOSApplicationExtension:
18221822
plat = "visionos_app_extension";
18231823
break;
1824+
case PlatformKind::DriverKit:
1825+
plat = "driverkit";
1826+
break;
1827+
case PlatformKind::Swift:
1828+
case PlatformKind::anyAppleOS:
1829+
// FIXME: [runtime availability] Figure out how to support this.
1830+
ASSERT(0);
1831+
break;
18241832
case PlatformKind::FreeBSD:
18251833
plat = "freebsd";
18261834
break;

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5858
/// describe what change you made. The content of this comment isn't important;
5959
/// it just ensures a conflict if two people change the module format.
6060
/// Don't worry about adhering to the 80-column limit for this line.
61-
const uint16_t SWIFTMODULE_VERSION_MINOR = 970; // return_borrow
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 971; // new platform kinds
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///

lib/SymbolGraphGen/AvailabilityMixin.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ StringRef getDomain(const SemanticAvailableAttr &AvAttr) {
5454
return { "watchOSAppExtension" };
5555
case swift::PlatformKind::visionOSApplicationExtension:
5656
return { "visionOSAppExtension" };
57+
case PlatformKind::DriverKit:
58+
return { "DriverKit" };
59+
case swift::PlatformKind::Swift:
60+
return { "Swift" };
61+
case PlatformKind::anyAppleOS:
62+
return { "Any Apple OS" };
5763
case swift::PlatformKind::FreeBSD:
5864
return { "FreeBSD" };
5965
case swift::PlatformKind::OpenBSD:

test/IDE/complete_decl_attribute.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ actor MyGenericGlobalActor<T> {
8383
// AVAILABILITY1-NEXT: Keyword/None: macOSApplicationExtension[#Platform#]; name=macOSApplicationExtension{{$}}
8484
// AVAILABILITY1-NEXT: Keyword/None: macCatalyst[#Platform#]; name=macCatalyst
8585
// AVAILABILITY1-NEXT: Keyword/None: macCatalystApplicationExtension[#Platform#]; name=macCatalystApplicationExtension
86+
// AVAILABILITY1-NEXT: Keyword/None: DriverKit[#Platform#]; name=DriverKit{{$}}
87+
// AVAILABILITY1-NEXT: Keyword/None: Swift[#Platform#]; name=Swift{{$}}
88+
// AVAILABILITY1-NEXT: Keyword/None: anyAppleOS[#Platform#]; name=anyAppleOS{{$}}
8689
// AVAILABILITY1-NEXT: Keyword/None: FreeBSD[#Platform#]; name=FreeBSD{{$}}
8790
// AVAILABILITY1-NEXT: Keyword/None: OpenBSD[#Platform#]; name=OpenBSD{{$}}
8891
// AVAILABILITY1-NEXT: Keyword/None: Windows[#Platform#]; name=Windows{{$}}

tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,9 @@ static void reportAvailabilityAttributes(ASTContext &Ctx, const Decl *D,
693693
static UIdent PlatformOSXAppExt("source.availability.platform.osx_app_extension");
694694
static UIdent PlatformtvOSAppExt("source.availability.platform.tvos_app_extension");
695695
static UIdent PlatformWatchOSAppExt("source.availability.platform.watchos_app_extension");
696+
static UIdent PlatformDriverKit("source.availability.platform.driverkit");
697+
static UIdent PlatformSwift("source.availability.platform.swift");
698+
static UIdent PlatformAnyAppleOS("source.availability.platform.any_apple_os");
696699
static UIdent PlatformFreeBSD("source.availability.platform.freebsd");
697700
static UIdent PlatformOpenBSD("source.availability.platform.openbsd");
698701
static UIdent PlatformWindows("source.availability.platform.windows");
@@ -743,6 +746,15 @@ static void reportAvailabilityAttributes(ASTContext &Ctx, const Decl *D,
743746
// FIXME: Formal platform support in SourceKit is needed.
744747
PlatformUID = UIdent();
745748
break;
749+
case PlatformKind::DriverKit:
750+
PlatformUID = PlatformDriverKit;
751+
break;
752+
case PlatformKind::Swift:
753+
PlatformUID = PlatformSwift;
754+
break;
755+
case PlatformKind::anyAppleOS:
756+
PlatformUID = PlatformAnyAppleOS;
757+
break;
746758
case PlatformKind::OpenBSD:
747759
PlatformUID = PlatformOpenBSD;
748760
break;
@@ -756,7 +768,7 @@ static void reportAvailabilityAttributes(ASTContext &Ctx, const Decl *D,
756768
PlatformUID = PlatformAndroid;
757769
break;
758770
}
759-
// FIXME: [availability] Handle other availability domains?
771+
// FIXME: [availability] Handle non-platform availability domains?
760772

761773
AvailableAttrInfo Info;
762774
Info.AttrKind = AvailableAttrKind;

0 commit comments

Comments
 (0)