Skip to content

Commit 7efc696

Browse files
committed
Avoid reconstructing the type of self in the per-module SwiftASTContext.
It will need to be reconstructed in SwiftASTContextForExpressions right after, so also use the scratch context here.
1 parent 9004c0e commit 7efc696

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,8 @@ GetPersistentState(Target *target, ExecutionContext &exe_ctx) {
489489
static bool CanEvaluateExpressionWithoutBindingGenericParams(
490490
const llvm::SmallVectorImpl<SwiftASTManipulator::VariableInfo> &variables,
491491
const llvm::Optional<SwiftLanguageRuntime::GenericSignature> &generic_sig,
492-
Block *block, StackFrame &stack_frame) {
492+
SwiftASTContextForExpressions &scratch_ctx, Block *block,
493+
StackFrame &stack_frame) {
493494
// First, find the compiler type of self with the generic parameters not
494495
// bound.
495496
auto self_var = SwiftExpressionParser::FindSelfVariable(block);
@@ -514,11 +515,7 @@ static bool CanEvaluateExpressionWithoutBindingGenericParams(
514515
if (!ts)
515516
return false;
516517

517-
auto *swift_ast_ctx = ts->GetSwiftASTContext();
518-
if (!swift_ast_ctx)
519-
return false;
520-
521-
auto swift_type = swift_ast_ctx->GetSwiftType(self_type);
518+
auto swift_type = scratch_ctx.GetSwiftType(self_type);
522519
if (!swift_type)
523520
return false;
524521

@@ -614,7 +611,8 @@ SwiftUserExpression::GetTextAndSetExpressionParser(
614611

615612
if (m_options.GetBindGenericTypes() == lldb::eDontBind &&
616613
!CanEvaluateExpressionWithoutBindingGenericParams(
617-
local_variables, m_generic_signature, sc.block, *stack_frame.get())) {
614+
local_variables, m_generic_signature, *m_swift_ast_ctx, sc.block,
615+
*stack_frame.get())) {
618616
diagnostic_manager.PutString(
619617
eDiagnosticSeverityError,
620618
"Could not evaluate the expression without binding generic types.");

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -211,19 +211,10 @@ CompilerType SwiftASTContext::GetCompilerType(swift::TypeBase *swift_type) {
211211
}
212212

213213
swift::Type SwiftASTContext::GetSwiftType(CompilerType compiler_type) {
214-
if (compiler_type.GetTypeSystem().isa_and_nonnull<SwiftASTContext>())
214+
if (compiler_type.GetTypeSystem().GetSharedPointer().get() == this)
215215
return reinterpret_cast<swift::TypeBase *>(
216216
compiler_type.GetOpaqueQualType());
217-
218-
// FIXME: Suboptimal performance, because the ConstString is looked up again.
219-
if (auto ts = compiler_type.GetTypeSystem()
220-
.dyn_cast_or_null<TypeSystemSwiftTypeRef>()) {
221-
ConstString mangled_name(
222-
reinterpret_cast<const char *>(compiler_type.GetOpaqueQualType()));
223-
if (auto *swift_ast_context = ts->GetSwiftASTContext())
224-
return swift_ast_context->ReconstructType(mangled_name);
225-
}
226-
return {};
217+
return ReconstructType(compiler_type.GetMangledTypeName());
227218
}
228219

229220
swift::Type SwiftASTContext::GetSwiftType(opaque_compiler_type_t opaque_type) {

lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,11 @@ class SwiftASTContext : public TypeSystemSwift {
406406

407407
CompilerType GetCompilerType(swift::TypeBase *swift_type);
408408
CompilerType GetCompilerType(ConstString mangled_name);
409+
/// Import compiler_type into this context and return the swift::Type.
409410
swift::Type GetSwiftType(CompilerType compiler_type);
411+
protected:
410412
swift::Type GetSwiftType(lldb::opaque_compiler_type_t opaque_type);
413+
public:
411414
swift::CanType
412415
GetCanonicalSwiftType(lldb::opaque_compiler_type_t opaque_type);
413416

0 commit comments

Comments
 (0)