Skip to content

Commit ac60ca0

Browse files
committed
Auto merge of #63655 - Centril:rollup-ty1ot40, r=Centril
Rollup of 4 pull requests Successful merges: - #62737 (Override Cycle::try_fold) - #63505 (Hash the remapped sysroot instead of the original.) - #63559 (rustc_codegen_utils: account for 1-indexed anonymous lifetimes in v0 mangling.) - #63621 (Modify librustc_llvm to pass -DNDEBUG while compiling.) Failed merges: r? @ghost
2 parents e910be8 + 6bce50f commit ac60ca0

File tree

9 files changed

+77
-10
lines changed

9 files changed

+77
-10
lines changed

src/bootstrap/compile.rs

+3
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,9 @@ pub fn build_codegen_backend(builder: &Builder<'_>,
790790
if builder.config.llvm_use_libcxx {
791791
cargo.env("LLVM_USE_LIBCXX", "1");
792792
}
793+
if builder.config.llvm_optimize && !builder.config.llvm_release_debuginfo {
794+
cargo.env("LLVM_NDEBUG", "1");
795+
}
793796
}
794797
_ => panic!("unknown backend: {}", backend),
795798
}

src/libcore/iter/adapters/mod.rs

+30
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,36 @@ impl<I> Iterator for Cycle<I> where I: Clone + Iterator {
405405
_ => (usize::MAX, None)
406406
}
407407
}
408+
409+
#[inline]
410+
fn try_fold<Acc, F, R>(&mut self, mut acc: Acc, mut f: F) -> R
411+
where
412+
F: FnMut(Acc, Self::Item) -> R,
413+
R: Try<Ok = Acc>,
414+
{
415+
// fully iterate the current iterator. this is necessary because
416+
// `self.iter` may be empty even when `self.orig` isn't
417+
acc = self.iter.try_fold(acc, &mut f)?;
418+
self.iter = self.orig.clone();
419+
420+
// complete a full cycle, keeping track of whether the cycled
421+
// iterator is empty or not. we need to return early in case
422+
// of an empty iterator to prevent an infinite loop
423+
let mut is_empty = true;
424+
acc = self.iter.try_fold(acc, |acc, x| {
425+
is_empty = false;
426+
f(acc, x)
427+
})?;
428+
429+
if is_empty {
430+
return Try::from_ok(acc);
431+
}
432+
433+
loop {
434+
self.iter = self.orig.clone();
435+
acc = self.iter.try_fold(acc, &mut f)?;
436+
}
437+
}
408438
}
409439

410440
#[stable(feature = "fused", since = "1.26.0")]

src/libcore/tests/iter.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1152,6 +1152,18 @@ fn test_cycle() {
11521152
assert_eq!(empty::<i32>().cycle().fold(0, |acc, x| acc + x), 0);
11531153

11541154
assert_eq!(once(1).cycle().skip(1).take(4).fold(0, |acc, x| acc + x), 4);
1155+
1156+
assert_eq!((0..10).cycle().take(5).sum::<i32>(), 10);
1157+
assert_eq!((0..10).cycle().take(15).sum::<i32>(), 55);
1158+
assert_eq!((0..10).cycle().take(25).sum::<i32>(), 100);
1159+
1160+
let mut iter = (0..10).cycle();
1161+
iter.nth(14);
1162+
assert_eq!(iter.take(8).sum::<i32>(), 38);
1163+
1164+
let mut iter = (0..10).cycle();
1165+
iter.nth(9);
1166+
assert_eq!(iter.take(3).sum::<i32>(), 3);
11551167
}
11561168

11571169
#[test]

src/librustc/session/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ top_level_options!(
395395
output_types: OutputTypes [TRACKED],
396396
search_paths: Vec<SearchPath> [UNTRACKED],
397397
libs: Vec<(String, Option<String>, Option<cstore::NativeLibraryKind>)> [TRACKED],
398-
maybe_sysroot: Option<PathBuf> [TRACKED],
398+
maybe_sysroot: Option<PathBuf> [UNTRACKED],
399399

400400
target_triple: TargetTriple [TRACKED],
401401

src/librustc_codegen_utils/symbol_names/v0.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,14 @@ impl SymbolMangler<'tcx> {
198198

199199
let lifetimes = regions.into_iter().map(|br| {
200200
match br {
201-
ty::BrAnon(i) => i + 1,
201+
ty::BrAnon(i) => {
202+
// FIXME(eddyb) for some reason, `anonymize_late_bound_regions` starts at `1`.
203+
assert_ne!(i, 0);
204+
i - 1
205+
},
202206
_ => bug!("symbol_names: non-anonymized region `{:?}` in `{:?}`", br, value),
203207
}
204-
}).max().unwrap_or(0);
208+
}).max().map_or(0, |max| max + 1);
205209

