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 6 pull requests #39652

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c68e963
Add Rvalue::Discriminant to retrieve discriminant
nagisa Jan 30, 2017
caf9f95
If is now always a SwitchInt in MIR
nagisa Jan 31, 2017
6849985
Move type of discriminant to AdtDef
nagisa Feb 1, 2017
a8075a4
AdtDef now contains discr_ty same as layouted
nagisa Feb 1, 2017
1355a57
SwitchInt over Switch
nagisa Feb 2, 2017
94e587e
Only SwitchInt over integers, not all consts
nagisa Feb 2, 2017
3393584
Fix build on further stages
nagisa Feb 2, 2017
76bc6c3
Reimplement simplify_cfg for SwitchInt
nagisa Feb 2, 2017
cd41479
Fix the IntTypeExt::to_ty() lifetime bounds
nagisa Feb 2, 2017
ff167a6
Fix SwitchInt building in ElaborateDrops pass
nagisa Feb 2, 2017
4e7770e
Prefer switching on false for boolean switches
nagisa Feb 2, 2017
d3f704a
Fix codegen test
nagisa Feb 2, 2017
5e465d5
Inspect now does not force on-stack Lvalue
nagisa Feb 2, 2017
1fee722
Revert use of layout code in typeck::collect
nagisa Feb 3, 2017
832d7e0
Add TerminatorKind::if_ convenience constructor
nagisa Feb 3, 2017
4e29e81
Fix build
nagisa Feb 3, 2017
cdd4aad
Fix tests
nagisa Feb 3, 2017
1e8c855
Rebase fixups
nagisa Feb 4, 2017
1246779
Inline open_drop_for_variant & clean matches::test
nagisa Feb 4, 2017
7c2752a
rustbuild: support setting verbosity in config.toml
Keruspe Feb 6, 2017
05eef36
rustdoc: Improve impl disambiguation
ollie27 Feb 6, 2017
4268872
rustbuild: add verbose to config.toml.example
Keruspe Feb 6, 2017
19bbd85
Fix branch name Cargo's downloaded from
alexcrichton Feb 5, 2017
52a887e
Remove some leftover makefiles.
Ms2ger Feb 8, 2017
fdd8c34
Improve backtrace formating while panicking.
Yamakaky Dec 4, 2016
168fd73
Rollup merge of #38165 - Yamakaky:better-backtrace, r=alexcrichton
frewsxcv Feb 8, 2017
359ea02
Rollup merge of #39456 - nagisa:mir-switchint-everywhere, r=nikomatsakis
frewsxcv Feb 8, 2017
0af9930
Rollup merge of #39587 - Keruspe:master, r=alexcrichton
frewsxcv Feb 8, 2017
cc0e540
Rollup merge of #39589 - ollie27:rustdoc_impl_disambiguation, r=alexc…
frewsxcv Feb 8, 2017
b5d1765
Rollup merge of #39598 - alexcrichton:cargo-branch, r=brson
frewsxcv Feb 8, 2017
7a48493
Rollup merge of #39641 - Ms2ger:purge-mk, r=alexcrichton
frewsxcv Feb 8, 2017
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
1 change: 0 additions & 1 deletion mk/cfg/aarch64-unknown-freebsd.mk

This file was deleted.

1 change: 0 additions & 1 deletion mk/cfg/i686-unknown-netbsd.mk

This file was deleted.

2 changes: 2 additions & 0 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ struct Build {
python: Option<String>,
full_bootstrap: Option<bool>,
extended: Option<bool>,
verbose: Option<usize>,
}

