Skip to content

Commit e160b85

Browse files
authored
Merge pull request #21117 from slavapestov/accessor-synthesis-cleanup
Accessor synthesis cleanup (NFC)
2 parents c829506 + a76012d commit e160b85

17 files changed

+324
-410
lines changed

include/swift/AST/Decl.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5194,7 +5194,10 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
51945194
return BodyKind(Bits.AbstractFunctionDecl.BodyKind);
51955195
}
51965196

5197-
using BodySynthesizer = void (*)(AbstractFunctionDecl *);
5197+
struct BodySynthesizer {
5198+
void (* Fn)(AbstractFunctionDecl *, void *);
5199+
void *Context;
5200+
};
51985201

51995202
private:
52005203
ParameterList *Params;
@@ -5318,7 +5321,8 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
53185321
BraceStmt *getBody(bool canSynthesize = true) const {
53195322
if (canSynthesize && getBodyKind() == BodyKind::Synthesize) {
53205323
const_cast<AbstractFunctionDecl *>(this)->setBodyKind(BodyKind::None);
5321-
(*Synthesizer)(const_cast<AbstractFunctionDecl *>(this));
5324+
(Synthesizer.Fn)(const_cast<AbstractFunctionDecl *>(this),
5325+
Synthesizer.Context);
53225326
}
53235327
if (getBodyKind() == BodyKind::Parsed ||
53245328
getBodyKind() == BodyKind::TypeChecked) {
@@ -5350,9 +5354,10 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
53505354
}
53515355

53525356
/// Note that parsing for the body was delayed.
5353-
void setBodySynthesizer(BodySynthesizer synthesizer) {
5357+
void setBodySynthesizer(void (* fn)(AbstractFunctionDecl *, void *),
5358+
void *context = nullptr) {
53545359
assert(getBodyKind() == BodyKind::None);
5355-
Synthesizer = synthesizer;
5360+
Synthesizer = {fn, context};
53565361
setBodyKind(BodyKind::Synthesize);
53575362
}
53585363

lib/AST/Decl.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5891,22 +5891,25 @@ ObjCSelector DestructorDecl::getObjCSelector() const {
58915891

58925892
SourceRange FuncDecl::getSourceRange() const {
58935893
SourceLoc StartLoc = getStartLoc();
5894-
if (StartLoc.isInvalid() ||
5895-
getBodyKind() == BodyKind::Synthesize)
5894+
5895+
if (StartLoc.isInvalid())
58965896
return SourceRange();
58975897

58985898
if (getBodyKind() == BodyKind::Unparsed ||
58995899
getBodyKind() == BodyKind::Skipped)
59005900
return { StartLoc, BodyRange.End };
59015901

5902-
if (auto *B = getBody()) {
5902+
if (auto *B = getBody(/*canSynthesize=*/false)) {
59035903
if (!B->isImplicit())
59045904
return { StartLoc, B->getEndLoc() };
59055905
}
59065906

59075907
if (isa<AccessorDecl>(this))
59085908
return StartLoc;
59095909

5910+
if (getBodyKind() == BodyKind::Synthesize)
5911+
return SourceRange();
5912+
59105913
auto TrailingWhereClauseSourceRange = getGenericTrailingWhereClauseSourceRange();
59115914
if (TrailingWhereClauseSourceRange.isValid())
59125915
return { StartLoc, TrailingWhereClauseSourceRange.End };

0 commit comments

Comments
 (0)