Skip to content

Commit ec1b1a3

Browse files
committed
AST: Remove ASTContext::ExternalDefinitions
Anything added here has a type checked body now, so it no longer serves any purpose.
1 parent 96749a2 commit ec1b1a3

File tree

9 files changed

+7
-120
lines changed

9 files changed

+7
-120
lines changed

docs/CompilerPerformance.md

-1
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,6 @@ $ cat /tmp/stats/*.json
717717
"AST.NumSourceLinesPerSecond": 3,
718718
"AST.NumLinkLibraries": 0,
719719
"AST.NumLoadedModules": 4,
720-
"AST.NumImportedExternalDefinitions": 0,
721720
"AST.NumTotalClangImportedEntities": 0,
722721
...
723722
"time.swift.Parsing.wall": 5.038023e-03,

include/swift/AST/ASTContext.h

+1-14
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,6 @@ class ASTContext final {
255255
#define IDENTIFIER_WITH_NAME(Name, IdStr) Identifier Id_##Name;
256256
#include "swift/AST/KnownIdentifiers.def"
257257

258-
/// The list of external definitions imported by this context.
259-
llvm::SetVector<Decl *> ExternalDefinitions;
260-
261-
/// FIXME: HACK HACK HACK
262-
/// This state should be tracked somewhere else.
263-
unsigned LastCheckedExternalDefinition = 0;
264-
265258
/// A consumer of type checker debug output.
266259
std::unique_ptr<TypeCheckerDebugConsumer> TypeCheckerDebug;
267260

@@ -580,14 +573,8 @@ class ASTContext final {
580573
ForeignLanguage language,
581574
const DeclContext *dc);
582575

583-
/// Add a declaration to a list of declarations that need to be emitted
584-
/// as part of the current module or source file, but are otherwise not
585-
/// nested within it.
586-
void addExternalDecl(Decl *decl);
587-
588576
/// Add a declaration that was synthesized to a per-source file list if
589-
/// if is part of a source file, or the external declarations list if
590-
/// it is part of an imported type context.
577+
/// if is part of a source file.
591578
void addSynthesizedDecl(Decl *decl);
592579

593580
/// Add a cleanup function to be called when the ASTContext is deallocated.

include/swift/Basic/Statistics.def

-3
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ FRONTEND_STATISTIC(AST, NumLinkLibraries)
105105
/// Number of top-level modules loaded in the AST context.
106106
FRONTEND_STATISTIC(AST, NumLoadedModules)
107107

108-
/// Number of external definitions imported into the AST context.
109-
FRONTEND_STATISTIC(AST, NumImportedExternalDefinitions)
110-
111108
/// Number of Clang entities imported into the AST context.
112109
FRONTEND_STATISTIC(AST, NumTotalClangImportedEntities)
113110

lib/AST/ASTContext.cpp

+3-14
Original file line numberDiff line numberDiff line change
@@ -1362,20 +1362,10 @@ bool ASTContext::hasArrayLiteralIntrinsics() const {
13621362
&& getDeallocateUninitializedArray();
13631363
}
13641364

1365-
void ASTContext::addExternalDecl(Decl *decl) {
1366-
ExternalDefinitions.insert(decl);
1367-
}
1368-
13691365
void ASTContext::addSynthesizedDecl(Decl *decl) {
1370-
auto *mod = cast<FileUnit>(decl->getDeclContext()->getModuleScopeContext());
1371-
if (mod->getKind() == FileUnitKind::ClangModule ||
1372-
mod->getKind() == FileUnitKind::DWARFModule ||
1373-
mod->getKind() == FileUnitKind::SerializedAST) {
1374-
ExternalDefinitions.insert(decl);
1375-
return;
1376-
}
1377-
1378-
cast<SourceFile>(mod)->SynthesizedDecls.push_back(decl);
1366+
auto *fileUnit = decl->getDeclContext()->getModuleScopeContext();
1367+
if (auto *sf = dyn_cast<SourceFile>(fileUnit))
1368+
sf->SynthesizedDecls.push_back(decl);
13791369
}
13801370

13811371
void ASTContext::addCleanup(std::function<void(void)> cleanup) {
@@ -2050,7 +2040,6 @@ ASTContext::takeDelayedConformanceDiags(NormalProtocolConformance *conformance){
20502040
size_t ASTContext::getTotalMemory() const {
20512041
size_t Size = sizeof(*this) +
20522042
// LoadedModules ?
2053-
// ExternalDefinitions ?
20542043
llvm::capacity_in_bytes(CanonicalGenericTypeParamTypeNames) +
20552044
// RemappedTypes ?
20562045
sizeof(getImpl()) +

lib/ClangImporter/ImportDecl.cpp

+3-56
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,7 @@ makeEnumRawValueConstructor(ClangImporter::Implementation &Impl,
538538

539539
ctorDecl->setBody(body);
540540
ctorDecl->setBodyTypeCheckedIfPresent();
541-
542-
Impl.registerExternalDecl(ctorDecl);
543-
541+
544542
return ctorDecl;
545543
}
546544

@@ -616,7 +614,7 @@ static AccessorDecl *makeEnumRawValueGetter(ClangImporter::Implementation &Impl,
616614

617615
getterDecl->setBody(body);
618616
getterDecl->setBodyTypeCheckedIfPresent();
619-
Impl.registerExternalDecl(getterDecl);
617+
620618
return getterDecl;
621619
}
622620

@@ -694,7 +692,6 @@ static AccessorDecl *makeStructRawValueGetter(
694692
getterDecl->setBody(body);
695693
getterDecl->setBodyTypeCheckedIfPresent();
696694

697-
Impl.registerExternalDecl(getterDecl);
698695
return getterDecl;
699696
}
700697

@@ -854,7 +851,6 @@ makeIndirectFieldAccessors(ClangImporter::Implementation &Impl,
854851
getterDecl->setBody(body);
855852
getterDecl->setBodyTypeCheckedIfPresent();
856853
getterDecl->getAttrs().add(new (C) TransparentAttr(/*implicit*/ true));
857-
Impl.registerExternalDecl(getterDecl);
858854
}
859855

