Skip to content

Commit 9e93d64

Browse files
committed
[LLDB] Simplify task formatter typesystem creation
and add missing nullptr checks. In this case there is no need to create a new scratch typesystem, we can just reuse the ValueObject's typesystem.
1 parent d604b9b commit 9e93d64

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

lldb/source/Plugins/Language/Swift/SwiftFormatters.cpp

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -798,16 +798,13 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
798798
TaskSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
799799
: SyntheticChildrenFrontEnd(*valobj_sp.get()) {
800800
auto target_sp = m_backend.GetTargetSP();
801-
auto ts_or_err =
802-
target_sp->GetScratchTypeSystemForLanguage(eLanguageTypeSwift);
803-
if (auto err = ts_or_err.takeError()) {
804-
LLDB_LOG_ERROR(GetLog(LLDBLog::DataFormatters | LLDBLog::Types),
805-
std::move(err),
806-
"could not get Swift type system for Task synthetic "
807-
"provider: {0}");
808-
return;
809-
}
810-
m_ts = llvm::dyn_cast_or_null<TypeSystemSwiftTypeRef>(ts_or_err->get());
801+
CompilerType type = valobj_sp->GetCompilerType();
802+
m_ts = type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
803+
if (!m_ts)
804+
LLDB_LOG(
805+
GetLog(LLDBLog::DataFormatters | LLDBLog::Types),
806+
"could not get Swift type system for Task synthetic provider: {0}",
807+
type.GetMangledTypeName());
811808
}
812809

813810
constexpr static StringLiteral TaskChildren[] = {
@@ -840,6 +837,8 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
840837
}
841838

842839
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override {
840+
if (!m_ts)
841+
return {};
843842
auto target_sp = m_backend.GetTargetSP();
844843

845844
// TypeMangling for "Swift.Bool"
@@ -1026,7 +1025,7 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
10261025
return {};
10271026
}
10281027

1029-
TypeSystemSwiftTypeRef *m_ts = nullptr;
1028+
TypeSystemSwiftSP m_ts;
10301029
addr_t m_task_ptr = LLDB_INVALID_ADDRESS;
10311030
ReflectionContextInterface::AsyncTaskInfo m_task_info;
10321031
ValueObjectSP m_address_sp;
@@ -1421,25 +1420,21 @@ class ActorSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
14211420
if (!m_is_supported_target)
14221421
return;
14231422

1424-
auto target_sp = m_backend.GetTargetSP();
1425-
auto ts_or_err =
1426-
target_sp->GetScratchTypeSystemForLanguage(eLanguageTypeSwift);
1427-
if (auto err = ts_or_err.takeError()) {
1428-
LLDB_LOG_ERROR(GetLog(LLDBLog::DataFormatters | LLDBLog::Types),
1429-
std::move(err),
1430-
"could not get Swift type system for Task synthetic "
1431-
"provider: {0}");
1432-
return;
1433-
}
1434-
m_ts = llvm::dyn_cast_or_null<TypeSystemSwiftTypeRef>(ts_or_err->get());
1423+
CompilerType type = valobj_sp->GetCompilerType();
1424+
m_ts = type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
1425+
if (!m_ts)
1426+
LLDB_LOG(
1427+
GetLog(LLDBLog::DataFormatters | LLDBLog::Types),
1428+
"could not get Swift type system for Actor synthetic provider: {0}",
1429+
type.GetMangledTypeName());
14351430
}
14361431

14371432
llvm::Expected<uint32_t> CalculateNumChildren() override {
14381433
return m_is_supported_target ? 1 : 0;
14391434
}
14401435

14411436
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override {
1442-
if (!m_is_supported_target || idx != 0)
1437+
if (!m_is_supported_target || idx != 0 || !m_ts)
14431438
return {};
14441439

14451440
if (!m_unprioritised_jobs_sp) {
@@ -1556,7 +1551,7 @@ class ActorSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
15561551

15571552
private:
15581553
bool m_is_supported_target = false;
1559-
TypeSystemSwiftTypeRef *m_ts = nullptr;
1554+
TypeSystemSwiftSP m_ts;
15601555
std::vector<addr_t> m_job_addrs;
15611556
CompilerType m_task_type;
15621557
ValueObjectSP m_unprioritised_jobs_sp;

0 commit comments

Comments
 (0)