Skip to content

Commit 5c50412

Browse files
committed
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. (cherry picked from commit 94ef543)
1 parent 986a036 commit 5c50412

File tree

10 files changed

+31
-27
lines changed

10 files changed

+31
-27
lines changed

include/swift/AST/DiagnosticsClangImporter.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ WARNING(implicit_bridging_header_imported_from_module,none,
9191
"is deprecated and will be removed in a later version of Swift",
9292
(StringRef, Identifier))
9393

94-
WARNING(clang_vfs_overlay_is_ignored,none,
95-
"ignoring '-ivfsoverlay' options provided to '-Xcc' in favor of "
96-
"'-vfsoverlay'", ())
97-
9894
#ifndef DIAG_NO_UNDEF
9995
# if defined(DIAG)
10096
# undef DIAG

include/swift/ClangImporter/ClangImporterOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ class ClangImporterOptions {
9696
/// When set, don't enforce warnings with -Werror.
9797
bool DebuggerSupport = false;
9898

99-
/// When set, clobber the Clang instance's virtual file system with the Swift
100-
/// virtual file system.
101-
bool ForceUseSwiftVirtualFileSystem = false;
102-
10399
/// Return a hash code of any components from these options that should
104100
/// contribute to a Swift Bridging PCH hash.
105101
llvm::hash_code getPCHHashComponents() const {

lib/ClangImporter/ClangImporter.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,17 +1032,10 @@ ClangImporter::create(ASTContext &ctx, const ClangImporterOptions &importerOpts,
10321032

10331033
// Set up the file manager.
10341034
{
1035-
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS;
1036-
if (!ctx.SearchPathOpts.VFSOverlayFiles.empty() ||
1037-
importerOpts.ForceUseSwiftVirtualFileSystem) {
1038-
// If the clang instance has overlays it means the user has provided
1039-
// -ivfsoverlay options. We're going to clobber their file system with
1040-
// the Swift file system, so warn about it.
1041-
if (!instance.getHeaderSearchOpts().VFSOverlayFiles.empty()) {
1042-
ctx.Diags.diagnose(SourceLoc(), diag::clang_vfs_overlay_is_ignored);
1043-
}
1044-
VFS = ctx.SourceMgr.getFileSystem();
1045-
}
1035+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
1036+
clang::createVFSFromCompilerInvocation(instance.getInvocation(),
1037+
instance.getDiagnostics(),
1038+
ctx.SourceMgr.getFileSystem());
10461039
instance.createFileManager(std::move(VFS));
10471040
}
10481041

lib/Frontend/Frontend.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,6 @@ static bool loadAndValidateVFSOverlay(
243243
const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &BaseFS,
244244
const llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> &OverlayFS,
245245
DiagnosticEngine &Diag) {
246-
// FIXME: It should be possible to allow chained lookup of later VFS overlays
247-
// through the mapping defined by earlier overlays.
248-
// See rdar://problem/39440687
249246
auto Buffer = BaseFS->getBufferForFile(File);
250247
if (!Buffer) {
251248
Diag.diagnose(SourceLoc(), diag::cannot_open_file, File,

test/Frontend/Inputs/vfs/a-modulemap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
module VFSMappedModule {
22
header "VFSMappedModule.h"
33
}
4+
5+
module YetAnotherVFSMappedModule {
6+
header "YetAnotherVFSMappedModule.h"
7+
}

test/Frontend/Inputs/vfs/b-header

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define MAJOR_SUCCESS 1
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
'version': 0,
3+
'use-external-names': false,
4+
'roots': [
5+
{
6+
'name': 'OUT_DIR', 'type': 'directory',
7+
'contents': [
8+
{ 'name': 'YetAnotherVFSMappedModule.h', 'type': 'file',
9+
'external-contents': 'INPUT_DIR/vfs/b-header'
10+
},
11+
{ 'name': 'YetAnotherVFSMappedModule.framework/Headers/VFSMappedModule.h', 'type': 'file',
12+
'external-contents': 'INPUT_DIR/vfs/b-header'
13+
},
14+
]
15+
},
16+
]
17+
}

test/Frontend/vfs.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: sed -e "s|INPUT_DIR|%/S/Inputs|g" -e "s|OUT_DIR|%/t|g" %S/Inputs/vfs/vfsoverlay.yaml > %t/overlay.yaml
33
// 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
44
// 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
5+
// 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
56

67
// 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
78
// RUN: c-index-test -read-diagnostics %/t/basic.dia 2>&1 | %FileCheck -check-prefix=BASIC_MAPPING_ERROR %s
@@ -20,10 +21,11 @@
2021
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %/t -DTEST_VFS_CLANG_IMPORTER -Xcc -ivfsoverlay -Xcc %/t/overlay.yaml -typecheck %/s
2122

2223
// If we see -ivfsoverlay and -vfsoverlay, we'll clobber Clang's VFS with our own.
23-
// 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
24-
25-
// WARN_VFS_CLOBBERED: warning: ignoring '-ivfsoverlay' options provided to '-Xcc' in favor of '-vfsoverlay'
24+
// 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
2625

2726
#if TEST_VFS_CLANG_IMPORTER
2827
import VFSMappedModule
28+
#if TEST_VFS_CLANG_IMPORTER_MERGE
29+
import YetAnotherVFSMappedModule
30+
#endif
2931
#endif

tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,6 @@ ASTUnitRef ASTProducer::createASTUnit(
950950

951951
if (fileSystem != llvm::vfs::getRealFileSystem()) {
952952
CompIns.getSourceMgr().setFileSystem(fileSystem);
953-
Invocation.getClangImporterOptions().ForceUseSwiftVirtualFileSystem = true;
954953
}
955954

956955
if (CompIns.setup(Invocation)) {

tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ static bool swiftCodeCompleteImpl(
200200

201201
if (FileSystem != llvm::vfs::getRealFileSystem()) {
202202
CI.getSourceMgr().setFileSystem(FileSystem);
203-
Invocation.getClangImporterOptions().ForceUseSwiftVirtualFileSystem = true;
204203
}
205204

206205
if (CI.setup(Invocation)) {

0 commit comments

Comments
 (0)