Skip to content

Commit fe227c2

Browse files
committed
AST: Fix GenericFunctionType::substGenericArgs() to support parameter packs
Instead of doing the bespoke thing, just erase this down to a FunctionType and call subst() on it.
1 parent 09417a5 commit fe227c2

File tree

2 files changed

+5
-24
lines changed

2 files changed

+5
-24
lines changed

include/swift/AST/Types.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4146,7 +4146,6 @@ class GenericFunctionType final
41464146
/// function type and return the resulting non-generic type.
41474147
FunctionType *substGenericArgs(SubstitutionMap subs,
41484148
SubstOptions options = std::nullopt);
4149-
FunctionType *substGenericArgs(llvm::function_ref<Type(Type)> substFn) const;
41504149

41514150
void Profile(llvm::FoldingSetNodeID &ID) {
41524151
std::optional<ExtInfo> info = std::nullopt;

lib/AST/TypeSubstitution.cpp

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,11 @@ Type QuerySubstitutionMap::operator()(SubstitutableType *type) const {
6161
FunctionType *
6262
GenericFunctionType::substGenericArgs(SubstitutionMap subs,
6363
SubstOptions options) {
64-
return substGenericArgs(
65-
[=](Type t) { return t.subst(subs, options); });
66-
}
67-
68-
FunctionType *GenericFunctionType::substGenericArgs(
69-
llvm::function_ref<Type(Type)> substFn) const {
70-
llvm::SmallVector<AnyFunctionType::Param, 4> params;
71-
params.reserve(getNumParams());
72-
73-
llvm::transform(getParams(), std::back_inserter(params),
74-
[&](const AnyFunctionType::Param &param) {
75-
return param.withType(substFn(param.getPlainType()));
76-
});
77-
78-
auto resultTy = substFn(getResult());
79-
80-
Type thrownError = getThrownError();
81-
if (thrownError)
82-
thrownError = substFn(thrownError);
83-
84-
// Build the resulting (non-generic) function type.
85-
return FunctionType::get(params, resultTy,
86-
getExtInfo().withThrows(isThrowing(), thrownError));
64+
// FIXME: Before dropping the signature, we should assert that
65+
// subs.getGenericSignature() is equal to this function type's
66+
// generic signature.
67+
Type fnType = FunctionType::get(getParams(), getResult(), getExtInfo());
68+
return fnType.subst(subs, options)->castTo<FunctionType>();
8769
}
8870

8971
CanFunctionType

0 commit comments

Comments
 (0)