@@ -468,25 +468,30 @@ DIMemoryObjectInfo::getPathStringToElement(unsigned Element,
468
468
469
469
// / If the specified value is a 'let' property in an initializer, return true.
470
470
bool DIMemoryObjectInfo::isElementLetProperty (unsigned Element) const {
471
- NullablePtr<NominalTypeDecl> NTD;
472
-
473
471
// If this is an element of a `_storage` tuple, we need to
474
472
// check the `$Storage` to determine whether underlying storage
475
473
// backing element is immutable.
476
474
if (auto *storageVar = getAsTypeWrapperLocalStorageVar ()) {
477
475
auto *wrappedType = cast<NominalTypeDecl>(
478
476
storageVar->getDeclContext ()->getInnermostTypeContext ());
479
477
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 ();
488
486
}
489
487
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
+
490
495
if (!NTD) {
491
496
// Otherwise, we miscounted elements?
492
497
assert (Element == 0 && " Element count problem" );
@@ -496,7 +501,7 @@ bool DIMemoryObjectInfo::isElementLetProperty(unsigned Element) const {
496
501
auto &Module = MemoryInst->getModule ();
497
502
498
503
auto expansionContext = TypeExpansionContext (*MemoryInst->getFunction ());
499
- for (auto *VD : NTD. get () ->getStoredProperties ()) {
504
+ for (auto *VD : NTD->getStoredProperties ()) {
500
505
auto FieldType = MemorySILType.getFieldType (VD, Module, expansionContext);
501
506
unsigned NumFieldElements =
502
507
getElementCountRec (expansionContext, Module, FieldType, false );
0 commit comments