Skip to content

Commit d6f635e

Browse files
benlangmuirMarc Rasi
authored andcommitted
---
yaml --- r: 341903 b: refs/heads/rxwei-patch-1 c: 205371c h: refs/heads/master i: 341901: ef24025 341899: f082b69 341895: 1e83d2f 341887: 9491508
1 parent 1bbc363 commit d6f635e

File tree

10 files changed

+209
-136
lines changed

10 files changed

+209
-136
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-08-18-a: b10b1fce14385faa6d44f6b933e95
10151015
refs/heads/rdar-43033749-fix-batch-mode-no-diags-swift-5.0-branch: a14e64eaad30de89f0f5f0b2a782eed7ecdcb255
10161016
refs/heads/revert-19006-error-bridging-integer-type: 8a9065a3696535305ea53fe9b71f91cbe6702019
10171017
refs/heads/revert-19050-revert-19006-error-bridging-integer-type: ecf752d54b05dd0a20f510f0bfa54a3fec3bcaca
1018-
refs/heads/rxwei-patch-1: 78a7d95f074a9b1003948d7efb3f7b34858efc74
1018+
refs/heads/rxwei-patch-1: 205371c886de189ff84a54229e7a7b97be142e77
10191019
refs/heads/shahmishal-patch-1: e58ec0f7488258d42bef51bc3e6d7b3dc74d7b2a
10201020
refs/heads/typelist-existential: 4046359efd541fb5c72d69a92eefc0a784df8f5e
10211021
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-20-a: 4319ba09e4fb8650ee86061075c74a016b6baab9

