diff --git a/include/swift/AST/Types.h b/include/swift/AST/Types.h index 5072a5c9f9e..527d76472c2 100644 --- a/include/swift/AST/Types.h +++ b/include/swift/AST/Types.h @@ -2663,6 +2663,8 @@ public: return Label != b.Label || !getType()->isEqual(b.getType()) || Flags != b.Flags; } + + Param getWithoutLabel() const { return Param(Ty, Identifier(), Flags); } }; class CanParam : public Param { diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index efee4f34da3..3ce90a0f528 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -534,20 +534,15 @@ static Type removeArgumentLabels(Type type, unsigned numArgumentLabels) { auto fnType = type->getAs(); // Drop argument labels from the input type. - Type inputType = fnType->getInput(); - if (auto tupleTy = dyn_cast(inputType.getPointer())) { - SmallVector elements; - elements.reserve(tupleTy->getNumElements()); - for (const auto &elt : tupleTy->getElements()) { - elements.push_back(elt.getWithoutName()); - } - inputType = TupleType::get(elements, type->getASTContext()); - } + llvm::SmallVector unlabeledParams; + unlabeledParams.reserve(fnType->getNumParams()); + for (const auto ¶m : fnType->getParams()) + unlabeledParams.push_back(param.getWithoutLabel()); - return FunctionType::get(inputType, - removeArgumentLabels(fnType->getResult(), - numArgumentLabels - 1), - fnType->getExtInfo()); + return FunctionType::get( + unlabeledParams, + removeArgumentLabels(fnType->getResult(), numArgumentLabels - 1), + fnType->getExtInfo()); } Type ConstraintSystem::openFunctionType( @@ -569,14 +564,21 @@ Type ConstraintSystem::openFunctionType( locator, replacements); - // Transform the input and output types. - auto inputTy = openType(genericFn->getInput(), replacements); + // Transform the parameters and output type. + llvm::SmallVector openedParams; + openedParams.reserve(genericFn->getNumParams()); + for (const auto ¶m : genericFn->getParams()) { + auto type = openType(param.getPlainType(), replacements); + openedParams.push_back(AnyFunctionType::Param(type, param.getLabel(), + param.getParameterFlags())); + } + auto resultTy = openType(genericFn->getResult(), replacements); // Build the resulting (non-generic) function type. - funcType = FunctionType::get(inputTy, resultTy, - FunctionType::ExtInfo(). - withThrows(genericFn->throws())); + funcType = FunctionType::get( + openedParams, resultTy, + FunctionType::ExtInfo().withThrows(genericFn->throws())); } return removeArgumentLabels(funcType, numArgumentLabelsToRemove); @@ -897,7 +899,9 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value, // DynamicSelf with the actual object type. if (!func->getDeclContext()->getAsProtocolOrProtocolExtensionContext()) { if (func->hasDynamicSelf()) { - Type selfTy = openedFnType->getInput()->getRValueInstanceType(); + auto params = openedFnType->getParams(); + assert(params.size() == 1); + Type selfTy = params.front().getType()->getRValueInstanceType(); openedType = openedType->replaceCovariantResultType( selfTy, func->getNumParameterLists()); @@ -1358,7 +1362,10 @@ ConstraintSystem::getTypeOfMemberReference( // Constrain the 'self' object type. auto openedFnType = openedType->castTo(); - Type selfObjTy = openedFnType->getInput()->getRValueInstanceType(); + auto openedParams = openedFnType->getParams(); + assert(openedParams.size() == 1); + + Type selfObjTy = openedParams.front().getType()->getRValueInstanceType(); if (outerDC->getAsProtocolOrProtocolExtensionContext()) { // For a protocol, substitute the base object directly. We don't need a // conformance constraint because we wouldn't have found the declaration @@ -1887,10 +1894,8 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator, if (boundFunctionType && CD->hasThrows() != boundFunctionType->throws()) { - boundType = FunctionType::get(boundFunctionType->getInput(), - boundFunctionType->getResult(), - boundFunctionType->getExtInfo(). - withThrows()); + boundType = boundFunctionType->withExtInfo( + boundFunctionType->getExtInfo().withThrows()); } } }