@@ -386,54 +386,22 @@ static Address getArgAsBuffer(IRGenFunction &IGF,
386386 getFixedBufferAlignment (IGF.IGM ));
387387}
388388
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 ();
411395 }
412- }
413396
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 ());
420398 return abstractType;
421399}
422400
423401SILType 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 ();
437405 return IGM.getLoweredType (concreteFormalType);
438406}
439407
@@ -1191,8 +1159,9 @@ static void addValueWitnesses(IRGenModule &IGM, ConstantStructBuilder &B,
11911159// / True if a type has a generic-parameter-dependent value witness table.
11921160// / Currently, this is true if the size and/or alignment of the type is
11931161// / 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 ();
11961165}
11971166
11981167static void addValueWitnessesForAbstractType (IRGenModule &IGM,
@@ -1364,7 +1333,8 @@ ConstantReference irgen::emitValueWitnessTable(IRGenModule &IGM,
13641333 // We should never be making a pattern if the layout isn't fixed.
13651334 // The reverse can be true for types whose layout depends on
13661335 // resilient types.
1367- assert ((!isPattern || hasDependentValueWitnessTable (IGM, abstractType)) &&
1336+ assert ((!isPattern || hasDependentValueWitnessTable (
1337+ IGM, abstractType->getAnyNominal ())) &&
13681338 " emitting VWT pattern for fixed-layout type" );
13691339
13701340 ConstantInitBuilder builder (IGM);
0 commit comments