Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ void SwiftREPL::Terminate() {
}

SwiftREPL::SwiftREPL(Target &target)
: REPL(LLVMCastKind::eKindSwift, target), m_swift_ast_sp() {}
: REPL(LLVMCastKind::eKindSwift, target), m_swift_ast(nullptr) {}

SwiftREPL::~SwiftREPL() {}

Expand Down Expand Up @@ -542,7 +542,7 @@ int SwiftREPL::CompleteCode(const std::string &current_code,
// our own copy of the AST and using this separate AST for completion.
//----------------------------------------------------------------------
Status error;
if (!m_swift_ast_sp) {
if (!m_swift_ast) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we also need to acquire the scratch context lock. That's very easy if you just call target.GetSwiftScratchContext().

auto type_system_or_err = m_target.GetScratchTypeSystemForLanguage(eLanguageTypeSwift);
if (!type_system_or_err) {
llvm::consumeError(type_system_or_err.takeError());
Expand All @@ -551,10 +551,9 @@ int SwiftREPL::CompleteCode(const std::string &current_code,

auto *target_swift_ast =
llvm::dyn_cast_or_null<SwiftASTContext>(&*type_system_or_err);
if (target_swift_ast)
m_swift_ast_sp.reset(new SwiftASTContext(*target_swift_ast));
m_swift_ast = target_swift_ast;
}
SwiftASTContext *swift_ast = m_swift_ast_sp.get();
SwiftASTContext *swift_ast = m_swift_ast;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should get rid of m_swift_ast and only use the local copy, because it's not safe to hold on to the pointer without also holding on to the lock.


if (swift_ast) {
swift::ASTContext *ast = swift_ast->GetASTContext();
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class SwiftREPL : public REPL {
}

private:
std::shared_ptr<SwiftASTContext> m_swift_ast_sp;
SwiftASTContext *m_swift_ast = nullptr;
bool m_completion_module_initialized = false;
};
}
Expand Down