Skip to content

Commit 9f0e6fa

Browse files
committed
Auto merge of rust-lang#77308 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
[beta] backports This backports the following: * revert const_type_id stabilization rust-lang#77083 * [mir-opt] Disable the `ConsideredEqual` logic in SimplifyBranchSame opt rust-lang#76837 * Rename Iterator::get_unchecked rust-lang#77201 (manually, because of file renaming and other issues on master causing literal cherry-pick to fail) * Rebase LLVM onto 11.0.0-rc3 rust-lang#77063 (bumping direct to master, see rust-lang#77063 (comment)). The last two have not yet been approved by compiler team, but I'm posting this now and going to go ahead and approve as I expect both to get approved and we want testing as much as possible before release in ~2 weeks. r? `@ghost`
2 parents 755064b + 656fa79 commit 9f0e6fa

18 files changed

+84
-53
lines changed

.gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
[submodule "src/llvm-project"]
3838
path = src/llvm-project
3939
url = https://github.com/rust-lang/llvm-project.git
40-
branch = rustc/11.0-2020-08-20
40+
branch = rustc/11.0-2020-09-22
4141
[submodule "src/doc/embedded-book"]
4242
path = src/doc/embedded-book
4343
url = https://github.com/rust-embedded/book.git

library/core/src/any.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ impl TypeId {
435435
/// assert_eq!(is_string(&"cookie monster".to_string()), true);
436436
/// ```
437437
#[stable(feature = "rust1", since = "1.0.0")]
438-
#[rustc_const_stable(feature = "const_type_id", since = "1.46.0")]
438+
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
439439
pub const fn of<T: ?Sized + 'static>() -> TypeId {
440440
TypeId { t: intrinsics::type_id::<T>() }
441441
}

library/core/src/intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ extern "rust-intrinsic" {
807807
/// crate it is invoked in.
808808
///
809809
/// The stabilized version of this intrinsic is [`crate::any::TypeId::of`].
810-
#[rustc_const_stable(feature = "const_type_id", since = "1.46.0")]
810+
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
811811
pub fn type_id<T: ?Sized + 'static>() -> u64;
812812

813813
/// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:

library/core/src/iter/adapters/fuse.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ where
116116
}
117117

118118
#[inline]
119-
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item
119+
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
120120
where
121121
Self: TrustedRandomAccess,
122122
{

library/core/src/iter/adapters/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ where
215215
self.it.count()
216216
}
217217

218-
unsafe fn get_unchecked(&mut self, idx: usize) -> T
218+
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> T
219219
where
220220
Self: TrustedRandomAccess,
221221
{
@@ -350,7 +350,7 @@ where
350350
self.it.map(T::clone).fold(init, f)
351351
}
352352

353-
unsafe fn get_unchecked(&mut self, idx: usize) -> T
353+
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> T
354354
where
355355
Self: TrustedRandomAccess,
356356
{
@@ -865,7 +865,7 @@ where
865865
self.iter.fold(init, map_fold(self.f, g))
866866
}
867867

868-
unsafe fn get_unchecked(&mut self, idx: usize) -> B
868+
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> B
869869
where
870870
Self: TrustedRandomAccess,
871871
{
@@ -1304,7 +1304,7 @@ where
13041304
self.iter.fold(init, enumerate(self.count, fold))
13051305
}
13061306

1307-
unsafe fn get_unchecked(&mut self, idx: usize) -> <Self as Iterator>::Item
1307+
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> <Self as Iterator>::Item
13081308
where
13091309
Self: TrustedRandomAccess,
13101310
{

library/core/src/iter/adapters/zip.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ where
5959
}
6060

