Skip to content

Commit 23519be

Browse files
Merge pull request #71318 from adrian-prantl/bridging-header-progress
Extend PreModuleImportCallback to support bridging header compilation
2 parents a6fb421 + c6c688c commit 23519be

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
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: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -761,10 +761,16 @@ 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+
void ASTContext::PreModuleImportHook(StringRef ModuleName,
769+
ModuleImportKind Kind) const {
770+
if (PreModuleImportCallback)
771+
PreModuleImportCallback(ModuleName, Kind);
772+
}
773+
768774
llvm::BumpPtrAllocator &ASTContext::getAllocator(AllocationArena arena) const {
769775
switch (arena) {
770776
case AllocationArena::Permanent:
@@ -2475,8 +2481,7 @@ ASTContext::getModule(ImportPath::Module ModulePath, bool AllowMemoryCached) {
24752481
return M;
24762482

24772483
auto moduleID = ModulePath[0];
2478-
if (PreModuleImportCallback)
2479-
PreModuleImportCallback(moduleID.Item.str(), false /*=IsOverlay*/);
2484+
PreModuleImportHook(moduleID.Item.str(), ModuleImportKind::Module);
24802485
for (auto &importer : getImpl().ModuleLoaders) {
24812486
if (ModuleDecl *M = importer->loadModule(moduleID.Loc, ModulePath,
24822487
AllowMemoryCached)) {
@@ -2509,7 +2514,7 @@ ModuleDecl *ASTContext::getOverlayModule(const FileUnit *FU) {
25092514
SmallString<16> path;
25102515
ModPath.getString(path);
25112516
if (!path.empty())
2512-
PreModuleImportCallback(path.str(), /*IsOverlay=*/true);
2517+
PreModuleImportCallback(path.str(), ModuleImportKind::Overlay);
25132518
}
25142519
for (auto &importer : getImpl().ModuleLoaders) {
25152520
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)