Skip to content

macCatalyst availability fixes #77506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ClangImporter/ClangAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ bool importer::isUnavailableInSwift(
if (version.empty())
continue;
if (platformAvailability->treatDeprecatedAsUnavailable(
decl, version, /*isAsync=*/false)) {
decl, version, /*isAsync=*/false, attr->isImplicit())) {
return true;
}
}
Expand Down
16 changes: 13 additions & 3 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2610,7 +2610,7 @@ bool PlatformAvailability::isPlatformRelevant(StringRef name) const {

bool PlatformAvailability::treatDeprecatedAsUnavailable(
const clang::Decl *clangDecl, const llvm::VersionTuple &version,
bool isAsync) const {
bool isAsync, bool isImplicitAvailability) const {
assert(!version.empty() && "Must provide version when deprecated");
unsigned major = version.getMajor();
std::optional<unsigned> minor = version.getMinor();
Expand Down Expand Up @@ -2647,8 +2647,18 @@ bool PlatformAvailability::treatDeprecatedAsUnavailable(

case PlatformKind::macCatalyst:
case PlatformKind::macCatalystApplicationExtension:
// ClangImporter does not yet support macCatalyst.
return false;
if (!isImplicitAvailability) {
// Anything deprecated by iOS 12 is unavailable for async import
// in Swift.
if (isAsync && !clangDecl->hasAttr<clang::SwiftAsyncAttr>()) {
return major <= 12;
}

// Anything deprecated in iOS 7.x and earlier is unavailable in Swift.
return major <= 7;
}

return major <= 13 && (!minor || *minor <= 1);

case PlatformKind::watchOS:
case PlatformKind::watchOSApplicationExtension:
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8672,7 +8672,7 @@ void ClangImporter::Implementation::importAttributes(

if (!deprecated.empty()) {
if (platformAvailability.treatDeprecatedAsUnavailable(
ClangDecl, deprecated, isAsync)) {
ClangDecl, deprecated, isAsync, avail->isImplicit())) {
AnyUnavailable = true;
PlatformAgnostic = PlatformAgnosticAvailabilityKind::Unavailable;
if (message.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ImporterImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ struct PlatformAvailability {
/// unavailable.
bool treatDeprecatedAsUnavailable(const clang::Decl *clangDecl,
const llvm::VersionTuple &version,
bool isAsync) const;
bool isAsync, bool isAvailabilityImplicit) const;

/// The message to embed for implicitly unavailability if a deprecated
/// API is now unavailable.
Expand Down
28 changes: 28 additions & 0 deletions test/ClangImporter/Inputs/custom-modules/AvailabilityExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,36 @@ struct NSSwiftUnavailableStruct {
int secrets;
} __attribute__((availability(swift, unavailable)));

struct UnavailableOniOS {
int foobar;
} __attribute__((availability(ios,unavailable)));

struct UnavailableOnMacCatalystOnly {
int foobar;
} __attribute__((availability(maccatalyst,unavailable)));

struct AvailableOnMacCatalystOnly {
int foobar;
} __attribute__((availability(maccatalyst, introduced=13.1))) __attribute__((availability(ios, unavailable)));

void unavailableWithOS() __attribute__((availability(ios, deprecated=8.0))) __attribute__((availability(swift, unavailable))) __attribute__((availability(macosx, deprecated=10.10))) ;

void availableOnIOSButUnavailableOnmacCatalyst() __attribute__((availability(ios,introduced=7.0))) __attribute__((availability(maccatalyst,unavailable)));

void availableOnIOSButDeprecatedOnmacCatalyst() __attribute__((availability(ios,introduced=7.0))) __attribute__((availability(maccatalyst,deprecated=9.0)));

void unavailableOnIOS() __attribute__((availability(ios,unavailable)));

void deprecatedOniOSButNotOnmacCatalyst() __attribute__((availability(ios,deprecated=13.1))) __attribute__((availability(maccatalyst,introduced=13.1)));

void availableOnIOSButUnavailableOniOSAppExtension() __attribute__((availability(ios,introduced=7.0))) __attribute__((availability(ios_app_extension,unavailable)));

void availableOnIOSButDeprecatedOniOSAppExtension() __attribute__((availability(ios,introduced=7.0))) __attribute__((availability(ios_app_extension,deprecated=7.0)));

void availableOnIOSAppExtensionButUnavailableOnmacCatalystAppExtension() __attribute__((availability(ios_app_extension,introduced=7.0))) __attribute__((availability(maccatalyst_app_extension,unavailable)));

void availableOnIOSAppExtensionButDeprecatedOnmacCatalystAppExtension() __attribute__((availability(ios_app_extension,introduced=7.0))) __attribute__((availability(maccatalyst_app_extension,deprecated=7.0)));

typedef NS_ENUM(NSInteger, NSEnumAddedCasesIn2017) {
NSEnumAddedCasesIn2017ExistingCaseOne,
NSEnumAddedCasesIn2017ExistingCaseTwo,
Expand Down
43 changes: 43 additions & 0 deletions utils/build-presets.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2334,6 +2334,21 @@ skip-test-tvos
skip-test-ios
skip-reconfigure

[preset: mixin_buildbot_incremental,test=macCatalyst,type=device]

test
validation-test
lit-args=-v

ios
maccatalyst

skip-test-ios
skip-test-tvos
skip-test-watchos
skip-test-xros
skip-reconfigure

#===------------------------------------------------------------------------===#
# Swift Preset
# Tools: Release and Assertions
Expand Down Expand Up @@ -2369,6 +2384,11 @@ mixin-preset=
buildbot_incremental,tools=RA,stdlib=RD,build
mixin_buildbot_incremental,test=watchOS,type=simulator

[preset: buildbot_incremental,tools=RA,stdlib=RD,test=macCatalyst,type=device]
mixin-preset=
buildbot_incremental,tools=RA,stdlib=RD,build
mixin_buildbot_incremental,test=macCatalyst,type=device

#===------------------------------------------------------------------------===#
# Swift Preset
# Tools: Release and Assertions
Expand Down Expand Up @@ -2415,6 +2435,13 @@ mixin-preset=

test-optimized

[preset: buildbot_incremental,tools=RA,stdlib=RDA,test=macCatalyst,type=device]
mixin-preset=
buildbot_incremental,tools=RA,stdlib=RDA,build
mixin_buildbot_incremental,test=macCatalyst,type=device

test-optimized

#===------------------------------------------------------------------------===#
# Swift Preset
# Tools: Release and Assertions
Expand Down Expand Up @@ -2458,6 +2485,14 @@ mixin-preset=

test-optimized

[preset: buildbot_incremental,tools=RA,stdlib=DA,test=macCatalyst,type=device]
mixin-preset=
buildbot_incremental,tools=RA,stdlib=DA,build
mixin_buildbot_incremental,test=macCatalyst,type=device

test-optimized


#===------------------------------------------------------------------------===#
# Swift Preset
# Tools: Release and Assertions
Expand Down Expand Up @@ -2498,6 +2533,14 @@ mixin-preset=

test-optimized

[preset: buildbot_incremental,tools=RA,stdlib=RA,test=macCatalyst,type=device]
mixin-preset=
buildbot_incremental,tools=RA,stdlib=RA,build
mixin_buildbot_incremental,test=macCatalyst,type=device

test-optimized


#===------------------------------------------------------------------------===#
# Swift Preset
# Tools: DebInfo and Assertions
Expand Down