Skip to content

Commit fd44c19

Browse files
committed
Replace stack frame parameter with the more general process. (NFC)
This is a completely NFC refactoring to replace the stack frame weak pointer passed through the LoadModule machinery with the less-specific lldb::ProcessSP that is actually needed in the end.
1 parent ff38851 commit fd44c19

File tree

4 files changed

+37
-40
lines changed

4 files changed

+37
-40
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,8 +1305,11 @@ static llvm::Expected<ParsedExpression> ParseAndImport(
13051305
Status implicit_import_error;
13061306
llvm::SmallVector<swift::AttributedImport<swift::ImportedModule>, 16>
13071307
additional_imports;
1308+
lldb::ProcessSP process_sp;
1309+
if (lldb::StackFrameSP this_frame_sp = stack_frame_wp.lock())
1310+
process_sp = this_frame_sp->CalculateProcess();
13081311
if (!SwiftASTContext::GetImplicitImports(swift_ast_context, sc, exe_scope,
1309-
stack_frame_wp, additional_imports,
1312+
process_sp, additional_imports,
13101313
implicit_import_error)) {
13111314
const char *msg = implicit_import_error.AsCString();
13121315
if (!msg)
@@ -1455,12 +1458,12 @@ static llvm::Expected<ParsedExpression> ParseAndImport(
14551458

14561459
Status auto_import_error;
14571460
if (!SwiftASTContext::CacheUserImports(swift_ast_context, sc, exe_scope,
1458-
stack_frame_wp, *source_file,
1461+
process_sp, *source_file,
14591462
auto_import_error)) {
1460-
const char *msg = auto_import_error.AsCString();
1461-
if (!msg)
1462-
msg = "error status positive, but import still failed";
1463-
return make_error<ModuleImportError>(msg, /*explicit=*/true);
1463+
const char *msg = auto_import_error.AsCString();
1464+
if (!msg)
1465+
msg = "error status positive, but import still failed";
1466+
return make_error<ModuleImportError>(msg, /*explicit=*/true);
14641467
}
14651468
}
14661469

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

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8085,7 +8085,7 @@ static void GetNameFromModule(swift::ModuleDecl *module, std::string &result) {
80858085

80868086
static swift::ModuleDecl *LoadOneModule(const SourceModule &module,
80878087
SwiftASTContext &swift_ast_context,
8088-
lldb::StackFrameWP &stack_frame_wp,
8088+
lldb::ProcessSP process_sp,
80898089
Status &error) {
80908090
LLDB_SCOPED_TIMER();
80918091
if (!module.path.size())
@@ -8097,22 +8097,16 @@ static swift::ModuleDecl *LoadOneModule(const SourceModule &module,
80978097
LOG_PRINTF(GetLog(LLDBLog::Types | LLDBLog::Expressions),
80988098
"Importing module %s", toplevel.AsCString());
80998099
swift::ModuleDecl *swift_module = nullptr;
8100-
lldb::StackFrameSP this_frame_sp(stack_frame_wp.lock());
8101-
81028100
auto *clangimporter = swift_ast_context.GetClangImporter();
81038101
swift::ModuleDecl *imported_header_module =
81048102
clangimporter ? clangimporter->getImportedHeaderModule() : nullptr;
81058103
if (imported_header_module &&
81068104
toplevel.GetStringRef() == imported_header_module->getName().str())
81078105
swift_module = imported_header_module;
8108-
else if (this_frame_sp) {
8109-
lldb::ProcessSP process_sp(this_frame_sp->CalculateProcess());
8110-
if (process_sp)
8111-
swift_module =
8112-
swift_ast_context.FindAndLoadModule(module, *process_sp.get(), error);
8113-
else
8114-
swift_module = swift_ast_context.GetModule(module, error);
8115-
} else
8106+
else if (process_sp)
8107+
swift_module =
8108+
swift_ast_context.FindAndLoadModule(module, *process_sp.get(), error);
8109+
else
81168110
swift_module = swift_ast_context.GetModule(module, error);
81178111

81188112
if (swift_module && IsDWARFImported(*swift_module)) {
@@ -8157,12 +8151,12 @@ static swift::ModuleDecl *LoadOneModule(const SourceModule &module,
81578151

81588152
bool SwiftASTContext::GetImplicitImports(
81598153
SwiftASTContext &swift_ast_context, SymbolContext &sc,
8160-
ExecutionContextScope &exe_scope, lldb::StackFrameWP &stack_frame_wp,
8154+
ExecutionContextScope &exe_scope, lldb::ProcessSP process_sp,
81618155
llvm::SmallVectorImpl<swift::AttributedImport<swift::ImportedModule>>
81628156
&modules,
81638157
Status &error) {
81648158
LLDB_SCOPED_TIMER();
8165-
if (!swift_ast_context.GetCompileUnitImports(sc, stack_frame_wp, modules,
8159+
if (!swift_ast_context.GetCompileUnitImports(sc, process_sp, modules,
81668160
error)) {
81678161
return false;
81688162
}
@@ -8187,7 +8181,7 @@ bool SwiftASTContext::GetImplicitImports(
81878181
SourceModule module_info;
81888182
module_info.path.emplace_back(module_pair.first());
81898183
auto *module =
8190-
LoadOneModule(module_info, swift_ast_context, stack_frame_wp, error);
8184+
LoadOneModule(module_info, swift_ast_context, process_sp, error);
81918185
if (!module)
81928186
return false;
81938187

@@ -8200,7 +8194,7 @@ bool SwiftASTContext::GetImplicitImports(
82008194
bool SwiftASTContext::CacheUserImports(SwiftASTContext &swift_ast_context,
82018195
SymbolContext &sc,
82028196
ExecutionContextScope &exe_scope,
8203-
lldb::StackFrameWP &stack_frame_wp,
8197+
lldb::ProcessSP process_sp,
82048198
swift::SourceFile &source_file,
82058199
Status &error) {
82068200
llvm::SmallString<1> m_description;
@@ -8221,8 +8215,7 @@ bool SwiftASTContext::CacheUserImports(SwiftASTContext &swift_ast_context,
82218215
LOG_PRINTF(GetLog(LLDBLog::Types | LLDBLog::Expressions),
82228216
"Performing auto import on found module: %s.\n",
82238217
module_name.c_str());
8224-
if (!LoadOneModule(module_info, swift_ast_context, stack_frame_wp,
8225-
error))
8218+
if (!LoadOneModule(module_info, swift_ast_context, process_sp, error))
82268219
return false;
82278220

82288221
// How do we tell we are in REPL or playground mode?
@@ -8235,16 +8228,16 @@ bool SwiftASTContext::CacheUserImports(SwiftASTContext &swift_ast_context,
82358228
}
82368229

82378230
bool SwiftASTContext::GetCompileUnitImports(
8238-
SymbolContext &sc, lldb::StackFrameWP &stack_frame_wp,
8231+
SymbolContext &sc, ProcessSP process_sp,
82398232
llvm::SmallVectorImpl<swift::AttributedImport<swift::ImportedModule>>
82408233
&modules,
82418234
Status &error) {
8242-
return GetCompileUnitImportsImpl(sc, stack_frame_wp, &modules, error);
8235+
return GetCompileUnitImportsImpl(sc, process_sp, &modules, error);
82438236
}
82448237

82458238
void SwiftASTContext::PerformCompileUnitImports(
8246-
SymbolContext &sc, lldb::StackFrameWP &stack_frame_wp, Status &error) {
8247-
GetCompileUnitImportsImpl(sc, stack_frame_wp, nullptr, error);
8239+
SymbolContext &sc, lldb::ProcessSP process_sp, Status &error) {
8240+
GetCompileUnitImportsImpl(sc, process_sp, nullptr, error);
82488241
}
82498242

82508243
static std::pair<Module *, lldb::user_id_t>
@@ -8253,7 +8246,7 @@ GetCUSignature(CompileUnit &compile_unit) {
82538246
}
82548247

82558248
bool SwiftASTContext::GetCompileUnitImportsImpl(
8256-
SymbolContext &sc, lldb::StackFrameWP &stack_frame_wp,
8249+
SymbolContext &sc, lldb::ProcessSP process_sp,
82578250
llvm::SmallVectorImpl<swift::AttributedImport<swift::ImportedModule>>
82588251
*modules,
82598252
Status &error) {
@@ -8277,7 +8270,7 @@ bool SwiftASTContext::GetCompileUnitImportsImpl(
82778270
SourceModule swift_module;
82788271
swift_module.path.emplace_back("Swift");
82798272
auto *stdlib =
8280-
LoadOneModule(swift_module, *this, stack_frame_wp, error);
8273+
LoadOneModule(swift_module, *this, process_sp, error);
82818274
if (!stdlib)
82828275
return false;
82838276

@@ -8298,7 +8291,7 @@ bool SwiftASTContext::GetCompileUnitImportsImpl(
82988291
continue;
82998292

83008293
auto *loaded_module =
8301-
LoadOneModule(module, *this, stack_frame_wp, error);
8294+
LoadOneModule(module, *this, process_sp, error);
83028295
if (!loaded_module)
83038296
return false;
83048297

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ class SwiftASTContext : public TypeSystemSwift {
757757
/// unit as well as any imports from previous expression evaluations.
758758
static bool GetImplicitImports(
759759
SwiftASTContext &swift_ast_context, SymbolContext &sc,
760-
ExecutionContextScope &exe_scope, lldb::StackFrameWP &stack_frame_wp,
760+
ExecutionContextScope &exe_scope, lldb::ProcessSP process_sp,
761761
llvm::SmallVectorImpl<swift::AttributedImport<swift::ImportedModule>>
762762
&modules,
763763
Status &error);
@@ -767,25 +767,24 @@ class SwiftASTContext : public TypeSystemSwift {
767767
static bool CacheUserImports(SwiftASTContext &swift_ast_context,
768768
SymbolContext &sc,
769769
ExecutionContextScope &exe_scope,
770-
lldb::StackFrameWP &stack_frame_wp,
770+
lldb::ProcessSP process_sp,
771771
swift::SourceFile &source_file, Status &error);
772772

773773
/// Retrieve/import the modules imported by the compilation
774774
/// unit. Early-exists with false if there was an import failure.
775775
bool GetCompileUnitImports(
776-
SymbolContext &sc, lldb::StackFrameWP &stack_frame_wp,
776+
SymbolContext &sc, lldb::ProcessSP process_sp,
777777
llvm::SmallVectorImpl<swift::AttributedImport<swift::ImportedModule>>
778778
&modules,
779779
Status &error);
780780

781781
/// Perform all the implicit imports for the current frame.
782-
void PerformCompileUnitImports(SymbolContext &sc,
783-
lldb::StackFrameWP &stack_frame_wp,
782+
void PerformCompileUnitImports(SymbolContext &sc, lldb::ProcessSP process_sp,
784783
Status &error);
785784

786785
protected:
787786
bool GetCompileUnitImportsImpl(
788-
SymbolContext &sc, lldb::StackFrameWP &stack_frame_wp,
787+
SymbolContext &sc, lldb::ProcessSP process_sp,
789788
llvm::SmallVectorImpl<swift::AttributedImport<swift::ImportedModule>>
790789
*modules,
791790
Status &error);

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,9 +1321,10 @@ TypeSystemSwiftTypeRefForExpressions::TypeSystemSwiftTypeRefForExpressions(
13211321
void TypeSystemSwiftTypeRefForExpressions::PerformCompileUnitImports(
13221322
SymbolContext &sc) {
13231323
Status error;
1324-
lldb::StackFrameWP stack_frame;
1324+
// FIXME: this is uninitialized!
1325+
lldb::ProcessSP process_sp;
13251326
if (m_swift_ast_context_initialized)
1326-
GetSwiftASTContext()->PerformCompileUnitImports(sc, stack_frame, error);
1327+
GetSwiftASTContext()->PerformCompileUnitImports(sc, process_sp, error);
13271328
else
13281329
m_initial_symbol_context = std::make_unique<SymbolContext>(sc);
13291330
}
@@ -1382,9 +1383,10 @@ TypeSystemSwiftTypeRefForExpressions::GetSwiftASTContext() const {
13821383

13831384
if (m_initial_symbol_context) {
13841385
Status error;
1385-
lldb::StackFrameWP stack_frame;
1386+
// FIXME: not initialized!
1387+
lldb::ProcessSP process_sp;
13861388
m_swift_ast_context->PerformCompileUnitImports(*m_initial_symbol_context,
1387-
stack_frame, error);
1389+
process_sp, error);
13881390
m_initial_symbol_context.reset();
13891391
}
13901392

0 commit comments

Comments
 (0)