Skip to content

Commit 7faf90a

Browse files
committed
IRGen: Replace ResilienceScope enum with AST's ResilienceExpansion, NFC
1 parent 6af7f95 commit 7faf90a

21 files changed

+137
-156
lines changed

Diff for: lib/IRGen/ClassMetadataLayout.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ template <class Impl> class ClassMetadataLayout : public MetadataLayout<Impl> {
8888
// Skip superclass fields if superclass is resilient.
8989
// FIXME: Needs runtime support to ensure the field offset vector is
9090
// populated correctly.
91-
if (!IGM.isResilient(superclassDecl, ResilienceScope::Component)) {
91+
if (!IGM.isResilient(superclassDecl, ResilienceExpansion::Maximal)) {
9292
addClassMembers(superclass->getClassOrBoundGenericClass());
9393
}
9494
}

Diff for: lib/IRGen/GenClass.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ namespace {
243243
// the field offset vector.
244244
ClassHasFixedSize = false;
245245
}
246-
} else if (IGM.isResilient(superclass, ResilienceScope::Component)) {
246+
} else if (IGM.isResilient(superclass, ResilienceExpansion::Maximal)) {
247247
// If the superclass is resilient, the number of stored properties
248248
// is not known at compile time.
249249
ClassHasMetadataPattern = true;

Diff for: lib/IRGen/GenDecl.cpp

+15-13
Original file line numberDiff line numberDiff line change
@@ -2614,36 +2614,38 @@ StringRef IRGenModule::mangleType(CanType type, SmallVectorImpl<char> &buffer) {
26142614
/// - For enums, new cases can be added
26152615
/// - For classes, the superclass might change the size or number
26162616
/// of stored properties
2617-
bool IRGenModule::isResilient(Decl *D, ResilienceScope scope) {
2617+
bool IRGenModule::isResilient(Decl *D, ResilienceExpansion expansion) {
26182618
auto NTD = dyn_cast<NominalTypeDecl>(D);
26192619
if (!NTD)
26202620
return false;
26212621

2622-
switch (scope) {
2623-
case ResilienceScope::Component:
2622+
switch (expansion) {
2623+
case ResilienceExpansion::Maximal:
26242624
return !NTD->hasFixedLayout(SILMod->getSwiftModule());
2625-
case ResilienceScope::Universal:
2625+
case ResilienceExpansion::Minimal:
26262626
return !NTD->hasFixedLayout();
26272627
}
26282628

26292629
llvm_unreachable("Bad resilience scope");
26302630
}
26312631

2632-
// The most general resilience scope where the given declaration is visible.
2633-
ResilienceScope IRGenModule::getResilienceScopeForAccess(NominalTypeDecl *decl) {
2632+
// The most general resilience expansion where the given declaration is visible.
2633+
ResilienceExpansion
2634+
IRGenModule::getResilienceExpansionForAccess(NominalTypeDecl *decl) {
26342635
if (decl->getModuleContext() == SILMod->getSwiftModule() &&
26352636
decl->getFormalAccess() != Accessibility::Public)
2636-
return ResilienceScope::Component;
2637-
return ResilienceScope::Universal;
2637+
return ResilienceExpansion::Maximal;
2638+
return ResilienceExpansion::Minimal;
26382639
}
26392640

2640-
// The most general resilience scope which has knowledge of the declaration's
2641+
// The most general resilience expansion which has knowledge of the declaration's
26412642
// layout. Calling isResilient() with this scope will always return false.
2642-
ResilienceScope IRGenModule::getResilienceScopeForLayout(NominalTypeDecl *decl) {
2643-
if (isResilient(decl, ResilienceScope::Universal))
2644-
return ResilienceScope::Component;
2643+
ResilienceExpansion
2644+
IRGenModule::getResilienceExpansionForLayout(NominalTypeDecl *decl) {
2645+
if (isResilient(decl, ResilienceExpansion::Minimal))
2646+
return ResilienceExpansion::Maximal;
26452647

2646-
return getResilienceScopeForAccess(decl);
2648+
return getResilienceExpansionForAccess(decl);
26472649
}
26482650

26492651
llvm::Constant *IRGenModule::

Diff for: lib/IRGen/GenEnum.cpp

+32-30
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ namespace {
470470
}
471471

472472
void destroy(IRGenFunction &IGF, Address addr, SILType T) const override {
473-
if (getSingleton() && !getSingleton()->isPOD(ResilienceScope::Component))
473+
if (getSingleton() && !getSingleton()->isPOD(ResilienceExpansion::Maximal))
474474
getSingleton()->destroy(IGF, getSingletonAddress(IGF, addr),
475475
getSingletonType(IGF.IGM, T));
476476
}
@@ -1193,10 +1193,10 @@ namespace {
11931193
void assign(IRGenFunction &IGF, Explosion &e, Address addr) const override {
11941194
assert(TIK >= Loadable);
11951195
Explosion old;
1196-
if (!isPOD(ResilienceScope::Component))
1196+
if (!isPOD(ResilienceExpansion::Maximal))
11971197
loadAsTake(IGF, addr, old);
11981198
initialize(IGF, e, addr);
1199-
if (!isPOD(ResilienceScope::Component))
1199+
if (!isPOD(ResilienceExpansion::Maximal))
12001200
consume(IGF, old);
12011201
}
12021202

@@ -1376,13 +1376,13 @@ namespace {
13761376

13771377
// If the payload is POD, then we can use POD value semantics.
13781378
auto &payloadTI = *ElementsWithPayload[0].ti;
1379-
if (payloadTI.isPOD(ResilienceScope::Component)) {
1379+
if (payloadTI.isPOD(ResilienceExpansion::Maximal)) {
13801380
CopyDestroyKind = POD;
13811381
// If the payload is a single refcounted pointer and we have a single
13821382
// empty case, then the layout will be a nullable pointer, and we can
13831383
// pass enum values directly into swift_retain/swift_release as-is.
13841384
} else if (tik >= TypeInfoKind::Loadable
1385-
&& payloadTI.isSingleRetainablePointer(ResilienceScope::Component,
1385+
&& payloadTI.isSingleRetainablePointer(ResilienceExpansion::Maximal,
13861386
&Refcounting)
13871387
&& ElementsWithNoPayload.size() == 1
13881388
// FIXME: All single-retainable-pointer types should eventually have
@@ -2775,14 +2775,14 @@ namespace {
27752775
bool allSingleRefcount = true;
27762776
bool haveRefcounting = false;
27772777
for (auto &elt : ElementsWithPayload) {
2778-
if (!elt.ti->isPOD(ResilienceScope::Component))
2778+
if (!elt.ti->isPOD(ResilienceExpansion::Maximal))
27792779
allPOD = false;
2780-
if (!elt.ti->isBitwiseTakable(ResilienceScope::Component))
2780+
if (!elt.ti->isBitwiseTakable(ResilienceExpansion::Maximal))
27812781
allBitwiseTakable = false;
27822782

27832783
// refcounting is only set in the else branches
27842784
ReferenceCounting refcounting;
2785-
if (!elt.ti->isSingleRetainablePointer(ResilienceScope::Component,
2785+
if (!elt.ti->isSingleRetainablePointer(ResilienceExpansion::Maximal,
27862786
&refcounting)) {
27872787
allSingleRefcount = false;
27882788
} else if (haveRefcounting) {
@@ -3579,7 +3579,7 @@ namespace {
35793579
auto &payloadTI = *payloadCasePair.ti;
35803580

35813581
// Trivial payloads don't need any work.
3582-
if (payloadTI.isPOD(ResilienceScope::Component)) {
3582+
if (payloadTI.isPOD(ResilienceExpansion::Maximal)) {
35833583
++tagIndex;
35843584
continue;
35853585
}
@@ -3861,8 +3861,8 @@ namespace {
38613861
auto &payloadTI = *payloadCasePair.ti;
38623862
// Trivial and, in the case of a take, bitwise-takable payloads,
38633863
// can all share the default path.
3864-
if (payloadTI.isPOD(ResilienceScope::Component)
3865-
|| (isTake && payloadTI.isBitwiseTakable(ResilienceScope::Component))) {
3864+
if (payloadTI.isPOD(ResilienceExpansion::Maximal)
3865+
|| (isTake && payloadTI.isBitwiseTakable(ResilienceExpansion::Maximal))) {
38663866
++tagIndex;
38673867
continue;
38683868
}
@@ -4646,17 +4646,19 @@ EnumImplStrategy *EnumImplStrategy::get(TypeConverter &TC,
46464646
// 1) Physical case indices won't change
46474647
// 2) The indirect-ness of cases won't change
46484648
// 3) Payload types won't change in a non-resilient way
4649-
bool isResilient = TC.IGM.isResilient(theEnum, ResilienceScope::Component);
4649+
bool isResilient = TC.IGM.isResilient(theEnum, ResilienceExpansion::Maximal);
46504650

46514651
// The most general resilience scope where the enum type is visible.
46524652
// Case numbering must not depend on any information that is not static
46534653
// in this resilience scope.
4654-
ResilienceScope accessScope = TC.IGM.getResilienceScopeForAccess(theEnum);
4654+
ResilienceExpansion accessScope =
4655+
TC.IGM.getResilienceExpansionForAccess(theEnum);
46554656

46564657
// The most general resilience scope where the enum's layout is known.
46574658
// Fixed-size optimizations can be applied if all payload types are
46584659
// fixed-size from this resilience scope.
4659-
ResilienceScope layoutScope = TC.IGM.getResilienceScopeForLayout(theEnum);
4660+
ResilienceExpansion layoutScope =
4661+
TC.IGM.getResilienceExpansionForLayout(theEnum);
46604662

46614663
for (auto elt : theEnum->getAllElements()) {
46624664
numElements++;
@@ -4711,7 +4713,7 @@ EnumImplStrategy *EnumImplStrategy::get(TypeConverter &TC,
47114713
elementsWithPayload.push_back({elt, substArgTI, origArgTI});
47124714

47134715
if (!isResilient) {
4714-
if (!substArgTI->isFixedSize(ResilienceScope::Component))
4716+
if (!substArgTI->isFixedSize(ResilienceExpansion::Maximal))
47154717
tik = Opaque;
47164718
else if (!substArgTI->isLoadable() && tik > Fixed)
47174719
tik = Fixed;
@@ -5034,8 +5036,8 @@ SingletonEnumImplStrategy::completeEnumTypeLayout(TypeConverter &TC,
50345036
alignment);
50355037
return registerEnumTypeInfo(new NonFixedEnumTypeInfo(*this, enumTy,
50365038
alignment,
5037-
eltTI.isPOD(ResilienceScope::Component),
5038-
eltTI.isBitwiseTakable(ResilienceScope::Component)));
5039+
eltTI.isPOD(ResilienceExpansion::Maximal),
5040+
eltTI.isBitwiseTakable(ResilienceExpansion::Maximal)));
50395041
} else {
50405042
auto &fixedEltTI = cast<FixedTypeInfo>(eltTI);
50415043
auto alignment = fixedEltTI.getFixedAlignment();
@@ -5046,8 +5048,8 @@ SingletonEnumImplStrategy::completeEnumTypeLayout(TypeConverter &TC,
50465048
fixedEltTI.getFixedSize(),
50475049
fixedEltTI.getSpareBits(),
50485050
alignment,
5049-
fixedEltTI.isPOD(ResilienceScope::Component),
5050-
fixedEltTI.isBitwiseTakable(ResilienceScope::Component));
5051+
fixedEltTI.isPOD(ResilienceExpansion::Maximal),
5052+
fixedEltTI.isBitwiseTakable(ResilienceExpansion::Maximal));
50515053
}
50525054
}
50535055
}
@@ -5106,7 +5108,7 @@ CCompatibleEnumImplStrategy::completeEnumTypeLayout(TypeConverter &TC,
51065108
auto &rawTI = TC.getCompleteTypeInfo(
51075109
theEnum->getRawType()->getCanonicalType());
51085110
auto &rawFixedTI = cast<FixedTypeInfo>(rawTI);
5109-
assert(rawFixedTI.isPOD(ResilienceScope::Component)
5111+
assert(rawFixedTI.isPOD(ResilienceExpansion::Maximal)
51105112
&& "c-compatible raw type isn't POD?!");
51115113
ExplosionSchema rawSchema = rawTI.getSchema();
51125114
assert(rawSchema.size() == 1
@@ -5122,7 +5124,7 @@ CCompatibleEnumImplStrategy::completeEnumTypeLayout(TypeConverter &TC,
51225124
applyLayoutAttributes(TC.IGM, Type.getSwiftRValueType(), /*fixed*/true,
51235125
alignment);
51245126

5125-
assert(!TC.IGM.isResilient(theEnum, ResilienceScope::Universal) &&
5127+
assert(!TC.IGM.isResilient(theEnum, ResilienceExpansion::Minimal) &&
51265128
"C-compatible enums cannot be resilient");
51275129

51285130
return registerEnumTypeInfo(new LoadableEnumTypeInfo(*this, enumTy,
@@ -5196,8 +5198,8 @@ TypeInfo *SinglePayloadEnumImplStrategy::completeFixedLayout(
51965198

51975199
return getFixedEnumTypeInfo(enumTy, Size(sizeWithTag), std::move(spareBits),
51985200
alignment,
5199-
payloadTI.isPOD(ResilienceScope::Component),
5200-
payloadTI.isBitwiseTakable(ResilienceScope::Component));
5201+
payloadTI.isPOD(ResilienceExpansion::Maximal),
5202+
payloadTI.isBitwiseTakable(ResilienceExpansion::Maximal));
52015203
}
52025204

52035205
TypeInfo *SinglePayloadEnumImplStrategy::completeDynamicLayout(
@@ -5219,8 +5221,8 @@ TypeInfo *SinglePayloadEnumImplStrategy::completeDynamicLayout(
52195221

52205222
return registerEnumTypeInfo(new NonFixedEnumTypeInfo(*this, enumTy,
52215223
alignment,
5222-
payloadTI.isPOD(ResilienceScope::Component),
5223-
payloadTI.isBitwiseTakable(ResilienceScope::Component)));
5224+
payloadTI.isPOD(ResilienceExpansion::Maximal),
5225+
payloadTI.isBitwiseTakable(ResilienceExpansion::Maximal)));
52245226
}
52255227

52265228
TypeInfo *
@@ -5256,9 +5258,9 @@ MultiPayloadEnumImplStrategy::completeFixedLayout(TypeConverter &TC,
52565258
auto &fixedPayloadTI = cast<FixedTypeInfo>(*elt.ti);
52575259
if (fixedPayloadTI.getFixedAlignment() > worstAlignment)
52585260
worstAlignment = fixedPayloadTI.getFixedAlignment();
5259-
if (!fixedPayloadTI.isPOD(ResilienceScope::Component))
5261+
if (!fixedPayloadTI.isPOD(ResilienceExpansion::Maximal))
52605262
isPOD = IsNotPOD;
5261-
if (!fixedPayloadTI.isBitwiseTakable(ResilienceScope::Component))
5263+
if (!fixedPayloadTI.isBitwiseTakable(ResilienceExpansion::Maximal))
52625264
isBT = IsNotBitwiseTakable;
52635265

52645266
unsigned payloadBytes = fixedPayloadTI.getFixedSize().getValue();
@@ -5401,8 +5403,8 @@ TypeInfo *MultiPayloadEnumImplStrategy::completeDynamicLayout(
54015403
for (auto &element : ElementsWithPayload) {
54025404
auto &payloadTI = *element.ti;
54035405
alignment = std::max(alignment, payloadTI.getBestKnownAlignment());
5404-
pod &= payloadTI.isPOD(ResilienceScope::Component);
5405-
bt &= payloadTI.isBitwiseTakable(ResilienceScope::Component);
5406+
pod &= payloadTI.isPOD(ResilienceExpansion::Maximal);
5407+
bt &= payloadTI.isBitwiseTakable(ResilienceExpansion::Maximal);
54065408
}
54075409

54085410
applyLayoutAttributes(TC.IGM, Type.getSwiftRValueType(), /*fixed*/false,
@@ -5436,7 +5438,7 @@ const TypeInfo *TypeConverter::convertEnumType(TypeBase *key, CanType type,
54365438
llvm::StructType *storageType;
54375439

54385440
// Resilient enum types lower down to the same opaque type.
5439-
if (IGM.isResilient(theEnum, ResilienceScope::Component))
5441+
if (IGM.isResilient(theEnum, ResilienceExpansion::Maximal))
54405442
storageType = cast<llvm::StructType>(IGM.OpaquePtrTy->getElementType());
54415443
else
54425444
storageType = IGM.createNominalType(theEnum);

Diff for: lib/IRGen/GenEnum.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ class EnumImplStrategy {
177177
return cast<llvm::StructType>(getTypeInfo().getStorageType());
178178
}
179179

180-
IsPOD_t isPOD(ResilienceScope scope) const {
181-
return getTypeInfo().isPOD(scope);
180+
IsPOD_t isPOD(ResilienceExpansion expansion) const {
181+
return getTypeInfo().isPOD(expansion);
182182
}
183183

184184
/// \group Query enum layout

Diff for: lib/IRGen/GenExistential.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ class ClassExistentialTypeInfo
10401040

10411041
public:
10421042

1043-
bool isSingleRetainablePointer(ResilienceScope scope,
1043+
bool isSingleRetainablePointer(ResilienceExpansion expansion,
10441044
ReferenceCounting *refcounting) const override{
10451045
if (refcounting) *refcounting = Refcounting;
10461046
return getNumStoredProtocols() == 0;

Diff for: lib/IRGen/GenFunc.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,8 @@ const TypeInfo *TypeConverter::convertBlockStorageType(SILBlockStorageType *T) {
724724
spareBits.extendWithSetBits(captureOffset.getValueInBits());
725725
size = captureOffset + fixedCapture->getFixedSize();
726726
spareBits.append(fixedCapture->getSpareBits());
727-
pod = fixedCapture->isPOD(ResilienceScope::Component);
728-
bt = fixedCapture->isBitwiseTakable(ResilienceScope::Component);
727+
pod = fixedCapture->isPOD(ResilienceExpansion::Maximal);
728+
bt = fixedCapture->isBitwiseTakable(ResilienceExpansion::Maximal);
729729
}
730730

731731
llvm::Type *storageElts[] = {
@@ -3553,7 +3553,7 @@ static llvm::Function *emitPartialApplicationForwarder(IRGenModule &IGM,
35533553
case ParameterConvention::Direct_Unowned:
35543554
// If the type is nontrivial, keep the context alive since the field
35553555
// depends on the context to not be deallocated.
3556-
if (!fieldTI.isPOD(ResilienceScope::Component))
3556+
if (!fieldTI.isPOD(ResilienceExpansion::Maximal))
35573557
dependsOnContextLifetime = true;
35583558
SWIFT_FALLTHROUGH;
35593559
case ParameterConvention::Direct_Deallocating:
@@ -3797,7 +3797,7 @@ void irgen::emitFunctionPartialApplication(IRGenFunction &IGF,
37973797
continue;
37983798
}
37993799

3800-
if (ti.isSingleSwiftRetainablePointer(ResilienceScope::Component)) {
3800+
if (ti.isSingleSwiftRetainablePointer(ResilienceExpansion::Maximal)) {
38013801
hasSingleSwiftRefcountedContext = Yes;
38023802
singleRefcountedConvention = param.getConvention();
38033803
} else {
@@ -4071,7 +4071,7 @@ void irgen::emitBlockHeader(IRGenFunction &IGF,
40714071
uint32_t flags = 0;
40724072
auto &captureTL
40734073
= IGF.getTypeInfoForLowered(blockTy->getCaptureType());
4074-
bool isPOD = captureTL.isPOD(ResilienceScope::Component);
4074+
bool isPOD = captureTL.isPOD(ResilienceExpansion::Maximal);
40754075
if (!isPOD)
40764076
flags |= 1 << 25;
40774077

Diff for: lib/IRGen/GenHeap.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,7 @@ const TypeInfo *TypeConverter::convertBoxType(SILBoxType *T) {
14891489
}
14901490

14911491
// We can share box info for all similarly-shaped POD types.
1492-
if (fixedTI.isPOD(ResilienceScope::Component)) {
1492+
if (fixedTI.isPOD(ResilienceExpansion::Maximal)) {
14931493
auto stride = fixedTI.getFixedStride();
14941494
auto align = fixedTI.getFixedAlignment();
14951495
auto foundPOD = PODBoxTI.find({stride.getValue(),align.getValue()});
@@ -1503,7 +1503,7 @@ const TypeInfo *TypeConverter::convertBoxType(SILBoxType *T) {
15031503
}
15041504

15051505
// We can share box info for all single-refcounted types.
1506-
if (fixedTI.isSingleSwiftRetainablePointer(ResilienceScope::Component)) {
1506+
if (fixedTI.isSingleSwiftRetainablePointer(ResilienceExpansion::Maximal)) {
15071507
if (!SwiftRetainablePointerBoxTI)
15081508
SwiftRetainablePointerBoxTI
15091509
= new SingleRefcountedBoxTypeInfo(IGM, ReferenceCounting::Native);

Diff for: lib/IRGen/GenMeta.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,7 @@ namespace {
15081508
// If the type is a singleton aggregate, the field's layout is equivalent
15091509
// to the aggregate's.
15101510
if (SILType singletonFieldTy = getSingletonAggregateFieldType(IGF.IGM,
1511-
silTy, ResilienceScope::Component))
1511+
silTy, ResilienceExpansion::Maximal))
15121512
return visit(singletonFieldTy.getSwiftRValueType());
15131513

15141514
// If the type is fixed-layout, emit a copy of its layout.
@@ -4307,7 +4307,7 @@ llvm::Value *irgen::emitVirtualMethodValue(IRGenFunction &IGF,
43074307
instanceTy = SILType::getPrimitiveObjectType(metaTy.getInstanceType());
43084308

43094309
if (IGF.IGM.isResilient(instanceTy.getClassOrBoundGenericClass(),
4310-
ResilienceScope::Component)) {
4310+
ResilienceExpansion::Maximal)) {
43114311
// The derived type that is making the super call is resilient,
43124312
// for example we may be in an extension of a class outside of our
43134313
// resilience domain. So, we need to load the superclass metadata
@@ -4571,9 +4571,9 @@ class EnumMetadataBuilder
45714571
auto enumTy = Target->getDeclaredTypeInContext()->getCanonicalType();
45724572
auto &enumTI = IGM.getTypeInfoForLowered(enumTy);
45734573
(void) enumTI;
4574-
assert(enumTI.isFixedSize(ResilienceScope::Component) &&
4574+
assert(enumTI.isFixedSize(ResilienceExpansion::Maximal) &&
45754575
"emitting constant enum metadata for resilient-sized type?");
4576-
assert(!enumTI.isFixedSize(ResilienceScope::Universal) &&
4576+
assert(!enumTI.isFixedSize(ResilienceExpansion::Minimal) &&
45774577
"non-generic, non-resilient enums don't need payload size in metadata");
45784578

45794579
auto &strategy = getEnumImplStrategy(IGM, enumTy);
@@ -4616,7 +4616,7 @@ class GenericEnumMetadataBuilder
46164616
auto enumTy = Target->getDeclaredTypeInContext()->getCanonicalType();
46174617
auto &enumTI = IGM.getTypeInfoForLowered(enumTy);
46184618
(void) enumTI;
4619-
assert(!enumTI.isFixedSize(ResilienceScope::Universal) &&
4619+
assert(!enumTI.isFixedSize(ResilienceExpansion::Minimal) &&
46204620
"non-generic, non-resilient enums don't need payload size in metadata");
46214621
addConstantWord(0);
46224622
}

0 commit comments

Comments
 (0)