Skip to content

Commit cbb6e69

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
1 parent 846a861 commit cbb6e69

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
@@ -1314,7 +1314,7 @@ ASTContext::synthesizeInvertibleProtocolDecl(InvertibleProtocolKind ip) const {
13141314

13151315
ModuleDecl *stdlib = getStdlibModule();
13161316
FileUnit *file = nullptr;
1317-
if (stdlib) {
1317+
if (stdlib && stdlib->hasFiles()) {
13181318
file = &stdlib->getFiles()[0]->getOrCreateSynthesizedFile();
13191319
} else {
13201320
file = &TheBuiltinModule->getMainFile(FileUnitKind::Builtin);
@@ -1338,7 +1338,7 @@ ASTContext::synthesizeInvertibleProtocolDecl(InvertibleProtocolKind ip) const {
13381338
protocol->setAccess(AccessLevel::Public);
13391339

13401340
// Hack to get name lookup to work after synthesizing it into the stdlib.
1341-
if (stdlib) {
1341+
if (stdlib && stdlib->hasFiles()) {
13421342
cast<SynthesizedFileUnit>(file)->addTopLevelDecl(protocol);
13431343
stdlib->clearLookupCache();
13441344
}

0 commit comments

Comments
 (0)