mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[AST] Adopt AnyFunctionType::getParams() when computing overloading signatures.
This commit is contained in:
@@ -1609,47 +1609,21 @@ static Type mapSignatureFunctionType(ASTContext &ctx, Type type,
|
||||
}
|
||||
|
||||
auto funcTy = type->castTo<AnyFunctionType>();
|
||||
auto argTy = funcTy->getInput();
|
||||
|
||||
if (auto tupleTy = argTy->getAs<TupleType>()) {
|
||||
SmallVector<TupleTypeElt, 4> elements;
|
||||
bool anyChanged = false;
|
||||
unsigned idx = 0;
|
||||
// Remap our parameters, and make sure to strip off @escaping
|
||||
for (const auto &elt : tupleTy->getElements()) {
|
||||
auto newEltTy = mapSignatureParamType(ctx, elt.getType());
|
||||
auto newParamFlags = elt.getParameterFlags().withEscaping(false);
|
||||
bool exactlyTheSame = newParamFlags == elt.getParameterFlags() &&
|
||||
newEltTy.getPointer() == elt.getType().getPointer();
|
||||
|
||||
// Don't build up anything if we never see any difference
|
||||
if (!anyChanged && exactlyTheSame) {
|
||||
++idx;
|
||||
continue;
|
||||
}
|
||||
|
||||
// First time we see a diff, copy over all the prior
|
||||
if (!anyChanged && !exactlyTheSame) {
|
||||
elements.append(tupleTy->getElements().begin(),
|
||||
tupleTy->getElements().begin() + idx);
|
||||
anyChanged = true;
|
||||
}
|
||||
|
||||
elements.emplace_back(newEltTy, elt.getName(), newParamFlags);
|
||||
}
|
||||
if (anyChanged) {
|
||||
argTy = TupleType::get(elements, ctx);
|
||||
}
|
||||
} else {
|
||||
argTy = mapSignatureParamType(ctx, argTy);
|
||||
SmallVector<AnyFunctionType::Param, 4> newParams;
|
||||
for (const auto ¶m : funcTy->getParams()) {
|
||||
auto newParamType = mapSignatureParamType(ctx, param.getType());
|
||||
ParameterTypeFlags newFlags = param.getParameterFlags().withEscaping(false);
|
||||
|
||||
// For the 'self' of a method, strip off 'inout'.
|
||||
if (isMethod) {
|
||||
// In methods, strip the 'inout' off of 'self' so that mutating and
|
||||
// non-mutating methods have the same self parameter type.
|
||||
if (auto inoutTy = argTy->getAs<InOutType>()) {
|
||||
argTy = inoutTy->getObjectType();
|
||||
}
|
||||
if (auto inoutType = newParamType->getAs<InOutType>())
|
||||
newParamType = inoutType->getObjectType();
|
||||
|
||||
newFlags = newFlags.withInOut(false);
|
||||
}
|
||||
|
||||
AnyFunctionType::Param newParam(newParamType, param.getLabel(), newFlags);
|
||||
newParams.push_back(newParam);
|
||||
}
|
||||
|
||||
// Map the result type.
|
||||
@@ -1665,9 +1639,9 @@ static Type mapSignatureFunctionType(ASTContext &ctx, Type type,
|
||||
// Rebuild the resulting function type.
|
||||
if (auto genericFuncTy = dyn_cast<GenericFunctionType>(funcTy))
|
||||
return GenericFunctionType::get(genericFuncTy->getGenericSignature(),
|
||||
argTy, resultTy, info);
|
||||
newParams, resultTy, info);
|
||||
|
||||
return FunctionType::get(argTy, resultTy, info);
|
||||
return FunctionType::get(newParams, resultTy, info);
|
||||
}
|
||||
|
||||
OverloadSignature ValueDecl::getOverloadSignature() const {
|
||||
|
||||
Reference in New Issue
Block a user