forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 352
[lldb] Change the representation of Swift enums #10781
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
Merged
adrian-prantl
merged 3 commits into
swiftlang:swift/release/6.2
from
adrian-prantl:fix-enums
Jun 6, 2025
Merged
[lldb] Change the representation of Swift enums #10781
adrian-prantl
merged 3 commits into
swiftlang:swift/release/6.2
from
adrian-prantl:fix-enums
Jun 6, 2025
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
augusto2112
reviewed
Jun 2, 2025
augusto2112
left a comment
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.
Very high level first pass (didn't look too deeply into the code yet).
lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeDynamicTypeResolution.cpp
Outdated
Show resolved
Hide resolved
kastiglione
reviewed
Jun 3, 2025
kastiglione
reviewed
Jun 3, 2025
611335b to
4423a2d
Compare
Author
|
@swift-ci test |
(Payload-carrying) Swift enums are a challenging datastructure to
support in LLDB; this patch makes an attempt to clean up a problem
with the previous implementation, namely the dynamic nature of the
children of an enum, which has, in the past, lead to caching bugs when
displaying the children of enums. The new scheme is as follows:
- The static value of an enum is its discriminator (its case).
- An enum has no static children.
- The synthtic value of an enum is its projected case's payload.
- A synthetic child provider for all Swift enums provides synthetic
children, which are the children of the projected case's payload.
For example:
```
enum E {
case a
case b(Int, (Int, Int))
}
let a : E= .a
let b : E= .b(1, (2, 3))
```
The value of `a` is `.a`.
The value of `b` is `.b`.
The synthtic value of `b` is (1, (2, 3)).
The synthetic child 0 of `b` is 1.
The synthetic child 1 of `b` is (2, 3).
The number of (non-synthetic) children of `b` is 0.
The Swift Optional formatter behaves similarly.
Known Issues:
- SwiftRuntimeTypeVisitor does currently not visit the children of
Objective-C types; this also needs to get fixed, and is surfaced by
the new synthtic child providers in 1 test.
Implementation Notes:
This removes a lot of enum-handling code from SwiftLanguageRuntime;
simplifying the type visitor and dynamic type resolution, adn moves it
into the Enum/Optional synthetic frontends.
This uncovers a couple of bugs in embedded Swift, which are now explicitly surfaced in the testcase.
This mostly makes debugging easier.
Author
|
@swift-ci test |
JDevlieghere
approved these changes
Jun 5, 2025
JDevlieghere
left a comment
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.
🥳
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.
(Payload-carrying) Swift enums are a challenging datastructure to
support in LLDB; this patch makes an attempt to clean up a problem
with the previous implementation, namely the dynamic nature of the
children of an enum, which has, in the past, lead to caching bugs when
displaying the children of enums. The new scheme is as follows:
The static value of an enum is its discriminator (its case).
An enum has no static children.
The synthtic value of an enum is its projected case's payload.
A synthetic child provider for all Swift enums provides synthetic
children, which are the children of the projected case's payload.
For example:
The value of
ais.a.The value of
bis.b.The synthtic value of
bis (1, (2, 3)).The synthetic child 0 of
bis 1.The synthetic child 1 of
bis (2, 3).The number of (non-synthetic) children of
bis 0.The Swift Optional formatter behaves similarly.
Known Issues:
(FIXED!) - There is a bug in upstream LLDB that prevents
ValueObject::GetSyntheticValue to return the synthetic value from a
synthtic frontend. To temporarily work around this problem the
Swift.Optional summary formatter implements its own printing of
children. This is not a permanent solution. I will try to fix the
upstream bug ASAP.
Objective-C types; this also needs to get fixed, and is surfaced by
the new synthtic child providers in 1 test.
Implementation Notes:
This removes a lot of enum-handling code from SwiftLanguageRuntime;
simplifying the type visitor and dynamic type resolution, adn moves it
into the Enum/Optional synthetic frontends.