Skip to content

Commit 211c580

Browse files
committed
[Cleanup] Eliminate DerivedFileUnit.
The only client of DerivedFileUnit was synthesized global '==' operators for Equatable conformances, which has since been removed.
1 parent 1dcfd33 commit 211c580

File tree

6 files changed

+11
-152
lines changed

6 files changed

+11
-152
lines changed

include/swift/AST/Module.h

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ namespace swift {
5353
class ExtensionDecl;
5454
class DebuggerClient;
5555
class DeclName;
56-
class DerivedFileUnit;
5756
class FileUnit;
5857
class FuncDecl;
5958
class InfixOperatorDecl;
@@ -238,8 +237,6 @@ class ModuleDecl : public TypeDecl, public DeclContext {
238237
/// dealing with.
239238
FileUnit &getMainFile(FileUnitKind expectedKind) const;
240239

241-
DerivedFileUnit &getDerivedFileUnit() const;
242-
243240
DebuggerClient *getDebugClient() const { return DebugClient; }
244241
void setDebugClient(DebuggerClient *R) {
245242
assert(!DebugClient && "Debugger client already set");
@@ -750,47 +747,6 @@ class FileUnit : public DeclContext {
750747
unsigned Alignment = alignof(FileUnit));
751748
};
752749

753-
/// A container for a module-level definition derived as part of an implicit
754-
/// protocol conformance.
755-
class DerivedFileUnit final : public FileUnit {
756-
TinyPtrVector<FuncDecl *> DerivedDecls;
757-
758-
public:
759-
DerivedFileUnit(ModuleDecl &M);
760-
~DerivedFileUnit() = default;
761-
762-
void addDerivedDecl(FuncDecl *FD) {
763-
DerivedDecls.push_back(FD);
764-
}
765-
766-
void lookupValue(ModuleDecl::AccessPathTy accessPath, DeclName name,
767-
NLKind lookupKind,
768-
SmallVectorImpl<ValueDecl*> &result) const override;
769-
770-
void lookupVisibleDecls(ModuleDecl::AccessPathTy accessPath,
771-
VisibleDeclConsumer &consumer,
772-
NLKind lookupKind) const override;
773-
774-
void getTopLevelDecls(SmallVectorImpl<Decl*> &results) const override;
775-
776-
void lookupObjCMethods(
777-
ObjCSelector selector,
778-
SmallVectorImpl<AbstractFunctionDecl *> &results) const override;
779-
780-
Identifier
781-
getDiscriminatorForPrivateValue(const ValueDecl *D) const override {
782-
llvm_unreachable("no private decls in the derived file unit");
783-
}
784-
785-
static bool classof(const FileUnit *file) {
786-
return file->getKind() == FileUnitKind::Derived;
787-
}
788-
static bool classof(const DeclContext *DC) {
789-
return isa<FileUnit>(DC) && classof(cast<FileUnit>(DC));
790-
}
791-
};
792-
793-
794750
/// A file containing Swift source code.
795751
///
796752
/// This is a .swift or .sil file (or a virtual file, such as the contents of

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,13 +1229,7 @@ void ASTContext::verifyAllLoadedModules() const {
12291229

12301230
for (auto &topLevelModulePair : LoadedModules) {
12311231
Module *M = topLevelModulePair.second;
1232-
bool hasAnyFileUnits = std::any_of(M->getFiles().begin(),
1233-
M->getFiles().end(),
1234-
[](const FileUnit *file) {
1235-
return !isa<DerivedFileUnit>(file);
1236-
});
1237-
if (!hasAnyFileUnits)
1238-
assert(M->failedToLoad());
1232+
assert(!M->getFiles().empty() || M->failedToLoad());
12391233
}
12401234
#endif
12411235
}

lib/AST/Module.cpp

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -347,35 +347,12 @@ ModuleDecl::ModuleDecl(Identifier name, ASTContext &ctx)
347347
}
348348

349349
void Module::addFile(FileUnit &newFile) {
350-
assert(!isa<DerivedFileUnit>(newFile) &&
351-
"DerivedFileUnits are added automatically");
352-
353350
// Require Main and REPL files to be the first file added.
354351
assert(Files.empty() ||
355352
!isa<SourceFile>(newFile) ||
356353
cast<SourceFile>(newFile).Kind == SourceFileKind::Library ||
357354
cast<SourceFile>(newFile).Kind == SourceFileKind::SIL);
358355
Files.push_back(&newFile);
359-
360-
switch (newFile.getKind()) {
361-
case FileUnitKind::Source:
362-
case FileUnitKind::ClangModule: {
363-
for (auto File : Files) {
364-
if (isa<DerivedFileUnit>(File))
365-
return;
366-
}
367-
auto DFU = new (getASTContext()) DerivedFileUnit(*this);
368-
Files.push_back(DFU);
369-
break;
370-
}
371-
372-
case FileUnitKind::Builtin:
373-
case FileUnitKind::SerializedAST:
374-
break;
375-
376-
case FileUnitKind::Derived:
377-
llvm_unreachable("DerivedFileUnits are added automatically");
378-
}
379356
}
380357

381358
void Module::removeFile(FileUnit &existingFile) {
@@ -390,15 +367,6 @@ void Module::removeFile(FileUnit &existingFile) {
390367
Files.erase(I.base());
391368
}
392369

393-
DerivedFileUnit &Module::getDerivedFileUnit() const {
394-
for (auto File : Files) {
395-
if (auto DFU = dyn_cast<DerivedFileUnit>(File))
396-
return *DFU;
397-
}
398-
llvm_unreachable("the client should not be calling this function if "
399-
"there is no DerivedFileUnit");
400-
}
401-
402370
VarDecl *Module::getDSOHandle() {
403371
if (DSOHandle)
404372
return DSOHandle;
@@ -540,58 +508,6 @@ void BuiltinUnit::lookupObjCMethods(
540508
// No @objc methods in the Builtin module.
541509
}
542510

543-
DerivedFileUnit::DerivedFileUnit(Module &M)
544-
: FileUnit(FileUnitKind::Derived, M) {
545-
M.getASTContext().addDestructorCleanup(*this);
546-
}
547-
548-
void DerivedFileUnit::lookupValue(Module::AccessPathTy accessPath,
549-
DeclName name,
550-
NLKind lookupKind,
551-
SmallVectorImpl<ValueDecl*> &result) const {
552-
// If this import is specific to some named type or decl ("import Swift.int")
553-
// then filter out any lookups that don't match.
554-
if (!Module::matchesAccessPath(accessPath, name))
555-
return;
556-
557-
for (auto D : DerivedDecls) {
558-
if (D->getFullName().matchesRef(name))
559-
result.push_back(D);
560-
}
561-
}
562-
563-
void DerivedFileUnit::lookupVisibleDecls(Module::AccessPathTy accessPath,
564-
VisibleDeclConsumer &consumer,
565-
NLKind lookupKind) const {
566-
assert(accessPath.size() <= 1 && "can only refer to top-level decls");
567-
568-
Identifier Id;
569-
if (!accessPath.empty()) {
570-
Id = accessPath.front().first;
571-
}
572-
573-
for (auto D : DerivedDecls) {
574-
if (Id.empty() || D->getName() == Id)
575-
consumer.foundDecl(D, DeclVisibilityKind::VisibleAtTopLevel);
576-
}
577-
}
578-
579-
void DerivedFileUnit::lookupObjCMethods(
580-
ObjCSelector selector,
581-
SmallVectorImpl<AbstractFunctionDecl *> &results) const {
582-
for (auto D : DerivedDecls) {
583-
if (auto func = dyn_cast<AbstractFunctionDecl>(D)) {
584-
if (func->isObjC() && func->getObjCSelector() == selector)
585-
results.push_back(func);
586-
}
587-
}
588-
}
589-
590-
void DerivedFileUnit::getTopLevelDecls(SmallVectorImpl<swift::Decl *> &results)
591-
const {
592-
results.append(DerivedDecls.begin(), DerivedDecls.end());
593-
}
594-
595511
void SourceFile::lookupValue(Module::AccessPathTy accessPath, DeclName name,
596512
NLKind lookupKind,
597513
SmallVectorImpl<ValueDecl*> &result) const {
@@ -1203,8 +1119,6 @@ StringRef Module::getModuleFilename() const {
12031119
Result = LF->getFilename();
12041120
continue;
12051121
}
1206-
if (isa<DerivedFileUnit>(F))
1207-
continue;
12081122
return StringRef();
12091123
}
12101124
return Result;

lib/Sema/CodeSynthesis.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ static void addMemberToContextIfNeeded(Decl *D, DeclContext *DC,
3737
ntd->addMember(D, Hint);
3838
} else if (auto *ed = dyn_cast<ExtensionDecl>(DC)) {
3939
ed->addMember(D, Hint);
40-
} else if (isa<SourceFile>(DC)) {
41-
auto *mod = DC->getParentModule();
42-
mod->getDerivedFileUnit().addDerivedDecl(cast<FuncDecl>(D));
4340
} else {
4441
assert((isa<AbstractFunctionDecl>(DC) || isa<FileUnit>(DC)) &&
4542
"Unknown declcontext");

test/SILGen/property_behavior.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extension behavior {
99
}
1010
}
1111

12-
// TODO: global accessor doesn't get walked because it's in DerivedFileUnit
12+
// TODO: global accessor doesn't get walked??
1313
var global: Int __behavior behavior
1414

1515
struct S1<T> {

unittests/AST/OverrideTests.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,36 +52,34 @@ class TestContext : public TestContextBase {
5252
SourceFile *FileForLookups;
5353

5454
void declareOptionalType(Identifier name) {
55-
auto wrapped = new (Ctx) GenericTypeParamDecl(File,
55+
auto wrapped = new (Ctx) GenericTypeParamDecl(FileForLookups,
5656
Ctx.getIdentifier("Wrapped"),
5757
SourceLoc(), /*depth*/0,
5858
/*index*/0);
5959
auto params = GenericParamList::create(Ctx, SourceLoc(), wrapped,
6060
SourceLoc());
6161
auto decl = new (Ctx) EnumDecl(SourceLoc(), name, SourceLoc(),
62-
/*inherited*/{}, params, File);
62+
/*inherited*/{}, params, FileForLookups);
6363
wrapped->setDeclContext(decl);
6464
FileForLookups->Decls.push_back(decl);
6565
}
6666

6767
public:
6868
ASTContext Ctx;
69-
DerivedFileUnit *File;
7069

7170
TestContext(ShouldDeclareOptionalTypes optionals = DoNotDeclareOptionalTypes)
7271
: Ctx(LangOpts, SearchPathOpts, SourceMgr, Diags) {
7372
auto stdlibID = Ctx.getIdentifier(STDLIB_NAME);
7473
auto *module = ModuleDecl::create(stdlibID, Ctx);
7574
Ctx.LoadedModules[stdlibID] = module;
76-
File = new (Ctx) DerivedFileUnit(*module);
7775

78-
if (optionals == DeclareOptionalTypes) {
79-
using ImplicitModuleImportKind = SourceFile::ImplicitModuleImportKind;
80-
FileForLookups = new (Ctx) SourceFile(*module, SourceFileKind::Library,
81-
/*buffer*/None,
82-
ImplicitModuleImportKind::None);
83-
module->addFile(*FileForLookups);
76+
using ImplicitModuleImportKind = SourceFile::ImplicitModuleImportKind;
77+
FileForLookups = new (Ctx) SourceFile(*module, SourceFileKind::Library,
78+
/*buffer*/None,
79+
ImplicitModuleImportKind::None);
80+
module->addFile(*FileForLookups);
8481

82+
if (optionals == DeclareOptionalTypes) {
8583
declareOptionalType(Ctx.getIdentifier("Optional"));
8684
declareOptionalType(Ctx.getIdentifier("ImplicitlyUnwrappedOptional"));
8785
}
@@ -92,7 +90,7 @@ class TestContext : public TestContextBase {
9290
GenericParamList *genericParams = nullptr) {
9391
auto result = new (Ctx) Nominal(SourceLoc(), Ctx.getIdentifier(name),
9492
SourceLoc(), /*inherited*/{},
95-
genericParams, File);
93+
genericParams, FileForLookups);
9694
result->setAccessibility(Accessibility::Internal);
9795
return result;
9896
}

0 commit comments

Comments
 (0)