mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Concurrency] Move removal of leading "get" for async imports.
Name adjustments should be performed by omitNeedlessWords(), not the early classifcation of async imports.
This commit is contained in:
@@ -442,6 +442,8 @@ public:
|
||||
///
|
||||
/// \param allPropertyNames The set of property names in the enclosing context.
|
||||
///
|
||||
/// \param isAsync Whether this is a function imported as 'async'.
|
||||
///
|
||||
/// \param scratch Scratch space that will be used for modifications beyond
|
||||
/// just chopping names.
|
||||
///
|
||||
@@ -455,6 +457,7 @@ bool omitNeedlessWords(StringRef &baseName,
|
||||
bool returnsSelf,
|
||||
bool isProperty,
|
||||
const InheritedNameSet *allPropertyNames,
|
||||
bool isAsync,
|
||||
StringScratchSpace &scratch);
|
||||
|
||||
} // end namespace swift
|
||||
|
||||
@@ -1220,6 +1220,7 @@ bool swift::omitNeedlessWords(StringRef &baseName,
|
||||
bool returnsSelf,
|
||||
bool isProperty,
|
||||
const InheritedNameSet *allPropertyNames,
|
||||
bool isAsync,
|
||||
StringScratchSpace &scratch) {
|
||||
bool anyChanges = false;
|
||||
OmissionTypeName resultType = returnsSelf ? contextType : givenResultType;
|
||||
@@ -1287,6 +1288,14 @@ bool swift::omitNeedlessWords(StringRef &baseName,
|
||||
}
|
||||
}
|
||||
|
||||
// If the base name of a method imported as "async" starts with the word
|
||||
// "get", drop the "get".
|
||||
if (isAsync && camel_case::getFirstWord(baseName) == "get" &&
|
||||
baseName.size() > 3) {
|
||||
baseName = baseName.substr(3);
|
||||
anyChanges = true;
|
||||
}
|
||||
|
||||
// If needed, split the base name.
|
||||
if (!argNames.empty() &&
|
||||
splitBaseName(baseName, argNames[0], paramTypes[0], firstParamName))
|
||||
|
||||
@@ -448,7 +448,7 @@ private:
|
||||
baseName = humbleBaseName.userFacingName();
|
||||
bool didOmit =
|
||||
omitNeedlessWords(baseName, argStrs, "", "", "", paramTypeNames, false,
|
||||
false, nullptr, scratch);
|
||||
false, nullptr, false, scratch);
|
||||
SmallVector<Identifier, 8> argLabels;
|
||||
for (auto str : argStrs)
|
||||
argLabels.push_back(getIdentifier(str));
|
||||
|
||||
@@ -804,7 +804,7 @@ static bool omitNeedlessWordsInFunctionName(
|
||||
ArrayRef<const clang::ParmVarDecl *> params, clang::QualType resultType,
|
||||
const clang::DeclContext *dc, const SmallBitVector &nonNullArgs,
|
||||
Optional<unsigned> errorParamIndex, bool returnsSelf, bool isInstanceMethod,
|
||||
NameImporter &nameImporter) {
|
||||
Optional<unsigned> completionHandlerIndex, NameImporter &nameImporter) {
|
||||
clang::ASTContext &clangCtx = nameImporter.getClangContext();
|
||||
|
||||
// Collect the parameter type names.
|
||||
@@ -817,10 +817,6 @@ static bool omitNeedlessWordsInFunctionName(
|
||||
if (i == 0)
|
||||
firstParamName = param->getName();
|
||||
|
||||
// Determine the number of parameters.
|
||||
unsigned numParams = params.size();
|
||||
if (errorParamIndex) --numParams;
|
||||
|
||||
bool isLastParameter
|
||||
= (i == params.size() - 1) ||
|
||||
(i == params.size() - 2 &&
|
||||
@@ -858,7 +854,8 @@ static bool omitNeedlessWordsInFunctionName(
|
||||
getClangTypeNameForOmission(clangCtx, resultType),
|
||||
getClangTypeNameForOmission(clangCtx, contextType),
|
||||
paramTypes, returnsSelf, /*isProperty=*/false,
|
||||
allPropertyNames, nameImporter.getScratch());
|
||||
allPropertyNames, completionHandlerIndex.hasValue(),
|
||||
nameImporter.getScratch());
|
||||
}
|
||||
|
||||
/// Prepare global name for importing onto a swift_newtype.
|
||||
@@ -1189,7 +1186,6 @@ Optional<ForeignAsyncConvention::Info>
|
||||
NameImporter::considerAsyncImport(
|
||||
const clang::ObjCMethodDecl *clangDecl,
|
||||
StringRef &baseName,
|
||||
SmallVectorImpl<char> &baseNameScratch,
|
||||
SmallVectorImpl<StringRef> ¶mNames,
|
||||
ArrayRef<const clang::ParmVarDecl *> params,
|
||||
bool isInitializer, bool hasCustomName,
|
||||
@@ -1225,17 +1221,6 @@ NameImporter::considerAsyncImport(
|
||||
return None;
|
||||
}
|
||||
|
||||
// If there's no custom name, and the base name starts with "get", drop the
|
||||
// get.
|
||||
if (!hasCustomName) {
|
||||
StringRef currentBaseName = newBaseName ? *newBaseName : baseName;
|
||||
if (currentBaseName.size() > 3 &&
|
||||
camel_case::getFirstWord(currentBaseName) == "get") {
|
||||
newBaseName = camel_case::toLowercaseInitialisms(
|
||||
currentBaseName.substr(3), baseNameScratch);
|
||||
}
|
||||
}
|
||||
|
||||
// Used for returns once we've determined that the method cannot be
|
||||
// imported as async, even though it has what looks like a completion handler
|
||||
// parameter.
|
||||
@@ -1473,7 +1458,6 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
|
||||
}
|
||||
|
||||
// If we have a swift_name attribute, use that.
|
||||
SmallString<32> asyncBaseNameScratch;
|
||||
if (auto *nameAttr = findSwiftNameAttr(D, version)) {
|
||||
bool skipCustomName = false;
|
||||
|
||||
@@ -1552,9 +1536,9 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
|
||||
|
||||
if (version.supportsConcurrency()) {
|
||||
if (auto asyncInfo = considerAsyncImport(
|
||||
method, parsedName.BaseName, asyncBaseNameScratch,
|
||||
parsedName.ArgumentLabels, params, isInitializer,
|
||||
/*hasCustomName=*/true, result.getErrorInfo())) {
|
||||
method, parsedName.BaseName, parsedName.ArgumentLabels,
|
||||
params, isInitializer, /*hasCustomName=*/true,
|
||||
result.getErrorInfo())) {
|
||||
result.info.hasAsyncInfo = true;
|
||||
result.info.asyncInfo = *asyncInfo;
|
||||
|
||||
@@ -1829,9 +1813,8 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
|
||||
if (version.supportsConcurrency() &&
|
||||
result.info.accessorKind == ImportedAccessorKind::None) {
|
||||
if (auto asyncInfo = considerAsyncImport(
|
||||
objcMethod, baseName, asyncBaseNameScratch,
|
||||
argumentNames, params, isInitializer, /*hasCustomName=*/false,
|
||||
result.getErrorInfo())) {
|
||||
objcMethod, baseName, argumentNames, params, isInitializer,
|
||||
/*hasCustomName=*/false, result.getErrorInfo())) {
|
||||
result.info.hasAsyncInfo = true;
|
||||
result.info.asyncInfo = *asyncInfo;
|
||||
}
|
||||
@@ -1971,7 +1954,7 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
|
||||
(void)omitNeedlessWords(baseName, {}, "", propertyTypeName,
|
||||
contextTypeName, {}, /*returnsSelf=*/false,
|
||||
/*isProperty=*/true, allPropertyNames,
|
||||
scratch);
|
||||
/*isAsync=*/false, scratch);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1983,7 +1966,12 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
|
||||
result.getErrorInfo()
|
||||
? Optional<unsigned>(result.getErrorInfo()->ErrorParameterIndex)
|
||||
: None,
|
||||
method->hasRelatedResultType(), method->isInstanceMethod(), *this);
|
||||
method->hasRelatedResultType(), method->isInstanceMethod(),
|
||||
result.getAsyncInfo().map(
|
||||
[](const ForeignAsyncConvention::Info &info) {
|
||||
return info.CompletionHandlerParamIndex;
|
||||
}),
|
||||
*this);
|
||||
}
|
||||
|
||||
// If the result is a value, lowercase it.
|
||||
|
||||
@@ -456,7 +456,6 @@ private:
|
||||
Optional<ForeignAsyncConvention::Info>
|
||||
considerAsyncImport(const clang::ObjCMethodDecl *clangDecl,
|
||||
StringRef &baseName,
|
||||
SmallVectorImpl<char> &baseNameScratch,
|
||||
SmallVectorImpl<StringRef> ¶mNames,
|
||||
ArrayRef<const clang::ParmVarDecl *> params,
|
||||
bool isInitializer, bool hasCustomName,
|
||||
|
||||
@@ -4867,7 +4867,8 @@ Optional<DeclName> TypeChecker::omitNeedlessWords(AbstractFunctionDecl *afd) {
|
||||
getTypeNameForOmission(resultType),
|
||||
getTypeNameForOmission(contextType),
|
||||
paramTypes, returnsSelf, false,
|
||||
/*allPropertyNames=*/nullptr, scratch))
|
||||
/*allPropertyNames=*/nullptr,
|
||||
afd->hasAsync(), scratch))
|
||||
return None;
|
||||
|
||||
/// Retrieve a replacement identifier.
|
||||
@@ -4922,7 +4923,8 @@ Optional<Identifier> TypeChecker::omitNeedlessWords(VarDecl *var) {
|
||||
OmissionTypeName contextTypeName = getTypeNameForOmission(contextType);
|
||||
if (::omitNeedlessWords(name, { }, "", typeName, contextTypeName, { },
|
||||
/*returnsSelf=*/false, true,
|
||||
/*allPropertyNames=*/nullptr, scratch)) {
|
||||
/*allPropertyNames=*/nullptr, /*isAsync=*/false,
|
||||
scratch)) {
|
||||
return Context.getIdentifier(name);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user