@@ -61,29 +61,11 @@ Type QuerySubstitutionMap::operator()(SubstitutableType *type) const {
61
61
FunctionType *
62
62
GenericFunctionType::substGenericArgs (SubstitutionMap subs,
63
63
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 ¶m) {
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>();
87
69
}
88
70
89
71
CanFunctionType
@@ -170,73 +152,6 @@ operator()(CanType dependentType, Type conformingReplacementType,
170
152
conformingReplacementType, conformedProtocol);
171
153
}
172
154
173
- static Type substGenericFunctionType (GenericFunctionType *genericFnType,
174
- InFlightSubstitution &IFS) {
175
- // Substitute into the function type (without generic signature).
176
- auto *bareFnType = FunctionType::get (genericFnType->getParams (),
177
- genericFnType->getResult (),
178
- genericFnType->getExtInfo ());
179
- Type result = Type (bareFnType).subst (IFS);
180
- if (!result || result->is <ErrorType>()) return result;
181
-
182
- auto *fnType = result->castTo <FunctionType>();
183
- // Substitute generic parameters.
184
- bool anySemanticChanges = false ;
185
- SmallVector<GenericTypeParamType *, 2 > genericParams;
186
- for (auto param : genericFnType->getGenericParams ()) {
187
- Type paramTy = Type (param).subst (IFS);
188
- if (!paramTy)
189
- return Type ();
190
-
191
- if (auto newParam = paramTy->getAs <GenericTypeParamType>()) {
192
- if (!newParam->isEqual (param))
193
- anySemanticChanges = true ;
194
-
195
- genericParams.push_back (newParam);
196
- } else {
197
- anySemanticChanges = true ;
198
- }
199
- }
200
-
201
- // If no generic parameters remain, this is a non-generic function type.
202
- if (genericParams.empty ())
203
- return result;
204
-
205
- // Transform requirements.
206
- SmallVector<Requirement, 2 > requirements;
207
- for (const auto &req : genericFnType->getRequirements ()) {
208
- // Substitute into the requirement.
209
- auto substReqt = req.subst (IFS);
210
-
211
- // Did anything change?
212
- if (!anySemanticChanges &&
213
- (!req.getFirstType ()->isEqual (substReqt.getFirstType ()) ||
214
- (req.getKind () != RequirementKind::Layout &&
215
- !req.getSecondType ()->isEqual (substReqt.getSecondType ())))) {
216
- anySemanticChanges = true ;
217
- }
218
-
219
- requirements.push_back (substReqt);
220
- }
221
-
222
- GenericSignature genericSig;
223
- if (anySemanticChanges) {
224
- // If there were semantic changes, we need to build a new generic
225
- // signature.
226
- ASTContext &ctx = genericFnType->getASTContext ();
227
- genericSig = buildGenericSignature (ctx, GenericSignature (),
228
- genericParams, requirements,
229
- /* allowInverses=*/ false );
230
- } else {
231
- // Use the mapped generic signature.
232
- genericSig = GenericSignature::get (genericParams, requirements);
233
- }
234
-
235
- // Produce the new generic function type.
236
- return GenericFunctionType::get (genericSig, fnType->getParams (),
237
- fnType->getResult (), fnType->getExtInfo ());
238
- }
239
-
240
155
InFlightSubstitution::InFlightSubstitution (TypeSubstitutionFn substType,
241
156
LookupConformanceFn lookupConformance,
242
157
SubstOptions options)
@@ -558,11 +473,8 @@ Type Type::subst(TypeSubstitutionFn substitutions,
558
473
}
559
474
560
475
Type Type::subst (InFlightSubstitution &IFS) const {
561
- // Handle substitutions into generic function types.
562
- // FIXME: This should be banned.
563
- if (auto genericFnType = getPointer ()->getAs <GenericFunctionType>()) {
564
- return substGenericFunctionType (genericFnType, IFS);
565
- }
476
+ ASSERT (!getPointer ()->getAs <GenericFunctionType>() &&
477
+ " Perhaps you want GenericFunctionType::substGenericArgs() instead" );
566
478
567
479
if (IFS.isInvariant (*this ))
568
480
return *this ;
0 commit comments