@@ -1327,8 +1327,9 @@ fn make_take_glue(cx: @block_ctxt, v: ValueRef, t: ty::t) {
1327
1327
} else if ty:: type_is_structural ( bcx_tcx ( bcx) , t) {
1328
1328
bcx = iter_structural_ty ( bcx, v, t, take_ty) ;
1329
1329
} else if ty:: type_is_vec ( bcx_tcx ( bcx) , t) {
1330
- bcx = tvec:: duplicate ( bcx, v) ;
1331
- bcx = tvec:: iter_vec ( bcx, v, t, take_ty) ;
1330
+ let { bcx: cx , val } = tvec:: duplicate ( bcx, Load ( bcx, v) , t) ;
1331
+ bcx = cx;
1332
+ Store ( bcx, val, v) ;
1332
1333
}
1333
1334
1334
1335
build_return ( bcx) ;
@@ -1361,6 +1362,9 @@ fn make_free_glue(bcx: @block_ctxt, v: ValueRef, t: ty::t) {
1361
1362
v = PointerCast ( bcx, v, type_of_1 ( bcx, t) ) ;
1362
1363
trans_uniq:: make_free_glue ( bcx, v, t)
1363
1364
}
1365
+ ty:: ty_vec ( _) | ty:: ty_str. {
1366
+ tvec:: make_free_glue ( bcx, PointerCast ( bcx, v, type_of_1 ( bcx, t) ) , t)
1367
+ }
1364
1368
ty:: ty_obj ( _) {
1365
1369
// Call through the obj's own fields-drop glue first.
1366
1370
// Then free the body.
@@ -1404,10 +1408,10 @@ fn make_drop_glue(bcx: @block_ctxt, v0: ValueRef, t: ty::t) {
1404
1408
let ccx = bcx_ccx ( bcx) ;
1405
1409
let bcx =
1406
1410
alt ty:: struct ( ccx. tcx , t) {
1407
- ty:: ty_vec ( _) { tvec:: make_drop_glue ( bcx, v0, t) }
1408
- ty:: ty_str. { tvec:: make_drop_glue ( bcx, v0, t) }
1409
1411
ty:: ty_box ( _) { decr_refcnt_maybe_free ( bcx, Load ( bcx, v0) , t) }
1410
- ty:: ty_uniq ( _) { free_ty ( bcx, Load ( bcx, v0) , t) }
1412
+ ty:: ty_uniq ( _) | ty:: ty_vec ( _) | ty:: ty_str. {
1413
+ free_ty ( bcx, Load ( bcx, v0) , t)
1414
+ }
1411
1415
ty:: ty_obj ( _) {
1412
1416
let box_cell =
1413
1417
GEP ( bcx, v0, [ C_int ( 0 ) , C_int ( abi:: obj_field_box) ] ) ;
@@ -1958,8 +1962,10 @@ fn drop_ty(cx: @block_ctxt, v: ValueRef, t: ty::t) -> @block_ctxt {
1958
1962
1959
1963
fn drop_ty_immediate ( bcx : @block_ctxt , v : ValueRef , t : ty:: t ) -> @block_ctxt {
1960
1964
alt ty:: struct ( bcx_tcx ( bcx) , t) {
1965
+ ty:: ty_uniq ( _) | ty:: ty_vec ( _) | ty:: ty_str. {
1966
+ ret free_ty ( bcx, v, t) ;
1967
+ }
1961
1968
ty:: ty_box ( _) { ret decr_refcnt_maybe_free ( bcx, v, t) ; }
1962
- ty:: ty_uniq ( _) { ret free_ty ( bcx, v, t) ; }
1963
1969
// FIXME A ty_ptr pointing at something that needs drop glue is somehow
1964
1970
// marked as needing drop glue. This is probably a mistake.
1965
1971
ty:: ty_ptr ( _) { ret bcx; }
@@ -1973,6 +1979,7 @@ fn take_ty_immediate(bcx: @block_ctxt, v: ValueRef, t: ty::t) -> result {
1973
1979
check trans_uniq:: type_is_unique_box ( bcx, t) ;
1974
1980
ret trans_uniq:: duplicate ( bcx, v, t) ;
1975
1981
}
1982
+ ty:: ty_str. | ty:: ty_vec ( _) { ret tvec:: duplicate ( bcx, v, t) ; }
1976
1983
_ { ret rslt( bcx, v) ; }
1977
1984
}
1978
1985
}
@@ -2068,30 +2075,32 @@ fn copy_val(cx: @block_ctxt, action: copy_action, dst: ValueRef,
2068
2075
ret copy_val_no_check ( cx, action, dst, src, t) ;
2069
2076
}
2070
2077
2071
- fn copy_val_no_check ( cx : @block_ctxt , action : copy_action , dst : ValueRef ,
2078
+ fn copy_val_no_check ( bcx : @block_ctxt , action : copy_action , dst : ValueRef ,
2072
2079
src : ValueRef , t : ty:: t ) -> @block_ctxt {
2073
- let ccx = bcx_ccx ( cx ) ;
2080
+ let ccx = bcx_ccx ( bcx ) ;
2074
2081
if ty:: type_is_scalar ( ccx. tcx , t) || ty:: type_is_native ( ccx. tcx , t) {
2075
- Store ( cx , src, dst) ;
2076
- ret cx ;
2082
+ Store ( bcx , src, dst) ;
2083
+ ret bcx ;
2077
2084
}
2078
- if ty:: type_is_nil ( ccx. tcx , t) || ty:: type_is_bot ( ccx. tcx , t) { ret cx ; }
2085
+ if ty:: type_is_nil ( ccx. tcx , t) || ty:: type_is_bot ( ccx. tcx , t) { ret bcx ; }
2079
2086
if ty:: type_is_boxed ( ccx. tcx , t) {
2080
- let bcx = cx;
2081
- if action == DROP_EXISTING { bcx = drop_ty ( cx, dst, t) ; }
2087
+ if action == DROP_EXISTING { bcx = drop_ty ( bcx, dst, t) ; }
2082
2088
Store ( bcx, src, dst) ;
2083
2089
ret take_ty( bcx, dst, t) ;
2084
2090
}
2091
+ if ty:: type_is_vec ( ccx. tcx , t) {
2092
+ if action == DROP_EXISTING { bcx = drop_ty ( bcx, dst, t) ; }
2093
+ let { bcx, val} = tvec:: duplicate ( bcx, src, t) ;
2094
+ Store ( bcx, val, dst) ;
2095
+ ret bcx;
2096
+ }
2085
2097
if ty:: type_is_unique_box ( ccx. tcx , t) {
2086
- let bcx = cx;
2087
- if action == DROP_EXISTING { bcx = drop_ty ( cx, dst, t) ; }
2098
+ if action == DROP_EXISTING { bcx = drop_ty ( bcx, dst, t) ; }
2088
2099
check trans_uniq:: type_is_unique_box ( bcx, t) ;
2089
2100
ret trans_uniq:: copy_val ( bcx, dst, src, t) ;
2090
2101
}
2091
- if type_is_structural_or_param ( ccx. tcx , t) || ty:: type_is_vec ( ccx. tcx , t)
2092
- {
2093
- let bcx = cx;
2094
- if action == DROP_EXISTING { bcx = drop_ty ( cx, dst, t) ; }
2102
+ if type_is_structural_or_param ( ccx. tcx , t) {
2103
+ if action == DROP_EXISTING { bcx = drop_ty ( bcx, dst, t) ; }
2095
2104
bcx = memmove_ty ( bcx, dst, src, t) ;
2096
2105
ret take_ty( bcx, dst, t) ;
2097
2106
}
@@ -2115,15 +2124,14 @@ fn move_val(cx: @block_ctxt, action: copy_action, dst: ValueRef,
2115
2124
ret cx;
2116
2125
} else if ty:: type_is_nil ( tcx, t) || ty:: type_is_bot ( tcx, t) {
2117
2126
ret cx;
2118
- } else if ty:: type_is_boxed ( tcx, t) || ty:: type_is_unique_box ( tcx, t) {
2127
+ } else if ty:: type_is_boxed ( tcx, t) || ty:: type_is_unique ( tcx, t) {
2119
2128
if src. kind == owned { src_val = Load ( cx, src_val) ; }
2120
2129
if action == DROP_EXISTING { cx = drop_ty ( cx, dst, t) ; }
2121
2130
Store ( cx, src_val, dst) ;
2122
2131
if src. kind == owned { ret zero_alloca ( cx, src. val , t) ; }
2123
2132
// If we're here, it must be a temporary.
2124
2133
ret revoke_clean ( cx, src_val) ;
2125
- } else if ty:: type_is_unique ( tcx, t) ||
2126
- type_is_structural_or_param ( tcx, t) {
2134
+ } else if type_is_structural_or_param ( tcx, t) {
2127
2135
if action == DROP_EXISTING { cx = drop_ty ( cx, dst, t) ; }
2128
2136
cx = memmove_ty ( cx, dst, src_val, t) ;
2129
2137
if src. kind == owned { ret zero_alloca ( cx, src_val, t) ; }
@@ -2270,6 +2278,7 @@ fn trans_expr_fn(bcx: @block_ctxt, f: ast::_fn, sp: span,
2270
2278
let upvars = get_freevars ( ccx. tcx , id) ;
2271
2279
let env_r = build_closure ( bcx, upvars, copying) ;
2272
2280
env = env_r. ptr ;
2281
+ bcx = env_r. bcx ;
2273
2282
trans_closure ( sub_cx, sp, f, llfn, none, [ ] , id, { |fcx|
2274
2283
load_environment ( bcx, fcx, env_r. ptrty , upvars, copying) ;
2275
2284
} ) ;
@@ -2600,14 +2609,13 @@ fn trans_for(cx: @block_ctxt, local: @ast::local, seq: @ast::expr,
2600
2609
let next_cx = new_sub_block_ctxt ( cx, "next" ) ;
2601
2610
let seq_ty = ty:: expr_ty ( bcx_tcx ( cx) , seq) ;
2602
2611
let { bcx: bcx , val : seq } = trans_temp_expr ( cx, seq) ;
2603
- let seq = PointerCast ( bcx, seq, T_ptr ( T_ptr ( T_opaque_vec ( ) ) ) ) ;
2612
+ let seq = PointerCast ( bcx, seq, T_ptr ( T_opaque_vec ( ) ) ) ;
2604
2613
let fill = tvec:: get_fill ( bcx, seq) ;
2605
2614
if ty:: type_is_str ( bcx_tcx ( bcx) , seq_ty) {
2606
2615
fill = Sub ( bcx, fill, C_int ( 1 ) ) ;
2607
2616
}
2608
- let bcx =
2609
- tvec:: iter_vec_raw ( bcx, seq, seq_ty, fill,
2610
- bind inner ( _, local, _, _, body, next_cx) ) ;
2617
+ let bcx = tvec:: iter_vec_raw ( bcx, seq, seq_ty, fill,
2618
+ bind inner ( _, local, _, _, body, next_cx) ) ;
2611
2619
Br ( bcx, next_cx. llbb ) ;
2612
2620
ret next_cx;
2613
2621
}
@@ -3183,15 +3191,14 @@ fn trans_rec_field(bcx: @block_ctxt, base: @ast::expr,
3183
3191
fn trans_index ( cx : @block_ctxt , sp : span , base : @ast:: expr , idx : @ast:: expr ,
3184
3192
id : ast:: node_id ) -> lval_result {
3185
3193
// Is this an interior vector?
3186
-
3187
3194
let base_ty = ty:: expr_ty ( bcx_tcx ( cx) , base) ;
3188
3195
let exp = trans_temp_expr ( cx, base) ;
3189
3196
let lv = autoderef ( exp. bcx , exp. val , base_ty) ;
3190
3197
let ix = trans_temp_expr ( lv. bcx , idx) ;
3191
3198
let v = lv. val ;
3192
3199
let bcx = ix. bcx ;
3193
- // Cast to an LLVM integer. Rust is less strict than LLVM in this regard.
3194
3200
3201
+ // Cast to an LLVM integer. Rust is less strict than LLVM in this regard.
3195
3202
let ix_val;
3196
3203
let ix_size = llsize_of_real ( bcx_ccx ( cx) , val_ty ( ix. val ) ) ;
3197
3204
let int_size = llsize_of_real ( bcx_ccx ( cx) , T_int ( ) ) ;
@@ -3200,6 +3207,7 @@ fn trans_index(cx: @block_ctxt, sp: span, base: @ast::expr, idx: @ast::expr,
3200
3207
} else if ix_size > int_size {
3201
3208
ix_val = Trunc ( bcx, ix. val , T_int ( ) ) ;
3202
3209
} else { ix_val = ix. val ; }
3210
+
3203
3211
let unit_ty = node_id_type ( bcx_ccx ( cx) , id) ;
3204
3212
let unit_sz = size_of ( bcx, unit_ty) ;
3205
3213
bcx = unit_sz. bcx ;
@@ -4444,18 +4452,11 @@ fn lval_to_dps(bcx: @block_ctxt, e: @ast::expr, dest: dest) -> @block_ctxt {
4444
4452
if kind == temporary {
4445
4453
revoke_clean ( bcx, val) ;
4446
4454
* cell = val;
4447
- } else if kind == owned_imm {
4455
+ } else if ty:: type_is_immediate ( bcx_tcx ( bcx) , ty) {
4456
+ if kind == owned { val = Load ( bcx, val) ; }
4448
4457
let { bcx: cx , val } = take_ty_immediate ( bcx, val, ty) ;
4449
4458
* cell = val;
4450
4459
bcx = cx;
4451
- } else if ty:: type_is_unique ( bcx_tcx ( bcx) , ty) {
4452
- // FIXME make vectors immediate again, lose this hack
4453
- // Do a song and a dance to work around the fact that take_ty
4454
- // for unique boxes overwrites the pointer.
4455
- let oldval = Load ( bcx, val) ;
4456
- bcx = take_ty ( bcx, val, ty) ;
4457
- * cell = Load ( bcx, val) ;
4458
- Store ( bcx, oldval, val) ;
4459
4460
} else {
4460
4461
bcx = take_ty ( bcx, val, ty) ;
4461
4462
* cell = Load ( bcx, val) ;
@@ -5469,21 +5470,13 @@ fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id,
5469
5470
// If this argument to this function is a tag, it'll have come in to
5470
5471
// this function as an opaque blob due to the way that type_of()
5471
5472
// works. So we have to cast to the destination's view of the type.
5472
-
5473
- let llargptr = alt fcx. llargs . find ( va. id ) {
5474
- some ( local_mem ( x) ) { PointerCast ( bcx, x, val_ty ( lldestptr) ) }
5475
- } ;
5473
+ let llarg = alt fcx. llargs . find ( va. id ) { some ( local_mem ( x) ) { x } } ;
5476
5474
let arg_ty = arg_tys[ i] . ty ;
5477
- let llargval;
5478
- if ty:: type_is_structural ( cx. ccx . tcx , arg_ty) ||
5479
- ty:: type_has_dynamic_size ( cx. ccx . tcx , arg_ty) ||
5480
- ( ty:: type_is_unique ( cx. ccx . tcx , arg_ty)
5481
- && !ty:: type_is_unique_box ( cx. ccx . tcx , arg_ty) ) {
5482
- // FIXME: Why do we do this for other unique pointer types but not
5483
- // unique boxes? Something's not quite right.
5484
- llargval = llargptr;
5485
- } else { llargval = Load ( bcx, llargptr) ; }
5486
- bcx = copy_val ( bcx, INIT , lldestptr, llargval, arg_ty) ;
5475
+ if ty:: type_contains_params ( bcx_tcx ( bcx) , arg_ty) {
5476
+ lldestptr = PointerCast ( bcx, lldestptr, val_ty ( llarg) ) ;
5477
+ }
5478
+ llarg = load_if_immediate ( bcx, llarg, arg_ty) ;
5479
+ bcx = copy_val ( bcx, INIT , lldestptr, llarg, arg_ty) ;
5487
5480
i += 1 u;
5488
5481
}
5489
5482
bcx = trans_block_cleanups ( bcx, find_scope_cx ( bcx) ) ;
@@ -5899,9 +5892,6 @@ fn register_native_fn(ccx: @crate_ctxt, sp: span, path: [str], name: str,
5899
5892
let i = arg_n;
5900
5893
for arg: ty:: arg in args {
5901
5894
let llarg = llvm:: LLVMGetParam ( fcx. llfn , i) ;
5902
- if arg. mode == ast:: by_ref {
5903
- llarg = load_if_immediate ( bcx, llarg, arg. ty ) ;
5904
- }
5905
5895
assert ( llarg as int != 0 ) ;
5906
5896
if cast_to_i32 {
5907
5897
let llarg_i32 = convert_arg_to_i32 ( bcx, llarg, arg. ty , arg. mode ) ;
0 commit comments