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 #110215

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a629267
Preserve argument indexes when inlining MIR
davidlattimore Mar 21, 2023
3352775
Inline and remove `renumber_regions`.
nnethercote Apr 11, 2023
7e8905c
Rename a variable.
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
44fbf0c
Add creation time support to `FileTimes` on apple and windows
beetrees Mar 30, 2023
f31c34c
Add test for `FileTimes`
beetrees Apr 8, 2023
7446321
Rename `NllVisitor` as `RegionRenumberer`.
nnethercote Apr 11, 2023
2f29108
Doc typo/grammar fix.
RustEnthusiast Apr 12, 2023
5c579a4
Rollup merge of #109466 - davidlattimore:inline-arg-via-var-debug-inf…
compiler-errors Apr 12, 2023
466e5c1
Rollup merge of #109773 - beetrees:set-file-time-improvements, r=Amanieu
compiler-errors Apr 12, 2023
70f73f0
Rollup merge of #110176 - nnethercote:renumber-cleanups, r=lqd
compiler-errors Apr 12, 2023
ffd0aeb
Rollup merge of #110182 - WaffleLapkin:neither, r=Nilstrieb
compiler-errors Apr 12, 2023
707f21b
Rollup merge of #110188 - Nilstrieb:remove-remove-dir-all, r=jyn514
compiler-errors Apr 12, 2023
3427cec
Rollup merge of #110190 - cbeuw:mir-offset, r=oli-obk
compiler-errors Apr 12, 2023
bc8878b
Rollup merge of #110209 - JohnTitor:issue-59003, r=compiler-errors
compiler-errors Apr 12, 2023
d43f5ea
Rollup merge of #110212 - RustEnthusiast:master, r=cuviper
compiler-errors 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);
}
}
10 changes: 4 additions & 6 deletions compiler/rustc_codegen_ssa/src/mir/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,11 +442,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let (var_ty, var_kind) = match var.value {
mir::VarDebugInfoContents::Place(place) => {
let var_ty = self.monomorphized_place_ty(place.as_ref());
let var_kind = if self.mir.local_kind(place.local) == mir::LocalKind::Arg
let var_kind = if let Some(arg_index) = var.argument_index
&& place.projection.is_empty()
&& var.source_info.scope == mir::OUTERMOST_SOURCE_SCOPE
{
let arg_index = place.local.index() - 1;
let arg_index = arg_index as usize;
if target_is_msvc {
// ScalarPair parameters are spilled to the stack so they need to
// be marked as a `LocalVariable` for MSVC debuggers to visualize
Expand All @@ -455,13 +454,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
if let Abi::ScalarPair(_, _) = var_ty_layout.abi {
VariableKind::LocalVariable
} else {
VariableKind::ArgumentVariable(arg_index + 1)
VariableKind::ArgumentVariable(arg_index)
}
} else {
// FIXME(eddyb) shouldn't `ArgumentVariable` indices be
// offset in closures to account for the hidden environment?
// Also, is this `+ 1` needed at all?
VariableKind::ArgumentVariable(arg_index + 1)
VariableKind::ArgumentVariable(arg_index)
}
} else {
VariableKind::LocalVariable
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
5 changes: 5 additions & 0 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,11 @@ pub struct VarDebugInfo<'tcx> {

/// Where the data for this user variable is to be found.
pub value: VarDebugInfoContents<'tcx>,

/// When present, indicates what argument number this variable is in the function that it
/// originated from (starting from 1). Note, if MIR inlining is enabled, then this is the
/// argument number in the original function before it was inlined.
pub argument_index: Option<u16>,
}

///////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ macro_rules! make_mir_visitor {
name: _,
source_info,
value,
argument_index: _,
} = var_debug_info;

self.visit_source_info(source_info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
)),
)
},
@call("mir_offset", args) => {
let ptr = self.parse_operand(args[0])?;
let offset = self.parse_operand(args[1])?;
Ok(Rvalue::BinaryOp(BinOp::Offset, Box::new((ptr, offset))))
},
@call("mir_len", args) => Ok(Rvalue::Len(self.parse_place(args[0])?)),
ExprKind::Borrow { borrow_kind, arg } => Ok(
Rvalue::Ref(self.tcx.lifetimes.re_erased, *borrow_kind, self.parse_place(*arg)?)
Expand Down
Loading