Skip to content

Commit a19122c

Browse files
committed
Auto merge of #47327 - MaloJaffre:beta-backport, r=Mark-Simulacrum
[beta] Backports Cherry-picked (cleanly) into beta: - #46916 - #47161 - #47208 - #47269
2 parents 2a65c6a + 6ff413e commit a19122c

File tree

40 files changed

+200
-81
lines changed

40 files changed

+200
-81
lines changed

src/Cargo.lock

+18-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap/channel.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub const CFG_RELEASE_NUM: &str = "1.24.0";
2929
// An optional number to put after the label, e.g. '.2' -> '-beta.2'
3030
// Be sure to make this starts with a dot to conform to semver pre-release
3131
// versions (section 9)
32-
pub const CFG_PRERELEASE_VERSION: &str = ".1";
32+
pub const CFG_PRERELEASE_VERSION: &str = ".2";
3333

3434
pub struct GitInfo {
3535
inner: Option<Info>,

src/libcore/str/pattern.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ unsafe impl<'a> Searcher<'a> for CharSearcher<'a> {
284284
#[inline]
285285
fn next(&mut self) -> SearchStep {
286286
let old_finger = self.finger;
287-
let slice = unsafe { self.haystack.get_unchecked(old_finger..self.haystack.len()) };
287+
let slice = unsafe { self.haystack.get_unchecked(old_finger..self.finger_back) };
288288
let mut iter = slice.chars();
289289
let old_len = iter.iter.len();
290290
if let Some(ch) = iter.next() {
@@ -304,7 +304,8 @@ unsafe impl<'a> Searcher<'a> for CharSearcher<'a> {
304304
fn next_match(&mut self) -> Option<(usize, usize)> {
305305
loop {
306306
// get the haystack after the last character found
307-
let bytes = if let Some(slice) = self.haystack.as_bytes().get(self.finger..) {
307+
let bytes = if let Some(slice) = self.haystack.as_bytes()
308+
.get(self.finger..self.finger_back) {
308309
slice
309310
} else {
310311
return None;
@@ -340,7 +341,7 @@ unsafe impl<'a> Searcher<'a> for CharSearcher<'a> {
340341
}
341342
} else {
342343
// found nothing, exit
343-
self.finger = self.haystack.len();
344+
self.finger = self.finger_back;
344345
return None;
345346
}
346347
}
@@ -353,7 +354,7 @@ unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> {
353354
#[inline]
354355
fn next_back(&mut self) -> SearchStep {
355356
let old_finger = self.finger_back;
356-
let slice = unsafe { self.haystack.slice_unchecked(0, old_finger) };
357+
let slice = unsafe { self.haystack.slice_unchecked(self.finger, old_finger) };
357358
let mut iter = slice.chars();
358359
let old_len = iter.iter.len();
359360
if let Some(ch) = iter.next_back() {
@@ -374,14 +375,17 @@ unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> {
374375
let haystack = self.haystack.as_bytes();
375376
loop {
376377
// get the haystack up to but not including the last character searched
377-
let bytes = if let Some(slice) = haystack.get(..self.finger_back) {
378+
let bytes = if let Some(slice) = haystack.get(self.finger..self.finger_back) {
378379
slice
379380
} else {
380381
return None;
381382
};
382383
// the last byte of the utf8 encoded needle
383384
let last_byte = unsafe { *self.utf8_encoded.get_unchecked(self.utf8_size - 1) };
384385
if let Some(index) = memchr::memrchr(last_byte, bytes) {
386+
// we searched a slice that was offset by self.finger,
387+
// add self.finger to recoup the original index
388+
let index = self.finger + index;
385389
// memrchr will return the index of the byte we wish to
386390
// find. In case of an ASCII character, this is indeed
387391
// were we wish our new finger to be ("after" the found
@@ -412,7 +416,7 @@ unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> {
412416
// found the last byte when searching in reverse.
413417
self.finger_back = index;
414418
} else {
415-
self.finger_back = 0;
419+
self.finger_back = self.finger;
416420
// found nothing, exit
417421
return None;
418422
}

src/libcore/tests/pattern.rs

+38
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,41 @@ fn test_reverse_search_shared_bytes() {
262262
[InRange(37, 40), Rejects(34, 37), InRange(10, 13), Rejects(8, 10), Done]
263263
);
264264
}
265+
266+
#[test]
267+
fn double_ended_regression_test() {
268+
// https://github.com/rust-lang/rust/issues/47175
269+
// Ensures that double ended searching comes to a convergence
270+
search_asserts!("abcdeabcdeabcde", 'a', "alternating double ended search",
271+
[next_match, next_match_back, next_match, next_match_back],
272+
[InRange(0, 1), InRange(10, 11), InRange(5, 6), Done]
273+
);
274+
search_asserts!("abcdeabcdeabcde", 'a', "triple double ended search for a",
275+
[next_match, next_match_back, next_match_back, next_match_back],
276+
[InRange(0, 1), InRange(10, 11), InRange(5, 6), Done]
277+
);
278+
search_asserts!("abcdeabcdeabcde", 'd', "triple double ended search for d",
279+
[next_match, next_match_back, next_match_back, next_match_back],
280+
[InRange(3, 4), InRange(13, 14), InRange(8, 9), Done]
281+
);
282+
search_asserts!(STRESS, 'Á', "Double ended search for two-byte Latin character",
283+
[next_match, next_match_back, next_match, next_match_back],
284+
[InRange(0, 2), InRange(32, 34), InRange(8, 10), Done]
285+
);
286+
search_asserts!(STRESS, '각', "Reverse double ended search for three-byte Hangul character",
287+
[next_match_back, next_back, next_match, next, next_match_back, next_match],
288+
[InRange(34, 37), Rejects(32, 34), InRange(19, 22), Rejects(22, 25), InRange(28, 31), Done]
289+
);
290+
search_asserts!(STRESS, 'ก', "Double ended search for three-byte Thai character",
291+
[next_match, next_back, next, next_match_back, next_match],
292+
[InRange(22, 25), Rejects(47, 48), Rejects(25, 28), InRange(40, 43), Done]
293+
);
294+
search_asserts!(STRESS, '😁', "Double ended search for four-byte emoji",
295+
[next_match_back, next, next_match, next_back, next_match],
296+
[InRange(43, 47), Rejects(0, 2), InRange(15, 19), Rejects(40, 43), Done]
297+
);
298+
search_asserts!(STRESS, 'ꁁ', "Double ended search for three-byte Yi character with repeated bytes",
299+
[next_match, next, next_match_back, next_back, next_match],
300+
[InRange(10, 13), Rejects(13, 14), InRange(37, 40), Rejects(34, 37), Done]
301+
);
302+
}

src/librustc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bitflags = "1.0"
1414
fmt_macros = { path = "../libfmt_macros" }
1515
graphviz = { path = "../libgraphviz" }
1616
jobserver = "0.1"
17-
log = "0.3"
17+
log = "0.4"
1818
rustc_apfloat = { path = "../librustc_apfloat" }
1919
rustc_back = { path = "../librustc_back" }
2020
rustc_const_math = { path = "../librustc_const_math" }

src/librustc/hir/map/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ pub fn map_crate<'hir>(sess: &::session::Session,
10681068
cmdline_args)
10691069
};
10701070

1071-
if log_enabled!(::log::LogLevel::Debug) {
1071+
if log_enabled!(::log::Level::Debug) {
10721072
// This only makes sense for ordered stores; note the
10731073
// enumerate to count the number of entries.
10741074
let (entries_less_1, _) = map.iter().filter(|&x| {

src/librustc/mir/mono.rs

+12
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ use syntax::ast::NodeId;
1212
use syntax::symbol::InternedString;
1313
use ty::Instance;
1414
use util::nodemap::FxHashMap;
15+
use rustc_data_structures::base_n;
1516
use rustc_data_structures::stable_hasher::{HashStable, StableHasherResult,
1617
StableHasher};
1718
use ich::{Fingerprint, StableHashingContext, NodeIdHashingMode};
19+
use std::hash::Hash;
1820

1921
#[derive(PartialEq, Eq, Clone, Copy, Debug, Hash)]
2022
pub enum MonoItem<'tcx> {
@@ -119,6 +121,16 @@ impl<'tcx> CodegenUnit<'tcx> {
119121
{
120122
&mut self.items
121123
}
124+
125+
pub fn mangle_name(human_readable_name: &str) -> String {
126+
// We generate a 80 bit hash from the name. This should be enough to
127+
// avoid collisions and is still reasonably short for filenames.
128+
let mut hasher = StableHasher::new();
129+
human_readable_name.hash(&mut hasher);
130+
let hash: u128 = hasher.finish();
131+
let hash = hash & ((1u128 << 80) - 1);
132+
base_n::encode(hash, base_n::CASE_INSENSITIVE)
133+
}
122134
}
123135

124136
impl<'tcx> HashStable<StableHashingContext<'tcx>> for CodegenUnit<'tcx> {

src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12341234
"rewrite operators on i128 and u128 into lang item calls (typically provided \
12351235
by compiler-builtins) so translation doesn't need to support them,
12361236
overriding the default for the current target"),
1237+
human_readable_cgu_names: bool = (false, parse_bool, [TRACKED],
1238+
"generate human-readable, predictable names for codegen units"),
12371239
}
12381240

12391241
pub fn default_lib_output() -> CrateType {

src/librustc_back/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ crate-type = ["dylib"]
1111
[dependencies]
1212
syntax = { path = "../libsyntax" }
1313
serialize = { path = "../libserialize" }
14-
log = "0.3"
14+
log = "0.4"
1515
rand = "0.3"
1616

1717
[features]

src/librustc_borrowck/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ crate-type = ["dylib"]
1010
test = false
1111

1212
[dependencies]
13-
log = "0.3"
13+
log = "0.4"
1414
syntax = { path = "../libsyntax" }
1515
syntax_pos = { path = "../libsyntax_pos" }
1616
graphviz = { path = "../libgraphviz" }

src/librustc_const_eval/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ crate-type = ["dylib"]
1010

1111
[dependencies]
1212
arena = { path = "../libarena" }
13-
log = "0.3"
13+
log = "0.4"
1414
rustc = { path = "../librustc" }
1515
rustc_const_math = { path = "../librustc_const_math" }
1616
rustc_data_structures = { path = "../librustc_data_structures" }

src/librustc_data_structures/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ path = "lib.rs"
99
crate-type = ["dylib"]
1010

1111
[dependencies]
12-
log = "0.3"
12+
log = "0.4"
1313
serialize = { path = "../libserialize" }
1414
cfg-if = "0.1.2"
1515
stable_deref_trait = "1.0.0"
1616
parking_lot_core = "0.2.8"
1717

1818
[dependencies.parking_lot]
1919
version = "0.5"
20-
features = ["nightly"]
20+
features = ["nightly"]

0 commit comments

Comments
 (0)