Skip to content

Commit c77784e

Browse files
committed
Sema: Remove TypeChecker parameter from mutating accessor computation
I'm about to convert this into requests, and we don't actually need the TypeChecker for anything.
1 parent ea84da3 commit c77784e

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1957,7 +1957,7 @@ static bool doesContextHaveValueSemantics(DeclContext *dc) {
19571957
return false;
19581958
}
19591959

1960-
static void validateSelfAccessKind(TypeChecker &TC, FuncDecl *FD) {
1960+
static void validateSelfAccessKind(FuncDecl *FD) {
19611961
// Validate the mutating attribute if present, and install it into the bit
19621962
// on funcdecl (instead of just being a DeclAttribute).
19631963
if (FD->getAttrs().hasAttribute<MutatingAttr>())
@@ -1972,7 +1972,8 @@ static void validateSelfAccessKind(TypeChecker &TC, FuncDecl *FD) {
19721972
accessor->getAccessorKind() == AccessorKind::DidSet ||
19731973
accessor->getAccessorKind() == AccessorKind::WillSet) {
19741974
auto storage = accessor->getStorage();
1975-
TC.validateDecl(storage);
1975+
if (auto *resolver = FD->getASTContext().getLazyResolver())
1976+
resolver->resolveDeclSignature(storage);
19761977
if (accessor->getAccessorKind() == AccessorKind::Get) {
19771978
FD->setSelfAccessKind(storage->isGetterMutating()
19781979
? SelfAccessKind::Mutating
@@ -1992,14 +1993,13 @@ static void validateSelfAccessKind(TypeChecker &TC, FuncDecl *FD) {
19921993
}
19931994
}
19941995

1995-
static bool validateAccessorIsMutating(TypeChecker &TC, FuncDecl *accessor) {
1996+
static bool validateAccessorIsMutating(FuncDecl *accessor) {
19961997
assert(accessor && "accessor not present!");
1997-
validateSelfAccessKind(TC, accessor);
1998+
validateSelfAccessKind(accessor);
19981999
return accessor->isMutating();
19992000
}
20002001

2001-
static bool computeIsGetterMutating(TypeChecker &TC,
2002-
AbstractStorageDecl *storage) {
2002+
static bool computeIsGetterMutating(AbstractStorageDecl *storage) {
20032003
// 'lazy' overrides the normal accessor-based rules and heavily
20042004
// restricts what accessors can be used. The getter is considered
20052005
// mutating if this is instance storage on a value type.
@@ -2016,7 +2016,10 @@ static bool computeIsGetterMutating(TypeChecker &TC,
20162016
if (auto wrapperInfo = var->getAttachedPropertyWrapperTypeInfo(0)) {
20172017
if (wrapperInfo.valueVar &&
20182018
(!storage->getGetter() || storage->getGetter()->isImplicit())) {
2019-
TC.validateDecl(wrapperInfo.valueVar);
2019+
// FIXME: Remove this once we request-ify isSetterMutating()
2020+
auto *resolver = storage->getASTContext().getLazyResolver();
2021+
if (resolver)
2022+
resolver->resolveDeclSignature(wrapperInfo.valueVar);
20202023
return wrapperInfo.valueVar->isGetterMutating() &&
20212024
var->isInstanceMember() &&
20222025
doesContextHaveValueSemantics(var->getDeclContext());
@@ -2033,28 +2036,30 @@ static bool computeIsGetterMutating(TypeChecker &TC,
20332036
if (!storage->getGetter())
20342037
return false;
20352038

2036-
return validateAccessorIsMutating(TC, storage->getGetter());
2039+
return validateAccessorIsMutating(storage->getGetter());
20372040

20382041
case ReadImplKind::Address:
2039-
return validateAccessorIsMutating(TC, storage->getAddressor());
2042+
return validateAccessorIsMutating(storage->getAddressor());
20402043

20412044
case ReadImplKind::Read:
2042-
return validateAccessorIsMutating(TC, storage->getReadCoroutine());
2045+
return validateAccessorIsMutating(storage->getReadCoroutine());
20432046
}
20442047

20452048
llvm_unreachable("bad impl kind");
20462049
}
20472050

2048-
static bool computeIsSetterMutating(TypeChecker &TC,
2049-
AbstractStorageDecl *storage) {
2051+
static bool computeIsSetterMutating(AbstractStorageDecl *storage) {
20502052
// If we have an attached property wrapper, the setter is mutating if
20512053
// the "value" property of the outermost wrapper type is mutating and we're
20522054
// in a context that has value semantics.
20532055
if (auto var = dyn_cast<VarDecl>(storage)) {
20542056
if (auto wrapperInfo = var->getAttachedPropertyWrapperTypeInfo(0)) {
20552057
if (wrapperInfo.valueVar &&
20562058
(!storage->getSetter() || storage->getSetter()->isImplicit())) {
2057-
TC.validateDecl(wrapperInfo.valueVar);
2059+
// FIXME: Remove this once we request-ify isSetterMutating()
2060+
auto *resolver = storage->getASTContext().getLazyResolver();
2061+
if (resolver)
2062+
resolver->resolveDeclSignature(wrapperInfo.valueVar);
20582063
return wrapperInfo.valueVar->isSetterMutating() &&
20592064
var->isInstanceMember() &&
20602065
doesContextHaveValueSemantics(var->getDeclContext());
@@ -2083,24 +2088,24 @@ static bool computeIsSetterMutating(TypeChecker &TC,
20832088
auto *setter = storage->getSetter();
20842089

20852090
if (setter)
2086-
result = validateAccessorIsMutating(TC, setter);
2091+
result = validateAccessorIsMutating(setter);
20872092

20882093
// As a special extra check, if the user also gave us a modify
20892094
// coroutine, check that it has the same mutatingness as the setter.
20902095
// TODO: arguably this should require the spelling to match even when
20912096
// it's the implied value.
20922097
if (impl.getReadWriteImpl() == ReadWriteImplKind::Modify) {
20932098
auto modifyAccessor = storage->getModifyCoroutine();
2094-
auto modifyResult = validateAccessorIsMutating(TC, modifyAccessor);
2099+
auto modifyResult = validateAccessorIsMutating(modifyAccessor);
20952100
if ((result || storage->isGetterMutating()) != modifyResult) {
2096-
TC.diagnose(modifyAccessor,
2097-
diag::modify_mutatingness_differs_from_setter,
2098-
modifyResult ? SelfAccessKind::Mutating
2099-
: SelfAccessKind::NonMutating,
2100-
modifyResult ? SelfAccessKind::NonMutating
2101-
: SelfAccessKind::Mutating);
2101+
modifyAccessor->diagnose(
2102+
diag::modify_mutatingness_differs_from_setter,
2103+
modifyResult ? SelfAccessKind::Mutating
2104+
: SelfAccessKind::NonMutating,
2105+
modifyResult ? SelfAccessKind::NonMutating
2106+
: SelfAccessKind::Mutating);
21022107
if (setter)
2103-
TC.diagnose(setter, diag::previous_accessor, "setter", 0);
2108+
setter->diagnose(diag::previous_accessor, "setter", 0);
21042109
modifyAccessor->setInvalid();
21052110
}
21062111
}
@@ -2109,16 +2114,15 @@ static bool computeIsSetterMutating(TypeChecker &TC,
21092114
}
21102115

21112116
case WriteImplKind::MutableAddress:
2112-
return validateAccessorIsMutating(TC, storage->getMutableAddressor());
2117+
return validateAccessorIsMutating(storage->getMutableAddressor());
21132118

21142119
case WriteImplKind::Modify:
2115-
return validateAccessorIsMutating(TC, storage->getModifyCoroutine());
2120+
return validateAccessorIsMutating(storage->getModifyCoroutine());
21162121
}
21172122
llvm_unreachable("bad storage kind");
21182123
}
21192124

2120-
static bool shouldUseOpaqueReadAccessor(TypeChecker &TC,
2121-
AbstractStorageDecl *storage) {
2125+
static bool shouldUseOpaqueReadAccessor(AbstractStorageDecl *storage) {
21222126
return storage->getAttrs().hasAttribute<BorrowedAttr>();
21232127
}
21242128

@@ -2130,13 +2134,13 @@ static void validateAbstractStorageDecl(TypeChecker &TC,
21302134
}
21312135
}
21322136

2133-
if (shouldUseOpaqueReadAccessor(TC, storage))
2137+
if (shouldUseOpaqueReadAccessor(storage))
21342138
storage->setOpaqueReadOwnership(OpaqueReadOwnership::Borrowed);
21352139

21362140
// isGetterMutating and isSetterMutating are part of the signature
21372141
// of a storage declaration and need to be validated immediately.
2138-
storage->setIsGetterMutating(computeIsGetterMutating(TC, storage));
2139-
storage->setIsSetterMutating(computeIsSetterMutating(TC, storage));
2142+
storage->setIsGetterMutating(computeIsGetterMutating(storage));
2143+
storage->setIsSetterMutating(computeIsSetterMutating(storage));
21402144

21412145
// Everything else about the accessors can wait until finalization.
21422146
// This will validate all the accessors.
@@ -3981,7 +3985,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
39813985
}
39823986
}
39833987

3984-
validateSelfAccessKind(*this, FD);
3988+
validateSelfAccessKind(FD);
39853989

39863990
// Check whether the return type is dynamic 'Self'.
39873991
FD->setDynamicSelf(checkDynamicSelfReturn(FD));

0 commit comments

Comments
 (0)