@@ -386,54 +386,22 @@ static Address getArgAsBuffer(IRGenFunction &IGF,
386
386
getFixedBufferAlignment (IGF.IGM ));
387
387
}
388
388
389
- static CanType getFormalTypeInContext (CanType abstractType, DeclContext *dc) {
390
- // Map the parent of any non-generic nominal type.
391
- if (auto nominalType = dyn_cast<NominalType>(abstractType)) {
392
- // If it doesn't have a parent, or the parent doesn't need remapping,
393
- // do nothing.
394
- auto abstractParentType = nominalType.getParent ();
395
- if (!abstractParentType) return abstractType;
396
- auto parentType = getFormalTypeInContext (abstractParentType, dc);
397
- if (abstractParentType == parentType) return abstractType;
398
-
399
- // Otherwise, rebuild the type.
400
- return CanType (NominalType::get (nominalType->getDecl (), parentType,
401
- nominalType->getDecl ()->getASTContext ()));
402
-
403
- // Map unbound types into their defining context.
404
- } else if (auto ugt = dyn_cast<UnboundGenericType>(abstractType)) {
405
- return dc->mapTypeIntoContext (ugt->getDecl ()->getDeclaredInterfaceType ())
406
- ->getCanonicalType ();
407
-
408
- // Everything else stays the same.
409
- } else {
410
- return abstractType;
389
+ // / Don't add new callers of this, it doesn't make any sense.
390
+ static CanType getFormalTypeInPrimaryContext (CanType abstractType) {
391
+ auto *nominal = abstractType.getAnyNominal ();
392
+ if (abstractType->isEqual (nominal->getDeclaredType ())) {
393
+ return nominal->mapTypeIntoContext (nominal->getDeclaredInterfaceType ())
394
+ ->getCanonicalType ();
411
395
}
412
- }
413
396
414
- // / Given an abstract type --- a type possibly expressed in terms of
415
- // / unbound generic types --- return the formal type within the type's
416
- // / primary defining context.
417
- CanType irgen::getFormalTypeInPrimaryContext (CanType abstractType) {
418
- if (auto nominal = abstractType.getAnyNominal ())
419
- return getFormalTypeInContext (abstractType, nominal);
397
+ assert (!abstractType->hasUnboundGenericType ());
420
398
return abstractType;
421
399
}
422
400
423
401
SILType irgen::getLoweredTypeInPrimaryContext (IRGenModule &IGM,
424
- CanType abstractType) {
425
- if (auto boundGenericType = dyn_cast<BoundGenericType>(abstractType)) {
426
- CanType concreteFormalType = getFormalTypeInPrimaryContext (abstractType);
427
-
428
- auto concreteLoweredType = IGM.getLoweredType (concreteFormalType);
429
- const auto *boundConcreteTI = &IGM.getTypeInfo (concreteLoweredType);
430
- auto packing = boundConcreteTI->getFixedPacking (IGM);
431
-
432
- abstractType =
433
- boundGenericType->getDecl ()->getDeclaredType ()->getCanonicalType ();
434
- }
435
- CanType concreteFormalType = getFormalTypeInPrimaryContext (abstractType);
436
-
402
+ NominalTypeDecl *type) {
403
+ CanType concreteFormalType = type->mapTypeIntoContext (
404
+ type->getDeclaredInterfaceType ())->getCanonicalType ();
437
405
return IGM.getLoweredType (concreteFormalType);
438
406
}
439
407
@@ -1191,8 +1159,9 @@ static void addValueWitnesses(IRGenModule &IGM, ConstantStructBuilder &B,
1191
1159
// / True if a type has a generic-parameter-dependent value witness table.
1192
1160
// / Currently, this is true if the size and/or alignment of the type is
1193
1161
// / dependent on its generic parameters.
1194
- bool irgen::hasDependentValueWitnessTable (IRGenModule &IGM, CanType ty) {
1195
- return !IGM.getTypeInfoForUnlowered (getFormalTypeInPrimaryContext (ty)).isFixedSize ();
1162
+ bool irgen::hasDependentValueWitnessTable (IRGenModule &IGM, NominalTypeDecl *decl) {
1163
+ auto ty = decl->mapTypeIntoContext (decl->getDeclaredInterfaceType ());
1164
+ return !IGM.getTypeInfoForUnlowered (ty).isFixedSize ();
1196
1165
}
1197
1166
1198
1167
static void addValueWitnessesForAbstractType (IRGenModule &IGM,
@@ -1364,7 +1333,8 @@ ConstantReference irgen::emitValueWitnessTable(IRGenModule &IGM,
1364
1333
// We should never be making a pattern if the layout isn't fixed.
1365
1334
// The reverse can be true for types whose layout depends on
1366
1335
// resilient types.
1367
- assert ((!isPattern || hasDependentValueWitnessTable (IGM, abstractType)) &&
1336
+ assert ((!isPattern || hasDependentValueWitnessTable (
1337
+ IGM, abstractType->getAnyNominal ())) &&
1368
1338
" emitting VWT pattern for fixed-layout type" );
1369
1339
1370
1340
ConstantInitBuilder builder (IGM);
0 commit comments