8000 [lldb][swift] Fix GetParentIfClosure for Struct/Enum constructors by felipepiovezan · Pull Request #10922 · swiftlang/llvm-project · GitHub
[go: up one dir, main page]

Skip to content

[lldb][swift] Fix GetParentIfClosure for Struct/Enum constructors #10922

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

Open
wants to merge 3 commits into
base: swift/release/6.2
Choose a base branch
from

Conversation

felipepiovezan
Copy link
@felipepiovezan felipepiovezan commented Jun 27, 2025
There are two possible variants of constructors: allocating (Kind::Allocator)
and initializing (Kind::Constructor). When mangling a closure, the "context"
is arbitrarily chosen to be the initializing variant.
As such, we need to check both when looking for the parent of a closure.
If both exist, `Kind::Constructor` is the one containing user code, so
it is always checked first.

rdar://154309468

We had a `class` called `MY_STRUCT`.
There are two possible variants of constructors: allocating (Kind::Allocator)
and initializing (Kind::Constructor). When mangling a closure, the "context"
is arbitrarily chosen to be the initializing variant.
As such, we need to check both when looking for the parent of a closure.
If both exist, `Kind::Constructor` is the one containing user code, so
it is always checked first.

rdar://154309468
@felipepiovezan felipepiovezan requested a review from a team as a code owner June 27, 2025 21:04
@felipepiovezan
Copy link
Author

@swift-ci test please

return !sc_list.IsEmpty();
}

// There are two possible variants of constructors: allocating (Kind::Allocator)

Choose a reason for hiding this comment

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

Suggested change
// There are two possible variants of constructors: allocating (Kind::Allocator)
/// There are two possible variants of constructors: allocating (Kind::Allocator)

// As per swift/lib/Demangling/Demangler.cpp, Kind::Constructor is
// expected to end in `c` and `Kind::Allocator` to end in `C`. This is a
// cheap way to avoid recreating the mangled tree from scratch.
if (ctor_kind_mangled_name.back() == 'c') {

Choose a reason for hiding this comment

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

We already do so many demangle operations when resolving types that I would rather demangle again here rather than hardcode details of the mangling scheme.

Copy link
Author
@felipepiovezan felipepiovezan Jun 27, 2025

Choose a reason for hiding this comment

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

It's not so much about demangling again, it's about reconstructing the entire demangle tree.
There is no "node.setKind", we are forced to rebuild everything, and I don't think there are any convenient APIs today to do this

init(input: [Int]) {
let find_me = "hello"
let _ = input.map {
return $0 // break_ctor_enum

Choose a reason for hiding this comment

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

I would write this as

print("break_ctor_enum")
return $0 

for more breakpoint stability

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
0