Skip to content

Commit 799eb1b

Browse files
committed
[ASTContext] Add setter for LLDB callback
`PreModuleImportCallback` is a variable for a callback function used specifically by LLDB to report progress updates on importing Swift modules in LLDB. This commit adds a setter for `PreModuleImportCallback` for greater flexibility in LLDB and removes the reference to this variable in the constructor. Related to swiftlang/llvm-project#7769 rdar://105286354
1 parent 5a66b62 commit 799eb1b

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

include/swift/AST/ASTContext.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ class ASTContext final {
239239
ClangImporterOptions &ClangImporterOpts,
240240
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
241241
SourceManager &SourceMgr, DiagnosticEngine &Diags,
242-
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend = nullptr,
243-
std::function<bool(llvm::StringRef, bool)> PreModuleImportCallback = {});
242+
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend = nullptr
243+
);
244244

245245
public:
246246
// Members that should only be used by ASTContext.cpp.
@@ -257,8 +257,8 @@ class ASTContext final {
257257
ClangImporterOptions &ClangImporterOpts,
258258
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
259259
SourceManager &SourceMgr, DiagnosticEngine &Diags,
260-
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend = nullptr,
261-
std::function<bool(llvm::StringRef, bool)> PreModuleImportCallback = {});
260+
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend = nullptr
261+
);
262262
~ASTContext();
263263

264264
/// Optional table of counters to report, nullptr when not collecting.
@@ -294,6 +294,8 @@ class ASTContext final {
294294
/// OutputBackend for writing outputs.
295295
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutputBackend;
296296

297+
void SetPreModuleImportCallback(std::function<bool(llvm::StringRef ModuleName, bool IsOverlay)> callback);
298+
297299
/// If the shared pointer is not a \c nullptr and the pointee is \c true,
298300
/// all operations working on this ASTContext should be aborted at the next
299301
/// possible opportunity.

lib/AST/ASTContext.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,8 @@ ASTContext *ASTContext::get(
629629
ClangImporterOptions &ClangImporterOpts,
630630
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
631631
SourceManager &SourceMgr, DiagnosticEngine &Diags,
632-
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutputBackend,
633-
std::function<bool(llvm::StringRef, bool)> PreModuleImportCallback) {
632+
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutputBackend
633+
) {
634634
// If more than two data structures are concatentated, then the aggregate
635635
// size math needs to become more complicated due to per-struct alignment
636636
// constraints.
@@ -644,7 +644,7 @@ ASTContext *ASTContext::get(
644644
return new (mem)
645645
ASTContext(langOpts, typecheckOpts, silOpts, SearchPathOpts,
646646
ClangImporterOpts, SymbolGraphOpts, SourceMgr, Diags,
647-
std::move(OutputBackend), PreModuleImportCallback);
647+
std::move(OutputBackend));
648648
}
649649

650650
ASTContext::ASTContext(
@@ -653,16 +653,15 @@ ASTContext::ASTContext(
653653
ClangImporterOptions &ClangImporterOpts,
654654
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
655655
SourceManager &SourceMgr, DiagnosticEngine &Diags,
656-
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend,
657-
std::function<bool(llvm::StringRef, bool)> PreModuleImportCallback)
656+
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend
657+
)
658658
: LangOpts(langOpts), TypeCheckerOpts(typecheckOpts), SILOpts(silOpts),
659659
SearchPathOpts(SearchPathOpts), ClangImporterOpts(ClangImporterOpts),
660660
SymbolGraphOpts(SymbolGraphOpts), SourceMgr(SourceMgr), Diags(Diags),
661661
OutputBackend(std::move(OutBackend)), evaluator(Diags, langOpts),
662662
TheBuiltinModule(createBuiltinModule(*this)),
663663
StdlibModuleName(getIdentifier(STDLIB_NAME)),
664664
SwiftShimsModuleName(getIdentifier(SWIFT_SHIMS_NAME)),
665-
PreModuleImportCallback(PreModuleImportCallback),
666665
TheErrorType(new (*this, AllocationArena::Permanent) ErrorType(
667666
*this, Type(), RecursiveTypeProperties::HasError)),
668667
TheUnresolvedType(new(*this, AllocationArena::Permanent)
@@ -715,6 +714,10 @@ ASTContext::~ASTContext() {
715714
getImpl().~Implementation();
716715
}
717716

717+
void ASTContext::SetPreModuleImportCallback(std::function<bool(llvm::StringRef ModuleName, bool IsOverlay)> callback) {
718+
ASTContext::PreModuleImportCallback = callback;
719+
}
720+
718721
llvm::BumpPtrAllocator &ASTContext::getAllocator(AllocationArena arena) const {
719722
switch (arena) {
720723
case AllocationArena::Permanent:

0 commit comments

Comments
 (0)