Skip to content

Commit 59a05ad

Browse files
committed
Auto merge of #110239 - matthiaskrgr:rollup-o90hx4s, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #109959 (Fix transmute intrinsic mir validation ICE) - #110176 (Renumbering cleanups) - #110182 (Use `itertools::Either` instead of own impl) - #110188 (Remove orphaned remove_dir_all implementation from rust-installer) - #110190 (Custom MIR: Support `BinOp::Offset`) - #110209 (Add regression test for #59003) - #110210 (`DescriptionCtx` cleanups) - #110217 (doc: loongarch: Fix typos) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 661b33f + a954584 commit 59a05ad

File tree

19 files changed

+208
-1128
lines changed

19 files changed

+208
-1128
lines changed

Cargo.lock

+1-2
Original file line numberDiff line numberDiff line change
@@ -2769,13 +2769,11 @@ dependencies = [
27692769
"anyhow",
27702770
"clap 3.2.20",
27712771
"flate2",
2772-
"lazy_static",
27732772
"num_cpus",
27742773
"rayon",
27752774
"remove_dir_all",
27762775
"tar",
27772776
"walkdir",
2778-
"winapi",
27792777
"xz2",
27802778
]
27812779

@@ -4576,6 +4574,7 @@ dependencies = [
45764574
"elsa",
45774575
"ena",
45784576
"indexmap",
4577+
"itertools",
45794578
"jobserver",
45804579
"libc",
45814580
"measureme",

compiler/rustc_borrowck/src/renumber.rs

+14-27
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,13 @@ pub fn renumber_mir<'tcx>(
2020
) {
2121
debug!(?body.arg_count);
2222

23-
let mut visitor = NllVisitor { infcx };
23+
let mut renumberer = RegionRenumberer { infcx };
2424

2525
for body in promoted.iter_mut() {
26-
visitor.visit_body(body);
26+
renumberer.visit_body(body);
2727
}
2828

29-
visitor.visit_body(body);
30-
}
31-
32-
/// Replaces all regions appearing in `value` with fresh inference
33-
/// variables.
34-
#[instrument(skip(infcx, get_ctxt_fn), level = "debug")]
35-
pub(crate) fn renumber_regions<'tcx, T, F>(
36-
infcx: &BorrowckInferCtxt<'_, 'tcx>,
37-
value: T,
38-
get_ctxt_fn: F,
39-
) -> T
40-
where
41-
T: TypeFoldable<TyCtxt<'tcx>>,
42-
F: Fn() -> RegionCtxt,
43-
{
44-
infcx.tcx.fold_regions(value, |_region, _depth| {
45-
let origin = NllRegionVariableOrigin::Existential { from_forall: false };
46-
infcx.next_nll_region_var(origin, || get_ctxt_fn())
47-
})
29+
renumberer.visit_body(body);
4830
}
4931

5032
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
@@ -82,21 +64,26 @@ impl RegionCtxt {
8264
}
8365
}
8466

85-
struct NllVisitor<'a, 'tcx> {
67+
struct RegionRenumberer<'a, 'tcx> {
8668
infcx: &'a BorrowckInferCtxt<'a, 'tcx>,
8769
}
8870

89-
impl<'a, 'tcx> NllVisitor<'a, 'tcx> {
71+
impl<'a, 'tcx> RegionRenumberer<'a, 'tcx> {
72+
/// Replaces all regions appearing in `value` with fresh inference
73+
/// variables.
9074
fn renumber_regions<T, F>(&mut self, value: T, region_ctxt_fn: F) -> T
9175
where
9276
T: TypeFoldable<TyCtxt<'tcx>>,
9377
F: Fn() -> RegionCtxt,
9478
{
95-
renumber_regions(self.infcx, value, region_ctxt_fn)
79+
let origin = NllRegionVariableOrigin::Existential { from_forall: false };
80+
self.infcx.tcx.fold_regions(value, |_region, _depth| {
81+
self.infcx.next_nll_region_var(origin, || region_ctxt_fn())
82+
})
9683
}
9784
}
9885

99-
impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
86+
impl<'a, 'tcx> MutVisitor<'tcx> for RegionRenumberer<'a, 'tcx> {
10087
fn tcx(&self) -> TyCtxt<'tcx> {
10188
self.infcx.tcx
10289
}
@@ -124,9 +111,9 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
124111
}
125112

126113
#[instrument(skip(self), level = "debug")]
127-
fn visit_constant(&mut self, constant: &mut Constant<'tcx>, _location: Location) {
114+
fn visit_constant(&mut self, constant: &mut Constant<'tcx>, location: Location) {
128115
let literal = constant.literal;
129-
constant.literal = self.renumber_regions(literal, || RegionCtxt::Location(_location));
116+
constant.literal = self.renumber_regions(literal, || RegionCtxt::Location(location));
130117
debug!("constant: {:#?}", constant);
131118
}
132119
}

