Skip to content

Commit 290a167

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 290a167

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

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

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -797,17 +797,13 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
797797
public:
798798
TaskSyntheticFrontEnd(lldb::ValueObjectSP valobj_sp)
799799
: SyntheticChildrenFrontEnd(*valobj_sp.get()) {
800-
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());
800+
CompilerType type = valobj_sp->GetCompilerType();
801+
m_ts = type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
802+
if (!m_ts)
803+
LLDB_LOG(
804+
GetLog(LLDBLog::DataFormatters | LLDBLog::Types),
805+
"could not get Swift type system for Task synthetic provider: {0}",
806+
type.GetMangledTypeName());
811807
}
812808

813809
constexpr static StringLiteral TaskChildren[] = {
@@ -840,6 +836,8 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
840836
}
841837

842838
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override {
839+
if (!m_ts)
840+
return {};
843841
auto target_sp = m_backend.GetTargetSP();
844842

845843
// TypeMangling for "Swift.Bool"
@@ -1026,7 +1024,7 @@ class TaskSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
10261024
return {};
10271025
}
10281026

1029-
TypeSystemSwiftTypeRef *m_ts = nullptr;
1027+
TypeSystemSwiftSP m_ts;
10301028
addr_t m_task_ptr = LLDB_INVALID_ADDRESS;
10311029
ReflectionContextInterface::AsyncTaskInfo m_task_info;
10321030
ValueObjectSP m_address_sp;
@@ -1421,25 +1419,21 @@ class ActorSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
14211419
if (!m_is_supported_target)
14221420
return;
14231421

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());
1422+
CompilerType type = valobj_sp->GetCompilerType();
1423+
m_ts = type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
1424+
if (!m_ts)
1425+
LLDB_LOG(
1426+
GetLog(LLDBLog::DataFormatters | LLDBLog::Types),
1427+
"could not get Swift type system for Actor synthetic provider: {0}",
1428+
type.GetMangledTypeName());
14351429
}
14361430

14371431
llvm::Expected<uint32_t> CalculateNumChildren() override {
14381432
return m_is_supported_target ? 1 : 0;
14391433
}
14401434

14411435
lldb::ValueObjectSP GetChildAtIndex(uint32_t idx) override {
1442-
if (!m_is_supported_target || idx != 0)
1436+
if (!m_is_supported_target || idx != 0 || !m_ts)
14431437
return {};
14441438

14451439
if (!m_unprioritised_jobs_sp) {
@@ -1556,7 +1550,7 @@ class ActorSyntheticFrontEnd : public SyntheticChildrenFrontEnd {
15561550

15571551
private:
15581552
bool m_is_supported_target = false;
1559-
TypeSystemSwiftTypeRef *m_ts = nullptr;
1553+
TypeSystemSwiftSP m_ts;
15601554
std::vector<addr_t> m_job_addrs;
15611555
CompilerType m_task_type;
15621556
ValueObjectSP m_unprioritised_jobs_sp;

0 commit comments

Comments
 (0)