Skip to content

Commit 0576ac1

Browse files
committed
Auto merge of #59397 - kennytm:rollup, r=kennytm
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)
2 parents c7b5f4d + 00478a0 commit 0576ac1

37 files changed

+233
-74
lines changed

src/doc/robots.txt

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# NB: This file is not automatically deployed. After changes, it needs to be uploaded manually to doc.rust-lang.org
2+
User-agent: *
3+
Disallow: /0.3/
4+
Disallow: /0.4/
5+
Disallow: /0.5/
6+
Disallow: /0.6/
7+
Disallow: /0.7/
8+
Disallow: /0.8/
9+
Disallow: /0.9/
10+
Disallow: /0.10/
11+
Disallow: /0.11.0/
12+
Disallow: /0.12.0/
13+
Disallow: /1.0.0-alpha/
14+
Disallow: /1.0.0-alpha.2/
15+
Disallow: /1.0.0-beta/
16+
Disallow: /1.0.0-beta.2/
17+
Disallow: /1.0.0-beta.3/
18+
Disallow: /1.0.0-beta.4/
19+
Disallow: /1.0.0-beta.5/

src/liballoc/boxed.rs

+3
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,9 @@ impl<I: DoubleEndedIterator + ?Sized> DoubleEndedIterator for Box<I> {
677677
fn next_back(&mut self) -> Option<I::Item> {
678678
(**self).next_back()
679679
}
680+
fn nth_back(&mut self, n: usize) -> Option<I::Item> {
681+
(**self).nth_back(n)
682+
}
680683
}
681684
#[stable(feature = "rust1", since = "1.0.0")]
682685
impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Box<I> {

src/liballoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
#![feature(maybe_uninit, maybe_uninit_slice, maybe_uninit_array)]
116116
#![feature(alloc_layout_extra)]
117117
#![feature(try_trait)]
118+
#![feature(iter_nth_back)]
118119

119120
// Allow testing this library
120121

src/libcore/hint.rs

+25-6
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,32 @@ pub unsafe fn unreachable_unchecked() -> ! {
6262
#[inline]
6363
#[unstable(feature = "renamed_spin_loop", issue = "55002")]
6464
pub fn spin_loop() {
65-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
66-
unsafe {
67-
asm!("pause" ::: "memory" : "volatile");
65+
#[cfg(
66+
all(
67+
any(target_arch = "x86", target_arch = "x86_64"),
68+
target_feature = "sse2"
69+
)
70+
)] {
71+
#[cfg(target_arch = "x86")] {
72+
unsafe { crate::arch::x86::_mm_pause() };
73+
}
74+
75+
#[cfg(target_arch = "x86_64")] {
76+
unsafe { crate::arch::x86_64::_mm_pause() };
77+
}
6878
}
6979

70-
#[cfg(target_arch = "aarch64")]
71-
unsafe {
72-
asm!("yield" ::: "memory" : "volatile");
80+
#[cfg(
81+
any(
82+
target_arch = "aarch64",
83+
all(target_arch = "arm", target_feature = "v6")
84+
)
85+
)] {
86+
#[cfg(target_arch = "aarch64")] {
87+
unsafe { crate::arch::aarch64::__yield() };
88+
}
89+
#[cfg(target_arch = "arm")] {
90+
unsafe { crate::arch::arm::__yield() };
91+
}
7392
}
7493
}

src/libcore/slice/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -3867,6 +3867,19 @@ impl<'a, T> DoubleEndedIterator for Windows<'a, T> {
38673867
ret
38683868
}
38693869
}
3870+
3871+
#[inline]
3872+
fn nth_back(&mut self, n: usize) -> Option<Self::Item> {
3873+
let (end, overflow) = self.v.len().overflowing_sub(n);
3874+
if end < self.size || overflow {
3875+
self.v = &[];
3876+
None
3877+
} else {
3878+
let ret = &self.v[end-self.size..end];
3879+
self.v = &self.v[..end-1];
3880+
Some(ret)
3881+
}
3882+
}
38703883
}
38713884

