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

Conversation

chelcassanova
Copy link
Contributor

@chelcassanova chelcassanova commented Nov 8, 2023

PreModuleImportCallback is a variable for a callback function called before module importing in the Swift compiler. It is currently being used 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

`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
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.

@@ -715,6 +714,10 @@ ASTContext::~ASTContext() {
getImpl().~Implementation();
}

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

Choose a reason for hiding this comment

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

Why do you need to qualify PreModuleImportCallback here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't, but I think I originally thought that PreModuleImportCallback was static even though it's not so I can remove the qualification.

@medismailben
Copy link
Contributor

FWIW, although this callback is used mainly as an LLDB module loading progress callback, it could also be used for/by other things. I'd retitle this PR to be more generic.

@chelcassanova
Copy link
Contributor Author

@swift-ci test

@chelcassanova
Copy link
Contributor Author

Good point about PreModuleImportCallback being generic. Since LLDB was the only one use it I thought it was created specifically for LLDB, I'll update the PR description to reflect this.

@chelcassanova chelcassanova changed the title [ASTContext] Add setter for LLDB callback [ASTContext] Add setter for PreModuleImportCallback Nov 8, 2023
@@ -294,6 +294,8 @@ class ASTContext final {
/// OutputBackend for writing outputs.
llvm::IntrusiveRefCntPtr<llvm::vfs::OutputBackend> OutputBackend;

void SetPreModuleImportCallback(std::function<bool(llvm::StringRef ModuleName, bool IsOverlay)> callback);
Copy link
Contributor

Choose a reason for hiding this comment

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

Doxygen comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'll add one here

Sets the `PreModuleImportCallback`'s setter return type to void to
account for the lambda functions in LLDB's progress reporting not
actually using its return value. Also adds a Doxygen comment for `SetPreModuleImportCallback`
@chelcassanova
Copy link
Contributor Author

@swift-ci test

@chelcassanova
Copy link
Contributor Author

@swift-ci smoke test

@chelcassanova
Copy link
Contributor Author

@chelcassanova
Copy link
Contributor Author

swiftlang/llvm-project#7769
@swift-ci please test

@chelcassanova
Copy link
Contributor Author

swiftlang/llvm-project#7769
@swift-ci please smoke test

@@ -715,6 +714,10 @@ ASTContext::~ASTContext() {
getImpl().~Implementation();
}

void ASTContext::SetPreModuleImportCallback(std::function<void(llvm::StringRef ModuleName, bool IsOverlay)> callback) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this line clang-formatted? Looks pretty long

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should've been, but I can also shorten it myself if clang-format is ignoring it for some reason

Copy link
Contributor

Choose a reason for hiding this comment

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

If clang-format says it's ok then it's fine

@chelcassanova
Copy link
Contributor Author

swiftlang/llvm-project#7769
@swift-ci please test

1 similar comment
@chelcassanova
Copy link
Contributor Author

swiftlang/llvm-project#7769
@swift-ci please test

@chelcassanova
Copy link
Contributor Author

swiftlang/llvm-project#7769
@swift-ci please test

2 similar comments
@chelcassanova
Copy link
Contributor Author

swiftlang/llvm-project#7769
@swift-ci please test

@chelcassanova
Copy link
Contributor Author

swiftlang/llvm-project#7769
@swift-ci please test

@chelcassanova chelcassanova merged commit 04316be into swiftlang:main Dec 1, 2023
chelcassanova added a commit to swiftlang/llvm-project that referenced this pull request Dec 1, 2023
LLDB's progress reporting infrastructure has had the ability to add
details to an overall progress report (added in
https://reviews.llvm.org/D143690) but this had yet to be implemented in
existing progress reports. This commit adds this functionality to
progress reports made for Swift operations (such as caching user
imports) so that instead of sending several individual progress reports
for each step in these operations, one progress report is created and
then incrementally updated.

Importing Swift modules takes place in the Swift compiler which uses a
callback function so that LLDB can perform its progress report. This
originally called into a function in `lldb_private::SwiftASTContext` but
will instead use a lambda function to increment a locally created
progress report.

Related to: swiftlang/swift#69730

rdar://105286354
chelcassanova added a commit to chelcassanova/llvm-project that referenced this pull request Feb 1, 2024
LLDB's progress reporting infrastructure has had the ability to add
details to an overall progress report (added in
https://reviews.llvm.org/D143690) but this had yet to be implemented in
existing progress reports. This commit adds this functionality to
progress reports made for Swift operations (such as caching user
imports) so that instead of sending several individual progress reports
for each step in these operations, one progress report is created and
then incrementally updated.

Importing Swift modules takes place in the Swift compiler which uses a
callback function so that LLDB can perform its progress report. This
originally called into a function in `lldb_private::SwiftASTContext` but
will instead use a lambda function to increment a locally created
progress report.

Related to: swiftlang/swift#69730

rdar://105286354
(cherry picked from commit 4106480)
chelcassanova added a commit to swiftlang/llvm-project that referenced this pull request Feb 1, 2024
LLDB's progress reporting infrastructure has had the ability to add
details to an overall progress report (added in
https://reviews.llvm.org/D143690) but this had yet to be implemented in
existing progress reports. This commit adds this functionality to
progress reports made for Swift operations (such as caching user
imports) so that instead of sending several individual progress reports
for each step in these operations, one progress report is created and
then incrementally updated.

Importing Swift modules takes place in the Swift compiler which uses a
callback function so that LLDB can perform its progress report. This
originally called into a function in `lldb_private::SwiftASTContext` but
will instead use a lambda function to increment a locally created
progress report.

Related to: swiftlang/swift#69730

rdar://105286354
(cherry picked from commit 4106480)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants