@@ -38,7 +38,6 @@ class Identifier;
38
38
enum class ModuleDependenciesKind : int8_t {
39
39
FirstKind,
40
40
SwiftInterface = FirstKind,
41
- SwiftSource,
42
41
SwiftBinary,
43
42
// Placeholder dependencies are a kind of dependencies used only by the
44
43
// dependency scanner. They are swift modules that the scanner will not be
@@ -64,7 +63,8 @@ enum class ModuleDependenciesKind : int8_t {
64
63
// of all targets, individually, have been computed.
65
64
SwiftPlaceholder,
66
65
Clang,
67
- LastKind = Clang + 1
66
+ SwiftSource,
67
+ LastKind = SwiftSource + 1
68
68
};
69
69
70
70
struct ModuleDependenciesKindHash {
@@ -98,6 +98,25 @@ class ModuleDependenciesStorageBase {
98
98
std::vector<std::string> moduleDependencies;
99
99
};
100
100
101
+ struct CommonSwiftTextualModuleDependencyDetails {
102
+ CommonSwiftTextualModuleDependencyDetails (ArrayRef<StringRef> extraPCMArgs)
103
+ : extraPCMArgs(extraPCMArgs.begin(), extraPCMArgs.end()) {}
104
+
105
+ // / To build a PCM to be used by this Swift module, we need to append these
106
+ // / arguments to the generic PCM build arguments reported from the dependency
107
+ // / graph.
108
+ const std::vector<std::string> extraPCMArgs;
109
+
110
+ // / Bridging header file, if there is one.
111
+ Optional<std::string> bridgingHeaderFile;
112
+
113
+ // / Source files on which the bridging header depends.
114
+ std::vector<std::string> bridgingSourceFiles;
115
+
116
+ // / (Clang) modules on which the bridging header depends.
117
+ std::vector<std::string> bridgingModuleDependencies;
118
+ };
119
+
101
120
// / Describes the dependencies of a Swift module described by an Swift interface file.
102
121
// /
103
122
// / This class is mostly an implementation detail for \c ModuleDependencies.
@@ -114,28 +133,14 @@ class SwiftInterfaceModuleDependenciesStorage :
114
133
// / interface.
115
134
const std::vector<std::string> buildCommandLine;
116
135
117
- // / To build a PCM to be used by this Swift module, we need to append these
118
- // / arguments to the generic PCM build arguments reported from the dependency
119
- // / graph.
120
- const std::vector<std::string> extraPCMArgs;
121
-
122
136
// / The hash value that will be used for the generated module
123
137
const std::string contextHash;
124
138
125
139
// / A flag that indicates this dependency is a framework
126
140
const bool isFramework;
127
141
128
- // / Bridging header file, if there is one.
129
- Optional<std::string> bridgingHeaderFile;
130
-
131
- // / Swift source files that are part of the Swift module, when known.
132
- std::vector<std::string> sourceFiles;
133
-
134
- // / Source files on which the bridging header depends.
135
- std::vector<std::string> bridgingSourceFiles;
136
-
137
- // / (Clang) modules on which the bridging header depends.
138
- std::vector<std::string> bridgingModuleDependencies;
142
+ // / Details common to Swift textual (interface or source) modules
143
+ CommonSwiftTextualModuleDependencyDetails textualModuleDetails;
139
144
140
145
SwiftInterfaceModuleDependenciesStorage (
141
146
const std::string swiftInterfaceFile,
@@ -149,8 +154,9 @@ class SwiftInterfaceModuleDependenciesStorage :
149
154
compiledModuleCandidates(compiledModuleCandidates.begin(),
150
155
compiledModuleCandidates.end()),
151
156
buildCommandLine(buildCommandLine.begin(), buildCommandLine.end()),
152
- extraPCMArgs(extraPCMArgs.begin(), extraPCMArgs.end()),
153
- contextHash(contextHash), isFramework(isFramework) { }
157
+ contextHash(contextHash), isFramework(isFramework),
158
+ textualModuleDetails(extraPCMArgs)
159
+ {}
154
160
155
161
ModuleDependenciesStorageBase *clone () const override {
156
162
return new SwiftInterfaceModuleDependenciesStorage (*this );
@@ -167,36 +173,26 @@ class SwiftInterfaceModuleDependenciesStorage :
167
173
class SwiftSourceModuleDependenciesStorage :
168
174
public ModuleDependenciesStorageBase {
169
175
public:
170
- // / To build a PCM to be used by this Swift module, we need to append these
171
- // / arguments to the generic PCM build arguments reported from the dependency
172
- // / graph.
173
- const std::vector<std::string> extraPCMArgs;
174
-
175
- // / Bridging header file, if there is one.
176
- Optional<std::string> bridgingHeaderFile;
177
176
178
177
// / Swift source files that are part of the Swift module, when known.
179
178
std::vector<std::string> sourceFiles;
180
179
181
- // / Source files on which the bridging header depends.
182
- std::vector<std::string> bridgingSourceFiles ;
180
+ // / Details common to Swift textual (interface or source) modules
181
+ CommonSwiftTextualModuleDependencyDetails textualModuleDetails ;
183
182
184
- // / (Clang) modules on which the bridging header depends.
185
- std::vector<std::string> bridgingModuleDependencies;
183
+ SwiftSourceModuleDependenciesStorage (
184
+ ArrayRef<StringRef> extraPCMArgs
185
+ ) : ModuleDependenciesStorageBase(ModuleDependenciesKind::SwiftSource),
186
+ textualModuleDetails (extraPCMArgs) {}
186
187
187
- SwiftSourceModuleDependenciesStorage (
188
- ArrayRef<StringRef> extraPCMArgs
189
- ) : ModuleDependenciesStorageBase(ModuleDependenciesKind::SwiftSource),
190
- extraPCMArgs (extraPCMArgs.begin(), extraPCMArgs.end()) {}
191
-
192
- ModuleDependenciesStorageBase *clone () const override {
193
- return new SwiftSourceModuleDependenciesStorage (*this );
194
- }
188
+ ModuleDependenciesStorageBase *clone () const override {
189
+ return new SwiftSourceModuleDependenciesStorage (*this );
190
+ }
195
191
196
- static bool classof (const ModuleDependenciesStorageBase *base) {
197
- return base->dependencyKind == ModuleDependenciesKind::SwiftSource;
198
- }
199
- };
192
+ static bool classof (const ModuleDependenciesStorageBase *base) {
193
+ return base->dependencyKind == ModuleDependenciesKind::SwiftSource;
194
+ }
195
+ };
200
196
201
197
// / Describes the dependencies of a pre-built Swift module (with no .swiftinterface).
202
198
// /
@@ -462,6 +458,14 @@ class ModuleDependencies {
462
458
463
459
using ModuleDependencyID = std::pair<std::string, ModuleDependenciesKind>;
464
460
using ModuleDependenciesVector = llvm::SmallVector<ModuleDependencies, 1 >;
461
+ using ModuleDependenciesKindMap =
462
+ std::unordered_map<ModuleDependenciesKind,
463
+ llvm::StringMap<ModuleDependenciesVector>,
464
+ ModuleDependenciesKindHash>;
465
+ using ModuleDependenciesKindRefMap =
466
+ std::unordered_map<ModuleDependenciesKind,
467
+ llvm::StringMap<const ModuleDependencies *>,
468
+ ModuleDependenciesKindHash>;
465
469
466
470
// / A cache describing the set of module dependencies that has been queried
467
471
// / thus far. This cache records/stores the actual Dependency values and can be
@@ -473,18 +477,35 @@ using ModuleDependenciesVector = llvm::SmallVector<ModuleDependencies, 1>;
473
477
// / ensure that the returned cached dependency was one that can be found in the
474
478
// / current scanning action's filesystem view.
475
479
class GlobalModuleDependenciesCache {
476
- // / All cached module dependencies, in the order in which they were
477
- // / encountered.
478
- std::vector<ModuleDependencyID> AllModules;
479
-
480
- // / Dependencies for modules that have already been computed.
481
- // / This maps a dependency kind to a map of a module's name to a vector of Dependency objects,
482
- // / which correspond to instances of the same module that may have been found
483
- // / in different sets of search paths.
484
- std::unordered_map<ModuleDependenciesKind,
485
- llvm::StringMap<ModuleDependenciesVector>,
486
- ModuleDependenciesKindHash>
487
- ModuleDependenciesKindMap;
480
+ // / Global cache contents specific to a target-triple specified on a scanner invocation
481
+ struct TargetSpecificGlobalCacheState {
482
+ // / All cached module dependencies, in the order in which they were
483
+ // / encountered.
484
+ std::vector<ModuleDependencyID> AllModules;
485
+
486
+ // / Dependencies for modules that have already been computed.
487
+ // / This maps a dependency kind to a map of a module's name to a vector of Dependency objects,
488
+ // / which correspond to instances of the same module that may have been found
489
+ // / in different sets of search paths.
490
+ ModuleDependenciesKindMap ModuleDependenciesMap;
491
+ };
492
+
493
+ // / All cached Swift source module dependencies, in the order in which they were encountered
494
+ std::vector<ModuleDependencyID> AllSourceModules;
495
+
496
+ // / Dependencies for all Swift source-based modules discovered. Each one is the main
497
+ // / module of a prior invocation of the scanner.
498
+ llvm::StringMap<ModuleDependencies> SwiftSourceModuleDependenciesMap;
499
+
500
+ // / A map from a String representing the target triple of a scanner invocation to the corresponding
501
+ // / cached dependencies discovered so far when using this triple.
502
+ llvm::StringMap<std::unique_ptr<TargetSpecificGlobalCacheState>> TargetSpecificCacheMap;
503
+
504
+ // / The current target triple cache configuration
505
+ Optional<std::string> CurrentTriple;
506
+
507
+ // / The triples used by scanners using this cache, in the order in which they were used
508
+ std::vector<std::string> AllTriples;
488
509
489
510
// / Additional information needed for Clang dependency scanning.
490
511
ClangModuleDependenciesCacheImpl *clangImpl = nullptr ;
@@ -506,13 +527,19 @@ class GlobalModuleDependenciesCache {
506
527
getDependenciesMap (ModuleDependenciesKind kind) const ;
507
528
508
529
public:
509
- GlobalModuleDependenciesCache ();
530
+ GlobalModuleDependenciesCache () {} ;
510
531
GlobalModuleDependenciesCache (const GlobalModuleDependenciesCache &) = delete ;
511
532
GlobalModuleDependenciesCache &
512
533
operator =(const GlobalModuleDependenciesCache &) = delete ;
513
534
514
535
virtual ~GlobalModuleDependenciesCache () { destroyClangImpl (); }
515
536
537
+ void configureForTriple (std::string triple);
538
+
539
+ const std::vector<std::string>& getAllTriples () const {
540
+ return AllTriples;
541
+ }
542
+
516
543
private:
517
544
// / Enforce clients not being allowed to query this cache directly, it must be
518
545
// / wrapped in an instance of `ModuleDependenciesCache`.
@@ -542,6 +569,12 @@ class GlobalModuleDependenciesCache {
542
569
Optional<ModuleDependencies>
543
570
findDependencies (StringRef moduleName, ModuleLookupSpecifics details) const ;
544
571
572
+ // / Return a pointer to the target-specific cache state of the current triple configuration.
573
+ TargetSpecificGlobalCacheState* getCurrentCache () const ;
574
+
575
+ // / Return a pointer to the target-specific cache state of the specified triple configuration.
576
+ TargetSpecificGlobalCacheState* getCacheForTriple (StringRef triple) const ;
577
+
545
578
public:
546
579
// / Look for module dependencies for a module with the given name.
547
580
// / This method has a deliberately-obtuse name to indicate that it is not to
@@ -552,6 +585,10 @@ class GlobalModuleDependenciesCache {
552
585
findAllDependenciesIrrespectiveOfSearchPaths (
553
586
StringRef moduleName, Optional<ModuleDependenciesKind> kind) const ;
554
587
588
+ // / Look for source-based module dependency details
589
+ Optional<ModuleDependencies>
590
+ findSourceModuleDependency (StringRef moduleName) const ;
591
+
555
592
// / Record dependencies for the given module.
556
593
const ModuleDependencies *recordDependencies (StringRef moduleName,
557
594
ModuleDependencies dependencies);
@@ -560,9 +597,16 @@ class GlobalModuleDependenciesCache {
560
597
const ModuleDependencies *updateDependencies (ModuleDependencyID moduleID,
561
598
ModuleDependencies dependencies);
562
599
563
- // / Reference the list of all module dependencies.
564
- const std::vector<ModuleDependencyID> &getAllModules () const {
565
- return AllModules;
600
+ // / Reference the list of all module dependencies that are not source-based modules
601
+ // / (i.e. interface dependencies, binary dependencies, clang dependencies).
602
+ const std::vector<ModuleDependencyID> &getAllNonSourceModules (StringRef triple) const {
603
+ auto targetSpecificCache = getCacheForTriple (triple);
604
+ return targetSpecificCache->AllModules ;
605
+ }
606
+
607
+ // / Return the list of all source-based modules discovered by this cache
608
+ const std::vector<ModuleDependencyID> &getAllSourceModules () const {
609
+ return AllSourceModules;
566
610
}
567
611
};
568
612
@@ -578,10 +622,7 @@ class ModuleDependenciesCache {
578
622
579
623
// / References to data in `globalCache` for dependencies accimulated during
580
624
// / the current scanning action.
581
- std::unordered_map<ModuleDependenciesKind,
582
- llvm::StringMap<const ModuleDependencies *>,
583
- ModuleDependenciesKindHash>
584
- ModuleDependenciesKindMap;
625
+ ModuleDependenciesKindRefMap ModuleDependenciesMap;
585
626
586
627
// / Retrieve the dependencies map that corresponds to the given dependency
587
628
// / kind.
@@ -651,9 +692,8 @@ class ModuleDependenciesCache {
651
692
void updateDependencies (ModuleDependencyID moduleID,
652
693
ModuleDependencies dependencies);
653
694
654
- // / Reference the list of all module dependencies.
655
- const std::vector<ModuleDependencyID> &getAllModules () const {
656
- return globalCache.getAllModules ();
695
+ const std::vector<ModuleDependencyID> &getAllSourceModules () const {
696
+ return globalCache.getAllSourceModules ();
657
697
}
658
698
};
659
699
0 commit comments