branches/rxwei-patch-1/tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 72 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,10 @@ struct InvocationOptions {
7777
const std::string PrimaryFile;
7878
const CompilerInvocation Invok;
7979

80-
/// All filesystem operations resulting from this invocation should use this
81-
/// filesystem.
82-
const llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem;
83-
8480
InvocationOptions(ArrayRef<const char *> CArgs, StringRef PrimaryFile,
85-
CompilerInvocation Invok,
86-
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem)
81+
CompilerInvocation Invok)
8782
: Args(_convertArgs(CArgs)), PrimaryFile(PrimaryFile),
88-
Invok(std::move(Invok)), FileSystem(FileSystem) {
89-
assert(FileSystem);
83+
Invok(std::move(Invok)) {
9084
// Assert invocation with a primary file. We want to avoid full typechecking
9185
// for all files.
9286
assert(!this->PrimaryFile.empty());
@@ -168,7 +162,6 @@ void InvocationOptions::profile(llvm::FoldingSetNodeID &ID) const {
168162
for (auto &Arg : Args)
169163
ID.AddString(Arg);
170164
ID.AddString(PrimaryFile);
171-
ID.AddPointer(FileSystem.get());
172165
}
173166

174167
//===----------------------------------------------------------------------===//
@@ -298,10 +291,13 @@ class ASTProducer : public ThreadSafeRefCountedBase<ASTProducer> {
298291
return AST;
299292
}
300293

301-
void getASTUnitAsync(std::shared_ptr<SwiftASTManager> Mgr,
302-
ArrayRef<ImmutableTextSnapshotRef> Snapshots,
303-
std::function<void(ASTUnitRef Unit, StringRef Error)> Receiver);
294+
void getASTUnitAsync(
295+
std::shared_ptr<SwiftASTManager> Mgr,
296+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
297+
ArrayRef<ImmutableTextSnapshotRef> Snapshots,
298+
std::function<void(ASTUnitRef Unit, StringRef Error)> Receiver);
304299
bool shouldRebuild(SwiftASTManager::Implementation &MgrImpl,
300+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
305301
ArrayRef<ImmutableTextSnapshotRef> Snapshots);
306302

307303
void enqueueConsumer(SwiftASTConsumerRef Consumer,
@@ -320,18 +316,23 @@ class ASTProducer : public ThreadSafeRefCountedBase<ASTProducer> {
320316
}
321317

322318
private:
323-
ASTUnitRef getASTUnitImpl(SwiftASTManager::Implementation &MgrImpl,
324-
ArrayRef<ImmutableTextSnapshotRef> Snapshots,
325-
std::string &Error);
326-
327-
ASTUnitRef createASTUnit(SwiftASTManager::Implementation &MgrImpl,
328-
ArrayRef<ImmutableTextSnapshotRef> Snapshots,
329-
std::string &Error);
330-
331-
void findSnapshotAndOpenFiles(SwiftASTManager::Implementation &MgrImpl,
332-
ArrayRef<ImmutableTextSnapshotRef> Snapshots,
333-
SmallVectorImpl<FileContent> &Contents,
334-
std::string &Error) const;
319+
ASTUnitRef
320+
getASTUnitImpl(SwiftASTManager::Implementation &MgrImpl,
321+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
322+
ArrayRef<ImmutableTextSnapshotRef> Snapshots,
323+
std::string &Error);
324+
325+
ASTUnitRef
326+
createASTUnit(SwiftASTManager::Implementation &MgrImpl,
327+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
328+
ArrayRef<ImmutableTextSnapshotRef> Snapshots,
329+
std::string &Error);
330+
331+
void findSnapshotAndOpenFiles(
332+
SwiftASTManager::Implementation &MgrImpl,
333+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
334+
ArrayRef<ImmutableTextSnapshotRef> Snapshots,
335+
SmallVectorImpl<FileContent> &Contents, std::string &Error) const;
335336
};
336337

337338
typedef IntrusiveRefCntPtr<ASTProducer> ASTProducerRef;
@@ -598,15 +599,17 @@ SwiftInvocationRef SwiftASTManager::getInvocation(
598599
return nullptr;
599600
}
600601

601-
InvocationOptions Opts(OrigArgs, PrimaryFile, CompInvok, FileSystem);
602+
InvocationOptions Opts(OrigArgs, PrimaryFile, CompInvok);
602603
return new SwiftInvocation(
603604
*new SwiftInvocation::Implementation(std::move(Opts)));
604605
}
605606

606-
void SwiftASTManager::processASTAsync(SwiftInvocationRef InvokRef,
607-
SwiftASTConsumerRef ASTConsumer,
608-
const void *OncePerASTToken,
609-
ArrayRef<ImmutableTextSnapshotRef> Snapshots) {
607+
void SwiftASTManager::processASTAsync(
608+
SwiftInvocationRef InvokRef, SwiftASTConsumerRef ASTConsumer,
609+
const void *OncePerASTToken,
610+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
611+
ArrayRef<ImmutableTextSnapshotRef> Snapshots) {
612+
assert(fileSystem);
610613
ASTProducerRef Producer = Impl.getASTProducer(InvokRef);
611614

612615
if (ASTUnitRef Unit = Producer->getExistingAST()) {
@@ -619,13 +622,13 @@ void SwiftASTManager::processASTAsync(SwiftInvocationRef InvokRef,
619622

620623
Producer->enqueueConsumer(ASTConsumer, Snapshots, OncePerASTToken);
621624

622-
auto handleAST = [this, Producer, ASTConsumer](ASTUnitRef unit,
623-
StringRef error) {
625+
auto handleAST = [this, Producer, ASTConsumer, fileSystem](ASTUnitRef unit,
626+
StringRef error) {
624627
auto consumers = Producer->takeConsumers(
625628
[&](SwiftASTConsumer *consumer,
626629
ArrayRef<ImmutableTextSnapshotRef> snapshots) {
627630
return consumer == ASTConsumer.get() ||
628-
!Producer->shouldRebuild(Impl, snapshots) ||
631+
!Producer->shouldRebuild(Impl, fileSystem, snapshots) ||
629632
(unit && consumer->canUseASTWithSnapshots(snapshots));
630633
});
631634

@@ -637,7 +640,8 @@ void SwiftASTManager::processASTAsync(SwiftInvocationRef InvokRef,
637640
}
638641
};
639642

640-
Producer->getASTUnitAsync(shared_from_this(), Snapshots, std::move(handleAST));
643+
Producer->getASTUnitAsync(shared_from_this(), fileSystem, Snapshots,
644+
std::move(handleAST));
641645
}
642646

643647
void SwiftASTManager::removeCachedAST(SwiftInvocationRef Invok) {
@@ -714,25 +718,31 @@ SwiftASTManager::Implementation::getMemoryBuffer(
714718
return nullptr;
715719
}
716720

717-
void ASTProducer::getASTUnitAsync(std::shared_ptr<SwiftASTManager> Mgr,
718-
ArrayRef<ImmutableTextSnapshotRef> Snaps,
719-
std::function<void(ASTUnitRef Unit, StringRef Error)> Receiver) {
721+
void ASTProducer::getASTUnitAsync(
722+
std::shared_ptr<SwiftASTManager> Mgr,
723+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
724+
ArrayRef<ImmutableTextSnapshotRef> Snaps,
725+
std::function<void(ASTUnitRef Unit, StringRef Error)> Receiver) {
720726

721727
ASTProducerRef ThisProducer = this;
722728
SmallVector<ImmutableTextSnapshotRef, 4> Snapshots;
723729
Snapshots.append(Snaps.begin(), Snaps.end());
724730

725-
Mgr->Impl.ASTBuildQueue.dispatch([ThisProducer, Mgr, Snapshots, Receiver] {
726-
std::string Error;
727-
ASTUnitRef Unit = ThisProducer->getASTUnitImpl(Mgr->Impl, Snapshots, Error);
728-
Receiver(Unit, Error);
729-
}, /*isStackDeep=*/true);
731+
Mgr->Impl.ASTBuildQueue.dispatch(
732+
[ThisProducer, Mgr, fileSystem, Snapshots, Receiver] {
733+
std::string Error;
734+
ASTUnitRef Unit = ThisProducer->getASTUnitImpl(Mgr->Impl, fileSystem,
735+
Snapshots, Error);
736+
Receiver(Unit, Error);
737+
},
738+
/*isStackDeep=*/true);
730739
}
731740

732-
ASTUnitRef ASTProducer::getASTUnitImpl(SwiftASTManager::Implementation &MgrImpl,
733-
ArrayRef<ImmutableTextSnapshotRef> Snapshots,
734-
std::string &Error) {
735-
if (!AST || shouldRebuild(MgrImpl, Snapshots)) {
741+
ASTUnitRef ASTProducer::getASTUnitImpl(
742+
SwiftASTManager::Implementation &MgrImpl,
743+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
744+
ArrayRef<ImmutableTextSnapshotRef> Snapshots, std::string &Error) {
745+
if (!AST || shouldRebuild(MgrImpl, fileSystem, Snapshots)) {
736746
bool IsRebuild = AST != nullptr;
737747
const InvocationOptions &Opts = InvokRef->Impl.Opts;
738748

@@ -746,7 +756,7 @@ ASTUnitRef ASTProducer::getASTUnitImpl(SwiftASTManager::Implementation &MgrImpl,
746756
Log->getOS() << Opts.Invok.getModuleName() << '/' << Opts.PrimaryFile;
747757
}
748758

749-
auto NewAST = createASTUnit(MgrImpl, Snapshots, Error);
759+
auto NewAST = createASTUnit(MgrImpl, fileSystem, Snapshots, Error);
750760
{
751761
// FIXME: ThreadSafeRefCntPtr is racy.
752762
llvm::sys::ScopedLock L(Mtx);
@@ -799,8 +809,10 @@ ASTProducer::takeConsumers(ConsumerPredicate predicate) {
799809
return consumers;
800810
}
801811

802-
bool ASTProducer::shouldRebuild(SwiftASTManager::Implementation &MgrImpl,
803-
ArrayRef<ImmutableTextSnapshotRef> Snapshots) {
812+
bool ASTProducer::shouldRebuild(
813+
SwiftASTManager::Implementation &MgrImpl,
814+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
815+
ArrayRef<ImmutableTextSnapshotRef> Snapshots) {
804816
const SwiftInvocation::Implementation &Invok = InvokRef->Impl;
805817

806818
// Check if the inputs changed.
@@ -819,8 +831,7 @@ bool ASTProducer::shouldRebuild(SwiftASTManager::Implementation &MgrImpl,
819831
}
820832
}
821833
if (!FoundSnapshot)
822-
InputStamps.push_back(
823-
MgrImpl.getBufferStamp(File, Invok.Opts.FileSystem));
834+
InputStamps.push_back(MgrImpl.getBufferStamp(File, fileSystem));
824835
}
825836
assert(InputStamps.size() ==
826837
Invok.Opts.Invok.getFrontendOptions().InputsAndOutputs.inputCount());
@@ -829,7 +840,7 @@ bool ASTProducer::shouldRebuild(SwiftASTManager::Implementation &MgrImpl,
829840

830841
for (auto &Dependency : DependencyStamps) {
831842
if (Dependency.second !=
832-
MgrImpl.getBufferStamp(Dependency.first, Invok.Opts.FileSystem))
843+
MgrImpl.getBufferStamp(Dependency.first, fileSystem))
833844
return true;
834845
}
835846

@@ -895,16 +906,17 @@ static void collectModuleDependencies(ModuleDecl *TopMod,
895906

896907
static std::atomic<uint64_t> ASTUnitGeneration{ 0 };
897908

898-
ASTUnitRef ASTProducer::createASTUnit(SwiftASTManager::Implementation &MgrImpl,
899-
ArrayRef<ImmutableTextSnapshotRef> Snapshots,
900-
std::string &Error) {
909+
ASTUnitRef ASTProducer::createASTUnit(
910+
SwiftASTManager::Implementation &MgrImpl,
911+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
912+
ArrayRef<ImmutableTextSnapshotRef> Snapshots, std::string &Error) {
901913
++MgrImpl.Stats->numASTBuilds;
902914

903915
Stamps.clear();
904916
DependencyStamps.clear();
905917

906918
SmallVector<FileContent, 8> Contents;
907-
findSnapshotAndOpenFiles(MgrImpl, Snapshots, Contents, Error);
919+
findSnapshotAndOpenFiles(MgrImpl, fileSystem, Snapshots, Contents, Error);
908920

909921
for (auto &Content : Contents)
910922
Stamps.push_back(Content.Stamp);
@@ -936,7 +948,7 @@ ASTUnitRef ASTProducer::createASTUnit(SwiftASTManager::Implementation &MgrImpl,
936948

937949
Invocation.getLangOptions().CollectParsedToken = true;
938950

939-
CompIns.getSourceMgr().setFileSystem(InvokRef->Impl.Opts.FileSystem);
951+
CompIns.getSourceMgr().setFileSystem(fileSystem);
940952
if (CompIns.setup(Invocation)) {
941953
// FIXME: Report the diagnostic.
942954
LOG_WARN_FUNC("Compilation setup failed!!!");
@@ -959,9 +971,8 @@ ASTUnitRef ASTProducer::createASTUnit(SwiftASTManager::Implementation &MgrImpl,
959971
// FIXME: There exists a small window where the module file may have been
960972
// modified after compilation finished and before we get its stamp.
961973
for (auto &Filename : Filenames) {
962-
DependencyStamps.push_back(std::make_pair(
963-
Filename,
964-
MgrImpl.getBufferStamp(Filename, InvokRef->Impl.Opts.FileSystem)));
974+
DependencyStamps.push_back(
975+
std::make_pair(Filename, MgrImpl.getBufferStamp(Filename, fileSystem)));
965976
}
966977

967978
// Since we only typecheck the primary file (plus referenced constructs
@@ -995,6 +1006,7 @@ ASTUnitRef ASTProducer::createASTUnit(SwiftASTManager::Implementation &MgrImpl,
9951006

9961007
void ASTProducer::findSnapshotAndOpenFiles(
9971008
SwiftASTManager::Implementation &MgrImpl,
1009+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
9981010
ArrayRef<ImmutableTextSnapshotRef> Snapshots,
9991011
SmallVectorImpl<FileContent> &Contents, std::string &Error) const {
10001012
const InvocationOptions &Opts = InvokRef->Impl.Opts;
@@ -1013,8 +1025,7 @@ void ASTProducer::findSnapshotAndOpenFiles(
10131025
if (FoundSnapshot)
10141026
continue;
10151027

1016-
auto Content =
1017-
MgrImpl.getFileContent(File, IsPrimary, Opts.FileSystem, Error);
1028+
auto Content = MgrImpl.getFileContent(File, IsPrimary, fileSystem, Error);
10181029
if (!Content.Buffer) {
10191030
LOG_WARN_FUNC("failed getting file contents for " << File << ": "
10201031
<< Error);

branches/rxwei-patch-1/tools/SourceKit/lib/SwiftLang/SwiftASTManager.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,12 @@ class SwiftASTManager : public std::enable_shared_from_this<SwiftASTManager> {
108108
/// \param OncePerASTToken if non-null, a previous query with the same value
109109
/// token, that is enqueued waiting to be executed on the same AST, will be
110110
/// cancelled.
111-
void processASTAsync(SwiftInvocationRef Invok,
112-
SwiftASTConsumerRef ASTConsumer,
113-
const void *OncePerASTToken,
114-
ArrayRef<ImmutableTextSnapshotRef> Snapshots =
115-
ArrayRef<ImmutableTextSnapshotRef>());
111+
void
112+
processASTAsync(SwiftInvocationRef Invok, SwiftASTConsumerRef ASTConsumer,
113+
const void *OncePerASTToken,
114+
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> fileSystem,
115+
ArrayRef<ImmutableTextSnapshotRef> Snapshots =
116+
ArrayRef<ImmutableTextSnapshotRef>());
116117

117118
std::unique_ptr<llvm::MemoryBuffer> getMemoryBuffer(StringRef Filename,
118119
std::string &Error);

branches/rxwei-patch-1/tools/SourceKit/lib/SwiftLang/SwiftCompletion.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ void SwiftLangSupport::codeComplete(
220220
Optional<VFSOptions> vfsOptions) {
221221

222222
std::string error;
223-
auto fileSystem = getFileSystem(vfsOptions, error);
223+
// FIXME: the use of None as primary file is to match the fact we do not read
224+
// the document contents using the editor documents infrastructure.
225+
auto fileSystem = getFileSystem(vfsOptions, /*primaryFile=*/None, error);
224226
if (!fileSystem)
225227
return SKConsumer.failed(error);
226228

branches/rxwei-patch-1/tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,8 @@ void SwiftLangSupport::findLocalRenameRanges(
13451345
/// FIXME: When request cancellation is implemented and Xcode adopts it,
13461346
/// don't use 'OncePerASTToken'.
13471347
static const char OncePerASTToken = 0;
1348-
getASTManager()->processASTAsync(Invok, ASTConsumer, &OncePerASTToken);
1348+
getASTManager()->processASTAsync(Invok, ASTConsumer, &OncePerASTToken,
1349+
llvm::vfs::getRealFileSystem());
13491350
}
13501351

13511352
SourceFile *SwiftLangSupport::getSyntacticSourceFile(

0 commit comments

Comments
 (0)