Skip to content

Commit 97085f9

Browse files
committed
Auto merge of #52958 - pietroalbini:rollup, r=pietroalbini
Rollup of 15 pull requests Successful merges: - #52793 (Add test for NLL: unexpected "free region `` does not outlive" error ) - #52799 (Use BitVector for global sets of AttrId) - #52809 (Add test for unexpected region for local data ReStatic) - #52834 ([NLL] Allow conflicting borrows of promoted length zero arrays) - #52835 (Fix Alias intra doc ICE) - #52854 (fix memrchr in miri) - #52899 (tests/ui: Add missing mips{64} ignores) - #52908 (Use SetLenOnDrop in Vec::truncate()) - #52915 (Don't count MIR locals as borrowed after StorageDead when finding locals live across a yield terminator) - #52926 (rustc: Trim down the `rust_2018_idioms` lint group) - #52930 (rustc_resolve: record single-segment extern crate import resolutions.) - #52939 (Make io::Read::read_to_end consider io::Take::limit) - #52942 (Another SmallVec.extend optimization) - #52947 (1.27 actually added the `armv5te-unknown-linux-musleabi` target) - #52954 (async can begin expressions) Failed merges: r? @ghost
2 parents c415676 + 3e7897f commit 97085f9

Some content is hidden

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

51 files changed

+512
-211
lines changed

RELEASES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Language
216216

217217
Compiler
218218
--------
219-
- [Added the `armv5te-unknown-linux-musl` target.][50423]
219+
- [Added the `armv5te-unknown-linux-musleabi` target.][50423]
220220

221221
Libraries
222222
---------

