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

rustdoc: Regression in display of macro_rules! matchers #86208

Closed
camelid opened this issue Jun 11, 2021 · 24 comments · Fixed by #86282
Closed

rustdoc: Regression in display of macro_rules! matchers #86208

camelid opened this issue Jun 11, 2021 · 24 comments · Fixed by #86282
Assignees
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-rustdoc-ui Area: rustdoc UI (generated HTML) C-bug Category: This is a bug. P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Milestone

Comments

@camelid
Copy link
Member

camelid commented Jun 11, 2021

Oddly enough, the two lines (and the areas around them) that show up when I grep for "macro_rules! in rustdoc don't appear to have changed at all in a while, so I'm not sure what caused this regression. Perhaps the span of the matcher changed? I wasn't able to reproduce this locally, even when I tried using a cross-crate re-export with a copy-pasted version of core::todo (modulo replacing $crate:: with ::std::). Also, the bug doesn't appear with, e.g., panic!, but does with compile_error!. So, this seems to be a subtle bug.

$ rg '"macro_rules!' src/librustdoc/
src/librustdoc/clean/mod.rs
2167:                "macro_rules! {} {{\n{}}}",

src/librustdoc/clean/inline.rs
541:                "macro_rules! {} {{\n{}}}",

beta (incorrect)

image

stable (correct)

image

@camelid camelid added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) regression-from-stable-to-beta Performance or correctness regression from stable to beta. C-bug Category: This is a bug. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc I-prioritize Issue: Indicates that prioritization has been requested for this issue. A-rustdoc-ui Area: rustdoc UI (generated HTML) E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Jun 11, 2021
@camelid
Copy link
Member Author

camelid commented Jun 11, 2021

This bug doesn't occur for core::todo! or core::compile_error!, which makes me think it's a bug with cross-crate spans (either in rustc or rustdoc). I think std::panic! rendering normally is further evidence of this, because std::panic! is currently not a re-export of core::panic!.

@camelid
Copy link
Member Author

camelid commented Jun 11, 2021

I wonder if #80339 is related?

@jyn514
Copy link
Member

jyn514 commented Jun 11, 2021

@camelid you can test by bisecting

@jyn514
Copy link
Member

jyn514 commented Jun 12, 2021

That line of code is

.map(|span| { format!(" {} => {{ ... }};\n", span.to_src(cx)) })

which hasn't changed in 2 years. So either span or to_src has changed.

@camelid
Copy link
Member Author

camelid commented Jun 12, 2021

@camelid you can test by bisecting

But I don't have an MCVE to bisect with. Can you bisect std itself?

@jyn514
Copy link
Member

jyn514 commented Jun 12, 2021

@camelid sure, it will just take a while 😅

@camelid
Copy link
Member Author

camelid commented Jun 12, 2021

I meant in terms of getting bisect-rustc to work with rustbuild so we're not also rebuilding rustdoc every time and instead are using CI rustdocs. Unless you're suggesting git bisect? But, yeah, it would probably take a while.

@jyn514
Copy link
Member

jyn514 commented Jun 13, 2021

@camelid you can use a custom script with bisect-rustc, it's a little tricky but it should work.

@camelid
Copy link
Member Author

camelid commented Jun 13, 2021

Ok, since this issue is present on beta but not stable, I think the regression occurred in 61edfd5...8a9fa36 (the merge-bases between master and stable/beta), so that narrows it down a bit.

@camelid
Copy link
Member Author

camelid commented Jun 13, 2021

I started scrolling through git log -S 61edfd591cedff66fca639c02f66984f6271e5a6...8a9fa3682dcf0de095ec308a29a7b19b0e011ef0 and found this commit that looks like it might be related: f94360f

@camelid
Copy link
Member Author

camelid commented Jun 13, 2021

Aha! I came up with a super simple repro:

pub use std::todo;

@camelid camelid removed the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Jun 13, 2021
@camelid
Copy link
Member Author

camelid commented Jun 13, 2021

Unfortunately, this bug seems even weirder than I thought, because the bisection pointed to 2020-03-11 as the regression date, which is bizarre because the bug is not present on stable.

The commit range I got was 3dbade6...1581278.

The command I used was:

$ cargo bisect-rustc --prompt --start=2020-01-01 --end=2021-05-01 -- doc --open

@camelid
Copy link
Member Author

camelid commented Jun 13, 2021

Based on looking through the commit range, these are the two PRs that seem most likely to have caused the regression: #66364 and #69677. #66364 seems especially likely to me, as it changed macro definitions in metadata, which is more likely to cause cross-crate macro issues.

I still don't understand why this issue is not present on stable, given that it regressed more than a year ago.

@jyn514
Copy link
Member

jyn514 commented Jun 13, 2021

@camelid if you build from source with channel = stable, does it still reproduce the bug?

@camelid
Copy link
Member Author

camelid commented Jun 13, 2021

I asked about this regression on Zulip, and Eric Huss gave a very helpful response, explaining that the reason the bisection gave such weird results is because there was a regression in March 2020 that was then fixed in April 2020, but then regressed again recently, in April 2021. Eric was able to determine that the PR that most recently caused the regression was #84233, which I was able to confirm by re-bisecting.

searched nightlies: from nightly-2021-01-01 to nightly-2021-05-01
regressed nightly: nightly-2021-04-30
searched commits: from ca075d2 to 478a07d
regressed commit: 814a560

