Skip to content

Commit

Permalink
Auto merge of #59397 - kennytm:rollup, r=kennytm
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - #59213 (Track changes to robots.txt)
 - #59239 (Remove inline assembly from hint::spin_loop)
 - #59251 (Use a valid name for graphviz graphs)
 - #59296 (Do not encode gensymed imports in metadata)
 - #59328 (Implement specialized nth_back() for Box and Windows.)
 - #59355 (Fix ICE with const generic param in struct)
 - #59377 (Correct minimum system LLVM version in tests)
  • Loading branch information
bors committed Mar 24, 2019
2 parents c7b5f4d + 00478a0 commit 0576ac1
Show file tree
Hide file tree
Showing 37 changed files with 233 additions and 74 deletions.
19 changes: 19 additions & 0 deletions src/doc/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# NB: This file is not automatically deployed. After changes, it needs to be uploaded manually to doc.rust-lang.org
User-agent: *
Disallow: /0.3/
Disallow: /0.4/
Disallow: /0.5/
Disallow: /0.6/
Disallow: /0.7/
Disallow: /0.8/
Disallow: /0.9/
Disallow: /0.10/
Disallow: /0.11.0/
Disallow: /0.12.0/
Disallow: /1.0.0-alpha/
Disallow: /1.0.0-alpha.2/
Disallow: /1.0.0-beta/
Disallow: /1.0.0-beta.2/
Disallow: /1.0.0-beta.3/
Disallow: /1.0.0-beta.4/
Disallow: /1.0.0-beta.5/
3 changes: 3 additions & 0 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,9 @@ impl<I: DoubleEndedIterator + ?Sized> DoubleEndedIterator for Box<I> {
fn next_back(&mut self) -> Option<I::Item> {
(**self).next_back()
}
fn nth_back(&mut self, n: usize) -> Option<I::Item> {
(**self).nth_back(n)
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Box<I> {
Expand Down
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
#![feature(maybe_uninit, maybe_uninit_slice, maybe_uninit_array)]
#![feature(alloc_layout_extra)]
#![feature(try_trait)]
#![feature(iter_nth_back)]

// Allow testing this library

Expand Down
31 changes: 25 additions & 6 deletions src/libcore/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,32 @@ pub unsafe fn unreachable_unchecked() -> ! {
#[inline]
#[unstable(feature = "renamed_spin_loop", issue = "55002")]
pub fn spin_loop() {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
unsafe {
asm!("pause" ::: "memory" : "volatile");
#[cfg(
all(
any(target_arch = "x86", target_arch = "x86_64"),
target_feature = "sse2"
)
)] {
#[cfg(target_arch = "x86")] {
unsafe { crate::arch::x86::_mm_pause() };
}

#[cfg(target_arch = "x86_64")] {
unsafe { crate::arch::x86_64::_mm_pause() };
}
}

#[cfg(target_arch = "aarch64")]
unsafe {
asm!("yield" ::: "memory" : "volatile");
#[cfg(
any(
target_arch = "aarch64",
all(target_arch = "arm", target_feature = "v6")
)
)] {
#[cfg(target_arch = "aarch64")] {
unsafe { crate::arch::aarch64::__yield() };
}
#[cfg(target_arch = "arm")] {
unsafe { crate::arch::arm::__yield() };
}
}
}
13 changes: 13 additions & 0 deletions src/libcore/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3867,6 +3867,19 @@ impl<'a, T> DoubleEndedIterator for Windows<'a, T> {
ret
}
}

#[inline]
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
let (end, overflow) = self.v.len().overflowing_sub(n);
if end < self.size || overflow {
self.v = &[];
None
} else {
let ret = &self.v[end-self.size..end];
self.v = &self.v[..end-1];
Some(ret)
}
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
13 changes: 13 additions & 0 deletions src/libcore/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,19 @@ fn test_windows_nth() {
assert_eq!(c2.next(), None);
}

