Skip to content

Commit 2895ec7

Browse files
committed
---
yaml --- r: 81719 b: refs/heads/master c: 89cc852 h: refs/heads/master i: 81717: 3de611a 81715: c9c8f57 81711: f97406f v: v3
1 parent 0a6b3e2 commit 2895ec7

File tree

5 files changed

+52
-32
lines changed

5 files changed

+52
-32
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 44997a127bb9acc1957d809a0e6cad190b75e491
2+
refs/heads/master: 89cc8529cc18802e4d7feb370e56809a1150b750
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6c08cc2db4f98e9f07ae7d50338396c4123c2f0a
55
refs/heads/try: 70152ff55722878cde684ee6462c14c65f2c4729

trunk/src/librustc/middle/trans/expr.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,36 @@ pub fn trans_to_datum(bcx: @mut Block, expr: @ast::Expr) -> DatumBlock {
313313
let target_obj_ty = expr_ty_adjusted(bcx, expr);
314314
debug!("auto_borrow_obj(target=%s)",
315315
target_obj_ty.repr(tcx));
316+
317+
// Extract source store information
318+
let (source_store, source_mutbl) = match ty::get(source_datum.ty).sty {
319+
ty::ty_trait(_, _, s, m, _) => (s, m),
320+
_ => {
321+
bcx.sess().span_bug(
322+
expr.span,
323+
fmt!("auto_borrow_trait_obj expected a trait, found %s",
324+
source_datum.ty.repr(bcx.tcx())));
325+
}
326+
};
327+
328+
// check if any borrowing is really needed or we could reuse the source_datum instead
329+
match ty::get(target_obj_ty).sty {
330+
ty::ty_trait(_, _, ty::RegionTraitStore(target_scope), target_mutbl, _) => {
331+
if target_mutbl == ast::MutImmutable && target_mutbl == source_mutbl {
332+
match source_store {
333+
ty::RegionTraitStore(source_scope) => {
334+
if tcx.region_maps.is_subregion_of(target_scope, source_scope) {
335+
return DatumBlock { bcx: bcx, datum: source_datum };
336+
}
337+
},
338+
_ => {}
339+
340+
};
341+
}
342+
},
343+
_ => {}
344+
}
345+
316346
let scratch = scratch_datum(bcx, target_obj_ty,
317347
"__auto_borrow_obj", false);
318348

@@ -331,15 +361,6 @@ pub fn trans_to_datum(bcx: @mut Block, expr: @ast::Expr) -> DatumBlock {
331361
// ~T, or &T, depending on source_obj_ty.
332362
let source_data_ptr = GEPi(bcx, source_llval, [0u, abi::trt_field_box]);
333363
let source_data = Load(bcx, source_data_ptr); // always a ptr
334-
let (source_store, source_mutbl) = match ty::get(source_datum.ty).sty {
335-
ty::ty_trait(_, _, s, m, _) => (s, m),
336-
_ => {
337-
bcx.sess().span_bug(
338-
expr.span,
339-
fmt!("auto_borrow_trait_obj expected a trait, found %s",
340-
source_datum.ty.repr(bcx.tcx())));
341-
}
342-
};
343364
let target_data = match source_store {
344365
ty::BoxTraitStore(*) => {
345366
// For deref of @T or @mut T, create a dummy datum and

trunk/src/librustc/middle/trans/meth.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,22 @@ pub fn trans_trait_callee(bcx: @mut Block,
434434
let _icx = push_ctxt("impl::trans_trait_callee");
435435
let mut bcx = bcx;
436436

437+
// make a local copy for trait if needed
437438
let self_ty = expr_ty_adjusted(bcx, self_expr);
438-
let self_scratch = scratch_datum(bcx, self_ty, "__trait_callee", false);
439-
bcx = expr::trans_into(bcx, self_expr, expr::SaveIn(self_scratch.val));
439+
let self_scratch = match ty::get(self_ty).sty {
440+
ty::ty_trait(_, _, ty::RegionTraitStore(*), _, _) => {
441+
unpack_datum!(bcx, expr::trans_to_datum(bcx, self_expr))
442+
}
443+
_ => {
444+
let d = scratch_datum(bcx, self_ty, "__trait_callee", false);
445+
bcx = expr::trans_into(bcx, self_expr, expr::SaveIn(d.val));
446+
// Arrange a temporary cleanup for the object in case something
447+
// should go wrong before the method is actually *invoked*.
448+
d.add_clean(bcx);
449+
d
450+
}
451+
};
440452

441-
// Arrange a temporary cleanup for the object in case something
442-
// should go wrong before the method is actually *invoked*.
443-
self_scratch.add_clean(bcx);
444453

445454
let callee_ty = node_id_type(bcx, callee_id);
446455
trans_trait_callee_from_llval(bcx,

trunk/src/librustc/middle/trans/type_.rs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -278,23 +278,12 @@ impl Type {
278278

279279
pub fn opaque_trait(ctx: &CrateContext, store: ty::TraitStore) -> Type {
280280
let tydesc_ptr = ctx.tydesc_type.ptr_to();
281-
match store {
282-
ty::BoxTraitStore => {
283-
Type::struct_(
284-
[ tydesc_ptr, Type::opaque_box(ctx).ptr_to() ],
285-
false)
286-
}
287-
ty::UniqTraitStore => {
288-
Type::struct_(
289-
[ tydesc_ptr, Type::unique(ctx, &Type::i8()).ptr_to()],
290-
false)
291-
}
292-
ty::RegionTraitStore(*) => {
293-
Type::struct_(
294-
[ tydesc_ptr, Type::i8().ptr_to() ],
295-
false)
296-
}
297-
}
281+
let box_ty = match store {
282+
ty::BoxTraitStore => Type::opaque_box(ctx),
283+
ty::UniqTraitStore => Type::unique(ctx, &Type::i8()),
284+
ty::RegionTraitStore(*) => Type::i8()
285+
};
286+
Type::struct_([tydesc_ptr, box_ty.ptr_to()], false)
298287
}
299288

300289
pub fn kind(&self) -> TypeKind {

trunk/src/test/run-pass/core-run-destroy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ fn test_destroy_actually_kills(force: bool) {
5555

5656
#[cfg(windows)]
5757
fn process_exists(pid: libc::pid_t) -> bool {
58+
#[fixed_stack_segment];
5859

5960
use std::libc::types::os::arch::extra::DWORD;
6061
use std::libc::funcs::extra::kernel32::{CloseHandle, GetExitCodeProcess, OpenProcess};

0 commit comments

Comments
 (0)