Skip to content

Commit f86541e

Browse files
authored
Merge pull request #84919 from slavapestov/stored-properties-of-resilient-types
Don't ask about stored properties of resilient types in various places
2 parents 9956cda + b720735 commit f86541e

File tree

9 files changed

+87
-37
lines changed

9 files changed

+87
-37
lines changed

lib/AST/Type.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5238,17 +5238,21 @@ getConcurrencyDiagnosticBehaviorLimitRec(
52385238
// merging our fields if we have a struct.
52395239
if (auto *structDecl = dyn_cast<StructDecl>(nomDecl)) {
52405240
std::optional<DiagnosticBehavior> diagnosticBehavior;
5241-
auto substMap = type->getContextSubstitutionMap();
5242-
for (auto storedProperty : structDecl->getStoredProperties()) {
5243-
auto lhs = diagnosticBehavior.value_or(DiagnosticBehavior::Unspecified);
5244-
auto astType = storedProperty->getInterfaceType().subst(substMap);
5245-
auto rhs = getConcurrencyDiagnosticBehaviorLimitRec(astType, declCtx,
5246-
visited);
5247-
auto result = lhs.merge(rhs.value_or(DiagnosticBehavior::Unspecified));
5248-
if (result != DiagnosticBehavior::Unspecified)
5249-
diagnosticBehavior = result;
5241+
5242+
if (!nomDecl->isResilient(declCtx->getParentModule(),
5243+
ResilienceExpansion::Maximal)) {
5244+
auto substMap = type->getContextSubstitutionMap();
5245+
for (auto storedProperty : structDecl->getStoredProperties()) {
5246+
auto lhs = diagnosticBehavior.value_or(DiagnosticBehavior::Unspecified);
5247+
auto astType = storedProperty->getInterfaceType().subst(substMap);
5248+
auto rhs = getConcurrencyDiagnosticBehaviorLimitRec(astType, declCtx,
5249+
visited);
5250+
auto result = lhs.merge(rhs.value_or(DiagnosticBehavior::Unspecified));
5251+
if (result != DiagnosticBehavior::Unspecified)
5252+
diagnosticBehavior = result;
5253+
}
5254+
return diagnosticBehavior;
52505255
}
5251-
return diagnosticBehavior;
52525256
}
52535257
}
52545258

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,22 +1190,24 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
11901190
Name);
11911191
// Collect the members.
11921192
SmallVector<MemberDIType, 16> MemberTypes;
1193-
for (VarDecl *VD : Decl->getStoredProperties()) {
1194-
auto memberTy = Type->getTypeOfMember(VD);
1195-
if (auto DbgTy = CompletedDebugTypeInfo::getFromTypeInfo(
1196-
memberTy,
1197-
IGM.getTypeInfoForUnlowered(
1198-
IGM.getSILTypes().getAbstractionPattern(VD), memberTy),
1199-
IGM))
1200-
MemberTypes.emplace_back(VD->getName().str(),
1201-
getByteSize() *
1202-
DbgTy->getAlignment().getValue(),
1203-
getOrCreateType(*DbgTy));
1204-
else
1205-
// Without complete type info we can only create a forward decl.
1206-
return DBuilder.createForwardDecl(
1207-
llvm::dwarf::DW_TAG_structure_type, MangledName, Scope, File, Line,
1208-
llvm::dwarf::DW_LANG_Swift, SizeInBits, 0);
1193+
if (!IGM.isResilient(Decl, ResilienceExpansion::Maximal)) {
1194+
for (VarDecl *VD : Decl->getStoredProperties()) {
1195+
auto memberTy = Type->getTypeOfMember(VD);
1196+
if (auto DbgTy = CompletedDebugTypeInfo::getFromTypeInfo(
1197+
memberTy,
1198+
IGM.getTypeInfoForUnlowered(
1199+
IGM.getSILTypes().getAbstractionPattern(VD), memberTy),
1200+
IGM))
1201+
MemberTypes.emplace_back(VD->getName().str(),
1202+
getByteSize() *
1203+
DbgTy->getAlignment().getValue(),
1204+
getOrCreateType(*DbgTy));
1205+
else
1206+
// Without complete type info we can only create a forward decl.
1207+
return DBuilder.createForwardDecl(
1208+
llvm::dwarf::DW_TAG_structure_type, MangledName, Scope, File, Line,
1209+
llvm::dwarf::DW_LANG_Swift, SizeInBits, 0);
1210+
}
12091211
}
12101212

12111213
SmallVector<llvm::Metadata *, 16> Members;
@@ -1245,17 +1247,21 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
12451247
UniqueID, Name);
12461248
// Collect the members.
12471249
SmallVector<MemberDIType, 16> MemberTypes;
1248-
for (VarDecl *VD : Decl->getStoredProperties()) {
1249-
Type memberTy = UnsubstitutedType->getTypeOfMember(VD);
1250-
auto DbgTy = DebugTypeInfo::getFromTypeInfo(
1251-
memberTy,
1252-
IGM.getTypeInfoForUnlowered(
1253-
IGM.getSILTypes().getAbstractionPattern(VD), memberTy),
1254-
IGM);
1255-
MemberTypes.emplace_back(VD->getName().str(),
1256-
getByteSize() * DbgTy.getAlignment().getValue(),
1257-
getOrCreateType(DbgTy));
1250+
1251+
if (!IGM.isResilient(Decl, ResilienceExpansion::Maximal)) {
1252+
for (VarDecl *VD : Decl->getStoredProperties()) {
1253+
Type memberTy = UnsubstitutedType->getTypeOfMember(VD);
1254+
auto DbgTy = DebugTypeInfo::getFromTypeInfo(
1255+
memberTy,
1256+
IGM.getTypeInfoForUnlowered(
1257+
IGM.getSILTypes().getAbstractionPattern(VD), memberTy),
1258+
IGM);
1259+
MemberTypes.emplace_back(VD->getName().str(),
1260+
getByteSize() * DbgTy.getAlignment().getValue(),
1261+
getOrCreateType(DbgTy));
1262+
}
12581263
}
1264+
12591265
SmallVector<llvm::Metadata *, 16> Members;
12601266
for (auto &Member : MemberTypes) {
12611267
unsigned OffsetInBits = 0;

lib/SIL/IR/SILModule.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,10 @@ unsigned SILModule::getFieldIndex(NominalTypeDecl *decl, VarDecl *field) {
804804
if (auto *classDecl = dyn_cast<ClassDecl>(decl)) {
805805
for (auto *superDecl = classDecl->getSuperclassDecl(); superDecl != nullptr;
806806
superDecl = superDecl->getSuperclassDecl()) {
807-
index += superDecl->getStoredProperties().size();
807+
if (!superDecl->isResilient(getSwiftModule(),
808+
ResilienceExpansion::Maximal)) {
809+
index += superDecl->getStoredProperties().size();
810+
}
808811
}
809812
}
810813
for (VarDecl *property : decl->getStoredProperties()) {

lib/SIL/IR/SILType.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ bool SILType::isEmpty(const SILFunction &F) const {
162162
// Also, a struct is empty if it either has no fields or if all fields are
163163
// empty.
164164
SILModule &module = F.getModule();
165+
if (structDecl->isResilient(module.getSwiftModule(),
166+
F.getResilienceExpansion())) {
167+
return false;
168+
}
169+
165170
TypeExpansionContext typeEx = F.getTypeExpansionContext();
166171
for (VarDecl *field : structDecl->getStoredProperties()) {
167172
if (!getFieldType(field, module, typeEx).isEmpty(F))

lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ TypeSubElementCount::TypeSubElementCount(SILType type, SILModule &mod,
6666
}
6767

6868
if (auto *structDecl = getFullyReferenceableStruct(type)) {
69+
// A resilient struct has 1 element.
70+
if (structDecl->isResilient(mod.getSwiftModule(),
71+
ResilienceExpansion::Maximal)) {
72+
number = 1;
73+
return;
74+
}
75+
6976
unsigned numElements = 0;
7077
for (auto *fieldDecl : structDecl->getStoredProperties())
7178
numElements += TypeSubElementCount(

lib/SILOptimizer/Analysis/DestructorAnalysis.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ bool DestructorAnalysis::isSafeType(CanType Ty) {
8080
areTypeParametersSafe(Ty))
8181
return cacheResult(Ty, true);
8282

83+
// Not allowed to look at stored properties of resilient types.
84+
if (Struct->isResilient(Mod->getSwiftModule(),
85+
ResilienceExpansion::Maximal)) {
86+
return cacheResult(Ty, false);
87+
}
88+
8389
// Check the stored properties.
8490
for (auto SP : Struct->getStoredProperties()) {
8591
if (!isSafeType(SP->getInterfaceType()->getCanonicalType()))
@@ -97,6 +103,8 @@ bool DestructorAnalysis::isSafeType(CanType Ty) {
97103
}
98104

99105
// TODO: enum types.
106+
// TODO: Don't forget to check resilience of enum decl, like
107+
// we do for structs above.
100108

101109
return cacheResult(Ty, false);
102110
}

lib/SILOptimizer/Mandatory/PredictableMemOpt.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ static unsigned getNumSubElements(SILType T, SILFunction &F,
102102
}
103103

104104
if (auto *SD = getFullyReferenceableStruct(T)) {
105+
if (SD->isResilient(F.getModule().getSwiftModule(),
106+
F.getResilienceExpansion())) {
107+
return false;
108+
}
109+
105110
unsigned NumElements = 0;
106111
for (auto *D : SD->getStoredProperties())
107112
NumElements +=

lib/Sema/TypeCheckCircularity.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,14 @@ bool CircularityChecker::expandTuple(CanTupleType tupleType, unsigned depth) {
232232
/// Visit a nominal type and try to expand it one level.
233233
bool CircularityChecker::expandNominal(CanType type, NominalTypeDecl *D,
234234
unsigned depth) {
235+
if (D->isResilient(OriginalDecl->getParentModule(),
236+
ResilienceExpansion::Maximal)) {
237+
LLVM_DEBUG(llvm::dbgs() << std::string(depth, ' ')
238+
<< "skipping resilient nominal "
239+
<< type << "\n";);
240+
return false;
241+
}
242+
235243
LLVM_DEBUG(llvm::dbgs() << std::string(depth, ' ') << "expanding nominal "
236244
<< type << "\n";);
237245
if (auto S = dyn_cast<StructDecl>(D)) {

lib/Sema/TypeCheckInvertible.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ static void checkInvertibleConformanceCommon(DeclContext *dc,
154154
ctx.Diags.diagnose(conformanceLoc,
155155
diag::invertible_conformance_other_source_file,
156156
getInvertibleProtocolKindName(ip), nominalDecl);
157+
158+
// Skip further work to avoid asking for stored properties of
159+
// resilient types.
160+
return;
157161
}
158162
}
159163

0 commit comments

Comments
 (0)