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

flag to dump proc-macro's generated tokenstream to file for debugging #124860

Open
programmerjake opened this issue May 7, 2024 · 2 comments
Open
Labels
A-proc-macros Area: Procedural macros 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

@programmerjake
Copy link
Member

programmerjake commented May 7, 2024

I think it would be useful for rustc to have flags to dump a proc-macro's generated tokenstream to a file when rustc generates an error or if you choose to always dump the macro's output.

the existing Zunpretty=expanded flag is not suitable because it fails if rustc can't parse the generated tokenstream, it expands all macros in the generated tokenstream instead of showing exactly what the proc-macro generated, and it usually generates a huge amount of output which makes finding the output of any particular proc macro invocation very annoying.

This came up here where the workaround I'm currently using is inspired by iirc https://github.com/drahnr/expander where the proc-macro writes an output file itself and generates include!("path/to/generated/file.rs")

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 7, 2024
@tgross35
Copy link
Contributor

tgross35 commented May 7, 2024

Could unpretty=expanded change to print the token stream even if it is broken? Maybe it could gain some better filtering options so you could only emit a specific file, macro name, or module.

@programmerjake
Copy link
Member Author

Could unpretty=expanded change to print the token stream even if it is broken? Maybe it could gain some better filtering options so you could only emit a specific file, macro name, or module.

If it also had an option to produce the output of a particular macro invocation without further expanding it, I think that would solve the majority of the problem. One important thing that wouldn't solve though is rustc error messages pointing to where in the generated file errors occur.

@jieyouxu jieyouxu added 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. A-proc-macros Area: Procedural macros and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-proc-macros Area: Procedural macros 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

No branches or pull requests

4 participants