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,14 +2204,17 @@ 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))
2210
2212
return M;
2211
2213
2212
2214
auto moduleID = ModulePath[0 ];
2213
2215
for (auto &importer : getImpl ().ModuleLoaders ) {
2216
+ if (callback)
2217
+ callback (llvm::formatv (" Loading module {0}" , moduleID.Item .str ()).str ());
2214
2218
if (ModuleDecl *M = importer->loadModule (moduleID.Loc , ModulePath)) {
2215
2219
if (LangOpts.EnableModuleLoadingRemarks ) {
2216
2220
Diags.diagnose (ModulePath.getSourceRange ().Start ,
@@ -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 ());
@@ -2237,31 +2243,42 @@ ModuleDecl *ASTContext::getOverlayModule(const FileUnit *FU) {
2237
2243
for (auto &importer : getImpl ().ModuleLoaders ) {
2238
2244
if (importer.get () == getClangModuleLoader ())
2239
2245
continue ;
2240
- if (ModuleDecl *M = importer->loadModule (SourceLoc (), ModPath)) {
2241
- return M;
2246
+ if (callback) {
2247
+ SmallString<256 > path;
2248
+ ModPath.getString (path);
2249
+ if (!path.empty ())
2250
+ callback (llvm::formatv (" Loading overlay module {0}" , path).str ());
2242
2251
}
2252
+ if (ModuleDecl *M = importer->loadModule (SourceLoc (), ModPath))
2253
+ return M;
2243
2254
}
2244
2255
2245
2256
return nullptr ;
2246
2257
}
2247
2258
2248
- ModuleDecl *ASTContext::getModuleByName (StringRef ModuleName) {
2259
+ ModuleDecl *
2260
+ ASTContext::getModuleByName (StringRef ModuleName,
2261
+ std::function<bool (llvm::StringRef)> callback) {
2249
2262
ImportPath::Module::Builder builder (*this , ModuleName, /* separator=*/ ' .' );
2250
- return getModule (builder.get ());
2263
+ return getModule (builder.get (), callback );
2251
2264
}
2252
2265
2253
- ModuleDecl *ASTContext::getModuleByIdentifier (Identifier ModuleID) {
2266
+ ModuleDecl *ASTContext::getModuleByIdentifier (
2267
+ Identifier ModuleID, std::function<bool (llvm::StringRef)> callback) {
2254
2268
ImportPath::Module::Builder builder (ModuleID);
2255
- return getModule (builder.get ());
2269
+ return getModule (builder.get (), callback );
2256
2270
}
2257
2271
2258
- ModuleDecl *ASTContext::getStdlibModule (bool loadIfAbsent) {
2272
+ ModuleDecl *
2273
+ ASTContext::getStdlibModule (bool loadIfAbsent,
2274
+ std::function<bool (llvm::StringRef)> callback) {
2259
2275
if (TheStdlibModule)
2260
2276
return TheStdlibModule;
2261
2277
2262
2278
if (loadIfAbsent) {
2263
2279
auto mutableThis = const_cast <ASTContext*>(this );
2264
- TheStdlibModule = mutableThis->getModuleByIdentifier (StdlibModuleName);
2280
+ TheStdlibModule =
2281
+ mutableThis->getModuleByIdentifier (StdlibModuleName, callback);
2265
2282
} else {
2266
2283
TheStdlibModule = getLoadedModule (StdlibModuleName);
2267
2284
}
0 commit comments