@@ -16,6 +16,7 @@ import back.x86;
16
16
import back. abi ;
17
17
18
18
import middle. ty . pat_ty ;
19
+ import middle. ty . plain_ty ;
19
20
20
21
import util. common ;
21
22
import util. common . append ;
@@ -341,7 +342,7 @@ fn type_of_fn_full(@crate_ctxt cx,
341
342
@ty. t output ) -> TypeRef {
342
343
let vec[ TypeRef ] atys = vec ( T_taskptr ( ) ) ;
343
344
344
- auto fn_ty = ty . plain_ty ( ty. ty_fn ( inputs, output) ) ;
345
+ auto fn_ty = plain_ty ( ty. ty_fn ( inputs, output) ) ;
345
346
auto ty_param_count = ty. count_ty_params ( fn_ty) ;
346
347
auto i = 0 u;
347
348
while ( i < ty_param_count) {
@@ -869,7 +870,7 @@ fn GEP_tup_like(@block_ctxt cx, @ty.t t,
869
870
// flattened the incoming structure.
870
871
871
872
auto s = split_type ( t, ixs, 0 u) ;
872
- auto prefix_ty = ty . plain_ty ( ty. ty_tup ( s. prefix ) ) ;
873
+ auto prefix_ty = plain_ty ( ty. ty_tup ( s. prefix ) ) ;
873
874
auto bcx = cx;
874
875
auto sz = size_of ( bcx, prefix_ty) ;
875
876
bcx = sz. bcx ;
@@ -985,7 +986,12 @@ fn get_tydesc(&@block_ctxt cx, @ty.t t) -> result {
985
986
auto i = 0 ;
986
987
for ( ValueRef td in tys. _1) {
987
988
auto tdp = cx. build. GEP ( tydescs, vec( C_int ( 0 ) , C_int ( i) ) ) ;
988
- cx. build. Store ( td, tdp) ;
989
+ if ( i == 0 ) {
990
+ cx. build. Store ( root, tdp) ;
991
+ } else {
992
+ cx. build . Store ( td, tdp) ;
993
+ }
994
+ i += 1 ;
989
995
}
990
996
991
997
auto bcx = cx;
@@ -1023,19 +1029,30 @@ fn make_tydesc(@crate_ctxt cx, @ty.t t, vec[ast.def_id] typaram_defs) {
1023
1029
auto glue_fn_ty = T_ptr ( T_fn ( vec ( T_taskptr ( ) ,
1024
1030
T_ptr ( T_ptr ( T_tydesc ( ) ) ) ,
1025
1031
pvoid) , T_void ( ) ) ) ;
1032
+
1033
+ // FIXME: this adjustment has to do with the ridiculous encoding of
1034
+ // glue-pointer-constants in the tydesc records: They are tydesc-relative
1035
+ // displacements. This is purely for compatibility with rustboot and
1036
+ // should go when it is discarded.
1037
+ fn off ( ValueRef tydescp,
1038
+ ValueRef gluefn) -> ValueRef {
1039
+ ret i2p ( llvm. LLVMConstSub ( p2i ( gluefn) , p2i ( tydescp) ) ,
1040
+ val_ty ( gluefn) ) ;
1041
+ }
1042
+
1043
+ auto name = sanitize ( cx. names . next ( "tydesc_" + ty. ty_to_str ( t) ) ) ;
1044
+ auto gvar = llvm. LLVMAddGlobal ( cx. llmod , T_tydesc ( ) , _str. buf ( name) ) ;
1026
1045
auto tydesc = C_struct ( vec ( C_null ( T_ptr ( T_ptr ( T_tydesc ( ) ) ) ) ,
1027
1046
llsize_of ( llty) ,
1028
1047
llalign_of ( llty) ,
1029
- take_glue , // take_glue_off
1030
- drop_glue , // drop_glue_off
1048
+ off ( gvar , take_glue ) , // take_glue_off
1049
+ off ( gvar , drop_glue ) , // drop_glue_off
1031
1050
C_null ( glue_fn_ty) , // free_glue_off
1032
1051
C_null ( glue_fn_ty) , // sever_glue_off
1033
1052
C_null ( glue_fn_ty) , // mark_glue_off
1034
1053
C_null ( glue_fn_ty) , // obj_drop_glue_off
1035
1054
C_null ( glue_fn_ty) ) ) ; // is_stateful
1036
1055
1037
- auto name = sanitize( cx. names. next( "tydesc_" + ty. ty_to_str( t) ) ) ;
1038
- auto gvar = llvm. LLVMAddGlobal ( cx. llmod, val_ty( tydesc) , _str. buf( name) ) ;
1039
1056
llvm. LLVMSetInitializer ( gvar, tydesc) ;
1040
1057
llvm. LLVMSetGlobalConstant ( gvar, True ) ;
1041
1058
llvm. LLVMSetLinkage ( gvar, lib. llvm . LLVMPrivateLinkage
@@ -1322,8 +1339,8 @@ fn iter_structural_ty(@block_ctxt cx,
1322
1339
ValueRef box_cell,
1323
1340
val_and_ty_fn f) -> result {
1324
1341
auto box_ptr = cx. build. Load ( box_cell) ;
1325
- auto tnil = ty . plain_ty( ty. ty_nil) ;
1326
- auto tbox = ty . plain_ty( ty. ty_box( tnil) ) ;
1342
+ auto tnil = plain_ty( ty. ty_nil) ;
1343
+ auto tbox = plain_ty( ty. ty_box( tnil) ) ;
1327
1344
1328
1345
auto inner_cx = new_sub_block_ctxt( cx, "iter box" ) ;
1329
1346
auto next_cx = new_sub_block_ctxt( cx, "next" ) ;
@@ -1524,7 +1541,7 @@ fn iter_sequence(@block_ctxt cx,
1524
1541
ret iter_sequence_body( cx, v, et, f, false ) ;
1525
1542
}
1526
1543
case ( ty. ty_str) {
1527
- auto et = ty . plain_ty( ty. ty_machine( common. ty_u8) ) ;
1544
+ auto et = plain_ty( ty. ty_machine( common. ty_u8) ) ;
1528
1545
ret iter_sequence_body( cx, v, et, f, true ) ;
1529
1546
}
1530
1547
case ( _) { fail; }
@@ -1542,6 +1559,15 @@ fn call_tydesc_glue_full(@block_ctxt cx, ValueRef v,
1542
1559
lltydescs = cx. build. Load ( lltydescs) ;
1543
1560
auto llfnptr = cx. build. GEP ( tydesc, vec( C_int ( 0 ) , C_int ( field) ) ) ;
1544
1561
auto llfn = cx. build. Load ( llfnptr) ;
1562
+
1563
+ // FIXME: this adjustment has to do with the ridiculous encoding of
1564
+ // glue-pointer-constants in the tydesc records: They are tydesc-relative
1565
+ // displacements. This is purely for compatibility with rustboot and
1566
+ // should go when it is discarded.
1567
+ llfn = cx. build. IntToPtr ( cx. build. Add ( cx. build. PtrToInt ( llfn, T_int ( ) ) ,
1568
+ cx. build. PtrToInt ( tydesc, T_int ( ) ) ) ,
1569
+ val_ty( llfn) ) ;
1570
+
1545
1571
cx. build. FastCall ( llfn, vec( cx. fcx. lltaskptr, lltydescs, llrawptr) ) ;
1546
1572
}
1547
1573
@@ -2259,7 +2285,7 @@ fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
2259
2285
check ( cx. fcx. ccx. items. contains_key( tid) ) ;
2260
2286
auto tag_item = cx. fcx. ccx. items. get( tid) ;
2261
2287
auto params = ty. item_ty( tag_item) . _0;
2262
- auto fty = ty . plain_ty( ty. ty_nil) ;
2288
+ auto fty = plain_ty( ty. ty_nil) ;
2263
2289
alt ( tag_item. node) {
2264
2290
case ( ast. item_tag( _, ?variants, _, _) ) {
2265
2291
for ( ast. variant v in variants) {
@@ -2635,7 +2661,7 @@ fn trans_bind(@block_ctxt cx, @ast.expr f,
2635
2661
}
2636
2662
2637
2663
// Synthesize a closure type.
2638
- let @ty. t bindings_ty = ty . plain_ty( ty. ty_tup( bound_tys) ) ;
2664
+ let @ty. t bindings_ty = plain_ty( ty. ty_tup( bound_tys) ) ;
2639
2665
let TypeRef lltarget_ty = type_of( bcx. fcx. ccx, ty. expr_ty( f) ) ;
2640
2666
let TypeRef llbindings_ty = type_of( bcx. fcx. ccx, bindings_ty) ;
2641
2667
let TypeRef llclosure_ty = T_closure_ptr ( lltarget_ty,
@@ -3593,52 +3619,52 @@ fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
3593
3619
}
3594
3620
3595
3621
// Synthesize an obj body type.
3596
- let @ty. t fields_ty = ty. plain_ty( ty. ty_tup( obj_fields) ) ;
3597
- let TypeRef llfields_ty = type_of( bcx. fcx. ccx, fields_ty) ;
3598
- let TypeRef llobj_body_ty =
3599
- T_ptr ( T_box ( T_struct ( vec( T_ptr ( T_tydesc ( ) ) ,
3600
- llfields_ty) ) ) ) ;
3622
+ let @ty. t fields_ty = plain_ty( ty. ty_tup( obj_fields) ) ;
3623
+ let @ty. t body_ty = plain_ty( ty. ty_tup( vec( plain_ty( ty. ty_type) ,
3624
+ fields_ty) ) ) ;
3625
+ let @ty. t boxed_body_ty = plain_ty( ty. ty_box( body_ty) ) ;
3626
+
3627
+ let TypeRef llboxed_body_ty = type_of( cx, boxed_body_ty) ;
3601
3628
3602
3629
// Malloc a box for the body.
3603
- auto r = trans_malloc_inner( bcx, llobj_body_ty) ;
3604
- bcx = r. bcx;
3605
- auto box = r. val;
3606
- auto rc = bcx. build. GEP ( box,
3607
- vec( C_int ( 0 ) ,
3608
- C_int ( abi. box_rc_field_refcnt) ) ) ;
3609
- auto body = bcx. build. GEP ( box,
3610
- vec( C_int ( 0 ) ,
3611
- C_int ( abi. box_rc_field_body) ) ) ;
3612
- bcx. build. Store ( C_int ( 1 ) , rc) ;
3630
+ auto box = trans_malloc_inner( bcx, llboxed_body_ty) ;
3631
+ bcx = box. bcx;
3632
+ auto rc = GEP_tup_like ( bcx, boxed_body_ty, box. val,
3633
+ vec( 0 , abi. box_rc_field_refcnt) ) ;
3634
+ bcx = rc. bcx;
3635
+ auto body = GEP_tup_like ( bcx, boxed_body_ty, box. val,
3636
+ vec( 0 , abi. box_rc_field_body) ) ;
3637
+ bcx = body. bcx;
3638
+ bcx. build. Store ( C_int ( 1 ) , rc. val) ;
3613
3639
3614
3640
// Store body tydesc.
3615
3641
auto body_tydesc =
3616
- bcx . build . GEP ( body,
3617
- vec( C_int ( 0 ) ,
3618
- C_int ( abi . obj_body_elt_tydesc ) ) ) ;
3642
+ GEP_tup_like ( bcx , body_ty , body. val ,
3643
+ vec( 0 , abi . obj_body_elt_tydesc ) ) ;
3644
+ bcx = body_tydesc . bcx ;
3619
3645
3620
- auto fields_tydesc = get_tydesc( r . bcx, fields_ty) ;
3646
+ auto fields_tydesc = get_tydesc( bcx, fields_ty) ;
3621
3647
bcx = fields_tydesc. bcx;
3622
- bcx. build. Store ( fields_tydesc. val, body_tydesc) ;
3648
+ bcx. build. Store ( fields_tydesc. val, body_tydesc. val ) ;
3623
3649
3624
3650
// Copy args into body fields.
3625
3651
auto body_fields =
3626
- bcx . build . GEP ( body,
3627
- vec( C_int ( 0 ) ,
3628
- C_int ( abi . obj_body_elt_fields ) ) ) ;
3652
+ GEP_tup_like ( bcx , body_ty , body. val ,
3653
+ vec( 0 , abi . obj_body_elt_fields ) ) ;
3654
+ bcx = body_fields . bcx ;
3629
3655
3630
3656
let int i = 0 ;
3631
3657
for ( ast. obj_field f in ob. fields) {
3632
3658
auto arg = bcx. fcx. llargs. get( f. id) ;
3633
3659
arg = load_scalar_or_boxed( bcx, arg, arg_tys. ( i) . ty) ;
3634
- auto field = bcx. build. GEP ( body_fields,
3635
- vec( C_int ( 0 ) , C_int ( i) ) ) ;
3636
- bcx = copy_ty( bcx, INIT , field, arg, arg_tys. ( i) . ty) . bcx;
3660
+ auto field = GEP_tup_like ( bcx, fields_ty, body_fields. val,
3661
+ vec( 0 , i) ) ;
3662
+ bcx = field. bcx;
3663
+ bcx = copy_ty( bcx, INIT , field. val, arg, arg_tys. ( i) . ty) . bcx;
3637
3664
i += 1 ;
3638
3665
}
3639
-
3640
3666
// Store box ptr in outer pair.
3641
- auto p = bcx. build. PointerCast ( box, llbox_ty) ;
3667
+ auto p = bcx. build. PointerCast ( box. val , llbox_ty) ;
3642
3668
bcx. build. Store ( p, pair_box) ;
3643
3669
}
3644
3670
bcx. build. Ret ( bcx. build. Load ( pair) ) ;
@@ -4030,6 +4056,10 @@ fn p2i(ValueRef v) -> ValueRef {
4030
4056
ret llvm. LLVMConstPtrToInt ( v, T_int ( ) ) ;
4031
4057
}
4032
4058
4059
+ fn i2p ( ValueRef v, TypeRef t) -> ValueRef {
4060
+ ret llvm. LLVMConstIntToPtr ( v, t) ;
4061
+ }
4062
+
4033
4063
fn trans_exit_task_glue ( @crate_ctxt cx ) {
4034
4064
let vec[ TypeRef ] T_args = vec ( ) ;
4035
4065
let vec[ ValueRef ] V_args = vec ( ) ;
0 commit comments