Skip to content

Commit 41bc59c

Browse files
authored
Merge pull request #68216 from tshortli/lazier-tbdgen
TBDGen: Skip visiting nominal types with non-public linkage
2 parents 35d6175 + fed04e0 commit 41bc59c

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

lib/SIL/IR/SILSymbolVisitor.cpp

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
239239
for (auto conformance :
240240
IDC->getLocalConformances(ConformanceLookupKind::NonInherited)) {
241241
auto protocol = conformance->getProtocol();
242-
if (Ctx.getOpts().PublicSymbolsOnly &&
243-
getDeclLinkage(protocol) != FormalLinkage::PublicUnique)
242+
if (canSkipNominal(protocol))
244243
continue;
245244

246245
auto needsWTable =
@@ -308,8 +307,7 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
308307
}
309308

310309
bool addClassMetadata(ClassDecl *CD) {
311-
if (Ctx.getOpts().PublicSymbolsOnly &&
312-
getDeclLinkage(CD) != FormalLinkage::PublicUnique)
310+
if (canSkipNominal(CD))
313311
return false;
314312

315313
auto &ctxt = CD->getASTContext();
@@ -365,6 +363,18 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
365363
Visitor.addMethodDescriptor(method);
366364
}
367365

366+
/// Returns `true` if the neither the nominal nor its members have any symbols
367+
/// that need to be visited because it has non-public linkage.
368+
bool canSkipNominal(const NominalTypeDecl *NTD) {
369+
if (!Ctx.getOpts().PublicSymbolsOnly)
370+
return false;
371+
372+
if (NTD->hasClangNode())
373+
return false;
374+
375+
return getDeclLinkage(NTD) != FormalLinkage::PublicUnique;
376+
}
377+
368378
public:
369379
SILSymbolVisitorImpl(SILSymbolVisitor &Visitor,
370380
const SILSymbolVisitorContext &Ctx)
@@ -585,6 +595,9 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
585595
}
586596

587597
void visitNominalTypeDecl(NominalTypeDecl *NTD) {
598+
if (canSkipNominal(NTD))
599+
return;
600+
588601
auto declaredType = NTD->getDeclaredType()->getCanonicalType();
589602

590603
if (!NTD->getObjCImplementationDecl()) {
@@ -680,12 +693,16 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
680693
}
681694

682695
void visitExtensionDecl(ExtensionDecl *ED) {
696+
auto nominal = ED->getExtendedNominal();
697+
if (canSkipNominal(nominal))
698+
return;
699+
683700
if (auto CD = dyn_cast_or_null<ClassDecl>(ED->getImplementedObjCDecl())) {
684701
// @_objcImplementation extensions generate the class metadata symbols.
685702
(void)addClassMetadata(CD);
686703
}
687704

688-
if (!isa<ProtocolDecl>(ED->getExtendedNominal())) {
705+
if (!isa<ProtocolDecl>(nominal)) {
689706
addConformances(ED);
690707
}
691708

@@ -738,6 +755,9 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
738755
#endif
739756

740757
void visitProtocolDecl(ProtocolDecl *PD) {
758+
if (canSkipNominal(PD))
759+
return;
760+
741761
if (!PD->isObjC() && !PD->isMarkerProtocol()) {
742762
Visitor.addProtocolDescriptor(PD);
743763

test/Inputs/lazy_typecheck.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ public struct PublicStruct {
7171
}
7272

7373
struct InternalStruct: DoesNotExist { // expected-error {{cannot find type 'DoesNotExist' in scope}}
74-
// FIXME: TBD emission causes this property to be typechecked
75-
// var x: DoesNotExist
74+
var x: DoesNotExist // expected-error {{cannot find type 'DoesNotExist' in scope}}
7675

7776
func f(_ x: DoesNotExist) {} // expected-error {{cannot find type 'DoesNotExist' in scope}}
7877
}

0 commit comments

Comments
 (0)