Skip to content

Commit a573305

Browse files
committed
Auto merge of #53354 - kennytm:rollup, r=kennytm
Rollup of 11 pull requests Successful merges: - #53112 (pretty print BTreeSet) - #53208 (Don't panic on std::env::vars() when env is null.) - #53226 (driver: set the syntax edition in phase 1) - #53229 (Make sure rlimit is only ever increased) - #53233 (targets: aarch64: Add bare-metal aarch64 target) - #53239 (rustc_codegen_llvm: Restore the closure env alloca hack for LLVM 5.) - #53246 (A few cleanups) - #53257 (Idiomatic improvements to IP method) - #53274 (Remove statics field from CodegenCx) - #53290 (Make LLVM emit assembly comments with -Z asm-comments) - #53317 (Mark prior failure to avoid ICE)
2 parents 23f09bb + 8e7f69a commit a573305

File tree

32 files changed

+486
-229
lines changed

32 files changed

+486
-229
lines changed

src/etc/debugger_pretty_printers_common.py

+22
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
TYPE_KIND_REGULAR_UNION = 17
4949
TYPE_KIND_OS_STRING = 18
5050
TYPE_KIND_STD_VECDEQUE = 19
51+
TYPE_KIND_STD_BTREESET = 20
5152

5253
ENCODED_ENUM_PREFIX = "RUST$ENCODED$ENUM$"
5354
ENUM_DISR_FIELD_NAME = "RUST$ENUM$DISR"
@@ -71,6 +72,9 @@
7172
STD_VECDEQUE_FIELD_NAME_HEAD,
7273
STD_VECDEQUE_FIELD_NAME_BUF]
7374

75+
# std::collections::BTreeSet<> related constants
76+
STD_BTREESET_FIELD_NAMES = ["map"]
77+
7478
# std::String related constants
7579
STD_STRING_FIELD_NAMES = ["vec"]
7680

@@ -175,6 +179,11 @@ def __classify_struct(self):
175179
self.__conforms_to_field_layout(STD_VECDEQUE_FIELD_NAMES)):
176180
return TYPE_KIND_STD_VECDEQUE
177181

182+
# STD COLLECTION BTREESET
183+
if (unqualified_type_name.startswith("BTreeSet<") and
184+
self.__conforms_to_field_layout(STD_BTREESET_FIELD_NAMES)):
185+
return TYPE_KIND_STD_BTREESET
186+
178187
# STD STRING
179188
if (unqualified_type_name.startswith("String") and
180189
self.__conforms_to_field_layout(STD_STRING_FIELD_NAMES)):
@@ -358,6 +367,19 @@ def extract_tail_head_ptr_and_cap_from_std_vecdeque(vec_val):
358367
return (tail, head, data_ptr, capacity)
359368

360369

370+
def extract_length_and_ptr_from_std_btreeset(vec_val):
371+
assert vec_val.type.get_type_kind() == TYPE_KIND_STD_BTREESET
372+
map = vec_val.get_child_at_index(0)
373+
root = map.get_child_at_index(0)
374+
length = map.get_child_at_index(1).as_integer()
375+
node = root.get_child_at_index(0)
376+
ptr = node.get_child_at_index(0)
377+
unique_ptr_val = ptr.get_child_at_index(0)
378+
data_ptr = unique_ptr_val.get_child_at_index(0)
379+
assert data_ptr.type.get_dwarf_type_kind() == DWARF_TYPE_CODE_PTR
380+
return (length, data_ptr)
381+
382+
361383
def extract_length_and_ptr_from_slice(slice_val):
362384
assert (slice_val.type.get_type_kind() == TYPE_KIND_SLICE or
363385
slice_val.type.get_type_kind() == TYPE_KIND_STR_SLICE)

src/etc/gdb_rust_pretty_printing.py

+26
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ def rust_pretty_printer_lookup_function(gdb_val):
127127
if type_kind == rustpp.TYPE_KIND_STD_VECDEQUE:
128128
return RustStdVecDequePrinter(val)
129129

