@@ -255,114 +255,13 @@ Type TypeChecker::lookupBoolType(const DeclContext *dc) {
255
255
return *boolType;
256
256
}
257
257
258
- // / Clone the given generic parameters in the given list. We don't need any
259
- // / of the requirements, because they will be inferred.
260
- static GenericParamList *cloneGenericParams (ASTContext &ctx,
261
- DeclContext *dc,
262
- GenericParamList *fromParams) {
263
- // Clone generic parameters.
264
- SmallVector<GenericTypeParamDecl *, 2 > toGenericParams;
265
- for (auto fromGP : *fromParams) {
266
- // Create the new generic parameter.
267
- auto toGP = new (ctx) GenericTypeParamDecl (dc, fromGP->getName (),
268
- SourceLoc (),
269
- fromGP->getDepth (),
270
- fromGP->getIndex ());
271
- toGP->setImplicit (true );
272
-
273
- // Record new generic parameter.
274
- toGenericParams.push_back (toGP);
275
- }
276
-
277
- auto toParams = GenericParamList::create (ctx, SourceLoc (), toGenericParams,
278
- SourceLoc ());
279
-
280
- auto outerParams = fromParams->getOuterParameters ();
281
- if (outerParams != nullptr )
282
- outerParams = cloneGenericParams (ctx, dc, outerParams);
283
- toParams->setOuterParameters (outerParams);
284
-
285
- return toParams;
286
- }
287
-
288
- // / Ensure that the outer generic parameters of the given generic
289
- // / context have been configured.
290
- static void configureOuterGenericParams (const GenericContext *dc) {
291
- auto genericParams = dc->getGenericParams ();
292
-
293
- // If we already configured the outer parameters, we're done.
294
- if (genericParams && genericParams->getOuterParameters ())
295
- return ;
296
-
297
- DeclContext *outerDC = dc->getParent ();
298
- while (!outerDC->isModuleScopeContext ()) {
299
- if (auto outerDecl = outerDC->getAsDecl ()) {
300
- if (auto outerGenericDC = outerDecl->getAsGenericContext ()) {
301
- if (genericParams)
302
- genericParams->setOuterParameters (outerGenericDC->getGenericParams ());
303
-
304
- configureOuterGenericParams (outerGenericDC);
305
- return ;
306
- }
307
- }
308
-
309
- outerDC = outerDC->getParent ();
310
- }
311
- }
312
-
313
258
// / Bind the given extension to the given nominal type.
314
259
static void bindExtensionToNominal (ExtensionDecl *ext,
315
260
NominalTypeDecl *nominal) {
316
261
if (ext->alreadyBoundToNominal ())
317
262
return ;
318
263
319
- // Hack to force generic parameter lists of protocols to be created if the
320
- // nominal is an (invalid) nested type of a protocol.
321
- DeclContext *outerDC = nominal;
322
- while (!outerDC->isModuleScopeContext ()) {
323
- if (auto *proto = dyn_cast<ProtocolDecl>(outerDC))
324
- proto->createGenericParamsIfMissing ();
325
-
326
- outerDC = outerDC->getParent ();
327
- }
328
-
329
- configureOuterGenericParams (nominal);
330
-
331
- if (auto proto = dyn_cast<ProtocolDecl>(nominal)) {
332
- // For a protocol extension, build the generic parameter list directly
333
- // since we want it to have an inheritance clause.
334
- ext->setGenericParams (proto->createGenericParams (ext));
335
- } else if (auto genericParams = nominal->getGenericParamsOfContext ()) {
336
- // Clone the generic parameter list of a generic type.
337
- ext->setGenericParams (
338
- cloneGenericParams (ext->getASTContext (), ext, genericParams));
339
- }
340
-
341
- // Set the depth of every generic parameter.
342
- auto *genericParams = ext->getGenericParams ();
343
- for (auto *outerParams = genericParams;
344
- outerParams != nullptr ;
345
- outerParams = outerParams->getOuterParameters ())
346
- outerParams->configureGenericParamDepth ();
347
-
348
- // If we have a trailing where clause, deal with it now.
349
- // For now, trailing where clauses are only permitted on protocol extensions.
350
- if (auto trailingWhereClause = ext->getTrailingWhereClause ()) {
351
- if (genericParams) {
352
- // Merge the trailing where clause into the generic parameter list.
353
- // FIXME: Long-term, we'd like clients to deal with the trailing where
354
- // clause explicitly, but for now it's far more direct to represent
355
- // the trailing where clause as part of the requirements.
356
- genericParams->addTrailingWhereClause (
357
- ext->getASTContext (),
358
- trailingWhereClause->getWhereLoc (),
359
- trailingWhereClause->getRequirements ());
360
- }
361
-
362
- // If there's no generic parameter list, the where clause is diagnosed
363
- // in typeCheckDecl().
364
- }
365
-
264
+ ext->createGenericParamsIfMissing (nominal);
366
265
nominal->addExtension (ext);
367
266
}
368
267
0 commit comments