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: when merging target features, keep the highest stability #137632

Merged
merged 4 commits into from
Mar 3, 2025

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Feb 25, 2025

This addresses #137366. (Not closing since we might consider a backport.)

rustdoc wants to pretend that it runs for all targets at once and has all target features, so tcx.rust_target_features() will actually be all the target features. For target features that exist on multiple targets, the stability info for one of the targets will be picked (first or last in the list, I guess). All the code consuming that query has to be aware that the data is basically nonsense when running in rustdoc, but the logic checking for unstable or forbidden #[target_feature] attributes was not aware of that.

This PR makes the tcx.rust_target_features() info in rustdoc slightly less nonsensical (and decidedly less random) by having the "most stable" target feature take precedent. That deals with #137366 (a conflict between a stable and a "forbidden" target feature of the same name for different targets), and also deals with the situation (that we did not seem to have yet) of a conflict between a stable and an unstable target feature of the same name. Note that if there are two unstable target features of the same name, rustdoc might still require the "wrong" nightly feature to be enabled -- but this can only possibly affect unstable code so I guess we can wait until that actually happens, and then someone will have to rewrite this entire thing to be less hacky.

@rustbot
Copy link
Collaborator

rustbot commented Feb 25, 2025

r? @workingjubilee

rustbot has assigned @workingjubilee.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 25, 2025
@RalfJung
Copy link
Member Author

Cc @rust-lang/rustdoc

@RalfJung
Copy link
Member Author

I haven't added a test as I am not sure how to build one... is it even possible to have a no_core rustdoc tests where we could set --target to an ARM target to check this?

@workingjubilee
Copy link
Member

😵‍💫 does rustdoc even respond to things like #![no_core]?

@workingjubilee
Copy link
Member

I suppose it must or core wouldn't work but I'm not feeling entirely sure right now...

@RalfJung
Copy link
Member Author

Given this is fixing a stable-to-stable regression I feel it's okay to land this without a test... though if a rustdoc person has an idea for how to test this that would of course be great. :)

@GuillaumeGomez
Copy link
Member

I'm not even sure to understand what needs to be checked in rustdoc. From reading the issue, what I see is that it failed compilation. What do you want to check in rustdoc?

@RalfJung
Copy link
Member Author

RalfJung commented Feb 28, 2025

It fails compilation only in rustdoc and only on ARM-32 targets. So we'd need a test that checks that some code builds fine in rustdoc on ARM-32. Ideally this test can be run on all hosts, which we usually do with #![no_core] tests that don't need a sysroot and thus can easily be cross-compiled, so we can just set --target <whatever>.

@GuillaumeGomez
Copy link
Member

Do we have an equivalent test for rustc? If so you can write the same one for rustdoc.

@RalfJung
Copy link
Member Author

RalfJung commented Feb 28, 2025

The rustc test would be something like

//@ compile-flags: --target armv7-unknown-linux-gnueabihf

#![crate_type = "lib"]
#![feature(no_core, lang_items)]
#![no_core]

#[lang = "sized"]
pub trait Sized {}

#[target_feature(enable = "neon,v7,aes")]
pub fn fun() {}

So do I just dump such a file into tests/rustdoc?

@GuillaumeGomez
Copy link
Member

In tests/rustdoc-ui with //@ check-pass but otherwise yes. :)

@fmease

This comment has been minimized.

@RalfJung
Copy link
Member Author

Hm that does not seem to do the right thing, the test passes even without my PR.

@RalfJung
Copy link
Member Author

Okay strange, of the two examples given in #137366, only one reproduces this way. 🤷 I guess one confirmed test is enough. ;)

@RalfJung RalfJung force-pushed the rustdoc-target-features branch from b072867 to eff59b8 Compare February 28, 2025 16:02
@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the rustdoc-target-features branch from eff59b8 to 6b63c57 Compare February 28, 2025 16:15
@RalfJung
Copy link
Member Author

Ah, right, the neon target feature is no longer "forbidden", we handle that via the ABI instead and that... I have no idea what that does under rustdoc, probably something nonsensical, but at least it does not error. ;)

