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

Subtle change in how ty fragments get stringified #128992

Closed
workingjubilee opened this issue Aug 11, 2024 · 10 comments
Closed

Subtle change in how ty fragments get stringified #128992

workingjubilee opened this issue Aug 11, 2024 · 10 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-discussion Category: Discussion or questions that doesn't represent real issues. regression-from-stable-to-beta Performance or correctness regression from stable to beta. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@workingjubilee
Copy link
Member

workingjubilee commented Aug 11, 2024

Something in lexing, parsing, or even stringification or pretty-printing is now causing code that previously yielded strings like "Component1" to serde, based on the type name, to now emit strings like " Component1". This has been extracted from #128899 because many of the regressions there proved to be unrelated to each other, and it was hard to triage out what the "real" problem was. We have and most of them depended on unstable library details, but the bbarker/bevy_serde_macros case was distinct.

See @Nemo157's comment:

Equality doesn't care about which order you check the keys in, the debug output is different but that shouldn't affect the comparison result. There seem to be extra spaces in the keys on one side, which I assume means the test itself is broken. EDIT: looking at it a little more, seems to be related to not accounting for whitespace in stringify! of ty fragments, so tests :: Component1 gets split at the :: and given the name Component1 instead of the expected Component1, maybe #125174 related.

Originally posted by @Nemo157 in #128899 (comment)

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 11, 2024
@Nemo157
Copy link
Member

Nemo157 commented Aug 11, 2024

Minimal example (playground):

macro_rules! test { ($t:ty) => { dbg!(stringify!($t)); } }
macro_rules! via_callback { () => { test!(foo::Bar); } }
fn main() { via_callback!(); }

on stable:

[src/main.rs:3:13] stringify!(foo::Bar) = "foo::Bar"

on beta and nightly:

[src/main.rs:3:13] stringify! (foo :: Bar) = "foo :: Bar"

@workingjubilee
Copy link
Member Author

Thank you very much for that repro, @Nemo157!

@workingjubilee workingjubilee added the regression-from-stable-to-beta Performance or correctness regression from stable to beta. label Aug 11, 2024
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Aug 11, 2024
@workingjubilee workingjubilee added the S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue label Aug 11, 2024
@compiler-errors
Copy link
Member

This regressed in #125174

@tgross35
Copy link
Contributor

Cc @nnethercote from the above

@nnethercote
Copy link
Contributor

Minimal example (playground):

macro_rules! test { ($t:ty) => { dbg!(stringify!($t)); } }
macro_rules! via_callback { () => { test!(foo::Bar); } }
fn main() { via_callback!(); }

on stable:

[src/main.rs:3:13] stringify!(foo::Bar) = "foo::Bar"

on beta and nightly:

[src/main.rs:3:13] stringify! (foo :: Bar) = "foo :: Bar"

Things like that aren't surprising. #125174 did change whitespace production in pretty printing output, the diff in the PR identifies quit a few other cases where output changed. These changes are valid.

  • The docs for stringify! say "Note that the expanded results of the input tokens may change in the future. You should be careful if you rely on the output."
  • Relatedly, the docs for impl Display for TokenStream say "Note: the exact form of the output is subject to change, e.g. there might be changes in the whitespace used between tokens. Therefore, you should not do any kind of simple substring matching on the output string (as produced by to_string) to implement a proc macro, because that matching might stop working if such changes happen. Instead, you should work at the TokenTree level, e.g. matching against TokenTree::Ident, TokenTree::Punct, or TokenTree::Literal."
  • Of course people don't always follow that advice, so compilation failure with "cargo check --tests" for espidf #125714 did a crater run and found very small amounts of breakage.

My initial guess is that somebody has recently written a new proc macro that uses impl Display for TokenStream and doesn't account for possible whitespace changes. And that this was written since #125174, which is why it didn't show up in the crater run for that PR.

@nnethercote
Copy link
Contributor

We have and most of them depended on unstable library details, but the bbarker/bevy_serde_macros case was distinct.

I overlooked this sentence before my earlier reply. I agree that, of the failures in #128899, bbarker/bevy_serde is probably caused by the changes in #125174.

@workingjubilee
Copy link
Member Author

@nnethercote Those lines date to November 25th, 2023, and your PR landed June 11, 2024. While it is technically possible to falsify git histories, I think that the real reason that your PR didn't reveal this in crater is that the "craterbot check" and "craterbot build-and-test" commands are non-identical, and beta crater runs use the build-and-test mode.

@nnethercote
Copy link
Contributor

Thanks for the info! I think the proper fix here needs to be on the bevy_serde_macros side, given that it was relying on behaviour that is subject to change.

@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-discussion Category: Discussion or questions that doesn't represent real issues. labels Aug 13, 2024
@saethlin saethlin added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 21, 2024
@apiraino
Copy link
Contributor

apiraino commented Oct 7, 2024

Hope it's fine to this as WONTFIX (as per prev. comment)

@apiraino apiraino closed this as not planned Won't fix, can't repro, duplicate, stale Oct 7, 2024
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-discussion Category: Discussion or questions that doesn't represent real issues. regression-from-stable-to-beta Performance or correctness regression from stable to beta. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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

9 participants