860856
// Synthesize the setter body
@@ -886,7 +882,6 @@ makeIndirectFieldAccessors(ClangImporter::Implementation &Impl,
886882
setterDecl->setBody(body);
887883
setterDecl->setBodyTypeCheckedIfPresent();
888884
setterDecl->getAttrs().add(new (C) TransparentAttr(/*implicit*/ true));
889-
Impl.registerExternalDecl(setterDecl);
890885
}
891886

892887
return { getterDecl, setterDecl };
@@ -964,7 +959,6 @@ makeUnionFieldAccessors(ClangImporter::Implementation &Impl,
964959
getterDecl->setBody(body);
965960
getterDecl->setBodyTypeCheckedIfPresent();
966961
getterDecl->getAttrs().add(new (C) TransparentAttr(/*implicit*/ true));
967-
Impl.registerExternalDecl(getterDecl);
968962
}
969963

970964
// Synthesize the setter body
@@ -1026,7 +1020,6 @@ makeUnionFieldAccessors(ClangImporter::Implementation &Impl,
10261020
setterDecl->setBody(body);
10271021
setterDecl->setBodyTypeCheckedIfPresent();
10281022
setterDecl->getAttrs().add(new (C) TransparentAttr(/*implicit*/ true));
1029-
Impl.registerExternalDecl(setterDecl);
10301023
}
10311024

10321025
return { getterDecl, setterDecl };
@@ -1160,8 +1153,6 @@ makeBitFieldAccessors(ClangImporter::Implementation &Impl,
11601153
cGetterExpr,
11611154
nullptr);
11621155
cGetterDecl->setBody(cGetterBody);
1163-
1164-
Impl.registerExternalDecl(getterDecl);
11651156
}
11661157

11671158
// Synthesize the setter body
@@ -1218,8 +1209,6 @@ makeBitFieldAccessors(ClangImporter::Implementation &Impl,
12181209
clang::FPOptions());
12191210

12201211
cSetterDecl->setBody(cSetterExpr);
1221-
1222-
Impl.registerExternalDecl(setterDecl);
12231212
}
12241213

12251214
return { getterDecl, setterDecl };
@@ -1296,9 +1285,6 @@ createDefaultConstructor(ClangImporter::Implementation &Impl,
12961285
constructor->setBody(body);
12971286
constructor->setBodyTypeCheckedIfPresent();
12981287

1299-
// Add this as an external definition.
1300-
Impl.registerExternalDecl(constructor);
1301-
13021288
// We're done.
13031289
return constructor;
13041290
}
@@ -1419,9 +1405,6 @@ createValueConstructor(ClangImporter::Implementation &Impl,
14191405
constructor->setBodyTypeCheckedIfPresent();
14201406
}
14211407

