Skip to content

Commit 063d993

Browse files
committed
Auto merge of #146575 - Zalathar:rollup-m6p4yrm, r=Zalathar
Rollup of 8 pull requests Successful merges: - #146402 (interpret: fix overlapping aggregate initialization) - #146530 (rustc_codegen_llvm: Adjust RISC-V inline assembly's clobber list) - #146533 (Note some previous attempts to change the Default impl for `[T; 0]`) - #146539 (fix 404 MCP link) - #146546 (Switch `std::vec::PeekMut::pop` from self to this parameter.) - #146549 (On FreeBSD, use readdir instead of readdir_r) - #146559 (Fix typo in error message) - #146563 (bootstrap.py: disable incremental build for bootstrap in CI) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d1ed52b + f7e67c2 commit 063d993

30 files changed

+179
-86
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ Shohei Wada <[email protected]>
609609
Shotaro Yamada <[email protected]>
610610
611611
Shyam Sundar B <[email protected]>
612+
612613
Simon Barber-Dueck <[email protected]> Simon BD <simon@server>
613614
614615
Simonas Kazlauskas <[email protected]> Simonas Kazlauskas <[email protected]>

compiler/rustc_codegen_llvm/src/asm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
240240
}
241241
InlineAsmArch::RiscV32 | InlineAsmArch::RiscV64 => {
242242
constraints.extend_from_slice(&[
243+
"~{fflags}".to_string(),
243244
"~{vtype}".to_string(),
244245
"~{vl}".to_string(),
245246
"~{vxsat}".to_string(),

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use itertools::Itertools as _;
2-
use rustc_abi::{self as abi, FIRST_VARIANT};
2+
use rustc_abi::{self as abi, BackendRepr, FIRST_VARIANT};
33
use rustc_middle::ty::adjustment::PointerCoercion;
44
use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutOf, TyAndLayout};
55
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
@@ -25,6 +25,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
2525
match *rvalue {
2626
mir::Rvalue::Use(ref operand) => {
2727
let cg_operand = self.codegen_operand(bx, operand);
28+
// Crucially, we do *not* use `OperandValue::Ref` for types with
29+
// `BackendRepr::Scalar | BackendRepr::ScalarPair`. This ensures we match the MIR
30+
// semantics regarding when assignment operators allow overlap of LHS and RHS.
31+
if matches!(
32+
cg_operand.layout.backend_repr,
33+
BackendRepr::Scalar(..) | BackendRepr::ScalarPair(..),
34+
) {
35+
debug_assert!(!matches!(cg_operand.val, OperandValue::Ref(..)));
36+
}
2837
// FIXME: consider not copying constants through stack. (Fixable by codegen'ing
2938
// constants into `OperandValue::Ref`; why don’t we do that yet if we don’t?)
3039
cg_operand.val.store(bx, dest);

compiler/rustc_const_eval/src/interpret/place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ where
858858
/// Also, if you use this you are responsible for validating that things get copied at the
859859
/// right type.
860860
#[instrument(skip(self), level = "trace")]
861-
fn copy_op_no_validate(
861+
pub(super) fn copy_op_no_validate(
862862
&mut self,
863863
src: &impl Projectable<'tcx, M::Provenance>,
864864
dest: &impl Writeable<'tcx, M::Provenance>,

compiler/rustc_const_eval/src/interpret/step.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
310310
operands: &IndexSlice<FieldIdx, mir::Operand<'tcx>>,
311311
dest: &PlaceTy<'tcx, M::Provenance>,
312312
) -> InterpResult<'tcx> {
313-
self.write_uninit(dest)?; // make sure all the padding ends up as uninit
314313
let (variant_index, variant_dest, active_field_index) = match *kind {
315314
mir::AggregateKind::Adt(_, variant_index, _, _, active_field_index) => {
316315
let variant_dest = self.project_downcast(dest, variant_index)?;
@@ -346,9 +345,20 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
346345
let field_index = active_field_index.unwrap_or(field_index);
347346
let field_dest = self.project_field(&variant_dest, field_index)?;
348347
let op = self.eval_operand(operand, Some(field_dest.layout))?;
349-
self.copy_op(&op, &field_dest)?;
348+
// We validate manually below so we don't have to do it here.
349+
self.copy_op_no_validate(&op, &field_dest, /*allow_transmute*/ false)?;
350350
}
351-
self.write_discriminant(variant_index, dest)
351+
self.write_discriminant(variant_index, dest)?;
352+
// Validate that the entire thing is valid, and reset padding that might be in between the
353+
// fields.
354+
if M::enforce_validity(self, dest.layout()) {
355+
self.validate_operand(
356+
dest,
357+
M::enforce_validity_recursively(self, dest.layout()),
358+
/*reset_provenance_and_padding*/ true,
359+
)?;
360+
}
361+
interp_ok(())
352362
}
353363

354364
/// Repeats `operand` into the destination. `dest` must have array type, and that type

compiler/rustc_middle/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ middle_failed_writing_file =
8484
# Note: We only mention patterns here since the error can only occur with references, and those
8585
# are forbidden in const generics.
8686
middle_invalid_const_in_valtree = constant {$global_const_id} cannot be used as pattern
87-
.note = constants that reference mutable or external memory cannot be used as pattern
87+
.note = constants that reference mutable or external memory cannot be used as patterns
8888
8989
middle_layout_cycle =
9090
a cycle occurred during layout computation

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,11 @@ pub enum StatementKind<'tcx> {
327327
/// interesting for optimizations? Do we want to allow such optimizations?
328328
///
329329
/// **Needs clarification**: We currently require that the LHS place not overlap with any place
330-
/// read as part of computation of the RHS for some rvalues (generally those not producing
331-
/// primitives). This requirement is under discussion in [#68364]. As a part of this discussion,
332-
/// it is also unclear in what order the components are evaluated.
330+
/// read as part of computation of the RHS for some rvalues. This requirement is under
331+
/// discussion in [#68364]. Specifically, overlap is permitted only for assignments of a type
332+
/// with `BackendRepr::Scalar | BackendRepr::ScalarPair` where all the scalar fields are
333+
/// [`Scalar::Initialized`][rustc_abi::Scalar::Initialized]. As a part of this discussion, it is
334+
/// also unclear in what order the components are evaluated.
333335
///
334336
/// [#68364]: https://github.com/rust-lang/rust/issues/68364
335337
///

library/alloc/src/vec/peek_mut.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ impl<'a, T> PeekMut<'a, T> {
2929

3030
/// Removes the peeked value from the vector and returns it.
3131
#[unstable(feature = "vec_peek_mut", issue = "122742")]
32-
pub fn pop(self) -> T {
32+
pub fn pop(this: Self) -> T {
3333
// SAFETY: PeekMut is only constructed if the vec is non-empty
34-
unsafe { self.vec.pop().unwrap_unchecked() }
34+
unsafe { this.vec.pop().unwrap_unchecked() }
3535
}
3636
}
3737

library/alloctests/tests/vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::ops::Bound::*;
1515
use std::panic::{AssertUnwindSafe, catch_unwind};
1616
use std::rc::Rc;
1717
use std::sync::atomic::{AtomicU32, Ordering};
18-
use std::vec::{Drain, IntoIter};
18+
use std::vec::{Drain, IntoIter, PeekMut};
1919

2020
use crate::testing::macros::struct_with_counted_drop;
2121

@@ -2647,7 +2647,7 @@ fn test_peek_mut() {
26472647
assert_eq!(*p, 2);
26482648
*p = 0;
26492649
assert_eq!(*p, 0);
2650-
p.pop();
2650+
PeekMut::pop(p);
26512651
assert_eq!(vec.len(), 1);
26522652
} else {
26532653
unreachable!()

library/core/src/array/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,11 @@ impl<T: Copy> SpecArrayClone for T {
472472
// The Default impls cannot be done with const generics because `[T; 0]` doesn't
473473
// require Default to be implemented, and having different impl blocks for
474474
// different numbers isn't supported yet.
475+
//
476+
// Trying to improve the `[T; 0]` situation has proven to be difficult.
477+
// Please see these issues for more context on past attempts and crater runs:
478+
// - https://github.com/rust-lang/rust/issues/61415
479+
// - https://github.com/rust-lang/rust/pull/145457
475480

476481
macro_rules! array_impl_default {
477482
{$n:expr, $t:ident $($ts:ident)*} => {

0 commit comments

Comments
 (0)