bisected with cargo-bisect-rustc v0.6.0

Host triple: x86_64-apple-darwin
Reproduce with:

cargo bisect-rustc --prompt --start=2021-01-01 --end=2021-05-01 --with-src -- doc --open 

@camelid camelid removed the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Jun 13, 2021
@camelid
Copy link
Member Author

camelid commented Jun 13, 2021

Just on a hunch, 39648ea seems likely to be the commit that caused the regression. It also explains why I was not able to minimize the regression without using std, since it seems that the regression is in the handling of the rust-src component.

@jyn514
Copy link
Member

jyn514 commented Jun 13, 2021

I think the more interesting question is why rustdoc depends on having the source available, that seems like a bug.

@camelid
Copy link
Member Author

camelid commented Jun 13, 2021

Yeah, I was thinking about that. We should probably switch to pretty-printing the matchers.

@camelid camelid self-assigned this Jun 13, 2021
@camelid
Copy link
Member Author

camelid commented Jun 13, 2021

Assigning priority as discussed in the prioritization working group.

@rustbot label: +P-high -I-prioritize

@rustbot rustbot added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jun 13, 2021
@camelid
Copy link
Member Author

camelid commented Jun 13, 2021

Yeah, I was thinking about that. We should probably switch to pretty-printing the matchers.

I think this change would make sense independently of this bug, for the reason mentioned in #86208 (comment), but the one issue is that it won't fix the underlying regression that this bug is a symptom of.

@jyn514
Copy link
Member

jyn514 commented Jun 13, 2021

@camelid what underlying regression? Nothing in the compiler should depend on if the source of dependencies is available IMO

@camelid
Copy link
Member Author

camelid commented Jun 13, 2021

@camelid what underlying regression? Nothing in the compiler should depend on if the source of dependencies is available IMO

Are there no other places where we use ToSource::to_src (a wrapper around span_to_snippet) in rustdoc?

EDIT: I looked and it seems like everywhere else handles no source gracefully.

@camelid
Copy link
Member Author

camelid commented Jun 13, 2021

I'm currently trying out a fix that switches us to using rustc_ast_pretty.

@camelid
Copy link
Member Author

camelid commented Jun 13, 2021

It's not pretty, but it does work:

image

@camelid camelid added this to the 1.53.0 milestone Jun 14, 2021
@LeSeulArtichaut LeSeulArtichaut added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Jun 22, 2021
camelid added a commit to camelid/rust that referenced this issue Jun 29, 2021
This test does not test the output as well as I would like, but I think
I am limited by htmldocck. I would really just like to strip all the
HTML tags from the output for the sake of the different `@has` checks,
but that doesn't seem to be currently possible.
@bors bors closed this as completed in 09d9b60 Jul 5, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 9, 2022
…uillaumeGomez

rustdoc: Preserve rendering of macro_rules matchers when possible

Fixes rust-lang#92331. This approach restores the behavior prior to rust-lang#86282 **if** the matcher token held by the compiler **and** the matcher token found in the source code are identical TokenTrees. Thus rust-lang#86208 remains fixed, but without regressing formatting for the vast majority of macros which are not macro-generated.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 10, 2022
…uillaumeGomez

rustdoc: Preserve rendering of macro_rules matchers when possible

Fixes rust-lang#92331. This approach restores the behavior prior to rust-lang#86282 **if** the matcher token held by the compiler **and** the matcher token found in the source code are identical TokenTrees. Thus rust-lang#86208 remains fixed, but without regressing formatting for the vast majority of macros which are not macro-generated.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 10, 2022
…uillaumeGomez

rustdoc: Preserve rendering of macro_rules matchers when possible

Fixes rust-lang#92331. This approach restores the behavior prior to rust-lang#86282 **if** the matcher token held by the compiler **and** the matcher token found in the source code are identical TokenTrees. Thus rust-lang#86208 remains fixed, but without regressing formatting for the vast majority of macros which are not macro-generated.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 12, 2022
…uillaumeGomez

rustdoc: Preserve rendering of macro_rules matchers when possible

Fixes rust-lang#92331. This approach restores the behavior prior to rust-lang#86282 **if** the matcher token held by the compiler **and** the matcher token found in the source code are identical TokenTrees. Thus rust-lang#86208 remains fixed, but without regressing formatting for the vast majority of macros which are not macro-generated.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 13, 2022
…uillaumeGomez

rustdoc: Preserve rendering of macro_rules matchers when possible

Fixes rust-lang#92331. This approach restores the behavior prior to rust-lang#86282 **if** the matcher token held by the compiler **and** the matcher token found in the source code are identical TokenTrees. Thus rust-lang#86208 remains fixed, but without regressing formatting for the vast majority of macros which are not macro-generated.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 13, 2022
…uillaumeGomez

rustdoc: Preserve rendering of macro_rules matchers when possible

Fixes rust-lang#92331. This approach restores the behavior prior to rust-lang#86282 **if** the matcher token held by the compiler **and** the matcher token found in the source code are identical TokenTrees. Thus rust-lang#86208 remains fixed, but without regressing formatting for the vast majority of macros which are not macro-generated.
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, ..) A-rustdoc-ui Area: rustdoc UI (generated HTML) C-bug Category: This is a bug. P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-rustdoc Relevant to the rustdoc 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