Skip to content

Commit 24ea8be

Browse files
committed
[Concurrency] Move removal of leading "get" for async imports.
Name adjustments should be performed by omitNeedlessWords(), not the early classifcation of async imports.
1 parent e185295 commit 24ea8be

File tree

6 files changed

+32
-31
lines changed

6 files changed

+32
-31
lines changed

include/swift/Basic/StringExtras.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ class InheritedNameSet {
442442
///
443443
/// \param allPropertyNames The set of property names in the enclosing context.
444444
///
445+
/// \param isAsync Whether this is a function imported as 'async'.
446+
///
445447
/// \param scratch Scratch space that will be used for modifications beyond
446448
/// just chopping names.
447449
///
@@ -455,6 +457,7 @@ bool omitNeedlessWords(StringRef &baseName,
455457
bool returnsSelf,
456458
bool isProperty,
457459
const InheritedNameSet *allPropertyNames,
460+
bool isAsync,
458461
StringScratchSpace &scratch);
459462

460463
} // end namespace swift

lib/Basic/StringExtras.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,7 @@ bool swift::omitNeedlessWords(StringRef &baseName,
12201220
bool returnsSelf,
12211221
bool isProperty,
12221222
const InheritedNameSet *allPropertyNames,
1223+
bool isAsync,
12231224
StringScratchSpace &scratch) {
12241225
bool anyChanges = false;
12251226
OmissionTypeName resultType = returnsSelf ? contextType : givenResultType;
@@ -1287,6 +1288,14 @@ bool swift::omitNeedlessWords(StringRef &baseName,
12871288
}
12881289
}
12891290

1291+
// If the base name of a method imported as "async" starts with the word
1292+
// "get", drop the "get".
1293+
if (isAsync && camel_case::getFirstWord(baseName) == "get" &&
1294+
baseName.size() > 3) {
1295+
baseName = baseName.substr(3);
1296+
anyChanges = true;
1297+
}
1298+
12901299
// If needed, split the base name.
12911300
if (!argNames.empty() &&
12921301
splitBaseName(baseName, argNames[0], paramTypes[0], firstParamName))

lib/ClangImporter/IAMInference.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ class IAMInference {
448448
baseName = humbleBaseName.userFacingName();
449449
bool didOmit =
450450
omitNeedlessWords(baseName, argStrs, "", "", "", paramTypeNames, false,
451-
false, nullptr, scratch);
451+
false, nullptr, false, scratch);
452452
SmallVector<Identifier, 8> argLabels;
453453
for (auto str : argStrs)
454454
argLabels.push_back(getIdentifier(str));

