Skip to content

Accessor synthesis cleanup (NFC) #21117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5194,7 +5194,10 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
return BodyKind(Bits.AbstractFunctionDecl.BodyKind);
}

using BodySynthesizer = void (*)(AbstractFunctionDecl *);
struct BodySynthesizer {
void (* Fn)(AbstractFunctionDecl *, void *);
void *Context;
};

private:
ParameterList *Params;
Expand Down Expand Up @@ -5318,7 +5321,8 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
BraceStmt *getBody(bool canSynthesize = true) const {
if (canSynthesize && getBodyKind() == BodyKind::Synthesize) {
const_cast<AbstractFunctionDecl *>(this)->setBodyKind(BodyKind::None);
(*Synthesizer)(const_cast<AbstractFunctionDecl *>(this));
(Synthesizer.Fn)(const_cast<AbstractFunctionDecl *>(this),
Synthesizer.Context);
}
if (getBodyKind() == BodyKind::Parsed ||
getBodyKind() == BodyKind::TypeChecked) {
Expand Down Expand Up @@ -5350,9 +5354,10 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
}

/// Note that parsing for the body was delayed.
void setBodySynthesizer(BodySynthesizer synthesizer) {
void setBodySynthesizer(void (* fn)(AbstractFunctionDecl *, void *),
void *context = nullptr) {
assert(getBodyKind() == BodyKind::None);
Synthesizer = synthesizer;
Synthesizer = {fn, context};
setBodyKind(BodyKind::Synthesize);
}

Expand Down
9 changes: 6 additions & 3 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5892,22 +5892,25 @@ ObjCSelector DestructorDecl::getObjCSelector() const {

SourceRange FuncDecl::getSourceRange() const {
SourceLoc StartLoc = getStartLoc();
if (StartLoc.isInvalid() ||
getBodyKind() == BodyKind::Synthesize)

if (StartLoc.isInvalid())
return SourceRange();

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

if (auto *B = getBody()) {
if (auto *B = getBody(/*canSynthesize=*/false)) {
if (!B->isImplicit())
return { StartLoc, B->getEndLoc() };
}

if (isa<AccessorDecl>(this))
return StartLoc;

if (getBodyKind() == BodyKind::Synthesize)
return SourceRange();

auto TrailingWhereClauseSourceRange = getGenericTrailingWhereClauseSourceRange();
if (TrailingWhereClauseSourceRange.isValid())
return { StartLoc, TrailingWhereClauseSourceRange.End };
Expand Down
Loading