diff options
| author | Patrick Walton <[email protected]> | 2011-03-17 17:39:47 -0700 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2011-03-17 17:39:47 -0700 |
| commit | 5eca7129e3857e3506d12de7591238f8a7d55da1 (patch) | |
| tree | 54701099b4b723539074b662daaf3290e63d51e0 /src/comp/middle/trans.rs | |
| parent | rustc: Typo: mutabliity -> mutability (diff) | |
| download | rust-5eca7129e3857e3506d12de7591238f8a7d55da1.tar.xz rust-5eca7129e3857e3506d12de7591238f8a7d55da1.zip | |
rustc: Switch mutability from being a type constructor to a field annotation
Diffstat (limited to 'src/comp/middle/trans.rs')
| -rw-r--r-- | src/comp/middle/trans.rs | 113 |
1 files changed, 57 insertions, 56 deletions
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index f119681b..2ef619cb 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -614,23 +614,23 @@ fn type_of_inner(@crate_ctxt cx, @ty.t t, bool boxed) -> TypeRef { llty = T_tag(cx.tn, size); } } - case (ty.ty_box(?t)) { - llty = T_ptr(T_box(type_of_inner(cx, t, true))); + case (ty.ty_box(?mt)) { + llty = T_ptr(T_box(type_of_inner(cx, mt.ty, true))); } - case (ty.ty_vec(?t)) { - llty = T_ptr(T_vec(type_of_inner(cx, t, true))); + case (ty.ty_vec(?mt)) { + llty = T_ptr(T_vec(type_of_inner(cx, mt.ty, true))); } case (ty.ty_tup(?elts)) { let vec[TypeRef] tys = vec(); - for (@ty.t elt in elts) { - tys += vec(type_of_inner(cx, elt, boxed)); + for (ty.mt elt in elts) { + tys += vec(type_of_inner(cx, elt.ty, boxed)); } llty = T_struct(tys); } case (ty.ty_rec(?fields)) { let vec[TypeRef] tys = vec(); for (ty.field f in fields) { - tys += vec(type_of_inner(cx, f.ty, boxed)); + tys += vec(type_of_inner(cx, f.mt.ty, boxed)); } llty = T_struct(tys); } @@ -971,8 +971,7 @@ fn static_size_of_tag(@crate_ctxt cx, @ty.t t) -> uint { auto max_size = 0u; auto variants = tag_variants(cx, tid); for (ast.variant variant in variants) { - let vec[@ty.t] tys = variant_types(cx, variant); - auto tup_ty = ty.plain_ty(ty.ty_tup(tys)); + auto tup_ty = ty.plain_tup_ty(variant_types(cx, variant)); // Perform any type parameter substitutions. tup_ty = ty.substitute_ty_params(ty_params, subtys, tup_ty); @@ -1021,12 +1020,16 @@ fn dynamic_size_of(@block_ctxt cx, @ty.t t) -> result { ret res(szptr.bcx, szptr.bcx.build.Load(szptr.val)); } case (ty.ty_tup(?elts)) { - ret align_elements(cx, elts); + let vec[@ty.t] tys = vec(); + for (ty.mt mt in elts) { + tys += vec(mt.ty); + } + ret align_elements(cx, tys); } case (ty.ty_rec(?flds)) { let vec[@ty.t] tys = vec(); for (ty.field f in flds) { - tys += vec(f.ty); + tys += vec(f.mt.ty); } ret align_elements(cx, tys); } @@ -1072,8 +1075,8 @@ fn dynamic_align_of(@block_ctxt cx, @ty.t t) -> result { case (ty.ty_tup(?elts)) { auto a = C_int(1); auto bcx = cx; - for (@ty.t e in elts) { - auto align = align_of(bcx, e); + for (ty.mt e in elts) { + auto align = align_of(bcx, e.ty); bcx = align.bcx; a = umax(bcx, a, align.val); } @@ -1083,7 +1086,7 @@ fn dynamic_align_of(@block_ctxt cx, @ty.t t) -> result { auto a = C_int(1); auto bcx = cx; for (ty.field f in flds) { - auto align = align_of(bcx, f.ty); + auto align = align_of(bcx, f.mt.ty); bcx = align.bcx; a = umax(bcx, a, align.val); } @@ -1183,7 +1186,7 @@ fn GEP_tup_like(@block_ctxt cx, @ty.t t, // flattened the incoming structure. auto s = split_type(t, ixs, 0u); - auto prefix_ty = plain_ty(ty.ty_tup(s.prefix)); + auto prefix_ty = ty.plain_tup_ty(s.prefix); auto bcx = cx; auto sz = size_of(bcx, prefix_ty); bcx = sz.bcx; @@ -1227,7 +1230,8 @@ fn GEP_tag(@block_ctxt cx, i += 1; } - auto tup_ty = ty.plain_ty(ty.ty_tup(true_arg_tys)); + + auto tup_ty = ty.plain_tup_ty(true_arg_tys); // Cast the blob pointer to the appropriate type, if we need to (i.e. if // the blob pointer isn't dynamically sized). @@ -1267,8 +1271,8 @@ fn trans_raw_malloc(@block_ctxt cx, TypeRef llptr_ty, ValueRef llsize) fn trans_malloc_boxed(@block_ctxt cx, @ty.t t) -> result { // Synthesize a fake box type structurally so we have something // to measure the size of. - auto boxed_body = plain_ty(ty.ty_tup(vec(plain_ty(ty.ty_int), t))); - auto box_ptr = plain_ty(ty.ty_box(t)); + auto boxed_body = ty.plain_tup_ty(vec(plain_ty(ty.ty_int), t)); + auto box_ptr = ty.plain_box_ty(t); auto sz = size_of(cx, boxed_body); auto llty = type_of(cx.fcx.ccx, box_ptr); ret trans_raw_malloc(sz.bcx, llty, sz.val); @@ -1566,7 +1570,7 @@ fn make_drop_glue(@block_ctxt cx, ValueRef v, @ty.t t) -> result { T_int(), C_int(0)); } - case (ty.ty_box(?body_ty)) { + case (ty.ty_box(?body_mt)) { fn hit_zero(@block_ctxt cx, ValueRef v, @ty.t body_ty) -> result { auto body = cx.build.GEP(v, @@ -1579,7 +1583,7 @@ fn make_drop_glue(@block_ctxt cx, ValueRef v, @ty.t t) -> result { ret trans_non_gc_free(res.bcx, v); } ret decr_refcnt_and_if_zero(cx, v, - bind hit_zero(_, v, body_ty), + bind hit_zero(_, v, body_mt.ty), "free box", T_int(), C_int(0)); } @@ -1831,7 +1835,7 @@ fn iter_structural_ty_full(@block_ctxt cx, auto box_a_ptr = cx.build.Load(box_a_cell); auto box_b_ptr = cx.build.Load(box_b_cell); auto tnil = plain_ty(ty.ty_nil); - auto tbox = plain_ty(ty.ty_box(tnil)); + auto tbox = ty.plain_box_ty(tnil); auto inner_cx = new_sub_block_ctxt(cx, "iter box"); auto next_cx = new_sub_block_ctxt(cx, "next"); @@ -1846,15 +1850,15 @@ fn iter_structural_ty_full(@block_ctxt cx, alt (t.struct) { case (ty.ty_tup(?args)) { let int i = 0; - for (@ty.t arg in args) { + for (ty.mt arg in args) { r = GEP_tup_like(r.bcx, t, av, vec(0, i)); auto elt_a = r.val; r = GEP_tup_like(r.bcx, t, bv, vec(0, i)); auto elt_b = r.val; r = f(r.bcx, - load_scalar_or_boxed(r.bcx, elt_a, arg), - load_scalar_or_boxed(r.bcx, elt_b, arg), - arg); + load_scalar_or_boxed(r.bcx, elt_a, arg.ty), + load_scalar_or_boxed(r.bcx, elt_b, arg.ty), + arg.ty); i += 1; } } @@ -1866,9 +1870,9 @@ fn iter_structural_ty_full(@block_ctxt cx, r = GEP_tup_like(r.bcx, t, bv, vec(0, i)); auto llfld_b = r.val; r = f(r.bcx, - load_scalar_or_boxed(r.bcx, llfld_a, fld.ty), - load_scalar_or_boxed(r.bcx, llfld_b, fld.ty), - fld.ty); + load_scalar_or_boxed(r.bcx, llfld_a, fld.mt.ty), + load_scalar_or_boxed(r.bcx, llfld_b, fld.mt.ty), + fld.mt.ty); i += 1; } } @@ -2106,8 +2110,8 @@ fn iter_sequence(@block_ctxt cx, } alt (t.struct) { - case (ty.ty_vec(?et)) { - ret iter_sequence_body(cx, v, et, f, false); + case (ty.ty_vec(?elt)) { + ret iter_sequence_body(cx, v, elt.ty, f, false); } case (ty.ty_str) { auto et = plain_ty(ty.ty_machine(common.ty_u8)); @@ -2397,9 +2401,6 @@ fn trans_unary(@block_ctxt cx, ast.unop op, } ret res(sub.bcx, val); } - case (ast._mutable) { - ret trans_expr(cx, e); - } } fail; } @@ -2698,12 +2699,12 @@ fn autoderef(@block_ctxt cx, ValueRef v, @ty.t t) -> result { while (true) { alt (t1.struct) { - case (ty.ty_box(?inner)) { + case (ty.ty_box(?mt)) { auto body = cx.build.GEP(v1, vec(C_int(0), C_int(abi.box_rc_field_body))); - t1 = inner; - v1 = load_scalar_or_boxed(cx, body, inner); + t1 = mt.ty; + v1 = load_scalar_or_boxed(cx, body, t1); } case (_) { ret res(cx, v1); @@ -2717,8 +2718,8 @@ fn autoderefed_ty(@ty.t t) -> @ty.t { while (true) { alt (t1.struct) { - case (ty.ty_box(?inner)) { - t1 = inner; + case (ty.ty_box(?mt)) { + t1 = mt.ty; } case (_) { ret t1; @@ -3483,7 +3484,7 @@ fn trans_field(@block_ctxt cx, &ast.span sp, @ast.expr base, r = autoderef(r.bcx, r.val, t); t = autoderefed_ty(t); alt (t.struct) { - case (ty.ty_tup(?fields)) { + case (ty.ty_tup(_)) { let uint ix = ty.field_num(cx.fcx.ccx.sess, sp, field); auto v = GEP_tup_like(r.bcx, t, r.val, vec(0, ix as int)); ret lval_mem(v.bcx, v.val); @@ -3623,7 +3624,7 @@ fn trans_bind_thunk(@crate_ctxt cx, auto fcx = new_fn_ctxt(cx, llthunk); auto bcx = new_top_block_ctxt(fcx); - auto llclosure_ptr_ty = type_of(cx, plain_ty(ty.ty_box(closure_ty))); + auto llclosure_ptr_ty = type_of(cx, ty.plain_box_ty(closure_ty)); auto llclosure = bcx.build.PointerCast(fcx.llenv, llclosure_ptr_ty); auto lltarget = GEP_tup_like(bcx, closure_ty, llclosure, @@ -3795,7 +3796,7 @@ fn trans_bind(@block_ctxt cx, @ast.expr f, } // Synthesize a closure type. - let @ty.t bindings_ty = plain_ty(ty.ty_tup(bound_tys)); + let @ty.t bindings_ty = ty.plain_tup_ty(bound_tys); // NB: keep this in sync with T_closure_ptr; we're making // a ty.t structure that has the same "shape" as the LLVM type @@ -3809,9 +3810,9 @@ fn trans_bind(@block_ctxt cx, @ast.expr f, vec(tydesc_ty, outgoing_fty, bindings_ty, - plain_ty(ty.ty_tup(captured_tys))); + ty.plain_tup_ty(captured_tys)); - let @ty.t closure_ty = plain_ty(ty.ty_tup(closure_tys)); + let @ty.t closure_ty = ty.plain_tup_ty(closure_tys); auto r = trans_malloc_boxed(bcx, closure_ty); auto box = r.val; @@ -4155,8 +4156,8 @@ fn trans_vec(@block_ctxt cx, vec[@ast.expr] args, auto t = node_ann_type(cx.fcx.ccx, ann); auto unit_ty = t; alt (t.struct) { - case (ty.ty_vec(?t)) { - unit_ty = t; + case (ty.ty_vec(?mt)) { + unit_ty = mt.ty; } case (_) { cx.fcx.ccx.sess.bug("non-vec type in trans_vec"); @@ -4183,8 +4184,8 @@ fn trans_vec(@block_ctxt cx, vec[@ast.expr] args, C_int(abi.vec_elt_data))); auto pseudo_tup_ty = - plain_ty(ty.ty_tup(_vec.init_elt[@ty.t](unit_ty, - _vec.len[@ast.expr](args)))); + ty.plain_tup_ty(_vec.init_elt[@ty.t](unit_ty, + _vec.len[@ast.expr](args))); let int i = 0; for (@ast.expr e in args) { @@ -4253,7 +4254,7 @@ fn trans_rec(@block_ctxt cx, vec[ast.field] fields, } for (ty.field tf in ty_fields) { - auto e_ty = tf.ty; + auto e_ty = tf.mt.ty; auto dst_res = GEP_tup_like(bcx, t, rec_val, vec(0, i)); bcx = dst_res.bcx; @@ -4359,7 +4360,7 @@ fn trans_expr(@block_ctxt cx, @ast.expr e) -> result { ret trans_cast(cx, e, ann); } - case (ast.expr_vec(?args, ?ann)) { + case (ast.expr_vec(?args, _, ?ann)) { ret trans_vec(cx, args, ann); } @@ -4910,7 +4911,7 @@ fn populate_fn_ctxt_from_llself(@block_ctxt cx, ValueRef llself) -> result { // Synthesize a tuple type for the fields so that GEP_tup_like() can work // its magic. - auto fields_tup_ty = ty.plain_ty(ty.ty_tup(field_tys)); + auto fields_tup_ty = ty.plain_tup_ty(field_tys); auto n_typarams = _vec.len[ast.ty_param](bcx.fcx.ccx.obj_typarams); let TypeRef llobj_box_ty = T_obj_ptr(bcx.fcx.ccx.tn, n_typarams); @@ -5102,12 +5103,12 @@ fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid, _vec.push[@ty.t](tps, tydesc_ty); } - let @ty.t typarams_ty = plain_ty(ty.ty_tup(tps)); - let @ty.t fields_ty = plain_ty(ty.ty_tup(obj_fields)); - let @ty.t body_ty = plain_ty(ty.ty_tup(vec(tydesc_ty, - typarams_ty, - fields_ty))); - let @ty.t boxed_body_ty = plain_ty(ty.ty_box(body_ty)); + let @ty.t typarams_ty = ty.plain_tup_ty(tps); + let @ty.t fields_ty = ty.plain_tup_ty(obj_fields); + let @ty.t body_ty = ty.plain_tup_ty(vec(tydesc_ty, + typarams_ty, + fields_ty)); + let @ty.t boxed_body_ty = ty.plain_box_ty(body_ty); // Malloc a box for the body. auto box = trans_malloc_boxed(bcx, body_ty); |