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 7 pull requests #67111

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c874789
remove dependency from libhermit
stlankes Nov 25, 2019
e4b2cb8
Add support for RISC-V 64-bit GNU/Linux
msizanoen1 Nov 23, 2019
930a0a2
Update libc
msizanoen1 Nov 30, 2019
a725a15
Miri core engine: use throw_ub instead of throw_panic
RalfJung Dec 1, 2019
15f159a
fix compile-fail tests
RalfJung Dec 1, 2019
c0e78d6
Create new types.rs file
GuillaumeGomez Dec 3, 2019
72fdce2
remove code that doesn't belong in clean/mod.rs anymore
GuillaumeGomez Dec 3, 2019
d84eb50
Fix TypedArena.
cjgillot Dec 3, 2019
81e549c
remove code that doesn't belong in clean/types.rs
GuillaumeGomez Dec 3, 2019
db0e6cd
fixup clean/types.rs imports
GuillaumeGomez Dec 3, 2019
91e021a
Make some private methods public
GuillaumeGomez Dec 3, 2019
f5e0d0c
Make some formatting improvements
GuillaumeGomez Dec 3, 2019
e14eebb
Make Lifetime struct field public
GuillaumeGomez Dec 3, 2019
12a2671
Remove unused constant
GuillaumeGomez Dec 3, 2019
756aa1e
rustc: Apply clearer naming to BodyAndCache, fix Deref impl, remove u…
Nashenas88 Dec 3, 2019
9a21f6e
rustc_mir: Fix tidy line lengths
Nashenas88 Dec 3, 2019
a5e144b
rustc_codegen_ssa: Fix line accidentally reverted during rebase
Nashenas88 Dec 5, 2019
0f306a7
Do not ICE on async fn with non-Copy infered type arg
estebank Dec 3, 2019
7ed9066
review comments
estebank Dec 5, 2019
183375f
Rollup merge of #66730 - hermitcore:master, r=alexcrichton
Centril Dec 7, 2019
296ecab
Rollup merge of #66899 - msizanoen1:riscv-std, r=alexcrichton
Centril Dec 7, 2019
eceacd2
Rollup merge of #66927 - RalfJung:engines-dont-panic, r=oli-obk
Centril Dec 7, 2019
1f029e7
Rollup merge of #66984 - GuillaumeGomez:move-clean-types, r=kinnison
Centril Dec 7, 2019
40e367f
Rollup merge of #66991 - Nashenas88:body_cache_cleanup, r=eddyb
Centril Dec 7, 2019
b8ab423
Rollup merge of #67003 - cjgillot:corrida, r=Mark-Simulacrum
Centril Dec 7, 2019
6c2232d
Rollup merge of #67004 - estebank:issue-66958, r=eddyb
Centril Dec 7, 2019
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
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1823,9 +1823,9 @@ checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"

