Skip to content

Commit d68866c

Browse files
[NFC] Explain the order for adding module loaders.
1 parent 8f55e42 commit d68866c

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

lib/Frontend/Frontend.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,23 @@ void CompilerInstance::setUpDiagnosticOptions() {
317317
}
318318
}
319319

320+
// The ordering of ModuleLoaders is important!
321+
//
322+
// 1. SourceLoader: This is a hack and only the compiler's tests are using it,
323+
// to avoid writing repetitive code involving generating modules/interfaces.
324+
// Ideally, we'd get rid of it.
325+
// 2. MemoryBufferSerializedModuleLoader: This is used by LLDB, because it might
326+
// already have the module available in memory.
327+
// 3. ModuleInterfaceLoader: Tries to find an up-to-date swiftmodule. If it
328+
// succeeds, it issues a particular "error" (see
329+
// [Note: ModuleInterfaceLoader-defer-to-SerializedModuleLoader]), which
330+
// is interpreted by the overarching loader as a command to use the
331+
// SerializedModuleLoader. If we failed to find a .swiftmodule, this falls
332+
// back to using an interface. Actual errors lead to diagnostics.
333+
// 4. SerializedModuleLoader: Loads a serialized module if it can.
334+
// 5. ClangImporter: This must come after all the Swift module loaders because
335+
// in the presence of overlays and mixed-source frameworks, we want to prefer
336+
// the overlay or framework module over the underlying Clang module.
320337
bool CompilerInstance::setUpModuleLoaders() {
321338
if (hasSourceImport()) {
322339
bool enableLibraryEvolution =
@@ -353,10 +370,6 @@ bool CompilerInstance::setUpModuleLoaders() {
353370
Context->addModuleLoader(std::move(MemoryBufferLoader));
354371
}
355372

356-
std::unique_ptr<SerializedModuleLoader> SML =
357-
SerializedModuleLoader::create(*Context, getDependencyTracker(), MLM);
358-
this->SML = SML.get();
359-
360373
// Wire up the Clang importer. If the user has specified an SDK, use it.
361374
// Otherwise, we just keep it around as our interface to Clang's ABI
362375
// knowledge.
@@ -379,7 +392,12 @@ bool CompilerInstance::setUpModuleLoaders() {
379392
FEOpts.RemarkOnRebuildFromModuleInterface);
380393
Context->addModuleLoader(std::move(PIML));
381394
}
395+
396+
std::unique_ptr<SerializedModuleLoader> SML =
397+
SerializedModuleLoader::create(*Context, getDependencyTracker(), MLM);
398+
this->SML = SML.get();
382399
Context->addModuleLoader(std::move(SML));
400+
383401
Context->addModuleLoader(std::move(clangImporter), /*isClang*/ true);
384402

385403
return false;

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ class ModuleInterfaceLoaderImpl {
764764
}
765765
}
766766

767+
// [Note: ModuleInterfaceLoader-defer-to-SerializedModuleLoader]
767768
// Finally, if there's a module adjacent to the .swiftinterface that we can
768769
// _likely_ load (it validates OK and is up to date), bail early with
769770
// errc::not_supported, so the next (serialized) loader in the chain will

0 commit comments

Comments
 (0)