Skip to content

Commit 8521453

Browse files
committed
[Concurrency] Drop "Asynchronously" suffix from imported 'async' methods.
The "Asynchronously" is a needless word for an "async" function. Remove it.
1 parent 24ea8be commit 8521453

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

lib/Basic/StringExtras.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,15 @@ bool swift::omitNeedlessWords(StringRef &baseName,
13011301
splitBaseName(baseName, argNames[0], paramTypes[0], firstParamName))
13021302
anyChanges = true;
13031303

1304+
// For a method imported as "async", drop the "Asynchronously" suffix from
1305+
// the base name. It is redundant with 'async'.
1306+
const StringRef asynchronously = "Asynchronously";
1307+
if (isAsync && camel_case::getLastWord(baseName) == asynchronously &&
1308+
baseName.size() > asynchronously.size()) {
1309+
baseName = baseName.drop_back(asynchronously.size());
1310+
anyChanges = true;
1311+
}
1312+
13041313
// Omit needless words based on parameter types.
13051314
for (unsigned i = 0, n = argNames.size(); i != n; ++i) {
13061315
// If there is no corresponding parameter, there is nothing to

test/ClangImporter/objc_async.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func testSlowServer(slowServer: SlowServer) async throws {
2020
// expected-error@-1{{call is 'async' but is not marked with 'await'}}
2121

2222
let _: String? = await try slowServer.fortune()
23+
let _: Int = await try slowServer.magicNumber(withSeed: 42)
2324
}
2425

2526
func testSlowServerSynchronous(slowServer: SlowServer) {

test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
-(void)findAnswerAsynchronously:(void (^)(NSString *_Nullable, NSError * _Nullable))handler __attribute__((swift_name("findAnswer(completionHandler:)")));
1111
-(BOOL)findAnswerFailinglyWithError:(NSError * _Nullable * _Nullable)error completion:(void (^)(NSString *_Nullable, NSError * _Nullable))handler __attribute__((swift_name("findAnswerFailingly(completionHandler:)")));
1212
-(void)doSomethingFun:(NSString *)operation then:(void (^)(void))completionHandler;
13-
-(void)getFortuneWithCompletionHandler:(void (^)(NSString *_Nullable, NSError * _Nullable))handler;
13+
-(void)getFortuneAsynchronouslyWithCompletionHandler:(void (^)(NSString *_Nullable, NSError * _Nullable))handler;
14+
-(void)getMagicNumberAsynchronouslyWithSeed:(NSInteger)seed completionHandler:(void (^)(NSInteger, NSError * _Nullable))handler;
1415
@property(readwrite) void (^completionHandler)(NSInteger);
1516

1617
-(void)doSomethingConflicted:(NSString *)operation completionHandler:(void (^)(NSInteger))handler;

0 commit comments

Comments
 (0)