|
47 | 47 | #include "llvm/ADT/TinyPtrVector.h" |
48 | 48 | #include "llvm/Support/Allocator.h" |
49 | 49 | #include "llvm/Support/DataTypes.h" |
| 50 | +#include "llvm/Support/VersionTuple.h" |
50 | 51 | #include "llvm/Support/VirtualOutputBackend.h" |
51 | 52 | #include <functional> |
52 | 53 | #include <memory> |
@@ -409,9 +410,17 @@ class ASTContext final { |
409 | 410 | /// Cache of module names that fail the 'canImport' test in this context. |
410 | 411 | mutable llvm::StringSet<> FailedModuleImportNames; |
411 | 412 |
|
| 413 | + /// Versions of the modules found during versioned canImport checks. |
| 414 | + struct ImportedModuleVersionInfo { |
| 415 | + llvm::VersionTuple Version; |
| 416 | + llvm::VersionTuple UnderlyingVersion; |
| 417 | + }; |
| 418 | + |
412 | 419 | /// Cache of module names that passed the 'canImport' test. This cannot be |
413 | | - /// mutable since it needs to be queried for dependency discovery. |
414 | | - llvm::StringSet<> SucceededModuleImportNames; |
| 420 | + /// mutable since it needs to be queried for dependency discovery. Keep sorted |
| 421 | + /// so caller of `forEachCanImportVersionCheck` can expect deterministic |
| 422 | + /// ordering. |
| 423 | + std::map<std::string, ImportedModuleVersionInfo> CanImportModuleVersions; |
415 | 424 |
|
416 | 425 | /// Set if a `-module-alias` was passed. Used to store mapping between module aliases and |
417 | 426 | /// their corresponding real names, and vice versa for a reverse lookup, which is needed to check |
@@ -1102,7 +1111,12 @@ class ASTContext final { |
1102 | 1111 | /// module is loaded in full. |
1103 | 1112 | bool canImportModuleImpl(ImportPath::Module ModulePath, |
1104 | 1113 | llvm::VersionTuple version, bool underlyingVersion, |
1105 | | - bool updateFailingList) const; |
| 1114 | + bool updateFailingList, |
| 1115 | + llvm::VersionTuple &foundVersion) const; |
| 1116 | + |
| 1117 | + /// Add successful canImport modules. |
| 1118 | + void addSucceededCanImportModule(StringRef moduleName, bool underlyingVersion, |
| 1119 | + const llvm::VersionTuple &versionInfo); |
1106 | 1120 |
|
1107 | 1121 | public: |
1108 | 1122 | namelookup::ImportCache &getImportCache() const; |
@@ -1144,10 +1158,10 @@ class ASTContext final { |
1144 | 1158 | llvm::VersionTuple version = llvm::VersionTuple(), |
1145 | 1159 | bool underlyingVersion = false) const; |
1146 | 1160 |
|
1147 | | - /// \returns a set of names from all successfully canImport module checks. |
1148 | | - const llvm::StringSet<> &getSuccessfulCanImportCheckNames() const { |
1149 | | - return SucceededModuleImportNames; |
1150 | | - } |
| 1161 | + /// Callback on each successful imported. |
| 1162 | + void forEachCanImportVersionCheck( |
| 1163 | + std::function<void(StringRef, const llvm::VersionTuple &, |
| 1164 | + const llvm::VersionTuple &)>) const; |
1151 | 1165 |
|
1152 | 1166 | /// \returns a module with a given name that was already loaded. If the |
1153 | 1167 | /// module was not loaded, returns nullptr. |
|
0 commit comments