#[test]
fn test_windows_nth_back() {
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
let mut c = v.windows(2);
assert_eq!(c.nth_back(2).unwrap()[0], 2);
assert_eq!(c.next_back().unwrap()[1], 2);

let v2: &[i32] = &[0, 1, 2, 3, 4];
let mut c2 = v2.windows(4);
assert_eq!(c2.nth_back(1).unwrap()[1], 1);
assert_eq!(c2.next_back(), None);
}

#[test]
fn test_windows_last() {
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
Expand Down
8 changes: 5 additions & 3 deletions src/librustc_codegen_llvm/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,12 +1156,14 @@ fn prepare_union_metadata(
// Enums
//=-----------------------------------------------------------------------------

// DWARF variant support is only available starting in LLVM 7.
// DWARF variant support is only available starting in LLVM 8.
// Although the earlier enum debug info output did not work properly
// in all situations, it is better for the time being to continue to
// sometimes emit the old style rather than emit something completely
// useless when rust is compiled against LLVM 6 or older. This
// function decides which representation will be emitted.
// useless when rust is compiled against LLVM 6 or older. LLVM 7
// contains an early version of the DWARF variant support, and will
// crash when handling the new debug info format. This function
// decides which representation will be emitted.
fn use_enum_fallback(cx: &CodegenCx<'_, '_>) -> bool {
// On MSVC we have to use the fallback mode, because LLVM doesn't
// lower variant parts to PDB.
Expand Down
12 changes: 11 additions & 1 deletion src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,20 @@ fn print_flowgraph<'a, 'tcx, W: Write>(variants: Vec<borrowck_dot::Variant>,
let body = tcx.hir().body(body_id);
let cfg = cfg::CFG::new(tcx, &body);
let labelled_edges = mode != PpFlowGraphMode::UnlabelledEdges;
let hir_id = code.id();
// We have to disassemble the hir_id because name must be ASCII
// alphanumeric. This does not appear in the rendered graph, so it does not
// have to be user friendly.
let name = format!(
"hir_id_{}_{}_{}",
hir_id.owner.address_space().index(),
hir_id.owner.as_array_index(),
hir_id.local_id.index(),
);
let lcfg = LabelledCFG {
tcx,
cfg: &cfg,
name: format!("node_{}", code.id()),
name,
labelled_edges,
};

Expand Down
8 changes: 4 additions & 4 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
let mut flow_inits = FlowAtLocation::new(do_dataflow(
tcx,
mir,
id,
def_id,
&attributes,
&dead_unwinds,
MaybeInitializedPlaces::new(tcx, mir, &mdpe),
Expand Down Expand Up @@ -191,7 +191,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
let flow_borrows = FlowAtLocation::new(do_dataflow(
tcx,
mir,
id,
def_id,
&attributes,
&dead_unwinds,
Borrows::new(tcx, mir, regioncx.clone(), &borrow_set),
Expand All @@ -200,7 +200,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
let flow_uninits = FlowAtLocation::new(do_dataflow(
tcx,
mir,
id,
def_id,
&attributes,
&dead_unwinds,
MaybeUninitializedPlaces::new(tcx, mir, &mdpe),
Expand All @@ -209,7 +209,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
let flow_ever_inits = FlowAtLocation::new(do_dataflow(
tcx,
mir,
id,
def_id,
&attributes,
&dead_unwinds,
EverInitializedPlaces::new(tcx, mir, &mdpe),
Expand Down
17 changes: 9 additions & 8 deletions src/librustc_mir/dataflow/graphviz.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
//! Hook into libgraphviz for rendering dataflow graphs for MIR.
use rustc::hir::HirId;
use rustc::hir::def_id::DefId;
use rustc::mir::{BasicBlock, Mir};

use std::fs;
use std::io;
use std::marker::PhantomData;
use std::path::Path;

use crate::util::graphviz_safe_def_name;

use super::{BitDenotation, DataflowState};
use super::DataflowBuilder;
use super::DebugFormatted;

pub trait MirWithFlowState<'tcx> {
type BD: BitDenotation<'tcx>;
fn hir_id(&self) -> HirId;
fn def_id(&self) -> DefId;
fn mir(&self) -> &Mir<'tcx>;
fn flow_state(&self) -> &DataflowState<'tcx, Self::BD>;
}
Expand All @@ -23,7 +25,7 @@ impl<'a, 'tcx, BD> MirWithFlowState<'tcx> for DataflowBuilder<'a, 'tcx, BD>
where BD: BitDenotation<'tcx>
{
type BD = BD;
fn hir_id(&self) -> HirId { self.hir_id }
fn def_id(&self) -> DefId { self.def_id }
fn mir(&self) -> &Mir<'tcx> { self.flow_state.mir() }
fn flow_state(&self) -> &DataflowState<'tcx, Self::BD> { &self.flow_state.flow_state }
}
Expand All @@ -47,8 +49,8 @@ pub(crate) fn print_borrowck_graph_to<'a, 'tcx, BD, P>(
let g = Graph { mbcx, phantom: PhantomData, render_idx };
let mut v = Vec::new();
dot::render(&g, &mut v)?;
debug!("print_borrowck_graph_to path: {} hir_id: {}",
path.display(), mbcx.hir_id);
debug!("print_borrowck_graph_to path: {} def_id: {:?}",
path.display(), mbcx.def_id);
fs::write(path, v)
}

Expand All @@ -69,9 +71,8 @@ impl<'a, 'tcx, MWF, P> dot::Labeller<'a> for Graph<'a, 'tcx, MWF, P>
type Node = Node;
type Edge = Edge;
fn graph_id(&self) -> dot::Id<'_> {
dot::Id::new(format!("graph_for_node_{}",
self.mbcx.hir_id()))
.unwrap()
let name = graphviz_safe_def_name(self.mbcx.def_id());
dot::Id::new(format!("graph_for_def_id_{}", name)).unwrap()
}

fn node_id(&self, n: &Node) -> dot::Id<'_> {
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_mir/dataflow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_data_structures::bit_set::{BitSet, BitSetOperator, HybridBitSet};
use rustc_data_structures::indexed_vec::Idx;
use rustc_data_structures::work_queue::WorkQueue;

use rustc::hir::HirId;
use rustc::hir::def_id::DefId;
use rustc::ty::{self, TyCtxt};
use rustc::mir::{self, Mir, BasicBlock, BasicBlockData, Location, Statement, Terminator};
use rustc::mir::traversal;
Expand Down Expand Up @@ -39,7 +39,7 @@ pub(crate) struct DataflowBuilder<'a, 'tcx: 'a, BD>
where
BD: BitDenotation<'tcx>
{
hir_id: HirId,
def_id: DefId,
flow_state: DataflowAnalysis<'a, 'tcx, BD>,
print_preflow_to: Option<String>,
print_postflow_to: Option<String>,
Expand Down Expand Up @@ -117,7 +117,7 @@ pub struct MoveDataParamEnv<'gcx, 'tcx> {

pub(crate) fn do_dataflow<'a, 'gcx, 'tcx, BD, P>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
mir: &'a Mir<'tcx>,
hir_id: HirId,
def_id: DefId,
attributes: &[ast::Attribute],
dead_unwinds: &BitSet<BasicBlock>,
bd: BD,
Expand All @@ -127,14 +127,14 @@ pub(crate) fn do_dataflow<'a, 'gcx, 'tcx, BD, P>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
P: Fn(&BD, BD::Idx) -> DebugFormatted
{
let flow_state = DataflowAnalysis::new(mir, dead_unwinds, bd);
flow_state.run(tcx, hir_id, attributes, p)
flow_state.run(tcx, def_id, attributes, p)
}

impl<'a, 'gcx: 'tcx, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitDenotation<'tcx>
{
pub(crate) fn run<P>(self,
tcx: TyCtxt<'a, 'gcx, 'tcx>,
hir_id: HirId,
def_id: DefId,
attributes: &[ast::Attribute],
p: P) -> DataflowResults<'tcx, BD>
where P: Fn(&BD, BD::Idx) -> DebugFormatted
Expand All @@ -159,7 +159,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitD
name_found(tcx.sess, attributes, "borrowck_graphviz_postflow");

let mut mbcx = DataflowBuilder {
hir_id,
def_id,
print_preflow_to, print_postflow_to, flow_state: self,
};

Expand Down
12 changes: 6 additions & 6 deletions src/librustc_mir/transform/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl MirPass for ElaborateDrops {
{
debug!("elaborate_drops({:?} @ {:?})", src, mir.span);

let id = tcx.hir().as_local_hir_id(src.def_id()).unwrap();
let def_id = src.def_id();
let param_env = tcx.param_env(src.def_id()).with_reveal_all();
let move_data = match MoveData::gather_moves(mir, tcx) {
Ok(move_data) => move_data,
Expand All @@ -50,13 +50,13 @@ impl MirPass for ElaborateDrops {
move_data,
param_env,
};
let dead_unwinds = find_dead_unwinds(tcx, mir, id, &env);
let dead_unwinds = find_dead_unwinds(tcx, mir, def_id, &env);
let flow_inits =
do_dataflow(tcx, mir, id, &[], &dead_unwinds,
do_dataflow(tcx, mir, def_id, &[], &dead_unwinds,
MaybeInitializedPlaces::new(tcx, mir, &env),
|bd, p| DebugFormatted::new(&bd.move_data().move_paths[p]));
let flow_uninits =
do_dataflow(tcx, mir, id, &[], &dead_unwinds,
do_dataflow(tcx, mir, def_id, &[], &dead_unwinds,
MaybeUninitializedPlaces::new(tcx, mir, &env),
|bd, p| DebugFormatted::new(&bd.move_data().move_paths[p]));

Expand All @@ -80,7 +80,7 @@ impl MirPass for ElaborateDrops {
fn find_dead_unwinds<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
mir: &Mir<'tcx>,
id: hir::HirId,
def_id: hir::def_id::DefId,
env: &MoveDataParamEnv<'tcx, 'tcx>)
-> BitSet<BasicBlock>
{
Expand All @@ -89,7 +89,7 @@ fn find_dead_unwinds<'a, 'tcx>(
// reach cleanup blocks, which can't have unwind edges themselves.
let mut dead_unwinds = BitSet::new_empty(mir.basic_blocks().len());
let flow_inits =
do_dataflow(tcx, mir, id, &[], &dead_unwinds,
do_dataflow(tcx, mir, def_id, &[], &dead_unwinds,
MaybeInitializedPlaces::new(tcx, mir, &env),
|bd, p| DebugFormatted::new(&bd.move_data().move_paths[p]));
for (bb, bb_data) in mir.basic_blocks().iter_enumerated() {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/transform/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,13 @@ fn locals_live_across_suspend_points(
FxHashMap<BasicBlock, liveness::LiveVarSet>,
) {
let dead_unwinds = BitSet::new_empty(mir.basic_blocks().len());
let hir_id = tcx.hir().as_local_hir_id(source.def_id()).unwrap();
let def_id = source.def_id();

// Calculate when MIR locals have live storage. This gives us an upper bound of their
// lifetimes.
let storage_live_analysis = MaybeStorageLive::new(mir);
let storage_live =
do_dataflow(tcx, mir, hir_id, &[], &dead_unwinds, storage_live_analysis,
do_dataflow(tcx, mir, def_id, &[], &dead_unwinds, storage_live_analysis,
|bd, p| DebugFormatted::new(&bd.mir().local_decls[p]));

// Find the MIR locals which do not use StorageLive/StorageDead statements.
Expand All @@ -410,7 +410,7 @@ fn locals_live_across_suspend_points(
let borrowed_locals = if !movable {
let analysis = HaveBeenBorrowedLocals::new(mir);
let result =
do_dataflow(tcx, mir, hir_id, &[], &dead_unwinds, analysis,
do_dataflow(tcx, mir, def_id, &[], &dead_unwinds, analysis,
|bd, p| DebugFormatted::new(&bd.mir().local_decls[p]));
Some((analysis, result))
} else {
Expand Down
Loading

0 comments on commit 0576ac1

Please sign in to comment.