Skip to content

Commit e7dfeab

Browse files
committed
[lldb][Swift][NFC] Adapt Swift plugin callables to IterationAction
(cherry picked from commit 6cf2732)
1 parent 8e843ee commit e7dfeab

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -172,24 +172,24 @@ static ModuleSP findRuntime(Process &process, RuntimeKind runtime_kind) {
172172
if (runtime_kind == RuntimeKind::Swift && image &&
173173
IsModuleSwiftRuntime(process, *image)) {
174174
runtime_image = image;
175-
return false;
175+
return IterationAction::Stop;
176176
}
177177
if (runtime_kind == RuntimeKind::ObjC &&
178178
objc_runtime->IsModuleObjCLibrary(image)) {
179179
runtime_image = image;
180-
return false;
180+
return IterationAction::Stop;
181181
}
182-
return true;
182+
return IterationAction::Continue;
183183
});
184184

185185
if (!runtime_image && runtime_kind == RuntimeKind::Swift) {
186186
// Do a more expensive search for a statically linked Swift runtime.
187187
process.GetTarget().GetImages().ForEach([&](const ModuleSP &image) {
188188
if (image && IsStaticSwiftRuntime(*image)) {
189189
runtime_image = image;
190-
return false;
190+
return IterationAction::Stop;
191191
}
192-
return true;
192+
return IterationAction::Continue;
193193
});
194194
}
195195
return runtime_image;
@@ -200,9 +200,9 @@ ModuleSP SwiftLanguageRuntime::FindConcurrencyModule(Process &process) {
200200
process.GetTarget().GetImages().ForEach([&](const ModuleSP &candidate) {
201201
if (candidate && IsModuleSwiftConcurrency(process, *candidate)) {
202202
concurrency_module = candidate;
203-
return false;
203+
return IterationAction::Stop;
204204
}
205-
return true;
205+
return IterationAction::Continue;
206206
});
207207
if (concurrency_module)
208208
return concurrency_module;
@@ -211,9 +211,9 @@ ModuleSP SwiftLanguageRuntime::FindConcurrencyModule(Process &process) {
211211
process.GetTarget().GetImages().ForEach([&](const ModuleSP &candidate) {
212212
if (candidate && IsStaticSwiftConcurrency(*candidate)) {
213213
concurrency_module = candidate;
214-
return false;
214+
return IterationAction::Stop;
215215
}
216-
return true;
216+
return IterationAction::Continue;
217217
});
218218
return concurrency_module;
219219
}
@@ -361,14 +361,15 @@ void SwiftLanguageRuntime::ProcessModulesToAdd() {
361361

362362
// Add all defered modules to reflection context that were added to
363363
// the target since this SwiftLanguageRuntime was created.
364-
modules_to_add_snapshot.ForEach([&](const ModuleSP &module_sp) -> bool {
365-
if (module_sp) {
366-
AddModuleToReflectionContext(module_sp);
367-
progress.Increment(++completion,
368-
module_sp->GetFileSpec().GetFilename().GetString());
369-
}
370-
return true;
371-
});
364+
modules_to_add_snapshot.ForEach(
365+
[&](const ModuleSP &module_sp) -> IterationAction {
366+
if (module_sp) {
367+
AddModuleToReflectionContext(module_sp);
368+
progress.Increment(
369+
++completion, module_sp->GetFileSpec().GetFilename().GetString());
370+
}
371+
return IterationAction::Continue;
372+
});
372373
}
373374

374375
SwiftMetadataCache *SwiftLanguageRuntime::GetSwiftMetadataCache() {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4232,11 +4232,14 @@ void SwiftASTContext::LoadModule(swift::ModuleDecl *swift_module,
42324232
if (!matching_module_list.IsEmpty()) {
42334233
matching_module_list.ForEach(
42344234
[&module_already_loaded, &module_spec,
4235-
&framework_name](const ModuleSP &module_sp) -> bool {
4235+
&framework_name](const ModuleSP &module_sp) -> IterationAction {
42364236
module_already_loaded = module_spec.GetFileSpec().GetPath().find(
42374237
framework_name) != std::string::npos;
4238-
return module_already_loaded ==
4239-
false; // Keep iterating if we didn't find the right module
4238+
// Keep iterating if we didn't find the right module
4239+
if (!module_already_loaded)
4240+
return IterationAction::Continue;
4241+
4242+
return IterationAction::Stop;
42404243
});
42414244
}
42424245
// If we already have this library loaded, don't try and load it again.

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,24 +431,27 @@ TypeSP TypeSystemSwiftTypeRefForExpressions::LookupClangType(
431431
return result;
432432

433433
ModuleSP cur_module = sc.module_sp;
434-
auto lookup = [&](const ModuleSP &m) -> bool {
434+
auto lookup = [&](const ModuleSP &m) -> IterationAction {
435435
// Already visited this.
436436
if (m == cur_module)
437-
return true;
437+
return IterationAction::Continue;
438438

439439
// Don't recursively call into LookupClangTypes() to avoid filling
440440
// hundreds of image caches with negative results.
441441
result = ::LookupClangType(const_cast<Module &>(*m), decl_context,
442442
ignore_modules);
443443
// Cache it in the expression context.
444-
if (result)
444+
if (result) {
445445
m_clang_type_cache.Insert(name.AsCString(), result);
446-
return !result;
446+
return IterationAction::Stop;
447+
}
448+
449+
return IterationAction::Continue;
447450
};
448451

449452
// Visit the current module first as a performance optimization heuristic.
450453
if (cur_module)
451-
if (!lookup(cur_module))
454+
if (lookup(cur_module) == IterationAction::Stop)
452455
return result;
453456

454457
if (TargetSP target_sp = GetTargetWP().lock())

0 commit comments

Comments
 (0)