Skip to content

Commit 87fe0d0

Browse files
Merge pull request #8103 from adrian-prantl/bridging-progress
Add progress reports for bridging header compilation.
2 parents 934601b + 50da0b5 commit 87fe0d0

File tree

10 files changed

+54
-25
lines changed

10 files changed

+54
-25
lines changed

lldb/include/lldb/Core/DebuggerEvents.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "lldb/Core/ModuleSpec.h"
10+
#include "lldb/Core/Progress.h"
1011
#include "lldb/Utility/Event.h"
1112
#include "lldb/Utility/StructuredData.h"
1213

@@ -39,7 +40,7 @@ class ProgressEventData : public EventData {
3940
GetAsStructuredData(const Event *event_ptr);
4041

4142
uint64_t GetID() const { return m_id; }
42-
bool IsFinite() const { return m_total != UINT64_MAX; }
43+
bool IsFinite() const { return m_total != Progress::kNonDeterministicTotal; }
4344
uint64_t GetCompleted() const { return m_completed; }
4445
uint64_t GetTotal() const { return m_total; }
4546
std::string GetMessage() const {

lldb/include/lldb/Core/Progress.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ class Progress {
9393
void Increment(uint64_t amount = 1,
9494
std::optional<std::string> updated_detail = {});
9595

96+
/// Used to indicate a non-deterministic progress report
97+
static constexpr uint64_t kNonDeterministicTotal = UINT64_MAX;
98+
9699
private:
97100
void ReportProgress();
98101
static std::atomic<uint64_t> g_id;

lldb/source/Core/DebuggerEvents.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "lldb/Core/DebuggerEvents.h"
1010
#include "lldb/Core/Debugger.h"
1111
#include "lldb/Core/Module.h"
12+
#include "lldb/Core/Progress.h"
1213
#include "llvm/Support/WithColor.h"
1314

1415
using namespace lldb_private;
@@ -41,7 +42,7 @@ void ProgressEventData::Dump(Stream *s) const {
4142
s->PutCString(", type = update");
4243
// If m_total is UINT64_MAX, there is no progress to report, just "start"
4344
// and "end". If it isn't we will show the completed and total amounts.
44-
if (m_total != UINT64_MAX)
45+
if (m_total != Progress::kNonDeterministicTotal)
4546
s->Printf(", progress = %" PRIu64 " of %" PRIu64, m_completed, m_total);
4647
}
4748

lldb/source/Core/Progress.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ Progress::Progress(std::string title, std::string details,
2222
std::optional<uint64_t> total,
2323
lldb_private::Debugger *debugger)
2424
: m_title(title), m_details(details), m_id(++g_id), m_completed(0),
25-
m_total(1) {
26-
assert(total == std::nullopt || total > 0);
25+
m_total(Progress::kNonDeterministicTotal) {
2726
if (total)
2827
m_total = *total;
2928

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,16 +2060,19 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
20602060
// swift::ASTContext
20612061
Progress progress("Importing Swift standard library");
20622062
swift_ast_sp->m_ast_context_ap->SetPreModuleImportCallback(
2063-
[&progress](llvm::StringRef module_name, bool is_overlay) {
2064-
progress.Increment(1, (is_overlay ? module_name.str() + " (overlay)"
2065-
: module_name.str()));
2063+
[&progress](llvm::StringRef module_name,
2064+
swift::ASTContext::ModuleImportKind kind) {
2065+
progress.Increment(1, (kind == swift::ASTContext::Overlay
2066+
? module_name.str() + " (overlay)"
2067+
: module_name.str()));
20662068
});
20672069

20682070
// Clear the callback function on scope exit to prevent an out-of-scope
20692071
// access of the progress local variable
20702072
auto on_exit = llvm::make_scope_exit([&]() {
20712073
swift_ast_sp->m_ast_context_ap->SetPreModuleImportCallback(
2072-
[](llvm::StringRef module_name, bool is_overlay) {
2074+
[](llvm::StringRef module_name,
2075+
swift::ASTContext::ModuleImportKind kind) {
20732076
Progress("Importing Swift modules");
20742077
});
20752078
});
@@ -2569,19 +2572,22 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(
25692572
const bool can_create = true;
25702573

25712574
// Report progress on module importing by using a callback function in
2572-
// swift::ASTContext
2575+
// swift::ASTContext.
25732576
Progress progress("Importing Swift standard library");
25742577
swift_ast_sp->m_ast_context_ap->SetPreModuleImportCallback(
2575-
[&progress](llvm::StringRef module_name, bool is_overlay) {
2576-
progress.Increment(1, (is_overlay ? module_name.str() + " (overlay)"
2577-
: module_name.str()));
2578+
[&progress](llvm::StringRef module_name,
2579+
swift::ASTContext::ModuleImportKind kind) {
2580+
progress.Increment(1, (kind == swift::ASTContext::Overlay
2581+
? module_name.str() + " (overlay)"
2582+
: module_name.str()));
25782583
});
25792584

25802585
// Clear the callback function on scope exit to prevent an out-of-scope
2581-
// access of the progress local variable
2586+
// access of the progress local variable.
25822587
auto on_exit = llvm::make_scope_exit([&]() {
25832588
swift_ast_sp->m_ast_context_ap->SetPreModuleImportCallback(
2584-
[](llvm::StringRef module_name, bool is_overlay) {
2589+
[](llvm::StringRef module_name,
2590+
swift::ASTContext::ModuleImportKind kind) {
25852591
Progress("Importing Swift modules");
25862592
});
25872593
});
@@ -3627,19 +3633,31 @@ swift::ModuleDecl *SwiftASTContext::GetModule(const SourceModule &module,
36273633
auto import_diags = getScopedDiagnosticConsumer();
36283634

36293635
// Report progress on module importing by using a callback function in
3630-
// swift::ASTContext
3636+
// swift::ASTContext.
36313637
Progress progress("Importing Swift modules");
3632-
ast->SetPreModuleImportCallback([&progress](llvm::StringRef module_name,
3633-
bool is_overlay) {
3634-
progress.Increment(
3635-
1, (is_overlay ? module_name.str() + " (overlay)" : module_name.str()));
3636-
});
3638+
ast->SetPreModuleImportCallback(
3639+
[&progress](llvm::StringRef module_name,
3640+
swift::ASTContext::ModuleImportKind kind) {
3641+
switch (kind) {
3642+
case swift::ASTContext::Module:
3643+
progress.Increment(1, module_name.str());
3644+
break;
3645+
case swift::ASTContext::Overlay:
3646+
progress.Increment(1, module_name.str() + " (overlay)");
3647+
break;
3648+
case swift::ASTContext::BridgingHeader:
3649+
progress.Increment(1,
3650+
"Compiling bridging header: " + module_name.str());
3651+
break;
3652+
}
3653+
});
36373654

36383655
// Clear the callback function on scope exit to prevent an out-of-scope access
36393656
// of the progress local variable
36403657
auto on_exit = llvm::make_scope_exit([&]() {
36413658
ast->SetPreModuleImportCallback(
3642-
[](llvm::StringRef module_name, bool is_overlay) {
3659+
[](llvm::StringRef module_name,
3660+
swift::ASTContext::ModuleImportKind kind) {
36433661
Progress("Importing Swift modules");
36443662
});
36453663
});

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2830,7 +2830,8 @@ TypeSystemSwiftTypeRef::GetBitSize(opaque_compiler_type_t type,
28302830
// pointer instead of the underlying object.
28312831
if (Flags(clang_type.GetTypeInfo()).AllSet(eTypeIsObjC | eTypeIsClass))
28322832
return GetPointerByteSize() * 8;
2833-
return clang_type.GetBitSize(exe_scope);
2833+
if (auto clang_size = clang_type.GetBitSize(exe_scope))
2834+
return clang_size;
28342835
}
28352836
if (!exe_scope) {
28362837
LLDB_LOGF(GetLog(LLDBLog::Types),
@@ -4253,7 +4254,8 @@ TypeSystemSwiftTypeRef::GetTypeBitAlign(opaque_compiler_type_t type,
42534254
// object pointer instead of the underlying object.
42544255
if (Flags(clang_type.GetTypeInfo()).AllSet(eTypeIsObjC | eTypeIsClass))
42554256
return GetPointerByteSize() * 8;
4256-
return clang_type.GetTypeBitAlign(exe_scope);
4257+
if (auto clang_align = clang_type.GetTypeBitAlign(exe_scope))
4258+
return clang_align;
42574259
}
42584260
if (!exe_scope) {
42594261
LLDB_LOGF(GetLog(LLDBLog::Types),
@@ -4264,7 +4266,8 @@ TypeSystemSwiftTypeRef::GetTypeBitAlign(opaque_compiler_type_t type,
42644266
}
42654267
if (auto *runtime =
42664268
SwiftLanguageRuntime::Get(exe_scope->CalculateProcess())) {
4267-
if (auto result = runtime->GetBitAlignment({weak_from_this(), type}, exe_scope))
4269+
if (auto result =
4270+
runtime->GetBitAlignment({weak_from_this(), type}, exe_scope))
42684271
return result;
42694272
// If this is an expression context, perhaps the type was
42704273
// defined in the expression. In that case we don't have debug

lldb/test/API/functionalities/progress_reporting/swift_progress_reporting/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
SWIFT_SOURCES := main.swift
2-
2+
SWIFT_BRIDGING_HEADER := bridging.h
3+
SWIFT_PRECOMPILE_BRIDGING_HEADER := YES
34
LD_EXTRAS := -L. -linvisible
45
SWIFTFLAGS_EXTRAS := -I.
56

lldb/test/API/functionalities/progress_reporting/swift_progress_reporting/TestSwiftProgressReporting.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def test_swift_progress_report(self):
3636

3737
beacons = [
3838
"Loading Swift module",
39+
"Compiling bridging header",
3940
"Importing modules used in expression",
4041
"Setting up Swift reflection",
4142
"Importing Swift module dependencies for main.swift",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
struct FromBridgingHeader {};

lldb/test/API/functionalities/progress_reporting/swift_progress_reporting/main.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Foundation
44
func main() {
55
let boo = Invisible.👻()
66
let s = NSAttributedString(string: "Hello")
7+
let b = FromBridgingHeader()
78
print("break here")
89
}
910

0 commit comments

Comments
 (0)