src/liballoc/vec.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -690,14 +690,20 @@ impl<T> Vec<T> {
690690
/// [`drain`]: #method.drain
691691
#[stable(feature = "rust1", since = "1.0.0")]
692692
pub fn truncate(&mut self, len: usize) {
693+
let current_len = self.len;
693694
unsafe {
695+
let mut ptr = self.as_mut_ptr().offset(self.len as isize);
696+
// Set the final length at the end, keeping in mind that
697+
// dropping an element might panic. Works around a missed
698+
// optimization, as seen in the following issue:
699+
// https://github.com/rust-lang/rust/issues/51802
700+
let mut local_len = SetLenOnDrop::new(&mut self.len);
701+
694702
// drop any extra elements
695-
while len < self.len {
696-
// decrement len before the drop_in_place(), so a panic on Drop
697-
// doesn't re-drop the just-failed value.
698-
self.len -= 1;
699-
let len = self.len;
700-
ptr::drop_in_place(self.get_unchecked_mut(len));
703+
for _ in len..current_len {
704+
local_len.decrement_len(1);
705+
ptr = ptr.offset(-1);
706+
ptr::drop_in_place(ptr);
701707
}
702708
}
703709
}
@@ -1512,6 +1518,11 @@ impl<'a> SetLenOnDrop<'a> {
15121518
fn increment_len(&mut self, increment: usize) {
15131519
self.local_len += increment;
15141520
}
1521+
1522+
#[inline]
1523+
fn decrement_len(&mut self, decrement: usize) {
1524+
self.local_len -= decrement;
1525+
}
15151526
}
15161527

15171528
impl<'a> Drop for SetLenOnDrop<'a> {

src/libcore/slice/memchr.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,30 @@ pub fn memrchr(x: u8, text: &[u8]) -> Option<usize> {
100100
// - the first remaining bytes, < 2 word size
101101
let len = text.len();
102102
let ptr = text.as_ptr();
103-
let usize_bytes = mem::size_of::<usize>();
103+
type Chunk = usize;
104104

105-
let mut offset = {
106-
// We call this just to obtain the length of the suffix
107-
let (_, _, suffix) = unsafe { text.align_to::<usize>() };
108-
len - suffix.len()
105+
let (min_aligned_offset, max_aligned_offset) = {
106+
// We call this just to obtain the length of the prefix and suffix.
107+
// In the middle we always process two chunks at once.
108+
let (prefix, _, suffix) = unsafe { text.align_to::<(Chunk, Chunk)>() };
109+
(prefix.len(), len - suffix.len())
109110
};
111+
112+
let mut offset = max_aligned_offset;
110113
if let Some(index) = text[offset..].iter().rposition(|elt| *elt == x) {
111114
return Some(offset + index);
112115
}
113116

114-
// search the body of the text
117+
// search the body of the text, make sure we don't cross min_aligned_offset.
118+
// offset is always aligned, so just testing `>` is sufficient and avoids possible
119+
// overflow.
115120
let repeated_x = repeat_byte(x);
121+
let chunk_bytes = mem::size_of::<Chunk>();
116122

117-
while offset >= 2 * usize_bytes {
123+
while offset > min_aligned_offset {
118124
unsafe {
119-
let u = *(ptr.offset(offset as isize - 2 * usize_bytes as isize) as *const usize);
120-
let v = *(ptr.offset(offset as isize - usize_bytes as isize) as *const usize);
125+
let u = *(ptr.offset(offset as isize - 2 * chunk_bytes as isize) as *const Chunk);
126+
let v = *(ptr.offset(offset as isize - chunk_bytes as isize) as *const Chunk);
121127

122128
// break if there is a matching byte
123129
let zu = contains_zero_byte(u ^ repeated_x);
@@ -126,7 +132,7 @@ pub fn memrchr(x: u8, text: &[u8]) -> Option<usize> {
126132
break;
127133
}
128134
}
129-
offset -= 2 * usize_bytes;
135+
offset -= 2 * chunk_bytes;
130136
}
131137

132138
// find the byte before the point the body loop stopped

src/librustc/mir/traversal.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use rustc_data_structures::bitvec::BitVector;
11+
use rustc_data_structures::bitvec::BitArray;
1212

1313
use super::*;
1414

@@ -32,7 +32,7 @@ use super::*;
3232
#[derive(Clone)]
3333
pub struct Preorder<'a, 'tcx: 'a> {
3434
mir: &'a Mir<'tcx>,
35-
visited: BitVector<BasicBlock>,
35+
visited: BitArray<BasicBlock>,
3636
worklist: Vec<BasicBlock>,
3737
}
3838

@@ -42,7 +42,7 @@ impl<'a, 'tcx> Preorder<'a, 'tcx> {
4242

4343
Preorder {
4444
mir,
45-
visited: BitVector::new(mir.basic_blocks().len()),
45+
visited: BitArray::new(mir.basic_blocks().len()),
4646
worklist,
4747
}
4848
}
@@ -104,15 +104,15 @@ impl<'a, 'tcx> ExactSizeIterator for Preorder<'a, 'tcx> {}
104104
/// A Postorder traversal of this graph is `D B C A` or `D C B A`
105105
pub struct Postorder<'a, 'tcx: 'a> {
106106
mir: &'a Mir<'tcx>,
107-
visited: BitVector<BasicBlock>,
107+
visited: BitArray<BasicBlock>,
108108
visit_stack: Vec<(BasicBlock, Successors<'a>)>
109109
}
110110

111111
impl<'a, 'tcx> Postorder<'a, 'tcx> {
112112
pub fn new(mir: &'a Mir<'tcx>, root: BasicBlock) -> Postorder<'a, 'tcx> {
113113
let mut po = Postorder {
114114
mir,
115-
visited: BitVector::new(mir.basic_blocks().len()),
115+
visited: BitArray::new(mir.basic_blocks().len()),
116116
visit_stack: Vec::new()
117117
};
118118

src/librustc/traits/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use middle::lang_items;
4545
use mir::interpret::{GlobalId};
4646

4747
use rustc_data_structures::sync::Lock;
48-
use rustc_data_structures::bitvec::BitVector;
48+
use rustc_data_structures::bitvec::BitArray;
4949
use std::iter;
5050
use std::cmp;
5151
use std::fmt;
@@ -3056,7 +3056,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
30563056
} else {
30573057
return Err(Unimplemented);
30583058
};
3059-
let mut ty_params = BitVector::new(substs_a.types().count());
3059+
let mut ty_params = BitArray::new(substs_a.types().count());
30603060
let mut found = false;
30613061
for ty in field.walk() {
30623062
if let ty::TyParam(p) = ty.sty {

src/librustc_codegen_llvm/debuginfo/create_scope_map.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use libc::c_uint;
2121

2222
use syntax_pos::Pos;
2323

24-
use rustc_data_structures::bitvec::BitVector;
24+
use rustc_data_structures::bitvec::BitArray;
2525
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
2626

2727
use syntax_pos::BytePos;
@@ -64,7 +64,7 @@ pub fn create_mir_scopes(
6464
};
6565

6666
// Find all the scopes with variables defined in them.
67-
let mut has_variables = BitVector::new(mir.source_scopes.len());
67+
let mut has_variables = BitArray::new(mir.source_scopes.len());
6868
for var in mir.vars_iter() {
6969
let decl = &mir.local_decls[var];
7070
has_variables.insert(decl.visibility_scope);
@@ -81,7 +81,7 @@ pub fn create_mir_scopes(
8181

8282
fn make_mir_scope(cx: &CodegenCx<'ll, '_>,
8383
mir: &Mir,
84-
has_variables: &BitVector<SourceScope>,
84+
has_variables: &BitArray<SourceScope>,
8585
debug_context: &FunctionDebugContextData<'ll>,
8686
scope: SourceScope,
8787
scopes: &mut IndexVec<SourceScope, MirDebugScope<'ll>>) {

src/librustc_codegen_llvm/mir/analyze.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! An analysis to determine which locals require allocas and
1212
//! which do not.
1313
14-
use rustc_data_structures::bitvec::BitVector;
14+
use rustc_data_structures::bitvec::BitArray;
1515
use rustc_data_structures::graph::dominators::Dominators;
1616
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
1717
use rustc::mir::{self, Location, TerminatorKind};
@@ -22,7 +22,7 @@ use rustc::ty::layout::LayoutOf;
2222
use type_of::LayoutLlvmExt;
2323
use super::FunctionCx;
2424

25-
pub fn non_ssa_locals(fx: &FunctionCx<'a, 'll, 'tcx>) -> BitVector<mir::Local> {
25+
pub fn non_ssa_locals(fx: &FunctionCx<'a, 'll, 'tcx>) -> BitArray<mir::Local> {
2626
let mir = fx.mir;
2727
let mut analyzer = LocalAnalyzer::new(fx);
2828

@@ -54,7 +54,7 @@ pub fn non_ssa_locals(fx: &FunctionCx<'a, 'll, 'tcx>) -> BitVector<mir::Local> {
5454
struct LocalAnalyzer<'mir, 'a: 'mir, 'll: 'a, 'tcx: 'll> {
5555
fx: &'mir FunctionCx<'a, 'll, 'tcx>,
5656
dominators: Dominators<mir::BasicBlock>,
57-
non_ssa_locals: BitVector<mir::Local>,
57+
non_ssa_locals: BitArray<mir::Local>,
5858
// The location of the first visited direct assignment to each
5959
// local, or an invalid location (out of bounds `block` index).
6060
first_assignment: IndexVec<mir::Local, Location>
@@ -67,7 +67,7 @@ impl LocalAnalyzer<'mir, 'a, 'll, 'tcx> {
6767
let mut analyzer = LocalAnalyzer {
6868
fx,
6969
dominators: fx.mir.dominators(),
70-
non_ssa_locals: BitVector::new(fx.mir.local_decls.len()),
70+
non_ssa_locals: BitArray::new(fx.mir.local_decls.len()),
7171
first_assignment: IndexVec::from_elem(invalid_location, &fx.mir.local_decls)
7272
};
7373

src/librustc_codegen_llvm/mir/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use syntax::symbol::keywords;
3131

3232
use std::iter;
3333

34-
use rustc_data_structures::bitvec::BitVector;
34+
use rustc_data_structures::bitvec::BitArray;
3535
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
3636

3737
pub use self::constant::codegen_static_initializer;
@@ -323,7 +323,7 @@ pub fn codegen_mir(
323323
debuginfo::start_emitting_source_locations(&fx.debug_context);
324324

325325
let rpo = traversal::reverse_postorder(&mir);
326-
let mut visited = BitVector::new(mir.basic_blocks().len());
326+
let mut visited = BitArray::new(mir.basic_blocks().len());
327327

328328
// Codegen the body of each block using reverse postorder
329329
for (bb, _) in rpo {
@@ -417,7 +417,7 @@ fn arg_local_refs(
417417
bx: &Builder<'a, 'll, 'tcx>,
418418
fx: &FunctionCx<'a, 'll, 'tcx>,
419419
scopes: &IndexVec<mir::SourceScope, debuginfo::MirDebugScope<'ll>>,
420-
memory_locals: &BitVector<mir::Local>,
420+
memory_locals: &BitArray<mir::Local>,
421421
) -> Vec<LocalRef<'ll, 'tcx>> {
422422
let mir = fx.mir;
423423
let tcx = bx.tcx();

0 commit comments

Comments
 (0)