@@ -318,6 +318,23 @@ void CompilerInstance::setUpDiagnosticOptions() {
318
318
}
319
319
}
320
320
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.
321
338
bool CompilerInstance::setUpModuleLoaders () {
322
339
if (hasSourceImport ()) {
323
340
bool enableLibraryEvolution =
@@ -354,10 +371,6 @@ bool CompilerInstance::setUpModuleLoaders() {
354
371
Context->addModuleLoader (std::move (MemoryBufferLoader));
355
372
}
356
373
357
- std::unique_ptr<SerializedModuleLoader> SML =
358
- SerializedModuleLoader::create (*Context, getDependencyTracker (), MLM);
359
- this ->SML = SML.get ();
360
-
361
374
// Wire up the Clang importer. If the user has specified an SDK, use it.
362
375
// Otherwise, we just keep it around as our interface to Clang's ABI
363
376
// knowledge.
@@ -380,7 +393,12 @@ bool CompilerInstance::setUpModuleLoaders() {
380
393
FEOpts.RemarkOnRebuildFromModuleInterface );
381
394
Context->addModuleLoader (std::move (PIML));
382
395
}
396
+
397
+ std::unique_ptr<SerializedModuleLoader> SML =
398
+ SerializedModuleLoader::create (*Context, getDependencyTracker (), MLM);
399
+ this ->SML = SML.get ();
383
400
Context->addModuleLoader (std::move (SML));
401
+
384
402
Context->addModuleLoader (std::move (clangImporter), /* isClang*/ true );
385
403
386
404
return false ;
0 commit comments