6161
#[inline]
62-
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item
62+
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
6363
where
6464
Self: TrustedRandomAccess,
6565
{
@@ -197,12 +197,14 @@ where
197197
let i = self.index;
198198
self.index += 1;
199199
// SAFETY: `i` is smaller than `self.len`, thus smaller than `self.a.len()` and `self.b.len()`
200-
unsafe { Some((self.a.get_unchecked(i), self.b.get_unchecked(i))) }
200+
unsafe {
201+
Some((self.a.__iterator_get_unchecked(i), self.b.__iterator_get_unchecked(i)))
202+
}
201203
} else if A::may_have_side_effect() && self.index < self.a.size() {
202204
// match the base implementation's potential side effects
203205
// SAFETY: we just checked that `self.index` < `self.a.len()`
204206
unsafe {
205-
self.a.get_unchecked(self.index);
207+
self.a.__iterator_get_unchecked(self.index);
206208
}
207209
self.index += 1;
208210
None
@@ -229,13 +231,13 @@ where
229231
// ensures that `end` is smaller than or equal to `self.len`,
230232
// so `i` is also smaller than `self.len`.
231233
unsafe {
232-
self.a.get_unchecked(i);
234+
self.a.__iterator_get_unchecked(i);
233235
}
234236
}
235237
if B::may_have_side_effect() {
236238
// SAFETY: same as above.
237239
unsafe {
238-
self.b.get_unchecked(i);
240+
self.b.__iterator_get_unchecked(i);
239241
}
240242
}
241243
}
@@ -277,7 +279,9 @@ where
277279
let i = self.len;
278280
// SAFETY: `i` is smaller than the previous value of `self.len`,
279281
// which is also smaller than or equal to `self.a.len()` and `self.b.len()`
280-
unsafe { Some((self.a.get_unchecked(i), self.b.get_unchecked(i))) }
282+
unsafe {
283+
Some((self.a.__iterator_get_unchecked(i), self.b.__iterator_get_unchecked(i)))
284+
}
281285
} else {
282286
None
283287
}
@@ -287,7 +291,7 @@ where
287291
unsafe fn get_unchecked(&mut self, idx: usize) -> <Self as Iterator>::Item {
288292
// SAFETY: the caller must uphold the contract for
289293
// `Iterator::get_unchecked`.
290-
unsafe { (self.a.get_unchecked(idx), self.b.get_unchecked(idx)) }
294+
unsafe { (self.a.__iterator_get_unchecked(idx), self.b.__iterator_get_unchecked(idx)) }
291295
}
292296
}
293297

@@ -430,6 +434,6 @@ unsafe impl<I: Iterator + TrustedRandomAccess> SpecTrustedRandomAccess for I {
430434
unsafe fn try_get_unchecked(&mut self, index: usize) -> Self::Item {
431435
// SAFETY: the caller must uphold the contract for
432436
// `Iterator::get_unchecked`.
433-
unsafe { self.get_unchecked(index) }
437+
unsafe { self.__iterator_get_unchecked(index) }
434438
}
435439
}

