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
This commit is contained in:
bors 2020-12-17 12:02:29 +00:00
commit caeb3335c0
21 changed files with 97 additions and 100 deletions

View File

@ -83,9 +83,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
return;
}
sym::unreachable => {
return;
}
sym::va_start => bx.va_start(args[0].immediate()),
sym::va_end => bx.va_end(args[0].immediate()),
sym::size_of_val => {
@ -106,8 +103,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bx.const_usize(bx.layout_of(tp_ty).align.abi.bytes())
}
}
sym::size_of
| sym::pref_align_of
sym::pref_align_of
| sym::min_align_of
| sym::needs_drop
| sym::type_id
@ -119,10 +115,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
.unwrap();
OperandRef::from_const(bx, value, ret_ty).immediate_or_packed_pair(bx)
}
// Effectively no-op
sym::forget => {
return;
}
sym::offset => {
let ptr = args[0].immediate();
let offset = args[1].immediate();
@ -218,9 +210,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
sym::add_with_overflow
| sym::sub_with_overflow
| sym::mul_with_overflow
| sym::wrapping_add
| sym::wrapping_sub
| sym::wrapping_mul
| sym::unchecked_div
| sym::unchecked_rem
| sym::unchecked_shl
@ -254,9 +243,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
return;
}
sym::wrapping_add => bx.add(args[0].immediate(), args[1].immediate()),
sym::wrapping_sub => bx.sub(args[0].immediate(), args[1].immediate()),
sym::wrapping_mul => bx.mul(args[0].immediate(), args[1].immediate()),
sym::exact_div => {
if signed {
bx.exactsdiv(args[0].immediate(), args[1].immediate())

View File

@ -61,12 +61,11 @@ crate fn eval_nullary_intrinsic<'tcx>(
ConstValue::Slice { data: alloc, start: 0, end: alloc.len() }
}
sym::needs_drop => ConstValue::from_bool(tp_ty.needs_drop(tcx, param_env)),
sym::size_of | sym::min_align_of | sym::pref_align_of => {
sym::min_align_of | sym::pref_align_of => {
let layout = tcx.layout_of(param_env.and(tp_ty)).map_err(|e| err_inval!(Layout(e)))?;
let n = match name {
sym::pref_align_of => layout.align.pref.bytes(),
sym::min_align_of => layout.align.abi.bytes(),
sym::size_of => layout.size.bytes(),
_ => bug!(),
};
ConstValue::from_machine_usize(n, &tcx)
@ -125,7 +124,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let (dest, ret) = match ret {
None => match intrinsic_name {
sym::transmute => throw_ub_format!("transmuting to uninhabited type"),
sym::unreachable => throw_ub!(Unreachable),
sym::abort => M::abort(self, "the program aborted execution".to_owned())?,
// Unsupported diverging intrinsic.
_ => return Ok(false),
@ -160,13 +158,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
sym::min_align_of
| sym::pref_align_of
| sym::needs_drop
| sym::size_of
| sym::type_id
| sym::type_name
| sym::variant_count => {
let gid = GlobalId { instance, promoted: None };
let ty = match intrinsic_name {
sym::min_align_of | sym::pref_align_of | sym::size_of | sym::variant_count => {
sym::min_align_of | sym::pref_align_of | sym::variant_count => {
self.tcx.types.usize
}
sym::needs_drop => self.tcx.types.bool,
@ -212,28 +209,16 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let out_val = numeric_intrinsic(intrinsic_name, bits, kind)?;
self.write_scalar(out_val, dest)?;
}
sym::wrapping_add
| sym::wrapping_sub
| sym::wrapping_mul
| sym::add_with_overflow
| sym::sub_with_overflow
| sym::mul_with_overflow => {
sym::add_with_overflow | sym::sub_with_overflow | sym::mul_with_overflow => {
let lhs = self.read_immediate(args[0])?;
let rhs = self.read_immediate(args[1])?;
let (bin_op, ignore_overflow) = match intrinsic_name {
sym::wrapping_add => (BinOp::Add, true),
sym::wrapping_sub => (BinOp::Sub, true),
sym::wrapping_mul => (BinOp::Mul, true),
sym::add_with_overflow => (BinOp::Add, false),
sym::sub_with_overflow => (BinOp::Sub, false),
sym::mul_with_overflow => (BinOp::Mul, false),
let bin_op = match intrinsic_name {
sym::add_with_overflow => BinOp::Add,
sym::sub_with_overflow => BinOp::Sub,
sym::mul_with_overflow => BinOp::Mul,
_ => bug!("Already checked for int ops"),
};
if ignore_overflow {
self.binop_ignore_overflow(bin_op, lhs, rhs, dest)?;
} else {
self.binop_with_overflow(bin_op, lhs, rhs, dest)?;
}
self.binop_with_overflow(bin_op, lhs, rhs, dest)?;
}
sym::saturating_add | sym::saturating_sub => {
let l = self.read_immediate(args[0])?;

View File

@ -364,6 +364,7 @@ fn run_post_borrowck_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tc
// `AddRetag` needs to run after `ElaborateDrops`. Otherwise it should run fairly late,
// but before optimizations begin.
&add_retag::AddRetag,
&lower_intrinsics::LowerIntrinsics,
&simplify::SimplifyCfg::new("elaborate-drops"),
// `Deaggregator` is conceptually part of MIR building, some backends rely on it happening
// and it can help optimizations.
@ -392,7 +393,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
// The main optimizations that we do on MIR.
let optimizations: &[&dyn MirPass<'tcx>] = &[
&lower_intrinsics::LowerIntrinsics,
&remove_unneeded_drops::RemoveUnneededDrops,
&match_branches::MatchBranchSimplification,
// inst combine is after MatchBranchSimplification to clean up Ne(_1, false)

View File

@ -1355,66 +1355,65 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
///
/// Panics unless we `.can_merge()`.
pub fn merge(
mut self,
self,
track_edge_idx: Option<LeftOrRight<usize>>,
) -> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>, marker::Edge> {
let Handle { node: mut parent_node, idx: parent_idx, _marker } = self.parent;
let old_parent_len = parent_node.len();
let mut left_node = self.left_child;
let left_len = left_node.len();
let old_left_len = left_node.len();
let right_node = self.right_child;
let right_len = right_node.len();
let new_left_len = old_left_len + 1 + right_len;
assert!(left_len + right_len < CAPACITY);
assert!(new_left_len <= CAPACITY);
assert!(match track_edge_idx {
None => true,
Some(LeftOrRight::Left(idx)) => idx <= left_len,
Some(LeftOrRight::Left(idx)) => idx <= old_left_len,
Some(LeftOrRight::Right(idx)) => idx <= right_len,
});
unsafe {
*left_node.reborrow_mut().into_len_mut() += right_len as u16 + 1;
*left_node.reborrow_mut().into_len_mut() = new_left_len as u16;
let parent_key = slice_remove(
self.parent.node.reborrow_mut().into_key_area_slice(),
self.parent.idx,
);
left_node.reborrow_mut().into_key_area_mut_at(left_len).write(parent_key);
let parent_key =
slice_remove(parent_node.reborrow_mut().into_key_area_slice(), parent_idx);
left_node.reborrow_mut().into_key_area_mut_at(old_left_len).write(parent_key);
ptr::copy_nonoverlapping(
right_node.reborrow().key_area().as_ptr(),
left_node.reborrow_mut().into_key_area_slice().as_mut_ptr().add(left_len + 1),
left_node.reborrow_mut().into_key_area_slice().as_mut_ptr().add(old_left_len + 1),
right_len,
);
let parent_val = slice_remove(
self.parent.node.reborrow_mut().into_val_area_slice(),
self.parent.idx,
);
left_node.reborrow_mut().into_val_area_mut_at(left_len).write(parent_val);
let parent_val =
slice_remove(parent_node.reborrow_mut().into_val_area_slice(), parent_idx);
left_node.reborrow_mut().into_val_area_mut_at(old_left_len).write(parent_val);
ptr::copy_nonoverlapping(
right_node.reborrow().val_area().as_ptr(),
left_node.reborrow_mut().into_val_area_slice().as_mut_ptr().add(left_len + 1),
left_node.reborrow_mut().into_val_area_slice().as_mut_ptr().add(old_left_len + 1),
right_len,
);
slice_remove(
&mut self.parent.node.reborrow_mut().into_edge_area_slice(),
self.parent.idx + 1,
);
let parent_old_len = self.parent.node.len();
self.parent.node.correct_childrens_parent_links(self.parent.idx + 1..parent_old_len);
*self.parent.node.reborrow_mut().into_len_mut() -= 1;
slice_remove(&mut parent_node.reborrow_mut().into_edge_area_slice(), parent_idx + 1);
parent_node.correct_childrens_parent_links(parent_idx + 1..old_parent_len);
*parent_node.reborrow_mut().into_len_mut() -= 1;
if self.parent.node.height > 1 {
if parent_node.height > 1 {
// SAFETY: the height of the nodes being merged is one below the height
// of the node of this edge, thus above zero, so they are internal.
let mut left_node = left_node.reborrow_mut().cast_to_internal_unchecked();
let right_node = right_node.cast_to_internal_unchecked();
ptr::copy_nonoverlapping(
right_node.reborrow().edge_area().as_ptr(),
left_node.reborrow_mut().into_edge_area_slice().as_mut_ptr().add(left_len + 1),
left_node
.reborrow_mut()
.into_edge_area_slice()
.as_mut_ptr()
.add(old_left_len + 1),
right_len + 1,
);
left_node.correct_childrens_parent_links(left_len + 1..=left_len + 1 + right_len);
left_node.correct_childrens_parent_links(old_left_len + 1..new_left_len + 1);
Global.deallocate(right_node.node.cast(), Layout::new::<InternalNode<K, V>>());
} else {
@ -1424,7 +1423,7 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
let new_idx = match track_edge_idx {
None => 0,
Some(LeftOrRight::Left(idx)) => idx,
Some(LeftOrRight::Right(idx)) => left_len + 1 + idx,
Some(LeftOrRight::Right(idx)) => old_left_len + 1 + idx,
};
Handle::new_edge(left_node, new_idx)
}

View File

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

View File

@ -1236,7 +1236,7 @@ mod impls {
impl PartialOrd for bool {
#[inline]
fn partial_cmp(&self, other: &bool) -> Option<Ordering> {
(*self as u8).partial_cmp(&(*other as u8))
Some(self.cmp(other))
}
}

View File

@ -207,7 +207,7 @@ impl Clean<ExternalCrate> for CrateNum {
};
ExternalCrate {
name: cx.tcx.crate_name(*self).to_string(),
name: cx.tcx.crate_name(*self),
src: krate_src,
attrs: cx.tcx.get_attrs(root).clean(cx),
primitives,

View File

@ -51,7 +51,7 @@ thread_local!(crate static MAX_DEF_ID: RefCell<FxHashMap<CrateNum, DefId>> = Def
#[derive(Clone, Debug)]
crate struct Crate {
crate name: String,
crate name: Symbol,
crate version: Option<String>,
crate src: FileName,
crate module: Option<Item>,
@ -66,7 +66,7 @@ crate struct Crate {
#[derive(Clone, Debug)]
crate struct ExternalCrate {
crate name: String,
crate name: Symbol,
crate src: FileName,
crate attrs: Attributes,
crate primitives: Vec<(DefId, PrimitiveType)>,

View File

@ -8,6 +8,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX};
use rustc_middle::middle::privacy::AccessLevels;
use rustc_span::source_map::FileName;
use rustc_span::Symbol;
use crate::clean::{self, GetDefId};
use crate::config::RenderInfo;
@ -74,7 +75,7 @@ crate struct Cache {
crate implementors: FxHashMap<DefId, Vec<Impl>>,
/// Cache of where external crate documentation can be found.
crate extern_locations: FxHashMap<CrateNum, (String, PathBuf, ExternalLocation)>,
crate extern_locations: FxHashMap<CrateNum, (Symbol, PathBuf, ExternalLocation)>,
/// Cache of where documentation for primitives can be found.
crate primitive_locations: FxHashMap<clean::PrimitiveType, DefId>,
@ -173,10 +174,10 @@ impl Cache {
},
_ => PathBuf::new(),
};
let extern_url = extern_html_root_urls.get(&e.name).map(|u| &**u);
let extern_url = extern_html_root_urls.get(&*e.name.as_str()).map(|u| &**u);
cache
.extern_locations
.insert(n, (e.name.clone(), src_root, extern_location(e, extern_url, &dst)));
.insert(n, (e.name, src_root, extern_location(e, extern_url, &dst)));
let did = DefId { krate: n, index: CRATE_DEF_INDEX };
cache.external_paths.insert(did, (vec![e.name.to_string()], ItemType::Module));
@ -195,7 +196,7 @@ impl Cache {
cache.primitive_locations.insert(prim, def_id);
}
cache.stack.push(krate.name.clone());
cache.stack.push(krate.name.to_string());
krate = cache.fold_crate(krate);
for (trait_did, dids, impl_) in cache.orphan_trait_impls.drain(..) {
@ -340,7 +341,7 @@ impl DocFolder for Cache {
// Keep track of the fully qualified path for this item.
let pushed = match item.name {
Some(ref n) if !n.is_empty() => {
Some(n) if !n.is_empty() => {
self.stack.push(n.to_string());
true
}

View File

@ -3,7 +3,6 @@ use std::sync::Arc;
use rustc_data_structures::sync::Lrc;
use rustc_session::Session;
use rustc_span::edition::Edition;
use rustc_span::Symbol;
use crate::clean;
use crate::config::{RenderInfo, RenderOptions};
@ -76,7 +75,7 @@ crate fn run_format<T: FormatRenderer>(
None => return Ok(()),
};
item.name = Some(Symbol::intern(&krate.name));
item.name = Some(krate.name);
// Render the crate documentation
let mut work = vec![(format_renderer.clone(), item)];

View File

@ -31,7 +31,7 @@ crate fn extern_location(
) -> ExternalLocation {
use ExternalLocation::*;
// See if there's documentation generated into the local directory
let local_location = dst.join(&e.name);
let local_location = dst.join(&*e.name.as_str());
if local_location.is_dir() {
return Local;
}

View File

@ -418,14 +418,15 @@ impl FormatRenderer for Context {
// If user passed in `--playground-url` arg, we fill in crate name here
let mut playground = None;
if let Some(url) = playground_url {
playground = Some(markdown::Playground { crate_name: Some(krate.name.clone()), url });
playground =
Some(markdown::Playground { crate_name: Some(krate.name.to_string()), url });
}
let mut layout = layout::Layout {
logo: String::new(),
favicon: String::new(),
external_html,
default_settings,
krate: krate.name.clone(),
krate: krate.name.to_string(),
css_file_extension: extension_css,
generate_search_filter,
};
@ -445,7 +446,7 @@ impl FormatRenderer for Context {
}
(sym::html_playground_url, Some(s)) => {
playground = Some(markdown::Playground {
crate_name: Some(krate.name.clone()),
crate_name: Some(krate.name.to_string()),
url: s.to_string(),
});
}
@ -530,7 +531,7 @@ impl FormatRenderer for Context {
}
fn after_krate(&mut self, krate: &clean::Crate, cache: &Cache) -> Result<(), Error> {
let final_file = self.dst.join(&krate.name).join("all.html");
let final_file = self.dst.join(&*krate.name.as_str()).join("all.html");
let settings_file = self.dst.join("settings.html");
let crate_name = krate.name.clone();
@ -1019,7 +1020,8 @@ themePicker.onblur = handleThemeButtonsBlur;
}
let dst = cx.dst.join(&format!("source-files{}.js", cx.shared.resource_suffix));
let (mut all_sources, _krates) = try_err!(collect(&dst, &krate.name, "sourcesIndex"), &dst);
let (mut all_sources, _krates) =
try_err!(collect(&dst, &krate.name.as_str(), "sourcesIndex"), &dst);
all_sources.push(format!(
"sourcesIndex[\"{}\"] = {};",
&krate.name,
@ -1035,7 +1037,7 @@ themePicker.onblur = handleThemeButtonsBlur;
// Update the search index
let dst = cx.dst.join(&format!("search-index{}.js", cx.shared.resource_suffix));
let (mut all_indexes, mut krates) = try_err!(collect_json(&dst, &krate.name), &dst);
let (mut all_indexes, mut krates) = try_err!(collect_json(&dst, &krate.name.as_str()), &dst);
all_indexes.push(search_index);
// Sort the indexes by crate so the file will be generated identically even
@ -1070,7 +1072,7 @@ themePicker.onblur = handleThemeButtonsBlur;
extra_scripts: &[],
static_extra_scripts: &[],
};
krates.push(krate.name.clone());
krates.push(krate.name.to_string());
krates.sort();
krates.dedup();
@ -1162,7 +1164,7 @@ themePicker.onblur = handleThemeButtonsBlur;
mydst.push(&format!("{}.{}.js", remote_item_type, remote_path[remote_path.len() - 1]));
let (mut all_implementors, _) =
try_err!(collect(&mydst, &krate.name, "implementors"), &mydst);
try_err!(collect(&mydst, &krate.name.as_str(), "implementors"), &mydst);
all_implementors.push(implementors);
// Sort the implementors by crate so the file will be generated
// identically even with rustdoc running in parallel.
@ -1648,16 +1650,17 @@ impl Context {
};
let file = &file;
let symbol;
let (krate, path) = if cnum == LOCAL_CRATE {
if let Some(path) = self.shared.local_sources.get(file) {
(&self.shared.layout.krate, path)
(self.shared.layout.krate.as_str(), path)
} else {
return None;
}
} else {
let (krate, src_root) = match *cache.extern_locations.get(&cnum)? {
(ref name, ref src, ExternalLocation::Local) => (name, src),
(ref name, ref src, ExternalLocation::Remote(ref s)) => {
(name, ref src, ExternalLocation::Local) => (name, src),
(name, ref src, ExternalLocation::Remote(ref s)) => {
root = s.to_string();
(name, src)
}
@ -1671,7 +1674,8 @@ impl Context {
let mut fname = file.file_name().expect("source has no filename").to_os_string();
fname.push(".html");
path.push_str(&fname.to_string_lossy());
(krate, &path)
symbol = krate.as_str();
(&*symbol, &path)
};
let loline = item.source.lo(self.sess()).line;

View File

@ -19,7 +19,7 @@ crate fn render(
krate: clean::Crate,
) -> Result<clean::Crate, Error> {
info!("emitting source files");
let dst = dst.join("src").join(&krate.name);
let dst = dst.join("src").join(&*krate.name.as_str());
scx.ensure_dir(&dst)?;
let mut folder = SourceCollector { dst, scx };
Ok(folder.fold_crate(krate))

View File

@ -223,7 +223,7 @@ impl FormatRenderer for JsonRenderer {
(
k.as_u32(),
types::ExternalCrate {
name: v.0.clone(),
name: v.0.to_string(),
html_root_url: match &v.2 {
ExternalLocation::Remote(s) => Some(s.clone()),
_ => None,

View File

@ -519,17 +519,12 @@ fn main_options(options: config::Options) -> MainResult {
// compiler all the way through the analysis passes. The rustdoc output is
// then generated from the cleaned AST of the crate. This runs all the
// plug/cleaning passes.
let crate_name = options.crate_name.clone();
let crate_version = options.crate_version.clone();
let output_format = options.output_format;
let (mut krate, renderinfo, renderopts, sess) = core::run_core(options);
info!("finished with rustc");
if let Some(name) = crate_name {
krate.name = name
}
krate.version = crate_version;
if show_coverage {

View File

@ -120,5 +120,9 @@
bb5: {
return; // scope 0 at $DIR/lower_intrinsics.rs:73:2: 73:2
}
bb6 (cleanup): {
resume; // scope 0 at $DIR/lower_intrinsics.rs:68:1: 73:2
}
}

View File

@ -25,7 +25,15 @@
StorageDead(_3); // scope 1 at $DIR/lower_intrinsics.rs:19:40: 19:41
StorageDead(_2); // scope 0 at $DIR/lower_intrinsics.rs:19:43: 19:44
_0 = const (); // scope 0 at $DIR/lower_intrinsics.rs:18:24: 20:2
goto -> bb2; // scope 0 at $DIR/lower_intrinsics.rs:20:1: 20:2
}
bb2: {
return; // scope 0 at $DIR/lower_intrinsics.rs:20:2: 20:2
}
bb3 (cleanup): {
resume; // scope 0 at $DIR/lower_intrinsics.rs:18:1: 20:2
}
}

View File

@ -27,5 +27,9 @@
StorageDead(_1); // scope 0 at $DIR/lower_intrinsics.rs:59:1: 59:2
return; // scope 0 at $DIR/lower_intrinsics.rs:59:2: 59:2
}
bb2 (cleanup): {
resume; // scope 0 at $DIR/lower_intrinsics.rs:55:1: 59:2
}
}

View File

@ -16,5 +16,9 @@
bb1: {
return; // scope 0 at $DIR/lower_intrinsics.rs:15:2: 15:2
}
bb2 (cleanup): {
resume; // scope 0 at $DIR/lower_intrinsics.rs:13:1: 15:2
}
}

View File

@ -18,5 +18,9 @@
- // + literal: Const { ty: unsafe extern "rust-intrinsic" fn() -> ! {std::intrinsics::unreachable}, val: Value(Scalar(<ZST>)) }
+ unreachable; // scope 1 at $DIR/lower_intrinsics.rs:24:14: 24:45
}
bb1 (cleanup): {
resume; // scope 0 at $DIR/lower_intrinsics.rs:23:1: 25:2
}
}

View File

@ -79,5 +79,9 @@
StorageDead(_3); // scope 0 at $DIR/lower_intrinsics.rs:10:1: 10:2
return; // scope 0 at $DIR/lower_intrinsics.rs:10:2: 10:2
}
bb4 (cleanup): {
resume; // scope 0 at $DIR/lower_intrinsics.rs:6:1: 10:2
}
}