130+
if type_kind == rustpp.TYPE_KIND_STD_BTREESET:
131+
return RustStdBTreeSetPrinter(val)
132+
130133
if type_kind == rustpp.TYPE_KIND_STD_STRING:
131134
return RustStdStringPrinter(val)
132135

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

301304

305+
class RustStdBTreeSetPrinter(object):
306+
def __init__(self, val):
307+
self.__val = val
308+
309+
@staticmethod
310+
def display_hint():
311+
return "array"
312+
313+
def to_string(self):
314+
(length, data_ptr) = \
315+
rustpp.extract_length_and_ptr_from_std_btreeset(self.__val)
316+
return (self.__val.type.get_unqualified_type_name() +
317+
("(len: %i)" % length))
318+
319+
def children(self):
320+
(length, data_ptr) = \
321+
rustpp.extract_length_and_ptr_from_std_btreeset(self.__val)
322+
val = GdbValue(data_ptr.get_wrapped_value().dereference()).get_child_at_index(3)
323+
gdb_ptr = val.get_wrapped_value()
324+
for index in xrange(length):
325+
yield (str(index), gdb_ptr[index])
326+
327+
302328
class RustStdStringPrinter(object):
303329
def __init__(self, val):
304330
self.__val = val

src/libfmt_macros/lib.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ impl<'a> Parser<'a> {
411411

412412
// fill character
413413
if let Some(&(_, c)) = self.cur.peek() {
414-
match self.cur.clone().skip(1).next() {
414+
match self.cur.clone().nth(1) {
415415
Some((_, '>')) | Some((_, '<')) | Some((_, '^')) => {
416416
spec.fill = Some(c);
417417
self.cur.next();
@@ -504,13 +504,11 @@ impl<'a> Parser<'a> {
504504
if word.is_empty() {
505505
self.cur = tmp;
506506
CountImplied
507+
} else if self.consume('$') {
508+
CountIsName(word)
507509
} else {
508-
if self.consume('$') {
509-
CountIsName(word)
510-
} else {
511-
self.cur = tmp;
512-
CountImplied
513-
}
510+
self.cur = tmp;
511+
CountImplied
514512
}
515513
}
516514
}

src/libgraphviz/lib.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@ impl<'a> Id<'a> {
420420
if !name.chars().all(|c| c.is_ascii_alphanumeric() || c == '_' ) {
421421
return Err(());
422422
}
423-
return Ok(Id { name: name });
423+
424+
Ok(Id { name })
424425
}
425426

426427
pub fn as_slice(&'a self) -> &'a str {
@@ -533,10 +534,10 @@ impl<'a> LabelText<'a> {
533534
/// Renders text as string suitable for a label in a .dot file.
534535
/// This includes quotes or suitable delimiters.
535536
pub fn to_dot_string(&self) -> String {
536-
match self {
537-
&LabelStr(ref s) => format!("\"{}\"", s.escape_default()),
538-
&EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(&s)),
539-
&HtmlStr(ref s) => format!("<{}>", s),
537+
match *self {
538+
LabelStr(ref s) => format!("\"{}\"", s.escape_default()),
539+
EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(&s)),
540+
HtmlStr(ref s) => format!("<{}>", s),
540541
}
541542
}
542543

src/librustc_apfloat/ieee.rs

+44-47
Original file line numberDiff line numberDiff line change
@@ -536,23 +536,21 @@ impl<S: Semantics> fmt::Display for IeeeFloat<S> {
536536
// Check whether we should use scientific notation.
537537
let scientific = if width == 0 {
538538
true
539+
} else if exp >= 0 {
540+
// 765e3 --> 765000
541+
// ^^^
542+
// But we shouldn't make the number look more precise than it is.
543+
exp as usize > width || digits + exp as usize > precision
539544
} else {
540-
if exp >= 0 {
541-
// 765e3 --> 765000
542-
// ^^^
543-
// But we shouldn't make the number look more precise than it is.
544-
exp as usize > width || digits + exp as usize > precision
545+
// Power of the most significant digit.
546+
let msd = exp + (digits - 1) as ExpInt;
547+
if msd >= 0 {
548+
// 765e-2 == 7.65
549+
false
545550
} else {
546-
// Power of the most significant digit.
547-
let msd = exp + (digits - 1) as ExpInt;
548-
if msd >= 0 {
549-
// 765e-2 == 7.65
550-
false
551-
} else {
552-
// 765e-5 == 0.00765
553-
// ^ ^^
554-
-msd as usize > width
555-
}
551+
// 765e-5 == 0.00765
552+
// ^ ^^
553+
-msd as usize > width
556554
}
557555
};
558556

@@ -702,7 +700,7 @@ impl<S: Semantics> Float for IeeeFloat<S> {
702700
// exponent = 1..10
703701
// significand = 1..1
704702
IeeeFloat {
705-
sig: [!0 & ((1 << S::PRECISION) - 1)],
703+
sig: [(1 << S::PRECISION) - 1],
706704
exp: S::MAX_EXP,
707705
category: Category::Normal,
708706
sign: false,
@@ -1507,10 +1505,11 @@ impl<S: Semantics, T: Semantics> FloatConvert<IeeeFloat<T>> for IeeeFloat<S> {
15071505
}
15081506

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

15151514
// If this is an extension, perform the shift.
15161515
if shift > 0 && (r.is_finite_non_zero() || r.category == Category::NaN) {
@@ -1738,27 +1737,25 @@ impl<S: Semantics> IeeeFloat<S> {
17381737
bit_pos -= 4;
17391738
if bit_pos >= 0 {
17401739
r.sig[0] |= (hex_value as Limb) << bit_pos;
1741-
} else {
1742-
// If zero or one-half (the hexadecimal digit 8) are followed
1743-
// by non-zero, they're a little more than zero or one-half.
1744-
if let Some(ref mut loss) = loss {
1745-
if hex_value != 0 {
1746-
if *loss == Loss::ExactlyZero {
1747-
*loss = Loss::LessThanHalf;
1748-
}
1749-
if *loss == Loss::ExactlyHalf {
1750-
*loss = Loss::MoreThanHalf;
1751-
}
1740+
// If zero or one-half (the hexadecimal digit 8) are followed
1741+
// by non-zero, they're a little more than zero or one-half.
1742+
} else if let Some(ref mut loss) = loss {
1743+
if hex_value != 0 {
1744+
if *loss == Loss::ExactlyZero {
1745+
*loss = Loss::LessThanHalf;
1746+
}
1747+
if *loss == Loss::ExactlyHalf {
1748+
*loss = Loss::MoreThanHalf;
17521749
}
1753-
} else {
1754-
loss = Some(match hex_value {
1755-
0 => Loss::ExactlyZero,
1756-
1..=7 => Loss::LessThanHalf,
1757-
8 => Loss::ExactlyHalf,
1758-
9..=15 => Loss::MoreThanHalf,
1759-
_ => unreachable!(),
1760-
});
17611750
}
1751+
} else {
1752+
loss = Some(match hex_value {
1753+
0 => Loss::ExactlyZero,
1754+
1..=7 => Loss::LessThanHalf,
1755+
8 => Loss::ExactlyHalf,
1756+
9..=15 => Loss::MoreThanHalf,
1757+
_ => unreachable!(),
1758+
});
17621759
}
17631760
} else if c == 'p' || c == 'P' {
17641761
if !any_digits {
@@ -2309,9 +2306,9 @@ mod sig {
23092306

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

@@ -2320,9 +2317,9 @@ mod sig {
23202317

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

@@ -2378,7 +2375,7 @@ mod sig {
23782375
limb = dst[i - jump];
23792376
if shift > 0 {
23802377
limb <<= shift;
2381-
if i >= jump + 1 {
2378+
if i > jump {
23822379
limb |= dst[i - jump - 1] >> (LIMB_BITS - shift);
23832380
}
23842381
}
@@ -2448,7 +2445,7 @@ mod sig {
24482445
let n = dst_limbs * LIMB_BITS - shift;
24492446
if n < src_bits {
24502447
let mask = (1 << (src_bits - n)) - 1;
2451-
dst[dst_limbs - 1] |= (src[dst_limbs] & mask) << n % LIMB_BITS;
2448+
dst[dst_limbs - 1] |= (src[dst_limbs] & mask) << (n % LIMB_BITS);
24522449
} else if n > src_bits && src_bits % LIMB_BITS > 0 {
24532450
dst[dst_limbs - 1] &= (1 << (src_bits % LIMB_BITS)) - 1;
24542451
}

src/librustc_codegen_llvm/back/write.rs

+3
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ pub fn target_machine_factory(sess: &Session, find_features: bool)
180180
let is_pie_binary = !find_features && is_pie_binary(sess);
181181
let trap_unreachable = sess.target.target.options.trap_unreachable;
182182

183+
let asm_comments = sess.asm_comments();
184+
183185
Arc::new(move || {
184186
let tm = unsafe {
185187
llvm::LLVMRustCreateTargetMachine(
@@ -193,6 +195,7 @@ pub fn target_machine_factory(sess: &Session, find_features: bool)
193195
fdata_sections,
194196
trap_unreachable,
195197
singlethread,
198+
asm_comments,
196199
)
197200
};
198201

src/librustc_codegen_llvm/consts.rs

-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ pub fn get_static(cx: &CodegenCx<'ll, '_>, def_id: DefId) -> &'ll Value {
230230
}
231231

232232
cx.instances.borrow_mut().insert(instance, g);
233-
cx.statics.borrow_mut().insert(g, def_id);
234233
g
235234
}
236235

src/librustc_codegen_llvm/context.rs

-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use common;
1313
use llvm;
1414
use rustc::dep_graph::DepGraphSafe;
1515
use rustc::hir;
16-
use rustc::hir::def_id::DefId;
1716
use debuginfo;
1817
use callee;
1918
use base;
@@ -78,9 +77,6 @@ pub struct CodegenCx<'a, 'tcx: 'a> {
7877
/// Cache of emitted const globals (value -> global)
7978
pub const_globals: RefCell<FxHashMap<&'a Value, &'a Value>>,
8079

81-
/// Mapping from static definitions to their DefId's.
82-
pub statics: RefCell<FxHashMap<&'a Value, DefId>>,
83-
8480
/// List of globals for static variables which need to be passed to the
8581
/// LLVM function ReplaceAllUsesWith (RAUW) when codegen is complete.
8682
/// (We have to make sure we don't invalidate any Values referring
@@ -297,7 +293,6 @@ impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
297293
const_cstr_cache: RefCell::new(FxHashMap()),
298294
const_unsized: RefCell::new(FxHashMap()),
299295
const_globals: RefCell::new(FxHashMap()),
300-
statics: RefCell::new(FxHashMap()),
301296
statics_to_rauw: RefCell::new(Vec::new()),
302297
used_statics: RefCell::new(Vec::new()),
303298
lltypes: RefCell::new(FxHashMap()),

src/librustc_codegen_llvm/llvm/ffi.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,8 @@ extern "C" {
14551455
FunctionSections: bool,
14561456
DataSections: bool,
14571457
TrapUnreachable: bool,
1458-
Singlethread: bool)
1458+
Singlethread: bool,
1459+
AsmComments: bool)
14591460
-> Option<&'static mut TargetMachine>;
14601461
pub fn LLVMRustDisposeTargetMachine(T: &'static mut TargetMachine);
14611462
pub fn LLVMRustAddAnalysisPasses(T: &'a TargetMachine, PM: &PassManager<'a>, M: &'a Module);

0 commit comments

Comments
 (0)