library/core/src/iter/traits/iterator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3251,7 +3251,7 @@ pub trait Iterator {
32513251
#[inline]
32523252
#[doc(hidden)]
32533253
#[unstable(feature = "trusted_random_access", issue = "none")]
3254-
unsafe fn get_unchecked(&mut self, _idx: usize) -> Self::Item
3254+
unsafe fn __iterator_get_unchecked(&mut self, _idx: usize) -> Self::Item
32553255
where
32563256
Self: TrustedRandomAccess,
32573257
{

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
#![feature(const_slice_ptr_len)]
9393
#![feature(const_size_of_val)]
9494
#![feature(const_align_of_val)]
95+
#![feature(const_type_id)]
9596
#![feature(const_type_name)]
9697
#![feature(const_likely)]
9798
#![feature(const_unreachable_unchecked)]

library/core/src/slice/mod.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -3922,7 +3922,7 @@ macro_rules! iterator {
39223922
}
39233923

39243924
#[doc(hidden)]
3925-
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
3925+
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
39263926
// SAFETY: the caller must guarantee that `i` is in bounds of
39273927
// the underlying slice, so `i` cannot overflow an `isize`, and
39283928
// the returned references is guaranteed to refer to an element
@@ -5022,7 +5022,7 @@ impl<'a, T> Iterator for Windows<'a, T> {
50225022
}
50235023

50245024
#[doc(hidden)]
5025-
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
5025+
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
50265026
// SAFETY: since the caller guarantees that `i` is in bounds,
50275027
// which means that `i` cannot overflow an `isize`, and the
50285028
// slice created by `from_raw_parts` is a subslice of `self.v`
@@ -5161,7 +5161,7 @@ impl<'a, T> Iterator for Chunks<'a, T> {
51615161
}
51625162

51635163
#[doc(hidden)]
5164-
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
5164+
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
51655165
let start = idx * self.chunk_size;
51665166
let end = match start.checked_add(self.chunk_size) {
51675167
None => self.v.len(),
@@ -5310,7 +5310,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {
53105310
}
53115311

53125312
#[doc(hidden)]
5313-
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
5313+
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
53145314
let start = idx * self.chunk_size;
53155315
let end = match start.checked_add(self.chunk_size) {
53165316
None => self.v.len(),
@@ -5463,7 +5463,7 @@ impl<'a, T> Iterator for ChunksExact<'a, T> {
54635463
}
54645464

54655465
#[doc(hidden)]
5466-
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
5466+
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
54675467
let start = idx * self.chunk_size;
54685468
// SAFETY: mostly identical to `Chunks::get_unchecked`.
54695469
unsafe { from_raw_parts(self.v.as_ptr().add(start), self.chunk_size) }
@@ -5597,7 +5597,7 @@ impl<'a, T> Iterator for ChunksExactMut<'a, T> {
55975597
}
55985598

55995599
#[doc(hidden)]
5600-
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
5600+
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
56015601
let start = idx * self.chunk_size;
56025602
// SAFETY: see comments for `ChunksMut::get_unchecked`.
56035603
unsafe { from_raw_parts_mut(self.v.as_mut_ptr().add(start), self.chunk_size) }
@@ -5723,10 +5723,10 @@ impl<'a, T, const N: usize> Iterator for ArrayChunks<'a, T, N> {
57235723
self.iter.last()
57245724
}
57255725

5726-
unsafe fn get_unchecked(&mut self, i: usize) -> &'a [T; N] {
5726+
unsafe fn __iterator_get_unchecked(&mut self, i: usize) -> &'a [T; N] {
57275727
// SAFETY: The safety guarantees of `get_unchecked` are transferred to
57285728
// the caller.
5729-
unsafe { self.iter.get_unchecked(i) }
5729+
unsafe { self.iter.__iterator_get_unchecked(i) }
57305730
}
57315731
}
57325732

@@ -5853,7 +5853,7 @@ impl<'a, T> Iterator for RChunks<'a, T> {
58535853
}
58545854

58555855
#[doc(hidden)]
5856-
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
5856+
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
58575857
let end = self.v.len() - idx * self.chunk_size;
58585858
let start = match end.checked_sub(self.chunk_size) {
58595859
None => 0,
@@ -5999,7 +5999,7 @@ impl<'a, T> Iterator for RChunksMut<'a, T> {
59995999
}
60006000

60016001
#[doc(hidden)]
6002-
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
6002+
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
60036003
let end = self.v.len() - idx * self.chunk_size;
60046004
let start = match end.checked_sub(self.chunk_size) {
60056005
None => 0,
@@ -6145,7 +6145,7 @@ impl<'a, T> Iterator for RChunksExact<'a, T> {
61456145
}
61466146

61476147
#[doc(hidden)]
6148-
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
6148+
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
61496149
let end = self.v.len() - idx * self.chunk_size;
61506150
let start = end - self.chunk_size;
61516151
// SAFETY:
@@ -6286,7 +6286,7 @@ impl<'a, T> Iterator for RChunksExactMut<'a, T> {
62866286
}
62876287

62886288
#[doc(hidden)]
6289-
unsafe fn get_unchecked(&mut self, idx: usize) -> Self::Item {
6289+
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
62906290
let end = self.v.len() - idx * self.chunk_size;
62916291
let start = end - self.chunk_size;
62926292
// SAFETY: see comments for `RChunksMut::get_unchecked`.

library/core/src/str/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -824,10 +824,10 @@ impl Iterator for Bytes<'_> {
824824
}
825825

826826
#[inline]
827-
unsafe fn get_unchecked(&mut self, idx: usize) -> u8 {
827+
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> u8 {
828828
// SAFETY: the caller must uphold the safety contract
829829
// for `Iterator::get_unchecked`.
830-
unsafe { self.0.get_unchecked(idx) }
830+
unsafe { self.0.__iterator_get_unchecked(idx) }
831831
}
832832
}
833833

src/librustc_mir/transform/simplify_try.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
616616
&& bb_l.terminator().kind == bb_r.terminator().kind;
617617
let statement_check = || {
618618
bb_l.statements.iter().zip(&bb_r.statements).try_fold(StatementEquality::TrivialEqual, |acc,(l,r)| {
619-
let stmt_equality = self.statement_equality(*adt_matched_on, &l, bb_l_idx, &r, bb_r_idx);
619+
let stmt_equality = self.statement_equality(*adt_matched_on, &l, bb_l_idx, &r, bb_r_idx, self.tcx.sess.opts.debugging_opts.mir_opt_level);
620620
if matches!(stmt_equality, StatementEquality::NotEqual) {
621621
// short circuit
622622
None
@@ -676,6 +676,7 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
676676
x_bb_idx: BasicBlock,
677677
y: &Statement<'tcx>,
678678
y_bb_idx: BasicBlock,
679+
mir_opt_level: usize,
679680
) -> StatementEquality {
680681
let helper = |rhs: &Rvalue<'tcx>,
681682
place: &Box<Place<'tcx>>,
@@ -694,7 +695,13 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
694695

695696
match rhs {
696697
Rvalue::Use(operand) if operand.place() == Some(adt_matched_on) => {
697-
StatementEquality::ConsideredEqual(side_to_choose)
698+
// FIXME(76803): This logic is currently broken because it does not take into
699+
// account the current discriminant value.
700+
if mir_opt_level > 2 {
701+
StatementEquality::ConsideredEqual(side_to_choose)
702+
} else {
703+
StatementEquality::NotEqual
704+
}
698705
}
699706
_ => {
700707
trace!(

src/llvm-project

Submodule llvm-project updated 333 files

src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff

+12-15
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,24 @@
1313

1414
bb0: {
1515
_2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16
16-
- switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16
17-
+ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16
16+
switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16
1817
}
1918

2019
bb1: {
21-
- discriminant(_0) = 0; // scope 0 at $DIR/simplify-arm.rs:12:17: 12:21
22-
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
23-
- }
24-
-
25-
- bb2: {
26-
- unreachable; // scope 0 at $DIR/simplify-arm.rs:10:11: 10:12
27-
- }
28-
-
29-
- bb3: {
20+
discriminant(_0) = 0; // scope 0 at $DIR/simplify-arm.rs:12:17: 12:21
21+
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
22+
}
23+
24+
bb2: {
25+
unreachable; // scope 0 at $DIR/simplify-arm.rs:10:11: 10:12
26+
}
27+
28+
bb3: {
3029
_0 = move _1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27
31-
- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
32-
+ goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
30+
goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6
3331
}
3432

35-
- bb4: {
36-
+ bb2: {
33+
bb4: {
3734
return; // scope 0 at $DIR/simplify-arm.rs:14:2: 14:2
3835
}
3936
}

src/test/ui/consts/const-typeid-of-rpass.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// run-pass
2+
#![feature(const_type_id)]
23
#![feature(core_intrinsics)]
34

45
use std::any::TypeId;

src/test/ui/consts/issue-73976-monomorphic.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// will be properly rejected. This test will ensure that monomorphic use of these
66
// would not be wrongly rejected in patterns.
77

8+
#![feature(const_type_id)]
89
#![feature(const_type_name)]
910

1011
use std::any::{self, TypeId};

src/test/ui/consts/issue-73976-polymorphic.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// This test case should either run-pass or be rejected at compile time.
66
// Currently we just disallow this usage and require pattern is monomorphic.
77

8+
#![feature(const_type_id)]
89
#![feature(const_type_name)]
910

1011
use std::any::{self, TypeId};

src/test/ui/consts/issue-73976-polymorphic.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error: constant pattern depends on a generic parameter
2-
--> $DIR/issue-73976-polymorphic.rs:19:37
2+
--> $DIR/issue-73976-polymorphic.rs:20:37
33
|
44
LL | matches!(GetTypeId::<T>::VALUE, GetTypeId::<T>::VALUE)
55
| ^^^^^^^^^^^^^^^^^^^^^
66

77
error: constant pattern depends on a generic parameter
8-
--> $DIR/issue-73976-polymorphic.rs:31:42
8+
--> $DIR/issue-73976-polymorphic.rs:32:42
99
|
1010
LL | matches!(GetTypeNameLen::<T>::VALUE, GetTypeNameLen::<T>::VALUE)
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error: constant pattern depends on a generic parameter
14-
--> $DIR/issue-73976-polymorphic.rs:19:37
14+
--> $DIR/issue-73976-polymorphic.rs:20:37
1515
|
1616
LL | matches!(GetTypeId::<T>::VALUE, GetTypeId::<T>::VALUE)
1717
| ^^^^^^^^^^^^^^^^^^^^^
1818

1919
error: constant pattern depends on a generic parameter
20-
--> $DIR/issue-73976-polymorphic.rs:31:42
20+
--> $DIR/issue-73976-polymorphic.rs:32:42
2121
|
2222
LL | matches!(GetTypeNameLen::<T>::VALUE, GetTypeNameLen::<T>::VALUE)
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)