Skip to content

Commit 1dd271a

Browse files
authored
Merge pull request #10749 from augusto2112/revert-generic-pwt
Revert "[lldb] Implement support for constrained generics in generic …
2 parents 159c373 + cd3d3f9 commit 1dd271a

File tree

11 files changed

+23
-307
lines changed

11 files changed

+23
-307
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,8 +879,8 @@ swift::FuncDecl *SwiftASTManipulator::GetFunctionToInjectVariableInto(
879879
// pointers in the wrapper, so we can pass them as opaque pointers in the
880880
// trampoline function later on.
881881
if (!ShouldBindGenericTypes(m_bind_generic_types) &&
882-
(variable.IsMetadataPointer() || variable.IsWitnessTable() ||
883-
variable.IsPackCount() || variable.IsUnboundPack()))
882+
(variable.IsMetadataPointer() || variable.IsPackCount() ||
883+
variable.IsUnboundPack()))
884884
return m_entrypoint_decl;
885885

886886
return m_function_decl;

lldb/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.h

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,6 @@ class SwiftASTManipulatorBase {
103103

104104
struct VariableInfo {
105105
CompilerType GetType() const { return m_type; }
106-
/// The unbound swift::Type. Unbound means that the generic type parameters
107-
/// are not substituted (for example, Array<T> instead of Array<Int>). Only
108-
/// valid the the variable that represents self when evaluating the
109-
/// expression without the generic types.
110-
const swift::Type &GetUnboundType() const { return m_unbound_type; }
111106
swift::Identifier GetName() const { return m_name; }
112107
VariableMetadata *GetMetadata() const { return m_metadata.get(); }
113108
void TakeMetadata(VariableMetadata *vmd) { m_metadata.reset(vmd); }
@@ -118,7 +113,6 @@ class SwiftASTManipulatorBase {
118113
bool IsOutermostMetadataPointer() const {
119114
return m_name.str().starts_with("$τ_0_");
120115
}
121-
bool IsWitnessTable() const { return m_name.str().starts_with("$WT"); }
122116
bool IsSelf() const {
123117
return m_name.str() == "$__lldb_injected_self";
124118
}
@@ -131,16 +125,14 @@ class SwiftASTManipulatorBase {
131125
VariableInfo(CompilerType type, swift::Identifier name,
132126
VariableMetadataSP metadata,
133127
swift::VarDecl::Introducer introducer,
134-
bool is_capture_list = false, bool is_unbound_pack = false,
135-
swift::Type unbound_type = {})
136-
: m_type(type), m_unbound_type(unbound_type), m_name(name),
137-
m_metadata(metadata), m_var_introducer(introducer),
138-
m_is_capture_list(is_capture_list),
128+
bool is_capture_list = false, bool is_unbound_pack = false)
129+
: m_type(type), m_name(name), m_metadata(metadata),
130+
m_var_introducer(introducer), m_is_capture_list(is_capture_list),
139131
m_is_unbound_pack(is_unbound_pack) {}
140132
VariableInfo(const VariableInfo &other)
141-
: m_type(other.m_type), m_unbound_type(other.m_unbound_type),
142-
m_name(other.m_name), m_metadata(other.m_metadata),
143-
m_decl(other.m_decl), m_var_introducer(other.m_var_introducer),
133+
: m_type(other.m_type), m_name(other.m_name),
134+
m_metadata(other.m_metadata), m_decl(other.m_decl),
135+
m_var_introducer(other.m_var_introducer),
144136
m_lookup_error(other.m_lookup_error.Clone()),
145137
m_is_capture_list(other.m_is_capture_list),
146138
m_is_unbound_pack(other.m_is_unbound_pack) {}
@@ -158,7 +150,6 @@ class SwiftASTManipulatorBase {
158150
m_lookup_error = other.m_lookup_error.Clone();
159151
m_is_capture_list = other.m_is_capture_list;
160152
m_is_unbound_pack = other.m_is_unbound_pack;
161-
m_unbound_type = other.m_unbound_type;
162153
return *this;
163154
}
164155

@@ -174,7 +165,6 @@ class SwiftASTManipulatorBase {
174165

175166
protected:
176167
CompilerType m_type;
177-
swift::Type m_unbound_type;
178168
swift::Identifier m_name;
179169
VariableMetadataSP m_metadata;
180170
swift::VarDecl *m_decl = nullptr;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ AddArchetypeTypeAliases(std::unique_ptr<SwiftASTManipulator> &code_manipulator,
11791179
llvm::SmallDenseMap<llvm::StringRef, MetadataPointerInfo>
11801180
visible_metadata_pointers;
11811181
for (auto &variable : code_manipulator->GetVariableInfo()) {
1182-
if (!variable.IsMetadataPointer() && !variable.IsWitnessTable())
1182+
if (!variable.IsMetadataPointer())
11831183
continue;
11841184

11851185
llvm::StringRef type_name;

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

Lines changed: 6 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#include "lldb/Target/Target.h"
1919
#include "lldb/Utility/StreamString.h"
2020

21-
#include "swift/AST/ASTContext.h"
22-
#include "swift/AST/ASTMangler.h"
2321
#include "swift/Basic/LangOptions.h"
2422
#include "swift/Demangling/Demangle.h"
2523
#include "swift/Demangling/Demangler.h"
@@ -32,11 +30,8 @@ using namespace lldb_private;
3230

3331
namespace lldb_private {
3432
std::optional<std::pair<unsigned, unsigned>>
35-
ParseSwiftGenericParameter(llvm::StringRef name, bool expect_dollar_prefix) {
36-
if (expect_dollar_prefix && !name.consume_front("$"))
37-
return {};
38-
39-
if (!name.consume_front("τ_"))
33+
ParseSwiftGenericParameter(llvm::StringRef name) {
34+
if (!name.consume_front("$τ_"))
4035
return {};
4136

4237
auto pair = name.split('_');
@@ -170,127 +165,6 @@ static llvm::Expected<llvm::SmallVector<MetadataInfo>> CollectMetadataInfos(
170165
}
171166
return metadata_info;
172167
}
173-
174-
/// Returns a map from the index and depth to the archetype name, for example,
175-
/// given: struct S<T, U> {} This function returns {{0, 0} -> T, {0, 1} -> U}.
176-
static llvm::DenseMap<std::pair<unsigned, unsigned>, llvm::StringRef>
177-
MakeIndexAndDepthToArchetypeMap(
178-
llvm::ArrayRef<swift::Requirement> requirements) {
179-
llvm::DenseMap<std::pair<unsigned, unsigned>, llvm::StringRef> map;
180-
for (auto &req : requirements) {
181-
if (req.getKind() != swift::RequirementKind::Conformance)
182-
continue;
183-
auto type = req.getFirstType();
184-
auto *generic_type =
185-
llvm::dyn_cast<swift::GenericTypeParamType>(type.getPointer());
186-
if (!generic_type)
187-
continue;
188-
189-
unsigned depth = generic_type->getDepth();
190-
unsigned index = generic_type->getIndex();
191-
auto name = generic_type->getName().str();
192-
map.insert({{depth, index}, name});
193-
}
194-
return map;
195-
}
196-
197-
struct ParsedWitnessTable {
198-
/// The full name of the variable in debug info. For example:
199-
/// $WTτ_0_0$SubType$$MangledProtocol.
200-
llvm::StringRef full_name;
201-
/// The archetype name, for example T.SubType
202-
std::string archetype_name;
203-
/// The mangled protocol name.
204-
llvm::StringRef mangled_protocol_name;
205-
/// The "display" protocol name.
206-
std::string protocol_name;
207-
ParsedWitnessTable(llvm::StringRef full_name, std::string archetype_name,
208-
llvm::StringRef mangled_protocol_name,
209-
std::string protocol_name)
210-
: full_name(full_name), archetype_name(archetype_name),
211-
mangled_protocol_name(mangled_protocol_name),
212-
protocol_name(protocol_name) {}
213-
};
214-
215-
/// Parses the witness table artificial variables.
216-
static llvm::Expected<llvm::SmallVector<ParsedWitnessTable>> ParseWitnessInfos(
217-
llvm::ArrayRef<SwiftASTManipulator::VariableInfo> local_variables,
218-
llvm::ArrayRef<swift::Requirement> requirements) {
219-
llvm::SmallVector<ParsedWitnessTable> witness_tables;
220-
auto indexes_to_archetype = MakeIndexAndDepthToArchetypeMap(requirements);
221-
for (auto &local_variable : local_variables) {
222-
if (!local_variable.IsWitnessTable())
223-
continue;
224-
225-
// Full name looks something like "$WTτ_0_0$SubType$$MangledProtocol.".
226-
auto full_name = local_variable.GetName().str();
227-
auto [metadata_name, mangled_protocol_name] = full_name.split("$$");
228-
229-
if (metadata_name.empty() || mangled_protocol_name.empty() ||
230-
!SwiftLanguageRuntime::IsSwiftMangledName(mangled_protocol_name))
231-
return llvm::createStringError(
232-
"malformed witness table name in debug info");
233-
234-
metadata_name = metadata_name.drop_front(StringRef("$WT").size());
235-
auto [front, back] = metadata_name.split('$');
236-
auto maybe_depth_and_index =
237-
ParseSwiftGenericParameter(front, /*expect_dollar_prefix*/ false);
238-
if (!maybe_depth_and_index)
239-
return llvm::createStringError(
240-
"malformed witness table name in debug info");
241-
242-
auto [depth, index] = *maybe_depth_and_index;
243-
244-
auto it = indexes_to_archetype.find({depth, index});
245-
if (it == indexes_to_archetype.end())
246-
return llvm::createStringError(
247-
"malformed witness table name in debug info");
248-
249-
std::string archetype_name = it->getSecond().str();
250-
if (!back.empty())
251-
archetype_name += "." + back.str();
252-
std::replace(archetype_name.begin(), archetype_name.end(), '$', '.');
253-
auto protocol_name =
254-
swift::Demangle::demangleSymbolAsString(mangled_protocol_name);
255-
witness_tables.emplace_back(full_name, archetype_name,
256-
mangled_protocol_name, protocol_name);
257-
}
258-
259-
// Order the witness tables according to the requirements, otherwise we risk
260-
// passing the witness table pointers in the wrong order when generating the
261-
// expression.
262-
llvm::SmallVector<ParsedWitnessTable> ordered_witness_tables;
263-
for (auto &Requirement : requirements) {
264-
if (Requirement.getKind() != swift::RequirementKind::Conformance)
265-
continue;
266-
swift::ProtocolDecl *ProtocolDecl = Requirement.getProtocolDecl();
267-
auto protocol_type = ProtocolDecl->getDeclaredType();
268-
auto type = Requirement.getFirstType();
269-
auto &ast_ctx = type->getASTContext();
270-
swift::Mangle::ASTMangler mangler(ast_ctx, true);
271-
std::string mangled_protocol_name =
272-
mangler.mangleTypeForDebugger(protocol_type, nullptr);
273-
std::string name;
274-
if (auto *generic_type =
275-
llvm::dyn_cast<swift::GenericTypeParamType>(type.getPointer()))
276-
name = generic_type->getName().str();
277-
else if (auto *dependent =
278-
llvm::dyn_cast<swift::DependentMemberType>(type.getPointer()))
279-
name = dependent->getString();
280-
281-
for (auto &parsed_witness_table : witness_tables) {
282-
if (name == parsed_witness_table.archetype_name &&
283-
mangled_protocol_name == parsed_witness_table.mangled_protocol_name) {
284-
ordered_witness_tables.emplace_back(std::move(parsed_witness_table));
285-
}
286-
}
287-
}
288-
assert(ordered_witness_tables.size() == witness_tables.size() &&
289-
"Ordered witness table size does not match");
290-
291-
return ordered_witness_tables;
292-
}
293-
294168
/// Constructs the signatures for the expression evaluation functions based on
295169
/// the metadata variables in scope and any variadic functiontion parameters.
296170
/// For every outermost metadata pointer in scope ($τ_0_0, $τ_0_1, etc), we want
@@ -334,27 +208,10 @@ static llvm::Expected<CallsAndArgs> MakeGenericSignaturesAndCalls(
334208
return llvm::createStringError(llvm::errc::not_supported,
335209
"Inconsistent generic signature");
336210

337-
auto self = llvm::find_if(
338-
local_variables, [](const SwiftASTManipulator::VariableInfo &variable) {
339-
return variable.IsSelf();
340-
});
341-
llvm::SmallVector<ParsedWitnessTable> witness_infos;
342-
if (self && self->GetUnboundType()) {
343-
auto bound_generic = llvm::cast<swift::NominalOrBoundGenericNominalType>(
344-
self->GetUnboundType().getPointer());
345-
auto decl = bound_generic->getDecl();
346-
auto requirements = decl->getGenericRequirements();
347-
auto witness_infos_or_err = ParseWitnessInfos(local_variables, requirements);
348-
if (!witness_infos_or_err)
349-
return witness_infos_or_err.takeError();
350-
witness_infos = *witness_infos_or_err;
351-
}
352-
353-
auto metatada_infos_or_err =
354-
CollectMetadataInfos(metadata_variables, generic_sig);
355-
if (!metatada_infos_or_err)
356-
return metatada_infos_or_err.takeError();
357-
auto metadata_infos = *metatada_infos_or_err;
211+
auto maybe_metadata_infos = CollectMetadataInfos(metadata_variables, generic_sig);
212+
if (!maybe_metadata_infos)
213+
return maybe_metadata_infos.takeError();
214+
auto metadata_infos = *maybe_metadata_infos;
358215

359216
llvm::SmallDenseMap<std::pair<unsigned, unsigned>, llvm::SmallString<4>> subs;
360217
std::string generic_params;
@@ -373,17 +230,11 @@ static llvm::Expected<CallsAndArgs> MakeGenericSignaturesAndCalls(
373230
s_generic_params << sig_archetype_name << ",";
374231
subs.insert({{depth, index}, sig_archetype_name});
375232
}
376-
std::string type_constraints;
377-
llvm::raw_string_ostream s_type_constraints(type_constraints);
378-
for (auto &wi : witness_infos)
379-
s_type_constraints << wi.archetype_name << ": " << wi.protocol_name << ",";
380233

381234
if (!generic_params.empty())
382235
generic_params.pop_back();
383236
if (!generic_params_no_packs.empty())
384237
generic_params_no_packs.pop_back();
385-
if (!type_constraints.empty())
386-
type_constraints.pop_back();
387238

388239
std::string user_expr;
389240
llvm::raw_string_ostream user_expr_stream(user_expr);
@@ -399,8 +250,6 @@ static llvm::Expected<CallsAndArgs> MakeGenericSignaturesAndCalls(
399250
<< *pack_type;
400251
}
401252
user_expr_stream << ")";
402-
if (!type_constraints.empty())
403-
user_expr_stream << "where " << type_constraints;
404253

405254
std::string trampoline;
406255
llvm::raw_string_ostream trampoline_stream(trampoline);
@@ -410,8 +259,6 @@ static llvm::Expected<CallsAndArgs> MakeGenericSignaturesAndCalls(
410259
if (needs_object_ptr)
411260
trampoline_stream << ", _ $__lldb_injected_self: inout $__lldb_context";
412261
trampoline_stream << ")";
413-
if (!type_constraints.empty())
414-
trampoline_stream << "where " << type_constraints;
415262

416263
std::string sink;
417264
std::string call;
@@ -444,12 +291,6 @@ static llvm::Expected<CallsAndArgs> MakeGenericSignaturesAndCalls(
444291
sink_stream << ", _: $__lldb_builtin_ptr_t";
445292
call_stream << ", " << var->GetName().str();
446293
}
447-
448-
for (auto &wi : witness_infos) {
449-
sink_stream << ", _: $__lldb_builtin_ptr_t";
450-
call_stream << ", " << wi.full_name;
451-
}
452-
453294
sink_stream << ")";
454295
call_stream << ")";
455296

lldb/source/Plugins/ExpressionParser/Swift/SwiftExpressionSourceCode.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ namespace lldb_private {
1919

2020
/// Parse a name such as "$τ_0_0".
2121
std::optional<std::pair<unsigned, unsigned>>
22-
ParseSwiftGenericParameter(llvm::StringRef name,
23-
bool expect_dollar_prefix = true);
22+
ParseSwiftGenericParameter(llvm::StringRef name);
2423

2524
class SwiftExpressionSourceCode : public ExpressionSourceCode {
2625
public:

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ static llvm::Error AddVariableInfo(
328328
return llvm::Error::success();
329329

330330
CompilerType target_type;
331-
swift::Type unbound_type;
332331
bool should_not_bind_generic_types =
333332
!SwiftASTManipulator::ShouldBindGenericTypes(bind_generic_types);
334333
bool is_unbound_pack =
@@ -340,17 +339,11 @@ static llvm::Error AddVariableInfo(
340339
// opaque pointer type. This is necessary because we don't bind the generic
341340
// parameters, and we can't have a type with unbound generics in a non-generic
342341
// function.
343-
if (should_not_bind_generic_types && is_self) {
342+
if (should_not_bind_generic_types && is_self)
344343
target_type = ast_context.GetBuiltinRawPointerType();
345-
CompilerType var_type = SwiftExpressionParser::ResolveVariable(
346-
variable_sp, stack_frame_sp, runtime, use_dynamic, bind_generic_types);
347-
if (auto unbound_type_or_err = ast_context.GetSwiftType(var_type))
348-
unbound_type = *unbound_type_or_err;
349-
else
350-
return unbound_type_or_err.takeError();
351-
} else if (is_unbound_pack) {
344+
else if (is_unbound_pack)
352345
target_type = variable_sp->GetType()->GetForwardCompilerType();
353-
} else {
346+
else {
354347
CompilerType var_type = SwiftExpressionParser::ResolveVariable(
355348
variable_sp, stack_frame_sp, runtime, use_dynamic, bind_generic_types);
356349

@@ -441,7 +434,7 @@ static llvm::Error AddVariableInfo(
441434
metadata_sp,
442435
variable_sp->IsConstant() ? swift::VarDecl::Introducer::Let
443436
: swift::VarDecl::Introducer::Var,
444-
false, is_unbound_pack, unbound_type);
437+
false, is_unbound_pack);
445438
processed_variables.insert(overridden_name);
446439
return llvm::Error::success();
447440
}

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4882,7 +4882,6 @@ bool TypeSystemSwiftTypeRef::DumpTypeValue(
48824882
format = eFormatPointer;
48834883
LLVM_FALLTHROUGH;
48844884
case Node::Kind::BuiltinTypeName:
4885-
case Node::Kind::DependentMemberType:
48864885
case Node::Kind::DependentGenericParamType:
48874886
case Node::Kind::FunctionType:
48884887
case Node::Kind::NoEscapeFunctionType:

0 commit comments

Comments
 (0)