mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Revert "[ClangImporter] Merge Swift & Clang VFS"
This commit is contained in:
committed by
GitHub
parent
820a16b25e
commit
fe2ad03f93
@@ -91,6 +91,10 @@ WARNING(implicit_bridging_header_imported_from_module,none,
|
|||||||
"is deprecated and will be removed in a later version of Swift",
|
"is deprecated and will be removed in a later version of Swift",
|
||||||
(StringRef, Identifier))
|
(StringRef, Identifier))
|
||||||
|
|
||||||
|
WARNING(clang_vfs_overlay_is_ignored,none,
|
||||||
|
"ignoring '-ivfsoverlay' options provided to '-Xcc' in favor of "
|
||||||
|
"'-vfsoverlay'", ())
|
||||||
|
|
||||||
#ifndef DIAG_NO_UNDEF
|
#ifndef DIAG_NO_UNDEF
|
||||||
# if defined(DIAG)
|
# if defined(DIAG)
|
||||||
# undef DIAG
|
# undef DIAG
|
||||||
|
|||||||
@@ -23,16 +23,10 @@
|
|||||||
|
|
||||||
namespace swift {
|
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.
|
/// This class manages and owns source buffers.
|
||||||
class SourceManager {
|
class SourceManager {
|
||||||
llvm::SourceMgr LLVMSourceMgr;
|
llvm::SourceMgr LLVMSourceMgr;
|
||||||
llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> FileSystem;
|
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem;
|
||||||
unsigned CodeCompletionBufferID = 0U;
|
unsigned CodeCompletionBufferID = 0U;
|
||||||
unsigned CodeCompletionOffset;
|
unsigned CodeCompletionOffset;
|
||||||
|
|
||||||
@@ -55,9 +49,9 @@ class SourceManager {
|
|||||||
mutable std::pair<const char *, const VirtualFile*> CachedVFile = {nullptr, nullptr};
|
mutable std::pair<const char *, const VirtualFile*> CachedVFile = {nullptr, nullptr};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SourceManager(llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> FS =
|
SourceManager(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS =
|
||||||
getRealOverlayFileSystem())
|
llvm::vfs::getRealFileSystem())
|
||||||
: FileSystem(FS) {}
|
: FileSystem(FS) {}
|
||||||
|
|
||||||
llvm::SourceMgr &getLLVMSourceMgr() {
|
llvm::SourceMgr &getLLVMSourceMgr() {
|
||||||
return LLVMSourceMgr;
|
return LLVMSourceMgr;
|
||||||
@@ -66,12 +60,11 @@ public:
|
|||||||
return LLVMSourceMgr;
|
return LLVMSourceMgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void setFileSystem(llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS) {
|
||||||
setFileSystem(llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> FS) {
|
|
||||||
FileSystem = FS;
|
FileSystem = FS;
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> getFileSystem() {
|
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> getFileSystem() {
|
||||||
return FileSystem;
|
return FileSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,3 +254,4 @@ private:
|
|||||||
} // end namespace swift
|
} // end namespace swift
|
||||||
|
|
||||||
#endif // SWIFT_BASIC_SOURCEMANAGER_H
|
#endif // SWIFT_BASIC_SOURCEMANAGER_H
|
||||||
|
|
||||||
|
|||||||
@@ -1012,35 +1012,14 @@ ClangImporter::create(ASTContext &ctx,
|
|||||||
|
|
||||||
// Set up the file manager.
|
// Set up the file manager.
|
||||||
{
|
{
|
||||||
if (instance.getHeaderSearchOpts().VFSOverlayFiles.empty()) {
|
if (!ctx.SearchPathOpts.VFSOverlayFiles.empty()) {
|
||||||
instance.setVirtualFileSystem(ctx.SourceMgr.getFileSystem());
|
// If the clang instance has overlays it means the user has provided
|
||||||
} else {
|
// -ivfsoverlay options and swift -vfsoverlay options. We're going to
|
||||||
// Initialize the clang VFS from its compiler invocation.
|
// clobber their file system with our own, so warn about it.
|
||||||
instance.createFileManager();
|
if (!instance.getHeaderSearchOpts().VFSOverlayFiles.empty()) {
|
||||||
|
ctx.Diags.diagnose(SourceLoc(), diag::clang_vfs_overlay_is_ignored);
|
||||||
// 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++;
|
|
||||||
}
|
}
|
||||||
|
instance.setVirtualFileSystem(ctx.SourceMgr.getFileSystem());
|
||||||
instance.setVirtualFileSystem(ClangImporterFS);
|
|
||||||
}
|
}
|
||||||
instance.createFileManager();
|
instance.createFileManager();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,6 +235,9 @@ static bool loadAndValidateVFSOverlay(
|
|||||||
const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &BaseFS,
|
const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> &BaseFS,
|
||||||
const llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> &OverlayFS,
|
const llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> &OverlayFS,
|
||||||
DiagnosticEngine &Diag) {
|
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);
|
auto Buffer = BaseFS->getBufferForFile(File);
|
||||||
if (!Buffer) {
|
if (!Buffer) {
|
||||||
Diag.diagnose(SourceLoc(), diag::cannot_open_file, File,
|
Diag.diagnose(SourceLoc(), diag::cannot_open_file, File,
|
||||||
@@ -261,7 +264,14 @@ bool CompilerInstance::setUpVirtualFileSystemOverlays() {
|
|||||||
hadAnyFailure |=
|
hadAnyFailure |=
|
||||||
loadAndValidateVFSOverlay(File, BaseFS, OverlayFS, Diagnostics);
|
loadAndValidateVFSOverlay(File, BaseFS, OverlayFS, Diagnostics);
|
||||||
}
|
}
|
||||||
SourceMgr.setFileSystem(OverlayFS);
|
|
||||||
|
// 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;
|
return hadAnyFailure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ static Optional<StringRef> getRelativeDepPath(StringRef DepPath,
|
|||||||
/// output path.
|
/// output path.
|
||||||
/// \note Needs to be in the swift namespace so CompilerInvocation can see it.
|
/// \note Needs to be in the swift namespace so CompilerInvocation can see it.
|
||||||
class swift::ParseableInterfaceBuilder {
|
class swift::ParseableInterfaceBuilder {
|
||||||
llvm::vfs::OverlayFileSystem &fs;
|
llvm::vfs::FileSystem &fs;
|
||||||
DiagnosticEngine &diags;
|
DiagnosticEngine &diags;
|
||||||
const StringRef interfacePath;
|
const StringRef interfacePath;
|
||||||
const StringRef moduleName;
|
const StringRef moduleName;
|
||||||
@@ -765,7 +765,7 @@ class ParseableInterfaceModuleLoaderImpl {
|
|||||||
using AccessPathElem = std::pair<Identifier, SourceLoc>;
|
using AccessPathElem = std::pair<Identifier, SourceLoc>;
|
||||||
friend class swift::ParseableInterfaceModuleLoader;
|
friend class swift::ParseableInterfaceModuleLoader;
|
||||||
ASTContext &ctx;
|
ASTContext &ctx;
|
||||||
llvm::vfs::OverlayFileSystem &fs;
|
llvm::vfs::FileSystem &fs;
|
||||||
DiagnosticEngine &diags;
|
DiagnosticEngine &diags;
|
||||||
ModuleRebuildInfo rebuildInfo;
|
ModuleRebuildInfo rebuildInfo;
|
||||||
const StringRef modulePath;
|
const StringRef modulePath;
|
||||||
|
|||||||
@@ -1,7 +1,3 @@
|
|||||||
module VFSMappedModule {
|
module VFSMappedModule {
|
||||||
header "VFSMappedModule.h"
|
header "VFSMappedModule.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
module YetAnotherVFSMappedModule {
|
|
||||||
header "YetAnotherVFSMappedModule.h"
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
#define MAJOR_SUCCESS 1
|
|
||||||
@@ -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'
|
|
||||||
},
|
|
||||||
]
|
|
||||||
},
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -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/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/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/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: 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
|
// 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
|
// 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.
|
// 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
|
#if TEST_VFS_CLANG_IMPORTER
|
||||||
import VFSMappedModule
|
import VFSMappedModule
|
||||||
#if TEST_VFS_CLANG_IMPORTER_MERGE
|
|
||||||
import YetAnotherVFSMappedModule
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -87,10 +87,8 @@ protected:
|
|||||||
SourceManager sourceMgr;
|
SourceManager sourceMgr;
|
||||||
|
|
||||||
// Create a file system that tracks how many times a file has been opened.
|
// 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()));
|
new OpenTrackingFileSystem(sourceMgr.getFileSystem()));
|
||||||
auto fs = llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>(
|
|
||||||
new llvm::vfs::OverlayFileSystem(baseFS));
|
|
||||||
|
|
||||||
sourceMgr.setFileSystem(fs);
|
sourceMgr.setFileSystem(fs);
|
||||||
PrintingDiagnosticConsumer printingConsumer;
|
PrintingDiagnosticConsumer printingConsumer;
|
||||||
@@ -128,7 +126,7 @@ protected:
|
|||||||
ASSERT_TRUE(fs->exists(cachedModulePath));
|
ASSERT_TRUE(fs->exists(cachedModulePath));
|
||||||
|
|
||||||
// Assert that we've only opened this file once, to write it.
|
// 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);
|
auto bufOrErr = fs->getBufferForFile(cachedModulePath);
|
||||||
ASSERT_TRUE(bufOrErr);
|
ASSERT_TRUE(bufOrErr);
|
||||||
|
|||||||
Reference in New Issue
Block a user