@@ -23,6 +23,7 @@ import std::option::some;
23
23
import std:: option:: none;
24
24
import std:: fs;
25
25
import std:: time;
26
+ import std:: vec;
26
27
import syntax:: ast;
27
28
import driver:: session;
28
29
import middle:: ty;
@@ -901,7 +902,7 @@ fn trans_malloc_boxed(cx: &@block_ctxt, t: ty::t) ->
901
902
fn field_of_tydesc ( cx : & @block_ctxt , t : & ty:: t , escapes : bool , field : int ) ->
902
903
result {
903
904
let ti = none :: < @tydesc_info > ;
904
- let tydesc = get_tydesc ( cx, t, escapes, ti) ;
905
+ let tydesc = get_tydesc ( cx, t, escapes, ti) . result ;
905
906
ret rslt( tydesc. bcx ,
906
907
tydesc. bcx . build . GEP ( tydesc. val , ~[ C_int ( 0 ) , C_int ( field) ] ) ) ;
907
908
}
@@ -1028,16 +1029,19 @@ fn get_derived_tydesc(cx: &@block_ctxt, t: &ty::t, escapes: bool,
1028
1029
ret rslt( cx, v) ;
1029
1030
}
1030
1031
1032
+ type get_tydesc_result = { kind : tydesc_kind , result : result } ;
1033
+
1031
1034
fn get_tydesc ( cx : & @block_ctxt , orig_t : & ty:: t , escapes : bool ,
1032
- static_ti : & mutable option:: t < @tydesc_info > ) -> result {
1035
+ static_ti : & mutable option:: t < @tydesc_info > )
1036
+ -> get_tydesc_result {
1033
1037
1034
1038
let t = ty:: strip_cname ( bcx_tcx ( cx) , orig_t) ;
1035
1039
1036
1040
// Is the supplied type a type param? If so, return the passed-in tydesc.
1037
1041
alt ty:: type_param ( bcx_tcx ( cx) , t) {
1038
1042
some ( id) {
1039
- if id < std :: vec:: len ( cx. fcx . lltydescs ) {
1040
- ret rslt ( cx, cx. fcx . lltydescs . ( id) ) ;
1043
+ if id < vec:: len ( cx. fcx . lltydescs ) {
1044
+ ret { kind : tk_param , result : rslt ( cx, cx. fcx . lltydescs . ( id) ) } ;
1041
1045
}
1042
1046
else {
1043
1047
bcx_tcx ( cx) . sess . span_bug ( cx. sp , "Unbound typaram in get_tydesc: "
@@ -1050,13 +1054,16 @@ fn get_tydesc(cx: &@block_ctxt, orig_t: &ty::t, escapes: bool,
1050
1054
1051
1055
// Does it contain a type param? If so, generate a derived tydesc.
1052
1056
if ty:: type_contains_params ( bcx_tcx ( cx) , t) {
1053
- ret get_derived_tydesc ( cx, t, escapes, static_ti) ;
1057
+ ret {
1058
+ kind : tk_derived,
1059
+ result : get_derived_tydesc ( cx, t, escapes, static_ti)
1060
+ } ;
1054
1061
}
1055
1062
1056
1063
// Otherwise, generate a tydesc if necessary, and return it.
1057
1064
let info = get_static_tydesc ( cx, t, ~[ ] ) ;
1058
1065
static_ti = some :: < @tydesc_info > ( info) ;
1059
- ret rslt( cx, info. tydesc ) ;
1066
+ ret { kind : tk_static , result : rslt ( cx, info. tydesc ) } ;
1060
1067
}
1061
1068
1062
1069
fn get_static_tydesc ( cx : & @block_ctxt , orig_t : & ty:: t , ty_params : & [ uint ] ) ->
@@ -1484,9 +1491,9 @@ fn trans_res_drop(cx: @block_ctxt, rs: ValueRef, did: &ast::def_id,
1484
1491
cx. build . Load ( cx. build . GEP ( dtor_pair,
1485
1492
~[ C_int ( 0 ) , C_int ( abi:: fn_field_box) ] ) ) ;
1486
1493
let args = ~[ cx. fcx . llretptr , cx. fcx . lltaskptr , dtor_env] ;
1487
- for tp: ty:: t in tps {
1494
+ for tp: ty:: t in tps {
1488
1495
let ti: option:: t < @tydesc_info > = none;
1489
- let td = get_tydesc ( cx, tp, false , ti) ;
1496
+ let td = get_tydesc ( cx, tp, false , ti) . result ;
1490
1497
args += ~[ td. val ] ;
1491
1498
cx = td. bcx ;
1492
1499
}
@@ -2130,7 +2137,7 @@ fn call_tydesc_glue_full(cx: &@block_ctxt, v: ValueRef, tydesc: ValueRef,
2130
2137
fn call_tydesc_glue ( cx : & @block_ctxt , v : ValueRef , t : & ty:: t , field : int ) ->
2131
2138
result {
2132
2139
let ti: option:: t < @tydesc_info > = none :: < @tydesc_info > ;
2133
- let td = get_tydesc ( cx, t, false , ti) ;
2140
+ let td = get_tydesc ( cx, t, false , ti) . result ;
2134
2141
call_tydesc_glue_full ( td. bcx , spill_if_immediate ( td. bcx , v, t) , td. val ,
2135
2142
field, ti) ;
2136
2143
ret rslt( td. bcx , C_nil ( ) ) ;
@@ -2146,7 +2153,7 @@ fn call_cmp_glue(cx: &@block_ctxt, lhs: ValueRef, rhs: ValueRef, t: &ty::t,
2146
2153
let llrawlhsptr = cx. build . BitCast ( lllhs, T_ptr ( T_i8 ( ) ) ) ;
2147
2154
let llrawrhsptr = cx. build . BitCast ( llrhs, T_ptr ( T_i8 ( ) ) ) ;
2148
2155
let ti = none :: < @tydesc_info > ;
2149
- let r = get_tydesc ( cx, t, false , ti) ;
2156
+ let r = get_tydesc ( cx, t, false , ti) . result ;
2150
2157
lazily_emit_tydesc_glue ( cx, abi:: tydesc_field_cmp_glue, ti) ;
2151
2158
let lltydesc = r. val ;
2152
2159
let lltydescs =
@@ -2561,10 +2568,10 @@ fn trans_vec_append(cx: &@block_ctxt, t: &ty::t, lhs: ValueRef, rhs: ValueRef)
2561
2568
}
2562
2569
let bcx = cx;
2563
2570
let ti = none :: < @tydesc_info > ;
2564
- let llvec_tydesc = get_tydesc ( bcx, t, false , ti) ;
2571
+ let llvec_tydesc = get_tydesc ( bcx, t, false , ti) . result ;
2565
2572
bcx = llvec_tydesc. bcx ;
2566
2573
ti = none :: < @tydesc_info > ;
2567
- let llelt_tydesc = get_tydesc ( bcx, elt_ty, false , ti) ;
2574
+ let llelt_tydesc = get_tydesc ( bcx, elt_ty, false , ti) . result ;
2568
2575
lazily_emit_tydesc_glue ( cx, abi:: tydesc_field_copy_glue, ti) ;
2569
2576
lazily_emit_tydesc_glue ( cx, abi:: tydesc_field_drop_glue, ti) ;
2570
2577
lazily_emit_tydesc_glue ( cx, abi:: tydesc_field_free_glue, ti) ;
@@ -2819,9 +2826,9 @@ mod ivec {
2819
2826
// FIXME (issue #511): This is needed to prevent a leak.
2820
2827
let no_tydesc_info = none;
2821
2828
2822
- rs = get_tydesc ( bcx, t, false , no_tydesc_info) ;
2829
+ rs = get_tydesc ( bcx, t, false , no_tydesc_info) . result ;
2823
2830
bcx = rs. bcx ;
2824
- rs = get_tydesc ( bcx, unit_ty, false , no_tydesc_info) ;
2831
+ rs = get_tydesc ( bcx, unit_ty, false , no_tydesc_info) . result ;
2825
2832
bcx = rs. bcx ;
2826
2833
lazily_emit_tydesc_glue ( bcx, abi:: tydesc_field_copy_glue, none) ;
2827
2834
lazily_emit_tydesc_glue ( bcx, abi:: tydesc_field_drop_glue, none) ;
@@ -3527,7 +3534,7 @@ fn build_environment(bcx: @block_ctxt, lltydescs: [ValueRef],
3527
3534
if copying {
3528
3535
let bound_tydesc = GEPi ( bcx, closure, ~[ 0 , abi:: closure_elt_tydesc] ) ;
3529
3536
let ti = none;
3530
- let bindings_tydesc = get_tydesc ( bcx, bindings_ty, true , ti) ;
3537
+ let bindings_tydesc = get_tydesc ( bcx, bindings_ty, true , ti) . result ;
3531
3538
lazily_emit_tydesc_glue ( bcx, abi:: tydesc_field_drop_glue, ti) ;
3532
3539
lazily_emit_tydesc_glue ( bcx, abi:: tydesc_field_free_glue, ti) ;
3533
3540
bcx = bindings_tydesc. bcx ;
@@ -3848,7 +3855,7 @@ fn lval_generic_fn(cx: &@block_ctxt, tpt: &ty::ty_param_kinds_and_ty,
3848
3855
// TODO: Doesn't always escape.
3849
3856
3850
3857
let ti = none :: < @tydesc_info > ;
3851
- let td = get_tydesc ( bcx, t, true , ti) ;
3858
+ let td = get_tydesc ( bcx, t, true , ti) . result ;
3852
3859
tis += ~[ ti] ;
3853
3860
bcx = td. bcx ;
3854
3861
tydescs += ~[ td. val ] ;
@@ -5254,7 +5261,7 @@ fn trans_log(lvl: int, cx: &@block_ctxt, e: &@ast::expr) -> result {
5254
5261
let log_bcx = sub. bcx ;
5255
5262
5256
5263
let ti = none :: < @tydesc_info > ;
5257
- let r = get_tydesc ( log_bcx, e_ty, false , ti) ;
5264
+ let r = get_tydesc ( log_bcx, e_ty, false , ti) . result ;
5258
5265
log_bcx = r. bcx ;
5259
5266
5260
5267
// Call the polymorphic log function.
@@ -6926,6 +6933,9 @@ fn declare_intrinsics(llmod: ModuleRef) -> hashmap<str, ValueRef> {
6926
6933
let T_memset64_args : [ TypeRef ] =
6927
6934
~[ T_ptr ( T_i8 ( ) ) , T_i8 ( ) , T_i64 ( ) , T_i32 ( ) , T_i1 ( ) ] ;
6928
6935
let T_trap_args : [ TypeRef ] = ~[ ] ;
6936
+ let gcroot =
6937
+ decl_cdecl_fn ( llmod, "llvm.gcroot" ,
6938
+ T_fn ( ~[ T_ptr ( T_ptr ( T_i8 ( ) ) ) , T_ptr ( T_i8 ( ) ) ] , T_void ( ) ) ) ;
6929
6939
let gcread =
6930
6940
decl_cdecl_fn ( llmod, "llvm.gcread" ,
6931
6941
T_fn ( ~[ T_ptr ( T_i8 ( ) ) , T_ptr ( T_ptr ( T_i8 ( ) ) ) ] , T_void ( ) ) ) ;
@@ -6943,6 +6953,7 @@ fn declare_intrinsics(llmod: ModuleRef) -> hashmap<str, ValueRef> {
6943
6953
T_fn ( T_memset64_args , T_void ( ) ) ) ;
6944
6954
let trap = decl_cdecl_fn ( llmod, "llvm.trap" , T_fn ( T_trap_args , T_void ( ) ) ) ;
6945
6955
let intrinsics = new_str_hash :: < ValueRef > ( ) ;
6956
+ intrinsics. insert ( "llvm.gcroot" , gcroot) ;
6946
6957
intrinsics. insert ( "llvm.gcread" , gcread) ;
6947
6958
intrinsics. insert ( "llvm.memmove.p0i8.p0i8.i32" , memmove32) ;
6948
6959
intrinsics. insert ( "llvm.memmove.p0i8.p0i8.i64" , memmove64) ;
@@ -7142,7 +7153,8 @@ fn trans_crate(sess: &session::session, crate: &@ast::crate, tcx: &ty::ctxt,
7142
7153
rust_object_type: T_rust_object ( ) ,
7143
7154
tydesc_type: tydesc_type,
7144
7155
task_type: task_type,
7145
- shape_cx: shape:: mk_ctxt ( llmod) } ;
7156
+ shape_cx: shape:: mk_ctxt ( llmod) ,
7157
+ gc_cx: gc:: mk_ctxt ( ) } ;
7146
7158
let cx = new_local_ctxt ( ccx) ;
7147
7159
collect_items ( ccx, crate ) ;
7148
7160
collect_tag_ctors ( ccx, crate ) ;
0 commit comments