[[package]]
name = "libc"
version = "0.2.64"
version = "0.2.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74dfca3d9957906e8d1e6a0b641dc9a59848e793f1da2165889fd4f62d10d79c"
checksum = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
dependencies = [
"rustc-std-workspace-core",
]
Expand Down
59 changes: 12 additions & 47 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,53 +202,18 @@ impl<T> TypedArena<T> {
#[inline]
pub fn alloc_from_iter<I: IntoIterator<Item = T>>(&self, iter: I) -> &mut [T] {
assert!(mem::size_of::<T>() != 0);
let mut iter = iter.into_iter();
let size_hint = iter.size_hint();

match size_hint {
(min, Some(max)) if min == max => {
// We know the exact number of elements the iterator will produce here
let len = min;

if len == 0 {
return &mut [];
}

self.ensure_capacity(len);

let slice = self.ptr.get();

unsafe {
let mut ptr = self.ptr.get();
for _ in 0..len {
// Write into uninitialized memory.
ptr::write(ptr, iter.next().unwrap());
// Advance the pointer.
ptr = ptr.offset(1);
// Update the pointer per iteration so if `iter.next()` panics
// we destroy the correct amount
self.ptr.set(ptr);
}
slice::from_raw_parts_mut(slice, len)
}
}
_ => {
cold_path(move || -> &mut [T] {
let mut vec: SmallVec<[_; 8]> = iter.collect();
if vec.is_empty() {
return &mut [];
}
// Move the content to the arena by copying it and then forgetting
// the content of the SmallVec
unsafe {
let len = vec.len();
let start_ptr = self.alloc_raw_slice(len);
vec.as_ptr().copy_to_nonoverlapping(start_ptr, len);
vec.set_len(0);
slice::from_raw_parts_mut(start_ptr, len)
}
})
}
let mut vec: SmallVec<[_; 8]> = iter.into_iter().collect();
if vec.is_empty() {
return &mut [];
}
// Move the content to the arena by copying it and then forgetting
// the content of the SmallVec
unsafe {
let len = vec.len();
let start_ptr = self.alloc_raw_slice(len);
vec.as_ptr().copy_to_nonoverlapping(start_ptr, len);
vec.set_len(0);
slice::from_raw_parts_mut(start_ptr, len)
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/libpanic_unwind/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ const UNWIND_DATA_REG: (i32, i32) = (24, 25); // I0, I1
#[cfg(target_arch = "hexagon")]
const UNWIND_DATA_REG: (i32, i32) = (0, 1); // R0, R1

#[cfg(target_arch = "riscv64")]
const UNWIND_DATA_REG: (i32, i32) = (10, 11); // x10, x11

// The following code is based on GCC's C and C++ personality routines. For reference, see:
// https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/libsupc++/eh_personality.cc
// https://github.com/gcc-mirror/gcc/blob/trunk/libgcc/unwind-c.c
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ macro_rules! arena_types {
[] generics: rustc::ty::Generics,
[] trait_def: rustc::ty::TraitDef,
[] adt_def: rustc::ty::AdtDef,
[] steal_mir: rustc::ty::steal::Steal<rustc::mir::BodyCache<$tcx>>,
[] mir: rustc::mir::BodyCache<$tcx>,
[] steal_mir: rustc::ty::steal::Steal<rustc::mir::BodyAndCache<$tcx>>,
[] mir: rustc::mir::BodyAndCache<$tcx>,
[] steal_promoted: rustc::ty::steal::Steal<
rustc_index::vec::IndexVec<
rustc::mir::Promoted,
rustc::mir::BodyCache<$tcx>
rustc::mir::BodyAndCache<$tcx>
>
>,
[] promoted: rustc_index::vec::IndexVec<
rustc::mir::Promoted,
rustc::mir::BodyCache<$tcx>
rustc::mir::BodyAndCache<$tcx>
>,
[] tables: rustc::ty::TypeckTables<$tcx>,
[] const_allocs: rustc::mir::interpret::Allocation,
Expand Down
54 changes: 25 additions & 29 deletions src/librustc/mir/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ impl Cache {
}

#[derive(Clone, Debug, HashStable, RustcEncodable, RustcDecodable, TypeFoldable)]
pub struct BodyCache<'tcx> {
cache: Cache,
pub struct BodyAndCache<'tcx> {
body: Body<'tcx>,
cache: Cache,
}

impl BodyCache<'tcx> {
impl BodyAndCache<'tcx> {
pub fn new(body: Body<'tcx>) -> Self {
Self {
cache: Cache::new(),
body,
cache: Cache::new(),
}
}
}
Expand All @@ -139,7 +139,7 @@ macro_rules! read_only {
};
}

impl BodyCache<'tcx> {
impl BodyAndCache<'tcx> {
pub fn ensure_predecessors(&mut self) {
self.cache.ensure_predecessors(&self.body);
}
Expand All @@ -148,8 +148,8 @@ impl BodyCache<'tcx> {
self.cache.predecessors(&self.body)
}

pub fn unwrap_read_only(&self) -> ReadOnlyBodyCache<'_, 'tcx> {
ReadOnlyBodyCache::new(&self.cache, &self.body)
pub fn unwrap_read_only(&self) -> ReadOnlyBodyAndCache<'_, 'tcx> {
ReadOnlyBodyAndCache::new(&self.body, &self.cache)
}

pub fn basic_blocks_mut(&mut self) -> &mut IndexVec<BasicBlock, BasicBlockData<'tcx>> {
Expand All @@ -163,48 +163,48 @@ impl BodyCache<'tcx> {
}
}

impl<'tcx> Index<BasicBlock> for BodyCache<'tcx> {
impl<'tcx> Index<BasicBlock> for BodyAndCache<'tcx> {
type Output = BasicBlockData<'tcx>;

fn index(&self, index: BasicBlock) -> &BasicBlockData<'tcx> {
&self.body[index]
}
}

