Skip to content

Commit eea5cfb

Browse files
committed
Refactor DynamicReplacementAttr::create
Remove a dead overload and add an overload for lazy member loading
1 parent ac08fce commit eea5cfb

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

include/swift/AST/Attr.h

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class FuncDecl;
5252
class ClassDecl;
5353
class GenericFunctionType;
5454
class LazyConformanceLoader;
55+
class LazyMemberLoader;
5556
class PatternBindingInitializer;
5657
class TrailingWhereClause;
5758

@@ -1010,18 +1011,31 @@ class DynamicReplacementAttr final
10101011
: public DeclAttribute,
10111012
private llvm::TrailingObjects<DynamicReplacementAttr, SourceLoc> {
10121013
friend TrailingObjects;
1014+
friend class DynamicallyReplacedDeclRequest;
10131015

10141016
DeclName ReplacedFunctionName;
1015-
AbstractFunctionDecl *ReplacedFunction;
1017+
LazyMemberLoader *Resolver = nullptr;
1018+
uint64_t ResolverContextData;
10161019

10171020
/// Create an @_dynamicReplacement(for:) attribute written in the source.
10181021
DynamicReplacementAttr(SourceLoc atLoc, SourceRange baseRange,
10191022
DeclName replacedFunctionName, SourceRange parenRange);
10201023

1021-
explicit DynamicReplacementAttr(DeclName name)
1024+
DynamicReplacementAttr(DeclName name, AbstractFunctionDecl *f)
10221025
: DeclAttribute(DAK_DynamicReplacement, SourceLoc(), SourceRange(),
10231026
/*Implicit=*/false),
1024-
ReplacedFunctionName(name), ReplacedFunction(nullptr) {
1027+
ReplacedFunctionName(name),
1028+
Resolver(nullptr), ResolverContextData(0) {
1029+
Bits.DynamicReplacementAttr.HasTrailingLocationInfo = false;
1030+
}
1031+
1032+
DynamicReplacementAttr(DeclName name,
1033+
LazyMemberLoader *Resolver = nullptr,
1034+
uint64_t Data = 0)
1035+
: DeclAttribute(DAK_DynamicReplacement, SourceLoc(), SourceRange(),
1036+
/*Implicit=*/false),
1037+
ReplacedFunctionName(name),
1038+
Resolver(Resolver), ResolverContextData(Data) {
10251039
Bits.DynamicReplacementAttr.HasTrailingLocationInfo = false;
10261040
}
10271041

@@ -1045,25 +1059,18 @@ class DynamicReplacementAttr final
10451059
SourceLoc LParenLoc, DeclName replacedFunction, SourceLoc RParenLoc);
10461060

10471061
static DynamicReplacementAttr *create(ASTContext &ctx,
1048-
DeclName replacedFunction);
1062+
DeclName replacedFunction,
1063+
AbstractFunctionDecl *replacedFuncDecl);
10491064

10501065
static DynamicReplacementAttr *create(ASTContext &ctx,
10511066
DeclName replacedFunction,
1052-
AbstractFunctionDecl *replacedFuncDecl);
1067+
LazyMemberLoader *Resolver,
1068+
uint64_t Data);
10531069

10541070
DeclName getReplacedFunctionName() const {
10551071
return ReplacedFunctionName;
10561072
}
10571073

1058-
AbstractFunctionDecl *getReplacedFunction() const {
1059-
return ReplacedFunction;
1060-
}
1061-
1062-
void setReplacedFunction(AbstractFunctionDecl *f) {
1063-
assert(ReplacedFunction == nullptr);
1064-
ReplacedFunction = f;
1065-
}
1066-
10671074
/// Retrieve the location of the opening parentheses, if there is one.
10681075
SourceLoc getLParenLoc() const;
10691076

lib/AST/Attr.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
#include "swift/AST/GenericEnvironment.h"
2323
#include "swift/AST/IndexSubset.h"
2424
#include "swift/AST/Module.h"
25+
#include "swift/AST/ParameterList.h"
2526
#include "swift/AST/TypeRepr.h"
2627
#include "swift/AST/Types.h"
27-
#include "swift/AST/ParameterList.h"
2828
#include "swift/Basic/Defer.h"
2929
#include "llvm/ADT/SmallString.h"
30-
#include "llvm/Support/raw_ostream.h"
31-
#include "llvm/Support/ErrorHandling.h"
3230
#include "llvm/ADT/StringSwitch.h"
31+
#include "llvm/Support/ErrorHandling.h"
32+
#include "llvm/Support/raw_ostream.h"
3333
using namespace swift;
3434

3535
#define DECL_ATTR(_, Id, ...) \
@@ -1148,7 +1148,7 @@ DynamicReplacementAttr::DynamicReplacementAttr(SourceLoc atLoc,
11481148
SourceRange parenRange)
11491149
: DeclAttribute(DAK_DynamicReplacement, atLoc, baseRange,
11501150
/*Implicit=*/false),
1151-
ReplacedFunctionName(name), ReplacedFunction(nullptr) {
1151+
ReplacedFunctionName(name) {
11521152
Bits.DynamicReplacementAttr.HasTrailingLocationInfo = true;
11531153
getTrailingLocations()[0] = parenRange.Start;
11541154
getTrailingLocations()[1] = parenRange.End;
@@ -1165,17 +1165,16 @@ DynamicReplacementAttr::create(ASTContext &Ctx, SourceLoc AtLoc,
11651165
SourceRange(LParenLoc, RParenLoc));
11661166
}
11671167

1168-
DynamicReplacementAttr *DynamicReplacementAttr::create(ASTContext &Ctx,
1169-
DeclName name) {
1170-
return new (Ctx) DynamicReplacementAttr(name);
1168+
DynamicReplacementAttr *
1169+
DynamicReplacementAttr::create(ASTContext &Ctx, DeclName name,
1170+
AbstractFunctionDecl *f) {
1171+
return new (Ctx) DynamicReplacementAttr(name, f);
11711172
}
11721173

11731174
DynamicReplacementAttr *
11741175
DynamicReplacementAttr::create(ASTContext &Ctx, DeclName name,
1175-
AbstractFunctionDecl *f) {
1176-
auto res = new (Ctx) DynamicReplacementAttr(name);
1177-
res->setReplacedFunction(f);
1178-
return res;
1176+
LazyMemberLoader *Resolver, uint64_t Data) {
1177+
return new (Ctx) DynamicReplacementAttr(name, Resolver, Data);
11791178
}
11801179

11811180
SourceLoc DynamicReplacementAttr::getLParenLoc() const {

0 commit comments

Comments
 (0)