Skip to content

Commit 59f1133

Browse files
committed
Sema: Do less work for structs in addImplicitConstructors()
1 parent 4e8bdcd commit 59f1133

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8540,16 +8540,20 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
85408540

85418541
// Bail out if we're validating one of our constructors already; we'll
85428542
// revisit the issue later.
8543-
bool alreadyValidatingCtor = false;
8544-
for (auto member : decl->getMembers()) {
8545-
if (auto ctor = dyn_cast<ConstructorDecl>(member)) {
8546-
validateDecl(ctor);
8547-
if (!ctor->hasValidSignature())
8548-
alreadyValidatingCtor = true;
8543+
if (isa<ClassDecl>(decl)) {
8544+
bool alreadyValidatingCtor = false;
8545+
for (auto member : decl->getMembers()) {
8546+
if (auto ctor = dyn_cast<ConstructorDecl>(member)) {
8547+
validateDecl(ctor);
8548+
if (!ctor->hasValidSignature())
8549+
alreadyValidatingCtor = true;
8550+
}
85498551
}
8552+
if (alreadyValidatingCtor)
8553+
return;
85508554
}
8551-
if (alreadyValidatingCtor)
8552-
return;
8555+
8556+
decl->setAddedImplicitInitializers();
85538557

85548558
// Check whether there is a user-declared constructor or an instance
85558559
// variable.
@@ -8558,7 +8562,6 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
85588562
bool SuppressMemberwiseInitializer = false;
85598563
bool FoundSynthesizedInit = false;
85608564
bool FoundDesignatedInit = false;
8561-
decl->setAddedImplicitInitializers();
85628565

85638566
// Before we look for constructors, we need to make sure that all synthesized
85648567
// initializers are properly synthesized.
@@ -8600,6 +8603,9 @@ void TypeChecker::addImplicitConstructors(NominalTypeDecl *decl) {
86008603
FoundDesignatedInit = true;
86018604
}
86028605

8606+
if (isa<StructDecl>(decl))
8607+
continue;
8608+
86038609
if (!ctor->isInvalid())
86048610
initializerParamTypes.insert(getInitializerParamType(ctor));
86058611

0 commit comments

Comments
 (0)