/// TOML representation of various global install decisions.
Expand Down Expand Up @@ -294,6 +295,7 @@ impl Config {
set(&mut config.vendor, build.vendor);
set(&mut config.full_bootstrap, build.full_bootstrap);
set(&mut config.extended, build.extended);
set(&mut config.verbose, build.verbose);

if let Some(ref install) = toml.install {
config.prefix = install.prefix.clone().map(PathBuf::from);
Expand Down
3 changes: 3 additions & 0 deletions src/bootstrap/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
# disabled by default.
#extended = false

# Verbosity level: 0 == not verbose, 1 == verbose, 2 == very verbose
#verbose = 0

# =============================================================================
# General install configuration options
# =============================================================================
Expand Down
4 changes: 1 addition & 3 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,7 @@ pub fn cargo(build: &Build, stage: u32, target: &str) {

let branch = match &build.config.channel[..] {
"stable" |
"beta" => {
build.release.split(".").take(2).collect::<Vec<_>>().join(".")
}
"beta" => format!("rust-{}", build.release_num),
_ => "master".to_string(),
};

Expand Down
15 changes: 14 additions & 1 deletion src/doc/book/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,19 @@ If you want more information, you can get a backtrace by setting the
```text
$ RUST_BACKTRACE=1 ./diverges
thread 'main' panicked at 'This function never returns!', hello.rs:2
Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
hello::diverges
at ./hello.rs:2
hello::main
at ./hello.rs:6
```

If you want the complete backtrace and filenames:

```text
$ RUST_BACKTRACE=full ./diverges
thread 'main' panicked at 'This function never returns!', hello.rs:2
stack backtrace:
1: 0x7f402773a829 - sys::backtrace::write::h0942de78b6c02817K8r
2: 0x7f402773d7fc - panicking::on_panic::h3f23f9d0b5f4c91bu9w
Expand Down Expand Up @@ -262,7 +275,7 @@ note: Run with `RUST_BACKTRACE=1` for a backtrace.
`RUST_BACKTRACE` also works with Cargo’s `run` command:

```text
$ RUST_BACKTRACE=1 cargo run
$ RUST_BACKTRACE=full cargo run
Running `target/debug/diverges`
thread 'main' panicked at 'This function never returns!', hello.rs:2
stack backtrace:
Expand Down
11 changes: 11 additions & 0 deletions src/librustc/middle/const_val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::rc::Rc;
use hir::def_id::DefId;
use rustc_const_math::*;
use self::ConstVal::*;
pub use rustc_const_math::ConstInt;

use std::collections::BTreeMap;

Expand Down Expand Up @@ -48,4 +49,14 @@ impl ConstVal {
Char(..) => "char",
}
}

pub fn to_const_int(&self) -> Option<ConstInt> {
match *self {
ConstVal::Integral(i) => Some(i),
ConstVal::Bool(true) => Some(ConstInt::Infer(1)),
ConstVal::Bool(false) => Some(ConstInt::Infer(0)),
ConstVal::Char(ch) => Some(ConstInt::U32(ch as u32)),
_ => None
}
}
}
67 changes: 33 additions & 34 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,36 +453,30 @@ pub enum TerminatorKind<'tcx> {
target: BasicBlock,
},

/// jump to branch 0 if this lvalue evaluates to true
If {
cond: Operand<'tcx>,
targets: (BasicBlock, BasicBlock),
},

/// lvalue evaluates to some enum; jump depending on the branch
Switch {
discr: Lvalue<'tcx>,
adt_def: &'tcx AdtDef,
targets: Vec<BasicBlock>,
},

/// operand evaluates to an integer; jump depending on its value
/// to one of the targets, and otherwise fallback to `otherwise`
SwitchInt {
/// discriminant value being tested
discr: Lvalue<'tcx>,
discr: Operand<'tcx>,

/// type of value being tested
switch_ty: Ty<'tcx>,

/// Possible values. The locations to branch to in each case
/// are found in the corresponding indices from the `targets` vector.
values: Vec<ConstVal>,

/// Possible branch sites. The length of this vector should be
/// equal to the length of the `values` vector plus 1 -- the
/// extra item is the block to branch to if none of the values
/// fit.
values: Cow<'tcx, [ConstInt]>,

/// Possible branch sites. The last element of this vector is used
/// for the otherwise branch, so values.len() == targets.len() + 1
/// should hold.
// This invariant is quite non-obvious and also could be improved.
// One way to make this invariant is to have something like this instead:
//
// branches: Vec<(ConstInt, BasicBlock)>,
// otherwise: Option<BasicBlock> // exhaustive if None
//
// However we’ve decided to keep this as-is until we figure a case
// where some other approach seems to be strictly better than other.
targets: Vec<BasicBlock>,
},

Expand Down Expand Up @@ -546,12 +540,21 @@ impl<'tcx> Terminator<'tcx> {
}

impl<'tcx> TerminatorKind<'tcx> {
pub fn if_<'a, 'gcx>(tcx: ty::TyCtxt<'a, 'gcx, 'tcx>, cond: Operand<'tcx>,
t: BasicBlock, f: BasicBlock) -> TerminatorKind<'tcx> {
static BOOL_SWITCH_FALSE: &'static [ConstInt] = &[ConstInt::Infer(0)];
TerminatorKind::SwitchInt {
discr: cond,
switch_ty: tcx.types.bool,
values: From::from(BOOL_SWITCH_FALSE),
targets: vec![f, t],
}
}

