-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Restrict sysroot crate imports to those defined in this repo. #143548
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
base: master
Are you sure you want to change the base?
Conversation
Some changes occurred in compiler/rustc_codegen_ssa Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred in src/tools/compiletest cc @jieyouxu Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt Some changes occurred in compiler/rustc_attr_data_structures Some changes occurred in compiler/rustc_attr_parsing Some changes occurred in compiler/rustc_codegen_gcc The Miri subtree was changed cc @rust-lang/miri Some changes occurred in exhaustiveness checking cc @Nadrieril Some changes occurred in compiler/rustc_sanitizers cc @rcvalle
|
src/tools/rustfmt/Cargo.toml
Outdated
tracing = { version = "0.1.37", default-features = false, features = ["std"] } | ||
tracing = { workspace = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a valid change for rustfmt. Although rustfmt is part of the r-l/rust workspace, it's independently developed in https://github.com/rust-lang/rustfmt, and I'm pretty sure this would prevent us from build from source when working on the git subtree, which isn't structured as a cargo workspace. I'd like to opt out of all rustfmt changes from this PR, but feel free to open a new PR directly to https://github.com/rust-lang/rustfmt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, will update 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ytmimi is it sufficient to revert the Cargo.toml changes, or do the other changes need to go via the other repo as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, there are some other workspace members that are also subtrees, like clippy, and miri. I didn't look at any tools besides rustfmt, but it's possible maintainers of those tools would prefer PRs be opened up directly to their respective repos as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ytmimi happy to split if needed but the wording you linked says:
The exception is that when rustc changes are required to implement a new tool feature or test, that should happen in one collective rustc PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ytmimi is it sufficient to revert the Cargo.toml changes, or do the other changes need to go via the other repo as well?
I'd rather that all changes were reverted, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using workspace dependencies for the Cargo.toml files in compiler
(except in codegen_gcc and codegen_clf) is entirely fine, and a good idea for the reasons you mention. Only the subtree crates like Miri, clippy, rustfmt cannot use workspace dependencies.
The root problem here is not the use of workspace dependencies, the problem is that rustfmt has tracing in its Cargo.toml, which it shouldn't. It should use rustc's tracing instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, turns out workspace dependencies do not work since the workspace Cargo.toml is not distributed in the rustc-dev package... see Zulip.
It's common to import dependencies from the sysroot via `extern crate` rather than use an explicit cargo dependency, when it's necessary to use the same dependency version as used by rustc itself. However, this is dangerous for crates.io crates, since rustc may not pull in the dependency on some targets, or may pull in multiple versions. In both cases, the `extern crate` fails to resolve. To address this, re-export all such dependencies from the appropriate `rustc_*` crates, and use this alias from crates which would otherwise need to use `extern crate`.
8e8dd82
to
c613bce
Compare
The Miri subtree was changed cc @rust-lang/miri Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt Some changes occurred in compiler/rustc_codegen_gcc |
The job Click to see the possible cause of the failure (guessed by this bot)
|
// These crates are pulled from the sysroot because they are part of | ||
// rustc's public API, so we need to ensure version compatibility. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this version compatibility still a concern?
I'm not sure what it's referring to, but I just want to make sure that removing this is not going to break something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this comment in a previous PR as essentially a TODO for this PR. Now that crates are re-exported there's no need to pull them by name from the sysroot in order to ensure the versions match.
use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; | ||
use rustc_errors::{Diag, DiagMessage}; | ||
use rustc_hir::def_id::LocalDefId; | ||
use rustc_middle::ty::TyCtxt; | ||
pub(crate) use rustc_resolve::rustdoc::main_body_opts; | ||
use rustc_resolve::rustdoc::may_be_doc_link; | ||
use rustc_resolve::rustdoc::pulldown_cmark::{ | ||
self, BrokenLink, CodeBlockKind, CowStr, Event, LinkType, Options, Parser, Tag, TagEnd, html, | ||
}; | ||
use rustc_span::edition::Edition; | ||
use rustc_span::{Span, Symbol}; | ||
use tracing::{debug, trace}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are still tracing imports all over rustdoc... and indeed, tracing is oddly a cargo dependency here. That seems wrong? Tracing has a global singleton so rustc drivers should use the version from the sysroot, not their own, to ensure there's one shared logging system across the rustc core + driver.
Probably best to do that in a separate PR, but maybe add a FIXME in the Cargo.toml to at least document this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rustdoc intentionally doesn't use rustc's copy of tracing to be able to enable trace logs for rustdoc without having to recompile rustc:
Lines 165 to 170 in c720f49
// When using CI artifacts with `download-rustc`, tracing is unconditionally built | |
// with `--features=static_max_level_info`, which disables almost all rustdoc logging. To avoid | |
// this, compile our own version of `tracing` that logs all levels. | |
// NOTE: this compiles both versions of tracing unconditionally, because | |
// - The compile time hit is not that bad, especially compared to rustdoc's incremental times, and | |
// - Otherwise, there's no warning that logging is being ignored when `download-rustc` is enabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, interesting. In Miri we use higher log levels to avoid that, since having two entirely separate loggers became quite annoying, but maybe that's less of a problem for rustdoc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Miri changes LGTM, except the ones in the vendored file where only the header at the top should be edited.
I'm fine with having these Miri changes here, seems easier to do this centrally than coordinate half a dozen PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file was deliberately not formatted since it is a copy from another repo. Please undo all the formatting here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I wondered why these formatting changes appeared!
@@ -613,10 +571,9 @@ struct JsonVisitor<'a> { | |||
object: &'a mut Object, | |||
} | |||
|
|||
impl<'a> tracing_subscriber::field::Visit for JsonVisitor<'a> { | |||
impl<'a> rustc_log::tracing_subscriber::field::Visit for JsonVisitor<'a> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid diff in the core of the file, please just import these modules at the top.
Do you think it is feasible to add an internal lint that rejects |
@oli-obk I'll look into this. How does testing work for sub-trees? Would each sub-tree need its own copy of the lint, or do the subtree repos have some way to run rust-wide lints? |
"internal" lints live in rustc like normal lints, but are gated behind a nightly-only flag. Miri enables them in their CI, I don't know if |
We have a list of internal lints that rustc has and enables everywhere. We'd have to limit it to crates with |
Not sure what you mean about restricting it, the lints need |
Ah right, my bad |
@@ -43,6 +43,7 @@ use std::fmt; | |||
pub use atomic_ref::AtomicRef; | |||
pub use ena::{snapshot_vec, undo_log, unify}; | |||
pub use rustc_index::static_assert_size; | |||
pub use {either, indexmap, smallvec, thin_vec}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub use {either, indexmap, smallvec, thin_vec}; | |
// Re-export some data-structure crates | |
pub use {either, indexmap, smallvec, thin_vec}; |
or something like the comment on tracing?
It's common to import dependencies from the sysroot via
extern crate
rather than use an explicit cargo dependency, when it's necessary to use the same dependency version as used by rustc itself. However, this is dangerous for crates.io crates, since rustc may not pull in the dependency on some targets, or may pull in multiple versions. In both cases, theextern crate
fails to resolve.To address this, re-export all such dependencies from the appropriate
rustc_*
crates, and use this alias from crates which would otherwise need to useextern crate
.See #143492 for an example of the kind of issue that can occur.