Merge Swift & Clang VFS in the ClangImporter

The clang importer has to deal with two virtual file systems, one coming
from clang, and one coming from swift. Currently, if both are set, we
emit a diagnostic that we'll pick the swift one.

This commit changes that, by merging the two virtual file systems. The
motivation for this change is the reproducer infrastructure in LLDB,
which adds a third virtual file system to the mix.
This commit is contained in:
Jonas Devlieghere
2019-07-18 16:28:15 -07:00
parent 2ebbe8c651
commit 94ef5431ff
10 changed files with 31 additions and 27 deletions

View File

@@ -91,10 +91,6 @@ 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

@@ -100,10 +100,6 @@ public:
/// When set, don't enforce warnings with -Werror.
bool DebuggerSupport = false;
/// When set, clobber the Clang instance's virtual file system with the Swift
/// virtual file system.
bool ForceUseSwiftVirtualFileSystem = false;
/// Return a hash code of any components from these options that should
/// contribute to a Swift Bridging PCH hash.
llvm::hash_code getPCHHashComponents() const {

View File

@@ -1018,17 +1018,10 @@ ClangImporter::create(ASTContext &ctx,
// Set up the file manager.
{
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS;
if (!ctx.SearchPathOpts.VFSOverlayFiles.empty() ||
importerOpts.ForceUseSwiftVirtualFileSystem) {
// If the clang instance has overlays it means the user has provided
// -ivfsoverlay options. We're going to clobber their file system with
// the Swift file system, so warn about it.
if (!instance.getHeaderSearchOpts().VFSOverlayFiles.empty()) {
ctx.Diags.diagnose(SourceLoc(), diag::clang_vfs_overlay_is_ignored);
}
VFS = ctx.SourceMgr.getFileSystem();
}
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
clang::createVFSFromCompilerInvocation(instance.getInvocation(),
instance.getDiagnostics(),
ctx.SourceMgr.getFileSystem());
instance.createFileManager(std::move(VFS));
}

View File

@@ -235,9 +235,6 @@ 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,

View File

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

View File

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

View File

@@ -0,0 +1,17 @@
{
'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,6 +2,7 @@
// 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
@@ -20,10 +21,11 @@
// 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 -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'
// 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
#if TEST_VFS_CLANG_IMPORTER
import VFSMappedModule
#if TEST_VFS_CLANG_IMPORTER_MERGE
import YetAnotherVFSMappedModule
#endif
#endif

View File

@@ -950,7 +950,6 @@ ASTUnitRef ASTProducer::createASTUnit(
if (fileSystem != llvm::vfs::getRealFileSystem()) {
CompIns.getSourceMgr().setFileSystem(fileSystem);
Invocation.getClangImporterOptions().ForceUseSwiftVirtualFileSystem = true;
}
if (CompIns.setup(Invocation)) {

View File

@@ -200,7 +200,6 @@ static bool swiftCodeCompleteImpl(
if (FileSystem != llvm::vfs::getRealFileSystem()) {
CI.getSourceMgr().setFileSystem(FileSystem);
Invocation.getClangImporterOptions().ForceUseSwiftVirtualFileSystem = true;
}
if (CI.setup(Invocation)) {