Skip to content

Commit 39d37ed

Browse files
committed
NCGenerics: handle failure to load stdlib
The stdlib module can end up being a non-null ModuleDecl that contains no files, due to a failure to load the stdlib. In such an unusual case, fall-back to synthesizing Copyable/Escapable into the Builtin module so that Sema can proceed. rdar://129092011 (cherry picked from commit cbb6e69)
1 parent b5f1c07 commit 39d37ed

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

include/swift/AST/Module.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,10 @@ class ModuleDecl
387387
/// Only to be called by MemoryBufferSerializedModuleLoader.
388388
void setBypassResilience() { BypassResilience = true; }
389389

390+
bool hasFiles() const {
391+
return !Files.empty();
392+
}
393+
390394
ArrayRef<FileUnit *> getFiles() {
391395
assert(!Files.empty() || failedToLoad());
392396
return Files;

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ ASTContext::synthesizeInvertibleProtocolDecl(InvertibleProtocolKind ip) const {
12561256

12571257
ModuleDecl *stdlib = getStdlibModule();
12581258
FileUnit *file = nullptr;
1259-
if (stdlib) {
1259+
if (stdlib && stdlib->hasFiles()) {
12601260
file = &stdlib->getFiles()[0]->getOrCreateSynthesizedFile();
12611261
} else {
12621262
file = &TheBuiltinModule->getMainFile(FileUnitKind::Builtin);
@@ -1280,7 +1280,7 @@ ASTContext::synthesizeInvertibleProtocolDecl(InvertibleProtocolKind ip) const {
12801280
protocol->setAccess(AccessLevel::Public);
12811281

12821282
// Hack to get name lookup to work after synthesizing it into the stdlib.
1283-
if (stdlib) {
1283+
if (stdlib && stdlib->hasFiles()) {
12841284
cast<SynthesizedFileUnit>(file)->addTopLevelDecl(protocol);
12851285
stdlib->clearLookupCache();
12861286
}

0 commit comments

Comments
 (0)