42
42
#include " swift/AST/PropertyWrappers.h"
43
43
#include " swift/AST/ProtocolConformance.h"
44
44
#include " swift/AST/RawComment.h"
45
- #include " swift/AST/SearchPathOptions.h"
46
45
#include " swift/AST/SILLayout.h"
46
+ #include " swift/AST/SearchPathOptions.h"
47
47
#include " swift/AST/SemanticAttrs.h"
48
48
#include " swift/AST/SourceFile.h"
49
49
#include " swift/AST/SubstitutionMap.h"
65
65
#include " llvm/IR/LLVMContext.h"
66
66
#include " llvm/Support/Allocator.h"
67
67
#include " llvm/Support/Compiler.h"
68
+ #include " llvm/Support/FormatVariadic.h"
68
69
#include < algorithm>
69
70
#include < memory>
70
71
@@ -2203,7 +2204,8 @@ bool ASTContext::canImportModule(ImportPath::Module ModuleName,
2203
2204
}
2204
2205
2205
2206
ModuleDecl *
2206
- ASTContext::getModule (ImportPath::Module ModulePath) {
2207
+ ASTContext::getModule (ImportPath::Module ModulePath,
2208
+ std::function<bool (llvm::StringRef)> callback) {
2207
2209
assert (!ModulePath.empty ());
2208
2210
2209
2211
if (auto *M = getLoadedModule (ModulePath))
@@ -2212,6 +2214,10 @@ ASTContext::getModule(ImportPath::Module ModulePath) {
2212
2214
auto moduleID = ModulePath[0 ];
2213
2215
for (auto &importer : getImpl ().ModuleLoaders ) {
2214
2216
if (ModuleDecl *M = importer->loadModule (moduleID.Loc , ModulePath)) {
2217
+ if (callback)
2218
+ callback (
2219
+ llvm::formatv (" Loading module overlay for {0}" , M->getNameStr ())
2220
+ .str ());
2215
2221
if (LangOpts.EnableModuleLoadingRemarks ) {
2216
2222
Diags.diagnose (ModulePath.getSourceRange ().Start ,
2217
2223
diag::module_loaded,
@@ -2224,7 +2230,9 @@ ASTContext::getModule(ImportPath::Module ModulePath) {
2224
2230
return nullptr ;
2225
2231
}
2226
2232
2227
- ModuleDecl *ASTContext::getOverlayModule (const FileUnit *FU) {
2233
+ ModuleDecl *
2234
+ ASTContext::getOverlayModule (const FileUnit *FU,
2235
+ std::function<bool (llvm::StringRef)> callback) {
2228
2236
assert (FU && FU->getKind () == FileUnitKind::ClangModule &&
2229
2237
" Overlays can only be retrieved for clang modules!" );
2230
2238
ImportPath::Module::Builder builder (FU->getParentModule ()->getName ());
@@ -2238,30 +2246,40 @@ ModuleDecl *ASTContext::getOverlayModule(const FileUnit *FU) {
2238
2246
if (importer.get () == getClangModuleLoader ())
2239
2247
continue ;
2240
2248
if (ModuleDecl *M = importer->loadModule (SourceLoc (), ModPath)) {
2249
+ if (callback)
2250
+ callback (
2251
+ llvm::formatv (" Loading module overlay for {0}" , M->getNameStr ())
2252
+ .str ());
2241
2253
return M;
2242
2254
}
2243
2255
}
2244
2256
2245
2257
return nullptr ;
2246
2258
}
2247
2259
2248
- ModuleDecl *ASTContext::getModuleByName (StringRef ModuleName) {
2260
+ ModuleDecl *
2261
+ ASTContext::getModuleByName (StringRef ModuleName,
2262
+ std::function<bool (llvm::StringRef)> callback) {
2249
2263
ImportPath::Module::Builder builder (*this , ModuleName, /* separator=*/ ' .' );
2250
- return getModule (builder.get ());
2264
+ return getModule (builder.get (), callback );
2251
2265
}
2252
2266
2253
- ModuleDecl *ASTContext::getModuleByIdentifier (Identifier ModuleID) {
2267
+ ModuleDecl *ASTContext::getModuleByIdentifier (
2268
+ Identifier ModuleID, std::function<bool (llvm::StringRef)> callback) {
2254
2269
ImportPath::Module::Builder builder (ModuleID);
2255
- return getModule (builder.get ());
2270
+ return getModule (builder.get (), callback );
2256
2271
}
2257
2272
2258
- ModuleDecl *ASTContext::getStdlibModule (bool loadIfAbsent) {
2273
+ ModuleDecl *
2274
+ ASTContext::getStdlibModule (bool loadIfAbsent,
2275
+ std::function<bool (llvm::StringRef)> callback) {
2259
2276
if (TheStdlibModule)
2260
2277
return TheStdlibModule;
2261
2278
2262
2279
if (loadIfAbsent) {
2263
2280
auto mutableThis = const_cast <ASTContext*>(this );
2264
- TheStdlibModule = mutableThis->getModuleByIdentifier (StdlibModuleName);
2281
+ TheStdlibModule =
2282
+ mutableThis->getModuleByIdentifier (StdlibModuleName, callback);
2265
2283
} else {
2266
2284
TheStdlibModule = getLoadedModule (StdlibModuleName);
2267
2285
}
0 commit comments