38723885
#[stable(feature = "rust1", since = "1.0.0")]

src/libcore/tests/slice.rs

+13
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,19 @@ fn test_windows_nth() {
578578
assert_eq!(c2.next(), None);
579579
}
580580

581+
#[test]
582+
fn test_windows_nth_back() {
583+
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
584+
let mut c = v.windows(2);
585+
assert_eq!(c.nth_back(2).unwrap()[0], 2);
586+
assert_eq!(c.next_back().unwrap()[1], 2);
587+
588+
let v2: &[i32] = &[0, 1, 2, 3, 4];
589+
let mut c2 = v2.windows(4);
590+
assert_eq!(c2.nth_back(1).unwrap()[1], 1);
591+
assert_eq!(c2.next_back(), None);
592+
}
593+
581594
#[test]
582595
fn test_windows_last() {
583596
let v: &[i32] = &[0, 1, 2, 3, 4, 5];

src/librustc_codegen_llvm/debuginfo/metadata.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1156,12 +1156,14 @@ fn prepare_union_metadata(
11561156
// Enums
11571157
//=-----------------------------------------------------------------------------
11581158

1159-
// DWARF variant support is only available starting in LLVM 7.
1159+
// DWARF variant support is only available starting in LLVM 8.
11601160
// Although the earlier enum debug info output did not work properly
11611161
// in all situations, it is better for the time being to continue to
11621162
// sometimes emit the old style rather than emit something completely
1163-
// useless when rust is compiled against LLVM 6 or older. This
1164-
// function decides which representation will be emitted.
1163+
// useless when rust is compiled against LLVM 6 or older. LLVM 7
1164+
// contains an early version of the DWARF variant support, and will
1165+
// crash when handling the new debug info format. This function
1166+
// decides which representation will be emitted.
11651167
fn use_enum_fallback(cx: &CodegenCx<'_, '_>) -> bool {
11661168
// On MSVC we have to use the fallback mode, because LLVM doesn't
11671169
// lower variant parts to PDB.

src/librustc_driver/pretty.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,20 @@ fn print_flowgraph<'a, 'tcx, W: Write>(variants: Vec<borrowck_dot::Variant>,
633633
let body = tcx.hir().body(body_id);
634634
let cfg = cfg::CFG::new(tcx, &body);
635635
let labelled_edges = mode != PpFlowGraphMode::UnlabelledEdges;
636+
let hir_id = code.id();
637+
// We have to disassemble the hir_id because name must be ASCII
638+
// alphanumeric. This does not appear in the rendered graph, so it does not
639+
// have to be user friendly.
640+
let name = format!(
641+
"hir_id_{}_{}_{}",
642+
hir_id.owner.address_space().index(),
643+
hir_id.owner.as_array_index(),
644+
hir_id.local_id.index(),
645+
);
636646
let lcfg = LabelledCFG {
637647
tcx,
638648
cfg: &cfg,
639-
name: format!("node_{}", code.id()),
649+
name,
640650
labelled_edges,
641651
};
642652

src/librustc_mir/borrow_check/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
156156
let mut flow_inits = FlowAtLocation::new(do_dataflow(
157157
tcx,
158158
mir,
159-
id,
159+
def_id,
160160
&attributes,
161161
&dead_unwinds,
162162
MaybeInitializedPlaces::new(tcx, mir, &mdpe),
@@ -191,7 +191,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
191191
let flow_borrows = FlowAtLocation::new(do_dataflow(
192192
tcx,
193193
mir,
194-
id,
194+
def_id,
195195
&attributes,
196196
&dead_unwinds,
197197
Borrows::new(tcx, mir, regioncx.clone(), &borrow_set),
@@ -200,7 +200,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
200200
let flow_uninits = FlowAtLocation::new(do_dataflow(
201201
tcx,
202202
mir,
203-
id,
203+
def_id,
204204
&attributes,
205205
&dead_unwinds,
206206
MaybeUninitializedPlaces::new(tcx, mir, &mdpe),
@@ -209,7 +209,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
209209
let flow_ever_inits = FlowAtLocation::new(do_dataflow(
210210
tcx,
211211
mir,
212-
id,
212+
def_id,
213213
&attributes,
214214
&dead_unwinds,
215215
EverInitializedPlaces::new(tcx, mir, &mdpe),

src/librustc_mir/dataflow/graphviz.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
//! Hook into libgraphviz for rendering dataflow graphs for MIR.
22
3-
use rustc::hir::HirId;
3+
use rustc::hir::def_id::DefId;
44
use rustc::mir::{BasicBlock, Mir};
55

66
use std::fs;
77
use std::io;
88
use std::marker::PhantomData;
99
use std::path::Path;
1010

11+
use crate::util::graphviz_safe_def_name;
12+
1113
use super::{BitDenotation, DataflowState};
1214
use super::DataflowBuilder;
1315
use super::DebugFormatted;
1416

1517
pub trait MirWithFlowState<'tcx> {
1618
type BD: BitDenotation<'tcx>;
17-
fn hir_id(&self) -> HirId;
19+
fn def_id(&self) -> DefId;
1820
fn mir(&self) -> &Mir<'tcx>;
1921
fn flow_state(&self) -> &DataflowState<'tcx, Self::BD>;
2022
}
@@ -23,7 +25,7 @@ impl<'a, 'tcx, BD> MirWithFlowState<'tcx> for DataflowBuilder<'a, 'tcx, BD>
2325
where BD: BitDenotation<'tcx>
2426
{
2527
type BD = BD;
26-
fn hir_id(&self) -> HirId { self.hir_id }
28+
fn def_id(&self) -> DefId { self.def_id }
2729
fn mir(&self) -> &Mir<'tcx> { self.flow_state.mir() }
2830
fn flow_state(&self) -> &DataflowState<'tcx, Self::BD> { &self.flow_state.flow_state }
2931
}
@@ -47,8 +49,8 @@ pub(crate) fn print_borrowck_graph_to<'a, 'tcx, BD, P>(
4749
let g = Graph { mbcx, phantom: PhantomData, render_idx };
4850
let mut v = Vec::new();
4951
dot::render(&g, &mut v)?;
50-
debug!("print_borrowck_graph_to path: {} hir_id: {}",
51-
path.display(), mbcx.hir_id);
52+
debug!("print_borrowck_graph_to path: {} def_id: {:?}",
53+
path.display(), mbcx.def_id);
5254
fs::write(path, v)
5355
}
5456

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

7778
fn node_id(&self, n: &Node) -> dot::Id<'_> {

src/librustc_mir/dataflow/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_data_structures::bit_set::{BitSet, BitSetOperator, HybridBitSet};
44
use rustc_data_structures::indexed_vec::Idx;
55
use rustc_data_structures::work_queue::WorkQueue;
66

7-
use rustc::hir::HirId;
7+
use rustc::hir::def_id::DefId;
88
use rustc::ty::{self, TyCtxt};
99
use rustc::mir::{self, Mir, BasicBlock, BasicBlockData, Location, Statement, Terminator};
1010
use rustc::mir::traversal;
@@ -39,7 +39,7 @@ pub(crate) struct DataflowBuilder<'a, 'tcx: 'a, BD>
3939
where
4040
BD: BitDenotation<'tcx>
4141
{
42-
hir_id: HirId,
42+
def_id: DefId,
4343
flow_state: DataflowAnalysis<'a, 'tcx, BD>,
4444
print_preflow_to: Option<String>,
4545
print_postflow_to: Option<String>,
@@ -117,7 +117,7 @@ pub struct MoveDataParamEnv<'gcx, 'tcx> {
117117

118118
pub(crate) fn do_dataflow<'a, 'gcx, 'tcx, BD, P>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
119119
mir: &'a Mir<'tcx>,
120-
hir_id: HirId,
120+
def_id: DefId,
121121
attributes: &[ast::Attribute],
122122
dead_unwinds: &BitSet<BasicBlock>,
123123
bd: BD,
@@ -127,14 +127,14 @@ pub(crate) fn do_dataflow<'a, 'gcx, 'tcx, BD, P>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
127127
P: Fn(&BD, BD::Idx) -> DebugFormatted
128128
{
129129
let flow_state = DataflowAnalysis::new(mir, dead_unwinds, bd);
130-
flow_state.run(tcx, hir_id, attributes, p)
130+
flow_state.run(tcx, def_id, attributes, p)
131131
}
132132

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

161161
let mut mbcx = DataflowBuilder {
162-
hir_id,
162+
def_id,
163163
print_preflow_to, print_postflow_to, flow_state: self,
164164
};
165165

src/librustc_mir/transform/elaborate_drops.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl MirPass for ElaborateDrops {
2828
{
2929
debug!("elaborate_drops({:?} @ {:?})", src, mir.span);
3030

31-
let id = tcx.hir().as_local_hir_id(src.def_id()).unwrap();
31+
let def_id = src.def_id();
3232
let param_env = tcx.param_env(src.def_id()).with_reveal_all();
3333
let move_data = match MoveData::gather_moves(mir, tcx) {
3434
Ok(move_data) => move_data,
@@ -50,13 +50,13 @@ impl MirPass for ElaborateDrops {
5050
move_data,
5151
param_env,
5252
};
53-
let dead_unwinds = find_dead_unwinds(tcx, mir, id, &env);
53+
let dead_unwinds = find_dead_unwinds(tcx, mir, def_id, &env);
5454
let flow_inits =
55-
do_dataflow(tcx, mir, id, &[], &dead_unwinds,
55+
do_dataflow(tcx, mir, def_id, &[], &dead_unwinds,
5656
MaybeInitializedPlaces::new(tcx, mir, &env),
5757
|bd, p| DebugFormatted::new(&bd.move_data().move_paths[p]));
5858
let flow_uninits =
59-
do_dataflow(tcx, mir, id, &[], &dead_unwinds,
59+
do_dataflow(tcx, mir, def_id, &[], &dead_unwinds,
6060
MaybeUninitializedPlaces::new(tcx, mir, &env),
6161
|bd, p| DebugFormatted::new(&bd.move_data().move_paths[p]));
6262

@@ -80,7 +80,7 @@ impl MirPass for ElaborateDrops {
8080
fn find_dead_unwinds<'a, 'tcx>(
8181
tcx: TyCtxt<'a, 'tcx, 'tcx>,
8282
mir: &Mir<'tcx>,
83-
id: hir::HirId,
83+
def_id: hir::def_id::DefId,
8484
env: &MoveDataParamEnv<'tcx, 'tcx>)
8585
-> BitSet<BasicBlock>
8686
{
@@ -89,7 +89,7 @@ fn find_dead_unwinds<'a, 'tcx>(
8989
// reach cleanup blocks, which can't have unwind edges themselves.
9090
let mut dead_unwinds = BitSet::new_empty(mir.basic_blocks().len());
9191
let flow_inits =
92-
do_dataflow(tcx, mir, id, &[], &dead_unwinds,
92+
do_dataflow(tcx, mir, def_id, &[], &dead_unwinds,
9393
MaybeInitializedPlaces::new(tcx, mir, &env),
9494
|bd, p| DebugFormatted::new(&bd.move_data().move_paths[p]));
9595
for (bb, bb_data) in mir.basic_blocks().iter_enumerated() {

src/librustc_mir/transform/generator.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,13 @@ fn locals_live_across_suspend_points(
390390
FxHashMap<BasicBlock, liveness::LiveVarSet>,
391391
) {
392392
let dead_unwinds = BitSet::new_empty(mir.basic_blocks().len());
393-
let hir_id = tcx.hir().as_local_hir_id(source.def_id()).unwrap();
393+
let def_id = source.def_id();
394394

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

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

0 commit comments

Comments
 (0)