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
This commit is contained in:
Marijn Haverbeke 2011-10-10 13:54:03 +02:00
parent b4bae8fea5
commit 33167f7dec
15 changed files with 34 additions and 38 deletions

View File

@ -101,7 +101,7 @@ fn get_rpaths_relative_to_output(os: session::os,
fn get_rpath_relative_to_output(os: session::os,
cwd: fs::path,
output: fs::path,
lib: fs::path) -> str {
&&lib: fs::path) -> str {
// Mac doesn't appear to support $ORIGIN
let prefix = alt os {
session::os_linux. { "$ORIGIN" + fs::path_sep() }
@ -154,7 +154,7 @@ fn get_absolute_rpaths(cwd: fs::path, libs: [fs::path]) -> [str] {
vec::map(bind get_absolute_rpath(cwd, _), libs)
}
fn get_absolute_rpath(cwd: fs::path, lib: fs::path) -> str {
fn get_absolute_rpath(cwd: fs::path, &&lib: fs::path) -> str {
fs::dirname(get_absolute(cwd, lib))
}

View File

@ -409,7 +409,7 @@ fn build_session(sopts: @session::options) -> session::session {
none, 0u, filesearch);
}
fn parse_pretty(sess: session::session, name: str) -> pp_mode {
fn parse_pretty(sess: session::session, &&name: str) -> pp_mode {
if str::eq(name, "normal") {
ret ppm_normal;
} else if str::eq(name, "expanded") {

View File

@ -98,7 +98,7 @@ fn in_cfg(cfg: ast::crate_cfg, attrs: [ast::attribute]) -> bool {
// so we can match against them. This is the list of configurations for
// which the item is valid
let item_cfg_metas = {
fn extract_metas(inner_items: [@ast::meta_item],
fn extract_metas(&&inner_items: [@ast::meta_item],
&&cfg_item: @ast::meta_item) -> [@ast::meta_item] {
alt cfg_item.node {
ast::meta_list(name, items) {

View File

@ -67,7 +67,7 @@ const tag_items_data_item_inlineness: uint = 0x27u;
// djb's cdb hashes.
fn hash_node_id(&&node_id: int) -> uint { ret 177573u ^ (node_id as uint); }
fn hash_path(s: str) -> uint {
fn hash_path(&&s: str) -> uint {
let h = 5381u;
for ch: u8 in str::bytes(s) { h = (h << 5u) + h ^ (ch as uint); }
ret h;

View File

@ -425,7 +425,7 @@ fn encode_index<T>(ebml_w: ebml::writer, buckets: [@[entry<T>]],
ebml::end_tag(ebml_w);
}
fn write_str(writer: io::writer, s: str) { writer.write_str(s); }
fn write_str(writer: io::writer, &&s: str) { writer.write_str(s); }
fn write_int(writer: io::writer, &&n: int) {
writer.write_be_uint(n as uint, 4u);

View File

@ -1400,7 +1400,7 @@ fn add_name(ch: checker, sp: span, name: ident) {
ch.seen += [name];
}
fn ident_id(i: ident) -> ident { ret i; }
fn ident_id(&&i: ident) -> ident { ret i; }
fn ensure_unique<T>(e: env, sp: span, elts: [T], id: fn(T) -> ident,
kind: str) {

View File

@ -5633,7 +5633,7 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
takes_argv: bool) -> ValueRef {
let unit_ty = ty::mk_str(ccx.tcx);
let vecarg_ty: ty::arg =
{mode: ast::by_ref,
{mode: ast::by_val,
ty: ty::mk_vec(ccx.tcx, {ty: unit_ty, mut: ast::imm})};
// FIXME: mk_nil should have a postcondition
let nt = ty::mk_nil(ccx.tcx);
@ -5653,14 +5653,7 @@ fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef,
let lltaskarg = llvm::LLVMGetParam(llfdecl, 1u);
let llenvarg = llvm::LLVMGetParam(llfdecl, 2u);
let args = [lloutputarg, lltaskarg, llenvarg];
if takes_argv {
let llargvarg = llvm::LLVMGetParam(llfdecl, 3u);
// The runtime still passes the arg vector by value, this kludge
// makes sure it becomes a pointer (to a pointer to a vec).
let minus_ptr = llvm::LLVMGetElementType(val_ty(llargvarg));
llargvarg = PointerCast(bcx, llargvarg, minus_ptr);
args += [do_spill_noroot(bcx, llargvarg)];
}
if takes_argv { args += [llvm::LLVMGetParam(llfdecl, 3u)]; }
Call(bcx, main_llfn, args);
build_return(bcx);
@ -5944,7 +5937,7 @@ fn register_native_fn(ccx: @crate_ctxt, sp: span, path: [str], name: str,
fn item_path(item: @ast::item) -> [str] { ret [item.ident]; }
fn collect_native_item(ccx: @crate_ctxt, i: @ast::native_item, pt: [str],
fn collect_native_item(ccx: @crate_ctxt, i: @ast::native_item, &&pt: [str],
_v: vt<[str]>) {
alt i.node {
ast::native_item_fn(_, _, _) {
@ -5956,7 +5949,8 @@ fn collect_native_item(ccx: @crate_ctxt, i: @ast::native_item, pt: [str],
}
}
fn collect_item_1(ccx: @crate_ctxt, i: @ast::item, pt: [str], v: vt<[str]>) {
fn collect_item_1(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
v: vt<[str]>) {
visit::visit_item(i, pt + item_path(i), v);
alt i.node {
ast::item_const(_, _) {
@ -5977,7 +5971,8 @@ fn collect_item_1(ccx: @crate_ctxt, i: @ast::item, pt: [str], v: vt<[str]>) {
}
}
fn collect_item_2(ccx: @crate_ctxt, i: @ast::item, pt: [str], v: vt<[str]>) {
fn collect_item_2(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
v: vt<[str]>) {
let new_pt = pt + item_path(i);
visit::visit_item(i, new_pt, v);
alt i.node {
@ -6018,7 +6013,7 @@ fn collect_items(ccx: @crate_ctxt, crate: @ast::crate) {
visit::visit_crate(*crate, [], visit::mk_vt(visitor2));
}
fn collect_tag_ctor(ccx: @crate_ctxt, i: @ast::item, pt: [str],
fn collect_tag_ctor(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
v: vt<[str]>) {
let new_pt = pt + item_path(i);
visit::visit_item(i, new_pt, v);
@ -6044,7 +6039,8 @@ fn collect_tag_ctors(ccx: @crate_ctxt, crate: @ast::crate) {
// The constant translation pass.
fn trans_constant(ccx: @crate_ctxt, it: @ast::item, pt: [str], v: vt<[str]>) {
fn trans_constant(ccx: @crate_ctxt, it: @ast::item, &&pt: [str],
v: vt<[str]>) {
let new_pt = pt + item_path(it);
visit::visit_item(it, new_pt, v);
alt it.node {

View File

@ -245,7 +245,7 @@ fn follow_for_trans(cx: ext_ctxt, mmaybe: option::t<arb_depth<matchable>>,
/* helper for transcribe_exprs: what vars from `b` occur in `e`? */
iter free_vars(b: bindings, e: @expr) -> ident {
let idents: hashmap<ident, ()> = new_str_hash::<()>();
fn mark_ident(i: ident, _fld: ast_fold, b: bindings,
fn mark_ident(&&i: ident, _fld: ast_fold, b: bindings,
idents: hashmap<ident, ()>) -> ident {
if b.contains_key(i) { idents.insert(i, ()); }
ret i;
@ -325,7 +325,7 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint],
// substitute, in a position that's required to be an ident
fn transcribe_ident(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint],
i: ident, _fld: ast_fold) -> ident {
&&i: ident, _fld: ast_fold) -> ident {
ret alt follow_for_trans(cx, b.find(i), idx_path) {
some(match_ident(a_id)) { a_id.node }
some(m) { match_error(cx, m, "an identifier") }

View File

@ -39,7 +39,7 @@ type ast_fold_precursor =
fold_mod: fn(_mod, ast_fold) -> _mod,
fold_native_mod: fn(native_mod, ast_fold) -> native_mod,
fold_variant: fn(variant_, ast_fold) -> variant_,
fold_ident: fn(ident, ast_fold) -> ident,
fold_ident: fn(&&ident, ast_fold) -> ident,
fold_path: fn(path_, ast_fold) -> path_,
fold_local: fn(local_, ast_fold) -> local_,
map_exprs: fn(fn(&&@expr) -> @expr, [@expr]) -> [@expr],
@ -66,7 +66,7 @@ type a_f =
fold_mod: fn(_mod) -> _mod,
fold_native_mod: fn(native_mod) -> native_mod,
fold_variant: fn(variant) -> variant,
fold_ident: fn(ident) -> ident,
fold_ident: fn(&&ident) -> ident,
fold_path: fn(path) -> path,
fold_local: fn(&&@local) -> @local,
map_exprs: fn(fn(&&@expr) -> @expr, [@expr]) -> [@expr],
@ -96,7 +96,7 @@ fn nf_fn_dummy(_f: _fn) -> _fn { fail; }
fn nf_mod_dummy(_m: _mod) -> _mod { fail; }
fn nf_native_mod_dummy(_n: native_mod) -> native_mod { fail; }
fn nf_variant_dummy(_v: variant) -> variant { fail; }
fn nf_ident_dummy(_i: ident) -> ident { fail; }
fn nf_ident_dummy(&&_i: ident) -> ident { fail; }
fn nf_path_dummy(_p: path) -> path { fail; }
fn nf_obj_field_dummy(_o: obj_field) -> obj_field { fail; }
fn nf_local_dummy(&&_o: @local) -> @local { fail; }
@ -471,7 +471,7 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
ret {name: v.name, args: vec::map(fold_variant_arg, v.args), id: v.id};
}
fn noop_fold_ident(i: ident, _fld: ast_fold) -> ident { ret i; }
fn noop_fold_ident(&&i: ident, _fld: ast_fold) -> ident { ret i; }
fn noop_fold_path(p: path_, fld: ast_fold) -> path_ {
ret {global: p.global,
@ -667,7 +667,7 @@ fn make_fold(afp: ast_fold_precursor) -> @foldres {
variant {
ret {node: afp.fold_variant(x.node, f), span: afp.new_span(x.span)};
}
fn f_ident(afp: ast_fold_precursor, f: ast_fold, x: ident) -> ident {
fn f_ident(afp: ast_fold_precursor, f: ast_fold, &&x: ident) -> ident {
ret afp.fold_ident(x, f);
}
fn f_path(afp: ast_fold_precursor, f: ast_fold, x: path) -> path {

View File

@ -1277,7 +1277,7 @@ fn print_view_item(s: ps, item: @ast::view_item) {
ast::view_item_export(ids, _) {
head(s, "export");
commasep(s, inconsistent, ids,
fn (s: ps, w: ast::ident) { word(s.s, w) });
fn (s: ps, &&w: ast::ident) { word(s.s, w) });
}
}
word(s.s, ";");

View File

@ -276,7 +276,7 @@ fn make_run_args(config: config, _props: test_props, testfile: str) ->
fn split_maybe_args(argstr: option::t<str>) -> [str] {
fn rm_whitespace(v: [str]) -> [str] {
fn flt(s: str) -> option::t<str> {
fn flt(&&s: str) -> option::t<str> {
if !is_whitespace(s) { option::some(s) } else { option::none }
}

View File

@ -11,11 +11,11 @@ native "rust" mod rustrt {
fn rust_str_push(&s: str, ch: u8);
}
fn eq(a: str, b: str) -> bool { a == b }
fn eq(&&a: str, &&b: str) -> bool { a == b }
fn lteq(a: str, b: str) -> bool { a <= b }
fn lteq(&&a: str, &&b: str) -> bool { a <= b }
fn hash(s: str) -> uint {
fn hash(&&s: str) -> uint {
// djb hash.
// FIXME: replace with murmur.

View File

@ -29,7 +29,7 @@ import std::comm::port;
import std::comm::recv;
import std::comm::send;
fn map(filename: [u8], emit: map_reduce::putter<[u8], int>) {
fn map(&&filename: [u8], emit: map_reduce::putter<[u8], int>) {
let f = io::file_reader(str::unsafe_from_bytes(filename));
while true {
@ -40,7 +40,7 @@ fn map(filename: [u8], emit: map_reduce::putter<[u8], int>) {
}
}
fn reduce(_word: [u8], get: map_reduce::getter<int>) {
fn reduce(&&_word: [u8], get: map_reduce::getter<int>) {
let count = 0;
while true { alt get() { some(_) { count += 1; } none. { break; } } }

View File

@ -6,7 +6,7 @@ import std::uint;
fn main() {
let count = @mutable 0u;
let hash = bind fn (_s: [@str], count: @mutable uint) -> uint {
let hash = bind fn (&&_s: [@str], count: @mutable uint) -> uint {
*count += 1u;
if *count == 10u {
fail;
@ -15,7 +15,7 @@ fn main() {
}
} (_, count);
fn eq(s: [@str], t: [@str]) -> bool {
fn eq(&&s: [@str], &&t: [@str]) -> bool {
ret s == t;
}

View File

@ -3,5 +3,5 @@ fn main() {
let y = bind echo(42, _);
y(fn (i: str) { });
y(fn(&&i: str) { });
}