1422-
// Add this as an external definition.
1423-
Impl.registerExternalDecl(constructor);
1424-
14251408
// We're done.
14261409
return constructor;
14271410
}
@@ -1930,8 +1913,7 @@ static bool addErrorDomain(NominalTypeDecl *swiftDecl,
19301913
getterDecl->setBody(
19311914
BraceStmt::create(C, SourceLoc(), {ret}, SourceLoc(), isImplicit));
19321915
getterDecl->setBodyTypeCheckedIfPresent();
1933-
1934-
importer.registerExternalDecl(getterDecl);
1916+
19351917
return true;
19361918
}
19371919

@@ -3080,12 +3062,6 @@ namespace {
30803062
}
30813063
}
30823064

3083-
// Add the type decl to ExternalDefinitions so that we can type-check
3084-
// raw values and SILGen can emit witness tables for derived conformances.
3085-
// FIXME: There might be better ways to do this.
3086-
Impl.registerExternalDecl(result);
3087-
if (errorWrapper)
3088-
Impl.registerExternalDecl(errorWrapper);
30893065
return result;
30903066
}
30913067

@@ -3327,11 +3303,6 @@ namespace {
33273303

33283304
result->setHasUnreferenceableStorage(hasUnreferenceableStorage);
33293305

3330-
// Add the struct decl to ExternalDefinitions so that IRGen can emit
3331-
// metadata for it.
3332-
// FIXME: There might be better ways to do this.
3333-
Impl.registerExternalDecl(result);
3334-
33353306
return result;
33363307
}
33373308

