@@ -93,14 +93,20 @@ template <typename KeyT, typename ValueT> class Memoizer {
93
93
public:
94
94
Memoizer () = default ;
95
95
96
+ Optional<ValueT> findExisting (KeyT key) {
97
+ auto iter = memos.find (key);
98
+ if (iter != memos.end ())
99
+ return iter->second ;
100
+ return None;
101
+ }
102
+
96
103
// / \p createFn must create a \ref ValueT that corresponds to the \ref KeyT
97
104
// / passed into it.
98
105
ValueT
99
106
findExistingOrCreateIfNew (KeyT key,
100
107
function_ref<ValueT(const KeyT &)> createFn) {
101
- auto iter = memos.find (key);
102
- if (iter != memos.end ())
103
- return iter->second ;
108
+ if (auto existing = findExisting (key))
109
+ return existing.getValue ();
104
110
ValueT v = createFn (key);
105
111
(void )insert (key, v);
106
112
return v;
@@ -499,10 +505,23 @@ class DependencyKey {
499
505
}
500
506
bool isInterface () const { return getAspect () == DeclAspect::interface; }
501
507
508
+ // / Create just the interface half of the keys for a provided Decl or Decl
509
+ // / pair
510
+ template <NodeKind kind, typename Entity>
511
+ static DependencyKey createForProvidedEntityInterface (Entity);
512
+
502
513
// / Given some type of provided entity compute the context field of the key.
503
514
template <NodeKind kind, typename Entity>
504
515
static std::string computeContextForProvidedEntity (Entity);
505
516
517
+ DependencyKey correspondingImplementation () const {
518
+ return withAspect (DeclAspect::implementation);
519
+ }
520
+
521
+ DependencyKey withAspect (DeclAspect aspect) const {
522
+ return DependencyKey (kind, aspect, context, name);
523
+ }
524
+
506
525
// / Given some type of provided entity compute the name field of the key.
507
526
template <NodeKind kind, typename Entity>
508
527
static std::string computeNameForProvidedEntity (Entity);
@@ -514,7 +533,8 @@ class DependencyKey {
514
533
template <NodeKind kind>
515
534
static DependencyKey createDependedUponKey (StringRef);
516
535
517
- static DependencyKey createKeyForWholeSourceFile (StringRef swiftDeps);
536
+ static DependencyKey createKeyForWholeSourceFile (DeclAspect,
537
+ StringRef swiftDeps);
518
538
519
539
std::string humanReadableName () const ;
520
540
@@ -616,6 +636,10 @@ class DepGraphNode {
616
636
// / See SourceFileDepGraphNode::SourceFileDepGraphNode(...) and
617
637
// / ModuleDepGraphNode::ModuleDepGraphNode(...) Don't set swiftDeps on
618
638
// / creation because this field can change if a node is moved.
639
+ DepGraphNode (DependencyKey key, Optional<StringRef> fingerprint)
640
+ : DepGraphNode(key, fingerprint ? fingerprint->str ()
641
+ : Optional<std::string>()) {}
642
+
619
643
DepGraphNode (DependencyKey key, Optional<std::string> fingerprint)
620
644
: key(key), fingerprint(fingerprint) {}
621
645
DepGraphNode (const DepGraphNode &other) = default;
@@ -627,8 +651,12 @@ class DepGraphNode {
627
651
628
652
const DependencyKey &getKey () const { return key; }
629
653
630
- const Optional<std::string> &getFingerprint () const { return fingerprint; }
631
-
654
+ const Optional<StringRef> getFingerprint () const {
655
+ if (fingerprint) {
656
+ return StringRef (fingerprint.getValue ());
657
+ }
658
+ return None;
659
+ }
632
660
// / When driver reads a SourceFileDepGraphNode, it may be a node that was
633
661
// / created to represent a name-lookup (a.k.a a "depend") in the frontend. In
634
662
// / that case, the node represents an entity that resides in some other file
@@ -637,7 +665,9 @@ class DepGraphNode {
637
665
// / (someday) have a fingerprint. In order to preserve the
638
666
// / ModuleDepGraphNode's identity but bring its fingerprint up to date, it
639
667
// / needs to set the fingerprint *after* the node has been created.
640
- void setFingerprint (Optional<std::string> fp) { fingerprint = fp; }
668
+ void setFingerprint (Optional<StringRef> fp) {
669
+ fingerprint = fp ? fp->str () : Optional<std::string>();
670
+ }
641
671
642
672
SWIFT_DEBUG_DUMP;
643
673
void dump (llvm::raw_ostream &os) const ;
@@ -684,7 +714,7 @@ class SourceFileDepGraphNode : public DepGraphNode {
684
714
SourceFileDepGraphNode () : DepGraphNode(), sequenceNumber(~0 ) {}
685
715
686
716
// / Used by the frontend to build nodes.
687
- SourceFileDepGraphNode (DependencyKey key, Optional<std::string > fingerprint,
717
+ SourceFileDepGraphNode (DependencyKey key, Optional<StringRef > fingerprint,
688
718
bool isProvides)
689
719
: DepGraphNode(key, fingerprint), isProvides(isProvides) {
690
720
assert (key.verify ());
@@ -780,34 +810,6 @@ class SourceFileDepGraph {
780
810
SourceFileDepGraph (const SourceFileDepGraph &g) = delete ;
781
811
SourceFileDepGraph (SourceFileDepGraph &&g) = default ;
782
812
783
- // / Simulate loading for unit testing:
784
- // / \param swiftDepsFileName The name of the swiftdeps file of the phony job
785
- // / \param includePrivateDeps Whether the graph includes intra-file arcs
786
- // / \param hadCompilationError Simulate a compilation error
787
- // / \param interfaceHash The interface hash of the simulated graph
788
- // / \param simpleNamesByRDK A map of vectors of names keyed by reference
789
- // / dependency key \param compoundNamesByRDK A map of (mangledHolder,
790
- // / baseName) pairs keyed by reference dependency key. For single-name
791
- // / dependencies, an initial underscore indicates that the name does not
792
- // / cascade. For compound names, it is the first name, the holder which
793
- // / indicates non-cascading. For member names, an initial underscore indicates
794
- // / file-privacy.
795
- static SourceFileDepGraph
796
- simulateLoad (std::string swiftDepsFileName, const bool includePrivateDeps,
797
- const bool hadCompilationError, std::string interfaceHash,
798
- llvm::StringMap<std::vector<std::string>> simpleNamesByRDK,
799
- llvm::StringMap<std::vector<std::pair<std::string, std::string>>>
800
- compoundNamesByRDK);
801
-
802
- static constexpr char noncascadingOrPrivatePrefix = ' #' ;
803
- static constexpr char nameFingerprintSeparator = ' ,' ;
804
-
805
- static std::string noncascading (std::string name);
806
-
807
- LLVM_ATTRIBUTE_UNUSED
808
- static std::string privatize (std::string name);
809
-
810
-
811
813
// / Nodes are owned by the graph.
812
814
~SourceFileDepGraph () {
813
815
forEachNode ([&](SourceFileDepGraphNode *n) { delete n; });
@@ -851,12 +853,15 @@ class SourceFileDepGraph {
851
853
// / The frontend creates a pair of nodes for every tracked Decl and the source
852
854
// / file itself.
853
855
InterfaceAndImplementationPair<SourceFileDepGraphNode>
854
- findExistingNodePairOrCreateAndAddIfNew (
855
- NodeKind k, const ContextNameFingerprint &contextNameFingerprint);
856
+ findExistingNodePairOrCreateAndAddIfNew (const DependencyKey &interfaceKey,
857
+ Optional<StringRef> fingerprint);
858
+
859
+ NullablePtr<SourceFileDepGraphNode>
860
+ findExistingNode (const DependencyKey &key);
856
861
857
862
SourceFileDepGraphNode *
858
- findExistingNodeOrCreateIfNew (DependencyKey key,
859
- const Optional<std::string> & fingerprint,
863
+ findExistingNodeOrCreateIfNew (const DependencyKey & key,
864
+ const Optional<StringRef> fingerprint,
860
865
bool isProvides);
861
866
862
867
// / \p Use is the Node that must be rebuilt when \p def changes.
0 commit comments