diff --git a/lldb/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp b/lldb/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp index c96d58a6b4f4b..f52a663882d1d 100644 --- a/lldb/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp +++ b/lldb/source/Plugins/ExpressionParser/Swift/SwiftASTManipulator.cpp @@ -540,7 +540,7 @@ bool SwiftASTManipulator::RewriteResult() { // First step, walk the function body converting returns to assignments to // temp variables + return: - for (swift::Decl *decl : m_source_file.Decls) { + for (swift::Decl *decl : m_source_file.getTopLevelDecls()) { if (auto top_level_code_decl = llvm::dyn_cast(decl)) { return_finder.SetDeclContext(top_level_code_decl); @@ -551,8 +551,8 @@ bool SwiftASTManipulator::RewriteResult() { // Second step, fetch the last expression, and if it is non-null, set it to // a temp result as well: - if (!m_source_file.Decls.empty()) { - swift::Decl *last_decl = *(m_source_file.Decls.end() - 1); + if (!m_source_file.getTopLevelDecls().empty()) { + swift::Decl *last_decl = *(m_source_file.getTopLevelDecls().end() - 1); if (auto last_top_level_code_decl = llvm::dyn_cast(last_decl)) { @@ -754,7 +754,7 @@ void SwiftASTManipulator::FindVariableDeclarations( }; if (m_repl) { - for (swift::Decl *decl : m_source_file.Decls) { + for (swift::Decl *decl : m_source_file.getTopLevelDecls()) { if (swift::VarDecl *var_decl = llvm::dyn_cast(decl)) { if (!var_decl->getName().str().startswith("$")) { register_one_var(var_decl); @@ -797,7 +797,7 @@ void SwiftASTManipulator::FindNonVariableDeclarations( if (!m_repl) return; // we don't do this for non-REPL expressions... yet - for (swift::Decl *decl : m_source_file.Decls) { + for (swift::Decl *decl : m_source_file.getTopLevelDecls()) { if (swift::ValueDecl *value_decl = llvm::dyn_cast(decl)) { if (!llvm::isa(value_decl) && value_decl->hasName()) { non_variables.push_back(value_decl); @@ -1125,9 +1125,13 @@ bool SwiftASTManipulator::AddExternalVariables( redirected_var_decl->setImplicit(true); - m_source_file.Decls.insert(m_source_file.Decls.begin(), top_level_code); - m_source_file.Decls.insert(m_source_file.Decls.begin(), - redirected_var_decl); + // FIXME: This should use SourceFile::addTopLevelDecl, but if these decls + // are not inserted at the beginning of the source file then + // SwiftREPL/FoundationTypes.test fails. + // + // See rdar://58355191 + m_source_file.prependTopLevelDecl(top_level_code); + m_source_file.prependTopLevelDecl(redirected_var_decl); variable.m_decl = redirected_var_decl; @@ -1402,7 +1406,7 @@ swift::ValueDecl *SwiftASTManipulator::MakeGlobalTypealias( if (make_private) { type_alias_decl->overwriteAccess(swift::AccessLevel::Private); } - m_source_file.Decls.push_back(type_alias_decl); + m_source_file.addTopLevelDecl(type_alias_decl); } return type_alias_decl;