impl<'tcx> IndexMut<BasicBlock> for BodyCache<'tcx> {
impl<'tcx> IndexMut<BasicBlock> for BodyAndCache<'tcx> {
fn index_mut(&mut self, index: BasicBlock) -> &mut Self::Output {
&mut self.basic_blocks_mut()[index]
}
}

impl<'tcx> Deref for BodyCache<'tcx> {
impl<'tcx> Deref for BodyAndCache<'tcx> {
type Target = Body<'tcx>;

fn deref(&self) -> &Self::Target {
&self.body
}
}

impl<'tcx> DerefMut for BodyCache<'tcx> {
impl<'tcx> DerefMut for BodyAndCache<'tcx> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.body
}
}

#[derive(Copy, Clone, Debug)]
pub struct ReadOnlyBodyCache<'a, 'tcx> {
cache: &'a Cache,
pub struct ReadOnlyBodyAndCache<'a, 'tcx> {
body: &'a Body<'tcx>,
cache: &'a Cache,
}

impl ReadOnlyBodyCache<'a, 'tcx> {
fn new(cache: &'a Cache, body: &'a Body<'tcx>) -> Self {
impl ReadOnlyBodyAndCache<'a, 'tcx> {
fn new(body: &'a Body<'tcx>, cache: &'a Cache) -> Self {
assert!(
cache.predecessors.is_some(),
"Cannot construct ReadOnlyBodyCache without computed predecessors");
"Cannot construct ReadOnlyBodyAndCache without computed predecessors");
Self {
cache,
body,
cache,
}
}

Expand All @@ -220,10 +220,6 @@ impl ReadOnlyBodyCache<'a, 'tcx> {
self.cache.unwrap_predecessor_locations(loc, self.body)
}

pub fn body(&self) -> &'a Body<'tcx> {
self.body
}

pub fn basic_blocks(&self) -> &IndexVec<BasicBlock, BasicBlockData<'tcx>> {
&self.body.basic_blocks
}
Expand All @@ -233,16 +229,16 @@ impl ReadOnlyBodyCache<'a, 'tcx> {
}
}

impl graph::DirectedGraph for ReadOnlyBodyCache<'a, 'tcx> {
impl graph::DirectedGraph for ReadOnlyBodyAndCache<'a, 'tcx> {
type Node = BasicBlock;
}

impl graph::GraphPredecessors<'graph> for ReadOnlyBodyCache<'a, 'tcx> {
impl graph::GraphPredecessors<'graph> for ReadOnlyBodyAndCache<'a, 'tcx> {
type Item = BasicBlock;
type Iter = IntoIter<BasicBlock>;
}

impl graph::WithPredecessors for ReadOnlyBodyCache<'a, 'tcx> {
impl graph::WithPredecessors for ReadOnlyBodyAndCache<'a, 'tcx> {
fn predecessors(
&self,
node: Self::Node,
Expand All @@ -251,19 +247,19 @@ impl graph::WithPredecessors for ReadOnlyBodyCache<'a, 'tcx> {
}
}

impl graph::WithNumNodes for ReadOnlyBodyCache<'a, 'tcx> {
impl graph::WithNumNodes for ReadOnlyBodyAndCache<'a, 'tcx> {
fn num_nodes(&self) -> usize {
self.body.num_nodes()
}
}

impl graph::WithStartNode for ReadOnlyBodyCache<'a, 'tcx> {
impl graph::WithStartNode for ReadOnlyBodyAndCache<'a, 'tcx> {
fn start_node(&self) -> Self::Node {
self.body.start_node()
}
}

impl graph::WithSuccessors for ReadOnlyBodyCache<'a, 'tcx> {
impl graph::WithSuccessors for ReadOnlyBodyAndCache<'a, 'tcx> {
fn successors(
&self,
node: Self::Node,
Expand All @@ -272,13 +268,13 @@ impl graph::WithSuccessors for ReadOnlyBodyCache<'a, 'tcx> {
}
}

impl<'a, 'b, 'tcx> graph::GraphSuccessors<'b> for ReadOnlyBodyCache<'a, 'tcx> {
impl<'a, 'b, 'tcx> graph::GraphSuccessors<'b> for ReadOnlyBodyAndCache<'a, 'tcx> {
type Item = BasicBlock;
type Iter = iter::Cloned<Successors<'b>>;
}


impl Deref for ReadOnlyBodyCache<'a, 'tcx> {
impl Deref for ReadOnlyBodyAndCache<'a, 'tcx> {
type Target = &'a Body<'tcx>;

fn deref(&self) -> &Self::Target {
Expand Down
21 changes: 19 additions & 2 deletions src/librustc/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,14 @@ pub enum UndefinedBehaviorInfo {
Unreachable,
/// An enum discriminant was set to a value which was outside the range of valid values.
InvalidDiscriminant(ScalarMaybeUndef),
/// A slice/array index projection went out-of-bounds.
BoundsCheckFailed { len: u64, index: u64 },
/// Something was divided by 0 (x / 0).
DivisionByZero,
/// Something was "remainded" by 0 (x % 0).
RemainderByZero,
/// Overflowing inbounds pointer arithmetic.
PointerArithOverflow,
}

impl fmt::Debug for UndefinedBehaviorInfo {
Expand All @@ -379,9 +387,18 @@ impl fmt::Debug for UndefinedBehaviorInfo {
Ub(msg) | UbExperimental(msg) =>
write!(f, "{}", msg),
Unreachable =>
write!(f, "entered unreachable code"),
write!(f, "entering unreachable code"),
InvalidDiscriminant(val) =>
write!(f, "encountered invalid enum discriminant {}", val),
write!(f, "encountering invalid enum discriminant {}", val),
BoundsCheckFailed { ref len, ref index } =>
write!(f, "indexing out of bounds: the len is {:?} but the index is {:?}",
len, index),
DivisionByZero =>
write!(f, "dividing by zero"),
RemainderByZero =>
write!(f, "calculating the remainder with a divisor of zero"),
PointerArithOverflow =>
write!(f, "overflowing in-bounds pointer arithmetic"),
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/mir/interpret/pointer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::{AllocId, InterpResult};

use crate::mir;
use crate::ty::layout::{self, HasDataLayout, Size};

use rustc_macros::HashStable;
Expand Down Expand Up @@ -88,13 +87,13 @@ pub trait PointerArithmetic: layout::HasDataLayout {
#[inline]
fn offset<'tcx>(&self, val: u64, i: u64) -> InterpResult<'tcx, u64> {
let (res, over) = self.overflowing_offset(val, i);
if over { throw_panic!(Overflow(mir::BinOp::Add)) } else { Ok(res) }
if over { throw_ub!(PointerArithOverflow) } else { Ok(res) }
}

#[inline]
fn signed_offset<'tcx>(&self, val: u64, i: i64) -> InterpResult<'tcx, u64> {
let (res, over) = self.overflowing_signed_offset(val, i128::from(i));
if over { throw_panic!(Overflow(mir::BinOp::Add)) } else { Ok(res) }
if over { throw_ub!(PointerArithOverflow) } else { Ok(res) }
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use syntax::symbol::Symbol;
use syntax_pos::{Span, DUMMY_SP};

pub use crate::mir::interpret::AssertMessage;
pub use crate::mir::cache::{BodyCache, ReadOnlyBodyCache};
pub use crate::mir::cache::{BodyAndCache, ReadOnlyBodyAndCache};
pub use crate::read_only;

mod cache;
Expand Down Expand Up @@ -108,7 +108,7 @@ pub struct Body<'tcx> {
pub yield_ty: Option<Ty<'tcx>>,

/// Generator drop glue.
pub generator_drop: Option<Box<BodyCache<'tcx>>>,
pub generator_drop: Option<Box<BodyAndCache<'tcx>>>,

/// The layout of a generator. Produced by the state transformation.
pub generator_layout: Option<GeneratorLayout<'tcx>>,
Expand Down Expand Up @@ -2597,7 +2597,7 @@ impl Location {
pub fn is_predecessor_of<'tcx>(
&self,
other: Location,
body: ReadOnlyBodyCache<'_, 'tcx>
body: ReadOnlyBodyAndCache<'_, 'tcx>
) -> bool {
// If we are in the same block as the other location and are an earlier statement
// then we are a predecessor of `other`.
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ use syntax_pos::Span;

macro_rules! body_cache_type {
(mut $a:lifetime, $tcx:lifetime) => {
&mut BodyCache<$tcx>
&mut BodyAndCache<$tcx>
};
($a:lifetime, $tcx:lifetime) => {
ReadOnlyBodyCache<$a, $tcx>
ReadOnlyBodyAndCache<$a, $tcx>
};
}

Expand Down
Loading