@@ -3644,14 +3615,6 @@ namespace {
36443615

36453616
void finishFuncDecl(const clang::FunctionDecl *decl,
36463617
AbstractFunctionDecl *result) {
3647-
// Keep track of inline function bodies so that we can generate
3648-
// IR from them using Clang's IR generator.
3649-
if ((decl->isInlined() || decl->hasAttr<clang::AlwaysInlineAttr>() ||
3650-
!decl->isExternallyVisible()) &&
3651-
decl->hasBody()) {
3652-
Impl.registerExternalDecl(result);
3653-
}
3654-
36553618
// Set availability.
36563619
if (decl->isVariadic()) {
36573620
Impl.markUnavailable(result, "Variadic function is unavailable");
@@ -3819,9 +3782,6 @@ namespace {
38193782
result->getAttrs().add(new (Impl.SwiftContext)
38203783
FinalAttr(/*IsImplicit=*/true));
38213784

3822-
if (!decl->hasExternalStorage())
3823-
Impl.registerExternalDecl(result);
3824-
38253785
// If this is a compatibility stub, mark it as such.
38263786
if (correctSwiftName)
38273787
markAsVariant(result, *correctSwiftName);
@@ -4533,11 +4493,6 @@ namespace {
45334493

45344494
result->setMemberLoader(&Impl, 0);
45354495

4536-
// Add the protocol decl to ExternalDefinitions so that IRGen can emit
4537-
// metadata for it.
4538-
// FIXME: There might be better ways to do this.
4539-
Impl.registerExternalDecl(result);
4540-
45414496
return result;
45424497
}
45434498

@@ -5149,7 +5104,6 @@ SwiftDeclConverter::importCFClassType(const clang::TypedefNameDecl *decl,
51495104
theClass->setAddedImplicitInitializers(); // suppress all initializers
51505105
theClass->setForeignClassKind(ClassDecl::ForeignKind::CFType);
51515106
addObjCAttribute(theClass, None);
5152-
Impl.registerExternalDecl(theClass);
51535107

51545108
if (superclass) {
51555109
SmallVector<TypeLoc, 4> inheritedTypes;
@@ -5438,7 +5392,6 @@ SwiftDeclConverter::importSwiftNewtype(const clang::TypedefNameDecl *decl,
54385392
}
54395393

54405394
Impl.ImportedDecls[{decl->getCanonicalDecl(), getVersion()}] = structDecl;
5441-
Impl.registerExternalDecl(structDecl);
54425395
return structDecl;
54435396
}
54445397

@@ -6341,9 +6294,6 @@ ConstructorDecl *SwiftDeclConverter::importConstructor(
63416294
// If this constructor overrides another constructor, mark it as such.
63426295
recordObjCOverride(result);
63436296

6344-
// Inform the context that we have external definitions.
6345-
Impl.registerExternalDecl(result);
6346-
63476297
return result;
63486298
}
63496299

@@ -8400,9 +8350,6 @@ ClangImporter::Implementation::createConstant(Identifier name, DeclContext *dc,
84008350
// Set the function up as the getter.
84018351
makeComputed(var, func, nullptr);
84028352

8403-
// Register this thunk as an external definition.
8404-
registerExternalDecl(func);
8405-
84068353
return var;
84078354
}
84088355

lib/ClangImporter/ImporterImpl.h

-5
Original file line numberDiff line numberDiff line change
@@ -606,11 +606,6 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
606606
bool shouldIgnoreBridgeHeaderTopLevelDecl(clang::Decl *D);
607607

608608
public:
609-
void registerExternalDecl(Decl *D) {
610-
if (!hasFinishedTypeChecking())
611-
SwiftContext.addExternalDecl(D);
612-
}
613-
614609
void recordImplicitUnwrapForDecl(Decl *decl, bool isIUO) {
615610
#if !defined(NDEBUG)
616611
Type ty;

lib/FrontendTool/FrontendTool.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,6 @@ static void countStatsPostSema(UnifiedStatsReporter &Stats,
509509

510510
auto const &AST = Instance.getASTContext();
511511
C.NumLoadedModules = AST.LoadedModules.size();
512-
C.NumImportedExternalDefinitions = AST.ExternalDefinitions.size();
513512

514513
if (auto *D = Instance.getDependencyTracker()) {
515514
C.NumDependencies = D->getDependencies().size();

lib/Sema/CodeSynthesis.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -1307,11 +1307,6 @@ void TypeChecker::synthesizeWitnessAccessorsForStorage(
13071307
assert(!accessor->hasBody());
13081308
accessor->setBodySynthesizer(&synthesizeAccessorBody);
13091309

1310-
// Make sure SILGen emits the accessor; on-demand accessors have shared
1311-
// linkage, and if its defined in a different translation unit from the
1312-
// conformance we cannot simply generate an external declaration.
1313-
Context.addExternalDecl(accessor);
1314-
13151310
maybeMarkTransparent(accessor, Context);
13161311
DeclsToFinalize.insert(accessor);
13171312
}

lib/Sema/TypeChecker.cpp

-21
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ static void bindExtensions(SourceFile &SF, TypeChecker &TC) {
294294

295295
static void typeCheckFunctionsAndExternalDecls(SourceFile &SF, TypeChecker &TC) {
296296
unsigned currentFunctionIdx = 0;
297-
unsigned currentExternalDef = TC.Context.LastCheckedExternalDefinition;
298297
unsigned currentSynthesizedDecl = SF.LastCheckedSynthesizedDecl;
299298
do {
300299
// Type check conformance contexts.
@@ -323,24 +322,6 @@ static void typeCheckFunctionsAndExternalDecls(SourceFile &SF, TypeChecker &TC)
323322
TC.typeCheckAbstractFunctionBody(AFD);
324323
}
325324

326-
// Type check external definitions.
327-
for (unsigned n = TC.Context.ExternalDefinitions.size();
328-
currentExternalDef != n;
329-
++currentExternalDef) {
330-
auto decl = TC.Context.ExternalDefinitions[currentExternalDef];
331-
332-
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(decl)) {
333-
TC.typeCheckAbstractFunctionBody(AFD);
334-
TC.checkFunctionErrorHandling(AFD);
335-
continue;
336-
}
337-
if (isa<NominalTypeDecl>(decl))
338-
continue;
339-
if (isa<VarDecl>(decl))
340-
continue;
341-
llvm_unreachable("Unhandled external definition kind");
342-
}
343-
344325
// Validate any referenced declarations for SIL's purposes.
345326
// Note: if we ever start putting extension members in vtables, we'll need
346327
// to validate those members too.
@@ -384,15 +365,13 @@ static void typeCheckFunctionsAndExternalDecls(SourceFile &SF, TypeChecker &TC)
384365
TC.UsedConformances.clear();
385366

386367
} while (currentFunctionIdx < TC.definedFunctions.size() ||
387-
currentExternalDef < TC.Context.ExternalDefinitions.size() ||
388368
currentSynthesizedDecl < SF.SynthesizedDecls.size() ||
389369
TC.NextDeclToFinalize < TC.DeclsToFinalize.size() ||
390370
!TC.ConformanceContexts.empty() ||
391371
!TC.UsedConformances.empty() ||
392372
!TC.PartiallyCheckedConformances.empty());
393373

394374
// FIXME: Horrible hack. Store this somewhere more appropriate.
395-
TC.Context.LastCheckedExternalDefinition = currentExternalDef;
396375
SF.LastCheckedSynthesizedDecl = currentSynthesizedDecl;
397376

398377
// Now that all types have been finalized, run any delayed

0 commit comments

Comments
 (0)