lib/ClangImporter/ImportName.cpp

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ static bool omitNeedlessWordsInFunctionName(
804804
ArrayRef<const clang::ParmVarDecl *> params, clang::QualType resultType,
805805
const clang::DeclContext *dc, const SmallBitVector &nonNullArgs,
806806
Optional<unsigned> errorParamIndex, bool returnsSelf, bool isInstanceMethod,
807-
NameImporter &nameImporter) {
807+
Optional<unsigned> completionHandlerIndex, NameImporter &nameImporter) {
808808
clang::ASTContext &clangCtx = nameImporter.getClangContext();
809809

810810
// Collect the parameter type names.
@@ -817,10 +817,6 @@ static bool omitNeedlessWordsInFunctionName(
817817
if (i == 0)
818818
firstParamName = param->getName();
819819

820-
// Determine the number of parameters.
821-
unsigned numParams = params.size();
822-
if (errorParamIndex) --numParams;
823-
824820
bool isLastParameter
825821
= (i == params.size() - 1) ||
826822
(i == params.size() - 2 &&
@@ -858,7 +854,8 @@ static bool omitNeedlessWordsInFunctionName(
858854
getClangTypeNameForOmission(clangCtx, resultType),
859855
getClangTypeNameForOmission(clangCtx, contextType),
860856
paramTypes, returnsSelf, /*isProperty=*/false,
861-
allPropertyNames, nameImporter.getScratch());
857+
allPropertyNames, completionHandlerIndex.hasValue(),
858+
nameImporter.getScratch());
862859
}
863860

864861
/// Prepare global name for importing onto a swift_newtype.
@@ -1189,7 +1186,6 @@ Optional<ForeignAsyncConvention::Info>
11891186
NameImporter::considerAsyncImport(
11901187
const clang::ObjCMethodDecl *clangDecl,
11911188
StringRef &baseName,
1192-
SmallVectorImpl<char> &baseNameScratch,
11931189
SmallVectorImpl<StringRef> &paramNames,
11941190
ArrayRef<const clang::ParmVarDecl *> params,
11951191
bool isInitializer, bool hasCustomName,
@@ -1225,17 +1221,6 @@ NameImporter::considerAsyncImport(
12251221
return None;
12261222
}
12271223

1228-
// If there's no custom name, and the base name starts with "get", drop the
1229-
// get.
1230-
if (!hasCustomName) {
1231-
StringRef currentBaseName = newBaseName ? *newBaseName : baseName;
1232-
if (currentBaseName.size() > 3 &&
1233-
camel_case::getFirstWord(currentBaseName) == "get") {
1234-
newBaseName = camel_case::toLowercaseInitialisms(
1235-
currentBaseName.substr(3), baseNameScratch);
1236-
}
1237-
}
1238-
12391224
// Used for returns once we've determined that the method cannot be
12401225
// imported as async, even though it has what looks like a completion handler
12411226
// parameter.
@@ -1473,7 +1458,6 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
14731458
}
14741459

14751460
// If we have a swift_name attribute, use that.
1476-
SmallString<32> asyncBaseNameScratch;
14771461
if (auto *nameAttr = findSwiftNameAttr(D, version)) {
14781462
bool skipCustomName = false;
14791463

@@ -1552,9 +1536,9 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
15521536

15531537
if (version.supportsConcurrency()) {
15541538
if (auto asyncInfo = considerAsyncImport(
1555-
method, parsedName.BaseName, asyncBaseNameScratch,
1556-
parsedName.ArgumentLabels, params, isInitializer,
1557-
/*hasCustomName=*/true, result.getErrorInfo())) {
1539+
method, parsedName.BaseName, parsedName.ArgumentLabels,
1540+
params, isInitializer, /*hasCustomName=*/true,
1541+
result.getErrorInfo())) {
15581542
result.info.hasAsyncInfo = true;
15591543
result.info.asyncInfo = *asyncInfo;
15601544

@@ -1829,9 +1813,8 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
18291813
if (version.supportsConcurrency() &&
18301814
result.info.accessorKind == ImportedAccessorKind::None) {
18311815
if (auto asyncInfo = considerAsyncImport(
1832-
objcMethod, baseName, asyncBaseNameScratch,
1833-
argumentNames, params, isInitializer, /*hasCustomName=*/false,
1834-
result.getErrorInfo())) {
1816+
objcMethod, baseName, argumentNames, params, isInitializer,
1817+
/*hasCustomName=*/false, result.getErrorInfo())) {
18351818
result.info.hasAsyncInfo = true;
18361819
result.info.asyncInfo = *asyncInfo;
18371820
}
@@ -1971,7 +1954,7 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
19711954
(void)omitNeedlessWords(baseName, {}, "", propertyTypeName,
19721955
contextTypeName, {}, /*returnsSelf=*/false,
19731956
/*isProperty=*/true, allPropertyNames,
1974-
scratch);
1957+
/*isAsync=*/false, scratch);
19751958
}
19761959
}
19771960

@@ -1983,7 +1966,12 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
19831966
result.getErrorInfo()
19841967
? Optional<unsigned>(result.getErrorInfo()->ErrorParameterIndex)
19851968
: None,
1986-
method->hasRelatedResultType(), method->isInstanceMethod(), *this);
1969+
method->hasRelatedResultType(), method->isInstanceMethod(),
1970+
result.getAsyncInfo().map(
1971+
[](const ForeignAsyncConvention::Info &info) {
1972+
return info.CompletionHandlerParamIndex;
1973+
}),
1974+
*this);
19871975
}
19881976

19891977
// If the result is a value, lowercase it.

lib/ClangImporter/ImportName.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ class NameImporter {
456456
Optional<ForeignAsyncConvention::Info>
457457
considerAsyncImport(const clang::ObjCMethodDecl *clangDecl,
458458
StringRef &baseName,
459-
SmallVectorImpl<char> &baseNameScratch,
460459
SmallVectorImpl<StringRef> &paramNames,
461460
ArrayRef<const clang::ParmVarDecl *> params,
462461
bool isInitializer, bool hasCustomName,

lib/Sema/MiscDiagnostics.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4867,7 +4867,8 @@ Optional<DeclName> TypeChecker::omitNeedlessWords(AbstractFunctionDecl *afd) {
48674867
getTypeNameForOmission(resultType),
48684868
getTypeNameForOmission(contextType),
48694869
paramTypes, returnsSelf, false,
4870-
/*allPropertyNames=*/nullptr, scratch))
4870+
/*allPropertyNames=*/nullptr,
4871+
afd->hasAsync(), scratch))
48714872
return None;
48724873

48734874
/// Retrieve a replacement identifier.
@@ -4922,7 +4923,8 @@ Optional<Identifier> TypeChecker::omitNeedlessWords(VarDecl *var) {
49224923
OmissionTypeName contextTypeName = getTypeNameForOmission(contextType);
49234924
if (::omitNeedlessWords(name, { }, "", typeName, contextTypeName, { },
49244925
/*returnsSelf=*/false, true,
4925-
/*allPropertyNames=*/nullptr, scratch)) {
4926+
/*allPropertyNames=*/nullptr, /*isAsync=*/false,
4927+
scratch)) {
49264928
return Context.getIdentifier(name);
49274929
}
49284930

0 commit comments

Comments
 (0)