Skip to content

Commit

Permalink
Auto merge of rust-lang#53354 - kennytm:rollup, r=kennytm
Browse files Browse the repository at this point in the history
Rollup of 11 pull requests

Successful merges:

 - rust-lang#53112 (pretty print BTreeSet)
 - rust-lang#53208 (Don't panic on std::env::vars() when env is null.)
 - rust-lang#53226 (driver: set the syntax edition in phase 1)
 - rust-lang#53229 (Make sure rlimit is only ever increased)
 - rust-lang#53233 (targets: aarch64: Add bare-metal aarch64 target)
 - rust-lang#53239 (rustc_codegen_llvm: Restore the closure env alloca hack for LLVM 5.)
 - rust-lang#53246 (A few cleanups)
 - rust-lang#53257 (Idiomatic improvements to IP method)
 - rust-lang#53274 (Remove statics field from CodegenCx)
 - rust-lang#53290 (Make LLVM emit assembly comments with -Z asm-comments)
 - rust-lang#53317 (Mark prior failure to avoid ICE)
  • Loading branch information
bors committed Aug 14, 2018
2 parents 23f09bb + 8e7f69a commit a573305
Show file tree
Hide file tree
Showing 32 changed files with 486 additions and 229 deletions.
22 changes: 22 additions & 0 deletions src/etc/debugger_pretty_printers_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
TYPE_KIND_REGULAR_UNION = 17
TYPE_KIND_OS_STRING = 18
TYPE_KIND_STD_VECDEQUE = 19
TYPE_KIND_STD_BTREESET = 20

ENCODED_ENUM_PREFIX = "RUST$ENCODED$ENUM$"
ENUM_DISR_FIELD_NAME = "RUST$ENUM$DISR"
Expand All @@ -71,6 +72,9 @@
STD_VECDEQUE_FIELD_NAME_HEAD,
STD_VECDEQUE_FIELD_NAME_BUF]

# std::collections::BTreeSet<> related constants
STD_BTREESET_FIELD_NAMES = ["map"]

# std::String related constants
STD_STRING_FIELD_NAMES = ["vec"]

Expand Down Expand Up @@ -175,6 +179,11 @@ def __classify_struct(self):
self.__conforms_to_field_layout(STD_VECDEQUE_FIELD_NAMES)):
return TYPE_KIND_STD_VECDEQUE

# STD COLLECTION BTREESET
if (unqualified_type_name.startswith("BTreeSet<") and
self.__conforms_to_field_layout(STD_BTREESET_FIELD_NAMES)):
return TYPE_KIND_STD_BTREESET

# STD STRING
if (unqualified_type_name.startswith("String") and
self.__conforms_to_field_layout(STD_STRING_FIELD_NAMES)):
Expand Down Expand Up @@ -358,6 +367,19 @@ def extract_tail_head_ptr_and_cap_from_std_vecdeque(vec_val):
return (tail, head, data_ptr, capacity)


def extract_length_and_ptr_from_std_btreeset(vec_val):
assert vec_val.type.get_type_kind() == TYPE_KIND_STD_BTREESET
map = vec_val.get_child_at_index(0)
root = map.get_child_at_index(0)
length = map.get_child_at_index(1).as_integer()
node = root.get_child_at_index(0)
ptr = node.get_child_at_index(0)
unique_ptr_val = ptr.get_child_at_index(0)
data_ptr = unique_ptr_val.get_child_at_index(0)
assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR
return (length, data_ptr)


def extract_length_and_ptr_from_slice(slice_val):
assert (slice_val.type.get_type_kind() == TYPE_KIND_SLICE or
slice_val.type.get_type_kind() == TYPE_KIND_STR_SLICE)
Expand Down
26 changes: 26 additions & 0 deletions src/etc/gdb_rust_pretty_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ def rust_pretty_printer_lookup_function(gdb_val):
if type_kind == rustpp.TYPE_KIND_STD_VECDEQUE:
return RustStdVecDequePrinter(val)

if type_kind == rustpp.TYPE_KIND_STD_BTREESET:
return RustStdBTreeSetPrinter(val)

if type_kind == rustpp.TYPE_KIND_STD_STRING:
return RustStdStringPrinter(val)

Expand Down Expand Up @@ -299,6 +302,29 @@ def children(self):
yield (str(index), (gdb_ptr + index).dereference())


class RustStdBTreeSetPrinter(object):
def __init__(self, val):
self.__val = val

@staticmethod
def display_hint():
return "array"

def to_string(self):
(length, data_ptr) = \
rustpp.extract_length_and_ptr_from_std_btreeset(self.__val)
return (self.__val.type.get_unqualified_type_name() +
("(len: %i)" % length))

def children(self):
(length, data_ptr) = \
rustpp.extract_length_and_ptr_from_std_btreeset(self.__val)
val = GdbValue(data_ptr.get_wrapped_value().dereference()).get_child_at_index(3)
gdb_ptr = val.get_wrapped_value()
for index in xrange(length):
yield (str(index), gdb_ptr[index])


