Skip to content

Commit 9f22ddf

Browse files
committed
Auto merge of #61915 - Centril:rollup-oire3i8, r=Centril
Rollup of 5 pull requests Successful merges: - #61702 (test more variants of enum-int-casting) - #61836 (Replace some uses of NodeId with HirId) - #61885 (Help LLVM better optimize slice::Iter(Mut)::len) - #61893 (make `Weak::ptr_eq`s into methods) - #61908 (don't ICE on large files) Failed merges: r? @ghost
2 parents b25ee64 + 6fe2653 commit 9f22ddf

Some content is hidden

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

84 files changed

+357
-404
lines changed

src/liballoc/rc.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1515,18 +1515,18 @@ impl<T: ?Sized> Weak<T> {
15151515
///
15161516
/// ```
15171517
/// #![feature(weak_ptr_eq)]
1518-
/// use std::rc::{Rc, Weak};
1518+
/// use std::rc::Rc;
15191519
///
15201520
/// let first_rc = Rc::new(5);
15211521
/// let first = Rc::downgrade(&first_rc);
15221522
/// let second = Rc::downgrade(&first_rc);
15231523
///
1524-
/// assert!(Weak::ptr_eq(&first, &second));
1524+
/// assert!(first.ptr_eq(&second));
15251525
///
15261526
/// let third_rc = Rc::new(5);
15271527
/// let third = Rc::downgrade(&third_rc);
15281528
///
1529-
/// assert!(!Weak::ptr_eq(&first, &third));
1529+
/// assert!(!first.ptr_eq(&third));
15301530
/// ```
15311531
///
15321532
/// Comparing `Weak::new`.
@@ -1537,16 +1537,16 @@ impl<T: ?Sized> Weak<T> {
15371537
///
15381538
/// let first = Weak::new();
15391539
/// let second = Weak::new();
1540-
/// assert!(Weak::ptr_eq(&first, &second));
1540+
/// assert!(first.ptr_eq(&second));
15411541
///
15421542
/// let third_rc = Rc::new(());
15431543
/// let third = Rc::downgrade(&third_rc);
1544-
/// assert!(!Weak::ptr_eq(&first, &third));
1544+
/// assert!(!first.ptr_eq(&third));
15451545
/// ```
15461546
#[inline]
15471547
#[unstable(feature = "weak_ptr_eq", issue = "55981")]
1548-
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
1549-
this.ptr.as_ptr() == other.ptr.as_ptr()
1548+
pub fn ptr_eq(&self, other: &Self) -> bool {
1549+
self.ptr.as_ptr() == other.ptr.as_ptr()
15501550
}
15511551
}
15521552

src/liballoc/sync.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1349,18 +1349,18 @@ impl<T: ?Sized> Weak<T> {
13491349
///
13501350
/// ```
13511351
/// #![feature(weak_ptr_eq)]
1352-
/// use std::sync::{Arc, Weak};
1352+
/// use std::sync::Arc;
13531353
///
13541354
/// let first_rc = Arc::new(5);
13551355
/// let first = Arc::downgrade(&first_rc);
13561356
/// let second = Arc::downgrade(&first_rc);
13571357
///
1358-
/// assert!(Weak::ptr_eq(&first, &second));
1358+
/// assert!(first.ptr_eq(&second));
13591359
///
13601360
/// let third_rc = Arc::new(5);
13611361
/// let third = Arc::downgrade(&third_rc);
13621362
///
1363-
/// assert!(!Weak::ptr_eq(&first, &third));
1363+
/// assert!(!first.ptr_eq(&third));
13641364
/// ```
13651365
///
13661366
/// Comparing `Weak::new`.
@@ -1371,16 +1371,16 @@ impl<T: ?Sized> Weak<T> {
13711371
///
13721372
/// let first = Weak::new();
13731373
/// let second = Weak::new();
1374-
/// assert!(Weak::ptr_eq(&first, &second));
1374+
/// assert!(first.ptr_eq(&second));
13751375
///
13761376
/// let third_rc = Arc::new(());
13771377
/// let third = Arc::downgrade(&third_rc);
1378-
/// assert!(!Weak::ptr_eq(&first, &third));
1378+
/// assert!(!first.ptr_eq(&third));
13791379
/// ```
13801380
#[inline]
13811381
#[unstable(feature = "weak_ptr_eq", issue = "55981")]
1382-
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
1383-
this.ptr.as_ptr() == other.ptr.as_ptr()
1382+
pub fn ptr_eq(&self, other: &Self) -> bool {
1383+
self.ptr.as_ptr() == other.ptr.as_ptr()
13841384
}
13851385
}
13861386

src/libcore/intrinsics.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1607,3 +1607,9 @@ pub fn maxnumf64(x: f64, y: f64) -> f64 {
16071607
// Identical to the `f32` case.
16081608
(if x < y || x != x { y } else { x }) * 1.0
16091609
}
1610+
1611+
/// For bootstrapping, implement unchecked_sub as just wrapping_sub.
1612+
#[cfg(bootstrap)]
1613+
pub unsafe fn unchecked_sub<T>(x: T, y: T) -> T {
1614+
sub_with_overflow(x, y).0
1615+
}

src/libcore/slice/mod.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
use crate::cmp::Ordering::{self, Less, Equal, Greater};
2626
use crate::cmp;
2727
use crate::fmt;
28-
use crate::intrinsics::assume;
28+
use crate::intrinsics::{assume, exact_div, unchecked_sub};
2929
use crate::isize;
3030
use crate::iter::*;
3131
use crate::ops::{FnMut, Try, self};
@@ -2998,14 +2998,27 @@ macro_rules! is_empty {
29982998
// unexpected way. (Tested by `codegen/slice-position-bounds-check`.)
29992999
macro_rules! len {
30003000
($self: ident) => {{
3001+
#![allow(unused_unsafe)] // we're sometimes used within an unsafe block
3002+
30013003
let start = $self.ptr;
3002-
let diff = ($self.end as usize).wrapping_sub(start as usize);
30033004
let size = size_from_ptr(start);
30043005
if size == 0 {
3006+
// This _cannot_ use `unchecked_sub` because we depend on wrapping
3007+
// to represent the length of long ZST slice iterators.
3008+
let diff = ($self.end as usize).wrapping_sub(start as usize);
30053009
diff
30063010
} else {
3007-
// Using division instead of `offset_from` helps LLVM remove bounds checks
3008-
diff / size
3011+
// We know that `start <= end`, so can do better than `offset_from`,
3012+
// which needs to deal in signed. By setting appropriate flags here
3013+
// we can tell LLVM this, which helps it remove bounds checks.
3014+
// SAFETY: By the type invariant, `start <= end`
3015+
let diff = unsafe { unchecked_sub($self.end as usize, start as usize) };
3016+
// By also telling LLVM that the pointers are apart by an exact
3017+
// multiple of the type size, it can optimize `len() == 0` down to
3018+
// `start == end` instead of `(end - start) < size`.
3019+
// SAFETY: By the type invariant, the pointers are aligned so the
3020+
// distance between them must be a multiple of pointee size
3021+
unsafe { exact_div(diff, size) }
30093022
}
30103023
}}
30113024
}

src/librustc/cfg/construct.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn construct<'tcx>(tcx: TyCtxt<'tcx>, body: &hir::Body) -> CFG {
4242
let body_exit;
4343

4444
// Find the tables for this body.
45-
let owner_def_id = tcx.hir().local_def_id(tcx.hir().body_owner(body.id()));
45+
let owner_def_id = tcx.hir().body_owner_def_id(body.id());
4646
let tables = tcx.typeck_tables_of(owner_def_id);
4747

4848
let mut cfg_builder = CFGBuilder {
@@ -357,7 +357,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
357357
args: I) -> CFGIndex {
358358
let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);
359359
let ret = self.straightline(call_expr, func_or_rcvr_exit, args);
360-
let m = self.tcx.hir().get_module_parent_by_hir_id(call_expr.hir_id);
360+
let m = self.tcx.hir().get_module_parent(call_expr.hir_id);
361361
if self.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(call_expr)) {
362362
self.add_unreachable_node()
363363
} else {

src/librustc/cfg/graphviz.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ pub struct LabelledCFG<'a, 'tcx: 'a> {
2222
impl<'a, 'tcx> LabelledCFG<'a, 'tcx> {
2323
fn local_id_to_string(&self, local_id: hir::ItemLocalId) -> String {
2424
assert!(self.cfg.owner_def_id.is_local());
25-
let node_id = self.tcx.hir().hir_to_node_id(hir::HirId {
25+
let hir_id = hir::HirId {
2626
owner: self.tcx.hir().def_index_to_hir_id(self.cfg.owner_def_id.index).owner,
2727
local_id
28-
});
29-
let s = self.tcx.hir().node_to_string(node_id);
28+
};
29+
let s = self.tcx.hir().node_to_string(hir_id);
3030

3131
// Replacing newlines with \\l causes each line to be left-aligned,
3232
// improving presentation of (long) pretty-printed expressions.

src/librustc/hir/intravisit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ pub trait Visitor<'v> : Sized {
171171
/// but cannot supply a `Map`; see `nested_visit_map` for advice.
172172
#[allow(unused_variables)]
173173
fn visit_nested_item(&mut self, id: ItemId) {
174-
let opt_item = self.nested_visit_map().inter().map(|map| map.expect_item_by_hir_id(id.id));
174+
let opt_item = self.nested_visit_map().inter().map(|map| map.expect_item(id.id));
175175
if let Some(item) = opt_item {
176176
self.visit_item(item);
177177
}

src/librustc/hir/map/hir_id_validator.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX};
22
use crate::hir::{self, intravisit, HirId, ItemLocalId};
3-
use syntax::ast::NodeId;
43
use crate::hir::itemlikevisit::ItemLikeVisitor;
54
use rustc_data_structures::fx::FxHashSet;
65
use rustc_data_structures::sync::{Lock, ParallelIterator, par_iter};
@@ -112,19 +111,9 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> {
112111

113112
trace!("missing hir id {:#?}", hir_id);
114113

115-
// We are already in ICE mode here, so doing a linear search
116-
// should be fine.
117-
let (node_id, _) = self.hir_map
118-
.definitions()
119-
.node_to_hir_id
120-
.iter()
121-
.enumerate()
122-
.find(|&(_, &entry)| hir_id == entry)
123-
.expect("no node_to_hir_id entry");
124-
let node_id = NodeId::from_usize(node_id);
125114
missing_items.push(format!("[local_id: {}, node:{}]",
126115
local_id,
127-
self.hir_map.node_to_string(node_id)));
116+
self.hir_map.node_to_string(hir_id)));
128117
}
129118
self.error(|| format!(
130119
"ItemLocalIds not assigned densely in {}. \
@@ -138,7 +127,7 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> {
138127
owner: owner_def_index,
139128
local_id,
140129
})
141-
.map(|h| format!("({:?} {})", h, self.hir_map.hir_to_string(h)))
130+
.map(|h| format!("({:?} {})", h, self.hir_map.node_to_string(h)))
142131
.collect::<Vec<_>>()));
143132
}
144133
}
@@ -156,14 +145,14 @@ impl<'a, 'hir: 'a> intravisit::Visitor<'hir> for HirIdValidator<'a, 'hir> {
156145

157146
if hir_id == hir::DUMMY_HIR_ID {
158147
self.error(|| format!("HirIdValidator: HirId {:?} is invalid",
159-
self.hir_map.hir_to_string(hir_id)));
148+
self.hir_map.node_to_string(hir_id)));
160149
return;
161150
}
162151

163152
if owner != hir_id.owner {
164153
self.error(|| format!(
165154
"HirIdValidator: The recorded owner of {} is {} instead of {}",
166-
self.hir_map.hir_to_string(hir_id),
155+
self.hir_map.node_to_string(hir_id),
167156
self.hir_map.def_path(DefId::local(hir_id.owner)).to_string_no_crate(),
168157
self.hir_map.def_path(DefId::local(owner)).to_string_no_crate()));
169158
}

0 commit comments

Comments
 (0)