Skip to content

[ASTContext] Add setter for PreModuleImportCallback #69730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ class ASTContext final {
ClangImporterOptions &ClangImporterOpts,
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
SourceManager &SourceMgr, DiagnosticEngine &Diags,
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend = nullptr,
std::function<bool(llvm::StringRef, bool)> PreModuleImportCallback = {});
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend = nullptr
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting formatting. Is that really clang-format's output ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it is, other than removing the callback in the constructor I didn't change anything else here.


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

/// Optional table of counters to report, nullptr when not collecting.
Expand Down Expand Up @@ -294,6 +294,11 @@ class ASTContext final {
/// OutputBackend for writing outputs.
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutputBackend;

/// Set the callback function that is invoked before Swift module importing is
/// performed
void SetPreModuleImportCallback(
std::function<void(llvm::StringRef ModuleName, bool IsOverlay)> callback);

/// If the shared pointer is not a \c nullptr and the pointee is \c true,
/// all operations working on this ASTContext should be aborted at the next
/// possible opportunity.
Expand Down Expand Up @@ -404,7 +409,7 @@ class ASTContext final {
getAllocator(AllocationArena arena = AllocationArena::Permanent) const;

/// An optional generic callback function invoked prior to importing a module.
mutable std::function<bool(llvm::StringRef ModuleName, bool IsOverlay)>
mutable std::function<void(llvm::StringRef ModuleName, bool IsOverlay)>
PreModuleImportCallback;

public:
Expand Down
15 changes: 9 additions & 6 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,7 @@ ASTContext *ASTContext::get(
ClangImporterOptions &ClangImporterOpts,
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
SourceManager &SourceMgr, DiagnosticEngine &Diags,
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutputBackend,
std::function<bool(llvm::StringRef, bool)> PreModuleImportCallback) {
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutputBackend) {
// If more than two data structures are concatentated, then the aggregate
// size math needs to become more complicated due to per-struct alignment
// constraints.
Expand All @@ -644,7 +643,7 @@ ASTContext *ASTContext::get(
return new (mem)
ASTContext(langOpts, typecheckOpts, silOpts, SearchPathOpts,
ClangImporterOpts, SymbolGraphOpts, SourceMgr, Diags,
std::move(OutputBackend), PreModuleImportCallback);
std::move(OutputBackend));
}

ASTContext::ASTContext(
Expand All @@ -653,16 +652,15 @@ ASTContext::ASTContext(
ClangImporterOptions &ClangImporterOpts,
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
SourceManager &SourceMgr, DiagnosticEngine &Diags,
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend,
std::function<bool(llvm::StringRef, bool)> PreModuleImportCallback)
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutBackend
)
: LangOpts(langOpts), TypeCheckerOpts(typecheckOpts), SILOpts(silOpts),
SearchPathOpts(SearchPathOpts), ClangImporterOpts(ClangImporterOpts),
SymbolGraphOpts(SymbolGraphOpts), SourceMgr(SourceMgr), Diags(Diags),
OutputBackend(std::move(OutBackend)), evaluator(Diags, langOpts),
TheBuiltinModule(createBuiltinModule(*this)),
StdlibModuleName(getIdentifier(STDLIB_NAME)),
SwiftShimsModuleName(getIdentifier(SWIFT_SHIMS_NAME)),
PreModuleImportCallback(PreModuleImportCallback),
TheErrorType(new (*this, AllocationArena::Permanent) ErrorType(
*this, Type(), RecursiveTypeProperties::HasError)),
TheUnresolvedType(new(*this, AllocationArena::Permanent)
Expand Down Expand Up @@ -715,6 +713,11 @@ ASTContext::~ASTContext() {
getImpl().~Implementation();
}

void ASTContext::SetPreModuleImportCallback(
std::function<void(llvm::StringRef ModuleName, bool IsOverlay)> callback) {
PreModuleImportCallback = callback;
}

llvm::BumpPtrAllocator &ASTContext::getAllocator(AllocationArena arena) const {
switch (arena) {
case AllocationArena::Permanent:
Expand Down