Skip to content

Commit b372ced

Browse files
Merge pull request #10675 from adrian-prantl/145257088
[lldb] Make variadic generic types work with TypeSystemSwiftTypeRef
2 parents f327405 + e48e8aa commit b372ced

File tree

9 files changed

+262
-157
lines changed

9 files changed

+262
-157
lines changed

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionParser.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,9 @@ static CompilerType GetSwiftTypeForVariableValueObject(
470470
if (!result)
471471
return {};
472472
if (SwiftASTManipulator::ShouldBindGenericTypes(bind_generic_types))
473-
result = runtime->BindGenericTypeParameters(*stack_frame_sp, result);
473+
result = llvm::expectedToOptional(
474+
runtime->BindGenericTypeParameters(*stack_frame_sp, result))
475+
.value_or(CompilerType());
474476
if (!result)
475477
return {};
476478
if (!result.GetTypeSystem()->SupportsLanguage(lldb::eLanguageTypeSwift))
@@ -606,12 +608,17 @@ AddRequiredAliases(Block *block, lldb::StackFrameSP &stack_frame_sp,
606608

607609
auto *stack_frame = stack_frame_sp.get();
608610
if (SwiftASTManipulator::ShouldBindGenericTypes(bind_generic_types)) {
609-
imported_self_type = swift_runtime->BindGenericTypeParameters(
611+
auto bound_type_or_err = swift_runtime->BindGenericTypeParameters(
610612
*stack_frame, imported_self_type);
611-
if (!imported_self_type)
612-
return llvm::createStringError(
613-
"Unable to add the aliases the expression needs because the Swift "
614-
"expression parser couldn't bind the type parameters for self.");
613+
if (!bound_type_or_err)
614+
return llvm::joinErrors(
615+
llvm::createStringError(
616+
"Unable to add the aliases the expression needs because the "
617+
"Swift expression parser couldn't bind the type parameters for "
618+
"self."),
619+
bound_type_or_err.takeError());
620+
621+
imported_self_type = *bound_type_or_err;
615622
}
616623

617624
{
@@ -1224,16 +1231,17 @@ AddArchetypeTypeAliases(std::unique_ptr<SwiftASTManipulator> &code_manipulator,
12241231
auto flavor = SwiftLanguageRuntime::GetManglingFlavor(type_name);
12251232
auto dependent_type = typeref_typesystem->CreateGenericTypeParamType(
12261233
info.depth, info.index, flavor);
1227-
auto bound_type =
1234+
auto bound_type_or_err =
12281235
runtime->BindGenericTypeParameters(stack_frame, dependent_type);
1229-
if (!bound_type) {
1230-
LLDB_LOG(
1231-
log,
1236+
if (!bound_type_or_err) {
1237+
LLDB_LOG_ERROR(
1238+
log, bound_type_or_err.takeError(),
12321239
"[AddArchetypeTypeAliases] Could not bind dependent generic param "
1233-
"type {0}",
1240+
"type {1}: {0}",
12341241
dependent_type.GetMangledTypeName());
12351242
continue;
12361243
}
1244+
auto bound_type = *bound_type_or_err;
12371245

12381246
LLDB_LOG(log,
12391247
"[AddArchetypeTypeAliases] Binding dependent generic param "

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,14 @@ std::string SwiftLanguageRuntime::GetObjectDescriptionExpr_Copy(
868868

869869
auto swift_ast_ctx =
870870
static_type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
871-
if (swift_ast_ctx)
872-
static_type = BindGenericTypeParameters(*frame_sp, static_type);
871+
if (swift_ast_ctx) {
872+
auto bound_type_or_err = BindGenericTypeParameters(*frame_sp, static_type);
873+
if (!bound_type_or_err) {
874+
LLDB_LOG_ERROR(log, bound_type_or_err.takeError(), "{0}");
875+
return {};
876+
}
877+
static_type = *bound_type_or_err;
878+
}
873879

874880
auto stride = 0;
875881
auto opt_stride = static_type.GetByteStride(frame_sp.get());

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

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ class SwiftLanguageRuntime : public LanguageRuntime {
273273
Address &address, Value::ValueType &value_type,
274274
llvm::ArrayRef<uint8_t> &local_buffer) override;
275275

276+
llvm::Expected<CompilerType> BindGenericPackType(StackFrame &frame,
277+
CompilerType pack_type,
278+
bool *indirect = nullptr);
276279
CompilerType BindGenericTypeParameters(
277280
CompilerType unbound_type,
278281
std::function<CompilerType(unsigned, unsigned)> finder);
@@ -343,12 +346,20 @@ class SwiftLanguageRuntime : public LanguageRuntime {
343346
unsigned dependent_generic_param_count = 0;
344347
unsigned num_counts = 0;
345348

346-
unsigned GetNumValuePacks() { return count_for_value_pack.size(); }
347-
unsigned GetNumTypePacks() { return count_for_type_pack.size(); }
348-
unsigned GetCountForValuePack(unsigned i) {
349+
unsigned GetNumValuePacks() const { return count_for_value_pack.size(); }
350+
unsigned GetNumTypePacks() const { return count_for_type_pack.size(); }
351+
unsigned GetCountForValuePack(unsigned i) const {
349352
return count_for_value_pack[i];
350353
}
351-
unsigned GetCountForTypePack(unsigned i) { return count_for_type_pack[i]; }
354+
unsigned GetCountForTypePack(unsigned i) const { return count_for_type_pack[i]; }
355+
bool HasPacks() const { return pack_expansions.size(); }
356+
bool IsPack(unsigned depth, unsigned index) const {
357+
if (HasPacks())
358+
for (auto param : generic_params)
359+
if (param.depth == depth && param.index == index)
360+
return param.is_pack;
361+
return false;
362+
}
352363
};
353364
/// Extract the generic signature out of a mangled Swift function name.
354365
static std::optional<GenericSignature>
@@ -359,8 +370,8 @@ class SwiftLanguageRuntime : public LanguageRuntime {
359370
/// version of \p base_type that replaces all generic type
360371
/// parameters with bound generic types. If a generic type parameter
361372
/// cannot be resolved, the input type is returned.
362-
CompilerType BindGenericTypeParameters(StackFrame &stack_frame,
363-
CompilerType base_type);
373+
llvm::Expected<CompilerType>
374+
BindGenericTypeParameters(StackFrame &stack_frame, CompilerType base_type);
364375

365376
bool IsStoredInlineInBuffer(CompilerType type) override;
366377

@@ -580,13 +591,14 @@ class SwiftLanguageRuntime : public LanguageRuntime {
580591
GetRemoteASTContext(SwiftASTContext &swift_ast_ctx);
581592

582593
/// Like \p BindGenericTypeParameters but for TypeSystemSwiftTypeRef.
583-
CompilerType BindGenericTypeParameters(StackFrame &stack_frame,
584-
TypeSystemSwiftTypeRef &ts,
585-
ConstString mangled_name);
594+
llvm::Expected<CompilerType>
595+
BindGenericTypeParameters(StackFrame &stack_frame, TypeSystemSwiftTypeRef &ts,
596+
ConstString mangled_name);
586597

587598
/// Like \p BindGenericTypeParameters but for RemoteAST.
588-
CompilerType BindGenericTypeParametersRemoteAST(StackFrame &stack_frame,
589-
CompilerType base_type);
599+
llvm::Expected<CompilerType>
600+
BindGenericTypeParametersRemoteAST(StackFrame &stack_frame,
601+
CompilerType base_type);
590602

591603
bool GetDynamicTypeAndAddress_Pack(ValueObject &in_value,
592604
CompilerType pack_type,

0 commit comments

Comments
 (0)