Skip to content

[lldb] Add formatters for Swift.Span #10905

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

Draft
wants to merge 2 commits into
base: swift/release/6.2
Choose a base branch
from

Conversation

kastiglione
Copy link

@kastiglione kastiglione commented Jun 26, 2025

Add synthetic child provider and summary formatter for Swift.Span (and MutableSpan) which was introduced in SE-0447.

The implementation of Span shares enough similarity with UnsafeBufferPointer and UnsafeRawBufferPointer, that the same code was refactored and reused to implement support for Span.

rdar://151411389

@kastiglione kastiglione requested a review from a team as a code owner June 26, 2025 22:56
@kastiglione
Copy link
Author

@swift-ci test

Comment on lines +141 to +183
std::optional<size_t>
SwiftUnsafeType::GetCountValue(llvm::StringRef child_name) {
ValueObjectSP count_value_sp(
m_valobj.GetChildMemberWithName(child_name, true));
if (!count_value_sp) {
LLDB_LOG(GetLog(LLDBLog::DataFormatters),
"{0}: Couldn't find ValueObject child member named '{1}'.",
__FUNCTION__, child_name);
return std::nullopt;
}

ValueObjectSP value_provided_child_sp;

// Implement Swift's 'value-providing synthetic children' workaround.
// Depending on whether the ValueObject type is a primitive or a structure,
// lldb should prioritize the synthetic value children.
// If it has no synthetic children then fallback to non synthetic children.
ValueObjectSP synthetic = count_value_sp->GetSyntheticValue();
if (synthetic)
value_provided_child_sp = synthetic->GetChildAtIndex(0, true);
if (!value_provided_child_sp)
value_provided_child_sp = count_value_sp->GetChildAtIndex(0, true);

// If neither child exists, fail.
if (!value_provided_child_sp) {
LLDB_LOG(GetLog(LLDBLog::DataFormatters),
"{0}: Couldn't extract 'value-providing synthetic children' from "
"ValueObject '{1}'.",
__FUNCTION__, child_name);
return std::nullopt;
}

size_t count = value_provided_child_sp->GetValueAsUnsigned(UINT64_MAX);

if (count == UINT64_MAX) {
LLDB_LOG(GetLog(LLDBLog::DataFormatters),
"{0}: Couldn't get a valid value for ValueObject '{1}'.",
__FUNCTION__, child_name);
return std::nullopt;
}

return count;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an extracted function, not new code.

Comment on lines +185 to +203
CompilerType SwiftUnsafeType::GetArgumentType() {
CompilerType type = m_valobj.GetCompilerType();
if (!type.IsValid()) {
LLDB_LOG(GetLog(LLDBLog::DataFormatters),
"{0}: Couldn't get the compiler type for the '{1}' ValueObject.",
__FUNCTION__, type.GetTypeName());
return {};
}

auto type_system = type.GetTypeSystem().dyn_cast_or_null<TypeSystemSwift>();
if (!type_system) {
LLDB_LOG(GetLog(LLDBLog::DataFormatters),
"{0}: Couldn't get {1} type system.", __FUNCTION__,
type.GetTypeName());
return {};
}

return type_system->GetGenericArgumentType(type.GetOpaqueQualType(), 0);
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an extracted function, not new code.

@kastiglione kastiglione marked this pull request as draft June 26, 2025 23:10
@kastiglione
Copy link
Author

@swift-ci test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants