Skip to content

[lldb][formatter] Add children of Swift Tasks #10057

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

Conversation

kastiglione
Copy link

@kastiglione kastiglione commented Feb 18, 2025

When displaying a Swift Task, include its child tasks.

This adds a children child to the Task synthetic provider. The type of children is a dynamically constructed tuple of N UnsafeCurrentTask, where N is the number of child tasks.

This allows users to see structured concurrency child tasks, in particular async let child tasks, and TaskGroup child tasks.

@kastiglione kastiglione requested a review from a team as a code owner February 18, 2025 22:36
@kastiglione
Copy link
Author

@swift-ci test

mangledTypenameForTasksTuple(tasks.size());
CompilerType tasks_tuple_type =
m_ts->GetTypeFromMangledTypename(ConstString(mangled_typename));
DataExtractor data{tasks.data(), tasks.size() * sizeof(tasks[0]),

Choose a reason for hiding this comment

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

The use of sizeof raises an eyebrow. Wouldn't you want the size of a task on the target here? (For example because of 32-bit pointers on watchOS)

Copy link
Author

Choose a reason for hiding this comment

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

The reason I did this is because data at hand (an lldb defined struct, AsyncTaskInfo), is internal lldb data. It comes from the target, but at this point it's internal data, not target data. Does that sound reasonable to you? It definitely felt like an uncommon scenario as I wrote this.

Choose a reason for hiding this comment

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

Oh, if this is a host data structure then this is of course fine!

CompilerType tasks_tuple_type =
m_ts->GetTypeFromMangledTypename(ConstString(mangled_typename));
DataExtractor data{tasks.data(), tasks.size() * sizeof(tasks[0]),
endian::InlHostByteOrder(), sizeof(void *)};

Choose a reason for hiding this comment

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

Maybe use multiples of the pointer size on the target, since we still need to bake in this knowledge.

Choose a reason for hiding this comment

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

Same comment, may have been my misunderstanding!

structure->addChild(
factory.createNode(Kind::Module, ::swift::STDLIB_NAME), factory);
structure->addChild(
factory.createNode(Kind::Identifier, "UnsafeCurrentTask"), factory);

Choose a reason for hiding this comment

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

In case you didn't already know, we also have

  CompilerType
  CreateTupleType(const std::vector<TupleElement> &elements);

in TypeSystemSwift.

Copy link
Author

Choose a reason for hiding this comment

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

I didn't, thanks.

Copy link
Author

Choose a reason for hiding this comment

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

hmm, that interface isn't a match for this use case. I don't have a CompilerType instance for the element types. I could create one, but is it worth it to mangle the element type only for CreateTupleType to demangle it?

Choose a reason for hiding this comment

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

Probably not.

Copy link

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

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

This is great! Just a couple questions inside.

@kastiglione
Copy link
Author

@swift-ci test

@kastiglione
Copy link
Author

@swift-ci test macOS

@kastiglione kastiglione merged commit 0e7ec03 into stable/20240723 Feb 23, 2025
3 checks passed
@kastiglione kastiglione deleted the dl/lldb-formatter-Add-children-of-Swift-Tasks branch February 23, 2025 16:51
kastiglione added a commit that referenced this pull request Mar 5, 2025
When displaying a Swift `Task`, include its child tasks.

This adds a `children` child to the `Task` synthetic provider. The type of `children` is a dynamically constructed tuple of N `UnsafeCurrentTask`, where N is the number of child tasks.

This allows users to see structured concurrency child tasks, in particular `async let` child tasks, and `TaskGroup` child tasks.
(cherry-picked from commit 0e7ec03)
kastiglione added a commit that referenced this pull request Mar 5, 2025
When displaying a Swift `Task`, include its child tasks.

This adds a `children` child to the `Task` synthetic provider. The type of `children` is a dynamically constructed tuple of N `UnsafeCurrentTask`, where N is the number of child tasks.

This allows users to see structured concurrency child tasks, in particular `async let` child tasks, and `TaskGroup` child tasks.
(cherry-picked from commit 0e7ec03)
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