forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 341
[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
kastiglione
wants to merge
2
commits into
swift/release/6.2
Choose a base branch
from
dl/lldb-Add-formatters-for-Swift.Span
base: swift/release/6.2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
[lldb] Add formatters for Swift.Span #10905
kastiglione
wants to merge
2
commits into
swift/release/6.2
from
dl/lldb-Add-formatters-for-Swift.Span
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@swift-ci test |
kastiglione
commented
Jun 26, 2025
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; | ||
} |
There was a problem hiding this comment.
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
commented
Jun 26, 2025
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); | ||
} |
There was a problem hiding this comment.
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.
@swift-ci test |
adrian-prantl
approved these changes
Jun 27, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add synthetic child provider and summary formatter for
Swift.Span
(andMutableSpan
) which was introduced in SE-0447.The implementation of
Span
shares enough similarity withUnsafeBufferPointer
andUnsafeRawBufferPointer
, that the same code was refactored and reused to implement support forSpan
.rdar://151411389