Skip to content

Commit 8ccab7e

Browse files
committed
Auto merge of #47900 - kennytm:rollup, r=kennytm
Rollup of 16 pull requests - Successful merges: #47838, #47840, #47844, #47874, #47875, #47876, #47884, #47886, #47889, #47890, #47891, #47795, #47677, #47893, #47895, #47552 - Failed merges:
2 parents 560a2f4 + af95302 commit 8ccab7e

Some content is hidden

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

43 files changed

+320
-48
lines changed

src/bootstrap/builder.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,11 @@ impl<'a> Builder<'a> {
377377
self.ensure(Libdir { compiler, target })
378378
}
379379

380+
pub fn sysroot_codegen_backends(&self, compiler: Compiler) -> PathBuf {
381+
self.sysroot_libdir(compiler, compiler.host)
382+
.with_file_name("codegen-backends")
383+
}
384+
380385
/// Returns the compiler's libdir where it stores the dynamic libraries that
381386
/// it itself links against.
382387
///

src/bootstrap/compile.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,7 @@ fn copy_codegen_backends_to_sysroot(builder: &Builder,
724724
//
725725
// Here we're looking for the output dylib of the `CodegenBackend` step and
726726
// we're copying that into the `codegen-backends` folder.
727-
let libdir = builder.sysroot_libdir(target_compiler, target);
728-
let dst = libdir.join("codegen-backends");
727+
let dst = builder.sysroot_codegen_backends(target_compiler);
729728
t!(fs::create_dir_all(&dst));
730729

731730
for backend in builder.config.rust_codegen_backends.iter() {

src/bootstrap/dist.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,11 +435,9 @@ impl Step for Rustc {
435435
}
436436

437437
// Copy over the codegen backends
438-
let backends_src = builder.sysroot_libdir(compiler, host)
439-
.join("codegen-backends");
440-
let backends_dst = image.join("lib/rustlib")
441-
.join(&*host)
442-
.join("lib/codegen-backends");
438+
let backends_src = builder.sysroot_codegen_backends(compiler);
439+
let backends_rel = backends_src.strip_prefix(&src).unwrap();
440+
let backends_dst = image.join(&backends_rel);
443441
t!(fs::create_dir_all(&backends_dst));
444442
cp_r(&backends_src, &backends_dst);
445443

src/libcore/fmt/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,6 +1586,7 @@ impl Display for ! {
15861586

15871587
#[stable(feature = "rust1", since = "1.0.0")]
15881588
impl Debug for bool {
1589+
#[inline]
15891590
fn fmt(&self, f: &mut Formatter) -> Result {
15901591
Display::fmt(self, f)
15911592
}
@@ -1748,6 +1749,7 @@ impl<T: Debug> Debug for [T] {
17481749

17491750
#[stable(feature = "rust1", since = "1.0.0")]
17501751
impl Debug for () {
1752+
#[inline]
17511753
fn fmt(&self, f: &mut Formatter) -> Result {
17521754
f.pad("()")
17531755
}

src/libcore/fmt/num.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ macro_rules! debug {
157157
($T:ident) => {
158158
#[stable(feature = "rust1", since = "1.0.0")]
159159
impl fmt::Debug for $T {
160+
#[inline]
160161
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
161162
fmt::Display::fmt(self, f)
162163
}

src/libcore/iter/mod.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ use fmt;
307307
use iter_private::TrustedRandomAccess;
308308
use ops::Try;
309309
use usize;
310+
use intrinsics;
310311

311312
#[stable(feature = "rust1", since = "1.0.0")]
312313
pub use self::iterator::Iterator;
@@ -694,6 +695,49 @@ impl<I> Iterator for StepBy<I> where I: Iterator {
694695
(f(inner_hint.0), inner_hint.1.map(f))
695696
}
696697
}
698+
699+
#[inline]
700+
fn nth(&mut self, mut n: usize) -> Option<Self::Item> {
701+
if self.first_take {
702+
self.first_take = false;
703+
let first = self.iter.next();
704+
if n == 0 {
705+
return first;
706+
}
707+
n -= 1;
708+
}
709+
// n and self.step are indices, we need to add 1 to get the amount of elements
710+
// When calling `.nth`, we need to subtract 1 again to convert back to an index
711+
// step + 1 can't overflow because `.step_by` sets `self.step` to `step - 1`
712+
let mut step = self.step + 1;
713+
// n + 1 could overflow
714+
// thus, if n is usize::MAX, instead of adding one, we call .nth(step)
715+
if n == usize::MAX {
716+
self.iter.nth(step - 1);
717+
} else {
718+
n += 1;
719+
}
720+
721+
// overflow handling
722+
loop {
723+
let mul = n.checked_mul(step);
724+
if unsafe { intrinsics::likely(mul.is_some()) } {
725+
return self.iter.nth(mul.unwrap() - 1);
726+
}
727+
let div_n = usize::MAX / n;
728+
let div_step = usize::MAX / step;
729+
let nth_n = div_n * n;
730+
let nth_step = div_step * step;
731+
let nth = if nth_n > nth_step {
732+
step -= div_n;
733+
nth_n
734+
} else {
735+
n -= div_step;
736+
nth_step
737+
};
738+
self.iter.nth(nth - 1);
739+
}
740+
}
697741
}
698742

699743
// StepBy can only make the iterator shorter, so the len will still fit.

src/libcore/tests/iter.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,68 @@ fn test_iterator_step_by() {
161161
assert_eq!(it.next(), None);
162162
}
163163

164+
#[test]
165+
fn test_iterator_step_by_nth() {
166+
let mut it = (0..16).step_by(5);
167+
assert_eq!(it.nth(0), Some(0));
168+
assert_eq!(it.nth(0), Some(5));
169+
assert_eq!(it.nth(0), Some(10));
170+
assert_eq!(it.nth(0), Some(15));
171+
assert_eq!(it.nth(0), None);
172+
173+
let it = (0..18).step_by(5);
174+
assert_eq!(it.clone().nth(0), Some(0));
175+
assert_eq!(it.clone().nth(1), Some(5));
176+
assert_eq!(it.clone().nth(2), Some(10));
177+
assert_eq!(it.clone().nth(3), Some(15));
178+
assert_eq!(it.clone().nth(4), None);
179+
assert_eq!(it.clone().nth(42), None);
180+
}
181+
182+
#[test]
183+
fn test_iterator_step_by_nth_overflow() {
184+
#[cfg(target_pointer_width = "8")]
185+
type Bigger = u16;
186+
#[cfg(target_pointer_width = "16")]
187+
type Bigger = u32;
188+
#[cfg(target_pointer_width = "32")]
189+
type Bigger = u64;
190+
#[cfg(target_pointer_width = "64")]
191+
type Bigger = u128;
192+
193+
#[derive(Clone)]
194+
struct Test(Bigger);
195+
impl<'a> Iterator for &'a mut Test {
196+
type Item = i32;
197+
fn next(&mut self) -> Option<Self::Item> { Some(21) }
198+
fn nth(&mut self, n: usize) -> Option<Self::Item> {
199+
self.0 += n as Bigger + 1;
200+
Some(42)
201+
}
202+
}
203+
204+
let mut it = Test(0);
205+
let root = usize::MAX >> (::std::mem::size_of::<usize>() * 8 / 2);
206+
let n = root + 20;
207+
(&mut it).step_by(n).nth(n);
208+
assert_eq!(it.0, n as Bigger * n as Bigger);
209+
210+
// large step
211+
let mut it = Test(0);
212+
(&mut it).step_by(usize::MAX).nth(5);
213+
assert_eq!(it.0, (usize::MAX as Bigger) * 5);
214+
215+
// n + 1 overflows
216+
let mut it = Test(0);
217+
(&mut it).step_by(2).nth(usize::MAX);
218+
assert_eq!(it.0, (usize::MAX as Bigger) * 2);
219+
220+
// n + 1 overflows
221+
let mut it = Test(0);
222+
(&mut it).step_by(1).nth(usize::MAX);
223+
assert_eq!(it.0, (usize::MAX as Bigger) * 1);
224+
}
225+
164226
#[test]
165227
#[should_panic]
166228
fn test_iterator_step_by_zero() {

src/libpanic_abort/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
#![feature(libc)]
2828
#![feature(panic_runtime)]
2929
#![feature(staged_api)]
30+
#![feature(rustc_attrs)]
3031

3132
// Rust's "try" function, but if we're aborting on panics we just call the
3233
// function as there's nothing else we need to do here.
3334
#[no_mangle]
35+
#[rustc_std_internal_symbol]
3436
pub unsafe extern fn __rust_maybe_catch_panic(f: fn(*mut u8),
3537
data: *mut u8,
3638
_data_ptr: *mut usize,
@@ -50,6 +52,7 @@ pub unsafe extern fn __rust_maybe_catch_panic(f: fn(*mut u8),
5052
// will kill us with an illegal instruction, which will do a good enough job for
5153
// now hopefully.
5254
#[no_mangle]
55+
#[rustc_std_internal_symbol]
5356
pub unsafe extern fn __rust_start_panic(_data: usize, _vtable: usize) -> u32 {
5457
abort();
5558

src/librustc/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ pointers for understanding them better.
176176
- `'gcx` -- the lifetime of the global arena (see `librustc/ty`).
177177
- generics -- the set of generic type parameters defined on a type or item
178178
- ICE -- internal compiler error. When the compiler crashes.
179+
- ICH -- incremental compilation hash.
179180
- infcx -- the inference context (see `librustc/infer`)
180181
- MIR -- the **Mid-level IR** that is created after type-checking for use by borrowck and trans.
181182
Defined in the `src/librustc/mir/` module, but much of the code that manipulates it is

src/librustc/dep_graph/dep_node.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,9 @@ define_dep_nodes!( <'tcx>
639639
[] TargetFeaturesEnabled(DefId),
640640

641641
[] InstanceDefSizeEstimate { instance_def: InstanceDef<'tcx> },
642+
643+
[] GetSymbolExportLevel(DefId),
644+
642645
);
643646

644647
trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {

0 commit comments

Comments
 (0)