Skip to content

Rollup of 8 pull requests #140165

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

Merged
merged 20 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7aab011
Use posix_spawn on cygwin
Berrysoft Apr 10, 2025
2d21c14
respect `repr(align(N))` on functions in miri
folkertdev Apr 20, 2025
c0c6d42
support both trait and non-trail associated declaration
Shourya742 Apr 21, 2025
b70763e
Update books
rustbot Apr 21, 2025
b5e8f1f
improve diagnostic for raw pointer field access using `->`
Kivooeo Apr 16, 2025
a7c7119
Added test
Shourya742 Apr 21, 2025
b8ca007
move autodiff pretty test to a autodiff sub module
Shourya742 Apr 22, 2025
6be270b
Handle another negated literal in `eat_token_lit`.
nnethercote Apr 22, 2025
e7a8654
test_nan: ensure the NAN contant is quiet
RalfJung Apr 22, 2025
5717623
MANTISSA_DIGITS: explain relation to bitwise representation
RalfJung Apr 22, 2025
47a1278
add comment for "Other" case
RalfJung Apr 22, 2025
f7b1e03
compiletest: Fix deadline bugs in new executor
Zalathar Apr 19, 2025
1586660
Rollup merge of #139617 - Berrysoft:cygwin-posix-spawn, r=joboet
ChrisDenton Apr 22, 2025
8089e31
Rollup merge of #139921 - Kivooeo:master, r=WaffleLapkin
ChrisDenton Apr 22, 2025
c046a43
Rollup merge of #140031 - Zalathar:deadline, r=jieyouxu
ChrisDenton Apr 22, 2025
107f04d
Rollup merge of #140072 - folkertdev:miri-fn-align, r=RalfJung
ChrisDenton Apr 22, 2025
264249f
Rollup merge of #140104 - Shourya742:2025-04-21-auto-diff-fails-on-im…
ChrisDenton Apr 22, 2025
9471811
Rollup merge of #140124 - rustbot:docs-update, r=ehuss
ChrisDenton Apr 22, 2025
15f8847
Rollup merge of #140144 - nnethercote:fix-140098, r=petrochenkov
ChrisDenton Apr 22, 2025
2d8264f
Rollup merge of #140149 - RalfJung:test_nan, r=tgross35
ChrisDenton Apr 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions compiler/rustc_builtin_macros/src/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,12 @@ mod llvm_enzyme {
ast::StmtKind::Item(iitem) => extract_item_info(iitem),
_ => None,
},
Annotatable::AssocItem(assoc_item, Impl { of_trait: false }) => {
match &assoc_item.kind {
ast::AssocItemKind::Fn(box ast::Fn { sig, ident, .. }) => {
Some((assoc_item.vis.clone(), sig.clone(), ident.clone()))
}
_ => None,
Annotatable::AssocItem(assoc_item, Impl { .. }) => match &assoc_item.kind {
ast::AssocItemKind::Fn(box ast::Fn { sig, ident, .. }) => {
Some((assoc_item.vis.clone(), sig.clone(), ident.clone()))
}
}
_ => None,
},
_ => None,
}) else {
dcx.emit_err(errors::AutoDiffInvalidApplication { span: item.span() });
Expand Down Expand Up @@ -365,7 +363,7 @@ mod llvm_enzyme {
}
Annotatable::Item(iitem.clone())
}
Annotatable::AssocItem(ref mut assoc_item, i @ Impl { of_trait: false }) => {
Annotatable::AssocItem(ref mut assoc_item, i @ Impl { .. }) => {
if !assoc_item.attrs.iter().any(|a| same_attribute(&a.kind, &attr.kind)) {
assoc_item.attrs.push(attr);
}
Expand Down
17 changes: 15 additions & 2 deletions compiler/rustc_const_eval/src/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,21 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {

// # Function pointers
// (both global from `alloc_map` and local from `extra_fn_ptr_map`)
if self.get_fn_alloc(id).is_some() {
return AllocInfo::new(Size::ZERO, Align::ONE, AllocKind::Function, Mutability::Not);
if let Some(fn_val) = self.get_fn_alloc(id) {
let align = match fn_val {
FnVal::Instance(instance) => {
// Function alignment can be set globally with the `-Zmin-function-alignment=<n>` flag;
// the alignment from a `#[repr(align(<n>))]` is used if it specifies a higher alignment.
let fn_align = self.tcx.codegen_fn_attrs(instance.def_id()).alignment;
let global_align = self.tcx.sess.opts.unstable_opts.min_function_alignment;

Ord::max(global_align, fn_align).unwrap_or(Align::ONE)
}
// Machine-specific extra functions currently do not support alignment restrictions.
FnVal::Other(_) => Align::ONE,
};

return AllocInfo::new(Size::ZERO, align, AllocKind::Function, Mutability::Not);
}

// # Global allocations
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3289,8 +3289,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.multipart_suggestion(
format!("{val} is a raw pointer; try dereferencing it"),
vec![
(base.span.shrink_to_lo(), "(*".to_string()),
(base.span.shrink_to_hi(), ")".to_string()),
(base.span.shrink_to_lo(), "(*".into()),
(base.span.between(field.span), format!(").")),
],
Applicability::MaybeIncorrect,
);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_parse/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ parse_expected_struct_field = expected one of `,`, `:`, or `{"}"}`, found `{$tok

parse_expected_trait_in_trait_impl_found_type = expected a trait, found type

parse_expr_rarrow_call = `->` used for field access or method call
parse_expr_rarrow_call = `->` is not valid syntax for field accesses and method calls
.suggestion = try using `.` instead
.help = the `.` operator will dereference the value if needed
.help = the `.` operator will automatically dereference the value, except if the value is a raw pointer

parse_extern_crate_name_with_dashes = crate name using dashes are not valid in `extern crate` statements
.label = dash-separated idents are not valid
Expand Down
26 changes: 13 additions & 13 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,17 @@ impl<'a> Parser<'a> {
/// Keep this in sync with `Token::can_begin_literal_maybe_minus` and
/// `Lit::from_token` (excluding unary negation).
fn eat_token_lit(&mut self) -> Option<token::Lit> {
let check_expr = |expr: P<Expr>| {
if let ast::ExprKind::Lit(token_lit) = expr.kind {
Some(token_lit)
} else if let ast::ExprKind::Unary(UnOp::Neg, inner) = &expr.kind
&& let ast::Expr { kind: ast::ExprKind::Lit(_), .. } = **inner
{
None
} else {
panic!("unexpected reparsed expr/literal: {:?}", expr.kind);
}
};
match self.token.uninterpolate().kind {
token::Ident(name, IdentIsRaw::No) if name.is_bool_lit() => {
self.bump();
Expand All @@ -2159,26 +2170,15 @@ impl<'a> Parser<'a> {
let lit = self
.eat_metavar_seq(MetaVarKind::Literal, |this| this.parse_literal_maybe_minus())
.expect("metavar seq literal");
let ast::ExprKind::Lit(token_lit) = lit.kind else {
panic!("didn't reparse a literal");
};
Some(token_lit)
check_expr(lit)
}
token::OpenInvisible(InvisibleOrigin::MetaVar(
mv_kind @ MetaVarKind::Expr { can_begin_literal_maybe_minus: true, .. },
)) => {
let expr = self
.eat_metavar_seq(mv_kind, |this| this.parse_expr())
.expect("metavar seq expr");
if let ast::ExprKind::Lit(token_lit) = expr.kind {
Some(token_lit)
} else if let ast::ExprKind::Unary(UnOp::Neg, inner) = &expr.kind
&& let ast::Expr { kind: ast::ExprKind::Lit(_), .. } = **inner
{
None
} else {
panic!("unexpected reparsed expr: {:?}", expr.kind);
}
check_expr(expr)
}
_ => None,
}
Expand Down
3 changes: 3 additions & 0 deletions library/core/src/num/f128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ impl f128 {
pub const RADIX: u32 = 2;

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

Expand Down
3 changes: 3 additions & 0 deletions library/core/src/num/f16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ impl f16 {
pub const RADIX: u32 = 2;

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

Expand Down
3 changes: 3 additions & 0 deletions library/core/src/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ impl f32 {
pub const RADIX: u32 = 2;

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

Expand Down
3 changes: 3 additions & 0 deletions library/core/src/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ impl f64 {
pub const RADIX: u32 = 2;

/// Number of significant digits in base 2.
///
/// Note that the size of the mantissa in the bitwise representation is one
/// smaller than this since the leading 1 is not stored explicitly.
#[stable(feature = "assoc_int_consts", since = "1.43.0")]
pub const MANTISSA_DIGITS: u32 = 53;
/// Approximate number of significant digits in base 10.
Expand Down
8 changes: 6 additions & 2 deletions library/std/src/sys/process/unix/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ impl Command {
all(target_os = "linux", target_env = "musl"),
target_os = "nto",
target_vendor = "apple",
target_os = "cygwin",
)))]
fn posix_spawn(
&mut self,
Expand All @@ -433,6 +434,7 @@ impl Command {
all(target_os = "linux", target_env = "musl"),
target_os = "nto",
target_vendor = "apple",
target_os = "cygwin",
))]
fn posix_spawn(
&mut self,
Expand Down Expand Up @@ -584,7 +586,7 @@ impl Command {
/// Some platforms can set a new working directory for a spawned process in the
/// `posix_spawn` path. This function looks up the function pointer for adding
/// such an action to a `posix_spawn_file_actions_t` struct.
#[cfg(not(all(target_os = "linux", target_env = "musl")))]
#[cfg(not(any(all(target_os = "linux", target_env = "musl"), target_os = "cygwin")))]
fn get_posix_spawn_addchdir() -> Option<PosixSpawnAddChdirFn> {
use crate::sys::weak::weak;

Expand Down Expand Up @@ -618,7 +620,9 @@ impl Command {
/// Weak symbol lookup doesn't work with statically linked libcs, so in cases
/// where static linking is possible we need to either check for the presence
/// of the symbol at compile time or know about it upfront.
#[cfg(all(target_os = "linux", target_env = "musl"))]
///
/// Cygwin doesn't support weak symbol, so just link it.
#[cfg(any(all(target_os = "linux", target_env = "musl"), target_os = "cygwin"))]
fn get_posix_spawn_addchdir() -> Option<PosixSpawnAddChdirFn> {
// Our minimum required musl supports this function, so we can just use it.
Some(libc::posix_spawn_file_actions_addchdir_np)
Expand Down
2 changes: 2 additions & 0 deletions library/std/tests/floats/f128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ fn test_nan() {
assert!(!nan.is_sign_negative());
assert!(!nan.is_normal());
assert_eq!(Fp::Nan, nan.classify());
// Ensure the quiet bit is set.
assert!(nan.to_bits() & (1 << (f128::MANTISSA_DIGITS - 2)) != 0);
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions library/std/tests/floats/f16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ fn test_nan() {
assert!(!nan.is_sign_negative());
assert!(!nan.is_normal());
assert_eq!(Fp::Nan, nan.classify());
// Ensure the quiet bit is set.
assert!(nan.to_bits() & (1 << (f16::MANTISSA_DIGITS - 2)) != 0);
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions library/std/tests/floats/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ fn test_nan() {
assert!(nan.is_sign_positive());
assert!(!nan.is_sign_negative());
assert_eq!(Fp::Nan, nan.classify());
// Ensure the quiet bit is set.
assert!(nan.to_bits() & (1 << (f32::MANTISSA_DIGITS - 2)) != 0);
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions library/std/tests/floats/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ fn test_nan() {
assert!(nan.is_sign_positive());
assert!(!nan.is_sign_negative());
assert_eq!(Fp::Nan, nan.classify());
// Ensure the quiet bit is set.
assert!(nan.to_bits() & (1 << (f64::MANTISSA_DIGITS - 2)) != 0);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/doc/nomicon
Submodule nomicon updated 1 files
+3 −3 src/exotic-sizes.md
8 changes: 5 additions & 3 deletions src/tools/compiletest/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ pub(crate) fn run_tests(config: &Config, tests: Vec<CollectedTest>) -> bool {
}

let completion = deadline_queue
.read_channel_while_checking_deadlines(&completion_rx, |_id, test| {
listener.test_timed_out(test);
})
.read_channel_while_checking_deadlines(
&completion_rx,
|id| running_tests.contains_key(&id),
|_id, test| listener.test_timed_out(test),
)
.expect("receive channel should never be closed early");

let RunningTest { test, join_handle } = running_tests.remove(&completion.id).unwrap();
Expand Down
60 changes: 42 additions & 18 deletions src/tools/compiletest/src/executor/deadline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,26 @@ impl<'a> DeadlineQueue<'a> {
Self { queue: VecDeque::with_capacity(capacity) }
}

/// All calls to [`Instant::now`] go through this wrapper method.
/// This makes it easier to find all places that read the current time.
fn now(&self) -> Instant {
Instant::now()
}

pub(crate) fn push(&mut self, id: TestId, test: &'a CollectedTest) {
let deadline = Instant::now() + Duration::from_secs(TEST_WARN_TIMEOUT_S);
let deadline = self.now() + Duration::from_secs(TEST_WARN_TIMEOUT_S);
if let Some(back) = self.queue.back() {
assert!(back.deadline <= deadline);
}
self.queue.push_back(DeadlineEntry { id, test, deadline });
}

/// Equivalent to `rx.read()`, except that if any test exceeds its deadline
/// Equivalent to `rx.recv()`, except that if a test exceeds its deadline
/// during the wait, the given callback will also be called for that test.
pub(crate) fn read_channel_while_checking_deadlines<T>(
&mut self,
rx: &mpsc::Receiver<T>,
is_running: impl Fn(TestId) -> bool,
mut on_deadline_passed: impl FnMut(TestId, &CollectedTest),
) -> Result<T, RecvError> {
loop {
Expand All @@ -39,18 +49,18 @@ impl<'a> DeadlineQueue<'a> {
// deadline, so do a normal receive.
return rx.recv();
};
let wait_duration = next_deadline.saturating_duration_since(Instant::now());
let next_deadline_timeout = next_deadline.saturating_duration_since(self.now());

let recv_result = rx.recv_timeout(next_deadline_timeout);
// Process deadlines after every receive attempt, regardless of
// outcome, so that we don't build up an unbounded backlog of stale
// entries due to a constant stream of tests finishing.
self.for_each_entry_past_deadline(&is_running, &mut on_deadline_passed);

let recv_result = rx.recv_timeout(wait_duration);
match recv_result {
Ok(value) => return Ok(value),
Err(RecvTimeoutError::Timeout) => {
// Notify the callback of tests that have exceeded their
// deadline, then loop and do annother channel read.
for DeadlineEntry { id, test, .. } in self.remove_tests_past_deadline() {
on_deadline_passed(id, test);
}
}
// Deadlines have already been processed, so loop and do another receive.
Err(RecvTimeoutError::Timeout) => {}
Err(RecvTimeoutError::Disconnected) => return Err(RecvError),
}
}
Expand All @@ -60,14 +70,28 @@ impl<'a> DeadlineQueue<'a> {
Some(self.queue.front()?.deadline)
}

fn remove_tests_past_deadline(&mut self) -> Vec<DeadlineEntry<'a>> {
let now = Instant::now();
let mut timed_out = vec![];
while let Some(deadline_entry) = pop_front_if(&mut self.queue, |entry| now < entry.deadline)
{
timed_out.push(deadline_entry);
fn for_each_entry_past_deadline(
&mut self,
is_running: impl Fn(TestId) -> bool,
mut on_deadline_passed: impl FnMut(TestId, &CollectedTest),
) {
let now = self.now();

// Clear out entries that are past their deadline, but only invoke the
// callback for tests that are still considered running.
while let Some(entry) = pop_front_if(&mut self.queue, |entry| entry.deadline <= now) {
if is_running(entry.id) {
on_deadline_passed(entry.id, entry.test);
}
}

// Also clear out any leading entries that are no longer running, even
// if their deadline hasn't been reached.
while let Some(_) = pop_front_if(&mut self.queue, |entry| !is_running(entry.id)) {}

if let Some(front) = self.queue.front() {
assert!(now < front.deadline);
}
timed_out
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/tools/miri/tests/pass/fn_align.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//@compile-flags: -Zmin-function-alignment=8
#![feature(fn_align)]

// When a function uses `repr(align(N))`, the function address should be a multiple of `N`.

#[repr(align(256))]
fn foo() {}

#[repr(align(16))]
fn bar() {}

#[repr(align(4))]
fn baz() {}

fn main() {
assert!((foo as usize).is_multiple_of(256));
assert!((bar as usize).is_multiple_of(16));

// The maximum of `repr(align(N))` and `-Zmin-function-alignment=N` is used.
assert!((baz as usize).is_multiple_of(8));
}
Loading
Loading