Skip to content

Commit d5c2e9c

Browse files
committed
Auto merge of #115787 - Mark-Simulacrum:stable-next, r=Mark-Simulacrum
[stable] 1.72.1 release This backports: * Remove assert that checks type equality #115215 * implied bounds: do not ICE on unconstrained region vars #115559 * rustdoc: correctly deal with self ty params when eliding default object lifetimes #115276 * Stop emitting non-power-of-two vectors in (non-portable-SIMD) codegen #115236 * Normalize before checking if local is freeze in deduced_param_attrs #114948 Some cherry-picks required merge conflict resolution, we'll see if I got it right based on CI (rustdoc fix and LLVM codegen test). r? `@Mark-Simulacrum`
2 parents 5680fa1 + 7900923 commit d5c2e9c

File tree

21 files changed

+414
-56
lines changed

21 files changed

+414
-56
lines changed

RELEASES.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
Version 1.72.1 (2023-09-14)
2+
===========================
3+
4+
- [Adjust codegen change to improve LLVM codegen](https://github.com/rust-lang/rust/pull/115236)
5+
- [rustdoc: Fix self ty params in objects with lifetimes](https://github.com/rust-lang/rust/pull/115276)
6+
- [Fix regression in compile times](https://github.com/rust-lang/rust/pull/114948)
7+
- Resolve some ICE regressions in the compiler:
8+
- [#115215](https://github.com/rust-lang/rust/pull/115215)
9+
- [#115559](https://github.com/rust-lang/rust/pull/115559)
10+
111
Version 1.72.0 (2023-08-24)
212
==========================
313

compiler/rustc_codegen_llvm/src/type_of.rs

+4
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,11 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
431431

432432
// Vectors, even for non-power-of-two sizes, have the same layout as
433433
// arrays but don't count as aggregate types
434+
// While LLVM theoretically supports non-power-of-two sizes, and they
435+
// often work fine, sometimes x86-isel deals with them horribly
436+
// (see #115212) so for now only use power-of-two ones.
434437
if let FieldsShape::Array { count, .. } = self.layout.fields()
438+
&& count.is_power_of_two()
435439
&& let element = self.field(cx, 0)
436440
&& element.ty.is_integral()
437441
{

compiler/rustc_codegen_ssa/src/mir/locals.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_index::IndexVec;
77
use rustc_middle::mir;
88
use rustc_middle::ty::print::with_no_trimmed_paths;
99
use std::ops::{Index, IndexMut};
10-
1110
pub(super) struct Locals<'tcx, V> {
1211
values: IndexVec<mir::Local, LocalRef<'tcx, V>>,
1312
}
@@ -36,17 +35,18 @@ impl<'tcx, V> Locals<'tcx, V> {
3635
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
3736
pub(super) fn initialize_locals(&mut self, values: Vec<LocalRef<'tcx, Bx::Value>>) {
3837
assert!(self.locals.values.is_empty());
39-
38+
// FIXME(#115215): After #115025 get's merged this might not be necessary
4039
for (local, value) in values.into_iter().enumerate() {
4140
match value {
4241
LocalRef::Place(_) | LocalRef::UnsizedPlace(_) | LocalRef::PendingOperand => (),
4342
LocalRef::Operand(op) => {
4443
let local = mir::Local::from_usize(local);
4544
let expected_ty = self.monomorphize(self.mir.local_decls[local].ty);
46-
assert_eq!(expected_ty, op.layout.ty, "unexpected initial operand type");
45+
if expected_ty != op.layout.ty {
46+
warn!("Unexpected initial operand type. See the issues/114858");
47+
}
4748
}
4849
}
49-
5050
self.locals.values.push(value);
5151
}
5252
}

compiler/rustc_mir_transform/src/deduce_param_attrs.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,12 @@ pub fn deduced_param_attrs<'tcx>(
203203
body.local_decls.iter().skip(1).take(body.arg_count).enumerate().map(
204204
|(arg_index, local_decl)| DeducedParamAttrs {
205205
read_only: !deduce_read_only.mutable_args.contains(arg_index)
206-
&& local_decl.ty.is_freeze(tcx, param_env),
206+
// We must normalize here to reveal opaques and normalize
207+
// their substs, otherwise we'll see exponential blow-up in
208+
// compile times: #113372
209+
&& tcx
210+
.normalize_erasing_regions(param_env, local_decl.ty)
211+
.is_freeze(tcx, param_env),
207212
},
208213
),
209214
);

compiler/rustc_trait_selection/src/traits/outlives_bounds.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,12 @@ impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> {
5757
let ty = OpportunisticRegionResolver::new(self).fold_ty(ty);
5858

5959
// We do not expect existential variables in implied bounds.
60-
// We may however encounter unconstrained lifetime variables in invalid
61-
// code. See #110161 for context.
60+
// We may however encounter unconstrained lifetime variables
61+
// in very rare cases.
62+
//
63+
// See `ui/implied-bounds/implied-bounds-unconstrained-2.rs` for
64+
// an example.
6265
assert!(!ty.has_non_region_infer());
63-
if ty.has_infer() {
64-
self.tcx.sess.delay_span_bug(
65-
self.tcx.def_span(body_id),
66-
"skipped implied_outlives_bounds due to unconstrained lifetimes",
67-
);
68-
return vec![];
69-
}
7066

7167
let mut canonical_var_values = OriginalQueryValues::default();
7268
let canonical_ty =

src/ci/docker/host-x86_64/arm-android/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:22.10
1+
FROM ubuntu:23.04
22

33
ARG DEBIAN_FRONTEND=noninteractive
44
COPY scripts/android-base-apt-get.sh /scripts/

src/ci/docker/host-x86_64/dist-android/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:22.10
1+
FROM ubuntu:23.04
22

33
COPY scripts/android-base-apt-get.sh /scripts/
44
RUN sh /scripts/android-base-apt-get.sh

src/ci/docker/host-x86_64/dist-various-1/install-x86_64-redox.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
set -ex
44

5-
curl https://static.redox-os.org/toolchain/x86_64-unknown-redox/relibc-install.tar.gz | \
5+
curl https://ci-mirrors.rust-lang.org/rustc/2022-11-27-relibc-install.tar.gz | \
66
tar --extract --gzip --directory /usr/local

src/ci/docker/host-x86_64/x86_64-gnu-llvm-15/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:22.10
1+
FROM ubuntu:23.04
22

33
ARG DEBIAN_FRONTEND=noninteractive
44

src/librustdoc/clean/mod.rs

+23-11
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ fn clean_generic_bound<'tcx>(
167167
let trait_ref = ty::Binder::dummy(ty::TraitRef::identity(cx.tcx, def_id));
168168

169169
let generic_args = clean_generic_args(generic_args, cx);
170-
let GenericArgs::AngleBracketed { bindings, .. } = generic_args
171-
else {
170+
let GenericArgs::AngleBracketed { bindings, .. } = generic_args else {
172171
bug!("clean: parenthesized `GenericBound::LangItemTrait`");
173172
};
174173

@@ -1818,33 +1817,46 @@ fn can_elide_trait_object_lifetime_bound<'tcx>(
18181817
#[derive(Debug)]
18191818
pub(crate) enum ContainerTy<'tcx> {
18201819
Ref(ty::Region<'tcx>),
1821-
Regular { ty: DefId, substs: ty::Binder<'tcx, &'tcx [ty::GenericArg<'tcx>]>, arg: usize },
1820+
Regular {
1821+
ty: DefId,
1822+
args: ty::Binder<'tcx, &'tcx [ty::GenericArg<'tcx>]>,
1823+
has_self: bool,
1824+
arg: usize,
1825+
},
18221826
}
18231827

18241828
impl<'tcx> ContainerTy<'tcx> {
18251829
fn object_lifetime_default(self, tcx: TyCtxt<'tcx>) -> ObjectLifetimeDefault<'tcx> {
18261830
match self {
18271831
Self::Ref(region) => ObjectLifetimeDefault::Arg(region),
1828-
Self::Regular { ty: container, substs, arg: index } => {
1832+
Self::Regular { ty: container, args, has_self, arg: index } => {
18291833
let (DefKind::Struct
18301834
| DefKind::Union
18311835
| DefKind::Enum
1832-
| DefKind::TyAlias
1833-
| DefKind::Trait
1834-
| DefKind::AssocTy
1835-
| DefKind::Variant) = tcx.def_kind(container)
1836+
| DefKind::TyAlias { .. }
1837+
| DefKind::Trait) = tcx.def_kind(container)
18361838
else {
18371839
return ObjectLifetimeDefault::Empty;
18381840
};
18391841

18401842
let generics = tcx.generics_of(container);
1841-
let param = generics.params[index].def_id;
1842-
let default = tcx.object_lifetime_default(param);
1843+
debug_assert_eq!(generics.parent_count, 0);
1844+
1845+
// If the container is a trait object type, the arguments won't contain the self type but the
1846+
// generics of the corresponding trait will. In such a case, offset the index by one.
1847+
// For comparison, if the container is a trait inside a bound, the arguments do contain the
1848+
// self type.
1849+
let offset =
1850+
if !has_self && generics.parent.is_none() && generics.has_self { 1 } else { 0 };
1851+
let param = generics.params[index + offset].def_id;
18431852

1853+
let default = tcx.object_lifetime_default(param);
18441854
match default {
18451855
rbv::ObjectLifetimeDefault::Param(lifetime) => {
1856+
// The index is relative to the parent generics but since we don't have any,
1857+
// we don't need to translate it.
18461858
let index = generics.param_def_id_to_index[&lifetime];
1847-
let arg = substs.skip_binder()[index as usize].expect_region();
1859+
let arg = args.skip_binder()[index as usize].expect_region();
18481860
ObjectLifetimeDefault::Arg(arg)
18491861
}
18501862
rbv::ObjectLifetimeDefault::Empty => ObjectLifetimeDefault::Empty,

src/librustdoc/clean/utils.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ pub(crate) fn krate(cx: &mut DocContext<'_>) -> Crate {
5454
let primitives = local_crate.primitives(cx.tcx);
5555
let keywords = local_crate.keywords(cx.tcx);
5656
{
57-
let ItemKind::ModuleItem(ref mut m) = *module.kind
58-
else { unreachable!() };
57+
let ItemKind::ModuleItem(ref mut m) = *module.kind else { unreachable!() };
5958
m.items.extend(primitives.iter().map(|&(def_id, prim)| {
6059
Item::from_def_id_and_parts(
6160
def_id,
@@ -74,18 +73,15 @@ pub(crate) fn krate(cx: &mut DocContext<'_>) -> Crate {
7473

7574
pub(crate) fn substs_to_args<'tcx>(
7675
cx: &mut DocContext<'tcx>,
77-
substs: ty::Binder<'tcx, &'tcx [ty::subst::GenericArg<'tcx>]>,
78-
mut skip_first: bool,
76+
args: ty::Binder<'tcx, &'tcx [ty::GenericArg<'tcx>]>,
77+
has_self: bool,
7978
container: Option<DefId>,
8079
) -> Vec<GenericArg> {
80+
let mut skip_first = has_self;
8181
let mut ret_val =
82-
Vec::with_capacity(substs.skip_binder().len().saturating_sub(if skip_first {
83-
1
84-
} else {
85-
0
86-
}));
82+
Vec::with_capacity(args.skip_binder().len().saturating_sub(if skip_first { 1 } else { 0 }));
8783

88-
ret_val.extend(substs.iter().enumerate().filter_map(|(index, kind)| {
84+
ret_val.extend(args.iter().enumerate().filter_map(|(index, kind)| {
8985
match kind.skip_binder().unpack() {
9086
GenericArgKind::Lifetime(lt) => {
9187
Some(GenericArg::Lifetime(clean_middle_region(lt).unwrap_or(Lifetime::elided())))
@@ -100,7 +96,8 @@ pub(crate) fn substs_to_args<'tcx>(
10096
None,
10197
container.map(|container| crate::clean::ContainerTy::Regular {
10298
ty: container,
103-
substs,
99+
args,
100+
has_self,
104101
arg: index,
105102
}),
106103
))),

src/version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.72.0
1+
1.72.1

tests/codegen/mem-replace-simple-type.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,21 @@ pub fn replace_ref_str<'a>(r: &mut &'a str, v: &'a str) -> &'a str {
3434
}
3535

3636
#[no_mangle]
37-
// CHECK-LABEL: @replace_short_array(
38-
pub fn replace_short_array(r: &mut [u32; 3], v: [u32; 3]) -> [u32; 3] {
37+
// CHECK-LABEL: @replace_short_array_3(
38+
pub fn replace_short_array_3(r: &mut [u32; 3], v: [u32; 3]) -> [u32; 3] {
3939
// CHECK-NOT: alloca
40-
// CHECK: %[[R:.+]] = load <3 x i32>, ptr %r, align 4
41-
// CHECK: store <3 x i32> %[[R]], ptr %0
42-
// CHECK: %[[V:.+]] = load <3 x i32>, ptr %v, align 4
43-
// CHECK: store <3 x i32> %[[V]], ptr %r
40+
// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %0, ptr align 4 %r, i64 12, i1 false)
41+
// CHECK: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %r, ptr align 4 %v, i64 12, i1 false)
42+
std::mem::replace(r, v)
43+
}
44+
45+
#[no_mangle]
46+
// CHECK-LABEL: @replace_short_array_4(
47+
pub fn replace_short_array_4(r: &mut [u32; 4], v: [u32; 4]) -> [u32; 4] {
48+
// CHECK-NOT: alloca
49+
// CHECK: %[[R:.+]] = load <4 x i32>, ptr %r, align 4
50+
// CHECK: store <4 x i32> %[[R]], ptr %0
51+
// CHECK: %[[V:.+]] = load <4 x i32>, ptr %v, align 4
52+
// CHECK: store <4 x i32> %[[V]], ptr %r
4453
std::mem::replace(r, v)
4554
}

tests/codegen/swap-small-types.rs

+24-9
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ type RGB48 = [u16; 3];
1111
// CHECK-LABEL: @swap_rgb48_manually(
1212
#[no_mangle]
1313
pub fn swap_rgb48_manually(x: &mut RGB48, y: &mut RGB48) {
14-
// CHECK-NOT: alloca
15-
// CHECK: %[[TEMP0:.+]] = load <3 x i16>, ptr %x, align 2
16-
// CHECK: %[[TEMP1:.+]] = load <3 x i16>, ptr %y, align 2
17-
// CHECK: store <3 x i16> %[[TEMP1]], ptr %x, align 2
18-
// CHECK: store <3 x i16> %[[TEMP0]], ptr %y, align 2
14+
// FIXME: See #115212 for why this has an alloca again
15+
16+
// CHECK: alloca [3 x i16], align 2
17+
// CHECK: call void @llvm.memcpy.p0.p0.i64({{.+}}, i64 6, i1 false)
18+
// CHECK: call void @llvm.memcpy.p0.p0.i64({{.+}}, i64 6, i1 false)
19+
// CHECK: call void @llvm.memcpy.p0.p0.i64({{.+}}, i64 6, i1 false)
1920

2021
let temp = *x;
2122
*x = *y;
@@ -25,11 +26,25 @@ pub fn swap_rgb48_manually(x: &mut RGB48, y: &mut RGB48) {
2526
// CHECK-LABEL: @swap_rgb48
2627
#[no_mangle]
2728
pub fn swap_rgb48(x: &mut RGB48, y: &mut RGB48) {
29+
// FIXME: See #115212 for why this has an alloca again
30+
31+
// CHECK: alloca [3 x i16], align 2
32+
// CHECK: call void @llvm.memcpy.p0.p0.i64({{.+}}, i64 6, i1 false)
33+
// CHECK: call void @llvm.memcpy.p0.p0.i64({{.+}}, i64 6, i1 false)
34+
// CHECK: call void @llvm.memcpy.p0.p0.i64({{.+}}, i64 6, i1 false)
35+
swap(x, y)
36+
}
37+
38+
type RGBA64 = [u16; 4];
39+
40+
// CHECK-LABEL: @swap_rgba64
41+
#[no_mangle]
42+
pub fn swap_rgba64(x: &mut RGBA64, y: &mut RGBA64) {
2843
// CHECK-NOT: alloca
29-
// CHECK: load <3 x i16>
30-
// CHECK: load <3 x i16>
31-
// CHECK: store <3 x i16>
32-
// CHECK: store <3 x i16>
44+
// CHECK-DAG: %[[XVAL:.+]] = load <4 x i16>, ptr %x, align 2
45+
// CHECK-DAG: %[[YVAL:.+]] = load <4 x i16>, ptr %y, align 2
46+
// CHECK-DAG: store <4 x i16> %[[YVAL]], ptr %x, align 2
47+
// CHECK-DAG: store <4 x i16> %[[XVAL]], ptr %y, align 2
3348
swap(x, y)
3449
}
3550

tests/rustdoc/inline_cross/auxiliary/dyn_trait.rs

+19
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,22 @@ pub trait HigherRankedBoundTrait1<'e> where for<'l> Self: 'e + 'l {}
6565
pub trait AmbiguousBoundTrait<'a, 'b>: 'a + 'b {}
6666

6767
pub struct AmbiguousBoundWrapper<'a, 'b, T: ?Sized + 'a + 'b>(&'a T, &'b T);
68+
69+
// Trait objects inside of another trait object, a trait bound or an associated type.
70+
71+
pub trait Inner {}
72+
pub trait Outer<T: ?Sized> {}
73+
pub trait Base {
74+
type Type<T: ?Sized>;
75+
}
76+
impl Base for () {
77+
type Type<T: ?Sized> = ();
78+
}
79+
80+
pub type NestedTraitObjects = dyn Outer<dyn Inner>;
81+
82+
pub fn apit_rpit(o: impl Outer<dyn Inner>) -> impl Outer<dyn Inner> {
83+
o
84+
}
85+
86+
pub type AssocTy = <() as Base>::Type<dyn Inner>;

tests/rustdoc/inline_cross/dyn_trait.rs

+15
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,18 @@ pub use dyn_trait::BareAmbiguousBoundEarly1;
128128
// @has user/type.BareAmbiguousBoundStatic.html
129129
// @has - '//*[@class="rust item-decl"]//code' "dyn AmbiguousBoundTrait<'o, 'o> + 'static;"
130130
pub use dyn_trait::BareAmbiguousBoundStatic;
131+
132+
// Regression test for issue #115179:
133+
134+
// @has user/type.NestedTraitObjects.html
135+
// @has - '//*[@class="rust item-decl"]//code' "dyn Outer<dyn Inner>;"
136+
pub use dyn_trait::NestedTraitObjects;
137+
138+
// @has user/fn.apit_rpit.html
139+
// @has - '//pre[@class="rust item-decl"]' \
140+
// "apit_rpit(o: impl Outer<dyn Inner>) -> impl Outer<dyn Inner>"
141+
pub use dyn_trait::apit_rpit;
142+
143+
// @has user/type.AssocTy.html
144+
// @has - '//*[@class="rust item-decl"]//code' "<() as Base>::Type<dyn Inner>"
145+
pub use dyn_trait::AssocTy;

0 commit comments

Comments
 (0)