Skip to content

Commit af86fdb

Browse files
authored
Merge pull request #9658 from hamishknight/lets-try-this-again-next
[next] [lldb] Update for removal of `ModuleDecl::addFile`
2 parents 69af46f + a90466e commit af86fdb

File tree

5 files changed

+45
-27
lines changed

5 files changed

+45
-27
lines changed

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

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,19 +1296,21 @@ SwiftExpressionParser::ParseAndImport(
12961296
return make_error<SwiftASTContextError>();
12971297

12981298
auto module_id = ast_context->getIdentifier(expr_name_buf);
1299-
module = swift::ModuleDecl::create(module_id, **ast_context, importInfo);
1300-
1301-
swift::SourceFileKind source_file_kind = swift::SourceFileKind::Library;
1302-
if (playground || repl) {
1303-
source_file_kind = swift::SourceFileKind::Main;
1304-
}
1299+
module = swift::ModuleDecl::create(
1300+
module_id, **ast_context, importInfo,
1301+
[&](swift::ModuleDecl *module, auto addFile) {
1302+
swift::SourceFileKind source_file_kind = swift::SourceFileKind::Library;
1303+
if (playground || repl) {
1304+
source_file_kind = swift::SourceFileKind::Main;
1305+
}
13051306

1306-
// Create the source file. Note, we disable delayed parsing for the
1307-
// swift expression parser.
1308-
source_file = new (**ast_context) swift::SourceFile(
1309-
*module, source_file_kind, buffer_id,
1310-
swift::SourceFile::ParsingFlags::DisableDelayedBodies);
1311-
module->addFile(*source_file);
1307+
// Create the source file. Note, we disable delayed parsing for the
1308+
// swift expression parser.
1309+
source_file = new (**ast_context) swift::SourceFile(
1310+
*module, source_file_kind, buffer_id,
1311+
swift::SourceFile::ParsingFlags::DisableDelayedBodies);
1312+
addFile(source_file);
1313+
});
13121314
}
13131315
// Swift Modules that rely on shared libraries (not frameworks)
13141316
// don't record the link information in the swiftmodule file, so we

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -614,18 +614,22 @@ void SwiftREPL::CompleteCode(const std::string &current_code,
614614
if (!repl_module) {
615615
swift::ImplicitImportInfo importInfo;
616616
importInfo.StdlibKind = swift::ImplicitStdlibKind::Stdlib;
617+
617618
auto repl_module_or_err = swift_ast->CreateModule(
618-
completion_module_info.path.back().GetString(), importInfo);
619+
completion_module_info.path.back().GetString(), importInfo,
620+
[&](swift::ModuleDecl *repl_module, auto addFile) {
621+
auto bufferID = (*ast)->SourceMgr.addMemBufferCopy("// swift repl\n");
622+
swift::SourceFile *repl_source_file = new (**ast) swift::SourceFile(
623+
*repl_module, swift::SourceFileKind::Main, bufferID);
624+
addFile(repl_source_file);
625+
});
619626
if (!repl_module_or_err) {
620627
llvm::consumeError(repl_module_or_err.takeError());
621628
return;
622629
}
623630
repl_module = &*repl_module_or_err;
624-
auto bufferID = (*ast)->SourceMgr.addMemBufferCopy("// swift repl\n");
625-
swift::SourceFile *repl_source_file = new (**ast)
626-
swift::SourceFile(*repl_module, swift::SourceFileKind::Main, bufferID);
627-
repl_module->addFile(*repl_source_file);
628-
swift::performImportResolution(*repl_source_file);
631+
632+
swift::performImportResolution(repl_module);
629633
m_completion_module_initialized = true;
630634
}
631635
if (repl_module) {

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,8 +1470,7 @@ void SwiftLanguageRuntime::RegisterGlobalError(Target &target, ConstString name,
14701470
module_info.path.push_back(ConstString(module_name));
14711471

14721472
swift::ModuleDecl *module_decl = nullptr;
1473-
auto module_decl_or_err = swift_ast_ctx->CreateModule(module_name,
1474-
/*importInfo*/ {});
1473+
auto module_decl_or_err = swift_ast_ctx->CreateEmptyModule(module_name);
14751474
if (!module_decl_or_err)
14761475
llvm::consumeError(module_decl_or_err.takeError());
14771476
else

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3823,8 +3823,14 @@ swift::ModuleDecl *SwiftASTContext::GetCachedModule(std::string module_name) {
38233823
}
38243824

38253825
llvm::Expected<swift::ModuleDecl &>
3826-
SwiftASTContext::CreateModule(std::string module_name,
3827-
swift::ImplicitImportInfo importInfo) {
3826+
SwiftASTContext::CreateEmptyModule(std::string module_name) {
3827+
return CreateModule(module_name, /*importInfo*/ {},
3828+
/*populateFiles*/ [](auto, auto) {});
3829+
}
3830+
3831+
llvm::Expected<swift::ModuleDecl &> SwiftASTContext::CreateModule(
3832+
std::string module_name, swift::ImplicitImportInfo importInfo,
3833+
swift::ModuleDecl::PopulateFilesFn populateFiles) {
38283834
VALID_OR_RETURN(llvm::createStringError("no context"));
38293835
if (module_name.empty())
38303836
return llvm::createStringError("invalid module name (empty)");
@@ -3838,7 +3844,8 @@ SwiftASTContext::CreateModule(std::string module_name,
38383844
return llvm::createStringError("invalid swift AST (nullptr)");
38393845

38403846
swift::Identifier module_id(ast->getIdentifier(module_name));
3841-
auto *module_decl = swift::ModuleDecl::create(module_id, **ast, importInfo);
3847+
auto *module_decl =
3848+
swift::ModuleDecl::create(module_id, **ast, importInfo, populateFiles);
38423849
if (!module_decl)
38433850
return llvm::createStringError(
38443851
llvm::formatv("failed to create module for \"{0}\"", module_name));
@@ -5118,9 +5125,8 @@ swift::ModuleDecl *SwiftASTContext::GetScratchModule() {
51185125

51195126
if (m_scratch_module == nullptr) {
51205127
ThreadSafeASTContext ast_ctx = GetASTContext();
5121-
m_scratch_module = swift::ModuleDecl::create(
5122-
GetASTContext()->getIdentifier("__lldb_scratch_module"),
5123-
**ast_ctx);
5128+
m_scratch_module = swift::ModuleDecl::createEmpty(
5129+
GetASTContext()->getIdentifier("__lldb_scratch_module"), **ast_ctx);
51245130
}
51255131
return m_scratch_module;
51265132
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,19 @@ class SwiftASTContext : public TypeSystemSwift {
309309
/// \return the ExtraArgs of the ClangImporterOptions.
310310
const std::vector<std::string> &GetClangArguments();
311311

312+
/// Attempt to create an empty Swift module.
313+
llvm::Expected<swift::ModuleDecl &>
314+
CreateEmptyModule(std::string module_name);
315+
312316
/// Attempt to create a Swift module.
313317
///
314318
/// \param importInfo Information about which modules should be implicitly
315319
/// imported by each file of the module.
320+
/// \param populateFiles A function which populates the files for the module.
321+
/// Once called, the module's list of files may not change.
316322
llvm::Expected<swift::ModuleDecl &>
317-
CreateModule(std::string module_name, swift::ImplicitImportInfo importInfo);
323+
CreateModule(std::string module_name, swift::ImplicitImportInfo importInfo,
324+
swift::ModuleDecl::PopulateFilesFn populateFiles);
318325

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

0 commit comments

Comments
 (0)