Skip to content

Commit 2887334

Browse files
authored
Merge pull request #85167 from tshortli/new-platform-kinds
AST: Introduce the `Swift`, `anyAppleOS`, and `DriverKit` platform kinds
2 parents 2a9f587 + 92227ad commit 2887334

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
@@ -2559,6 +2559,14 @@ PlatformAvailability::PlatformAvailability(const LangOptions &langOpts)
25592559
case PlatformKind::visionOSApplicationExtension:
25602560
break;
25612561

2562+
case PlatformKind::DriverKit:
2563+
deprecatedAsUnavailableMessage = "";
2564+
break;
2565+
2566+
case PlatformKind::Swift:
2567+
case PlatformKind::anyAppleOS:
2568+
llvm_unreachable("Unexpected platform");
2569+
25622570
case PlatformKind::FreeBSD:
25632571
deprecatedAsUnavailableMessage = "";
25642572
break;
@@ -2614,6 +2622,13 @@ bool PlatformAvailability::isPlatformRelevant(StringRef name) const {
26142622
return name == "xros" || name == "xros_app_extension" ||
26152623
name == "visionos" || name == "visionos_app_extension";
26162624

2625+
case PlatformKind::DriverKit:
2626+
return name == "driverkit";
2627+
2628+
case PlatformKind::Swift:
2629+
case PlatformKind::anyAppleOS:
2630+
break; // Unexpected
2631+
26172632
case PlatformKind::FreeBSD:
26182633
return name == "freebsd";
26192634

@@ -2691,6 +2706,15 @@ bool PlatformAvailability::treatDeprecatedAsUnavailable(
26912706
// No deprecation filter on xrOS
26922707
return false;
26932708

2709+
case PlatformKind::DriverKit:
2710+
// No deprecation filter on DriverKit
2711+
// FIXME: [availability] This should probably have a value.
2712+
return false;
2713+
2714+
case PlatformKind::Swift:
2715+
case PlatformKind::anyAppleOS:
2716+
break; // Unexpected
2717+
26942718
case PlatformKind::FreeBSD:
26952719
// No deprecation filter on FreeBSD
26962720
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)