Skip to content

Commit 33167f7

Browse files
committed
Adjust function signatures to allow for vecs being immediate
Some code was relying on vectors being implicitly by-reference (as non-immediate value). This adds the necessary &&-sigils. Closes #1021
1 parent b4bae8f commit 33167f7

File tree

15 files changed

+34
-38
lines changed

15 files changed

+34
-38
lines changed

src/comp/back/rpath.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn get_rpaths_relative_to_output(os: session::os,
101101
fn get_rpath_relative_to_output(os: session::os,
102102
cwd: fs::path,
103103
output: fs::path,
104-
lib: fs::path) -> str {
104+
&&lib: fs::path) -> str {
105105
// Mac doesn't appear to support $ORIGIN
106106
let prefix = alt os {
107107
session::os_linux. { "$ORIGIN" + fs::path_sep() }
@@ -154,7 +154,7 @@ fn get_absolute_rpaths(cwd: fs::path, libs: [fs::path]) -> [str] {
154154
vec::map(bind get_absolute_rpath(cwd, _), libs)
155155
}
156156

157-
fn get_absolute_rpath(cwd: fs::path, lib: fs::path) -> str {
157+
fn get_absolute_rpath(cwd: fs::path, &&lib: fs::path) -> str {
158158
fs::dirname(get_absolute(cwd, lib))
159159
}
160160

src/comp/driver/rustc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ fn build_session(sopts: @session::options) -> session::session {
409409
none, 0u, filesearch);
410410
}
411411

412-
fn parse_pretty(sess: session::session, name: str) -> pp_mode {
412+
fn parse_pretty(sess: session::session, &&name: str) -> pp_mode {
413413
if str::eq(name, "normal") {
414414
ret ppm_normal;
415415
} else if str::eq(name, "expanded") {

src/comp/front/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fn in_cfg(cfg: ast::crate_cfg, attrs: [ast::attribute]) -> bool {
9898
// so we can match against them. This is the list of configurations for
9999
// which the item is valid
100100
let item_cfg_metas = {
101-
fn extract_metas(inner_items: [@ast::meta_item],
101+
fn extract_metas(&&inner_items: [@ast::meta_item],
102102
&&cfg_item: @ast::meta_item) -> [@ast::meta_item] {
103103
alt cfg_item.node {
104104
ast::meta_list(name, items) {

src/comp/metadata/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const tag_items_data_item_inlineness: uint = 0x27u;
6767
// djb's cdb hashes.
6868
fn hash_node_id(&&node_id: int) -> uint { ret 177573u ^ (node_id as uint); }
6969

70-
fn hash_path(s: str) -> uint {
70+
fn hash_path(&&s: str) -> uint {
7171
let h = 5381u;
7272
for ch: u8 in str::bytes(s) { h = (h << 5u) + h ^ (ch as uint); }
7373
ret h;

src/comp/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ fn encode_index<T>(ebml_w: ebml::writer, buckets: [@[entry<T>]],
425425
ebml::end_tag(ebml_w);
426426
}
427427

428-
fn write_str(writer: io::writer, s: str) { writer.write_str(s); }
428+
fn write_str(writer: io::writer, &&s: str) { writer.write_str(s); }
429429

430430
fn write_int(writer: io::writer, &&n: int) {
431431
writer.write_be_uint(n as uint, 4u);

src/comp/middle/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ fn add_name(ch: checker, sp: span, name: ident) {
14001400
ch.seen += [name];
14011401
}
14021402

1403-
fn ident_id(i: ident) -> ident { ret i; }
1403+
fn ident_id(&&i: ident) -> ident { ret i; }
14041404

14051405
fn ensure_unique<T>(e: env, sp: span, elts: [T], id: fn(T) -> ident,
14061406
kind: str) {

src/comp/middle/trans.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5633,7 +5633,7 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
56335633
takes_argv: bool) -> ValueRef {
56345634
let unit_ty = ty::mk_str(ccx.tcx);
56355635
let vecarg_ty: ty::arg =
5636-
{mode: ast::by_ref,
5636+
{mode: ast::by_val,
56375637
ty: ty::mk_vec(ccx.tcx, {ty: unit_ty, mut: ast::imm})};
56385638
// FIXME: mk_nil should have a postcondition
56395639
let nt = ty::mk_nil(ccx.tcx);
@@ -5653,14 +5653,7 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
56535653
let lltaskarg = llvm::LLVMGetParam(llfdecl, 1u);
56545654
let llenvarg = llvm::LLVMGetParam(llfdecl, 2u);
56555655
let args = [lloutputarg, lltaskarg, llenvarg];
5656-
if takes_argv {
5657-
let llargvarg = llvm::LLVMGetParam(llfdecl, 3u);
5658-
// The runtime still passes the arg vector by value, this kludge
5659-
// makes sure it becomes a pointer (to a pointer to a vec).
5660-
let minus_ptr = llvm::LLVMGetElementType(val_ty(llargvarg));
5661-
llargvarg = PointerCast(bcx, llargvarg, minus_ptr);
5662-
args += [do_spill_noroot(bcx, llargvarg)];
5663-
}
5656+
if takes_argv { args += [llvm::LLVMGetParam(llfdecl, 3u)]; }
56645657
Call(bcx, main_llfn, args);
56655658
build_return(bcx);
56665659

@@ -5944,7 +5937,7 @@ fn register_native_fn(ccx: @crate_ctxt, sp: span, path: [str], name: str,
59445937

59455938
fn item_path(item: @ast::item) -> [str] { ret [item.ident]; }
59465939

5947-
fn collect_native_item(ccx: @crate_ctxt, i: @ast::native_item, pt: [str],
5940+
fn collect_native_item(ccx: @crate_ctxt, i: @ast::native_item, &&pt: [str],
59485941
_v: vt<[str]>) {
59495942
alt i.node {
59505943
ast::native_item_fn(_, _, _) {
@@ -5956,7 +5949,8 @@ fn collect_native_item(ccx: @crate_ctxt, i: @ast::native_item, pt: [str],
59565949
}
59575950
}
59585951

5959-
fn collect_item_1(ccx: @crate_ctxt, i: @ast::item, pt: [str], v: vt<[str]>) {
5952+
fn collect_item_1(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
5953+
v: vt<[str]>) {
59605954
visit::visit_item(i, pt + item_path(i), v);
59615955
alt i.node {
59625956
ast::item_const(_, _) {
@@ -5977,7 +5971,8 @@ fn collect_item_1(ccx: @crate_ctxt, i: @ast::item, pt: [str], v: vt<[str]>) {
59775971
}
59785972
}
59795973

5980-
fn collect_item_2(ccx: @crate_ctxt, i: @ast::item, pt: [str], v: vt<[str]>) {
5974+
fn collect_item_2(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
5975+
v: vt<[str]>) {
59815976
let new_pt = pt + item_path(i);
59825977
visit::visit_item(i, new_pt, v);
59835978
alt i.node {
@@ -6018,7 +6013,7 @@ fn collect_items(ccx: @crate_ctxt, crate: @ast::crate) {
60186013
visit::visit_crate(*crate, [], visit::mk_vt(visitor2));
60196014
}
60206015

6021-
fn collect_tag_ctor(ccx: @crate_ctxt, i: @ast::item, pt: [str],
6016+
fn collect_tag_ctor(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
60226017
v: vt<[str]>) {
60236018
let new_pt = pt + item_path(i);
60246019
visit::visit_item(i, new_pt, v);
@@ -6044,7 +6039,8 @@ fn collect_tag_ctors(ccx: @crate_ctxt, crate: @ast::crate) {
60446039

60456040

60466041
// The constant translation pass.
6047-
fn trans_constant(ccx: @crate_ctxt, it: @ast::item, pt: [str], v: vt<[str]>) {
6042+
fn trans_constant(ccx: @crate_ctxt, it: @ast::item, &&pt: [str],
6043+
v: vt<[str]>) {
60486044
let new_pt = pt + item_path(it);
60496045
visit::visit_item(it, new_pt, v);
60506046
alt it.node {

src/comp/syntax/ext/simplext.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fn follow_for_trans(cx: ext_ctxt, mmaybe: option::t<arb_depth<matchable>>,
245245
/* helper for transcribe_exprs: what vars from `b` occur in `e`? */
246246
iter free_vars(b: bindings, e: @expr) -> ident {
247247
let idents: hashmap<ident, ()> = new_str_hash::<()>();
248-
fn mark_ident(i: ident, _fld: ast_fold, b: bindings,
248+
fn mark_ident(&&i: ident, _fld: ast_fold, b: bindings,
249249
idents: hashmap<ident, ()>) -> ident {
250250
if b.contains_key(i) { idents.insert(i, ()); }
251251
ret i;
@@ -325,7 +325,7 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint],
325325

326326
// substitute, in a position that's required to be an ident
327327
fn transcribe_ident(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint],
328-
i: ident, _fld: ast_fold) -> ident {
328+
&&i: ident, _fld: ast_fold) -> ident {
329329
ret alt follow_for_trans(cx, b.find(i), idx_path) {
330330
some(match_ident(a_id)) { a_id.node }
331331
some(m) { match_error(cx, m, "an identifier") }

src/comp/syntax/fold.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type ast_fold_precursor =
3939
fold_mod: fn(_mod, ast_fold) -> _mod,
4040
fold_native_mod: fn(native_mod, ast_fold) -> native_mod,
4141
fold_variant: fn(variant_, ast_fold) -> variant_,
42-
fold_ident: fn(ident, ast_fold) -> ident,
42+
fold_ident: fn(&&ident, ast_fold) -> ident,
4343
fold_path: fn(path_, ast_fold) -> path_,
4444
fold_local: fn(local_, ast_fold) -> local_,
4545
map_exprs: fn(fn(&&@expr) -> @expr, [@expr]) -> [@expr],
@@ -66,7 +66,7 @@ type a_f =
6666
fold_mod: fn(_mod) -> _mod,
6767
fold_native_mod: fn(native_mod) -> native_mod,
6868
fold_variant: fn(variant) -> variant,
69-
fold_ident: fn(ident) -> ident,
69+
fold_ident: fn(&&ident) -> ident,
7070
fold_path: fn(path) -> path,
7171
fold_local: fn(&&@local) -> @local,
7272
map_exprs: fn(fn(&&@expr) -> @expr, [@expr]) -> [@expr],
@@ -96,7 +96,7 @@ fn nf_fn_dummy(_f: _fn) -> _fn { fail; }
9696
fn nf_mod_dummy(_m: _mod) -> _mod { fail; }
9797
fn nf_native_mod_dummy(_n: native_mod) -> native_mod { fail; }
9898
fn nf_variant_dummy(_v: variant) -> variant { fail; }
99-
fn nf_ident_dummy(_i: ident) -> ident { fail; }
99+
fn nf_ident_dummy(&&_i: ident) -> ident { fail; }
100100
fn nf_path_dummy(_p: path) -> path { fail; }
101101
fn nf_obj_field_dummy(_o: obj_field) -> obj_field { fail; }
102102
fn nf_local_dummy(&&_o: @local) -> @local { fail; }
@@ -471,7 +471,7 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
471471
ret {name: v.name, args: vec::map(fold_variant_arg, v.args), id: v.id};
472472
}
473473

474-
fn noop_fold_ident(i: ident, _fld: ast_fold) -> ident { ret i; }
474+
fn noop_fold_ident(&&i: ident, _fld: ast_fold) -> ident { ret i; }
475475

476476
fn noop_fold_path(p: path_, fld: ast_fold) -> path_ {
477477
ret {global: p.global,
@@ -667,7 +667,7 @@ fn make_fold(afp: ast_fold_precursor) -> @foldres {
667667
variant {
668668
ret {node: afp.fold_variant(x.node, f), span: afp.new_span(x.span)};
669669
}
670-
fn f_ident(afp: ast_fold_precursor, f: ast_fold, x: ident) -> ident {
670+
fn f_ident(afp: ast_fold_precursor, f: ast_fold, &&x: ident) -> ident {
671671
ret afp.fold_ident(x, f);
672672
}
673673
fn f_path(afp: ast_fold_precursor, f: ast_fold, x: path) -> path {

src/comp/syntax/print/pprust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ fn print_view_item(s: ps, item: @ast::view_item) {
12771277
ast::view_item_export(ids, _) {
12781278
head(s, "export");
12791279
commasep(s, inconsistent, ids,
1280-
fn (s: ps, w: ast::ident) { word(s.s, w) });
1280+
fn (s: ps, &&w: ast::ident) { word(s.s, w) });
12811281
}
12821282
}
12831283
word(s.s, ";");

src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ fn make_run_args(config: config, _props: test_props, testfile: str) ->
276276

277277
fn split_maybe_args(argstr: option::t<str>) -> [str] {
278278
fn rm_whitespace(v: [str]) -> [str] {
279-
fn flt(s: str) -> option::t<str> {
279+
fn flt(&&s: str) -> option::t<str> {
280280
if !is_whitespace(s) { option::some(s) } else { option::none }
281281
}
282282

src/lib/str.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ native "rust" mod rustrt {
1111
fn rust_str_push(&s: str, ch: u8);
1212
}
1313

14-
fn eq(a: str, b: str) -> bool { a == b }
14+
fn eq(&&a: str, &&b: str) -> bool { a == b }
1515

16-
fn lteq(a: str, b: str) -> bool { a <= b }
16+
fn lteq(&&a: str, &&b: str) -> bool { a <= b }
1717

18-
fn hash(s: str) -> uint {
18+
fn hash(&&s: str) -> uint {
1919
// djb hash.
2020
// FIXME: replace with murmur.
2121

src/test/bench/task-perf-word-count-generic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import std::comm::port;
2929
import std::comm::recv;
3030
import std::comm::send;
3131

32-
fn map(filename: [u8], emit: map_reduce::putter<[u8], int>) {
32+
fn map(&&filename: [u8], emit: map_reduce::putter<[u8], int>) {
3333
let f = io::file_reader(str::unsafe_from_bytes(filename));
3434

3535
while true {
@@ -40,7 +40,7 @@ fn map(filename: [u8], emit: map_reduce::putter<[u8], int>) {
4040
}
4141
}
4242

43-
fn reduce(_word: [u8], get: map_reduce::getter<int>) {
43+
fn reduce(&&_word: [u8], get: map_reduce::getter<int>) {
4444
let count = 0;
4545

4646
while true { alt get() { some(_) { count += 1; } none. { break; } } }

src/test/run-fail/unwind-misc-1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import std::uint;
66

77
fn main() {
88
let count = @mutable 0u;
9-
let hash = bind fn (_s: [@str], count: @mutable uint) -> uint {
9+
let hash = bind fn (&&_s: [@str], count: @mutable uint) -> uint {
1010
*count += 1u;
1111
if *count == 10u {
1212
fail;
@@ -15,7 +15,7 @@ fn main() {
1515
}
1616
} (_, count);
1717

18-
fn eq(s: [@str], t: [@str]) -> bool {
18+
fn eq(&&s: [@str], &&t: [@str]) -> bool {
1919
ret s == t;
2020
}
2121

src/test/run-pass/bind-parameterized-args-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ fn main() {
33

44
let y = bind echo(42, _);
55

6-
y(fn (i: str) { });
6+
y(fn(&&i: str) { });
77
}

0 commit comments

Comments
 (0)