@@ -1029,6 +1029,31 @@ ImportDecl::findBestImportKind(ArrayRef<ValueDecl *> Decls) {
1029
1029
return FirstKind;
1030
1030
}
1031
1031
1032
+ Optional<VarDecl *>
1033
+ NominalTypeDecl::ToStoredProperty::operator ()(Decl *decl) const {
1034
+ if (auto var = dyn_cast<VarDecl>(decl)) {
1035
+ if (!var->isStatic () && var->hasStorage ())
1036
+ return var;
1037
+ }
1038
+
1039
+ return None;
1040
+ }
1041
+
1042
+ Optional<Decl *>
1043
+ NominalTypeDecl::ToStoredPropertyOrMissingMemberPlaceholder
1044
+ ::operator ()(Decl *decl) const {
1045
+ if (auto var = dyn_cast<VarDecl>(decl)) {
1046
+ if (!var->isStatic () && var->hasStorage ())
1047
+ return var;
1048
+ }
1049
+ if (auto missing = dyn_cast<MissingMemberDecl>(decl)) {
1050
+ if (missing->getNumberOfFieldOffsetVectorEntries () > 0 )
1051
+ return missing;
1052
+ }
1053
+
1054
+ return None;
1055
+ }
1056
+
1032
1057
void NominalTypeDecl::setConformanceLoader (LazyMemberLoader *lazyLoader,
1033
1058
uint64_t contextData) {
1034
1059
assert (!Bits.NominalTypeDecl .HasLazyConformances &&
@@ -1534,22 +1559,36 @@ bool VarDecl::isInitExposedToClients() const {
1534
1559
1535
1560
// / Check whether the given type representation will be
1536
1561
// / default-initializable.
1537
- static bool isDefaultInitializable (const TypeRepr *typeRepr) {
1562
+ static bool isDefaultInitializable (const TypeRepr *typeRepr, ASTContext &ctx ) {
1538
1563
// Look through most attributes.
1539
1564
if (const auto attributed = dyn_cast<AttributedTypeRepr>(typeRepr)) {
1540
1565
// Ownership kinds have optionalness requirements.
1541
1566
if (optionalityOf (attributed->getAttrs ().getOwnership ()) ==
1542
1567
ReferenceOwnershipOptionality::Required)
1543
1568
return true ;
1544
1569
1545
- return isDefaultInitializable (attributed->getTypeRepr ());
1570
+ return isDefaultInitializable (attributed->getTypeRepr (), ctx );
1546
1571
}
1547
1572
1548
1573
// Optional types are default-initializable.
1549
1574
if (isa<OptionalTypeRepr>(typeRepr) ||
1550
1575
isa<ImplicitlyUnwrappedOptionalTypeRepr>(typeRepr))
1551
1576
return true ;
1552
1577
1578
+ // Also support the desugared 'Optional<T>' spelling.
1579
+ if (!ctx.isSwiftVersionAtLeast (5 )) {
1580
+ if (auto *identRepr = dyn_cast<SimpleIdentTypeRepr>(typeRepr)) {
1581
+ if (identRepr->getIdentifier () == ctx.Id_Void )
1582
+ return true ;
1583
+ }
1584
+
1585
+ if (auto *identRepr = dyn_cast<GenericIdentTypeRepr>(typeRepr)) {
1586
+ if (identRepr->getIdentifier () == ctx.Id_Optional &&
1587
+ identRepr->getNumGenericArgs () == 1 )
1588
+ return true ;
1589
+ }
1590
+ }
1591
+
1553
1592
// Tuple types are default-initializable if all of their element
1554
1593
// types are.
1555
1594
if (const auto tuple = dyn_cast<TupleTypeRepr>(typeRepr)) {
@@ -1558,7 +1597,7 @@ static bool isDefaultInitializable(const TypeRepr *typeRepr) {
1558
1597
return false ;
1559
1598
1560
1599
for (const auto elt : tuple->getElements ()) {
1561
- if (!isDefaultInitializable (elt.Type ))
1600
+ if (!isDefaultInitializable (elt.Type , ctx ))
1562
1601
return false ;
1563
1602
}
1564
1603
@@ -1610,11 +1649,13 @@ bool PatternBindingDecl::isDefaultInitializable(unsigned i) const {
1610
1649
if (entry.getPattern ()->isNeverDefaultInitializable ())
1611
1650
return false ;
1612
1651
1652
+ auto &ctx = getASTContext ();
1653
+
1613
1654
// If the pattern is typed as optional (or tuples thereof), it is
1614
1655
// default initializable.
1615
1656
if (const auto typedPattern = dyn_cast<TypedPattern>(entry.getPattern ())) {
1616
1657
if (const auto typeRepr = typedPattern->getTypeLoc ().getTypeRepr ()) {
1617
- if (::isDefaultInitializable (typeRepr))
1658
+ if (::isDefaultInitializable (typeRepr, ctx ))
1618
1659
return true ;
1619
1660
} else if (typedPattern->isImplicit ()) {
1620
1661
// Lazy vars have implicit storage assigned to back them. Because the
@@ -3419,7 +3460,7 @@ void NominalTypeDecl::addExtension(ExtensionDecl *extension) {
3419
3460
addedExtension (extension);
3420
3461
}
3421
3462
3422
- auto NominalTypeDecl::getStoredProperties (bool skipInaccessible ) const
3463
+ auto NominalTypeDecl::getStoredProperties () const
3423
3464
-> StoredPropertyRange {
3424
3465
// This should be called at most once per SIL instruction that accesses a
3425
3466
// VarDecl.
@@ -3432,10 +3473,9 @@ auto NominalTypeDecl::getStoredProperties(bool skipInaccessible) const
3432
3473
// Clang-imported classes never have stored properties.
3433
3474
if (hasClangNode () && isa<ClassDecl>(this ))
3434
3475
return StoredPropertyRange (DeclRange (nullptr , nullptr ),
3435
- ToStoredProperty (skipInaccessible ));
3476
+ ToStoredProperty ());
3436
3477
3437
- return StoredPropertyRange (getMembers (),
3438
- ToStoredProperty (skipInaccessible));
3478
+ return StoredPropertyRange (getMembers (), ToStoredProperty ());
3439
3479
}
3440
3480
3441
3481
bool NominalTypeDecl::isOptionalDecl () const {
@@ -6467,7 +6507,9 @@ bool AbstractFunctionDecl::isObjCInstanceMethod() const {
6467
6507
}
6468
6508
6469
6509
static bool requiresNewVTableEntry (const AbstractFunctionDecl *decl) {
6470
- if (!isa<ClassDecl>(decl->getDeclContext ()))
6510
+ auto *dc = decl->getDeclContext ();
6511
+
6512
+ if (!isa<ClassDecl>(dc))
6471
6513
return true ;
6472
6514
6473
6515
assert (isa<FuncDecl>(decl) || isa<ConstructorDecl>(decl));
@@ -6476,7 +6518,16 @@ static bool requiresNewVTableEntry(const AbstractFunctionDecl *decl) {
6476
6518
// Dynamic methods are always accessed by objc_msgSend().
6477
6519
if (decl->isFinal () || decl->isObjCDynamic () || decl->hasClangNode ())
6478
6520
return false ;
6479
-
6521
+
6522
+ auto &ctx = dc->getASTContext ();
6523
+
6524
+ // FIXME: Remove this once getInterfaceType(), isDesignatedInit() and
6525
+ // anything else that is used below has been request-ified.
6526
+ if (!decl->hasInterfaceType ()) {
6527
+ ctx.getLazyResolver ()->resolveDeclSignature (
6528
+ const_cast <AbstractFunctionDecl *>(decl));
6529
+ }
6530
+
6480
6531
// Initializers are not normally inherited, but required initializers can
6481
6532
// be overridden for invocation from dynamic types, and convenience initializers
6482
6533
// are conditionally inherited when all designated initializers are available,
@@ -6500,7 +6551,14 @@ static bool requiresNewVTableEntry(const AbstractFunctionDecl *decl) {
6500
6551
6501
6552
if (!base || base->hasClangNode () || base->isObjCDynamic ())
6502
6553
return true ;
6503
-
6554
+
6555
+ // FIXME: Remove this once getInterfaceType(), isDesignatedInit() and
6556
+ // anything else that is used below has been request-ified.
6557
+ if (!base->hasInterfaceType ()) {
6558
+ ctx.getLazyResolver ()->resolveDeclSignature (
6559
+ const_cast <AbstractFunctionDecl *>(base));
6560
+ }
6561
+
6504
6562
// As above, convenience initializers are not formally overridable in Swift
6505
6563
// vtables, although same-named initializers are modeled as overriding for
6506
6564
// various QoI and objc interop reasons. Even if we "override" a non-required
0 commit comments