Skip to content

Commit 0deff4b

Browse files
author
Marc Rasi
committed
---
yaml --- r: 313087 b: refs/heads/tensorflow-merge c: 7e15723 h: refs/heads/master i: 313085: 04e7079 313083: d04a29a 313079: 5384b57 313071: 8c12842 313055: 8b9e11b 313023: baa182d 312959: f5a7adc 312831: abb714e
1 parent fa69e7e commit 0deff4b

File tree

12 files changed

+197
-101
lines changed

12 files changed

+197
-101
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ refs/heads/chase-my-tail: 8bb91443a9e81bbfac92a2621a0af887a1da8dbf
13791379
refs/heads/consider-outer-alternatives: 708bac749ec60a22a79e2eefbe734f9488a7370d
13801380
refs/heads/revert-25740-oops-i-linked-it-again: fdd41aeb682fc488572bdc1cf71b2ff6997ba576
13811381
refs/heads/swift-5.1-branch-06-12-2019: e63b7b2d3b93c48232d386099d0ec525d21d8f8d
1382-
refs/heads/tensorflow-merge: ed3a8ec6fcf283e47ec3207d09f643b723176cd9
1382+
refs/heads/tensorflow-merge: 7e1572380532fb8b88ee063b2e936792be87d240
13831383
refs/heads/update-checkout-sha-info: 5832743c5c2a842976c42a508a4c6dcceefb0aef
13841384
refs/tags/swift-5.1-DEVELOPMENT-SNAPSHOT-2019-06-12-a: 228f0448d9bb909aacbba4afcb7c600a405d15da
13851385
refs/tags/swift-5.1-DEVELOPMENT-SNAPSHOT-2019-06-14-a: 922861a77b5fc2bf46bc917da70ceb15eef76836
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import CModule
2+
import SwiftModule
3+
4+
func foo(
5+
_ structDefinedInCModule: StructDefinedInCModule,
6+
_ structDefinedInSwiftModule: StructDefinedInSwiftModule,
7+
_ structDefinedInSameTarget: StructDefinedInSameTarget
8+
) {
9+
}
10+
11+
// CHECK-CMODULE: <Declaration>struct StructDefinedInCModule</Declaration>
12+
13+
// CHECK-SWIFTMODULE: <Declaration>struct StructDefinedInSwiftModule</Declaration>
14+
15+
// CHECK-SAMETARGET: <Declaration>struct StructDefinedInSameTarget</Declaration>
16+
17+
// RUN: %empty-directory(%t)
18+
// RUN: %swift -emit-module -o %t/SwiftModule.swiftmodule -module-name SwiftModule %S/../Inputs/vfs/SwiftModule/SwiftModule.swift
19+
// RUN: %sourcekitd-test -req=cursor -pos=5:43 -vfs-files=/target_file1.swift=%s,/target_file2.swift=%S/../Inputs/vfs/other_file_in_target.swift,/CModule/module.modulemap=%S/../Inputs/vfs/CModule/module.modulemap,/CModule/CModule.h=%S/../Inputs/vfs/CModule/CModule.h,/SwiftModule/SwiftModule.swiftmodule=%t/SwiftModule.swiftmodule /target_file1.swift -- /target_file1.swift /target_file2.swift -I /CModule -I /SwiftModule | %FileCheck --check-prefix=CHECK-CMODULE %s
20+
// USR test intentionally omitted for CModule, because SourceKit does not support clang USRs.
21+
// RUN: %sourcekitd-test -req=cursor -pos=6:43 -vfs-files=/target_file1.swift=%s,/target_file2.swift=%S/../Inputs/vfs/other_file_in_target.swift,/CModule/module.modulemap=%S/../Inputs/vfs/CModule/module.modulemap,/CModule/CModule.h=%S/../Inputs/vfs/CModule/CModule.h,/SwiftModule/SwiftModule.swiftmodule=%t/SwiftModule.swiftmodule /target_file1.swift -- /target_file1.swift /target_file2.swift -I /CModule -I /SwiftModule | %FileCheck --check-prefix=CHECK-SWIFTMODULE %s
22+
// RUN: %sourcekitd-test -req=cursor -usr "s:11SwiftModule015StructDefinedInaB0V" -vfs-files=/target_file1.swift=%s,/target_file2.swift=%S/../Inputs/vfs/other_file_in_target.swift,/CModule/module.modulemap=%S/../Inputs/vfs/CModule/module.modulemap,/CModule/CModule.h=%S/../Inputs/vfs/CModule/CModule.h,/SwiftModule/SwiftModule.swiftmodule=%t/SwiftModule.swiftmodule /target_file1.swift -- /target_file1.swift /target_file2.swift -I /CModule -I /SwiftModule | %FileCheck --check-prefix=CHECK-SWIFTMODULE %s
23+
// RUN: %sourcekitd-test -req=cursor -pos=7:43 -vfs-files=/target_file1.swift=%s,/target_file2.swift=%S/../Inputs/vfs/other_file_in_target.swift,/CModule/module.modulemap=%S/../Inputs/vfs/CModule/module.modulemap,/CModule/CModule.h=%S/../Inputs/vfs/CModule/CModule.h,/SwiftModule/SwiftModule.swiftmodule=%t/SwiftModule.swiftmodule /target_file1.swift -- /target_file1.swift /target_file2.swift -I /CModule -I /SwiftModule | %FileCheck --check-prefix=CHECK-SAMETARGET %s
24+
// RUN: %sourcekitd-test -req=cursor -usr "s:4main25StructDefinedInSameTargetV" -vfs-files=/target_file1.swift=%s,/target_file2.swift=%S/../Inputs/vfs/other_file_in_target.swift,/CModule/module.modulemap=%S/../Inputs/vfs/CModule/module.modulemap,/CModule/CModule.h=%S/../Inputs/vfs/CModule/CModule.h,/SwiftModule/SwiftModule.swiftmodule=%t/SwiftModule.swiftmodule /target_file1.swift -- /target_file1.swift /target_file2.swift -I /CModule -I /SwiftModule | %FileCheck --check-prefix=CHECK-SAMETARGET %s
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
struct StructDefinedInCModule {
22
int intFieldDefinedInCModule;
33
};
4+
5+
void functionDefinedInCModule();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import CModule
2+
import SwiftModule
3+
4+
func foo(
5+
_ structDefinedInSwiftModule: StructDefinedInSwiftModule,
6+
_ structDefinedInSameTarget: StructDefinedInSameTarget
7+
) {
8+
let a: String = functionDefinedInCModule()
9+
// CHECK: cannot convert value of type 'Void' to specified type 'String'
10+
11+
let b: Float = structDefinedInSwiftModule.methodDefinedInSwiftModule()
12+
// CHECK: cannot convert value of type '()' to specified type 'Float'
13+
14+
let c: Double = structDefinedInSameTarget.methodDefinedInSameTarget()
15+
// CHECK: cannot convert value of type '()' to specified type 'Double'
16+
}
17+
18+
// RUN: %empty-directory(%t)
19+
// RUN: %swift -emit-module -o %t/SwiftModule.swiftmodule -module-name SwiftModule %S/../Inputs/vfs/SwiftModule/SwiftModule.swift
20+
// RUN: %sourcekitd-test -req=open -vfs-files=/target_file1.swift=%s,/target_file2.swift=%S/../Inputs/vfs/other_file_in_target.swift,/CModule/module.modulemap=%S/../Inputs/vfs/CModule/module.modulemap,/CModule/CModule.h=%S/../Inputs/vfs/CModule/CModule.h,/SwiftModule/SwiftModule.swiftmodule=%t/SwiftModule.swiftmodule /target_file1.swift -- /target_file1.swift /target_file2.swift -I /CModule -I /SwiftModule == \
21+
// RUN: -req=print-diags -vfs-files=/target_file1.swift=%s,/target_file2.swift=%S/../Inputs/vfs/other_file_in_target.swift,/CModule/module.modulemap=%S/../Inputs/vfs/CModule/module.modulemap,/CModule/CModule.h=%S/../Inputs/vfs/CModule/CModule.h,/SwiftModule/SwiftModule.swiftmodule=%t/SwiftModule.swiftmodule /target_file1.swift | %FileCheck %s

