Skip to content

Commit ac08fce

Browse files
committed
Add loadDynamicallyReplacedFunctionDecl
To support lazy resolution of the cross-referenced function in a serialized @_dynamicReplacement(for: ...) attribute, add a utility to the LazyMemberLoader and plumb it through. This is a more general utility than the current resolver, which relies on the type checker to strip the attribute off of VarDecls and fan it back out onto accessors, which means serialization has only ever seen AbstractFunctionDecls.
1 parent ee99bf1 commit ac08fce

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

include/swift/AST/LazyResolver.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ class alignas(void*) LazyMemberLoader {
103103
virtual void
104104
loadRequirementSignature(const ProtocolDecl *proto, uint64_t contextData,
105105
SmallVectorImpl<Requirement> &requirements) = 0;
106+
107+
/// Returns the replaced decl for a given @_dynamicReplacement(for:) attribute.
108+
virtual ValueDecl *
109+
loadDynamicallyReplacedFunctionDecl(const DynamicReplacementAttr *DRA,
110+
uint64_t contextData) = 0;
106111
};
107112

108113
/// A class that can lazily load conformances from a serialized format.

lib/ClangImporter/ImporterImpl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,12 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
12301230
llvm_unreachable("unimplemented for ClangImporter");
12311231
}
12321232

1233+
ValueDecl *
1234+
loadDynamicallyReplacedFunctionDecl(const DynamicReplacementAttr *DRA,
1235+
uint64_t contextData) override {
1236+
llvm_unreachable("unimplemented for ClangImporter");
1237+
}
1238+
12331239
void loadRequirementSignature(const ProtocolDecl *decl, uint64_t contextData,
12341240
SmallVectorImpl<Requirement> &reqs) override {
12351241
llvm_unreachable("unimplemented for ClangImporter");

lib/Serialization/Deserialization.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5457,6 +5457,11 @@ ModuleFile::loadAssociatedTypeDefault(const swift::AssociatedTypeDecl *ATD,
54575457
return getType(contextData);
54585458
}
54595459

5460+
ValueDecl *ModuleFile::loadDynamicallyReplacedFunctionDecl(
5461+
const DynamicReplacementAttr *DRA, uint64_t contextData) {
5462+
return cast<ValueDecl>(getDecl(contextData));
5463+
}
5464+
54605465
void ModuleFile::finishNormalConformance(NormalProtocolConformance *conformance,
54615466
uint64_t contextData) {
54625467
using namespace decls_block;

lib/Serialization/ModuleFile.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,10 @@ class ModuleFile
839839
virtual Type loadAssociatedTypeDefault(const AssociatedTypeDecl *ATD,
840840
uint64_t contextData) override;
841841

842+
virtual ValueDecl *
843+
loadDynamicallyReplacedFunctionDecl(const DynamicReplacementAttr *DRA,
844+
uint64_t contextData) override;
845+
842846
virtual void finishNormalConformance(NormalProtocolConformance *conformance,
843847
uint64_t contextData) override;
844848

0 commit comments

Comments
 (0)