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,8 @@ 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 (llvm::formatv (" Loading module {0}" , M->getNameStr ()).str ());
2215
2219
if (LangOpts.EnableModuleLoadingRemarks ) {
2216
2220
Diags.diagnose (ModulePath.getSourceRange ().Start ,
2217
2221
diag::module_loaded,
@@ -2224,7 +2228,9 @@ ASTContext::getModule(ImportPath::Module ModulePath) {
2224
2228
return nullptr ;
2225
2229
}
2226
2230
2227
- ModuleDecl *ASTContext::getOverlayModule (const FileUnit *FU) {
2231
+ ModuleDecl *
2232
+ ASTContext::getOverlayModule (const FileUnit *FU,
2233
+ std::function<bool (llvm::StringRef)> callback) {
2228
2234
assert (FU && FU->getKind () == FileUnitKind::ClangModule &&
2229
2235
" Overlays can only be retrieved for clang modules!" );
2230
2236
ImportPath::Module::Builder builder (FU->getParentModule ()->getName ());
@@ -2238,30 +2244,39 @@ ModuleDecl *ASTContext::getOverlayModule(const FileUnit *FU) {
2238
2244
if (importer.get () == getClangModuleLoader ())
2239
2245
continue ;
2240
2246
if (ModuleDecl *M = importer->loadModule (SourceLoc (), ModPath)) {
2247
+ if (callback)
2248
+ callback (
2249
+ llvm::formatv (" Loading overlay module {0}" , M->getNameStr ()).str ());
2241
2250
return M;
2242
2251
}
2243
2252
}
2244
2253
2245
2254
return nullptr ;
2246
2255
}
2247
2256
2248
- ModuleDecl *ASTContext::getModuleByName (StringRef ModuleName) {
2257
+ ModuleDecl *
2258
+ ASTContext::getModuleByName (StringRef ModuleName,
2259
+ std::function<bool (llvm::StringRef)> callback) {
2249
2260
ImportPath::Module::Builder builder (*this , ModuleName, /* separator=*/ ' .' );
2250
- return getModule (builder.get ());
2261
+ return getModule (builder.get (), callback );
2251
2262
}
2252
2263
2253
- ModuleDecl *ASTContext::getModuleByIdentifier (Identifier ModuleID) {
2264
+ ModuleDecl *ASTContext::getModuleByIdentifier (
2265
+ Identifier ModuleID, std::function<bool (llvm::StringRef)> callback) {
2254
2266
ImportPath::Module::Builder builder (ModuleID);
2255
- return getModule (builder.get ());
2267
+ return getModule (builder.get (), callback );
2256
2268
}
2257
2269
2258
- ModuleDecl *ASTContext::getStdlibModule (bool loadIfAbsent) {
2270
+ ModuleDecl *
2271
+ ASTContext::getStdlibModule (bool loadIfAbsent,
2272
+ std::function<bool (llvm::StringRef)> callback) {
2259
2273
if (TheStdlibModule)
2260
2274
return TheStdlibModule;
2261
2275
2262
2276
if (loadIfAbsent) {
2263
2277
auto mutableThis = const_cast <ASTContext*>(this );
2264
- TheStdlibModule = mutableThis->getModuleByIdentifier (StdlibModuleName);
2278
+ TheStdlibModule =
2279
+ mutableThis->getModuleByIdentifier (StdlibModuleName, callback);
2265
2280
} else {
2266
2281
TheStdlibModule = getLoadedModule (StdlibModuleName);
2267
2282
}
0 commit comments