compiler/rustc_const_eval/src/transform/validate.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -679,13 +679,21 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
679679
// Unlike `mem::transmute`, a MIR `Transmute` is well-formed
680680
// for any two `Sized` types, just potentially UB to run.
681681

682-
if !op_ty.is_sized(self.tcx, self.param_env) {
682+
if !self
683+
.tcx
684+
.normalize_erasing_regions(self.param_env, op_ty)
685+
.is_sized(self.tcx, self.param_env)
686+
{
683687
self.fail(
684688
location,
685689
format!("Cannot transmute from non-`Sized` type {op_ty:?}"),
686690
);
687691
}
688-
if !target_type.is_sized(self.tcx, self.param_env) {
692+
if !self
693+
.tcx
694+
.normalize_erasing_regions(self.param_env, *target_type)
695+
.is_sized(self.tcx, self.param_env)
696+
{
689697
self.fail(
690698
location,
691699
format!("Cannot transmute to non-`Sized` type {target_type:?}"),

compiler/rustc_data_structures/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ tempfile = "3.2"
3333
thin-vec = "0.2.12"
3434
tracing = "0.1"
3535
elsa = "=1.7.1"
36+
itertools = "0.10.1"
3637

3738
[dependencies.parking_lot]
3839
version = "0.11"

compiler/rustc_data_structures/src/sso/either_iter.rs

-73
This file was deleted.

compiler/rustc_data_structures/src/sso/map.rs

+35-35
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
use super::either_iter::EitherIter;
21
use crate::fx::FxHashMap;
32
use arrayvec::ArrayVec;
3+
use itertools::Either;
44
use std::fmt;
55
use std::hash::Hash;
66
use std::ops::Index;
77

8-
// For pointer-sized arguments arrays
9-
// are faster than set/map for up to 64
10-
// arguments.
11-
//
12-
// On the other hand such a big array
13-
// hurts cache performance, makes passing
14-
// sso structures around very expensive.
15-
//
16-
// Biggest performance benefit is gained
17-
// for reasonably small arrays that stay
18-
// small in vast majority of cases.
19-
//
20-
// '8' is chosen as a sane default, to be
21-
// reevaluated later.
8+
/// For pointer-sized arguments arrays
9+
/// are faster than set/map for up to 64
10+
/// arguments.
11+
///
12+
/// On the other hand such a big array
13+
/// hurts cache performance, makes passing
14+
/// sso structures around very expensive.
15+
///
16+
/// Biggest performance benefit is gained
17+
/// for reasonably small arrays that stay
18+
/// small in vast majority of cases.
19+
///
20+
/// '8' is chosen as a sane default, to be
21+
/// reevaluated later.
2222
const SSO_ARRAY_SIZE: usize = 8;
2323

2424
/// Small-storage-optimized implementation of a map.
@@ -138,35 +138,35 @@ impl<K, V> SsoHashMap<K, V> {
138138
/// The iterator element type is `&'a K`.
139139
pub fn keys(&self) -> impl Iterator<Item = &'_ K> {
140140
match self {
141-
SsoHashMap::Array(array) => EitherIter::Left(array.iter().map(|(k, _v)| k)),
142-
SsoHashMap::Map(map) => EitherIter::Right(map.keys()),
141+
SsoHashMap::Array(array) => Either::Left(array.iter().map(|(k, _v)| k)),
142+
SsoHashMap::Map(map) => Either::Right(map.keys()),
143143
}
144144
}
145145

146146
/// An iterator visiting all values in arbitrary order.
147147
/// The iterator element type is `&'a V`.
148148
pub fn values(&self) -> impl Iterator<Item = &'_ V> {
149149
match self {
150-
SsoHashMap::Array(array) => EitherIter::Left(array.iter().map(|(_k, v)| v)),
151-
SsoHashMap::Map(map) => EitherIter::Right(map.values()),
150+
SsoHashMap::Array(array) => Either::Left(array.iter().map(|(_k, v)| v)),
151+
SsoHashMap::Map(map) => Either::Right(map.values()),
152152
}
153153
}
154154

155155
/// An iterator visiting all values mutably in arbitrary order.
156156
/// The iterator element type is `&'a mut V`.
157157
pub fn values_mut(&mut self) -> impl Iterator<Item = &'_ mut V> {
158158
match self {
159-
SsoHashMap::Array(array) => EitherIter::Left(array.iter_mut().map(|(_k, v)| v)),
160-
SsoHashMap::Map(map) => EitherIter::Right(map.values_mut()),
159+
SsoHashMap::Array(array) => Either::Left(array.iter_mut().map(|(_k, v)| v)),
160+
SsoHashMap::Map(map) => Either::Right(map.values_mut()),
161161
}
162162
}
163163

164164
/// Clears the map, returning all key-value pairs as an iterator. Keeps the
165165
/// allocated memory for reuse.
166166
pub fn drain(&mut self) -> impl Iterator<Item = (K, V)> + '_ {
167167
match self {
168-
SsoHashMap::Array(array) => EitherIter::Left(array.drain(..)),
169-
SsoHashMap::Map(map) => EitherIter::Right(map.drain()),
168+
SsoHashMap::Array(array) => Either::Left(array.drain(..)),
169+
SsoHashMap::Map(map) => Either::Right(map.drain()),
170170
}
171171
}
172172
}
@@ -406,16 +406,16 @@ where
406406
}
407407

