Skip to content

Commit 62a37d7

Browse files
authored
Merge pull request #26160 from slavapestov/prepare-for-finalize-decl-removal
Prepare for finalizeDecl() removal
2 parents 6318ebc + a347dce commit 62a37d7

15 files changed

+273
-257
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3454,9 +3454,7 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
34543454
private:
34553455
/// Predicate used to filter StoredPropertyRange.
34563456
struct ToStoredProperty {
3457-
ToStoredProperty(bool skipInaccessible = false) :
3458-
skipUserInaccessible(skipInaccessible) {}
3459-
bool skipUserInaccessible;
3457+
ToStoredProperty() {}
34603458
Optional<VarDecl *> operator()(Decl *decl) const;
34613459
};
34623460

@@ -3466,7 +3464,7 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
34663464
ToStoredProperty>;
34673465

34683466
/// Return a collection of the stored member variables of this type.
3469-
StoredPropertyRange getStoredProperties(bool skipInaccessible = false) const;
3467+
StoredPropertyRange getStoredProperties() const;
34703468

34713469
private:
34723470
/// Predicate used to filter StoredPropertyRange.
@@ -7150,32 +7148,6 @@ inline bool ValueDecl::isSettable(const DeclContext *UseDC,
71507148
return false;
71517149
}
71527150

