Skip to content

Commit 81a52f5

Browse files
Merge pull request #4525 from swiftwasm/main
[pull] swiftwasm from main
2 parents 1875f06 + 261953a commit 81a52f5

File tree

17 files changed

+93
-33
lines changed

17 files changed

+93
-33
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5575,10 +5575,16 @@ NOTE(note_deprecated_rename, none,
55755575
"use '%0' instead", (StringRef))
55765576

55775577
ERROR(availability_decl_more_than_enclosing, none,
5578-
"declaration cannot be more available than enclosing scope", ())
5578+
"%0 cannot be more available than enclosing scope",
5579+
(DescriptiveDeclKind))
5580+
5581+
NOTE(availability_implicit_decl_here, none,
5582+
"%0 implicitly declared here with availability of %1 %2 or newer",
5583+
(DescriptiveDeclKind, StringRef, llvm::VersionTuple))
55795584

55805585
NOTE(availability_decl_more_than_enclosing_enclosing_here, none,
5581-
"enclosing scope here", ())
5586+
"enclosing scope requires availability of %0 %1 or newer",
5587+
(StringRef, llvm::VersionTuple))
55825588

55835589
ERROR(availability_decl_only_version_newer, none,
55845590
"%0 is only available in %1 %2 or newer",

lib/AST/Expr.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,12 @@ Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {
19061906
return expr;
19071907
};
19081908

1909+
auto maybeUnwrapConversions = [](Expr *expr) {
1910+
if (auto *covariantReturn = dyn_cast<CovariantReturnConversionExpr>(expr))
1911+
expr = covariantReturn->getSubExpr();
1912+
return expr;
1913+
};
1914+
19091915
switch (getThunkKind()) {
19101916
case AutoClosureExpr::Kind::None:
19111917
case AutoClosureExpr::Kind::AsyncLet:
@@ -1916,6 +1922,7 @@ Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {
19161922
body = body->getSemanticsProvidingExpr();
19171923
body = maybeUnwrapOpenExistential(body);
19181924
body = maybeUnwrapOptionalEval(body);
1925+
body = maybeUnwrapConversions(body);
19191926

19201927
if (auto *outerCall = dyn_cast<ApplyExpr>(body)) {
19211928
return outerCall->getFn();
@@ -1934,6 +1941,7 @@ Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {
19341941
innerBody = innerBody->getSemanticsProvidingExpr();
19351942
innerBody = maybeUnwrapOpenExistential(innerBody);
19361943
innerBody = maybeUnwrapOptionalEval(innerBody);
1944+
innerBody = maybeUnwrapConversions(innerBody);
19371945

19381946
if (auto *outerCall = dyn_cast<ApplyExpr>(innerBody)) {
19391947
if (auto *innerCall = dyn_cast<ApplyExpr>(outerCall->getFn())) {

lib/ClangImporter/ClangImporter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,9 +2224,10 @@ bool PlatformAvailability::isPlatformRelevant(StringRef name) const {
22242224
return name == "ios" || name == "ios_app_extension";
22252225

22262226
case PlatformKind::macCatalyst:
2227+
return name == "ios" || name == "maccatalyst";
22272228
case PlatformKind::macCatalystApplicationExtension:
2228-
// ClangImporter does not yet support macCatalyst.
2229-
return false;
2229+
return name == "ios" || name == "ios_app_extension" ||
2230+
name == "maccatalyst" || name == "maccatalyst_app_extension";
22302231

22312232
case PlatformKind::tvOS:
22322233
return name == "tvos";

lib/ClangImporter/ImportDecl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9083,9 +9083,12 @@ void ClangImporter::Implementation::importAttributes(
90839083
llvm::StringSwitch<Optional<PlatformKind>>(Platform)
90849084
.Case("ios", PlatformKind::iOS)
90859085
.Case("macos", PlatformKind::macOS)
9086+
.Case("maccatalyst", PlatformKind::macCatalyst)
90869087
.Case("tvos", PlatformKind::tvOS)
90879088
.Case("watchos", PlatformKind::watchOS)
90889089
.Case("ios_app_extension", PlatformKind::iOSApplicationExtension)
9090+
.Case("maccatalyst_app_extension",
9091+
PlatformKind::macCatalystApplicationExtension)
90899092
.Case("macos_app_extension",
90909093
PlatformKind::macOSApplicationExtension)
90919094
.Case("tvos_app_extension",

lib/Sema/TypeCheckAttr.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,9 +1710,19 @@ void AttributeChecker::visitAvailableAttr(AvailableAttr *attr) {
17101710

17111711
if (EnclosingDecl) {
17121712
if (!AttrRange.isContainedIn(EnclosingAnnotatedRange.getValue())) {
1713-
diagnose(attr->getLocation(), diag::availability_decl_more_than_enclosing);
1713+
diagnose(D->isImplicit() ? EnclosingDecl->getLoc() : attr->getLocation(),
1714+
diag::availability_decl_more_than_enclosing,
1715+
D->getDescriptiveKind());
1716+
if (D->isImplicit())
1717+
diagnose(EnclosingDecl->getLoc(),
1718+
diag::availability_implicit_decl_here,
1719+
D->getDescriptiveKind(),
1720+
prettyPlatformString(targetPlatform(Ctx.LangOpts)),
1721+
AttrRange.getOSVersion().getLowerEndpoint());
17141722
diagnose(EnclosingDecl->getLoc(),
1715-
diag::availability_decl_more_than_enclosing_enclosing_here);
1723+
diag::availability_decl_more_than_enclosing_enclosing_here,
1724+
prettyPlatformString(targetPlatform(Ctx.LangOpts)),
1725+
EnclosingAnnotatedRange->getOSVersion().getLowerEndpoint());
17161726
}
17171727
}
17181728

test/ClangImporter/objc_parse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ func ivars(_ hive: Hive) {
315315
hive.queen.description() // expected-error{{value of type 'Hive' has no member 'queen'}}
316316
}
317317

318-
class NSObjectable : NSObjectProtocol {
318+
class NSObjectable : NSObjectProtocol { // expected-error {{cannot declare conformance to 'NSObjectProtocol' in Swift; 'NSObjectable' should inherit 'NSObject' instead}}
319319
@objc var description : String { return "" }
320320
@objc(conformsToProtocol:) func conforms(to _: Protocol) -> Bool { return false }
321321
@objc(isKindOfClass:) func isKind(of aClass: AnyClass) -> Bool { return false }

test/Distributed/Runtime/distributed_actor_init_local.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// UNSUPPORTED: use_os_stdlib
99
// UNSUPPORTED: back_deployment_runtime
1010

11+
// REQUIRES: rdar92910719
12+
1113
import Distributed
1214

1315
enum MyError: Error {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -enable-objc-interop -print-indexed-symbols -source-filename %s | %FileCheck %s
2+
// REQUIRES: objc_interop
3+
4+
import Foundation
5+
6+
@objc
7+
class Foo: NSObject {
8+
// CHECK-DAG: constructor/Swift | init(object:)
9+
init(object: Any?) {}
10+
}
11+
12+
extension Foo {
13+
// CHECK-DAG: static-property/Swift | boom
14+
static let boom = Foo(object: self)
15+
}

test/Inputs/clang-importer-sdk/usr/include/objc/NSObject.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
@class NSString;
77

88
@protocol NSObject
9+
- (instancetype)self;
910
@property (readonly, copy) NSString *description;
1011
- (instancetype)retain OBJC_ARC_UNAVAILABLE;
1112
- (Class)class;

test/PrintAsObjC/classes.swift

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,6 @@ class ClassWithCustomName2 {}
113113
@objc(CustomNameSub)
114114
class ClassWithCustomNameSub : ClassWithCustomName {}
115115

116-
117-
// CHECK-LABEL: @interface ClassWithNSObjectProtocol <NSObject>
118-
// CHECK-NEXT: @property (nonatomic, readonly, copy) NSString * _Nonnull description;
119-
// CHECK-NEXT: - (BOOL)conformsToProtocol:(Protocol * _Nonnull)_ SWIFT_WARN_UNUSED_RESULT;
120-
// CHECK-NEXT: - (BOOL)isKindOfClass:(Class _Nonnull)aClass SWIFT_WARN_UNUSED_RESULT;
121-
// CHECK-NEXT: - (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
122-
// CHECK-NEXT: @end
123-
@objc @objcMembers class ClassWithNSObjectProtocol : NSObjectProtocol {
124-
@objc var description: String { return "me" }
125-
@objc(conformsToProtocol:)
126-
func conforms(to _: Protocol) -> Bool { return false }
127-
128-
@objc(isKindOfClass:)
129-
func isKind(of aClass: AnyClass) -> Bool { return false }
130-
}
131-
132116
// CHECK-LABEL: @interface DiscardableResult : NSObject
133117
// CHECK-NEXT: - (NSInteger)nonDiscardable:(NSInteger)x SWIFT_WARN_UNUSED_RESULT;
134118
// CHECK-NEXT: - (NSInteger)discardable:(NSInteger)x;

test/Sema/availability_versions.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -615,19 +615,19 @@ class ClassAvailableOn10_9 {
615615
}
616616

617617
@available(OSX, introduced: 10.51)
618-
class ClassAvailableOn10_51 { // expected-note {{enclosing scope here}}
618+
class ClassAvailableOn10_51 { // expected-note {{enclosing scope requires availability of macOS 10.51 or newer}}
619619
func someMethod() {}
620620
class func someClassMethod() {
621621
let _ = ClassAvailableOn10_51()
622622
}
623623
var someProp : Int = 22
624624

625-
@available(OSX, introduced: 10.9) // expected-error {{declaration cannot be more available than enclosing scope}}
625+
@available(OSX, introduced: 10.9) // expected-error {{instance method cannot be more available than enclosing scope}}
626626
func someMethodAvailableOn10_9() { }
627627

628628
@available(OSX, introduced: 10.52)
629-
var propWithGetter: Int { // expected-note{{enclosing scope here}}
630-
@available(OSX, introduced: 10.51) // expected-error {{declaration cannot be more available than enclosing scope}}
629+
var propWithGetter: Int { // expected-note{{enclosing scope requires availability of macOS 10.52 or newer}}
630+
@available(OSX, introduced: 10.51) // expected-error {{getter cannot be more available than enclosing scope}}
631631
get { return 0 }
632632
}
633633
}
@@ -1022,8 +1022,8 @@ extension ClassToExtend : ProtocolAvailableOn10_51 {
10221022
}
10231023

10241024
@available(OSX, introduced: 10.51)
1025-
extension ClassToExtend { // expected-note {{enclosing scope here}}
1026-
@available(OSX, introduced: 10.9) // expected-error {{declaration cannot be more available than enclosing scope}}
1025+
extension ClassToExtend { // expected-note {{enclosing scope requires availability of macOS 10.51 or newer}}
1026+
@available(OSX, introduced: 10.9) // expected-error {{instance method cannot be more available than enclosing scope}}
10271027
func extensionMethod10_9() { }
10281028
}
10291029

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@import Foundation;
2+
3+
__attribute__((availability(macosx,introduced=10.0)))
4+
__attribute__((availability(ios,introduced=2.0)))
5+
__attribute__((availability(tvos,introduced=1.0)))
6+
__attribute__((availability(watchos,introduced=2.0)))
7+
__attribute__((availability(maccatalyst,introduced=13.1)))
8+
@interface NSBaseClass : NSObject
9+
- (instancetype) init
10+
__attribute__((objc_designated_initializer))
11+
__attribute__((availability(macosx,introduced=10.0)))
12+
__attribute__((availability(ios,introduced=2.0)))
13+
__attribute__((availability(tvos,introduced=1.0)))
14+
__attribute__((availability(watchos,introduced=2.0)))
15+
__attribute__((availability(maccatalyst,introduced=13.1)));
16+
@end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
module AttrObjc_FooClangModule { header "attr_objc_foo_clang_module.h" }
22
module Testable_ClangModule { header "testable_clang.h" }
33
module ObjcAsync { header "objc_async.h" }
4+
module Available_NSObject { header "available_nsobject.h" }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-swift-frontend -I %t -I %S/Inputs/custom-modules -parse-stdlib -parse-as-library -typecheck -verify -target x86_64-apple-ios15.4-macabi %s
2+
3+
// REQUIRES: objc_interop
4+
// REQUIRES: maccatalyst_support
5+
6+
import Available_NSObject
7+
8+
@available(iOS 15.0, *)
9+
open class OverAvailableClass: NSBaseClass {}
10+
// expected-error@-1 {{initializer cannot be more available than enclosing scope}}
11+
// expected-note@-2 {{initializer implicitly declared here with availability of Mac Catalyst 13.1 or newer}}
12+
// expected-note@-3 {{enclosing scope requires availability of Mac Catalyst 15.0 or newer}}
13+

test/attr/attr_availability_osx.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ doSomethingDeprecatedOniOS() // okay
8484
struct TestStruct {}
8585

8686
@available(macOS 10.10, *)
87-
extension TestStruct { // expected-note {{enclosing scope here}}
87+
extension TestStruct { // expected-note {{enclosing scope requires availability of macOS 10.10 or newer}}
8888
@available(swift 400)
8989
func doTheThing() {} // expected-note {{'doTheThing()' was introduced in Swift 400}}
9090

91-
@available(macOS 10.9, *) // expected-error {{declaration cannot be more available than enclosing scope}}
91+
@available(macOS 10.9, *) // expected-error {{instance method cannot be more available than enclosing scope}}
9292
@available(swift 400)
9393
func doAnotherThing() {} // expected-note {{'doAnotherThing()' was introduced in Swift 400}}
9494

utils/build_swift/build_swift/shell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def quote(command):
206206
if isinstance(command, (str,)):
207207
return _quote(command)
208208

209-
if isinstance(command, collections.Iterable):
209+
if isinstance(command, collections.abc.Iterable):
210210
return ' '.join([_quote(arg) for arg in _normalize_args(command)])
211211

212212
raise ValueError('Invalid command type: {}'.format(type(command).__name__))

utils/build_swift/tests/build_swift/test_shell.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def duplicate(x):
6565

6666
result = shell._flatmap(duplicate, [1, 2, 3])
6767

68-
self.assertIsInstance(result, collections.Iterable)
68+
self.assertIsInstance(result, collections.abc.Iterable)
6969
self.assertEqual(list(result), [1, 1, 2, 2, 3, 3])
7070

7171
# -------------------------------------------------------------------------

0 commit comments

Comments
 (0)