Skip to content

Rollup of 5 pull requests #72134

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

Merged
merged 12 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/liballoc/alloc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn allocate_zeroed() {
}

#[bench]
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
fn alloc_owned_small(b: &mut Bencher) {
b.iter(|| {
let _: Box<_> = box 10;
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/collections/linked_list/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ fn test_insert_prev() {

#[test]
#[cfg_attr(target_os = "emscripten", ignore)]
#[cfg_attr(miri, ignore)] // Miri does not support threads
fn test_send() {
let n = list_from(&[1, 2, 3]);
thread::spawn(move || {
Expand Down
8 changes: 4 additions & 4 deletions src/liballoc/collections/vec_deque/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::*;
use test;

#[bench]
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
fn bench_push_back_100(b: &mut test::Bencher) {
let mut deq = VecDeque::with_capacity(101);
b.iter(|| {
Expand All @@ -16,7 +16,7 @@ fn bench_push_back_100(b: &mut test::Bencher) {
}

#[bench]
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
fn bench_push_front_100(b: &mut test::Bencher) {
let mut deq = VecDeque::with_capacity(101);
b.iter(|| {
Expand All @@ -29,7 +29,7 @@ fn bench_push_front_100(b: &mut test::Bencher) {
}

#[bench]
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
fn bench_pop_back_100(b: &mut test::Bencher) {
let mut deq = VecDeque::<i32>::with_capacity(101);

Expand All @@ -43,7 +43,7 @@ fn bench_pop_back_100(b: &mut test::Bencher) {
}

#[bench]
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
fn bench_pop_front_100(b: &mut test::Bencher) {
let mut deq = VecDeque::<i32>::with_capacity(101);

Expand Down
8 changes: 5 additions & 3 deletions src/liballoc/sync/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ impl Drop for Canary {

#[test]
#[cfg_attr(target_os = "emscripten", ignore)]
#[cfg_attr(miri, ignore)] // Miri does not support threads
fn manually_share_arc() {
let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let arc_v = Arc::new(v);
Expand Down Expand Up @@ -337,12 +336,13 @@ fn test_ptr_eq() {

#[test]
#[cfg_attr(target_os = "emscripten", ignore)]
#[cfg_attr(miri, ignore)] // Miri does not support threads
fn test_weak_count_locked() {
let mut a = Arc::new(atomic::AtomicBool::new(false));
let a2 = a.clone();
let t = thread::spawn(move || {
for _i in 0..1000000 {
// Miri is too slow
let count = if cfg!(miri) { 1000 } else { 1000000 };
for _i in 0..count {
Arc::get_mut(&mut a);
}
a.store(true, SeqCst);
Expand All @@ -351,6 +351,8 @@ fn test_weak_count_locked() {
while !a2.load(SeqCst) {
let n = Arc::weak_count(&a2);
assert!(n < 2, "bad weak count: {}", n);
#[cfg(miri)] // Miri's scheduler does not guarantee liveness, and thus needs this hint.
atomic::spin_loop_hint();
}
t.join().unwrap();
}
Expand Down
18 changes: 17 additions & 1 deletion src/librustc_middle/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,29 @@ macro_rules! make_mir_visitor {
TerminatorKind::Goto { .. } |
TerminatorKind::Resume |
TerminatorKind::Abort |
TerminatorKind::Return |
TerminatorKind::GeneratorDrop |
TerminatorKind::Unreachable |
TerminatorKind::FalseEdges { .. } |
TerminatorKind::FalseUnwind { .. } => {
}

TerminatorKind::Return => {
// `return` logically moves from the return place `_0`. Note that the place
// cannot be changed by any visitor, though.
let $($mutability)? local = RETURN_PLACE;
self.visit_local(
& $($mutability)? local,
PlaceContext::NonMutatingUse(NonMutatingUseContext::Move),
source_location,
);

assert_eq!(
local,
RETURN_PLACE,
"`MutVisitor` tried to mutate return place of `return` terminator"
);
}

TerminatorKind::SwitchInt {
discr,
switch_ty,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ fn do_mir_borrowck<'a, 'tcx>(
nll_errors,
} = nll::compute_regions(
infcx,
def_id.to_def_id(),
def_id,
free_regions,
body,
&promoted,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_mir/borrow_check/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use rustc_data_structures::fx::FxHashMap;
use rustc_errors::Diagnostic;
use rustc_hir::def_id::DefId;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_index::vec::IndexVec;
use rustc_infer::infer::InferCtxt;
use rustc_middle::mir::{
Expand Down Expand Up @@ -157,7 +157,7 @@ fn populate_polonius_move_facts(
/// This may result in errors being reported.
pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
infcx: &InferCtxt<'cx, 'tcx>,
def_id: DefId,
def_id: LocalDefId,
universal_regions: UniversalRegions<'tcx>,
body: &Body<'tcx>,
promoted: &IndexVec<Promoted, Body<'tcx>>,
Expand Down Expand Up @@ -272,7 +272,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
// Dump facts if requested.
let polonius_output = all_facts.and_then(|all_facts| {
if infcx.tcx.sess.opts.debugging_opts.nll_facts {
let def_path = infcx.tcx.def_path(def_id);
let def_path = infcx.tcx.def_path(def_id.to_def_id());
let dir_path =
PathBuf::from("nll-facts").join(def_path.to_filename_friendly_no_crate());
all_facts.write_to_dir(dir_path, location_table).unwrap();
Expand All @@ -292,7 +292,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(

// Solve the region constraints.
let (closure_region_requirements, nll_errors) =
regioncx.solve(infcx, &body, def_id, polonius_output.clone());
regioncx.solve(infcx, &body, def_id.to_def_id(), polonius_output.clone());

if !nll_errors.is_empty() {
// Suppress unhelpful extra errors in `infer_opaque_types`.
Expand Down
56 changes: 29 additions & 27 deletions src/librustc_mir/borrow_check/type_check/input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,37 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
//
// e.g., `|x: FxHashMap<_, &'static u32>| ...`
let user_provided_sig;
if !self.tcx().is_closure(self.mir_def_id) {
if !self.tcx().is_closure(self.mir_def_id.to_def_id()) {
user_provided_sig = None;
} else {
let typeck_tables = self.tcx().typeck_tables_of(self.mir_def_id.expect_local());
user_provided_sig = match typeck_tables.user_provided_sigs.get(&self.mir_def_id) {
None => None,
Some(user_provided_poly_sig) => {
// Instantiate the canonicalized variables from
// user-provided signature (e.g., the `_` in the code
// above) with fresh variables.
let (poly_sig, _) = self.infcx.instantiate_canonical_with_fresh_inference_vars(
body.span,
&user_provided_poly_sig,
);

// Replace the bound items in the fn sig with fresh
// variables, so that they represent the view from
// "inside" the closure.
Some(
self.infcx
.replace_bound_vars_with_fresh_vars(
let typeck_tables = self.tcx().typeck_tables_of(self.mir_def_id);
user_provided_sig =
match typeck_tables.user_provided_sigs.get(&self.mir_def_id.to_def_id()) {
None => None,
Some(user_provided_poly_sig) => {
// Instantiate the canonicalized variables from
// user-provided signature (e.g., the `_` in the code
// above) with fresh variables.
let (poly_sig, _) =
self.infcx.instantiate_canonical_with_fresh_inference_vars(
body.span,
LateBoundRegionConversionTime::FnCall,
&poly_sig,
)
.0,
)
&user_provided_poly_sig,
);

// Replace the bound items in the fn sig with fresh
// variables, so that they represent the view from
// "inside" the closure.
Some(
self.infcx
.replace_bound_vars_with_fresh_vars(
body.span,
LateBoundRegionConversionTime::FnCall,
&poly_sig,
)
.0,
)
}
}
}
};

debug!(
Expand Down Expand Up @@ -120,7 +122,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
if let Err(terr) = self.eq_opaque_type_and_type(
mir_output_ty,
normalized_output_ty,
self.mir_def_id,
self.mir_def_id.to_def_id(),
Locations::All(output_span),
ConstraintCategory::BoringNoLocation,
) {
Expand All @@ -143,7 +145,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
if let Err(err) = self.eq_opaque_type_and_type(
mir_output_ty,
user_provided_output_ty,
self.mir_def_id,
self.mir_def_id.to_def_id(),
Locations::All(output_span),
ConstraintCategory::BoringNoLocation,
) {
Expand Down
38 changes: 16 additions & 22 deletions src/librustc_mir/borrow_check/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,26 +108,22 @@ mod relate_tys;
///
/// - `infcx` -- inference context to use
/// - `param_env` -- parameter environment to use for trait solving
/// - `mir` -- MIR to type-check
/// - `mir_def_id` -- DefId from which the MIR is derived (must be local)
/// - `region_bound_pairs` -- the implied outlives obligations between type parameters
/// and lifetimes (e.g., `&'a T` implies `T: 'a`)
/// - `implicit_region_bound` -- a region which all generic parameters are assumed
/// to outlive; should represent the fn body
/// - `input_tys` -- fully liberated, but **not** normalized, expected types of the arguments;
/// the types of the input parameters found in the MIR itself will be equated with these
/// - `output_ty` -- fully liberated, but **not** normalized, expected return type;
/// the type for the RETURN_PLACE will be equated with this
/// - `liveness` -- results of a liveness computation on the MIR; used to create liveness
/// constraints for the regions in the types of variables
/// - `body` -- MIR body to type-check
/// - `promoted` -- map of promoted constants within `body`
/// - `mir_def_id` -- `LocalDefId` from which the MIR is derived
/// - `universal_regions` -- the universal regions from `body`s function signature
/// - `location_table` -- MIR location map of `body`
/// - `borrow_set` -- information about borrows occurring in `body`
/// - `all_facts` -- when using Polonius, this is the generated set of Polonius facts
/// - `flow_inits` -- results of a maybe-init dataflow analysis
/// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysis
/// - `elements` -- MIR region map
pub(crate) fn type_check<'mir, 'tcx>(
infcx: &InferCtxt<'_, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
body: &Body<'tcx>,
promoted: &IndexVec<Promoted, Body<'tcx>>,
mir_def_id: DefId,
mir_def_id: LocalDefId,
universal_regions: &Rc<UniversalRegions<'tcx>>,
location_table: &LocationTable,
borrow_set: &BorrowSet<'tcx>,
Expand Down Expand Up @@ -191,7 +187,7 @@ pub(crate) fn type_check<'mir, 'tcx>(

fn type_check_internal<'a, 'tcx, R>(
infcx: &'a InferCtxt<'a, 'tcx>,
mir_def_id: DefId,
mir_def_id: LocalDefId,
param_env: ty::ParamEnv<'tcx>,
body: &'a Body<'tcx>,
promoted: &'a IndexVec<Promoted, Body<'tcx>>,
Expand Down Expand Up @@ -271,7 +267,7 @@ struct TypeVerifier<'a, 'b, 'tcx> {
body: &'b Body<'tcx>,
promoted: &'b IndexVec<Promoted, Body<'tcx>>,
last_span: Span,
mir_def_id: DefId,
mir_def_id: LocalDefId,
errors_reported: bool,
}

Expand Down Expand Up @@ -815,7 +811,7 @@ struct TypeChecker<'a, 'tcx> {
/// User type annotations are shared between the main MIR and the MIR of
/// all of the promoted items.
user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>,
mir_def_id: DefId,
mir_def_id: LocalDefId,
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
implicit_region_bound: ty::Region<'tcx>,
reported_errors: FxHashSet<(Ty<'tcx>, Span)>,
Expand Down Expand Up @@ -963,7 +959,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
fn new(
infcx: &'a InferCtxt<'a, 'tcx>,
body: &'a Body<'tcx>,
mir_def_id: DefId,
mir_def_id: LocalDefId,
param_env: ty::ParamEnv<'tcx>,
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
implicit_region_bound: ty::Region<'tcx>,
Expand Down Expand Up @@ -1142,7 +1138,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// When you have `let x: impl Foo = ...` in a closure,
// the resulting inferend values are stored with the
// def-id of the base function.
let parent_def_id = self.tcx().closure_base_def_id(self.mir_def_id);
let parent_def_id = self.tcx().closure_base_def_id(self.mir_def_id.to_def_id());
return self.eq_opaque_type_and_type(sub, sup, parent_def_id, locations, category);
} else {
return Err(terr);
Expand Down Expand Up @@ -1994,7 +1990,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span) {
let ccx = ConstCx::new_with_param_env(
tcx,
self.mir_def_id.expect_local(),
self.mir_def_id,
body,
self.param_env,
);
Expand All @@ -2010,9 +2006,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
&traits::Obligation::new(
ObligationCause::new(
span,
self.tcx()
.hir()
.local_def_id_to_hir_id(self.mir_def_id.expect_local()),
self.tcx().hir().local_def_id_to_hir_id(self.mir_def_id),
traits::ObligationCauseCode::RepeatVec(should_suggest),
),
self.param_env,
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_mir/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_middle::mir::interpret::{InterpError, InterpErrorInfo};
use rustc_middle::ty;
use rustc_middle::ty::layout::TyAndLayout;
use rustc_span::symbol::{sym, Symbol};
use rustc_target::abi::{Abi, LayoutOf, Scalar, VariantIdx, Variants};
use rustc_target::abi::{Abi, LayoutOf, Scalar, Size, VariantIdx, Variants};

use std::hash::Hash;

Expand Down Expand Up @@ -744,10 +744,11 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
match op.layout.ty.kind {
ty::Str => {
let mplace = op.assert_mem_place(self.ecx); // strings are never immediate
let len = mplace.len(self.ecx)?;
try_validation!(
self.ecx.read_str(mplace),
self.ecx.memory.read_bytes(mplace.ptr, Size::from_bytes(len)),
self.path,
err_ub!(InvalidStr(..)) => { "uninitialized or non-UTF-8 data in str" },
err_ub!(InvalidUninitBytes(..)) => { "uninitialized data in `str`" },
);
}
ty::Array(tys, ..) | ty::Slice(tys)
Expand Down
7 changes: 6 additions & 1 deletion src/librustc_mir/transform/copy_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ impl<'tcx> MirPass<'tcx> for CopyPropagation {
}
// Conservatively gives up if the dest is an argument,
// because there may be uses of the original argument value.
if body.local_kind(dest_local) == LocalKind::Arg {
// Also gives up on the return place, as we cannot propagate into its implicit
// use by `return`.
if matches!(
body.local_kind(dest_local),
LocalKind::Arg | LocalKind::ReturnPointer
) {
debug!(" Can't copy-propagate local: dest {:?} (argument)", dest_local);
continue;
}
Expand Down
10 changes: 10 additions & 0 deletions src/librustc_mir/transform/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ impl<'tcx> MutVisitor<'tcx> for RenameLocalVisitor<'tcx> {
*local = self.to;
}
}

fn visit_terminator_kind(&mut self, kind: &mut TerminatorKind<'tcx>, location: Location) {
match kind {
TerminatorKind::Return => {
// Do not replace the implicit `_0` access here, as that's not possible. The
// transform already handles `return` correctly.
}
_ => self.super_terminator_kind(kind, location),
}
}
}

struct DerefArgVisitor<'tcx> {
Expand Down
Loading