pub fn successors(&self) -> Cow<[BasicBlock]> {
use self::TerminatorKind::*;
match *self {
Goto { target: ref b } => slice::ref_slice(b).into_cow(),
If { targets: (b1, b2), .. } => vec![b1, b2].into_cow(),
Switch { targets: ref b, .. } => b[..].into_cow(),
SwitchInt { targets: ref b, .. } => b[..].into_cow(),
Resume => (&[]).into_cow(),
Return => (&[]).into_cow(),
Expand Down Expand Up @@ -580,8 +583,6 @@ impl<'tcx> TerminatorKind<'tcx> {
use self::TerminatorKind::*;
match *self {
Goto { target: ref mut b } => vec![b],
If { targets: (ref mut b1, ref mut b2), .. } => vec![b1, b2],
Switch { targets: ref mut b, .. } => b.iter_mut().collect(),
SwitchInt { targets: ref mut b, .. } => b.iter_mut().collect(),
Resume => Vec::new(),
Return => Vec::new(),
Expand Down Expand Up @@ -659,8 +660,6 @@ impl<'tcx> TerminatorKind<'tcx> {
use self::TerminatorKind::*;
match *self {
Goto { .. } => write!(fmt, "goto"),
If { cond: ref lv, .. } => write!(fmt, "if({:?})", lv),
Switch { discr: ref lv, .. } => write!(fmt, "switch({:?})", lv),
SwitchInt { discr: ref lv, .. } => write!(fmt, "switchInt({:?})", lv),
Return => write!(fmt, "return"),
Resume => write!(fmt, "resume"),
Expand Down Expand Up @@ -710,18 +709,11 @@ impl<'tcx> TerminatorKind<'tcx> {
match *self {
Return | Resume | Unreachable => vec![],
Goto { .. } => vec!["".into()],
If { .. } => vec!["true".into(), "false".into()],
Switch { ref adt_def, .. } => {
adt_def.variants
.iter()
.map(|variant| variant.name.to_string().into())
.collect()
}
SwitchInt { ref values, .. } => {
values.iter()
.map(|const_val| {
let mut buf = String::new();
fmt_const_val(&mut buf, const_val).unwrap();
fmt_const_val(&mut buf, &ConstVal::Integral(*const_val)).unwrap();
buf.into()
})
.chain(iter::once(String::from("otherwise").into()))
Expand Down Expand Up @@ -997,6 +989,12 @@ pub enum Rvalue<'tcx> {

UnaryOp(UnOp, Operand<'tcx>),

/// Read the discriminant of an ADT.
///
/// Undefined (i.e. no effort is made to make it defined, but there’s no reason why it cannot
/// be defined to return, say, a 0) if ADT is not an enum.
Discriminant(Lvalue<'tcx>),

/// Creates an *uninitialized* Box
Box(Ty<'tcx>),

Expand Down Expand Up @@ -1111,6 +1109,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
write!(fmt, "Checked{:?}({:?}, {:?})", op, a, b)
}
UnaryOp(ref op, ref a) => write!(fmt, "{:?}({:?})", op, a),
Discriminant(ref lval) => write!(fmt, "discriminant({:?})", lval),
Box(ref t) => write!(fmt, "Box({:?})", t),
InlineAsm { ref asm, ref outputs, ref inputs } => {
write!(fmt, "asm!({:?} : {:?} : {:?})", asm, outputs, inputs)
Expand Down
35 changes: 23 additions & 12 deletions src/librustc/mir/tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use ty::subst::{Subst, Substs};
use ty::{self, AdtDef, Ty, TyCtxt};
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
use hir;
use ty::util::IntTypeExt;

#[derive(Copy, Clone, Debug)]
pub enum LvalueTy<'tcx> {
Expand Down Expand Up @@ -135,15 +136,15 @@ impl<'tcx> Lvalue<'tcx> {
impl<'tcx> Rvalue<'tcx> {
pub fn ty<'a, 'gcx>(&self, mir: &Mir<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Ty<'tcx>>
{
match self {
&Rvalue::Use(ref operand) => Some(operand.ty(mir, tcx)),
&Rvalue::Repeat(ref operand, ref count) => {
match *self {
Rvalue::Use(ref operand) => Some(operand.ty(mir, tcx)),
Rvalue::Repeat(ref operand, ref count) => {
let op_ty = operand.ty(mir, tcx);
let count = count.value.as_u64(tcx.sess.target.uint_type);
assert_eq!(count as usize as u64, count);
Some(tcx.mk_array(op_ty, count as usize))
}
&Rvalue::Ref(reg, bk, ref lv) => {
Rvalue::Ref(reg, bk, ref lv) => {
let lv_ty = lv.ty(mir, tcx).to_ty(tcx);
Some(tcx.mk_ref(reg,
ty::TypeAndMut {
Expand All @@ -152,27 +153,37 @@ impl<'tcx> Rvalue<'tcx> {
}
))
}
&Rvalue::Len(..) => Some(tcx.types.usize),
&Rvalue::Cast(.., ty) => Some(ty),
&Rvalue::BinaryOp(op, ref lhs, ref rhs) => {
Rvalue::Len(..) => Some(tcx.types.usize),
Rvalue::Cast(.., ty) => Some(ty),
Rvalue::BinaryOp(op, ref lhs, ref rhs) => {
let lhs_ty = lhs.ty(mir, tcx);
let rhs_ty = rhs.ty(mir, tcx);
Some(op.ty(tcx, lhs_ty, rhs_ty))
}
&Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => {
Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => {
let lhs_ty = lhs.ty(mir, tcx);
let rhs_ty = rhs.ty(mir, tcx);
let ty = op.ty(tcx, lhs_ty, rhs_ty);
let ty = tcx.intern_tup(&[ty, tcx.types.bool], false);
Some(ty)
}
&Rvalue::UnaryOp(_, ref operand) => {
Rvalue::UnaryOp(_, ref operand) => {
Some(operand.ty(mir, tcx))
}
&Rvalue::Box(t) => {
Rvalue::Discriminant(ref lval) => {
let ty = lval.ty(mir, tcx).to_ty(tcx);
if let ty::TyAdt(adt_def, _) = ty.sty {
Some(adt_def.discr_ty.to_ty(tcx))
} else {
// Undefined behaviour, bug for now; may want to return something for
// the `discriminant` intrinsic later.
bug!("Rvalue::Discriminant on Lvalue of type {:?}", ty);
}
}
Rvalue::Box(t) => {
Some(tcx.mk_box(t))
}
&Rvalue::Aggregate(ref ak, ref ops) => {
Rvalue::Aggregate(ref ak, ref ops) => {
match *ak {
AggregateKind::Array => {
if let Some(operand) = ops.get(0) {
Expand All @@ -196,7 +207,7 @@ impl<'tcx> Rvalue<'tcx> {
}
}
}
&Rvalue::InlineAsm { .. } => None
Rvalue::InlineAsm { .. } => None
}
}
}
Expand Down
43 changes: 19 additions & 24 deletions src/librustc/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use ty::subst::Substs;
use ty::{ClosureSubsts, Region, Ty};
use mir::*;
use rustc_const_math::ConstUsize;
use rustc_data_structures::tuple_slice::TupleSlice;
use rustc_data_structures::indexed_vec::Idx;
use syntax_pos::Span;

Expand Down Expand Up @@ -224,6 +223,12 @@ macro_rules! make_mir_visitor {
self.super_const_val(const_val);
}

fn visit_const_int(&mut self,
const_int: &ConstInt,
_: Location) {
self.super_const_int(const_int);
}

fn visit_const_usize(&mut self,
const_usize: & $($mutability)* ConstUsize,
_: Location) {
Expand Down Expand Up @@ -363,31 +368,14 @@ macro_rules! make_mir_visitor {
self.visit_branch(block, target);
}

TerminatorKind::If { ref $($mutability)* cond,
ref $($mutability)* targets } => {
self.visit_operand(cond, source_location);
for &target in targets.as_slice() {
self.visit_branch(block, target);
}
}

TerminatorKind::Switch { ref $($mutability)* discr,
adt_def: _,
ref targets } => {
self.visit_lvalue(discr, LvalueContext::Inspect, source_location);
for &target in targets {
self.visit_branch(block, target);
}
}

TerminatorKind::SwitchInt { ref $($mutability)* discr,
ref $($mutability)* switch_ty,
ref $($mutability)* values,
ref values,
ref targets } => {
self.visit_lvalue(discr, LvalueContext::Inspect, source_location);
self.visit_operand(discr, source_location);
self.visit_ty(switch_ty);
for value in values {
self.visit_const_val(value, source_location);
for value in &values[..] {
self.visit_const_int(value, source_location);
}
for &target in targets {
self.visit_branch(block, target);
Expand Down Expand Up @@ -506,6 +494,10 @@ macro_rules! make_mir_visitor {
self.visit_operand(op, location);
}

Rvalue::Discriminant(ref $($mutability)* lvalue) => {
self.visit_lvalue(lvalue, LvalueContext::Inspect, location);
}

Rvalue::Box(ref $($mutability)* ty) => {
self.visit_ty(ty);
}
Expand Down Expand Up @@ -712,10 +704,13 @@ macro_rules! make_mir_visitor {
_substs: & $($mutability)* ClosureSubsts<'tcx>) {
}

fn super_const_val(&mut self, _substs: & $($mutability)* ConstVal) {
fn super_const_val(&mut self, _const_val: & $($mutability)* ConstVal) {
}

fn super_const_int(&mut self, _const_int: &ConstInt) {
}

fn super_const_usize(&mut self, _substs: & $($mutability)* ConstUsize) {
fn super_const_usize(&mut self, _const_usize: & $($mutability)* ConstUsize) {
}

// Convenience methods
Expand Down
Loading