Skip to content

Commit 34f78df

Browse files
authored
Merge pull request #66529 from DougGregor/requestify-has-storage-5.9
2 parents 8215e8f + beeadb2 commit 34f78df

21 files changed

+341
-83
lines changed

include/swift/AST/Decl.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5295,10 +5295,10 @@ class AbstractStorageDecl : public ValueDecl {
52955295

52965296
/// Overwrite the registered implementation-info. This should be
52975297
/// used carefully.
5298-
void setImplInfo(StorageImplInfo implInfo) {
5299-
LazySemanticInfo.ImplInfoComputed = 1;
5300-
ImplInfo = implInfo;
5301-
}
5298+
void setImplInfo(StorageImplInfo implInfo);
5299+
5300+
/// Cache the implementation-info, for use by the request-evaluator.
5301+
void cacheImplInfo(StorageImplInfo implInfo);
53025302

53035303
ReadImplKind getReadImpl() const {
53045304
return getImplInfo().getReadImpl();
@@ -5313,9 +5313,7 @@ class AbstractStorageDecl : public ValueDecl {
53135313

53145314
/// Return true if this is a VarDecl that has storage associated with
53155315
/// it.
5316-
bool hasStorage() const {
5317-
return getImplInfo().hasStorage();
5318-
}
5316+
bool hasStorage() const;
53195317

53205318
/// Return true if this storage has the basic accessors/capability
53215319
/// to be mutated. This is generally constant after the accessors are

include/swift/AST/DiagnosticsSema.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7095,6 +7095,13 @@ ERROR(invalid_macro_role_for_macro_syntax,none,
70957095
(unsigned))
70967096
ERROR(macro_cannot_introduce_names,none,
70977097
"'%0' macros are not allowed to introduce names", (StringRef))
7098+
ERROR(macro_accessor_missing_from_expansion,none,
7099+
"expansion of macro %0 did not produce a %select{non-|}1observing "
7100+
"accessor",
7101+
(DeclName, bool))
7102+
ERROR(macro_init_accessor_not_documented,none,
7103+
"expansion of macro %0 produced an unexpected 'init' accessor",
7104+
(DeclName))
70987105

70997106
ERROR(macro_resolve_circular_reference, none,
71007107
"circular reference resolving %select{freestanding|attached}0 macro %1",

include/swift/AST/Evaluator.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,12 @@ class Evaluator {
316316
cache.insert<Request>(request, std::move(output));
317317
}
318318

319+
template<typename Request,
320+
typename std::enable_if<!Request::hasExternalCache>::type* = nullptr>
321+
bool hasCachedResult(const Request &request) {
322+
return cache.find_as(request) != cache.end<Request>();
323+
}
324+
319325
/// Do not introduce new callers of this function.
320326
template<typename Request,
321327
typename std::enable_if<!Request::hasExternalCache>::type* = nullptr>

include/swift/AST/NameLookup.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,13 @@ void forEachPotentialResolvedMacro(
555555
llvm::function_ref<void(MacroDecl *, const MacroRoleAttr *)> body
556556
);
557557

558+
/// For each macro with the given role that might be attached to the given
559+
/// declaration, call the body.
560+
void forEachPotentialAttachedMacro(
561+
Decl *decl, MacroRole role,
562+
llvm::function_ref<void(MacroDecl *macro, const MacroRoleAttr *)> body
563+
);
564+
558565
} // end namespace namelookup
559566

560567
/// Describes an inherited nominal entry.

include/swift/AST/TypeCheckRequests.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,26 @@ class InitAccessorPropertiesRequest :
16861686
ArrayRef<VarDecl *>
16871687
evaluate(Evaluator &evaluator, NominalTypeDecl *decl) const;
16881688

1689+
// Evaluation.
1690+
bool evaluate(Evaluator &evaluator, AbstractStorageDecl *decl) const;
1691+
1692+
public:
1693+
bool isCached() const { return true; }
1694+
};
1695+
1696+
class HasStorageRequest :
1697+
public SimpleRequest<HasStorageRequest,
1698+
bool(AbstractStorageDecl *),
1699+
RequestFlags::Cached> {
1700+
public:
1701+
using SimpleRequest::SimpleRequest;
1702+
1703+
private:
1704+
friend SimpleRequest;
1705+
1706+
// Evaluation.
1707+
bool evaluate(Evaluator &evaluator, AbstractStorageDecl *decl) const;
1708+
16891709
public:
16901710
bool isCached() const { return true; }
16911711
};

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ SWIFT_REQUEST(TypeChecker, SelfAccessKindRequest, SelfAccessKind(FuncDecl *),
302302
SWIFT_REQUEST(TypeChecker, StorageImplInfoRequest,
303303
StorageImplInfo(AbstractStorageDecl *), SeparatelyCached,
304304
NoLocationInfo)
305+
SWIFT_REQUEST(TypeChecker, HasStorageRequest,
306+
bool(AbstractStorageDecl *), Cached,
307+
NoLocationInfo)
305308
SWIFT_REQUEST(TypeChecker, StoredPropertiesAndMissingMembersRequest,
306309
ArrayRef<Decl *>(NominalTypeDecl *), Cached, NoLocationInfo)
307310
SWIFT_REQUEST(TypeChecker, StoredPropertiesRequest,

lib/AST/Decl.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2525,7 +2525,7 @@ AbstractStorageDecl::getAccessStrategy(AccessSemantics semantics,
25252525
ResilienceExpansion expansion) const {
25262526
switch (semantics) {
25272527
case AccessSemantics::DirectToStorage:
2528-
assert(hasStorage());
2528+
assert(hasStorage() || getASTContext().Diags.hadAnyError());
25292529
return AccessStrategy::getStorage();
25302530

25312531
case AccessSemantics::DistributedThunk:
@@ -6384,13 +6384,40 @@ bool ProtocolDecl::hasCircularInheritedProtocols() const {
63846384
ctx.evaluator, HasCircularInheritedProtocolsRequest{mutableThis}, true);
63856385
}
63866386

6387+
bool AbstractStorageDecl::hasStorage() const {
6388+
ASTContext &ctx = getASTContext();
6389+
return evaluateOrDefault(ctx.evaluator,
6390+
HasStorageRequest{const_cast<AbstractStorageDecl *>(this)},
6391+
false);
6392+
}
6393+
63876394
StorageImplInfo AbstractStorageDecl::getImplInfo() const {
63886395
ASTContext &ctx = getASTContext();
63896396
return evaluateOrDefault(ctx.evaluator,
63906397
StorageImplInfoRequest{const_cast<AbstractStorageDecl *>(this)},
63916398
StorageImplInfo::getSimpleStored(StorageIsMutable));
63926399
}
63936400

6401+
void AbstractStorageDecl::cacheImplInfo(StorageImplInfo implInfo) {
6402+
LazySemanticInfo.ImplInfoComputed = 1;
6403+
ImplInfo = implInfo;
6404+
}
6405+
6406+
void AbstractStorageDecl::setImplInfo(StorageImplInfo implInfo) {
6407+
cacheImplInfo(implInfo);
6408+
6409+
if (isImplicit()) {
6410+
auto &evaluator = getASTContext().evaluator;
6411+
HasStorageRequest request{this};
6412+
if (!evaluator.hasCachedResult(request))
6413+
evaluator.cacheOutput(request, implInfo.hasStorage());
6414+
else {
6415+
assert(
6416+
evaluateOrDefault(evaluator, request, false) == implInfo.hasStorage());
6417+
}
6418+
}
6419+
}
6420+
63946421
bool AbstractStorageDecl::hasPrivateAccessor() const {
63956422
for (auto accessor : getAllAccessors()) {
63966423
if (hasPrivateOrFilePrivateFormalAccess(accessor))

lib/AST/NameLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1627,7 +1627,7 @@ void namelookup::forEachPotentialResolvedMacro(
16271627

16281628
/// For each macro with the given role that might be attached to the given
16291629
/// declaration, call the body.
1630-
static void forEachPotentialAttachedMacro(
1630+
void namelookup::forEachPotentialAttachedMacro(
16311631
Decl *decl, MacroRole role,
16321632
llvm::function_ref<void(MacroDecl *macro, const MacroRoleAttr *)> body
16331633
) {

lib/AST/TypeCheckRequests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ StorageImplInfoRequest::getCachedResult() const {
687687

688688
void StorageImplInfoRequest::cacheResult(StorageImplInfo value) const {
689689
auto *storage = std::get<0>(getStorage());
690-
storage->setImplInfo(value);
690+
storage->cacheImplInfo(value);
691691
}
692692

693693
//----------------------------------------------------------------------------//

lib/ClangImporter/ClangImporter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "swift/AST/NameLookupRequests.h"
3535
#include "swift/AST/PrettyStackTrace.h"
3636
#include "swift/AST/SourceFile.h"
37+
#include "swift/AST/TypeCheckRequests.h"
3738
#include "swift/AST/Types.h"
3839
#include "swift/Basic/Defer.h"
3940
#include "swift/Basic/Platform.h"
@@ -5042,6 +5043,7 @@ cloneBaseMemberDecl(ValueDecl *decl, DeclContext *newContext) {
50425043
out->setIsObjC(var->isObjC());
50435044
out->setIsDynamic(var->isDynamic());
50445045
out->copyFormalAccessFrom(var);
5046+
out->getASTContext().evaluator.cacheOutput(HasStorageRequest{out}, false);
50455047
out->setAccessors(SourceLoc(),
50465048
makeBaseClassMemberAccessors(newContext, out, var),
50475049
SourceLoc());

0 commit comments

Comments
 (0)