class RustStdStringPrinter(object):
def __init__(self, val):
self.__val = val
Expand Down
12 changes: 5 additions & 7 deletions src/libfmt_macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ impl<'a> Parser<'a> {

// fill character
if let Some(&(_, c)) = self.cur.peek() {
match self.cur.clone().skip(1).next() {
match self.cur.clone().nth(1) {
Some((_, '>')) | Some((_, '<')) | Some((_, '^')) => {
spec.fill = Some(c);
self.cur.next();
Expand Down Expand Up @@ -504,13 +504,11 @@ impl<'a> Parser<'a> {
if word.is_empty() {
self.cur = tmp;
CountImplied
} else if self.consume('$') {
CountIsName(word)
} else {
if self.consume('$') {
CountIsName(word)
} else {
self.cur = tmp;
CountImplied
}
self.cur = tmp;
CountImplied
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions src/libgraphviz/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ impl<'a> Id<'a> {
if !name.chars().all(|c| c.is_ascii_alphanumeric() || c == '_' ) {
return Err(());
}
return Ok(Id { name: name });

Ok(Id { name })
}

pub fn as_slice(&'a self) -> &'a str {
Expand Down Expand Up @@ -533,10 +534,10 @@ impl<'a> LabelText<'a> {
/// Renders text as string suitable for a label in a .dot file.
/// This includes quotes or suitable delimiters.
pub fn to_dot_string(&self) -> String {
match self {
&LabelStr(ref s) => format!("\"{}\"", s.escape_default()),
&EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(&s)),
&HtmlStr(ref s) => format!("<{}>", s),
match *self {
LabelStr(ref s) => format!("\"{}\"", s.escape_default()),
EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(&s)),
HtmlStr(ref s) => format!("<{}>", s),
}
}

Expand Down
91 changes: 44 additions & 47 deletions src/librustc_apfloat/ieee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,23 +536,21 @@ impl<S: Semantics> fmt::Display for IeeeFloat<S> {
// Check whether we should use scientific notation.
let scientific = if width == 0 {
true
} else if exp >= 0 {
// 765e3 --> 765000
// ^^^
// But we shouldn't make the number look more precise than it is.
exp as usize > width || digits + exp as usize > precision
} else {
if exp >= 0 {
// 765e3 --> 765000
// ^^^
// But we shouldn't make the number look more precise than it is.
exp as usize > width || digits + exp as usize > precision
// Power of the most significant digit.
let msd = exp + (digits - 1) as ExpInt;
if msd >= 0 {
// 765e-2 == 7.65
false
} else {
// Power of the most significant digit.
let msd = exp + (digits - 1) as ExpInt;
if msd >= 0 {
// 765e-2 == 7.65
false
} else {
// 765e-5 == 0.00765
// ^ ^^
-msd as usize > width
}
// 765e-5 == 0.00765
// ^ ^^
-msd as usize > width
}
};

Expand Down Expand Up @@ -702,7 +700,7 @@ impl<S: Semantics> Float for IeeeFloat<S> {
// exponent = 1..10
// significand = 1..1
IeeeFloat {
sig: [!0 & ((1 << S::PRECISION) - 1)],
sig: [(1 << S::PRECISION) - 1],
exp: S::MAX_EXP,
category: Category::Normal,
sign: false,
Expand Down Expand Up @@ -1507,10 +1505,11 @@ impl<S: Semantics, T: Semantics> FloatConvert<IeeeFloat<T>> for IeeeFloat<S> {
}

// If this is a truncation, perform the shift.
let mut loss = Loss::ExactlyZero;
if shift < 0 && (r.is_finite_non_zero() || r.category == Category::NaN) {
loss = sig::shift_right(&mut r.sig, &mut 0, -shift as usize);
}
let loss = if shift < 0 && (r.is_finite_non_zero() || r.category == Category::NaN) {
sig::shift_right(&mut r.sig, &mut 0, -shift as usize)
} else {
Loss::ExactlyZero
};

// If this is an extension, perform the shift.
if shift > 0 && (r.is_finite_non_zero() || r.category == Category::NaN) {
Expand Down Expand Up @@ -1738,27 +1737,25 @@ impl<S: Semantics> IeeeFloat<S> {
bit_pos -= 4;
if bit_pos >= 0 {
r.sig[0] |= (hex_value as Limb) << bit_pos;
} else {
// If zero or one-half (the hexadecimal digit 8) are followed
// by non-zero, they're a little more than zero or one-half.
if let Some(ref mut loss) = loss {
if hex_value != 0 {
if *loss == Loss::ExactlyZero {
*loss = Loss::LessThanHalf;
}
if *loss == Loss::ExactlyHalf {
*loss = Loss::MoreThanHalf;
}
// If zero or one-half (the hexadecimal digit 8) are followed
// by non-zero, they're a little more than zero or one-half.
} else if let Some(ref mut loss) = loss {
if hex_value != 0 {
if *loss == Loss::ExactlyZero {
*loss = Loss::LessThanHalf;
}
if *loss == Loss::ExactlyHalf {
*loss = Loss::MoreThanHalf;
}
} else {
loss = Some(match hex_value {
0 => Loss::ExactlyZero,
1..=7 => Loss::LessThanHalf,
8 => Loss::ExactlyHalf,
9..=15 => Loss::MoreThanHalf,
_ => unreachable!(),
});
}
} else {
loss = Some(match hex_value {
0 => Loss::ExactlyZero,
1..=7 => Loss::LessThanHalf,
8 => Loss::ExactlyHalf,
9..=15 => Loss::MoreThanHalf,
_ => unreachable!(),
});
}
} else if c == 'p' || c == 'P' {
if !any_digits {
Expand Down Expand Up @@ -2309,9 +2306,9 @@ mod sig {

/// One, not zero, based LSB. That is, returns 0 for a zeroed significand.
pub(super) fn olsb(limbs: &[Limb]) -> usize {
for i in 0..limbs.len() {
if limbs[i] != 0 {
return i * LIMB_BITS + limbs[i].trailing_zeros() as usize + 1;
for (i, &limb) in limbs.iter().enumerate() {
if limb != 0 {
return i * LIMB_BITS + limb.trailing_zeros() as usize + 1;
}
}

Expand All @@ -2320,9 +2317,9 @@ mod sig {

/// One, not zero, based MSB. That is, returns 0 for a zeroed significand.
pub(super) fn omsb(limbs: &[Limb]) -> usize {
for i in (0..limbs.len()).rev() {
if limbs[i] != 0 {
return (i + 1) * LIMB_BITS - limbs[i].leading_zeros() as usize;
for (i, &limb) in limbs.iter().enumerate().rev() {
if limb != 0 {
return (i + 1) * LIMB_BITS - limb.leading_zeros() as usize;
}
}

Expand Down Expand Up @@ -2378,7 +2375,7 @@ mod sig {
limb = dst[i - jump];
if shift > 0 {
limb <<= shift;
if i >= jump + 1 {
if i > jump {
limb |= dst[i - jump - 1] >> (LIMB_BITS - shift);
}
}
Expand Down Expand Up @@ -2448,7 +2445,7 @@ mod sig {
let n = dst_limbs * LIMB_BITS - shift;
if n < src_bits {
let mask = (1 << (src_bits - n)) - 1;
dst[dst_limbs - 1] |= (src[dst_limbs] & mask) << n % LIMB_BITS;
dst[dst_limbs - 1] |= (src[dst_limbs] & mask) << (n % LIMB_BITS);
} else if n > src_bits && src_bits % LIMB_BITS > 0 {
dst[dst_limbs - 1] &= (1 << (src_bits % LIMB_BITS)) - 1;
}
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ pub fn target_machine_factory(sess: &Session, find_features: bool)
let is_pie_binary = !find_features && is_pie_binary(sess);
let trap_unreachable = sess.target.target.options.trap_unreachable;

let asm_comments = sess.asm_comments();

Arc::new(move || {
let tm = unsafe {
llvm::LLVMRustCreateTargetMachine(
Expand All @@ -193,6 +195,7 @@ pub fn target_machine_factory(sess: &Session, find_features: bool)
fdata_sections,
trap_unreachable,
singlethread,
asm_comments,
)
};

Expand Down
1 change: 0 additions & 1 deletion src/librustc_codegen_llvm/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ pub fn get_static(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll Value {
}

cx.instances.borrow_mut().insert(instance, g);
cx.statics.borrow_mut().insert(g, def_id);
g
}

Expand Down
5 changes: 0 additions & 5 deletions src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use common;
use llvm;
use rustc::dep_graph::DepGraphSafe;
use rustc::hir;
use rustc::hir::def_id::DefId;
use debuginfo;
use callee;
use base;
Expand Down Expand Up @@ -78,9 +77,6 @@ pub struct CodegenCx<'a, 'tcx: 'a> {
/// Cache of emitted const globals (value -> global)
pub const_globals: RefCell<FxHashMap<&'a Value, &'a Value>>,

/// Mapping from static definitions to their DefId's.
pub statics: RefCell<FxHashMap<&'a Value, DefId>>,

/// List of globals for static variables which need to be passed to the
/// LLVM function ReplaceAllUsesWith (RAUW) when codegen is complete.
/// (We have to make sure we don't invalidate any Values referring
Expand Down Expand Up @@ -297,7 +293,6 @@ impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
const_cstr_cache: RefCell::new(FxHashMap()),
const_unsized: RefCell::new(FxHashMap()),
const_globals: RefCell::new(FxHashMap()),
statics: RefCell::new(FxHashMap()),
statics_to_rauw: RefCell::new(Vec::new()),
used_statics: RefCell::new(Vec::new()),
lltypes: RefCell::new(FxHashMap()),
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_codegen_llvm/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,8 @@ extern "C" {
FunctionSections: bool,
DataSections: bool,
TrapUnreachable: bool,
Singlethread: bool)
Singlethread: bool,
AsmComments: bool)
-> Option<&'static mut TargetMachine>;
pub fn LLVMRustDisposeTargetMachine(T: &'static mut TargetMachine);
pub fn LLVMRustAddAnalysisPasses(T: &'a TargetMachine, PM: &PassManager<'a>, M: &'a Module);
Expand Down
Loading

0 comments on commit a573305

Please sign in to comment.