@@ -2481,7 +2481,6 @@ fn join_branches(parent_cx: @block_ctxt, ins: [result]) -> @block_ctxt {
2481
2481
2482
2482
tag dest {
2483
2483
by_val( @mutable ValueRef ) ;
2484
- by_ref ( @mutable ValueRef ) ;
2485
2484
save_in ( ValueRef ) ;
2486
2485
ignore;
2487
2486
}
@@ -2493,7 +2492,6 @@ fn empty_dest_cell() -> @mutable ValueRef {
2493
2492
fn dup_for_join ( dest : dest ) -> dest {
2494
2493
alt dest {
2495
2494
by_val( _) { by_val ( empty_dest_cell ( ) ) }
2496
- by_ref ( _) { by_ref ( empty_dest_cell ( ) ) }
2497
2495
_ { dest }
2498
2496
}
2499
2497
}
@@ -2507,7 +2505,7 @@ fn join_returns(parent_cx: @block_ctxt, in_cxs: [@block_ctxt],
2507
2505
Br ( cx, out. llbb ) ;
2508
2506
reachable = true ;
2509
2507
alt in_ds[ i] {
2510
- by_val ( cell) | by_ref ( cell ) {
2508
+ by_val ( cell) {
2511
2509
if option:: is_none ( phi) {
2512
2510
phi = some ( EmptyPhi ( out, val_ty ( * cell) ) ) ;
2513
2511
}
@@ -2522,7 +2520,7 @@ fn join_returns(parent_cx: @block_ctxt, in_cxs: [@block_ctxt],
2522
2520
Unreachable ( out) ;
2523
2521
} else {
2524
2522
alt out_dest {
2525
- by_val( cell) | by_ref ( cell ) { * cell = option:: get ( phi) ; }
2523
+ by_val( cell) { * cell = option:: get ( phi) ; }
2526
2524
_ { }
2527
2525
}
2528
2526
}
@@ -3333,7 +3331,7 @@ fn trans_lval(cx: @block_ctxt, e: @ast::expr) -> lval_result {
3333
3331
// A by-ref returning function
3334
3332
if expr_is_lval ( bcx_tcx ( cx) , e) {
3335
3333
let cell = empty_dest_cell ( ) ;
3336
- let bcx = trans_call ( cx, f, none, args, e. id , by_ref ( cell) ) ;
3334
+ let bcx = trans_call ( cx, f, none, args, e. id , by_val ( cell) ) ;
3337
3335
ret lval_mem( bcx, * cell) ;
3338
3336
} else { // By-value return
3339
3337
let { bcx, val} = dps_to_result ( cx, { |bcx, dest|
@@ -3799,7 +3797,8 @@ fn trans_args(cx: @block_ctxt, outer_cx: @block_ctxt, llenv: ValueRef,
3799
3797
args : [ ValueRef ] ,
3800
3798
retslot : ValueRef ,
3801
3799
to_zero : [ { v : ValueRef , t : ty:: t } ] ,
3802
- to_revoke : [ { v : ValueRef , t : ty:: t } ] } {
3800
+ to_revoke : [ { v : ValueRef , t : ty:: t } ] ,
3801
+ ret_ref : bool } {
3803
3802
3804
3803
let args: [ ty:: arg ] = ty:: ty_fn_args ( bcx_tcx ( cx) , fn_ty) ;
3805
3804
let llargs: [ ValueRef ] = [ ] ;
@@ -3825,19 +3824,20 @@ fn trans_args(cx: @block_ctxt, outer_cx: @block_ctxt, llenv: ValueRef,
3825
3824
}
3826
3825
// Arg 0: Output pointer.
3827
3826
let llretty = type_of_or_i8 ( bcx, full_retty) ;
3828
- let dest_ref = false ;
3829
- let llretslot = alt dest {
3830
- ignore. {
3831
- if ty:: type_is_nil ( tcx, full_retty) || !option:: is_none ( lliterbody) {
3832
- llvm:: LLVMGetUndef ( T_ptr ( llretty) )
3833
- } else { alloca ( cx, llretty) }
3834
- }
3835
- save_in ( dst) { dst }
3836
- by_val ( _) { alloca ( cx, llretty) }
3837
- by_ref ( _) { dest_ref = true ; alloca ( cx, T_ptr ( llretty) ) }
3827
+ let llretslot = if ret_ref {
3828
+ alloca ( cx, T_ptr ( llretty) )
3829
+ } else {
3830
+ alt dest {
3831
+ ignore. {
3832
+ if ty:: type_is_nil ( tcx, full_retty) ||
3833
+ !option:: is_none ( lliterbody) {
3834
+ llvm:: LLVMGetUndef ( T_ptr ( llretty) )
3835
+ } else { alloca ( cx, llretty) }
3836
+ }
3837
+ save_in ( dst) { dst }
3838
+ by_val ( _) { alloca ( cx, llretty) }
3839
+ }
3838
3840
} ;
3839
- // FIXME[DSP] does this always hold?
3840
- assert dest_ref == ret_ref;
3841
3841
3842
3842
if ty:: type_contains_params ( tcx, retty) {
3843
3843
// It's possible that the callee has some generic-ness somewhere in
@@ -3898,7 +3898,8 @@ fn trans_args(cx: @block_ctxt, outer_cx: @block_ctxt, llenv: ValueRef,
3898
3898
args : llargs,
3899
3899
retslot : llretslot,
3900
3900
to_zero : to_zero,
3901
- to_revoke : to_revoke} ;
3901
+ to_revoke : to_revoke,
3902
+ ret_ref : ret_ref} ;
3902
3903
}
3903
3904
3904
3905
fn trans_call ( in_cx : @block_ctxt , f : @ast:: expr ,
@@ -3953,12 +3954,13 @@ fn trans_call(in_cx: @block_ctxt, f: @ast::expr,
3953
3954
args_res. to_revoke ) ;
3954
3955
alt dest {
3955
3956
ignore. {
3956
- if llvm:: LLVMIsUndef ( llretslot) != lib:: llvm:: True {
3957
+ if llvm:: LLVMIsUndef ( llretslot) != lib:: llvm:: True &&
3958
+ !args_res. ret_ref {
3957
3959
bcx = drop_ty ( bcx, llretslot, ret_ty) ;
3958
3960
}
3959
3961
}
3960
3962
save_in ( _) { } // Already saved by callee
3961
- by_ref ( cell ) | by_val ( cell) {
3963
+ by_val ( cell) {
3962
3964
* cell = Load ( bcx, llretslot) ;
3963
3965
}
3964
3966
}
@@ -4278,13 +4280,6 @@ fn trans_temp_expr(bcx: @block_ctxt, e: @ast::expr) -> lval_result {
4278
4280
}
4279
4281
}
4280
4282
4281
- // FIXME[DPS] supersede by trans_temp_expr, get rid of by_ref dests
4282
- fn trans_expr_by_ref ( bcx : @block_ctxt , e : @ast:: expr ) -> result {
4283
- let cell = empty_dest_cell ( ) ;
4284
- bcx = trans_expr_dps ( bcx, e, by_ref ( cell) ) ;
4285
- ret rslt( bcx, * cell) ;
4286
- }
4287
-
4288
4283
// Invariants:
4289
4284
// - things returning nil get dest=ignore
4290
4285
// - any lvalue expr may be given dest=by_ref
@@ -4476,10 +4471,6 @@ fn lval_to_dps(bcx: @block_ctxt, e: @ast::expr, dest: dest) -> @block_ctxt {
4476
4471
* cell = Load ( bcx, val) ;
4477
4472
}
4478
4473
}
4479
- by_ref ( cell) {
4480
- assert is_mem;
4481
- * cell = val;
4482
- }
4483
4474
save_in ( loc) { bcx = move_val_if_temp ( bcx, INIT , loc, lv, ty) ; }
4484
4475
ignore. { }
4485
4476
}
@@ -4728,7 +4719,8 @@ fn trans_ret(bcx: @block_ctxt, e: option::t<@ast::expr>) -> @block_ctxt {
4728
4719
alt e {
4729
4720
some( x) {
4730
4721
if ast_util:: ret_by_ref ( bcx. fcx . ret_style ) {
4731
- let { bcx: cx , val } = trans_expr_by_ref ( bcx, x) ;
4722
+ let { bcx: cx , val , is_mem } = trans_lval ( bcx, x) ;
4723
+ assert is_mem;
4732
4724
Store ( cx, val, bcx. fcx . llretptr ) ;
4733
4725
bcx = cx;
4734
4726
} else {
0 commit comments