@@ -699,7 +699,9 @@ static void maybeMarkTransparent(FuncDecl *accessor,
699
699
->isNominalTypeOrNominalTypeExtensionContext ();
700
700
701
701
// FIXME: resilient global variables
702
- if (!NTD || NTD->hasFixedLayout ())
702
+ if (!NTD ||
703
+ NTD->hasFixedLayout () ||
704
+ (isa<ClassDecl>(NTD) && NTD->getClangDecl ()))
703
705
accessor->getAttrs ().add (new (TC.Context ) TransparentAttr (IsImplicit));
704
706
}
705
707
@@ -793,14 +795,6 @@ static void synthesizeStoredMaterializeForSet(FuncDecl *materializeForSet,
793
795
794
796
SourceLoc loc = storage->getLoc ();
795
797
materializeForSet->setBody (BraceStmt::create (ctx, loc, returnStmt, loc,true ));
796
-
797
- maybeMarkTransparent (materializeForSet, storage, TC);
798
-
799
- TC.typeCheckDecl (materializeForSet, true );
800
-
801
- // Register the accessor as an external decl if the storage was imported.
802
- if (needsToBeRegisteredAsExternalDecl (storage))
803
- TC.Context .addExternalDecl (materializeForSet);
804
798
}
805
799
806
800
// / Does a storage decl currently lacking accessor functions require a
@@ -896,7 +890,6 @@ void swift::addTrivialAccessorsToStorage(AbstractStorageDecl *storage,
896
890
if (setter) {
897
891
FuncDecl *materializeForSet = addMaterializeForSet (storage, TC);
898
892
synthesizeMaterializeForSet (materializeForSet, storage, TC);
899
- TC.typeCheckDecl (materializeForSet, true );
900
893
TC.typeCheckDecl (materializeForSet, false );
901
894
}
902
895
}
@@ -941,7 +934,6 @@ void TypeChecker::synthesizeWitnessAccessorsForStorage(
941
934
requirement->getSetter () && !storage->getMaterializeForSetFunc ()) {
942
935
FuncDecl *materializeForSet = addMaterializeForSet (storage, *this );
943
936
synthesizeMaterializeForSet (materializeForSet, storage, *this );
944
- typeCheckDecl (materializeForSet, true );
945
937
typeCheckDecl (materializeForSet, false );
946
938
}
947
939
return ;
@@ -1153,15 +1145,6 @@ static void synthesizeComputedMaterializeForSet(FuncDecl *materializeForSet,
1153
1145
1154
1146
SourceLoc loc = storage->getLoc ();
1155
1147
materializeForSet->setBody (BraceStmt::create (ctx, loc, body, loc, true ));
1156
-
1157
- // Mark it transparent, there is no user benefit to this actually existing.
1158
- materializeForSet->getAttrs ().add (new (ctx) TransparentAttr (IsImplicit));
1159
-
1160
- TC.typeCheckDecl (materializeForSet, true );
1161
-
1162
- // Register the accessor as an external decl if the storage was imported.
1163
- if (needsToBeRegisteredAsExternalDecl (storage))
1164
- TC.Context .addExternalDecl (materializeForSet);
1165
1148
}
1166
1149
1167
1150
// / Build a direct call to an addressor from within a
@@ -1333,15 +1316,6 @@ static void synthesizeAddressedMaterializeForSet(FuncDecl *materializeForSet,
1333
1316
1334
1317
SourceLoc loc = storage->getLoc ();
1335
1318
materializeForSet->setBody (BraceStmt::create (ctx, loc, body, loc));
1336
-
1337
- // Mark it transparent, there is no user benefit to this actually existing.
1338
- materializeForSet->getAttrs ().add (new (ctx) TransparentAttr (IsImplicit));
1339
-
1340
- TC.typeCheckDecl (materializeForSet, true );
1341
-
1342
- // Register the accessor as an external decl if the storage was imported.
1343
- if (needsToBeRegisteredAsExternalDecl (storage))
1344
- TC.Context .addExternalDecl (materializeForSet);
1345
1319
}
1346
1320
1347
1321
void swift::synthesizeMaterializeForSet (FuncDecl *materializeForSet,
@@ -1363,20 +1337,19 @@ void swift::synthesizeMaterializeForSet(FuncDecl *materializeForSet,
1363
1337
|| needsDynamicMaterializeForSet (var)) {
1364
1338
synthesizeComputedMaterializeForSet (materializeForSet, storage,
1365
1339
bufferDecl, TC);
1366
- return ;
1340
+ } else {
1341
+ synthesizeStoredMaterializeForSet (materializeForSet, storage,
1342
+ bufferDecl, TC);
1367
1343
}
1368
-
1369
- synthesizeStoredMaterializeForSet (materializeForSet, storage,
1370
- bufferDecl, TC);
1371
- return ;
1344
+ break ;
1372
1345
}
1373
1346
1374
1347
// We should access these by calling mutableAddress.
1375
1348
case AbstractStorageDecl::AddressedWithTrivialAccessors:
1376
1349
case AbstractStorageDecl::ComputedWithMutableAddress:
1377
1350
synthesizeAddressedMaterializeForSet (materializeForSet, storage,
1378
1351
bufferDecl, TC);
1379
- return ;
1352
+ break ;
1380
1353
1381
1354
// These must be accessed with a getter/setter pair.
1382
1355
// TODO: StoredWithObservers and AddressedWithObservers could be
@@ -1387,9 +1360,16 @@ void swift::synthesizeMaterializeForSet(FuncDecl *materializeForSet,
1387
1360
case AbstractStorageDecl::Computed:
1388
1361
synthesizeComputedMaterializeForSet (materializeForSet, storage,
1389
1362
bufferDecl, TC);
1390
- return ;
1363
+ break ;
1391
1364
}
1392
- llvm_unreachable (" bad abstract storage kind" );
1365
+
1366
+ maybeMarkTransparent (materializeForSet, storage, TC);
1367
+
1368
+ TC.typeCheckDecl (materializeForSet, true );
1369
+
1370
+ // Register the accessor as an external decl if the storage was imported.
1371
+ if (needsToBeRegisteredAsExternalDecl (storage))
1372
+ TC.Context .addExternalDecl (materializeForSet);
1393
1373
}
1394
1374
1395
1375
// / Given a VarDecl with a willSet: and/or didSet: specifier, synthesize the
@@ -1761,10 +1741,17 @@ void swift::maybeAddMaterializeForSet(AbstractStorageDecl *storage,
1761
1741
return ;
1762
1742
}
1763
1743
1764
- // Structs and enums don't need this.
1765
- } else {
1766
- assert (isa<StructDecl>(container) || isa<EnumDecl>(container));
1744
+ // Enums don't need this.
1745
+ } else if (isa<EnumDecl>(container)) {
1767
1746
return ;
1747
+
1748
+ // Computed properties of @_fixed_layout structs don't need this, but
1749
+ // resilient structs do, since stored properties can resiliently become
1750
+ // computed or vice versa.
1751
+ } else {
1752
+ auto *structDecl = cast<StructDecl>(container);
1753
+ if (structDecl->hasFixedLayout ())
1754
+ return ;
1768
1755
}
1769
1756
1770
1757
addMaterializeForSet (storage, TC);
0 commit comments