From b4bae8fea5943a0b95a1a9be13a8155ee45418b7 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 10 Oct 2011 13:32:50 +0200 Subject: [PATCH] Make vectors and strings immediates again There's no good reason to force them to be spilled anymore. Some pieces of trans become more elegant this way, and less stack allocs and load/stores are needed. Issue #1021 --- src/comp/front/test.rs | 2 +- src/comp/middle/trans.rs | 98 ++++++++++++++----------------- src/comp/middle/trans_alt.rs | 13 ++-- src/comp/middle/trans_vec.rs | 96 +++++++++++++----------------- src/comp/middle/ty.rs | 2 +- src/lib/posix_fs.rs | 2 +- src/lib/vec.rs | 2 +- src/lib/win32_fs.rs | 4 +- src/test/run-pass/interior-vec.rs | 2 +- 9 files changed, 100 insertions(+), 121 deletions(-) diff --git a/src/comp/front/test.rs b/src/comp/front/test.rs index 78b6388b17a29..6f7270f4396f8 100644 --- a/src/comp/front/test.rs +++ b/src/comp/front/test.rs @@ -284,7 +284,7 @@ fn mk_main(cx: test_ctxt) -> @ast::item { let args_ty: ast::ty = nospan(ast::ty_vec(args_mt)); let args_arg: ast::arg = - {mode: ast::by_ref, + {mode: ast::by_val, ty: @args_ty, ident: "args", id: cx.next_node_id()}; diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 92cd1f76e611f..4e20543bc0b76 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -1327,8 +1327,9 @@ fn make_take_glue(cx: @block_ctxt, v: ValueRef, t: ty::t) { } else if ty::type_is_structural(bcx_tcx(bcx), t) { bcx = iter_structural_ty(bcx, v, t, take_ty); } else if ty::type_is_vec(bcx_tcx(bcx), t) { - bcx = tvec::duplicate(bcx, v); - bcx = tvec::iter_vec(bcx, v, t, take_ty); + let {bcx: cx, val} = tvec::duplicate(bcx, Load(bcx, v), t); + bcx = cx; + Store(bcx, val, v); } build_return(bcx); @@ -1361,6 +1362,9 @@ fn make_free_glue(bcx: @block_ctxt, v: ValueRef, t: ty::t) { v = PointerCast(bcx, v, type_of_1(bcx, t)); trans_uniq::make_free_glue(bcx, v, t) } + ty::ty_vec(_) | ty::ty_str. { + tvec::make_free_glue(bcx, PointerCast(bcx, v, type_of_1(bcx, t)), t) + } ty::ty_obj(_) { // Call through the obj's own fields-drop glue first. // Then free the body. @@ -1404,10 +1408,10 @@ fn make_drop_glue(bcx: @block_ctxt, v0: ValueRef, t: ty::t) { let ccx = bcx_ccx(bcx); let bcx = alt ty::struct(ccx.tcx, t) { - ty::ty_vec(_) { tvec::make_drop_glue(bcx, v0, t) } - ty::ty_str. { tvec::make_drop_glue(bcx, v0, t) } ty::ty_box(_) { decr_refcnt_maybe_free(bcx, Load(bcx, v0), t) } - ty::ty_uniq(_) { free_ty(bcx, Load(bcx, v0), t) } + ty::ty_uniq(_) | ty::ty_vec(_) | ty::ty_str. { + free_ty(bcx, Load(bcx, v0), t) + } ty::ty_obj(_) { let box_cell = GEP(bcx, v0, [C_int(0), C_int(abi::obj_field_box)]); @@ -1958,8 +1962,10 @@ fn drop_ty(cx: @block_ctxt, v: ValueRef, t: ty::t) -> @block_ctxt { fn drop_ty_immediate(bcx: @block_ctxt, v: ValueRef, t: ty::t) -> @block_ctxt { alt ty::struct(bcx_tcx(bcx), t) { + ty::ty_uniq(_) | ty::ty_vec(_) | ty::ty_str. { + ret free_ty(bcx, v, t); + } ty::ty_box(_) { ret decr_refcnt_maybe_free(bcx, v, t); } - ty::ty_uniq(_) { ret free_ty(bcx, v, t); } // FIXME A ty_ptr pointing at something that needs drop glue is somehow // marked as needing drop glue. This is probably a mistake. ty::ty_ptr(_) { ret bcx; } @@ -1973,6 +1979,7 @@ fn take_ty_immediate(bcx: @block_ctxt, v: ValueRef, t: ty::t) -> result { check trans_uniq::type_is_unique_box(bcx, t); ret trans_uniq::duplicate(bcx, v, t); } + ty::ty_str. | ty::ty_vec(_) { ret tvec::duplicate(bcx, v, t); } _ { ret rslt(bcx, v); } } } @@ -2068,30 +2075,32 @@ fn copy_val(cx: @block_ctxt, action: copy_action, dst: ValueRef, ret copy_val_no_check(cx, action, dst, src, t); } -fn copy_val_no_check(cx: @block_ctxt, action: copy_action, dst: ValueRef, +fn copy_val_no_check(bcx: @block_ctxt, action: copy_action, dst: ValueRef, src: ValueRef, t: ty::t) -> @block_ctxt { - let ccx = bcx_ccx(cx); + let ccx = bcx_ccx(bcx); if ty::type_is_scalar(ccx.tcx, t) || ty::type_is_native(ccx.tcx, t) { - Store(cx, src, dst); - ret cx; + Store(bcx, src, dst); + ret bcx; } - if ty::type_is_nil(ccx.tcx, t) || ty::type_is_bot(ccx.tcx, t) { ret cx; } + if ty::type_is_nil(ccx.tcx, t) || ty::type_is_bot(ccx.tcx, t) { ret bcx; } if ty::type_is_boxed(ccx.tcx, t) { - let bcx = cx; - if action == DROP_EXISTING { bcx = drop_ty(cx, dst, t); } + if action == DROP_EXISTING { bcx = drop_ty(bcx, dst, t); } Store(bcx, src, dst); ret take_ty(bcx, dst, t); } + if ty::type_is_vec(ccx.tcx, t) { + if action == DROP_EXISTING { bcx = drop_ty(bcx, dst, t); } + let {bcx, val} = tvec::duplicate(bcx, src, t); + Store(bcx, val, dst); + ret bcx; + } if ty::type_is_unique_box(ccx.tcx, t) { - let bcx = cx; - if action == DROP_EXISTING { bcx = drop_ty(cx, dst, t); } + if action == DROP_EXISTING { bcx = drop_ty(bcx, dst, t); } check trans_uniq::type_is_unique_box(bcx, t); ret trans_uniq::copy_val(bcx, dst, src, t); } - if type_is_structural_or_param(ccx.tcx, t) || ty::type_is_vec(ccx.tcx, t) - { - let bcx = cx; - if action == DROP_EXISTING { bcx = drop_ty(cx, dst, t); } + if type_is_structural_or_param(ccx.tcx, t) { + if action == DROP_EXISTING { bcx = drop_ty(bcx, dst, t); } bcx = memmove_ty(bcx, dst, src, t); ret take_ty(bcx, dst, t); } @@ -2115,15 +2124,14 @@ fn move_val(cx: @block_ctxt, action: copy_action, dst: ValueRef, ret cx; } else if ty::type_is_nil(tcx, t) || ty::type_is_bot(tcx, t) { ret cx; - } else if ty::type_is_boxed(tcx, t) || ty::type_is_unique_box(tcx, t) { + } else if ty::type_is_boxed(tcx, t) || ty::type_is_unique(tcx, t) { if src.kind == owned { src_val = Load(cx, src_val); } if action == DROP_EXISTING { cx = drop_ty(cx, dst, t); } Store(cx, src_val, dst); if src.kind == owned { ret zero_alloca(cx, src.val, t); } // If we're here, it must be a temporary. ret revoke_clean(cx, src_val); - } else if ty::type_is_unique(tcx, t) || - type_is_structural_or_param(tcx, t) { + } else if type_is_structural_or_param(tcx, t) { if action == DROP_EXISTING { cx = drop_ty(cx, dst, t); } cx = memmove_ty(cx, dst, src_val, t); if src.kind == owned { ret zero_alloca(cx, src_val, t); } @@ -2270,6 +2278,7 @@ fn trans_expr_fn(bcx: @block_ctxt, f: ast::_fn, sp: span, let upvars = get_freevars(ccx.tcx, id); let env_r = build_closure(bcx, upvars, copying); env = env_r.ptr; + bcx = env_r.bcx; trans_closure(sub_cx, sp, f, llfn, none, [], id, {|fcx| load_environment(bcx, fcx, env_r.ptrty, upvars, copying); }); @@ -2600,14 +2609,13 @@ fn trans_for(cx: @block_ctxt, local: @ast::local, seq: @ast::expr, let next_cx = new_sub_block_ctxt(cx, "next"); let seq_ty = ty::expr_ty(bcx_tcx(cx), seq); let {bcx: bcx, val: seq} = trans_temp_expr(cx, seq); - let seq = PointerCast(bcx, seq, T_ptr(T_ptr(T_opaque_vec()))); + let seq = PointerCast(bcx, seq, T_ptr(T_opaque_vec())); let fill = tvec::get_fill(bcx, seq); if ty::type_is_str(bcx_tcx(bcx), seq_ty) { fill = Sub(bcx, fill, C_int(1)); } - let bcx = - tvec::iter_vec_raw(bcx, seq, seq_ty, fill, - bind inner(_, local, _, _, body, next_cx)); + let bcx = tvec::iter_vec_raw(bcx, seq, seq_ty, fill, + bind inner(_, local, _, _, body, next_cx)); Br(bcx, next_cx.llbb); ret next_cx; } @@ -3183,15 +3191,14 @@ fn trans_rec_field(bcx: @block_ctxt, base: @ast::expr, fn trans_index(cx: @block_ctxt, sp: span, base: @ast::expr, idx: @ast::expr, id: ast::node_id) -> lval_result { // Is this an interior vector? - let base_ty = ty::expr_ty(bcx_tcx(cx), base); let exp = trans_temp_expr(cx, base); let lv = autoderef(exp.bcx, exp.val, base_ty); let ix = trans_temp_expr(lv.bcx, idx); let v = lv.val; let bcx = ix.bcx; - // Cast to an LLVM integer. Rust is less strict than LLVM in this regard. + // Cast to an LLVM integer. Rust is less strict than LLVM in this regard. let ix_val; let ix_size = llsize_of_real(bcx_ccx(cx), val_ty(ix.val)); let int_size = llsize_of_real(bcx_ccx(cx), T_int()); @@ -3200,6 +3207,7 @@ fn trans_index(cx: @block_ctxt, sp: span, base: @ast::expr, idx: @ast::expr, } else if ix_size > int_size { ix_val = Trunc(bcx, ix.val, T_int()); } else { ix_val = ix.val; } + let unit_ty = node_id_type(bcx_ccx(cx), id); let unit_sz = size_of(bcx, unit_ty); bcx = unit_sz.bcx; @@ -4444,18 +4452,11 @@ fn lval_to_dps(bcx: @block_ctxt, e: @ast::expr, dest: dest) -> @block_ctxt { if kind == temporary { revoke_clean(bcx, val); *cell = val; - } else if kind == owned_imm { + } else if ty::type_is_immediate(bcx_tcx(bcx), ty) { + if kind == owned { val = Load(bcx, val); } let {bcx: cx, val} = take_ty_immediate(bcx, val, ty); *cell = val; bcx = cx; - } else if ty::type_is_unique(bcx_tcx(bcx), ty) { - // FIXME make vectors immediate again, lose this hack - // Do a song and a dance to work around the fact that take_ty - // for unique boxes overwrites the pointer. - let oldval = Load(bcx, val); - bcx = take_ty(bcx, val, ty); - *cell = Load(bcx, val); - Store(bcx, oldval, val); } else { bcx = take_ty(bcx, val, ty); *cell = Load(bcx, val); @@ -5469,21 +5470,13 @@ fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id, // If this argument to this function is a tag, it'll have come in to // this function as an opaque blob due to the way that type_of() // works. So we have to cast to the destination's view of the type. - - let llargptr = alt fcx.llargs.find(va.id) { - some(local_mem(x)) { PointerCast(bcx, x, val_ty(lldestptr)) } - }; + let llarg = alt fcx.llargs.find(va.id) { some(local_mem(x)) { x } }; let arg_ty = arg_tys[i].ty; - let llargval; - if ty::type_is_structural(cx.ccx.tcx, arg_ty) || - ty::type_has_dynamic_size(cx.ccx.tcx, arg_ty) || - (ty::type_is_unique(cx.ccx.tcx, arg_ty) - && !ty::type_is_unique_box(cx.ccx.tcx, arg_ty)) { - // FIXME: Why do we do this for other unique pointer types but not - // unique boxes? Something's not quite right. - llargval = llargptr; - } else { llargval = Load(bcx, llargptr); } - bcx = copy_val(bcx, INIT, lldestptr, llargval, arg_ty); + if ty::type_contains_params(bcx_tcx(bcx), arg_ty) { + lldestptr = PointerCast(bcx, lldestptr, val_ty(llarg)); + } + llarg = load_if_immediate(bcx, llarg, arg_ty); + bcx = copy_val(bcx, INIT, lldestptr, llarg, arg_ty); i += 1u; } bcx = trans_block_cleanups(bcx, find_scope_cx(bcx)); @@ -5899,9 +5892,6 @@ fn register_native_fn(ccx: @crate_ctxt, sp: span, path: [str], name: str, let i = arg_n; for arg: ty::arg in args { let llarg = llvm::LLVMGetParam(fcx.llfn, i); - if arg.mode == ast::by_ref { - llarg = load_if_immediate(bcx, llarg, arg.ty); - } assert (llarg as int != 0); if cast_to_i32 { let llarg_i32 = convert_arg_to_i32(bcx, llarg, arg.ty, arg.mode); diff --git a/src/comp/middle/trans_alt.rs b/src/comp/middle/trans_alt.rs index 6ac217bdee9c0..29b903c3f89e9 100644 --- a/src/comp/middle/trans_alt.rs +++ b/src/comp/middle/trans_alt.rs @@ -49,10 +49,10 @@ fn trans_opt(bcx: @block_ctxt, o: opt) -> opt_result { alt l.node { ast::lit_str(s) { let strty = ty::mk_str(bcx_tcx(bcx)); - let {bcx, val: dst} = trans::alloc_ty(bcx, strty); - bcx = trans_vec::trans_str(bcx, s, trans::save_in(dst)); - add_clean_temp(bcx, dst, strty); - ret single_result(rslt(bcx, dst)); + let cell = trans::empty_dest_cell(); + bcx = trans_vec::trans_str(bcx, s, trans::by_val(cell)); + add_clean_temp(bcx, *cell, strty); + ret single_result(rslt(bcx, *cell)); } _ { ret single_result( @@ -473,8 +473,9 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail, } lit(l) { kind = alt l.node { - ast::lit_str(_) { compare } - ast::lit_nil. { test_val = Load(bcx, val); compare } + ast::lit_str(_) | ast::lit_nil. { + test_val = Load(bcx, val); compare + } _ { test_val = Load(bcx, val); switch } }; } diff --git a/src/comp/middle/trans_vec.rs b/src/comp/middle/trans_vec.rs index c772d026ffc9b..eddbda3f6a257 100644 --- a/src/comp/middle/trans_vec.rs +++ b/src/comp/middle/trans_vec.rs @@ -12,17 +12,10 @@ import trans::{call_memmove, trans_shared_malloc, llsize_of, type_of_or_i8, import trans_build::*; import trans_common::*; -fn get_fill(bcx: @block_ctxt, vptrptr: ValueRef) -> ValueRef { - Load(bcx, GEPi(bcx, Load(bcx, vptrptr), [0, abi::vec_elt_fill as int])) +fn get_fill(bcx: @block_ctxt, vptr: ValueRef) -> ValueRef { + Load(bcx, GEPi(bcx, vptr, [0, abi::vec_elt_fill as int])) } -fn get_alloc(bcx: @block_ctxt, vptrptr: ValueRef) -> ValueRef { - Load(bcx, GEPi(bcx, Load(bcx, vptrptr), [0, abi::vec_elt_alloc as int])) -} -fn get_dataptr(bcx: @block_ctxt, vptrptr: ValueRef, unit_ty: TypeRef) -> - ValueRef { - ret get_dataptr_simple(bcx, Load(bcx, vptrptr), unit_ty); -} -fn get_dataptr_simple(bcx: @block_ctxt, vptr: ValueRef, unit_ty: TypeRef) +fn get_dataptr(bcx: @block_ctxt, vptr: ValueRef, unit_ty: TypeRef) -> ValueRef { let ptr = GEPi(bcx, vptr, [0, abi::vec_elt_elems as int]); PointerCast(bcx, ptr, T_ptr(unit_ty)) @@ -71,31 +64,31 @@ fn alloc(bcx: @block_ctxt, vec_ty: ty::t, elts: uint) -> alloc_result { llunitty: llunitty}; } -fn duplicate(bcx: @block_ctxt, vptrptr: ValueRef) -> @block_ctxt { - let fill = get_fill(bcx, vptrptr); - let vptr = Load(bcx, vptrptr); +fn duplicate(bcx: @block_ctxt, vptr: ValueRef, vec_ty: ty::t) -> result { + let fill = get_fill(bcx, vptr); let size = Add(bcx, fill, llsize_of(T_opaque_vec())); let {bcx: bcx, val: newptr} = trans_shared_malloc(bcx, val_ty(vptr), size); let bcx = call_memmove(bcx, newptr, vptr, size).bcx; + let unit_ty = ty::sequence_element_type(bcx_tcx(bcx), vec_ty); Store(bcx, fill, InBoundsGEP(bcx, newptr, [C_int(0), C_uint(abi::vec_elt_alloc)])); - Store(bcx, newptr, vptrptr); - ret bcx; + if ty::type_needs_drop(bcx_tcx(bcx), unit_ty) { + bcx = iter_vec(bcx, newptr, vec_ty, trans::take_ty); + } + ret rslt(bcx, newptr); } -fn make_drop_glue(bcx: @block_ctxt, vptrptr: ValueRef, vec_ty: ty::t) -> +fn make_free_glue(bcx: @block_ctxt, vptr: ValueRef, vec_ty: ty::t) -> @block_ctxt { let unit_ty = ty::sequence_element_type(bcx_tcx(bcx), vec_ty); - let vptr = Load(bcx, vptrptr); let drop_cx = new_sub_block_ctxt(bcx, "drop"); let next_cx = new_sub_block_ctxt(bcx, "next"); let null_test = IsNull(bcx, vptr); CondBr(bcx, null_test, next_cx.llbb, drop_cx.llbb); if ty::type_needs_drop(bcx_tcx(bcx), unit_ty) { - drop_cx = iter_vec(drop_cx, vptrptr, vec_ty, trans::drop_ty); + drop_cx = iter_vec(drop_cx, vptr, vec_ty, trans::drop_ty); } drop_cx = trans::trans_shared_free(drop_cx, vptr); - Store(drop_cx, C_null(val_ty(vptr)), vptrptr); Br(drop_cx, next_cx.llbb); ret next_cx; } @@ -118,7 +111,7 @@ fn trans_vec(bcx: @block_ctxt, args: [@ast::expr], id: ast::node_id, add_clean_free(bcx, vptr, true); // Store the individual elements. - let dataptr = get_dataptr_simple(bcx, vptr, llunitty); + let dataptr = get_dataptr(bcx, vptr, llunitty); let i = 0u, temp_cleanups = [vptr]; for e in args { let lleltptr = if ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) { @@ -130,8 +123,7 @@ fn trans_vec(bcx: @block_ctxt, args: [@ast::expr], id: ast::node_id, i += 1u; } for clean in temp_cleanups { revoke_clean(bcx, clean); } - Store(bcx, vptr, trans::get_dest_addr(dest)); - ret bcx; + ret trans::store_in_dest(bcx, vptr, dest); } fn trans_str(bcx: @block_ctxt, s: str, dest: dest) -> @block_ctxt { @@ -141,50 +133,47 @@ fn trans_str(bcx: @block_ctxt, s: str, dest: dest) -> @block_ctxt { let llcstr = C_cstr(bcx_ccx(bcx), s); let bcx = - call_memmove(bcx, get_dataptr_simple(bcx, sptr, T_i8()), llcstr, + call_memmove(bcx, get_dataptr(bcx, sptr, T_i8()), llcstr, C_uint(veclen)).bcx; - Store(bcx, sptr, trans::get_dest_addr(dest)); - ret bcx; + ret trans::store_in_dest(bcx, sptr, dest); } fn trans_append(cx: @block_ctxt, vec_ty: ty::t, lhsptr: ValueRef, - rhsptr: ValueRef) -> @block_ctxt { + rhs: ValueRef) -> @block_ctxt { // Cast to opaque interior vector types if necessary. let unit_ty = ty::sequence_element_type(bcx_tcx(cx), vec_ty); let dynamic = ty::type_has_dynamic_size(bcx_tcx(cx), unit_ty); if dynamic { lhsptr = PointerCast(cx, lhsptr, T_ptr(T_ptr(T_opaque_vec()))); - rhsptr = PointerCast(cx, rhsptr, T_ptr(T_ptr(T_opaque_vec()))); + rhs = PointerCast(cx, rhs, T_ptr(T_opaque_vec())); } - let strings = - alt ty::struct(bcx_tcx(cx), vec_ty) { - ty::ty_str. { true } - ty::ty_vec(_) { false } - }; + let strings = alt ty::struct(bcx_tcx(cx), vec_ty) { + ty::ty_str. { true } + ty::ty_vec(_) { false } + }; let {bcx: bcx, val: unit_sz} = size_of(cx, unit_ty); let llunitty = type_of_or_i8(cx, unit_ty); - let rhs = Load(bcx, rhsptr); let lhs = Load(bcx, lhsptr); let self_append = ICmp(bcx, lib::llvm::LLVMIntEQ, lhs, rhs); - let lfill = get_fill(bcx, lhsptr); - let rfill = get_fill(bcx, rhsptr); + let lfill = get_fill(bcx, lhs); + let rfill = get_fill(bcx, rhs); let new_fill = Add(bcx, lfill, rfill); if strings { new_fill = Sub(bcx, new_fill, C_int(1)); } let opaque_lhs = PointerCast(bcx, lhsptr, T_ptr(T_ptr(T_opaque_vec()))); Call(bcx, bcx_ccx(cx).upcalls.vec_grow, [cx.fcx.lltaskptr, opaque_lhs, new_fill]); // Was overwritten if we resized - rhsptr = Select(bcx, self_append, lhsptr, rhsptr); + let lhs = Load(bcx, lhsptr); + rhs = Select(bcx, self_append, lhs, rhs); - let lhs_data = get_dataptr(bcx, lhsptr, llunitty); + let lhs_data = get_dataptr(bcx, lhs, llunitty); let lhs_off = lfill; if strings { lhs_off = Sub(bcx, lhs_off, C_int(1)); } let write_ptr = pointer_add(bcx, lhs_data, lhs_off); let write_ptr_ptr = do_spill_noroot(bcx, write_ptr); - let bcx = - iter_vec_raw(bcx, rhsptr, vec_ty, rfill, + let bcx = iter_vec_raw(bcx, rhs, vec_ty, rfill, // We have to increment by the dynamically-computed size. {|bcx, addr, _ty| let write_ptr = Load(bcx, write_ptr_ptr); @@ -221,8 +210,8 @@ fn trans_append_literal(bcx: @block_ctxt, vptrptr: ValueRef, vec_ty: ty::t, ret bcx; } -fn trans_add(bcx: @block_ctxt, vec_ty: ty::t, lhsptr: ValueRef, - rhsptr: ValueRef, dest: dest) -> @block_ctxt { +fn trans_add(bcx: @block_ctxt, vec_ty: ty::t, lhs: ValueRef, + rhs: ValueRef, dest: dest) -> @block_ctxt { let strings = alt ty::struct(bcx_tcx(bcx), vec_ty) { ty::ty_str. { true } ty::ty_vec(_) { false } @@ -231,15 +220,15 @@ fn trans_add(bcx: @block_ctxt, vec_ty: ty::t, lhsptr: ValueRef, let llunitty = type_of_or_i8(bcx, unit_ty); let {bcx: bcx, val: llunitsz} = size_of(bcx, unit_ty); - let lhs_fill = get_fill(bcx, lhsptr); + let lhs_fill = get_fill(bcx, lhs); if strings { lhs_fill = Sub(bcx, lhs_fill, C_int(1)); } - let rhs_fill = get_fill(bcx, rhsptr); + let rhs_fill = get_fill(bcx, rhs); let new_fill = Add(bcx, lhs_fill, rhs_fill); let {bcx: bcx, val: new_vec_ptr} = alloc_raw(bcx, new_fill, new_fill); new_vec_ptr = PointerCast(bcx, new_vec_ptr, T_ptr(T_vec(llunitty))); let write_ptr_ptr = do_spill_noroot - (bcx, get_dataptr_simple(bcx, new_vec_ptr, llunitty)); + (bcx, get_dataptr(bcx, new_vec_ptr, llunitty)); let copy_fn = bind fn (bcx: @block_ctxt, addr: ValueRef, _ty: ty::t, write_ptr_ptr: ValueRef, unit_ty: ty::t, llunitsz: ValueRef) @@ -256,23 +245,22 @@ fn trans_add(bcx: @block_ctxt, vec_ty: ty::t, lhsptr: ValueRef, ret bcx; }(_, _, _, write_ptr_ptr, unit_ty, llunitsz); - let bcx = iter_vec_raw(bcx, lhsptr, vec_ty, lhs_fill, copy_fn); - bcx = iter_vec_raw(bcx, rhsptr, vec_ty, rhs_fill, copy_fn); - Store(bcx, new_vec_ptr, trans::get_dest_addr(dest)); - ret bcx; + let bcx = iter_vec_raw(bcx, lhs, vec_ty, lhs_fill, copy_fn); + bcx = iter_vec_raw(bcx, rhs, vec_ty, rhs_fill, copy_fn); + ret trans::store_in_dest(bcx, new_vec_ptr, dest); } type val_and_ty_fn = fn(@block_ctxt, ValueRef, ty::t) -> result; type iter_vec_block = block(@block_ctxt, ValueRef, ty::t) -> @block_ctxt; -fn iter_vec_raw(bcx: @block_ctxt, vptrptr: ValueRef, vec_ty: ty::t, +fn iter_vec_raw(bcx: @block_ctxt, vptr: ValueRef, vec_ty: ty::t, fill: ValueRef, f: iter_vec_block) -> @block_ctxt { let unit_ty = ty::sequence_element_type(bcx_tcx(bcx), vec_ty); let llunitty = type_of_or_i8(bcx, unit_ty); let {bcx: bcx, val: unit_sz} = size_of(bcx, unit_ty); - vptrptr = PointerCast(bcx, vptrptr, T_ptr(T_ptr(T_vec(llunitty)))); - let data_ptr = get_dataptr(bcx, vptrptr, llunitty); + vptr = PointerCast(bcx, vptr, T_ptr(T_vec(llunitty))); + let data_ptr = get_dataptr(bcx, vptr, llunitty); // Calculate the last pointer address we want to handle. // TODO: Optimize this when the size of the unit type is statically @@ -299,10 +287,10 @@ fn iter_vec_raw(bcx: @block_ctxt, vptrptr: ValueRef, vec_ty: ty::t, ret next_cx; } -fn iter_vec(bcx: @block_ctxt, vptrptr: ValueRef, vec_ty: ty::t, +fn iter_vec(bcx: @block_ctxt, vptr: ValueRef, vec_ty: ty::t, f: iter_vec_block) -> @block_ctxt { - vptrptr = PointerCast(bcx, vptrptr, T_ptr(T_ptr(T_opaque_vec()))); - ret iter_vec_raw(bcx, vptrptr, vec_ty, get_fill(bcx, vptrptr), f); + vptr = PointerCast(bcx, vptr, T_ptr(T_opaque_vec())); + ret iter_vec_raw(bcx, vptr, vec_ty, get_fill(bcx, vptr), f); } // diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index faf11cb691a4f..428278b413241 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -920,7 +920,7 @@ pure fn type_is_scalar(cx: ctxt, ty: t) -> bool { // FIXME maybe inline this for speed? fn type_is_immediate(cx: ctxt, ty: t) -> bool { ret type_is_scalar(cx, ty) || type_is_boxed(cx, ty) || - type_is_unique_box(cx, ty) || type_is_native(cx, ty); + type_is_unique(cx, ty) || type_is_native(cx, ty); } fn type_has_pointers(cx: ctxt, ty: t) -> bool { diff --git a/src/lib/posix_fs.rs b/src/lib/posix_fs.rs index a20f9d7711f15..5ebebc2748a35 100644 --- a/src/lib/posix_fs.rs +++ b/src/lib/posix_fs.rs @@ -1,6 +1,6 @@ native "rust" mod rustrt { - fn rust_list_files(path: str) -> [str]; + fn rust_list_files(&&path: str) -> [str]; } fn list_dir(path: str) -> [str] { diff --git a/src/lib/vec.rs b/src/lib/vec.rs index 59f29d40d7c1f..bf21e056f6c84 100644 --- a/src/lib/vec.rs +++ b/src/lib/vec.rs @@ -5,7 +5,7 @@ import uint::next_power_of_two; import ptr::addr_of; native "rust-intrinsic" mod rusti { - fn vec_len(v: [T]) -> uint; + fn vec_len(&&v: [T]) -> uint; } native "rust" mod rustrt { diff --git a/src/lib/win32_fs.rs b/src/lib/win32_fs.rs index dcd8a905d2eff..e1bfb24b6d182 100644 --- a/src/lib/win32_fs.rs +++ b/src/lib/win32_fs.rs @@ -1,8 +1,8 @@ native "rust" mod rustrt { - fn rust_list_files(path: str) -> [str]; - fn rust_file_is_dir(path: str) -> int; + fn rust_list_files(&&path: str) -> [str]; + fn rust_file_is_dir(&&path: str) -> int; } fn list_dir(path: str) -> [str] { diff --git a/src/test/run-pass/interior-vec.rs b/src/test/run-pass/interior-vec.rs index 20487ed6f4c13..0c0a3c17179b4 100644 --- a/src/test/run-pass/interior-vec.rs +++ b/src/test/run-pass/interior-vec.rs @@ -1,7 +1,7 @@ import rusti::vec_len; native "rust-intrinsic" mod rusti { - fn vec_len(v: [T]) -> uint; + fn vec_len(&&v: [T]) -> uint; } fn main() {