The last commit disables this check in rustdoc. It also adds a test.

@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the rustdoc-target-features branch from 6b63c57 to 63088e3 Compare February 28, 2025 16:31
Comment on lines +93 to +94
if !tcx.sess.opts.actually_rustdoc {
if abi_feature_constraints.incompatible.contains(&name.as_str()) {
Copy link
Member

Choose a reason for hiding this comment

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

isn't this just &&?

Copy link
Member Author

@RalfJung RalfJung Mar 1, 2025

Choose a reason for hiding this comment

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

name is a Symbol. So &&name does not work, no.

Copy link
Member

Choose a reason for hiding this comment

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

I was commenting on both lines because I meant that this is && the control flow operator:

if x {
    if y {
    };
};

if x && y {
};

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, that's what you meant.^^

Yeah you are right.

Copy link
Member Author

Choose a reason for hiding this comment

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

Now it's already rolled up so I'll rather not push to this PR.

@@ -0,0 +1,28 @@
//! This is a regression test for <https://github.com/rust-lang/rust/issues/137366>, ensuring
//! that we can use the `neon` target feature on ARM-32 targets in rustdoc despite there
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
//! that we can use the `neon` target feature on ARM-32 targets in rustdoc despite there
//! that we can use the `neon` target feature on ARM32 targets in rustdoc despite there

Copy link
Member

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

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

r=me with nits addressed

@RalfJung RalfJung added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 1, 2025
@RalfJung
Copy link
Member Author

RalfJung commented Mar 1, 2025

Nominating for backport as #137366 is a stable-to-stable regression.

@RalfJung RalfJung added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 1, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 1, 2025
…r=workingjubilee

rustdoc: when merging target features, keep the highest stability

This addresses rust-lang#137366. (Not closing since we might consider a backport.)

rustdoc wants to pretend that it runs for all targets at once and has all target features, so `tcx.rust_target_features()` will actually be all the target features. For target features that exist on multiple targets, the stability info for one of the targets will be picked (first or last in the list, I guess). All the code consuming that query has to be aware that the data is basically nonsense when running in rustdoc, but the logic checking for unstable or forbidden `#[target_feature]` attributes was not aware of that.

This PR makes the  `tcx.rust_target_features()` info in rustdoc slightly less nonsensical (and decidedly less random) by having the "most stable" target feature take precedent. That deals with rust-lang#137366 (a conflict between a stable and a "forbidden" target feature of the same name for different targets), and also deals with the situation (that we did not seem to have yet) of a conflict between a stable and an unstable target feature of the same name. Note that if there are two unstable target features of the same name, rustdoc might still require the "wrong" nightly feature to be enabled -- but this can only possibly affect unstable code so I guess we can wait until that actually happens, and then someone will have to rewrite this entire thing to be less hacky.
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 2, 2025
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#136865 (Perform deeper compiletest path normalization for `$TEST_BUILD_DIR` to account for compare-mode/debugger cases, and normalize long type file filename hashes)
 - rust-lang#136922 (Pattern types: Avoid having to handle an Option for range ends in the type system or the HIR)
 - rust-lang#137081 (change config.toml to bootstrap.toml)
 - rust-lang#137103 ({json|html}docck: catch and error on deprecated syntax)
 - rust-lang#137632 (rustdoc: when merging target features, keep the highest stability)
 - rust-lang#137684 (Add rustdoc support for `--emit=dep-info[=path]`)
 - rust-lang#137794 (make qnx pass a test)
 - rust-lang#137801 (tests: Unignore target modifier tests on all platforms)
 - rust-lang#137826 (test(codegen): add looping_over_ne_bytes test for rust-lang#133528)

Failed merges:

 - rust-lang#137147 (Add exclude to config.toml)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 2, 2025
…r=workingjubilee

rustdoc: when merging target features, keep the highest stability

This addresses rust-lang#137366. (Not closing since we might consider a backport.)

rustdoc wants to pretend that it runs for all targets at once and has all target features, so `tcx.rust_target_features()` will actually be all the target features. For target features that exist on multiple targets, the stability info for one of the targets will be picked (first or last in the list, I guess). All the code consuming that query has to be aware that the data is basically nonsense when running in rustdoc, but the logic checking for unstable or forbidden `#[target_feature]` attributes was not aware of that.

This PR makes the  `tcx.rust_target_features()` info in rustdoc slightly less nonsensical (and decidedly less random) by having the "most stable" target feature take precedent. That deals with rust-lang#137366 (a conflict between a stable and a "forbidden" target feature of the same name for different targets), and also deals with the situation (that we did not seem to have yet) of a conflict between a stable and an unstable target feature of the same name. Note that if there are two unstable target features of the same name, rustdoc might still require the "wrong" nightly feature to be enabled -- but this can only possibly affect unstable code so I guess we can wait until that actually happens, and then someone will have to rewrite this entire thing to be less hacky.
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 2, 2025
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#136865 (Perform deeper compiletest path normalization for `$TEST_BUILD_DIR` to account for compare-mode/debugger cases, and normalize long type file filename hashes)
 - rust-lang#137081 (change config.toml to bootstrap.toml)
 - rust-lang#137103 ({json|html}docck: catch and error on deprecated syntax)
 - rust-lang#137632 (rustdoc: when merging target features, keep the highest stability)
 - rust-lang#137684 (Add rustdoc support for `--emit=dep-info[=path]`)
 - rust-lang#137794 (make qnx pass a test)
 - rust-lang#137801 (tests: Unignore target modifier tests on all platforms)
 - rust-lang#137826 (test(codegen): add looping_over_ne_bytes test for rust-lang#133528)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 2, 2025
…r=workingjubilee

rustdoc: when merging target features, keep the highest stability

This addresses rust-lang#137366. (Not closing since we might consider a backport.)

rustdoc wants to pretend that it runs for all targets at once and has all target features, so `tcx.rust_target_features()` will actually be all the target features. For target features that exist on multiple targets, the stability info for one of the targets will be picked (first or last in the list, I guess). All the code consuming that query has to be aware that the data is basically nonsense when running in rustdoc, but the logic checking for unstable or forbidden `#[target_feature]` attributes was not aware of that.

This PR makes the  `tcx.rust_target_features()` info in rustdoc slightly less nonsensical (and decidedly less random) by having the "most stable" target feature take precedent. That deals with rust-lang#137366 (a conflict between a stable and a "forbidden" target feature of the same name for different targets), and also deals with the situation (that we did not seem to have yet) of a conflict between a stable and an unstable target feature of the same name. Note that if there are two unstable target features of the same name, rustdoc might still require the "wrong" nightly feature to be enabled -- but this can only possibly affect unstable code so I guess we can wait until that actually happens, and then someone will have to rewrite this entire thing to be less hacky.
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 3, 2025
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#136865 (Perform deeper compiletest path normalization for `$TEST_BUILD_DIR` to account for compare-mode/debugger cases, and normalize long type file filename hashes)
 - rust-lang#137103 ({json|html}docck: catch and error on deprecated syntax)
 - rust-lang#137632 (rustdoc: when merging target features, keep the highest stability)
 - rust-lang#137684 (Add rustdoc support for `--emit=dep-info[=path]`)
 - rust-lang#137794 (make qnx pass a test)
 - rust-lang#137801 (tests: Unignore target modifier tests on all platforms)
 - rust-lang#137826 (test(codegen): add looping_over_ne_bytes test for rust-lang#133528)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 3, 2025
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#137103 ({json|html}docck: catch and error on deprecated syntax)
 - rust-lang#137632 (rustdoc: when merging target features, keep the highest stability)
 - rust-lang#137684 (Add rustdoc support for `--emit=dep-info[=path]`)
 - rust-lang#137794 (make qnx pass a test)
 - rust-lang#137801 (tests: Unignore target modifier tests on all platforms)
 - rust-lang#137826 (test(codegen): add looping_over_ne_bytes test for rust-lang#133528)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 3, 2025
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#137103 ({json|html}docck: catch and error on deprecated syntax)
 - rust-lang#137632 (rustdoc: when merging target features, keep the highest stability)
 - rust-lang#137684 (Add rustdoc support for `--emit=dep-info[=path]`)
 - rust-lang#137794 (make qnx pass a test)
 - rust-lang#137801 (tests: Unignore target modifier tests on all platforms)
 - rust-lang#137826 (test(codegen): add looping_over_ne_bytes test for rust-lang#133528)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 3, 2025
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#137103 ({json|html}docck: catch and error on deprecated syntax)
 - rust-lang#137632 (rustdoc: when merging target features, keep the highest stability)
 - rust-lang#137684 (Add rustdoc support for `--emit=dep-info[=path]`)
 - rust-lang#137794 (make qnx pass a test)
 - rust-lang#137801 (tests: Unignore target modifier tests on all platforms)
 - rust-lang#137826 (test(codegen): add looping_over_ne_bytes test for rust-lang#133528)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 3, 2025
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#137103 ({json|html}docck: catch and error on deprecated syntax)
 - rust-lang#137632 (rustdoc: when merging target features, keep the highest stability)
 - rust-lang#137684 (Add rustdoc support for `--emit=dep-info[=path]`)
 - rust-lang#137794 (make qnx pass a test)
 - rust-lang#137801 (tests: Unignore target modifier tests on all platforms)
 - rust-lang#137826 (test(codegen): add looping_over_ne_bytes test for rust-lang#133528)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 3, 2025
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#137103 ({json|html}docck: catch and error on deprecated syntax)
 - rust-lang#137632 (rustdoc: when merging target features, keep the highest stability)
 - rust-lang#137684 (Add rustdoc support for `--emit=dep-info[=path]`)
 - rust-lang#137794 (make qnx pass a test)
 - rust-lang#137801 (tests: Unignore target modifier tests on all platforms)
 - rust-lang#137826 (test(codegen): add looping_over_ne_bytes test for rust-lang#133528)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 962e492 into rust-lang:master Mar 3, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 3, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 3, 2025
Rollup merge of rust-lang#137632 - RalfJung:rustdoc-target-features, r=workingjubilee

rustdoc: when merging target features, keep the highest stability

This addresses rust-lang#137366. (Not closing since we might consider a backport.)

rustdoc wants to pretend that it runs for all targets at once and has all target features, so `tcx.rust_target_features()` will actually be all the target features. For target features that exist on multiple targets, the stability info for one of the targets will be picked (first or last in the list, I guess). All the code consuming that query has to be aware that the data is basically nonsense when running in rustdoc, but the logic checking for unstable or forbidden `#[target_feature]` attributes was not aware of that.

This PR makes the  `tcx.rust_target_features()` info in rustdoc slightly less nonsensical (and decidedly less random) by having the "most stable" target feature take precedent. That deals with rust-lang#137366 (a conflict between a stable and a "forbidden" target feature of the same name for different targets), and also deals with the situation (that we did not seem to have yet) of a conflict between a stable and an unstable target feature of the same name. Note that if there are two unstable target features of the same name, rustdoc might still require the "wrong" nightly feature to be enabled -- but this can only possibly affect unstable code so I guess we can wait until that actually happens, and then someone will have to rewrite this entire thing to be less hacky.
TomJo2000 added a commit to TomJo2000/termux-packages-prs that referenced this pull request Mar 5, 2025
backport: rust-lang/rust#137632 to fix cross compilation of docs
@apiraino
Copy link
Contributor

apiraino commented Mar 6, 2025

hey @rust-lang/rustdoc Are you interested (or neutral or against) in having this patch backported to beta channel. It fixes a regression on stable.

@RalfJung RalfJung deleted the rustdoc-target-features branch March 6, 2025 17:36
@jieyouxu jieyouxu added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. beta-nominated Nominated for backporting to the compiler in the beta channel. and removed beta-nominated Nominated for backporting to the compiler in the beta channel. labels Mar 9, 2025
@jieyouxu
Copy link
Member

jieyouxu commented Mar 9, 2025

(t-rustdoc backport nomination thread is #t-rustdoc > beta-nominated: #137632)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta-nominated Nominated for backporting to the compiler in the beta channel. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants