Skip to content

Commit 1aa3f53

Browse files
committed
---
yaml --- r: 1325 b: refs/heads/master c: eb16942 h: refs/heads/master i: 1323: 4330b0c v: v3
1 parent de5e723 commit 1aa3f53

File tree

2 files changed

+71
-41
lines changed

2 files changed

+71
-41
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 8ef22972dbe50b2e05c8983769a638fd5b6a23b5
2+
refs/heads/master: eb16942c1de42c2f30f7e0eb0ff69371a167f7bd

trunk/src/comp/middle/trans.rs

Lines changed: 70 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import back.x86;
1616
import back.abi;
1717

1818
import middle.ty.pat_ty;
19+
import middle.ty.plain_ty;
1920

2021
import util.common;
2122
import util.common.append;
@@ -341,7 +342,7 @@ fn type_of_fn_full(@crate_ctxt cx,
341342
@ty.t output) -> TypeRef {
342343
let vec[TypeRef] atys = vec(T_taskptr());
343344

344-
auto fn_ty = ty.plain_ty(ty.ty_fn(inputs, output));
345+
auto fn_ty = plain_ty(ty.ty_fn(inputs, output));
345346
auto ty_param_count = ty.count_ty_params(fn_ty);
346347
auto i = 0u;
347348
while (i < ty_param_count) {
@@ -869,7 +870,7 @@ fn GEP_tup_like(@block_ctxt cx, @ty.t t,
869870
// flattened the incoming structure.
870871

871872
auto s = split_type(t, ixs, 0u);
872-
auto prefix_ty = ty.plain_ty(ty.ty_tup(s.prefix));
873+
auto prefix_ty = plain_ty(ty.ty_tup(s.prefix));
873874
auto bcx = cx;
874875
auto sz = size_of(bcx, prefix_ty);
875876
bcx = sz.bcx;
@@ -985,7 +986,12 @@ fn get_tydesc(&@block_ctxt cx, @ty.t t) -> result {
985986
auto i = 0;
986987
for (ValueRef td in tys._1) {
987988
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;
989995
}
990996

991997
auto bcx = cx;
@@ -1023,19 +1029,30 @@ fn make_tydesc(@crate_ctxt cx, @ty.t t, vec[ast.def_id] typaram_defs) {
10231029
auto glue_fn_ty = T_ptr(T_fn(vec(T_taskptr(),
10241030
T_ptr(T_ptr(T_tydesc())),
10251031
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));
10261045
auto tydesc = C_struct(vec(C_null(T_ptr(T_ptr(T_tydesc()))),
10271046
llsize_of(llty),
10281047
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
10311050
C_null(glue_fn_ty), // free_glue_off
10321051
C_null(glue_fn_ty), // sever_glue_off
10331052
C_null(glue_fn_ty), // mark_glue_off
10341053
C_null(glue_fn_ty), // obj_drop_glue_off
10351054
C_null(glue_fn_ty))); // is_stateful
10361055

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));
10391056
llvm.LLVMSetInitializer(gvar, tydesc);
10401057
llvm.LLVMSetGlobalConstant(gvar, True);
10411058
llvm.LLVMSetLinkage(gvar, lib.llvm.LLVMPrivateLinkage
@@ -1322,8 +1339,8 @@ fn iter_structural_ty(@block_ctxt cx,
13221339
ValueRef box_cell,
13231340
val_and_ty_fn f) -> result {
13241341
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));
13271344

13281345
auto inner_cx = new_sub_block_ctxt(cx, "iter box");
13291346
auto next_cx = new_sub_block_ctxt(cx, "next");
@@ -1524,7 +1541,7 @@ fn iter_sequence(@block_ctxt cx,
15241541
ret iter_sequence_body(cx, v, et, f, false);
15251542
}
15261543
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));
15281545
ret iter_sequence_body(cx, v, et, f, true);
15291546
}
15301547
case (_) { fail; }
@@ -1542,6 +1559,15 @@ fn call_tydesc_glue_full(@block_ctxt cx, ValueRef v,
15421559
lltydescs = cx.build.Load(lltydescs);
15431560
auto llfnptr = cx.build.GEP(tydesc, vec(C_int(0), C_int(field)));
15441561
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+
15451571
cx.build.FastCall(llfn, vec(cx.fcx.lltaskptr, lltydescs, llrawptr));
15461572
}
15471573

@@ -2259,7 +2285,7 @@ fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
22592285
check (cx.fcx.ccx.items.contains_key(tid));
22602286
auto tag_item = cx.fcx.ccx.items.get(tid);
22612287
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);
22632289
alt (tag_item.node) {
22642290
case (ast.item_tag(_, ?variants, _, _)) {
22652291
for (ast.variant v in variants) {
@@ -2635,7 +2661,7 @@ fn trans_bind(@block_ctxt cx, @ast.expr f,
26352661
}
26362662

26372663
// 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));
26392665
let TypeRef lltarget_ty = type_of(bcx.fcx.ccx, ty.expr_ty(f));
26402666
let TypeRef llbindings_ty = type_of(bcx.fcx.ccx, bindings_ty);
26412667
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,
35933619
}
35943620

35953621
// 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);
36013628

36023629
// 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);
36133639

36143640
// Store body tydesc.
36153641
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;
36193645

3620-
auto fields_tydesc = get_tydesc(r.bcx, fields_ty);
3646+
auto fields_tydesc = get_tydesc(bcx, fields_ty);
36213647
bcx = fields_tydesc.bcx;
3622-
bcx.build.Store(fields_tydesc.val, body_tydesc);
3648+
bcx.build.Store(fields_tydesc.val, body_tydesc.val);
36233649

36243650
// Copy args into body fields.
36253651
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;
36293655

36303656
let int i = 0;
36313657
for (ast.obj_field f in ob.fields) {
36323658
auto arg = bcx.fcx.llargs.get(f.id);
36333659
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;
36373664
i += 1;
36383665
}
3639-
36403666
// 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);
36423668
bcx.build.Store(p, pair_box);
36433669
}
36443670
bcx.build.Ret(bcx.build.Load(pair));
@@ -4030,6 +4056,10 @@ fn p2i(ValueRef v) -> ValueRef {
40304056
ret llvm.LLVMConstPtrToInt(v, T_int());
40314057
}
40324058

4059+
fn i2p(ValueRef v, TypeRef t) -> ValueRef {
4060+
ret llvm.LLVMConstIntToPtr(v, t);
4061+
}
4062+
40334063
fn trans_exit_task_glue(@crate_ctxt cx) {
40344064
let vec[TypeRef] T_args = vec();
40354065
let vec[ValueRef] V_args = vec();

0 commit comments

Comments
 (0)