408408
impl<K, V> IntoIterator for SsoHashMap<K, V> {
409-
type IntoIter = EitherIter<
410-
<ArrayVec<(K, V), 8> as IntoIterator>::IntoIter,
409+
type IntoIter = Either<
410+
<ArrayVec<(K, V), SSO_ARRAY_SIZE> as IntoIterator>::IntoIter,
411411
<FxHashMap<K, V> as IntoIterator>::IntoIter,
412412
>;
413413
type Item = <Self::IntoIter as Iterator>::Item;
414414

415415
fn into_iter(self) -> Self::IntoIter {
416416
match self {
417-
SsoHashMap::Array(array) => EitherIter::Left(array.into_iter()),
418-
SsoHashMap::Map(map) => EitherIter::Right(map.into_iter()),
417+
SsoHashMap::Array(array) => Either::Left(array.into_iter()),
418+
SsoHashMap::Map(map) => Either::Right(map.into_iter()),
419419
}
420420
}
421421
}
@@ -435,9 +435,9 @@ fn adapt_array_mut_it<K, V>(pair: &mut (K, V)) -> (&K, &mut V) {
435435
}
436436

437437
impl<'a, K, V> IntoIterator for &'a SsoHashMap<K, V> {
438-
type IntoIter = EitherIter<
438+
type IntoIter = Either<
439439
std::iter::Map<
440-
<&'a ArrayVec<(K, V), 8> as IntoIterator>::IntoIter,
440+
<&'a ArrayVec<(K, V), SSO_ARRAY_SIZE> as IntoIterator>::IntoIter,
441441
fn(&'a (K, V)) -> (&'a K, &'a V),
442442
>,
443443
<&'a FxHashMap<K, V> as IntoIterator>::IntoIter,
@@ -446,16 +446,16 @@ impl<'a, K, V> IntoIterator for &'a SsoHashMap<K, V> {
446446

447447
fn into_iter(self) -> Self::IntoIter {
448448
match self {
449-
SsoHashMap::Array(array) => EitherIter::Left(array.into_iter().map(adapt_array_ref_it)),
450-
SsoHashMap::Map(map) => EitherIter::Right(map.iter()),
449+
SsoHashMap::Array(array) => Either::Left(array.into_iter().map(adapt_array_ref_it)),
450+
SsoHashMap::Map(map) => Either::Right(map.iter()),
451451
}
452452
}
453453
}
454454

455455
impl<'a, K, V> IntoIterator for &'a mut SsoHashMap<K, V> {
456-
type IntoIter = EitherIter<
456+
type IntoIter = Either<
457457
std::iter::Map<
458-
<&'a mut ArrayVec<(K, V), 8> as IntoIterator>::IntoIter,
458+
<&'a mut ArrayVec<(K, V), SSO_ARRAY_SIZE> as IntoIterator>::IntoIter,
459459
fn(&'a mut (K, V)) -> (&'a K, &'a mut V),
460460
>,
461461
<&'a mut FxHashMap<K, V> as IntoIterator>::IntoIter,
@@ -464,8 +464,8 @@ impl<'a, K, V> IntoIterator for &'a mut SsoHashMap<K, V> {
464464

465465
fn into_iter(self) -> Self::IntoIter {
466466
match self {
467-
SsoHashMap::Array(array) => EitherIter::Left(array.into_iter().map(adapt_array_mut_it)),
468-
SsoHashMap::Map(map) => EitherIter::Right(map.iter_mut()),
467+
SsoHashMap::Array(array) => Either::Left(array.into_iter().map(adapt_array_mut_it)),
468+
SsoHashMap::Map(map) => Either::Right(map.iter_mut()),
469469
}
470470
}
471471
}

compiler/rustc_data_structures/src/sso/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
mod either_iter;
21
mod map;
32
mod set;
43

compiler/rustc_infer/messages.ftl

-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ infer_region_explanation = {$pref_kind ->
163163
[as_defined] the lifetime `{$desc_arg}` as defined here
164164
[as_defined_anon] the anonymous lifetime as defined here
165165
[defined_here] the anonymous lifetime defined here
166-
[anon_num_here] the anonymous lifetime #{$desc_num_arg} defined here
167166
[defined_here_reg] the lifetime `{$desc_arg}` as defined here
168167
}{$suff_kind ->
169168
*[should_not_happen] [{$suff_kind}]

0 commit comments

Comments
 (0)