Skip to content

Commit d4f3940

Browse files
authored
Merge pull request #37173 from brson/stable-next
[stable] Backports for 1.12.1
2 parents 3191fba + 2d49342 commit d4f3940

23 files changed

+269
-50
lines changed

mk/main.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
######################################################################
1414

1515
# The version number
16-
CFG_RELEASE_NUM=1.12.0
16+
CFG_RELEASE_NUM=1.12.1
1717

1818
# An optional number to put after the label, e.g. '.2' -> '-beta.2'
1919
# NB Make sure it starts with a dot to conform to semver pre-release

src/librustc/ty/flags.rs

+5
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ impl FlagComputation {
107107
}
108108

109109
&ty::TyProjection(ref data) => {
110+
// currently we can't normalize projections that
111+
// include bound regions, so track those separately.
112+
if !data.has_escaping_regions() {
113+
self.add_flags(TypeFlags::HAS_NORMALIZABLE_PROJECTION);
114+
}
110115
self.add_flags(TypeFlags::HAS_PROJECTION);
111116
self.add_projection_ty(data);
112117
}

src/librustc/ty/fold.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
105105
TypeFlags::HAS_FREE_REGIONS |
106106
TypeFlags::HAS_TY_INFER |
107107
TypeFlags::HAS_PARAMS |
108-
TypeFlags::HAS_PROJECTION |
108+
TypeFlags::HAS_NORMALIZABLE_PROJECTION |
109109
TypeFlags::HAS_TY_ERR |
110110
TypeFlags::HAS_SELF)
111111
}

