Skip to content

Commit 01429f8

Browse files
committed
Extend PreModuleImportCallback to support bridging header compilation
1 parent 5aaa17f commit 01429f8

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

include/swift/AST/ASTContext.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,19 @@ class ASTContext final {
295295
/// OutputBackend for writing outputs.
296296
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutputBackend;
297297

298+
enum ModuleImportKind {
299+
Module = 0,
300+
Overlay,
301+
BridgingHeader
302+
};
303+
using PreModuleImportCallbackPtr =
304+
std::function<void(StringRef ModuleName, ModuleImportKind Kind)>;
298305
/// Set the callback function that is invoked before Swift module importing is
299-
/// performed
300-
void SetPreModuleImportCallback(
301-
std::function<void(llvm::StringRef ModuleName, bool IsOverlay)> callback);
306+
/// performed.
307+
void SetPreModuleImportCallback(PreModuleImportCallbackPtr callback);
308+
309+
/// Call the PreModuleImportCallback. Used by ClangImporter.
310+
void PreModuleImportHook(StringRef ModuleName, ModuleImportKind Kind) const;
302311

303312
/// If the shared pointer is not a \c nullptr and the pointee is \c true,
304313
/// all operations working on this ASTContext should be aborted at the next
@@ -414,8 +423,7 @@ class ASTContext final {
414423
getAllocator(AllocationArena arena = AllocationArena::Permanent) const;
415424

416425
/// An optional generic callback function invoked prior to importing a module.
417-
mutable std::function<void(llvm::StringRef ModuleName, bool IsOverlay)>
418-
PreModuleImportCallback;
426+
mutable PreModuleImportCallbackPtr PreModuleImportCallback;
419427

420428
public:
421429
/// Allocate - Allocate memory from the ASTContext bump pointer.

lib/AST/ASTContext.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,10 +761,17 @@ ASTContext::~ASTContext() {
761761
}
762762

763763
void ASTContext::SetPreModuleImportCallback(
764-
std::function<void(llvm::StringRef ModuleName, bool IsOverlay)> callback) {
764+
PreModuleImportCallbackPtr callback) {
765765
PreModuleImportCallback = callback;
766766
}
767767

768+
ASTContext::PreModuleImportCallbackPtr
769+
ASTContext::PreModuleImportHook(StringRef ModuleName,
770+
ModuleImportKind Kind) const {
771+
if (PreModuleImportCallback)
772+
PreModuleImportCallback(ModuleName, Kind);
773+
}
774+
768775
llvm::BumpPtrAllocator &ASTContext::getAllocator(AllocationArena arena) const {
769776
switch (arena) {
770777
case AllocationArena::Permanent:
@@ -2476,7 +2483,7 @@ ASTContext::getModule(ImportPath::Module ModulePath, bool AllowMemoryCached) {
24762483

24772484
auto moduleID = ModulePath[0];
24782485
if (PreModuleImportCallback)
2479-
PreModuleImportCallback(moduleID.Item.str(), false /*=IsOverlay*/);
2486+
PreModuleImportCallback(moduleID.Item.str(), ModuleImportKind::Module);
24802487
for (auto &importer : getImpl().ModuleLoaders) {
24812488
if (ModuleDecl *M = importer->loadModule(moduleID.Loc, ModulePath,
24822489
AllowMemoryCached)) {
@@ -2509,7 +2516,7 @@ ModuleDecl *ASTContext::getOverlayModule(const FileUnit *FU) {
25092516
SmallString<16> path;
25102517
ModPath.getString(path);
25112518
if (!path.empty())
2512-
PreModuleImportCallback(path.str(), /*IsOverlay=*/true);
2519+
PreModuleImportCallback(path.str(), ModuleImportKind::Overlay);
25132520
}
25142521
for (auto &importer : getImpl().ModuleLoaders) {
25152522
if (importer.get() == getClangModuleLoader())

lib/ClangImporter/ClangImporter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,10 @@ bool ClangImporter::Implementation::importHeader(
15391539
std::unique_ptr<llvm::MemoryBuffer> sourceBuffer,
15401540
bool implicitImport) {
15411541

1542+
// Progress update for the debugger.
1543+
SwiftContext.PreModuleImportHook(
1544+
headerName, ASTContext::ModuleImportKind::BridgingHeader);
1545+
15421546
// Don't even try to load the bridging header if the Clang AST is in a bad
15431547
// state. It could cause a crash.
15441548
auto &clangDiags = getClangASTContext().getDiagnostics();

0 commit comments

Comments
 (0)