@@ -187,6 +187,82 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
187187 std::vector<std::pair<std::string, MacroPluginDependency>> macroDependencies;
188188 std::vector<std::string> auxiliaryFiles;
189189
190+ auto addCommonDependencyInfo =
191+ [¤tModuleImports,
192+ ¤tOptionalModuleImports,
193+ &importedClangDependenciesIDs,
194+ &auxiliaryFiles,
195+ ¯oDependencies] (ModuleDependencyInfo &moduleDep) {
196+ // Add imports of this module
197+ for (const auto &moduleName : currentModuleImports)
198+ moduleDep.addModuleImport (moduleName.importIdentifier );
199+ // Add optional imports of this module
200+ for (const auto &moduleName : currentOptionalModuleImports)
201+ moduleDep.addOptionalModuleImport (moduleName.importIdentifier );
202+
203+ // Add qualified dependencies of this module
204+ moduleDep.setImportedClangDependencies (importedClangDependenciesIDs);
205+
206+ // Add any auxiliary files
207+ moduleDep.setAuxiliaryFiles (auxiliaryFiles);
208+
209+ // Add macro dependencies
210+ for (const auto &md: macroDependencies)
211+ moduleDep.addMacroDependency (md.first ,
212+ md.second .LibraryPath ,
213+ md.second .ExecutablePath );
214+
215+ moduleDep.setIsFinalized (true );
216+ };
217+
218+ auto addSwiftTextualDependencyInfo =
219+ [this ,
220+ &importedSwiftDependenciesIDs,
221+ &crossImportOverlayDependenciesIDs,
222+ &swiftOverlayDependenciesIDs] (ModuleDependencyInfo &moduleDep,
223+ unsigned bridgingHeaderFileID,
224+ unsigned bridgingSourceFilesArrayID,
225+ unsigned bridgingModuleDependenciesArrayID,
226+ unsigned bridgingHeaderIncludeTreeID) {
227+
228+ moduleDep.setImportedSwiftDependencies (importedSwiftDependenciesIDs);
229+ moduleDep.setCrossImportOverlayDependencies (crossImportOverlayDependenciesIDs);
230+ moduleDep.setSwiftOverlayDependencies (swiftOverlayDependenciesIDs);
231+
232+ // Add bridging header file path
233+ if (bridgingHeaderFileID != 0 ) {
234+ auto bridgingHeaderFile = getIdentifier (bridgingHeaderFileID);
235+ if (!bridgingHeaderFile)
236+ llvm::report_fatal_error (" Bad bridging header path" );
237+
238+ moduleDep.addBridgingHeader (*bridgingHeaderFile);
239+ }
240+
241+ // Add bridging source files
242+ auto bridgingSourceFiles = getStringArray (bridgingSourceFilesArrayID);
243+ if (!bridgingSourceFiles)
244+ llvm::report_fatal_error (" Bad bridging source files" );
245+ for (const auto &file : *bridgingSourceFiles)
246+ moduleDep.addHeaderSourceFile (file);
247+
248+ // Add bridging module dependencies
249+ auto bridgingModuleDeps = getStringArray (bridgingModuleDependenciesArrayID);
250+ if (!bridgingModuleDeps)
251+ llvm::report_fatal_error (" Bad bridging module dependencies" );
252+ llvm::StringSet<> alreadyAdded;
253+ std::vector<ModuleDependencyID> bridgingModuleDepIDs;
254+ for (const auto &mod : bridgingModuleDeps.value ())
255+ bridgingModuleDepIDs.push_back (ModuleDependencyID{mod, ModuleDependencyKind::Clang});
256+ moduleDep.setHeaderClangDependencies (bridgingModuleDepIDs);
257+
258+ // Add bridging header include tree
259+ auto bridgingHeaderIncludeTree = getIdentifier (bridgingHeaderIncludeTreeID);
260+ if (!bridgingHeaderIncludeTree)
261+ llvm::report_fatal_error (" Bad bridging header include tree" );
262+ if (!bridgingHeaderIncludeTree->empty ())
263+ moduleDep.addBridgingHeaderIncludeTree (*bridgingHeaderIncludeTree);
264+ };
265+
190266 while (!Cursor.AtEndOfStream ()) {
191267 auto entry = cantFail (Cursor.advance (), " Advance bitstream cursor" );
192268
@@ -307,9 +383,10 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
307383 if (!moduleName)
308384 llvm::report_fatal_error (" Bad module name" );
309385 currentModuleName = *moduleName;
386+
387+ // ACTODO: Proper import infos.
310388 auto importStrings = getStringArray (moduleImportsArrayID);
311389 auto optionalImportStrings = getStringArray (optionalModuleImportsArrayID);
312- // ACTODO: Proper import infos.
313390 currentModuleImports.clear ();
314391 currentOptionalModuleImports.clear ();
315392 if (importStrings.has_value ())
@@ -420,76 +497,19 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
420497 if (!userModuleVersion)
421498 llvm::report_fatal_error (" Bad userModuleVersion" );
422499
423- // TODO: MacroDependencies
424500 // Form the dependencies storage object
425501 auto moduleDep = ModuleDependencyInfo::forSwiftInterfaceModule (
426502 outputModulePath.value (), optionalSwiftInterfaceFile.value (),
427503 compiledCandidatesRefs, buildCommandRefs, linkLibraries, extraPCMRefs,
428504 *contextHash, isFramework, isStatic, *rootFileSystemID, *moduleCacheKey,
429505 *userModuleVersion);
430506
431- // Add imports of this module
432- for (const auto &moduleName : currentModuleImports)
433- moduleDep.addModuleImport (moduleName.importIdentifier );
434- // Add optional imports of this module
435- for (const auto &moduleName : currentOptionalModuleImports)
436- moduleDep.addOptionalModuleImport (moduleName.importIdentifier );
437-
438- // Add qualified dependencies of this module
439- moduleDep.setImportedSwiftDependencies (importedSwiftDependenciesIDs);
440- moduleDep.setImportedClangDependencies (importedClangDependenciesIDs);
441- moduleDep.setCrossImportOverlayDependencies (crossImportOverlayDependenciesIDs);
442- moduleDep.setSwiftOverlayDependencies (swiftOverlayDependenciesIDs);
443- moduleDep.setAuxiliaryFiles (auxiliaryFiles);
444-
445- // Add bridging header file path
446- if (bridgingHeaderFileID != 0 ) {
447- auto bridgingHeaderFile = getIdentifier (bridgingHeaderFileID);
448- if (!bridgingHeaderFile)
449- llvm::report_fatal_error (" Bad bridging header path" );
450-
451- moduleDep.addBridgingHeader (*bridgingHeaderFile);
452- }
453-
454- // Add bridging source files
455- auto bridgingSourceFiles = getStringArray (bridgingSourceFilesArrayID);
456- if (!bridgingSourceFiles)
457- llvm::report_fatal_error (" Bad bridging source files" );
458- for (const auto &file : *bridgingSourceFiles)
459- moduleDep.addHeaderSourceFile (file);
460-
461- // Add source files
462- auto sourceFiles = getStringArray (sourceFilesArrayID);
463- if (!sourceFiles)
464- llvm::report_fatal_error (" Bad bridging source files" );
465- for (const auto &file : *sourceFiles)
466- moduleDep.addSourceFile (file);
507+ addCommonDependencyInfo (moduleDep);
508+ addSwiftTextualDependencyInfo (moduleDep, bridgingHeaderFileID,
509+ bridgingSourceFilesArrayID,
510+ bridgingModuleDependenciesArrayID,
511+ bridgingHeaderIncludeTreeID);
467512
468- // Add bridging module dependencies
469- auto bridgingModuleDeps = getStringArray (bridgingModuleDependenciesArrayID);
470- if (!bridgingModuleDeps)
471- llvm::report_fatal_error (" Bad bridging module dependencies" );
472- llvm::StringSet<> alreadyAdded;
473- std::vector<ModuleDependencyID> bridgingModuleDepIDs;
474- for (const auto &mod : bridgingModuleDeps.value ())
475- bridgingModuleDepIDs.push_back (ModuleDependencyID{mod, ModuleDependencyKind::Clang});
476- moduleDep.setHeaderClangDependencies (bridgingModuleDepIDs);
477-
478- // Add bridging header include tree
479- auto bridgingHeaderIncludeTree =
480- getIdentifier (bridgingHeaderIncludeTreeID);
481- if (!bridgingHeaderIncludeTree)
482- llvm::report_fatal_error (" Bad bridging header include tree" );
483- if (!bridgingHeaderIncludeTree->empty ())
484- moduleDep.addBridgingHeaderIncludeTree (*bridgingHeaderIncludeTree);
485-
486- // Add macro dependencies
487- for (const auto &md: macroDependencies)
488- moduleDep.addMacroDependency (md.first ,
489- md.second .LibraryPath ,
490- md.second .ExecutablePath );
491-
492- moduleDep.setIsFinalized (true );
493513 cache.recordDependency (currentModuleName, std::move (moduleDep));
494514 hasCurrentModule = false ;
495515 break ;
@@ -540,68 +560,19 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
540560 *rootFileSystemID, buildCommandRefs, bridgingHeaderBuildCommandRefs,
541561 extraPCMRefs);
542562
543- // Add imports of this module
544- for (const auto &moduleName : currentModuleImports)
545- moduleDep.addModuleImport (moduleName.importIdentifier );
546- // Add optional imports of this module
547- for (const auto &moduleName : currentOptionalModuleImports)
548- moduleDep.addOptionalModuleImport (moduleName.importIdentifier );
549-
550- // Add qualified dependencies of this module
551- moduleDep.setImportedSwiftDependencies (importedSwiftDependenciesIDs);
552- moduleDep.setImportedClangDependencies (importedClangDependenciesIDs);
553- moduleDep.setCrossImportOverlayDependencies (crossImportOverlayDependenciesIDs);
554- moduleDep.setSwiftOverlayDependencies (swiftOverlayDependenciesIDs);
555-
556- // Add bridging header file path
557- if (bridgingHeaderFileID != 0 ) {
558- auto bridgingHeaderFile = getIdentifier (bridgingHeaderFileID);
559- if (!bridgingHeaderFile)
560- llvm::report_fatal_error (" Bad bridging header path" );
561-
562- moduleDep.addBridgingHeader (*bridgingHeaderFile);
563- }
564-
565- // Add bridging source files
566- auto bridgingSourceFiles = getStringArray (bridgingSourceFilesArrayID);
567- if (!bridgingSourceFiles)
568- llvm::report_fatal_error (" Bad bridging source files" );
569- for (const auto &file : *bridgingSourceFiles)
570- moduleDep.addHeaderSourceFile (file);
571-
572563 // Add source files
573564 auto sourceFiles = getStringArray (sourceFilesArrayID);
574565 if (!sourceFiles)
575566 llvm::report_fatal_error (" Bad bridging source files" );
576567 for (const auto &file : *sourceFiles)
577568 moduleDep.addSourceFile (file);
578569
579- // Add bridging module dependencies
580- auto bridgingModuleDeps = getStringArray (bridgingModuleDependenciesArrayID);
581- if (!bridgingModuleDeps)
582- llvm::report_fatal_error ( " Bad bridging module dependencies " );
583- llvm::StringSet<> alreadyAdded ;
570+ addCommonDependencyInfo (moduleDep);
571+ addSwiftTextualDependencyInfo (moduleDep, bridgingHeaderFileID,
572+ bridgingSourceFilesArrayID,
573+ bridgingModuleDependenciesArrayID,
574+ bridgingHeaderIncludeTreeID) ;
584575
585- std::vector<ModuleDependencyID> headerDependencyIDs;
586- for (const auto &mod : *bridgingModuleDeps)
587- headerDependencyIDs.push_back ({mod, ModuleDependencyKind::Clang});
588- moduleDep.setHeaderClangDependencies (headerDependencyIDs);
589-
590- // Add bridging header include tree
591- auto bridgingHeaderIncludeTree =
592- getIdentifier (bridgingHeaderIncludeTreeID);
593- if (!bridgingHeaderIncludeTree)
594- llvm::report_fatal_error (" Bad bridging header include tree" );
595- if (!bridgingHeaderIncludeTree->empty ())
596- moduleDep.addBridgingHeaderIncludeTree (*bridgingHeaderIncludeTree);
597-
598- // Add macro dependencies
599- for (const auto &md: macroDependencies)
600- moduleDep.addMacroDependency (md.first ,
601- md.second .LibraryPath ,
602- md.second .ExecutablePath );
603-
604- moduleDep.setIsFinalized (true );
605576 cache.recordDependency (currentModuleName, std::move (moduleDep));
606577 hasCurrentModule = false ;
607578 break ;
@@ -651,18 +622,7 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
651622 *headerImport, *definingInterfacePath, isFramework, isStatic,
652623 *moduleCacheKey, *userModuleVersion);
653624
654- // Add imports of this module
655- for (const auto &moduleName : currentModuleImports)
656- moduleDep.addModuleImport (moduleName.importIdentifier );
657- // Add optional imports of this module
658- for (const auto &moduleName : currentOptionalModuleImports)
659- moduleDep.addOptionalModuleImport (moduleName.importIdentifier );
660-
661- // Add qualified dependencies of this module
662- moduleDep.setImportedSwiftDependencies (importedSwiftDependenciesIDs);
663- moduleDep.setImportedClangDependencies (importedClangDependenciesIDs);
664- moduleDep.setCrossImportOverlayDependencies (crossImportOverlayDependenciesIDs);
665- moduleDep.setSwiftOverlayDependencies (swiftOverlayDependenciesIDs);
625+ addCommonDependencyInfo (moduleDep);
666626
667627 auto headerModuleDependencies = getStringArray (headerModuleDependenciesArrayID);
668628 if (!headerModuleDependencies)
@@ -682,13 +642,6 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
682642 for (const auto &depSource : *headerImportsSourceFiles)
683643 moduleDep.addHeaderSourceFile (depSource);
684644
685- // Add macro dependencies
686- for (const auto &md: macroDependencies)
687- moduleDep.addMacroDependency (md.first ,
688- md.second .LibraryPath ,
689- md.second .ExecutablePath );
690-
691- moduleDep.setIsFinalized (true );
692645 cache.recordDependency (currentModuleName, std::move (moduleDep));
693646 hasCurrentModule = false ;
694647 break ;
@@ -717,14 +670,6 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
717670 auto moduleDep = ModuleDependencyInfo::forPlaceholderSwiftModuleStub (
718671 *compiledModulePath, *moduleDocPath, *moduleSourceInfoPath);
719672
720-
721- // Add dependencies of this module
722- for (const auto &moduleName : currentModuleImports)
723- moduleDep.addModuleImport (moduleName.importIdentifier );
724- // Add optional imports of this module
725- for (const auto &moduleName : currentOptionalModuleImports)
726- moduleDep.addOptionalModuleImport (moduleName.importIdentifier );
727-
728673 cache.recordDependency (currentModuleName, std::move (moduleDep));
729674 hasCurrentModule = false ;
730675 break ;
@@ -777,20 +722,8 @@ bool ModuleDependenciesCacheDeserializer::readGraph(ModuleDependenciesCache &cac
777722 *pcmOutputPath, *mappedPCMPath, *moduleMapPath, *contextHash,
778723 *commandLineArgs, *fileDependencies, *capturedPCMArgs, linkLibraries,
779724 *rootFileSystemID, *clangIncludeTreeRoot, *moduleCacheKey, isSystem);
725+ addCommonDependencyInfo (moduleDep);
780726
781- // Add imports of this module
782- for (const auto &moduleName : currentModuleImports)
783- moduleDep.addModuleImport (moduleName.importIdentifier );
784- // Add qualified dependencies of this module
785- moduleDep.setImportedClangDependencies (importedClangDependenciesIDs);
786-
787- // Add macro dependencies
788- for (const auto &md: macroDependencies)
789- moduleDep.addMacroDependency (md.first ,
790- md.second .LibraryPath ,
791- md.second .ExecutablePath );
792-
793- moduleDep.setIsFinalized (true );
794727 cache.recordDependency (currentModuleName, std::move (moduleDep));
795728 hasCurrentModule = false ;
796729 break ;
0 commit comments