Skip to content

Commit fe5d977

Browse files
committed
Auto merge of #1197 - RalfJung:rustup, r=RalfJung
Rustup
2 parents b9eb21a + cc1ebd0 commit fe5d977

File tree

8 files changed

+60
-60
lines changed

8 files changed

+60
-60
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
04e7f96dd89b1f0ad615dff1c85d11d4c4c64cb4
1+
d9051341a1c142542a3f7dab509266606c775382

src/eval.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use std::ffi::OsStr;
55
use rand::rngs::StdRng;
66
use rand::SeedableRng;
77

8-
use rustc_hir::def_id::DefId;
98
use rustc::ty::layout::{LayoutOf, Size};
109
use rustc::ty::{self, TyCtxt};
10+
use rustc_hir::def_id::DefId;
1111

1212
use crate::*;
1313

@@ -50,10 +50,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
5050
let mut ecx = InterpCx::new(
5151
tcx.at(rustc_span::source_map::DUMMY_SP),
5252
ty::ParamEnv::reveal_all(),
53-
Evaluator::new(
54-
config.communicate,
55-
config.validate,
56-
),
53+
Evaluator::new(config.communicate, config.validate),
5754
MemoryExtra::new(
5855
StdRng::seed_from_u64(config.seed.unwrap_or(0)),
5956
config.stacked_borrows,

src/helpers.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use std::ffi::OsStr;
22
use std::{iter, mem};
33

4-
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
54
use rustc::mir;
65
use rustc::ty::{
76
self,
87
layout::{self, LayoutOf, Size, TyLayout},
98
List, TyCtxt,
109
};
10+
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
1111
use rustc_span::source_map::DUMMY_SP;
1212

1313
use rand::RngCore;
@@ -515,7 +515,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
515515
fn alloc_os_str_as_c_str(
516516
&mut self,
517517
os_str: &OsStr,
518-
memkind: MemoryKind<MiriMemoryKind>
518+
memkind: MemoryKind<MiriMemoryKind>,
519519
) -> Pointer<Tag> {
520520
let size = os_str.len() as u64 + 1; // Make space for `0` terminator.
521521
let this = self.eval_context_mut();
@@ -532,17 +532,17 @@ pub fn immty_from_int_checked<'tcx>(
532532
layout: TyLayout<'tcx>,
533533
) -> InterpResult<'tcx, ImmTy<'tcx, Tag>> {
534534
let int = int.into();
535-
Ok(ImmTy::try_from_int(int, layout).ok_or_else(||
535+
Ok(ImmTy::try_from_int(int, layout).ok_or_else(|| {
536536
err_unsup_format!("Signed value {:#x} does not fit in {} bits", int, layout.size.bits())
537-
)?)
537+
})?)
538538
}
539539

540540
pub fn immty_from_uint_checked<'tcx>(
541541
int: impl Into<u128>,
542542
layout: TyLayout<'tcx>,
543543
) -> InterpResult<'tcx, ImmTy<'tcx, Tag>> {
544544
let int = int.into();
545-
Ok(ImmTy::try_from_uint(int, layout).ok_or_else(||
545+
Ok(ImmTy::try_from_uint(int, layout).ok_or_else(|| {
546546
err_unsup_format!("Signed value {:#x} does not fit in {} bits", int, layout.size.bits())
547-
)?)
547+
})?)
548548
}

src/lib.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
extern crate log;
99
// From rustc.
1010
extern crate rustc_apfloat;
11-
extern crate syntax;
11+
extern crate rustc_ast;
1212
#[macro_use]
1313
extern crate rustc;
14-
extern crate rustc_hir;
15-
extern crate rustc_span;
1614
extern crate rustc_data_structures;
15+
extern crate rustc_hir;
1716
extern crate rustc_mir;
17+
extern crate rustc_span;
1818
extern crate rustc_target;
1919

2020
mod diagnostics;
@@ -44,7 +44,8 @@ pub use crate::shims::tls::{EvalContextExt as TlsEvalContextExt, TlsData};
4444
pub use crate::shims::EvalContextExt as ShimsEvalContextExt;
4545

4646
pub use crate::diagnostics::{
47-
register_diagnostic, report_diagnostic, EvalContextExt as DiagnosticsEvalContextExt, NonHaltingDiagnostic,
47+
register_diagnostic, report_diagnostic, EvalContextExt as DiagnosticsEvalContextExt,
48+
NonHaltingDiagnostic,
4849
};
4950
pub use crate::eval::{create_ecx, eval_main, MiriConfig, TerminationInfo};
5051
pub use crate::helpers::EvalContextExt as HelpersEvalContextExt;
@@ -56,12 +57,17 @@ pub use crate::mono_hash_map::MonoHashMap;
5657
pub use crate::operator::EvalContextExt as OperatorEvalContextExt;
5758
pub use crate::range_map::RangeMap;
5859
pub use crate::stacked_borrows::{
59-
EvalContextExt as StackedBorEvalContextExt, Item, Permission, PtrId, Stack,
60-
Stacks, Tag,
60+
EvalContextExt as StackedBorEvalContextExt, Item, Permission, PtrId, Stack, Stacks, Tag,
6161
};
6262

6363
/// Insert rustc arguments at the beginning of the argument list that Miri wants to be
6464
/// set per default, for maximal validation power.
6565
pub fn miri_default_args() -> &'static [&'static str] {
66-
&["-Zalways-encode-mir", "-Zmir-emit-retag", "-Zmir-opt-level=0", "--cfg=miri", "-Cdebug-assertions=on"]
66+
&[
67+
"-Zalways-encode-mir",
68+
"-Zmir-emit-retag",
69+
"-Zmir-opt-level=0",
70+
"--cfg=miri",
71+
"-Cdebug-assertions=on",
72+
]
6773
}

