Skip to content

Commit 85fbb57

Browse files
committed
Auto merge of #114553 - matthiaskrgr:rollup-5yddunv, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #114466 (Add Allocation to SMIR) - #114505 (Add documentation to has_deref) - #114519 (use offset_of! to calculate dirent64 field offsets) - #114537 (Migrate GUI colors test to original CSS color format) - #114539 (linkchecker: Remove unneeded FIXME about intra-doc links) Failed merges: - #114485 (Add trait decls to SMIR) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5973bfb + f542163 commit 85fbb57

File tree

13 files changed

+82
-46
lines changed

13 files changed

+82
-46
lines changed

compiler/rustc_codegen_ssa/src/mir/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
441441
LocalRef::Place(place) => place,
442442
LocalRef::UnsizedPlace(place) => bx.load_operand(place).deref(cx),
443443
LocalRef::Operand(..) => {
444-
if place_ref.has_deref() {
444+
if place_ref.is_indirect_first_projection() {
445445
base = 1;
446446
let cg_base = self.codegen_consume(
447447
bx,

compiler/rustc_const_eval/src/interpret/step.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
247247

248248
AddressOf(_, place) => {
249249
// Figure out whether this is an addr_of of an already raw place.
250-
let place_base_raw = if place.has_deref() {
250+
let place_base_raw = if place.is_indirect_first_projection() {
251251
let ty = self.frame().body.local_decls[place.local].ty;
252252
ty.is_unsafe_ptr()
253253
} else {

compiler/rustc_middle/src/mir/mod.rs

+17-11
Original file line numberDiff line numberDiff line change
@@ -1592,14 +1592,13 @@ impl<'tcx> Place<'tcx> {
15921592
self.projection.iter().any(|elem| elem.is_indirect())
15931593
}
15941594

1595-
/// If MirPhase >= Derefered and if projection contains Deref,
1596-
/// It's guaranteed to be in the first place
1597-
pub fn has_deref(&self) -> bool {
1598-
// To make sure this is not accidentally used in wrong mir phase
1599-
debug_assert!(
1600-
self.projection.is_empty() || !self.projection[1..].contains(&PlaceElem::Deref)
1601-
);
1602-
self.projection.first() == Some(&PlaceElem::Deref)
1595+
/// Returns `true` if this `Place`'s first projection is `Deref`.
1596+
///
1597+
/// This is useful because for MIR phases `AnalysisPhase::PostCleanup` and later,
1598+
/// `Deref` projections can only occur as the first projection. In that case this method
1599+
/// is equivalent to `is_indirect`, but faster.
1600+
pub fn is_indirect_first_projection(&self) -> bool {
1601+
self.as_ref().is_indirect_first_projection()
16031602
}
16041603

16051604
/// Finds the innermost `Local` from this `Place`, *if* it is either a local itself or
@@ -1672,9 +1671,16 @@ impl<'tcx> PlaceRef<'tcx> {
16721671
self.projection.iter().any(|elem| elem.is_indirect())
16731672
}
16741673

1675-
/// If MirPhase >= Derefered and if projection contains Deref,
1676-
/// It's guaranteed to be in the first place
1677-
pub fn has_deref(&self) -> bool {
1674+
/// Returns `true` if this `Place`'s first projection is `Deref`.
1675+
///
1676+
/// This is useful because for MIR phases `AnalysisPhase::PostCleanup` and later,
1677+
/// `Deref` projections can only occur as the first projection. In that case this method
1678+
/// is equivalent to `is_indirect`, but faster.
1679+
pub fn is_indirect_first_projection(&self) -> bool {
1680+
// To make sure this is not accidentally used in wrong mir phase
1681+
debug_assert!(
1682+
self.projection.is_empty() || !self.projection[1..].contains(&PlaceElem::Deref)
1683+
);
16781684
self.projection.first() == Some(&PlaceElem::Deref)
16791685
}
16801686

compiler/rustc_mir_dataflow/src/value_analysis.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ impl Map {
839839
tail_elem: Option<TrackElem>,
840840
f: &mut impl FnMut(ValueIndex),
841841
) {
842-
if place.has_deref() {
842+
if place.is_indirect_first_projection() {
843843
// We do not track indirect places.
844844
return;
845845
}

compiler/rustc_mir_transform/src/add_retag.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<'tcx> MirPass<'tcx> for AddRetag {
6060
let basic_blocks = body.basic_blocks.as_mut();
6161
let local_decls = &body.local_decls;
6262
let needs_retag = |place: &Place<'tcx>| {
63-
!place.has_deref() // we're not really interested in stores to "outside" locations, they are hard to keep track of anyway
63+
!place.is_indirect_first_projection() // we're not really interested in stores to "outside" locations, they are hard to keep track of anyway
6464
&& may_contain_reference(place.ty(&*local_decls, tcx).ty, /*depth*/ 3, tcx)
6565
&& !local_decls[place.local].is_deref_temp()
6666
};

compiler/rustc_mir_transform/src/copy_prop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
154154
fn visit_operand(&mut self, operand: &mut Operand<'tcx>, loc: Location) {
155155
if let Operand::Move(place) = *operand
156156
// A move out of a projection of a copy is equivalent to a copy of the original projection.
157-
&& !place.has_deref()
157+
&& !place.is_indirect_first_projection()
158158
&& !self.fully_moved.contains(place.local)
159159
{
160160
*operand = Operand::Copy(place);

compiler/rustc_smir/src/rustc_smir/mod.rs

+31
Original file line numberDiff line numberDiff line change
@@ -1063,3 +1063,34 @@ impl<'tcx> Stable<'tcx> for rustc_middle::ty::BoundTy {
10631063
BoundTy { var: self.var.as_usize(), kind: self.kind.stable(tables) }
10641064
}
10651065
}
1066+
1067+
impl<'tcx> Stable<'tcx> for mir::interpret::Allocation {
1068+
type T = stable_mir::ty::Allocation;
1069+
1070+
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
1071+
let size = self.size();
1072+
let mut bytes: Vec<Option<u8>> = self
1073+
.inspect_with_uninit_and_ptr_outside_interpreter(0..size.bytes_usize())
1074+
.iter()
1075+
.copied()
1076+
.map(Some)
1077+
.collect();
1078+
for (i, b) in bytes.iter_mut().enumerate() {
1079+
if !self.init_mask().get(rustc_target::abi::Size::from_bytes(i)) {
1080+
*b = None;
1081+
}
1082+
}
1083+
stable_mir::ty::Allocation {
1084+
bytes: bytes,
1085+
provenance: {
1086+
let mut ptrs = Vec::new();
1087+
for (size, prov) in self.provenance().ptrs().iter() {
1088+
ptrs.push((size.bytes_usize(), opaque(prov)));
1089+
}
1090+
stable_mir::ty::ProvenanceMap { ptrs }
1091+
},
1092+
align: self.align.bytes(),
1093+
mutability: self.mutability.stable(tables),
1094+
}
1095+
}
1096+
}

compiler/rustc_smir/src/stable_mir/ty.rs

+22
Original file line numberDiff line numberDiff line change
@@ -242,3 +242,25 @@ pub struct BoundTy {
242242
pub var: usize,
243243
pub kind: BoundTyKind,
244244
}
245+
246+
pub type Bytes = Vec<Option<u8>>;
247+
pub type Size = usize;
248+
pub type Prov = Opaque;
249+
pub type Align = u64;
250+
pub type InitMaskMaterialized = Vec<u64>;
251+
252+
/// Stores the provenance information of pointers stored in memory.
253+
#[derive(Clone, Debug)]
254+
pub struct ProvenanceMap {
255+
/// Provenance in this map applies from the given offset for an entire pointer-size worth of
256+
/// bytes. Two entries in this map are always at least a pointer size apart.
257+
pub ptrs: Vec<(Size, Prov)>,
258+
}
259+
260+
#[derive(Clone, Debug)]
261+
pub struct Allocation {
262+
pub bytes: Bytes,
263+
pub provenance: ProvenanceMap,
264+
pub align: Align,
265+
pub mutability: Mutability,
266+
}

library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@
298298
#![feature(maybe_uninit_slice)]
299299
#![feature(maybe_uninit_uninit_array)]
300300
#![feature(maybe_uninit_write_slice)]
301+
#![feature(offset_of)]
301302
#![feature(panic_can_unwind)]
302303
#![feature(panic_info_message)]
303304
#![feature(panic_internals)]

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

+2-25
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,6 @@ use crate::ffi::{CStr, OsStr, OsString};
77
use crate::fmt;
88
use crate::io::{self, BorrowedCursor, Error, IoSlice, IoSliceMut, SeekFrom};
99
use crate::mem;
10-
#[cfg(any(
11-
target_os = "android",
12-
target_os = "linux",
13-
target_os = "solaris",
14-
target_os = "fuchsia",
15-
target_os = "redox",
16-
target_os = "illumos",
17-
target_os = "nto",
18-
target_os = "vita",
19-
))]
20-
use crate::mem::MaybeUninit;
2110
use crate::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd};
2211
use crate::path::{Path, PathBuf};
2312
use crate::ptr;
@@ -712,22 +701,10 @@ impl Iterator for ReadDir {
712701
// requires the full extent of *entry_ptr to be in bounds of the same
713702
// allocation, which is not necessarily the case here.
714703
//
715-
// Absent any other way to obtain a pointer to `(*entry_ptr).d_name`
716-
// legally in Rust analogously to how it would be done in C, we instead
717-
// need to make our own non-libc allocation that conforms to the weird
718-
// imaginary definition of dirent64, and use that for a field offset
719-
// computation.
704+
// Instead we must access fields individually through their offsets.
720705
macro_rules! offset_ptr {
721706
($entry_ptr:expr, $field:ident) => {{
722-
const OFFSET: isize = {
723-
let delusion = MaybeUninit::<dirent64>::uninit();
724-
let entry_ptr = delusion.as_ptr();
725-
unsafe {
726-
ptr::addr_of!((*entry_ptr).$field)
727-
.cast::<u8>()
728-
.offset_from(entry_ptr.cast::<u8>())
729-
}
730-
};
707+
const OFFSET: isize = mem::offset_of!(dirent64, $field) as isize;
731708
if true {
732709
// Cast to the same type determined by the else branch.
733710
$entry_ptr.byte_offset(OFFSET).cast::<_>()

src/tools/clippy/clippy_lints/src/dereference.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ fn referent_used_exactly_once<'tcx>(
11701170
&& let [location] = *local_assignments(mir, local).as_slice()
11711171
&& let Some(statement) = mir.basic_blocks[location.block].statements.get(location.statement_index)
11721172
&& let StatementKind::Assign(box (_, Rvalue::Ref(_, _, place))) = statement.kind
1173-
&& !place.has_deref()
1173+
&& !place.is_indirect_first_projection()
11741174
// Ensure not in a loop (https://github.com/rust-lang/rust-clippy/issues/9710)
11751175
&& TriColorDepthFirstSearch::new(&mir.basic_blocks).run_from(location.block, &mut CycleDetector).is_none()
11761176
{

src/tools/linkchecker/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ impl Checker {
368368
return;
369369
}
370370
// Search for intra-doc links that rustdoc didn't warn about
371-
// FIXME(#77199, 77200) Rustdoc should just warn about these directly.
372371
// NOTE: only looks at one line at a time; in practice this should find most links
373372
for (i, line) in source.lines().enumerate() {
374373
for broken_link in BROKEN_INTRA_DOC_LINK.captures_iter(line) {

tests/rustdoc-gui/search-error.goml

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,20 @@ call-function: (
2020
"check-colors",
2121
{
2222
"theme": "ayu",
23-
"error_background": "rgb(79, 76, 76)",
23+
"error_background": "#4f4c4c",
2424
},
2525
)
2626
call-function: (
2727
"check-colors",
2828
{
2929
"theme": "dark",
30-
"error_background": "rgb(72, 72, 72)",
30+
"error_background": "#484848",
3131
},
3232
)
3333
call-function: (
3434
"check-colors",
3535
{
3636
"theme": "light",
37-
"error_background": "rgb(208, 204, 204)",
37+
"error_background": "#d0cccc",
3838
},
3939
)

0 commit comments

Comments
 (0)