Skip to content

Commit 281a82d

Browse files
committed
[lldb] Adapt Swift plugin to changes in CompilerType API
1 parent 642dcd7 commit 281a82d

File tree

9 files changed

+157
-99
lines changed

9 files changed

+157
-99
lines changed

lldb/source/Expression/Materializer.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,12 @@ class EntityVariableBase : public Materializer::Entity {
545545
valobj_sp->GetData(data, extract_error);
546546
if (!extract_error.Success()) {
547547
if (valobj_type.GetMinimumLanguage() == lldb::eLanguageTypeSwift) {
548-
std::optional<uint64_t> size =
549-
valobj_type.GetByteSize(frame_sp.get());
550-
if (size && *size == 0) {
548+
auto size_or_err = valobj_type.GetByteSize(frame_sp.get());
549+
if (!size_or_err) {
550+
err = Status::FromError(size_or_err.takeError());
551+
return;
552+
}
553+
if (*size_or_err == 0) {
551554
// We don't need to materialize empty structs in Swift.
552555
return;
553556
}
@@ -676,14 +679,19 @@ class EntityVariableBase : public Materializer::Entity {
676679

677680
Status extract_error;
678681

679-
map.GetMemoryData(data, m_temporary_allocation,
680-
valobj_sp->GetByteSize().value_or(0), extract_error);
682+
map.GetMemoryData(
683+
data, m_temporary_allocation,
684+
llvm::expectedToOptional(valobj_sp->GetByteSize()).value_or(0),
685+
extract_error);
681686

682687
if (!extract_error.Success()) {
683688
if (valobj_type.GetMinimumLanguage() == lldb::eLanguageTypeSwift) {
684-
std::optional<uint64_t> size =
685-
valobj_type.GetByteSize(frame_sp.get());
686-
if (size && *size == 0)
689+
auto size_or_err = valobj_type.GetByteSize(frame_sp.get());
690+
if (!size_or_err) {
691+
err = Status::FromError(size_or_err.takeError());
692+
return;
693+
}
694+
if (*size_or_err == 0)
687695
// We don't need to dematerialize empty structs in Swift.
688696
return;
689697
}

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,8 +1761,8 @@ void SwiftLanguageRuntime::WillStartExecutingUserExpression(
17611761
return;
17621762
}
17631763
ConstString BoolName("bool");
1764-
std::optional<uint64_t> bool_size =
1765-
ts->GetBuiltinTypeByName(BoolName).GetByteSize(nullptr);
1764+
std::optional<uint64_t> bool_size = llvm::expectedToOptional(
1765+
ts->GetBuiltinTypeByName(BoolName).GetByteSize(nullptr));
17661766
if (!bool_size)
17671767
return;
17681768

@@ -1836,8 +1836,8 @@ void SwiftLanguageRuntime::DidFinishExecutingUserExpression(
18361836
return;
18371837
}
18381838
ConstString BoolName("bool");
1839-
std::optional<uint64_t> bool_size =
1840-
ts->GetBuiltinTypeByName(BoolName).GetByteSize(nullptr);
1839+
std::optional<uint64_t> bool_size = llvm::expectedToOptional(
1840+
ts->GetBuiltinTypeByName(BoolName).GetByteSize(nullptr));
18411841
if (!bool_size)
18421842
return;
18431843

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ class SwiftLanguageRuntime : public LanguageRuntime {
418418
ExecutionContext *exe_ctx);
419419

420420
/// Ask Remote Mirrors for the size of a Swift type.
421-
std::optional<uint64_t> GetBitSize(CompilerType type,
421+
llvm::Expected<uint64_t> GetBitSize(CompilerType type,
422422
ExecutionContextScope *exe_scope);
423423

424424
/// Ask Remote mirrors for the stride of a Swift type.

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,8 @@ class LLDBTypeInfoProvider : public swift::remote::TypeInfoProvider {
381381
return nullptr;
382382
TypeSystemSwiftTypeRef &typesystem = *m_ts;
383383
// Build a TypeInfo for the Clang type.
384-
auto size = clang_type.GetByteSize(exe_scope);
384+
std::optional<uint64_t> size =
385+
llvm::expectedToOptional(clang_type.GetByteSize(exe_scope));
385386
auto bit_align = clang_type.GetTypeBitAlign(exe_scope);
386387
std::vector<swift::reflection::FieldInfo> fields;
387388
if (clang_type.IsAggregateType()) {
@@ -1214,9 +1215,11 @@ llvm::Expected<CompilerType> SwiftLanguageRuntime::GetChildCompilerTypeAtIndex(
12141215
if (auto pack_element_type = ts->GetSILPackElementAtIndex(type, idx)) {
12151216
llvm::raw_string_ostream os(child_name);
12161217
os << '.' << idx;
1217-
child_byte_size =
1218-
GetBitSize(pack_element_type, exe_ctx.GetBestExecutionContextScope())
1219-
.value_or(0);
1218+
auto size_or_err =
1219+
GetBitSize(pack_element_type, exe_ctx.GetBestExecutionContextScope());
1220+
if (!size_or_err)
1221+
return size_or_err.takeError();
1222+
child_byte_size = *size_or_err;
12201223
int stack_dir = -1;
12211224
child_byte_offset = ts->GetPointerByteSize() * idx * stack_dir;
12221225
child_bitfield_bit_size = 0;
@@ -2236,7 +2239,9 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Existential(
22362239

22372240

22382241
if (use_local_buffer)
2239-
PushLocalBuffer(existential_address, in_value.GetByteSize().value_or(0));
2242+
PushLocalBuffer(
2243+
existential_address,
2244+
llvm::expectedToOptional(in_value.GetByteSize()).value_or(0));
22402245

22412246
swift::remote::RemoteAddress remote_existential(existential_address);
22422247

@@ -2522,7 +2527,7 @@ CompilerType SwiftLanguageRuntime::BindGenericTypeParameters(
25222527
LLDB_LOG_ERROR(
25232528
GetLog(LLDBLog::Expressions | LLDBLog::Types),
25242529
type_ref_or_err.takeError(),
2525-
"Couldn't get rype ref when binding generic type parameters: {0}");
2530+
"Couldn't get type ref when binding generic type parameters: {0}");
25262531
failure = true;
25272532
return;
25282533
}
@@ -2687,8 +2692,8 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Value(
26872692
ExecutionContextScope *exe_scope = exe_ctx.GetBestExecutionContextScope();
26882693
if (!exe_scope)
26892694
return false;
2690-
std::optional<uint64_t> size =
2691-
bound_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
2695+
std::optional<uint64_t> size = llvm::expectedToOptional(
2696+
bound_type.GetByteSize(exe_ctx.GetBestExecutionContextScope()));
26922697
if (!size)
26932698
return false;
26942699
AddressType address_type;
@@ -2704,7 +2709,8 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Value(
27042709
if (in_value_buffer.empty())
27052710
return false;
27062711
// If the dynamic type doesn't in the buffer we can't use it either.
2707-
if (in_value_buffer.size() < bound_type.GetByteSize(exe_scope))
2712+
if (in_value_buffer.size() <
2713+
llvm::expectedToOptional(bound_type.GetByteSize(exe_scope)).value_or(0))
27082714
return false;
27092715

27102716
value_type = Value::GetValueTypeFromAddressType(address_type);
@@ -2810,8 +2816,9 @@ Value::ValueType SwiftLanguageRuntime::GetValueType(
28102816
}
28112817

28122818
if (use_local_buffer)
2813-
PushLocalBuffer(existential_address,
2814-
in_value.GetByteSize().value_or(0));
2819+
PushLocalBuffer(
2820+
existential_address,
2821+
llvm::expectedToOptional(in_value.GetByteSize()).value_or(0));
28152822

28162823
// Read the value witness table and check if the data is inlined in
28172824
// the existential container or not.
@@ -3331,7 +3338,10 @@ SwiftLanguageRuntime::GetTypeRef(CompilerType type,
33313338
auto type_ref_or_err = reflection_ctx->GetTypeRef(
33323339
dem, node, module_holder->GetDescriptorFinder());
33333340
if (!type_ref_or_err)
3334-
return type_ref_or_err.takeError();
3341+
return llvm::joinErrors(
3342+
llvm::createStringError("cannot get typeref for type %s",
3343+
type.GetMangledTypeName().GetCString()),
3344+
type_ref_or_err.takeError());
33353345

33363346
if (log && log->GetVerbose()) {
33373347
std::stringstream ss;
@@ -3537,14 +3547,12 @@ SwiftLanguageRuntime::ResolveTypeAlias(CompilerType alias) {
35373547
return llvm::createStringError("cannot resolve type alias via reflection");
35383548
}
35393549

3540-
std::optional<uint64_t>
3550+
llvm::Expected<uint64_t>
35413551
SwiftLanguageRuntime::GetBitSize(CompilerType type,
35423552
ExecutionContextScope *exe_scope) {
35433553
auto type_info_or_err = GetSwiftRuntimeTypeInfo(type, exe_scope);
3544-
if (!type_info_or_err) {
3545-
LLDB_LOG_ERROR(GetLog(LLDBLog::Types), type_info_or_err.takeError(), "{0}");
3546-
return {};
3547-
}
3554+
if (!type_info_or_err)
3555+
return type_info_or_err.takeError();
35483556

35493557
return type_info_or_err->getSize() * 8;
35503558
}

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeRemoteAST.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,9 @@ SwiftLanguageRuntime::GetDynamicTypeAndAddress_ExistentialRemoteAST(
245245
if (!swift_type)
246246
return {};
247247
if (use_local_buffer)
248-
PushLocalBuffer(existential_address, in_value.GetByteSize().value_or(0));
248+
PushLocalBuffer(
249+
existential_address,
250+
llvm::expectedToOptional(in_value.GetByteSize()).value_or(0));
249251

250252
auto result = remote_ast.getDynamicTypeAndAddressForExistential(
251253
remote_existential, swift_type);

0 commit comments

Comments
 (0)