Skip to content

Commit 8b22894

Browse files
committed
Auto merge of rust-lang#135655 - matthiaskrgr:rollup-ocj5y1t, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#134455 (cleanup promoteds move check) - rust-lang#135421 (Make tidy warn on unrecognized directives) - rust-lang#135611 (Remove unnecessary assertion for reference error) - rust-lang#135620 (ci: improve github action name) - rust-lang#135621 (Move some std tests to integration tests) - rust-lang#135639 (new solver: prefer trivial builtin impls) - rust-lang#135654 (add src/librustdoc and src/rustdoc-json-types to RUSTC_IF_UNCHANGED_ALLOWED_PATHS) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6067b36 + 10239b1 commit 8b22894

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+634
-562
lines changed

Diff for: .github/workflows/ghcr.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# for PR jobs, because forks can't access secrets.
1010
# That's why we use ghcr.io: it has no rate limit and it doesn't require authentication.
1111

12-
name: GHCR
12+
name: GHCR image mirroring
1313

1414
on:
1515
workflow_dispatch:

Diff for: Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4259,6 +4259,7 @@ dependencies = [
42594259
"rustc_serialize",
42604260
"rustc_type_ir",
42614261
"rustc_type_ir_macros",
4262+
"smallvec",
42624263
"tracing",
42634264
]
42644265

Diff for: compiler/rustc_borrowck/src/lib.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,6 @@ fn do_mir_borrowck<'tcx>(
182182
let location_table = PoloniusLocationTable::new(body);
183183

184184
let move_data = MoveData::gather_moves(body, tcx, |_| true);
185-
let promoted_move_data = promoted
186-
.iter_enumerated()
187-
.map(|(idx, body)| (idx, MoveData::gather_moves(body, tcx, |_| true)));
188185

189186
let flow_inits = MaybeInitializedPlaces::new(tcx, body, &move_data)
190187
.iterate_to_fixpoint(tcx, body, Some("borrowck"))
@@ -242,10 +239,14 @@ fn do_mir_borrowck<'tcx>(
242239
false
243240
};
244241

245-
for (idx, move_data) in promoted_move_data {
242+
// While promoteds should mostly be correct by construction, we need to check them for
243+
// invalid moves to detect moving out of arrays:`struct S; fn main() { &([S][0]); }`.
244+
for promoted_body in &promoted {
246245
use rustc_middle::mir::visit::Visitor;
247-
248-
let promoted_body = &promoted[idx];
246+
// This assumes that we won't use some of the fields of the `promoted_mbcx`
247+
// when detecting and reporting move errors. While it would be nice to move
248+
// this check out of `MirBorrowckCtxt`, actually doing so is far from trivial.
249+
let move_data = MoveData::gather_moves(promoted_body, tcx, |_| true);
249250
let mut promoted_mbcx = MirBorrowckCtxt {
250251
infcx: &infcx,
251252
body: promoted_body,
@@ -270,9 +271,6 @@ fn do_mir_borrowck<'tcx>(
270271
move_errors: Vec::new(),
271272
diags_buffer,
272273
};
273-
MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body);
274-
promoted_mbcx.report_move_errors();
275-
276274
struct MoveVisitor<'a, 'b, 'infcx, 'tcx> {
277275
ctxt: &'a mut MirBorrowckCtxt<'b, 'infcx, 'tcx>,
278276
}
@@ -284,6 +282,8 @@ fn do_mir_borrowck<'tcx>(
284282
}
285283
}
286284
}
285+
MoveVisitor { ctxt: &mut promoted_mbcx }.visit_body(promoted_body);
286+
promoted_mbcx.report_move_errors();
287287
}
288288

289289
let mut mbcx = MirBorrowckCtxt {

Diff for: compiler/rustc_hir_analysis/src/check/check.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,6 @@ fn check_type_alias_type_params_are_used<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalD
16371637
let ty = tcx.type_of(def_id).instantiate_identity();
16381638
if ty.references_error() {
16391639
// If there is already another error, do not emit an error for not using a type parameter.
1640-
assert!(tcx.dcx().has_errors().is_some());
16411640
return;
16421641
}
16431642

Diff for: compiler/rustc_next_trait_solver/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ rustc_macros = { path = "../rustc_macros", optional = true }
1313
rustc_serialize = { path = "../rustc_serialize", optional = true }
1414
rustc_type_ir = { path = "../rustc_type_ir", default-features = false }
1515
rustc_type_ir_macros = { path = "../rustc_type_ir_macros" }
16+
smallvec = "1.8.1"
1617
tracing = "0.1"
1718
# tidy-alphabetical-end
1819

Diff for: compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

+26-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_type_ir::lang_items::TraitSolverLangItem;
88
use rustc_type_ir::solve::CanonicalResponse;
99
use rustc_type_ir::visit::TypeVisitableExt as _;
1010
use rustc_type_ir::{self as ty, Interner, TraitPredicate, TypingMode, Upcast as _, elaborate};
11+
use smallvec::SmallVec;
1112
use tracing::{instrument, trace};
1213

1314
use crate::delegate::SolverDelegate;
@@ -225,7 +226,7 @@ where
225226
}
226227

227228
ecx.probe_and_evaluate_goal_for_constituent_tys(
228-
CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
229+
CandidateSource::BuiltinImpl(BuiltinImplSource::Trivial),
229230
goal,
230231
structural_traits::instantiate_constituent_tys_for_sized_trait,
231232
)
@@ -1194,7 +1195,30 @@ where
11941195
};
11951196
}
11961197

1197-
// FIXME: prefer trivial builtin impls
1198+
// We prefer trivial builtin candidates, i.e. builtin impls without any
1199+
// nested requirements, over all others. This is a fix for #53123 and
1200+
// prevents where-bounds from accidentally extending the lifetime of a
1201+
// variable.
1202+
if candidates
1203+
.iter()
1204+
.any(|c| matches!(c.source, CandidateSource::BuiltinImpl(BuiltinImplSource::Trivial)))
1205+
{
1206+
let trivial_builtin_impls: SmallVec<[_; 1]> = candidates
1207+
.iter()
1208+
.filter(|c| {
1209+
matches!(c.source, CandidateSource::BuiltinImpl(BuiltinImplSource::Trivial))
1210+
})
1211+
.map(|c| c.result)
1212+
.collect();
1213+
// There should only ever be a single trivial builtin candidate
1214+
// as they would otherwise overlap.
1215+
assert_eq!(trivial_builtin_impls.len(), 1);
1216+
return if let Some(response) = self.try_merge_responses(&trivial_builtin_impls) {
1217+
Ok((response, Some(TraitGoalProvenVia::Misc)))
1218+
} else {
1219+
Ok((self.bail_with_ambiguity(&trivial_builtin_impls), None))
1220+
};
1221+
}
11981222

11991223
// If there are non-global where-bounds, prefer where-bounds
12001224
// (including global ones) over everything else.

Diff for: compiler/rustc_trait_selection/src/traits/project.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
991991
Err(ErrorGuaranteed { .. }) => true,
992992
}
993993
}
994-
ImplSource::Builtin(BuiltinImplSource::Misc, _) => {
994+
ImplSource::Builtin(BuiltinImplSource::Misc | BuiltinImplSource::Trivial, _) => {
995995
// While a builtin impl may be known to exist, the associated type may not yet
996996
// be known. Any type with multiple potential associated types is therefore
997997
// not eligible.
@@ -1296,7 +1296,7 @@ fn confirm_select_candidate<'cx, 'tcx>(
12961296
) -> Progress<'tcx> {
12971297
match impl_source {
12981298
ImplSource::UserDefined(data) => confirm_impl_candidate(selcx, obligation, data),
1299-
ImplSource::Builtin(BuiltinImplSource::Misc, data) => {
1299+
ImplSource::Builtin(BuiltinImplSource::Misc | BuiltinImplSource::Trivial, data) => {
13001300
let tcx = selcx.tcx();
13011301
let trait_def_id = obligation.predicate.trait_def_id(tcx);
13021302
if tcx.is_lang_item(trait_def_id, LangItem::Coroutine) {

Diff for: compiler/rustc_ty_utils/src/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ fn resolve_associated_item<'tcx>(
248248
})
249249
}
250250
}
251-
traits::ImplSource::Builtin(BuiltinImplSource::Misc, _) => {
251+
traits::ImplSource::Builtin(BuiltinImplSource::Misc | BuiltinImplSource::Trivial, _) => {
252252
if tcx.is_lang_item(trait_ref.def_id, LangItem::Clone) {
253253
// FIXME(eddyb) use lang items for methods instead of names.
254254
let name = tcx.item_name(trait_item_id);

Diff for: compiler/rustc_type_ir/src/solve/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ pub enum CandidateSource<I: Interner> {
169169
#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
170170
#[cfg_attr(feature = "nightly", derive(HashStable_NoContext, TyEncodable, TyDecodable))]
171171
pub enum BuiltinImplSource {
172+
/// A built-in impl that is considered trivial, without any nested requirements. They
173+
/// are preferred over where-clauses, and we want to track them explicitly.
174+
Trivial,
172175
/// Some built-in impl we don't need to differentiate. This should be used
173176
/// unless more specific information is necessary.
174177
Misc,

Diff for: library/std/Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ license = "MIT OR Apache-2.0"
77
repository = "https://github.com/rust-lang/rust.git"
88
description = "The Rust Standard Library"
99
edition = "2021"
10+
autobenches = false
1011

1112
[lib]
1213
crate-type = ["dylib", "rlib"]
@@ -130,6 +131,18 @@ name = "pipe-subprocess"
130131
path = "tests/pipe_subprocess.rs"
131132
harness = false
132133

134+
[[test]]
135+
name = "sync"
136+
path = "tests/sync/lib.rs"
137+
138+
[[test]]
139+
name = "floats"
140+
path = "tests/floats/lib.rs"
141+
142+
[[test]]
143+
name = "thread_local"
144+
path = "tests/thread_local/lib.rs"
145+
133146
[[bench]]
134147
name = "stdbenches"
135148
path = "benches/lib.rs"

Diff for: library/std/benches/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
extern crate test;
66

77
mod hash;
8+
mod path;
9+
mod time;

Diff for: library/std/benches/path.rs

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
use core::hint::black_box;
2+
use std::collections::{BTreeSet, HashSet};
3+
use std::hash::{DefaultHasher, Hash, Hasher};
4+
use std::path::*;
5+
6+
#[bench]
7+
#[cfg_attr(miri, ignore)] // Miri isn't fast...
8+
fn bench_path_cmp_fast_path_buf_sort(b: &mut test::Bencher) {
9+
let prefix = "my/home";
10+
let mut paths: Vec<_> =
11+
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
12+
13+
paths.sort();
14+
15+
b.iter(|| {
16+
black_box(paths.as_mut_slice()).sort_unstable();
17+
});
18+
}
19+
20+
#[bench]
21+
#[cfg_attr(miri, ignore)] // Miri isn't fast...
22+
fn bench_path_cmp_fast_path_long(b: &mut test::Bencher) {
23+
let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/";
24+
let paths: Vec<_> =
25+
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
26+
27+
let mut set = BTreeSet::new();
28+
29+
paths.iter().for_each(|p| {
30+
set.insert(p.as_path());
31+
});
32+
33+
b.iter(|| {
34+
set.remove(paths[500].as_path());
35+
set.insert(paths[500].as_path());
36+
});
37+
}
38+
39+
#[bench]
40+
#[cfg_attr(miri, ignore)] // Miri isn't fast...
41+
fn bench_path_cmp_fast_path_short(b: &mut test::Bencher) {
42+
let prefix = "my/home";
43+
let paths: Vec<_> =
44+
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
45+
46+
let mut set = BTreeSet::new();
47+
48+
paths.iter().for_each(|p| {
49+
set.insert(p.as_path());
50+
});
51+
52+
b.iter(|| {
53+
set.remove(paths[500].as_path());
54+
set.insert(paths[500].as_path());
55+
});
56+
}
57+
58+
#[bench]
59+
#[cfg_attr(miri, ignore)] // Miri isn't fast...
60+
fn bench_path_hashset(b: &mut test::Bencher) {
61+
let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/";
62+
let paths: Vec<_> =
63+
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
64+
65+
let mut set = HashSet::new();
66+
67+
paths.iter().for_each(|p| {
68+
set.insert(p.as_path());
69+
});
70+
71+
b.iter(|| {
72+
set.remove(paths[500].as_path());
73+
set.insert(black_box(paths[500].as_path()))
74+
});
75+
}
76+
77+
#[bench]
78+
#[cfg_attr(miri, ignore)] // Miri isn't fast...
79+
fn bench_path_hashset_miss(b: &mut test::Bencher) {
80+
let prefix = "/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/";
81+
let paths: Vec<_> =
82+
(0..1000).map(|num| PathBuf::from(prefix).join(format!("file {num}.rs"))).collect();
83+
84+
let mut set = HashSet::new();
85+
86+
paths.iter().for_each(|p| {
87+
set.insert(p.as_path());
88+
});
89+
90+
let probe = PathBuf::from(prefix).join("other");
91+
92+
b.iter(|| set.remove(black_box(probe.as_path())));
93+
}
94+
95+
#[bench]
96+
fn bench_hash_path_short(b: &mut test::Bencher) {
97+
let mut hasher = DefaultHasher::new();
98+
let path = Path::new("explorer.exe");
99+
100+
b.iter(|| black_box(path).hash(&mut hasher));
101+
102+
black_box(hasher.finish());
103+
}
104+
105+
#[bench]
106+
fn bench_hash_path_long(b: &mut test::Bencher) {
107+
let mut hasher = DefaultHasher::new();
108+
let path =
109+
Path::new("/aaaaa/aaaaaa/./../aaaaaaaa/bbbbbbbbbbbbb/ccccccccccc/ddddddddd/eeeeeee.fff");
110+
111+
b.iter(|| black_box(path).hash(&mut hasher));
112+
113+
black_box(hasher.finish());
114+
}

Diff for: library/std/benches/time.rs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use std::time::Instant;
2+
3+
#[cfg(not(target_arch = "wasm32"))]
4+
use test::{Bencher, black_box};
5+
6+
macro_rules! bench_instant_threaded {
7+
($bench_name:ident, $thread_count:expr) => {
8+
#[bench]
9+
#[cfg(not(target_arch = "wasm32"))]
10+
fn $bench_name(b: &mut Bencher) -> std::thread::Result<()> {
11+
use std::sync::Arc;
12+
use std::sync::atomic::{AtomicBool, Ordering};
13+
14+
let running = Arc::new(AtomicBool::new(true));
15+
16+
let threads: Vec<_> = (0..$thread_count)
17+
.map(|_| {
18+
let flag = Arc::clone(&running);
19+
std::thread::spawn(move || {
20+
while flag.load(Ordering::Relaxed) {
21+
black_box(Instant::now());
22+
}
23+
})
24+
})
25+
.collect();
26+
27+
b.iter(|| {
28+
let a = Instant::now();
29+
let b = Instant::now();
30+
assert!(b >= a);
31+
});
32+
33+
running.store(false, Ordering::Relaxed);
34+
35+
for t in threads {
36+
t.join()?;
37+
}
38+
Ok(())
39+
}
40+
};
41+
}
42+
43+
bench_instant_threaded!(instant_contention_01_threads, 0);
44+
bench_instant_threaded!(instant_contention_02_threads, 1);
45+
bench_instant_threaded!(instant_contention_04_threads, 3);
46+
bench_instant_threaded!(instant_contention_08_threads, 7);
47+
bench_instant_threaded!(instant_contention_16_threads, 15);

Diff for: library/std/src/env.rs

-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
1111
#![stable(feature = "env", since = "1.0.0")]
1212

13-
#[cfg(test)]
14-
mod tests;
15-
1613
use crate::error::Error;
1714
use crate::ffi::{OsStr, OsString};
1815
use crate::path::{Path, PathBuf};

0 commit comments

Comments
 (0)