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