Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #110239

Merged
merged 22 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d8ed2fb
Fix transmute intrinsic mir validation ICE
JakobDegen Apr 5, 2023
3352775
Inline and remove `renumber_regions`.
nnethercote Apr 11, 2023
7e8905c
Rename a variable.
nnethercote Apr 11, 2023
955ba37
Remove the unused `anon_num_here` error.
nnethercote Apr 11, 2023
0465201
Use `itertools::Either` instead of own `EitherIter` impl
WaffleLapkin Apr 11, 2023
a329592
Use `SSO_ARRAY_SIZE` instead of `8` in `SsoHashMap` impl
WaffleLapkin Apr 11, 2023
a11053a
Remove orphaned remove_dir_all implementation from rust-installer
Noratrieb Apr 11, 2023
cecb901
Add Offset binary op to custom mir
cbeuw Apr 11, 2023
06ec5fa
Add regression test for #59003
JohnTitor Apr 11, 2023
7446321
Rename `NllVisitor` as `RegionRenumberer`.
nnethercote Apr 11, 2023
c9b0635
Inline and remove `DescriptionCtx::add_to`.
nnethercote Apr 11, 2023
877777f
Inline and remove `DescriptionCtx::from_early_bound_and_free_regions`.
nnethercote Apr 11, 2023
76d0c6f
Inline and remove `msg_span_from_early_bound_and_free_regions`.
nnethercote Apr 11, 2023
f45417b
doc: loongarch: Fix typos
heiher Apr 12, 2023
fd40f51
Rollup merge of #109959 - JakobDegen:transmute-validate, r=compiler-e…
matthiaskrgr Apr 12, 2023
827b74c
Rollup merge of #110176 - nnethercote:renumber-cleanups, r=lqd
matthiaskrgr Apr 12, 2023
f21d840
Rollup merge of #110182 - WaffleLapkin:neither, r=Nilstrieb
matthiaskrgr Apr 12, 2023
2118667
Rollup merge of #110188 - Nilstrieb:remove-remove-dir-all, r=jyn514
matthiaskrgr Apr 12, 2023
bb037e6
Rollup merge of #110190 - cbeuw:mir-offset, r=oli-obk
matthiaskrgr Apr 12, 2023
4976926
Rollup merge of #110209 - JohnTitor:issue-59003, r=compiler-errors
matthiaskrgr Apr 12, 2023
7614ea4
Rollup merge of #110210 - nnethercote:DescriptionCtx-cleanups, r=davi…
matthiaskrgr Apr 12, 2023
a954584
Rollup merge of #110217 - rust-loongarch:fix-typos, r=GuillaumeGomez
matthiaskrgr Apr 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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