Skip to content

[lldb] Update for removal of ModuleDecl::addFile #9618

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 @@ -1295,19 +1295,21 @@ SwiftExpressionParser::ParseAndImport(
return make_error<SwiftASTContextError>();

auto module_id = ast_context->getIdentifier(expr_name_buf);
module = swift::ModuleDecl::create(module_id, **ast_context, importInfo);

swift::SourceFileKind source_file_kind = swift::SourceFileKind::Library;
if (playground || repl) {
source_file_kind = swift::SourceFileKind::Main;
}
module = swift::ModuleDecl::create(
module_id, **ast_context, importInfo,
[&](swift::ModuleDecl *module, auto addFile) {
swift::SourceFileKind source_file_kind = swift::SourceFileKind::Library;
if (playground || repl) {
source_file_kind = swift::SourceFileKind::Main;
}

// Create the source file. Note, we disable delayed parsing for the
// swift expression parser.
source_file = new (**ast_context) swift::SourceFile(
*module, source_file_kind, buffer_id,
swift::SourceFile::ParsingFlags::DisableDelayedBodies);
module->addFile(*source_file);
// Create the source file. Note, we disable delayed parsing for the
// swift expression parser.
source_file = new (**ast_context) swift::SourceFile(
*module, source_file_kind, buffer_id,
swift::SourceFile::ParsingFlags::DisableDelayedBodies);
addFile(source_file);
});
}
// Swift Modules that rely on shared libraries (not frameworks)
// don't record the link information in the swiftmodule file, so we
Expand Down
16 changes: 10 additions & 6 deletions lldb/source/Plugins/ExpressionParser/Swift/SwiftREPL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,18 +608,22 @@ void SwiftREPL::CompleteCode(const std::string &current_code,
if (!repl_module) {
swift::ImplicitImportInfo importInfo;
importInfo.StdlibKind = swift::ImplicitStdlibKind::Stdlib;

auto repl_module_or_err = swift_ast->CreateModule(
completion_module_info.path.back().GetString(), importInfo);
completion_module_info.path.back().GetString(), importInfo,
[&](swift::ModuleDecl *repl_module, auto addFile) {
auto bufferID = (*ast)->SourceMgr.addMemBufferCopy("// swift repl\n");
swift::SourceFile *repl_source_file = new (**ast) swift::SourceFile(
*repl_module, swift::SourceFileKind::Main, bufferID);
addFile(repl_source_file);
});
if (!repl_module_or_err) {
llvm::consumeError(repl_module_or_err.takeError());
return;
}
repl_module = &*repl_module_or_err;
auto bufferID = (*ast)->SourceMgr.addMemBufferCopy("// swift repl\n");
swift::SourceFile *repl_source_file = new (**ast)
swift::SourceFile(*repl_module, swift::SourceFileKind::Main, bufferID);
repl_module->addFile(*repl_source_file);
swift::performImportResolution(*repl_source_file);

swift::performImportResolution(repl_module);
m_completion_module_initialized = true;
}
if (repl_module) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1477,8 +1477,7 @@ void SwiftLanguageRuntime::RegisterGlobalError(Target &target, ConstString name,
module_info.path.push_back(ConstString(module_name));

swift::ModuleDecl *module_decl = nullptr;
auto module_decl_or_err = swift_ast_ctx->CreateModule(module_name,
/*importInfo*/ {});
auto module_decl_or_err = swift_ast_ctx->CreateEmptyModule(module_name);
if (!module_decl_or_err)
llvm::consumeError(module_decl_or_err.takeError());
else
Expand Down
18 changes: 12 additions & 6 deletions lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3834,8 +3834,14 @@ swift::ModuleDecl *SwiftASTContext::GetCachedModule(std::string module_name) {
}

llvm::Expected<swift::ModuleDecl &>
SwiftASTContext::CreateModule(std::string module_name,
swift::ImplicitImportInfo importInfo) {
SwiftASTContext::CreateEmptyModule(std::string module_name) {
return CreateModule(module_name, /*importInfo*/ {},
/*populateFiles*/ [](auto, auto) {});
}

llvm::Expected<swift::ModuleDecl &> SwiftASTContext::CreateModule(
std::string module_name, swift::ImplicitImportInfo importInfo,
swift::ModuleDecl::PopulateFilesFn populateFiles) {
VALID_OR_RETURN(llvm::createStringError("no context"));
if (module_name.empty())
return llvm::createStringError("invalid module name (empty)");
Expand All @@ -3849,7 +3855,8 @@ SwiftASTContext::CreateModule(std::string module_name,
return llvm::createStringError("invalid swift AST (nullptr)");

swift::Identifier module_id(ast->getIdentifier(module_name));
auto *module_decl = swift::ModuleDecl::create(module_id, **ast, importInfo);
auto *module_decl =
swift::ModuleDecl::create(module_id, **ast, importInfo, populateFiles);
if (!module_decl)
return llvm::createStringError("failed to create module for \"{0}\"",
module_name.c_str());
Expand Down Expand Up @@ -5130,9 +5137,8 @@ swift::ModuleDecl *SwiftASTContext::GetScratchModule() {

if (m_scratch_module == nullptr) {
ThreadSafeASTContext ast_ctx = GetASTContext();
m_scratch_module = swift::ModuleDecl::create(
GetASTContext()->getIdentifier("__lldb_scratch_module"),
**ast_ctx);
m_scratch_module = swift::ModuleDecl::createEmpty(
GetASTContext()->getIdentifier("__lldb_scratch_module"), **ast_ctx);
}
return m_scratch_module;
}
Expand Down
9 changes: 8 additions & 1 deletion lldb/source/Plugins/TypeSystem/Swift/SwiftASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,19 @@ class SwiftASTContext : public TypeSystemSwift {
/// \return the ExtraArgs of the ClangImporterOptions.
const std::vector<std::string> &GetClangArguments();

/// Attempt to create an empty Swift module.
llvm::Expected<swift::ModuleDecl &>
CreateEmptyModule(std::string module_name);

/// Attempt to create a Swift module.
///
/// \param importInfo Information about which modules should be implicitly
/// imported by each file of the module.
/// \param populateFiles A function which populates the files for the module.
/// Once called, the module's list of files may not change.
llvm::Expected<swift::ModuleDecl &>
CreateModule(std::string module_name, swift::ImplicitImportInfo importInfo);
CreateModule(std::string module_name, swift::ImplicitImportInfo importInfo,
swift::ModuleDecl::PopulateFilesFn populateFiles);

// This function should only be called when all search paths
// for all items in a swift::ASTContext have been setup to
Expand Down