Skip to content

Commit c138722

Browse files
committed
[Type checker] Lazily synthesize the empty implicit destructor of a class.
This is more a matter of principle than an optimization, eliminating unnecessary calls to `AbstractFunctionDecl::setBody()`.
1 parent 690409d commit c138722

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/AST/Decl.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3775,6 +3775,14 @@ DestructorDecl *ClassDecl::getDestructor() {
37753775
return cast<DestructorDecl>(results.front());
37763776
}
37773777

3778+
/// Synthesizer callback for an empty implicit function body.
3779+
static std::pair<BraceStmt *, bool>
3780+
synthesizeEmplyFunctionBody(AbstractFunctionDecl *afd, void *context) {
3781+
ASTContext &ctx = afd->getASTContext();
3782+
return { BraceStmt::create(ctx, afd->getLoc(), { }, afd->getLoc(), true),
3783+
/*isTypeChecked=*/true };
3784+
}
3785+
37783786
void ClassDecl::addImplicitDestructor() {
37793787
if (hasDestructor() || isInvalid())
37803788
return;
@@ -3785,8 +3793,8 @@ void ClassDecl::addImplicitDestructor() {
37853793
DD->setImplicit();
37863794
DD->setValidationToChecked();
37873795

3788-
// Create an empty body for the destructor.
3789-
DD->setBody(BraceStmt::create(ctx, getLoc(), { }, getLoc(), true));
3796+
// Synthesize an empty body for the destructor as needed.
3797+
DD->setBodySynthesizer(synthesizeEmplyFunctionBody);
37903798
addMember(DD);
37913799

37923800
// Propagate access control and versioned-ness.

0 commit comments

Comments
 (0)