4242#include " swift/AST/PropertyWrappers.h"
4343#include " swift/AST/ProtocolConformance.h"
4444#include " swift/AST/RawComment.h"
45- #include " swift/AST/SearchPathOptions.h"
4645#include " swift/AST/SILLayout.h"
46+ #include " swift/AST/SearchPathOptions.h"
4747#include " swift/AST/SemanticAttrs.h"
4848#include " swift/AST/SourceFile.h"
4949#include " swift/AST/SubstitutionMap.h"
6565#include " llvm/IR/LLVMContext.h"
6666#include " llvm/Support/Allocator.h"
6767#include " llvm/Support/Compiler.h"
68+ #include " llvm/Support/FormatVariadic.h"
6869#include < algorithm>
6970#include < memory>
7071
@@ -578,13 +579,13 @@ void ASTContext::operator delete(void *Data) throw() {
578579 AlignedFree (Data);
579580}
580581
581- ASTContext *ASTContext::get (LangOptions &langOpts,
582- TypeCheckerOptions &typecheckOpts , SILOptions &silOpts,
583- SearchPathOptions &SearchPathOpts,
584- ClangImporterOptions &ClangImporterOpts ,
585- symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts ,
586- SourceManager &SourceMgr, DiagnosticEngine &Diags ) {
587- // If more than two data structures are concatenated , then the aggregate
582+ ASTContext *ASTContext::get (
583+ LangOptions &langOpts, TypeCheckerOptions &typeckOpts , SILOptions &silOpts,
584+ SearchPathOptions &SearchPathOpts, ClangImporterOptions &ClangImporterOpts ,
585+ symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts ,
586+ SourceManager &SourceMgr, DiagnosticEngine &Diags ,
587+ std::function< bool (llvm::StringRef, bool )> PreModuleImportCallback ) {
588+ // If more than two data structures are concatentated , then the aggregate
588589 // size math needs to become more complicated due to per-struct alignment
589590 // constraints.
590591 auto align = std::max (alignof (ASTContext), alignof (Implementation));
@@ -594,19 +595,21 @@ ASTContext *ASTContext::get(LangOptions &langOpts,
594595 impl = reinterpret_cast <void *>(
595596 llvm::alignAddr (impl, llvm::Align (alignof (Implementation))));
596597 new (impl) Implementation ();
597- return new (mem)
598- ASTContext (langOpts, typecheckOpts, silOpts, SearchPathOpts ,
599- ClangImporterOpts, SymbolGraphOpts, SourceMgr, Diags);
598+ return new (mem) ASTContext (langOpts, typeckOpts, silOpts, SearchPathOpts,
599+ ClangImporterOpts, SymbolGraphOpts, SourceMgr ,
600+ Diags, PreModuleImportCallback );
600601}
601602
602- ASTContext::ASTContext (LangOptions &langOpts, TypeCheckerOptions &typecheckOpts,
603- SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
604- ClangImporterOptions &ClangImporterOpts,
605- symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
606- SourceManager &SourceMgr, DiagnosticEngine &Diags)
603+ ASTContext::ASTContext (
604+ LangOptions &langOpts, TypeCheckerOptions &typeckOpts, SILOptions &silOpts,
605+ SearchPathOptions &SearchPathOpts, ClangImporterOptions &ClangImporterOpts,
606+ symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
607+ SourceManager &SourceMgr, DiagnosticEngine &Diags,
608+ std::function<bool (llvm::StringRef, bool )> PreModuleImportCallback)
607609 : LangOpts(langOpts), TypeCheckerOpts(typecheckOpts), SILOpts(silOpts),
608610 SearchPathOpts (SearchPathOpts), ClangImporterOpts(ClangImporterOpts),
609611 SymbolGraphOpts(SymbolGraphOpts), SourceMgr(SourceMgr), Diags(Diags),
612+ PreModuleImportCallback(PreModuleImportCallback),
610613 evaluator(Diags, langOpts), TheBuiltinModule(createBuiltinModule(*this )),
611614 StdlibModuleName(getIdentifier(STDLIB_NAME)),
612615 SwiftShimsModuleName(getIdentifier(SWIFT_SHIMS_NAME)),
@@ -622,18 +625,18 @@ ASTContext::ASTContext(LangOptions &langOpts, TypeCheckerOptions &typecheckOpts,
622625 The##SHORT_ID##Type(new (*this , AllocationArena::Permanent) \
623626 ID##Type(*this )),
624627#include " swift/AST/TypeNodes.def"
625- TheIEEE32Type (new (*this , AllocationArena::Permanent)
626- BuiltinFloatType(BuiltinFloatType::IEEE32,*this )),
627- TheIEEE64Type(new (*this , AllocationArena::Permanent)
628- BuiltinFloatType(BuiltinFloatType::IEEE64,*this )),
629- TheIEEE16Type(new (*this , AllocationArena::Permanent)
630- BuiltinFloatType(BuiltinFloatType::IEEE16,*this )),
631- TheIEEE80Type(new (*this , AllocationArena::Permanent)
632- BuiltinFloatType(BuiltinFloatType::IEEE80,*this )),
633- TheIEEE128Type(new (*this , AllocationArena::Permanent)
634- BuiltinFloatType(BuiltinFloatType::IEEE128, *this )),
635- ThePPC128Type(new (*this , AllocationArena::Permanent)
636- BuiltinFloatType(BuiltinFloatType::PPC128, *this )) {
628+ TheIEEE32Type (new (*this , AllocationArena::Permanent)
629+ BuiltinFloatType(BuiltinFloatType::IEEE32, *this )),
630+ TheIEEE64Type(new (*this , AllocationArena::Permanent)
631+ BuiltinFloatType(BuiltinFloatType::IEEE64, *this )),
632+ TheIEEE16Type(new (*this , AllocationArena::Permanent)
633+ BuiltinFloatType(BuiltinFloatType::IEEE16, *this )),
634+ TheIEEE80Type(new (*this , AllocationArena::Permanent)
635+ BuiltinFloatType(BuiltinFloatType::IEEE80, *this )),
636+ TheIEEE128Type(new (*this , AllocationArena::Permanent)
637+ BuiltinFloatType(BuiltinFloatType::IEEE128, *this )),
638+ ThePPC128Type(new (*this , AllocationArena::Permanent)
639+ BuiltinFloatType(BuiltinFloatType::PPC128, *this )) {
637640
638641 // Initialize all of the known identifiers.
639642#define IDENTIFIER_WITH_NAME (Name, IdStr ) Id_##Name = getIdentifier(IdStr);
@@ -2211,6 +2214,8 @@ ASTContext::getModule(ImportPath::Module ModulePath) {
22112214 return M;
22122215
22132216 auto moduleID = ModulePath[0 ];
2217+ if (PreModuleImportCallback)
2218+ PreModuleImportCallback (moduleID.Item .str (), false /* =IsOverlay*/ );
22142219 for (auto &importer : getImpl ().ModuleLoaders ) {
22152220 if (ModuleDecl *M = importer->loadModule (moduleID.Loc , ModulePath)) {
22162221 if (LangOpts.EnableModuleLoadingRemarks ) {
@@ -2235,12 +2240,17 @@ ModuleDecl *ASTContext::getOverlayModule(const FileUnit *FU) {
22352240 return Existing;
22362241 }
22372242
2243+ if (PreModuleImportCallback) {
2244+ SmallString<16 > path;
2245+ ModPath.getString (path);
2246+ if (!path.empty ())
2247+ PreModuleImportCallback (path.str (), /* IsOverlay=*/ true );
2248+ }
22382249 for (auto &importer : getImpl ().ModuleLoaders ) {
22392250 if (importer.get () == getClangModuleLoader ())
22402251 continue ;
2241- if (ModuleDecl *M = importer->loadModule (SourceLoc (), ModPath)) {
2252+ if (ModuleDecl *M = importer->loadModule (SourceLoc (), ModPath))
22422253 return M;
2243- }
22442254 }
22452255
22462256 return nullptr ;
0 commit comments