Skip to content

Commit

Permalink
Auto merge of rust-lang#110239 - matthiaskrgr:rollup-o90hx4s, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#109959 (Fix transmute intrinsic mir validation ICE)
 - rust-lang#110176 (Renumbering cleanups)
 - rust-lang#110182 (Use `itertools::Either` instead of own impl)
 - rust-lang#110188 (Remove orphaned remove_dir_all implementation from rust-installer)
 - rust-lang#110190 (Custom MIR: Support `BinOp::Offset`)
 - rust-lang#110209 (Add regression test for rust-lang#59003)
 - rust-lang#110210 (`DescriptionCtx` cleanups)
 - rust-lang#110217 (doc: loongarch: Fix typos)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Apr 12, 2023
2 parents 661b33f + a954584 commit 59a05ad
Show file tree
Hide file tree
Showing 19 changed files with 208 additions and 1,128 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2769,13 +2769,11 @@ dependencies = [
"anyhow",
"clap 3.2.20",
"flate2",
"lazy_static",
"num_cpus",
"rayon",
"remove_dir_all",
"tar",
"walkdir",
"winapi",
"xz2",
]

Expand Down Expand Up @@ -4576,6 +4574,7 @@ dependencies = [
"elsa",
"ena",
"indexmap",
"itertools",
"jobserver",
"libc",
"measureme",
Expand Down
41 changes: 14 additions & 27 deletions compiler/rustc_borrowck/src/renumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,13 @@ pub fn renumber_mir<'tcx>(
) {
debug!(?body.arg_count);

let mut visitor = NllVisitor { infcx };
let mut renumberer = RegionRenumberer { infcx };

for body in promoted.iter_mut() {
visitor.visit_body(body);
renumberer.visit_body(body);
}

visitor.visit_body(body);
}

/// Replaces all regions appearing in `value` with fresh inference
/// variables.
#[instrument(skip(infcx, get_ctxt_fn), level = "debug")]
pub(crate) fn renumber_regions<'tcx, T, F>(
infcx: &BorrowckInferCtxt<'_, 'tcx>,
value: T,
get_ctxt_fn: F,
) -> T
where
T: TypeFoldable<TyCtxt<'tcx>>,
F: Fn() -> RegionCtxt,
{
infcx.tcx.fold_regions(value, |_region, _depth| {
let origin = NllRegionVariableOrigin::Existential { from_forall: false };
infcx.next_nll_region_var(origin, || get_ctxt_fn())
})
renumberer.visit_body(body);
}

#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
Expand Down Expand Up @@ -82,21 +64,26 @@ impl RegionCtxt {
}
}

