Skip to content

Commit 58e330d

Browse files
committed
[DI] Simplify immutability checks on _storage base
1 parent 24b2bca commit 58e330d

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -468,25 +468,30 @@ DIMemoryObjectInfo::getPathStringToElement(unsigned Element,
468468

469469
/// If the specified value is a 'let' property in an initializer, return true.
470470
bool DIMemoryObjectInfo::isElementLetProperty(unsigned Element) const {
471-
NullablePtr<NominalTypeDecl> NTD;
472-
473471
// If this is an element of a `_storage` tuple, we need to
474472
// check the `$Storage` to determine whether underlying storage
475473
// backing element is immutable.
476474
if (auto *storageVar = getAsTypeWrapperLocalStorageVar()) {
477475
auto *wrappedType = cast<NominalTypeDecl>(
478476
storageVar->getDeclContext()->getInnermostTypeContext());
479477
assert(wrappedType && "_storage reference without type wrapper");
480-
NTD = wrappedType->getTypeWrapperStorageDecl();
481-
} else {
482-
// If we aren't representing 'self' in a non-delegating initializer, then we
483-
// can't have 'let' properties.
484-
if (!isNonDelegatingInit())
485-
return IsLet;
486-
487-
NTD = MemorySILType.getNominalOrBoundGenericNominal();
478+
479+
auto storageVarType = storageVar->getInterfaceType()->getAs<TupleType>();
480+
assert(Element < storageVarType->getNumElements());
481+
auto propertyName = storageVarType->getElement(Element).getName();
482+
483+
auto *storageDecl = wrappedType->getTypeWrapperStorageDecl();
484+
auto *property = storageDecl->lookupDirect(propertyName).front();
485+
return cast<VarDecl>(property)->isLet();
488486
}
489487

488+
// If we aren't representing 'self' in a non-delegating initializer, then we
489+
// can't have 'let' properties.
490+
if (!isNonDelegatingInit())
491+
return IsLet;
492+
493+
auto NTD = MemorySILType.getNominalOrBoundGenericNominal();
494+
490495
if (!NTD) {
491496
// Otherwise, we miscounted elements?
492497
assert(Element == 0 && "Element count problem");
@@ -496,7 +501,7 @@ bool DIMemoryObjectInfo::isElementLetProperty(unsigned Element) const {
496501
auto &Module = MemoryInst->getModule();
497502

498503
auto expansionContext = TypeExpansionContext(*MemoryInst->getFunction());
499-
for (auto *VD : NTD.get()->getStoredProperties()) {
504+
for (auto *VD : NTD->getStoredProperties()) {
500505
auto FieldType = MemorySILType.getFieldType(VD, Module, expansionContext);
501506
unsigned NumFieldElements =
502507
getElementCountRec(expansionContext, Module, FieldType, false);

0 commit comments

Comments
 (0)