Skip to content

Commit 107849a

Browse files
authored
Merge pull request #16049 from slavapestov/sema-external-declarations
Sema: Remove some unnecessary processing of external declarations
2 parents 4c733c3 + 8d262be commit 107849a

File tree

4 files changed

+6
-55
lines changed

4 files changed

+6
-55
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,6 +2639,7 @@ namespace {
26392639
AccessLevel::Public, Loc, name, Loc, None, nullptr, dc);
26402640
structDecl->computeType();
26412641
structDecl->setCheckedInheritanceClause();
2642+
structDecl->setAddedImplicitInitializers();
26422643

26432644
auto options = getDefaultMakeStructRawValuedOptions();
26442645
options |= MakeStructRawValuedFlags::MakeUnlabeledValueInit;
@@ -2689,6 +2690,7 @@ namespace {
26892690
errorWrapper = new (C) StructDecl(loc, name, loc, None, nullptr, dc);
26902691
errorWrapper->computeType();
26912692
errorWrapper->setValidationStarted();
2693+
errorWrapper->setAddedImplicitInitializers();
26922694
errorWrapper->setAccess(AccessLevel::Public);
26932695
errorWrapper->getAttrs().add(
26942696
new (Impl.SwiftContext) FixedLayoutAttr(/*IsImplicit*/true));
@@ -3124,6 +3126,7 @@ namespace {
31243126
Impl.importSourceLoc(decl->getLocation()),
31253127
None, nullptr, dc);
31263128
result->computeType();
3129+
result->setAddedImplicitInitializers();
31273130
Impl.ImportedDecls[{decl->getCanonicalDecl(), getVersion()}] = result;
31283131

31293132
// FIXME: Figure out what to do with superclasses in C++. One possible
@@ -5300,6 +5303,7 @@ SwiftDeclConverter::importSwiftNewtype(const clang::TypedefNameDecl *decl,
53005303
decl, AccessLevel::Public, Loc, name, Loc, None, nullptr, dc);
53015304
structDecl->computeType();
53025305
structDecl->setCheckedInheritanceClause();
5306+
structDecl->setAddedImplicitInitializers();
53035307

53045308
// Import the type of the underlying storage
53055309
auto storedUnderlyingType = Impl.importTypeIgnoreIUO(
@@ -5578,6 +5582,7 @@ SwiftDeclConverter::importAsOptionSetType(DeclContext *dc, Identifier name,
55785582
decl, AccessLevel::Public, Loc, name, Loc, None, nullptr, dc);
55795583
structDecl->computeType();
55805584
structDecl->setCheckedInheritanceClause();
5585+
structDecl->setAddedImplicitInitializers();
55815586

55825587
makeStructRawValued(Impl, structDecl, underlyingType,
55835588
{KnownProtocolKind::OptionSet});

lib/Sema/TypeCheckDecl.cpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9098,32 +9098,6 @@ void TypeChecker::synthesizeMemberForLookup(NominalTypeDecl *target,
90989098
}
90999099
}
91009100

9101-
void TypeChecker::addImplicitStructConformances(StructDecl *SD) {
9102-
// Type-check the protocol conformances of the struct decl to instantiate its
9103-
// derived conformances.
9104-
checkConformancesInContext(SD, SD);
9105-
}
9106-
9107-
void TypeChecker::addImplicitEnumConformances(EnumDecl *ED) {
9108-
// Type-check the raw values of the enum.
9109-
for (auto elt : ED->getAllElements()) {
9110-
assert(elt->hasRawValueExpr());
9111-
if (elt->getTypeCheckedRawValueExpr()) continue;
9112-
Expr *typeChecked = elt->getRawValueExpr();
9113-
Type rawTy = ED->mapTypeIntoContext(ED->getRawType());
9114-
auto resultTy = typeCheckExpression(
9115-
typeChecked, ED, TypeLoc::withoutLoc(rawTy), CTP_EnumCaseRawValue);
9116-
assert(resultTy);
9117-
(void)resultTy;
9118-
elt->setTypeCheckedRawValueExpr(typeChecked);
9119-
checkEnumElementErrorHandling(elt);
9120-
}
9121-
9122-
// Type-check the protocol conformances of the enum decl to instantiate its
9123-
// derived conformances.
9124-
checkConformancesInContext(ED, ED);
9125-
}
9126-
91279101
void TypeChecker::defineDefaultConstructor(NominalTypeDecl *decl) {
91289102
PrettyStackTraceDecl stackTrace("defining default constructor for",
91299103
decl);

lib/Sema/TypeChecker.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,6 @@ TypeChecker::~TypeChecker() {
6565
Context.setLazyResolver(nullptr);
6666
}
6767

68-
void TypeChecker::handleExternalDecl(Decl *decl) {
69-
if (auto SD = dyn_cast<StructDecl>(decl)) {
70-
addImplicitStructConformances(SD);
71-
}
72-
if (auto CD = dyn_cast<ClassDecl>(decl)) {
73-
CD->addImplicitDestructor();
74-
}
75-
if (auto ED = dyn_cast<EnumDecl>(decl)) {
76-
addImplicitEnumConformances(ED);
77-
}
78-
}
79-
8068
ProtocolDecl *TypeChecker::getProtocol(SourceLoc loc, KnownProtocolKind kind) {
8169
auto protocol = Context.getProtocol(kind);
8270
if (!protocol && loc.isValid()) {
@@ -475,10 +463,8 @@ static void typeCheckFunctionsAndExternalDecls(SourceFile &SF, TypeChecker &TC)
475463
TC.checkFunctionErrorHandling(AFD);
476464
continue;
477465
}
478-
if (isa<NominalTypeDecl>(decl)) {
479-
TC.handleExternalDecl(decl);
466+
if (isa<NominalTypeDecl>(decl))
480467
continue;
481-
}
482468
if (isa<VarDecl>(decl))
483469
continue;
484470
llvm_unreachable("Unhandled external definition kind");

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,14 +1539,6 @@ class TypeChecker final : public LazyResolver {
15391539
/// struct or class.
15401540
void addImplicitConstructors(NominalTypeDecl *typeDecl);
15411541

1542-
/// \brief Add the RawOptionSet (todo:, Equatable, and Hashable) methods to an
1543-
/// imported NS_OPTIONS struct.
1544-
void addImplicitStructConformances(StructDecl *ED);
1545-
1546-
/// \brief Add the RawRepresentable, Equatable, and Hashable methods to an
1547-
/// enum with a raw type.
1548-
void addImplicitEnumConformances(EnumDecl *ED);
1549-
15501542
/// Synthesize the member with the given name on the target if applicable,
15511543
/// i.e. if the member is synthesizable and has not yet been added to the
15521544
/// target.
@@ -2269,12 +2261,6 @@ class TypeChecker final : public LazyResolver {
22692261
/// we're parsing the standard library.
22702262
ModuleDecl *getStdlibModule(const DeclContext *dc);
22712263

2272-
/// \name AST Mutation Listener Implementation
2273-
/// @{
2274-
void handleExternalDecl(Decl *decl);
2275-
2276-
/// @}
2277-
22782264
/// \name Lazy resolution.
22792265
///
22802266
/// Routines that perform lazy resolution as required for AST operations.

0 commit comments

Comments
 (0)