Skip to content

Commit 933ae8d

Browse files
authored
Merge pull request swiftlang#26446 from slavapestov/cleanup-for-lazy-accessors
Cleanup in preparation for lazy accessors
2 parents a892f8a + 04e9a7c commit 933ae8d

19 files changed

+84
-73
lines changed

include/swift/AST/Decl.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2588,12 +2588,6 @@ class ValueDecl : public Decl {
25882588
void setInterfaceType(Type type);
25892589

25902590
bool hasValidSignature() const;
2591-
2592-
/// isSettable - Determine whether references to this decl may appear
2593-
/// on the left-hand side of an assignment or as the operand of a
2594-
/// `&` or 'inout' operator.
2595-
bool isSettable(const DeclContext *UseDC,
2596-
const DeclRefExpr *base = nullptr) const;
25972591

25982592
/// isInstanceMember - Determine whether this value is an instance member
25992593
/// of an enum or protocol.
@@ -4546,6 +4540,12 @@ class AbstractStorageDecl : public ValueDecl {
45464540
return getImplInfo().supportsMutation();
45474541
}
45484542

4543+
/// isSettable - Determine whether references to this decl may appear
4544+
/// on the left-hand side of an assignment or as the operand of a
4545+
/// `&` or 'inout' operator.
4546+
bool isSettable(const DeclContext *UseDC,
4547+
const DeclRefExpr *base = nullptr) const;
4548+
45494549
/// Are there any accessors for this declaration, including implicit ones?
45504550
bool hasAnyAccessors() const {
45514551
return !getAllAccessors().empty();
@@ -4647,6 +4647,10 @@ class AbstractStorageDecl : public ValueDecl {
46474647

46484648
AccessLevel getSetterFormalAccess() const;
46494649

4650+
AccessScope
4651+
getSetterFormalAccessScope(const DeclContext *useDC = nullptr,
4652+
bool treatUsableFromInlineAsPublic = false) const;
4653+
46504654
void setSetterAccess(AccessLevel accessLevel) {
46514655
assert(!Accessors.getInt().hasValue());
46524656
overwriteSetterAccess(accessLevel);
@@ -5485,9 +5489,6 @@ class SubscriptDecl : public GenericContext, public AbstractStorageDecl {
54855489
/// element types.
54865490
void computeType();
54875491

5488-
/// Returns whether the result of the subscript operation can be set.
5489-
bool isSettable() const;
5490-
54915492
/// Determine the kind of Objective-C subscripting this declaration
54925493
/// implies.
54935494
ObjCSubscriptKind getObjCSubscriptKind() const;
@@ -7098,14 +7099,13 @@ class MissingMemberDecl : public Decl {
70987099
}
70997100
};
71007101

7101-
inline bool ValueDecl::isSettable(const DeclContext *UseDC,
7102-
const DeclRefExpr *base) const {
7103-
if (auto vd = dyn_cast<VarDecl>(this)) {
7102+
inline bool AbstractStorageDecl::isSettable(const DeclContext *UseDC,
7103+
const DeclRefExpr *base) const {
7104+
if (auto vd = dyn_cast<VarDecl>(this))
71047105
return vd->isSettable(UseDC, base);
7105-
} else if (auto sd = dyn_cast<SubscriptDecl>(this)) {
7106-
return sd->isSettable();
7107-
} else
7108-
return false;
7106+
7107+
auto sd = cast<SubscriptDecl>(this);
7108+
return sd->supportsMutation();
71097109
}
71107110

71117111
inline void

lib/AST/Decl.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4799,6 +4799,13 @@ AbstractStorageDecl::getSetterFormalAccess() const {
47994799
AccessLevel::Private);
48004800
}
48014801

4802+
AccessScope
4803+
AbstractStorageDecl::getSetterFormalAccessScope(const DeclContext *useDC,
4804+
bool treatUsableFromInlineAsPublic) const {
4805+
return getAccessScopeForFormalAccess(this, getSetterFormalAccess(), useDC,
4806+
treatUsableFromInlineAsPublic);
4807+
}
4808+
48024809
void AbstractStorageDecl::setComputedSetter(AccessorDecl *setter) {
48034810
assert(getImplInfo().getReadImpl() == ReadImplKind::Get);
48044811
assert(!getImplInfo().supportsMutation());
@@ -5055,10 +5062,6 @@ bool VarDecl::isLazilyInitializedGlobal() const {
50555062
return !sourceFileContext->isScriptMode();
50565063
}
50575064

5058-
bool SubscriptDecl::isSettable() const {
5059-
return supportsMutation();
5060-
}
5061-
50625065
SourceRange VarDecl::getSourceRange() const {
50635066
if (auto Param = dyn_cast<ParamDecl>(this))
50645067
return Param->getSourceRange();

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6694,7 +6694,7 @@ SwiftDeclConverter::importSubscript(Decl *decl,
66946694
if (setter && existingSubscript && getterAndSetterInSameType) {
66956695
// Can we update the subscript by adding the setter?
66966696
if (existingSubscript->hasClangNode() &&
6697-
!existingSubscript->isSettable()) {
6697+
!existingSubscript->supportsMutation()) {
66986698
// Create the setter thunk.
66996699
auto setterThunk = buildSubscriptSetterDecl(
67006700
Impl, existingSubscript, setter, elementTy,

lib/IRGen/GenClass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/AST/AttrKind.h"
2323
#include "swift/AST/Decl.h"
2424
#include "swift/AST/IRGenOptions.h"
25+
#include "swift/AST/LazyResolver.h"
2526
#include "swift/AST/Module.h"
2627
#include "swift/AST/Pattern.h"
2728
#include "swift/AST/PrettyStackTrace.h"
@@ -297,6 +298,9 @@ namespace {
297298
SILType classType,
298299
bool superclass) {
299300
for (VarDecl *var : theClass->getStoredProperties()) {
301+
if (!var->hasInterfaceType())
302+
IGM.Context.getLazyResolver()->resolveDeclSignature(var);
303+
300304
SILType type = classType.getFieldType(var, IGM.getSILModule());
301305

302306
// Lower the field type.

lib/IRGen/GenDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class CategoryInitializerVisitor
242242
llvm::Value *getterArgs[] = {classMetadata, sel, imp, types};
243243
Builder.CreateCall(class_replaceMethod, getterArgs);
244244

245-
if (subscript->isSettable()) {
245+
if (subscript->supportsMutation()) {
246246
emitObjCSetterDescriptorParts(IGM, subscript,
247247
name, types, imp);
248248
sel = Builder.CreateCall(IGM.getObjCSelRegisterNameFn(),

lib/IRGen/GenObjC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ SILFunction *irgen::emitObjCSetterDescriptorParts(IRGenModule &IGM,
12421242
llvm::Constant *&selectorRef,
12431243
llvm::Constant *&atEncoding,
12441244
llvm::Constant *&impl) {
1245-
assert(subscript->isSettable() && "not a settable subscript?!");
1245+
assert(subscript->supportsMutation() && "not a settable subscript?!");
12461246

12471247
Selector setterSel(subscript, Selector::ForSetter);
12481248
selectorRef = IGM.getAddrOfObjCMethodName(setterSel.str());

lib/SIL/SILVerifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4944,8 +4944,8 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
49444944
if (F->hasForeignBody())
49454945
return;
49464946

4947-
assert(F->isAvailableExternally() &&
4948-
"external declaration of internal SILFunction not allowed");
4947+
require(F->isAvailableExternally(),
4948+
"external declaration of internal SILFunction not allowed");
49494949
// If F is an external declaration, there is nothing further to do,
49504950
// return.
49514951
return;

lib/SILGen/SILGen.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,14 +613,14 @@ static bool isEmittedOnDemand(SILModule &M, SILDeclRef constant) {
613613
if (isa<ClangModuleUnit>(dc))
614614
return true;
615615

616-
if (auto *sf = dyn_cast<SourceFile>(dc))
617-
if (M.isWholeModule() || M.getAssociatedContext() == dc)
618-
return false;
619-
620616
if (auto *func = dyn_cast<FuncDecl>(d))
621617
if (func->hasForcedStaticDispatch())
622618
return true;
623619

620+
if (auto *sf = dyn_cast<SourceFile>(dc))
621+
if (M.isWholeModule() || M.getAssociatedContext() == dc)
622+
return false;
623+
624624
return false;
625625
}
626626

lib/SILGen/SILGenProlog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ static void emitCaptureArguments(SILGenFunction &SGF,
342342
CapturedValue capture,
343343
uint16_t ArgNo) {
344344

345-
auto *VD = capture.getDecl();
345+
auto *VD = cast<VarDecl>(capture.getDecl());
346346
SILLocation Loc(VD);
347347
Loc.markAsPrologue();
348348

lib/SILGen/SILGenType.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,8 @@ class SILGenType : public TypeMemberVisitor<SILGenType> {
10501050

10511051
void visitAccessors(AbstractStorageDecl *asd) {
10521052
for (auto *accessor : asd->getAllAccessors())
1053-
visitFuncDecl(accessor);
1053+
if (!accessor->hasForcedStaticDispatch())
1054+
visitFuncDecl(accessor);
10541055
}
10551056
};
10561057

@@ -1180,7 +1181,8 @@ class SILGenExtension : public TypeMemberVisitor<SILGenExtension> {
11801181

11811182
void visitAccessors(AbstractStorageDecl *asd) {
11821183
for (auto *accessor : asd->getAllAccessors())
1183-
visitFuncDecl(accessor);
1184+
if (!accessor->hasForcedStaticDispatch())
1185+
visitFuncDecl(accessor);
11841186
}
11851187
};
11861188

0 commit comments

Comments
 (0)