46
46
using namespace swift ;
47
47
using namespace fine_grained_dependencies ;
48
48
49
- // ==============================================================================
50
- // MARK: Emitting and reading SourceFileDepGraph
51
- // ==============================================================================
52
-
53
- Optional<SourceFileDepGraph> SourceFileDepGraph::loadFromPath (StringRef path) {
54
- auto bufferOrError = llvm::MemoryBuffer::getFile (path);
55
- if (!bufferOrError)
56
- return None;
57
- return loadFromBuffer (*bufferOrError.get ());
58
- }
59
-
60
- Optional<SourceFileDepGraph>
61
- SourceFileDepGraph::loadFromBuffer (llvm::MemoryBuffer &buffer) {
62
- SourceFileDepGraph fg;
63
- llvm::yaml::Input yamlReader (llvm::MemoryBufferRef (buffer), nullptr );
64
- yamlReader >> fg;
65
- if (yamlReader.error ())
66
- return None;
67
- // return fg; compiles for Mac but not Linux, because it cannot be copied.
68
- return Optional<SourceFileDepGraph>(std::move (fg));
69
- }
70
-
71
- // ==============================================================================
72
- // MARK: Start of SourceFileDepGraph building, specific to status quo
73
- // ==============================================================================
74
-
75
49
// ==============================================================================
76
50
// MARK: Helpers for key construction that must be in frontend
77
51
// ==============================================================================
@@ -501,7 +475,7 @@ class SourceFileDepGraphConstructor {
501
475
// / a flag indicating if the member is private to its enclosing file, and
502
476
// / a flag indicating if the dependency cascades.
503
477
const std::vector<std::pair<std::tuple<std::string, std::string, bool >, bool >>
504
- memberDepends ;
478
+ dependsWithContexts ;
505
479
506
480
// / The base name of a class member depended-upon for dynamic lookup, and a
507
481
// / cascades flag.
@@ -534,7 +508,8 @@ class SourceFileDepGraphConstructor {
534
508
bool hadCompilationError,
535
509
const std::string &interfaceHash,
536
510
ArrayRef<std::pair<std::string, bool >> topLevelDepends,
537
- ArrayRef<std::pair<std::tuple<std::string, std::string, bool >, bool >> memberDepends,
511
+ ArrayRef<std::pair<std::tuple<std::string, std::string, bool >, bool >>
512
+ dependsWithContexts,
538
513
ArrayRef<std::pair<std::string, bool >> dynamicLookupDepends,
539
514
ArrayRef<std::string> externalDependencies,
540
515
@@ -554,7 +529,7 @@ class SourceFileDepGraphConstructor {
554
529
555
530
interfaceHash (interfaceHash),
556
531
topLevelDepends (topLevelDepends),
557
- memberDepends (memberDepends ),
532
+ dependsWithContexts (dependsWithContexts ),
558
533
dynamicLookupDepends (dynamicLookupDepends),
559
534
externalDependencies (externalDependencies),
560
535
@@ -569,11 +544,15 @@ class SourceFileDepGraphConstructor {
569
544
classMembers (classMembers)
570
545
{}
571
546
572
- SourceFileDepGraphConstructor static forSourceFile (SourceFile *SF,
573
- const DependencyTracker &depTracker,
574
- StringRef swiftDeps,
575
- const bool includePrivateDeps,
576
- const bool hadCompilationError) {
547
+ // clang-format off
548
+ static SourceFileDepGraphConstructor
549
+ forSourceFile (
550
+ SourceFile *SF,
551
+ const DependencyTracker &depTracker,
552
+ StringRef swiftDeps,
553
+ const bool includePrivateDeps,
554
+ const bool hadCompilationError) {
555
+ // clang-format on
577
556
578
557
SourceFileDeclFinder declFinder (SF, includePrivateDeps);
579
558
std::vector<std::pair<std::string, bool >> topLevelDepends;
@@ -584,11 +563,11 @@ class SourceFileDepGraphConstructor {
584
563
for (const auto &p: SF->getReferencedNameTracker ()->getDynamicLookupNames ())
585
564
dynamicLookupDepends.push_back (std::make_pair (p.getFirst ().userFacingName (), p.getSecond ()));
586
565
587
- std::vector<std::pair<std::tuple<std::string, std::string, bool >, bool >> memberDepends ;
566
+ std::vector<std::pair<std::tuple<std::string, std::string, bool >, bool >> dependsWithContexts ;
588
567
for (const auto &p: SF->getReferencedNameTracker ()->getUsedMembers ()) {
589
568
const auto &member = p.getFirst ().second ;
590
569
StringRef emptyOrUserFacingName = member.empty () ? " " : member.userFacingName ();
591
- memberDepends .push_back (
570
+ dependsWithContexts .push_back (
592
571
std::make_pair (
593
572
std::make_tuple (
594
573
mangleTypeAsContext (p.getFirst ().first ),
@@ -604,7 +583,7 @@ class SourceFileDepGraphConstructor {
604
583
605
584
getInterfaceHash (SF),
606
585
topLevelDepends,
607
- memberDepends ,
586
+ dependsWithContexts ,
608
587
dynamicLookupDepends,
609
588
depTracker.getDependencies (),
610
589
@@ -782,7 +761,7 @@ void SourceFileDepGraphConstructor::addDependencyArcsToGraph() {
782
761
// TODO: express the multiple provides and depends streams with variadic
783
762
// templates
784
763
addAllDependenciesFrom<NodeKind::topLevel>(topLevelDepends);
785
- addAllDependenciesFrom (memberDepends );
764
+ addAllDependenciesFrom (dependsWithContexts );
786
765
addAllDependenciesFrom<NodeKind::dynamicLookup>(dynamicLookupDepends);
787
766
addAllDependenciesFrom (externalDependencies);
788
767
}
@@ -798,7 +777,7 @@ void SourceFileDepGraphConstructor::recordThatThisWholeFileDependsOn(
798
777
// Entry point from the Frontend to this whole system
799
778
// ==============================================================================
800
779
801
- bool swift:: fine_grained_dependencies::emitReferenceDependencies (
780
+ bool fine_grained_dependencies::emitReferenceDependencies (
802
781
DiagnosticEngine &diags, SourceFile *const SF,
803
782
const DependencyTracker &depTracker, StringRef outputPath,
804
783
const bool alsoEmitDotFile) {
@@ -814,8 +793,9 @@ bool swift::fine_grained_dependencies::emitReferenceDependencies(
814
793
// we force the inclusion of private declarations when fingerprints
815
794
// are enabled.
816
795
const bool includeIntrafileDeps =
817
- SF->getASTContext ().LangOpts .FineGrainedDependenciesIncludeIntrafileOnes ||
818
- SF->getASTContext ().LangOpts .EnableTypeFingerprints ;
796
+ SF->getASTContext ()
797
+ .LangOpts .FineGrainedDependenciesIncludeIntrafileOnes ||
798
+ SF->getASTContext ().LangOpts .EnableTypeFingerprints ;
819
799
const bool hadCompilationError = SF->getASTContext ().hadError ();
820
800
auto gc = SourceFileDepGraphConstructor::forSourceFile (
821
801
SF, depTracker, outputPath, includeIntrafileDeps, hadCompilationError);
@@ -832,13 +812,9 @@ bool swift::fine_grained_dependencies::emitReferenceDependencies(
832
812
// If path is stdout, cannot read it back, so check for "-"
833
813
assert (outputPath == " -" || g.verifyReadsWhatIsWritten (outputPath));
834
814
835
- if (alsoEmitDotFile) {
836
- std::string dotFileName = outputPath.str () + " .dot" ;
837
- withOutputFile (diags, dotFileName, [&](llvm::raw_pwrite_stream &out) {
838
- DotFileEmitter<SourceFileDepGraph>(out, g, false , false ).emit ();
839
- return false ;
840
- });
841
- }
815
+ if (alsoEmitDotFile)
816
+ g.emitDotFile (outputPath, diags);
817
+
842
818
return hadError;
843
819
}
844
820
@@ -952,7 +928,10 @@ SourceFileDepGraph SourceFileDepGraph::simulateLoad(
952
928
953
929
// clang-format off
954
930
SourceFileDepGraphConstructor c (
955
- swiftDepsFilename, includePrivateDeps, hadCompilationError, interfaceHash,
931
+ swiftDepsFilename,
932
+ includePrivateDeps,
933
+ hadCompilationError,
934
+ interfaceHash,
956
935
getSimpleDepends (simpleNamesByRDK[dependsTopLevel]),
957
936
getCompoundDepends (simpleNamesByRDK[dependsNominal],
958
937
compoundNamesByRDK[dependsMember]),
@@ -961,7 +940,7 @@ SourceFileDepGraph SourceFileDepGraph::simulateLoad(
961
940
{}, // precedence groups
962
941
{}, // memberOperatorDecls
963
942
{}, // operators
964
- getMangledHolderProvides (simpleNamesByRDK[providesNominal]) , // topNominals
943
+ {} , // topNominals
965
944
getBaseNameProvides (simpleNamesByRDK[providesTopLevel]), // topValues
966
945
getMangledHolderProvides (simpleNamesByRDK[providesNominal]), // allNominals
967
946
getMangledHolderProvides (simpleNamesByRDK[providesNominal]), // potentialMemberHolders
0 commit comments