Skip to content

Commit caeb333

Browse files
committed
Auto merge of #80114 - GuillaumeGomez:rollup-gszr5kn, r=GuillaumeGomez
Rollup of 5 pull requests Successful merges: - #80006 (BTreeMap: more expressive local variables in merge) - #80022 (BTreeSet: simplify implementation of pop_first/pop_last) - #80035 (Optimization for bool's PartialOrd impl) - #80040 (Always run intrinsics lowering pass) - #80047 (Use more symbols in rustdoc) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 001bd77 + 5873fe8 commit caeb333

21 files changed

+97
-100
lines changed

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
8383
return;
8484
}
8585

86-
sym::unreachable => {
87-
return;
88-
}
8986
sym::va_start => bx.va_start(args[0].immediate()),
9087
sym::va_end => bx.va_end(args[0].immediate()),
9188
sym::size_of_val => {
@@ -106,8 +103,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
106103
bx.const_usize(bx.layout_of(tp_ty).align.abi.bytes())
107104
}
108105
}
109-
sym::size_of
110-
| sym::pref_align_of
106+
sym::pref_align_of
111107
| sym::min_align_of
112108
| sym::needs_drop
113109
| sym::type_id
@@ -119,10 +115,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
119115
.unwrap();
120116
OperandRef::from_const(bx, value, ret_ty).immediate_or_packed_pair(bx)
121117
}
122-
// Effectively no-op
123-
sym::forget => {
124-
return;
125-
}
126118
sym::offset => {
127119
let ptr = args[0].immediate();
128120
let offset = args[1].immediate();
@@ -218,9 +210,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
218210
sym::add_with_overflow
219211
| sym::sub_with_overflow
220212
| sym::mul_with_overflow
221-
| sym::wrapping_add
222-
| sym::wrapping_sub
223-
| sym::wrapping_mul
224213
| sym::unchecked_div
225214
| sym::unchecked_rem
226215
| sym::unchecked_shl
@@ -254,9 +243,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
254243

255244
return;
256245
}
257-
sym::wrapping_add => bx.add(args[0].immediate(), args[1].immediate()),
258-
sym::wrapping_sub => bx.sub(args[0].immediate(), args[1].immediate()),
259-
sym::wrapping_mul => bx.mul(args[0].immediate(), args[1].immediate()),
260246
sym::exact_div => {
261247
if signed {
262248
bx.exactsdiv(args[0].immediate(), args[1].immediate())

compiler/rustc_mir/src/interpret/intrinsics.rs

+8-23
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,11 @@ crate fn eval_nullary_intrinsic<'tcx>(
6161
ConstValue::Slice { data: alloc, start: 0, end: alloc.len() }
6262
}
6363
sym::needs_drop => ConstValue::from_bool(tp_ty.needs_drop(tcx, param_env)),
64-
sym::size_of | sym::min_align_of | sym::pref_align_of => {
64+
sym::min_align_of | sym::pref_align_of => {
6565
let layout = tcx.layout_of(param_env.and(tp_ty)).map_err(|e| err_inval!(Layout(e)))?;
6666
let n = match name {
6767
sym::pref_align_of => layout.align.pref.bytes(),
6868
sym::min_align_of => layout.align.abi.bytes(),
69-
sym::size_of => layout.size.bytes(),
7069
_ => bug!(),
7170
};
7271
ConstValue::from_machine_usize(n, &tcx)
@@ -125,7 +124,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
125124
let (dest, ret) = match ret {
126125
None => match intrinsic_name {
127126
sym::transmute => throw_ub_format!("transmuting to uninhabited type"),
128-
sym::unreachable => throw_ub!(Unreachable),
129127
sym::abort => M::abort(self, "the program aborted execution".to_owned())?,
130128
// Unsupported diverging intrinsic.
131129
_ => return Ok(false),
@@ -160,13 +158,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
160158
sym::min_align_of
161159
| sym::pref_align_of
162160
| sym::needs_drop
163-
| sym::size_of
164161
| sym::type_id
165162
| sym::type_name
166163
| sym::variant_count => {
167164
let gid = GlobalId { instance, promoted: None };
168165
let ty = match intrinsic_name {
169-
sym::min_align_of | sym::pref_align_of | sym::size_of | sym::variant_count => {
166+
sym::min_align_of | sym::pref_align_of | sym::variant_count => {
170167
self.tcx.types.usize
171168
}
172169
sym::needs_drop => self.tcx.types.bool,
@@ -212,28 +209,16 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
212209
let out_val = numeric_intrinsic(intrinsic_name, bits, kind)?;
213210
self.write_scalar(out_val, dest)?;
214211
}
215-
sym::wrapping_add
216-
| sym::wrapping_sub
217-
| sym::wrapping_mul
218-
| sym::add_with_overflow
219-
| sym::sub_with_overflow
220-
| sym::mul_with_overflow => {
212+
sym::add_with_overflow | sym::sub_with_overflow | sym::mul_with_overflow => {
221213
let lhs = self.read_immediate(args[0])?;
222214
let rhs = self.read_immediate(args[1])?;
223-
let (bin_op, ignore_overflow) = match intrinsic_name {
224-
sym::wrapping_add => (BinOp::Add, true),
225-
sym::wrapping_sub => (BinOp::Sub, true),
226-
sym::wrapping_mul => (BinOp::Mul, true),
227-
sym::add_with_overflow => (BinOp::Add, false),
228-
sym::sub_with_overflow => (BinOp::Sub, false),
229-
sym::mul_with_overflow => (BinOp::Mul, false),
215+
let bin_op = match intrinsic_name {
216+
sym::add_with_overflow => BinOp::Add,
217+
sym::sub_with_overflow => BinOp::Sub,
218+
sym::mul_with_overflow => BinOp::Mul,
230219
_ => bug!("Already checked for int ops"),
231220
};
232-
if ignore_overflow {
233-
self.binop_ignore_overflow(bin_op, lhs, rhs, dest)?;
234-
} else {
235-
self.binop_with_overflow(bin_op, lhs, rhs, dest)?;
236-
}
221+
self.binop_with_overflow(bin_op, lhs, rhs, dest)?;
237222
}
238223
sym::saturating_add | sym::saturating_sub => {
239224
let l = self.read_immediate(args[0])?;

compiler/rustc_mir/src/transform/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ fn run_post_borrowck_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tc
364364
// `AddRetag` needs to run after `ElaborateDrops`. Otherwise it should run fairly late,
365365
// but before optimizations begin.
366366
&add_retag::AddRetag,
367+
&lower_intrinsics::LowerIntrinsics,
367368
&simplify::SimplifyCfg::new("elaborate-drops"),
368369
// `Deaggregator` is conceptually part of MIR building, some backends rely on it happening
369370
// and it can help optimizations.
@@ -392,7 +393,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
392393

393394
// The main optimizations that we do on MIR.
394395
let optimizations: &[&dyn MirPass<'tcx>] = &[
395-
&lower_intrinsics::LowerIntrinsics,
396396
&remove_unneeded_drops::RemoveUnneededDrops,
397397
&match_branches::MatchBranchSimplification,
398398
// inst combine is after MatchBranchSimplification to clean up Ne(_1, false)

library/alloc/src/collections/btree/node.rs

+27-28
Original file line numberDiff line numberDiff line change
@@ -1355,66 +1355,65 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
13551355
///
13561356
/// Panics unless we `.can_merge()`.
13571357
pub fn merge(
1358-
mut self,
1358+
self,
13591359
track_edge_idx: Option<LeftOrRight<usize>>,
13601360
) -> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>, marker::Edge> {
1361+
let Handle { node: mut parent_node, idx: parent_idx, _marker } = self.parent;
1362+
let old_parent_len = parent_node.len();
13611363
let mut left_node = self.left_child;
1362-
let left_len = left_node.len();
1364+
let old_left_len = left_node.len();
13631365
let right_node = self.right_child;
13641366
let right_len = right_node.len();
1367+
let new_left_len = old_left_len + 1 + right_len;
13651368

1366-
assert!(left_len + right_len < CAPACITY);
1369+
assert!(new_left_len <= CAPACITY);
13671370
assert!(match track_edge_idx {
13681371
None => true,
1369-
Some(LeftOrRight::Left(idx)) => idx <= left_len,
1372+
Some(LeftOrRight::Left(idx)) => idx <= old_left_len,
13701373
Some(LeftOrRight::Right(idx)) => idx <= right_len,
13711374
});
13721375

13731376
unsafe {
1374-
*left_node.reborrow_mut().into_len_mut() += right_len as u16 + 1;
1377+
*left_node.reborrow_mut().into_len_mut() = new_left_len as u16;
13751378

1376-
let parent_key = slice_remove(
1377-
self.parent.node.reborrow_mut().into_key_area_slice(),
1378-
self.parent.idx,
1379-
);
1380-
left_node.reborrow_mut().into_key_area_mut_at(left_len).write(parent_key);
1379+
let parent_key =
1380+
slice_remove(parent_node.reborrow_mut().into_key_area_slice(), parent_idx);
1381+
left_node.reborrow_mut().into_key_area_mut_at(old_left_len).write(parent_key);
13811382
ptr::copy_nonoverlapping(
13821383
right_node.reborrow().key_area().as_ptr(),
1383-
left_node.reborrow_mut().into_key_area_slice().as_mut_ptr().add(left_len + 1),
1384+
left_node.reborrow_mut().into_key_area_slice().as_mut_ptr().add(old_left_len + 1),
13841385
right_len,
13851386
);
13861387

1387-
let parent_val = slice_remove(
1388-
self.parent.node.reborrow_mut().into_val_area_slice(),
1389-
self.parent.idx,
1390-
);
1391-
left_node.reborrow_mut().into_val_area_mut_at(left_len).write(parent_val);
1388+
let parent_val =
1389+
slice_remove(parent_node.reborrow_mut().into_val_area_slice(), parent_idx);
1390+
left_node.reborrow_mut().into_val_area_mut_at(old_left_len).write(parent_val);
13921391
ptr::copy_nonoverlapping(
13931392
right_node.reborrow().val_area().as_ptr(),
1394-
left_node.reborrow_mut().into_val_area_slice().as_mut_ptr().add(left_len + 1),
1393+
left_node.reborrow_mut().into_val_area_slice().as_mut_ptr().add(old_left_len + 1),
13951394
right_len,
13961395
);
13971396

1398-
slice_remove(
1399-
&mut self.parent.node.reborrow_mut().into_edge_area_slice(),
1400-
self.parent.idx + 1,
1401-
);
1402-
let parent_old_len = self.parent.node.len();
1403-
self.parent.node.correct_childrens_parent_links(self.parent.idx + 1..parent_old_len);
1404-
*self.parent.node.reborrow_mut().into_len_mut() -= 1;
1397+
slice_remove(&mut parent_node.reborrow_mut().into_edge_area_slice(), parent_idx + 1);
1398+
parent_node.correct_childrens_parent_links(parent_idx + 1..old_parent_len);
1399+
*parent_node.reborrow_mut().into_len_mut() -= 1;
14051400

1406-
if self.parent.node.height > 1 {
1401+
if parent_node.height > 1 {
14071402
// SAFETY: the height of the nodes being merged is one below the height
14081403
// of the node of this edge, thus above zero, so they are internal.
14091404
let mut left_node = left_node.reborrow_mut().cast_to_internal_unchecked();
14101405
let right_node = right_node.cast_to_internal_unchecked();
14111406
ptr::copy_nonoverlapping(
14121407
right_node.reborrow().edge_area().as_ptr(),
1413-
left_node.reborrow_mut().into_edge_area_slice().as_mut_ptr().add(left_len + 1),
1408+
left_node
1409+
.reborrow_mut()
1410+
.into_edge_area_slice()
1411+
.as_mut_ptr()
1412+
.add(old_left_len + 1),
14141413
right_len + 1,
14151414
);
14161415

1417-
left_node.correct_childrens_parent_links(left_len + 1..=left_len + 1 + right_len);
1416+
left_node.correct_childrens_parent_links(old_left_len + 1..new_left_len + 1);
14181417

14191418
Global.deallocate(right_node.node.cast(), Layout::new::<InternalNode<K, V>>());
14201419
} else {
@@ -1424,7 +1423,7 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
14241423
let new_idx = match track_edge_idx {
14251424
None => 0,
14261425
Some(LeftOrRight::Left(idx)) => idx,
1427-
Some(LeftOrRight::Right(idx)) => left_len + 1 + idx,
1426+
Some(LeftOrRight::Right(idx)) => old_left_len + 1 + idx,
14281427
};
14291428
Handle::new_edge(left_node, new_idx)
14301429
}

library/alloc/src/collections/btree/set.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ impl<T: Ord> BTreeSet<T> {
679679
/// ```
680680
#[unstable(feature = "map_first_last", issue = "62924")]
681681
pub fn pop_first(&mut self) -> Option<T> {
682-
self.map.first_entry().map(|entry| entry.remove_entry().0)
682+
self.map.pop_first().map(|kv| kv.0)
683683
}
684684

685685
/// Removes the last value from the set and returns it, if any.
@@ -701,7 +701,7 @@ impl<T: Ord> BTreeSet<T> {
701701
/// ```
702702
#[unstable(feature = "map_first_last", issue = "62924")]
703703
pub fn pop_last(&mut self) -> Option<T> {
704-
self.map.last_entry().map(|entry| entry.remove_entry().0)
704+
self.map.pop_last().map(|kv| kv.0)
705705
}
706706

707707
/// Adds a value to the set.

library/core/src/cmp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ mod impls {
12361236
impl PartialOrd for bool {
12371237
#[inline]
12381238
fn partial_cmp(&self, other: &bool) -> Option<Ordering> {
1239-
(*self as u8).partial_cmp(&(*other as u8))
1239+
Some(self.cmp(other))
12401240
}
12411241
}
12421242

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl Clean<ExternalCrate> for CrateNum {
207207
};
208208

209209
ExternalCrate {
210-
name: cx.tcx.crate_name(*self).to_string(),
210+
name: cx.tcx.crate_name(*self),
211211
src: krate_src,
212212
attrs: cx.tcx.get_attrs(root).clean(cx),
213213
primitives,

src/librustdoc/clean/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ thread_local!(crate static MAX_DEF_ID: RefCell<FxHashMap<CrateNum, DefId>> = Def
5151

5252
#[derive(Clone, Debug)]
5353
crate struct Crate {
54-
crate name: String,
54+
crate name: Symbol,
5555
crate version: Option<String>,
5656
crate src: FileName,
5757
crate module: Option<Item>,
@@ -66,7 +66,7 @@ crate struct Crate {
6666

6767
#[derive(Clone, Debug)]
6868
crate struct ExternalCrate {
69-
crate name: String,
69+
crate name: Symbol,
7070
crate src: FileName,
7171
crate attrs: Attributes,
7272
crate primitives: Vec<(DefId, PrimitiveType)>,

src/librustdoc/formats/cache.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
88
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX};
99
use rustc_middle::middle::privacy::AccessLevels;
1010
use rustc_span::source_map::FileName;
11+
use rustc_span::Symbol;
1112

1213
use crate::clean::{self, GetDefId};
1314
use crate::config::RenderInfo;
@@ -74,7 +75,7 @@ crate struct Cache {
7475
crate implementors: FxHashMap<DefId, Vec<Impl>>,
7576

7677
/// Cache of where external crate documentation can be found.
77-
crate extern_locations: FxHashMap<CrateNum, (String, PathBuf, ExternalLocation)>,
78+
crate extern_locations: FxHashMap<CrateNum, (Symbol, PathBuf, ExternalLocation)>,
7879

7980
/// Cache of where documentation for primitives can be found.
8081
crate primitive_locations: FxHashMap<clean::PrimitiveType, DefId>,
@@ -173,10 +174,10 @@ impl Cache {
173174
},
174175
_ => PathBuf::new(),
175176
};
176-
let extern_url = extern_html_root_urls.get(&e.name).map(|u| &**u);
177+
let extern_url = extern_html_root_urls.get(&*e.name.as_str()).map(|u| &**u);
177178
cache
178179
.extern_locations
179-
.insert(n, (e.name.clone(), src_root, extern_location(e, extern_url, &dst)));
180+
.insert(n, (e.name, src_root, extern_location(e, extern_url, &dst)));
180181

181182
let did = DefId { krate: n, index: CRATE_DEF_INDEX };
182183
cache.external_paths.insert(did, (vec![e.name.to_string()], ItemType::Module));
@@ -195,7 +196,7 @@ impl Cache {
195196
cache.primitive_locations.insert(prim, def_id);
196197
}
197198

198-
cache.stack.push(krate.name.clone());
199+
cache.stack.push(krate.name.to_string());
199200
krate = cache.fold_crate(krate);
200201

201202
for (trait_did, dids, impl_) in cache.orphan_trait_impls.drain(..) {
@@ -340,7 +341,7 @@ impl DocFolder for Cache {
340341

341342
// Keep track of the fully qualified path for this item.
342343
let pushed = match item.name {
343-
Some(ref n) if !n.is_empty() => {
344+
Some(n) if !n.is_empty() => {
344345
self.stack.push(n.to_string());
345346
true
346347
}

src/librustdoc/formats/renderer.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::sync::Arc;
33
use rustc_data_structures::sync::Lrc;
44
use rustc_session::Session;
55
use rustc_span::edition::Edition;
6-
use rustc_span::Symbol;
76

87
use crate::clean;
98
use crate::config::{RenderInfo, RenderOptions};
@@ -76,7 +75,7 @@ crate fn run_format<T: FormatRenderer>(
7675
None => return Ok(()),
7776
};
7877

79-
item.name = Some(Symbol::intern(&krate.name));
78+
item.name = Some(krate.name);
8079

8180
// Render the crate documentation
8281
let mut work = vec![(format_renderer.clone(), item)];

src/librustdoc/html/render/cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ crate fn extern_location(
3131
) -> ExternalLocation {
3232
use ExternalLocation::*;
3333
// See if there's documentation generated into the local directory
34-
let local_location = dst.join(&e.name);
34+
let local_location = dst.join(&*e.name.as_str());
3535
if local_location.is_dir() {
3636
return Local;
3737
}

0 commit comments

Comments
 (0)