@@ -1021,7 +1021,10 @@ bool ClangImporter::canReadPCH(StringRef PCHFilename) {
10211021
10221022  //  Note: Reusing the file manager is safe; this is a component that's already
10231023  //  reused when building PCM files for the module cache.
1024-   CI.createSourceManager (Impl.Instance ->getFileManager ());
1024+   CI.setVirtualFileSystem (
1025+       Impl.Instance ->getFileManager ().getVirtualFileSystemPtr ());
1026+   CI.setFileManager (&Impl.Instance ->getFileManager ());
1027+   CI.createSourceManager ();
10251028  auto  &clangSrcMgr = CI.getSourceManager ();
10261029  auto  FID = clangSrcMgr.createFileID (
10271030                        std::make_unique<ZeroFilledMemoryBuffer>(1 , " <main>" 
@@ -1402,21 +1405,15 @@ std::unique_ptr<ClangImporter> ClangImporter::create(
14021405  if  (tracker)
14031406    instance.addDependencyCollector (tracker->getClangCollector ());
14041407
1405-   {
1406-     //  Now set up the real client for Clang diagnostics---configured with proper
1407-     //  options---as opposed to the temporary one we made above.
1408-     auto  actualDiagClient = std::make_unique<ClangDiagnosticConsumer>(
1409-         importer->Impl , instance.getDiagnosticOpts (),
1410-         importerOpts.DumpClangDiagnostics );
1411-     instance.createDiagnostics (*VFS, actualDiagClient.release ());
1412-   }
1408+   //  Now set up the real client for Clang diagnostics---configured with proper
1409+   //  options---as opposed to the temporary one we made above.
1410+   auto  actualDiagClient = std::make_unique<ClangDiagnosticConsumer>(
1411+       importer->Impl , instance.getDiagnosticOpts (),
1412+       importerOpts.DumpClangDiagnostics );
14131413
1414-   //  Set up the file manager.
1415-   {
1416-     VFS = clang::createVFSFromCompilerInvocation (
1417-         instance.getInvocation (), instance.getDiagnostics (), std::move (VFS));
1418-     instance.createFileManager (VFS);
1419-   }
1414+   instance.createVirtualFileSystem (std::move (VFS), actualDiagClient.get ());
1415+   instance.createFileManager ();
1416+   instance.createDiagnostics (actualDiagClient.release ());
14201417
14211418  //  Don't stop emitting messages if we ever can't load a module.
14221419  //  FIXME: This is actually a general problem: any "fatal" error could mess up
@@ -1435,11 +1432,13 @@ std::unique_ptr<ClangImporter> ClangImporter::create(
14351432  if  (ctx.LangOpts .ClangTarget .has_value ()) {
14361433    //  If '-clang-target' is set, create a mock invocation with the Swift triple
14371434    //  to configure CodeGen and Target options for Swift compilation.
1438-     auto  swiftTargetClangArgs = importer->getClangCC1Arguments (ctx, VFS, true );
1435+     auto  swiftTargetClangArgs = importer->getClangCC1Arguments (
1436+         ctx, instance.getVirtualFileSystemPtr (), true );
14391437    if  (!swiftTargetClangArgs)
14401438      return  nullptr ;
14411439    auto  swiftTargetClangInvocation = createClangInvocation (
1442-         importer.get (), importerOpts, VFS, *swiftTargetClangArgs);
1440+         importer.get (), importerOpts, instance.getVirtualFileSystemPtr (),
1441+         *swiftTargetClangArgs);
14431442    if  (!swiftTargetClangInvocation)
14441443      return  nullptr ;
14451444
@@ -1924,15 +1923,14 @@ std::string ClangImporter::getBridgingHeaderContents(
19241923
19251924  invocation->getPreprocessorOpts ().resetNonModularOptions ();
19261925
1927-   clang::FileManager &fileManager = Impl.Instance ->getFileManager ();
1928- 
19291926  clang::CompilerInstance rewriteInstance (
19301927      std::move (invocation), Impl.Instance ->getPCHContainerOperations (),
19311928      &Impl.Instance ->getModuleCache ());
1932-   rewriteInstance.createDiagnostics (fileManager.getVirtualFileSystem (),
1933-                                     new  clang::IgnoringDiagConsumer);
1934-   rewriteInstance.setFileManager (&fileManager);
1935-   rewriteInstance.createSourceManager (fileManager);
1929+   rewriteInstance.setVirtualFileSystem (
1930+       Impl.Instance ->getFileManager ().getVirtualFileSystemPtr ());
1931+   rewriteInstance.setFileManager (&Impl.Instance ->getFileManager ());
1932+   rewriteInstance.createDiagnostics (new  clang::IgnoringDiagConsumer);
1933+   rewriteInstance.createSourceManager ();
19361934  rewriteInstance.setTarget (&Impl.Instance ->getTarget ());
19371935
19381936  std::string result;
@@ -1980,7 +1978,8 @@ std::string ClangImporter::getBridgingHeaderContents(
19801978    return  " " 
19811979  }
19821980
1983-   if  (auto  fileInfo = fileManager.getOptionalFileRef (headerPath)) {
1981+   if  (auto  fileInfo =
1982+           rewriteInstance.getFileManager ().getOptionalFileRef (headerPath)) {
19841983    fileSize = fileInfo->getSize ();
19851984    fileModTime = fileInfo->getModificationTime ();
19861985  }
@@ -2029,16 +2028,15 @@ ClangImporter::cloneCompilerInstanceForPrecompiling() {
20292028  //  Share the CASOption and the underlying CAS.
20302029  invocation->setCASOption (Impl.Invocation ->getCASOptsPtr ());
20312030
2032-   clang::FileManager &fileManager = Impl.Instance ->getFileManager ();
2033- 
20342031  auto  clonedInstance = std::make_unique<clang::CompilerInstance>(
20352032      std::move (invocation), Impl.Instance ->getPCHContainerOperations (),
20362033      &Impl.Instance ->getModuleCache ());
2037-   clonedInstance->createDiagnostics (fileManager.getVirtualFileSystem (),
2038-                                     &Impl.Instance ->getDiagnosticClient (),
2034+   clonedInstance->setVirtualFileSystem (
2035+       Impl.Instance ->getFileManager ().getVirtualFileSystemPtr ());
2036+   clonedInstance->setFileManager (&Impl.Instance ->getFileManager ());
2037+   clonedInstance->createDiagnostics (&Impl.Instance ->getDiagnosticClient (),
20392038                                    /* ShouldOwnClient=*/ false );
2040-   clonedInstance->setFileManager (&fileManager);
2041-   clonedInstance->createSourceManager (fileManager);
2039+   clonedInstance->createSourceManager ();
20422040  clonedInstance->setTarget (&Impl.Instance ->getTarget ());
20432041  clonedInstance->setOutputBackend (Impl.SwiftContext .OutputBackend );
20442042
0 commit comments