branches/tensorflow-merge/tools/SourceKit/include/SourceKit/Core/FileSystemProvider.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ namespace SourceKit {
2828
/// specifying 'key.vfs.args'. SourceKit then passes the given arguments to the
2929
/// selected FileSystemProvider, and uses the resulting llvm::vfs::FileSystem
3030
/// while serving the request.
31+
///
32+
/// The following requests currently support custom FileSystemProviders (other
33+
/// requests respond with an invalid request error if you try):
34+
/// - source.request.editor.open: Associates the given custom filesystem with
35+
/// this editor file, so that all subsequent
36+
/// operations on this editor file use it.
37+
/// - source.request.codecomplete: Uses the given custom filesystem to process.
38+
/// - source.request.cursorinfo: Uses the given custom filesystem to process.
3139
class FileSystemProvider {
3240
public:
3341
virtual ~FileSystemProvider() = default;

branches/tensorflow-merge/tools/SourceKit/include/SourceKit/Core/LangSupport.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -667,9 +667,10 @@ class LangSupport {
667667
virtual void
668668
codeCompleteSetCustom(ArrayRef<CustomCompletionInfo> completions) = 0;
669669

670-
virtual void editorOpen(StringRef Name, llvm::MemoryBuffer *Buf,
671-
EditorConsumer &Consumer,
672-
ArrayRef<const char *> Args) = 0;
670+
virtual void
671+
editorOpen(StringRef Name, llvm::MemoryBuffer *Buf, EditorConsumer &Consumer,
672+
ArrayRef<const char *> Args,
673+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem) = 0;
673674

674675
virtual void editorOpenInterface(EditorConsumer &Consumer,
675676
StringRef Name,
@@ -718,12 +719,12 @@ class LangSupport {
718719
unsigned Length,
719720
EditorConsumer &Consumer) = 0;
720721

721-
virtual void getCursorInfo(StringRef Filename, unsigned Offset,
722-
unsigned Length, bool Actionables,
723-
bool CancelOnSubsequentRequest,
724-
ArrayRef<const char *> Args,
725-
std::function<void(const RequestResult<CursorInfoData> &)> Receiver) = 0;
726-
722+
virtual void
723+
getCursorInfo(StringRef Filename, unsigned Offset, unsigned Length,
724+
bool Actionables, bool CancelOnSubsequentRequest,
725+
ArrayRef<const char *> Args,
726+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
727+
std::function<void(const RequestResult<CursorInfoData> &)> Receiver) = 0;
727728

728729
virtual void getNameInfo(StringRef Filename, unsigned Offset,
729730
NameTranslatingInfo &Input,
@@ -735,11 +736,11 @@ class LangSupport {
735736
ArrayRef<const char *> Args,
736737
std::function<void(const RequestResult<RangeInfo> &)> Receiver) = 0;
737738

738-
virtual void
739-
getCursorInfoFromUSR(StringRef Filename, StringRef USR,
740-
bool CancelOnSubsequentRequest,
741-
ArrayRef<const char *> Args,
742-
std::function<void(const RequestResult<CursorInfoData> &)> Receiver) = 0;
739+
virtual void getCursorInfoFromUSR(
740+
StringRef Filename, StringRef USR, bool CancelOnSubsequentRequest,
741+
ArrayRef<const char *> Args,
742+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
743+
std::function<void(const RequestResult<CursorInfoData> &)> Receiver) = 0;
743744

744745
virtual void findRelatedIdentifiersInFile(StringRef Filename,
745746
unsigned Offset,

branches/tensorflow-merge/tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,15 @@ struct InvocationOptions {
7777
const std::string PrimaryFile;
7878
const CompilerInvocation Invok;
7979

80+
/// If defined, all filesystem operations resulting from this invocation
81+
/// should use this filesystem instead of the real filesystem.
82+
const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem;
83+
8084
InvocationOptions(ArrayRef<const char *> CArgs, StringRef PrimaryFile,
81-
CompilerInvocation Invok)
82-
: Args(_convertArgs(CArgs)),
83-
PrimaryFile(PrimaryFile),
84-
Invok(std::move(Invok)) {
85+
CompilerInvocation Invok,
86+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem)
87+
: Args(_convertArgs(CArgs)), PrimaryFile(PrimaryFile),
88+
Invok(std::move(Invok)), FileSystem(FileSystem) {
8589
// Assert invocation with a primary file. We want to avoid full typechecking
8690
// for all files.
8791
assert(!this->PrimaryFile.empty());
@@ -163,6 +167,7 @@ void InvocationOptions::profile(llvm::FoldingSetNodeID &ID) const {
163167
for (auto &Arg : Args)
164168
ID.AddString(Arg);
165169
ID.AddString(PrimaryFile);
170+
ID.AddPointer(FileSystem.get());
166171
}
167172

168173
//===----------------------------------------------------------------------===//
@@ -373,11 +378,15 @@ struct SwiftASTManager::Implementation {
373378
"sourcekit.swift.ASTBuilding" };
374379

375380
ASTProducerRef getASTProducer(SwiftInvocationRef InvokRef);
376-
FileContent getFileContent(StringRef FilePath, bool IsPrimary,
377-
std::string &Error);
378-
BufferStamp getBufferStamp(StringRef FilePath);
379-
std::unique_ptr<llvm::MemoryBuffer> getMemoryBuffer(StringRef Filename,
380-
std::string &Error);
381+
FileContent
382+
getFileContent(StringRef FilePath, bool IsPrimary, std::string &Error,
383+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem);
384+
BufferStamp
385+
getBufferStamp(StringRef FilePath,
386+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem);
387+
std::unique_ptr<llvm::MemoryBuffer> getMemoryBuffer(
388+
StringRef Filename, std::string &Error,
389+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem = nullptr);
381390
};
382391

383392
SwiftASTManager::SwiftASTManager(
@@ -541,17 +550,17 @@ bool SwiftASTManager::initCompilerInvocationNoInputs(
541550
return false;
542551
}
543552

544-
SwiftInvocationRef
545-
SwiftASTManager::getInvocation(ArrayRef<const char *> OrigArgs,
546-
StringRef PrimaryFile,
547-
std::string &Error) {
553+
SwiftInvocationRef SwiftASTManager::getInvocation(
554+
ArrayRef<const char *> OrigArgs, StringRef PrimaryFile, std::string &Error,
555+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem) {
548556

549557
DiagnosticEngine Diags(Impl.SourceMgr);
550558
EditorDiagConsumer CollectDiagConsumer;
551559
Diags.addConsumer(CollectDiagConsumer);
552560

553561
CompilerInvocation CompInvok;
554-
if (initCompilerInvocation(CompInvok, OrigArgs, Diags, PrimaryFile, Error)) {
562+
if (initCompilerInvocation(CompInvok, OrigArgs, Diags, PrimaryFile, Error,
563+
FileSystem)) {
555564
// We create a traced operation here to represent the failure to parse
556565
// arguments since we cannot reach `createAST` where that would normally
557566
// happen.
@@ -568,7 +577,7 @@ SwiftASTManager::getInvocation(ArrayRef<const char *> OrigArgs,
568577
return nullptr;
569578
}
570579

571-
InvocationOptions Opts(OrigArgs, PrimaryFile, CompInvok);
580+
InvocationOptions Opts(OrigArgs, PrimaryFile, CompInvok, FileSystem);
572581
return new SwiftInvocation(
573582
*new SwiftInvocation::Implementation(std::move(Opts)));
574583
}
@@ -634,38 +643,45 @@ static FileContent getFileContentFromSnap(ImmutableTextSnapshotRef Snap,
634643
}
635644

636645
FileContent SwiftASTManager::Implementation::getFileContent(
637-
StringRef UnresolvedPath, bool IsPrimary, std::string &Error) {
646+
StringRef UnresolvedPath, bool IsPrimary, std::string &Error,
647+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem) {
638648
std::string FilePath = SwiftLangSupport::resolvePathSymlinks(UnresolvedPath);
639649
if (auto EditorDoc = EditorDocs->findByPath(FilePath))
640650
return getFileContentFromSnap(EditorDoc->getLatestSnapshot(), IsPrimary,
641651
FilePath);
642652

643653
// FIXME: Is there a way to get timestamp and buffer for a file atomically ?
644-
auto Stamp = getBufferStamp(FilePath);
645-
auto Buffer = getMemoryBuffer(FilePath, Error);
654+
auto Stamp = getBufferStamp(FilePath, FileSystem);
655+
auto Buffer = getMemoryBuffer(FilePath, Error, FileSystem);
646656
return FileContent(nullptr, UnresolvedPath, std::move(Buffer), IsPrimary,
647657
Stamp);
648658
}
649659

650-
BufferStamp SwiftASTManager::Implementation::getBufferStamp(StringRef FilePath){
660+
BufferStamp SwiftASTManager::Implementation::getBufferStamp(
661+
StringRef FilePath,
662+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem) {
651663
if (auto EditorDoc = EditorDocs->findByPath(FilePath))
652664
return EditorDoc->getLatestSnapshot()->getStamp();
653665

654-
llvm::sys::fs::file_status Status;
655-
if (std::error_code Ret = llvm::sys::fs::status(FilePath, Status)) {
666+
auto StatusOrErr = FileSystem
667+
? FileSystem->status(FilePath)
668+
: llvm::vfs::getRealFileSystem()->status(FilePath);
669+
if (std::error_code Err = StatusOrErr.getError()) {
656670
// Failure to read the file.
657-
LOG_WARN_FUNC("failed to stat file: " << FilePath
658-
<< " (" << Ret.message() << ')');
671+
LOG_WARN_FUNC("failed to stat file: " << FilePath << " (" << Err.message()
672+
<< ')');
659673
return -1;
660674
}
661-
return Status.getLastModificationTime().time_since_epoch().count();
675+
return StatusOrErr.get().getLastModificationTime().time_since_epoch().count();
662676
}
663677

664678
std::unique_ptr<llvm::MemoryBuffer>
665-
SwiftASTManager::Implementation::getMemoryBuffer(StringRef Filename,
666-
std::string &Error) {
679+
SwiftASTManager::Implementation::getMemoryBuffer(
680+
StringRef Filename, std::string &Error,
681+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem) {
667682
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =
668-
llvm::MemoryBuffer::getFile(Filename);
683+
FileSystem ? FileSystem->getBufferForFile(Filename)
684+
: llvm::vfs::getRealFileSystem()->getBufferForFile(Filename);
669685
if (FileBufOrErr)
670686
return std::move(FileBufOrErr.get());
671687

@@ -780,15 +796,17 @@ bool ASTProducer::shouldRebuild(SwiftASTManager::Implementation &MgrImpl,
780796
}
781797
}
782798
if (!FoundSnapshot)
783-
InputStamps.push_back(MgrImpl.getBufferStamp(File));
799+
InputStamps.push_back(
800+
MgrImpl.getBufferStamp(File, Invok.Opts.FileSystem));
784801
}
785802
assert(InputStamps.size() ==
786803
Invok.Opts.Invok.getFrontendOptions().InputsAndOutputs.inputCount());
787804
if (Stamps != InputStamps)
788805
return true;
789806

790807
for (auto &Dependency : DependencyStamps) {
791-
if (Dependency.second != MgrImpl.getBufferStamp(Dependency.first))
808+
if (Dependency.second !=
809+
MgrImpl.getBufferStamp(Dependency.first, Invok.Opts.FileSystem))
792810
return true;
793811
}
794812

@@ -895,7 +913,7 @@ ASTUnitRef ASTProducer::createASTUnit(SwiftASTManager::Implementation &MgrImpl,
895913

896914
Invocation.getLangOptions().CollectParsedToken = true;
897915

898-
if (CompIns.setup(Invocation)) {
916+
if (CompIns.setup(Invocation, InvokRef->Impl.Opts.FileSystem)) {
899917
// FIXME: Report the diagnostic.
900918
LOG_WARN_FUNC("Compilation setup failed!!!");
901919
Error = "compilation setup failed";
@@ -917,8 +935,9 @@ ASTUnitRef ASTProducer::createASTUnit(SwiftASTManager::Implementation &MgrImpl,
917935
// FIXME: There exists a small window where the module file may have been
918936
// modified after compilation finished and before we get its stamp.
919937
for (auto &Filename : Filenames) {
920-
DependencyStamps.push_back(std::make_pair(Filename,
921-
MgrImpl.getBufferStamp(Filename)));
938+
DependencyStamps.push_back(std::make_pair(
939+
Filename,
940+
MgrImpl.getBufferStamp(Filename, InvokRef->Impl.Opts.FileSystem)));
922941
}
923942

924943
// Since we only typecheck the primary file (plus referenced constructs
@@ -970,7 +989,8 @@ void ASTProducer::findSnapshotAndOpenFiles(
970989
if (FoundSnapshot)
971990
continue;
972991

973-
auto Content = MgrImpl.getFileContent(File, IsPrimary, Error);
992+
auto Content =
993+
MgrImpl.getFileContent(File, IsPrimary, Error, Opts.FileSystem);
974994
if (!Content.Buffer) {
975995
LOG_WARN_FUNC("failed getting file contents for " << File << ": "
976996
<< Error);

branches/tensorflow-merge/tools/SourceKit/lib/SwiftLang/SwiftASTManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ class SwiftASTManager : public std::enable_shared_from_this<SwiftASTManager> {
9393
StringRef RuntimeResourcePath);
9494
~SwiftASTManager();
9595

96-
SwiftInvocationRef getInvocation(ArrayRef<const char *> Args,
97-
StringRef PrimaryFile,
98-
std::string &Error);
96+
SwiftInvocationRef getInvocation(
97+
ArrayRef<const char *> Args, StringRef PrimaryFile, std::string &Error,
98+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem = nullptr);
9999

100100
/// Provides the AST associated with an invocation to the AST consumer,
101101
/// asynchronously.

0 commit comments

Comments
 (0)