Skip to content
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

Pretty-printing support for Rust generators #62572

Closed
tmandry opened this issue Jul 10, 2019 · 1 comment · Fixed by #84752
Closed

Pretty-printing support for Rust generators #62572

tmandry opened this issue Jul 10, 2019 · 1 comment · Fixed by #84752
Labels
A-async-await Area: Async & Await A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tmandry
Copy link
Member

tmandry commented Jul 10, 2019

Support printing Rust generators in a way that looks more like enums. Generators (as of #59897) are represented in Rust as variant layouts with some extra fields on the outer layout. These extra fields (which are upvars, captured from the environment of the generator closure) seem to cause printing to become less pretty.

Today printing a Rust generator from rust-gdb looks like this:

$2 = generator_objects::main::generator {__0: 0x7fffffffd204, <<variant>>: {__state: 3, 0: generator_objects::main::generator::Unresumed, 1: generator_objects::main::generator::Returned, 2: generator_objects::main::generator::Panicked, 3: generator_objects::main::generator::Suspend0 {c: 6, d: 7}, 4: generator_objects::main::generator::Suspend1 {c: 6, d: 7}}}

Note that we print the fields of every single variant, even though the discriminant is marked in the DWARF output.

Here's the test which produced the above output. The above excerpt is from the second print in the test. __0 in the output is the upvar for a from the environment (it should be called a instead of __0, but this is a problem in the compiler).

I also opened this bug on GDB; I'm not sure how much we upstream pretty printing support today.

@Mark-Simulacrum Mark-Simulacrum added the A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) label Jul 10, 2019
@Centril Centril added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-enhancement Category: An issue proposing an enhancement or a PR with one. A-async-await Area: Async & Await labels Jul 10, 2019
@nikomatsakis nikomatsakis added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Aug 13, 2019
@nikomatsakis
Copy link
Contributor

Check-in from async-await wg: marking as "deferred", since this is not a blocker for stabilization.

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 2, 2021
Fix debuginfo for generators

First, all fields except the discriminant (including `outer_fields`) should be put into structures inside the variant part, which gives an equivalent layout but offers us much better integration with debuggers.

Second, artificial flags in generator variants should be removed.
 - Literally, variants are not artificial. We have `yield` statements, upvars and inner variables in the source code.
 - Functionally, we don't want debuggers to suppress the variants. It contains the state of the generator, which is useful when debugging. So they shouldn't be marked artificial.
 - Debuggers may use artificial flags to find the active variant. In this case, marking variants artificial will make debuggers not work properly.

Fixes rust-lang#62572.
Fixes rust-lang#79009.

And refer https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Debuginfo.20for.20generators.
@bors bors closed this as completed in 2553053 May 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants