Skip to content

Commit 1a5bf12

Browse files
committed
Auto merge of #140165 - ChrisDenton:rollup-on2dpr5, r=ChrisDenton
Rollup of 8 pull requests Successful merges: - #139617 (Use posix_spawn on cygwin) - #139921 (improve diagnostic for raw pointer field access with ->) - #140031 (compiletest: Fix deadline bugs in new executor) - #140072 (handle function alignment in miri) - #140104 (Fix auto diff failing on inherent impl blocks) - #140124 (Update books) - #140144 (Handle another negated literal in `eat_token_lit`.) - #140149 (test_nan: ensure the NAN contant is quiet) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6bc57c6 + 2d8264f commit 1a5bf12

34 files changed

+326
-85
lines changed

compiler/rustc_builtin_macros/src/autodiff.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,12 @@ mod llvm_enzyme {
217217
ast::StmtKind::Item(iitem) => extract_item_info(iitem),
218218
_ => None,
219219
},
220-
Annotatable::AssocItem(assoc_item, Impl { of_trait: false }) => {
221-
match &assoc_item.kind {
222-
ast::AssocItemKind::Fn(box ast::Fn { sig, ident, .. }) => {
223-
Some((assoc_item.vis.clone(), sig.clone(), ident.clone()))
224-
}
225-
_ => None,
220+
Annotatable::AssocItem(assoc_item, Impl { .. }) => match &assoc_item.kind {
221+
ast::AssocItemKind::Fn(box ast::Fn { sig, ident, .. }) => {
222+
Some((assoc_item.vis.clone(), sig.clone(), ident.clone()))
226223
}
227-
}
224+
_ => None,
225+
},
228226
_ => None,
229227
}) else {
230228
dcx.emit_err(errors::AutoDiffInvalidApplication { span: item.span() });
@@ -365,7 +363,7 @@ mod llvm_enzyme {
365363
}
366364
Annotatable::Item(iitem.clone())
367365
}
368-
Annotatable::AssocItem(ref mut assoc_item, i @ Impl { of_trait: false }) => {
366+
Annotatable::AssocItem(ref mut assoc_item, i @ Impl { .. }) => {
369367
if !assoc_item.attrs.iter().any(|a| same_attribute(&a.kind, &attr.kind)) {
370368
assoc_item.attrs.push(attr);
371369
}

compiler/rustc_const_eval/src/interpret/memory.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,21 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
872872

873873
// # Function pointers
874874
// (both global from `alloc_map` and local from `extra_fn_ptr_map`)
875-
if self.get_fn_alloc(id).is_some() {
876-
return AllocInfo::new(Size::ZERO, Align::ONE, AllocKind::Function, Mutability::Not);
875+
if let Some(fn_val) = self.get_fn_alloc(id) {
876+
let align = match fn_val {
877+
FnVal::Instance(instance) => {
878+
// Function alignment can be set globally with the `-Zmin-function-alignment=<n>` flag;
879+
// the alignment from a `#[repr(align(<n>))]` is used if it specifies a higher alignment.
880+
let fn_align = self.tcx.codegen_fn_attrs(instance.def_id()).alignment;
881+
let global_align = self.tcx.sess.opts.unstable_opts.min_function_alignment;
882+
883+
Ord::max(global_align, fn_align).unwrap_or(Align::ONE)
884+
}
885+
// Machine-specific extra functions currently do not support alignment restrictions.
886+
FnVal::Other(_) => Align::ONE,
887+
};
888+
889+
return AllocInfo::new(Size::ZERO, align, AllocKind::Function, Mutability::Not);
877890
}
878891

879892
// # Global allocations

compiler/rustc_hir_typeck/src/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3289,8 +3289,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
32893289
err.multipart_suggestion(
32903290
format!("{val} is a raw pointer; try dereferencing it"),
32913291
vec![
3292-
(base.span.shrink_to_lo(), "(*".to_string()),
3293-
(base.span.shrink_to_hi(), ")".to_string()),
3292+
(base.span.shrink_to_lo(), "(*".into()),
3293+
(base.span.between(field.span), format!(").")),
32943294
],
32953295
Applicability::MaybeIncorrect,
32963296
);

compiler/rustc_parse/messages.ftl

+2-2
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ parse_expected_struct_field = expected one of `,`, `:`, or `{"}"}`, found `{$tok
246246
247247
parse_expected_trait_in_trait_impl_found_type = expected a trait, found type
248248
249-
parse_expr_rarrow_call = `->` used for field access or method call
249+
parse_expr_rarrow_call = `->` is not valid syntax for field accesses and method calls
250250
.suggestion = try using `.` instead
251-
.help = the `.` operator will dereference the value if needed
251+
.help = the `.` operator will automatically dereference the value, except if the value is a raw pointer
252252
253253
parse_extern_crate_name_with_dashes = crate name using dashes are not valid in `extern crate` statements
254254
.label = dash-separated idents are not valid

compiler/rustc_parse/src/parser/expr.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -2146,6 +2146,17 @@ impl<'a> Parser<'a> {
21462146
/// Keep this in sync with `Token::can_begin_literal_maybe_minus` and
21472147
/// `Lit::from_token` (excluding unary negation).
21482148
fn eat_token_lit(&mut self) -> Option<token::Lit> {
2149+
let check_expr = |expr: P<Expr>| {
2150+
if let ast::ExprKind::Lit(token_lit) = expr.kind {
2151+
Some(token_lit)
2152+
} else if let ast::ExprKind::Unary(UnOp::Neg, inner) = &expr.kind
2153+
&& let ast::Expr { kind: ast::ExprKind::Lit(_), .. } = **inner
2154+
{
2155+
None
2156+
} else {
2157+
panic!("unexpected reparsed expr/literal: {:?}", expr.kind);
2158+
}
2159+
};
21492160
match self.token.uninterpolate().kind {
21502161
token::Ident(name, IdentIsRaw::No) if name.is_bool_lit() => {
21512162
self.bump();
@@ -2159,26 +2170,15 @@ impl<'a> Parser<'a> {
21592170
let lit = self
21602171
.eat_metavar_seq(MetaVarKind::Literal, |this| this.parse_literal_maybe_minus())
21612172
.expect("metavar seq literal");
2162-
let ast::ExprKind::Lit(token_lit) = lit.kind else {
2163-
panic!("didn't reparse a literal");
2164-
};
2165-
Some(token_lit)
2173+
check_expr(lit)
21662174
}
21672175
token::OpenInvisible(InvisibleOrigin::MetaVar(
21682176
mv_kind @ MetaVarKind::Expr { can_begin_literal_maybe_minus: true, .. },
21692177
)) => {
21702178
let expr = self
21712179
.eat_metavar_seq(mv_kind, |this| this.parse_expr())
21722180
.expect("metavar seq expr");
2173-
if let ast::ExprKind::Lit(token_lit) = expr.kind {
2174-
Some(token_lit)
2175-
} else if let ast::ExprKind::Unary(UnOp::Neg, inner) = &expr.kind
2176-
&& let ast::Expr { kind: ast::ExprKind::Lit(_), .. } = **inner
2177-
{
2178-
None
2179-
} else {
2180-
panic!("unexpected reparsed expr: {:?}", expr.kind);
2181-
}
2181+
check_expr(expr)
21822182
}
21832183
_ => None,
21842184
}

library/core/src/num/f128.rs

+3
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ impl f128 {
145145
pub const RADIX: u32 = 2;
146146

147147
/// Number of significant digits in base 2.
148+
///
149+
/// Note that the size of the mantissa in the bitwise representation is one
150+
/// smaller than this since the leading 1 is not stored explicitly.
148151
#[unstable(feature = "f128", issue = "116909")]
149152
pub const MANTISSA_DIGITS: u32 = 113;
150153

library/core/src/num/f16.rs

+3
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ impl f16 {
140140
pub const RADIX: u32 = 2;
141141

142142
/// Number of significant digits in base 2.
143+
///
144+
/// Note that the size of the mantissa in the bitwise representation is one
145+
/// smaller than this since the leading 1 is not stored explicitly.
143146
#[unstable(feature = "f16", issue = "116909")]
144147
pub const MANTISSA_DIGITS: u32 = 11;
145148

library/core/src/num/f32.rs

+3
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ impl f32 {
390390
pub const RADIX: u32 = 2;
391391

392392
/// Number of significant digits in base 2.
393+
///
394+
/// Note that the size of the mantissa in the bitwise representation is one
395+
/// smaller than this since the leading 1 is not stored explicitly.
393396
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
394397
pub const MANTISSA_DIGITS: u32 = 24;
395398

library/core/src/num/f64.rs

+3
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ impl f64 {
390390
pub const RADIX: u32 = 2;
391391

392392
/// Number of significant digits in base 2.
393+
///
394+
/// Note that the size of the mantissa in the bitwise representation is one
395+
/// smaller than this since the leading 1 is not stored explicitly.
393396
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
394397
pub const MANTISSA_DIGITS: u32 = 53;
395398
/// Approximate number of significant digits in base 10.

library/std/src/sys/process/unix/unix.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ impl Command {
415415
all(target_os = "linux", target_env = "musl"),
416416
target_os = "nto",
417417
target_vendor = "apple",
418+
target_os = "cygwin",
418419
)))]
419420
fn posix_spawn(
420421
&mut self,
@@ -433,6 +434,7 @@ impl Command {
433434
all(target_os = "linux", target_env = "musl"),
434435
target_os = "nto",
435436
target_vendor = "apple",
437+
target_os = "cygwin",
436438
))]
437439
fn posix_spawn(
438440
&mut self,
@@ -584,7 +586,7 @@ impl Command {
584586
/// Some platforms can set a new working directory for a spawned process in the
585587
/// `posix_spawn` path. This function looks up the function pointer for adding
586588
/// such an action to a `posix_spawn_file_actions_t` struct.
587-
#[cfg(not(all(target_os = "linux", target_env = "musl")))]
589+
#[cfg(not(any(all(target_os = "linux", target_env = "musl"), target_os = "cygwin")))]
588590
fn get_posix_spawn_addchdir() -> Option<PosixSpawnAddChdirFn> {
589591
use crate::sys::weak::weak;
590592

@@ -618,7 +620,9 @@ impl Command {
618620
/// Weak symbol lookup doesn't work with statically linked libcs, so in cases
619621
/// where static linking is possible we need to either check for the presence
620622
/// of the symbol at compile time or know about it upfront.
621-
#[cfg(all(target_os = "linux", target_env = "musl"))]
623+
///
624+
/// Cygwin doesn't support weak symbol, so just link it.
625+
#[cfg(any(all(target_os = "linux", target_env = "musl"), target_os = "cygwin"))]
622626
fn get_posix_spawn_addchdir() -> Option<PosixSpawnAddChdirFn> {
623627
// Our minimum required musl supports this function, so we can just use it.
624628
Some(libc::posix_spawn_file_actions_addchdir_np)

library/std/tests/floats/f128.rs

+2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ fn test_nan() {
112112
assert!(!nan.is_sign_negative());
113113
assert!(!nan.is_normal());
114114
assert_eq!(Fp::Nan, nan.classify());
115+
// Ensure the quiet bit is set.
116+
assert!(nan.to_bits() & (1 << (f128::MANTISSA_DIGITS - 2)) != 0);
115117
}
116118

117119
#[test]

library/std/tests/floats/f16.rs

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ fn test_nan() {
9595
assert!(!nan.is_sign_negative());
9696
assert!(!nan.is_normal());
9797
assert_eq!(Fp::Nan, nan.classify());
98+
// Ensure the quiet bit is set.
99+
assert!(nan.to_bits() & (1 << (f16::MANTISSA_DIGITS - 2)) != 0);
98100
}
99101

100102
#[test]

library/std/tests/floats/f32.rs

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ fn test_nan() {
7272
assert!(nan.is_sign_positive());
7373
assert!(!nan.is_sign_negative());
7474
assert_eq!(Fp::Nan, nan.classify());
75+
// Ensure the quiet bit is set.
76+
assert!(nan.to_bits() & (1 << (f32::MANTISSA_DIGITS - 2)) != 0);
7577
}
7678

7779
#[test]

library/std/tests/floats/f64.rs

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ fn test_nan() {
6060
assert!(nan.is_sign_positive());
6161
assert!(!nan.is_sign_negative());
6262
assert_eq!(Fp::Nan, nan.classify());
63+
// Ensure the quiet bit is set.
64+
assert!(nan.to_bits() & (1 << (f64::MANTISSA_DIGITS - 2)) != 0);
6365
}
6466

6567
#[test]

src/doc/nomicon

src/tools/compiletest/src/executor.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ pub(crate) fn run_tests(config: &Config, tests: Vec<CollectedTest>) -> bool {
5757
}
5858

5959
let completion = deadline_queue
60-
.read_channel_while_checking_deadlines(&completion_rx, |_id, test| {
61-
listener.test_timed_out(test);
62-
})
60+
.read_channel_while_checking_deadlines(
61+
&completion_rx,
62+
|id| running_tests.contains_key(&id),
63+
|_id, test| listener.test_timed_out(test),
64+
)
6365
.expect("receive channel should never be closed early");
6466

6567
let RunningTest { test, join_handle } = running_tests.remove(&completion.id).unwrap();

src/tools/compiletest/src/executor/deadline.rs

+42-18
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,26 @@ impl<'a> DeadlineQueue<'a> {
2121
Self { queue: VecDeque::with_capacity(capacity) }
2222
}
2323

24+
/// All calls to [`Instant::now`] go through this wrapper method.
25+
/// This makes it easier to find all places that read the current time.
26+
fn now(&self) -> Instant {
27+
Instant::now()
28+
}
29+
2430
pub(crate) fn push(&mut self, id: TestId, test: &'a CollectedTest) {
25-
let deadline = Instant::now() + Duration::from_secs(TEST_WARN_TIMEOUT_S);
31+
let deadline = self.now() + Duration::from_secs(TEST_WARN_TIMEOUT_S);
32+
if let Some(back) = self.queue.back() {
33+
assert!(back.deadline <= deadline);
34+
}
2635
self.queue.push_back(DeadlineEntry { id, test, deadline });
2736
}
2837

29-
/// Equivalent to `rx.read()`, except that if any test exceeds its deadline
38+
/// Equivalent to `rx.recv()`, except that if a test exceeds its deadline
3039
/// during the wait, the given callback will also be called for that test.
3140
pub(crate) fn read_channel_while_checking_deadlines<T>(
3241
&mut self,
3342
rx: &mpsc::Receiver<T>,
43+
is_running: impl Fn(TestId) -> bool,
3444
mut on_deadline_passed: impl FnMut(TestId, &CollectedTest),
3545
) -> Result<T, RecvError> {
3646
loop {
@@ -39,18 +49,18 @@ impl<'a> DeadlineQueue<'a> {
3949
// deadline, so do a normal receive.
4050
return rx.recv();
4151
};
42-
let wait_duration = next_deadline.saturating_duration_since(Instant::now());
52+
let next_deadline_timeout = next_deadline.saturating_duration_since(self.now());
53+
54+
let recv_result = rx.recv_timeout(next_deadline_timeout);
55+
// Process deadlines after every receive attempt, regardless of
56+
// outcome, so that we don't build up an unbounded backlog of stale
57+
// entries due to a constant stream of tests finishing.
58+
self.for_each_entry_past_deadline(&is_running, &mut on_deadline_passed);
4359

44-
let recv_result = rx.recv_timeout(wait_duration);
4560
match recv_result {
4661
Ok(value) => return Ok(value),
47-
Err(RecvTimeoutError::Timeout) => {
48-
// Notify the callback of tests that have exceeded their
49-
// deadline, then loop and do annother channel read.
50-
for DeadlineEntry { id, test, .. } in self.remove_tests_past_deadline() {
51-
on_deadline_passed(id, test);
52-
}
53-
}
62+
// Deadlines have already been processed, so loop and do another receive.
63+
Err(RecvTimeoutError::Timeout) => {}
5464
Err(RecvTimeoutError::Disconnected) => return Err(RecvError),
5565
}
5666
}
@@ -60,14 +70,28 @@ impl<'a> DeadlineQueue<'a> {
6070
Some(self.queue.front()?.deadline)
6171
}
6272

63-
fn remove_tests_past_deadline(&mut self) -> Vec<DeadlineEntry<'a>> {
64-
let now = Instant::now();
65-
let mut timed_out = vec![];
66-
while let Some(deadline_entry) = pop_front_if(&mut self.queue, |entry| now < entry.deadline)
67-
{
68-
timed_out.push(deadline_entry);
73+
fn for_each_entry_past_deadline(
74+
&mut self,
75+
is_running: impl Fn(TestId) -> bool,
76+
mut on_deadline_passed: impl FnMut(TestId, &CollectedTest),
77+
) {
78+
let now = self.now();
79+
80+
// Clear out entries that are past their deadline, but only invoke the
81+
// callback for tests that are still considered running.
82+
while let Some(entry) = pop_front_if(&mut self.queue, |entry| entry.deadline <= now) {
83+
if is_running(entry.id) {
84+
on_deadline_passed(entry.id, entry.test);
85+
}
86+
}
87+
88+
// Also clear out any leading entries that are no longer running, even
89+
// if their deadline hasn't been reached.
90+
while let Some(_) = pop_front_if(&mut self.queue, |entry| !is_running(entry.id)) {}
91+
92+
if let Some(front) = self.queue.front() {
93+
assert!(now < front.deadline);
6994
}
70-
timed_out
7195
}
7296
}
7397

src/tools/miri/tests/pass/fn_align.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@compile-flags: -Zmin-function-alignment=8
2+
#![feature(fn_align)]
3+
4+
// When a function uses `repr(align(N))`, the function address should be a multiple of `N`.
5+
6+
#[repr(align(256))]
7+
fn foo() {}
8+
9+
#[repr(align(16))]
10+
fn bar() {}
11+
12+
#[repr(align(4))]
13+
fn baz() {}
14+
15+
fn main() {
16+
assert!((foo as usize).is_multiple_of(256));
17+
assert!((bar as usize).is_multiple_of(16));
18+
19+
// The maximum of `repr(align(N))` and `-Zmin-function-alignment=N` is used.
20+
assert!((baz as usize).is_multiple_of(8));
21+
}

0 commit comments

Comments
 (0)