Skip to content

Commit 64c32c6

Browse files
committed
AST: Remove a few utility methods from AbstractStorageDecl
Since the return value of getAccessor() depends on mutable state, it does not make sense in the request evaluator world. Let's begin by removing some utility methods derived from getAccessor(), replacing calls to them with calls to getAccessor().
1 parent 3691944 commit 64c32c6

33 files changed

+191
-213
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4635,16 +4635,6 @@ class AbstractStorageDecl : public ValueDecl {
46354635
return SourceRange();
46364636
}
46374637

4638-
/// Retrieve the getter used to access the value of this variable.
4639-
AccessorDecl *getGetter() const {
4640-
return getAccessor(AccessorKind::Get);
4641-
}
4642-
4643-
/// Retrieve the setter used to mutate the value of this variable.
4644-
AccessorDecl *getSetter() const {
4645-
return getAccessor(AccessorKind::Set);
4646-
}
4647-
46484638
AccessLevel getSetterFormalAccess() const;
46494639

46504640
AccessScope
@@ -4658,45 +4648,6 @@ class AbstractStorageDecl : public ValueDecl {
46584648

46594649
void overwriteSetterAccess(AccessLevel accessLevel);
46604650

4661-
/// Return the decl for the immutable addressor if it exists.
4662-
AccessorDecl *getAddressor() const {
4663-
return getAccessor(AccessorKind::Address);
4664-
}
4665-
4666-
/// Return the decl for the mutable accessor if it exists.
4667-
AccessorDecl *getMutableAddressor() const {
4668-
return getAccessor(AccessorKind::MutableAddress);
4669-
}
4670-
4671-
/// Return the appropriate addressor for the given access kind.
4672-
AccessorDecl *getAddressorForAccess(AccessKind accessKind) const {
4673-
if (accessKind == AccessKind::Read)
4674-
return getAddressor();
4675-
return getMutableAddressor();
4676-
}
4677-
4678-
/// Return the decl for the 'read' coroutine accessor if it exists.
4679-
AccessorDecl *getReadCoroutine() const {
4680-
return getAccessor(AccessorKind::Read);
4681-
}
4682-
4683-
/// Return the decl for the 'modify' coroutine accessor if it exists.
4684-
AccessorDecl *getModifyCoroutine() const {
4685-
return getAccessor(AccessorKind::Modify);
4686-
}
4687-
4688-
/// Return the decl for the willSet specifier if it exists, this is
4689-
/// only valid on a declaration with Observing storage.
4690-
AccessorDecl *getWillSetFunc() const {
4691-
return getAccessor(AccessorKind::WillSet);
4692-
}
4693-
4694-
/// Return the decl for the didSet specifier if it exists, this is
4695-
/// only valid on a declaration with Observing storage.
4696-
AccessorDecl *getDidSetFunc() const {
4697-
return getAccessor(AccessorKind::DidSet);
4698-
}
4699-
47004651
/// Given that this is an Objective-C property or subscript declaration,
47014652
/// produce its getter selector.
47024653
ObjCSelector
@@ -7111,11 +7062,11 @@ inline bool AbstractStorageDecl::isSettable(const DeclContext *UseDC,
71117062
inline void
71127063
AbstractStorageDecl::overwriteSetterAccess(AccessLevel accessLevel) {
71137064
Accessors.setInt(accessLevel);
7114-
if (auto setter = getSetter())
7065+
if (auto setter = getAccessor(AccessorKind::Set))
71157066
setter->overwriteAccess(accessLevel);
7116-
if (auto modify = getModifyCoroutine())
7067+
if (auto modify = getAccessor(AccessorKind::Modify))
71177068
modify->overwriteAccess(accessLevel);
7118-
if (auto mutableAddressor = getMutableAddressor())
7069+
if (auto mutableAddressor = getAccessor(AccessorKind::MutableAddress))
71197070
mutableAddressor->overwriteAccess(accessLevel);
71207071
}
71217072

lib/AST/ASTPrinter.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
628628
llvm::is_contained(Options.ExcludeAttrList, DAK_SetterAccess);
629629

630630
if (auto storageDecl = dyn_cast<AbstractStorageDecl>(D)) {
631-
if (auto setter = storageDecl->getSetter()) {
631+
if (auto setter = storageDecl->getAccessor(AccessorKind::Set)) {
632632
AccessLevel setterAccess = setter->getFormalAccess();
633633
if (setterAccess != D->getFormalAccess() && !shouldSkipSetterAccess)
634634
printAccess(setterAccess, "(set)");
@@ -895,12 +895,12 @@ static StaticSpellingKind getCorrectStaticSpelling(const Decl *D) {
895895
}
896896

897897
static bool hasMutatingGetter(const AbstractStorageDecl *ASD) {
898-
return ASD->getGetter() && ASD->isGetterMutating();
898+
return ASD->getAccessor(AccessorKind::Get) && ASD->isGetterMutating();
899899
}
900900

901901
static bool hasNonMutatingSetter(const AbstractStorageDecl *ASD) {
902902
if (!ASD->isSettable(nullptr)) return false;
903-
auto setter = ASD->getSetter();
903+
auto setter = ASD->getAccessor(AccessorKind::Set);
904904
return setter && setter->isExplicitNonMutating();
905905
}
906906

@@ -1804,8 +1804,8 @@ void PrintAST::printAccessors(const AbstractStorageDecl *ASD) {
18041804
if ((PrintAbstract || isGetSetImpl()) &&
18051805
!Options.PrintGetSetOnRWProperties &&
18061806
!Options.FunctionDefinitions &&
1807-
!ASD->getGetter()->isMutating() &&
1808-
!ASD->getSetter()->isExplicitNonMutating()) {
1807+
!ASD->getAccessor(AccessorKind::Get)->isMutating() &&
1808+
!ASD->getAccessor(AccessorKind::Set)->isExplicitNonMutating()) {
18091809
return;
18101810
}
18111811

@@ -1814,7 +1814,8 @@ void PrintAST::printAccessors(const AbstractStorageDecl *ASD) {
18141814

18151815
// Helper to print an accessor. Returns true if the
18161816
// accessor was present but skipped.
1817-
auto PrintAccessor = [&](AccessorDecl *Accessor) -> bool {
1817+
auto PrintAccessor = [&](AccessorKind Kind) -> bool {
1818+
auto *Accessor = ASD->getAccessor(Kind);
18181819
if (!Accessor || !shouldPrint(Accessor))
18191820
return true;
18201821
if (!PrintAccessorBody) {
@@ -1836,11 +1837,11 @@ void PrintAST::printAccessors(const AbstractStorageDecl *ASD) {
18361837
// Determine if we should print the getter without the 'get { ... }'
18371838
// block around it.
18381839
bool isOnlyGetter = impl.getReadImpl() == ReadImplKind::Get &&
1839-
ASD->getGetter();
1840+
ASD->getAccessor(AccessorKind::Get);
18401841
bool isGetterMutating = ASD->supportsMutation() || ASD->isGetterMutating();
18411842
if (isOnlyGetter && !isGetterMutating && PrintAccessorBody &&
18421843
Options.FunctionBody && Options.CollapseSingleGetterProperty) {
1843-
Options.FunctionBody(ASD->getGetter(), Printer);
1844+
Options.FunctionBody(ASD->getAccessor(AccessorKind::Get), Printer);
18441845
indent();
18451846
return;
18461847
}
@@ -1851,22 +1852,22 @@ void PrintAST::printAccessors(const AbstractStorageDecl *ASD) {
18511852
Printer.printNewline();
18521853

18531854
if (PrintAbstract) {
1854-
PrintAccessor(ASD->getGetter());
1855+
PrintAccessor(AccessorKind::Get);
18551856
if (ASD->supportsMutation())
1856-
PrintAccessor(ASD->getSetter());
1857+
PrintAccessor(AccessorKind::Set);
18571858
} else {
18581859
switch (impl.getReadImpl()) {
18591860
case ReadImplKind::Stored:
18601861
case ReadImplKind::Inherited:
18611862
break;
18621863
case ReadImplKind::Get:
1863-
PrintAccessor(ASD->getGetter());
1864+
PrintAccessor(AccessorKind::Get);
18641865
break;
18651866
case ReadImplKind::Address:
1866-
PrintAccessor(ASD->getAddressor());
1867+
PrintAccessor(AccessorKind::Address);
18671868
break;
18681869
case ReadImplKind::Read:
1869-
PrintAccessor(ASD->getReadCoroutine());
1870+
PrintAccessor(AccessorKind::Read);
18701871
break;
18711872
}
18721873
switch (impl.getWriteImpl()) {
@@ -1876,22 +1877,22 @@ void PrintAST::printAccessors(const AbstractStorageDecl *ASD) {
18761877
llvm_unreachable("simply-stored variable should have been filtered out");
18771878
case WriteImplKind::StoredWithObservers:
18781879
case WriteImplKind::InheritedWithObservers: {
1879-
PrintAccessor(ASD->getGetter());
1880-
PrintAccessor(ASD->getSetter());
1880+
PrintAccessor(AccessorKind::Get);
1881+
PrintAccessor(AccessorKind::Set);
18811882
break;
18821883
}
18831884
case WriteImplKind::Set:
1884-
PrintAccessor(ASD->getSetter());
1885+
PrintAccessor(AccessorKind::Set);
18851886
if (!shouldHideModifyAccessor())
1886-
PrintAccessor(ASD->getModifyCoroutine());
1887+
PrintAccessor(AccessorKind::Modify);
18871888
break;
18881889
case WriteImplKind::MutableAddress:
1889-
PrintAccessor(ASD->getMutableAddressor());
1890-
PrintAccessor(ASD->getWillSetFunc());
1891-
PrintAccessor(ASD->getDidSetFunc());
1890+
PrintAccessor(AccessorKind::MutableAddress);
1891+
PrintAccessor(AccessorKind::WillSet);
1892+
PrintAccessor(AccessorKind::DidSet);
18921893
break;
18931894
case WriteImplKind::Modify:
1894-
PrintAccessor(ASD->getModifyCoroutine());
1895+
PrintAccessor(AccessorKind::Modify);
18951896
break;
18961897
}
18971898
}

lib/AST/ASTScopeCreation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ void SubscriptDeclScope::expandAScopeThatDoesNotCreateANewInsertionPoint(
856856
auto *leaf =
857857
scopeCreator.createGenericParamScopes(sub, sub->getGenericParams(), this);
858858
auto *params = scopeCreator.createSubtree<AbstractFunctionParamsScope>(
859-
leaf, sub->getIndices(), sub->getGetter());
859+
leaf, sub->getIndices(), sub->getAccessor(AccessorKind::Get));
860860
scopeCreator.addChildrenForAllExplicitAccessors(sub, params);
861861
}
862862

lib/AST/ASTVerifier.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2390,50 +2390,50 @@ class Verifier : public ASTWalker {
23902390
void verifyChecked(AbstractStorageDecl *ASD) {
23912391
if (ASD->hasAccess() && ASD->isSettable(nullptr)) {
23922392
auto setterAccess = ASD->getSetterFormalAccess();
2393-
if (ASD->getSetter() &&
2394-
ASD->getSetter()->getFormalAccess() != setterAccess) {
2393+
auto *setter = ASD->getAccessor(AccessorKind::Set);
2394+
if (setter && setter->getFormalAccess() != setterAccess) {
23952395
Out << "AbstractStorageDecl's setter access is out of sync"
23962396
" with the access actually on the setter\n";
23972397
abort();
23982398
}
23992399
}
24002400

2401-
if (auto getter = ASD->getGetter()) {
2401+
if (auto getter = ASD->getAccessor(AccessorKind::Get)) {
24022402
if (getter->isMutating() != ASD->isGetterMutating()) {
24032403
Out << "AbstractStorageDecl::isGetterMutating is out of sync"
24042404
" with whether the getter is actually mutating\n";
24052405
abort();
24062406
}
24072407
}
2408-
if (auto setter = ASD->getSetter()) {
2408+
if (auto setter = ASD->getAccessor(AccessorKind::Set)) {
24092409
if (setter->isMutating() != ASD->isSetterMutating()) {
24102410
Out << "AbstractStorageDecl::isSetterMutating is out of sync"
24112411
" with whether the setter is actually mutating\n";
24122412
abort();
24132413
}
24142414
}
2415-
if (auto addressor = ASD->getAddressor()) {
2415+
if (auto addressor = ASD->getAccessor(AccessorKind::Address)) {
24162416
if (addressor->isMutating() != ASD->isGetterMutating()) {
24172417
Out << "AbstractStorageDecl::isGetterMutating is out of sync"
24182418
" with whether immutable addressor is mutating";
24192419
abort();
24202420
}
24212421
}
2422-
if (auto reader = ASD->getReadCoroutine()) {
2422+
if (auto reader = ASD->getAccessor(AccessorKind::Read)) {
24232423
if (reader->isMutating() != ASD->isGetterMutating()) {
24242424
Out << "AbstractStorageDecl::isGetterMutating is out of sync"
24252425
" with whether read accessor is mutating";
24262426
abort();
24272427
}
24282428
}
2429-
if (auto addressor = ASD->getMutableAddressor()) {
2429+
if (auto addressor = ASD->getAccessor(AccessorKind::MutableAddress)) {
24302430
if (addressor->isMutating() != ASD->isSetterMutating()) {
24312431
Out << "AbstractStorageDecl::isSetterMutating is out of sync"
24322432
" with whether mutable addressor is mutating";
24332433
abort();
24342434
}
24352435
}
2436-
if (auto modifier = ASD->getModifyCoroutine()) {
2436+
if (auto modifier = ASD->getAccessor(AccessorKind::Modify)) {
24372437
if (modifier->isMutating() !=
24382438
(ASD->isSetterMutating() || ASD->isGetterMutating())) {
24392439
Out << "AbstractStorageDecl::isSetterMutating is out of sync"
@@ -2475,7 +2475,7 @@ class Verifier : public ASTWalker {
24752475
if (!var->getDeclContext()->contextHasLazyGenericEnvironment()) {
24762476
typeForAccessors =
24772477
var->getDeclContext()->mapTypeIntoContext(typeForAccessors);
2478-
if (const FuncDecl *getter = var->getGetter()) {
2478+
if (const FuncDecl *getter = var->getAccessor(AccessorKind::Get)) {
24792479
if (getter->getParameters()->size() != 0) {
24802480
Out << "property getter has parameters\n";
24812481
abort();
@@ -2496,7 +2496,7 @@ class Verifier : public ASTWalker {
24962496
}
24972497
}
24982498

2499-
if (const FuncDecl *setter = var->getSetter()) {
2499+
if (const FuncDecl *setter = var->getAccessor(AccessorKind::Set)) {
25002500
if (setter->hasInterfaceType()) {
25012501
if (!setter->getResultInterfaceType()->isVoid()) {
25022502
Out << "property setter has non-Void result type\n";

lib/AST/AccessRequests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ static bool isStoredWithPrivateSetter(VarDecl *VD) {
161161
return false;
162162

163163
if (VD->isLet() ||
164-
(VD->getSetter() &&
165-
!VD->getSetter()->isImplicit()))
164+
(VD->getAccessor(AccessorKind::Set) &&
165+
!VD->getAccessor(AccessorKind::Set)->isImplicit()))
166166
return false;
167167

168168
return true;

lib/AST/Decl.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4651,9 +4651,9 @@ bool AbstractStorageDecl::hasPrivateAccessor() const {
46514651
}
46524652

46534653
bool AbstractStorageDecl::hasDidSetOrWillSetDynamicReplacement() const {
4654-
if (auto *func = getDidSetFunc())
4654+
if (auto *func = getAccessor(AccessorKind::DidSet))
46554655
return func->getAttrs().hasAttribute<DynamicReplacementAttr>();
4656-
if (auto *func = getWillSetFunc())
4656+
if (auto *func = getAccessor(AccessorKind::WillSet))
46574657
return func->getAttrs().hasAttribute<DynamicReplacementAttr>();
46584658
return false;
46594659
}
@@ -4809,8 +4809,8 @@ AbstractStorageDecl::getSetterFormalAccessScope(const DeclContext *useDC,
48094809
void AbstractStorageDecl::setComputedSetter(AccessorDecl *setter) {
48104810
assert(getImplInfo().getReadImpl() == ReadImplKind::Get);
48114811
assert(!getImplInfo().supportsMutation());
4812-
assert(getGetter() && "invariant check: missing getter");
4813-
assert(!getSetter() && "already has a setter");
4812+
assert(getAccessor(AccessorKind::Get) && "invariant check: missing getter");
4813+
assert(!getAccessor(AccessorKind::Set) && "already has a setter");
48144814
assert(hasClangNode() && "should only be used for ObjC properties");
48154815
assert(setter && "should not be called for readonly properties");
48164816
assert(setter->getAccessorKind() == AccessorKind::Set);
@@ -4855,7 +4855,7 @@ getNameFromObjcAttribute(const ObjCAttr *attr, DeclName preferredName) {
48554855
ObjCSelector
48564856
AbstractStorageDecl::getObjCGetterSelector(Identifier preferredName) const {
48574857
// If the getter has an @objc attribute with a name, use that.
4858-
if (auto getter = getGetter()) {
4858+
if (auto getter = getAccessor(AccessorKind::Get)) {
48594859
if (auto name = getNameFromObjcAttribute(getter->getAttrs().
48604860
getAttribute<ObjCAttr>(), preferredName))
48614861
return *name;
@@ -4885,7 +4885,7 @@ AbstractStorageDecl::getObjCGetterSelector(Identifier preferredName) const {
48854885
ObjCSelector
48864886
AbstractStorageDecl::getObjCSetterSelector(Identifier preferredName) const {
48874887
// If the setter has an @objc attribute with a name, use that.
4888-
auto setter = getSetter();
4888+
auto setter = getAccessor(AccessorKind::Set);
48894889
auto objcAttr = setter ? setter->getAttrs().getAttribute<ObjCAttr>()
48904890
: nullptr;
48914891
if (auto name = getNameFromObjcAttribute(objcAttr, DeclName(preferredName))) {

lib/AST/SwiftNameTranslation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ getObjCNameForSwiftDecl(const ValueDecl *VD, DeclName PreferredName){
114114
return {BaseName, ObjCSelector()};
115115
return {VAD->getObjCPropertyName(), ObjCSelector()};
116116
} else if (auto *SD = dyn_cast<SubscriptDecl>(VD)) {
117-
return getObjCNameForSwiftDecl(SD->getGetter(), PreferredName);
117+
return getObjCNameForSwiftDecl(SD->getAccessor(AccessorKind::Get),
118+
PreferredName);
118119
} else if (auto *EL = dyn_cast<EnumElementDecl>(VD)) {
119120
SmallString<64> Buffer;
120121
{

lib/AST/Type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2556,7 +2556,7 @@ bool ReplaceOpaqueTypesWithUnderlyingTypes::shouldPerformSubstitution(
25562556
return true;
25572557
}
25582558
} else if (auto *asd = dyn_cast<AbstractStorageDecl>(namingDecl)) {
2559-
auto *getter = asd->getGetter();
2559+
auto *getter = asd->getAccessor(AccessorKind::Get);
25602560
if (getter &&
25612561
getter->getResilienceExpansion() == ResilienceExpansion::Minimal) {
25622562
return true;

lib/ClangImporter/ImportDecl.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3627,13 +3627,13 @@ namespace {
36273627
case ImportedAccessorKind::PropertyGetter: {
36283628
auto property = getImplicitProperty(importedName, decl);
36293629
if (!property) return nullptr;
3630-
return property->getGetter();
3630+
return property->getAccessor(AccessorKind::Get);
36313631
}
36323632

36333633
case ImportedAccessorKind::PropertySetter:
36343634
auto property = getImplicitProperty(importedName, decl);
36353635
if (!property) return nullptr;
3636-
return property->getSetter();
3636+
return property->getAccessor(AccessorKind::Set);
36373637
}
36383638

36393639
return importFunctionDecl(decl, importedName, correctSwiftName, None);
@@ -5008,8 +5008,8 @@ namespace {
50085008
// Only record overrides of class members.
50095009
if (overridden) {
50105010
result->setOverriddenDecl(overridden);
5011-
getter->setOverriddenDecl(overridden->getGetter());
5012-
if (auto parentSetter = overridden->getSetter())
5011+
getter->setOverriddenDecl(overridden->getAccessor(AccessorKind::Get));
5012+
if (auto parentSetter = overridden->getAccessor(AccessorKind::Set))
50135013
if (setter)
50145014
setter->setOverriddenDecl(parentSetter);
50155015
}
@@ -6514,10 +6514,10 @@ void SwiftDeclConverter::recordObjCOverride(SubscriptDecl *subscript) {
65146514

65156515
// The index types match. This is an override, so mark it as such.
65166516
subscript->setOverriddenDecl(parentSub);
6517-
auto getterThunk = subscript->getGetter();
6518-
getterThunk->setOverriddenDecl(parentSub->getGetter());
6519-
if (auto parentSetter = parentSub->getSetter()) {
6520-
if (auto setterThunk = subscript->getSetter())
6517+
auto getterThunk = subscript->getAccessor(AccessorKind::Get);
6518+
getterThunk->setOverriddenDecl(parentSub->getAccessor(AccessorKind::Get));
6519+
if (auto parentSetter = parentSub->getAccessor(AccessorKind::Set)) {
6520+
if (auto setterThunk = subscript->getAccessor(AccessorKind::Set))
65216521
setterThunk->setOverriddenDecl(parentSetter);
65226522
}
65236523

0 commit comments

Comments
 (0)