Skip to content

Commit e85a715

Browse files
authored
Merge pull request swiftlang#27634 from varungandhi-apple/vg-add-module-loader-ordering-doc
2 parents 3bd45c8 + d68866c commit e85a715

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
@@ -318,6 +318,23 @@ void CompilerInstance::setUpDiagnosticOptions() {
318318
}
319319
}
320320

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

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

386404
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)