src/machine.rs

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
44
use std::borrow::Cow;
55
use std::cell::RefCell;
6-
use std::rc::Rc;
76
use std::num::NonZeroU64;
7+
use std::rc::Rc;
88

99
use rand::rngs::StdRng;
1010

11-
use rustc_hir::def_id::DefId;
1211
use rustc::mir;
1312
use rustc::ty::{
1413
self,
1514
layout::{LayoutOf, Size},
1615
Ty, TyCtxt,
1716
};
17+
use rustc_ast::attr;
18+
use rustc_hir::def_id::DefId;
1819
use rustc_span::{source_map::Span, symbol::sym};
19-
use syntax::attr;
2020

2121
use crate::*;
2222

@@ -85,11 +85,7 @@ impl MemoryExtra {
8585
} else {
8686
None
8787
};
88-
MemoryExtra {
89-
stacked_borrows,
90-
intptrcast: Default::default(),
91-
rng: RefCell::new(rng),
92-
}
88+
MemoryExtra { stacked_borrows, intptrcast: Default::default(), rng: RefCell::new(rng) }
9389
}
9490
}
9591

@@ -307,18 +303,15 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
307303
) -> (Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>, Self::PointerTag) {
308304
let kind = kind.expect("we set our STATIC_KIND so this cannot be None");
309305
let alloc = alloc.into_owned();
310-
let (stacks, base_tag) = if let Some(stacked_borrows) = memory_extra.stacked_borrows.as_ref() {
311-
let (stacks, base_tag) = Stacks::new_allocation(
312-
id,
313-
alloc.size,
314-
Rc::clone(stacked_borrows),
315-
kind,
316-
);
317-
(Some(stacks), base_tag)
318-
} else {
319-
// No stacks, no tag.
320-
(None, Tag::Untagged)
321-
};
306+
let (stacks, base_tag) =
307+
if let Some(stacked_borrows) = memory_extra.stacked_borrows.as_ref() {
308+
let (stacks, base_tag) =
309+
Stacks::new_allocation(id, alloc.size, Rc::clone(stacked_borrows), kind);
310+
(Some(stacks), base_tag)
311+
} else {
312+
// No stacks, no tag.
313+
(None, Tag::Untagged)
314+
};
322315
let mut stacked_borrows = memory_extra.stacked_borrows.as_ref().map(|sb| sb.borrow_mut());
323316
let alloc: Allocation<Tag, Self::AllocExtra> = alloc.with_tags_and_extra(
324317
|alloc| {
@@ -360,14 +353,11 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
360353

361354
#[inline(always)]
362355
fn stack_push(ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx, FrameData<'tcx>> {
363-
let call_id = ecx.memory.extra.stacked_borrows.as_ref().map_or(
364-
NonZeroU64::new(1).unwrap(),
365-
|stacked_borrows| stacked_borrows.borrow_mut().new_call(),
366-
);
367-
Ok(FrameData {
368-
call_id,
369-
catch_panic: None,
370-
})
356+
let stacked_borrows = ecx.memory.extra.stacked_borrows.as_ref();
357+
let call_id = stacked_borrows.map_or(NonZeroU64::new(1).unwrap(), |stacked_borrows| {
358+
stacked_borrows.borrow_mut().new_call()
359+
});
360+
Ok(FrameData { call_id, catch_panic: None })
371361
}
372362

373363
#[inline(always)]

src/operator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
103103
offset: i64,
104104
) -> InterpResult<'tcx, Scalar<Tag>> {
105105
let pointee_size = i64::try_from(self.layout_of(pointee_ty)?.size.bytes()).unwrap();
106-
let offset = offset
107-
.checked_mul(pointee_size)
108-
.ok_or_else(|| err_ub_format!("overflow during offset comutation for inbounds pointer arithmetic"))?;
106+
let offset = offset.checked_mul(pointee_size).ok_or_else(|| {
107+
err_ub_format!("overflow during offset comutation for inbounds pointer arithmetic")
108+
})?;
109109
// We do this first, to rule out overflows.
110110
let offset_ptr = ptr.ptr_signed_offset(offset, self)?;
111111
// What we need to check is that starting at `min(ptr, offset_ptr)`,

src/shims/foreign_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc::ty;
99
use rustc::ty::layout::{Align, Size};
1010
use rustc_apfloat::Float;
1111
use rustc_span::symbol::sym;
12-
use syntax::attr;
12+
use rustc_ast::attr;
1313

1414
use crate::*;
1515

src/stacked_borrows.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use std::fmt;
77
use std::num::NonZeroU64;
88
use std::rc::Rc;
99

10-
use rustc_hir::Mutability;
1110
use rustc::mir::RetagKind;
1211
use rustc::ty::{self, layout::Size};
12+
use rustc_hir::Mutability;
1313

1414
use crate::*;
1515

@@ -293,9 +293,12 @@ impl<'tcx> Stack {
293293
// Two main steps: Find granting item, remove incompatible items above.
294294

295295
// Step 1: Find granting item.
296-
let granting_idx = self.find_granting(access, tag).ok_or_else(|| err_ub!(UbExperimental(
297-
format!("no item granting {} to tag {:?} found in borrow stack.", access, tag),
298-
)))?;
296+
let granting_idx = self.find_granting(access, tag).ok_or_else(|| {
297+
err_ub!(UbExperimental(format!(
298+
"no item granting {} to tag {:?} found in borrow stack.",
299+
access, tag
300+
),))
301+
})?;
299302

300303
// Step 2: Remove incompatible items above them. Make sure we do not remove protected
301304
// items. Behavior differs for reads and writes.
@@ -334,10 +337,12 @@ impl<'tcx> Stack {
334337
/// active protectors at all because we will remove all items.
335338
fn dealloc(&mut self, tag: Tag, global: &GlobalState) -> InterpResult<'tcx> {
336339
// Step 1: Find granting item.
337-
self.find_granting(AccessKind::Write, tag).ok_or_else(|| err_ub!(UbExperimental(format!(
338-
"no item granting write access for deallocation to tag {:?} found in borrow stack",
339-
tag,
340-
))))?;
340+
self.find_granting(AccessKind::Write, tag).ok_or_else(|| {
341+
err_ub!(UbExperimental(format!(
342+
"no item granting write access for deallocation to tag {:?} found in borrow stack",
343+
tag,
344+
)))
345+
})?;
341346

342347
// Step 2: Remove all items. Also checks for protectors.
343348
for item in self.borrows.drain(..).rev() {
@@ -575,7 +580,9 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
575580
// breaking `Rc::from_raw`.
576581
RefKind::Raw { .. } => Tag::Untagged,
577582
// All other pointesr are properly tracked.
578-
_ => Tag::Tagged(this.memory.extra.stacked_borrows.as_ref().unwrap().borrow_mut().new_ptr()),
583+
_ => Tag::Tagged(
584+
this.memory.extra.stacked_borrows.as_ref().unwrap().borrow_mut().new_ptr(),
585+
),
579586
};
580587

581588
// Reborrow.

0 commit comments

Comments
 (0)