Skip to content

Commit 38484e7

Browse files
committed
Refactor DeserializeAllCompilerFlags to take an array of buffers (NFC)
1 parent 993b2f7 commit 38484e7

File tree

1 file changed

+54
-33
lines changed

1 file changed

+54
-33
lines changed

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

Lines changed: 54 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ static void printASTValidationError(
10861086
llvm::raw_ostream &errs,
10871087
const swift::serialization::ValidationInfo &ast_info,
10881088
const swift::serialization::ExtendedValidationInfo &ext_ast_info,
1089-
Module &module, StringRef module_buf, bool invalid_name,
1089+
StringRef module_name, StringRef module_buf, bool invalid_name,
10901090
bool invalid_size) {
10911091
const char *error = getImportFailureString(ast_info.status);
10921092
errs << "AST validation error";
@@ -1111,9 +1111,9 @@ static void printASTValidationError(
11111111
- SDK path: {7}
11121112
- Clang Importer Options:
11131113
)",
1114-
ast_info.name, module.GetSpecificationDescription(), error,
1115-
ast_info.targetTriple, ast_info.shortVersion, ast_info.bytes,
1116-
module_buf.size(), ext_ast_info.getSDKPath());
1114+
ast_info.name, module_name, error, ast_info.targetTriple,
1115+
ast_info.shortVersion, ast_info.bytes, module_buf.size(),
1116+
ext_ast_info.getSDKPath());
11171117
for (StringRef ExtraOpt : ext_ast_info.getExtraClangImporterOptions())
11181118
LLDB_LOG(log, " -- {0}", ExtraOpt);
11191119
}
@@ -1171,21 +1171,16 @@ static std::string GetPluginServerForSDK(llvm::StringRef sdk_path) {
11711171
/// invocation with the concatenated search paths from the blobs.
11721172
/// \returns true if an error was encountered.
11731173
static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
1174-
Module &module,
1174+
llvm::StringRef module_name,
1175+
llvm::ArrayRef<StringRef> buffers,
1176+
const PathMappingList &path_map,
11751177
bool discover_implicit_search_paths,
11761178
const std::string &m_description,
11771179
llvm::raw_ostream &error,
11781180
bool &got_serialized_options,
11791181
bool &found_swift_modules) {
11801182
bool found_validation_errors = false;
11811183
got_serialized_options = false;
1182-
auto ast_file_datas = module.GetASTData(eLanguageTypeSwift);
1183-
LOG_PRINTF(GetLog(LLDBLog::Types), "Found %d AST file data entries.",
1184-
(int)ast_file_datas.size());
1185-
1186-
// If no N_AST symbols exist, this is not an error.
1187-
if (ast_file_datas.empty())
1188-
return false;
11891184

11901185
auto &search_path_options = invocation.getSearchPathOptions();
11911186
auto get_override_server = [&](llvm::StringRef plugin_path) -> std::string {
@@ -1258,9 +1253,7 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
12581253

12591254
// An AST section consists of one or more AST modules, optionally
12601255
// with headers. Iterate over all AST modules.
1261-
for (auto ast_file_data_sp : ast_file_datas) {
1262-
llvm::StringRef buf((const char *)ast_file_data_sp->GetBytes(),
1263-
ast_file_data_sp->GetByteSize());
1256+
for (auto buf : buffers) {
12641257
swift::serialization::ValidationInfo info;
12651258
for (; !buf.empty(); buf = buf.substr(info.bytes)) {
12661259
llvm::SmallVector<swift::serialization::SearchPath> searchPaths;
@@ -1275,8 +1268,8 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
12751268
if (invalid_ast || invalid_size || invalid_name) {
12761269
// Validation errors are diagnosed, but not fatal for the context.
12771270
found_validation_errors = true;
1278-
printASTValidationError(error, info, extended_validation_info, module,
1279-
buf, invalid_name, invalid_size);
1271+
printASTValidationError(error, info, extended_validation_info,
1272+
module_name, buf, invalid_name, invalid_size);
12801273
// If there's a size error, quit the loop early, otherwise try the next.
12811274
if (invalid_size)
12821275
break;
@@ -1288,8 +1281,7 @@ static bool DeserializeAllCompilerFlags(swift::CompilerInvocation &invocation,
12881281

12891282
auto remap = [&](const std::string &path) {
12901283
ConstString remapped;
1291-
if (module.GetSourceMappingList().RemapPath(ConstString(path),
1292-
remapped))
1284+
if (path_map.RemapPath(ConstString(path), remapped))
12931285
return remapped.GetStringRef().str();
12941286
return path;
12951287
};
@@ -1881,13 +1873,28 @@ SwiftASTContext::CreateInstance(lldb::LanguageType language, Module &module,
18811873
llvm::raw_svector_ostream errs(error);
18821874
// Implicit search paths will be discoverd by ValidateSecionModules().
18831875
bool discover_implicit_search_paths = false;
1884-
if (DeserializeAllCompilerFlags(swift_ast_sp->GetCompilerInvocation(),
1885-
module, discover_implicit_search_paths,
1886-
m_description, errs, got_serialized_options,
1887-
found_swift_modules)) {
1888-
// Validation errors are not fatal for the context.
1889-
swift_ast_sp->AddDiagnostic(eDiagnosticSeverityError, errs.str());
1890-
}
1876+
1877+
auto ast_file_datas = module.GetASTData(eLanguageTypeSwift);
1878+
std::string module_name = module.GetSpecificationDescription();
1879+
LOG_PRINTF(GetLog(LLDBLog::Types), "Found %d AST file data entries in %s.",
1880+
(int)ast_file_datas.size(), module_name.c_str());
1881+
std::vector<llvm::StringRef> buffers;
1882+
for (auto &data : ast_file_datas)
1883+
if (data)
1884+
buffers.push_back(
1885+
StringRef((const char *)data->GetBytes(), data->GetByteSize()));
1886+
1887+
// If no N_AST symbols exist, this is not an error.
1888+
if (!buffers.empty())
1889+
if (DeserializeAllCompilerFlags(
1890+
swift_ast_sp->GetCompilerInvocation(),
1891+
module_name, buffers,
1892+
module.GetSourceMappingList(), discover_implicit_search_paths,
1893+
m_description, errs, got_serialized_options,
1894+
found_swift_modules)) {
1895+
// Validation errors are not fatal for the context.
1896+
swift_ast_sp->AddDiagnostic(eDiagnosticSeverityError, errs.str());
1897+
}
18911898

18921899
llvm::StringRef serialized_triple =
18931900
swift_ast_sp->GetCompilerInvocation().getTargetTriple();
@@ -2194,13 +2201,27 @@ static void ProcessModule(
21942201
llvm::SmallString<0> error;
21952202
llvm::raw_svector_ostream errs(error);
21962203
swift::CompilerInvocation invocation;
2197-
if (DeserializeAllCompilerFlags(
2198-
invocation, *module_sp, discover_implicit_search_paths, m_description,
2199-
errs, got_serialized_options, found_swift_modules)) {
2200-
// TODO: After removing DeserializeAllCompilerFlags from
2201-
// CreateInstance(per-Module), errs will need to be
2202-
// collected here and surfaced.
2203-
}
2204+
2205+
auto ast_file_datas = module_sp->GetASTData(eLanguageTypeSwift);
2206+
std::string module_name = module_sp->GetSpecificationDescription();
2207+
LOG_PRINTF(GetLog(LLDBLog::Types), "Found %d AST file data entries in %s.",
2208+
(int)ast_file_datas.size(), module_name.c_str());
2209+
std::vector<llvm::StringRef> buffers;
2210+
for (auto &data : ast_file_datas)
2211+
if (data)
2212+
buffers.push_back(
2213+
StringRef((const char *)data->GetBytes(), data->GetByteSize()));
2214+
2215+
// If no N_AST symbols exist, this is not an error.
2216+
if (!buffers.empty())
2217+
if (DeserializeAllCompilerFlags(
2218+
invocation, module_name, buffers, module_sp->GetSourceMappingList(),
2219+
discover_implicit_search_paths, m_description, errs,
2220+
got_serialized_options, found_swift_modules)) {
2221+
// TODO: After removing DeserializeAllCompilerFlags from
2222+
// CreateInstance(per-Module), errs will need to be
2223+
// collected here and surfaced.
2224+
}
22042225

22052226
// Copy the interesting deserialized flags to the out parameters.
22062227
const auto &opts = invocation.getSearchPathOptions();

0 commit comments

Comments
 (0)