Revert "[ClangImporter] Merge Swift & Clang VFS"

This commit is contained in:
Jonas Devlieghere
2019-07-05 15:30:43 -07:00
committed by GitHub
parent 820a16b25e
commit fe2ad03f93
10 changed files with 37 additions and 76 deletions

View File

@@ -91,6 +91,10 @@ WARNING(implicit_bridging_header_imported_from_module,none,
"is deprecated and will be removed in a later version of Swift",
(StringRef, Identifier))
WARNING(clang_vfs_overlay_is_ignored,none,
"ignoring '-ivfsoverlay' options provided to '-Xcc' in favor of "
"'-vfsoverlay'", ())
#ifndef DIAG_NO_UNDEF
# if defined(DIAG)
# undef DIAG

View File

@@ -23,16 +23,10 @@
namespace swift {
static inline llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>
getRealOverlayFileSystem() {
return llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>(
new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
}
/// This class manages and owns source buffers.
class SourceManager {
llvm::SourceMgr LLVMSourceMgr;
llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> FileSystem;
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem;
unsigned CodeCompletionBufferID = 0U;
unsigned CodeCompletionOffset;
@@ -55,8 +49,8 @@ class SourceManager {
mutable std::pair<const char *, const VirtualFile*> CachedVFile = {nullptr, nullptr};
public:
SourceManager(llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> FS =
getRealOverlayFileSystem())
SourceManager(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS =
llvm::vfs::getRealFileSystem())
: FileSystem(FS) {}
llvm::SourceMgr &getLLVMSourceMgr() {
@@ -66,12 +60,11 @@ public:
return LLVMSourceMgr;
}
void
setFileSystem(llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> FS) {
void setFileSystem(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS) {
FileSystem = FS;
}
llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> getFileSystem() {
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> getFileSystem() {
return FileSystem;
}
@@ -261,3 +254,4 @@ private:
} // end namespace swift
#endif // SWIFT_BASIC_SOURCEMANAGER_H

View File

@@ -1012,35 +1012,14 @@ ClangImporter::create(ASTContext &ctx,
// Set up the file manager.
{
if (instance.getHeaderSearchOpts().VFSOverlayFiles.empty()) {
instance.setVirtualFileSystem(ctx.SourceMgr.getFileSystem());
} else {
// Initialize the clang VFS from its compiler invocation.
instance.createFileManager();
// Create a new overlay file system for the clang importer with the clang
// VFS as its root.
auto ClangImporterFS =
llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>(
new llvm::vfs::OverlayFileSystem(
&instance.getVirtualFileSystem()));
auto SwiftFS = ctx.SourceMgr.getFileSystem();
auto it = SwiftFS->overlays_rbegin();
auto end = SwiftFS->overlays_rend();
// The Swift file system is an overlay file system with the real file
// system as its root. Skip the root so we query the other overlays
// before falling back to the real file system.
it++;
// Add all remaining Swift overlay file systems to the new file system.
while (it != end) {
ClangImporterFS->pushOverlay(*it);
it++;
if (!ctx.SearchPathOpts.VFSOverlayFiles.empty()) {
// If the clang instance has overlays it means the user has provided
// -ivfsoverlay options and swift -vfsoverlay options. We're going to
// clobber their file system with our own, so warn about it.
if (!instance.getHeaderSearchOpts().VFSOverlayFiles.empty()) {
ctx.Diags.diagnose(SourceLoc(), diag::clang_vfs_overlay_is_ignored);
}
instance.setVirtualFileSystem(ClangImporterFS);
instance.setVirtualFileSystem(ctx.SourceMgr.getFileSystem());
}
instance.createFileManager();
}

View File

@@ -235,6 +235,9 @@ static bool loadAndValidateVFSOverlay(
const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &BaseFS,
const llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> &OverlayFS,
DiagnosticEngine &Diag) {
// FIXME: It should be possible to allow chained lookup of later VFS overlays
// through the mapping defined by earlier overlays.
// See rdar://problem/39440687
auto Buffer = BaseFS->getBufferForFile(File);
if (!Buffer) {
Diag.diagnose(SourceLoc(), diag::cannot_open_file, File,
@@ -261,7 +264,14 @@ bool CompilerInstance::setUpVirtualFileSystemOverlays() {
hadAnyFailure |=
loadAndValidateVFSOverlay(File, BaseFS, OverlayFS, Diagnostics);
}
// If we successfully loaded all the overlays, let the source manager and
// diagnostic engine take advantage of the overlay file system.
if (!hadAnyFailure &&
(OverlayFS->overlays_begin() != OverlayFS->overlays_end())) {
SourceMgr.setFileSystem(OverlayFS);
}
return hadAnyFailure;
}

View File

@@ -273,7 +273,7 @@ static Optional<StringRef> getRelativeDepPath(StringRef DepPath,
/// output path.
/// \note Needs to be in the swift namespace so CompilerInvocation can see it.
class swift::ParseableInterfaceBuilder {
llvm::vfs::OverlayFileSystem &fs;
llvm::vfs::FileSystem &fs;
DiagnosticEngine &diags;
const StringRef interfacePath;
const StringRef moduleName;
@@ -765,7 +765,7 @@ class ParseableInterfaceModuleLoaderImpl {
using AccessPathElem = std::pair<Identifier, SourceLoc>;
friend class swift::ParseableInterfaceModuleLoader;
ASTContext &ctx;
llvm::vfs::OverlayFileSystem &fs;
llvm::vfs::FileSystem &fs;
DiagnosticEngine &diags;
ModuleRebuildInfo rebuildInfo;
const StringRef modulePath;

View File

@@ -1,7 +1,3 @@
module VFSMappedModule {
header "VFSMappedModule.h"
}
module YetAnotherVFSMappedModule {
header "YetAnotherVFSMappedModule.h"
}

View File

@@ -1 +0,0 @@
#define MAJOR_SUCCESS 1

View File

@@ -1,17 +0,0 @@
{
'version': 0,
'use-external-names': false,
'roots': [
{
'name': 'OUT_DIR', 'type': 'directory',
'contents': [
{ 'name': 'YetAnotherVFSMappedModule.h', 'type': 'file',
'external-contents': 'INPUT_DIR/vfs/b-header'
},
{ 'name': 'YetAnotherVFSMappedModule.framework/Headers/VFSMappedModule.h', 'type': 'file',
'external-contents': 'INPUT_DIR/vfs/b-header'
},
]
},
]
}

View File

@@ -2,7 +2,6 @@
// RUN: sed -e "s|INPUT_DIR|%/S/Inputs|g" -e "s|OUT_DIR|%/t|g" %S/Inputs/vfs/vfsoverlay.yaml > %t/overlay.yaml
// RUN: sed -e "s|INPUT_DIR|%/S/Inputs|g" -e "s|OUT_DIR|%/t|g" %S/Inputs/vfs/secondary-vfsoverlay.yaml > %t/secondary-overlay.yaml
// RUN: sed -e "s|INPUT_DIR|%/S/Inputs|g" -e "s|OUT_DIR|%/t|g" %S/Inputs/vfs/tertiary-vfsoverlay.yaml > %t/tertiary-overlay.yaml
// RUN: sed -e "s|INPUT_DIR|%/S/Inputs|g" -e "s|OUT_DIR|%/t|g" %S/Inputs/vfs/quaternary-vfsoverlay.yaml > %t/quaternary-vfsoverlay.yaml
// RUN: not %target-swift-frontend -vfsoverlay %/t/overlay.yaml -typecheck %s %/t/mapped-file.swift -serialize-diagnostics-path %/t/basic.dia 2>&1 | %FileCheck -check-prefix=BASIC_MAPPING_ERROR %s
// RUN: c-index-test -read-diagnostics %/t/basic.dia 2>&1 | %FileCheck -check-prefix=BASIC_MAPPING_ERROR %s
@@ -21,11 +20,10 @@
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %/t -DTEST_VFS_CLANG_IMPORTER -Xcc -ivfsoverlay -Xcc %/t/overlay.yaml -typecheck %/s
// If we see -ivfsoverlay and -vfsoverlay, we'll clobber Clang's VFS with our own.
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %/t -DTEST_VFS_CLANG_IMPORTER -DTEST_VFS_CLANG_IMPORTER_MERGE -vfsoverlay %/t/overlay.yaml -Xcc -ivfsoverlay -Xcc %/t/quaternary-vfsoverlay.yaml -typecheck %/s 2>&1
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %/t -DTEST_VFS_CLANG_IMPORTER -vfsoverlay %/t/overlay.yaml -Xcc -ivfsoverlay -Xcc %/t/overlay.yaml -typecheck %/s 2>&1 | %FileCheck -check-prefix=WARN_VFS_CLOBBERED %s
// WARN_VFS_CLOBBERED: warning: ignoring '-ivfsoverlay' options provided to '-Xcc' in favor of '-vfsoverlay'
#if TEST_VFS_CLANG_IMPORTER
import VFSMappedModule
#if TEST_VFS_CLANG_IMPORTER_MERGE
import YetAnotherVFSMappedModule
#endif
#endif

View File

@@ -87,10 +87,8 @@ protected:
SourceManager sourceMgr;
// Create a file system that tracks how many times a file has been opened.
llvm::IntrusiveRefCntPtr<OpenTrackingFileSystem> baseFS(
llvm::IntrusiveRefCntPtr<OpenTrackingFileSystem> fs(
new OpenTrackingFileSystem(sourceMgr.getFileSystem()));
auto fs = llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>(
new llvm::vfs::OverlayFileSystem(baseFS));
sourceMgr.setFileSystem(fs);
PrintingDiagnosticConsumer printingConsumer;
@@ -128,7 +126,7 @@ protected:
ASSERT_TRUE(fs->exists(cachedModulePath));
// Assert that we've only opened this file once, to write it.
ASSERT_EQ((unsigned)1, baseFS->numberOfOpens(cachedModulePath));
ASSERT_EQ((unsigned)1, fs->numberOfOpens(cachedModulePath));
auto bufOrErr = fs->getBufferForFile(cachedModulePath);
ASSERT_TRUE(bufOrErr);