Skip to content

Replace stack frame parameter with the more general process. (NFC) #4070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1305,8 +1305,11 @@ static llvm::Expected<ParsedExpression> ParseAndImport(
Status implicit_import_error;
llvm::SmallVector<swift::AttributedImport<swift::ImportedModule>, 16>
additional_imports;
lldb::ProcessSP process_sp;
if (lldb::StackFrameSP this_frame_sp = stack_frame_wp.lock())
process_sp = this_frame_sp->CalculateProcess();
if (!SwiftASTContext::GetImplicitImports(swift_ast_context, sc, exe_scope,
stack_frame_wp, additional_imports,
process_sp, additional_imports,
implicit_import_error)) {
const char *msg = implicit_import_error.AsCString();
if (!msg)
Expand Down Expand Up @@ -1455,12 +1458,12 @@ static llvm::Expected<ParsedExpression> ParseAndImport(

Status auto_import_error;
if (!SwiftASTContext::CacheUserImports(swift_ast_context, sc, exe_scope,
stack_frame_wp, *source_file,
process_sp, *source_file,
auto_import_error)) {
const char *msg = auto_import_error.AsCString();
if (!msg)
msg = "error status positive, but import still failed";
return make_error<ModuleImportError>(msg, /*explicit=*/true);
const char *msg = auto_import_error.AsCString();
if (!msg)
msg = "error status positive, but import still failed";
return make_error<ModuleImportError>(msg, /*explicit=*/true);
}
}

Expand Down
41 changes: 17 additions & 24 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8085,7 +8085,7 @@ static void GetNameFromModule(swift::ModuleDecl *module, std::string &result) {

static swift::ModuleDecl *LoadOneModule(const SourceModule &module,
SwiftASTContext &swift_ast_context,
lldb::StackFrameWP &stack_frame_wp,
lldb::ProcessSP process_sp,
Status &error) {
LLDB_SCOPED_TIMER();
if (!module.path.size())
Expand All @@ -8097,22 +8097,16 @@ static swift::ModuleDecl *LoadOneModule(const SourceModule &module,
LOG_PRINTF(GetLog(LLDBLog::Types | LLDBLog::Expressions),
"Importing module %s", toplevel.AsCString());
swift::ModuleDecl *swift_module = nullptr;
lldb::StackFrameSP this_frame_sp(stack_frame_wp.lock());

auto *clangimporter = swift_ast_context.GetClangImporter();
swift::ModuleDecl *imported_header_module =
clangimporter ? clangimporter->getImportedHeaderModule() : nullptr;
if (imported_header_module &&
toplevel.GetStringRef() == imported_header_module->getName().str())
swift_module = imported_header_module;
else if (this_frame_sp) {
lldb::ProcessSP process_sp(this_frame_sp->CalculateProcess());
if (process_sp)
swift_module =
swift_ast_context.FindAndLoadModule(module, *process_sp.get(), error);
else
swift_module = swift_ast_context.GetModule(module, error);
} else
else if (process_sp)
swift_module =
swift_ast_context.FindAndLoadModule(module, *process_sp.get(), error);
else
swift_module = swift_ast_context.GetModule(module, error);

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

bool SwiftASTContext::GetImplicitImports(
SwiftASTContext &swift_ast_context, SymbolContext &sc,
ExecutionContextScope &exe_scope, lldb::StackFrameWP &stack_frame_wp,
ExecutionContextScope &exe_scope, lldb::ProcessSP process_sp,
llvm::SmallVectorImpl<swift::AttributedImport<swift::ImportedModule>>
&modules,
Status &error) {
LLDB_SCOPED_TIMER();
if (!swift_ast_context.GetCompileUnitImports(sc, stack_frame_wp, modules,
if (!swift_ast_context.GetCompileUnitImports(sc, process_sp, modules,
error)) {
return false;
}
Expand All @@ -8187,7 +8181,7 @@ bool SwiftASTContext::GetImplicitImports(
SourceModule module_info;
module_info.path.emplace_back(module_pair.first());
auto *module =
LoadOneModule(module_info, swift_ast_context, stack_frame_wp, error);
LoadOneModule(module_info, swift_ast_context, process_sp, error);
if (!module)
return false;

Expand All @@ -8200,7 +8194,7 @@ bool SwiftASTContext::GetImplicitImports(
bool SwiftASTContext::CacheUserImports(SwiftASTContext &swift_ast_context,
SymbolContext &sc,
ExecutionContextScope &exe_scope,
lldb::StackFrameWP &stack_frame_wp,
lldb::ProcessSP process_sp,
swift::SourceFile &source_file,
Status &error) {
llvm::SmallString<1> m_description;
Expand All @@ -8221,8 +8215,7 @@ bool SwiftASTContext::CacheUserImports(SwiftASTContext &swift_ast_context,
LOG_PRINTF(GetLog(LLDBLog::Types | LLDBLog::Expressions),
"Performing auto import on found module: %s.\n",
module_name.c_str());
if (!LoadOneModule(module_info, swift_ast_context, stack_frame_wp,
error))
if (!LoadOneModule(module_info, swift_ast_context, process_sp, error))
return false;

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

bool SwiftASTContext::GetCompileUnitImports(
SymbolContext &sc, lldb::StackFrameWP &stack_frame_wp,
SymbolContext &sc, ProcessSP process_sp,
llvm::SmallVectorImpl<swift::AttributedImport<swift::ImportedModule>>
&modules,
Status &error) {
return GetCompileUnitImportsImpl(sc, stack_frame_wp, &modules, error);
return GetCompileUnitImportsImpl(sc, process_sp, &modules, error);
}

void SwiftASTContext::PerformCompileUnitImports(
SymbolContext &sc, lldb::StackFrameWP &stack_frame_wp, Status &error) {
GetCompileUnitImportsImpl(sc, stack_frame_wp, nullptr, error);
SymbolContext &sc, lldb::ProcessSP process_sp, Status &error) {
GetCompileUnitImportsImpl(sc, process_sp, nullptr, error);
}

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

bool SwiftASTContext::GetCompileUnitImportsImpl(
SymbolContext &sc, lldb::StackFrameWP &stack_frame_wp,
SymbolContext &sc, lldb::ProcessSP process_sp,
llvm::SmallVectorImpl<swift::AttributedImport<swift::ImportedModule>>
*modules,
Status &error) {
Expand All @@ -8277,7 +8270,7 @@ bool SwiftASTContext::GetCompileUnitImportsImpl(
SourceModule swift_module;
swift_module.path.emplace_back("Swift");
auto *stdlib =
LoadOneModule(swift_module, *this, stack_frame_wp, error);
LoadOneModule(swift_module, *this, process_sp, error);
if (!stdlib)
return false;

Expand All @@ -8298,7 +8291,7 @@ bool SwiftASTContext::GetCompileUnitImportsImpl(
continue;

auto *loaded_module =
LoadOneModule(module, *this, stack_frame_wp, error);
LoadOneModule(module, *this, process_sp, error);
if (!loaded_module)
return false;

Expand Down
11 changes: 5 additions & 6 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ class SwiftASTContext : public TypeSystemSwift {
/// unit as well as any imports from previous expression evaluations.
static bool GetImplicitImports(
SwiftASTContext &swift_ast_context, SymbolContext &sc,
ExecutionContextScope &exe_scope, lldb::StackFrameWP &stack_frame_wp,
ExecutionContextScope &exe_scope, lldb::ProcessSP process_sp,
llvm::SmallVectorImpl<swift::AttributedImport<swift::ImportedModule>>
&modules,
Status &error);
Expand All @@ -767,25 +767,24 @@ class SwiftASTContext : public TypeSystemSwift {
static bool CacheUserImports(SwiftASTContext &swift_ast_context,
SymbolContext &sc,
ExecutionContextScope &exe_scope,
lldb::StackFrameWP &stack_frame_wp,
lldb::ProcessSP process_sp,
swift::SourceFile &source_file, Status &error);

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

/// Perform all the implicit imports for the current frame.
void PerformCompileUnitImports(SymbolContext &sc,
lldb::StackFrameWP &stack_frame_wp,
void PerformCompileUnitImports(SymbolContext &sc, lldb::ProcessSP process_sp,
Status &error);

protected:
bool GetCompileUnitImportsImpl(
SymbolContext &sc, lldb::StackFrameWP &stack_frame_wp,
SymbolContext &sc, lldb::ProcessSP process_sp,
llvm::SmallVectorImpl<swift::AttributedImport<swift::ImportedModule>>
*modules,
Status &error);
Expand Down
10 changes: 6 additions & 4 deletions lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1321,9 +1321,10 @@ TypeSystemSwiftTypeRefForExpressions::TypeSystemSwiftTypeRefForExpressions(
void TypeSystemSwiftTypeRefForExpressions::PerformCompileUnitImports(
SymbolContext &sc) {
Status error;
lldb::StackFrameWP stack_frame;
// FIXME: this is uninitialized!
lldb::ProcessSP process_sp;
Comment on lines +1324 to +1325

Choose a reason for hiding this comment

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

is this intended to be fixed before merging?

Copy link
Author

Choose a reason for hiding this comment

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

Fix is in #4077

if (m_swift_ast_context_initialized)
GetSwiftASTContext()->PerformCompileUnitImports(sc, stack_frame, error);
GetSwiftASTContext()->PerformCompileUnitImports(sc, process_sp, error);
else
m_initial_symbol_context = std::make_unique<SymbolContext>(sc);
}
Expand Down Expand Up @@ -1382,9 +1383,10 @@ TypeSystemSwiftTypeRefForExpressions::GetSwiftASTContext() const {

if (m_initial_symbol_context) {
Status error;
lldb::StackFrameWP stack_frame;
// FIXME: not initialized!
lldb::ProcessSP process_sp;
m_swift_ast_context->PerformCompileUnitImports(*m_initial_symbol_context,
stack_frame, error);
process_sp, error);
m_initial_symbol_context.reset();
}

Expand Down