206210
self.push_opt_integer_62("G", lifetimes as u64);
207211
lifetime_depths.end += lifetimes;
@@ -297,6 +301,10 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
297301
// Late-bound lifetimes use indices starting at 1,
298302
// see `BinderLevel` for more details.
299303
ty::ReLateBound(debruijn, ty::BrAnon(i)) => {
304+
// FIXME(eddyb) for some reason, `anonymize_late_bound_regions` starts at `1`.
305+
assert_ne!(i, 0);
306+
let i = i - 1;
307+
300308
let binder = &self.binders[self.binders.len() - 1 - debruijn.index()];
301309
let depth = binder.lifetime_depths.start + i;
302310

src/librustc_llvm/build.rs

+4
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ fn main() {
151151
cfg.define("LLVM_RUSTLLVM", None);
152152
}
153153

154+
if env::var_os("LLVM_NDEBUG").is_some() {
155+
cfg.define("NDEBUG", None);
156+
}
157+
154158
build_helper::rerun_if_changed_anything_in_dir(Path::new("../rustllvm"));
155159
cfg.file("../rustllvm/PassWrapper.cpp")
156160
.file("../rustllvm/RustWrapper.cpp")

src/test/run-make-fulldeps/reproducible-build-2/Makefile

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# Objects are reproducible but their path is not.
66

77
all: \
8-
fat_lto
8+
fat_lto \
9+
sysroot
910

1011
fat_lto:
1112
rm -rf $(TMPDIR) && mkdir $(TMPDIR)
@@ -14,3 +15,12 @@ fat_lto:
1415
cp $(TMPDIR)/reproducible-build $(TMPDIR)/reproducible-build-a
1516
$(RUSTC) reproducible-build.rs -C lto=fat
1617
cmp "$(TMPDIR)/reproducible-build-a" "$(TMPDIR)/reproducible-build" || exit 1
18+
19+
sysroot:
20+
rm -rf $(TMPDIR) && mkdir $(TMPDIR)
21+
$(RUSTC) reproducible-build-aux.rs
22+
$(RUSTC) reproducible-build.rs --crate-type rlib --sysroot $(shell $(RUSTC) --print sysroot) --remap-path-prefix=$(shell $(RUSTC) --print sysroot)=/sysroot
23+
cp -r $(shell $(RUSTC) --print sysroot) $(TMPDIR)/sysroot
24+
cp $(TMPDIR)/libreproducible_build.rlib $(TMPDIR)/libfoo.rlib
25+
$(RUSTC) reproducible-build.rs --crate-type rlib --sysroot $(TMPDIR)/sysroot --remap-path-prefix=$(TMPDIR)/sysroot=/sysroot
26+
cmp "$(TMPDIR)/libreproducible_build.rlib" "$(TMPDIR)/libfoo.rlib" || exit 1

src/test/ui/symbol-names/impl1.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ fn main() {
6464
//[legacy]~^ ERROR symbol-name(_ZN198_$LT$$u5b$$RF$dyn$u20$impl1..Foo$u2b$Assoc$u20$$u3d$$u20$extern$u20$$u22$C$u22$$u20$fn$LP$$RF$u8$RP$$u2b$impl1..AutoTrait$u3b$$u20$_$u5d$$u20$as$u20$impl1..main..$u7b$$u7b$closure$u7d$$u7d$..Bar$GT$6method
6565
//[legacy]~| ERROR demangling(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method
6666
//[legacy]~| ERROR demangling-alt(<[&dyn impl1::Foo+Assoc = extern "C" fn(&u8)+impl1::AutoTrait; _] as impl1::main::{{closure}}::Bar>::method)
67-
//[v0]~^^^^ ERROR symbol-name(_RNvXNCNvCs4fqI2P2rA04_5impl14mains_0ARDNtB6_3Foop5AssocFG0_KCRL0_hEuNtB6_9AutoTraitEL_j3_NtB2_3Bar6method)
68-
//[v0]~| ERROR demangling(<[&dyn impl1[317d481089b8c8fe]::Foo<Assoc = for<'a, 'b> extern "C" fn(&'b u8)> + impl1[317d481089b8c8fe]::AutoTrait; 3: usize] as impl1[317d481089b8c8fe]::main::{closure#1}::Bar>::method)
69-
//[v0]~| ERROR demangling-alt(<[&dyn impl1::Foo<Assoc = for<'a, 'b> extern "C" fn(&'b u8)> + impl1::AutoTrait; 3] as impl1::main::{closure#1}::Bar>::method)
67+
//[v0]~^^^^ ERROR symbol-name(_RNvXNCNvCs4fqI2P2rA04_5impl14mains_0ARDNtB6_3Foop5AssocFG_KCRL0_hEuNtB6_9AutoTraitEL_j3_NtB2_3Bar6method)
68+
//[v0]~| ERROR demangling(<[&dyn impl1[317d481089b8c8fe]::Foo<Assoc = for<'a> extern "C" fn(&'a u8)> + impl1[317d481089b8c8fe]::AutoTrait; 3: usize] as impl1[317d481089b8c8fe]::main::{closure#1}::Bar>::method)
69+
//[v0]~| ERROR demangling-alt(<[&dyn impl1::Foo<Assoc = for<'a> extern "C" fn(&'a u8)> + impl1::AutoTrait; 3] as impl1::main::{closure#1}::Bar>::method)
7070
#[rustc_def_path]
7171
//[legacy]~^ ERROR def-path(<[&dyn Foo<Assoc = for<'r> extern "C" fn(&'r u8)> + AutoTrait; _] as main::{{closure}}#1::Bar>::method)
7272
//[v0]~^^ ERROR def-path(<[&dyn Foo<Assoc = for<'r> extern "C" fn(&'r u8)> + AutoTrait; _] as main::{{closure}}#1::Bar>::method)

src/test/ui/symbol-names/impl1.v0.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ error: def-path(bar::<impl foo::Foo>::baz)
4646
LL | #[rustc_def_path]
4747
| ^^^^^^^^^^^^^^^^^
4848

49-
error: symbol-name(_RNvXNCNvCs4fqI2P2rA04_5impl14mains_0ARDNtB6_3Foop5AssocFG0_KCRL0_hEuNtB6_9AutoTraitEL_j3_NtB2_3Bar6method)
49+
error: symbol-name(_RNvXNCNvCs4fqI2P2rA04_5impl14mains_0ARDNtB6_3Foop5AssocFG_KCRL0_hEuNtB6_9AutoTraitEL_j3_NtB2_3Bar6method)
5050
--> $DIR/impl1.rs:63:13
5151
|
5252
LL | #[rustc_symbol_name]
5353
| ^^^^^^^^^^^^^^^^^^^^
5454

55-
error: demangling(<[&dyn impl1[317d481089b8c8fe]::Foo<Assoc = for<'a, 'b> extern "C" fn(&'b u8)> + impl1[317d481089b8c8fe]::AutoTrait; 3: usize] as impl1[317d481089b8c8fe]::main::{closure#1}::Bar>::method)
55+
error: demangling(<[&dyn impl1[317d481089b8c8fe]::Foo<Assoc = for<'a> extern "C" fn(&'a u8)> + impl1[317d481089b8c8fe]::AutoTrait; 3: usize] as impl1[317d481089b8c8fe]::main::{closure#1}::Bar>::method)
5656
--> $DIR/impl1.rs:63:13
5757
|
5858
LL | #[rustc_symbol_name]
5959
| ^^^^^^^^^^^^^^^^^^^^
6060

61-
error: demangling-alt(<[&dyn impl1::Foo<Assoc = for<'a, 'b> extern "C" fn(&'b u8)> + impl1::AutoTrait; 3] as impl1::main::{closure#1}::Bar>::method)
61+
error: demangling-alt(<[&dyn impl1::Foo<Assoc = for<'a> extern "C" fn(&'a u8)> + impl1::AutoTrait; 3] as impl1::main::{closure#1}::Bar>::method)
6262
--> $DIR/impl1.rs:63:13
6363
|
6464
LL | #[rustc_symbol_name]

0 commit comments

Comments
 (0)