mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
AST: App extension platforms always inherit availability from their parents.
This commit is contained in:
@@ -51,6 +51,12 @@ llvm::Optional<StringRef> closestCorrectedPlatformString(StringRef candidate);
|
||||
/// for emission in diagnostics (e.g., "macOS").
|
||||
StringRef prettyPlatformString(PlatformKind platform);
|
||||
|
||||
/// Returns the base platform for an application-extension platform. For example
|
||||
/// `iOS` would be returned for `iOSApplicationExtension`. Returns `None` for
|
||||
/// platforms which are not application extension platforms.
|
||||
llvm::Optional<PlatformKind>
|
||||
basePlatformForExtensionPlatform(PlatformKind Platform);
|
||||
|
||||
/// Returns whether the passed-in platform is active, given the language
|
||||
/// options. A platform is active if either it is the target platform or its
|
||||
/// AppExtension variant is the target platform. For example, OS X is
|
||||
|
||||
@@ -83,14 +83,19 @@ swift::closestCorrectedPlatformString(StringRef candidate) {
|
||||
return (minDistance < distanceThreshold) ? result : llvm::None;
|
||||
}
|
||||
|
||||
static bool isApplicationExtensionPlatform(PlatformKind Platform) {
|
||||
llvm::Optional<PlatformKind>
|
||||
swift::basePlatformForExtensionPlatform(PlatformKind Platform) {
|
||||
switch (Platform) {
|
||||
case PlatformKind::macOSApplicationExtension:
|
||||
return PlatformKind::macOS;
|
||||
case PlatformKind::iOSApplicationExtension:
|
||||
return PlatformKind::iOS;
|
||||
case PlatformKind::macCatalystApplicationExtension:
|
||||
return PlatformKind::macCatalyst;
|
||||
case PlatformKind::tvOSApplicationExtension:
|
||||
return PlatformKind::tvOS;
|
||||
case PlatformKind::watchOSApplicationExtension:
|
||||
return true;
|
||||
return PlatformKind::watchOS;
|
||||
case PlatformKind::macOS:
|
||||
case PlatformKind::iOS:
|
||||
case PlatformKind::macCatalyst:
|
||||
@@ -99,11 +104,15 @@ static bool isApplicationExtensionPlatform(PlatformKind Platform) {
|
||||
case PlatformKind::OpenBSD:
|
||||
case PlatformKind::Windows:
|
||||
case PlatformKind::none:
|
||||
return false;
|
||||
return llvm::None;
|
||||
}
|
||||
llvm_unreachable("bad PlatformKind");
|
||||
}
|
||||
|
||||
static bool isApplicationExtensionPlatform(PlatformKind Platform) {
|
||||
return basePlatformForExtensionPlatform(Platform).has_value();
|
||||
}
|
||||
|
||||
static bool isPlatformActiveForTarget(PlatformKind Platform,
|
||||
const llvm::Triple &Target,
|
||||
bool EnableAppExtensionRestrictions) {
|
||||
@@ -187,20 +196,21 @@ PlatformKind swift::targetPlatform(const LangOptions &LangOpts) {
|
||||
|
||||
bool swift::inheritsAvailabilityFromPlatform(PlatformKind Child,
|
||||
PlatformKind Parent) {
|
||||
if (auto ChildPlatformBase = basePlatformForExtensionPlatform(Child)) {
|
||||
if (Parent == ChildPlatformBase)
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Child == PlatformKind::macCatalyst && Parent == PlatformKind::iOS)
|
||||
return true;
|
||||
|
||||
if (Child == PlatformKind::macCatalystApplicationExtension) {
|
||||
if (Parent == PlatformKind::iOS ||
|
||||
Parent == PlatformKind::iOSApplicationExtension ||
|
||||
Parent == PlatformKind::macCatalyst) {
|
||||
Parent == PlatformKind::iOSApplicationExtension) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Ideally we would have all ApplicationExtension platforms
|
||||
// inherit from their non-extension platform.
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
func ios() {} // expected-note 2{{'ios()' has been explicitly marked unavailable here}}
|
||||
|
||||
@available(iOSApplicationExtension, unavailable)
|
||||
func ios_extension() {} // expected-note 2{{'ios_extension()' has been explicitly marked unavailable here}}
|
||||
func ios_extension() {} // expected-note {{'ios_extension()' has been explicitly marked unavailable here}}
|
||||
|
||||
func call_ios_extension() {
|
||||
ios_extension() // expected-error {{'ios_extension()' is unavailable}}
|
||||
@@ -19,7 +19,7 @@ func call_ios() {
|
||||
|
||||
@available(iOS, unavailable)
|
||||
func ios_call_ios_extension() {
|
||||
ios_extension() // expected-error {{'ios_extension()' is unavailable}}
|
||||
ios_extension()
|
||||
}
|
||||
|
||||
@available(iOS, unavailable)
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
func osx() {} // expected-note 3{{'osx()' has been explicitly marked unavailable here}}
|
||||
|
||||
@available(OSXApplicationExtension, unavailable)
|
||||
func osx_extension() {} // expected-note 3{{'osx_extension()' has been explicitly marked unavailable here}}
|
||||
func osx_extension() {} // expected-note {{'osx_extension()' has been explicitly marked unavailable here}}
|
||||
|
||||
func call_osx_extension() {
|
||||
osx_extension() // expected-error {{'osx_extension()' is unavailable}}
|
||||
@@ -18,7 +18,7 @@ func call_osx() {
|
||||
|
||||
@available(OSX, unavailable)
|
||||
func osx_call_osx_extension() {
|
||||
osx_extension() // expected-error {{'osx_extension()' is unavailable}}
|
||||
osx_extension()
|
||||
}
|
||||
|
||||
@available(OSX, unavailable)
|
||||
@@ -46,7 +46,7 @@ extension NotOnOSX {
|
||||
}
|
||||
|
||||
func osx_call_osx_extension() {
|
||||
osx_extension() // expected-error {{'osx_extension()' is unavailable in application extensions for macOS}}
|
||||
osx_extension()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user