Skip to content

Commit 8307d27

Browse files
authored
Merge pull request #332 from solson/rustup
rustup
2 parents 2c4fcd8 + a1f71af commit 8307d27

24 files changed

+60
-78
lines changed

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ script:
3636
notifications:
3737
email:
3838
on_success: never
39+
branches:
40+
only:
41+
- master
3942
env:
4043
global:
4144
- RUST_TEST_NOCAPTURE=1

miri/bin/miri.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn after_analysis<'a, 'tcx>(state: &mut CompileState<'a, 'tcx>) {
131131
);
132132
} else if let Some((entry_node_id, _)) = *state.session.entry_fn.borrow() {
133133
let entry_def_id = tcx.hir.local_def_id(entry_node_id);
134-
let start_wrapper = tcx.lang_items.start_fn().and_then(|start_fn| {
134+
let start_wrapper = tcx.lang_items().start_fn().and_then(|start_fn| {
135135
if tcx.is_mir_available(start_fn) {
136136
Some(start_fn)
137137
} else {

miri/fn_call.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
9696
dest_ty: Ty<'tcx>,
9797
dest_block: mir::BasicBlock,
9898
) -> EvalResult<'tcx> {
99-
let name = self.tcx.item_name(def_id);
10099
let attrs = self.tcx.get_attrs(def_id);
101-
let link_name = attr::first_attr_value_str_by_name(&attrs, "link_name")
102-
.unwrap_or(name)
103-
.as_str();
100+
let link_name = match attr::first_attr_value_str_by_name(&attrs, "link_name") {
101+
Some(name) => name.as_str(),
102+
None => self.tcx.item_name(def_id),
103+
};
104104

105105
match &link_name[..] {
106106
"malloc" => {
@@ -477,28 +477,26 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
477477

478478
/// Get an instance for a path.
479479
fn resolve_path(&self, path: &[&str]) -> EvalResult<'tcx, ty::Instance<'tcx>> {
480-
let cstore = &self.tcx.sess.cstore;
481-
482-
let crates = cstore.crates();
483-
crates
480+
self.tcx
481+
.crates()
484482
.iter()
485-
.find(|&&krate| cstore.crate_name(krate) == path[0])
483+
.find(|&&krate| self.tcx.original_crate_name(krate) == path[0])
486484
.and_then(|krate| {
487485
let krate = DefId {
488486
krate: *krate,
489487
index: CRATE_DEF_INDEX,
490488
};
491-
let mut items = cstore.item_children(krate, self.tcx.sess);
489+
let mut items = self.tcx.item_children(krate);
492490
let mut path_it = path.iter().skip(1).peekable();
493491

494492
while let Some(segment) = path_it.next() {
495-
for item in &mem::replace(&mut items, vec![]) {
493+
for item in mem::replace(&mut items, Default::default()).iter() {
496494
if item.ident.name == *segment {
497495
if path_it.peek().is_none() {
498496
return Some(ty::Instance::mono(self.tcx, item.def.def_id()));
499497
}
500498

501-
items = cstore.item_children(item.def.def_id(), self.tcx.sess);
499+
items = self.tcx.item_children(item.def.def_id());
502500
break;
503501
}
504502
}

miri/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl<'a, 'tcx> EvalContextExt<'tcx> for EvalContext<'a, 'tcx, super::Evaluator>
3232
) -> EvalResult<'tcx> {
3333
let substs = instance.substs;
3434

35-
let intrinsic_name = &self.tcx.item_name(instance.def_id()).as_str()[..];
35+
let intrinsic_name = &self.tcx.item_name(instance.def_id())[..];
3636
match intrinsic_name {
3737
"align_offset" => {
3838
// FIXME: return a real value in case the target allocation has an

rustc_tests/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn after_analysis<'a, 'tcx>(state: &mut CompileState<'a, 'tcx>) {
100100
state.hir_crate.unwrap().visit_all_item_likes(&mut Visitor(limits, tcx, state));
101101
} else if let Some((entry_node_id, _)) = *state.session.entry_fn.borrow() {
102102
let entry_def_id = tcx.hir.local_def_id(entry_node_id);
103-
let start_wrapper = tcx.lang_items.start_fn().and_then(|start_fn|
103+
let start_wrapper = tcx.lang_items().start_fn().and_then(|start_fn|
104104
if tcx.is_mir_available(start_fn) { Some(start_fn) } else { None });
105105
miri::eval_main(tcx, entry_def_id, start_wrapper, limits);
106106

src/librustc_mir/interpret/eval_context.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
508508
stmt: 0,
509509
});
510510

511-
let cur_frame = self.cur_frame();
512-
self.memory.set_cur_frame(cur_frame);
511+
self.memory.cur_frame = self.cur_frame();
513512

514513
if self.stack.len() > self.stack_limit {
515514
err!(StackFrameLimitReached)
@@ -520,14 +519,13 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
520519

521520
pub(super) fn pop_stack_frame(&mut self) -> EvalResult<'tcx> {
522521
::log_settings::settings().indentation -= 1;
523-
self.memory.locks_lifetime_ended(None);
522+
self.end_region(None)?;
524523
let frame = self.stack.pop().expect(
525524
"tried to pop a stack frame, but there were none",
526525
);
527526
if !self.stack.is_empty() {
528-
// TODO: IS this the correct time to start considering these accesses as originating from the returned-to stack frame?
529-
let cur_frame = self.cur_frame();
530-
self.memory.set_cur_frame(cur_frame);
527+
// TODO: Is this the correct time to start considering these accesses as originating from the returned-to stack frame?
528+
self.memory.cur_frame = self.cur_frame();
531529
}
532530
match frame.return_to_block {
533531
StackPopCleanup::MarkStatic(mutable) => {
@@ -2267,7 +2265,7 @@ fn fn_once_adapter_instance<'a, 'tcx>(
22672265
substs: ty::ClosureSubsts<'tcx>,
22682266
) -> ty::Instance<'tcx> {
22692267
debug!("fn_once_adapter_shim({:?}, {:?})", closure_did, substs);
2270-
let fn_once = tcx.lang_items.fn_once_trait().unwrap();
2268+
let fn_once = tcx.lang_items().fn_once_trait().unwrap();
22712269
let call_once = tcx.associated_items(fn_once)
22722270
.find(|it| it.kind == ty::AssociatedKind::Method)
22732271
.unwrap()
@@ -2346,7 +2344,7 @@ pub fn resolve<'a, 'tcx>(
23462344
ty::InstanceDef::Intrinsic(def_id)
23472345
}
23482346
_ => {
2349-
if Some(def_id) == tcx.lang_items.drop_in_place_fn() {
2347+
if Some(def_id) == tcx.lang_items().drop_in_place_fn() {
23502348
let ty = substs.type_at(0);
23512349
if needs_drop_glue(tcx, ty) {
23522350
debug!(" => nontrivial drop glue");
@@ -2440,7 +2438,7 @@ fn resolve_associated_item<'a, 'tcx>(
24402438
}
24412439
}
24422440
::rustc::traits::VtableClosure(closure_data) => {
2443-
let trait_closure_kind = tcx.lang_items.fn_trait_kind(trait_id).unwrap();
2441+
let trait_closure_kind = tcx.lang_items().fn_trait_kind(trait_id).unwrap();
24442442
resolve_closure(
24452443
tcx,
24462444
closure_data.closure_def_id,
@@ -2461,7 +2459,7 @@ fn resolve_associated_item<'a, 'tcx>(
24612459
substs: rcvr_substs,
24622460
}
24632461
}
2464-
::rustc::traits::VtableBuiltin(..) if Some(trait_id) == tcx.lang_items.clone_trait() => {
2462+
::rustc::traits::VtableBuiltin(..) if Some(trait_id) == tcx.lang_items().clone_trait() => {
24652463
ty::Instance {
24662464
def: ty::InstanceDef::CloneShim(def_id, trait_ref.self_ty()),
24672465
substs: rcvr_substs

src/librustc_mir/interpret/memory.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ pub struct Memory<'a, 'tcx, M: Machine<'tcx>> {
268268
writes_are_aligned: Cell<bool>,
269269

270270
/// The current stack frame. Used to check accesses against locks.
271-
cur_frame: usize,
271+
pub(super) cur_frame: usize,
272272
}
273273

274274
impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
@@ -530,10 +530,6 @@ impl<'a, 'tcx, M: Machine<'tcx>> Memory<'a, 'tcx, M> {
530530
}
531531
Ok(())
532532
}
533-
534-
pub(crate) fn set_cur_frame(&mut self, cur_frame: usize) {
535-
self.cur_frame = cur_frame;
536-
}
537533
}
538534

539535
/// Locking

src/librustc_mir/interpret/step.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
164164
}
165165
}
166166
EndRegion(ce) => {
167-
self.end_region(ce)?;
167+
self.end_region(Some(ce))?;
168168
}
169169

170170
// Defined to do nothing. These are added by optimization passes, to avoid changing the

src/librustc_mir/interpret/validation.rs

+34-19
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
4545
if self.tcx.sess.opts.debugging_opts.mir_emit_validate == 0 {
4646
return Ok(());
4747
}
48+
debug_assert!(self.memory.cur_frame == self.cur_frame());
4849

4950
// HACK: Determine if this method is whitelisted and hence we do not perform any validation.
5051
// We currently insta-UB on anything passing around uninitialized memory, so we have to whitelist
@@ -55,17 +56,17 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
5556
use regex::Regex;
5657
lazy_static! {
5758
static ref RE: Regex = Regex::new("^(\
58-
std::mem::uninitialized::|\
59-
std::mem::forget::|\
59+
(std|alloc::heap::__core)::mem::uninitialized::|\
60+
(std|alloc::heap::__core)::mem::forget::|\
6061
<(std|alloc)::heap::Heap as (std::heap|alloc::allocator)::Alloc>::|\
61-
<std::mem::ManuallyDrop<T>><.*>::new$|\
62-
<std::mem::ManuallyDrop<T> as std::ops::DerefMut><.*>::deref_mut$|\
63-
std::ptr::read::|\
62+
<(std|alloc::heap::__core)::mem::ManuallyDrop<T>><.*>::new$|\
63+
<(std|alloc::heap::__core)::mem::ManuallyDrop<T> as std::ops::DerefMut><.*>::deref_mut$|\
64+
(std|alloc::heap::__core)::ptr::read::|\
6465
\
6566
<std::sync::Arc<T>><.*>::inner$|\
6667
<std::sync::Arc<T>><.*>::drop_slow$|\
6768
(std::heap|alloc::allocator)::Layout::for_value::|\
68-
std::mem::(size|align)_of_val::\
69+
(std|alloc::heap::__core)::mem::(size|align)_of_val::\
6970
)").unwrap();
7071
}
7172
// Now test
@@ -93,7 +94,8 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
9394
if query.mutbl == MutMutable {
9495
let lft = DynamicLifetime {
9596
frame: self.cur_frame(),
96-
region: Some(scope),
97+
region: Some(scope), // Notably, we only ever suspend things for given regions.
98+
// Suspending for the entire function does not make any sense.
9799
};
98100
trace!("Suspending {:?} until {:?}", query, scope);
99101
self.suspended.entry(lft).or_insert_with(Vec::new).push(
@@ -106,17 +108,30 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
106108
self.validate(query, mode)
107109
}
108110

109-
pub(crate) fn end_region(&mut self, scope: region::Scope) -> EvalResult<'tcx> {
110-
self.memory.locks_lifetime_ended(Some(scope));
111-
// Recover suspended lvals
112-
let lft = DynamicLifetime {
113-
frame: self.cur_frame(),
114-
region: Some(scope),
115-
};
116-
if let Some(queries) = self.suspended.remove(&lft) {
117-
for query in queries {
118-
trace!("Recovering {:?} from suspension", query);
119-
self.validate(query, ValidationMode::Recover(scope))?;
111+
/// Release locks and executes suspensions of the given region (or the entire fn, in case of None).
112+
pub(crate) fn end_region(&mut self, scope: Option<region::Scope>) -> EvalResult<'tcx> {
113+
debug_assert!(self.memory.cur_frame == self.cur_frame());
114+
self.memory.locks_lifetime_ended(scope);
115+
match scope {
116+
Some(scope) => {
117+
// Recover suspended lvals
118+
let lft = DynamicLifetime {
119+
frame: self.cur_frame(),
120+
region: Some(scope),
121+
};
122+
if let Some(queries) = self.suspended.remove(&lft) {
123+
for query in queries {
124+
trace!("Recovering {:?} from suspension", query);
125+
self.validate(query, ValidationMode::Recover(scope))?;
126+
}
127+
}
128+
}
129+
None => {
130+
// Clean suspension table of current frame
131+
let cur_frame = self.cur_frame();
132+
self.suspended.retain(|lft, _| {
133+
lft.frame != cur_frame // keep only what is in the other (lower) frames
134+
});
120135
}
121136
}
122137
Ok(())
@@ -543,7 +558,7 @@ impl<'a, 'tcx, M: Machine<'tcx>> EvalContext<'a, 'tcx, M> {
543558
Ok(())
544559
}
545560
TyAdt(adt, subst) => {
546-
if Some(adt.did) == self.tcx.lang_items.unsafe_cell_type() &&
561+
if Some(adt.did) == self.tcx.lang_items().unsafe_cell_type() &&
547562
query.mutbl == MutImmutable
548563
{
549564
// No locks for shared unsafe cells. Also no other validation, the only field is private anyway.

tests/compile-fail/deallocate-bad-alignment.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use alloc::allocator::*;
77

88
// error-pattern: tried to deallocate or reallocate using incorrect alignment or size
99

10-
use alloc::heap::*;
1110
fn main() {
1211
unsafe {
1312
let x = Heap.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap();

tests/compile-fail/deallocate-bad-size.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use alloc::allocator::*;
77

88
// error-pattern: tried to deallocate or reallocate using incorrect alignment or size
99

10-
use alloc::heap::*;
1110
fn main() {
1211
unsafe {
1312
let x = Heap.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap();

tests/compile-fail/deallocate-twice.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use alloc::allocator::*;
77

88
// error-pattern: tried to deallocate dangling pointer
99

10-
use alloc::heap::*;
1110
fn main() {
1211
unsafe {
1312
let x = Heap.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap();

tests/compile-fail/reallocate-bad-alignment-2.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use alloc::allocator::*;
77

88
// error-pattern: tried to deallocate or reallocate using incorrect alignment or size
99

10-
use alloc::heap::*;
1110
fn main() {
1211
unsafe {
1312
let x = Heap.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap();

tests/compile-fail/reallocate-bad-alignment.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use alloc::allocator::*;
77

88
// error-pattern: tried to deallocate or reallocate using incorrect alignment or size
99

10-
use alloc::heap::*;
1110
fn main() {
1211
unsafe {
1312
let x = Heap.alloc(Layout::from_size_align_unchecked(1, 2)).unwrap();

tests/compile-fail/reallocate-bad-size.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use alloc::allocator::*;
77

88
// error-pattern: tried to deallocate or reallocate using incorrect alignment or size
99

10-
use alloc::heap::*;
1110
fn main() {
1211
unsafe {
1312
let x = Heap.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap();

tests/compile-fail/reallocate-dangling.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use alloc::allocator::*;
77

88
// error-pattern: dangling pointer was dereferenced
99

10-
use alloc::heap::*;
1110
fn main() {
1211
unsafe {
1312
let x = Heap.alloc(Layout::from_size_align_unchecked(1, 1)).unwrap();

tests/run-pass-fullmir/u128.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// compile-flags: -Zmir-emit-validate=0
12-
1311
#![feature(i128_type)]
1412

1513
fn b<T>(t: T) -> T { t }

tests/run-pass-fullmir/unsized-tuple-impls.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// compile-flags: -Zmir-emit-validate=0
12-
1311
#![feature(unsized_tuple_coercion)]
1412
use std::mem;
1513

tests/run-pass/dst-field-align.rs

-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// FIXME: Broken by #296
12-
// compile-flags: -Zmir-emit-validate=0
13-
1411
#![allow(dead_code)]
1512

1613
struct Foo<T: ?Sized> {

tests/run-pass/mir_coercions.rs

-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// FIXME: investigate again once #296 is fixed
12-
// compile-flags: -Zmir-emit-validate=0
13-
1411
#![feature(coerce_unsized, unsize)]
1512

1613
use std::ops::CoerceUnsized;

tests/run-pass/non_capture_closure_to_fn_ptr.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// FIXME: investigate again once #296 is fixed
2-
// compile-flags: -Zmir-emit-validate=0
3-
41
// allow(const_err) to work around a bug in warnings
52
#[allow(const_err)]
63
static FOO: fn() = || { assert_ne!(42, 43) };

tests/run-pass/pointers.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// compile-flags: -Zmir-emit-validate=0
2-
31
fn one_line_ref() -> i16 {
42
*&1
53
}

tests/run-pass/subslice_array.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// FIXME: investigate again once #296 is fixed
2-
// compile-flags: -Zmir-emit-validate=0
3-
41
#![feature(advanced_slice_patterns)]
52
#![feature(slice_patterns)]
63

tests/run-pass/tuple_like_enum_variant_constructor_pointer_opt.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// FIXME: investigate again once #296 is fixed
2-
// compile-flags: -Zmir-emit-validate=0
3-
41
fn main() {
52
let x = 5;
63
assert_eq!(Some(&x).map(Some), Some(Some(&x)));

0 commit comments

Comments
 (0)