struct NllVisitor<'a, 'tcx> {
struct RegionRenumberer<'a, 'tcx> {
infcx: &'a BorrowckInferCtxt<'a, 'tcx>,
}

impl<'a, 'tcx> NllVisitor<'a, 'tcx> {
impl<'a, 'tcx> RegionRenumberer<'a, 'tcx> {
/// Replaces all regions appearing in `value` with fresh inference
/// variables.
fn renumber_regions<T, F>(&mut self, value: T, region_ctxt_fn: F) -> T
where
T: TypeFoldable<TyCtxt<'tcx>>,
F: Fn() -> RegionCtxt,
{
renumber_regions(self.infcx, value, region_ctxt_fn)
let origin = NllRegionVariableOrigin::Existential { from_forall: false };
self.infcx.tcx.fold_regions(value, |_region, _depth| {
self.infcx.next_nll_region_var(origin, || region_ctxt_fn())
})
}
}

impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
impl<'a, 'tcx> MutVisitor<'tcx> for RegionRenumberer<'a, 'tcx> {
fn tcx(&self) -> TyCtxt<'tcx> {
self.infcx.tcx
}
Expand Down Expand Up @@ -124,9 +111,9 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NllVisitor<'a, 'tcx> {
}

#[instrument(skip(self), level = "debug")]
fn visit_constant(&mut self, constant: &mut Constant<'tcx>, _location: Location) {
fn visit_constant(&mut self, constant: &mut Constant<'tcx>, location: Location) {
let literal = constant.literal;
constant.literal = self.renumber_regions(literal, || RegionCtxt::Location(_location));
constant.literal = self.renumber_regions(literal, || RegionCtxt::Location(location));
debug!("constant: {:#?}", constant);
}
}
12 changes: 10 additions & 2 deletions compiler/rustc_const_eval/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,13 +679,21 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
// Unlike `mem::transmute`, a MIR `Transmute` is well-formed
// for any two `Sized` types, just potentially UB to run.

if !op_ty.is_sized(self.tcx, self.param_env) {
if !self
.tcx
.normalize_erasing_regions(self.param_env, op_ty)
.is_sized(self.tcx, self.param_env)
{
self.fail(
location,
format!("Cannot transmute from non-`Sized` type {op_ty:?}"),
);
}
if !target_type.is_sized(self.tcx, self.param_env) {
if !self
.tcx
.normalize_erasing_regions(self.param_env, *target_type)
.is_sized(self.tcx, self.param_env)
{
self.fail(
location,
format!("Cannot transmute to non-`Sized` type {target_type:?}"),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tempfile = "3.2"
thin-vec = "0.2.12"
tracing = "0.1"
elsa = "=1.7.1"
itertools = "0.10.1"

[dependencies.parking_lot]
version = "0.11"
Expand Down
73 changes: 0 additions & 73 deletions compiler/rustc_data_structures/src/sso/either_iter.rs

This file was deleted.

70 changes: 35 additions & 35 deletions compiler/rustc_data_structures/src/sso/map.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
use super::either_iter::EitherIter;
use crate::fx::FxHashMap;
use arrayvec::ArrayVec;
use itertools::Either;
use std::fmt;
use std::hash::Hash;
use std::ops::Index;

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

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

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

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

/// Clears the map, returning all key-value pairs as an iterator. Keeps the
/// allocated memory for reuse.
pub fn drain(&mut self) -> impl Iterator<Item = (K, V)> + '_ {
match self {
SsoHashMap::Array(array) => EitherIter::Left(array.drain(..)),
SsoHashMap::Map(map) => EitherIter::Right(map.drain()),
SsoHashMap::Array(array) => Either::Left(array.drain(..)),
SsoHashMap::Map(map) => Either::Right(map.drain()),
}
}
}
Expand Down Expand Up @@ -406,16 +406,16 @@ where
}

impl<K, V> IntoIterator for SsoHashMap<K, V> {
type IntoIter = EitherIter<
<ArrayVec<(K, V), 8> as IntoIterator>::IntoIter,
type IntoIter = Either<
<ArrayVec<(K, V), SSO_ARRAY_SIZE> as IntoIterator>::IntoIter,
<FxHashMap<K, V> as IntoIterator>::IntoIter,
>;
type Item = <Self::IntoIter as Iterator>::Item;

fn into_iter(self) -> Self::IntoIter {
match self {
SsoHashMap::Array(array) => EitherIter::Left(array.into_iter()),
SsoHashMap::Map(map) => EitherIter::Right(map.into_iter()),
SsoHashMap::Array(array) => Either::Left(array.into_iter()),
SsoHashMap::Map(map) => Either::Right(map.into_iter()),
}
}
}
Expand All @@ -435,9 +435,9 @@ fn adapt_array_mut_it<K, V>(pair: &mut (K, V)) -> (&K, &mut V) {
}

impl<'a, K, V> IntoIterator for &'a SsoHashMap<K, V> {
type IntoIter = EitherIter<
type IntoIter = Either<
std::iter::Map<
<&'a ArrayVec<(K, V), 8> as IntoIterator>::IntoIter,
<&'a ArrayVec<(K, V), SSO_ARRAY_SIZE> as IntoIterator>::IntoIter,
fn(&'a (K, V)) -> (&'a K, &'a V),
>,
<&'a FxHashMap<K, V> as IntoIterator>::IntoIter,
Expand All @@ -446,16 +446,16 @@ impl<'a, K, V> IntoIterator for &'a SsoHashMap<K, V> {

fn into_iter(self) -> Self::IntoIter {
match self {
SsoHashMap::Array(array) => EitherIter::Left(array.into_iter().map(adapt_array_ref_it)),
SsoHashMap::Map(map) => EitherIter::Right(map.iter()),
SsoHashMap::Array(array) => Either::Left(array.into_iter().map(adapt_array_ref_it)),
SsoHashMap::Map(map) => Either::Right(map.iter()),
}
}
}

impl<'a, K, V> IntoIterator for &'a mut SsoHashMap<K, V> {
type IntoIter = EitherIter<
type IntoIter = Either<
std::iter::Map<
<&'a mut ArrayVec<(K, V), 8> as IntoIterator>::IntoIter,
<&'a mut ArrayVec<(K, V), SSO_ARRAY_SIZE> as IntoIterator>::IntoIter,
fn(&'a mut (K, V)) -> (&'a K, &'a mut V),
>,
<&'a mut FxHashMap<K, V> as IntoIterator>::IntoIter,
Expand All @@ -464,8 +464,8 @@ impl<'a, K, V> IntoIterator for &'a mut SsoHashMap<K, V> {

fn into_iter(self) -> Self::IntoIter {
match self {
SsoHashMap::Array(array) => EitherIter::Left(array.into_iter().map(adapt_array_mut_it)),
SsoHashMap::Map(map) => EitherIter::Right(map.iter_mut()),
SsoHashMap::Array(array) => Either::Left(array.into_iter().map(adapt_array_mut_it)),
SsoHashMap::Map(map) => Either::Right(map.iter_mut()),
}
}
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_data_structures/src/sso/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod either_iter;
mod map;
mod set;

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_infer/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ infer_region_explanation = {$pref_kind ->
[as_defined] the lifetime `{$desc_arg}` as defined here
[as_defined_anon] the anonymous lifetime as defined here
[defined_here] the anonymous lifetime defined here
[anon_num_here] the anonymous lifetime #{$desc_num_arg} defined here
[defined_here_reg] the lifetime `{$desc_arg}` as defined here
}{$suff_kind ->
*[should_not_happen] [{$suff_kind}]
Expand Down
Loading

0 comments on commit 59a05ad

Please sign in to comment.