Skip to content

Commit 0183d13

Browse files
authored
Merge pull request swiftlang#35955 from DougGregor/se-0297-default
2 parents 4b44bf7 + 77105a4 commit 0183d13

File tree

6 files changed

+33
-17
lines changed

6 files changed

+33
-17
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,31 @@ Swift Next
7575
}
7676
```
7777

78+
* [SE-0297][]:
79+
80+
An Objective-C method that delivers its results asynchronously via a completion handler block will be translated into an `async` method that directly returns the result (or throws). For example, the following Objective-C method from [CloudKit](https://developer.apple.com/documentation/cloudkit/ckcontainer/1640387-fetchshareparticipantwithuserrec):
81+
82+
```objc
83+
- (void)fetchShareParticipantWithUserRecordID:(CKRecordID *)userRecordID
84+
completionHandler:(void (^)(CKShareParticipant * _Nullable, NSError * _Nullable))completionHandler;
85+
```
86+
87+
will be translated into an `async throws` method that returns the participant instance:
88+
89+
```swift
90+
func fetchShareParticipant(
91+
withUserRecordID userRecordID: CKRecord.ID
92+
) async throws -> CKShare.Participant
93+
```
94+
95+
Swift callers can invoke this `async` method within an `await` expression:
96+
97+
```swift
98+
guard let participant = try? await container.fetchShareParticipant(withUserRecordID: user) else {
99+
return nil
100+
}
101+
```
102+
78103
* [SE-0298][]:
79104

80105
The "for" loop can be used to traverse asynchronous sequences in asynchronous code:
@@ -8336,6 +8361,7 @@ Swift 1.0
83368361
[SE-0286]: <https://github.com/apple/swift-evolution/blob/main/proposals/0286-forward-scan-trailing-closures.md>
83378362
[SE-0287]: <https://github.com/apple/swift-evolution/blob/main/proposals/0287-implicit-member-chains.md>
83388363
[SE-0296]: <https://github.com/apple/swift-evolution/blob/main/proposals/0296-async-await.md>
8364+
[SE-0297]: <https://github.com/apple/swift-evolution/blob/main/proposals/0297-concurrency-objc.md>
83398365
[SE-0298]: <https://github.com/apple/swift-evolution/blob/main/proposals/0298-asyncsequence.md>
83408366

83418367
[SR-75]: <https://bugs.swift.org/browse/SR-75>

lib/ClangImporter/ClangImporter.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3781,7 +3781,6 @@ void ClangImporter::Implementation::lookupValue(
37813781
clangDecl->getMostRecentDecl();
37823782

37833783
CurrentVersion.forEachOtherImportNameVersion(
3784-
SwiftContext.LangOpts.EnableExperimentalConcurrency,
37853784
[&](ImportNameVersion nameVersion) {
37863785
if (anyMatching)
37873786
return;

lib/ClangImporter/ImportDecl.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7700,8 +7700,7 @@ void SwiftDeclConverter::importNonOverriddenMirroredMethods(DeclContext *dc,
77007700
members.push_back(alternate);
77017701
}
77027702

7703-
if (Impl.SwiftContext.LangOpts.EnableExperimentalConcurrency &&
7704-
!getVersion().supportsConcurrency()) {
7703+
if (!getVersion().supportsConcurrency()) {
77057704
auto asyncVersion = getVersion().withConcurrency(true);
77067705
if (auto asyncImport = Impl.importMirroredDecl(
77077706
objcMethod, dc, asyncVersion, proto)) {
@@ -9090,12 +9089,10 @@ ClangImporter::Implementation::createConstant(Identifier name, DeclContext *dc,
90909089

90919090
// Mark the function transparent so that we inline it away completely.
90929091
func->getAttrs().add(new (C) TransparentAttr(/*implicit*/ true));
9093-
// If we're in concurrency mode, mark the constant as @actorIndependent
9094-
if (SwiftContext.LangOpts.EnableExperimentalConcurrency) {
9095-
auto actorIndependentAttr = new (C) ActorIndependentAttr(
9096-
ActorIndependentKind::Unsafe, /*IsImplicit=*/true);
9097-
var->getAttrs().add(actorIndependentAttr);
9098-
}
9092+
auto actorIndependentAttr = new (C) ActorIndependentAttr(
9093+
ActorIndependentKind::Unsafe, /*IsImplicit=*/true);
9094+
var->getAttrs().add(actorIndependentAttr);
9095+
90999096
// Set the function up as the getter.
91009097
makeComputed(var, func, nullptr);
91019098

lib/ClangImporter/ImportName.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,6 @@ bool NameImporter::forEachDistinctImportName(
22492249
seenNames.push_back(key);
22502250

22512251
activeVersion.forEachOtherImportNameVersion(
2252-
swiftCtx.LangOpts.EnableExperimentalConcurrency,
22532252
[&](ImportNameVersion nameVersion) {
22542253
// Check to see if the name is different.
22552254
ImportedName newName = importName(decl, nameVersion);

lib/ClangImporter/ImportName.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,14 @@ class ImportNameVersion : public RelationalOperationsBase<ImportNameVersion> {
116116
///
117117
/// This is the most useful order for importing compatibility stubs.
118118
void forEachOtherImportNameVersion(
119-
bool withConcurrency,
120119
llvm::function_ref<void(ImportNameVersion)> action) const {
121120
assert(*this >= ImportNameVersion::swift2());
122121

123122
ImportNameVersion nameVersion = *this;
124123
assert(!nameVersion.supportsConcurrency());
125124

126-
// If we've been asked to also consider concurrency, do so for the
127-
// primary version (only).
128-
if (withConcurrency) {
129-
action(nameVersion.withConcurrency(true));
130-
}
125+
// Consider concurrency imports.
126+
action(nameVersion.withConcurrency(true));
131127

132128
while (nameVersion > ImportNameVersion::swift2()) {
133129
--nameVersion.rawValue;

lib/ClangImporter/SwiftLookupTable.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1857,7 +1857,6 @@ SwiftNameLookupExtension::hashExtension(llvm::hash_code code) const {
18571857
SWIFT_LOOKUP_TABLE_VERSION_MAJOR,
18581858
SWIFT_LOOKUP_TABLE_VERSION_MINOR,
18591859
inferImportAsMember,
1860-
swiftCtx.LangOpts.EnableExperimentalConcurrency,
18611860
version::getSwiftFullVersion());
18621861
}
18631862

0 commit comments

Comments
 (0)