src/librustc/ty/item_path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
305305
/// Returns the def-id of `def_id`'s parent in the def tree. If
306306
/// this returns `None`, then `def_id` represents a crate root or
307307
/// inlined root.
308-
fn parent_def_id(&self, def_id: DefId) -> Option<DefId> {
308+
pub fn parent_def_id(&self, def_id: DefId) -> Option<DefId> {
309309
let key = self.def_key(def_id);
310310
key.parent.map(|index| DefId { krate: def_id.krate, index: index })
311311
}

src/librustc/ty/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,10 @@ bitflags! {
527527
// Only set for TyInfer other than Fresh.
528528
const KEEP_IN_LOCAL_TCX = 1 << 11,
529529

530+
// Is there a projection that does not involve a bound region?
531+
// Currently we can't normalize projections w/ bound regions.
532+
const HAS_NORMALIZABLE_PROJECTION = 1 << 12,
533+
530534
const NEEDS_SUBST = TypeFlags::HAS_PARAMS.bits |
531535
TypeFlags::HAS_SELF.bits |
532536
TypeFlags::HAS_RE_EARLY_BOUND.bits,

src/librustc_mir/build/expr/as_lvalue.rs

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
9696
ExprKind::LogicalOp { .. } |
9797
ExprKind::Box { .. } |
9898
ExprKind::Cast { .. } |
99+
ExprKind::Use { .. } |
99100
ExprKind::NeverToAny { .. } |
100101
ExprKind::ReifyFnPointer { .. } |
101102
ExprKind::UnsafeFnPointer { .. } |

src/librustc_mir/build/expr/as_rvalue.rs

+4
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
115115
let source = unpack!(block = this.as_operand(block, source));
116116
block.and(Rvalue::Cast(CastKind::Misc, source, expr.ty))
117117
}
118+
ExprKind::Use { source } => {
119+
let source = unpack!(block = this.as_operand(block, source));
120+
block.and(Rvalue::Use(source))
121+
}
118122
ExprKind::ReifyFnPointer { source } => {
119123
let source = unpack!(block = this.as_operand(block, source));
120124
block.and(Rvalue::Cast(CastKind::ReifyFnPointer, source, expr.ty))

src/librustc_mir/build/expr/category.rs

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ impl Category {
6868
ExprKind::Binary { .. } |
6969
ExprKind::Box { .. } |
7070
ExprKind::Cast { .. } |
71+
ExprKind::Use { .. } |
7172
ExprKind::ReifyFnPointer { .. } |
7273
ExprKind::UnsafeFnPointer { .. } |
7374
ExprKind::Unsize { .. } |

src/librustc_mir/build/expr/into.rs

+1
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
249249
ExprKind::Binary { .. } |
250250
ExprKind::Box { .. } |
251251
ExprKind::Cast { .. } |
252+
ExprKind::Use { .. } |
252253
ExprKind::ReifyFnPointer { .. } |
253254
ExprKind::UnsafeFnPointer { .. } |
254255
ExprKind::Unsize { .. } |

src/librustc_mir/hair/cx/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,8 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
602602
// Check to see if this cast is a "coercion cast", where the cast is actually done
603603
// using a coercion (or is a no-op).
604604
if let Some(&TyCastKind::CoercionCast) = cx.tcx.cast_kinds.borrow().get(&source.id) {
605-
// Skip the actual cast itexpr, as it's now a no-op.
606-
return source.make_mirror(cx);
605+
// Convert the lexpr to a vexpr.
606+
ExprKind::Use { source: source.to_ref() }
607607
} else {
608608
ExprKind::Cast { source: source.to_ref() }
609609
}

src/librustc_mir/hair/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ pub enum ExprKind<'tcx> {
139139
Cast {
140140
source: ExprRef<'tcx>,
141141
},
142+
Use {
143+
source: ExprRef<'tcx>,
144+
}, // Use a lexpr to get a vexpr.
142145
NeverToAny {
143146
source: ExprRef<'tcx>,
144147
},

src/librustc_trans/base.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,16 @@ pub fn compare_scalar_types<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
320320
_ => bug!("compare_scalar_types: must be a comparison operator"),
321321
}
322322
}
323-
ty::TyFnDef(..) | ty::TyFnPtr(_) | ty::TyBool | ty::TyUint(_) | ty::TyChar => {
323+
ty::TyBool => {
324+
// FIXME(#36856) -- using `from_immediate` forces these booleans into `i8`,
325+
// which works around some LLVM bugs
326+
ICmp(bcx,
327+
bin_op_to_icmp_predicate(op, false),
328+
from_immediate(bcx, lhs),
329+
from_immediate(bcx, rhs),
330+
debug_loc)
331+
}
332+
ty::TyFnDef(..) | ty::TyFnPtr(_) | ty::TyUint(_) | ty::TyChar => {
324333
ICmp(bcx,
325334
bin_op_to_icmp_predicate(op, false),
326335
lhs,

src/librustc_trans/builder.rs

+56-17
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use value::Value;
2222
use util::nodemap::FnvHashMap;
2323
use libc::{c_uint, c_char};
2424

25+
use std::borrow::Cow;
2526
use std::ffi::CString;
2627
use std::ptr;
2728
use syntax_pos::Span;
@@ -175,8 +176,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
175176
.collect::<Vec<String>>()
176177
.join(", "));
177178

178-
check_call("invoke", llfn, args);
179-
179+
let args = self.check_call("invoke", llfn, args);
180180
let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(ptr::null_mut());
181181

182182
unsafe {
@@ -543,6 +543,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
543543
debug!("Store {:?} -> {:?}", Value(val), Value(ptr));
544544
assert!(!self.llbuilder.is_null());
545545
self.count_insn("store");
546+
let ptr = self.check_store(val, ptr);
546547
unsafe {
547548
llvm::LLVMBuildStore(self.llbuilder, val, ptr)
548549
}
@@ -552,6 +553,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
552553
debug!("Store {:?} -> {:?}", Value(val), Value(ptr));
553554
assert!(!self.llbuilder.is_null());
554555
self.count_insn("store.volatile");
556+
let ptr = self.check_store(val, ptr);
555557
unsafe {
556558
let insn = llvm::LLVMBuildStore(self.llbuilder, val, ptr);
557559
llvm::LLVMSetVolatile(insn, llvm::True);
@@ -562,6 +564,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
562564
pub fn atomic_store(&self, val: ValueRef, ptr: ValueRef, order: AtomicOrdering) {
563565
debug!("Store {:?} -> {:?}", Value(val), Value(ptr));
564566
self.count_insn("store.atomic");
567+
let ptr = self.check_store(val, ptr);
565568
unsafe {
566569
let ty = Type::from_ref(llvm::LLVMTypeOf(ptr));
567570
let align = llalign_of_pref(self.ccx, ty.element_type());
@@ -857,8 +860,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
857860
.collect::<Vec<String>>()
858861
.join(", "));
859862

860-
check_call("call", llfn, args);
861-
863+
let args = self.check_call("call", llfn, args);
862864
let bundle = bundle.as_ref().map(|b| b.raw()).unwrap_or(ptr::null_mut());
863865

864866
unsafe {
@@ -1100,10 +1102,32 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11001102
llvm::LLVMRustBuildAtomicFence(self.llbuilder, order, scope);
11011103
}
11021104
}
1103-
}
11041105

1105-
fn check_call(typ: &str, llfn: ValueRef, args: &[ValueRef]) {
1106-
if cfg!(debug_assertions) {
1106+
/// Returns the ptr value that should be used for storing `val`.
1107+
fn check_store<'b>(&self,
1108+
val: ValueRef,
1109+
ptr: ValueRef) -> ValueRef {
1110+
let dest_ptr_ty = val_ty(ptr);
1111+
let stored_ty = val_ty(val);
1112+
let stored_ptr_ty = stored_ty.ptr_to();
1113+
1114+
assert_eq!(dest_ptr_ty.kind(), llvm::TypeKind::Pointer);
1115+
1116+
if dest_ptr_ty == stored_ptr_ty {
1117+
ptr
1118+
} else {
1119+
debug!("Type mismatch in store. \
1120+
Expected {:?}, got {:?}; inserting bitcast",
1121+
dest_ptr_ty, stored_ptr_ty);
1122+
self.bitcast(ptr, stored_ptr_ty)
1123+
}
1124+
}
1125+
1126+
/// Returns the args that should be used for a call to `llfn`.
1127+
fn check_call<'b>(&self,
1128+
typ: &str,
1129+
llfn: ValueRef,
1130+
args: &'b [ValueRef]) -> Cow<'b, [ValueRef]> {
11071131
let mut fn_ty = val_ty(llfn);
11081132
// Strip off pointers
11091133
while fn_ty.kind() == llvm::TypeKind::Pointer {
@@ -1115,16 +1139,31 @@ fn check_call(typ: &str, llfn: ValueRef, args: &[ValueRef]) {
11151139

11161140
let param_tys = fn_ty.func_params();
11171141

1118-
let iter = param_tys.into_iter()
1119-
.zip(args.iter().map(|&v| val_ty(v)));
1120-
for (i, (expected_ty, actual_ty)) in iter.enumerate() {
1121-
if expected_ty != actual_ty {
1122-
bug!("Type mismatch in function call of {:?}. \
1123-
Expected {:?} for param {}, got {:?}",
1124-
Value(llfn),
1125-
expected_ty, i, actual_ty);
1142+
let all_args_match = param_tys.iter()
1143+
.zip(args.iter().map(|&v| val_ty(v)))
1144+
.all(|(expected_ty, actual_ty)| *expected_ty == actual_ty);
1145+
1146+
if all_args_match {
1147+
return Cow::Borrowed(args);
1148+
}
1149+
1150+
let casted_args: Vec<_> = param_tys.into_iter()
1151+
.zip(args.iter())
1152+
.enumerate()
1153+
.map(|(i, (expected_ty, &actual_val))| {
1154+
let actual_ty = val_ty(actual_val);
1155+
if expected_ty != actual_ty {
1156+
debug!("Type mismatch in function call of {:?}. \
1157+
Expected {:?} for param {}, got {:?}; injecting bitcast",
1158+
Value(llfn),
1159+
expected_ty, i, actual_ty);
1160+
self.bitcast(actual_val, expected_ty)
1161+
} else {
1162+
actual_val
1163+
}
1164+
})
1165+
.collect();
11261166

1127-
}
1128-
}
1167+
return Cow::Owned(casted_args);
11291168
}
11301169
}

src/librustc_trans/collector.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,9 @@ fn create_fn_trans_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10421042
let concrete_substs = monomorphize::apply_param_substs(tcx,
10431043
param_substs,
10441044
&fn_substs);
1045-
assert!(concrete_substs.is_normalized_for_trans());
1045+
assert!(concrete_substs.is_normalized_for_trans(),
1046+
"concrete_substs not normalized for trans: {:?}",
1047+
concrete_substs);
10461048
TransItem::Fn(Instance::new(def_id, concrete_substs))
10471049
}
10481050

src/librustc_trans/mir/mod.rs

+13-22
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use machine;
2222
use type_of;
2323

2424
use syntax_pos::DUMMY_SP;
25-
use syntax::parse::token::keywords;
2625

2726
use std::ops::Deref;
2827
use std::rc::Rc;
@@ -301,7 +300,6 @@ fn arg_local_refs<'bcx, 'tcx>(bcx: &BlockAndBuilder<'bcx, 'tcx>,
301300
_ => bug!("spread argument isn't a tuple?!")
302301
};
303302

304-
let lltuplety = type_of::type_of(bcx.ccx(), arg_ty);
305303
let lltemp = bcx.with_block(|bcx| {
306304
base::alloc_ty(bcx, arg_ty, &format!("arg{}", arg_index))
307305
});
@@ -319,27 +317,20 @@ fn arg_local_refs<'bcx, 'tcx>(bcx: &BlockAndBuilder<'bcx, 'tcx>,
319317
} else {
320318
arg.store_fn_arg(bcx, &mut llarg_idx, dst);
321319
}
322-
323-
bcx.with_block(|bcx| arg_scope.map(|scope| {
324-
let byte_offset_of_var_in_tuple =
325-
machine::llelement_offset(bcx.ccx(), lltuplety, i);
326-
327-
let ops = unsafe {
328-
[llvm::LLVMRustDIBuilderCreateOpDeref(),
329-
llvm::LLVMRustDIBuilderCreateOpPlus(),
330-
byte_offset_of_var_in_tuple as i64]
331-
};
332-
333-
let variable_access = VariableAccess::IndirectVariable {
334-
alloca: lltemp,
335-
address_operations: &ops
336-
};
337-
declare_local(bcx, keywords::Invalid.name(),
338-
tupled_arg_ty, scope, variable_access,
339-
VariableKind::ArgumentVariable(arg_index + i + 1),
340-
bcx.fcx().span.unwrap_or(DUMMY_SP));
341-
}));
342320
}
321+
322+
// Now that we have one alloca that contains the aggregate value,
323+
// we can create one debuginfo entry for the argument.
324+
bcx.with_block(|bcx| arg_scope.map(|scope| {
325+
let variable_access = VariableAccess::DirectVariable {
326+
alloca: lltemp
327+
};
328+
declare_local(bcx, arg_decl.debug_name,
329+
arg_ty, scope, variable_access,
330+
VariableKind::ArgumentVariable(arg_index + 1),
331+
bcx.fcx().span.unwrap_or(DUMMY_SP));
332+
}));
333+
343334
return LocalRef::Lvalue(LvalueRef::new_sized(lltemp, LvalueTy::from_ty(arg_ty)));
344335
}
345336

src/librustc_typeck/check/_match.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -535,13 +535,21 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
535535
report_unexpected_def();
536536
return;
537537
}
538-
Def::Variant(..) | Def::Struct(..) => {
538+
Def::Variant(..) => {
539539
let variant = tcx.expect_variant_def(def);
540540
if variant.kind != VariantKind::Unit {
541541
report_unexpected_def();
542542
return;
543543
}
544544
}
545+
Def::Struct(ctor_did) => {
546+
let did = tcx.parent_def_id(ctor_did).expect("struct ctor has no parent");
547+
let variant = tcx.lookup_adt_def(did).struct_variant();
548+
if variant.kind != VariantKind::Unit {
549+
report_unexpected_def();
550+
return;
551+
}
552+
}
545553
Def::Const(..) | Def::AssociatedConst(..) => {} // OK
546554
_ => bug!("unexpected pattern definition {:?}", def)
547555
}
@@ -592,9 +600,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
592600
report_unexpected_def(false);
593601
return;
594602
}
595-
Def::Variant(..) | Def::Struct(..) => {
603+
Def::Variant(..) => {
596604
tcx.expect_variant_def(def)
597605
}
606+
Def::Struct(ctor_did) => {
607+
let did = tcx.parent_def_id(ctor_did).expect("struct ctor has no parent");
608+
tcx.lookup_adt_def(did).struct_variant()
609+
}
598610
_ => bug!("unexpected pattern definition {:?}", def)
599611
};
600612
if variant.kind == VariantKind::Unit && subpats.is_empty() && ddpos.is_some() {

src/rustllvm/llvm-auto-clean-trigger

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# If this file is modified, then llvm will be forcibly cleaned and then rebuilt.
22
# The actual contents of this file do not matter, but to trigger a change on the
33
# build bots then the contents should be changed so git updates the mtime.
4-
2016-09-17
4+
2016-10-10

0 commit comments

Comments
 (0)