@@ -1957,7 +1957,7 @@ static bool doesContextHaveValueSemantics(DeclContext *dc) {
1957
1957
return false ;
1958
1958
}
1959
1959
1960
- static void validateSelfAccessKind (TypeChecker &TC, FuncDecl *FD) {
1960
+ static void validateSelfAccessKind (FuncDecl *FD) {
1961
1961
// Validate the mutating attribute if present, and install it into the bit
1962
1962
// on funcdecl (instead of just being a DeclAttribute).
1963
1963
if (FD->getAttrs ().hasAttribute <MutatingAttr>())
@@ -1972,7 +1972,8 @@ static void validateSelfAccessKind(TypeChecker &TC, FuncDecl *FD) {
1972
1972
accessor->getAccessorKind () == AccessorKind::DidSet ||
1973
1973
accessor->getAccessorKind () == AccessorKind::WillSet) {
1974
1974
auto storage = accessor->getStorage ();
1975
- TC.validateDecl (storage);
1975
+ if (auto *resolver = FD->getASTContext ().getLazyResolver ())
1976
+ resolver->resolveDeclSignature (storage);
1976
1977
if (accessor->getAccessorKind () == AccessorKind::Get) {
1977
1978
FD->setSelfAccessKind (storage->isGetterMutating ()
1978
1979
? SelfAccessKind::Mutating
@@ -1992,14 +1993,13 @@ static void validateSelfAccessKind(TypeChecker &TC, FuncDecl *FD) {
1992
1993
}
1993
1994
}
1994
1995
1995
- static bool validateAccessorIsMutating (TypeChecker &TC, FuncDecl *accessor) {
1996
+ static bool validateAccessorIsMutating (FuncDecl *accessor) {
1996
1997
assert (accessor && " accessor not present!" );
1997
- validateSelfAccessKind (TC, accessor);
1998
+ validateSelfAccessKind (accessor);
1998
1999
return accessor->isMutating ();
1999
2000
}
2000
2001
2001
- static bool computeIsGetterMutating (TypeChecker &TC,
2002
- AbstractStorageDecl *storage) {
2002
+ static bool computeIsGetterMutating (AbstractStorageDecl *storage) {
2003
2003
// 'lazy' overrides the normal accessor-based rules and heavily
2004
2004
// restricts what accessors can be used. The getter is considered
2005
2005
// mutating if this is instance storage on a value type.
@@ -2016,7 +2016,10 @@ static bool computeIsGetterMutating(TypeChecker &TC,
2016
2016
if (auto wrapperInfo = var->getAttachedPropertyWrapperTypeInfo (0 )) {
2017
2017
if (wrapperInfo.valueVar &&
2018
2018
(!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 );
2020
2023
return wrapperInfo.valueVar ->isGetterMutating () &&
2021
2024
var->isInstanceMember () &&
2022
2025
doesContextHaveValueSemantics (var->getDeclContext ());
@@ -2033,28 +2036,30 @@ static bool computeIsGetterMutating(TypeChecker &TC,
2033
2036
if (!storage->getGetter ())
2034
2037
return false ;
2035
2038
2036
- return validateAccessorIsMutating (TC, storage->getGetter ());
2039
+ return validateAccessorIsMutating (storage->getGetter ());
2037
2040
2038
2041
case ReadImplKind::Address:
2039
- return validateAccessorIsMutating (TC, storage->getAddressor ());
2042
+ return validateAccessorIsMutating (storage->getAddressor ());
2040
2043
2041
2044
case ReadImplKind::Read:
2042
- return validateAccessorIsMutating (TC, storage->getReadCoroutine ());
2045
+ return validateAccessorIsMutating (storage->getReadCoroutine ());
2043
2046
}
2044
2047
2045
2048
llvm_unreachable (" bad impl kind" );
2046
2049
}
2047
2050
2048
- static bool computeIsSetterMutating (TypeChecker &TC,
2049
- AbstractStorageDecl *storage) {
2051
+ static bool computeIsSetterMutating (AbstractStorageDecl *storage) {
2050
2052
// If we have an attached property wrapper, the setter is mutating if
2051
2053
// the "value" property of the outermost wrapper type is mutating and we're
2052
2054
// in a context that has value semantics.
2053
2055
if (auto var = dyn_cast<VarDecl>(storage)) {
2054
2056
if (auto wrapperInfo = var->getAttachedPropertyWrapperTypeInfo (0 )) {
2055
2057
if (wrapperInfo.valueVar &&
2056
2058
(!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 );
2058
2063
return wrapperInfo.valueVar ->isSetterMutating () &&
2059
2064
var->isInstanceMember () &&
2060
2065
doesContextHaveValueSemantics (var->getDeclContext ());
@@ -2083,24 +2088,24 @@ static bool computeIsSetterMutating(TypeChecker &TC,
2083
2088
auto *setter = storage->getSetter ();
2084
2089
2085
2090
if (setter)
2086
- result = validateAccessorIsMutating (TC, setter);
2091
+ result = validateAccessorIsMutating (setter);
2087
2092
2088
2093
// As a special extra check, if the user also gave us a modify
2089
2094
// coroutine, check that it has the same mutatingness as the setter.
2090
2095
// TODO: arguably this should require the spelling to match even when
2091
2096
// it's the implied value.
2092
2097
if (impl.getReadWriteImpl () == ReadWriteImplKind::Modify) {
2093
2098
auto modifyAccessor = storage->getModifyCoroutine ();
2094
- auto modifyResult = validateAccessorIsMutating (TC, modifyAccessor);
2099
+ auto modifyResult = validateAccessorIsMutating (modifyAccessor);
2095
2100
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);
2102
2107
if (setter)
2103
- TC. diagnose (setter, diag::previous_accessor, " setter" , 0 );
2108
+ setter-> diagnose (diag::previous_accessor, " setter" , 0 );
2104
2109
modifyAccessor->setInvalid ();
2105
2110
}
2106
2111
}
@@ -2109,16 +2114,15 @@ static bool computeIsSetterMutating(TypeChecker &TC,
2109
2114
}
2110
2115
2111
2116
case WriteImplKind::MutableAddress:
2112
- return validateAccessorIsMutating (TC, storage->getMutableAddressor ());
2117
+ return validateAccessorIsMutating (storage->getMutableAddressor ());
2113
2118
2114
2119
case WriteImplKind::Modify:
2115
- return validateAccessorIsMutating (TC, storage->getModifyCoroutine ());
2120
+ return validateAccessorIsMutating (storage->getModifyCoroutine ());
2116
2121
}
2117
2122
llvm_unreachable (" bad storage kind" );
2118
2123
}
2119
2124
2120
- static bool shouldUseOpaqueReadAccessor (TypeChecker &TC,
2121
- AbstractStorageDecl *storage) {
2125
+ static bool shouldUseOpaqueReadAccessor (AbstractStorageDecl *storage) {
2122
2126
return storage->getAttrs ().hasAttribute <BorrowedAttr>();
2123
2127
}
2124
2128
@@ -2130,13 +2134,13 @@ static void validateAbstractStorageDecl(TypeChecker &TC,
2130
2134
}
2131
2135
}
2132
2136
2133
- if (shouldUseOpaqueReadAccessor (TC, storage))
2137
+ if (shouldUseOpaqueReadAccessor (storage))
2134
2138
storage->setOpaqueReadOwnership (OpaqueReadOwnership::Borrowed);
2135
2139
2136
2140
// isGetterMutating and isSetterMutating are part of the signature
2137
2141
// 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));
2140
2144
2141
2145
// Everything else about the accessors can wait until finalization.
2142
2146
// This will validate all the accessors.
@@ -3981,7 +3985,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
3981
3985
}
3982
3986
}
3983
3987
3984
- validateSelfAccessKind (* this , FD);
3988
+ validateSelfAccessKind (FD);
3985
3989
3986
3990
// Check whether the return type is dynamic 'Self'.
3987
3991
FD->setDynamicSelf (checkDynamicSelfReturn (FD));
0 commit comments