Skip to content

Commit 94ef543

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.
1 parent 2ebbe8c commit 94ef543

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
@@ -100,10 +100,6 @@ class ClangImporterOptions {
100100
/// When set, don't enforce warnings with -Werror.
101101
bool DebuggerSupport = false;
102102

103-
/// When set, clobber the Clang instance's virtual file system with the Swift
104-
/// virtual file system.
105-
bool ForceUseSwiftVirtualFileSystem = false;
106-
107103
/// Return a hash code of any components from these options that should
108104
/// contribute to a Swift Bridging PCH hash.
109105
llvm::hash_code getPCHHashComponents() const {

lib/ClangImporter/ClangImporter.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,17 +1018,10 @@ ClangImporter::create(ASTContext &ctx,
10181018

10191019
// Set up the file manager.
10201020
{
1021-
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS;
1022-
if (!ctx.SearchPathOpts.VFSOverlayFiles.empty() ||
1023-
importerOpts.ForceUseSwiftVirtualFileSystem) {
1024-
// If the clang instance has overlays it means the user has provided
1025-
// -ivfsoverlay options. We're going to clobber their file system with
1026-
// the Swift file system, so warn about it.
1027-
if (!instance.getHeaderSearchOpts().VFSOverlayFiles.empty()) {
1028-
ctx.Diags.diagnose(SourceLoc(), diag::clang_vfs_overlay_is_ignored);
1029-
}
1030-
VFS = ctx.SourceMgr.getFileSystem();
1031-
}
1021+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS =
1022+
clang::createVFSFromCompilerInvocation(instance.getInvocation(),
1023+
instance.getDiagnostics(),
1024+
ctx.SourceMgr.getFileSystem());
10321025
instance.createFileManager(std::move(VFS));
10331026
}
10341027

lib/Frontend/Frontend.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,6 @@ static bool loadAndValidateVFSOverlay(
235235
const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &BaseFS,
236236
const llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> &OverlayFS,
237237
DiagnosticEngine &Diag) {
238-
// FIXME: It should be possible to allow chained lookup of later VFS overlays
239-
// through the mapping defined by earlier overlays.
240-
// See rdar://problem/39440687
241238
auto Buffer = BaseFS->getBufferForFile(File);
242239
if (!Buffer) {
243240
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)