@@ -1021,7 +1021,9 @@ 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 (Impl.Instance ->getVirtualFileSystemPtr ());
1025+ CI.setFileManager (&Impl.Instance ->getFileManager ());
1026+ CI.createSourceManager ();
10251027 auto &clangSrcMgr = CI.getSourceManager ();
10261028 auto FID = clangSrcMgr.createFileID (
10271029 std::make_unique<ZeroFilledMemoryBuffer>(1 , " <main>" ));
@@ -1402,21 +1404,15 @@ std::unique_ptr<ClangImporter> ClangImporter::create(
14021404 if (tracker)
14031405 instance.addDependencyCollector (tracker->getClangCollector ());
14041406
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- }
1407+ // Now set up the real client for Clang diagnostics---configured with proper
1408+ // options---as opposed to the temporary one we made above.
1409+ auto actualDiagClient = std::make_unique<ClangDiagnosticConsumer>(
1410+ importer->Impl , instance.getDiagnosticOpts (),
1411+ importerOpts.DumpClangDiagnostics );
14131412
1414- // Set up the file manager.
1415- {
1416- VFS = clang::createVFSFromCompilerInvocation (
1417- instance.getInvocation (), instance.getDiagnostics (), std::move (VFS));
1418- instance.createFileManager (VFS);
1419- }
1413+ instance.createVirtualFileSystem (std::move (VFS), actualDiagClient.get ());
1414+ instance.createFileManager ();
1415+ instance.createDiagnostics (actualDiagClient.release ());
14201416
14211417 // Don't stop emitting messages if we ever can't load a module.
14221418 // FIXME: This is actually a general problem: any "fatal" error could mess up
@@ -1435,11 +1431,13 @@ std::unique_ptr<ClangImporter> ClangImporter::create(
14351431 if (ctx.LangOpts .ClangTarget .has_value ()) {
14361432 // If '-clang-target' is set, create a mock invocation with the Swift triple
14371433 // to configure CodeGen and Target options for Swift compilation.
1438- auto swiftTargetClangArgs = importer->getClangCC1Arguments (ctx, VFS, true );
1434+ auto swiftTargetClangArgs = importer->getClangCC1Arguments (
1435+ ctx, instance.getVirtualFileSystemPtr (), true );
14391436 if (!swiftTargetClangArgs)
14401437 return nullptr ;
14411438 auto swiftTargetClangInvocation = createClangInvocation (
1442- importer.get (), importerOpts, VFS, *swiftTargetClangArgs);
1439+ importer.get (), importerOpts, instance.getVirtualFileSystemPtr (),
1440+ *swiftTargetClangArgs);
14431441 if (!swiftTargetClangInvocation)
14441442 return nullptr ;
14451443
@@ -1924,15 +1922,14 @@ std::string ClangImporter::getBridgingHeaderContents(
19241922
19251923 invocation->getPreprocessorOpts ().resetNonModularOptions ();
19261924
1927- clang::FileManager &fileManager = Impl.Instance ->getFileManager ();
1928-
19291925 clang::CompilerInstance rewriteInstance (
19301926 std::move (invocation), Impl.Instance ->getPCHContainerOperations (),
19311927 &Impl.Instance ->getModuleCache ());
1932- rewriteInstance.createDiagnostics (fileManager.getVirtualFileSystem (),
1933- new clang::IgnoringDiagConsumer);
1934- rewriteInstance.setFileManager (&fileManager);
1935- rewriteInstance.createSourceManager (fileManager);
1928+ rewriteInstance.setVirtualFileSystem (
1929+ Impl.Instance ->getVirtualFileSystemPtr ());
1930+ rewriteInstance.setFileManager (&Impl.Instance ->getFileManager ());
1931+ rewriteInstance.createDiagnostics (new clang::IgnoringDiagConsumer);
1932+ rewriteInstance.createSourceManager ();
19361933 rewriteInstance.setTarget (&Impl.Instance ->getTarget ());
19371934
19381935 std::string result;
@@ -1980,7 +1977,8 @@ std::string ClangImporter::getBridgingHeaderContents(
19801977 return " " ;
19811978 }
19821979
1983- if (auto fileInfo = fileManager.getOptionalFileRef (headerPath)) {
1980+ if (auto fileInfo =
1981+ rewriteInstance.getFileManager ().getOptionalFileRef (headerPath)) {
19841982 fileSize = fileInfo->getSize ();
19851983 fileModTime = fileInfo->getModificationTime ();
19861984 }
@@ -2029,16 +2027,15 @@ ClangImporter::cloneCompilerInstanceForPrecompiling() {
20292027 // Share the CASOption and the underlying CAS.
20302028 invocation->setCASOption (Impl.Invocation ->getCASOptsPtr ());
20312029
2032- clang::FileManager &fileManager = Impl.Instance ->getFileManager ();
2033-
20342030 auto clonedInstance = std::make_unique<clang::CompilerInstance>(
20352031 std::move (invocation), Impl.Instance ->getPCHContainerOperations (),
20362032 &Impl.Instance ->getModuleCache ());
2037- clonedInstance->createDiagnostics (fileManager.getVirtualFileSystem (),
2038- &Impl.Instance ->getDiagnosticClient (),
2033+ clonedInstance->setVirtualFileSystem (
2034+ Impl.Instance ->getVirtualFileSystemPtr ());
2035+ clonedInstance->setFileManager (&Impl.Instance ->getFileManager ());
2036+ clonedInstance->createDiagnostics (&Impl.Instance ->getDiagnosticClient (),
20392037 /* ShouldOwnClient=*/ false );
2040- clonedInstance->setFileManager (&fileManager);
2041- clonedInstance->createSourceManager (fileManager);
2038+ clonedInstance->createSourceManager ();
20422039 clonedInstance->setTarget (&Impl.Instance ->getTarget ());
20432040 clonedInstance->setOutputBackend (Impl.SwiftContext .OutputBackend );
20442041
0 commit comments