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

[beta] backport various PRs #50027

Merged
merged 16 commits into from
Apr 19, 2018
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
3 changes: 2 additions & 1 deletion src/bootstrap/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,8 @@ tool_extended!((self, builder),
target: self.target,
extra_features: Vec::new(),
});
if clippy.is_some() {
let channel = &builder.config.channel;
if clippy.is_some() && channel != "stable" && channel != "beta" {
self.extra_features.push("clippy".to_owned());
}
builder.ensure(native::Openssl {
Expand Down
1 change: 1 addition & 0 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2280,6 +2280,7 @@ bitflags! {
const NAKED = 0b0001_0000;
const NO_MANGLE = 0b0010_0000;
const RUSTC_STD_INTERNAL_SYMBOL = 0b0100_0000;
const NO_DEBUG = 0b1000_0000;
}
}

Expand Down
24 changes: 12 additions & 12 deletions src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,12 @@ impl_stable_hash_for!(struct mir::interpret::MemoryPointer {

enum AllocDiscriminant {
Alloc,
ExternStatic,
Static,
Function,
}
impl_stable_hash_for!(enum self::AllocDiscriminant {
Alloc,
ExternStatic,
Static,
Function
});

Expand All @@ -396,24 +396,25 @@ impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
hasher: &mut StableHasher<W>,
) {
ty::tls::with_opt(|tcx| {
trace!("hashing {:?}", *self);
let tcx = tcx.expect("can't hash AllocIds during hir lowering");
if let Some(alloc) = tcx.interpret_interner.get_alloc(*self) {
if let Some(def_id) = tcx.interpret_interner.get_static(*self) {
AllocDiscriminant::Static.hash_stable(hcx, hasher);
trace!("hashing {:?} as static {:?}", *self, def_id);
def_id.hash_stable(hcx, hasher);
} else if let Some(alloc) = tcx.interpret_interner.get_alloc(*self) {
AllocDiscriminant::Alloc.hash_stable(hcx, hasher);
if hcx.alloc_id_recursion_tracker.insert(*self) {
tcx
.interpret_interner
.get_corresponding_static_def_id(*self)
.hash_stable(hcx, hasher);
trace!("hashing {:?} as alloc {:#?}", *self, alloc);
alloc.hash_stable(hcx, hasher);
assert!(hcx.alloc_id_recursion_tracker.remove(self));
} else {
trace!("skipping hashing of {:?} due to recursion", *self);
}
} else if let Some(inst) = tcx.interpret_interner.get_fn(*self) {
trace!("hashing {:?} as fn {:#?}", *self, inst);
AllocDiscriminant::Function.hash_stable(hcx, hasher);
inst.hash_stable(hcx, hasher);
} else if let Some(def_id) = tcx.interpret_interner
.get_corresponding_static_def_id(*self) {
AllocDiscriminant::ExternStatic.hash_stable(hcx, hasher);
def_id.hash_stable(hcx, hasher);
} else {
bug!("no allocation for {}", self);
}
Expand Down Expand Up @@ -532,7 +533,6 @@ for ::mir::interpret::EvalError<'gcx> {
InvalidPointerMath |
ReadUndefBytes |
DeadLocal |
ExecutionTimeLimitReached |
StackFrameLimitReached |
OutOfTls |
TlsOutOfBounds |
Expand Down
3 changes: 0 additions & 3 deletions src/librustc/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ pub enum EvalErrorKind<'tcx> {
Intrinsic(String),
OverflowingMath,
InvalidChar(u128),
ExecutionTimeLimitReached,
StackFrameLimitReached,
OutOfTls,
TlsOutOfBounds,
Expand Down Expand Up @@ -188,8 +187,6 @@ impl<'tcx> Error for EvalError<'tcx> {
"mir not found",
InvalidChar(..) =>
"tried to interpret an invalid 32-bit value as a char",
ExecutionTimeLimitReached =>
"the expression was too complex to be evaluated or resulted in an infinite loop",
StackFrameLimitReached =>
"reached the configured maximum number of stack frames",
OutOfTls =>
Expand Down
63 changes: 23 additions & 40 deletions src/librustc/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,12 @@ pub struct AllocId(pub u64);
impl ::rustc_serialize::UseSpecializedEncodable for AllocId {}
impl ::rustc_serialize::UseSpecializedDecodable for AllocId {}

pub const ALLOC_DISCRIMINANT: usize = 0;
pub const FN_DISCRIMINANT: usize = 1;
pub const EXTERN_STATIC_DISCRIMINANT: usize = 2;
pub const SHORTHAND_START: usize = 3;
#[derive(RustcDecodable, RustcEncodable)]
enum AllocKind {
Alloc,
Fn,
Static,
}

pub fn specialized_encode_alloc_id<
'a, 'tcx,
Expand All @@ -166,26 +168,18 @@ pub fn specialized_encode_alloc_id<
encoder: &mut E,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
alloc_id: AllocId,
shorthand: Option<usize>,
) -> Result<(), E::Error> {
if let Some(shorthand) = shorthand {
return shorthand.encode(encoder);
}
if let Some(alloc) = tcx.interpret_interner.get_alloc(alloc_id) {
trace!("encoding {:?} with {:#?}", alloc_id, alloc);
ALLOC_DISCRIMINANT.encode(encoder)?;
AllocKind::Alloc.encode(encoder)?;
alloc.encode(encoder)?;
// encode whether this allocation is the root allocation of a static
tcx.interpret_interner
.get_corresponding_static_def_id(alloc_id)
.encode(encoder)?;
} else if let Some(fn_instance) = tcx.interpret_interner.get_fn(alloc_id) {
trace!("encoding {:?} with {:#?}", alloc_id, fn_instance);
FN_DISCRIMINANT.encode(encoder)?;
AllocKind::Fn.encode(encoder)?;
fn_instance.encode(encoder)?;
} else if let Some(did) = tcx.interpret_interner.get_corresponding_static_def_id(alloc_id) {
// extern "C" statics don't have allocations, just encode its def_id
EXTERN_STATIC_DISCRIMINANT.encode(encoder)?;
} else if let Some(did) = tcx.interpret_interner.get_static(alloc_id) {
// referring to statics doesn't need to know about their allocations, just about its DefId
AllocKind::Static.encode(encoder)?;
did.encode(encoder)?;
} else {
bug!("alloc id without corresponding allocation: {}", alloc_id);
Expand All @@ -196,53 +190,42 @@ pub fn specialized_encode_alloc_id<
pub fn specialized_decode_alloc_id<
'a, 'tcx,
D: Decoder,
CACHE: FnOnce(&mut D, usize, AllocId),
SHORT: FnOnce(&mut D, usize) -> Result<AllocId, D::Error>
CACHE: FnOnce(&mut D, AllocId),
>(
decoder: &mut D,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
pos: usize,
cache: CACHE,
short: SHORT,
) -> Result<AllocId, D::Error> {
match usize::decode(decoder)? {
ALLOC_DISCRIMINANT => {
match AllocKind::decode(decoder)? {
AllocKind::Alloc => {
let alloc_id = tcx.interpret_interner.reserve();
trace!("creating alloc id {:?} at {}", alloc_id, pos);
trace!("creating alloc id {:?}", alloc_id);
// insert early to allow recursive allocs
cache(decoder, pos, alloc_id);
cache(decoder, alloc_id);

let allocation = Allocation::decode(decoder)?;
trace!("decoded alloc {:?} {:#?}", alloc_id, allocation);
let allocation = tcx.intern_const_alloc(allocation);
tcx.interpret_interner.intern_at_reserved(alloc_id, allocation);

if let Some(glob) = Option::<DefId>::decode(decoder)? {
tcx.interpret_interner.cache(glob, alloc_id);
}

Ok(alloc_id)
},
FN_DISCRIMINANT => {
trace!("creating fn alloc id at {}", pos);
AllocKind::Fn => {
trace!("creating fn alloc id");
let instance = ty::Instance::decode(decoder)?;
trace!("decoded fn alloc instance: {:?}", instance);
let id = tcx.interpret_interner.create_fn_alloc(instance);
trace!("created fn alloc id: {:?}", id);
cache(decoder, pos, id);
cache(decoder, id);
Ok(id)
},
EXTERN_STATIC_DISCRIMINANT => {
trace!("creating extern static alloc id at {}", pos);
AllocKind::Static => {
trace!("creating extern static alloc id at");
let did = DefId::decode(decoder)?;
let alloc_id = tcx.interpret_interner.reserve();
tcx.interpret_interner.cache(did, alloc_id);
let alloc_id = tcx.interpret_interner.cache_static(did);
cache(decoder, alloc_id);
Ok(alloc_id)
},
shorthand => {
trace!("loading shorthand {}", shorthand);
short(decoder, shorthand)
},
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@ pub struct Session {

/// The maximum number of stackframes allowed in const eval
pub const_eval_stack_frame_limit: Cell<usize>,
/// The maximum number miri steps per constant
pub const_eval_step_limit: Cell<usize>,

/// The metadata::creader module may inject an allocator/panic_runtime
/// dependency if it didn't already find one, and this tracks what was
Expand Down Expand Up @@ -1146,7 +1144,6 @@ pub fn build_session_(
recursion_limit: Cell::new(64),
type_length_limit: Cell::new(1048576),
const_eval_stack_frame_limit: Cell::new(100),
const_eval_step_limit: Cell::new(1_000_000),
next_node_id: Cell::new(NodeId::new(1)),
injected_allocator: Cell::new(None),
allocator_kind: Cell::new(None),
Expand Down
39 changes: 16 additions & 23 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,18 +935,16 @@ struct InterpretInternerInner<'tcx> {
/// Allows obtaining const allocs via a unique identifier
alloc_by_id: FxHashMap<interpret::AllocId, &'tcx interpret::Allocation>,

/// Reverse map of `alloc_cache`
global_cache: FxHashMap<interpret::AllocId, DefId>,
/// Allows obtaining static def ids via a unique id
statics: FxHashMap<interpret::AllocId, DefId>,

/// The AllocId to assign to the next new regular allocation.
/// Always incremented, never gets smaller.
next_id: interpret::AllocId,

/// Allows checking whether a static already has an allocation
///
/// This is only important for detecting statics referring to themselves
// FIXME(oli-obk) move it to the EvalContext?
alloc_cache: FxHashMap<DefId, interpret::AllocId>,
/// Inverse map of `statics`
/// Used so we don't allocate a new pointer every time we need one
static_cache: FxHashMap<DefId, interpret::AllocId>,

/// A cache for basic byte allocations keyed by their contents. This is used to deduplicate
/// allocations for string and bytestring literals.
Expand Down Expand Up @@ -980,30 +978,25 @@ impl<'tcx> InterpretInterner<'tcx> {
self.inner.borrow().alloc_by_id.get(&id).cloned()
}

pub fn get_cached(
&self,
static_id: DefId,
) -> Option<interpret::AllocId> {
self.inner.borrow().alloc_cache.get(&static_id).cloned()
}

pub fn cache(
pub fn cache_static(
&self,
static_id: DefId,
alloc_id: interpret::AllocId,
) {
let mut inner = self.inner.borrow_mut();
inner.global_cache.insert(alloc_id, static_id);
if let Some(old) = inner.alloc_cache.insert(static_id, alloc_id) {
bug!("tried to cache {:?}, but was already existing as {:#?}", static_id, old);
) -> interpret::AllocId {
if let Some(alloc_id) = self.inner.borrow().static_cache.get(&static_id).cloned() {
return alloc_id;
}
let alloc_id = self.reserve();
let mut inner = self.inner.borrow_mut();
inner.static_cache.insert(static_id, alloc_id);
inner.statics.insert(alloc_id, static_id);
alloc_id
}

pub fn get_corresponding_static_def_id(
pub fn get_static(
&self,
ptr: interpret::AllocId,
) -> Option<DefId> {
self.inner.borrow().global_cache.get(&ptr).cloned()
self.inner.borrow().statics.get(&ptr).cloned()
}

pub fn intern_at_reserved(
Expand Down
Loading