Skip to content

Commit 4effe9e

Browse files
committed
[lldb] Adapt Swift plugin to changes in CompilerType API
(cherry picked from commit e3763e3)
1 parent 9f96063 commit 4effe9e

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
@@ -534,9 +534,12 @@ class EntityVariableBase : public Materializer::Entity {
534534
valobj_sp->GetData(data, extract_error);
535535
if (!extract_error.Success()) {
536536
if (valobj_type.GetMinimumLanguage() == lldb::eLanguageTypeSwift) {
537-
std::optional<uint64_t> size =
538-
valobj_type.GetByteSize(frame_sp.get());
539-
if (size && *size == 0) {
537+
auto size_or_err = valobj_type.GetByteSize(frame_sp.get());
538+
if (!size_or_err) {
539+
err = Status::FromError(size_or_err.takeError());
540+
return;
541+
}
542+
if (*size_or_err == 0) {
540543
// We don't need to materialize empty structs in Swift.
541544
return;
542545
}
@@ -663,14 +666,19 @@ class EntityVariableBase : public Materializer::Entity {
663666

664667
Status extract_error;
665668

666-
map.GetMemoryData(data, m_temporary_allocation,
667-
valobj_sp->GetByteSize().value_or(0), extract_error);
669+
map.GetMemoryData(
670+
data, m_temporary_allocation,
671+
llvm::expectedToOptional(valobj_sp->GetByteSize()).value_or(0),
672+
extract_error);
668673

669674
if (!extract_error.Success()) {
670675
if (valobj_type.GetMinimumLanguage() == lldb::eLanguageTypeSwift) {
671-
std::optional<uint64_t> size =
672-
valobj_type.GetByteSize(frame_sp.get());
673-
if (size && *size == 0)
676+
auto size_or_err = valobj_type.GetByteSize(frame_sp.get());
677+
if (!size_or_err) {
678+
err = Status::FromError(size_or_err.takeError());
679+
return;
680+
}
681+
if (*size_or_err == 0)
674682
// We don't need to dematerialize empty structs in Swift.
675683
return;
676684
}

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
@@ -413,7 +413,7 @@ class SwiftLanguageRuntime : public LanguageRuntime {
413413
ExecutionContext *exe_ctx);
414414

415415
/// Ask Remote Mirrors for the size of a Swift type.
416-
std::optional<uint64_t> GetBitSize(CompilerType type,
416+
llvm::Expected<uint64_t> GetBitSize(CompilerType type,
417417
ExecutionContextScope *exe_scope);
418418

419419
/// 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;
@@ -2203,7 +2206,9 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Existential(
22032206

22042207

22052208
if (use_local_buffer)
2206-
PushLocalBuffer(existential_address, in_value.GetByteSize().value_or(0));
2209+
PushLocalBuffer(
2210+
existential_address,
2211+
llvm::expectedToOptional(in_value.GetByteSize()).value_or(0));
22072212

22082213
swift::remote::RemoteAddress remote_existential(existential_address);
22092214

@@ -2451,7 +2456,7 @@ CompilerType SwiftLanguageRuntime::BindGenericTypeParameters(
24512456
LLDB_LOG_ERROR(
24522457
GetLog(LLDBLog::Expressions | LLDBLog::Types),
24532458
type_ref_or_err.takeError(),
2454-
"Couldn't get rype ref when binding generic type parameters: {0}");
2459+
"Couldn't get type ref when binding generic type parameters: {0}");
24552460
failure = true;
24562461
return;
24572462
}
@@ -2616,8 +2621,8 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Value(
26162621
ExecutionContextScope *exe_scope = exe_ctx.GetBestExecutionContextScope();
26172622
if (!exe_scope)
26182623
return false;
2619-
std::optional<uint64_t> size =
2620-
bound_type.GetByteSize(exe_ctx.GetBestExecutionContextScope());
2624+
std::optional<uint64_t> size = llvm::expectedToOptional(
2625+
bound_type.GetByteSize(exe_ctx.GetBestExecutionContextScope()));
26212626
if (!size)
26222627
return false;
26232628
AddressType address_type;
@@ -2633,7 +2638,8 @@ bool SwiftLanguageRuntime::GetDynamicTypeAndAddress_Value(
26332638
if (in_value_buffer.empty())
26342639
return false;
26352640
// If the dynamic type doesn't in the buffer we can't use it either.
2636-
if (in_value_buffer.size() < bound_type.GetByteSize(exe_scope))
2641+
if (in_value_buffer.size() <
2642+
llvm::expectedToOptional(bound_type.GetByteSize(exe_scope)).value_or(0))
26372643
return false;
26382644

26392645
value_type = Value::GetValueTypeFromAddressType(address_type);
@@ -2739,8 +2745,9 @@ Value::ValueType SwiftLanguageRuntime::GetValueType(
27392745
}
27402746

27412747
if (use_local_buffer)
2742-
PushLocalBuffer(existential_address,
2743-
in_value.GetByteSize().value_or(0));
2748+
PushLocalBuffer(
2749+
existential_address,
2750+
llvm::expectedToOptional(in_value.GetByteSize()).value_or(0));
27442751

27452752
// Read the value witness table and check if the data is inlined in
27462753
// the existential container or not.
@@ -3260,7 +3267,10 @@ SwiftLanguageRuntime::GetTypeRef(CompilerType type,
32603267
auto type_ref_or_err = reflection_ctx->GetTypeRef(
32613268
dem, node, module_holder->GetDescriptorFinder());
32623269
if (!type_ref_or_err)
3263-
return type_ref_or_err.takeError();
3270+
return llvm::joinErrors(
3271+
llvm::createStringError("cannot get typeref for type %s",
3272+
type.GetMangledTypeName().GetCString()),
3273+
type_ref_or_err.takeError());
32643274

32653275
if (log && log->GetVerbose()) {
32663276
std::stringstream ss;
@@ -3466,14 +3476,12 @@ SwiftLanguageRuntime::ResolveTypeAlias(CompilerType alias) {
34663476
return llvm::createStringError("cannot resolve type alias via reflection");
34673477
}
34683478

3469-
std::optional<uint64_t>
3479+
llvm::Expected<uint64_t>
34703480
SwiftLanguageRuntime::GetBitSize(CompilerType type,
34713481
ExecutionContextScope *exe_scope) {
34723482
auto type_info_or_err = GetSwiftRuntimeTypeInfo(type, exe_scope);
3473-
if (!type_info_or_err) {
3474-
LLDB_LOG_ERROR(GetLog(LLDBLog::Types), type_info_or_err.takeError(), "{0}");
3475-
return {};
3476-
}
3483+
if (!type_info_or_err)
3484+
return type_info_or_err.takeError();
34773485

34783486
return type_info_or_err->getSize() * 8;
34793487
}

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

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

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

0 commit comments

Comments
 (0)