@@ -93,10 +93,16 @@ tag cleanup {
93
93
clean( fn ( @block_ctxt cx) -> result) ;
94
94
}
95
95
96
+
97
+ tag block_kind {
98
+ SCOPE_BLOCK ;
99
+ NON_SCOPE_BLOCK ;
100
+ }
101
+
96
102
state type block_ctxt = rec ( BasicBlockRef llbb,
97
103
builder build,
98
104
block_parent parent,
99
- bool is_scope ,
105
+ block_kind kind ,
100
106
mutable vec[ cleanup] cleanups,
101
107
@fn_ctxt fcx) ;
102
108
@@ -640,7 +646,7 @@ fn trans_non_gc_free(@block_ctxt cx, ValueRef v) -> result {
640
646
}
641
647
642
648
fn find_scope_cx ( @block_ctxt cx ) -> @block_ctxt {
643
- if ( cx. is_scope ) {
649
+ if ( cx. kind == SCOPE_BLOCK ) {
644
650
ret cx;
645
651
}
646
652
alt ( cx. parent ) {
@@ -1492,8 +1498,13 @@ fn memcpy_ty(@block_ctxt cx,
1492
1498
}
1493
1499
}
1494
1500
1501
+ tag copy_action {
1502
+ INIT ;
1503
+ DROP_EXISTING;
1504
+ }
1505
+
1495
1506
fn copy_ty( @block_ctxt cx,
1496
- bool is_init ,
1507
+ copy_action action ,
1497
1508
ValueRef dst,
1498
1509
ValueRef src,
1499
1510
@ty. t t) -> result {
@@ -1505,15 +1516,15 @@ fn copy_ty(@block_ctxt cx,
1505
1516
1506
1517
} else if ( ty. type_is_boxed( t) ) {
1507
1518
auto r = incr_all_refcnts( cx, src, t) ;
1508
- if ( ! is_init ) {
1519
+ if ( action == DROP_EXISTING ) {
1509
1520
r = drop_ty( r. bcx, r. bcx. build. Load ( dst) , t) ;
1510
1521
}
1511
1522
ret res( r. bcx, r. bcx. build. Store ( src, dst) ) ;
1512
1523
1513
1524
} else if ( ty. type_is_structural( t) ||
1514
1525
ty. type_has_dynamic_size( t) ) {
1515
1526
auto r = incr_all_refcnts( cx, src, t) ;
1516
- if ( ! is_init ) {
1527
+ if ( action == DROP_EXISTING ) {
1517
1528
r = drop_ty( r. bcx, dst, t) ;
1518
1529
}
1519
1530
ret memcpy_ty( r. bcx, dst, src, t) ;
@@ -1623,7 +1634,7 @@ fn trans_unary(@block_ctxt cx, ast.unop op,
1623
1634
vec( C_int ( 0 ) ,
1624
1635
C_int ( abi. box_rc_field_body) ) ) ;
1625
1636
sub. bcx. build. Store ( C_int ( 1 ) , rc) ;
1626
- sub = copy_ty( sub. bcx, true , body, e_val, e_ty) ;
1637
+ sub = copy_ty( sub. bcx, INIT , body, e_val, e_ty) ;
1627
1638
ret res( sub. bcx, box) ;
1628
1639
}
1629
1640
case ( ast. deref) {
@@ -1815,7 +1826,7 @@ fn trans_for(@block_ctxt cx,
1815
1826
1816
1827
cx. build. Br ( scope_cx. llbb) ;
1817
1828
auto local_res = alloc_local( scope_cx, local) ;
1818
- auto bcx = copy_ty( local_res. bcx, true , local_res. val, curr, t) . bcx;
1829
+ auto bcx = copy_ty( local_res. bcx, INIT , local_res. val, curr, t) . bcx;
1819
1830
bcx = trans_block( bcx, body) . bcx;
1820
1831
bcx. build. Br ( next_cx. llbb) ;
1821
1832
ret res( next_cx, C_nil( ) ) ;
@@ -1955,7 +1966,7 @@ fn trans_pat_binding(@block_ctxt cx, @ast.pat pat, ValueRef llval)
1955
1966
cx. fcx. lllocals. insert( def_id, dst) ;
1956
1967
cx. cleanups += clean( bind drop_slot( _, dst, ty) ) ;
1957
1968
1958
- ret copy_ty( cx, true , dst, llval, ty) ;
1969
+ ret copy_ty( cx, INIT , dst, llval, ty) ;
1959
1970
}
1960
1971
case ( ast. pat_tag( _, ?subpats, _, _) ) {
1961
1972
if ( _vec. len[ @ast. pat] ( subpats) == 0 u) { ret res( cx, llval) ; }
@@ -2496,7 +2507,7 @@ fn trans_bind(@block_ctxt cx, @ast.expr f,
2496
2507
for ( ValueRef v in bound_vals) {
2497
2508
auto bound = bcx. build. GEP ( bindings,
2498
2509
vec( C_int ( 0 ) , C_int ( i) ) ) ;
2499
- bcx = copy_ty( r. bcx, true , bound, v, bound_tys. ( i) ) . bcx;
2510
+ bcx = copy_ty( r. bcx, INIT , bound, v, bound_tys. ( i) ) . bcx;
2500
2511
i += 1 ;
2501
2512
}
2502
2513
@@ -2608,7 +2619,7 @@ fn trans_tup(@block_ctxt cx, vec[ast.elt] elts,
2608
2619
auto t = ty. expr_ty( e. expr) ;
2609
2620
auto src_res = trans_expr( r. bcx, e. expr) ;
2610
2621
auto dst_elt = r. bcx. build. GEP ( tup_val, vec( C_int( 0 ) , C_int ( i) ) ) ;
2611
- r = copy_ty( src_res. bcx, true , dst_elt, src_res. val, t) ;
2622
+ r = copy_ty( src_res. bcx, INIT , dst_elt, src_res. val, t) ;
2612
2623
i += 1 ;
2613
2624
}
2614
2625
ret res( r. bcx, tup_val) ;
@@ -2645,7 +2656,7 @@ fn trans_vec(@block_ctxt cx, vec[@ast.expr] args,
2645
2656
for ( @ast. expr e in args) {
2646
2657
auto src_res = trans_expr( sub. bcx, e) ;
2647
2658
auto dst_elt = sub. bcx. build. GEP ( body, vec( C_int ( 0 ) , C_int ( i) ) ) ;
2648
- sub = copy_ty( src_res. bcx, true , dst_elt, src_res. val, unit_ty) ;
2659
+ sub = copy_ty( src_res. bcx, INIT , dst_elt, src_res. val, unit_ty) ;
2649
2660
i += 1 ;
2650
2661
}
2651
2662
auto fill = sub. bcx. build. GEP ( vec_val,
@@ -2668,7 +2679,7 @@ fn trans_rec(@block_ctxt cx, vec[ast.field] fields,
2668
2679
auto src_res = trans_expr( r. bcx, f. expr) ;
2669
2680
auto dst_elt = r. bcx. build. GEP ( rec_val, vec( C_int( 0 ) , C_int ( i) ) ) ;
2670
2681
// FIXME: calculate copy init-ness in typestate.
2671
- r = copy_ty( src_res. bcx, true , dst_elt, src_res. val, t) ;
2682
+ r = copy_ty( src_res. bcx, INIT , dst_elt, src_res. val, t) ;
2672
2683
i += 1 ;
2673
2684
}
2674
2685
ret res( r. bcx, rec_val) ;
@@ -2727,7 +2738,8 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
2727
2738
auto rhs_res = trans_expr( lhs_res. res. bcx, src) ;
2728
2739
auto t = node_ann_type( cx. fcx. ccx, ann) ;
2729
2740
// FIXME: calculate copy init-ness in typestate.
2730
- ret copy_ty( rhs_res. bcx, false , lhs_res. res. val, rhs_res. val, t) ;
2741
+ ret copy_ty( rhs_res. bcx, DROP_EXISTING ,
2742
+ lhs_res. res. val, rhs_res. val, t) ;
2731
2743
}
2732
2744
2733
2745
case ( ast. expr_assign_op( ?op, ?dst, ?src, ?ann) ) {
@@ -2739,7 +2751,8 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result {
2739
2751
auto rhs_res = trans_expr( lhs_res. res. bcx, src) ;
2740
2752
auto v = trans_eager_binop( rhs_res. bcx, op, lhs_val, rhs_res. val) ;
2741
2753
// FIXME: calculate copy init-ness in typestate.
2742
- ret copy_ty( rhs_res. bcx, false , lhs_res. res. val, v, t) ;
2754
+ ret copy_ty( rhs_res. bcx, DROP_EXISTING ,
2755
+ lhs_res. res. val, v, t) ;
2743
2756
}
2744
2757
2745
2758
case ( ast. expr_bind( ?f, ?args, ?ann) ) {
@@ -2889,7 +2902,7 @@ fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result {
2889
2902
alt ( cx. fcx. llretptr) {
2890
2903
case ( some[ ValueRef ] ( ?llptr) ) {
2891
2904
// Generic return via tydesc + retptr.
2892
- bcx = copy_ty( bcx, true , llptr, val, t) . bcx;
2905
+ bcx = copy_ty( bcx, INIT , llptr, val, t) . bcx;
2893
2906
bcx. build. RetVoid ( ) ;
2894
2907
}
2895
2908
case ( none[ ValueRef ] ) {
@@ -2921,7 +2934,7 @@ fn init_local(@block_ctxt cx, @ast.local local) -> result {
2921
2934
alt ( local. init) {
2922
2935
case ( some[ @ast. expr] ( ?e) ) {
2923
2936
auto sub = trans_expr( bcx, e) ;
2924
- bcx = copy_ty( sub. bcx, true , llptr, sub. val, ty) . bcx;
2937
+ bcx = copy_ty( sub. bcx, INIT , llptr, sub. val, ty) . bcx;
2925
2938
}
2926
2939
case ( _) {
2927
2940
if ( middle. ty. type_has_dynamic_size( ty) ) {
@@ -2983,7 +2996,7 @@ fn new_builder(BasicBlockRef llbb) -> builder {
2983
2996
// You probably don't want to use this one. See the
2984
2997
// next three functions instead.
2985
2998
fn new_block_ctxt( @fn_ctxt cx, block_parent parent,
2986
- bool is_scope ,
2999
+ block_kind kind ,
2987
3000
str name) -> @block_ctxt {
2988
3001
let vec[ cleanup] cleanups = vec( ) ;
2989
3002
let BasicBlockRef llbb =
@@ -2993,32 +3006,32 @@ fn new_block_ctxt(@fn_ctxt cx, block_parent parent,
2993
3006
ret @rec( llbb=llbb,
2994
3007
build=new_builder( llbb) ,
2995
3008
parent=parent,
2996
- is_scope=is_scope ,
3009
+ kind=kind ,
2997
3010
mutable cleanups=cleanups,
2998
3011
fcx=cx) ;
2999
3012
}
3000
3013
3001
3014
// Use this when you're at the top block of a function or the like.
3002
3015
fn new_top_block_ctxt( @fn_ctxt fcx) -> @block_ctxt {
3003
- ret new_block_ctxt( fcx, parent_none, true , "function top level" ) ;
3016
+ ret new_block_ctxt( fcx, parent_none, SCOPE_BLOCK , "function top level" ) ;
3004
3017
}
3005
3018
3006
3019
// Use this when you're at a curly-brace or similar lexical scope.
3007
3020
fn new_scope_block_ctxt( @block_ctxt bcx, str n) -> @block_ctxt {
3008
- ret new_block_ctxt( bcx. fcx, parent_some( bcx) , true , n) ;
3021
+ ret new_block_ctxt( bcx. fcx, parent_some( bcx) , SCOPE_BLOCK , n) ;
3009
3022
}
3010
3023
3011
3024
// Use this when you're making a general CFG BB within a scope.
3012
3025
fn new_sub_block_ctxt( @block_ctxt bcx, str n) -> @block_ctxt {
3013
- ret new_block_ctxt( bcx. fcx, parent_some( bcx) , false , n) ;
3026
+ ret new_block_ctxt( bcx. fcx, parent_some( bcx) , NON_SCOPE_BLOCK , n) ;
3014
3027
}
3015
3028
3016
3029
3017
3030
fn trans_block_cleanups( @block_ctxt cx,
3018
3031
@block_ctxt cleanup_cx) -> @block_ctxt {
3019
3032
auto bcx = cx;
3020
3033
3021
- if ( ! cleanup_cx. is_scope ) {
3034
+ if ( cleanup_cx. kind != SCOPE_BLOCK ) {
3022
3035
check ( _vec. len[ cleanup] ( cleanup_cx. cleanups) == 0 u) ;
3023
3036
}
3024
3037
@@ -3430,7 +3443,7 @@ fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
3430
3443
arg = load_scalar_or_boxed( r. bcx, arg, arg_tys. ( i) . ty) ;
3431
3444
auto field = r. bcx. build. GEP ( body_fields,
3432
3445
vec( C_int ( 0 ) , C_int ( i) ) ) ;
3433
- r = copy_ty( r. bcx, true , field, arg, arg_tys. ( i) . ty) ;
3446
+ r = copy_ty( r. bcx, INIT , field, arg, arg_tys. ( i) . ty) ;
3434
3447
i += 1 ;
3435
3448
}
3436
3449
0 commit comments