Skip to content

Commit 1836349

Browse files
committed
Update to master
1 parent 63511ef commit 1836349

File tree

5 files changed

+72
-68
lines changed

5 files changed

+72
-68
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,16 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a, 'gcx>> for mir::interpret::Al
336336
.interpret_interner
337337
.expect("cannot hash AllocIds during HIR lowering")
338338
.borrow();
339-
if let Some(alloc) = interner.get_alloc(*self) {
340-
false.hash_stable(hcx, hasher);
341-
// FIXME: recursive allocations
339+
if let Some(def_id) = interner.get_corresponding_static_def_id(*self) {
340+
0.hash_stable(hcx, hasher);
341+
// statics are unique via their DefId
342+
def_id.hash_stable(hcx, hasher);
343+
} else if let Some(alloc) = interner.get_alloc(*self) {
344+
// not a static, can't be recursive, hash the allocation
345+
1.hash_stable(hcx, hasher);
342346
alloc.hash_stable(hcx, hasher);
343347
} else if let Some(inst) = interner.get_fn(*self) {
344-
true.hash_stable(hcx, hasher);
348+
2.hash_stable(hcx, hasher);
345349
inst.hash_stable(hcx, hasher);
346350
} else {
347351
bug!("no allocation for {}", self);

src/librustc_trans/mir/analyze.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> {
128128
_ => None,
129129
};
130130
if let Some((def_id, args)) = check {
131-
if Some(def_id) == self.cx.ccx.tcx().lang_items().box_free_fn() {
131+
if Some(def_id) == self.fx.cx.tcx.lang_items().box_free_fn() {
132132
// box_free(x) shares with `drop x` the property that it
133133
// is not guaranteed to be statically dominated by the
134134
// definition of x, so x must always be in an alloca.

src/librustc_trans/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
204204
let (otherwise, targets) = targets.split_last().unwrap();
205205
let switch = bx.switch(discr.immediate(),
206206
llblock(self, *otherwise), values.len());
207-
let switch_llty = bcx.ccx.layout_of(switch_ty).immediate_llvm_type(bcx.ccx);
207+
let switch_llty = bx.cx.layout_of(switch_ty).immediate_llvm_type(bx.cx);
208208
for (&value, target) in values.iter().zip(targets) {
209209
let llval = C_uint_big(switch_llty, value);
210210
let llbb = llblock(self, *target);

src/librustc_trans/mir/constant.rs

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use type_of::LayoutLlvmExt;
2929
use type_::Type;
3030

3131
use super::super::callee;
32-
use super::MirContext;
32+
use super::FunctionCx;
3333

3434
fn to_const_int(value: ValueRef, t: Ty, tcx: TyCtxt) -> Option<ConstInt> {
3535
match t.sty {
@@ -135,44 +135,44 @@ pub fn const_scalar_checked_binop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
135135
}
136136
}
137137

138-
pub fn primval_to_llvm(ccx: &CrateContext,
138+
pub fn primval_to_llvm(cx: &CodegenCx,
139139
cv: PrimVal,
140140
scalar: &Scalar,
141141
llty: Type) -> ValueRef {
142-
let bits = if scalar.is_bool() { 1 } else { scalar.value.size(ccx).bits() };
142+
let bits = if scalar.is_bool() { 1 } else { scalar.value.size(cx).bits() };
143143
match cv {
144-
PrimVal::Undef => C_undef(Type::ix(ccx, bits)),
144+
PrimVal::Undef => C_undef(Type::ix(cx, bits)),
145145
PrimVal::Bytes(b) => {
146-
let llval = C_uint_big(Type::ix(ccx, bits), b);
146+
let llval = C_uint_big(Type::ix(cx, bits), b);
147147
if scalar.value == layout::Pointer {
148148
unsafe { llvm::LLVMConstIntToPtr(llval, llty.to_ref()) }
149149
} else {
150150
consts::bitcast(llval, llty)
151151
}
152152
},
153153
PrimVal::Ptr(ptr) => {
154-
let interpret_interner = ccx.tcx().interpret_interner.borrow();
154+
let interpret_interner = cx.tcx.interpret_interner.borrow();
155155
if let Some(fn_instance) = interpret_interner.get_fn(ptr.alloc_id) {
156-
callee::get_fn(ccx, fn_instance)
156+
callee::get_fn(cx, fn_instance)
157157
} else {
158158
let static_ = interpret_interner.get_corresponding_static_def_id(ptr.alloc_id);
159159
let base_addr = if let Some(def_id) = static_ {
160-
assert!(ccx.tcx().is_static(def_id).is_some());
161-
consts::get_static(ccx, def_id)
160+
assert!(cx.tcx.is_static(def_id).is_some());
161+
consts::get_static(cx, def_id)
162162
} else if let Some(alloc) = interpret_interner.get_alloc(ptr.alloc_id) {
163-
let init = global_initializer(ccx, alloc);
163+
let init = global_initializer(cx, alloc);
164164
if alloc.mutable {
165-
consts::addr_of_mut(ccx, init, alloc.align, "byte_str")
165+
consts::addr_of_mut(cx, init, alloc.align, "byte_str")
166166
} else {
167-
consts::addr_of(ccx, init, alloc.align, "byte_str")
167+
consts::addr_of(cx, init, alloc.align, "byte_str")
168168
}
169169
} else {
170170
bug!("missing allocation {:?}", ptr.alloc_id);
171171
};
172172

173173
let llval = unsafe { llvm::LLVMConstInBoundsGEP(
174-
consts::bitcast(base_addr, Type::i8p(ccx)),
175-
&C_usize(ccx, ptr.offset),
174+
consts::bitcast(base_addr, Type::i8p(cx)),
175+
&C_usize(cx, ptr.offset),
176176
1,
177177
) };
178178
if scalar.value != layout::Pointer {
@@ -185,94 +185,94 @@ pub fn primval_to_llvm(ccx: &CrateContext,
185185
}
186186
}
187187

188-
pub fn global_initializer(ccx: &CrateContext, alloc: &Allocation) -> ValueRef {
188+
pub fn global_initializer(cx: &CodegenCx, alloc: &Allocation) -> ValueRef {
189189
let mut llvals = Vec::with_capacity(alloc.relocations.len() + 1);
190-
let layout = ccx.data_layout();
190+
let layout = cx.data_layout();
191191
let pointer_size = layout.pointer_size.bytes() as usize;
192192

193193
let mut next_offset = 0;
194194
for (&offset, &alloc_id) in &alloc.relocations {
195195
assert_eq!(offset as usize as u64, offset);
196196
let offset = offset as usize;
197197
if offset > next_offset {
198-
llvals.push(C_bytes(ccx, &alloc.bytes[next_offset..offset]));
198+
llvals.push(C_bytes(cx, &alloc.bytes[next_offset..offset]));
199199
}
200200
let ptr_offset = read_target_uint(
201201
layout.endian,
202202
&alloc.bytes[offset..(offset + pointer_size)],
203203
).expect("global_initializer: could not read relocation pointer") as u64;
204204
llvals.push(primval_to_llvm(
205-
ccx,
205+
cx,
206206
PrimVal::Ptr(MemoryPointer { alloc_id, offset: ptr_offset }),
207207
&Scalar {
208208
value: layout::Primitive::Pointer,
209209
valid_range: 0..=!0
210210
},
211-
Type::i8p(ccx)
211+
Type::i8p(cx)
212212
));
213213
next_offset = offset + pointer_size;
214214
}
215215
if alloc.bytes.len() >= next_offset {
216-
llvals.push(C_bytes(ccx, &alloc.bytes[next_offset ..]));
216+
llvals.push(C_bytes(cx, &alloc.bytes[next_offset ..]));
217217
}
218218

219-
C_struct(ccx, &llvals, true)
219+
C_struct(cx, &llvals, true)
220220
}
221221

222222
pub fn trans_static_initializer<'a, 'tcx>(
223223
cx: &CodegenCx<'a, 'tcx>,
224224
def_id: DefId)
225225
-> Result<ValueRef, ConstEvalErr<'tcx>>
226226
{
227-
let instance = ty::Instance::mono(ccx.tcx(), def_id);
227+
let instance = ty::Instance::mono(cx.tcx, def_id);
228228
let cid = GlobalId {
229229
instance,
230230
promoted: None
231231
};
232232
let param_env = ty::ParamEnv::empty(traits::Reveal::All);
233-
ccx.tcx().const_eval(param_env.and(cid))?;
233+
cx.tcx.const_eval(param_env.and(cid))?;
234234

235-
let alloc_id = ccx
236-
.tcx()
235+
let alloc_id = cx
236+
.tcx
237237
.interpret_interner
238238
.borrow()
239239
.get_cached(def_id)
240240
.expect("global not cached");
241241

242-
let alloc = ccx
243-
.tcx()
242+
let alloc = cx
243+
.tcx
244244
.interpret_interner
245245
.borrow()
246246
.get_alloc(alloc_id)
247247
.expect("miri allocation never successfully created");
248-
Ok(global_initializer(ccx, alloc))
248+
Ok(global_initializer(cx, alloc))
249249
}
250250

251251
impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
252252
fn const_to_miri_value(
253253
&mut self,
254-
bcx: &Builder<'a, 'tcx>,
254+
bx: &Builder<'a, 'tcx>,
255255
constant: &'tcx ty::Const<'tcx>,
256256
) -> Result<MiriValue, ConstEvalErr<'tcx>> {
257257
match constant.val {
258258
ConstVal::Unevaluated(def_id, ref substs) => {
259-
let tcx = bcx.tcx();
259+
let tcx = bx.tcx();
260260
let param_env = ty::ParamEnv::empty(traits::Reveal::All);
261261
let instance = ty::Instance::resolve(tcx, param_env, def_id, substs).unwrap();
262262
let cid = GlobalId {
263263
instance,
264264
promoted: None,
265265
};
266266
let c = tcx.const_eval(param_env.and(cid))?;
267-
self.const_to_miri_value(bcx, c)
267+
self.const_to_miri_value(bx, c)
268268
},
269269
ConstVal::Value(miri_val) => Ok(miri_val),
270270
}
271271
}
272272

273273
pub fn mir_constant_to_miri_value(
274274
&mut self,
275-
bcx: &Builder<'a, 'tcx>,
275+
bx: &Builder<'a, 'tcx>,
276276
constant: &mir::Constant<'tcx>,
277277
) -> Result<MiriValue, ConstEvalErr<'tcx>> {
278278
match constant.literal {
@@ -282,49 +282,49 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
282282
instance: self.instance,
283283
promoted: Some(index),
284284
};
285-
bcx.tcx().const_eval(param_env.and(cid))
285+
bx.tcx().const_eval(param_env.and(cid))
286286
}
287287
mir::Literal::Value { value } => {
288288
Ok(self.monomorphize(&value))
289289
}
290-
}.and_then(|c| self.const_to_miri_value(bcx, c))
290+
}.and_then(|c| self.const_to_miri_value(bx, c))
291291
}
292292

293293
// Old version of trans_constant now used just for SIMD shuffle
294294
pub fn remove_me_shuffle_indices(&mut self,
295-
bcx: &Builder<'a, 'tcx>,
295+
bx: &Builder<'a, 'tcx>,
296296
constant: &mir::Constant<'tcx>)
297297
-> (ValueRef, Ty<'tcx>)
298298
{
299-
let layout = bcx.ccx.layout_of(constant.ty);
300-
self.mir_constant_to_miri_value(bcx, constant)
299+
let layout = bx.cx.layout_of(constant.ty);
300+
self.mir_constant_to_miri_value(bx, constant)
301301
.and_then(|c| {
302302
let llval = match c {
303303
MiriValue::ByVal(val) => {
304304
let scalar = match layout.abi {
305305
layout::Abi::Scalar(ref x) => x,
306306
_ => bug!("from_const: invalid ByVal layout: {:#?}", layout)
307307
};
308-
primval_to_llvm(bcx.ccx, val, scalar, layout.immediate_llvm_type(bcx.ccx))
308+
primval_to_llvm(bx.cx, val, scalar, layout.immediate_llvm_type(bx.cx))
309309
},
310310
MiriValue::ByValPair(a_val, b_val) => {
311311
let (a_scalar, b_scalar) = match layout.abi {
312312
layout::Abi::ScalarPair(ref a, ref b) => (a, b),
313313
_ => bug!("from_const: invalid ByValPair layout: {:#?}", layout)
314314
};
315315
let a_llval = primval_to_llvm(
316-
bcx.ccx,
316+
bx.cx,
317317
a_val,
318318
a_scalar,
319-
layout.scalar_pair_element_llvm_type(bcx.ccx, 0),
319+
layout.scalar_pair_element_llvm_type(bx.cx, 0),
320320
);
321321
let b_llval = primval_to_llvm(
322-
bcx.ccx,
322+
bx.cx,
323323
b_val,
324324
b_scalar,
325-
layout.scalar_pair_element_llvm_type(bcx.ccx, 1),
325+
layout.scalar_pair_element_llvm_type(bx.cx, 1),
326326
);
327-
C_struct(bcx.ccx, &[a_llval, b_llval], false)
327+
C_struct(bx.cx, &[a_llval, b_llval], false)
328328
},
329329
MiriValue::ByRef(..) => {
330330
let field_ty = constant.ty.builtin_index().unwrap();
@@ -334,7 +334,7 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
334334
};
335335
let values: Result<Vec<ValueRef>, _> = (0..fields).map(|field| {
336336
let field = const_val_field(
337-
bcx.tcx(),
337+
bx.tcx(),
338338
ty::ParamEnv::empty(traits::Reveal::All),
339339
self.instance,
340340
None,
@@ -344,29 +344,29 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
344344
)?;
345345
match field.val {
346346
ConstVal::Value(MiriValue::ByVal(prim)) => {
347-
let layout = bcx.ccx.layout_of(field_ty);
347+
let layout = bx.cx.layout_of(field_ty);
348348
let scalar = match layout.abi {
349349
layout::Abi::Scalar(ref x) => x,
350350
_ => bug!("from_const: invalid ByVal layout: {:#?}", layout)
351351
};
352352
Ok(primval_to_llvm(
353-
bcx.ccx, prim, scalar,
354-
layout.immediate_llvm_type(bcx.ccx),
353+
bx.cx, prim, scalar,
354+
layout.immediate_llvm_type(bx.cx),
355355
))
356356
},
357357
other => bug!("simd shuffle field {:?}, {}", other, constant.ty),
358358
}
359359
}).collect();
360-
C_struct(bcx.ccx, &values?, false)
360+
C_struct(bx.cx, &values?, false)
361361
},
362362
};
363363
Ok((llval, constant.ty))
364364
})
365365
.unwrap_or_else(|e| {
366-
e.report(bcx.tcx(), constant.span, "shuffle_indices");
366+
e.report(bx.tcx(), constant.span, "shuffle_indices");
367367
// We've errored, so we don't have to produce working code.
368368
let ty = self.monomorphize(&constant.ty);
369-
let llty = bcx.ccx.layout_of(ty).llvm_type(bcx.ccx);
369+
let llty = bx.cx.layout_of(ty).llvm_type(bx.cx);
370370
(C_undef(llty), ty)
371371
})
372372
}

src/librustc_trans/mir/operand.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ impl<'a, 'tcx> OperandRef<'tcx> {
9393
}
9494
}
9595

96-
pub fn from_const(bcx: &Builder<'a, 'tcx>,
96+
pub fn from_const(bx: &Builder<'a, 'tcx>,
9797
miri_val: MiriValue,
9898
ty: ty::Ty<'tcx>)
9999
-> Result<OperandRef<'tcx>, ConstEvalErr<'tcx>> {
100-
let layout = bcx.ccx.layout_of(ty);
100+
let layout = bx.cx.layout_of(ty);
101101

102102
if layout.is_zst() {
103-
return Ok(OperandRef::new_zst(bcx.ccx, layout));
103+
return Ok(OperandRef::new_zst(bx.cx, layout));
104104
}
105105

106106
let val = match miri_val {
@@ -110,10 +110,10 @@ impl<'a, 'tcx> OperandRef<'tcx> {
110110
_ => bug!("from_const: invalid ByVal layout: {:#?}", layout)
111111
};
112112
let llval = primval_to_llvm(
113-
bcx.ccx,
113+
bx.cx,
114114
x,
115115
scalar,
116-
layout.immediate_llvm_type(bcx.ccx),
116+
layout.immediate_llvm_type(bx.cx),
117117
);
118118
OperandValue::Immediate(llval)
119119
},
@@ -123,16 +123,16 @@ impl<'a, 'tcx> OperandRef<'tcx> {
123123
_ => bug!("from_const: invalid ByValPair layout: {:#?}", layout)
124124
};
125125
let a_llval = primval_to_llvm(
126-
bcx.ccx,
126+
bx.cx,
127127
a,
128128
a_scalar,
129-
layout.scalar_pair_element_llvm_type(bcx.ccx, 0),
129+
layout.scalar_pair_element_llvm_type(bx.cx, 0),
130130
);
131131
let b_llval = primval_to_llvm(
132-
bcx.ccx,
132+
bx.cx,
133133
b,
134134
b_scalar,
135-
layout.scalar_pair_element_llvm_type(bcx.ccx, 1),
135+
layout.scalar_pair_element_llvm_type(bx.cx, 1),
136136
);
137137
OperandValue::Pair(a_llval, b_llval)
138138
},
@@ -142,12 +142,12 @@ impl<'a, 'tcx> OperandRef<'tcx> {
142142
valid_range: 0..=!0
143143
};
144144
let ptr = primval_to_llvm(
145-
bcx.ccx,
145+
bx.cx,
146146
ptr.into_inner_primval(),
147147
&scalar,
148-
layout.llvm_type(bcx.ccx).ptr_to(),
148+
layout.llvm_type(bx.cx).ptr_to(),
149149
);
150-
return Ok(PlaceRef::new_sized(ptr, layout, align).load(bcx));
150+
return Ok(PlaceRef::new_sized(ptr, layout, align).load(bx));
151151
},
152152
};
153153

0 commit comments

Comments
 (0)