7153-
inline Optional<VarDecl *>
7154-
NominalTypeDecl::ToStoredProperty::operator()(Decl *decl) const {
7155-
if (auto var = dyn_cast<VarDecl>(decl)) {
7156-
if (!var->isStatic() && var->hasStorage() &&
7157-
(!skipUserInaccessible || var->isUserAccessible()))
7158-
return var;
7159-
}
7160-
7161-
return None;
7162-
}
7163-
7164-
inline Optional<Decl *>
7165-
NominalTypeDecl::ToStoredPropertyOrMissingMemberPlaceholder
7166-
::operator()(Decl *decl) const {
7167-
if (auto var = dyn_cast<VarDecl>(decl)) {
7168-
if (!var->isStatic() && var->hasStorage())
7169-
return var;
7170-
}
7171-
if (auto missing = dyn_cast<MissingMemberDecl>(decl)) {
7172-
if (missing->getNumberOfFieldOffsetVectorEntries() > 0)
7173-
return missing;
7174-
}
7175-
7176-
return None;
7177-
}
7178-
71797151
inline void
71807152
AbstractStorageDecl::overwriteSetterAccess(AccessLevel accessLevel) {
71817153
Accessors.setInt(accessLevel);

include/swift/AST/KnownIdentifiers.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ IDENTIFIER(type)
119119
IDENTIFIER(Value)
120120
IDENTIFIER(value)
121121
IDENTIFIER_WITH_NAME(value_, "_value")
122+
IDENTIFIER(Void)
122123
IDENTIFIER(WinSDK)
123124
IDENTIFIER(with)
124125
IDENTIFIER(withArguments)

lib/AST/Decl.cpp

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,31 @@ ImportDecl::findBestImportKind(ArrayRef<ValueDecl *> Decls) {
10291029
return FirstKind;
10301030
}
10311031

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+
10321057
void NominalTypeDecl::setConformanceLoader(LazyMemberLoader *lazyLoader,
10331058
uint64_t contextData) {
10341059
assert(!Bits.NominalTypeDecl.HasLazyConformances &&
@@ -1534,22 +1559,36 @@ bool VarDecl::isInitExposedToClients() const {
15341559

15351560
/// Check whether the given type representation will be
15361561
/// default-initializable.
1537-
static bool isDefaultInitializable(const TypeRepr *typeRepr) {
1562+
static bool isDefaultInitializable(const TypeRepr *typeRepr, ASTContext &ctx) {
15381563
// Look through most attributes.
15391564
if (const auto attributed = dyn_cast<AttributedTypeRepr>(typeRepr)) {
15401565
// Ownership kinds have optionalness requirements.
15411566
if (optionalityOf(attributed->getAttrs().getOwnership()) ==
15421567
ReferenceOwnershipOptionality::Required)
15431568
return true;
15441569

1545-
return isDefaultInitializable(attributed->getTypeRepr());
1570+
return isDefaultInitializable(attributed->getTypeRepr(), ctx);
15461571
}
15471572

15481573
// Optional types are default-initializable.
15491574
if (isa<OptionalTypeRepr>(typeRepr) ||
15501575
isa<ImplicitlyUnwrappedOptionalTypeRepr>(typeRepr))
15511576
return true;
15521577

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+
15531592
// Tuple types are default-initializable if all of their element
15541593
// types are.
15551594
if (const auto tuple = dyn_cast<TupleTypeRepr>(typeRepr)) {
@@ -1558,7 +1597,7 @@ static bool isDefaultInitializable(const TypeRepr *typeRepr) {
15581597
return false;
15591598

15601599
for (const auto elt : tuple->getElements()) {
1561-
if (!isDefaultInitializable(elt.Type))
1600+
if (!isDefaultInitializable(elt.Type, ctx))
15621601
return false;
15631602
}
15641603

@@ -1610,11 +1649,13 @@ bool PatternBindingDecl::isDefaultInitializable(unsigned i) const {
16101649
if (entry.getPattern()->isNeverDefaultInitializable())
16111650
return false;
16121651

1652+
auto &ctx = getASTContext();
1653+
16131654
// If the pattern is typed as optional (or tuples thereof), it is
16141655
// default initializable.
16151656
if (const auto typedPattern = dyn_cast<TypedPattern>(entry.getPattern())) {
16161657
if (const auto typeRepr = typedPattern->getTypeLoc().getTypeRepr()) {
1617-
if (::isDefaultInitializable(typeRepr))
1658+
if (::isDefaultInitializable(typeRepr, ctx))
16181659
return true;
16191660
} else if (typedPattern->isImplicit()) {
16201661
// Lazy vars have implicit storage assigned to back them. Because the
@@ -3419,7 +3460,7 @@ void NominalTypeDecl::addExtension(ExtensionDecl *extension) {
34193460
addedExtension(extension);
34203461
}
34213462

3422-
auto NominalTypeDecl::getStoredProperties(bool skipInaccessible) const
3463+
auto NominalTypeDecl::getStoredProperties() const
34233464
-> StoredPropertyRange {
34243465
// This should be called at most once per SIL instruction that accesses a
34253466
// VarDecl.
@@ -3432,10 +3473,9 @@ auto NominalTypeDecl::getStoredProperties(bool skipInaccessible) const
34323473
// Clang-imported classes never have stored properties.
34333474
if (hasClangNode() && isa<ClassDecl>(this))
34343475
return StoredPropertyRange(DeclRange(nullptr, nullptr),
3435-
ToStoredProperty(skipInaccessible));
3476+
ToStoredProperty());
34363477

3437-
return StoredPropertyRange(getMembers(),
3438-
ToStoredProperty(skipInaccessible));
3478+
return StoredPropertyRange(getMembers(), ToStoredProperty());
34393479
}
34403480

34413481
bool NominalTypeDecl::isOptionalDecl() const {
@@ -6467,7 +6507,9 @@ bool AbstractFunctionDecl::isObjCInstanceMethod() const {
64676507
}
64686508

64696509
static bool requiresNewVTableEntry(const AbstractFunctionDecl *decl) {
6470-
if (!isa<ClassDecl>(decl->getDeclContext()))
6510+
auto *dc = decl->getDeclContext();
6511+
6512+
if (!isa<ClassDecl>(dc))
64716513
return true;
64726514

64736515
assert(isa<FuncDecl>(decl) || isa<ConstructorDecl>(decl));
@@ -6476,7 +6518,16 @@ static bool requiresNewVTableEntry(const AbstractFunctionDecl *decl) {
64766518
// Dynamic methods are always accessed by objc_msgSend().
64776519
if (decl->isFinal() || decl->isObjCDynamic() || decl->hasClangNode())
64786520
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+
64806531
// Initializers are not normally inherited, but required initializers can
64816532
// be overridden for invocation from dynamic types, and convenience initializers
64826533
// are conditionally inherited when all designated initializers are available,
@@ -6500,7 +6551,14 @@ static bool requiresNewVTableEntry(const AbstractFunctionDecl *decl) {
65006551

65016552
if (!base || base->hasClangNode() || base->isObjCDynamic())
65026553
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+
65046562
// As above, convenience initializers are not formally overridable in Swift
65056563
// vtables, although same-named initializers are modeled as overriding for
65066564
// various QoI and objc interop reasons. Even if we "override" a non-required

lib/SIL/TypeLowering.cpp

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,10 +1267,20 @@ namespace {
12671267
if (handleResilience(structType, D, properties))
12681268
return handleAddressOnly(structType, properties);
12691269

1270+
auto subMap = structType->getContextSubstitutionMap(
1271+
M.getSwiftModule(), D);
1272+
12701273
// Classify the type according to its stored properties.
12711274
for (auto field : D->getStoredProperties()) {
1275+
// FIXME: Remove this once getInterfaceType() is a request.
1276+
if (!field->hasInterfaceType())
1277+
M.getASTContext().getLazyResolver()->resolveDeclSignature(field);
1278+
12721279
auto substFieldType =
1273-
structType->getTypeOfMember(D->getModuleContext(), field, nullptr);
1280+
field->getInterfaceType()
1281+
.subst(subMap, SubstFlags::UseErrorType)
1282+
->getCanonicalType();
1283+
12741284
properties.addSubobject(classifyType(substFieldType->getCanonicalType(),
12751285
M, Sig, Expansion));
12761286
}
@@ -1297,6 +1307,9 @@ namespace {
12971307
Expansion);
12981308
}
12991309

1310+
auto subMap = enumType->getContextSubstitutionMap(
1311+
M.getSwiftModule(), D);
1312+
13001313
// Accumulate the properties of all direct payloads.
13011314
for (auto elt : D->getAllElements()) {
13021315
// No-payload elements do not affect any recursive properties.
@@ -1308,11 +1321,15 @@ namespace {
13081321
properties.setNonTrivial();
13091322
continue;
13101323
}
1311-
1312-
auto substEltType = enumType->getTypeOfMember(
1313-
D->getModuleContext(), elt,
1314-
elt->getArgumentInterfaceType())
1315-
->getCanonicalType();
1324+
1325+
// FIXME: Remove this once getInterfaceType() is a request.
1326+
if (!elt->hasInterfaceType())
1327+
M.getASTContext().getLazyResolver()->resolveDeclSignature(elt);
1328+
1329+
auto substEltType =
1330+
elt->getArgumentInterfaceType()
1331+
.subst(subMap, SubstFlags::UseErrorType)
1332+
->getCanonicalType();
13161333

13171334
properties.addSubobject(classifyType(substEltType, M, Sig, Expansion));
13181335
}
@@ -2591,6 +2608,10 @@ CanSILBoxType TypeConverter::getBoxTypeForEnumElement(SILType enumType,
25912608

25922609
auto &C = M.getASTContext();
25932610

2611+
// FIXME: Remove this once getInterfaceType() is a request.
2612+
if (!elt->hasInterfaceType())
2613+
C.getLazyResolver()->resolveDeclSignature(elt);
2614+
25942615
auto boxSignature = getEffectiveGenericSignature(enumDecl);
25952616

25962617
if (boxSignature == CanGenericSignature()) {
@@ -2655,12 +2676,15 @@ static void countNumberOfInnerFields(unsigned &fieldsCount, SILModule &Module,
26552676
unsigned fieldsCountBefore = fieldsCount;
26562677
unsigned maxEnumCount = 0;
26572678
for (auto elt : enumDecl->getAllElements()) {
2658-
if (!elt->getArgumentInterfaceType()) {
2679+
if (!elt->hasAssociatedValues())
26592680
continue;
2660-
}
2661-
if (elt->isIndirect()) {
2681+
2682+
if (elt->isIndirect())
26622683
continue;
2663-
}
2684+
2685+
if (!elt->hasInterfaceType())
2686+
enumDecl->getASTContext().getLazyResolver()->resolveDeclSignature(elt);
2687+
26642688
// Although one might assume enums have a fields count of 1
26652689
// Which holds true for current uses of this code
26662690
// (we shouldn't expand enums)

0 commit comments

Comments
 (0)