Skip to content

fix #1352: change param order on vec::init_fn (and vec::init_fn_mut), putting block in final position. #1559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/comp/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
let s = "fn(";
let out_ty: TypeRef = llvm::LLVMGetReturnType(ty);
let n_args = llvm::LLVMCountParamTypes(ty) as uint;
let args: [TypeRef] = vec::init_elt::<TypeRef>(0 as TypeRef, n_args);
let args: [TypeRef] = vec::init_elt::<TypeRef>(n_args, 0 as TypeRef);
unsafe {
llvm::LLVMGetParamTypes(ty, vec::to_ptr(args));
}
Expand All @@ -984,7 +984,7 @@ fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) ->
10 {
let s: str = "{";
let n_elts = llvm::LLVMCountStructElementTypes(ty) as uint;
let elts: [TypeRef] = vec::init_elt::<TypeRef>(0 as TypeRef, n_elts);
let elts: [TypeRef] = vec::init_elt::<TypeRef>(n_elts, 0 as TypeRef);
unsafe {
llvm::LLVMGetStructElementTypes(ty, vec::to_ptr(elts));
}
Expand Down Expand Up @@ -1027,8 +1027,8 @@ fn float_width(llt: TypeRef) -> uint {
}

fn fn_ty_param_tys(fn_ty: TypeRef) -> [TypeRef] unsafe {
let args = vec::init_elt(0 as TypeRef,
llvm::LLVMCountParamTypes(fn_ty) as uint);
let args = vec::init_elt(llvm::LLVMCountParamTypes(fn_ty) as uint,
0 as TypeRef);
llvm::LLVMGetParamTypes(fn_ty, vec::to_ptr(args));
ret args;
}
Expand Down
4 changes: 2 additions & 2 deletions src/comp/middle/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ fn get_simple_extern_fn(cx: @block_ctxt,
llmod: ModuleRef,
name: str, n_args: int) -> ValueRef {
let ccx = cx.fcx.lcx.ccx;
let inputs = vec::init_elt::<TypeRef>(ccx.int_type, n_args as uint);
let inputs = vec::init_elt::<TypeRef>(n_args as uint, ccx.int_type);
let output = ccx.int_type;
let t = T_fn(inputs, output);
ret get_extern_fn(externs, llmod, name,
Expand Down Expand Up @@ -2869,7 +2869,7 @@ fn lval_maybe_callee_to_lval(c: lval_maybe_callee, ty: ty::t) -> lval_result {
alt c.generic {
some(gi) {
let n_args = vec::len(ty::ty_fn_args(bcx_tcx(c.bcx), ty));
let args = vec::init_elt(none::<@ast::expr>, n_args);
let args = vec::init_elt(n_args, none::<@ast::expr>);
let space = alloc_ty(c.bcx, ty);
let bcx = trans_closure::trans_bind_1(space.bcx, ty, c, args, ty,
save_in(space.val));
Expand Down
8 changes: 4 additions & 4 deletions src/comp/middle/trans_alt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ fn enter_opt(ccx: @crate_ctxt, m: match, opt: opt, col: uint, tag_size: uint,
ast::pat_range(l1, l2) {
ret if opt_eq(range(l1, l2), opt) { some([]) } else { none };
}
_ { ret some(vec::init_elt(dummy, size)); }
_ { ret some(vec::init_elt(size, dummy)); }
}
}
ret enter_match(m, col, val, bind e(ccx, dummy, opt, tag_size, _));
Expand All @@ -197,7 +197,7 @@ fn enter_rec(m: match, col: uint, fields: [ast::ident], val: ValueRef) ->
}
ret some(pats);
}
_ { ret some(vec::init_elt(dummy, vec::len(fields))); }
_ { ret some(vec::init_elt(vec::len(fields), dummy)); }
}
}
ret enter_match(m, col, val, bind e(dummy, fields, _));
Expand All @@ -209,7 +209,7 @@ fn enter_tup(m: match, col: uint, val: ValueRef, n_elts: uint) -> match {
option::t<[@ast::pat]> {
alt p.node {
ast::pat_tup(elts) { ret some(elts); }
_ { ret some(vec::init_elt(dummy, n_elts)); }
_ { ret some(vec::init_elt(n_elts, dummy)); }
}
}
ret enter_match(m, col, val, bind e(dummy, n_elts, _));
Expand Down Expand Up @@ -343,7 +343,7 @@ fn pick_col(m: match) -> uint {
_ { 0u }
}
}
let scores = vec::init_elt_mut(0u, vec::len(m[0].pats));
let scores = vec::init_elt_mut(vec::len(m[0].pats), 0u);
for br: match_branch in m {
let i = 0u;
for p: @ast::pat in br.pats { scores[i] += score(p); i += 1u; }
Expand Down
8 changes: 4 additions & 4 deletions src/comp/middle/trans_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ fn val_str(tn: type_names, v: ValueRef) -> str { ret ty_str(tn, val_ty(v)); }
fn struct_elt(llstructty: TypeRef, n: uint) -> TypeRef unsafe {
let elt_count = llvm::LLVMCountStructElementTypes(llstructty) as uint;
assert (n < elt_count);
let elt_tys = vec::init_elt(T_nil(), elt_count);
let elt_tys = vec::init_elt(elt_count, T_nil());
llvm::LLVMGetStructElementTypes(llstructty, to_ptr(elt_tys));
ret llvm::LLVMGetElementType(elt_tys[n]);
}
Expand Down Expand Up @@ -594,8 +594,8 @@ fn T_tydesc_field(cx: @crate_ctxt, field: int) -> TypeRef unsafe {
// Bit of a kludge: pick the fn typeref out of the tydesc..

let tydesc_elts: [TypeRef] =
vec::init_elt::<TypeRef>(T_nil(),
abi::n_tydesc_fields as uint);
vec::init_elt::<TypeRef>(abi::n_tydesc_fields as uint,
T_nil());
llvm::LLVMGetStructElementTypes(cx.tydesc_type,
to_ptr::<TypeRef>(tydesc_elts));
let t = llvm::LLVMGetElementType(tydesc_elts[field]);
Expand Down Expand Up @@ -729,7 +729,7 @@ fn T_opaque_tag_ptr(cx: @crate_ctxt) -> TypeRef {
}

fn T_captured_tydescs(cx: @crate_ctxt, n: uint) -> TypeRef {
ret T_struct(vec::init_elt::<TypeRef>(T_ptr(cx.tydesc_type), n));
ret T_struct(vec::init_elt::<TypeRef>(n, T_ptr(cx.tydesc_type)));
}

fn T_opaque_iface_ptr(cx: @crate_ctxt) -> TypeRef {
Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/trans_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fn trans_iface_callee(bcx: @block_ctxt, fld_expr: @ast::expr,
fn llfn_arg_tys(ft: TypeRef) -> {inputs: [TypeRef], output: TypeRef} {
let out_ty = llvm::LLVMGetReturnType(ft);
let n_args = llvm::LLVMCountParamTypes(ft);
let args = vec::init_elt(0 as TypeRef, n_args as uint);
let args = vec::init_elt(n_args as uint, 0 as TypeRef);
unsafe { llvm::LLVMGetParamTypes(ft, vec::to_ptr(args)); }
{inputs: args, output: out_ty}
}
Expand Down
12 changes: 6 additions & 6 deletions src/comp/middle/tstate/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
alt e.node {
expr_vec(elts, _) {
ret find_pre_post_state_exprs(fcx, pres, e.id,
vec::init_elt(init_assign,
vec::len(elts)), elts,
vec::init_elt(vec::len(elts),
init_assign), elts,
return_val);
}
expr_call(operator, operands, _) {
Expand Down Expand Up @@ -386,8 +386,8 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
expr_rec(fields, maybe_base) {
let changed =
find_pre_post_state_exprs(fcx, pres, e.id,
vec::init_elt(init_assign,
vec::len(fields)),
vec::init_elt(vec::len(fields),
init_assign),
field_exprs(fields), return_val);
alt maybe_base {
none. {/* do nothing */ }
Expand All @@ -402,8 +402,8 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
}
expr_tup(elts) {
ret find_pre_post_state_exprs(fcx, pres, e.id,
vec::init_elt(init_assign,
vec::len(elts)), elts,
vec::init_elt(vec::len(elts),
init_assign), elts,
return_val);
}
expr_copy(a) { ret find_pre_post_state_sub(fcx, pres, a, e.id, none); }
Expand Down
10 changes: 5 additions & 5 deletions src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fn instantiate_path(fcx: @fn_ctxt, pth: @ast::path,
tpt: ty_param_bounds_and_ty, sp: span)
-> ty_param_substs_opt_and_ty {
let ty_param_count = vec::len(*tpt.bounds);
let vars = vec::init_fn({|_i| next_ty_var(fcx)}, ty_param_count);
let vars = vec::init_fn(ty_param_count, {|_i| next_ty_var(fcx)});
let ty_substs_len = vec::len(pth.node.types);
if ty_substs_len > 0u {
let param_var_len = vec::len(vars);
Expand Down Expand Up @@ -611,9 +611,9 @@ fn compare_impl_method(tcx: ty::ctxt, sp: span, impl_m: ty::method,
} else {
let impl_fty = ty::mk_fn(tcx, impl_m.fty);
// Add dummy substs for the parameters of the impl method
let substs = substs + vec::init_fn({|i|
let substs = substs + vec::init_fn(vec::len(*if_m.tps), {|i|
ty::mk_param(tcx, i + impl_tps, {crate: 0, node: 0})
}, vec::len(*if_m.tps));
});
let if_fty = ty::substitute_type_params(tcx, substs,
ty::mk_fn(tcx, if_m.fty));
alt ty::unify::unify(impl_fty, if_fty, ty::unify::precise, tcx) {
Expand Down Expand Up @@ -1650,7 +1650,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
// HACK: build an arguments list with dummy arguments to
// check against
let dummy = {mode: ast::by_ref, ty: ty::mk_bot(fcx.ccx.tcx)};
arg_tys = vec::init_elt(dummy, supplied_arg_count);
arg_tys = vec::init_elt(supplied_arg_count, dummy);
}

// Check the arguments.
Expand Down Expand Up @@ -2334,7 +2334,7 @@ fn next_ty_var(fcx: @fn_ctxt) -> ty::t {

fn bind_params(fcx: @fn_ctxt, tp: ty::t, count: uint)
-> {vars: [ty::t], ty: ty::t} {
let vars = vec::init_fn({|_i| next_ty_var(fcx)}, count);
let vars = vec::init_fn(count, {|_i| next_ty_var(fcx)});
{vars: vars, ty: ty::substitute_type_params(fcx.ccx.tcx, vars, tp)}
}

Expand Down
6 changes: 3 additions & 3 deletions src/comp/syntax/print/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ fn mk_printer(out: io::writer, linewidth: uint) -> printer {
// fall behind.
let n: uint = 3u * linewidth;
#debug("mk_printer %u", linewidth);
let token: [mutable token] = vec::init_elt_mut(EOF, n);
let size: [mutable int] = vec::init_elt_mut(0, n);
let scan_stack: [mutable uint] = vec::init_elt_mut(0u, n);
let token: [mutable token] = vec::init_elt_mut(n, EOF);
let size: [mutable int] = vec::init_elt_mut(n, 0);
let scan_stack: [mutable uint] = vec::init_elt_mut(n, 0u);
let print_stack: [print_stack_elt] = [];
@{out: out,
buf_len: n,
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ fn check_expected_errors(expected_errors: [errors::expected_error],
procres: procres) {

// true if we found the error in question
let found_flags = vec::init_elt_mut(false, vec::len(expected_errors));
let found_flags = vec::init_elt_mut(vec::len(expected_errors), false);

if procres.status == 0 {
fatal("process did not return an error status");
Expand Down
10 changes: 5 additions & 5 deletions src/libcore/extfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ mod rt {
let len = str::char_len(s);
if len < prec {
let diff = prec - len;
let pad = str_init_elt('0', diff);
let pad = str_init_elt(diff, '0');
pad + s
} else { s }
};
Expand All @@ -386,8 +386,8 @@ mod rt {
}

// FIXME: This might be useful in str: but needs to be utf8 safe first
fn str_init_elt(c: char, n_elts: uint) -> str {
let svec = vec::init_elt::<u8>(c as u8, n_elts);
fn str_init_elt(n_elts: uint, c: char) -> str {
let svec = vec::init_elt::<u8>(n_elts, c as u8);

ret str::unsafe_from_bytes(svec);
}
Expand All @@ -407,7 +407,7 @@ mod rt {
let padchar = ' ';
let diff = uwidth - strlen;
if have_flag(cv.flags, flag_left_justify) {
let padstr = str_init_elt(padchar, diff);
let padstr = str_init_elt(diff, padchar);
ret s + padstr;
}
let might_zero_pad = false;
Expand All @@ -429,7 +429,7 @@ mod rt {
padchar = '0';
zero_padding = true;
}
let padstr = str_init_elt(padchar, diff);
let padstr = str_init_elt(diff, padchar);
// This is completely heinous. If we have a signed value then
// potentially rip apart the intermediate result and insert some
// zeros. It may make sense to convert zero padding to a precision
Expand Down
20 changes: 10 additions & 10 deletions src/libcore/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Creates and initializes an immutable vector.
Creates an immutable vector of size `n_elts` and initializes the elements
to the value returned by the function `op`.
*/
fn init_fn<T>(op: init_op<T>, n_elts: uint) -> [T] {
fn init_fn<T>(n_elts: uint, op: init_op<T>) -> [T] {
let v = [];
reserve(v, n_elts);
let i: uint = 0u;
Expand All @@ -105,7 +105,7 @@ Creates and initializes a mutable vector.
Creates a mutable vector of size `n_elts` and initializes the elements to
the value returned by the function `op`.
*/
fn init_fn_mut<T>(op: init_op<T>, n_elts: uint) -> [mutable T] {
fn init_fn_mut<T>(n_elts: uint, op: init_op<T>) -> [mutable T] {
let v = [mutable];
reserve(v, n_elts);
let i: uint = 0u;
Expand All @@ -121,7 +121,7 @@ Creates and initializes an immutable vector.
Creates an immutable vector of size `n_elts` and initializes the elements
to the value `t`.
*/
fn init_elt<T: copy>(t: T, n_elts: uint) -> [T] {
fn init_elt<T: copy>(n_elts: uint, t: T) -> [T] {
let v = [];
reserve(v, n_elts);
let i: uint = 0u;
Expand All @@ -138,7 +138,7 @@ Creates and initializes a mutable vector.
Creates a mutable vector of size `n_elts` and initializes the elements
to the value `t`.
*/
fn init_elt_mut<T: copy>(t: T, n_elts: uint) -> [mutable T] {
fn init_elt_mut<T: copy>(n_elts: uint, t: T) -> [mutable T] {
let v = [mutable];
reserve(v, n_elts);
let i: uint = 0u;
Expand Down Expand Up @@ -365,13 +365,13 @@ Function: grow_fn
Expands a vector in place, initializing the new elements to the result of a
function

Function `init_fn` is called `n` times with the values [0..`n`)
Function `init_op` is called `n` times with the values [0..`n`)

Parameters:

v - The vector to grow
n - The number of elements to add
init_fn - A function to call to retreive each appended element's value
init_op - A function to call to retreive each appended element's value
*/
fn grow_fn<T>(&v: [T], n: uint, op: init_op<T>) {
reserve(v, next_power_of_two(len(v) + n));
Expand Down Expand Up @@ -1026,14 +1026,14 @@ mod tests {
#[test]
fn test_init_fn() {
// Test on-stack init_fn.
let v = init_fn(square, 3u);
let v = init_fn(3u, square);
assert (len(v) == 3u);
assert (v[0] == 0u);
assert (v[1] == 1u);
assert (v[2] == 4u);

// Test on-heap init_fn.
v = init_fn(square, 5u);
v = init_fn(5u, square);
assert (len(v) == 5u);
assert (v[0] == 0u);
assert (v[1] == 1u);
Expand All @@ -1045,13 +1045,13 @@ mod tests {
#[test]
fn test_init_elt() {
// Test on-stack init_elt.
let v = init_elt(10u, 2u);
let v = init_elt(2u, 10u);
assert (len(v) == 2u);
assert (v[0] == 10u);
assert (v[1] == 10u);

// Test on-heap init_elt.
v = init_elt(20u, 6u);
v = init_elt(6u, 20u);
assert (v[0] == 20u);
assert (v[1] == 20u);
assert (v[2] == 20u);
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ init - If true then the bits are initialized to 1, otherwise 0
*/
fn create(nbits: uint, init: bool) -> t {
let elt = if init { !0u } else { 0u };
let storage = vec::init_elt_mut::<uint>(elt, nbits / uint_bits + 1u);
let storage = vec::init_elt_mut::<uint>(nbits / uint_bits + 1u, elt);
ret @{storage: storage, nbits: nbits};
}

Expand Down Expand Up @@ -117,7 +117,7 @@ Function: clone
Makes a copy of a bitvector
*/
fn clone(v: t) -> t {
let storage = vec::init_elt_mut::<uint>(0u, v.nbits / uint_bits + 1u);
let storage = vec::init_elt_mut::<uint>(v.nbits / uint_bits + 1u, 0u);
let len = vec::len(v.storage);
uint::range(0u, len) {|i| storage[i] = v.storage[i]; };
ret @{storage: storage, nbits: v.nbits};
Expand Down Expand Up @@ -267,7 +267,7 @@ in the resulting vector has either value 0u or 1u.
*/
fn to_vec(v: t) -> [uint] {
let sub = bind init_to_vec(v, _);
ret vec::init_fn::<uint>(sub, v.nbits);
ret vec::init_fn::<uint>(v.nbits, sub);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn create<T: copy>() -> t<T> {
mutable nelts: 0u,
mutable lo: 0u,
mutable hi: 0u,
mutable elts: vec::init_elt_mut(none, initial_capacity)
mutable elts: vec::init_elt_mut(initial_capacity, none)
};
repr as t::<T>
}
Expand Down
Loading