Rollup merge of #125637 - nnethercote:rustfmt-fixes, r=GuillaumeGomez
rustfmt fixes The `rmake.rs` entries in `rustfmt.toml` are causing major problems for `x fmt`. This PR removes them and does some minor related cleanups. r? ``@GuillaumeGomez``
This commit is contained in:
commit
faabc74625
5 changed files with 37 additions and 40 deletions
|
@ -219,10 +219,8 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> {
|
||||||
for (i, field) in variant.fields.iter_enumerated() {
|
for (i, field) in variant.fields.iter_enumerated() {
|
||||||
let field_ty = field.ty(self.tcx, args);
|
let field_ty = field.ty(self.tcx, args);
|
||||||
if field_ty == *cast_ty {
|
if field_ty == *cast_ty {
|
||||||
let place = place.project_deeper(
|
let place = place
|
||||||
&[ProjectionElem::Field(i, *cast_ty)],
|
.project_deeper(&[ProjectionElem::Field(i, *cast_ty)], self.tcx);
|
||||||
self.tcx,
|
|
||||||
);
|
|
||||||
let operand = if operand.is_move() {
|
let operand = if operand.is_move() {
|
||||||
Operand::Move(place)
|
Operand::Move(place)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -209,18 +209,14 @@ impl<Dyn: ?Sized> DynMetadata<Dyn> {
|
||||||
// Consider a reference like `&(i32, dyn Send)`: the vtable will only store the size of the
|
// Consider a reference like `&(i32, dyn Send)`: the vtable will only store the size of the
|
||||||
// `Send` part!
|
// `Send` part!
|
||||||
// SAFETY: DynMetadata always contains a valid vtable pointer
|
// SAFETY: DynMetadata always contains a valid vtable pointer
|
||||||
return unsafe {
|
return unsafe { crate::intrinsics::vtable_size(self.vtable_ptr() as *const ()) };
|
||||||
crate::intrinsics::vtable_size(self.vtable_ptr() as *const ())
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the alignment of the type associated with this vtable.
|
/// Returns the alignment of the type associated with this vtable.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn align_of(self) -> usize {
|
pub fn align_of(self) -> usize {
|
||||||
// SAFETY: DynMetadata always contains a valid vtable pointer
|
// SAFETY: DynMetadata always contains a valid vtable pointer
|
||||||
return unsafe {
|
return unsafe { crate::intrinsics::vtable_align(self.vtable_ptr() as *const ()) };
|
||||||
crate::intrinsics::vtable_align(self.vtable_ptr() as *const ())
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the size and alignment together as a `Layout`
|
/// Returns the size and alignment together as a `Layout`
|
||||||
|
|
19
rustfmt.toml
19
rustfmt.toml
|
@ -3,25 +3,18 @@ version = "Two"
|
||||||
use_small_heuristics = "Max"
|
use_small_heuristics = "Max"
|
||||||
merge_derives = false
|
merge_derives = false
|
||||||
|
|
||||||
# by default we ignore everything in the repository
|
# Files to ignore. Each entry uses gitignore syntax, but `!` prefixes aren't allowed.
|
||||||
# tidy only checks files which are not ignored, each entry follows gitignore style
|
|
||||||
ignore = [
|
ignore = [
|
||||||
"/build/",
|
"/build/",
|
||||||
"/*-build/",
|
"/*-build/",
|
||||||
"/build-*/",
|
"/build-*/",
|
||||||
"/vendor/",
|
"/vendor/",
|
||||||
|
|
||||||
# tests for now are not formatted, as they are sometimes pretty-printing constrained
|
# Tests for now are not formatted, as they are sometimes pretty-printing constrained
|
||||||
# (and generally rustfmt can move around comments in UI-testing incompatible ways)
|
# (and generally rustfmt can move around comments in UI-testing incompatible ways).
|
||||||
"/tests/*",
|
"/tests/",
|
||||||
|
|
||||||
# but we still want to format rmake.rs files in tests/run-make/ so we need to do this
|
# Do not format submodules.
|
||||||
# dance to avoid the parent directory from being excluded
|
|
||||||
"!/tests/run-make/",
|
|
||||||
"/tests/run-make/*/*.rs",
|
|
||||||
"!/tests/run-make/*/rmake.rs",
|
|
||||||
|
|
||||||
# do not format submodules
|
|
||||||
# FIXME: sync submodule list with tidy/bootstrap/etc
|
# FIXME: sync submodule list with tidy/bootstrap/etc
|
||||||
# tidy/src/walk.rs:filter_dirs
|
# tidy/src/walk.rs:filter_dirs
|
||||||
"library/backtrace",
|
"library/backtrace",
|
||||||
|
@ -43,7 +36,7 @@ ignore = [
|
||||||
"src/tools/rustc-perf",
|
"src/tools/rustc-perf",
|
||||||
"src/tools/rustfmt",
|
"src/tools/rustfmt",
|
||||||
|
|
||||||
# these are ignored by a standard cargo fmt run
|
# These are ignored by a standard cargo fmt run.
|
||||||
"compiler/rustc_codegen_cranelift/scripts",
|
"compiler/rustc_codegen_cranelift/scripts",
|
||||||
"compiler/rustc_codegen_cranelift/example/gen_block_iterate.rs", # uses edition 2024
|
"compiler/rustc_codegen_cranelift/example/gen_block_iterate.rs", # uses edition 2024
|
||||||
]
|
]
|
||||||
|
|
|
@ -12,8 +12,8 @@ use std::sync::mpsc::SyncSender;
|
||||||
|
|
||||||
fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> impl FnMut(bool) -> bool {
|
fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> impl FnMut(bool) -> bool {
|
||||||
let mut cmd = Command::new(rustfmt);
|
let mut cmd = Command::new(rustfmt);
|
||||||
// avoid the submodule config paths from coming into play,
|
// Avoid the submodule config paths from coming into play. We only allow a single global config
|
||||||
// we only allow a single global config for the workspace for now
|
// for the workspace for now.
|
||||||
cmd.arg("--config-path").arg(&src.canonicalize().unwrap());
|
cmd.arg("--config-path").arg(&src.canonicalize().unwrap());
|
||||||
cmd.arg("--edition").arg("2021");
|
cmd.arg("--edition").arg("2021");
|
||||||
cmd.arg("--unstable-features");
|
cmd.arg("--unstable-features");
|
||||||
|
@ -24,7 +24,7 @@ fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> impl F
|
||||||
cmd.args(paths);
|
cmd.args(paths);
|
||||||
let cmd_debug = format!("{cmd:?}");
|
let cmd_debug = format!("{cmd:?}");
|
||||||
let mut cmd = cmd.spawn().expect("running rustfmt");
|
let mut cmd = cmd.spawn().expect("running rustfmt");
|
||||||
// poor man's async: return a closure that'll wait for rustfmt's completion
|
// Poor man's async: return a closure that'll wait for rustfmt's completion.
|
||||||
move |block: bool| -> bool {
|
move |block: bool| -> bool {
|
||||||
if !block {
|
if !block {
|
||||||
match cmd.try_wait() {
|
match cmd.try_wait() {
|
||||||
|
@ -72,7 +72,7 @@ fn verify_rustfmt_version(build: &Builder<'_>) -> bool {
|
||||||
!program_out_of_date(&stamp_file, &version)
|
!program_out_of_date(&stamp_file, &version)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates the last rustfmt version used
|
/// Updates the last rustfmt version used.
|
||||||
fn update_rustfmt_version(build: &Builder<'_>) {
|
fn update_rustfmt_version(build: &Builder<'_>) {
|
||||||
let Some((version, stamp_file)) = get_rustfmt_version(build) else {
|
let Some((version, stamp_file)) = get_rustfmt_version(build) else {
|
||||||
return;
|
return;
|
||||||
|
@ -115,8 +115,15 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
|
||||||
let rustfmt_config: RustfmtConfig = t!(toml::from_str(&rustfmt_config));
|
let rustfmt_config: RustfmtConfig = t!(toml::from_str(&rustfmt_config));
|
||||||
let mut fmt_override = ignore::overrides::OverrideBuilder::new(&build.src);
|
let mut fmt_override = ignore::overrides::OverrideBuilder::new(&build.src);
|
||||||
for ignore in rustfmt_config.ignore {
|
for ignore in rustfmt_config.ignore {
|
||||||
if let Some(ignore) = ignore.strip_prefix('!') {
|
if ignore.starts_with('!') {
|
||||||
fmt_override.add(ignore).expect(ignore);
|
// A `!`-prefixed entry could be added as a whitelisted entry in `fmt_override`, i.e.
|
||||||
|
// strip the `!` prefix. But as soon as whitelisted entries are added, an
|
||||||
|
// `OverrideBuilder` will only traverse those whitelisted entries, and won't traverse
|
||||||
|
// any files that aren't explicitly mentioned. No bueno! Maybe there's a way to combine
|
||||||
|
// explicit whitelisted entries and traversal of unmentioned files, but for now just
|
||||||
|
// forbid such entries.
|
||||||
|
eprintln!("`!`-prefixed entries are not supported in rustfmt.toml, sorry");
|
||||||
|
crate::exit!(1);
|
||||||
} else {
|
} else {
|
||||||
fmt_override.add(&format!("!{ignore}")).expect(&ignore);
|
fmt_override.add(&format!("!{ignore}")).expect(&ignore);
|
||||||
}
|
}
|
||||||
|
@ -168,9 +175,10 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
|
||||||
untracked_count += 1;
|
untracked_count += 1;
|
||||||
fmt_override.add(&format!("!/{untracked_path}")).expect(untracked_path);
|
fmt_override.add(&format!("!/{untracked_path}")).expect(untracked_path);
|
||||||
}
|
}
|
||||||
// Only check modified files locally to speed up runtime.
|
// Only check modified files locally to speed up runtime. We still check all files in
|
||||||
// We still check all files in CI to avoid bugs in `get_modified_rs_files` letting regressions slip through;
|
// CI to avoid bugs in `get_modified_rs_files` letting regressions slip through; we
|
||||||
// we also care about CI time less since this is still very fast compared to building the compiler.
|
// also care about CI time less since this is still very fast compared to building the
|
||||||
|
// compiler.
|
||||||
if !CiEnv::is_ci() && paths.is_empty() {
|
if !CiEnv::is_ci() && paths.is_empty() {
|
||||||
match get_modified_rs_files(build) {
|
match get_modified_rs_files(build) {
|
||||||
Ok(Some(files)) => {
|
Ok(Some(files)) => {
|
||||||
|
@ -275,21 +283,23 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
|
||||||
.overrides(fmt_override)
|
.overrides(fmt_override)
|
||||||
.build_parallel();
|
.build_parallel();
|
||||||
|
|
||||||
// there is a lot of blocking involved in spawning a child process and reading files to format.
|
// There is a lot of blocking involved in spawning a child process and reading files to format.
|
||||||
// spawn more processes than available concurrency to keep the CPU busy
|
// Spawn more processes than available concurrency to keep the CPU busy.
|
||||||
let max_processes = build.jobs() as usize * 2;
|
let max_processes = build.jobs() as usize * 2;
|
||||||
|
|
||||||
// spawn child processes on a separate thread so we can batch entries we have received from ignore
|
// Spawn child processes on a separate thread so we can batch entries we have received from
|
||||||
|
// ignore.
|
||||||
let thread = std::thread::spawn(move || {
|
let thread = std::thread::spawn(move || {
|
||||||
let mut children = VecDeque::new();
|
let mut children = VecDeque::new();
|
||||||
while let Ok(path) = rx.recv() {
|
while let Ok(path) = rx.recv() {
|
||||||
// try getting more paths from the channel to amortize the overhead of spawning processes
|
// Try getting more paths from the channel to amortize the overhead of spawning
|
||||||
|
// processes.
|
||||||
let paths: Vec<_> = rx.try_iter().take(63).chain(std::iter::once(path)).collect();
|
let paths: Vec<_> = rx.try_iter().take(63).chain(std::iter::once(path)).collect();
|
||||||
|
|
||||||
let child = rustfmt(&src, &rustfmt_path, paths.as_slice(), check);
|
let child = rustfmt(&src, &rustfmt_path, paths.as_slice(), check);
|
||||||
children.push_back(child);
|
children.push_back(child);
|
||||||
|
|
||||||
// poll completion before waiting
|
// Poll completion before waiting.
|
||||||
for i in (0..children.len()).rev() {
|
for i in (0..children.len()).rev() {
|
||||||
if children[i](false) {
|
if children[i](false) {
|
||||||
children.swap_remove_back(i);
|
children.swap_remove_back(i);
|
||||||
|
@ -298,12 +308,12 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if children.len() >= max_processes {
|
if children.len() >= max_processes {
|
||||||
// await oldest child
|
// Await oldest child.
|
||||||
children.pop_front().unwrap()(true);
|
children.pop_front().unwrap()(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// await remaining children
|
// Await remaining children.
|
||||||
for mut child in children {
|
for mut child in children {
|
||||||
child(true);
|
child(true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue