Skip to content

Commit 09417a5

Browse files
committed
Sema: Move old overload of substGenericArgs() to TypeOfReference.cpp
1 parent 964f081 commit 09417a5

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

lib/Sema/TypeOfReference.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,30 @@ Type ConstraintSystem::openOpaqueType(Type type, ContextualTypePurpose context,
404404
});
405405
}
406406

407+
/// FIXME: This can be folded into its callers after a bit of cleanup.
408+
static FunctionType *substGenericArgs(
409+
GenericFunctionType *funcTy,
410+
llvm::function_ref<Type(Type)> substFn) {
411+
llvm::SmallVector<AnyFunctionType::Param, 4> params;
412+
params.reserve(funcTy->getNumParams());
413+
414+
llvm::transform(funcTy->getParams(), std::back_inserter(params),
415+
[&](const AnyFunctionType::Param &param) {
416+
return param.withType(substFn(param.getPlainType()));
417+
});
418+
419+
auto resultTy = substFn(funcTy->getResult());
420+
421+
Type thrownError = funcTy->getThrownError();
422+
if (thrownError)
423+
thrownError = substFn(thrownError);
424+
425+
// Build the resulting (non-generic) function type.
426+
return FunctionType::get(params, resultTy,
427+
funcTy->getExtInfo().withThrows(
428+
funcTy->isThrowing(), thrownError));
429+
}
430+
407431
FunctionType *ConstraintSystem::openFunctionType(
408432
AnyFunctionType *funcType,
409433
ConstraintLocatorBuilder locator,
@@ -419,7 +443,7 @@ FunctionType *ConstraintSystem::openFunctionType(
419443
return openType(type, replacements, locator);
420444
});
421445

422-
funcType = genericFn->substGenericArgs(
446+
funcType = substGenericArgs(genericFn,
423447
[&](Type type) { return openType(type, replacements, locator); });
424448
}
425449

@@ -1546,7 +1570,7 @@ DeclReferenceType ConstraintSystem::getTypeOfMemberReference(
15461570
openedType = value->getInterfaceType()->castTo<AnyFunctionType>();
15471571

15481572
if (auto *genericFn = openedType->getAs<GenericFunctionType>()) {
1549-
openedType = genericFn->substGenericArgs(
1573+
openedType = substGenericArgs(genericFn,
15501574
[&](Type type) { return openType(type, replacements, locator); });
15511575
}
15521576
} else {

0 commit comments

Comments
 (0)