diff options
209 files changed, 3364 insertions, 3359 deletions
diff --git a/src/comp/back/link.rs b/src/comp/back/link.rs index 0bbdafd1e6b..704759ce4fd 100644 --- a/src/comp/back/link.rs +++ b/src/comp/back/link.rs @@ -31,7 +31,7 @@ tag output_type { output_type_exe; } -fn llvm_err(sess: session::session, msg: &str) { +fn llvm_err(sess: session::session, msg: str) { let buf = llvm::LLVMRustGetLastError(); if buf == std::ptr::null() { sess.fatal(msg); @@ -41,11 +41,9 @@ fn llvm_err(sess: session::session, msg: &str) { fn link_intrinsics(sess: session::session, llmod: ModuleRef) { let path = fs::connect(sess.get_opts().sysroot, "lib/intrinsics.bc"); let membuf = - str::as_buf( - path, - {|buf| - llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf) - }); + str::as_buf(path, {|buf| + llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf) + }); if membuf as uint == 0u { llvm_err(sess, "installation problem: couldn't open " + path); fail; @@ -75,7 +73,7 @@ mod write { // Decides what to call an intermediate file, given the name of the output // and the extension to use. - fn mk_intermediate_name(output_path: &str, extension: &str) -> str { + fn mk_intermediate_name(output_path: str, extension: str) -> str { let dot_pos = str::index(output_path, '.' as u8); let stem; if dot_pos < 0 { @@ -83,7 +81,7 @@ mod write { } else { stem = str::substr(output_path, 0u, dot_pos as uint); } ret stem + "." + extension; } - fn run_passes(sess: session::session, llmod: ModuleRef, output: &str) { + fn run_passes(sess: session::session, llmod: ModuleRef, output: str) { let opts = sess.get_opts(); if opts.time_llvm_passes { llvm::LLVMRustEnableTimePasses(); } link_intrinsics(sess, llmod); @@ -147,8 +145,8 @@ mod write { False); if threshold != 0u { - llvm::LLVMPassManagerBuilderUseInlinerWithThreshold( - MPMB, threshold); + llvm::LLVMPassManagerBuilderUseInlinerWithThreshold + (MPMB, threshold); } llvm::LLVMPassManagerBuilderPopulateModulePassManager(MPMB, pm.llpm); @@ -196,15 +194,14 @@ mod write { let _: () = str::as_buf(x86::get_target_triple(), {|buf_t| str::as_buf(output, {|buf_o| - llvm::LLVMRustWriteOutputFile( - pm.llpm, - llmod, - buf_t, - buf_o, - LLVMAssemblyFile, - CodeGenOptLevel) - }) - }); + llvm::LLVMRustWriteOutputFile(pm.llpm, + llmod, + buf_t, + buf_o, + LLVMAssemblyFile, + CodeGenOptLevel) + }) + }); } @@ -221,8 +218,8 @@ mod write { buf_o, LLVMObjectFile, CodeGenOptLevel) - }) - }); + }) + }); } } else { // If we aren't saving temps then just output the file @@ -237,8 +234,8 @@ mod write { buf_o, FileType, CodeGenOptLevel) - }) - }); + }) + }); } // Clean up and return @@ -311,7 +308,7 @@ mod write { type link_meta = {name: str, vers: str, extras_hash: str}; -fn build_link_meta(sess: &session::session, c: &ast::crate, output: &str, +fn build_link_meta(sess: session::session, c: ast::crate, output: str, sha: sha1) -> link_meta { type provided_metas = @@ -319,7 +316,7 @@ fn build_link_meta(sess: &session::session, c: &ast::crate, output: &str, vers: option::t<str>, cmh_items: [@ast::meta_item]}; - fn provided_link_metas(sess: &session::session, c: &ast::crate) -> + fn provided_link_metas(sess: session::session, c: ast::crate) -> provided_metas { let name: option::t<str> = none; let vers: option::t<str> = none; @@ -343,13 +340,13 @@ fn build_link_meta(sess: &session::session, c: &ast::crate, output: &str, } // This calculates CMH as defined above - fn crate_meta_extras_hash(sha: sha1, _crate: &ast::crate, - metas: &provided_metas) -> str { - fn len_and_str(s: &str) -> str { + fn crate_meta_extras_hash(sha: sha1, _crate: ast::crate, + metas: provided_metas) -> str { + fn len_and_str(s: str) -> str { ret #fmt["%u_%s", str::byte_len(s), s]; } - fn len_and_str_lit(l: &ast::lit) -> str { + fn len_and_str_lit(l: ast::lit) -> str { ret len_and_str(pprust::lit_to_str(@l)); } @@ -373,14 +370,14 @@ fn build_link_meta(sess: &session::session, c: &ast::crate, output: &str, ret truncated_sha1_result(sha); } - fn warn_missing(sess: &session::session, name: &str, default: &str) { + fn warn_missing(sess: session::session, name: str, default: str) { if !sess.get_opts().library { ret; } sess.warn(#fmt["missing crate link meta '%s', using '%s' as default", name, default]); } - fn crate_meta_name(sess: &session::session, _crate: &ast::crate, - output: &str, metas: &provided_metas) -> str { + fn crate_meta_name(sess: session::session, _crate: ast::crate, + output: str, metas: provided_metas) -> str { ret alt metas.name { some(v) { v } none. { @@ -397,8 +394,8 @@ fn build_link_meta(sess: &session::session, c: &ast::crate, output: &str, }; } - fn crate_meta_vers(sess: &session::session, _crate: &ast::crate, - metas: &provided_metas) -> str { + fn crate_meta_vers(sess: session::session, _crate: ast::crate, + metas: provided_metas) -> str { ret alt metas.vers { some(v) { v } none. { @@ -423,7 +420,7 @@ fn truncated_sha1_result(sha: sha1) -> str { // This calculates STH for a symbol, as defined above -fn symbol_hash(tcx: ty::ctxt, sha: sha1, t: ty::t, link_meta: &link_meta) -> +fn symbol_hash(tcx: ty::ctxt, sha: sha1, t: ty::t, link_meta: link_meta) -> str { // NB: do *not* use abbrevs here as we want the symbol names // to be independent of one another in the crate. @@ -441,7 +438,7 @@ fn symbol_hash(tcx: ty::ctxt, sha: sha1, t: ty::t, link_meta: &link_meta) -> ret "_" + hash; } -fn get_symbol_hash(ccx: &@crate_ctxt, t: ty::t) -> str { +fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> str { let hash = ""; alt ccx.type_sha1s.find(t) { some(h) { hash = h; } @@ -453,7 +450,7 @@ fn get_symbol_hash(ccx: &@crate_ctxt, t: ty::t) -> str { ret hash; } -fn mangle(ss: &[str]) -> str { +fn mangle(ss: [str]) -> str { // Follow C++ namespace-mangling style let n = "_ZN"; // Begin name-sequence. @@ -464,35 +461,35 @@ fn mangle(ss: &[str]) -> str { ret n; } -fn exported_name(path: &[str], hash: &str, _vers: &str) -> str { +fn exported_name(path: [str], hash: str, _vers: str) -> str { // FIXME: versioning isn't working yet ret mangle(path + [hash]); // + "@" + vers; } -fn mangle_exported_name(ccx: &@crate_ctxt, path: &[str], t: ty::t) -> str { +fn mangle_exported_name(ccx: @crate_ctxt, path: [str], t: ty::t) -> str { let hash = get_symbol_hash(ccx, t); ret exported_name(path, hash, ccx.link_meta.vers); } -fn mangle_internal_name_by_type_only(ccx: &@crate_ctxt, t: ty::t, name: &str) - -> str { +fn mangle_internal_name_by_type_only(ccx: @crate_ctxt, t: ty::t, name: str) -> + str { let s = util::ppaux::ty_to_short_str(ccx.tcx, t); let hash = get_symbol_hash(ccx, t); ret mangle([name, s, hash]); } -fn mangle_internal_name_by_path_and_seq(ccx: &@crate_ctxt, path: &[str], - flav: &str) -> str { +fn mangle_internal_name_by_path_and_seq(ccx: @crate_ctxt, path: [str], + flav: str) -> str { ret mangle(path + [ccx.names.next(flav)]); } -fn mangle_internal_name_by_path(_ccx: &@crate_ctxt, path: &[str]) -> str { +fn mangle_internal_name_by_path(_ccx: @crate_ctxt, path: [str]) -> str { ret mangle(path); } -fn mangle_internal_name_by_seq(ccx: &@crate_ctxt, flav: &str) -> str { +fn mangle_internal_name_by_seq(ccx: @crate_ctxt, flav: str) -> str { ret ccx.names.next(flav); } // diff --git a/src/comp/back/upcall.rs b/src/comp/back/upcall.rs index 774cb30c001..3b1ee9c9cee 100644 --- a/src/comp/back/upcall.rs +++ b/src/comp/back/upcall.rs @@ -41,14 +41,14 @@ type upcalls = fn declare_upcalls(_tn: type_names, tydesc_type: TypeRef, taskptr_type: TypeRef, llmod: ModuleRef) -> @upcalls { - fn decl(llmod: ModuleRef, name: &str, tys: [TypeRef], rv: TypeRef) -> + fn decl(llmod: ModuleRef, name: str, tys: [TypeRef], rv: TypeRef) -> ValueRef { let arg_tys: [TypeRef] = []; for t: TypeRef in tys { arg_tys += [t]; } let fn_ty = T_fn(arg_tys, rv); ret trans::decl_cdecl_fn(llmod, "upcall_" + name, fn_ty); } - fn decl_with_taskptr(taskptr_type: TypeRef, llmod: ModuleRef, name: &str, + fn decl_with_taskptr(taskptr_type: TypeRef, llmod: ModuleRef, name: str, tys: [TypeRef], rv: TypeRef) -> ValueRef { ret decl(llmod, name, [taskptr_type] + tys, rv); } diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index 3a6f7386292..dd7f13390f1 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -41,7 +41,7 @@ import back::link::output_type; tag pp_mode { ppm_normal; ppm_expanded; ppm_typed; ppm_identified; } -fn default_configuration(sess: session::session, argv0: &str, input: &str) -> +fn default_configuration(sess: session::session, argv0: str, input: str) -> ast::crate_cfg { let libc = alt sess.get_targ_cfg().os { @@ -60,7 +60,7 @@ fn default_configuration(sess: session::session, argv0: &str, input: &str) -> mk("build_compiler", argv0), mk("build_input", input)]; } -fn build_configuration(sess: session::session, argv0: &str, input: &str) -> +fn build_configuration(sess: session::session, argv0: str, input: str) -> ast::crate_cfg { // Combine the configuration requested by the session (command line) with // some default and generated configuration items @@ -78,7 +78,7 @@ fn build_configuration(sess: session::session, argv0: &str, input: &str) -> } // Convert strings provided as --cfg [cfgspec] into a crate_cfg -fn parse_cfgspecs(cfgspecs: &[str]) -> ast::crate_cfg { +fn parse_cfgspecs(cfgspecs: [str]) -> ast::crate_cfg { // FIXME: It would be nice to use the parser to parse all varieties of // meta_item here. At the moment we just support the meta_word variant. let words = []; @@ -86,16 +86,16 @@ fn parse_cfgspecs(cfgspecs: &[str]) -> ast::crate_cfg { ret words; } -fn input_is_stdin(filename: &str) -> bool { filename == "-" } +fn input_is_stdin(filename: str) -> bool { filename == "-" } -fn parse_input(sess: session::session, cfg: &ast::crate_cfg, input: &str) -> +fn parse_input(sess: session::session, cfg: ast::crate_cfg, input: str) -> @ast::crate { if !input_is_stdin(input) { parser::parse_crate_from_file(input, cfg, sess.get_parse_sess()) } else { parse_input_src(sess, cfg, input).crate } } -fn parse_input_src(sess: session::session, cfg: &ast::crate_cfg, infile: &str) +fn parse_input_src(sess: session::session, cfg: ast::crate_cfg, infile: str) -> {crate: @ast::crate, src: str} { let srcbytes = if infile != "-" { @@ -108,7 +108,7 @@ fn parse_input_src(sess: session::session, cfg: &ast::crate_cfg, infile: &str) ret {crate: crate, src: src}; } -fn time<@T>(do_it: bool, what: &str, thunk: fn() -> T) -> T { +fn time<@T>(do_it: bool, what: str, thunk: fn() -> T) -> T { if !do_it { ret thunk(); } let start = std::time::precise_time_s(); let rv = thunk(); @@ -118,8 +118,8 @@ fn time<@T>(do_it: bool, what: &str, thunk: fn() -> T) -> T { ret rv; } -fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: &str, - output: &str) { +fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str, + output: str) { let time_passes = sess.get_opts().time_passes; let crate = time(time_passes, "parsing", bind parse_input(sess, cfg, input)); @@ -158,8 +158,9 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: &str, let mut_map = time(time_passes, "mutability checking", bind middle::mut::check_crate(ty_cx, crate)); - let copy_map = time(time_passes, "alias checking", - bind middle::alias::check_crate(ty_cx, crate)); + let copy_map = + time(time_passes, "alias checking", + bind middle::alias::check_crate(ty_cx, crate)); time(time_passes, "kind checking", bind kind::check_crate(ty_cx, crate)); if sess.get_opts().no_trans { ret; } let llmod = @@ -170,12 +171,12 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: &str, bind link::write::run_passes(sess, llmod, output)); } -fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, - input: &str, ppm: pp_mode) { - fn ann_paren_for_expr(node: &pprust::ann_node) { +fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str, + ppm: pp_mode) { + fn ann_paren_for_expr(node: pprust::ann_node) { alt node { pprust::node_expr(s, expr) { pprust::popen(s); } _ { } } } - fn ann_typed_post(tcx: &ty::ctxt, node: &pprust::ann_node) { + fn ann_typed_post(tcx: ty::ctxt, node: pprust::ann_node) { alt node { pprust::node_expr(s, expr) { pp::space(s.s); @@ -187,7 +188,7 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, _ { } } } - fn ann_identified_post(node: &pprust::ann_node) { + fn ann_identified_post(node: pprust::ann_node) { alt node { pprust::node_item(s, item) { pp::space(s.s); @@ -240,14 +241,14 @@ fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, io::string_reader(src), io::stdout(), ann); } -fn version(argv0: &str) { +fn version(argv0: str) { let vers = "unknown version"; let env_vers = #env["CFG_VERSION"]; if str::byte_len(env_vers) != 0u { vers = env_vers; } io::stdout().write_str(#fmt["%s %s\n", argv0, vers]); } -fn usage(argv0: &str) { +fn usage(argv0: str) { io::stdout().write_str(#fmt["usage: %s [options] <input>\n", argv0] + " options: @@ -285,7 +286,7 @@ options: "); } -fn get_os(triple: &str) -> session::os { +fn get_os(triple: str) -> session::os { ret if str::find(triple, "win32") >= 0 || str::find(triple, "mingw32") >= 0 { session::os_win32 @@ -296,7 +297,7 @@ fn get_os(triple: &str) -> session::os { } else { log_err "Unknown operating system!"; fail }; } -fn get_arch(triple: &str) -> session::arch { +fn get_arch(triple: str) -> session::arch { ret if str::find(triple, "i386") >= 0 || str::find(triple, "i486") >= 0 || str::find(triple, "i586") >= 0 || str::find(triple, "i686") >= 0 || @@ -310,7 +311,7 @@ fn get_arch(triple: &str) -> session::arch { } else { log_err "Unknown architecture! " + triple; fail }; } -fn get_default_sysroot(binary: &str) -> str { +fn get_default_sysroot(binary: str) -> str { let dirname = fs::dirname(binary); if str::eq(dirname, binary) { ret "."; } ret dirname; @@ -327,8 +328,8 @@ fn build_target_config() -> @session::config { ret target_cfg; } -fn build_session_options(binary: &str, match: &getopts::match, - binary_dir: &str) -> @session::options { +fn build_session_options(binary: str, match: getopts::match, binary_dir: str) + -> @session::options { let library = opt_present(match, "lib"); let static = opt_present(match, "static"); @@ -415,7 +416,7 @@ fn build_session(sopts: @session::options) -> session::session { none, 0u); } -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") { @@ -513,6 +514,7 @@ fn main(args: [str]) { link::output_type_assembly. { "s" } + // Object and exe output both use the '.o' extension here link::output_type_object. | link::output_type_exe. { "o" @@ -554,9 +556,9 @@ fn main(args: [str]) { } else { lib_cmd = "-shared"; } // Converts a library file name into a gcc -l argument - fn unlib(config: @session::config, filename: &str) -> str { + fn unlib(config: @session::config, filename: str) -> str { let rmlib = - bind fn (config: @session::config, filename: &str) -> str { + bind fn (config: @session::config, filename: str) -> str { if config.os == session::os_macos || config.os == session::os_linux && str::find(filename, "lib") == 0 { @@ -564,7 +566,7 @@ fn main(args: [str]) { str::byte_len(filename)); } else { ret filename; } }(config, _); - fn rmext(filename: &str) -> str { + fn rmext(filename: str) -> str { let parts = str::split(filename, '.' as u8); vec::pop(parts); ret str::connect(parts, "."); diff --git a/src/comp/driver/session.rs b/src/comp/driver/session.rs index 13d17ef6303..5a2b26739aa 100644 --- a/src/comp/driver/session.rs +++ b/src/comp/driver/session.rs @@ -58,46 +58,46 @@ obj session(targ_cfg: @config, fn get_targ_cfg() -> @config { ret targ_cfg; } fn get_opts() -> @options { ret opts; } fn get_cstore() -> metadata::cstore::cstore { cstore } - fn span_fatal(sp: span, msg: &str) -> ! { + fn span_fatal(sp: span, msg: str) -> ! { // FIXME: Use constants, but rustboot doesn't know how to export them. codemap::emit_error(some(sp), msg, parse_sess.cm); fail; } - fn fatal(msg: &str) -> ! { + fn fatal(msg: str) -> ! { codemap::emit_error(none, msg, parse_sess.cm); fail; } - fn span_err(sp: span, msg: &str) { + fn span_err(sp: span, msg: str) { codemap::emit_error(some(sp), msg, parse_sess.cm); err_count += 1u; } - fn err(msg: &str) { + fn err(msg: str) { codemap::emit_error(none, msg, parse_sess.cm); err_count += 1u; } fn abort_if_errors() { if err_count > 0u { self.fatal("aborting due to previous errors"); } } - fn span_warn(sp: span, msg: &str) { + fn span_warn(sp: span, msg: str) { // FIXME: Use constants, but rustboot doesn't know how to export them. codemap::emit_warning(some(sp), msg, parse_sess.cm); } - fn warn(msg: &str) { codemap::emit_warning(none, msg, parse_sess.cm); } - fn span_note(sp: span, msg: &str) { + fn warn(msg: str) { codemap::emit_warning(none, msg, parse_sess.cm); } + fn span_note(sp: span, msg: str) { // FIXME: Use constants, but rustboot doesn't know how to export them. codemap::emit_note(some(sp), msg, parse_sess.cm); } - fn note(msg: &str) { codemap::emit_note(none, msg, parse_sess.cm); } - fn span_bug(sp: span, msg: &str) -> ! { + fn note(msg: str) { codemap::emit_note(none, msg, parse_sess.cm); } + fn span_bug(sp: span, msg: str) -> ! { self.span_fatal(sp, #fmt["internal compiler error %s", msg]); } - fn bug(msg: &str) -> ! { + fn bug(msg: str) -> ! { self.fatal(#fmt["internal compiler error %s", msg]); } - fn span_unimpl(sp: span, msg: &str) -> ! { + fn span_unimpl(sp: span, msg: str) -> ! { self.span_bug(sp, "unimplemented " + msg); } - fn unimpl(msg: &str) -> ! { self.bug("unimplemented " + msg); } + fn unimpl(msg: str) -> ! { self.bug("unimplemented " + msg); } fn get_codemap() -> codemap::codemap { ret parse_sess.cm; } fn lookup_pos(pos: uint) -> codemap::loc { ret codemap::lookup_char_pos(parse_sess.cm, pos); diff --git a/src/comp/front/attr.rs b/src/comp/front/attr.rs index edb6da5b257..a13fc4aad35 100644 --- a/src/comp/front/attr.rs +++ b/src/comp/front/attr.rs @@ -30,7 +30,7 @@ export mk_attr; // From a list of crate attributes get only the meta_items that impact crate // linkage -fn find_linkage_metas(attrs: &[ast::attribute]) -> [@ast::meta_item] { +fn find_linkage_metas(attrs: [ast::attribute]) -> [@ast::meta_item] { let metas: [@ast::meta_item] = []; for attr: ast::attribute in find_attrs_by_name(attrs, "link") { alt attr.node.value.node { @@ -42,10 +42,10 @@ fn find_linkage_metas(attrs: &[ast::attribute]) -> [@ast::meta_item] { } // Search a list of attributes and return only those with a specific name -fn find_attrs_by_name(attrs: &[ast::attribute], name: ast::ident) -> +fn find_attrs_by_name(attrs: [ast::attribute], name: ast::ident) -> [ast::attribute] { let filter = - bind fn (a: &ast::attribute, name: ast::ident) -> + bind fn (a: ast::attribute, name: ast::ident) -> option::t<ast::attribute> { if get_attr_name(a) == name { option::some(a) @@ -54,14 +54,14 @@ fn find_attrs_by_name(attrs: &[ast::attribute], name: ast::ident) -> ret vec::filter_map(filter, attrs); } -fn get_attr_name(attr: &ast::attribute) -> ast::ident { +fn get_attr_name(attr: ast::attribute) -> ast::ident { get_meta_item_name(@attr.node.value) } -fn find_meta_items_by_name(metas: &[@ast::meta_item], name: ast::ident) -> +fn find_meta_items_by_name(metas: [@ast::meta_item], name: ast::ident) -> [@ast::meta_item] { let filter = - bind fn (m: &@ast::meta_item, name: ast::ident) -> + bind fn (m: @ast::meta_item, name: ast::ident) -> option::t<@ast::meta_item> { if get_meta_item_name(m) == name { option::some(m) @@ -70,7 +70,7 @@ fn find_meta_items_by_name(metas: &[@ast::meta_item], name: ast::ident) -> ret vec::filter_map(filter, metas); } -fn get_meta_item_name(meta: &@ast::meta_item) -> ast::ident { +fn get_meta_item_name(meta: @ast::meta_item) -> ast::ident { alt meta.node { ast::meta_word(n) { n } ast::meta_name_value(n, _) { n } @@ -80,7 +80,7 @@ fn get_meta_item_name(meta: &@ast::meta_item) -> ast::ident { // Gets the string value if the meta_item is a meta_name_value variant // containing a string, otherwise none -fn get_meta_item_value_str(meta: &@ast::meta_item) -> option::t<str> { +fn get_meta_item_value_str(meta: @ast::meta_item) -> option::t<str> { alt meta.node { ast::meta_name_value(_, v) { alt v.node { ast::lit_str(s) { option::some(s) } _ { option::none } } @@ -89,10 +89,10 @@ fn get_meta_item_value_str(meta: &@ast::meta_item) -> option::t<str> { } } -fn attr_meta(attr: &ast::attribute) -> @ast::meta_item { @attr.node.value } +fn attr_meta(attr: ast::attribute) -> @ast::meta_item { @attr.node.value } // Get the meta_items from inside a vector of attributes -fn attr_metas(attrs: &[ast::attribute]) -> [@ast::meta_item] { +fn attr_metas(attrs: [ast::attribute]) -> [@ast::meta_item] { let mitems = []; for a: ast::attribute in attrs { mitems += [attr_meta(a)]; } ret mitems; @@ -119,7 +119,7 @@ fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool { } } -fn contains(haystack: &[@ast::meta_item], needle: @ast::meta_item) -> bool { +fn contains(haystack: [@ast::meta_item], needle: @ast::meta_item) -> bool { log #fmt["looking for %s", syntax::print::pprust::meta_item_to_str(*needle)]; for item: @ast::meta_item in haystack { @@ -131,15 +131,15 @@ fn contains(haystack: &[@ast::meta_item], needle: @ast::meta_item) -> bool { ret false; } -fn contains_name(metas: &[@ast::meta_item], name: ast::ident) -> bool { +fn contains_name(metas: [@ast::meta_item], name: ast::ident) -> bool { let matches = find_meta_items_by_name(metas, name); ret vec::len(matches) > 0u; } // FIXME: This needs to sort by meta_item variant in addition to the item name -fn sort_meta_items(items: &[@ast::meta_item]) -> [@ast::meta_item] { - fn lteq(ma: &@ast::meta_item, mb: &@ast::meta_item) -> bool { - fn key(m: &@ast::meta_item) -> ast::ident { +fn sort_meta_items(items: [@ast::meta_item]) -> [@ast::meta_item] { + fn lteq(ma: @ast::meta_item, mb: @ast::meta_item) -> bool { + fn key(m: @ast::meta_item) -> ast::ident { alt m.node { ast::meta_word(name) { name } ast::meta_name_value(name, _) { name } @@ -160,11 +160,11 @@ fn sort_meta_items(items: &[@ast::meta_item]) -> [@ast::meta_item] { ret v2; } -fn remove_meta_items_by_name(items: &[@ast::meta_item], name: &str) -> +fn remove_meta_items_by_name(items: [@ast::meta_item], name: str) -> [@ast::meta_item] { let filter = - bind fn (item: &@ast::meta_item, name: &str) -> + bind fn (item: @ast::meta_item, name: str) -> option::t<@ast::meta_item> { if get_meta_item_name(item) != name { option::some(item) @@ -174,7 +174,7 @@ fn remove_meta_items_by_name(items: &[@ast::meta_item], name: &str) -> ret vec::filter_map(filter, items); } -fn require_unique_names(sess: &session::session, metas: &[@ast::meta_item]) { +fn require_unique_names(sess: session::session, metas: [@ast::meta_item]) { let map = map::new_str_hash(); for meta: @ast::meta_item in metas { let name = get_meta_item_name(meta); @@ -186,11 +186,11 @@ fn require_unique_names(sess: &session::session, metas: &[@ast::meta_item]) { } } -fn span<@T>(item: &T) -> ast::spanned<T> { +fn span<@T>(item: T) -> ast::spanned<T> { ret {node: item, span: ast_util::dummy_sp()}; } -fn mk_name_value_item_str(name: ast::ident, value: &str) -> @ast::meta_item { +fn mk_name_value_item_str(name: ast::ident, value: str) -> @ast::meta_item { let value_lit = span(ast::lit_str(value)); ret mk_name_value_item(name, value_lit); } @@ -199,7 +199,7 @@ fn mk_name_value_item(name: ast::ident, value: ast::lit) -> @ast::meta_item { ret @span(ast::meta_name_value(name, value)); } -fn mk_list_item(name: ast::ident, items: &[@ast::meta_item]) -> +fn mk_list_item(name: ast::ident, items: [@ast::meta_item]) -> @ast::meta_item { ret @span(ast::meta_list(name, items)); } diff --git a/src/comp/front/config.rs b/src/comp/front/config.rs index 0d391f63c34..843a936cc38 100644 --- a/src/comp/front/config.rs +++ b/src/comp/front/config.rs @@ -24,12 +24,12 @@ fn strip_unconfigured_items(crate: @ast::crate) -> @ast::crate { ret res; } -fn filter_item(cfg: &ast::crate_cfg, item: &@ast::item) -> +fn filter_item(cfg: ast::crate_cfg, item: @ast::item) -> option::t<@ast::item> { if item_in_cfg(cfg, item) { option::some(item) } else { option::none } } -fn fold_mod(cfg: &ast::crate_cfg, m: &ast::_mod, fld: fold::ast_fold) -> +fn fold_mod(cfg: ast::crate_cfg, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod { let filter = bind filter_item(cfg, _); let filtered_items = vec::filter_map(filter, m.items); @@ -37,14 +37,14 @@ fn fold_mod(cfg: &ast::crate_cfg, m: &ast::_mod, fld: fold::ast_fold) -> items: vec::map(fld.fold_item, filtered_items)}; } -fn filter_native_item(cfg: &ast::crate_cfg, item: &@ast::native_item) -> +fn filter_native_item(cfg: ast::crate_cfg, item: @ast::native_item) -> option::t<@ast::native_item> { if native_item_in_cfg(cfg, item) { option::some(item) } else { option::none } } -fn fold_native_mod(cfg: &ast::crate_cfg, nm: &ast::native_mod, +fn fold_native_mod(cfg: ast::crate_cfg, nm: ast::native_mod, fld: fold::ast_fold) -> ast::native_mod { let filter = bind filter_native_item(cfg, _); let filtered_items = vec::filter_map(filter, nm.items); @@ -54,7 +54,7 @@ fn fold_native_mod(cfg: &ast::crate_cfg, nm: &ast::native_mod, items: filtered_items}; } -fn filter_stmt(cfg: &ast::crate_cfg, stmt: &@ast::stmt) -> +fn filter_stmt(cfg: ast::crate_cfg, stmt: @ast::stmt) -> option::t<@ast::stmt> { alt stmt.node { ast::stmt_decl(decl, _) { @@ -71,7 +71,7 @@ fn filter_stmt(cfg: &ast::crate_cfg, stmt: &@ast::stmt) -> } } -fn fold_block(cfg: &ast::crate_cfg, b: &ast::blk_, fld: fold::ast_fold) -> +fn fold_block(cfg: ast::crate_cfg, b: ast::blk_, fld: fold::ast_fold) -> ast::blk_ { let filter = bind filter_stmt(cfg, _); let filtered_stmts = vec::filter_map(filter, b.stmts); @@ -81,18 +81,17 @@ fn fold_block(cfg: &ast::crate_cfg, b: &ast::blk_, fld: fold::ast_fold) -> rules: b.rules}; } -fn item_in_cfg(cfg: &ast::crate_cfg, item: &@ast::item) -> bool { +fn item_in_cfg(cfg: ast::crate_cfg, item: @ast::item) -> bool { ret in_cfg(cfg, item.attrs); } -fn native_item_in_cfg(cfg: &ast::crate_cfg, item: &@ast::native_item) -> - bool { +fn native_item_in_cfg(cfg: ast::crate_cfg, item: @ast::native_item) -> bool { ret in_cfg(cfg, item.attrs); } // Determine if an item should be translated in the current crate // configuration based on the item's attributes -fn in_cfg(cfg: &ast::crate_cfg, attrs: &[ast::attribute]) -> bool { +fn in_cfg(cfg: ast::crate_cfg, attrs: [ast::attribute]) -> bool { // The "cfg" attributes on the item let item_cfg_attrs = attr::find_attrs_by_name(attrs, "cfg"); @@ -104,9 +103,8 @@ fn in_cfg(cfg: &ast::crate_cfg, attrs: &[ast::attribute]) -> bool { // which the item is valid let item_cfg_metas = { - fn extract_metas(inner_items: &[@ast::meta_item], - cfg_item: &@ast::meta_item) -> - [@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) { assert (name == "cfg"); diff --git a/src/comp/front/test.rs b/src/comp/front/test.rs index f5ef18066d1..e0d9fa45ce1 100644 --- a/src/comp/front/test.rs +++ b/src/comp/front/test.rs @@ -55,14 +55,13 @@ fn modify_for_testing(crate: @ast::crate) -> @ast::crate { ret res; } -fn fold_mod(_cx: &test_ctxt, m: &ast::_mod, fld: fold::ast_fold) -> - ast::_mod { +fn fold_mod(_cx: test_ctxt, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod { // Remove any defined main function from the AST so it doesn't clash with // the one we're going to add. FIXME: This is sloppy. Instead we should // have some mechanism to indicate to the translation pass which function // we want to be main. - fn nomain(item: &@ast::item) -> option::t<@ast::item> { + fn nomain(item: @ast::item) -> option::t<@ast::item> { alt item.node { ast::item_fn(f, _) { if item.ident == "main" { @@ -78,7 +77,7 @@ fn fold_mod(_cx: &test_ctxt, m: &ast::_mod, fld: fold::ast_fold) -> ret fold::noop_fold_mod(mod_nomain, fld); } -fn fold_crate(cx: &test_ctxt, c: &ast::crate_, fld: fold::ast_fold) -> +fn fold_crate(cx: test_ctxt, c: ast::crate_, fld: fold::ast_fold) -> ast::crate_ { let folded = fold::noop_fold_crate(c, fld); @@ -88,7 +87,7 @@ fn fold_crate(cx: &test_ctxt, c: &ast::crate_, fld: fold::ast_fold) -> } -fn fold_item(cx: &test_ctxt, i: &@ast::item, fld: fold::ast_fold) -> +fn fold_item(cx: test_ctxt, i: @ast::item, fld: fold::ast_fold) -> @ast::item { cx.path += [i.ident]; @@ -106,11 +105,11 @@ fn fold_item(cx: &test_ctxt, i: &@ast::item, fld: fold::ast_fold) -> ret res; } -fn is_test_fn(i: &@ast::item) -> bool { +fn is_test_fn(i: @ast::item) -> bool { let has_test_attr = vec::len(attr::find_attrs_by_name(i.attrs, "test")) > 0u; - fn has_test_signature(i: &@ast::item) -> bool { + fn has_test_signature(i: @ast::item) -> bool { alt i.node { ast::item_fn(f, tps) { let input_cnt = vec::len(f.decl.inputs); @@ -125,11 +124,11 @@ fn is_test_fn(i: &@ast::item) -> bool { ret has_test_attr && has_test_signature(i); } -fn is_ignored(i: &@ast::item) -> bool { +fn is_ignored(i: @ast::item) -> bool { attr::contains_name(attr::attr_metas(i.attrs), "ignore") } -fn add_test_module(cx: &test_ctxt, m: &ast::_mod) -> ast::_mod { +fn add_test_module(cx: test_ctxt, m: ast::_mod) -> ast::_mod { let testmod = mk_test_module(cx); ret {items: m.items + [testmod] with m}; } @@ -151,7 +150,7 @@ mod __test { */ -fn mk_test_module(cx: &test_ctxt) -> @ast::item { +fn mk_test_module(cx: test_ctxt) -> @ast::item { // A function that generates a vector of test descriptors to feed to the // test runner let testsfn = mk_tests(cx); @@ -172,9 +171,9 @@ fn mk_test_module(cx: &test_ctxt) -> @ast::item { ret @item; } -fn nospan<@T>(t: &T) -> ast::spanned<T> { ret {node: t, span: dummy_sp()}; } +fn nospan<@T>(t: T) -> ast::spanned<T> { ret {node: t, span: dummy_sp()}; } -fn mk_tests(cx: &test_ctxt) -> @ast::item { +fn mk_tests(cx: test_ctxt) -> @ast::item { let ret_ty = mk_test_desc_vec_ty(cx); let decl: ast::fn_decl = @@ -215,7 +214,7 @@ fn empty_fn_ty() -> ast::ty { } // The ast::ty of [std::test::test_desc] -fn mk_test_desc_vec_ty(cx: &test_ctxt) -> @ast::ty { +fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::ty { let test_desc_ty_path: ast::path = nospan({global: false, idents: ["std", "test", "test_desc"], @@ -229,7 +228,7 @@ fn mk_test_desc_vec_ty(cx: &test_ctxt) -> @ast::ty { ret @nospan(ast::ty_vec(vec_mt)); } -fn mk_test_desc_vec(cx: &test_ctxt) -> @ast::expr { +fn mk_test_desc_vec(cx: test_ctxt) -> @ast::expr { log #fmt["building test vector from %u tests", vec::len(cx.testfns)]; let descs = []; for test: test in cx.testfns { @@ -242,7 +241,7 @@ fn mk_test_desc_vec(cx: &test_ctxt) -> @ast::expr { span: dummy_sp()}; } -fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr { +fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr { let path = test.path; log #fmt["encoding %s", ast_util::path_name_i(path)]; @@ -284,13 +283,15 @@ fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr { ret @desc_rec; } -fn mk_main(cx: &test_ctxt) -> @ast::item { +fn mk_main(cx: test_ctxt) -> @ast::item { let args_mt: ast::mt = {ty: @nospan(ast::ty_str), mut: ast::imm}; let args_ty: ast::ty = nospan(ast::ty_vec(args_mt)); let args_arg: ast::arg = - {mode: ast::by_ref, ty: @args_ty, ident: "args", + {mode: ast::by_ref, + ty: @args_ty, + ident: "args", id: cx.next_node_id()}; let ret_ty = nospan(ast::ty_nil); @@ -322,7 +323,7 @@ fn mk_main(cx: &test_ctxt) -> @ast::item { ret @item; } -fn mk_test_main_call(cx: &test_ctxt) -> @ast::expr { +fn mk_test_main_call(cx: test_ctxt) -> @ast::expr { // Get the args passed to main so we can pass the to test_main let args_path: ast::path = diff --git a/src/comp/lib/llvm.rs b/src/comp/lib/llvm.rs index 431893b0201..8abdb8560f7 100644 --- a/src/comp/lib/llvm.rs +++ b/src/comp/lib/llvm.rs @@ -809,15 +809,19 @@ native "cdecl" mod llvm = "rustllvm" { Value: Bool); fn LLVMPassManagerBuilderSetDisableUnrollLoops(PMB: PassManagerBuilderRef, Value: Bool); - fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls( - PMB: PassManagerBuilderRef, Value: Bool); - fn LLVMPassManagerBuilderUseInlinerWithThreshold( - PMB: PassManagerBuilderRef, threshold: uint); - fn LLVMPassManagerBuilderPopulateModulePassManager( - PMB: PassManagerBuilderRef, PM: PassManagerRef); - - fn LLVMPassManagerBuilderPopulateFunctionPassManager( - PMB: PassManagerBuilderRef, PM: PassManagerRef); + fn LLVMPassManagerBuilderSetDisableSimplifyLibCalls + (PMB: PassManagerBuilderRef, + Value: Bool); + fn LLVMPassManagerBuilderUseInlinerWithThreshold + (PMB: PassManagerBuilderRef, + threshold: uint); + fn LLVMPassManagerBuilderPopulateModulePassManager(PMB: + PassManagerBuilderRef, + PM: PassManagerRef); + + fn LLVMPassManagerBuilderPopulateFunctionPassManager(PMB: + PassManagerBuilderRef, + PM: PassManagerRef); /** Destroys a memory buffer. */ fn LLVMDisposeMemoryBuffer(MemBuf: MemoryBufferRef); @@ -898,7 +902,7 @@ native "cdecl" mod llvm = "rustllvm" { obj type_names(type_names: std::map::hashmap<TypeRef, str>, named_types: std::map::hashmap<str, TypeRef>) { - fn associate(s: &str, t: TypeRef) { + fn associate(s: str, t: TypeRef) { assert (!named_types.contains_key(s)); assert (!type_names.contains_key(t)); type_names.insert(t, s); @@ -909,17 +913,17 @@ obj type_names(type_names: std::map::hashmap<TypeRef, str>, fn get_name(t: TypeRef) -> str { ret type_names.get(t); } - fn name_has_type(s: &str) -> bool { ret named_types.contains_key(s); } + fn name_has_type(s: str) -> bool { ret named_types.contains_key(s); } - fn get_type(s: &str) -> TypeRef { ret named_types.get(s); } + fn get_type(s: str) -> TypeRef { ret named_types.get(s); } } fn mk_type_names() -> type_names { let nt = std::map::new_str_hash::<TypeRef>(); - fn hash(t: &TypeRef) -> uint { ret t as uint; } + fn hash(t: TypeRef) -> uint { ret t as uint; } - fn eq(a: &TypeRef, b: &TypeRef) -> bool { ret a as uint == b as uint; } + fn eq(a: TypeRef, b: TypeRef) -> bool { ret a as uint == b as uint; } let hasher: std::map::hashfn<TypeRef> = hash; let eqer: std::map::eqfn<TypeRef> = eq; @@ -932,7 +936,7 @@ fn type_to_str(names: type_names, ty: TypeRef) -> str { ret type_to_str_inner(names, [], ty); } -fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) -> +fn type_to_str_inner(names: type_names, outer0: [TypeRef], ty: TypeRef) -> str { if names.type_has_name(ty) { ret names.get_name(ty); } @@ -941,7 +945,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) -> let kind: int = llvm::LLVMGetTypeKind(ty); - fn tys_str(names: type_names, outer: &[TypeRef], tys: &[TypeRef]) -> str { + fn tys_str(names: type_names, outer: [TypeRef], tys: [TypeRef]) -> str { let s: str = ""; let first: bool = true; for t: TypeRef in tys { @@ -957,6 +961,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) -> + // FIXME: more enum-as-int constants determined from Core::h; // horrible, horrible. Complete as needed. @@ -973,6 +978,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) -> + 7 { ret "i" + std::int::str(llvm::LLVMGetIntTypeWidth(ty) as int); } @@ -980,6 +986,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) -> + 8 { let s = "fn("; let out_ty: TypeRef = llvm::LLVMGetReturnType(ty); @@ -995,6 +1002,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) -> + 9 { let s: str = "{"; let n_elts: uint = llvm::LLVMCountStructElementTypes(ty); @@ -1008,6 +1016,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) -> + 10 { let el_ty = llvm::LLVMGetElementType(ty); ret "[" + type_to_str_inner(names, outer, el_ty) + "]"; @@ -1016,6 +1025,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) -> + 11 { let i: uint = 0u; for tout: TypeRef in outer0 { @@ -1032,6 +1042,7 @@ fn type_to_str_inner(names: type_names, outer0: &[TypeRef], ty: TypeRef) -> + 12 { ret "Opaque"; } @@ -1066,7 +1077,7 @@ resource target_data_res(TD: TargetDataRef) { type target_data = {lltd: TargetDataRef, dtor: @target_data_res}; -fn mk_target_data(string_rep: &str) -> target_data { +fn mk_target_data(string_rep: str) -> target_data { let lltd = str::as_buf(string_rep, {|buf| llvm::LLVMCreateTargetData(buf) }); ret {lltd: lltd, dtor: @target_data_res(lltd)}; diff --git a/src/comp/metadata/common.rs b/src/comp/metadata/common.rs index 9d6a2c745f8..a22dfa62d2b 100644 --- a/src/comp/metadata/common.rs +++ b/src/comp/metadata/common.rs @@ -65,9 +65,9 @@ const tag_crate_dep: uint = 0x26u; 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_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; diff --git a/src/comp/metadata/creader.rs b/src/comp/metadata/creader.rs index 2c74f03612e..d9438c38e21 100644 --- a/src/comp/metadata/creader.rs +++ b/src/comp/metadata/creader.rs @@ -30,7 +30,7 @@ export list_file_metadata; // Traverses an AST, reading all the information about use'd crates and native // libraries necessary for later resolving, typechecking, linking, etc. -fn read_crates(sess: session::session, crate: &ast::crate) { +fn read_crates(sess: session::session, crate: ast::crate) { let e = @{sess: sess, crate_cache: @std::map::new_str_hash::<int>(), @@ -50,7 +50,7 @@ type env = library_search_paths: [str], mutable next_crate_num: ast::crate_num}; -fn visit_view_item(e: env, i: &@ast::view_item) { +fn visit_view_item(e: env, i: @ast::view_item) { alt i.node { ast::view_item_use(ident, meta_items, id) { let cnum = resolve_crate(e, ident, meta_items, i.span); @@ -60,7 +60,7 @@ fn visit_view_item(e: env, i: &@ast::view_item) { } } -fn visit_item(e: env, i: &@ast::item) { +fn visit_item(e: env, i: @ast::item) { alt i.node { ast::item_native_mod(m) { if m.abi != ast::native_abi_rust && m.abi != ast::native_abi_cdecl { @@ -81,7 +81,7 @@ fn visit_item(e: env, i: &@ast::item) { } // A diagnostic function for dumping crate metadata to an output stream -fn list_file_metadata(path: &str, out: io::writer) { +fn list_file_metadata(path: str, out: io::writer) { alt get_metadata_section(path) { option::some(bytes) { decoder::list_crate_metadata(bytes, out); } option::none. { @@ -90,7 +90,7 @@ fn list_file_metadata(path: &str, out: io::writer) { } } -fn metadata_matches(crate_data: &@[u8], metas: &[@ast::meta_item]) -> bool { +fn metadata_matches(crate_data: @[u8], metas: [@ast::meta_item]) -> bool { let attrs = decoder::get_crate_attributes(crate_data); let linkage_metas = attr::find_linkage_metas(attrs); @@ -116,8 +116,8 @@ fn default_native_lib_naming(sess: session::session, static: bool) -> } } -fn find_library_crate(sess: &session::session, ident: &ast::ident, - metas: &[@ast::meta_item], library_search_paths: &[str]) +fn find_library_crate(sess: session::session, ident: ast::ident, + metas: [@ast::meta_item], library_search_paths: [str]) -> option::t<{ident: str, data: @[u8]}> { attr::require_unique_names(sess, metas); @@ -146,9 +146,9 @@ fn find_library_crate(sess: &session::session, ident: &ast::ident, ret find_library_crate_aux(nn2, crate_name, metas, library_search_paths); } -fn find_library_crate_aux(nn: &{prefix: str, suffix: str}, crate_name: &str, - metas: &[@ast::meta_item], - library_search_paths: &[str]) -> +fn find_library_crate_aux(nn: {prefix: str, suffix: str}, crate_name: str, + metas: [@ast::meta_item], + library_search_paths: [str]) -> option::t<{ident: str, data: @[u8]}> { let prefix: str = nn.prefix + crate_name; let suffix: str = nn.suffix; @@ -184,11 +184,11 @@ fn find_library_crate_aux(nn: &{prefix: str, suffix: str}, crate_name: &str, ret none; } -fn get_metadata_section(filename: &str) -> option::t<@[u8]> { +fn get_metadata_section(filename: str) -> option::t<@[u8]> { let mb = str::as_buf(filename, {|buf| - llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf) - }); + llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf) + }); if mb as int == 0 { ret option::none::<@[u8]>; } let of = mk_object_file(mb); let si = mk_section_iter(of.llof); @@ -206,8 +206,8 @@ fn get_metadata_section(filename: &str) -> option::t<@[u8]> { ret option::none::<@[u8]>; } -fn load_library_crate(sess: &session::session, span: span, ident: &ast::ident, - metas: &[@ast::meta_item], library_search_paths: &[str]) +fn load_library_crate(sess: session::session, span: span, ident: ast::ident, + metas: [@ast::meta_item], library_search_paths: [str]) -> {ident: str, data: @[u8]} { @@ -219,7 +219,7 @@ fn load_library_crate(sess: &session::session, span: span, ident: &ast::ident, } } -fn resolve_crate(e: env, ident: &ast::ident, metas: [@ast::meta_item], +fn resolve_crate(e: env, ident: ast::ident, metas: [@ast::meta_item], span: span) -> ast::crate_num { if !e.crate_cache.contains_key(ident) { let cinfo = @@ -247,7 +247,7 @@ fn resolve_crate(e: env, ident: &ast::ident, metas: [@ast::meta_item], } // Go through the crate metadata and load any crates that it references -fn resolve_crate_deps(e: env, cdata: &@[u8]) -> cstore::cnum_map { +fn resolve_crate_deps(e: env, cdata: @[u8]) -> cstore::cnum_map { log "resolving deps of external crate"; // The map from crate numbers in the crate we're resolving to local crate // numbers diff --git a/src/comp/metadata/csearch.rs b/src/comp/metadata/csearch.rs index d526ee05247..f05d98127b9 100644 --- a/src/comp/metadata/csearch.rs +++ b/src/comp/metadata/csearch.rs @@ -11,18 +11,18 @@ export lookup_defs; export get_tag_variants; export get_type; -fn get_symbol(cstore: &cstore::cstore, def: ast::def_id) -> str { +fn get_symbol(cstore: cstore::cstore, def: ast::def_id) -> str { let cdata = cstore::get_crate_data(cstore, def.crate).data; ret decoder::get_symbol(cdata, def.node); } -fn get_type_param_count(cstore: &cstore::cstore, def: &ast::def_id) -> uint { +fn get_type_param_count(cstore: cstore::cstore, def: ast::def_id) -> uint { let cdata = cstore::get_crate_data(cstore, def.crate).data; ret decoder::get_type_param_count(cdata, def.node); } -fn lookup_defs(cstore: &cstore::cstore, cnum: ast::crate_num, - path: &[ast::ident]) -> [ast::def] { +fn lookup_defs(cstore: cstore::cstore, cnum: ast::crate_num, + path: [ast::ident]) -> [ast::def] { let cdata = cstore::get_crate_data(cstore, cnum).data; ret decoder::lookup_defs(cdata, cnum, path); } @@ -48,8 +48,8 @@ fn get_type(tcx: ty::ctxt, def: ast::def_id) -> ty::ty_param_kinds_and_ty { // external crates - if those types further refer to types in other crates // then we must translate the crate number from that encoded in the external // crate to the correct local crate number. -fn translate_def_id(sess: &session::session, searched_crate: ast::crate_num, - def_id: &ast::def_id) -> ast::def_id { +fn translate_def_id(sess: session::session, searched_crate: ast::crate_num, + def_id: ast::def_id) -> ast::def_id { let ext_cnum = def_id.crate; let node_id = def_id.node; diff --git a/src/comp/metadata/cstore.rs b/src/comp/metadata/cstore.rs index ed737e046ec..05d45fc6e32 100644 --- a/src/comp/metadata/cstore.rs +++ b/src/comp/metadata/cstore.rs @@ -49,7 +49,7 @@ type cstore_private = type use_crate_map = map::hashmap<ast::node_id, ast::crate_num>; // Internal method to retrieve the data from the cstore -fn p(cstore: &cstore) -> cstore_private { alt cstore { private(p) { p } } } +fn p(cstore: cstore) -> cstore_private { alt cstore { private(p) { p } } } fn mk_cstore() -> cstore { let meta_cache = map::new_int_hash::<crate_metadata>(); @@ -61,20 +61,20 @@ fn mk_cstore() -> cstore { mutable used_link_args: []}); } -fn get_crate_data(cstore: &cstore, cnum: ast::crate_num) -> crate_metadata { +fn get_crate_data(cstore: cstore, cnum: ast::crate_num) -> crate_metadata { ret p(cstore).metas.get(cnum); } -fn set_crate_data(cstore: &cstore, cnum: ast::crate_num, - data: &crate_metadata) { +fn set_crate_data(cstore: cstore, cnum: ast::crate_num, + data: crate_metadata) { p(cstore).metas.insert(cnum, data); } -fn have_crate_data(cstore: &cstore, cnum: ast::crate_num) -> bool { +fn have_crate_data(cstore: cstore, cnum: ast::crate_num) -> bool { ret p(cstore).metas.contains_key(cnum); } -iter iter_crate_data(cstore: &cstore) -> +iter iter_crate_data(cstore: cstore) -> @{key: ast::crate_num, val: crate_metadata} { for each kv: @{key: ast::crate_num, val: crate_metadata} in p(cstore).metas.items() { @@ -82,17 +82,17 @@ iter iter_crate_data(cstore: &cstore) -> } } -fn add_used_crate_file(cstore: &cstore, lib: &str) { +fn add_used_crate_file(cstore: cstore, lib: str) { if !vec::member(lib, p(cstore).used_crate_files) { p(cstore).used_crate_files += [lib]; } } -fn get_used_crate_files(cstore: &cstore) -> [str] { +fn get_used_crate_files(cstore: cstore) -> [str] { ret p(cstore).used_crate_files; } -fn add_used_library(cstore: &cstore, lib: &str) -> bool { +fn add_used_library(cstore: cstore, lib: str) -> bool { if lib == "" { ret false; } if vec::member(lib, p(cstore).used_libraries) { ret false; } @@ -101,25 +101,24 @@ fn add_used_library(cstore: &cstore, lib: &str) -> bool { ret true; } -fn get_used_libraries(cstore: &cstore) -> [str] { +fn get_used_libraries(cstore: cstore) -> [str] { ret p(cstore).used_libraries; } -fn add_used_link_args(cstore: &cstore, args: &str) { +fn add_used_link_args(cstore: cstore, args: str) { p(cstore).used_link_args += str::split(args, ' ' as u8); } -fn get_used_link_args(cstore: &cstore) -> [str] { +fn get_used_link_args(cstore: cstore) -> [str] { ret p(cstore).used_link_args; } -fn add_use_stmt_cnum(cstore: &cstore, use_id: ast::node_id, +fn add_use_stmt_cnum(cstore: cstore, use_id: ast::node_id, cnum: ast::crate_num) { p(cstore).use_crate_map.insert(use_id, cnum); } -fn get_use_stmt_cnum(cstore: &cstore, use_id: ast::node_id) -> - ast::crate_num { +fn get_use_stmt_cnum(cstore: cstore, use_id: ast::node_id) -> ast::crate_num { ret p(cstore).use_crate_map.get(use_id); } diff --git a/src/comp/metadata/decoder.rs b/src/comp/metadata/decoder.rs index 7803e6922a1..cd241f3931e 100644 --- a/src/comp/metadata/decoder.rs +++ b/src/comp/metadata/decoder.rs @@ -34,9 +34,9 @@ export external_resolver; // def_id for an item defined in another crate, somebody needs to figure out // what crate that's in and give us a def_id that makes sense for the current // build. -type external_resolver = fn(&ast::def_id) -> ast::def_id; +type external_resolver = fn(ast::def_id) -> ast::def_id; -fn lookup_hash(d: &ebml::doc, eq_fn: fn(&[u8]) -> bool, hash: uint) -> +fn lookup_hash(d: ebml::doc, eq_fn: fn([u8]) -> bool, hash: uint) -> [ebml::doc] { let index = ebml::get_doc(d, tag_index); let table = ebml::get_doc(index, tag_index_table); @@ -56,8 +56,8 @@ fn lookup_hash(d: &ebml::doc, eq_fn: fn(&[u8]) -> bool, hash: uint) -> ret result; } -fn maybe_find_item(item_id: int, items: &ebml::doc) -> option::t<ebml::doc> { - fn eq_item(bytes: &[u8], item_id: int) -> bool { +fn maybe_find_item(item_id: int, items: ebml::doc) -> option::t<ebml::doc> { + fn eq_item(bytes: [u8], item_id: int) -> bool { ret ebml::be_uint_from_bytes(@bytes, 0u, 4u) as int == item_id; } let eqer = bind eq_item(_, item_id); @@ -67,36 +67,36 @@ fn maybe_find_item(item_id: int, items: &ebml::doc) -> option::t<ebml::doc> { } else { ret option::some::<ebml::doc>(found[0]); } } -fn find_item(item_id: int, items: &ebml::doc) -> ebml::doc { +fn find_item(item_id: int, items: ebml::doc) -> ebml::doc { ret option::get(maybe_find_item(item_id, items)); } // Looks up an item in the given metadata and returns an ebml doc pointing // to the item data. -fn lookup_item(item_id: int, data: &@[u8]) -> ebml::doc { +fn lookup_item(item_id: int, data: @[u8]) -> ebml::doc { let items = ebml::get_doc(ebml::new_doc(data), tag_items); ret find_item(item_id, items); } -fn item_family(item: &ebml::doc) -> u8 { +fn item_family(item: ebml::doc) -> u8 { let fam = ebml::get_doc(item, tag_items_data_item_family); ret ebml::doc_as_uint(fam) as u8; } -fn item_symbol(item: &ebml::doc) -> str { +fn item_symbol(item: ebml::doc) -> str { let sym = ebml::get_doc(item, tag_items_data_item_symbol); ret str::unsafe_from_bytes(ebml::doc_data(sym)); } -fn variant_tag_id(d: &ebml::doc) -> ast::def_id { +fn variant_tag_id(d: ebml::doc) -> ast::def_id { let tagdoc = ebml::get_doc(d, tag_items_data_item_tag_id); ret parse_def_id(ebml::doc_data(tagdoc)); } -fn item_type(item: &ebml::doc, this_cnum: ast::crate_num, tcx: ty::ctxt, - extres: &external_resolver) -> ty::t { +fn item_type(item: ebml::doc, this_cnum: ast::crate_num, tcx: ty::ctxt, + extres: external_resolver) -> ty::t { fn parse_external_def_id(this_cnum: ast::crate_num, - extres: &external_resolver, s: &str) -> + extres: external_resolver, s: str) -> ast::def_id { let buf = str::bytes(s); let external_def_id = parse_def_id(buf); @@ -114,7 +114,7 @@ fn item_type(item: &ebml::doc, this_cnum: ast::crate_num, tcx: ty::ctxt, def_parser, tcx); } -fn item_ty_param_kinds(item: &ebml::doc) -> [ast::kind] { +fn item_ty_param_kinds(item: ebml::doc) -> [ast::kind] { let ks: [ast::kind] = []; let tp = tag_items_data_item_ty_param_kinds; for each p: ebml::doc in ebml::tagged_docs(item, tp) { @@ -135,7 +135,7 @@ fn item_ty_param_kinds(item: &ebml::doc) -> [ast::kind] { ret ks; } -fn tag_variant_ids(item: &ebml::doc, this_cnum: ast::crate_num) -> +fn tag_variant_ids(item: ebml::doc, this_cnum: ast::crate_num) -> [ast::def_id] { let ids: [ast::def_id] = []; let v = tag_items_data_item_variant; @@ -148,8 +148,8 @@ fn tag_variant_ids(item: &ebml::doc, this_cnum: ast::crate_num) -> // Given a path and serialized crate metadata, returns the ID of the // definition the path refers to. -fn resolve_path(path: &[ast::ident], data: @[u8]) -> [ast::def_id] { - fn eq_item(data: &[u8], s: &str) -> bool { +fn resolve_path(path: [ast::ident], data: @[u8]) -> [ast::def_id] { + fn eq_item(data: [u8], s: str) -> bool { ret str::eq(str::unsafe_from_bytes(data), s); } let s = str::connect(path, "::"); @@ -165,14 +165,14 @@ fn resolve_path(path: &[ast::ident], data: @[u8]) -> [ast::def_id] { } // Crate metadata queries -fn lookup_defs(data: &@[u8], cnum: ast::crate_num, path: &[ast::ident]) -> +fn lookup_defs(data: @[u8], cnum: ast::crate_num, path: [ast::ident]) -> [ast::def] { ret vec::map(bind lookup_def(cnum, data, _), resolve_path(path, data)); } // FIXME doesn't yet handle re-exported externals -fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: &ast::def_id) -> +fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: ast::def_id) -> ast::def { let item = lookup_item(did_.node, data); let fam_ch = item_family(item); @@ -198,8 +198,8 @@ fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: &ast::def_id) -> ret def; } -fn get_type(data: @[u8], def: ast::def_id, tcx: &ty::ctxt, - extres: &external_resolver) -> ty::ty_param_kinds_and_ty { +fn get_type(data: @[u8], def: ast::def_id, tcx: ty::ctxt, + extres: external_resolver) -> ty::ty_param_kinds_and_ty { let this_cnum = def.crate; let node_id = def.node; let item = lookup_item(node_id, data); @@ -225,8 +225,8 @@ fn get_symbol(data: @[u8], id: ast::node_id) -> str { ret item_symbol(lookup_item(id, data)); } -fn get_tag_variants(_data: &@[u8], def: ast::def_id, tcx: &ty::ctxt, - extres: &external_resolver) -> [ty::variant_info] { +fn get_tag_variants(_data: @[u8], def: ast::def_id, tcx: ty::ctxt, + extres: external_resolver) -> [ty::variant_info] { let external_crate_id = def.crate; let data = cstore::get_crate_data(tcx.sess.get_cstore(), external_crate_id).data; @@ -267,7 +267,7 @@ fn family_has_type_params(fam_ch: u8) -> bool { }; } -fn read_path(d: &ebml::doc) -> {path: str, pos: uint} { +fn read_path(d: ebml::doc) -> {path: str, pos: uint} { let desc = ebml::doc_data(d); let pos = ebml::be_uint_from_bytes(@desc, 0u, 4u); let pathbytes = vec::slice::<u8>(desc, 4u, vec::len::<u8>(desc)); @@ -275,7 +275,7 @@ fn read_path(d: &ebml::doc) -> {path: str, pos: uint} { ret {path: path, pos: pos}; } -fn describe_def(items: &ebml::doc, id: ast::def_id) -> str { +fn describe_def(items: ebml::doc, id: ast::def_id) -> str { if id.crate != ast::local_crate { ret "external"; } ret item_family_to_str(item_family(find_item(id.node, items))); } @@ -295,7 +295,7 @@ fn item_family_to_str(fam: u8) -> str { } } -fn get_meta_items(md: &ebml::doc) -> [@ast::meta_item] { +fn get_meta_items(md: ebml::doc) -> [@ast::meta_item] { let items: [@ast::meta_item] = []; for each meta_item_doc: ebml::doc in ebml::tagged_docs(md, tag_meta_item_word) { @@ -323,7 +323,7 @@ fn get_meta_items(md: &ebml::doc) -> [@ast::meta_item] { ret items; } -fn get_attributes(md: &ebml::doc) -> [ast::attribute] { +fn get_attributes(md: ebml::doc) -> [ast::attribute] { let attrs: [ast::attribute] = []; alt ebml::maybe_get_doc(md, tag_attributes) { option::some(attrs_d) { @@ -344,13 +344,13 @@ fn get_attributes(md: &ebml::doc) -> [ast::attribute] { ret attrs; } -fn list_meta_items(meta_items: &ebml::doc, out: io::writer) { +fn list_meta_items(meta_items: ebml::doc, out: io::writer) { for mi: @ast::meta_item in get_meta_items(meta_items) { out.write_str(#fmt["%s\n", pprust::meta_item_to_str(*mi)]); } } -fn list_crate_attributes(md: &ebml::doc, out: io::writer) { +fn list_crate_attributes(md: ebml::doc, out: io::writer) { out.write_str("=Crate Attributes=\n"); for attr: ast::attribute in get_attributes(md) { @@ -389,7 +389,7 @@ fn list_crate_deps(data: @[u8], out: io::writer) { out.write_str("\n"); } -fn list_crate_items(bytes: &@[u8], md: &ebml::doc, out: io::writer) { +fn list_crate_items(bytes: @[u8], md: ebml::doc, out: io::writer) { out.write_str("=Items=\n"); let paths = ebml::get_doc(md, tag_paths); let items = ebml::get_doc(md, tag_items); @@ -410,7 +410,7 @@ fn list_crate_items(bytes: &@[u8], md: &ebml::doc, out: io::writer) { out.write_str("\n"); } -fn list_crate_metadata(bytes: &@[u8], out: io::writer) { +fn list_crate_metadata(bytes: @[u8], out: io::writer) { let md = ebml::new_doc(bytes); list_crate_attributes(md, out); list_crate_deps(bytes, out); diff --git a/src/comp/metadata/encoder.rs b/src/comp/metadata/encoder.rs index 342ddcc887d..9c48772cd22 100644 --- a/src/comp/metadata/encoder.rs +++ b/src/comp/metadata/encoder.rs @@ -26,13 +26,13 @@ type abbrev_map = map::hashmap<ty::t, tyencode::ty_abbrev>; type encode_ctxt = {ccx: @crate_ctxt, type_abbrevs: abbrev_map}; // Path table encoding -fn encode_name(ebml_w: &ebml::writer, name: &str) { +fn encode_name(ebml_w: ebml::writer, name: str) { ebml::start_tag(ebml_w, tag_paths_data_name); ebml_w.writer.write(str::bytes(name)); ebml::end_tag(ebml_w); } -fn encode_def_id(ebml_w: &ebml::writer, id: &def_id) { +fn encode_def_id(ebml_w: ebml::writer, id: def_id) { ebml::start_tag(ebml_w, tag_def_id); ebml_w.writer.write(str::bytes(def_to_str(id))); ebml::end_tag(ebml_w); @@ -40,8 +40,8 @@ fn encode_def_id(ebml_w: &ebml::writer, id: &def_id) { type entry<T> = {val: T, pos: uint}; -fn encode_tag_variant_paths(ebml_w: &ebml::writer, variants: &[variant], - path: &[str], index: &mutable [entry<str>]) { +fn encode_tag_variant_paths(ebml_w: ebml::writer, variants: [variant], + path: [str], index: &mutable [entry<str>]) { for variant: variant in variants { add_to_index(ebml_w, path, index, variant.node.name); ebml::start_tag(ebml_w, tag_paths_data_item); @@ -51,15 +51,15 @@ fn encode_tag_variant_paths(ebml_w: &ebml::writer, variants: &[variant], } } -fn add_to_index(ebml_w: &ebml::writer, path: &[str], - index: &mutable [entry<str>], name: &str) { +fn add_to_index(ebml_w: ebml::writer, path: [str], + index: &mutable [entry<str>], name: str) { let full_path = path + [name]; index += [{val: str::connect(full_path, "::"), pos: ebml_w.writer.tell()}]; } -fn encode_native_module_item_paths(ebml_w: &ebml::writer, nmod: &native_mod, - path: &[str], +fn encode_native_module_item_paths(ebml_w: ebml::writer, nmod: native_mod, + path: [str], index: &mutable [entry<str>]) { for nitem: @native_item in nmod.items { add_to_index(ebml_w, path, index, nitem.ident); @@ -70,8 +70,8 @@ fn encode_native_module_item_paths(ebml_w: &ebml::writer, nmod: &native_mod, } } -fn encode_module_item_paths(ebml_w: &ebml::writer, module: &_mod, - path: &[str], index: &mutable [entry<str>]) { +fn encode_module_item_paths(ebml_w: ebml::writer, module: _mod, path: [str], + index: &mutable [entry<str>]) { for it: @item in module.items { if !ast_util::is_exported(it.ident, module) { cont; } alt it.node { @@ -149,7 +149,7 @@ fn encode_module_item_paths(ebml_w: &ebml::writer, module: &_mod, } } -fn encode_item_paths(ebml_w: &ebml::writer, crate: &@crate) -> [entry<str>] { +fn encode_item_paths(ebml_w: ebml::writer, crate: @crate) -> [entry<str>] { let index: [entry<str>] = []; let path: [str] = []; ebml::start_tag(ebml_w, tag_paths); @@ -160,21 +160,21 @@ fn encode_item_paths(ebml_w: &ebml::writer, crate: &@crate) -> [entry<str>] { // Item info table encoding -fn encode_family(ebml_w: &ebml::writer, c: u8) { +fn encode_family(ebml_w: ebml::writer, c: u8) { ebml::start_tag(ebml_w, tag_items_data_item_family); ebml_w.writer.write([c]); ebml::end_tag(ebml_w); } -fn encode_inlineness(ebml_w: &ebml::writer, c: u8) { +fn encode_inlineness(ebml_w: ebml::writer, c: u8) { ebml::start_tag(ebml_w, tag_items_data_item_inlineness); ebml_w.writer.write([c]); ebml::end_tag(ebml_w); } -fn def_to_str(did: &def_id) -> str { ret #fmt["%d:%d", did.crate, did.node]; } +fn def_to_str(did: def_id) -> str { ret #fmt["%d:%d", did.crate, did.node]; } -fn encode_type_param_kinds(ebml_w: &ebml::writer, tps: &[ty_param]) { +fn encode_type_param_kinds(ebml_w: ebml::writer, tps: [ty_param]) { ebml::start_tag(ebml_w, tag_items_data_item_ty_param_kinds); ebml::write_vint(ebml_w.writer, vec::len::<ty_param>(tps)); for tp: ty_param in tps { @@ -189,13 +189,13 @@ fn encode_type_param_kinds(ebml_w: &ebml::writer, tps: &[ty_param]) { ebml::end_tag(ebml_w); } -fn encode_variant_id(ebml_w: &ebml::writer, vid: &def_id) { +fn encode_variant_id(ebml_w: ebml::writer, vid: def_id) { ebml::start_tag(ebml_w, tag_items_data_item_variant); ebml_w.writer.write(str::bytes(def_to_str(vid))); ebml::end_tag(ebml_w); } -fn encode_type(ecx: &@encode_ctxt, ebml_w: &ebml::writer, typ: ty::t) { +fn encode_type(ecx: @encode_ctxt, ebml_w: ebml::writer, typ: ty::t) { ebml::start_tag(ebml_w, tag_items_data_item_type); let f = def_to_str; let ty_str_ctxt = @@ -206,29 +206,28 @@ fn encode_type(ecx: &@encode_ctxt, ebml_w: &ebml::writer, typ: ty::t) { ebml::end_tag(ebml_w); } -fn encode_symbol(ecx: &@encode_ctxt, ebml_w: &ebml::writer, id: node_id) { +fn encode_symbol(ecx: @encode_ctxt, ebml_w: ebml::writer, id: node_id) { ebml::start_tag(ebml_w, tag_items_data_item_symbol); ebml_w.writer.write(str::bytes(ecx.ccx.item_symbols.get(id))); ebml::end_tag(ebml_w); } -fn encode_discriminant(ecx: &@encode_ctxt, ebml_w: &ebml::writer, - id: node_id) { +fn encode_discriminant(ecx: @encode_ctxt, ebml_w: ebml::writer, id: node_id) { ebml::start_tag(ebml_w, tag_items_data_item_symbol); ebml_w.writer.write(str::bytes(ecx.ccx.discrim_symbols.get(id))); ebml::end_tag(ebml_w); } -fn encode_tag_id(ebml_w: &ebml::writer, id: &def_id) { +fn encode_tag_id(ebml_w: ebml::writer, id: def_id) { ebml::start_tag(ebml_w, tag_items_data_item_tag_id); ebml_w.writer.write(str::bytes(def_to_str(id))); ebml::end_tag(ebml_w); } -fn encode_tag_variant_info(ecx: &@encode_ctxt, ebml_w: &ebml::writer, - id: node_id, variants: &[variant], +fn encode_tag_variant_info(ecx: @encode_ctxt, ebml_w: ebml::writer, + id: node_id, variants: [variant], index: &mutable [entry<int>], - ty_params: &[ty_param]) { + ty_params: [ty_param]) { for variant: variant in variants { index += [{val: variant.node.id, pos: ebml_w.writer.tell()}]; ebml::start_tag(ebml_w, tag_items_data_item); @@ -246,7 +245,7 @@ fn encode_tag_variant_info(ecx: &@encode_ctxt, ebml_w: &ebml::writer, } } -fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: &ebml::writer, item: @item, +fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, index: &mutable [entry<int>]) { alt item.node { item_const(_, _) { @@ -349,8 +348,8 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: &ebml::writer, item: @item, } } -fn encode_info_for_native_item(ecx: &@encode_ctxt, ebml_w: &ebml::writer, - nitem: &@native_item) { +fn encode_info_for_native_item(ecx: @encode_ctxt, ebml_w: ebml::writer, + nitem: @native_item) { ebml::start_tag(ebml_w, tag_items_data_item); alt nitem.node { native_item_ty. { @@ -370,7 +369,7 @@ fn encode_info_for_native_item(ecx: &@encode_ctxt, ebml_w: &ebml::writer, ebml::end_tag(ebml_w); } -fn encode_info_for_items(ecx: &@encode_ctxt, ebml_w: &ebml::writer) -> +fn encode_info_for_items(ecx: @encode_ctxt, ebml_w: ebml::writer) -> [entry<int>] { let index: [entry<int>] = []; ebml::start_tag(ebml_w, tag_items_data); @@ -395,7 +394,7 @@ fn encode_info_for_items(ecx: &@encode_ctxt, ebml_w: &ebml::writer) -> // Path and definition ID indexing -fn create_index<T>(index: &[entry<T>], hash_fn: fn(&T) -> uint) -> +fn create_index<T>(index: [entry<T>], hash_fn: fn(T) -> uint) -> [@[entry<T>]] { let buckets: [@mutable [entry<T>]] = []; for each i: uint in uint::range(0u, 256u) { buckets += [@mutable []]; } @@ -411,8 +410,8 @@ fn create_index<T>(index: &[entry<T>], hash_fn: fn(&T) -> uint) -> ret buckets_frozen; } -fn encode_index<T>(ebml_w: &ebml::writer, buckets: &[@[entry<T>]], - write_fn: fn(&io::writer, &T)) { +fn encode_index<T>(ebml_w: ebml::writer, buckets: [@[entry<T>]], + write_fn: fn(io::writer, T)) { let writer = io::new_writer(ebml_w.writer); ebml::start_tag(ebml_w, tag_index); let bucket_locs: [uint] = []; @@ -435,13 +434,13 @@ 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) { +fn write_int(writer: io::writer, n: int) { writer.write_be_uint(n as uint, 4u); } -fn encode_meta_item(ebml_w: &ebml::writer, mi: &meta_item) { +fn encode_meta_item(ebml_w: ebml::writer, mi: meta_item) { alt mi.node { meta_word(name) { ebml::start_tag(ebml_w, tag_meta_item_word); @@ -478,7 +477,7 @@ fn encode_meta_item(ebml_w: &ebml::writer, mi: &meta_item) { } } -fn encode_attributes(ebml_w: &ebml::writer, attrs: &[attribute]) { +fn encode_attributes(ebml_w: ebml::writer, attrs: [attribute]) { ebml::start_tag(ebml_w, tag_attributes); for attr: attribute in attrs { ebml::start_tag(ebml_w, tag_attribute); @@ -492,9 +491,9 @@ fn encode_attributes(ebml_w: &ebml::writer, attrs: &[attribute]) { // metadata that Rust cares about for linking crates. This attribute requires // 'name' and 'vers' items, so if the user didn't provide them we will throw // them in anyway with default values. -fn synthesize_crate_attrs(ecx: &@encode_ctxt, crate: &@crate) -> [attribute] { +fn synthesize_crate_attrs(ecx: @encode_ctxt, crate: @crate) -> [attribute] { - fn synthesize_link_attr(ecx: &@encode_ctxt, items: &[@meta_item]) -> + fn synthesize_link_attr(ecx: @encode_ctxt, items: [@meta_item]) -> attribute { assert (ecx.ccx.link_meta.name != ""); @@ -526,7 +525,7 @@ fn synthesize_crate_attrs(ecx: &@encode_ctxt, crate: &@crate) -> [attribute] { } else { alt attr.node.value.node { meta_list(n, l) { - found_link_attr = true; + found_link_attr = true;; [synthesize_link_attr(ecx, l)] } _ { [attr] } @@ -539,9 +538,9 @@ fn synthesize_crate_attrs(ecx: &@encode_ctxt, crate: &@crate) -> [attribute] { ret attrs; } -fn encode_crate_deps(ebml_w: &ebml::writer, cstore: &cstore::cstore) { +fn encode_crate_deps(ebml_w: ebml::writer, cstore: cstore::cstore) { - fn get_ordered_names(cstore: &cstore::cstore) -> [str] { + fn get_ordered_names(cstore: cstore::cstore) -> [str] { type hashkv = @{key: crate_num, val: cstore::crate_metadata}; type numname = {crate: crate_num, ident: str}; @@ -552,9 +551,7 @@ fn encode_crate_deps(ebml_w: &ebml::writer, cstore: &cstore::cstore) { } // Sort by cnum - fn lteq(kv1: &numname, kv2: &numname) -> bool { - kv1.crate <= kv2.crate - } + fn lteq(kv1: numname, kv2: numname) -> bool { kv1.crate <= kv2.crate } std::sort::quick_sort(lteq, pairs); // Sanity-check the crate numbers @@ -565,7 +562,7 @@ fn encode_crate_deps(ebml_w: &ebml::writer, cstore: &cstore::cstore) { } // Return just the names - fn name(kv: &numname) -> str { kv.ident } + fn name(kv: numname) -> str { kv.ident } // mutable -> immutable hack for vec::map let immpairs = vec::slice(pairs, 0u, vec::len(pairs)); ret vec::map(name, immpairs); @@ -584,7 +581,7 @@ fn encode_crate_deps(ebml_w: &ebml::writer, cstore: &cstore::cstore) { ebml::end_tag(ebml_w); } -fn encode_metadata(cx: &@crate_ctxt, crate: &@crate) -> str { +fn encode_metadata(cx: @crate_ctxt, crate: @crate) -> str { let abbrevs = map::mk_hashmap(ty::hash_ty, ty::eq_ty); let ecx = @{ccx: cx, type_abbrevs: abbrevs}; @@ -620,7 +617,7 @@ fn encode_metadata(cx: &@crate_ctxt, crate: &@crate) -> str { } // Get the encoded string for a type -fn encoded_ty(tcx: &ty::ctxt, t: ty::t) -> str { +fn encoded_ty(tcx: ty::ctxt, t: ty::t) -> str { let cx = @{ds: def_to_str, tcx: tcx, abbrevs: tyencode::ac_no_abbrevs}; let sw = io::string_writer(); tyencode::enc_ty(sw.get_writer(), cx, t); diff --git a/src/comp/metadata/tydecode.rs b/src/comp/metadata/tydecode.rs index 788c5d0bc5d..ce73f736b79 100644 --- a/src/comp/metadata/tydecode.rs +++ b/src/comp/metadata/tydecode.rs @@ -20,7 +20,7 @@ export parse_ty_data; // data buffer. Whatever format you choose should not contain pipe characters. // Callback to translate defs to strs or back: -type str_def = fn(&str) -> ast::def_id; +type str_def = fn(str) -> ast::def_id; type pstate = {data: @[u8], crate: int, mutable pos: uint, len: uint, tcx: ty::ctxt}; @@ -401,7 +401,7 @@ fn parse_ty_fn(st: @pstate, sd: str_def) -> // Rust metadata parsing -fn parse_def_id(buf: &[u8]) -> ast::def_id { +fn parse_def_id(buf: [u8]) -> ast::def_id { let colon_idx = 0u; let len = vec::len::<u8>(buf); while colon_idx < len && buf[colon_idx] != ':' as u8 { colon_idx += 1u; } diff --git a/src/comp/metadata/tyencode.rs b/src/comp/metadata/tyencode.rs index 999a3c65716..dde77d6533f 100644 --- a/src/comp/metadata/tyencode.rs +++ b/src/comp/metadata/tyencode.rs @@ -21,7 +21,7 @@ export enc_ty; type ctxt = // Def -> str Callback: // The type context. - {ds: fn(&def_id) -> str, tcx: ty::ctxt, abbrevs: abbrev_ctxt}; + {ds: fn(def_id) -> str, tcx: ty::ctxt, abbrevs: abbrev_ctxt}; // Compact string representation for ty.t values. API ty_str & parse_from_str. // Extra parameters are for converting to/from def_ids in the string rep. @@ -30,14 +30,14 @@ type ty_abbrev = {pos: uint, len: uint, s: @str}; tag abbrev_ctxt { ac_no_abbrevs; ac_use_abbrevs(hashmap<ty::t, ty_abbrev>); } -fn cx_uses_abbrevs(cx: &@ctxt) -> bool { +fn cx_uses_abbrevs(cx: @ctxt) -> bool { alt cx.abbrevs { ac_no_abbrevs. { ret false; } ac_use_abbrevs(_) { ret true; } } } -fn enc_ty(w: &io::writer, cx: &@ctxt, t: ty::t) { +fn enc_ty(w: io::writer, cx: @ctxt, t: ty::t) { alt cx.abbrevs { ac_no_abbrevs. { let result_str: @str; @@ -82,7 +82,7 @@ fn enc_ty(w: &io::writer, cx: &@ctxt, t: ty::t) { } } } -fn enc_mt(w: &io::writer, cx: &@ctxt, mt: &ty::mt) { +fn enc_mt(w: io::writer, cx: @ctxt, mt: ty::mt) { alt mt.mut { imm. { } mut. { w.write_char('m'); } @@ -90,7 +90,7 @@ fn enc_mt(w: &io::writer, cx: &@ctxt, mt: &ty::mt) { } enc_ty(w, cx, mt.ty); } -fn enc_sty(w: &io::writer, cx: &@ctxt, st: &ty::sty) { +fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) { alt st { ty::ty_nil. { w.write_char('n'); } ty::ty_bot. { w.write_char('z'); } @@ -194,7 +194,7 @@ fn enc_sty(w: &io::writer, cx: &@ctxt, st: &ty::sty) { } } } -fn enc_proto(w: &io::writer, proto: proto) { +fn enc_proto(w: io::writer, proto: proto) { alt proto { proto_iter. { w.write_char('W'); } proto_fn. { w.write_char('F'); } @@ -202,8 +202,8 @@ fn enc_proto(w: &io::writer, proto: proto) { } } -fn enc_ty_fn(w: &io::writer, cx: &@ctxt, args: &[ty::arg], out: ty::t, - cf: &controlflow, constrs: &[@ty::constr]) { +fn enc_ty_fn(w: io::writer, cx: @ctxt, args: [ty::arg], out: ty::t, + cf: controlflow, constrs: [@ty::constr]) { w.write_char('['); for arg: ty::arg in args { alt arg.mode { @@ -227,7 +227,7 @@ fn enc_ty_fn(w: &io::writer, cx: &@ctxt, args: &[ty::arg], out: ty::t, } // FIXME less copy-and-paste -fn enc_constr(w: &io::writer, cx: &@ctxt, c: &@ty::constr) { +fn enc_constr(w: io::writer, cx: @ctxt, c: @ty::constr) { w.write_str(path_to_str(c.node.path)); w.write_char('('); w.write_str(cx.ds(c.node.id)); @@ -244,7 +244,7 @@ fn enc_constr(w: &io::writer, cx: &@ctxt, c: &@ty::constr) { w.write_char(')'); } -fn enc_ty_constr(w: &io::writer, cx: &@ctxt, c: &@ty::type_constr) { +fn enc_ty_constr(w: io::writer, cx: @ctxt, c: @ty::type_constr) { w.write_str(path_to_str(c.node.path)); w.write_char('('); w.write_str(cx.ds(c.node.id)); diff --git a/src/comp/middle/alias.rs b/src/comp/middle/alias.rs index 03cd853e9a2..2d14daa2c42 100644 --- a/src/comp/middle/alias.rs +++ b/src/comp/middle/alias.rs @@ -45,7 +45,7 @@ type ctx = mutable next_local: uint, copy_map: copy_map}; -fn check_crate(tcx: ty::ctxt, crate: &@ast::crate) -> copy_map { +fn check_crate(tcx: ty::ctxt, crate: @ast::crate) -> copy_map { // Stores information about object fields and function // arguments that's otherwise not easily available. let cx = @@ -63,17 +63,19 @@ fn check_crate(tcx: ty::ctxt, crate: &@ast::crate) -> copy_map { ret cx.copy_map; } -fn visit_fn(f: &ast::_fn, _tp: &[ast::ty_param], _sp: &span, _name: &fn_ident, - _id: ast::node_id, sc: &scope, v: &vt<scope>) { +fn visit_fn(f: ast::_fn, _tp: [ast::ty_param], _sp: span, _name: fn_ident, + _id: ast::node_id, sc: scope, v: vt<scope>) { visit::visit_fn_decl(f.decl, sc, v); let scope = alt f.proto { + // Blocks need to obey any restrictions from the enclosing scope. ast::proto_block. | ast::proto_closure. { sc } + // Non capturing functions start out fresh. _ { @[] @@ -82,7 +84,7 @@ fn visit_fn(f: &ast::_fn, _tp: &[ast::ty_param], _sp: &span, _name: &fn_ident, v.visit_block(f.body, scope, v); } -fn visit_expr(cx: &@ctx, ex: &@ast::expr, sc: &scope, v: &vt<scope>) { +fn visit_expr(cx: @ctx, ex: @ast::expr, sc: scope, v: vt<scope>) { let handled = true; alt ex.node { ast::expr_call(f, args) { @@ -129,14 +131,14 @@ fn visit_expr(cx: &@ctx, ex: &@ast::expr, sc: &scope, v: &vt<scope>) { if !handled { visit::visit_expr(ex, sc, v); } } -fn register_locals(cx: &ctx, pat: &@ast::pat) { +fn register_locals(cx: ctx, pat: @ast::pat) { for each pat in ast_util::pat_bindings(pat) { cx.local_map.insert(pat.id, local(cx.next_local)); cx.next_local += 1u; } } -fn visit_decl(cx: &@ctx, d: &@ast::decl, sc: &scope, v: &vt<scope>) { +fn visit_decl(cx: @ctx, d: @ast::decl, sc: scope, v: vt<scope>) { visit::visit_decl(d, sc, v); alt d.node { ast::decl_local(locs) { @@ -156,22 +158,21 @@ fn visit_decl(cx: &@ctx, d: &@ast::decl, sc: &scope, v: &vt<scope>) { } } -fn cant_copy(cx: &ctx, r: &restrict) -> bool { +fn cant_copy(cx: ctx, r: restrict) -> bool { if r.given_up { ret false; } // FIXME alt contexts copying not supported yet if r.node_id == 0 { ret true; } + // FIXME warn when copy is expensive if ty::type_allows_implicit_copy(cx.tcx, r.ty) { r.given_up = true; cx.copy_map.insert(r.node_id, ()); ret false; - } else { - ret true; - } + } else { ret true; } } -fn check_call(cx: &ctx, f: &@ast::expr, args: &[@ast::expr], sc: &scope) - -> [restrict] { +fn check_call(cx: ctx, f: @ast::expr, args: [@ast::expr], sc: scope) -> + [restrict] { let fty = ty::type_autoderef(cx.tcx, ty::expr_ty(cx.tcx, f)); let arg_ts = ty::ty_fn_args(cx.tcx, fty); let mut_roots: [{arg: uint, node: node_id}] = []; @@ -193,7 +194,9 @@ fn check_call(cx: &ctx, f: &@ast::expr, args: &[@ast::expr], sc: &scope) let unsafe_t = alt inner_mut(root.ds) { some(t) { some(t) } _ { none } }; restricts += - [@{root_var: root_var, + [ + // FIXME kludge + @{root_var: root_var, node_id: arg_t.mode == ast::by_mut_ref ? 0 : arg.id, ty: arg_t.ty, local_id: cx.next_local, @@ -201,7 +204,6 @@ fn check_call(cx: &ctx, f: &@ast::expr, args: &[@ast::expr], sc: &scope) unsafe_ty: unsafe_t, depends_on: deps(sc, root_var), mutable ok: valid, - // FIXME kludge mutable given_up: arg_t.mode == ast::by_move}]; i += 1u; } @@ -230,12 +232,12 @@ fn check_call(cx: &ctx, f: &@ast::expr, args: &[@ast::expr], sc: &scope) for arg_t: ty::arg in arg_ts { let mut_alias = arg_t.mode == ast::by_mut_ref; if i != j && - ty_can_unsafely_include(cx, ty, arg_t.ty, mut_alias) && - cant_copy(cx, r) { - cx.tcx.sess.span_err( - args[i].span, - #fmt["argument %u may alias with argument %u, \ - which is not immutably rooted", i, j]); + ty_can_unsafely_include(cx, ty, arg_t.ty, mut_alias) && + cant_copy(cx, r) { + cx.tcx.sess.span_err(args[i].span, + #fmt["argument %u may alias with argument %u, \ + which is not immutably rooted", + i, j]); } i += 1u; } @@ -253,8 +255,8 @@ fn check_call(cx: &ctx, f: &@ast::expr, args: &[@ast::expr], sc: &scope) alt r.root_var { some(root) { if node == root && cant_copy(cx, r) { - cx.tcx.sess.span_err( - args[arg].span, "passing a mutable alias to a \ + cx.tcx.sess.span_err(args[arg].span, + "passing a mutable alias to a \ variable that roots another alias"); break; } @@ -268,8 +270,8 @@ fn check_call(cx: &ctx, f: &@ast::expr, args: &[@ast::expr], sc: &scope) ret restricts; } -fn check_alt(cx: &ctx, input: &@ast::expr, arms: &[ast::arm], sc: &scope, - v: &vt<scope>) { +fn check_alt(cx: ctx, input: @ast::expr, arms: [ast::arm], sc: scope, + v: vt<scope>) { v.visit_expr(input, sc, v); let root = expr_root(cx.tcx, input, true); for a: ast::arm in arms { @@ -279,8 +281,9 @@ fn check_alt(cx: &ctx, input: &@ast::expr, arms: &[ast::arm], sc: &scope, let root_var = path_def_id(cx, root.ex); new_sc = @(*sc + - [@{root_var: root_var, - // FIXME need to use separate restrict for each binding + [ + // FIXME need to use separate restrict for each binding + @{root_var: root_var, node_id: 0, ty: ty::mk_int(cx.tcx), local_id: cx.next_local, @@ -295,8 +298,8 @@ fn check_alt(cx: &ctx, input: &@ast::expr, arms: &[ast::arm], sc: &scope, } } -fn check_for_each(cx: &ctx, local: &@ast::local, call: &@ast::expr, - blk: &ast::blk, sc: &scope, v: &vt<scope>) { +fn check_for_each(cx: ctx, local: @ast::local, call: @ast::expr, + blk: ast::blk, sc: scope, v: vt<scope>) { v.visit_expr(call, sc, v); alt call.node { ast::expr_call(f, args) { @@ -307,8 +310,8 @@ fn check_for_each(cx: &ctx, local: &@ast::local, call: &@ast::expr, } } -fn check_for(cx: &ctx, local: &@ast::local, seq: &@ast::expr, blk: &ast::blk, - sc: &scope, v: &vt<scope>) { +fn check_for(cx: ctx, local: @ast::local, seq: @ast::expr, blk: ast::blk, + sc: scope, v: vt<scope>) { v.visit_expr(seq, sc, v); let root = expr_root(cx.tcx, seq, false); let unsafe = inner_mut(root.ds); @@ -321,13 +324,12 @@ fn check_for(cx: &ctx, local: &@ast::local, seq: &@ast::expr, blk: &ast::blk, if mt.mut != ast::imm { unsafe = some(seq_t); } elt_t = mt.ty; } - ty::ty_str. { - elt_t = ty::mk_mach(cx.tcx, ast::ty_u8); - } + ty::ty_str. { elt_t = ty::mk_mach(cx.tcx, ast::ty_u8); } } let root_var = path_def_id(cx, root.ex); let new_sc = @{root_var: root_var, + // FIXME reenable when trans knows how to copy for vars node_id: 0, // blk.node.id, ty: elt_t, @@ -341,8 +343,8 @@ fn check_for(cx: &ctx, local: &@ast::local, seq: &@ast::expr, blk: &ast::blk, visit::visit_block(blk, @(*sc + [new_sc]), v); } -fn check_var(cx: &ctx, ex: &@ast::expr, p: &ast::path, id: ast::node_id, - assign: bool, sc: &scope) { +fn check_var(cx: ctx, ex: @ast::expr, p: ast::path, id: ast::node_id, + assign: bool, sc: scope) { let def = cx.tcx.def_map.get(id); if !def_is_local(def, true) { ret; } let my_defnum = ast_util::def_id_of_def(def).node; @@ -350,6 +352,7 @@ fn check_var(cx: &ctx, ex: &@ast::expr, p: &ast::path, id: ast::node_id, alt cx.local_map.find(my_defnum) { some(local(id)) { id } _ { 0u } }; let var_t = ty::expr_ty(cx.tcx, ex); for r: restrict in *sc { + // excludes variables introduced since the alias was made if my_local_id < r.local_id { alt r.unsafe_ty { @@ -366,7 +369,7 @@ fn check_var(cx: &ctx, ex: &@ast::expr, p: &ast::path, id: ast::node_id, } } -fn check_lval(cx: &@ctx, dest: &@ast::expr, sc: &scope, v: &vt<scope>) { +fn check_lval(cx: @ctx, dest: @ast::expr, sc: scope, v: vt<scope>) { alt dest.node { ast::expr_path(p) { let def = cx.tcx.def_map.get(dest.id); @@ -379,27 +382,29 @@ fn check_lval(cx: &@ctx, dest: &@ast::expr, sc: &scope, v: &vt<scope>) { } } -fn check_assign(cx: &@ctx, dest: &@ast::expr, src: &@ast::expr, sc: &scope, - v: &vt<scope>) { +fn check_assign(cx: @ctx, dest: @ast::expr, src: @ast::expr, sc: scope, + v: vt<scope>) { visit_expr(cx, src, sc, v); check_lval(cx, dest, sc, v); } -fn test_scope(cx: &ctx, sc: &scope, r: &restrict, p: &ast::path) { +fn test_scope(cx: ctx, sc: scope, r: restrict, p: ast::path) { let prob = r.ok; for dep: uint in r.depends_on { if prob != valid { break; } prob = sc[dep].ok; } if prob != valid && cant_copy(cx, r) { - let msg = alt prob { - overwritten(sp, wpt) { - {span: sp, msg: "overwriting " + ast_util::path_name(wpt)} - } - val_taken(sp, vpt) { - {span: sp, msg: "taking the value of " + ast_util::path_name(vpt)} - } - }; + let msg = + alt prob { + overwritten(sp, wpt) { + {span: sp, msg: "overwriting " + ast_util::path_name(wpt)} + } + val_taken(sp, vpt) { + {span: sp, + msg: "taking the value of " + ast_util::path_name(vpt)} + } + }; cx.tcx.sess.span_err(msg.span, msg.msg + " will invalidate alias " + ast_util::path_name(p) + @@ -407,7 +412,7 @@ fn test_scope(cx: &ctx, sc: &scope, r: &restrict, p: &ast::path) { } } -fn deps(sc: &scope, root: &option::t<node_id>) -> [uint] { +fn deps(sc: scope, root: option::t<node_id>) -> [uint] { let result = []; alt root { some(dn) { @@ -422,14 +427,14 @@ fn deps(sc: &scope, root: &option::t<node_id>) -> [uint] { ret result; } -fn path_def(cx: &ctx, ex: &@ast::expr) -> option::t<ast::def> { +fn path_def(cx: ctx, ex: @ast::expr) -> option::t<ast::def> { ret alt ex.node { ast::expr_path(_) { some(cx.tcx.def_map.get(ex.id)) } _ { none } } } -fn path_def_id(cx: &ctx, ex: &@ast::expr) -> option::t<ast::node_id> { +fn path_def_id(cx: ctx, ex: @ast::expr) -> option::t<ast::node_id> { alt ex.node { ast::expr_path(_) { ret some(ast_util::def_id_of_def(cx.tcx.def_map.get(ex.id)).node); @@ -438,12 +443,12 @@ fn path_def_id(cx: &ctx, ex: &@ast::expr) -> option::t<ast::node_id> { } } -fn ty_can_unsafely_include(cx: &ctx, needle: ty::t, haystack: ty::t, - mut: bool) -> bool { - fn get_mut(cur: bool, mt: &ty::mt) -> bool { +fn ty_can_unsafely_include(cx: ctx, needle: ty::t, haystack: ty::t, mut: bool) + -> bool { + fn get_mut(cur: bool, mt: ty::mt) -> bool { ret cur || mt.mut != ast::imm; } - fn helper(tcx: &ty::ctxt, needle: ty::t, haystack: ty::t, mut: bool) -> + fn helper(tcx: ty::ctxt, needle: ty::t, haystack: ty::t, mut: bool) -> bool { if needle == haystack { ret true; } alt ty::struct(tcx, haystack) { @@ -472,6 +477,7 @@ fn ty_can_unsafely_include(cx: &ctx, needle: ty::t, haystack: ty::t, + // These may contain anything. ty::ty_fn(_, _, _, _, _) { ret true; @@ -480,6 +486,7 @@ fn ty_can_unsafely_include(cx: &ctx, needle: ty::t, haystack: ty::t, + // A type param may include everything, but can only be // treated as opaque downstream, and is thus safe unless we // saw mutable fields, in which case the whole thing can be @@ -493,7 +500,7 @@ fn ty_can_unsafely_include(cx: &ctx, needle: ty::t, haystack: ty::t, ret helper(cx.tcx, needle, haystack, mut); } -fn def_is_local(d: &ast::def, objfields_count: bool) -> bool { +fn def_is_local(d: ast::def, objfields_count: bool) -> bool { ret alt d { ast::def_local(_) | ast::def_arg(_, _) | ast::def_binding(_) | ast::def_upvar(_, _, _) { diff --git a/src/comp/middle/ast_map.rs b/src/comp/middle/ast_map.rs index 356d2b46b8c..d31a8d65e13 100644 --- a/src/comp/middle/ast_map.rs +++ b/src/comp/middle/ast_map.rs @@ -14,7 +14,7 @@ tag ast_node { type map = std::map::hashmap<node_id, ast_node>; -fn map_crate(c: &crate) -> map { +fn map_crate(c: crate) -> map { // FIXME: This is using an adapter to convert the smallintmap // interface to the hashmap interface. It would be better to just // convert everything to use the smallintmap. @@ -29,7 +29,7 @@ fn map_crate(c: &crate) -> map { ret map; } -fn map_item(map: &map, i: &@item, e: &(), v: &vt<()>) { +fn map_item(map: map, i: @item, e: (), v: vt<()>) { map.insert(i.id, node_item(i)); alt i.node { item_obj(_, _, ctor_id) { map.insert(ctor_id, node_obj_ctor(i)); } @@ -38,19 +38,19 @@ fn map_item(map: &map, i: &@item, e: &(), v: &vt<()>) { visit::visit_item(i, e, v); } -fn map_native_item(map: &map, i: &@native_item, e: &(), v: &vt<()>) { +fn map_native_item(map: map, i: @native_item, e: (), v: vt<()>) { map.insert(i.id, node_native_item(i)); visit::visit_native_item(i, e, v); } -fn map_expr(map: &map, ex: &@expr, e: &(), v: &vt<()>) { +fn map_expr(map: map, ex: @expr, e: (), v: vt<()>) { map.insert(ex.id, node_expr(ex)); visit::visit_expr(ex, e, v); } fn new_smallintmap_int_adapter<@V>() -> std::map::hashmap<int, V> { - let key_idx = fn (key: &int) -> uint { key as uint }; - let idx_key = fn (idx: &uint) -> int { idx as int }; + let key_idx = fn (key: int) -> uint { key as uint }; + let idx_key = fn (idx: uint) -> int { idx as int }; ret new_smallintmap_adapter(key_idx, idx_key); } @@ -60,34 +60,33 @@ fn new_smallintmap_int_adapter<@V>() -> std::map::hashmap<int, V> { // interface. // FIXME: hashmap and smallintmap should support the same interface. fn new_smallintmap_adapter<@K, - @V>(key_idx: fn(&K) -> uint, - idx_key: fn(&uint) -> K) -> - std::map::hashmap<K, V> { + @V>(key_idx: fn(K) -> uint, idx_key: fn(uint) -> K) + -> std::map::hashmap<K, V> { obj adapter<@K, @V>(map: smallintmap::smallintmap<V>, - key_idx: fn(&K) -> uint, - idx_key: fn(&uint) -> K) { + key_idx: fn(K) -> uint, + idx_key: fn(uint) -> K) { fn size() -> uint { fail } - fn insert(key: &K, value: &V) -> bool { + fn insert(key: K, value: V) -> bool { let exists = smallintmap::contains_key(map, key_idx(key)); smallintmap::insert(map, key_idx(key), value); ret !exists; } - fn contains_key(key: &K) -> bool { + fn contains_key(key: K) -> bool { ret smallintmap::contains_key(map, key_idx(key)); } - fn get(key: &K) -> V { ret smallintmap::get(map, key_idx(key)); } + fn get(key: K) -> V { ret smallintmap::get(map, key_idx(key)); } - fn find(key: &K) -> option::t<V> { + fn find(key: K) -> option::t<V> { ret smallintmap::find(map, key_idx(key)); } - fn remove(_key: &K) -> option::t<V> { fail } + fn remove(_key: K) -> option::t<V> { fail } fn rehash() { fail } @@ -114,7 +113,7 @@ fn new_smallintmap_adapter<@K, ret adapter(map, key_idx, idx_key); } -fn node_span(node: &ast_node) -> codemap::span { +fn node_span(node: ast_node) -> codemap::span { alt node { node_item(item) { item.span } node_obj_ctor(item) { item.span } diff --git a/src/comp/middle/check_alt.rs b/src/comp/middle/check_alt.rs index ce5e937cf69..03f83d0a7e7 100644 --- a/src/comp/middle/check_alt.rs +++ b/src/comp/middle/check_alt.rs @@ -3,7 +3,7 @@ import syntax::ast_util::variant_def_ids; import syntax::ast_util::dummy_sp; import syntax::visit; -fn check_crate(tcx: &ty::ctxt, crate: &@crate) { +fn check_crate(tcx: ty::ctxt, crate: @crate) { let v = @{visit_expr: bind check_expr(tcx, _, _, _), visit_local: bind check_local(tcx, _, _, _) @@ -12,12 +12,12 @@ fn check_crate(tcx: &ty::ctxt, crate: &@crate) { tcx.sess.abort_if_errors(); } -fn check_expr(tcx: &ty::ctxt, ex: &@expr, s: &(), v: &visit::vt<()>) { +fn check_expr(tcx: ty::ctxt, ex: @expr, s: (), v: visit::vt<()>) { visit::visit_expr(ex, s, v); alt ex.node { expr_alt(_, arms) { check_arms(tcx, arms); } _ { } } } -fn check_arms(tcx: &ty::ctxt, arms: &[arm]) { +fn check_arms(tcx: ty::ctxt, arms: [arm]) { let i = 0; for arm: arm in arms { for arm_pat: @pat in arm.pats { @@ -41,8 +41,8 @@ fn check_arms(tcx: &ty::ctxt, arms: &[arm]) { } } -fn pattern_supersedes(tcx: &ty::ctxt, a: &@pat, b: &@pat) -> bool { - fn patterns_supersede(tcx: &ty::ctxt, as: &[@pat], bs: &[@pat]) -> bool { +fn pattern_supersedes(tcx: ty::ctxt, a: @pat, b: @pat) -> bool { + fn patterns_supersede(tcx: ty::ctxt, as: [@pat], bs: [@pat]) -> bool { let i = 0; for a: @pat in as { if !pattern_supersedes(tcx, a, bs[i]) { ret false; } @@ -50,8 +50,8 @@ fn pattern_supersedes(tcx: &ty::ctxt, a: &@pat, b: &@pat) -> bool { } ret true; } - fn field_patterns_supersede(tcx: &ty::ctxt, fas: &[field_pat], - fbs: &[field_pat]) -> bool { + fn field_patterns_supersede(tcx: ty::ctxt, fas: [field_pat], + fbs: [field_pat]) -> bool { let wild = @{id: 0, node: pat_wild, span: dummy_sp()}; for fa: field_pat in fas { let pb = wild; @@ -102,7 +102,7 @@ fn pattern_supersedes(tcx: &ty::ctxt, a: &@pat, b: &@pat) -> bool { } } -fn check_local(tcx: &ty::ctxt, loc: &@local, s: &(), v: &visit::vt<()>) { +fn check_local(tcx: ty::ctxt, loc: @local, s: (), v: visit::vt<()>) { visit::visit_local(loc, s, v); if is_refutable(tcx, loc.node.pat) { tcx.sess.span_err(loc.node.pat.span, @@ -110,7 +110,7 @@ fn check_local(tcx: &ty::ctxt, loc: &@local, s: &(), v: &visit::vt<()>) { } } -fn is_refutable(tcx: &ty::ctxt, pat: &@pat) -> bool { +fn is_refutable(tcx: ty::ctxt, pat: @pat) -> bool { alt pat.node { pat_wild. | pat_bind(_) { ret false; } pat_lit(_) { ret true; } diff --git a/src/comp/middle/freevars.rs b/src/comp/middle/freevars.rs index 50d4d1c062b..14641d556d1 100644 --- a/src/comp/middle/freevars.rs +++ b/src/comp/middle/freevars.rs @@ -29,15 +29,15 @@ type freevar_map = hashmap<ast::node_id, freevar_info>; // Since we want to be able to collect upvars in some arbitrary piece // of the AST, we take a walker function that we invoke with a visitor // in order to start the search. -fn collect_freevars(def_map: &resolve::def_map, walker: &fn(&visit::vt<int>)) - -> freevar_info { +fn collect_freevars(def_map: resolve::def_map, walker: fn(visit::vt<int>)) -> + freevar_info { let seen = new_int_hash(); let refs = @mutable []; - fn ignore_item(_i: &@ast::item, _depth: &int, _v: &visit::vt<int>) { } + fn ignore_item(_i: @ast::item, _depth: int, _v: visit::vt<int>) { } let walk_expr = - lambda (expr: &@ast::expr, depth: &int, v: &visit::vt<int>) { + lambda (expr: @ast::expr, depth: int, v: visit::vt<int>) { alt expr.node { ast::expr_fn(f) { if f.proto == ast::proto_block || @@ -81,28 +81,26 @@ fn collect_freevars(def_map: &resolve::def_map, walker: &fn(&visit::vt<int>)) // efficient as it fully recomputes the free variables at every // node of interest rather than building up the free variables in // one pass. This could be improved upon if it turns out to matter. -fn annotate_freevars(def_map: &resolve::def_map, crate: &@ast::crate) -> +fn annotate_freevars(def_map: resolve::def_map, crate: @ast::crate) -> freevar_map { let freevars = new_int_hash(); let walk_fn = - lambda (f: &ast::_fn, tps: &[ast::ty_param], sp: &span, - i: &ast::fn_ident, nid: ast::node_id) { + lambda (f: ast::_fn, tps: [ast::ty_param], sp: span, i: ast::fn_ident, + nid: ast::node_id) { let start_walk = - lambda (v: &visit::vt<int>) { + lambda (v: visit::vt<int>) { v.visit_fn(f, tps, sp, i, nid, 1, v); }; let vars = collect_freevars(def_map, start_walk); freevars.insert(nid, vars); }; let walk_expr = - lambda (expr: &@ast::expr) { + lambda (expr: @ast::expr) { alt expr.node { ast::expr_for_each(local, _, body) { let start_walk = - lambda (v: &visit::vt<int>) { - v.visit_block(body, 1, v); - }; + lambda (v: visit::vt<int>) { v.visit_block(body, 1, v); }; let vars = collect_freevars(def_map, start_walk); freevars.insert(body.node.id, vars); } @@ -118,13 +116,13 @@ fn annotate_freevars(def_map: &resolve::def_map, crate: &@ast::crate) -> ret freevars; } -fn get_freevars(tcx: &ty::ctxt, fid: ast::node_id) -> freevar_info { +fn get_freevars(tcx: ty::ctxt, fid: ast::node_id) -> freevar_info { alt tcx.freevars.find(fid) { none. { fail "get_freevars: " + int::str(fid) + " has no freevars"; } some(d) { ret d; } } } -fn has_freevars(tcx: &ty::ctxt, fid: ast::node_id) -> bool { +fn has_freevars(tcx: ty::ctxt, fid: ast::node_id) -> bool { ret std::vec::len(*get_freevars(tcx, fid)) != 0u; } diff --git a/src/comp/middle/gc.rs b/src/comp/middle/gc.rs index 4ce93f7737a..2069f4096de 100644 --- a/src/comp/middle/gc.rs +++ b/src/comp/middle/gc.rs @@ -21,7 +21,7 @@ type ctxt = @{mutable next_tydesc_num: uint}; fn mk_ctxt() -> ctxt { ret @{mutable next_tydesc_num: 0u}; } -fn add_global(ccx: &@crate_ctxt, llval: ValueRef, name: &str) -> ValueRef { +fn add_global(ccx: @crate_ctxt, llval: ValueRef, name: str) -> ValueRef { let llglobal = str::as_buf(name, {|buf| @@ -32,7 +32,7 @@ fn add_global(ccx: &@crate_ctxt, llval: ValueRef, name: &str) -> ValueRef { ret llglobal; } -fn add_gc_root(cx: &@block_ctxt, llval: ValueRef, ty: ty::t) -> @block_ctxt { +fn add_gc_root(cx: @block_ctxt, llval: ValueRef, ty: ty::t) -> @block_ctxt { let bcx = cx; if !type_is_gc_relevant(bcx_tcx(cx), ty) || ty::type_has_dynamic_size(bcx_tcx(cx), ty) { @@ -102,7 +102,7 @@ fn add_gc_root(cx: &@block_ctxt, llval: ValueRef, ty: ty::t) -> @block_ctxt { ret bcx; } -fn type_is_gc_relevant(cx: &ty::ctxt, ty: ty::t) -> bool { +fn type_is_gc_relevant(cx: ty::ctxt, ty: ty::t) -> bool { alt ty::struct(cx, ty) { ty::ty_nil. | ty::ty_bot. | ty::ty_bool. | ty::ty_int. | ty::ty_float. | ty::ty_uint. | ty::ty_machine(_) | ty::ty_char. | ty::ty_str. | @@ -113,6 +113,7 @@ fn type_is_gc_relevant(cx: &ty::ctxt, ty: ty::t) -> bool { + ty::ty_rec(fields) { for f in fields { if type_is_gc_relevant(cx, f.mt.ty) { ret true; } } ret false; @@ -124,6 +125,7 @@ fn type_is_gc_relevant(cx: &ty::ctxt, ty: ty::t) -> bool { + ty::ty_tag(did, tps) { let variants = ty::tag_variants(cx, did); for variant in variants { @@ -137,6 +139,7 @@ fn type_is_gc_relevant(cx: &ty::ctxt, ty: ty::t) -> bool { + ty::ty_vec(tm) { ret type_is_gc_relevant(cx, tm.ty); } @@ -144,6 +147,7 @@ fn type_is_gc_relevant(cx: &ty::ctxt, ty: ty::t) -> bool { + ty::ty_box(_) | ty::ty_uniq(_) | ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _, _) | ty::ty_obj(_) | ty::ty_param(_, _) | ty::ty_res(_, _, _) { @@ -152,6 +156,7 @@ fn type_is_gc_relevant(cx: &ty::ctxt, ty: ty::t) -> bool { + ty::ty_var(_) { fail "ty_var in type_is_gc_relevant"; } diff --git a/src/comp/middle/kind.rs b/src/comp/middle/kind.rs index 052eccb304d..21053f83f8f 100644 --- a/src/comp/middle/kind.rs +++ b/src/comp/middle/kind.rs @@ -104,15 +104,15 @@ fn kind_to_str(k: kind) -> str { } } -fn type_and_kind(tcx: &ty::ctxt, e: &@ast::expr) -> +fn type_and_kind(tcx: ty::ctxt, e: @ast::expr) -> {ty: ty::t, kind: ast::kind} { let t = ty::expr_ty(tcx, e); let k = ty::type_kind(tcx, t); {ty: t, kind: k} } -fn need_expr_kind(tcx: &ty::ctxt, e: &@ast::expr, k_need: ast::kind, - descr: &str) { +fn need_expr_kind(tcx: ty::ctxt, e: @ast::expr, k_need: ast::kind, + descr: str) { let tk = type_and_kind(tcx, e); log #fmt["for %s: want %s type, got %s type %s", descr, kind_to_str(k_need), kind_to_str(tk.kind), @@ -127,13 +127,12 @@ fn need_expr_kind(tcx: &ty::ctxt, e: &@ast::expr, k_need: ast::kind, } } -fn need_shared_lhs_rhs(tcx: &ty::ctxt, a: &@ast::expr, b: &@ast::expr, - op: &str) { +fn need_shared_lhs_rhs(tcx: ty::ctxt, a: @ast::expr, b: @ast::expr, op: str) { need_expr_kind(tcx, a, ast::kind_shared, op + " lhs"); need_expr_kind(tcx, b, ast::kind_shared, op + " rhs"); } -fn check_expr(tcx: &ty::ctxt, e: &@ast::expr) { +fn check_expr(tcx: ty::ctxt, e: @ast::expr) { alt e.node { ast::expr_move(a, b) { need_shared_lhs_rhs(tcx, a, b, "<-"); } ast::expr_assign(a, b) { need_shared_lhs_rhs(tcx, a, b, "="); } @@ -182,7 +181,7 @@ fn check_expr(tcx: &ty::ctxt, e: &@ast::expr) { } } -fn check_crate(tcx: &ty::ctxt, crate: &@ast::crate) { +fn check_crate(tcx: ty::ctxt, crate: @ast::crate) { let visit = visit::mk_simple_visitor(@{visit_expr: bind check_expr(tcx, _) with *visit::default_simple_visitor()}); diff --git a/src/comp/middle/mut.rs b/src/comp/middle/mut.rs index a2570648535..eae2d1b1541 100644 --- a/src/comp/middle/mut.rs +++ b/src/comp/middle/mut.rs @@ -12,9 +12,9 @@ type deref = @{mut: bool, kind: deref_t, outer_t: ty::t}; // vec of dereferences that were used on this root. Note that, in this vec, // the inner derefs come in front, so foo.bar[1] becomes rec(ex=foo, // ds=[index,field]) -fn expr_root(tcx: &ty::ctxt, ex: @expr, autoderef: bool) -> +fn expr_root(tcx: ty::ctxt, ex: @expr, autoderef: bool) -> {ex: @expr, ds: @[deref]} { - fn maybe_auto_unbox(tcx: &ty::ctxt, t: ty::t) -> {t: ty::t, ds: [deref]} { + fn maybe_auto_unbox(tcx: ty::ctxt, t: ty::t) -> {t: ty::t, ds: [deref]} { let ds = []; while true { alt ty::struct(tcx, t) { @@ -68,14 +68,13 @@ fn expr_root(tcx: &ty::ctxt, ex: @expr, autoderef: bool) -> let auto_unbox = maybe_auto_unbox(tcx, ty::expr_ty(tcx, base)); alt ty::struct(tcx, auto_unbox.t) { ty::ty_vec(mt) { - ds += [@{mut: mt.mut != imm, - kind: index, - outer_t: auto_unbox.t}]; + ds += + [@{mut: mt.mut != imm, + kind: index, + outer_t: auto_unbox.t}]; } ty::ty_str. { - ds += [@{mut: false, - kind: index, - outer_t: auto_unbox.t}]; + ds += [@{mut: false, kind: index, outer_t: auto_unbox.t}]; } } ds += auto_unbox.ds; @@ -106,12 +105,12 @@ fn expr_root(tcx: &ty::ctxt, ex: @expr, autoderef: bool) -> ret {ex: ex, ds: @ds}; } -fn mut_field(ds: &@[deref]) -> bool { +fn mut_field(ds: @[deref]) -> bool { for d: deref in *ds { if d.mut { ret true; } } ret false; } -fn inner_mut(ds: &@[deref]) -> option::t<ty::t> { +fn inner_mut(ds: @[deref]) -> option::t<ty::t> { for d: deref in *ds { if d.mut { ret some(d.outer_t); } } ret none; } @@ -121,7 +120,7 @@ fn inner_mut(ds: &@[deref]) -> option::t<ty::t> { type mut_map = std::map::hashmap<node_id, ()>; type ctx = {tcx: ty::ctxt, mut_map: mut_map}; -fn check_crate(tcx: ty::ctxt, crate: &@crate) -> mut_map { +fn check_crate(tcx: ty::ctxt, crate: @crate) -> mut_map { let cx = @{tcx: tcx, mut_map: std::map::new_int_hash()}; let v = @{visit_expr: bind visit_expr(cx, _, _, _), @@ -133,7 +132,7 @@ fn check_crate(tcx: ty::ctxt, crate: &@crate) -> mut_map { tag msg { msg_assign; msg_move_out; msg_mut_alias; } -fn mk_err(cx: &@ctx, span: &syntax::codemap::span, msg: msg, name: &str) { +fn mk_err(cx: @ctx, span: syntax::codemap::span, msg: msg, name: str) { cx.tcx.sess.span_err(span, alt msg { msg_assign. { "assigning to " + name } @@ -144,7 +143,7 @@ fn mk_err(cx: &@ctx, span: &syntax::codemap::span, msg: msg, name: &str) { }); } -fn visit_decl(cx: &@ctx, d: &@decl, e: &(), v: &visit::vt<()>) { +fn visit_decl(cx: @ctx, d: @decl, e: (), v: visit::vt<()>) { visit::visit_decl(d, e, v); alt d.node { decl_local(locs) { @@ -161,7 +160,7 @@ fn visit_decl(cx: &@ctx, d: &@decl, e: &(), v: &visit::vt<()>) { } } -fn visit_expr(cx: &@ctx, ex: &@expr, e: &(), v: &visit::vt<()>) { +fn visit_expr(cx: @ctx, ex: @expr, e: (), v: visit::vt<()>) { alt ex.node { expr_call(f, args) { check_call(cx, f, args); } expr_swap(lhs, rhs) { @@ -180,7 +179,7 @@ fn visit_expr(cx: &@ctx, ex: &@expr, e: &(), v: &visit::vt<()>) { visit::visit_expr(ex, e, v); } -fn check_lval(cx: &@ctx, dest: &@expr, msg: msg) { +fn check_lval(cx: @ctx, dest: @expr, msg: msg) { alt dest.node { expr_path(p) { let def = cx.tcx.def_map.get(dest.id); @@ -193,9 +192,7 @@ fn check_lval(cx: &@ctx, dest: &@expr, msg: msg) { _ { let root = expr_root(cx.tcx, dest, false); if vec::len(*root.ds) == 0u { - if msg == msg_assign { - mk_err(cx, dest.span, msg, "non-lvalue"); - } + if msg == msg_assign { mk_err(cx, dest.span, msg, "non-lvalue"); } } else if !root.ds[0].mut { let name = alt root.ds[0].kind { @@ -209,7 +206,7 @@ fn check_lval(cx: &@ctx, dest: &@expr, msg: msg) { } } -fn check_move_rhs(cx: &@ctx, src: &@expr) { +fn check_move_rhs(cx: @ctx, src: @expr) { alt src.node { expr_path(p) { alt cx.tcx.def_map.get(src.id) { @@ -231,20 +228,18 @@ fn check_move_rhs(cx: &@ctx, src: &@expr) { } } -fn check_call(cx: &@ctx, f: &@expr, args: &[@expr]) { +fn check_call(cx: @ctx, f: @expr, args: [@expr]) { let arg_ts = ty::ty_fn_args(cx.tcx, ty::type_autoderef(cx.tcx, ty::expr_ty(cx.tcx, f))); let i = 0u; for arg_t: ty::arg in arg_ts { - if arg_t.mode != by_ref { - check_lval(cx, args[i], msg_mut_alias); - } + if arg_t.mode != by_ref { check_lval(cx, args[i], msg_mut_alias); } i += 1u; } } -fn is_immutable_def(def: &def) -> option::t<str> { +fn is_immutable_def(def: def) -> option::t<str> { alt def { def_fn(_, _) | def_mod(_) | def_native_mod(_) | def_const(_) | def_use(_) { diff --git a/src/comp/middle/resolve.rs b/src/comp/middle/resolve.rs index ae52009bb66..b4a1b0bbcfb 100644 --- a/src/comp/middle/resolve.rs +++ b/src/comp/middle/resolve.rs @@ -78,7 +78,7 @@ type ext_hash = hashmap<{did: def_id, ident: str, ns: namespace}, def>; fn new_ext_hash() -> ext_hash { type key = {did: def_id, ident: str, ns: namespace}; - fn hash(v: &key) -> uint { + fn hash(v: key) -> uint { ret str::hash(v.ident) + util::common::hash_def(v.did) + alt v.ns { ns_value. { 1u } @@ -86,7 +86,7 @@ fn new_ext_hash() -> ext_hash { ns_module. { 3u } }; } - fn eq(v1: &key, v2: &key) -> bool { + fn eq(v1: key, v2: key) -> bool { ret util::common::def_eq(v1.did, v2.did) && str::eq(v1.ident, v2.ident) && v1.ns == v2.ns; } @@ -137,7 +137,7 @@ tag dir { inside; outside; } tag namespace { ns_value; ns_type; ns_module; } -fn resolve_crate(sess: session, amap: &ast_map::map, crate: @ast::crate) -> +fn resolve_crate(sess: session, amap: ast_map::map, crate: @ast::crate) -> {def_map: def_map, ext_map: ext_map} { let e = @{cstore: sess.get_cstore(), @@ -160,7 +160,7 @@ fn resolve_crate(sess: session, amap: &ast_map::map, crate: @ast::crate) -> // Locate all modules and imports and index them, so that the next passes can // resolve through them. -fn map_crate(e: &@env, c: &@ast::crate) { +fn map_crate(e: @env, c: @ast::crate) { // First, find all the modules, and index the names that they contain let v_map_mod = @@ -175,7 +175,7 @@ fn map_crate(e: &@env, c: &@ast::crate) { index: index_mod(c.node.module), mutable glob_imports: [], glob_imported_names: new_str_hash::<import_state>()}); - fn index_vi(e: @env, i: &@ast::view_item, sc: &scopes, _v: &vt<scopes>) { + fn index_vi(e: @env, i: @ast::view_item, sc: scopes, _v: vt<scopes>) { alt i.node { ast::view_item_import(name, ids, id) { e.imports.insert(id, todo(id, name, ids, i.span, sc)); @@ -191,7 +191,7 @@ fn map_crate(e: &@env, c: &@ast::crate) { _ { } } } - fn index_i(e: @env, i: &@ast::item, sc: &scopes, v: &vt<scopes>) { + fn index_i(e: @env, i: @ast::item, sc: scopes, v: vt<scopes>) { visit_item_with_scope(i, sc, v); alt i.node { ast::item_mod(md) { @@ -221,8 +221,7 @@ fn map_crate(e: &@env, c: &@ast::crate) { with *visit::default_visitor::<scopes>()}; visit::visit_crate(*c, cons(scope_crate, @nil), visit::mk_vt(v_link_glob)); - fn link_glob(e: @env, vi: &@ast::view_item, sc: &scopes, - _v: &vt<scopes>) { + fn link_glob(e: @env, vi: @ast::view_item, sc: scopes, _v: vt<scopes>) { fn find_mod(e: @env, sc: scopes) -> @indexed_mod { alt sc { cons(scope_item(i), tl) { @@ -243,6 +242,7 @@ fn map_crate(e: &@env, c: &@ast::crate) { + //if it really is a glob import, that is ast::view_item_import_glob(path, _) { let imp = follow_import(*e, sc, path, vi.span); @@ -256,7 +256,7 @@ fn map_crate(e: &@env, c: &@ast::crate) { } } -fn resolve_imports(e: &env) { +fn resolve_imports(e: env) { for each it: @{key: ast::node_id, val: import_state} in e.imports.items() { alt it.val { @@ -269,7 +269,7 @@ fn resolve_imports(e: &env) { e.sess.abort_if_errors(); } -fn resolve_names(e: &@env, c: &@ast::crate) { +fn resolve_names(e: @env, c: @ast::crate) { let v = @{visit_native_item: visit_native_item_with_scope, visit_item: visit_item_with_scope, @@ -285,7 +285,7 @@ fn resolve_names(e: &@env, c: &@ast::crate) { visit::visit_crate(*c, cons(scope_crate, @nil), visit::mk_vt(v)); e.sess.abort_if_errors(); - fn walk_expr(e: @env, exp: &@ast::expr, sc: &scopes, v: &vt<scopes>) { + fn walk_expr(e: @env, exp: @ast::expr, sc: scopes, v: vt<scopes>) { visit_expr_with_scope(exp, sc, v); alt exp.node { ast::expr_path(p) { @@ -296,7 +296,7 @@ fn resolve_names(e: &@env, c: &@ast::crate) { _ { } } } - fn walk_ty(e: @env, t: &@ast::ty, sc: &scopes, v: &vt<scopes>) { + fn walk_ty(e: @env, t: @ast::ty, sc: scopes, v: vt<scopes>) { visit::visit_ty(t, sc, v); alt t.node { ast::ty_path(p, id) { @@ -306,11 +306,11 @@ fn resolve_names(e: &@env, c: &@ast::crate) { _ { } } } - fn walk_constr(e: @env, p: &ast::path, sp: &span, id: node_id, - sc: &scopes, _v: &vt<scopes>) { + fn walk_constr(e: @env, p: ast::path, sp: span, id: node_id, sc: scopes, + _v: vt<scopes>) { maybe_insert(e, id, lookup_path_strict(*e, sc, sp, p.node, ns_value)); } - fn walk_pat(e: &@env, pat: &@ast::pat, sc: &scopes, v: &vt<scopes>) { + fn walk_pat(e: @env, pat: @ast::pat, sc: scopes, v: vt<scopes>) { visit::visit_pat(pat, sc, v); alt pat.node { ast::pat_tag(p, _) { @@ -337,18 +337,18 @@ fn resolve_names(e: &@env, c: &@ast::crate) { // Visit helper functions -fn visit_item_with_scope(i: &@ast::item, sc: &scopes, v: &vt<scopes>) { +fn visit_item_with_scope(i: @ast::item, sc: scopes, v: vt<scopes>) { visit::visit_item(i, cons(scope_item(i), @sc), v); } -fn visit_native_item_with_scope(ni: &@ast::native_item, sc: &scopes, - v: &vt<scopes>) { +fn visit_native_item_with_scope(ni: @ast::native_item, sc: scopes, + v: vt<scopes>) { visit::visit_native_item(ni, cons(scope_native_item(ni), @sc), v); } -fn visit_fn_with_scope(e: &@env, f: &ast::_fn, tp: &[ast::ty_param], - sp: &span, name: &fn_ident, id: node_id, sc: &scopes, - v: &vt<scopes>) { +fn visit_fn_with_scope(e: @env, f: ast::_fn, tp: [ast::ty_param], sp: span, + name: fn_ident, id: node_id, sc: scopes, + v: vt<scopes>) { // is this a main fn declaration? alt name { some(nm) { @@ -369,7 +369,7 @@ fn visit_fn_with_scope(e: &@env, f: &ast::_fn, tp: &[ast::ty_param], cons(scope_fn(f.decl, f.proto, tp), @sc), v); } -fn visit_block_with_scope(b: &ast::blk, sc: &scopes, v: &vt<scopes>) { +fn visit_block_with_scope(b: ast::blk, sc: scopes, v: vt<scopes>) { let pos = @mutable 0u, loc = @mutable 0u; let block_sc = cons(scope_block(b, pos, loc), @sc); for stmt in b.node.stmts { @@ -380,7 +380,7 @@ fn visit_block_with_scope(b: &ast::blk, sc: &scopes, v: &vt<scopes>) { visit::visit_expr_opt(b.node.expr, block_sc, v); } -fn visit_decl_with_scope(d: &@decl, sc: &scopes, v: &vt<scopes>) { +fn visit_decl_with_scope(d: @decl, sc: scopes, v: vt<scopes>) { let loc_pos = alt list::car(sc) { scope_block(_, _, pos) { pos } @@ -394,14 +394,14 @@ fn visit_decl_with_scope(d: &@decl, sc: &scopes, v: &vt<scopes>) { } } -fn visit_arm_with_scope(a: &ast::arm, sc: &scopes, v: &vt<scopes>) { +fn visit_arm_with_scope(a: ast::arm, sc: scopes, v: vt<scopes>) { for p: @pat in a.pats { v.visit_pat(p, sc, v); } let sc_inner = cons(scope_arm(a), @sc); visit::visit_expr_opt(a.guard, sc_inner, v); v.visit_block(a.body, sc_inner, v); } -fn visit_expr_with_scope(x: &@ast::expr, sc: &scopes, v: &vt<scopes>) { +fn visit_expr_with_scope(x: @ast::expr, sc: scopes, v: vt<scopes>) { alt x.node { ast::expr_for(decl, coll, blk) | ast::expr_for_each(decl, coll, blk) { let f_e = alt x.node { expr_for_each(_, _, _) { true } _ { false } }; @@ -414,7 +414,7 @@ fn visit_expr_with_scope(x: &@ast::expr, sc: &scopes, v: &vt<scopes>) { } } -fn follow_import(e: &env, sc: &scopes, path: &[ident], sp: &span) -> +fn follow_import(e: env, sc: scopes, path: [ident], sp: span) -> option::t<def> { let path_len = vec::len(path); let dcur = lookup_in_scope_strict(e, sc, sp, path[0], ns_module); @@ -439,7 +439,7 @@ fn follow_import(e: &env, sc: &scopes, path: &[ident], sp: &span) -> } else { ret none; } } -fn resolve_constr(e: @env, c: &@ast::constr, sc: &scopes, _v: &vt<scopes>) { +fn resolve_constr(e: @env, c: @ast::constr, sc: scopes, _v: vt<scopes>) { let new_def = lookup_path_strict(*e, sc, c.span, c.node.path.node, ns_value); if option::is_some(new_def) { @@ -457,8 +457,8 @@ fn resolve_constr(e: @env, c: &@ast::constr, sc: &scopes, _v: &vt<scopes>) { } // Import resolution -fn resolve_import(e: &env, defid: ast::def_id, name: &ast::ident, - ids: &[ast::ident], sp: &codemap::span, sc_in: &scopes) { +fn resolve_import(e: env, defid: ast::def_id, name: ast::ident, + ids: [ast::ident], sp: codemap::span, sc_in: scopes) { e.imports.insert(defid.node, resolving(sp)); let n_idents = vec::len(ids); let end_id = ids[n_idents - 1u]; @@ -507,9 +507,9 @@ fn resolve_import(e: &env, defid: ast::def_id, name: &ast::ident, } } } - fn register(e: &env, defid: def_id, sp: &span, name: &ident, sc: &scopes, - val: &option::t<def>, typ: &option::t<def>, - md: &option::t<def>) { + fn register(e: env, defid: def_id, sp: span, name: ident, sc: scopes, + val: option::t<def>, typ: option::t<def>, + md: option::t<def>) { if is_none(val) && is_none(typ) && is_none(md) { unresolved_err(e, sc, sp, name, "import"); } else { e.imports.insert(defid.node, resolved(val, typ, md)); } @@ -539,7 +539,7 @@ fn ns_name(ns: namespace) -> str { } } -fn unresolved_err(e: &env, sc: &scopes, sp: &span, name: &ident, kind: &str) { +fn unresolved_err(e: env, sc: scopes, sp: span, name: ident, kind: str) { fn find_fn_or_mod_scope(sc: scopes) -> scope { while true { alt sc { @@ -564,16 +564,16 @@ fn unresolved_err(e: &env, sc: &scopes, sp: &span, name: &ident, kind: &str) { e.sess.span_err(sp, mk_unresolved_msg(name, kind)); } -fn unresolved_fatal(e: &env, sp: &span, id: &ident, kind: &str) -> ! { +fn unresolved_fatal(e: env, sp: span, id: ident, kind: str) -> ! { e.sess.span_fatal(sp, mk_unresolved_msg(id, kind)); } -fn mk_unresolved_msg(id: &ident, kind: &str) -> str { +fn mk_unresolved_msg(id: ident, kind: str) -> str { ret #fmt["unresolved %s: %s", kind, id]; } // Lookup helpers -fn lookup_path_strict(e: &env, sc: &scopes, sp: &span, pth: &ast::path_, +fn lookup_path_strict(e: env, sc: scopes, sp: span, pth: ast::path_, ns: namespace) -> option::t<def> { let n_idents = vec::len(pth.idents); let headns = if n_idents == 1u { ns } else { ns_module }; @@ -597,7 +597,7 @@ fn lookup_path_strict(e: &env, sc: &scopes, sp: &span, pth: &ast::path_, ret dcur; } -fn lookup_in_scope_strict(e: &env, sc: scopes, sp: &span, name: &ident, +fn lookup_in_scope_strict(e: env, sc: scopes, sp: span, name: ident, ns: namespace) -> option::t<def> { alt lookup_in_scope(e, sc, sp, name, ns) { none. { unresolved_err(e, sc, sp, name, ns_name(ns)); ret none; } @@ -605,7 +605,7 @@ fn lookup_in_scope_strict(e: &env, sc: scopes, sp: &span, name: &ident, } } -fn scope_is_fn(sc: &scope) -> bool { +fn scope_is_fn(sc: scope) -> bool { ret alt sc { scope_fn(_, ast::proto_iter., _) | scope_fn(_, ast::proto_fn., _) | scope_native_item(_) { @@ -615,7 +615,7 @@ fn scope_is_fn(sc: &scope) -> bool { }; } -fn scope_closes(sc: &scope) -> option::t<bool> { +fn scope_closes(sc: scope) -> option::t<bool> { alt sc { scope_fn(_, ast::proto_block., _) | scope_loop(_, true) { some(true) } scope_fn(_, ast::proto_closure., _) { some(false) } @@ -623,7 +623,7 @@ fn scope_closes(sc: &scope) -> option::t<bool> { } } -fn def_is_local(d: &def) -> bool { +fn def_is_local(d: def) -> bool { ret alt d { ast::def_arg(_, _) | ast::def_local(_) | ast::def_binding(_) | ast::def_upvar(_, _, _) { @@ -633,17 +633,17 @@ fn def_is_local(d: &def) -> bool { }; } -fn def_is_obj_field(d: &def) -> bool { +fn def_is_obj_field(d: def) -> bool { ret alt d { ast::def_obj_field(_, _) { true } _ { false } }; } -fn def_is_ty_arg(d: &def) -> bool { +fn def_is_ty_arg(d: def) -> bool { ret alt d { ast::def_ty_arg(_, _) { true } _ { false } }; } -fn lookup_in_scope(e: &env, sc: scopes, sp: &span, name: &ident, - ns: namespace) -> option::t<def> { - fn in_scope(e: &env, sp: &span, name: &ident, s: &scope, ns: namespace) -> +fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace) + -> option::t<def> { + fn in_scope(e: env, sp: span, name: ident, s: scope, ns: namespace) -> option::t<def> { alt s { scope_crate. { @@ -749,7 +749,7 @@ fn lookup_in_scope(e: &env, sc: scopes, sp: &span, name: &ident, } -fn lookup_in_ty_params(name: &ident, ty_params: &[ast::ty_param]) -> +fn lookup_in_ty_params(name: ident, ty_params: [ast::ty_param]) -> option::t<def> { let i = 0u; for tp: ast::ty_param in ty_params { @@ -759,7 +759,7 @@ fn lookup_in_ty_params(name: &ident, ty_params: &[ast::ty_param]) -> ret none::<def>; } -fn lookup_in_pat(name: &ident, pat: &@ast::pat) -> option::t<def_id> { +fn lookup_in_pat(name: ident, pat: @ast::pat) -> option::t<def_id> { let found = none; for each bound in ast_util::pat_bindings(pat) { let p_name = alt bound.node { ast::pat_bind(n) { n } }; @@ -768,9 +768,8 @@ fn lookup_in_pat(name: &ident, pat: &@ast::pat) -> option::t<def_id> { ret found; } -fn lookup_in_fn(name: &ident, decl: &ast::fn_decl, - ty_params: &[ast::ty_param], ns: namespace) -> - option::t<def> { +fn lookup_in_fn(name: ident, decl: ast::fn_decl, ty_params: [ast::ty_param], + ns: namespace) -> option::t<def> { alt ns { ns_value. { for a: ast::arg in decl.inputs { @@ -785,7 +784,7 @@ fn lookup_in_fn(name: &ident, decl: &ast::fn_decl, } } -fn lookup_in_obj(name: &ident, ob: &ast::_obj, ty_params: &[ast::ty_param], +fn lookup_in_obj(name: ident, ob: ast::_obj, ty_params: [ast::ty_param], ns: namespace) -> option::t<def> { alt ns { ns_value. { @@ -801,7 +800,7 @@ fn lookup_in_obj(name: &ident, ob: &ast::_obj, ty_params: &[ast::ty_param], } } -fn lookup_in_block(name: &ident, b: &ast::blk_, pos: uint, loc_pos: uint, +fn lookup_in_block(name: ident, b: ast::blk_, pos: uint, loc_pos: uint, ns: namespace) -> option::t<def> { let i = vec::len(b.stmts); while i > 0u { @@ -858,7 +857,7 @@ fn lookup_in_block(name: &ident, b: &ast::blk_, pos: uint, loc_pos: uint, ret none::<def>; } -fn found_def_item(i: &@ast::item, ns: namespace) -> option::t<def> { +fn found_def_item(i: @ast::item, ns: namespace) -> option::t<def> { alt i.node { ast::item_const(_, _) { if ns == ns_value { ret some(ast::def_const(local_def(i.id))); } @@ -903,7 +902,7 @@ fn found_def_item(i: &@ast::item, ns: namespace) -> option::t<def> { ret none::<def>; } -fn lookup_in_mod_strict(e: &env, sc: &scopes, m: def, sp: &span, name: &ident, +fn lookup_in_mod_strict(e: env, sc: scopes, m: def, sp: span, name: ident, ns: namespace, dr: dir) -> option::t<def> { alt lookup_in_mod(e, m, sp, name, ns, dr) { none. { unresolved_err(e, sc, sp, name, ns_name(ns)); ret none; } @@ -911,7 +910,7 @@ fn lookup_in_mod_strict(e: &env, sc: &scopes, m: def, sp: &span, name: &ident, } } -fn lookup_in_mod(e: &env, m: &def, sp: &span, name: &ident, ns: namespace, +fn lookup_in_mod(e: env, m: def, sp: span, name: ident, ns: namespace, dr: dir) -> option::t<def> { let defid = ast_util::def_id_of_def(m); if defid.crate != ast::local_crate { @@ -938,7 +937,7 @@ fn lookup_in_mod(e: &env, m: &def, sp: &span, name: &ident, ns: namespace, } } -fn found_view_item(e: &env, vi: @ast::view_item) -> option::t<def> { +fn found_view_item(e: env, vi: @ast::view_item) -> option::t<def> { alt vi.node { ast::view_item_use(_, _, id) { let cnum = cstore::get_use_stmt_cnum(e.cstore, id); @@ -947,7 +946,7 @@ fn found_view_item(e: &env, vi: @ast::view_item) -> option::t<def> { } } -fn lookup_import(e: &env, defid: def_id, ns: namespace) -> option::t<def> { +fn lookup_import(e: env, defid: def_id, ns: namespace) -> option::t<def> { alt e.imports.get(defid.node) { todo(node_id, name, path, span, scopes) { resolve_import(e, local_def(node_id), name, path, span, scopes); @@ -960,12 +959,12 @@ fn lookup_import(e: &env, defid: def_id, ns: namespace) -> option::t<def> { } } -fn lookup_in_local_native_mod(e: &env, node_id: node_id, sp: &span, - id: &ident, ns: namespace) -> option::t<def> { +fn lookup_in_local_native_mod(e: env, node_id: node_id, sp: span, id: ident, + ns: namespace) -> option::t<def> { ret lookup_in_local_mod(e, node_id, sp, id, ns, inside); } -fn lookup_in_local_mod(e: &env, node_id: node_id, sp: &span, id: &ident, +fn lookup_in_local_mod(e: env, node_id: node_id, sp: span, id: ident, ns: namespace, dr: dir) -> option::t<def> { let info = e.mod_map.get(node_id); if dr == outside && !ast_util::is_exported(id, option::get(info.m)) { @@ -993,14 +992,13 @@ fn lookup_in_local_mod(e: &env, node_id: node_id, sp: &span, id: &ident, ret lookup_glob_in_mod(e, info, sp, id, ns, outside); } -fn lookup_glob_in_mod(e: &env, info: @indexed_mod, sp: &span, id: &ident, +fn lookup_glob_in_mod(e: env, info: @indexed_mod, sp: span, id: ident, wanted_ns: namespace, dr: dir) -> option::t<def> { - fn per_ns(e: &env, info: @indexed_mod, sp: &span, id: &ident, - ns: namespace, dr: dir) -> option::t<def> { + fn per_ns(e: env, info: @indexed_mod, sp: span, id: ident, ns: namespace, + dr: dir) -> option::t<def> { - fn lookup_in_mod_(e: &env, def: &glob_imp_def, sp: &span, - name: &ident, ns: namespace, dr: dir) -> - option::t<glob_imp_def> { + fn lookup_in_mod_(e: env, def: glob_imp_def, sp: span, name: ident, + ns: namespace, dr: dir) -> option::t<glob_imp_def> { alt lookup_in_mod(e, def.def, sp, name, ns, dr) { option::some(d) { option::some({def: d, item: def.item}) } option::none. { option::none } @@ -1050,7 +1048,7 @@ fn lookup_glob_in_mod(e: &env, info: @indexed_mod, sp: &span, id: &ident, } } -fn lookup_in_mie(e: &env, mie: &mod_index_entry, ns: namespace) -> +fn lookup_in_mie(e: env, mie: mod_index_entry, ns: namespace) -> option::t<def> { alt mie { mie_view_item(view_item) { @@ -1089,15 +1087,15 @@ fn lookup_in_mie(e: &env, mie: &mod_index_entry, ns: namespace) -> // Module indexing -fn add_to_index(index: &hashmap<ident, list<mod_index_entry>>, id: &ident, - ent: &mod_index_entry) { +fn add_to_index(index: hashmap<ident, list<mod_index_entry>>, id: ident, + ent: mod_index_entry) { alt index.find(id) { none. { index.insert(id, cons(ent, @nil::<mod_index_entry>)); } some(prev) { index.insert(id, cons(ent, @prev)); } } } -fn index_mod(md: &ast::_mod) -> mod_index { +fn index_mod(md: ast::_mod) -> mod_index { let index = new_str_hash::<list<mod_index_entry>>(); for it: @ast::view_item in md.view_items { alt it.node { @@ -1107,12 +1105,14 @@ fn index_mod(md: &ast::_mod) -> mod_index { + ast::view_item_import(ident, _, id) { add_to_index(index, ident, mie_import_ident(id, it.span)); } + ast::view_item_import_from(_, idents, _) { for ident in idents { add_to_index(index, ident.node.name, @@ -1122,6 +1122,7 @@ fn index_mod(md: &ast::_mod) -> mod_index { + //globbed imports have to be resolved lazily. ast::view_item_import_glob(_, _) | ast::view_item_export(_, _) { } @@ -1148,7 +1149,7 @@ fn index_mod(md: &ast::_mod) -> mod_index { ret index; } -fn index_nmod(md: &ast::native_mod) -> mod_index { +fn index_nmod(md: ast::native_mod) -> mod_index { let index = new_str_hash::<list<mod_index_entry>>(); for it: @ast::view_item in md.view_items { alt it.node { @@ -1194,7 +1195,7 @@ fn ns_for_def(d: def) -> namespace { }; } -fn lookup_external(e: &env, cnum: int, ids: &[ident], ns: namespace) -> +fn lookup_external(e: env, cnum: int, ids: [ident], ns: namespace) -> option::t<def> { for d: def in csearch::lookup_defs(e.sess.get_cstore(), cnum, ids) { e.ext_map.insert(ast_util::def_id_of_def(d), ids); @@ -1205,7 +1206,7 @@ fn lookup_external(e: &env, cnum: int, ids: &[ident], ns: namespace) -> // Collision detection -fn check_for_collisions(e: &@env, c: &ast::crate) { +fn check_for_collisions(e: @env, c: ast::crate) { // Module indices make checking those relatively simple -- just check each // name for multiple entities in the same namespace. for each m: @{key: ast::node_id, val: @indexed_mod} in e.mod_map.items() { @@ -1224,11 +1225,11 @@ fn check_for_collisions(e: &@env, c: &ast::crate) { visit::visit_crate(c, (), visit::mk_vt(v)); } -fn check_mod_name(e: &env, name: &ident, entries: list<mod_index_entry>) { +fn check_mod_name(e: env, name: ident, entries: list<mod_index_entry>) { let saw_mod = false; let saw_type = false; let saw_value = false; - fn dup(e: &env, sp: &span, word: &str, name: &ident) { + fn dup(e: env, sp: span, word: str, name: ident) { e.sess.span_fatal(sp, "duplicate definition of " + word + name); } while true { @@ -1256,7 +1257,7 @@ fn check_mod_name(e: &env, name: &ident, entries: list<mod_index_entry>) { } } -fn mie_span(mie: &mod_index_entry) -> span { +fn mie_span(mie: mod_index_entry) -> span { ret alt mie { mie_view_item(item) { item.span } mie_import_ident(_, span) { span } @@ -1266,8 +1267,8 @@ fn mie_span(mie: &mod_index_entry) -> span { }; } -fn check_item(e: &@env, i: &@ast::item, x: &(), v: &vt<()>) { - fn typaram_names(tps: &[ast::ty_param]) -> [ident] { +fn check_item(e: @env, i: @ast::item, x: (), v: vt<()>) { + fn typaram_names(tps: [ast::ty_param]) -> [ident] { let x: [ast::ident] = []; for tp: ast::ty_param in tps { x += [tp.ident] } ret x; @@ -1280,7 +1281,7 @@ fn check_item(e: &@env, i: &@ast::item, x: &(), v: &vt<()>) { "type parameter"); } ast::item_obj(ob, ty_params, _) { - fn field_name(field: &ast::obj_field) -> ident { ret field.ident; } + fn field_name(field: ast::obj_field) -> ident { ret field.ident; } ensure_unique(*e, i.span, ob.fields, field_name, "object field"); for m: @ast::method in ob.methods { check_fn(*e, m.span, m.node.meth); @@ -1296,14 +1297,14 @@ fn check_item(e: &@env, i: &@ast::item, x: &(), v: &vt<()>) { } } -fn check_pat(ch: checker, p: &@ast::pat) { +fn check_pat(ch: checker, p: @ast::pat) { for each p in ast_util::pat_bindings(p) { let ident = alt p.node { pat_bind(n) { n } }; add_name(ch, p.span, ident); } } -fn check_arm(e: &@env, a: &ast::arm, x: &(), v: &vt<()>) { +fn check_arm(e: @env, a: ast::arm, x: (), v: vt<()>) { visit::visit_arm(a, x, v); let ch0 = checker(*e, "binding"); check_pat(ch0, a.pats[0]); @@ -1333,7 +1334,7 @@ fn check_arm(e: &@env, a: &ast::arm, x: &(), v: &vt<()>) { } } -fn check_block(e: &@env, b: &ast::blk, x: &(), v: &vt<()>) { +fn check_block(e: @env, b: ast::blk, x: (), v: vt<()>) { visit::visit_block(b, x, v); let values = checker(*e, "value"); let types = checker(*e, "type"); @@ -1381,15 +1382,15 @@ fn check_block(e: &@env, b: &ast::blk, x: &(), v: &vt<()>) { } } -fn check_fn(e: &env, sp: &span, f: &ast::_fn) { - fn arg_name(a: &ast::arg) -> ident { ret a.ident; } +fn check_fn(e: env, sp: span, f: ast::_fn) { + fn arg_name(a: ast::arg) -> ident { ret a.ident; } ensure_unique(e, sp, f.decl.inputs, arg_name, "argument"); } -fn check_expr(e: &@env, ex: &@ast::expr, x: &(), v: &vt<()>) { +fn check_expr(e: @env, ex: @ast::expr, x: (), v: vt<()>) { alt ex.node { ast::expr_rec(fields, _) { - fn field_name(f: &ast::field) -> ident { ret f.node.ident; } + fn field_name(f: ast::field) -> ident { ret f.node.ident; } ensure_unique(*e, ex.span, fields, field_name, "field"); } _ { } @@ -1397,10 +1398,10 @@ fn check_expr(e: &@env, ex: &@ast::expr, x: &(), v: &vt<()>) { visit::visit_expr(ex, x, v); } -fn check_ty(e: &@env, ty: &@ast::ty, x: &(), v: &vt<()>) { +fn check_ty(e: @env, ty: @ast::ty, x: (), v: vt<()>) { alt ty.node { ast::ty_rec(fields) { - fn field_name(f: &ast::ty_field) -> ident { ret f.node.ident; } + fn field_name(f: ast::ty_field) -> ident { ret f.node.ident; } ensure_unique(*e, ty.span, fields, field_name, "field"); } _ { } @@ -1410,34 +1411,34 @@ fn check_ty(e: &@env, ty: &@ast::ty, x: &(), v: &vt<()>) { type checker = @{mutable seen: [ident], kind: str, sess: session}; -fn checker(e: &env, kind: &str) -> checker { +fn checker(e: env, kind: str) -> checker { let seen: [ident] = []; ret @{mutable seen: seen, kind: kind, sess: e.sess}; } -fn check_name(ch: &checker, sp: &span, name: &ident) { +fn check_name(ch: checker, sp: span, name: ident) { for s: ident in ch.seen { if str::eq(s, name) { ch.sess.span_fatal(sp, "duplicate " + ch.kind + " name: " + name); } } } -fn add_name(ch: &checker, sp: &span, name: &ident) { +fn add_name(ch: checker, sp: span, name: ident) { check_name(ch, sp, name); 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) { +fn ensure_unique<T>(e: env, sp: span, elts: [T], id: fn(T) -> ident, + kind: str) { let ch = checker(e, kind); for elt: T in elts { add_name(ch, sp, id(elt)); } } -fn check_bad_exports(e: &@env) { - fn lookup_glob_any(e: &env, info: &@indexed_mod, sp: &span, ident: &ident) - -> bool { +fn check_bad_exports(e: @env) { + fn lookup_glob_any(e: env, info: @indexed_mod, sp: span, ident: ident) -> + bool { ret !option::is_none(lookup_glob_in_mod(e, info, sp, ident, ns_module, inside)) || !option::is_none(lookup_glob_in_mod(e, info, sp, ident, diff --git a/src/comp/middle/shape.rs b/src/comp/middle/shape.rs index 080018df961..01c0e059b14 100644 --- a/src/comp/middle/shape.rs +++ b/src/comp/middle/shape.rs @@ -69,7 +69,7 @@ const shape_uniq: u8 = 22u8; // FIXME: This is a bad API in trans_common. fn C_u8(n: u8) -> ValueRef { ret trans_common::C_u8(n as uint); } -fn hash_res_info(ri: &res_info) -> uint { +fn hash_res_info(ri: res_info) -> uint { let h = 5381u; h *= 33u; h += ri.did.crate as uint; @@ -80,12 +80,12 @@ fn hash_res_info(ri: &res_info) -> uint { ret h; } -fn eq_res_info(a: &res_info, b: &res_info) -> bool { +fn eq_res_info(a: res_info, b: res_info) -> bool { ret a.did.crate == b.did.crate && a.did.node == b.did.node && a.t == b.t; } -fn mk_global(ccx: &@crate_ctxt, name: &str, llval: ValueRef, internal: bool) - -> ValueRef { +fn mk_global(ccx: @crate_ctxt, name: str, llval: ValueRef, internal: bool) -> + ValueRef { let llglobal = str::as_buf(name, {|buf| @@ -111,7 +111,7 @@ fn mk_global(ccx: &@crate_ctxt, name: &str, llval: ValueRef, internal: bool) // // TODO: Use this in dynamic_size_of() as well. -fn largest_variants(ccx: &@crate_ctxt, tag_id: &ast::def_id) -> [uint] { +fn largest_variants(ccx: @crate_ctxt, tag_id: ast::def_id) -> [uint] { // Compute the minimum and maximum size and alignment for each variant. // // TODO: We could do better here; e.g. we know that any variant that @@ -133,7 +133,7 @@ fn largest_variants(ccx: &@crate_ctxt, tag_id: &ast::def_id) -> [uint] { // follow from how elem_t doesn't contain params. // (Could add a postcondition to type_contains_params, // once we implement Issue #586.) - check trans_common::type_has_static_size(ccx, elem_t); + check (trans_common::type_has_static_size(ccx, elem_t)); let llty = trans::type_of(ccx, dummy_sp(), elem_t); min_size += trans::llsize_of_real(ccx, llty); min_align += trans::llalign_of_real(ccx, llty); @@ -200,8 +200,8 @@ fn round_up(size: u16, align: u8) -> u16 { type size_align = {size: u16, align: u8}; -fn compute_static_tag_size(ccx: &@crate_ctxt, largest_variants: &[uint], - did: &ast::def_id) -> size_align { +fn compute_static_tag_size(ccx: @crate_ctxt, largest_variants: [uint], + did: ast::def_id) -> size_align { let max_size = 0u16; let max_align = 1u8; let variants = ty::tag_variants(ccx.tcx, did); @@ -212,7 +212,7 @@ fn compute_static_tag_size(ccx: &@crate_ctxt, largest_variants: &[uint], // FIXME: there should really be a postcondition // on tag_variants that would obviate the need for // this check. (Issue #586) - check trans_common::type_has_static_size(ccx, typ); + check (trans_common::type_has_static_size(ccx, typ)); lltys += [trans::type_of(ccx, dummy_sp(), typ)]; } @@ -234,7 +234,7 @@ fn compute_static_tag_size(ccx: &@crate_ctxt, largest_variants: &[uint], tag tag_kind { tk_unit; tk_enum; tk_complex; } -fn tag_kind(ccx: &@crate_ctxt, did: &ast::def_id) -> tag_kind { +fn tag_kind(ccx: @crate_ctxt, did: ast::def_id) -> tag_kind { let variants = ty::tag_variants(ccx.tcx, did); if vec::len(variants) == 0u { ret tk_complex; } for v: ty::variant_info in variants { @@ -246,15 +246,15 @@ fn tag_kind(ccx: &@crate_ctxt, did: &ast::def_id) -> tag_kind { // Returns the code corresponding to the pointer size on this architecture. -fn s_int(_tcx: &ty_ctxt) -> u8 { +fn s_int(_tcx: ty_ctxt) -> u8 { ret shape_i32; // TODO: x86-64 } -fn s_uint(_tcx: &ty_ctxt) -> u8 { +fn s_uint(_tcx: ty_ctxt) -> u8 { ret shape_u32; // TODO: x86-64 } -fn s_float(_tcx: &ty_ctxt) -> u8 { +fn s_float(_tcx: ty_ctxt) -> u8 { ret shape_f64; // TODO: x86-64 } @@ -284,12 +284,12 @@ fn add_u16(dest: &mutable [u8], val: u16) { dest += [val & 0xffu16 as u8, val >> 8u16 as u8]; } -fn add_substr(dest: &mutable [u8], src: &[u8]) { +fn add_substr(dest: &mutable [u8], src: [u8]) { add_u16(dest, vec::len(src) as u16); dest += src; } -fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] { +fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint]) -> [u8] { let s = []; alt ty::struct(ccx.tcx, t) { @@ -299,6 +299,7 @@ fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] { + ty::ty_int. { s += [s_int(ccx.tcx)]; } @@ -306,12 +307,14 @@ fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] { + ty::ty_uint. | ty::ty_ptr(_) | ty::ty_type. | ty::ty_native(_) { s += [s_uint(ccx.tcx)]; } + ty::ty_machine(ast::ty_i8.) { s += [shape_i8]; } @@ -324,6 +327,7 @@ fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] { + ty::ty_str. { s += [shape_vec]; add_bool(s, true); // type is POD @@ -332,6 +336,7 @@ fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] { } + ty::ty_tag(did, tps) { alt tag_kind(ccx, did) { tk_unit. { @@ -370,6 +375,7 @@ fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] { + ty::ty_box(mt) { s += [shape_box]; add_substr(s, shape_of(ccx, mt.ty, ty_param_map)); @@ -400,6 +406,7 @@ fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] { + ty::ty_fn(_, _, _, _, _) { s += [shape_fn]; } @@ -408,6 +415,7 @@ fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] { + ty::ty_res(did, raw_subt, tps) { let subt = ty::substitute_type_params(ccx.tcx, tps, raw_subt); let ri = {did: did, t: subt}; @@ -424,11 +432,13 @@ fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] { } + ty::ty_var(n) { fail "shape_of ty_var"; } + ty::ty_param(n, _) { // Find the type parameter in the parameter list. let found = false; @@ -449,7 +459,7 @@ fn shape_of(ccx: &@crate_ctxt, t: ty::t, ty_param_map: &[uint]) -> [u8] { } // FIXME: We might discover other variants as we traverse these. Handle this. -fn shape_of_variant(ccx: &@crate_ctxt, v: &ty::variant_info, +fn shape_of_variant(ccx: @crate_ctxt, v: ty::variant_info, ty_param_count: uint) -> [u8] { let ty_param_map = []; let i = 0u; @@ -460,7 +470,7 @@ fn shape_of_variant(ccx: &@crate_ctxt, v: &ty::variant_info, ret s; } -fn gen_tag_shapes(ccx: &@crate_ctxt) -> ValueRef { +fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef { // Loop over all the tag variants and write their shapes into a data // buffer. As we do this, it's possible for us to discover new tags, so we // must do this first. @@ -555,7 +565,7 @@ fn gen_tag_shapes(ccx: &@crate_ctxt) -> ValueRef { ret mk_global(ccx, "tag_shapes", C_bytes(header), true); } -fn gen_resource_shapes(ccx: &@crate_ctxt) -> ValueRef { +fn gen_resource_shapes(ccx: @crate_ctxt) -> ValueRef { let dtors = []; let i = 0u; let len = interner::len(ccx.shape_cx.resources); @@ -568,7 +578,7 @@ fn gen_resource_shapes(ccx: &@crate_ctxt) -> ValueRef { ret mk_global(ccx, "resource_shapes", C_struct(dtors), true); } -fn gen_shape_tables(ccx: &@crate_ctxt) { +fn gen_shape_tables(ccx: @crate_ctxt) { let lltagstable = gen_tag_shapes(ccx); let llresourcestable = gen_resource_shapes(ccx); trans_common::set_struct_body(ccx.shape_cx.llshapetablesty, diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 3d0cd917f53..d91e17fc215 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -74,15 +74,15 @@ import trans_objects::trans_anon_obj; import trans_objects::trans_obj; import tvec = trans_vec; -fn type_of(cx: &@crate_ctxt, sp: &span, t: ty::t) - : type_has_static_size(cx, t) -> TypeRef { type_of_inner(cx, sp, t) } +fn type_of(cx: @crate_ctxt, sp: span, t: ty::t) : type_has_static_size(cx, t) + -> TypeRef { + type_of_inner(cx, sp, t) +} -fn type_of_explicit_args(cx: &@crate_ctxt, sp: &span, inputs: &[ty::arg]) -> +fn type_of_explicit_args(cx: @crate_ctxt, sp: span, inputs: [ty::arg]) -> [TypeRef] { let atys = []; - for arg in inputs { - atys += [T_ptr(type_of_inner(cx, sp, arg.ty))]; - } + for arg in inputs { atys += [T_ptr(type_of_inner(cx, sp, arg.ty))]; } ret atys; } @@ -93,8 +93,8 @@ fn type_of_explicit_args(cx: &@crate_ctxt, sp: &span, inputs: &[ty::arg]) -> // - create_llargs_for_fn_args. // - new_fn_ctxt // - trans_args -fn type_of_fn_full(cx: &@crate_ctxt, sp: &span, proto: ast::proto, - is_method: bool, inputs: &[ty::arg], output: ty::t, +fn type_of_fn_full(cx: @crate_ctxt, sp: span, proto: ast::proto, + is_method: bool, inputs: [ty::arg], output: ty::t, ty_param_count: uint) -> TypeRef { let atys: [TypeRef] = []; @@ -125,22 +125,21 @@ fn type_of_fn_full(cx: &@crate_ctxt, sp: &span, proto: ast::proto, ret T_fn(atys, llvm::LLVMVoidType()); } -fn type_of_fn(cx: &@crate_ctxt, sp: &span, proto: ast::proto, - inputs: &[ty::arg], output: ty::t, ty_param_count: uint) -> - TypeRef { +fn type_of_fn(cx: @crate_ctxt, sp: span, proto: ast::proto, inputs: [ty::arg], + output: ty::t, ty_param_count: uint) -> TypeRef { ret type_of_fn_full(cx, sp, proto, false, inputs, output, ty_param_count); } // Given a function type and a count of ty params, construct an llvm type -fn type_of_fn_from_ty(cx: &@crate_ctxt, sp: &span, fty: ty::t, +fn type_of_fn_from_ty(cx: @crate_ctxt, sp: span, fty: ty::t, ty_param_count: uint) -> TypeRef { ret type_of_fn(cx, sp, ty::ty_fn_proto(cx.tcx, fty), ty::ty_fn_args(cx.tcx, fty), ty::ty_fn_ret(cx.tcx, fty), ty_param_count); } -fn type_of_native_fn(cx: &@crate_ctxt, sp: &span, abi: ast::native_abi, - inputs: &[ty::arg], output: ty::t, ty_param_count: uint) +fn type_of_native_fn(cx: @crate_ctxt, sp: span, abi: ast::native_abi, + inputs: [ty::arg], output: ty::t, ty_param_count: uint) -> TypeRef { let atys: [TypeRef] = []; if abi == ast::native_abi_rust { @@ -154,7 +153,7 @@ fn type_of_native_fn(cx: &@crate_ctxt, sp: &span, abi: ast::native_abi, /* FIXME: could add type_has_static_size as a constraint, allowing us to get rid of some impossible cases. */ -fn type_of_inner(cx: &@crate_ctxt, sp: &span, t: ty::t) -> TypeRef { +fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t) -> TypeRef { // Check the cache. if cx.lltypes.contains_key(t) { ret cx.lltypes.get(t); } @@ -230,7 +229,7 @@ fn type_of_inner(cx: &@crate_ctxt, sp: &span, t: ty::t) -> TypeRef { ret llty; } -fn type_of_tag(cx: &@crate_ctxt, sp: &span, did: &ast::def_id, t: ty::t) -> +fn type_of_tag(cx: @crate_ctxt, sp: span, did: ast::def_id, t: ty::t) -> TypeRef { let degen = std::vec::len(ty::tag_variants(cx.tcx, did)) == 1u; if ty::type_has_dynamic_size(cx.tcx, t) { @@ -244,14 +243,13 @@ fn type_of_tag(cx: &@crate_ctxt, sp: &span, did: &ast::def_id, t: ty::t) -> } } -fn type_of_ty_param_kinds_and_ty(lcx: @local_ctxt, sp: &span, - tpt: &ty::ty_param_kinds_and_ty) -> TypeRef { +fn type_of_ty_param_kinds_and_ty(lcx: @local_ctxt, sp: span, + tpt: ty::ty_param_kinds_and_ty) -> TypeRef { let cx = lcx.ccx; let t = tpt.ty; alt ty::struct(cx.tcx, t) { ty::ty_fn(_, _, _, _, _) { - let llfnty = - type_of_fn_from_ty(cx, sp, t, std::vec::len(tpt.kinds)); + let llfnty = type_of_fn_from_ty(cx, sp, t, std::vec::len(tpt.kinds)); ret T_fn_pair(*cx, llfnty); } _ { @@ -261,23 +259,22 @@ fn type_of_ty_param_kinds_and_ty(lcx: @local_ctxt, sp: &span, // FIXME: could have a precondition on tpt, but that // doesn't work right now because one predicate can't imply // another - check type_has_static_size(cx, t); + check (type_has_static_size(cx, t)); type_of(cx, sp, t) } -fn type_of_or_i8(bcx: &@block_ctxt, typ: ty::t) -> TypeRef { +fn type_of_or_i8(bcx: @block_ctxt, typ: ty::t) -> TypeRef { let ccx = bcx_ccx(bcx); if check type_has_static_size(ccx, typ) { let sp = bcx.sp; type_of(ccx, sp, typ) - } - else { T_i8() } - } + } else { T_i8() } +} // Name sanitation. LLVM will happily accept identifiers with weird names, but // gas doesn't! -fn sanitize(s: &str) -> str { +fn sanitize(s: str) -> str { let result = ""; for c: u8 in s { if c == '@' as u8 { @@ -303,8 +300,8 @@ fn sanitize(s: &str) -> str { } -fn log_fn_time(ccx: &@crate_ctxt, name: &str, start: &time::timeval, - end: &time::timeval) { +fn log_fn_time(ccx: @crate_ctxt, name: str, start: time::timeval, + end: time::timeval) { let elapsed = 1000 * (end.sec - start.sec as int) + ((end.usec as int) - (start.usec as int)) / 1000; @@ -312,19 +309,18 @@ fn log_fn_time(ccx: &@crate_ctxt, name: &str, start: &time::timeval, } -fn decl_fn(llmod: ModuleRef, name: &str, cc: uint, llty: TypeRef) -> - ValueRef { +fn decl_fn(llmod: ModuleRef, name: str, cc: uint, llty: TypeRef) -> ValueRef { let llfn: ValueRef = str::as_buf(name, {|buf| llvm::LLVMAddFunction(llmod, buf, llty) }); llvm::LLVMSetFunctionCallConv(llfn, cc); ret llfn; } -fn decl_cdecl_fn(llmod: ModuleRef, name: &str, llty: TypeRef) -> ValueRef { +fn decl_cdecl_fn(llmod: ModuleRef, name: str, llty: TypeRef) -> ValueRef { ret decl_fn(llmod, name, lib::llvm::LLVMCCallConv, llty); } -fn decl_fastcall_fn(llmod: ModuleRef, name: &str, llty: TypeRef) -> ValueRef { +fn decl_fastcall_fn(llmod: ModuleRef, name: str, llty: TypeRef) -> ValueRef { let llfn = decl_fn(llmod, name, lib::llvm::LLVMFastCallConv, llty); let _: () = str::as_buf("rust", {|buf| llvm::LLVMSetGC(llfn, buf) }); ret llfn; @@ -333,7 +329,7 @@ fn decl_fastcall_fn(llmod: ModuleRef, name: &str, llty: TypeRef) -> ValueRef { // Only use this if you are going to actually define the function. It's // not valid to simply declare a function as internal. -fn decl_internal_fastcall_fn(llmod: ModuleRef, name: &str, llty: TypeRef) -> +fn decl_internal_fastcall_fn(llmod: ModuleRef, name: str, llty: TypeRef) -> ValueRef { let llfn = decl_fn(llmod, name, lib::llvm::LLVMFastCallConv, llty); llvm::LLVMSetLinkage(llfn, @@ -342,36 +338,36 @@ fn decl_internal_fastcall_fn(llmod: ModuleRef, name: &str, llty: TypeRef) -> ret llfn; } -fn decl_glue(llmod: ModuleRef, cx: &crate_ctxt, s: &str) -> ValueRef { +fn decl_glue(llmod: ModuleRef, cx: crate_ctxt, s: str) -> ValueRef { ret decl_cdecl_fn(llmod, s, T_fn([T_taskptr(cx)], T_void())); } -fn get_extern_fn(externs: &hashmap<str, ValueRef>, llmod: ModuleRef, - name: &str, cc: uint, ty: TypeRef) -> ValueRef { +fn get_extern_fn(externs: hashmap<str, ValueRef>, llmod: ModuleRef, name: str, + cc: uint, ty: TypeRef) -> ValueRef { if externs.contains_key(name) { ret externs.get(name); } let f = decl_fn(llmod, name, cc, ty); externs.insert(name, f); ret f; } -fn get_extern_const(externs: &hashmap<str, ValueRef>, llmod: ModuleRef, - name: &str, ty: TypeRef) -> ValueRef { +fn get_extern_const(externs: hashmap<str, ValueRef>, llmod: ModuleRef, + name: str, ty: TypeRef) -> ValueRef { if externs.contains_key(name) { ret externs.get(name); } let c = str::as_buf(name, {|buf| llvm::LLVMAddGlobal(llmod, ty, buf) }); externs.insert(name, c); ret c; } -fn get_simple_extern_fn(externs: &hashmap<str, ValueRef>, llmod: ModuleRef, - name: &str, n_args: int) -> ValueRef { +fn get_simple_extern_fn(externs: hashmap<str, ValueRef>, llmod: ModuleRef, + name: str, n_args: int) -> ValueRef { let inputs = std::vec::init_elt::<TypeRef>(T_int(), n_args as uint); let output = T_int(); let t = T_fn(inputs, output); ret get_extern_fn(externs, llmod, name, lib::llvm::LLVMCCallConv, t); } -fn trans_native_call(cx: &@block_ctxt, externs: &hashmap<str, ValueRef>, - llmod: ModuleRef, name: &str, args: &[ValueRef]) -> +fn trans_native_call(cx: @block_ctxt, externs: hashmap<str, ValueRef>, + llmod: ModuleRef, name: str, args: [ValueRef]) -> ValueRef { let n: int = std::vec::len::<ValueRef>(args) as int; let llnative: ValueRef = get_simple_extern_fn(externs, llmod, name, n); @@ -380,29 +376,29 @@ fn trans_native_call(cx: &@block_ctxt, externs: &hashmap<str, ValueRef>, ret Call(cx, llnative, call_args); } -fn trans_non_gc_free(cx: &@block_ctxt, v: ValueRef) -> @block_ctxt { +fn trans_non_gc_free(cx: @block_ctxt, v: ValueRef) -> @block_ctxt { Call(cx, bcx_ccx(cx).upcalls.free, [cx.fcx.lltaskptr, PointerCast(cx, v, T_ptr(T_i8())), C_int(0)]); ret cx; } -fn trans_shared_free(cx: &@block_ctxt, v: ValueRef) -> @block_ctxt { +fn trans_shared_free(cx: @block_ctxt, v: ValueRef) -> @block_ctxt { Call(cx, bcx_ccx(cx).upcalls.shared_free, [cx.fcx.lltaskptr, PointerCast(cx, v, T_ptr(T_i8()))]); ret cx; } -fn umax(cx: &@block_ctxt, a: ValueRef, b: ValueRef) -> ValueRef { +fn umax(cx: @block_ctxt, a: ValueRef, b: ValueRef) -> ValueRef { let cond = ICmp(cx, lib::llvm::LLVMIntULT, a, b); ret Select(cx, cond, b, a); } -fn umin(cx: &@block_ctxt, a: ValueRef, b: ValueRef) -> ValueRef { +fn umin(cx: @block_ctxt, a: ValueRef, b: ValueRef) -> ValueRef { let cond = ICmp(cx, lib::llvm::LLVMIntULT, a, b); ret Select(cx, cond, a, b); } -fn align_to(cx: &@block_ctxt, off: ValueRef, align: ValueRef) -> ValueRef { +fn align_to(cx: @block_ctxt, off: ValueRef, align: ValueRef) -> ValueRef { let mask = Sub(cx, align, C_int(1)); let bumped = Add(cx, off, mask); ret And(cx, bumped, Not(cx, mask)); @@ -410,12 +406,12 @@ fn align_to(cx: &@block_ctxt, off: ValueRef, align: ValueRef) -> ValueRef { // Returns the real size of the given type for the current target. -fn llsize_of_real(cx: &@crate_ctxt, t: TypeRef) -> uint { +fn llsize_of_real(cx: @crate_ctxt, t: TypeRef) -> uint { ret llvm::LLVMStoreSizeOfType(cx.td.lltd, t); } // Returns the real alignment of the given type for the current target. -fn llalign_of_real(cx: &@crate_ctxt, t: TypeRef) -> uint { +fn llalign_of_real(cx: @crate_ctxt, t: TypeRef) -> uint { ret llvm::LLVMPreferredAlignmentOfType(cx.td.lltd, t); } @@ -429,33 +425,27 @@ fn llalign_of(t: TypeRef) -> ValueRef { False); } -fn size_of(cx: &@block_ctxt, t: ty::t) -> result { +fn size_of(cx: @block_ctxt, t: ty::t) -> result { let ccx = bcx_ccx(cx); if check type_has_static_size(ccx, t) { let sp = cx.sp; rslt(cx, llsize_of(type_of(ccx, sp, t))) - } - else { - dynamic_size_of(cx, t) - } + } else { dynamic_size_of(cx, t) } } -fn align_of(cx: &@block_ctxt, t: ty::t) -> result { +fn align_of(cx: @block_ctxt, t: ty::t) -> result { let ccx = bcx_ccx(cx); if check type_has_static_size(ccx, t) { let sp = cx.sp; rslt(cx, llalign_of(type_of(ccx, sp, t))) - } - else { - dynamic_align_of(cx, t) - } + } else { dynamic_align_of(cx, t) } } -fn alloca(cx: &@block_ctxt, t: TypeRef) -> ValueRef { +fn alloca(cx: @block_ctxt, t: TypeRef) -> ValueRef { ret Alloca(new_raw_block_ctxt(cx.fcx, cx.fcx.llstaticallocas), t); } -fn dynastack_alloca(cx: &@block_ctxt, t: TypeRef, n: ValueRef, ty: ty::t) -> +fn dynastack_alloca(cx: @block_ctxt, t: TypeRef, n: ValueRef, ty: ty::t) -> ValueRef { let bcx = cx; let dy_cx = new_raw_block_ctxt(cx.fcx, cx.fcx.lldynamicallocas); @@ -478,7 +468,7 @@ fn dynastack_alloca(cx: &@block_ctxt, t: TypeRef, n: ValueRef, ty: ty::t) -> ret PointerCast(dy_cx, llresult, T_ptr(t)); } -fn mk_obstack_token(ccx: &@crate_ctxt, fcx: @fn_ctxt, lltaskptr: ValueRef) -> +fn mk_obstack_token(ccx: @crate_ctxt, fcx: @fn_ctxt, lltaskptr: ValueRef) -> ValueRef { let cx = new_raw_block_ctxt(fcx, fcx.lldynamicallocas); ret Call(cx, ccx.upcalls.dynastack_mark, [lltaskptr]); @@ -489,7 +479,7 @@ fn mk_obstack_token(ccx: &@crate_ctxt, fcx: @fn_ctxt, lltaskptr: ValueRef) -> // to have (a) the same size as the type that was passed in; (b) to be non- // recursive. This is done by replacing all boxes in a type with boxed unit // types. -fn simplify_type(ccx: &@crate_ctxt, typ: ty::t) -> ty::t { +fn simplify_type(ccx: @crate_ctxt, typ: ty::t) -> ty::t { fn simplifier(ccx: @crate_ctxt, typ: ty::t) -> ty::t { alt ty::struct(ccx.tcx, typ) { ty::ty_box(_) { ret ty::mk_imm_box(ccx.tcx, ty::mk_nil(ccx.tcx)); } @@ -517,7 +507,7 @@ fn simplify_type(ccx: &@crate_ctxt, typ: ty::t) -> ty::t { // Computes the size of the data part of a non-dynamically-sized tag. -fn static_size_of_tag(cx: &@crate_ctxt, sp: &span, t: ty::t) -> uint { +fn static_size_of_tag(cx: @crate_ctxt, sp: span, t: ty::t) -> uint { if ty::type_has_dynamic_size(cx.tcx, t) { cx.tcx.sess.span_fatal(sp, "dynamically sized type passed to \ @@ -540,7 +530,7 @@ fn static_size_of_tag(cx: &@crate_ctxt, sp: &span, t: ty::t) -> uint { // FIXME: Avoid this check. Since the parent has static // size, any field must as well. There should be a way to // express that with constrained types. - check type_has_static_size(cx, tup_ty); + check (type_has_static_size(cx, tup_ty)); let this_size = llsize_of_real(cx, type_of(cx, sp, tup_ty)); if max_size < this_size { max_size = this_size; } } @@ -553,8 +543,8 @@ fn static_size_of_tag(cx: &@crate_ctxt, sp: &span, t: ty::t) -> uint { } } -fn dynamic_size_of(cx: &@block_ctxt, t: ty::t) -> result { - fn align_elements(cx: &@block_ctxt, elts: &[ty::t]) -> result { +fn dynamic_size_of(cx: @block_ctxt, t: ty::t) -> result { + fn align_elements(cx: @block_ctxt, elts: [ty::t]) -> result { // // C padding rules: // @@ -626,7 +616,7 @@ fn dynamic_size_of(cx: &@block_ctxt, t: ty::t) -> result { } } -fn dynamic_align_of(cx: &@block_ctxt, t: ty::t) -> result { +fn dynamic_align_of(cx: @block_ctxt, t: ty::t) -> result { alt ty::struct(bcx_tcx(cx), t) { ty::ty_param(p, _) { let aptr = field_of_tydesc(cx, t, false, abi::tydesc_field_align); @@ -660,7 +650,7 @@ fn dynamic_align_of(cx: &@block_ctxt, t: ty::t) -> result { // Simple wrapper around GEP that takes an array of ints and wraps them // in C_int() -fn GEPi(cx: &@block_ctxt, base: ValueRef, ixs: &[int]) -> ValueRef { +fn GEPi(cx: @block_ctxt, base: ValueRef, ixs: [int]) -> ValueRef { let v: [ValueRef] = []; for i: int in ixs { v += [C_int(i)]; } ret InBoundsGEP(cx, base, v); @@ -668,7 +658,7 @@ fn GEPi(cx: &@block_ctxt, base: ValueRef, ixs: &[int]) -> ValueRef { // Increment a pointer by a given amount and then cast it to be a pointer // to a given type. -fn bump_ptr(bcx: &@block_ctxt, t: ty::t, base: ValueRef, sz: ValueRef) -> +fn bump_ptr(bcx: @block_ctxt, t: ty::t, base: ValueRef, sz: ValueRef) -> ValueRef { let raw = PointerCast(bcx, base, T_ptr(T_i8())); let bumped = GEP(bcx, raw, [sz]); @@ -677,8 +667,7 @@ fn bump_ptr(bcx: &@block_ctxt, t: ty::t, base: ValueRef, sz: ValueRef) -> let sp = bcx.sp; let typ = T_ptr(type_of(ccx, sp, t)); PointerCast(bcx, bumped, typ) - } - else { bumped } + } else { bumped } } // Replacement for the LLVM 'GEP' instruction when field-indexing into a @@ -686,7 +675,7 @@ fn bump_ptr(bcx: &@block_ctxt, t: ty::t, base: ValueRef, sz: ValueRef) -> // ty::struct and knows what to do when it runs into a ty_param stuck in the // middle of the thing it's GEP'ing into. Much like size_of and align_of, // above. -fn GEP_tup_like(cx: &@block_ctxt, t: ty::t, base: ValueRef, ixs: &[int]) -> +fn GEP_tup_like(cx: @block_ctxt, t: ty::t, base: ValueRef, ixs: [int]) -> result { assert (ty::type_is_tup_like(bcx_tcx(cx), t)); // It might be a static-known type. Handle this. @@ -709,7 +698,7 @@ fn GEP_tup_like(cx: &@block_ctxt, t: ty::t, base: ValueRef, ixs: &[int]) -> // elements of the type and splitting the Xth off. Return the prefix as // well as the innermost Xth type. - fn split_type(ccx: &@crate_ctxt, t: ty::t, ixs: &[int], n: uint) -> + fn split_type(ccx: @crate_ctxt, t: ty::t, ixs: [int], n: uint) -> {prefix: [ty::t], target: ty::t} { let len: uint = std::vec::len::<int>(ixs); // We don't support 0-index or 1-index GEPs: The former is nonsense @@ -768,8 +757,8 @@ fn GEP_tup_like(cx: &@block_ctxt, t: ty::t, base: ValueRef, ixs: &[int]) -> // This function uses GEP_tup_like() above and automatically performs casts as // appropriate. @llblobptr is the data part of a tag value; its actual type is // meaningless, as it will be cast away. -fn GEP_tag(cx: @block_ctxt, llblobptr: ValueRef, tag_id: &ast::def_id, - variant_id: &ast::def_id, ty_substs: &[ty::t], +fn GEP_tag(cx: @block_ctxt, llblobptr: ValueRef, tag_id: ast::def_id, + variant_id: ast::def_id, ty_substs: [ty::t], ix: uint) : valid_variant_index(ix, cx, tag_id, variant_id) -> result { let variant = ty::tag_variant_with_id(bcx_tcx(cx), tag_id, variant_id); @@ -800,26 +789,25 @@ fn GEP_tag(cx: @block_ctxt, llblobptr: ValueRef, tag_id: &ast::def_id, if check type_has_static_size(ccx, tup_ty) { let llty = type_of(ccx, sp, tup_ty); llunionptr = TruncOrBitCast(cx, llblobptr, T_ptr(llty)); - } - else { llunionptr = llblobptr; } + } else { llunionptr = llblobptr; } // Do the GEP_tup_like(). let rs = GEP_tup_like(cx, tup_ty, llunionptr, [0, ix as int]); // Cast the result to the appropriate type, if necessary. let rs_ccx = bcx_ccx(rs.bcx); - let val = if check type_has_static_size(rs_ccx, elem_ty) { - let llelemty = type_of(rs_ccx, sp, elem_ty); - PointerCast(rs.bcx, rs.val, T_ptr(llelemty)) - } - else { rs.val }; + let val = + if check type_has_static_size(rs_ccx, elem_ty) { + let llelemty = type_of(rs_ccx, sp, elem_ty); + PointerCast(rs.bcx, rs.val, T_ptr(llelemty)) + } else { rs.val }; ret rslt(rs.bcx, val); } // trans_raw_malloc: expects a type indicating which pointer type we want and // a size indicating how much space we want malloc'd. -fn trans_raw_malloc(cx: &@block_ctxt, llptr_ty: TypeRef, llsize: ValueRef) -> +fn trans_raw_malloc(cx: @block_ctxt, llptr_ty: TypeRef, llsize: ValueRef) -> result { // FIXME: need a table to collect tydesc globals. @@ -832,7 +820,7 @@ fn trans_raw_malloc(cx: &@block_ctxt, llptr_ty: TypeRef, llsize: ValueRef) -> // trans_shared_malloc: expects a type indicating which pointer type we want // and a size indicating how much space we want malloc'd. -fn trans_shared_malloc(cx: &@block_ctxt, llptr_ty: TypeRef, llsize: ValueRef) +fn trans_shared_malloc(cx: @block_ctxt, llptr_ty: TypeRef, llsize: ValueRef) -> result { // FIXME: need a table to collect tydesc globals. @@ -846,7 +834,7 @@ fn trans_shared_malloc(cx: &@block_ctxt, llptr_ty: TypeRef, llsize: ValueRef) // trans_malloc_boxed_raw: expects an unboxed type and returns a pointer to // enough space for something of that type, along with space for a reference // count; in other words, it allocates a box for something of that type. -fn trans_malloc_boxed_raw(cx: &@block_ctxt, t: ty::t) -> result { +fn trans_malloc_boxed_raw(cx: @block_ctxt, t: ty::t) -> result { // Synthesize a fake box type structurally so we have something // to measure the size of. @@ -867,14 +855,14 @@ fn trans_malloc_boxed_raw(cx: &@block_ctxt, t: ty::t) -> result { // (requires Issue #586) let ccx = bcx_ccx(cx); let sp = cx.sp; - check type_has_static_size(ccx, box_ptr); + check (type_has_static_size(ccx, box_ptr)); let llty = type_of(ccx, sp, box_ptr); ret trans_raw_malloc(sz.bcx, llty, sz.val); } // trans_malloc_boxed: usefully wraps trans_malloc_box_raw; allocates a box, // initializes the reference count to 1, and pulls out the body and rc -fn trans_malloc_boxed(cx: &@block_ctxt, t: ty::t) -> +fn trans_malloc_boxed(cx: @block_ctxt, t: ty::t) -> {bcx: @block_ctxt, box: ValueRef, body: ValueRef} { let res = trans_malloc_boxed_raw(cx, t); let box = res.val; @@ -889,7 +877,7 @@ fn trans_malloc_boxed(cx: &@block_ctxt, t: ty::t) -> // Given a type and a field index into its corresponding type descriptor, // returns an LLVM ValueRef of that field from the tydesc, generating the // tydesc if necessary. -fn field_of_tydesc(cx: &@block_ctxt, t: ty::t, escapes: bool, field: int) -> +fn field_of_tydesc(cx: @block_ctxt, t: ty::t, escapes: bool, field: int) -> result { let ti = none::<@tydesc_info>; let tydesc = get_tydesc(cx, t, escapes, tps_normal, ti).result; @@ -902,7 +890,7 @@ fn field_of_tydesc(cx: &@block_ctxt, t: ty::t, escapes: bool, field: int) -> // each of the ty params it uses (from the current frame) and a vector of the // indices of the ty params present in the type. This is used solely for // constructing derived tydescs. -fn linearize_ty_params(cx: &@block_ctxt, t: ty::t) -> +fn linearize_ty_params(cx: @block_ctxt, t: ty::t) -> {params: [uint], descs: [ValueRef]} { let param_vals: [ValueRef] = []; let param_defs: [uint] = []; @@ -925,7 +913,7 @@ fn linearize_ty_params(cx: &@block_ctxt, t: ty::t) -> ret {params: x.defs, descs: x.vals}; } -fn trans_stack_local_derived_tydesc(cx: &@block_ctxt, llsz: ValueRef, +fn trans_stack_local_derived_tydesc(cx: @block_ctxt, llsz: ValueRef, llalign: ValueRef, llroottydesc: ValueRef, llfirstparam: ValueRef, n_params: uint, obj_params: uint) -> ValueRef { @@ -953,7 +941,7 @@ fn trans_stack_local_derived_tydesc(cx: &@block_ctxt, llsz: ValueRef, // or closure itself rather than in the type descriptor). tag ty_param_storage { tps_normal; tps_obj(uint); tps_fn(uint); } -fn get_derived_tydesc(cx: &@block_ctxt, t: ty::t, escapes: bool, +fn get_derived_tydesc(cx: @block_ctxt, t: ty::t, escapes: bool, storage: ty_param_storage, static_ti: &mutable option::t<@tydesc_info>) -> result { alt cx.fcx.derived_tydescs.find(t) { @@ -1037,7 +1025,7 @@ fn get_derived_tydesc(cx: &@block_ctxt, t: ty::t, escapes: bool, type get_tydesc_result = {kind: tydesc_kind, result: result}; -fn get_tydesc(cx: &@block_ctxt, orig_t: ty::t, escapes: bool, +fn get_tydesc(cx: @block_ctxt, orig_t: ty::t, escapes: bool, storage: ty_param_storage, static_ti: &mutable option::t<@tydesc_info>) -> get_tydesc_result { @@ -1072,7 +1060,7 @@ fn get_tydesc(cx: &@block_ctxt, orig_t: ty::t, escapes: bool, ret {kind: tk_static, result: rslt(cx, info.tydesc)}; } -fn get_static_tydesc(cx: &@block_ctxt, orig_t: ty::t, ty_params: &[uint]) -> +fn get_static_tydesc(cx: @block_ctxt, orig_t: ty::t, ty_params: [uint]) -> @tydesc_info { let t = ty::strip_cname(bcx_tcx(cx), orig_t); @@ -1108,7 +1096,7 @@ fn set_always_inline(f: ValueRef) { lib::llvm::llvm::Attribute); } -fn set_glue_inlining(cx: &@local_ctxt, f: ValueRef, t: ty::t) { +fn set_glue_inlining(cx: @local_ctxt, f: ValueRef, t: ty::t) { if ty::type_is_structural(cx.ccx.tcx, t) { set_no_inline(f); } else { set_always_inline(f); } @@ -1116,8 +1104,8 @@ fn set_glue_inlining(cx: &@local_ctxt, f: ValueRef, t: ty::t) { // Generates the declaration for (but doesn't emit) a type descriptor. -fn declare_tydesc(cx: &@local_ctxt, sp: &span, t: ty::t, ty_params: &[uint]) - -> @tydesc_info { +fn declare_tydesc(cx: @local_ctxt, sp: span, t: ty::t, ty_params: [uint]) -> + @tydesc_info { log "+++ declare_tydesc " + ty_to_str(cx.ccx.tcx, t); let ccx = cx.ccx; let llsize; @@ -1158,12 +1146,12 @@ fn declare_tydesc(cx: &@local_ctxt, sp: &span, t: ty::t, ty_params: &[uint]) } tag glue_helper { - default_helper(fn(&@block_ctxt, ValueRef, ty::t)); - copy_helper(fn(&@block_ctxt, ValueRef, ValueRef, ty::t)); + default_helper(fn(@block_ctxt, ValueRef, ty::t)); + copy_helper(fn(@block_ctxt, ValueRef, ValueRef, ty::t)); } -fn declare_generic_glue(cx: &@local_ctxt, t: ty::t, llfnty: TypeRef, - name: &str) -> ValueRef { +fn declare_generic_glue(cx: @local_ctxt, t: ty::t, llfnty: TypeRef, name: str) + -> ValueRef { let name = name; let fn_nm; if cx.ccx.sess.get_opts().debuginfo { @@ -1175,9 +1163,9 @@ fn declare_generic_glue(cx: &@local_ctxt, t: ty::t, llfnty: TypeRef, ret llfn; } -fn make_generic_glue_inner(cx: &@local_ctxt, sp: &span, t: ty::t, - llfn: ValueRef, helper: &glue_helper, - ty_params: &[uint]) -> ValueRef { +fn make_generic_glue_inner(cx: @local_ctxt, sp: span, t: ty::t, + llfn: ValueRef, helper: glue_helper, + ty_params: [uint]) -> ValueRef { let fcx = new_fn_ctxt(cx, sp, llfn); llvm::LLVMSetLinkage(llfn, lib::llvm::LLVMInternalLinkage as llvm::Linkage); @@ -1188,9 +1176,10 @@ fn make_generic_glue_inner(cx: &@local_ctxt, sp: &span, t: ty::t, // passed by value. let ccx = cx.ccx; - let llty = if check type_has_static_size(ccx, t) { - T_ptr(type_of(ccx, sp, t)) - } else { T_ptr(T_i8()) }; + let llty = + if check type_has_static_size(ccx, t) { + T_ptr(type_of(ccx, sp, t)) + } else { T_ptr(T_i8()) }; let ty_param_count = std::vec::len::<uint>(ty_params); let lltyparams = llvm::LLVMGetParam(llfn, 3u); @@ -1225,8 +1214,8 @@ fn make_generic_glue_inner(cx: &@local_ctxt, sp: &span, t: ty::t, ret llfn; } -fn make_generic_glue(cx: &@local_ctxt, sp: &span, t: ty::t, llfn: ValueRef, - helper: &glue_helper, ty_params: &[uint], name: &str) -> +fn make_generic_glue(cx: @local_ctxt, sp: span, t: ty::t, llfn: ValueRef, + helper: glue_helper, ty_params: [uint], name: str) -> ValueRef { if !cx.ccx.sess.get_opts().stats { ret make_generic_glue_inner(cx, sp, t, llfn, helper, ty_params); @@ -1240,7 +1229,7 @@ fn make_generic_glue(cx: &@local_ctxt, sp: &span, t: ty::t, llfn: ValueRef, ret llval; } -fn emit_tydescs(ccx: &@crate_ctxt) { +fn emit_tydescs(ccx: @crate_ctxt) { for each pair: @{key: ty::t, val: @tydesc_info} in ccx.tydescs.items() { let glue_fn_ty = T_ptr(T_glue_fn(*ccx)); let cmp_fn_ty = T_ptr(T_cmp_glue_fn(*ccx)); @@ -1297,7 +1286,7 @@ fn emit_tydescs(ccx: &@crate_ctxt) { } } -fn make_take_glue(cx: &@block_ctxt, v: ValueRef, t: ty::t) { +fn make_take_glue(cx: @block_ctxt, v: ValueRef, t: ty::t) { let bcx = cx; // NB: v is an *alias* of type t here, not a direct value. if ty::type_is_boxed(bcx_tcx(bcx), t) { @@ -1312,7 +1301,7 @@ fn make_take_glue(cx: &@block_ctxt, v: ValueRef, t: ty::t) { build_return(bcx); } -fn incr_refcnt_of_boxed(cx: &@block_ctxt, box_ptr: ValueRef) -> @block_ctxt { +fn incr_refcnt_of_boxed(cx: @block_ctxt, box_ptr: ValueRef) -> @block_ctxt { let rc_ptr = GEP(cx, box_ptr, [C_int(0), C_int(abi::box_rc_field_refcnt)]); let rc = Load(cx, rc_ptr); @@ -1321,7 +1310,7 @@ fn incr_refcnt_of_boxed(cx: &@block_ctxt, box_ptr: ValueRef) -> @block_ctxt { ret cx; } -fn make_free_glue(bcx: &@block_ctxt, v0: ValueRef, t: ty::t) { +fn make_free_glue(bcx: @block_ctxt, v0: ValueRef, t: ty::t) { // NB: v is an *alias* of type t here, not a direct value. let bcx = alt ty::struct(bcx_tcx(bcx), t) { @@ -1377,43 +1366,44 @@ fn make_free_glue(bcx: &@block_ctxt, v0: ValueRef, t: ty::t) { build_return(bcx); } -fn make_drop_glue(bcx: &@block_ctxt, v0: ValueRef, t: ty::t) { +fn make_drop_glue(bcx: @block_ctxt, v0: ValueRef, t: ty::t) { // NB: v0 is an *alias* of type t here, not a direct value. 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, v0, v0, t) } - ty::ty_uniq(_) { - let vptr = Load(bcx, v0); - let bcx = trans_shared_free(bcx, vptr); - Store(bcx, C_null(val_ty(vptr)), v0); - bcx - } - ty::ty_obj(_) { - let box_cell = - GEP(bcx, v0, [C_int(0), C_int(abi::obj_field_box)]); - decr_refcnt_maybe_free(bcx, box_cell, v0, t) - } - ty::ty_res(did, inner, tps) { - trans_res_drop(bcx, v0, did, inner, tps) - } - ty::ty_fn(_, _, _, _, _) { - let box_cell = GEP(bcx, v0, [C_int(0), C_int(abi::fn_field_box)]); - decr_refcnt_maybe_free(bcx, box_cell, v0, t) - } - _ { - if ty::type_has_pointers(ccx.tcx, t) && - ty::type_is_structural(ccx.tcx, t) { - iter_structural_ty(bcx, v0, t, drop_ty) - } else { 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, v0, v0, t) } + ty::ty_uniq(_) { + let vptr = Load(bcx, v0); + let bcx = trans_shared_free(bcx, vptr); + Store(bcx, C_null(val_ty(vptr)), v0); + bcx + } + ty::ty_obj(_) { + let box_cell = + GEP(bcx, v0, [C_int(0), C_int(abi::obj_field_box)]); + decr_refcnt_maybe_free(bcx, box_cell, v0, t) + } + ty::ty_res(did, inner, tps) { + trans_res_drop(bcx, v0, did, inner, tps) + } + ty::ty_fn(_, _, _, _, _) { + let box_cell = GEP(bcx, v0, [C_int(0), C_int(abi::fn_field_box)]); + decr_refcnt_maybe_free(bcx, box_cell, v0, t) + } + _ { + if ty::type_has_pointers(ccx.tcx, t) && + ty::type_is_structural(ccx.tcx, t) { + iter_structural_ty(bcx, v0, t, drop_ty) + } else { bcx } + } + }; build_return(bcx); } -fn trans_res_drop(cx: @block_ctxt, rs: ValueRef, did: &ast::def_id, - inner_t: ty::t, tps: &[ty::t]) -> @block_ctxt { +fn trans_res_drop(cx: @block_ctxt, rs: ValueRef, did: ast::def_id, + inner_t: ty::t, tps: [ty::t]) -> @block_ctxt { let ccx = bcx_ccx(cx); let inner_t_s = ty::substitute_type_params(ccx.tcx, tps, inner_t); let tup_ty = ty::mk_tup(ccx.tcx, [ty::mk_int(ccx.tcx), inner_t_s]); @@ -1445,8 +1435,9 @@ fn trans_res_drop(cx: @block_ctxt, rs: ValueRef, did: &ast::def_id, // value here, but the dtor expects a type that still has opaque pointers // for type variables. let val_llty = - lib::llvm::fn_ty_param_tys(llvm::LLVMGetElementType( - llvm::LLVMTypeOf(dtor_addr)))[std::vec::len(args)]; + lib::llvm::fn_ty_param_tys + (llvm::LLVMGetElementType + (llvm::LLVMTypeOf(dtor_addr)))[std::vec::len(args)]; let val_cast = BitCast(cx, val.val, val_llty); FastCall(cx, dtor_addr, args + [val_cast]); @@ -1456,7 +1447,7 @@ fn trans_res_drop(cx: @block_ctxt, rs: ValueRef, did: &ast::def_id, ret next_cx; } -fn decr_refcnt_maybe_free(cx: &@block_ctxt, box_ptr_alias: ValueRef, +fn decr_refcnt_maybe_free(cx: @block_ctxt, box_ptr_alias: ValueRef, full_alias: ValueRef, t: ty::t) -> @block_ctxt { let ccx = bcx_ccx(cx); let rc_adj_cx = new_sub_block_ctxt(cx, "rc--"); @@ -1481,7 +1472,7 @@ fn decr_refcnt_maybe_free(cx: &@block_ctxt, box_ptr_alias: ValueRef, // Structural comparison: a rather involved form of glue. -fn maybe_name_value(cx: &@crate_ctxt, v: ValueRef, s: &str) { +fn maybe_name_value(cx: @crate_ctxt, v: ValueRef, s: str) { if cx.sess.get_opts().save_temps { let _: () = str::as_buf(s, {|buf| llvm::LLVMSetValueName(v, buf) }); } @@ -1538,7 +1529,7 @@ fn compare_scalar_types(cx: @block_ctxt, lhs: ValueRef, rhs: ValueRef, // A helper function to do the actual comparison of scalar values. -fn compare_scalar_values(cx: &@block_ctxt, lhs: ValueRef, rhs: ValueRef, +fn compare_scalar_values(cx: @block_ctxt, lhs: ValueRef, rhs: ValueRef, nt: scalar_type, llop: ValueRef) -> result { let eq_cmp; let lt_cmp; @@ -1573,7 +1564,7 @@ fn compare_scalar_values(cx: &@block_ctxt, lhs: ValueRef, rhs: ValueRef, // the above, and "auto eq_result = cmp_fn(eq_cmp, lhs, rhs);" in the // below. - fn generic_cmp(cx: &@block_ctxt, nt: scalar_type, op: uint, lhs: ValueRef, + fn generic_cmp(cx: @block_ctxt, nt: scalar_type, op: uint, lhs: ValueRef, rhs: ValueRef) -> ValueRef { let r: ValueRef; if nt == nil_type { @@ -1605,23 +1596,22 @@ fn compare_scalar_values(cx: &@block_ctxt, lhs: ValueRef, rhs: ValueRef, ret rslt(last_cx, last_result); } -type val_pair_fn = fn(&@block_ctxt, ValueRef, ValueRef) -> @block_ctxt; -type val_and_ty_fn = fn(&@block_ctxt, ValueRef, ty::t) -> @block_ctxt; +type val_pair_fn = fn(@block_ctxt, ValueRef, ValueRef) -> @block_ctxt; +type val_and_ty_fn = fn(@block_ctxt, ValueRef, ty::t) -> @block_ctxt; -fn load_inbounds(cx: &@block_ctxt, p: ValueRef, idxs: &[ValueRef]) -> - ValueRef { +fn load_inbounds(cx: @block_ctxt, p: ValueRef, idxs: [ValueRef]) -> ValueRef { ret Load(cx, InBoundsGEP(cx, p, idxs)); } -fn store_inbounds(cx: &@block_ctxt, v: ValueRef, p: ValueRef, - idxs: &[ValueRef]) { +fn store_inbounds(cx: @block_ctxt, v: ValueRef, p: ValueRef, + idxs: [ValueRef]) { Store(cx, v, InBoundsGEP(cx, p, idxs)); } // Iterates through the elements of a structural type. fn iter_structural_ty(cx: @block_ctxt, av: ValueRef, t: ty::t, - f: &val_and_ty_fn) -> @block_ctxt { - fn iter_boxpp(cx: @block_ctxt, box_cell: ValueRef, f: &val_and_ty_fn) -> + f: val_and_ty_fn) -> @block_ctxt { + fn iter_boxpp(cx: @block_ctxt, box_cell: ValueRef, f: val_and_ty_fn) -> @block_ctxt { let box_ptr = Load(cx, box_cell); let tnil = ty::mk_nil(bcx_tcx(cx)); @@ -1636,8 +1626,8 @@ fn iter_structural_ty(cx: @block_ctxt, av: ValueRef, t: ty::t, } fn iter_variant(cx: @block_ctxt, a_tup: ValueRef, - variant: &ty::variant_info, tps: &[ty::t], - tid: &ast::def_id, f: &val_and_ty_fn) -> @block_ctxt { + variant: ty::variant_info, tps: [ty::t], tid: ast::def_id, + f: val_and_ty_fn) -> @block_ctxt { if std::vec::len::<ty::t>(variant.args) == 0u { ret cx; } let fn_ty = variant.ctor_ty; let ccx = bcx_ccx(cx); @@ -1733,23 +1723,23 @@ fn iter_structural_ty(cx: @block_ctxt, av: ValueRef, t: ty::t, ret cx; } -fn lazily_emit_all_tydesc_glue(cx: &@block_ctxt, - static_ti: &option::t<@tydesc_info>) { +fn lazily_emit_all_tydesc_glue(cx: @block_ctxt, + static_ti: option::t<@tydesc_info>) { lazily_emit_tydesc_glue(cx, abi::tydesc_field_take_glue, static_ti); lazily_emit_tydesc_glue(cx, abi::tydesc_field_drop_glue, static_ti); lazily_emit_tydesc_glue(cx, abi::tydesc_field_free_glue, static_ti); lazily_emit_tydesc_glue(cx, abi::tydesc_field_cmp_glue, static_ti); } -fn lazily_emit_all_generic_info_tydesc_glues(cx: &@block_ctxt, - gi: &generic_info) { +fn lazily_emit_all_generic_info_tydesc_glues(cx: @block_ctxt, + gi: generic_info) { for ti: option::t<@tydesc_info> in gi.static_tis { lazily_emit_all_tydesc_glue(cx, ti); } } -fn lazily_emit_tydesc_glue(cx: &@block_ctxt, field: int, - static_ti: &option::t<@tydesc_info>) { +fn lazily_emit_tydesc_glue(cx: @block_ctxt, field: int, + static_ti: option::t<@tydesc_info>) { alt static_ti { none. { } some(ti) { @@ -1823,8 +1813,8 @@ fn lazily_emit_tydesc_glue(cx: &@block_ctxt, field: int, } } -fn call_tydesc_glue_full(cx: &@block_ctxt, v: ValueRef, tydesc: ValueRef, - field: int, static_ti: &option::t<@tydesc_info>) { +fn call_tydesc_glue_full(cx: @block_ctxt, v: ValueRef, tydesc: ValueRef, + field: int, static_ti: option::t<@tydesc_info>) { lazily_emit_tydesc_glue(cx, field, static_ti); let static_glue_fn = none; @@ -1860,7 +1850,7 @@ fn call_tydesc_glue_full(cx: &@block_ctxt, v: ValueRef, tydesc: ValueRef, lltydescs, llrawptr]); } -fn call_tydesc_glue(cx: &@block_ctxt, v: ValueRef, t: ty::t, field: int) -> +fn call_tydesc_glue(cx: @block_ctxt, v: ValueRef, t: ty::t, field: int) -> @block_ctxt { let ti: option::t<@tydesc_info> = none::<@tydesc_info>; let {bcx: bcx, val: td} = get_tydesc(cx, t, false, tps_normal, ti).result; @@ -1868,7 +1858,7 @@ fn call_tydesc_glue(cx: &@block_ctxt, v: ValueRef, t: ty::t, field: int) -> ret bcx; } -fn call_cmp_glue(cx: &@block_ctxt, lhs: ValueRef, rhs: ValueRef, t: ty::t, +fn call_cmp_glue(cx: @block_ctxt, lhs: ValueRef, rhs: ValueRef, t: ty::t, llop: ValueRef) -> result { // We can't use call_tydesc_glue_full() and friends here because compare // glue has a special signature. @@ -1913,7 +1903,7 @@ fn call_cmp_glue(cx: &@block_ctxt, lhs: ValueRef, rhs: ValueRef, t: ty::t, // Compares two values. Performs the simple scalar comparison if the types are // scalar and calls to comparison glue otherwise. -fn compare(cx: &@block_ctxt, lhs: ValueRef, rhs: ValueRef, t: ty::t, +fn compare(cx: @block_ctxt, lhs: ValueRef, rhs: ValueRef, t: ty::t, llop: ValueRef) -> result { if ty::type_is_scalar(bcx_tcx(cx), t) { ret compare_scalar_types(cx, lhs, rhs, t, llop); @@ -1921,28 +1911,28 @@ fn compare(cx: &@block_ctxt, lhs: ValueRef, rhs: ValueRef, t: ty::t, ret call_cmp_glue(cx, lhs, rhs, t, llop); } -fn take_ty(cx: &@block_ctxt, v: ValueRef, t: ty::t) -> @block_ctxt { +fn take_ty(cx: @block_ctxt, v: ValueRef, t: ty::t) -> @block_ctxt { if ty::type_has_pointers(bcx_tcx(cx), t) { ret call_tydesc_glue(cx, v, t, abi::tydesc_field_take_glue); } ret cx; } -fn drop_ty(cx: &@block_ctxt, v: ValueRef, t: ty::t) -> @block_ctxt { +fn drop_ty(cx: @block_ctxt, v: ValueRef, t: ty::t) -> @block_ctxt { if ty::type_needs_drop(bcx_tcx(cx), t) { ret call_tydesc_glue(cx, v, t, abi::tydesc_field_drop_glue); } ret cx; } -fn free_ty(cx: &@block_ctxt, v: ValueRef, t: ty::t) -> @block_ctxt { +fn free_ty(cx: @block_ctxt, v: ValueRef, t: ty::t) -> @block_ctxt { if ty::type_has_pointers(bcx_tcx(cx), t) { ret call_tydesc_glue(cx, v, t, abi::tydesc_field_free_glue); } ret cx; } -fn call_memmove(cx: &@block_ctxt, dst: ValueRef, src: ValueRef, +fn call_memmove(cx: @block_ctxt, dst: ValueRef, src: ValueRef, n_bytes: ValueRef) -> result { // FIXME: switch to the 64-bit variant when on such a platform. // TODO: Provide LLVM with better alignment information when the alignment @@ -1961,7 +1951,7 @@ fn call_memmove(cx: &@block_ctxt, dst: ValueRef, src: ValueRef, Call(cx, memmove, [dst_ptr, src_ptr, size, align, volatile])); } -fn call_bzero(cx: &@block_ctxt, dst: ValueRef, n_bytes: ValueRef, +fn call_bzero(cx: @block_ctxt, dst: ValueRef, n_bytes: ValueRef, align_bytes: ValueRef) -> result { // FIXME: switch to the 64-bit variant when on such a platform. @@ -1979,7 +1969,7 @@ fn call_bzero(cx: &@block_ctxt, dst: ValueRef, n_bytes: ValueRef, Call(cx, memset, [dst_ptr, C_u8(0u), size, align, volatile])); } -fn memmove_ty(cx: &@block_ctxt, dst: ValueRef, src: ValueRef, t: ty::t) -> +fn memmove_ty(cx: @block_ctxt, dst: ValueRef, src: ValueRef, t: ty::t) -> result { let ccx = bcx_ccx(cx); if check type_has_static_size(ccx, t) { @@ -1999,7 +1989,7 @@ fn memmove_ty(cx: &@block_ctxt, dst: ValueRef, src: ValueRef, t: ty::t) -> tag copy_action { INIT; DROP_EXISTING; } // These are the types that are passed by pointer. -fn type_is_structural_or_param(tcx: &ty::ctxt, t: ty::t) -> bool { +fn type_is_structural_or_param(tcx: ty::ctxt, t: ty::t) -> bool { if ty::type_is_structural(tcx, t) { ret true; } alt ty::struct(tcx, t) { ty::ty_param(_, _) { ret true; } @@ -2007,7 +1997,7 @@ fn type_is_structural_or_param(tcx: &ty::ctxt, t: ty::t) -> bool { } } -fn copy_val(cx: &@block_ctxt, action: copy_action, dst: ValueRef, +fn copy_val(cx: @block_ctxt, action: copy_action, dst: ValueRef, src: ValueRef, t: ty::t) -> @block_ctxt { if type_is_structural_or_param(bcx_ccx(cx).tcx, t) && action == DROP_EXISTING { @@ -2024,7 +2014,7 @@ 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(cx: @block_ctxt, action: copy_action, dst: ValueRef, src: ValueRef, t: ty::t) -> @block_ctxt { let ccx = bcx_ccx(cx); if ty::type_is_scalar(ccx.tcx, t) || ty::type_is_native(ccx.tcx, t) { @@ -2038,8 +2028,8 @@ fn copy_val_no_check(cx: &@block_ctxt, action: copy_action, dst: ValueRef, Store(bcx, src, dst); ret take_ty(bcx, dst, t); } - if type_is_structural_or_param(ccx.tcx, t) || - ty::type_is_vec(ccx.tcx, 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); } bcx = memmove_ty(bcx, dst, src, t).bcx; @@ -2056,7 +2046,7 @@ fn copy_val_no_check(cx: &@block_ctxt, action: copy_action, dst: ValueRef, // case where a variable is always deinitialized by block exit and thus // doesn't need to be dropped. fn move_val(cx: @block_ctxt, action: copy_action, dst: ValueRef, - src: &lval_result, t: ty::t) -> @block_ctxt { + src: lval_result, t: ty::t) -> @block_ctxt { let src_val = src.res.val; let tcx = bcx_tcx(cx); if ty::type_is_scalar(tcx, t) || ty::type_is_native(tcx, t) { @@ -2074,7 +2064,7 @@ fn move_val(cx: @block_ctxt, action: copy_action, dst: ValueRef, // If we're here, it must be a temporary. ret revoke_clean(cx, src_val, t); } else if ty::type_is_unique(tcx, t) || - type_is_structural_or_param(tcx, t) { + 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).bcx; if src.is_mem { ret zero_alloca(cx, src_val, t).bcx; } @@ -2087,7 +2077,7 @@ fn move_val(cx: @block_ctxt, action: copy_action, dst: ValueRef, } fn move_val_if_temp(cx: @block_ctxt, action: copy_action, dst: ValueRef, - src: &lval_result, t: ty::t) -> @block_ctxt { + src: lval_result, t: ty::t) -> @block_ctxt { // Lvals in memory are not temporaries. Copy them. if src.is_mem { @@ -2097,7 +2087,7 @@ fn move_val_if_temp(cx: @block_ctxt, action: copy_action, dst: ValueRef, ret move_val(cx, action, dst, src, t); } -fn trans_crate_lit(cx: &@crate_ctxt, lit: &ast::lit) -> ValueRef { +fn trans_crate_lit(cx: @crate_ctxt, lit: ast::lit) -> ValueRef { alt lit.node { ast::lit_int(i) { ret C_int(i); } ast::lit_uint(u) { ret C_int(u as int); } @@ -2135,7 +2125,7 @@ fn trans_crate_lit(cx: &@crate_ctxt, lit: &ast::lit) -> ValueRef { } } -fn trans_lit(cx: &@block_ctxt, lit: &ast::lit) -> result { +fn trans_lit(cx: @block_ctxt, lit: ast::lit) -> result { alt lit.node { ast::lit_str(s) { ret tvec::trans_str(cx, s); } _ { ret rslt(cx, trans_crate_lit(bcx_ccx(cx), lit)); } @@ -2144,20 +2134,20 @@ fn trans_lit(cx: &@block_ctxt, lit: &ast::lit) -> result { // Converts an annotation to a type -fn node_id_type(cx: &@crate_ctxt, id: ast::node_id) -> ty::t { +fn node_id_type(cx: @crate_ctxt, id: ast::node_id) -> ty::t { ret ty::node_id_to_monotype(cx.tcx, id); } -fn node_type(cx: &@crate_ctxt, sp: &span, id: ast::node_id) -> TypeRef { +fn node_type(cx: @crate_ctxt, sp: span, id: ast::node_id) -> TypeRef { let ty = node_id_type(cx, id); // How to make this a precondition? // FIXME (again, would require a predicate that implies // another predicate) - check type_has_static_size(cx, ty); + check (type_has_static_size(cx, ty)); type_of(cx, sp, ty) } -fn trans_unary(cx: &@block_ctxt, op: ast::unop, e: &@ast::expr, +fn trans_unary(cx: @block_ctxt, op: ast::unop, e: @ast::expr, id: ast::node_id) -> result { let e_ty = ty::expr_ty(bcx_tcx(cx), e); alt op { @@ -2186,9 +2176,10 @@ fn trans_unary(cx: &@block_ctxt, op: ast::unop, e: &@ast::expr, let e_sp = e.span; let llety = T_ptr(type_of(sub_ccx, e_sp, e_ty)); body = PointerCast(sub.bcx, body, llety); - } - else {} // FIXME: can remove the else{} once we have - // a new snapshot + } else { + } // FIXME: can remove the else{} once we have + // a new snapshot + let bcx = move_val_if_temp(sub.bcx, INIT, body, lv, e_ty); ret rslt(bcx, sub.box); } @@ -2200,7 +2191,7 @@ fn trans_unary(cx: &@block_ctxt, op: ast::unop, e: &@ast::expr, } } -fn trans_compare(cx: &@block_ctxt, op: ast::binop, lhs: ValueRef, +fn trans_compare(cx: @block_ctxt, op: ast::binop, lhs: ValueRef, _lhs_t: ty::t, rhs: ValueRef, rhs_t: ty::t) -> result { // Determine the operation we need. let llop; @@ -2223,7 +2214,7 @@ fn trans_compare(cx: &@block_ctxt, op: ast::binop, lhs: ValueRef, // Important to get types for both lhs and rhs, because one might be _|_ // and the other not. -fn trans_eager_binop(cx: &@block_ctxt, op: ast::binop, lhs: ValueRef, +fn trans_eager_binop(cx: @block_ctxt, op: ast::binop, lhs: ValueRef, lhs_t: ty::t, rhs: ValueRef, rhs_t: ty::t) -> result { // If either is bottom, it diverges. So no need to do the @@ -2282,7 +2273,7 @@ fn trans_eager_binop(cx: &@block_ctxt, op: ast::binop, lhs: ValueRef, } } -fn autoderef(cx: &@block_ctxt, v: ValueRef, t: ty::t) -> result_t { +fn autoderef(cx: @block_ctxt, v: ValueRef, t: ty::t) -> result_t { let v1: ValueRef = v; let t1: ty::t = t; let ccx = bcx_ccx(cx); @@ -2317,8 +2308,7 @@ fn autoderef(cx: &@block_ctxt, v: ValueRef, t: ty::t) -> result_t { ty::substitute_type_params(ccx.tcx, tps, variants[0].args[0]); if check type_has_static_size(ccx, t1) { v1 = PointerCast(cx, v1, T_ptr(type_of(ccx, sp, t1))); - } - else {} // FIXME: typestate hack + } else { } // FIXME: typestate hack } _ { break; } } @@ -2327,8 +2317,8 @@ fn autoderef(cx: &@block_ctxt, v: ValueRef, t: ty::t) -> result_t { ret {bcx: cx, val: v1, ty: t1}; } -fn trans_binary(cx: &@block_ctxt, op: ast::binop, a: &@ast::expr, - b: &@ast::expr) -> result { +fn trans_binary(cx: @block_ctxt, op: ast::binop, a: @ast::expr, b: @ast::expr) + -> result { // First couple cases are lazy: alt op { @@ -2376,8 +2366,7 @@ fn trans_binary(cx: &@block_ctxt, op: ast::binop, a: &@ast::expr, } } -fn join_results(parent_cx: &@block_ctxt, t: TypeRef, ins: &[result]) -> - result { +fn join_results(parent_cx: @block_ctxt, t: TypeRef, ins: [result]) -> result { let live: [result] = []; let vals: [ValueRef] = []; let bbs: [BasicBlockRef] = []; @@ -2407,7 +2396,7 @@ fn join_results(parent_cx: &@block_ctxt, t: TypeRef, ins: &[result]) -> ret rslt(join_cx, phi); } -fn join_branches(parent_cx: &@block_ctxt, ins: &[result]) -> @block_ctxt { +fn join_branches(parent_cx: @block_ctxt, ins: [result]) -> @block_ctxt { let out = new_sub_block_ctxt(parent_cx, "join"); for r: result in ins { if !is_terminated(r.bcx) { Br(r.bcx, out.llbb); } } ret out; @@ -2415,8 +2404,8 @@ fn join_branches(parent_cx: &@block_ctxt, ins: &[result]) -> @block_ctxt { tag out_method { return; save_in(ValueRef); } -fn trans_if(cx: &@block_ctxt, cond: &@ast::expr, thn: &ast::blk, - els: &option::t<@ast::expr>, output: &out_method) -> result { +fn trans_if(cx: @block_ctxt, cond: @ast::expr, thn: ast::blk, + els: option::t<@ast::expr>, output: out_method) -> result { let cond_res = trans_expr(cx, cond); if ty::type_is_bot(bcx_tcx(cx), ty::expr_ty(bcx_tcx(cx), cond)) { @@ -2456,23 +2445,24 @@ fn trans_if(cx: &@block_ctxt, cond: &@ast::expr, thn: &ast::blk, ret rslt(join_branches(cx, [then_res, else_res]), C_nil()); } -fn trans_for(cx: &@block_ctxt, local: &@ast::local, seq: &@ast::expr, - body: &ast::blk) -> result { - fn inner(cx: &@block_ctxt, local: @ast::local, curr: ValueRef, t: ty::t, - body: &ast::blk, outer_next_cx: @block_ctxt) -> @block_ctxt { +fn trans_for(cx: @block_ctxt, local: @ast::local, seq: @ast::expr, + body: ast::blk) -> result { + fn inner(cx: @block_ctxt, local: @ast::local, curr: ValueRef, t: ty::t, + body: ast::blk, outer_next_cx: @block_ctxt) -> @block_ctxt { let next_cx = new_sub_block_ctxt(cx, "next"); let scope_cx = new_loop_scope_block_ctxt(cx, option::some::<@block_ctxt>(next_cx), outer_next_cx, "for loop scope"); Br(cx, scope_cx.llbb); - let {bcx, val: dst} = alloc_local(scope_cx, local); - let val = load_if_immediate(bcx, PointerCast(bcx, curr, - val_ty(dst)), t); + let {bcx: bcx, val: dst} = alloc_local(scope_cx, local); + let val = + load_if_immediate(bcx, PointerCast(bcx, curr, val_ty(dst)), t); let bcx = copy_val(bcx, INIT, dst, val, t); add_clean(scope_cx, dst, t); - let bcx = trans_alt::bind_irrefutable_pat(bcx, local.node.pat, dst, - cx.fcx.lllocals, false); + let bcx = + trans_alt::bind_irrefutable_pat(bcx, local.node.pat, dst, + cx.fcx.lllocals, false); bcx = trans_block(bcx, body, return).bcx; if !is_terminated(bcx) { Br(bcx, next_cx.llbb); @@ -2482,14 +2472,15 @@ 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, val: seq} = trans_expr(cx, seq); + let {bcx: bcx, val: seq} = trans_expr(cx, seq); let seq = PointerCast(bcx, seq, T_ptr(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 rslt(next_cx, C_nil()); } @@ -2596,7 +2587,7 @@ fn build_environment(bcx: @block_ctxt, lltydescs: [ValueRef], // Given a context and a list of upvars, build a closure. This just // collects the upvars and packages them up for build_environment. -fn build_closure(cx: &@block_ctxt, upvars: &@[ast::def], copying: bool) -> +fn build_closure(cx: @block_ctxt, upvars: @[ast::def], copying: bool) -> {ptr: ValueRef, ptrty: ty::t, bcx: @block_ctxt} { let closure_vals: [lval_result] = []; let closure_tys: [ty::t] = []; @@ -2623,8 +2614,8 @@ fn build_closure(cx: &@block_ctxt, upvars: &@[ast::def], copying: bool) -> // be dynamically sized, we can't skip past them to get to the tydescs until // we have loaded the tydescs. Thus we use the stored size of the bindings // in the tydesc for the closure to skip over them. Ugh. -fn find_environment_tydescs(bcx: &@block_ctxt, envty: ty::t, - closure: ValueRef) -> ValueRef { +fn find_environment_tydescs(bcx: @block_ctxt, envty: ty::t, closure: ValueRef) + -> ValueRef { ret if !ty::type_has_dynamic_size(bcx_tcx(bcx), envty) { // If we can find the typarams statically, do it @@ -2652,8 +2643,8 @@ fn find_environment_tydescs(bcx: &@block_ctxt, envty: ty::t, // Given an enclosing block context, a new function context, a closure type, // and a list of upvars, generate code to load and populate the environment // with the upvars and type descriptors. -fn load_environment(enclosing_cx: &@block_ctxt, fcx: &@fn_ctxt, envty: ty::t, - upvars: &@[ast::def], copying: bool) { +fn load_environment(enclosing_cx: @block_ctxt, fcx: @fn_ctxt, envty: ty::t, + upvars: @[ast::def], copying: bool) { let bcx = new_raw_block_ctxt(fcx, fcx.llcopyargs); let ty = ty::mk_imm_box(bcx_tcx(bcx), envty); @@ -2662,7 +2653,7 @@ fn load_environment(enclosing_cx: &@block_ctxt, fcx: &@fn_ctxt, envty: ty::t, let sp = bcx.sp; // FIXME: should have postcondition on mk_imm_box, // so this check won't be necessary - check type_has_static_size(ccx, ty); + check (type_has_static_size(ccx, ty)); let llty = type_of(ccx, sp, ty); let llclosure = PointerCast(bcx, fcx.llenv, llty); @@ -2702,8 +2693,8 @@ fn load_environment(enclosing_cx: &@block_ctxt, fcx: &@fn_ctxt, envty: ty::t, } } -fn trans_for_each(cx: &@block_ctxt, local: &@ast::local, seq: &@ast::expr, - body: &ast::blk) -> result { +fn trans_for_each(cx: @block_ctxt, local: @ast::local, seq: @ast::expr, + body: ast::blk) -> result { /* * The translation is a little .. complex here. Code like: * @@ -2783,8 +2774,7 @@ fn trans_for_each(cx: &@block_ctxt, local: &@ast::local, seq: &@ast::expr, } } -fn trans_while(cx: &@block_ctxt, cond: &@ast::expr, body: &ast::blk) -> - result { +fn trans_while(cx: @block_ctxt, cond: @ast::expr, body: ast::blk) -> result { let next_cx = new_sub_block_ctxt(cx, "while next"); let cond_cx = new_loop_scope_block_ctxt(cx, option::none::<@block_ctxt>, next_cx, @@ -2799,7 +2789,7 @@ fn trans_while(cx: &@block_ctxt, cond: &@ast::expr, body: &ast::blk) -> ret rslt(next_cx, C_nil()); } -fn trans_do_while(cx: &@block_ctxt, body: &ast::blk, cond: &@ast::expr) -> +fn trans_do_while(cx: @block_ctxt, body: ast::blk, cond: @ast::expr) -> result { let next_cx = new_sub_block_ctxt(cx, "next"); let body_cx = @@ -2832,7 +2822,7 @@ type lval_result = llobj: option::t<ValueRef>, method_ty: option::t<ty::t>}; -fn lval_mem(cx: &@block_ctxt, val: ValueRef) -> lval_result { +fn lval_mem(cx: @block_ctxt, val: ValueRef) -> lval_result { ret {res: rslt(cx, val), is_mem: true, generic: none::<generic_info>, @@ -2840,7 +2830,7 @@ fn lval_mem(cx: &@block_ctxt, val: ValueRef) -> lval_result { method_ty: none::<ty::t>}; } -fn lval_val(cx: &@block_ctxt, val: ValueRef) -> lval_result { +fn lval_val(cx: @block_ctxt, val: ValueRef) -> lval_result { ret {res: rslt(cx, val), is_mem: false, generic: none::<generic_info>, @@ -2848,16 +2838,16 @@ fn lval_val(cx: &@block_ctxt, val: ValueRef) -> lval_result { method_ty: none::<ty::t>}; } -fn trans_external_path(cx: &@block_ctxt, did: &ast::def_id, - tpt: &ty::ty_param_kinds_and_ty) -> ValueRef { +fn trans_external_path(cx: @block_ctxt, did: ast::def_id, + tpt: ty::ty_param_kinds_and_ty) -> ValueRef { let lcx = cx.fcx.lcx; let name = csearch::get_symbol(lcx.ccx.sess.get_cstore(), did); ret get_extern_const(lcx.ccx.externs, lcx.ccx.llmod, name, type_of_ty_param_kinds_and_ty(lcx, cx.sp, tpt)); } -fn lval_generic_fn(cx: &@block_ctxt, tpt: &ty::ty_param_kinds_and_ty, - fn_id: &ast::def_id, id: ast::node_id) -> lval_result { +fn lval_generic_fn(cx: @block_ctxt, tpt: ty::ty_param_kinds_and_ty, + fn_id: ast::def_id, id: ast::node_id) -> lval_result { let lv; if fn_id.crate == ast::local_crate { // Internal reference. @@ -2887,7 +2877,7 @@ fn lval_generic_fn(cx: &@block_ctxt, tpt: &ty::ty_param_kinds_and_ty, ret lv; } -fn lookup_discriminant(lcx: &@local_ctxt, vid: &ast::def_id) -> ValueRef { +fn lookup_discriminant(lcx: @local_ctxt, vid: ast::def_id) -> ValueRef { alt lcx.ccx.discrims.find(vid.node) { none. { // It's an external discriminant that we haven't seen yet. @@ -2908,7 +2898,7 @@ fn lookup_discriminant(lcx: &@local_ctxt, vid: &ast::def_id) -> ValueRef { } } -fn trans_local_var(cx: &@block_ctxt, def: &ast::def) -> lval_result { +fn trans_local_var(cx: @block_ctxt, def: ast::def) -> lval_result { alt def { ast::def_upvar(did, _, _) { assert (cx.fcx.llupvars.contains_key(did.node)); @@ -2931,14 +2921,13 @@ fn trans_local_var(cx: &@block_ctxt, def: &ast::def) -> lval_result { ret lval_mem(cx, cx.fcx.llobjfields.get(did.node)); } _ { - bcx_ccx(cx).sess.span_unimpl( - cx.sp, - "unsupported def type in trans_local_def"); + bcx_ccx(cx).sess.span_unimpl + (cx.sp, "unsupported def type in trans_local_def"); } } } -fn trans_var(cx: &@block_ctxt, sp: &span, def: &ast::def, id: ast::node_id) -> +fn trans_var(cx: @block_ctxt, sp: span, def: ast::def, id: ast::node_id) -> lval_result { let ccx = bcx_ccx(cx); alt def { @@ -2991,13 +2980,13 @@ fn trans_var(cx: &@block_ctxt, sp: &span, def: &ast::def, id: ast::node_id) -> } } -fn trans_path(cx: &@block_ctxt, p: &ast::path, id: ast::node_id) -> +fn trans_path(cx: @block_ctxt, p: ast::path, id: ast::node_id) -> lval_result { ret trans_var(cx, p.span, bcx_tcx(cx).def_map.get(id), id); } -fn trans_field(cx: &@block_ctxt, sp: &span, v: ValueRef, t0: ty::t, - field: &ast::ident) -> lval_result { +fn trans_field(cx: @block_ctxt, sp: span, v: ValueRef, t0: ty::t, + field: ast::ident) -> lval_result { let r = autoderef(cx, v, t0); let t = r.ty; alt ty::struct(bcx_tcx(cx), t) { @@ -3030,8 +3019,8 @@ fn trans_field(cx: &@block_ctxt, sp: &span, v: ValueRef, t0: ty::t, } } -fn trans_index(cx: &@block_ctxt, sp: &span, base: &@ast::expr, - idx: &@ast::expr, id: ast::node_id) -> lval_result { +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); @@ -3066,15 +3055,15 @@ fn trans_index(cx: &@block_ctxt, sp: &span, base: &@ast::expr, // fail: bad bounds check. trans_fail(fail_cx, some::<span>(sp), "bounds check"); - let elt = if check type_has_static_size(ncx, unit_ty) { - let elt_1 = GEP(next_cx, body, [ix_val]); - let llunitty = type_of(ncx, sp, unit_ty); - PointerCast(next_cx, elt_1, T_ptr(llunitty)) - } - else { - body = PointerCast(next_cx, body, T_ptr(T_i8())); - GEP(next_cx, body, [scaled_ix]) - }; + let elt = + if check type_has_static_size(ncx, unit_ty) { + let elt_1 = GEP(next_cx, body, [ix_val]); + let llunitty = type_of(ncx, sp, unit_ty); + PointerCast(next_cx, elt_1, T_ptr(llunitty)) + } else { + body = PointerCast(next_cx, body, T_ptr(T_i8())); + GEP(next_cx, body, [scaled_ix]) + }; ret lval_mem(next_cx, elt); } @@ -3082,7 +3071,7 @@ fn trans_index(cx: &@block_ctxt, sp: &span, base: &@ast::expr, // The additional bool returned indicates whether it's mem (that is // represented as an alloca or heap, hence needs a 'load' to be used as an // immediate). -fn trans_lval_gen(cx: &@block_ctxt, e: &@ast::expr) -> lval_result { +fn trans_lval_gen(cx: @block_ctxt, e: @ast::expr) -> lval_result { alt e.node { ast::expr_path(p) { ret trans_path(cx, p, e.id); } ast::expr_field(base, ident) { @@ -3110,10 +3099,10 @@ fn trans_lval_gen(cx: &@block_ctxt, e: &@ast::expr) -> lval_result { ty::ty_tag(_, _) { let ety = ty::expr_ty(ccx.tcx, e); let sp = e.span; - let ellty = if check type_has_static_size(ccx, ety) { - T_ptr(type_of(ccx, sp, ety)) - } - else { T_typaram_ptr(ccx.tn) }; + let ellty = + if check type_has_static_size(ccx, ety) { + T_ptr(type_of(ccx, sp, ety)) + } else { T_typaram_ptr(ccx.tn) }; PointerCast(sub.bcx, sub.val, ellty) } ty::ty_ptr(_) { sub.val } @@ -3146,7 +3135,7 @@ fn trans_lval_gen(cx: &@block_ctxt, e: &@ast::expr) -> lval_result { } } -fn trans_lval(cx: &@block_ctxt, e: &@ast::expr) -> lval_result { +fn trans_lval(cx: @block_ctxt, e: @ast::expr) -> lval_result { let lv = trans_lval_gen(cx, e); alt lv.generic { some(gi) { @@ -3160,7 +3149,7 @@ fn trans_lval(cx: &@block_ctxt, e: &@ast::expr) -> lval_result { } } -fn int_cast(bcx: &@block_ctxt, lldsttype: TypeRef, llsrctype: TypeRef, +fn int_cast(bcx: @block_ctxt, lldsttype: TypeRef, llsrctype: TypeRef, llsrc: ValueRef, signed: bool) -> ValueRef { let srcsz = llvm::LLVMGetIntTypeWidth(llsrctype); let dstsz = llvm::LLVMGetIntTypeWidth(lldsttype); @@ -3173,7 +3162,7 @@ fn int_cast(bcx: &@block_ctxt, lldsttype: TypeRef, llsrctype: TypeRef, } else { ZExtOrBitCast(bcx, llsrc, lldsttype) }; } -fn float_cast(bcx: &@block_ctxt, lldsttype: TypeRef, llsrctype: TypeRef, +fn float_cast(bcx: @block_ctxt, lldsttype: TypeRef, llsrctype: TypeRef, llsrc: ValueRef) -> ValueRef { let srcsz = lib::llvm::float_width(llsrctype); let dstsz = lib::llvm::float_width(lldsttype); @@ -3184,7 +3173,7 @@ fn float_cast(bcx: &@block_ctxt, lldsttype: TypeRef, llsrctype: TypeRef, } else { llsrc }; } -fn trans_cast(cx: &@block_ctxt, e: &@ast::expr, id: ast::node_id) -> result { +fn trans_cast(cx: @block_ctxt, e: @ast::expr, id: ast::node_id) -> result { let ccx = bcx_ccx(cx); let e_res = trans_expr(cx, e); let ll_t_in = val_ty(e_res.val); @@ -3192,11 +3181,11 @@ fn trans_cast(cx: &@block_ctxt, e: &@ast::expr, id: ast::node_id) -> result { let t_out = node_id_type(ccx, id); // Check should be avoidable because it's a cast. // FIXME: Constrain types so as to avoid this check. - check type_has_static_size(ccx, t_out); + check (type_has_static_size(ccx, t_out)); let ll_t_out = type_of(ccx, e.span, t_out); tag kind { native_; integral; float; other; } - fn t_kind(tcx: &ty::ctxt, t: ty::t) -> kind { + fn t_kind(tcx: ty::ctxt, t: ty::t) -> kind { ret if ty::type_is_fp(tcx, t) { float } else if ty::type_is_native(tcx, t) { @@ -3241,16 +3230,16 @@ fn trans_cast(cx: &@block_ctxt, e: &@ast::expr, id: ast::node_id) -> result { ret rslt(e_res.bcx, newval); } -fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: ty::t, - outgoing_fty: ty::t, args: &[option::t<@ast::expr>], +fn trans_bind_thunk(cx: @local_ctxt, sp: span, incoming_fty: ty::t, + outgoing_fty: ty::t, args: [option::t<@ast::expr>], env_ty: ty::t, ty_param_count: uint, - target_fn: &option::t<ValueRef>) -> - {val: ValueRef, ty: TypeRef} { + target_fn: option::t<ValueRef>) -> + {val: ValueRef, ty: TypeRef} { // FIXME // This should be a precondition on trans_bind_thunk, but we would need // to support record fields as constraint args let ccx = cx.ccx; - check type_has_static_size(ccx, incoming_fty); + check (type_has_static_size(ccx, incoming_fty)); // Here we're not necessarily constructing a thunk in the sense of // "function with no arguments". The result of compiling 'bind f(foo, @@ -3274,10 +3263,8 @@ fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: ty::t, // construct and return that thunk. // Give the thunk a name, type, and value. - let s: str = - mangle_internal_name_by_path_and_seq(ccx, cx.path, "thunk"); - let llthunk_ty: TypeRef = - get_pair_fn_ty(type_of(ccx, sp, incoming_fty)); + let s: str = mangle_internal_name_by_path_and_seq(ccx, cx.path, "thunk"); + let llthunk_ty: TypeRef = get_pair_fn_ty(type_of(ccx, sp, incoming_fty)); let llthunk: ValueRef = decl_internal_fastcall_fn(ccx.llmod, s, llthunk_ty); @@ -3301,10 +3288,9 @@ fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: ty::t, let closure_ty = ty::mk_imm_box(ccx.tcx, env_ty); // FIXME: would be nice to have a postcondition on mk_imm_box // (Issue #586) - check type_has_static_size(ccx, closure_ty); + check (type_has_static_size(ccx, closure_ty)); let llclosure_ptr_ty = type_of(ccx, sp, closure_ty); - let llclosure = - PointerCast(copy_args_bcx, fcx.llenv, llclosure_ptr_ty); + let llclosure = PointerCast(copy_args_bcx, fcx.llenv, llclosure_ptr_ty); // "target", in this context, means the function that's having some of its // arguments bound and that will be called inside the thunk we're @@ -3373,6 +3359,7 @@ fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: ty::t, alt arg { + // Arg provided at binding time; thunk copies it from // closure. some(e) { @@ -3391,6 +3378,7 @@ fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: ty::t, b += 1; } + // Arg will be provided when the thunk is invoked. none. { let arg: ValueRef = llvm::LLVMGetParam(llthunk, a); @@ -3422,14 +3410,14 @@ fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: ty::t, ret {val: llthunk, ty: llthunk_ty}; } -fn trans_bind(cx: &@block_ctxt, f: &@ast::expr, - args: &[option::t<@ast::expr>], id: ast::node_id) -> result { +fn trans_bind(cx: @block_ctxt, f: @ast::expr, args: [option::t<@ast::expr>], + id: ast::node_id) -> result { let f_res = trans_lval_gen(cx, f); ret trans_bind_1(cx, f, f_res, args, id); } -fn trans_bind_1(cx: &@block_ctxt, f: &@ast::expr, f_res: &lval_result, - args: &[option::t<@ast::expr>], id: ast::node_id) -> result { +fn trans_bind_1(cx: @block_ctxt, f: @ast::expr, f_res: lval_result, + args: [option::t<@ast::expr>], id: ast::node_id) -> result { let bound: [@ast::expr] = []; for argopt: option::t<@ast::expr> in args { alt argopt { none. { } some(e) { bound += [e]; } } @@ -3457,7 +3445,7 @@ fn trans_bind_1(cx: &@block_ctxt, f: &@ast::expr, f_res: &lval_result, // FIXME: should follow from a precondition on trans_bind_1 let ccx = bcx_ccx(cx); - check type_has_static_size(ccx, outgoing_fty); + check (type_has_static_size(ccx, outgoing_fty)); // Arrange for the bound function to live in the first binding spot // if the function is not statically known. @@ -3500,10 +3488,10 @@ fn trans_bind_1(cx: &@block_ctxt, f: &@ast::expr, f_res: &lval_result, ret rslt(bcx, pair_v); } -fn trans_arg_expr(cx: &@block_ctxt, arg: &ty::arg, lldestty0: TypeRef, +fn trans_arg_expr(cx: @block_ctxt, arg: ty::arg, lldestty0: TypeRef, to_zero: &mutable [{v: ValueRef, t: ty::t}], to_revoke: &mutable [{v: ValueRef, t: ty::t}], - e: &@ast::expr) -> result { + e: @ast::expr) -> result { let ccx = bcx_ccx(cx); let e_ty = ty::expr_ty(ccx.tcx, e); let is_bot = ty::type_is_bot(ccx.tcx, e_ty); @@ -3525,12 +3513,11 @@ fn trans_arg_expr(cx: &@block_ctxt, arg: &ty::arg, lldestty0: TypeRef, if ccx.copy_map.contains_key(e.id) && lv.is_mem { if !copied { let alloc = alloc_ty(bcx, e_ty); - bcx = copy_val(alloc.bcx, INIT, alloc.val, - load_if_immediate(alloc.bcx, val, e_ty), e_ty); + bcx = + copy_val(alloc.bcx, INIT, alloc.val, + load_if_immediate(alloc.bcx, val, e_ty), e_ty); val = alloc.val; - } else { - bcx = take_ty(bcx, val, e_ty); - } + } else { bcx = take_ty(bcx, val, e_ty); } add_clean(bcx, val, e_ty); } } else if type_is_immediate(ccx, e_ty) && !lv.is_mem { @@ -3550,9 +3537,7 @@ fn trans_arg_expr(cx: &@block_ctxt, arg: &ty::arg, lldestty0: TypeRef, // Use actual ty, not declared ty -- anything else doesn't make // sense if declared ty is a ty param to_zero += [{v: lv.res.val, t: e_ty}]; - } else { - to_revoke += [{v: lv.res.val, t: e_ty}]; - } + } else { to_revoke += [{v: lv.res.val, t: e_ty}]; } } ret rslt(bcx, val); } @@ -3564,9 +3549,9 @@ fn trans_arg_expr(cx: &@block_ctxt, arg: &ty::arg, lldestty0: TypeRef, // - create_llargs_for_fn_args. // - new_fn_ctxt // - trans_args -fn trans_args(cx: &@block_ctxt, llenv: ValueRef, - gen: &option::t<generic_info>, lliterbody: &option::t<ValueRef>, - es: &[@ast::expr], fn_ty: ty::t) -> +fn trans_args(cx: @block_ctxt, llenv: ValueRef, gen: option::t<generic_info>, + lliterbody: option::t<ValueRef>, es: [@ast::expr], fn_ty: ty::t) + -> {bcx: @block_ctxt, args: [ValueRef], retslot: ValueRef, @@ -3665,8 +3650,8 @@ fn trans_args(cx: &@block_ctxt, llenv: ValueRef, to_revoke: to_revoke}; } -fn trans_call(in_cx: &@block_ctxt, f: &@ast::expr, - lliterbody: &option::t<ValueRef>, args: &[@ast::expr], +fn trans_call(in_cx: @block_ctxt, f: @ast::expr, + lliterbody: option::t<ValueRef>, args: [@ast::expr], id: ast::node_id) -> result { // NB: 'f' isn't necessarily a function; it might be an entire self-call // expression because of the hack that allows us to process self-calls @@ -3762,7 +3747,7 @@ fn trans_call(in_cx: &@block_ctxt, f: &@ast::expr, ret rslt(bcx, retval); } -fn trans_tup(cx: &@block_ctxt, elts: &[@ast::expr], id: ast::node_id) -> +fn trans_tup(cx: @block_ctxt, elts: [@ast::expr], id: ast::node_id) -> result { let bcx = cx; let t = node_id_type(bcx.fcx.lcx.ccx, id); @@ -3782,8 +3767,8 @@ fn trans_tup(cx: &@block_ctxt, elts: &[@ast::expr], id: ast::node_id) -> ret rslt(bcx, tup_val); } -fn trans_rec(cx: &@block_ctxt, fields: &[ast::field], - base: &option::t<@ast::expr>, id: ast::node_id) -> result { +fn trans_rec(cx: @block_ctxt, fields: [ast::field], + base: option::t<@ast::expr>, id: ast::node_id) -> result { let bcx = cx; let t = node_id_type(bcx_ccx(bcx), id); let rec_res = alloc_ty(bcx, t); @@ -3827,11 +3812,11 @@ fn trans_rec(cx: &@block_ctxt, fields: &[ast::field], ret rslt(bcx, rec_val); } -fn trans_expr(cx: &@block_ctxt, e: &@ast::expr) -> result { +fn trans_expr(cx: @block_ctxt, e: @ast::expr) -> result { ret trans_expr_out(cx, e, return); } -fn trans_expr_out(cx: &@block_ctxt, e: &@ast::expr, output: out_method) -> +fn trans_expr_out(cx: @block_ctxt, e: @ast::expr, output: out_method) -> result { // Fixme Fill in cx.sp alt e.node { @@ -4047,8 +4032,8 @@ fn trans_expr_out(cx: &@block_ctxt, e: &@ast::expr, output: out_method) -> ret rslt(sub.res.bcx, v); } -fn with_out_method(work: fn(&out_method) -> result, cx: @block_ctxt, - id: ast::node_id, outer_output: &out_method) -> result { +fn with_out_method(work: fn(out_method) -> result, cx: @block_ctxt, + id: ast::node_id, outer_output: out_method) -> result { let ccx = bcx_ccx(cx); if outer_output != return { ret work(outer_output); @@ -4070,12 +4055,12 @@ fn with_out_method(work: fn(&out_method) -> result, cx: @block_ctxt, // latter group "immediates" and, in some circumstances when we know we have a // pointer (or need one), perform load/store operations based on the // immediate-ness of the type. -fn type_is_immediate(ccx: &@crate_ctxt, t: ty::t) -> bool { +fn type_is_immediate(ccx: @crate_ctxt, t: ty::t) -> bool { ret ty::type_is_scalar(ccx.tcx, t) || ty::type_is_boxed(ccx.tcx, t) || ty::type_is_native(ccx.tcx, t); } -fn do_spill(cx: &@block_ctxt, v: ValueRef, t: ty::t) -> result { +fn do_spill(cx: @block_ctxt, v: ValueRef, t: ty::t) -> result { // We have a value but we have to spill it, and root it, to pass by alias. let bcx = cx; let r = alloc_ty(bcx, t); @@ -4089,23 +4074,23 @@ fn do_spill(cx: &@block_ctxt, v: ValueRef, t: ty::t) -> result { // Since this function does *not* root, it is the caller's responsibility to // ensure that the referent is pointed to by a root. -fn do_spill_noroot(cx: &@block_ctxt, v: ValueRef) -> ValueRef { +fn do_spill_noroot(cx: @block_ctxt, v: ValueRef) -> ValueRef { let llptr = alloca(cx, val_ty(v)); Store(cx, v, llptr); ret llptr; } -fn spill_if_immediate(cx: &@block_ctxt, v: ValueRef, t: ty::t) -> result { +fn spill_if_immediate(cx: @block_ctxt, v: ValueRef, t: ty::t) -> result { if type_is_immediate(bcx_ccx(cx), t) { ret do_spill(cx, v, t); } ret rslt(cx, v); } -fn load_if_immediate(cx: &@block_ctxt, v: ValueRef, t: ty::t) -> ValueRef { +fn load_if_immediate(cx: @block_ctxt, v: ValueRef, t: ty::t) -> ValueRef { if type_is_immediate(bcx_ccx(cx), t) { ret Load(cx, v); } ret v; } -fn trans_log(lvl: int, cx: &@block_ctxt, e: &@ast::expr) -> result { +fn trans_log(lvl: int, cx: @block_ctxt, e: @ast::expr) -> result { let lcx = cx.fcx.lcx; let modname = str::connect(lcx.module_path, "::"); let global; @@ -4156,7 +4141,7 @@ fn trans_log(lvl: int, cx: &@block_ctxt, e: &@ast::expr) -> result { ret rslt(after_cx, C_nil()); } -fn trans_check_expr(cx: &@block_ctxt, e: &@ast::expr, s: &str) -> result { +fn trans_check_expr(cx: @block_ctxt, e: @ast::expr, s: str) -> result { let cond_res = trans_expr(cx, e); let expr_str = s + " " + expr_to_str(e) + " failed"; let fail_cx = new_sub_block_ctxt(cx, "fail"); @@ -4166,8 +4151,8 @@ fn trans_check_expr(cx: &@block_ctxt, e: &@ast::expr, s: &str) -> result { ret rslt(next_cx, C_nil()); } -fn trans_fail_expr(cx: &@block_ctxt, sp_opt: &option::t<span>, - fail_expr: &option::t<@ast::expr>) -> result { +fn trans_fail_expr(cx: @block_ctxt, sp_opt: option::t<span>, + fail_expr: option::t<@ast::expr>) -> result { let bcx = cx; alt fail_expr { some(expr) { @@ -4193,14 +4178,14 @@ fn trans_fail_expr(cx: &@block_ctxt, sp_opt: &option::t<span>, } } -fn trans_fail(cx: &@block_ctxt, sp_opt: &option::t<span>, fail_str: &str) -> +fn trans_fail(cx: @block_ctxt, sp_opt: option::t<span>, fail_str: str) -> result { let V_fail_str = C_cstr(bcx_ccx(cx), fail_str); ret trans_fail_value(cx, sp_opt, V_fail_str); } -fn trans_fail_value(cx: &@block_ctxt, sp_opt: &option::t<span>, - V_fail_str: &ValueRef) -> result { +fn trans_fail_value(cx: @block_ctxt, sp_opt: option::t<span>, + V_fail_str: ValueRef) -> result { let V_filename; let V_line; alt sp_opt { @@ -4219,7 +4204,7 @@ fn trans_fail_value(cx: &@block_ctxt, sp_opt: &option::t<span>, ret rslt(cx, C_nil()); } -fn trans_put(in_cx: &@block_ctxt, e: &option::t<@ast::expr>) -> result { +fn trans_put(in_cx: @block_ctxt, e: option::t<@ast::expr>) -> result { let cx = new_scope_block_ctxt(in_cx, "put"); Br(in_cx, cx.llbb); let llcallee = C_nil(); @@ -4257,7 +4242,7 @@ fn trans_put(in_cx: &@block_ctxt, e: &option::t<@ast::expr>) -> result { ret rslt(next_cx, C_nil()); } -fn trans_uniq(cx: &@block_ctxt, contents: &@ast::expr) -> lval_result { +fn trans_uniq(cx: @block_ctxt, contents: @ast::expr) -> lval_result { let bcx = cx; let contents_ty = ty::expr_ty(bcx_tcx(bcx), contents); @@ -4276,7 +4261,7 @@ fn trans_uniq(cx: &@block_ctxt, contents: &@ast::expr) -> lval_result { ret lval_val(r.bcx, llptrptr); } -fn trans_break_cont(sp: &span, cx: &@block_ctxt, to_end: bool) -> result { +fn trans_break_cont(sp: span, cx: @block_ctxt, to_end: bool) -> result { let bcx = cx; // Locate closest loop block, outputting cleanup as we go. @@ -4315,15 +4300,15 @@ fn trans_break_cont(sp: &span, cx: &@block_ctxt, to_end: bool) -> result { bcx_ccx(cx).sess.bug("in trans::trans_break_cont()"); } -fn trans_break(sp: &span, cx: &@block_ctxt) -> result { +fn trans_break(sp: span, cx: @block_ctxt) -> result { ret trans_break_cont(sp, cx, true); } -fn trans_cont(sp: &span, cx: &@block_ctxt) -> result { +fn trans_cont(sp: span, cx: @block_ctxt) -> result { ret trans_break_cont(sp, cx, false); } -fn trans_ret(cx: &@block_ctxt, e: &option::t<@ast::expr>) -> result { +fn trans_ret(cx: @block_ctxt, e: option::t<@ast::expr>) -> result { let bcx = cx; alt e { some(x) { @@ -4364,10 +4349,10 @@ fn trans_ret(cx: &@block_ctxt, e: &option::t<@ast::expr>) -> result { ret rslt(new_sub_block_ctxt(bcx, "ret.unreachable"), C_nil()); } -fn build_return(bcx: &@block_ctxt) { Br(bcx, bcx_fcx(bcx).llreturn); } +fn build_return(bcx: @block_ctxt) { Br(bcx, bcx_fcx(bcx).llreturn); } // fn trans_be(cx: &@block_ctxt, e: &@ast::expr) -> result { -fn trans_be(cx: &@block_ctxt, e: &@ast::expr) : ast_util::is_call_expr(e) -> +fn trans_be(cx: @block_ctxt, e: @ast::expr) : ast_util::is_call_expr(e) -> result { // FIXME: Turn this into a real tail call once @@ -4376,7 +4361,7 @@ fn trans_be(cx: &@block_ctxt, e: &@ast::expr) : ast_util::is_call_expr(e) -> ret trans_ret(cx, some(e)); } -fn init_local(bcx: @block_ctxt, local: &@ast::local) -> result { +fn init_local(bcx: @block_ctxt, local: @ast::local) -> result { let ty = node_id_type(bcx_ccx(bcx), local.node.id); let llptr = bcx.fcx.lllocals.get(local.node.id); // Make a note to drop this slot on the way out. @@ -4408,23 +4393,22 @@ fn init_local(bcx: @block_ctxt, local: &@ast::local) -> result { bcx.fcx.lllocals, false); ret rslt(bcx, llptr); - fn must_zero(local: &@ast::local) -> bool { + fn must_zero(local: @ast::local) -> bool { alt local.node.init { some(init) { might_not_init(init.expr) } none. { true } } } - fn might_not_init(expr: &@ast::expr) -> bool { + fn might_not_init(expr: @ast::expr) -> bool { type env = @mutable bool; let e = @mutable false; // FIXME: Probably also need to account for expressions that // fail but since we don't unwind yet, it doesn't seem to be a // problem let visitor = - visit::mk_vt( - @{visit_expr: - fn (ex: &@ast::expr, e: &env, v: &vt<env>) { + visit::mk_vt(@{visit_expr: + fn (ex: @ast::expr, e: env, v: vt<env>) { let might_not_init = alt ex.node { ast::expr_ret(_) { true } @@ -4441,15 +4425,14 @@ fn init_local(bcx: @block_ctxt, local: &@ast::local) -> result { } } -fn zero_alloca(cx: &@block_ctxt, llptr: ValueRef, t: ty::t) -> result { +fn zero_alloca(cx: @block_ctxt, llptr: ValueRef, t: ty::t) -> result { let bcx = cx; let ccx = bcx_ccx(cx); if check type_has_static_size(ccx, t) { let sp = cx.sp; let llty = type_of(ccx, sp, t); Store(bcx, C_null(llty), llptr); - } - else { + } else { let llsz = size_of(bcx, t); // FIXME passing in the align here is correct, but causes issue #843 // let llalign = align_of(llsz.bcx, t); @@ -4458,7 +4441,7 @@ fn zero_alloca(cx: &@block_ctxt, llptr: ValueRef, t: ty::t) -> result { ret rslt(bcx, llptr); } -fn trans_stmt(cx: &@block_ctxt, s: &ast::stmt) -> result { +fn trans_stmt(cx: @block_ctxt, s: ast::stmt) -> result { // FIXME Fill in cx.sp let bcx = cx; @@ -4481,8 +4464,8 @@ fn trans_stmt(cx: &@block_ctxt, s: &ast::stmt) -> result { // You probably don't want to use this one. See the // next three functions instead. -fn new_block_ctxt(cx: &@fn_ctxt, parent: &block_parent, kind: block_kind, - name: &str) -> @block_ctxt { +fn new_block_ctxt(cx: @fn_ctxt, parent: block_parent, kind: block_kind, + name: str) -> @block_ctxt { let s = ""; if cx.lcx.ccx.sess.get_opts().save_temps || cx.lcx.ccx.sess.get_opts().debuginfo { @@ -4501,30 +4484,29 @@ fn new_block_ctxt(cx: &@fn_ctxt, parent: &block_parent, kind: block_kind, // Use this when you're at the top block of a function or the like. -fn new_top_block_ctxt(fcx: &@fn_ctxt) -> @block_ctxt { +fn new_top_block_ctxt(fcx: @fn_ctxt) -> @block_ctxt { ret new_block_ctxt(fcx, parent_none, SCOPE_BLOCK, "function top level"); } // Use this when you're at a curly-brace or similar lexical scope. -fn new_scope_block_ctxt(bcx: &@block_ctxt, n: &str) -> @block_ctxt { +fn new_scope_block_ctxt(bcx: @block_ctxt, n: str) -> @block_ctxt { ret new_block_ctxt(bcx.fcx, parent_some(bcx), SCOPE_BLOCK, n); } -fn new_loop_scope_block_ctxt(bcx: &@block_ctxt, - _cont: &option::t<@block_ctxt>, - _break: &@block_ctxt, n: &str) -> @block_ctxt { +fn new_loop_scope_block_ctxt(bcx: @block_ctxt, _cont: option::t<@block_ctxt>, + _break: @block_ctxt, n: str) -> @block_ctxt { ret new_block_ctxt(bcx.fcx, parent_some(bcx), LOOP_SCOPE_BLOCK(_cont, _break), n); } // Use this when you're making a general CFG BB within a scope. -fn new_sub_block_ctxt(bcx: &@block_ctxt, n: &str) -> @block_ctxt { +fn new_sub_block_ctxt(bcx: @block_ctxt, n: str) -> @block_ctxt { ret new_block_ctxt(bcx.fcx, parent_some(bcx), NON_SCOPE_BLOCK, n); } -fn new_raw_block_ctxt(fcx: &@fn_ctxt, llbb: BasicBlockRef) -> @block_ctxt { +fn new_raw_block_ctxt(fcx: @fn_ctxt, llbb: BasicBlockRef) -> @block_ctxt { ret @{llbb: llbb, mutable terminated: false, parent: parent_none, @@ -4542,7 +4524,7 @@ fn new_raw_block_ctxt(fcx: &@fn_ctxt, llbb: BasicBlockRef) -> @block_ctxt { // need to make sure those variables go out of scope when the block ends. We // do that by running a 'cleanup' function for each variable. // trans_block_cleanups runs all the cleanup functions for the block. -fn trans_block_cleanups(cx: &@block_ctxt, cleanup_cx: &@block_ctxt) -> +fn trans_block_cleanups(cx: @block_ctxt, cleanup_cx: @block_ctxt) -> @block_ctxt { let bcx = cx; if cleanup_cx.kind == NON_SCOPE_BLOCK { @@ -4560,7 +4542,7 @@ fn trans_block_cleanups(cx: &@block_ctxt, cleanup_cx: &@block_ctxt) -> ret bcx; } -fn trans_fn_cleanups(fcx: &@fn_ctxt, cx: &@block_ctxt) { +fn trans_fn_cleanups(fcx: @fn_ctxt, cx: @block_ctxt) { alt fcx.llobstacktoken { some(lltoken_) { let lltoken = lltoken_; // satisfy alias checker @@ -4571,7 +4553,7 @@ fn trans_fn_cleanups(fcx: &@fn_ctxt, cx: &@block_ctxt) { } } -iter block_locals(b: &ast::blk) -> @ast::local { +iter block_locals(b: ast::blk) -> @ast::local { // FIXME: putting from inside an iter block doesn't work, so we can't // use the index here. @@ -4590,7 +4572,7 @@ iter block_locals(b: &ast::blk) -> @ast::local { } } -fn llstaticallocas_block_ctxt(fcx: &@fn_ctxt) -> @block_ctxt { +fn llstaticallocas_block_ctxt(fcx: @fn_ctxt) -> @block_ctxt { ret @{llbb: fcx.llstaticallocas, mutable terminated: false, parent: parent_none, @@ -4600,7 +4582,7 @@ fn llstaticallocas_block_ctxt(fcx: &@fn_ctxt) -> @block_ctxt { fcx: fcx}; } -fn llderivedtydescs_block_ctxt(fcx: &@fn_ctxt) -> @block_ctxt { +fn llderivedtydescs_block_ctxt(fcx: @fn_ctxt) -> @block_ctxt { ret @{llbb: fcx.llderivedtydescs, mutable terminated: false, parent: parent_none, @@ -4611,23 +4593,23 @@ fn llderivedtydescs_block_ctxt(fcx: &@fn_ctxt) -> @block_ctxt { } -fn alloc_ty(cx: &@block_ctxt, t: ty::t) -> result { +fn alloc_ty(cx: @block_ctxt, t: ty::t) -> result { let bcx = cx; let ccx = bcx_ccx(cx); - let val = if check type_has_static_size(ccx, t) { - let sp = cx.sp; - alloca(bcx, type_of(ccx, sp, t)) - } - else { - // NB: we have to run this particular 'size_of' in a - // block_ctxt built on the llderivedtydescs block for the fn, - // so that the size dominates the array_alloca that - // comes next. - - let n = size_of(llderivedtydescs_block_ctxt(bcx.fcx), t); - bcx.fcx.llderivedtydescs = n.bcx.llbb; - dynastack_alloca(bcx, T_i8(), n.val, t) - }; + let val = + if check type_has_static_size(ccx, t) { + let sp = cx.sp; + alloca(bcx, type_of(ccx, sp, t)) + } else { + // NB: we have to run this particular 'size_of' in a + // block_ctxt built on the llderivedtydescs block for the fn, + // so that the size dominates the array_alloca that + // comes next. + + let n = size_of(llderivedtydescs_block_ctxt(bcx.fcx), t); + bcx.fcx.llderivedtydescs = n.bcx.llbb; + dynastack_alloca(bcx, T_i8(), n.val, t) + }; // NB: since we've pushed all size calculations in this // function up to the alloca block, we actually return the @@ -4643,7 +4625,7 @@ fn alloc_ty(cx: &@block_ctxt, t: ty::t) -> result { ret rslt(cx, val); } -fn alloc_local(cx: &@block_ctxt, local: &@ast::local) -> result { +fn alloc_local(cx: @block_ctxt, local: @ast::local) -> result { let t = node_id_type(bcx_ccx(cx), local.node.id); let r = alloc_ty(cx, t); alt local.node.pat.node { @@ -4659,8 +4641,7 @@ fn alloc_local(cx: &@block_ctxt, local: &@ast::local) -> result { ret r; } -fn trans_block(cx: &@block_ctxt, b: &ast::blk, output: &out_method) -> - result { +fn trans_block(cx: @block_ctxt, b: ast::blk, output: out_method) -> result { let bcx = cx; for each local: @ast::local in block_locals(b) { // FIXME Update bcx.sp @@ -4677,7 +4658,7 @@ fn trans_block(cx: &@block_ctxt, b: &ast::blk, output: &out_method) -> // we're in dead-code land. Stop here. if is_terminated(bcx) { ret r; } } - fn accept_out_method(expr: &@ast::expr) -> bool { + fn accept_out_method(expr: @ast::expr) -> bool { ret alt expr.node { ast::expr_if(_, _, _) { true } ast::expr_alt(_, _) { true } @@ -4717,7 +4698,7 @@ fn trans_block(cx: &@block_ctxt, b: &ast::blk, output: &out_method) -> ret rslt(bcx, r.val); } -fn new_local_ctxt(ccx: &@crate_ctxt) -> @local_ctxt { +fn new_local_ctxt(ccx: @crate_ctxt) -> @local_ctxt { let pth: [str] = []; ret @{path: pth, module_path: [ccx.link_meta.name], @@ -4759,7 +4740,7 @@ fn mk_standard_basic_blocks(llfn: ValueRef) -> // - create_llargs_for_fn_args. // - new_fn_ctxt // - trans_args -fn new_fn_ctxt_w_id(cx: @local_ctxt, sp: &span, llfndecl: ValueRef, +fn new_fn_ctxt_w_id(cx: @local_ctxt, sp: span, llfndecl: ValueRef, id: ast::node_id) -> @fn_ctxt { let llretptr: ValueRef = llvm::LLVMGetParam(llfndecl, 0u); let lltaskptr: ValueRef = llvm::LLVMGetParam(llfndecl, 1u); @@ -4799,7 +4780,7 @@ fn new_fn_ctxt_w_id(cx: @local_ctxt, sp: &span, llfndecl: ValueRef, lcx: cx}; } -fn new_fn_ctxt(cx: @local_ctxt, sp: &span, llfndecl: ValueRef) -> @fn_ctxt { +fn new_fn_ctxt(cx: @local_ctxt, sp: span, llfndecl: ValueRef) -> @fn_ctxt { be new_fn_ctxt_w_id(cx, sp, llfndecl, -1); } @@ -4817,9 +4798,9 @@ fn new_fn_ctxt(cx: @local_ctxt, sp: &span, llfndecl: ValueRef) -> @fn_ctxt { // spaces that have been created for them (by code in the llallocas field of // the function's fn_ctxt). create_llargs_for_fn_args populates the llargs // field of the fn_ctxt with -fn create_llargs_for_fn_args(cx: &@fn_ctxt, proto: ast::proto, +fn create_llargs_for_fn_args(cx: @fn_ctxt, proto: ast::proto, ty_self: option::t<ty::t>, ret_ty: ty::t, - args: &[ast::arg], ty_params: &[ast::ty_param]) { + args: [ast::arg], ty_params: [ast::ty_param]) { // Skip the implicit arguments 0, 1, and 2. TODO: Pull out 3u and define // it as a constant, since we're using it in several places in trans this // way. @@ -4859,8 +4840,8 @@ fn create_llargs_for_fn_args(cx: &@fn_ctxt, proto: ast::proto, } } -fn copy_args_to_allocas(fcx: @fn_ctxt, scope: @block_ctxt, args: &[ast::arg], - arg_tys: &[ty::arg], ignore_mut: bool) { +fn copy_args_to_allocas(fcx: @fn_ctxt, scope: @block_ctxt, args: [ast::arg], + arg_tys: [ty::arg], ignore_mut: bool) { let llcopyargs = new_raw_block_ctxt(fcx, fcx.llcopyargs); let bcx = llcopyargs; let arg_n: uint = 0u; @@ -4868,15 +4849,17 @@ fn copy_args_to_allocas(fcx: @fn_ctxt, scope: @block_ctxt, args: &[ast::arg], let arg_ty = arg_tys[arg_n].ty; alt aarg.mode { ast::by_ref. { - let mutated = !ignore_mut && - fcx.lcx.ccx.mut_map.contains_key(aarg.id); + let mutated = + !ignore_mut && fcx.lcx.ccx.mut_map.contains_key(aarg.id); + // Overwrite the llargs entry for locally mutated params // with a local alloca. if mutated { let aptr = bcx.fcx.llargs.get(aarg.id); - let {bcx, val: alloc} = alloc_ty(bcx, arg_ty); - bcx = copy_val(bcx, INIT, alloc, - load_if_immediate(bcx, aptr, arg_ty), arg_ty); + let {bcx: bcx, val: alloc} = alloc_ty(bcx, arg_ty); + bcx = + copy_val(bcx, INIT, alloc, + load_if_immediate(bcx, aptr, arg_ty), arg_ty); bcx.fcx.llargs.insert(aarg.id, alloc); add_clean(scope, alloc, arg_ty); } @@ -4891,12 +4874,12 @@ fn copy_args_to_allocas(fcx: @fn_ctxt, scope: @block_ctxt, args: &[ast::arg], fcx.llcopyargs = llcopyargs.llbb; } -fn is_terminated(cx: &@block_ctxt) -> bool { +fn is_terminated(cx: @block_ctxt) -> bool { let inst = llvm::LLVMGetLastInstruction(cx.llbb); ret llvm::LLVMIsATerminatorInst(inst) as int != 0; } -fn arg_tys_of_fn(ccx: &@crate_ctxt, id: ast::node_id) -> [ty::arg] { +fn arg_tys_of_fn(ccx: @crate_ctxt, id: ast::node_id) -> [ty::arg] { alt ty::struct(ccx.tcx, ty::node_id_to_type(ccx.tcx, id)) { ty::ty_fn(_, arg_tys, _, _, _) { ret arg_tys; } } @@ -4924,8 +4907,9 @@ fn populate_fn_ctxt_from_llself(fcx: @fn_ctxt, llself: val_self_pair) { // The object fields immediately follow the type parameters, so we skip // over them to get the pointer. - let obj_fields = PointerCast(bcx, GEP(bcx, obj_typarams, [C_int(1)]), - T_ptr(type_of_or_i8(bcx, fields_tup_ty))); + let obj_fields = + PointerCast(bcx, GEP(bcx, obj_typarams, [C_int(1)]), + T_ptr(type_of_or_i8(bcx, fields_tup_ty))); let i: int = 0; for p: ast::ty_param in fcx.lcx.obj_typarams { @@ -4949,7 +4933,7 @@ fn populate_fn_ctxt_from_llself(fcx: @fn_ctxt, llself: val_self_pair) { // Ties up the llstaticallocas -> llcopyargs -> llderivedtydescs -> // lldynamicallocas -> lltop edges, and builds the return block. -fn finish_fn(fcx: &@fn_ctxt, lltop: BasicBlockRef) { +fn finish_fn(fcx: @fn_ctxt, lltop: BasicBlockRef) { Br(new_raw_block_ctxt(fcx, fcx.llstaticallocas), fcx.llcopyargs); Br(new_raw_block_ctxt(fcx, fcx.llcopyargs), fcx.llderivedtydescs_first); Br(new_raw_block_ctxt(fcx, fcx.llderivedtydescs), fcx.lldynamicallocas); @@ -4963,10 +4947,10 @@ fn finish_fn(fcx: &@fn_ctxt, lltop: BasicBlockRef) { // trans_closure: Builds an LLVM function out of a source function. // If the function closes over its environment a closure will be // returned. -fn trans_closure(bcx_maybe: &option::t<@block_ctxt>, - llfnty: &option::t<TypeRef>, cx: @local_ctxt, sp: &span, - f: &ast::_fn, llfndecl: ValueRef, ty_self: option::t<ty::t>, - ty_params: &[ast::ty_param], id: ast::node_id) -> +fn trans_closure(bcx_maybe: option::t<@block_ctxt>, + llfnty: option::t<TypeRef>, cx: @local_ctxt, sp: span, + f: ast::_fn, llfndecl: ValueRef, ty_self: option::t<ty::t>, + ty_params: [ast::ty_param], id: ast::node_id) -> option::t<{fn_pair: ValueRef, bcx: @block_ctxt}> { set_uwtable(llfndecl); @@ -5035,17 +5019,17 @@ fn trans_closure(bcx_maybe: &option::t<@block_ctxt>, ret res; } -fn trans_fn_inner(cx: @local_ctxt, sp: &span, f: &ast::_fn, - llfndecl: ValueRef, ty_self: option::t<ty::t>, - ty_params: &[ast::ty_param], id: ast::node_id) { +fn trans_fn_inner(cx: @local_ctxt, sp: span, f: ast::_fn, llfndecl: ValueRef, + ty_self: option::t<ty::t>, ty_params: [ast::ty_param], + id: ast::node_id) { trans_closure(none, none, cx, sp, f, llfndecl, ty_self, ty_params, id); } // trans_fn: creates an LLVM function corresponding to a source language // function. -fn trans_fn(cx: @local_ctxt, sp: &span, f: &ast::_fn, llfndecl: ValueRef, - ty_self: option::t<ty::t>, ty_params: &[ast::ty_param], +fn trans_fn(cx: @local_ctxt, sp: span, f: ast::_fn, llfndecl: ValueRef, + ty_self: option::t<ty::t>, ty_params: [ast::ty_param], id: ast::node_id) { if !cx.ccx.sess.get_opts().stats { trans_fn_inner(cx, sp, f, llfndecl, ty_self, ty_params, id); @@ -5058,8 +5042,8 @@ fn trans_fn(cx: @local_ctxt, sp: &span, f: &ast::_fn, llfndecl: ValueRef, log_fn_time(cx.ccx, str::connect(cx.path, "::"), start, end); } -fn trans_res_ctor(cx: @local_ctxt, sp: &span, dtor: &ast::_fn, - ctor_id: ast::node_id, ty_params: &[ast::ty_param]) { +fn trans_res_ctor(cx: @local_ctxt, sp: span, dtor: ast::_fn, + ctor_id: ast::node_id, ty_params: [ast::ty_param]) { // Create a function for the constructor let llctor_decl; alt cx.ccx.item_ids.find(ctor_id) { @@ -5097,8 +5081,8 @@ fn trans_res_ctor(cx: @local_ctxt, sp: &span, dtor: &ast::_fn, fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id, - variant: &ast::variant, index: int, is_degen: bool, - ty_params: &[ast::ty_param]) { + variant: ast::variant, index: int, is_degen: bool, + ty_params: [ast::ty_param]) { if std::vec::len::<ast::variant_arg>(variant.node.args) == 0u { ret; // nullary constructors are just constants @@ -5176,9 +5160,7 @@ fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id, ty::type_has_dynamic_size(cx.ccx.tcx, arg_ty) || ty::type_is_unique(cx.ccx.tcx, arg_ty) { llargval = llargptr; - } else { - llargval = Load(bcx, llargptr); - } + } else { llargval = Load(bcx, llargptr); } bcx = copy_val(bcx, INIT, lldestptr, llargval, arg_ty); i += 1u; } @@ -5191,14 +5173,14 @@ fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id, // FIXME: this should do some structural hash-consing to avoid // duplicate constants. I think. Maybe LLVM has a magical mode // that does so later on? -fn trans_const_expr(cx: &@crate_ctxt, e: @ast::expr) -> ValueRef { +fn trans_const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef { alt e.node { ast::expr_lit(lit) { ret trans_crate_lit(cx, *lit); } _ { cx.sess.span_unimpl(e.span, "consts that's not a plain literal"); } } } -fn trans_const(cx: &@crate_ctxt, e: @ast::expr, id: ast::node_id) { +fn trans_const(cx: @crate_ctxt, e: @ast::expr, id: ast::node_id) { let v = trans_const_expr(cx, e); // The scalars come back as 1st class LLVM vals @@ -5213,7 +5195,7 @@ fn trans_const(cx: &@crate_ctxt, e: @ast::expr, id: ast::node_id) { } } -fn trans_item(cx: @local_ctxt, item: &ast::item) { +fn trans_item(cx: @local_ctxt, item: ast::item) { alt item.node { ast::item_fn(f, tps) { let sub_cx = extend_path(cx, item.ident); @@ -5272,7 +5254,7 @@ fn trans_item(cx: @local_ctxt, item: &ast::item) { // separate modules in the compiled program. That's because modules exist // only as a convenience for humans working with the code, to organize names // and control visibility. -fn trans_mod(cx: @local_ctxt, m: &ast::_mod) { +fn trans_mod(cx: @local_ctxt, m: ast::_mod) { for item: @ast::item in m.items { trans_item(cx, *item); } } @@ -5282,15 +5264,15 @@ fn get_pair_fn_ty(llpairty: TypeRef) -> TypeRef { ret struct_elt(llpairty, 0u); } -fn decl_fn_and_pair(ccx: &@crate_ctxt, sp: &span, path: &[str], flav: &str, - ty_params: &[ast::ty_param], node_id: ast::node_id) { +fn decl_fn_and_pair(ccx: @crate_ctxt, sp: span, path: [str], flav: str, + ty_params: [ast::ty_param], node_id: ast::node_id) { decl_fn_and_pair_full(ccx, sp, path, flav, ty_params, node_id, node_id_type(ccx, node_id)); } -fn decl_fn_and_pair_full(ccx: &@crate_ctxt, sp: &span, path: &[str], - _flav: &str, ty_params: &[ast::ty_param], - node_id: ast::node_id, node_type: ty::t) { +fn decl_fn_and_pair_full(ccx: @crate_ctxt, sp: span, path: [str], _flav: str, + ty_params: [ast::ty_param], node_id: ast::node_id, + node_type: ty::t) { let path = path; let llfty = type_of_fn_from_ty(ccx, sp, node_type, std::vec::len(ty_params)); @@ -5315,7 +5297,7 @@ fn decl_fn_and_pair_full(ccx: &@crate_ctxt, sp: &span, path: &[str], // Create a _rust_main(args: [str]) function which will be called from the // runtime rust_start function -fn create_main_wrapper(ccx: &@crate_ctxt, sp: &span, main_llfn: ValueRef, +fn create_main_wrapper(ccx: @crate_ctxt, sp: span, main_llfn: ValueRef, main_node_type: ty::t) { if ccx.main_fn != none::<ValueRef> { @@ -5330,7 +5312,7 @@ fn create_main_wrapper(ccx: &@crate_ctxt, sp: &span, main_llfn: ValueRef, let llfn = create_main(ccx, sp, main_llfn, main_takes_argv); ccx.main_fn = some(llfn); - fn create_main(ccx: &@crate_ctxt, sp: &span, main_llfn: ValueRef, + fn create_main(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 = @@ -5371,7 +5353,7 @@ fn create_main_wrapper(ccx: &@crate_ctxt, sp: &span, main_llfn: ValueRef, // Create a closure: a pair containing (1) a ValueRef, pointing to where the // fn's definition is in the executable we're creating, and (2) a pointer to // space for the function's environment. -fn create_fn_pair(cx: &@crate_ctxt, ps: &str, llfnty: TypeRef, llfn: ValueRef, +fn create_fn_pair(cx: @crate_ctxt, ps: str, llfnty: TypeRef, llfn: ValueRef, external: bool) -> ValueRef { let gvar = str::as_buf(ps, @@ -5392,7 +5374,7 @@ fn create_fn_pair(cx: &@crate_ctxt, ps: &str, llfnty: TypeRef, llfn: ValueRef, // Create a /real/ closure: this is like create_fn_pair, but creates a // a fn value on the stack with a specified environment (which need not be // on the stack). -fn create_real_fn_pair(cx: &@block_ctxt, llfnty: TypeRef, llfn: ValueRef, +fn create_real_fn_pair(cx: @block_ctxt, llfnty: TypeRef, llfn: ValueRef, llenvptr: ValueRef) -> ValueRef { let lcx = cx.fcx.lcx; @@ -5406,8 +5388,8 @@ fn create_real_fn_pair(cx: &@block_ctxt, llfnty: TypeRef, llfn: ValueRef, ret pair; } -fn register_fn_pair(cx: &@crate_ctxt, ps: &str, llfnty: TypeRef, - llfn: ValueRef, id: ast::node_id) { +fn register_fn_pair(cx: @crate_ctxt, ps: str, llfnty: TypeRef, llfn: ValueRef, + id: ast::node_id) { // FIXME: We should also hide the unexported pairs in crates. let gvar = @@ -5419,7 +5401,7 @@ fn register_fn_pair(cx: &@crate_ctxt, ps: &str, llfnty: TypeRef, // Returns the number of type parameters that the given native function has. -fn native_fn_ty_param_count(cx: &@crate_ctxt, id: ast::node_id) -> uint { +fn native_fn_ty_param_count(cx: @crate_ctxt, id: ast::node_id) -> uint { let count; let native_item = alt cx.ast_map.find(id) { some(ast_map::node_native_item(i)) { i } }; @@ -5435,7 +5417,7 @@ fn native_fn_ty_param_count(cx: &@crate_ctxt, id: ast::node_id) -> uint { ret count; } -fn native_fn_wrapper_type(cx: &@crate_ctxt, sp: &span, ty_param_count: uint, +fn native_fn_wrapper_type(cx: @crate_ctxt, sp: span, ty_param_count: uint, x: ty::t) -> TypeRef { alt ty::struct(cx.tcx, x) { ty::ty_native_fn(abi, args, out) { @@ -5444,8 +5426,8 @@ fn native_fn_wrapper_type(cx: &@crate_ctxt, sp: &span, ty_param_count: uint, } } -fn decl_native_fn_and_pair(ccx: &@crate_ctxt, sp: &span, path: &[str], - name: &str, id: ast::node_id) { +fn decl_native_fn_and_pair(ccx: @crate_ctxt, sp: span, path: [str], name: str, + id: ast::node_id) { let path = path; let num_ty_param = native_fn_ty_param_count(ccx, id); // Declare the wrapper. @@ -5526,7 +5508,7 @@ fn decl_native_fn_and_pair(ccx: &@crate_ctxt, sp: &span, path: &[str], } else { call_args += [llarg]; } arg_n += 1u; } - fn convert_arg_to_i32(cx: &@block_ctxt, v: ValueRef, t: ty::t, + fn convert_arg_to_i32(cx: @block_ctxt, v: ValueRef, t: ty::t, mode: ty::mode) -> ValueRef { if mode == ast::by_ref { if ty::type_is_integral(bcx_tcx(cx), t) { @@ -5535,7 +5517,7 @@ fn decl_native_fn_and_pair(ccx: &@crate_ctxt, sp: &span, path: &[str], let lldsttype = T_int(); let ccx = bcx_ccx(cx); let sp = cx.sp; - check type_has_static_size(ccx, t); + check (type_has_static_size(ccx, t)); let llsrctype = type_of(ccx, sp, t); if llvm::LLVMGetIntTypeWidth(lldsttype) > llvm::LLVMGetIntTypeWidth(llsrctype) { @@ -5548,7 +5530,7 @@ fn decl_native_fn_and_pair(ccx: &@crate_ctxt, sp: &span, path: &[str], ret vp2i(cx, v); } - fn trans_simple_native_abi(bcx: &@block_ctxt, name: &str, + fn trans_simple_native_abi(bcx: @block_ctxt, name: str, call_args: &mutable [ValueRef], fn_type: ty::t, uses_retptr: bool, cc: uint) -> {val: ValueRef, rptr: ValueRef} { @@ -5557,11 +5539,12 @@ fn decl_native_fn_and_pair(ccx: &@crate_ctxt, sp: &span, path: &[str], let ccx = bcx_ccx(bcx); let llnativefnty = - if uses_retptr { T_fn(call_arg_tys, T_void()) } - else { + if uses_retptr { + T_fn(call_arg_tys, T_void()) + } else { let fn_ret_ty = ty::ty_fn_ret(bcx_tcx(bcx), fn_type); // FIXME: Could follow from a constraint on fn_type... - check type_has_static_size(ccx, fn_ret_ty); + check (type_has_static_size(ccx, fn_ret_ty)); let sp = bcx.sp; T_fn(call_arg_tys, type_of(ccx, sp, fn_ret_ty)) }; @@ -5619,7 +5602,8 @@ fn decl_native_fn_and_pair(ccx: &@crate_ctxt, sp: &span, path: &[str], rptr = result.rptr; } _ { - r = trans_native_call(new_raw_block_ctxt(bcx.fcx, bcx.llbb), + r = + trans_native_call(new_raw_block_ctxt(bcx.fcx, bcx.llbb), ccx.externs, ccx.llmod, name, call_args); rptr = BitCast(bcx, fcx.llretptr, T_ptr(T_i32())); } @@ -5634,10 +5618,10 @@ fn decl_native_fn_and_pair(ccx: &@crate_ctxt, sp: &span, path: &[str], finish_fn(fcx, lltop); } -fn item_path(item: &@ast::item) -> [str] { ret [item.ident]; } +fn item_path(item: @ast::item) -> [str] { ret [item.ident]; } -fn collect_native_item(ccx: @crate_ctxt, i: &@ast::native_item, pt: &[str], - _v: &vt<[str]>) { +fn collect_native_item(ccx: @crate_ctxt, i: @ast::native_item, pt: [str], + _v: vt<[str]>) { alt i.node { ast::native_item_fn(_, _, _) { if !ccx.obj_methods.contains_key(i.id) { @@ -5648,8 +5632,7 @@ 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(_, _) { @@ -5657,12 +5640,16 @@ fn collect_item_1(ccx: @crate_ctxt, i: &@ast::item, pt: &[str], let s = mangle_exported_name(ccx, pt + [i.ident], node_id_type(ccx, i.id)); - let g = str::as_buf(s, { |buf| - // FIXME: Could follow from a constraint on types of const - // items - check type_has_static_size(ccx, typ); - llvm::LLVMAddGlobal(ccx.llmod, type_of(ccx, i.span, typ), buf) - }); + let g = str::as_buf + (s, + // FIXME: Could follow from a constraint on types of const + // items + {|buf| + check (type_has_static_size(ccx, typ)); + llvm::LLVMAddGlobal(ccx.llmod, + type_of(ccx, i.span, typ), + buf) + }); ccx.item_symbols.insert(i.id, s); ccx.consts.insert(i.id, g); } @@ -5670,8 +5657,7 @@ fn collect_item_1(ccx: @crate_ctxt, i: &@ast::item, pt: &[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 { @@ -5699,7 +5685,7 @@ fn collect_item_2(ccx: &@crate_ctxt, i: &@ast::item, pt: &[str], } } -fn collect_items(ccx: &@crate_ctxt, crate: @ast::crate) { +fn collect_items(ccx: @crate_ctxt, crate: @ast::crate) { let visitor0 = visit::default_visitor(); let visitor1 = @{visit_native_item: bind collect_native_item(ccx, _, _, _), @@ -5710,8 +5696,8 @@ 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], - v: &vt<[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); alt i.node { @@ -5727,7 +5713,7 @@ fn collect_tag_ctor(ccx: @crate_ctxt, i: &@ast::item, pt: &[str], } } -fn collect_tag_ctors(ccx: &@crate_ctxt, crate: @ast::crate) { +fn collect_tag_ctors(ccx: @crate_ctxt, crate: @ast::crate) { let visitor = @{visit_item: bind collect_tag_ctor(ccx, _, _, _) with *visit::default_visitor()}; @@ -5736,8 +5722,7 @@ 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 { @@ -5764,14 +5749,14 @@ fn trans_constant(ccx: @crate_ctxt, it: &@ast::item, pt: &[str], } } -fn trans_constants(ccx: &@crate_ctxt, crate: @ast::crate) { +fn trans_constants(ccx: @crate_ctxt, crate: @ast::crate) { let visitor = @{visit_item: bind trans_constant(ccx, _, _, _) with *visit::default_visitor()}; visit::visit_crate(*crate, [], visit::mk_vt(visitor)); } -fn vp2i(cx: &@block_ctxt, v: ValueRef) -> ValueRef { +fn vp2i(cx: @block_ctxt, v: ValueRef) -> ValueRef { ret PtrToInt(cx, v, T_int()); } @@ -5817,7 +5802,7 @@ fn declare_intrinsics(llmod: ModuleRef) -> hashmap<str, ValueRef> { ret intrinsics; } -fn trap(bcx: &@block_ctxt) { +fn trap(bcx: @block_ctxt) { let v: [ValueRef] = []; alt bcx_ccx(bcx).intrinsics.find("llvm.trap") { some(x) { Call(bcx, x, v); } @@ -5834,7 +5819,7 @@ fn make_glues(llmod: ModuleRef, taskptr_type: TypeRef) -> @glue_fns { ret @{no_op_type_glue: decl_no_op_type_glue(llmod, taskptr_type)}; } -fn make_common_glue(sess: &session::session, output: &str) { +fn make_common_glue(sess: session::session, output: str) { // FIXME: part of this is repetitive and is probably a good idea // to autogen it. let task_type = T_task(); @@ -5842,9 +5827,9 @@ fn make_common_glue(sess: &session::session, output: &str) { let llmod = str::as_buf("rust_out", {|buf| - llvm::LLVMModuleCreateWithNameInContext( - buf, llvm::LLVMGetGlobalContext()) - }); + llvm::LLVMModuleCreateWithNameInContext + (buf, llvm::LLVMGetGlobalContext()) + }); let _: () = str::as_buf(x86::get_data_layout(), {|buf| llvm::LLVMSetDataLayout(llmod, buf) }); @@ -5860,7 +5845,7 @@ fn make_common_glue(sess: &session::session, output: &str) { link::write::run_passes(sess, llmod, output); } -fn create_module_map(ccx: &@crate_ctxt) -> ValueRef { +fn create_module_map(ccx: @crate_ctxt) -> ValueRef { let elttype = T_struct([T_int(), T_int()]); let maptype = T_array(elttype, ccx.module_data.size() + 1u); let map = @@ -5881,7 +5866,7 @@ fn create_module_map(ccx: &@crate_ctxt) -> ValueRef { // FIXME use hashed metadata instead of crate names once we have that -fn create_crate_map(ccx: &@crate_ctxt) -> ValueRef { +fn create_crate_map(ccx: @crate_ctxt) -> ValueRef { let subcrates: [ValueRef] = []; let i = 1; let cstore = ccx.sess.get_cstore(); @@ -5914,7 +5899,7 @@ fn create_crate_map(ccx: &@crate_ctxt) -> ValueRef { ret map; } -fn write_metadata(cx: &@crate_ctxt, crate: &@ast::crate) { +fn write_metadata(cx: @crate_ctxt, crate: @ast::crate) { if !cx.sess.get_opts().library { ret; } let llmeta = C_postr(metadata::encoder::encode_metadata(cx, crate)); let llconst = trans_common::C_struct([llmeta]); @@ -5944,19 +5929,20 @@ fn write_metadata(cx: &@crate_ctxt, crate: &@ast::crate) { } // Writes the current ABI version into the crate. -fn write_abi_version(ccx: &@crate_ctxt) { +fn write_abi_version(ccx: @crate_ctxt) { shape::mk_global(ccx, "rust_abi_version", C_uint(abi::abi_version), false); } -fn trans_crate(sess: &session::session, crate: &@ast::crate, tcx: &ty::ctxt, - output: &str, amap: &ast_map::map, mut_map: mut::mut_map, +fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt, + output: str, amap: ast_map::map, mut_map: mut::mut_map, copy_map: alias::copy_map) -> ModuleRef { let llmod = - str::as_buf("rust_out", {|buf| - llvm::LLVMModuleCreateWithNameInContext( - buf, llvm::LLVMGetGlobalContext()) - }); + str::as_buf("rust_out", + {|buf| + llvm::LLVMModuleCreateWithNameInContext(buf, + llvm::LLVMGetGlobalContext()) + }); let _: () = str::as_buf(x86::get_data_layout(), {|buf| llvm::LLVMSetDataLayout(llmod, buf) }); diff --git a/src/comp/middle/trans_alt.rs b/src/comp/middle/trans_alt.rs index f8e844cc2d6..c72979c3bca 100644 --- a/src/comp/middle/trans_alt.rs +++ b/src/comp/middle/trans_alt.rs @@ -28,7 +28,7 @@ tag opt { lit(@ast::lit); var(/* variant id */uint, /* variant dids */{tg: def_id, var: def_id}); } -fn opt_eq(a: &opt, b: &opt) -> bool { +fn opt_eq(a: opt, b: opt) -> bool { alt a { lit(la) { ret alt b { lit(lb) { lit_eq(la, lb) } var(_, _) { false } }; @@ -38,14 +38,14 @@ fn opt_eq(a: &opt, b: &opt) -> bool { } } } -fn trans_opt(bcx: &@block_ctxt, o: &opt) -> result { +fn trans_opt(bcx: @block_ctxt, o: opt) -> result { alt o { lit(l) { ret trans::trans_lit(bcx, *l); } var(id, _) { ret rslt(bcx, C_int(id as int)); } } } -fn variant_opt(ccx: &@crate_ctxt, pat_id: ast::node_id) -> opt { +fn variant_opt(ccx: @crate_ctxt, pat_id: ast::node_id) -> opt { let vdef = ast_util::variant_def_ids(ccx.tcx.def_map.get(pat_id)); let variants = ty::tag_variants(ccx.tcx, vdef.tg); let i = 0u; @@ -57,7 +57,7 @@ fn variant_opt(ccx: &@crate_ctxt, pat_id: ast::node_id) -> opt { } type bind_map = [{ident: ast::ident, val: ValueRef}]; -fn assoc(key: &str, list: &bind_map) -> option::t<ValueRef> { +fn assoc(key: str, list: bind_map) -> option::t<ValueRef> { for elt: {ident: ast::ident, val: ValueRef} in list { if str::eq(elt.ident, key) { ret some(elt.val); } } @@ -73,7 +73,7 @@ type match_branch = id_map: ast_util::pat_id_map}}; type match = [match_branch]; -fn matches_always(p: &@ast::pat) -> bool { +fn matches_always(p: @ast::pat) -> bool { ret alt p.node { ast::pat_wild. { true } ast::pat_bind(_) { true } @@ -83,9 +83,9 @@ fn matches_always(p: &@ast::pat) -> bool { }; } -type enter_pat = fn(&@ast::pat) -> option::t<[@ast::pat]>; +type enter_pat = fn(@ast::pat) -> option::t<[@ast::pat]>; -fn enter_match(m: &match, col: uint, val: ValueRef, e: &enter_pat) -> match { +fn enter_match(m: match, col: uint, val: ValueRef, e: enter_pat) -> match { let result = []; for br: match_branch in m { alt e(br.pats[col]) { @@ -110,18 +110,18 @@ fn enter_match(m: &match, col: uint, val: ValueRef, e: &enter_pat) -> match { ret result; } -fn enter_default(m: &match, col: uint, val: ValueRef) -> match { - fn e(p: &@ast::pat) -> option::t<[@ast::pat]> { +fn enter_default(m: match, col: uint, val: ValueRef) -> match { + fn e(p: @ast::pat) -> option::t<[@ast::pat]> { ret if matches_always(p) { some([]) } else { none }; } ret enter_match(m, col, val, e); } -fn enter_opt(ccx: &@crate_ctxt, m: &match, opt: &opt, col: uint, - tag_size: uint, val: ValueRef) -> match { +fn enter_opt(ccx: @crate_ctxt, m: match, opt: opt, col: uint, tag_size: uint, + val: ValueRef) -> match { let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()}; - fn e(ccx: &@crate_ctxt, dummy: &@ast::pat, opt: &opt, size: uint, - p: &@ast::pat) -> option::t<[@ast::pat]> { + fn e(ccx: @crate_ctxt, dummy: @ast::pat, opt: opt, size: uint, + p: @ast::pat) -> option::t<[@ast::pat]> { alt p.node { ast::pat_tag(ctor, subpats) { ret if opt_eq(variant_opt(ccx, p.id), opt) { @@ -137,10 +137,10 @@ fn enter_opt(ccx: &@crate_ctxt, m: &match, opt: &opt, col: uint, ret enter_match(m, col, val, bind e(ccx, dummy, opt, tag_size, _)); } -fn enter_rec(m: &match, col: uint, fields: &[ast::ident], val: ValueRef) -> +fn enter_rec(m: match, col: uint, fields: [ast::ident], val: ValueRef) -> match { let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()}; - fn e(dummy: &@ast::pat, fields: &[ast::ident], p: &@ast::pat) -> + fn e(dummy: @ast::pat, fields: [ast::ident], p: @ast::pat) -> option::t<[@ast::pat]> { alt p.node { ast::pat_rec(fpats, _) { @@ -160,9 +160,9 @@ fn enter_rec(m: &match, col: uint, fields: &[ast::ident], val: ValueRef) -> ret enter_match(m, col, val, bind e(dummy, fields, _)); } -fn enter_tup(m: &match, col: uint, val: ValueRef, n_elts: uint) -> match { +fn enter_tup(m: match, col: uint, val: ValueRef, n_elts: uint) -> match { let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()}; - fn e(dummy: &@ast::pat, n_elts: uint, p: &@ast::pat) -> + fn e(dummy: @ast::pat, n_elts: uint, p: @ast::pat) -> option::t<[@ast::pat]> { alt p.node { ast::pat_tup(elts) { ret some(elts); } @@ -172,9 +172,9 @@ fn enter_tup(m: &match, col: uint, val: ValueRef, n_elts: uint) -> match { ret enter_match(m, col, val, bind e(dummy, n_elts, _)); } -fn enter_box(m: &match, col: uint, val: ValueRef) -> match { +fn enter_box(m: match, col: uint, val: ValueRef) -> match { let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()}; - fn e(dummy: &@ast::pat, p: &@ast::pat) -> option::t<[@ast::pat]> { + fn e(dummy: @ast::pat, p: @ast::pat) -> option::t<[@ast::pat]> { alt p.node { ast::pat_box(sub) { ret some([sub]); } _ { ret some([dummy]); } @@ -183,8 +183,8 @@ fn enter_box(m: &match, col: uint, val: ValueRef) -> match { ret enter_match(m, col, val, bind e(dummy, _)); } -fn get_options(ccx: &@crate_ctxt, m: &match, col: uint) -> [opt] { - fn add_to_set(set: &mutable [opt], val: &opt) { +fn get_options(ccx: @crate_ctxt, m: match, col: uint) -> [opt] { + fn add_to_set(set: &mutable [opt], val: opt) { for l: opt in set { if opt_eq(l, val) { ret; } } set += [val]; } @@ -203,7 +203,7 @@ fn get_options(ccx: &@crate_ctxt, m: &match, col: uint) -> [opt] { } fn extract_variant_args(bcx: @block_ctxt, pat_id: ast::node_id, - vdefs: &{tg: def_id, var: def_id}, val: ValueRef) -> + vdefs: {tg: def_id, var: def_id}, val: ValueRef) -> {vals: [ValueRef], bcx: @block_ctxt} { let ccx = bcx.fcx.lcx.ccx; let ty_param_substs = ty::node_id_to_type_params(ccx.tcx, pat_id); @@ -232,7 +232,7 @@ fn extract_variant_args(bcx: @block_ctxt, pat_id: ast::node_id, ret {vals: args, bcx: bcx}; } -fn collect_record_fields(m: &match, col: uint) -> [ast::ident] { +fn collect_record_fields(m: match, col: uint) -> [ast::ident] { let fields = []; for br: match_branch in m { alt br.pats[col].node { @@ -249,14 +249,14 @@ fn collect_record_fields(m: &match, col: uint) -> [ast::ident] { ret fields; } -fn any_box_pat(m: &match, col: uint) -> bool { +fn any_box_pat(m: match, col: uint) -> bool { for br: match_branch in m { alt br.pats[col].node { ast::pat_box(_) { ret true; } _ { } } } ret false; } -fn any_tup_pat(m: &match, col: uint) -> bool { +fn any_tup_pat(m: match, col: uint) -> bool { for br: match_branch in m { alt br.pats[col].node { ast::pat_tup(_) { ret true; } _ { } } } @@ -266,7 +266,7 @@ fn any_tup_pat(m: &match, col: uint) -> bool { type exit_node = {bound: bind_map, from: BasicBlockRef, to: BasicBlockRef}; type mk_fail = fn() -> BasicBlockRef; -fn pick_col(m: &match) -> uint { +fn pick_col(m: match) -> uint { let scores = vec::init_elt_mut(0u, vec::len(m[0].pats)); for br: match_branch in m { let i = 0u; @@ -293,8 +293,8 @@ fn pick_col(m: &match) -> uint { ret best_col; } -fn compile_submatch(bcx: @block_ctxt, m: &match, vals: [ValueRef], - f: &mk_fail, exits: &mutable [exit_node]) { +fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail, + exits: &mutable [exit_node]) { if vec::len(m) == 0u { Br(bcx, f()); ret; } if vec::len(m[0].pats) == 0u { let data = m[0].data; @@ -407,10 +407,11 @@ fn compile_submatch(bcx: @block_ctxt, m: &match, vals: [ValueRef], } } lit(l) { - kind = alt l.node { - ast::lit_str(_) { compare } - _ { test_val = Load(bcx, val); switch } - }; + kind = + alt l.node { + ast::lit_str(_) { compare } + _ { test_val = Load(bcx, val); switch } + }; } } } @@ -473,8 +474,8 @@ fn compile_submatch(bcx: @block_ctxt, m: &match, vals: [ValueRef], } // Returns false for unreachable blocks -fn make_phi_bindings(bcx: &@block_ctxt, map: &[exit_node], - ids: &ast_util::pat_id_map) -> bool { +fn make_phi_bindings(bcx: @block_ctxt, map: [exit_node], + ids: ast_util::pat_id_map) -> bool { let our_block = bcx.llbb as uint; let success = true; for each item: @{key: ast::ident, val: ast::node_id} in ids.items() { @@ -496,8 +497,8 @@ fn make_phi_bindings(bcx: &@block_ctxt, map: &[exit_node], ret success; } -fn trans_alt(cx: &@block_ctxt, expr: &@ast::expr, arms: &[ast::arm], - output: &trans::out_method) -> result { +fn trans_alt(cx: @block_ctxt, expr: @ast::expr, arms: [ast::arm], + output: trans::out_method) -> result { let bodies = []; let match: match = []; let er = trans::trans_expr(cx, expr); @@ -524,7 +525,7 @@ fn trans_alt(cx: &@block_ctxt, expr: &@ast::expr, arms: &[ast::arm], // Cached fail-on-fallthrough block let fail_cx = @mutable none; - fn mk_fail(cx: &@block_ctxt, sp: &span, + fn mk_fail(cx: @block_ctxt, sp: span, done: @mutable option::t<BasicBlockRef>) -> BasicBlockRef { alt *done { some(bb) { ret bb; } _ { } } let fail_cx = new_sub_block_ctxt(cx, "case_fallthrough"); @@ -556,7 +557,7 @@ fn trans_alt(cx: &@block_ctxt, expr: &@ast::expr, arms: &[ast::arm], } // Not alt-related, but similar to the pattern-munging code above -fn bind_irrefutable_pat(bcx: @block_ctxt, pat: &@ast::pat, val: ValueRef, +fn bind_irrefutable_pat(bcx: @block_ctxt, pat: @ast::pat, val: ValueRef, table: hashmap<ast::node_id, ValueRef>, make_copy: bool) -> @block_ctxt { let ccx = bcx.fcx.lcx.ccx; @@ -566,7 +567,7 @@ fn bind_irrefutable_pat(bcx: @block_ctxt, pat: &@ast::pat, val: ValueRef, let ty = ty::node_id_to_monotype(ccx.tcx, pat.id); // FIXME: Could constrain pat_bind to make this // check unnecessary. - check type_has_static_size(ccx, ty); + check (type_has_static_size(ccx, ty)); let llty = trans::type_of(ccx, pat.span, ty); let alloc = trans::alloca(bcx, llty); bcx = diff --git a/src/comp/middle/trans_build.rs b/src/comp/middle/trans_build.rs index 52b976e2844..ebf1b20c0ca 100644 --- a/src/comp/middle/trans_build.rs +++ b/src/comp/middle/trans_build.rs @@ -5,58 +5,58 @@ import llvm::{ValueRef, TypeRef, BasicBlockRef, BuilderRef, Opcode, ModuleRef}; import trans_common::block_ctxt; -fn B(cx: &@block_ctxt) -> BuilderRef { +fn B(cx: @block_ctxt) -> BuilderRef { let b = *cx.fcx.lcx.ccx.builder; llvm::LLVMPositionBuilderAtEnd(b, cx.llbb); ret b; } -fn RetVoid(cx: &@block_ctxt) -> ValueRef { +fn RetVoid(cx: @block_ctxt) -> ValueRef { assert (!cx.terminated); cx.terminated = true; ret llvm::LLVMBuildRetVoid(B(cx)); } -fn Ret(cx: &@block_ctxt, V: ValueRef) -> ValueRef { +fn Ret(cx: @block_ctxt, V: ValueRef) -> ValueRef { assert (!cx.terminated); cx.terminated = true; ret llvm::LLVMBuildRet(B(cx), V); } -fn AggregateRet(cx: &@block_ctxt, RetVals: &[ValueRef]) -> ValueRef { +fn AggregateRet(cx: @block_ctxt, RetVals: [ValueRef]) -> ValueRef { assert (!cx.terminated); cx.terminated = true; ret llvm::LLVMBuildAggregateRet(B(cx), vec::to_ptr(RetVals), vec::len(RetVals)); } -fn Br(cx: &@block_ctxt, Dest: BasicBlockRef) -> ValueRef { +fn Br(cx: @block_ctxt, Dest: BasicBlockRef) -> ValueRef { assert (!cx.terminated); cx.terminated = true; ret llvm::LLVMBuildBr(B(cx), Dest); } -fn CondBr(cx: &@block_ctxt, If: ValueRef, Then: BasicBlockRef, +fn CondBr(cx: @block_ctxt, If: ValueRef, Then: BasicBlockRef, Else: BasicBlockRef) -> ValueRef { assert (!cx.terminated); cx.terminated = true; ret llvm::LLVMBuildCondBr(B(cx), If, Then, Else); } -fn Switch(cx: &@block_ctxt, V: ValueRef, Else: BasicBlockRef, NumCases: uint) +fn Switch(cx: @block_ctxt, V: ValueRef, Else: BasicBlockRef, NumCases: uint) -> ValueRef { assert (!cx.terminated); cx.terminated = true; ret llvm::LLVMBuildSwitch(B(cx), V, Else, NumCases); } -fn IndirectBr(cx: &@block_ctxt, Addr: ValueRef, NumDests: uint) -> ValueRef { +fn IndirectBr(cx: @block_ctxt, Addr: ValueRef, NumDests: uint) -> ValueRef { assert (!cx.terminated); cx.terminated = true; ret llvm::LLVMBuildIndirectBr(B(cx), Addr, NumDests); } -fn Invoke(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef], +fn Invoke(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef], Then: BasicBlockRef, Catch: BasicBlockRef) -> ValueRef { assert (!cx.terminated); cx.terminated = true; @@ -68,172 +68,171 @@ fn Invoke(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef], }); } -fn Unreachable(cx: &@block_ctxt) -> ValueRef { +fn Unreachable(cx: @block_ctxt) -> ValueRef { assert (!cx.terminated); cx.terminated = true; ret llvm::LLVMBuildUnreachable(B(cx)); } /* Arithmetic */ -fn Add(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn Add(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildAdd(B(cx), LHS, RHS, buf) }); } -fn NSWAdd(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn NSWAdd(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildNSWAdd(B(cx), LHS, RHS, buf) }); } -fn NUWAdd(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn NUWAdd(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildNUWAdd(B(cx), LHS, RHS, buf) }); } -fn FAdd(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn FAdd(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildFAdd(B(cx), LHS, RHS, buf) }); } -fn Sub(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn Sub(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildSub(B(cx), LHS, RHS, buf) }); } -fn NSWSub(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn NSWSub(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildNSWSub(B(cx), LHS, RHS, buf) }); } -fn NUWSub(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn NUWSub(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildNUWSub(B(cx), LHS, RHS, buf) }); } -fn FSub(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn FSub(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildFSub(B(cx), LHS, RHS, buf) }); } -fn Mul(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn Mul(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildMul(B(cx), LHS, RHS, buf) }); } -fn NSWMul(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn NSWMul(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildNSWMul(B(cx), LHS, RHS, buf) }); } -fn NUWMul(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn NUWMul(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildNUWMul(B(cx), LHS, RHS, buf) }); } -fn FMul(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn FMul(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildFMul(B(cx), LHS, RHS, buf) }); } -fn UDiv(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn UDiv(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildUDiv(B(cx), LHS, RHS, buf) }); } -fn SDiv(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn SDiv(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildSDiv(B(cx), LHS, RHS, buf) }); } -fn ExactSDiv(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn ExactSDiv(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildExactSDiv(B(cx), LHS, RHS, buf) }); } -fn FDiv(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn FDiv(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildFDiv(B(cx), LHS, RHS, buf) }); } -fn URem(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn URem(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildURem(B(cx), LHS, RHS, buf) }); } -fn SRem(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn SRem(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildSRem(B(cx), LHS, RHS, buf) }); } -fn FRem(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn FRem(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildFRem(B(cx), LHS, RHS, buf) }); } -fn Shl(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn Shl(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildShl(B(cx), LHS, RHS, buf) }); } -fn LShr(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn LShr(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildLShr(B(cx), LHS, RHS, buf) }); } -fn AShr(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn AShr(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildAShr(B(cx), LHS, RHS, buf) }); } -fn And(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn And(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildAnd(B(cx), LHS, RHS, buf) }); } -fn Or(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn Or(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildOr(B(cx), LHS, RHS, buf) }); } -fn Xor(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn Xor(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildXor(B(cx), LHS, RHS, buf) }); } -fn BinOp(cx: &@block_ctxt, Op: Opcode, LHS: ValueRef, RHS: ValueRef) -> +fn BinOp(cx: @block_ctxt, Op: Opcode, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildBinOp(B(cx), Op, LHS, RHS, buf) }); } -fn Neg(cx: &@block_ctxt, V: ValueRef) -> ValueRef { +fn Neg(cx: @block_ctxt, V: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildNeg(B(cx), V, buf) }); } -fn NSWNeg(cx: &@block_ctxt, V: ValueRef) -> ValueRef { +fn NSWNeg(cx: @block_ctxt, V: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildNSWNeg(B(cx), V, buf) }); } -fn NUWNeg(cx: &@block_ctxt, V: ValueRef) -> ValueRef { +fn NUWNeg(cx: @block_ctxt, V: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildNUWNeg(B(cx), V, buf) }); } -fn FNeg(cx: &@block_ctxt, V: ValueRef) -> ValueRef { +fn FNeg(cx: @block_ctxt, V: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildFNeg(B(cx), V, buf) }); } -fn Not(cx: &@block_ctxt, V: ValueRef) -> ValueRef { +fn Not(cx: @block_ctxt, V: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildNot(B(cx), V, buf) }); } /* Memory */ -fn Malloc(cx: &@block_ctxt, Ty: TypeRef) -> ValueRef { +fn Malloc(cx: @block_ctxt, Ty: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildMalloc(B(cx), Ty, buf) }); } -fn ArrayMalloc(cx: &@block_ctxt, Ty: TypeRef, Val: ValueRef) -> ValueRef { +fn ArrayMalloc(cx: @block_ctxt, Ty: TypeRef, Val: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildArrayMalloc(B(cx), Ty, Val, buf) }); } -fn Alloca(cx: &@block_ctxt, Ty: TypeRef) -> ValueRef { +fn Alloca(cx: @block_ctxt, Ty: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildAlloca(B(cx), Ty, buf) }); } -fn ArrayAlloca(cx: &@block_ctxt, Ty: TypeRef, Val: ValueRef) -> ValueRef { +fn ArrayAlloca(cx: @block_ctxt, Ty: TypeRef, Val: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildArrayAlloca(B(cx), Ty, Val, buf) }); } -fn Free(cx: &@block_ctxt, PointerVal: ValueRef) -> ValueRef { +fn Free(cx: @block_ctxt, PointerVal: ValueRef) -> ValueRef { ret llvm::LLVMBuildFree(B(cx), PointerVal); } -fn Load(cx: &@block_ctxt, PointerVal: ValueRef) -> ValueRef { +fn Load(cx: @block_ctxt, PointerVal: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildLoad(B(cx), PointerVal, buf) }); } -fn Store(cx: &@block_ctxt, Val: ValueRef, Ptr: ValueRef) -> ValueRef { +fn Store(cx: @block_ctxt, Val: ValueRef, Ptr: ValueRef) -> ValueRef { ret llvm::LLVMBuildStore(B(cx), Val, Ptr); } -fn GEP(cx: &@block_ctxt, Pointer: ValueRef, Indices: &[ValueRef]) -> - ValueRef { +fn GEP(cx: @block_ctxt, Pointer: ValueRef, Indices: [ValueRef]) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildGEP(B(cx), Pointer, @@ -242,7 +241,7 @@ fn GEP(cx: &@block_ctxt, Pointer: ValueRef, Indices: &[ValueRef]) -> }); } -fn InBoundsGEP(cx: &@block_ctxt, Pointer: ValueRef, Indices: &[ValueRef]) -> +fn InBoundsGEP(cx: @block_ctxt, Pointer: ValueRef, Indices: [ValueRef]) -> ValueRef { ret str::as_buf("", {|buf| @@ -252,19 +251,19 @@ fn InBoundsGEP(cx: &@block_ctxt, Pointer: ValueRef, Indices: &[ValueRef]) -> }); } -fn StructGEP(cx: &@block_ctxt, Pointer: ValueRef, Idx: uint) -> ValueRef { +fn StructGEP(cx: @block_ctxt, Pointer: ValueRef, Idx: uint) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildStructGEP(B(cx), Pointer, Idx, buf) }); } -fn GlobalString(cx: &@block_ctxt, _Str: sbuf) -> ValueRef { +fn GlobalString(cx: @block_ctxt, _Str: sbuf) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildGlobalString(B(cx), _Str, buf) }); } -fn GlobalStringPtr(cx: &@block_ctxt, _Str: sbuf) -> ValueRef { +fn GlobalStringPtr(cx: @block_ctxt, _Str: sbuf) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildGlobalStringPtr(B(cx), _Str, buf) @@ -272,71 +271,71 @@ fn GlobalStringPtr(cx: &@block_ctxt, _Str: sbuf) -> ValueRef { } /* Casts */ -fn Trunc(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { +fn Trunc(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildTrunc(B(cx), Val, DestTy, buf) }); } -fn ZExt(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { +fn ZExt(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildZExt(B(cx), Val, DestTy, buf) }); } -fn SExt(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { +fn SExt(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildSExt(B(cx), Val, DestTy, buf) }); } -fn FPToUI(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { +fn FPToUI(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildFPToUI(B(cx), Val, DestTy, buf) }); } -fn FPToSI(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { +fn FPToSI(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildFPToSI(B(cx), Val, DestTy, buf) }); } -fn UIToFP(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { +fn UIToFP(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildUIToFP(B(cx), Val, DestTy, buf) }); } -fn SIToFP(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { +fn SIToFP(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildSIToFP(B(cx), Val, DestTy, buf) }); } -fn FPTrunc(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { +fn FPTrunc(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildFPTrunc(B(cx), Val, DestTy, buf) }); } -fn FPExt(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { +fn FPExt(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildFPExt(B(cx), Val, DestTy, buf) }); } -fn PtrToInt(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { +fn PtrToInt(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildPtrToInt(B(cx), Val, DestTy, buf) }); } -fn IntToPtr(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { +fn IntToPtr(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildIntToPtr(B(cx), Val, DestTy, buf) }); } -fn BitCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { +fn BitCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildBitCast(B(cx), Val, DestTy, buf) }); } -fn ZExtOrBitCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> +fn ZExtOrBitCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| @@ -344,7 +343,7 @@ fn ZExtOrBitCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> }); } -fn SExtOrBitCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> +fn SExtOrBitCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| @@ -352,7 +351,7 @@ fn SExtOrBitCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> }); } -fn TruncOrBitCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> +fn TruncOrBitCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| @@ -360,7 +359,7 @@ fn TruncOrBitCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> }); } -fn Cast(cx: &@block_ctxt, Op: Opcode, Val: ValueRef, DestTy: TypeRef, +fn Cast(cx: @block_ctxt, Op: Opcode, Val: ValueRef, DestTy: TypeRef, _Name: sbuf) -> ValueRef { ret str::as_buf("", {|buf| @@ -368,41 +367,39 @@ fn Cast(cx: &@block_ctxt, Op: Opcode, Val: ValueRef, DestTy: TypeRef, }); } -fn PointerCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { +fn PointerCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildPointerCast(B(cx), Val, DestTy, buf) }); } -fn IntCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { +fn IntCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildIntCast(B(cx), Val, DestTy, buf) }); } -fn FPCast(cx: &@block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { +fn FPCast(cx: @block_ctxt, Val: ValueRef, DestTy: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildFPCast(B(cx), Val, DestTy, buf) }); } /* Comparisons */ -fn ICmp(cx: &@block_ctxt, Op: uint, LHS: ValueRef, RHS: ValueRef) -> - ValueRef { +fn ICmp(cx: @block_ctxt, Op: uint, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildICmp(B(cx), Op, LHS, RHS, buf) }); } -fn FCmp(cx: &@block_ctxt, Op: uint, LHS: ValueRef, RHS: ValueRef) -> - ValueRef { +fn FCmp(cx: @block_ctxt, Op: uint, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildFCmp(B(cx), Op, LHS, RHS, buf) }); } /* Miscellaneous instructions */ -fn Phi(cx: &@block_ctxt, Ty: TypeRef, vals: &[ValueRef], - bbs: &[BasicBlockRef]) -> ValueRef { +fn Phi(cx: @block_ctxt, Ty: TypeRef, vals: [ValueRef], bbs: [BasicBlockRef]) + -> ValueRef { let phi = str::as_buf("", {|buf| llvm::LLVMBuildPhi(B(cx), Ty, buf) }); assert (vec::len::<ValueRef>(vals) == vec::len::<BasicBlockRef>(bbs)); llvm::LLVMAddIncoming(phi, vec::to_ptr(vals), vec::to_ptr(bbs), @@ -410,13 +407,13 @@ fn Phi(cx: &@block_ctxt, Ty: TypeRef, vals: &[ValueRef], ret phi; } -fn AddIncomingToPhi(phi: ValueRef, vals: &[ValueRef], bbs: &[BasicBlockRef]) { +fn AddIncomingToPhi(phi: ValueRef, vals: [ValueRef], bbs: [BasicBlockRef]) { assert (vec::len::<ValueRef>(vals) == vec::len::<BasicBlockRef>(bbs)); llvm::LLVMAddIncoming(phi, vec::to_ptr(vals), vec::to_ptr(bbs), vec::len(vals)); } -fn Call(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef { +fn Call(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef]) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildCall(B(cx), Fn, vec::to_ptr(Args), @@ -424,7 +421,7 @@ fn Call(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef { }); } -fn FastCall(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef { +fn FastCall(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef]) -> ValueRef { let v = str::as_buf("", {|buf| @@ -435,7 +432,7 @@ fn FastCall(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef { ret v; } -fn CallWithConv(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef], Conv: uint) +fn CallWithConv(cx: @block_ctxt, Fn: ValueRef, Args: [ValueRef], Conv: uint) -> ValueRef { let v = str::as_buf("", @@ -447,7 +444,7 @@ fn CallWithConv(cx: &@block_ctxt, Fn: ValueRef, Args: &[ValueRef], Conv: uint) ret v; } -fn Select(cx: &@block_ctxt, If: ValueRef, Then: ValueRef, Else: ValueRef) -> +fn Select(cx: @block_ctxt, If: ValueRef, Then: ValueRef, Else: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| @@ -455,11 +452,11 @@ fn Select(cx: &@block_ctxt, If: ValueRef, Then: ValueRef, Else: ValueRef) -> }); } -fn VAArg(cx: &@block_ctxt, list: ValueRef, Ty: TypeRef) -> ValueRef { +fn VAArg(cx: @block_ctxt, list: ValueRef, Ty: TypeRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildVAArg(B(cx), list, Ty, buf) }); } -fn ExtractElement(cx: &@block_ctxt, VecVal: ValueRef, Index: ValueRef) -> +fn ExtractElement(cx: @block_ctxt, VecVal: ValueRef, Index: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| @@ -468,7 +465,7 @@ fn ExtractElement(cx: &@block_ctxt, VecVal: ValueRef, Index: ValueRef) -> }); } -fn InsertElement(cx: &@block_ctxt, VecVal: ValueRef, EltVal: ValueRef, +fn InsertElement(cx: @block_ctxt, VecVal: ValueRef, EltVal: ValueRef, Index: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| @@ -477,7 +474,7 @@ fn InsertElement(cx: &@block_ctxt, VecVal: ValueRef, EltVal: ValueRef, }); } -fn ShuffleVector(cx: &@block_ctxt, V1: ValueRef, V2: ValueRef, Mask: ValueRef) +fn ShuffleVector(cx: @block_ctxt, V1: ValueRef, V2: ValueRef, Mask: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| @@ -485,14 +482,14 @@ fn ShuffleVector(cx: &@block_ctxt, V1: ValueRef, V2: ValueRef, Mask: ValueRef) }); } -fn ExtractValue(cx: &@block_ctxt, AggVal: ValueRef, Index: uint) -> ValueRef { +fn ExtractValue(cx: @block_ctxt, AggVal: ValueRef, Index: uint) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildExtractValue(B(cx), AggVal, Index, buf) }); } -fn InsertValue(cx: &@block_ctxt, AggVal: ValueRef, EltVal: ValueRef, +fn InsertValue(cx: @block_ctxt, AggVal: ValueRef, EltVal: ValueRef, Index: uint) -> ValueRef { ret str::as_buf("", {|buf| @@ -501,20 +498,20 @@ fn InsertValue(cx: &@block_ctxt, AggVal: ValueRef, EltVal: ValueRef, }); } -fn IsNull(cx: &@block_ctxt, Val: ValueRef) -> ValueRef { +fn IsNull(cx: @block_ctxt, Val: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildIsNull(B(cx), Val, buf) }); } -fn IsNotNull(cx: &@block_ctxt, Val: ValueRef) -> ValueRef { +fn IsNotNull(cx: @block_ctxt, Val: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildIsNotNull(B(cx), Val, buf) }); } -fn PtrDiff(cx: &@block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { +fn PtrDiff(cx: @block_ctxt, LHS: ValueRef, RHS: ValueRef) -> ValueRef { ret str::as_buf("", {|buf| llvm::LLVMBuildPtrDiff(B(cx), LHS, RHS, buf) }); } -fn Trap(cx: &@block_ctxt) -> ValueRef { +fn Trap(cx: @block_ctxt) -> ValueRef { let b = B(cx); let BB: BasicBlockRef = llvm::LLVMGetInsertBlock(b); let FN: ValueRef = llvm::LLVMGetBasicBlockParent(BB); diff --git a/src/comp/middle/trans_common.rs b/src/comp/middle/trans_common.rs index 7322bb50df7..b266f642921 100644 --- a/src/comp/middle/trans_common.rs +++ b/src/comp/middle/trans_common.rs @@ -62,7 +62,7 @@ import trans::type_of_fn_full; import trans::drop_ty; obj namegen(mutable i: int) { - fn next(prefix: &str) -> str { i += 1; ret prefix + int::str(i); } + fn next(prefix: str) -> str { i += 1; ret prefix + int::str(i); } } type derived_tydesc_info = {lltydesc: ValueRef, escapes: bool}; @@ -291,15 +291,15 @@ type fn_ctxt = lcx: @local_ctxt}; tag cleanup { - clean(fn(&@block_ctxt) -> @block_ctxt); - clean_temp(ValueRef, fn(&@block_ctxt) -> @block_ctxt); + clean(fn(@block_ctxt) -> @block_ctxt); + clean_temp(ValueRef, fn(@block_ctxt) -> @block_ctxt); } -fn add_clean(cx: &@block_ctxt, val: ValueRef, ty: ty::t) { +fn add_clean(cx: @block_ctxt, val: ValueRef, ty: ty::t) { find_scope_cx(cx).cleanups += [clean(bind drop_ty(_, val, ty))]; } -fn add_clean_temp(cx: &@block_ctxt, val: ValueRef, ty: ty::t) { - fn spill_and_drop(cx: &@block_ctxt, val: ValueRef, ty: ty::t) -> +fn add_clean_temp(cx: @block_ctxt, val: ValueRef, ty: ty::t) { + fn spill_and_drop(cx: @block_ctxt, val: ValueRef, ty: ty::t) -> @block_ctxt { let bcx = cx; let r = trans::spill_if_immediate(bcx, val, ty); @@ -315,7 +315,7 @@ fn add_clean_temp(cx: &@block_ctxt, val: ValueRef, ty: ty::t) { // to a system where we can also cancel the cleanup on local variables, but // this will be more involved. For now, we simply zero out the local, and the // drop glue checks whether it is zero. -fn revoke_clean(cx: &@block_ctxt, val: ValueRef, t: ty::t) -> @block_ctxt { +fn revoke_clean(cx: @block_ctxt, val: ValueRef, t: ty::t) -> @block_ctxt { if ty::type_is_unique(bcx_tcx(cx), t) { // Just zero out the allocation. This ensures that the GC won't try to // traverse dangling pointers. @@ -346,8 +346,8 @@ fn revoke_clean(cx: &@block_ctxt, val: ValueRef, t: ty::t) -> @block_ctxt { ret cx; } -fn get_res_dtor(ccx: &@crate_ctxt, sp: &span, did: &ast::def_id, - inner_t: ty::t) -> ValueRef { +fn get_res_dtor(ccx: @crate_ctxt, sp: span, did: ast::def_id, inner_t: ty::t) + -> ValueRef { if did.crate == ast::local_crate { alt ccx.fn_pairs.find(did.node) { some(x) { ret x; } @@ -418,7 +418,7 @@ type block_ctxt = sp: span, fcx: @fn_ctxt}; -fn is_terminated(cx: &@block_ctxt) -> bool { ret cx.terminated; } +fn is_terminated(cx: @block_ctxt) -> bool { ret cx.terminated; } // FIXME: we should be able to use option::t<@block_parent> here but // the infinite-tag check in rustboot gets upset. @@ -427,7 +427,7 @@ tag block_parent { parent_none; parent_some(@block_ctxt); } type result = {bcx: @block_ctxt, val: ValueRef}; type result_t = {bcx: @block_ctxt, val: ValueRef, ty: ty::t}; -fn extend_path(cx: @local_ctxt, name: &str) -> @local_ctxt { +fn extend_path(cx: @local_ctxt, name: str) -> @local_ctxt { ret @{path: cx.path + [name] with *cx}; } @@ -452,7 +452,7 @@ fn struct_elt(llstructty: TypeRef, n: uint) -> TypeRef { ret llvm::LLVMGetElementType(elt_tys[n]); } -fn find_scope_cx(cx: &@block_ctxt) -> @block_ctxt { +fn find_scope_cx(cx: @block_ctxt) -> @block_ctxt { if cx.kind != NON_SCOPE_BLOCK { ret cx; } alt cx.parent { parent_some(b) { ret find_scope_cx(b); } @@ -466,14 +466,14 @@ fn find_scope_cx(cx: &@block_ctxt) -> @block_ctxt { // Accessors // TODO: When we have overloading, simplify these names! -fn bcx_tcx(bcx: &@block_ctxt) -> ty::ctxt { ret bcx.fcx.lcx.ccx.tcx; } -fn bcx_ccx(bcx: &@block_ctxt) -> @crate_ctxt { ret bcx.fcx.lcx.ccx; } -fn bcx_lcx(bcx: &@block_ctxt) -> @local_ctxt { ret bcx.fcx.lcx; } -fn bcx_fcx(bcx: &@block_ctxt) -> @fn_ctxt { ret bcx.fcx; } -fn fcx_ccx(fcx: &@fn_ctxt) -> @crate_ctxt { ret fcx.lcx.ccx; } -fn fcx_tcx(fcx: &@fn_ctxt) -> ty::ctxt { ret fcx.lcx.ccx.tcx; } -fn lcx_ccx(lcx: &@local_ctxt) -> @crate_ctxt { ret lcx.ccx; } -fn ccx_tcx(ccx: &@crate_ctxt) -> ty::ctxt { ret ccx.tcx; } +fn bcx_tcx(bcx: @block_ctxt) -> ty::ctxt { ret bcx.fcx.lcx.ccx.tcx; } +fn bcx_ccx(bcx: @block_ctxt) -> @crate_ctxt { ret bcx.fcx.lcx.ccx; } +fn bcx_lcx(bcx: @block_ctxt) -> @local_ctxt { ret bcx.fcx.lcx; } +fn bcx_fcx(bcx: @block_ctxt) -> @fn_ctxt { ret bcx.fcx; } +fn fcx_ccx(fcx: @fn_ctxt) -> @crate_ctxt { ret fcx.lcx.ccx; } +fn fcx_tcx(fcx: @fn_ctxt) -> ty::ctxt { ret fcx.lcx.ccx.tcx; } +fn lcx_ccx(lcx: @local_ctxt) -> @crate_ctxt { ret lcx.ccx; } +fn ccx_tcx(ccx: @crate_ctxt) -> ty::ctxt { ret ccx.tcx; } // LLVM type constructors. fn T_void() -> TypeRef { @@ -532,27 +532,27 @@ fn T_size_t() -> TypeRef { ret T_i32(); } -fn T_fn(inputs: &[TypeRef], output: TypeRef) -> TypeRef { +fn T_fn(inputs: [TypeRef], output: TypeRef) -> TypeRef { ret llvm::LLVMFunctionType(output, to_ptr(inputs), std::vec::len::<TypeRef>(inputs), False); } -fn T_fn_pair(cx: &crate_ctxt, tfn: TypeRef) -> TypeRef { +fn T_fn_pair(cx: crate_ctxt, tfn: TypeRef) -> TypeRef { ret T_struct([T_ptr(tfn), T_opaque_closure_ptr(cx)]); } fn T_ptr(t: TypeRef) -> TypeRef { ret llvm::LLVMPointerType(t, 0u); } -fn T_struct(elts: &[TypeRef]) -> TypeRef { +fn T_struct(elts: [TypeRef]) -> TypeRef { ret llvm::LLVMStructType(to_ptr(elts), std::vec::len(elts), False); } -fn T_named_struct(name: &str) -> TypeRef { +fn T_named_struct(name: str) -> TypeRef { let c = llvm::LLVMGetGlobalContext(); ret str::as_buf(name, {|buf| llvm::LLVMStructCreateNamed(c, buf) }); } -fn set_struct_body(t: TypeRef, elts: &[TypeRef]) { +fn set_struct_body(t: TypeRef, elts: [TypeRef]) { llvm::LLVMStructSetBody(t, to_ptr(elts), std::vec::len(elts), False); } @@ -590,7 +590,7 @@ fn T_task() -> TypeRef { ret t; } -fn T_tydesc_field(cx: &crate_ctxt, field: int) -> TypeRef { +fn T_tydesc_field(cx: crate_ctxt, field: int) -> TypeRef { // Bit of a kludge: pick the fn typeref out of the tydesc.. let tydesc_elts: [TypeRef] = @@ -601,7 +601,7 @@ fn T_tydesc_field(cx: &crate_ctxt, field: int) -> TypeRef { ret t; } -fn T_glue_fn(cx: &crate_ctxt) -> TypeRef { +fn T_glue_fn(cx: crate_ctxt) -> TypeRef { let s = "glue_fn"; if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); } let t = T_tydesc_field(cx, abi::tydesc_field_drop_glue); @@ -609,7 +609,7 @@ fn T_glue_fn(cx: &crate_ctxt) -> TypeRef { ret t; } -fn T_cmp_glue_fn(cx: &crate_ctxt) -> TypeRef { +fn T_cmp_glue_fn(cx: crate_ctxt) -> TypeRef { let s = "cmp_glue_fn"; if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); } let t = T_tydesc_field(cx, abi::tydesc_field_cmp_glue); @@ -663,11 +663,11 @@ fn T_chan(_t: TypeRef) -> TypeRef { } -fn T_taskptr(cx: &crate_ctxt) -> TypeRef { ret T_ptr(cx.task_type); } +fn T_taskptr(cx: crate_ctxt) -> TypeRef { ret T_ptr(cx.task_type); } // This type must never be used directly; it must always be cast away. -fn T_typaram(tn: &type_names) -> TypeRef { +fn T_typaram(tn: type_names) -> TypeRef { let s = "typaram"; if tn.name_has_type(s) { ret tn.get_type(s); } let t = T_i8(); @@ -675,10 +675,10 @@ fn T_typaram(tn: &type_names) -> TypeRef { ret t; } -fn T_typaram_ptr(tn: &type_names) -> TypeRef { ret T_ptr(T_typaram(tn)); } +fn T_typaram_ptr(tn: type_names) -> TypeRef { ret T_ptr(T_typaram(tn)); } -fn T_closure_ptr(cx: &crate_ctxt, llbindings_ty: TypeRef, n_ty_params: uint) - -> TypeRef { +fn T_closure_ptr(cx: crate_ctxt, llbindings_ty: TypeRef, n_ty_params: uint) -> + TypeRef { // NB: keep this in sync with code in trans_bind; we're making // an LLVM typeref structure that has the same "shape" as the ty::t // it constructs. @@ -686,7 +686,7 @@ fn T_closure_ptr(cx: &crate_ctxt, llbindings_ty: TypeRef, n_ty_params: uint) T_captured_tydescs(cx, n_ty_params)]))); } -fn T_opaque_closure_ptr(cx: &crate_ctxt) -> TypeRef { +fn T_opaque_closure_ptr(cx: crate_ctxt) -> TypeRef { let s = "*closure"; if cx.tn.name_has_type(s) { ret cx.tn.get_type(s); } let t = T_closure_ptr(cx, T_nil(), 0u); @@ -694,19 +694,18 @@ fn T_opaque_closure_ptr(cx: &crate_ctxt) -> TypeRef { ret t; } -fn T_tag(tn: &type_names, size: uint) -> TypeRef { +fn T_tag(tn: type_names, size: uint) -> TypeRef { let s = "tag_" + uint::to_str(size, 10u); if tn.name_has_type(s) { ret tn.get_type(s); } - let t = if size == 0u { - T_struct([T_int()]) - } else { - T_struct([T_int(), T_array(T_i8(), size)]) - }; + let t = + if size == 0u { + T_struct([T_int()]) + } else { T_struct([T_int(), T_array(T_i8(), size)]) }; tn.associate(s, t); ret t; } -fn T_opaque_tag(tn: &type_names) -> TypeRef { +fn T_opaque_tag(tn: type_names) -> TypeRef { let s = "opaque_tag"; if tn.name_has_type(s) { ret tn.get_type(s); } let t = T_struct([T_int(), T_i8()]); @@ -714,26 +713,26 @@ fn T_opaque_tag(tn: &type_names) -> TypeRef { ret t; } -fn T_opaque_tag_ptr(tn: &type_names) -> TypeRef { +fn T_opaque_tag_ptr(tn: type_names) -> TypeRef { ret T_ptr(T_opaque_tag(tn)); } -fn T_captured_tydescs(cx: &crate_ctxt, n: uint) -> TypeRef { +fn T_captured_tydescs(cx: crate_ctxt, n: uint) -> TypeRef { ret T_struct(std::vec::init_elt::<TypeRef>(T_ptr(cx.tydesc_type), n)); } -fn T_obj_ptr(cx: &crate_ctxt, n_captured_tydescs: uint) -> TypeRef { +fn T_obj_ptr(cx: crate_ctxt, n_captured_tydescs: uint) -> TypeRef { // This function is not publicly exposed because it returns an incomplete // type. The dynamically-sized fields follow the captured tydescs. - fn T_obj(cx: &crate_ctxt, n_captured_tydescs: uint) -> TypeRef { + fn T_obj(cx: crate_ctxt, n_captured_tydescs: uint) -> TypeRef { ret T_struct([T_ptr(cx.tydesc_type), T_captured_tydescs(cx, n_captured_tydescs)]); } ret T_ptr(T_box(T_obj(cx, n_captured_tydescs))); } -fn T_opaque_obj_ptr(cx: &crate_ctxt) -> TypeRef { ret T_obj_ptr(cx, 0u); } +fn T_opaque_obj_ptr(cx: crate_ctxt) -> TypeRef { ret T_obj_ptr(cx, 0u); } fn T_opaque_port_ptr() -> TypeRef { ret T_ptr(T_i8()); } @@ -753,11 +752,11 @@ fn C_integral(t: TypeRef, u: uint, sign_extend: Bool) -> ValueRef { ret llvm::LLVMRustConstSmallInt(t, u, sign_extend); } -fn C_float(s: &str) -> ValueRef { +fn C_float(s: str) -> ValueRef { ret str::as_buf(s, {|buf| llvm::LLVMConstRealOfString(T_float(), buf) }); } -fn C_floating(s: &str, t: TypeRef) -> ValueRef { +fn C_floating(s: str, t: TypeRef) -> ValueRef { ret str::as_buf(s, {|buf| llvm::LLVMConstRealOfString(t, buf) }); } @@ -782,7 +781,7 @@ fn C_u8(i: uint) -> ValueRef { ret C_integral(T_i8(), i, False); } // This is a 'c-like' raw string, which differs from // our boxed-and-length-annotated strings. -fn C_cstr(cx: &@crate_ctxt, s: &str) -> ValueRef { +fn C_cstr(cx: @crate_ctxt, s: str) -> ValueRef { let sc = str::as_buf(s, {|buf| @@ -798,7 +797,7 @@ fn C_cstr(cx: &@crate_ctxt, s: &str) -> ValueRef { } // Returns a Plain Old LLVM String: -fn C_postr(s: &str) -> ValueRef { +fn C_postr(s: str) -> ValueRef { ret str::as_buf(s, {|buf| llvm::LLVMConstString(buf, str::byte_len(s), False) @@ -813,26 +812,26 @@ fn C_zero_byte_arr(size: uint) -> ValueRef { std::vec::len(elts)); } -fn C_struct(elts: &[ValueRef]) -> ValueRef { +fn C_struct(elts: [ValueRef]) -> ValueRef { ret llvm::LLVMConstStruct(std::vec::to_ptr(elts), std::vec::len(elts), False); } -fn C_named_struct(T: TypeRef, elts: &[ValueRef]) -> ValueRef { +fn C_named_struct(T: TypeRef, elts: [ValueRef]) -> ValueRef { ret llvm::LLVMConstNamedStruct(T, std::vec::to_ptr(elts), std::vec::len(elts)); } -fn C_array(ty: TypeRef, elts: &[ValueRef]) -> ValueRef { +fn C_array(ty: TypeRef, elts: [ValueRef]) -> ValueRef { ret llvm::LLVMConstArray(ty, std::vec::to_ptr(elts), std::vec::len(elts)); } -fn C_bytes(bytes: &[u8]) -> ValueRef { +fn C_bytes(bytes: [u8]) -> ValueRef { ret llvm::LLVMConstString(unsafe::reinterpret_cast(vec::to_ptr(bytes)), vec::len(bytes), False); } -fn C_shape(ccx: &@crate_ctxt, bytes: &[u8]) -> ValueRef { +fn C_shape(ccx: @crate_ctxt, bytes: [u8]) -> ValueRef { let llshape = C_bytes(bytes); let llglobal = str::as_buf(ccx.names.next("shape"), @@ -847,8 +846,8 @@ fn C_shape(ccx: &@crate_ctxt, bytes: &[u8]) -> ValueRef { } -pure fn valid_variant_index(ix: uint, cx: @block_ctxt, tag_id: &ast::def_id, - variant_id: &ast::def_id) -> bool { +pure fn valid_variant_index(ix: uint, cx: @block_ctxt, tag_id: ast::def_id, + variant_id: ast::def_id) -> bool { // Handwaving: it's ok to pretend this code is referentially // transparent, because the relevant parts of the type context don't @@ -860,7 +859,7 @@ pure fn valid_variant_index(ix: uint, cx: @block_ctxt, tag_id: &ast::def_id, } } -pure fn type_has_static_size(cx: &@crate_ctxt, t: ty::t) -> bool { +pure fn type_has_static_size(cx: @crate_ctxt, t: ty::t) -> bool { !ty::type_has_dynamic_size(cx.tcx, t) } diff --git a/src/comp/middle/trans_objects.rs b/src/comp/middle/trans_objects.rs index 392d8fccbed..cd554dac8d4 100644 --- a/src/comp/middle/trans_objects.rs +++ b/src/comp/middle/trans_objects.rs @@ -28,8 +28,8 @@ export trans_obj; // trans_obj: create an LLVM function that is the object constructor for the // object being translated. -fn trans_obj(cx: @local_ctxt, sp: &span, ob: &ast::_obj, - ctor_id: ast::node_id, ty_params: &[ast::ty_param]) { +fn trans_obj(cx: @local_ctxt, sp: span, ob: ast::_obj, ctor_id: ast::node_id, + ty_params: [ast::ty_param]) { // To make a function, we have to create a function context and, inside // that, a number of block contexts for which code is generated. @@ -48,8 +48,7 @@ fn trans_obj(cx: @local_ctxt, sp: &span, ob: &ast::_obj, // we're creating. let fn_args: [ast::arg] = []; for f: ast::obj_field in ob.fields { - fn_args += - [{mode: ast::by_ref, ty: f.ty, ident: f.ident, id: f.id}]; + fn_args += [{mode: ast::by_ref, ty: f.ty, ident: f.ident, id: f.id}]; } let fcx = new_fn_ctxt(cx, sp, llctor_decl); @@ -205,7 +204,7 @@ fn trans_obj(cx: @local_ctxt, sp: &span, ob: &ast::_obj, // function and putting it in the generated code as an object item, we are // instead "inlining" the construction of the object and returning the object // itself. -fn trans_anon_obj(bcx: @block_ctxt, sp: &span, anon_obj: &ast::anon_obj, +fn trans_anon_obj(bcx: @block_ctxt, sp: span, anon_obj: ast::anon_obj, id: ast::node_id) -> result { let ccx = bcx_ccx(bcx); @@ -394,12 +393,12 @@ tag vtbl_mthd { } // Alphabetize ast::methods by ident. A helper for create_vtbl. -fn ast_mthd_lteq(a: &@ast::method, b: &@ast::method) -> bool { +fn ast_mthd_lteq(a: @ast::method, b: @ast::method) -> bool { ret str::lteq(a.node.ident, b.node.ident); } // Alphabetize vtbl_mthds by ident. A helper for create_vtbl. -fn vtbl_mthd_lteq(a: &vtbl_mthd, b: &vtbl_mthd) -> bool { +fn vtbl_mthd_lteq(a: vtbl_mthd, b: vtbl_mthd) -> bool { alt a { normal_mthd(ma) { alt b { @@ -418,8 +417,8 @@ fn vtbl_mthd_lteq(a: &vtbl_mthd, b: &vtbl_mthd) -> bool { // filtering_fn: Used by create_vtbl to filter a list of methods to remove the // ones that we don't need forwarding slots for. -fn filtering_fn(cx: @local_ctxt, m: &vtbl_mthd, addtl_meths: [@ast::method]) - -> option::t<vtbl_mthd> { +fn filtering_fn(cx: @local_ctxt, m: vtbl_mthd, addtl_meths: [@ast::method]) -> + option::t<vtbl_mthd> { // Since m is a fwding_mthd, and we're checking to see if it's in // addtl_meths (which only contains normal_mthds), we can't just check if @@ -442,10 +441,9 @@ fn filtering_fn(cx: @local_ctxt, m: &vtbl_mthd, addtl_meths: [@ast::method]) // create_vtbl: Create a vtable for a regular object or for an outer anonymous // object, and return a pointer to it. -fn create_vtbl(cx: @local_ctxt, sp: &span, outer_obj_ty: ty::t, - ob: &ast::_obj, ty_params: &[ast::ty_param], - inner_obj_ty: option::t<ty::t>, additional_field_tys: &[ty::t]) - -> ValueRef { +fn create_vtbl(cx: @local_ctxt, sp: span, outer_obj_ty: ty::t, ob: ast::_obj, + ty_params: [ast::ty_param], inner_obj_ty: option::t<ty::t>, + additional_field_tys: [ty::t]) -> ValueRef { let llmethods: [ValueRef] = []; @@ -531,7 +529,7 @@ fn create_vtbl(cx: @local_ctxt, sp: &span, outer_obj_ty: ty::t, // create_backwarding_vtbl: Create a vtable for the inner object of an // anonymous object, so that any self-calls made from the inner object's // methods get redirected appropriately. -fn create_backwarding_vtbl(cx: @local_ctxt, sp: &span, inner_obj_ty: ty::t, +fn create_backwarding_vtbl(cx: @local_ctxt, sp: span, inner_obj_ty: ty::t, outer_obj_ty: ty::t) -> ValueRef { // This vtbl needs to have slots for all of the methods on an inner @@ -564,7 +562,7 @@ fn create_backwarding_vtbl(cx: @local_ctxt, sp: &span, inner_obj_ty: ty::t, // finish_vtbl: Given a vector of vtable entries, create the table in // read-only memory and return a pointer to it. -fn finish_vtbl(cx: @local_ctxt, llmethods: [ValueRef], name: &str) -> +fn finish_vtbl(cx: @local_ctxt, llmethods: [ValueRef], name: str) -> ValueRef { let vtbl = C_struct(llmethods); let vtbl_name = mangle_internal_name_by_path(cx.ccx, cx.path + [name]); @@ -594,9 +592,9 @@ fn finish_vtbl(cx: @local_ctxt, llmethods: [ValueRef], name: &str) -> // one for each method on inner, each of which takes all the same arguments as // the corresponding method on inner does, calls that method on outer, and // returns the value returned from that call. -fn process_bkwding_mthd(cx: @local_ctxt, sp: &span, m: @ty::method, - ty_params: &[ast::ty_param], outer_obj_ty: ty::t, - _additional_field_tys: &[ty::t]) -> ValueRef { +fn process_bkwding_mthd(cx: @local_ctxt, sp: span, m: @ty::method, + ty_params: [ast::ty_param], outer_obj_ty: ty::t, + _additional_field_tys: [ty::t]) -> ValueRef { // Create a local context that's aware of the name of the method we're // creating. @@ -717,10 +715,10 @@ fn process_bkwding_mthd(cx: @local_ctxt, sp: &span, m: @ty::method, // calls inner.foo() with those arguments, and then returns the value returned // from that call. (The inner object won't exist until run-time, but we know // its type statically.) -fn process_fwding_mthd(cx: @local_ctxt, sp: &span, m: @ty::method, - ty_params: &[ast::ty_param], inner_obj_ty: ty::t, +fn process_fwding_mthd(cx: @local_ctxt, sp: span, m: @ty::method, + ty_params: [ast::ty_param], inner_obj_ty: ty::t, backwarding_vtbl: ValueRef, - additional_field_tys: &[ty::t]) -> ValueRef { + additional_field_tys: [ty::t]) -> ValueRef { // Create a local context that's aware of the name of the method we're // creating. @@ -783,11 +781,11 @@ fn process_fwding_mthd(cx: @local_ctxt, sp: &span, m: @ty::method, // create_object_body_type maybe should have a postcondition... let cx_ccx = cx.ccx; - check type_has_static_size(cx_ccx, body_ty); + check (type_has_static_size(cx_ccx, body_ty)); llself_obj_body = PointerCast(bcx, llself_obj_body, - T_ptr(type_of(cx_ccx, sp, body_ty))); + T_ptr(type_of(cx_ccx, sp, body_ty))); // Now, reach into the body and grab the inner_obj. let llinner_obj = @@ -873,8 +871,8 @@ fn process_fwding_mthd(cx: @local_ctxt, sp: &span, m: @ty::method, // create_object_body_type: Synthesize a big structural tuple type for an // object body: [tydesc, [typaram, ...], [field, ...], inner_obj]. -fn create_object_body_type(tcx: &ty::ctxt, fields_ty: &[ty::t], - typarams_ty: &[ty::t], +fn create_object_body_type(tcx: ty::ctxt, fields_ty: [ty::t], + typarams_ty: [ty::t], maybe_inner_obj_ty: option::t<ty::t>) -> ty::t { let tydesc_ty: ty::t = ty::mk_type(tcx); @@ -901,7 +899,7 @@ fn create_object_body_type(tcx: &ty::ctxt, fields_ty: &[ty::t], // process_normal_mthd: Create the contents of a normal vtable slot. A helper // function for create_vtbl. fn process_normal_mthd(cx: @local_ctxt, m: @ast::method, self_ty: ty::t, - ty_params: &[ast::ty_param]) -> ValueRef { + ty_params: [ast::ty_param]) -> ValueRef { let llfnty = T_nil(); alt ty::struct(cx.ccx.tcx, node_id_type(cx.ccx, m.node.id)) { diff --git a/src/comp/middle/trans_vec.rs b/src/comp/middle/trans_vec.rs index 48143461a31..08279f07b8b 100644 --- a/src/comp/middle/trans_vec.rs +++ b/src/comp/middle/trans_vec.rs @@ -12,26 +12,25 @@ 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 { +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_alloc(bcx: &@block_ctxt, vptrptr: ValueRef) -> ValueRef { +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) -> +fn get_dataptr(bcx: @block_ctxt, vptrptr: ValueRef, unit_ty: TypeRef) -> ValueRef { let ptr = GEPi(bcx, Load(bcx, vptrptr), [0, abi::vec_elt_elems as int]); PointerCast(bcx, ptr, T_ptr(unit_ty)) } -fn pointer_add(bcx: &@block_ctxt, ptr: ValueRef, bytes: ValueRef) -> - ValueRef { +fn pointer_add(bcx: @block_ctxt, ptr: ValueRef, bytes: ValueRef) -> ValueRef { let old_ty = val_ty(ptr); let bptr = PointerCast(bcx, ptr, T_ptr(T_i8())); ret PointerCast(bcx, InBoundsGEP(bcx, bptr, [bytes]), old_ty); } -fn alloc_raw(bcx: &@block_ctxt, fill: ValueRef, alloc: ValueRef) -> result { +fn alloc_raw(bcx: @block_ctxt, fill: ValueRef, alloc: ValueRef) -> result { let llvecty = T_opaque_vec(); let vecsize = Add(bcx, alloc, llsize_of(llvecty)); let {bcx: bcx, val: vecptr} = @@ -50,7 +49,7 @@ type alloc_result = llunitsz: ValueRef, llunitty: TypeRef}; -fn alloc(bcx: &@block_ctxt, vec_ty: &ty::t, elts: uint) -> alloc_result { +fn alloc(bcx: @block_ctxt, vec_ty: ty::t, elts: uint) -> alloc_result { let unit_ty = ty::sequence_element_type(bcx_tcx(bcx), vec_ty); let llunitty = type_of_or_i8(bcx, unit_ty); let llvecty = T_vec(llunitty); @@ -62,7 +61,8 @@ fn alloc(bcx: &@block_ctxt, vec_ty: &ty::t, elts: uint) -> alloc_result { let vptr = PointerCast(bcx, vptr, T_ptr(llvecty)); let r = alloc_ty(bcx, vec_ty); - let vptrptr = r.val; bcx = r.bcx; + let vptrptr = r.val; + bcx = r.bcx; Store(bcx, vptr, vptrptr); add_clean_temp(bcx, vptrptr, vec_ty); @@ -73,7 +73,7 @@ fn alloc(bcx: &@block_ctxt, vec_ty: &ty::t, elts: uint) -> alloc_result { llunitty: llunitty}; } -fn duplicate(bcx: &@block_ctxt, vptrptr: ValueRef) -> @block_ctxt { +fn duplicate(bcx: @block_ctxt, vptrptr: ValueRef) -> @block_ctxt { let fill = get_fill(bcx, vptrptr); let vptr = Load(bcx, vptrptr); let size = Add(bcx, fill, llsize_of(T_opaque_vec())); @@ -85,7 +85,7 @@ fn duplicate(bcx: &@block_ctxt, vptrptr: ValueRef) -> @block_ctxt { Store(bcx, newptr, vptrptr); ret bcx; } -fn make_drop_glue(bcx: &@block_ctxt, vptrptr: ValueRef, vec_ty: ty::t) -> +fn make_drop_glue(bcx: @block_ctxt, vptrptr: ValueRef, vec_ty: ty::t) -> @block_ctxt { let unit_ty = ty::sequence_element_type(bcx_tcx(bcx), vec_ty); let vptr = Load(bcx, vptrptr); @@ -102,7 +102,7 @@ fn make_drop_glue(bcx: &@block_ctxt, vptrptr: ValueRef, vec_ty: ty::t) -> ret next_cx; } -fn trans_vec(bcx: &@block_ctxt, args: &[@ast::expr], id: ast::node_id) -> +fn trans_vec(bcx: @block_ctxt, args: [@ast::expr], id: ast::node_id) -> result { let vec_ty = node_id_type(bcx_ccx(bcx), id); let {bcx: bcx, @@ -127,7 +127,7 @@ fn trans_vec(bcx: &@block_ctxt, args: &[@ast::expr], id: ast::node_id) -> } ret rslt(bcx, vptr); } -fn trans_str(bcx: &@block_ctxt, s: str) -> result { +fn trans_str(bcx: @block_ctxt, s: str) -> result { let veclen = std::str::byte_len(s) + 1u; // +1 for \0 let {bcx: bcx, val: sptr, _} = alloc(bcx, ty::mk_str(bcx_tcx(bcx)), veclen); @@ -140,7 +140,7 @@ fn trans_str(bcx: &@block_ctxt, s: str) -> result { ret rslt(bcx, sptr); } -fn trans_append(cx: &@block_ctxt, vec_ty: ty::t, lhsptr: ValueRef, +fn trans_append(cx: @block_ctxt, vec_ty: ty::t, lhsptr: ValueRef, rhsptr: ValueRef) -> result { // Cast to opaque interior vector types if necessary. let unit_ty = ty::sequence_element_type(bcx_tcx(cx), vec_ty); @@ -179,7 +179,7 @@ fn trans_append(cx: &@block_ctxt, vec_ty: ty::t, lhsptr: ValueRef, let bcx = iter_vec_raw(bcx, rhsptr, vec_ty, rfill, // We have to increment by the dynamically-computed size. - {|&bcx, addr, _ty| + {|bcx, addr, _ty| let write_ptr = Load(bcx, write_ptr_ptr); let bcx = copy_val(bcx, INIT, write_ptr, @@ -193,8 +193,8 @@ fn trans_append(cx: &@block_ctxt, vec_ty: ty::t, lhsptr: ValueRef, ret rslt(bcx, C_nil()); } -fn trans_append_literal(bcx: &@block_ctxt, vptrptr: ValueRef, vec_ty: ty::t, - vals: &[@ast::expr]) -> @block_ctxt { +fn trans_append_literal(bcx: @block_ctxt, vptrptr: ValueRef, vec_ty: ty::t, + vals: [@ast::expr]) -> @block_ctxt { let elt_ty = ty::sequence_element_type(bcx_tcx(bcx), vec_ty); let ti = none; let {bcx: bcx, val: td} = @@ -214,9 +214,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) - -> result { +fn trans_add(bcx: @block_ctxt, vec_ty: ty::t, lhsptr: ValueRef, + rhsptr: ValueRef) -> result { let strings = alt ty::struct(bcx_tcx(bcx), vec_ty) { ty::ty_str. { true } @@ -239,15 +238,16 @@ fn trans_add(bcx: &@block_ctxt, vec_ty: ty::t, lhsptr: ValueRef, let write_ptr_ptr = do_spill_noroot(bcx, get_dataptr(bcx, new_vec_ptr_ptr, llunitty)); let copy_fn = - bind fn (bcx: &@block_ctxt, addr: ValueRef, _ty: ty::t, + bind fn (bcx: @block_ctxt, addr: ValueRef, _ty: ty::t, write_ptr_ptr: ValueRef, unit_ty: ty::t, llunitsz: ValueRef) -> @block_ctxt { let write_ptr = Load(bcx, write_ptr_ptr); let bcx = copy_val(bcx, INIT, write_ptr, load_if_immediate(bcx, addr, unit_ty), unit_ty); - let incr = ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) ? - llunitsz : C_int(1); + let incr = + ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) ? + llunitsz : C_int(1); Store(bcx, InBoundsGEP(bcx, write_ptr, [incr]), write_ptr_ptr); ret bcx; @@ -258,12 +258,12 @@ fn trans_add(bcx: &@block_ctxt, vec_ty: ty::t, lhsptr: ValueRef, ret rslt(bcx, new_vec_ptr_ptr); } -type val_and_ty_fn = fn(&@block_ctxt, ValueRef, ty::t) -> result; +type val_and_ty_fn = fn(@block_ctxt, ValueRef, ty::t) -> result; -type iter_vec_block = block(&@block_ctxt, ValueRef, ty::t) -> @block_ctxt; +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, - fill: ValueRef, f: &iter_vec_block) -> @block_ctxt { +fn iter_vec_raw(bcx: @block_ctxt, vptrptr: 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); @@ -289,14 +289,14 @@ fn iter_vec_raw(bcx: &@block_ctxt, vptrptr: ValueRef, vec_ty: ty::t, if ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) { unit_sz } else { C_int(1) }; - AddIncomingToPhi(data_ptr, [InBoundsGEP(body_cx, data_ptr, - [increment])], [body_cx.llbb]); + AddIncomingToPhi(data_ptr, [InBoundsGEP(body_cx, data_ptr, [increment])], + [body_cx.llbb]); Br(body_cx, header_cx.llbb); ret next_cx; } -fn iter_vec(bcx: &@block_ctxt, vptrptr: ValueRef, vec_ty: ty::t, - f: &iter_vec_block) -> @block_ctxt { +fn iter_vec(bcx: @block_ctxt, vptrptr: 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); } diff --git a/src/comp/middle/tstate/ann.rs b/src/comp/middle/tstate/ann.rs index f88d803b7bf..d71ac7ac92e 100644 --- a/src/comp/middle/tstate/ann.rs +++ b/src/comp/middle/tstate/ann.rs @@ -70,84 +70,84 @@ fn empty_ann(num_vars: uint) -> ts_ann { states: empty_states(num_vars)}; } -fn get_pre(p: &pre_and_post) -> precond { ret p.precondition; } +fn get_pre(p: pre_and_post) -> precond { ret p.precondition; } -fn get_post(p: &pre_and_post) -> postcond { ret p.postcondition; } +fn get_post(p: pre_and_post) -> postcond { ret p.postcondition; } -fn difference(p1: &precond, p2: &precond) -> bool { +fn difference(p1: precond, p2: precond) -> bool { ret tritv_difference(p1, p2); } -fn union(p1: &precond, p2: &precond) -> bool { ret tritv_union(p1, p2); } +fn union(p1: precond, p2: precond) -> bool { ret tritv_union(p1, p2); } -fn intersect(p1: &precond, p2: &precond) -> bool { +fn intersect(p1: precond, p2: precond) -> bool { ret tritv_intersect(p1, p2); } -fn pps_len(p: &pre_and_post) -> uint { +fn pps_len(p: pre_and_post) -> uint { // gratuitous check assert (p.precondition.nbits == p.postcondition.nbits); ret p.precondition.nbits; } -fn require(i: uint, p: &pre_and_post) { +fn require(i: uint, p: pre_and_post) { // sets the ith bit in p's pre tritv_set(i, p.precondition, ttrue); } -fn require_and_preserve(i: uint, p: &pre_and_post) { +fn require_and_preserve(i: uint, p: pre_and_post) { // sets the ith bit in p's pre and post tritv_set(i, p.precondition, ttrue); tritv_set(i, p.postcondition, ttrue); } -fn set_in_postcond(i: uint, p: &pre_and_post) -> bool { +fn set_in_postcond(i: uint, p: pre_and_post) -> bool { // sets the ith bit in p's post ret set_in_postcond_(i, p.postcondition); } -fn set_in_postcond_(i: uint, p: &postcond) -> bool { +fn set_in_postcond_(i: uint, p: postcond) -> bool { let was_set = tritv_get(p, i); tritv_set(i, p, ttrue); ret was_set != ttrue; } -fn set_in_poststate(i: uint, s: &pre_and_post_state) -> bool { +fn set_in_poststate(i: uint, s: pre_and_post_state) -> bool { // sets the ith bit in p's post ret set_in_poststate_(i, s.poststate); } -fn set_in_poststate_(i: uint, p: &poststate) -> bool { +fn set_in_poststate_(i: uint, p: poststate) -> bool { let was_set = tritv_get(p, i); tritv_set(i, p, ttrue); ret was_set != ttrue; } -fn clear_in_poststate(i: uint, s: &pre_and_post_state) -> bool { +fn clear_in_poststate(i: uint, s: pre_and_post_state) -> bool { // sets the ith bit in p's post ret clear_in_poststate_(i, s.poststate); } -fn clear_in_poststate_(i: uint, s: &poststate) -> bool { +fn clear_in_poststate_(i: uint, s: poststate) -> bool { let was_set = tritv_get(s, i); tritv_set(i, s, tfalse); ret was_set != tfalse; } -fn clear_in_prestate(i: uint, s: &pre_and_post_state) -> bool { +fn clear_in_prestate(i: uint, s: pre_and_post_state) -> bool { // sets the ith bit in p's pre ret clear_in_prestate_(i, s.prestate); } -fn clear_in_prestate_(i: uint, s: &prestate) -> bool { +fn clear_in_prestate_(i: uint, s: prestate) -> bool { let was_set = tritv_get(s, i); tritv_set(i, s, tfalse); ret was_set != tfalse; } -fn clear_in_postcond(i: uint, s: &pre_and_post) -> bool { +fn clear_in_postcond(i: uint, s: pre_and_post) -> bool { // sets the ith bit in p's post let was_set = tritv_get(s.postcondition, i); tritv_set(i, s.postcondition, tfalse); @@ -156,72 +156,72 @@ fn clear_in_postcond(i: uint, s: &pre_and_post) -> bool { // Sets all the bits in a's precondition to equal the // corresponding bit in p's precondition. -fn set_precondition(a: ts_ann, p: &precond) { +fn set_precondition(a: ts_ann, p: precond) { tritv_copy(a.conditions.precondition, p); } // Sets all the bits in a's postcondition to equal the // corresponding bit in p's postcondition. -fn set_postcondition(a: ts_ann, p: &postcond) { +fn set_postcondition(a: ts_ann, p: postcond) { tritv_copy(a.conditions.postcondition, p); } // Sets all the bits in a's prestate to equal the // corresponding bit in p's prestate. -fn set_prestate(a: ts_ann, p: &prestate) -> bool { +fn set_prestate(a: ts_ann, p: prestate) -> bool { ret tritv_copy(a.states.prestate, p); } // Sets all the bits in a's postcondition to equal the // corresponding bit in p's postcondition. -fn set_poststate(a: ts_ann, p: &poststate) -> bool { +fn set_poststate(a: ts_ann, p: poststate) -> bool { ret tritv_copy(a.states.poststate, p); } // Set all the bits in p that are set in new -fn extend_prestate(p: &prestate, new: &poststate) -> bool { +fn extend_prestate(p: prestate, new: poststate) -> bool { ret tritv_union(p, new); } // Set all the bits in p that are set in new -fn extend_poststate(p: &poststate, new: &poststate) -> bool { +fn extend_poststate(p: poststate, new: poststate) -> bool { ret tritv_union(p, new); } // Sets the given bit in p to "don't care" // FIXME: is this correct? -fn relax_prestate(i: uint, p: &prestate) -> bool { +fn relax_prestate(i: uint, p: prestate) -> bool { let was_set = tritv_get(p, i); tritv_set(i, p, dont_care); ret was_set != dont_care; } // Clears the given bit in p -fn relax_poststate(i: uint, p: &poststate) -> bool { +fn relax_poststate(i: uint, p: poststate) -> bool { ret relax_prestate(i, p); } // Clears the given bit in p -fn relax_precond(i: uint, p: &precond) { relax_prestate(i, p); } +fn relax_precond(i: uint, p: precond) { relax_prestate(i, p); } // Sets all the bits in p to "don't care" -fn clear(p: &precond) { tritv_clear(p); } +fn clear(p: precond) { tritv_clear(p); } // Sets all the bits in p to true -fn set(p: &precond) { tritv_set_all(p); } +fn set(p: precond) { tritv_set_all(p); } -fn ann_precond(a: &ts_ann) -> precond { ret a.conditions.precondition; } +fn ann_precond(a: ts_ann) -> precond { ret a.conditions.precondition; } -fn ann_prestate(a: &ts_ann) -> prestate { ret a.states.prestate; } +fn ann_prestate(a: ts_ann) -> prestate { ret a.states.prestate; } -fn ann_poststate(a: &ts_ann) -> poststate { ret a.states.poststate; } +fn ann_poststate(a: ts_ann) -> poststate { ret a.states.poststate; } -fn pp_clone(p: &pre_and_post) -> pre_and_post { +fn pp_clone(p: pre_and_post) -> pre_and_post { ret @{precondition: clone(p.precondition), postcondition: clone(p.postcondition)}; } diff --git a/src/comp/middle/tstate/annotate.rs b/src/comp/middle/tstate/annotate.rs index 5a97d6bc0ae..a3e6be26969 100644 --- a/src/comp/middle/tstate/annotate.rs +++ b/src/comp/middle/tstate/annotate.rs @@ -25,11 +25,11 @@ import aux::crate_ctxt; import aux::add_node; import middle::tstate::ann::empty_ann; -fn collect_ids_expr(e: &@expr, rs: @mutable [node_id]) { *rs += [e.id]; } +fn collect_ids_expr(e: @expr, rs: @mutable [node_id]) { *rs += [e.id]; } -fn collect_ids_block(b: &blk, rs: @mutable [node_id]) { *rs += [b.node.id]; } +fn collect_ids_block(b: blk, rs: @mutable [node_id]) { *rs += [b.node.id]; } -fn collect_ids_stmt(s: &@stmt, rs: @mutable [node_id]) { +fn collect_ids_stmt(s: @stmt, rs: @mutable [node_id]) { alt s.node { stmt_decl(_, id) { log "node_id " + int::str(id); @@ -45,12 +45,12 @@ fn collect_ids_stmt(s: &@stmt, rs: @mutable [node_id]) { } } -fn collect_ids_local(l: &@local, rs: @mutable [node_id]) { +fn collect_ids_local(l: @local, rs: @mutable [node_id]) { *rs += pat_binding_ids(l.node.pat); } -fn node_ids_in_fn(f: &_fn, tps: &[ty_param], sp: &span, i: &fn_ident, - id: node_id, rs: @mutable [node_id]) { +fn node_ids_in_fn(f: _fn, tps: [ty_param], sp: span, i: fn_ident, id: node_id, + rs: @mutable [node_id]) { let collect_ids = visit::mk_simple_visitor(@{visit_expr: bind collect_ids_expr(_, rs), visit_block: bind collect_ids_block(_, rs), @@ -60,28 +60,28 @@ fn node_ids_in_fn(f: &_fn, tps: &[ty_param], sp: &span, i: &fn_ident, visit::visit_fn(f, tps, sp, i, id, (), collect_ids); } -fn init_vecs(ccx: &crate_ctxt, node_ids: &[node_id], len: uint) { +fn init_vecs(ccx: crate_ctxt, node_ids: [node_id], len: uint) { for i: node_id in node_ids { log int::str(i) + " |-> " + uint::str(len); add_node(ccx, i, empty_ann(len)); } } -fn visit_fn(ccx: &crate_ctxt, num_constraints: uint, f: &_fn, - tps: &[ty_param], sp: &span, i: &fn_ident, id: node_id) { +fn visit_fn(ccx: crate_ctxt, num_constraints: uint, f: _fn, tps: [ty_param], + sp: span, i: fn_ident, id: node_id) { let node_ids: @mutable [node_id] = @mutable []; node_ids_in_fn(f, tps, sp, i, id, node_ids); let node_id_vec = *node_ids; init_vecs(ccx, node_id_vec, num_constraints); } -fn annotate_in_fn(ccx: &crate_ctxt, f: &_fn, tps: &[ty_param], sp: &span, - i: &fn_ident, id: node_id) { +fn annotate_in_fn(ccx: crate_ctxt, f: _fn, tps: [ty_param], sp: span, + i: fn_ident, id: node_id) { let f_info = get_fn_info(ccx, id); visit_fn(ccx, num_constraints(f_info), f, tps, sp, i, id); } -fn annotate_crate(ccx: &crate_ctxt, crate: &crate) { +fn annotate_crate(ccx: crate_ctxt, crate: crate) { let do_ann = visit::mk_simple_visitor(@{visit_fn: bind annotate_in_fn(ccx, _, _, _, _, _) diff --git a/src/comp/middle/tstate/auxiliary.rs b/src/comp/middle/tstate/auxiliary.rs index 63ff90c4792..b873b9d6233 100644 --- a/src/comp/middle/tstate/auxiliary.rs +++ b/src/comp/middle/tstate/auxiliary.rs @@ -59,7 +59,7 @@ fn def_id_to_str(d: def_id) -> str { ret int::str(d.crate) + "," + int::str(d.node); } -fn comma_str(args: &[@constr_arg_use]) -> str { +fn comma_str(args: [@constr_arg_use]) -> str { let rslt = ""; let comma = false; for a: @constr_arg_use in args { @@ -73,7 +73,7 @@ fn comma_str(args: &[@constr_arg_use]) -> str { ret rslt; } -fn constraint_to_str(tcx: &ty::ctxt, c: &sp_constr) -> str { +fn constraint_to_str(tcx: ty::ctxt, c: sp_constr) -> str { alt c.node { ninit(_, i) { ret "init(" + i + " [" + tcx.sess.span_str(c.span) + "])"; @@ -85,7 +85,7 @@ fn constraint_to_str(tcx: &ty::ctxt, c: &sp_constr) -> str { } } -fn tritv_to_str(fcx: fn_ctxt, v: &tritv::t) -> str { +fn tritv_to_str(fcx: fn_ctxt, v: tritv::t) -> str { let s = ""; let comma = false; for p: norm_constraint in constraints(fcx) { @@ -102,10 +102,10 @@ fn tritv_to_str(fcx: fn_ctxt, v: &tritv::t) -> str { ret s; } -fn log_tritv(fcx: &fn_ctxt, v: &tritv::t) { log tritv_to_str(fcx, v); } +fn log_tritv(fcx: fn_ctxt, v: tritv::t) { log tritv_to_str(fcx, v); } -fn first_difference_string(fcx: &fn_ctxt, expected: &tritv::t, - actual: &tritv::t) -> str { +fn first_difference_string(fcx: fn_ctxt, expected: tritv::t, actual: tritv::t) + -> str { let s: str = ""; for c: norm_constraint in constraints(fcx) { if tritv_get(expected, c.bit_num) == ttrue && @@ -118,7 +118,7 @@ fn first_difference_string(fcx: &fn_ctxt, expected: &tritv::t, fn log_tritv_err(fcx: fn_ctxt, v: tritv::t) { log_err tritv_to_str(fcx, v); } -fn tos(v: &[uint]) -> str { +fn tos(v: [uint]) -> str { let rslt = ""; for i: uint in v { if i == 0u { @@ -128,11 +128,11 @@ fn tos(v: &[uint]) -> str { ret rslt; } -fn log_cond(v: &[uint]) { log tos(v); } +fn log_cond(v: [uint]) { log tos(v); } -fn log_cond_err(v: &[uint]) { log_err tos(v); } +fn log_cond_err(v: [uint]) { log_err tos(v); } -fn log_pp(pp: &pre_and_post) { +fn log_pp(pp: pre_and_post) { let p1 = tritv::to_vec(pp.precondition); let p2 = tritv::to_vec(pp.postcondition); log "pre:"; @@ -141,7 +141,7 @@ fn log_pp(pp: &pre_and_post) { log_cond(p2); } -fn log_pp_err(pp: &pre_and_post) { +fn log_pp_err(pp: pre_and_post) { let p1 = tritv::to_vec(pp.precondition); let p2 = tritv::to_vec(pp.postcondition); log_err "pre:"; @@ -150,7 +150,7 @@ fn log_pp_err(pp: &pre_and_post) { log_cond_err(p2); } -fn log_states(pp: &pre_and_post_state) { +fn log_states(pp: pre_and_post_state) { let p1 = tritv::to_vec(pp.prestate); let p2 = tritv::to_vec(pp.poststate); log "prestate:"; @@ -159,7 +159,7 @@ fn log_states(pp: &pre_and_post_state) { log_cond(p2); } -fn log_states_err(pp: &pre_and_post_state) { +fn log_states_err(pp: pre_and_post_state) { let p1 = tritv::to_vec(pp.prestate); let p2 = tritv::to_vec(pp.poststate); log_err "prestate:"; @@ -168,7 +168,7 @@ fn log_states_err(pp: &pre_and_post_state) { log_cond_err(p2); } -fn print_ident(i: &ident) { log " " + i + " "; } +fn print_ident(i: ident) { log " " + i + " "; } fn print_idents(idents: &mutable [ident]) { if vec::len::<ident>(idents) == 0u { ret; } @@ -281,11 +281,11 @@ type fn_info = i_diverge: tsconstr, used_vars: @mutable [node_id]}; -fn tsconstr_to_def_id(t: &tsconstr) -> def_id { +fn tsconstr_to_def_id(t: tsconstr) -> def_id { alt t { ninit(id, _) { local_def(id) } npred(_, id, _) { id } } } -fn tsconstr_to_node_id(t: &tsconstr) -> node_id { +fn tsconstr_to_node_id(t: tsconstr) -> node_id { alt t { ninit(id, _) { id } npred(_, id, _) { fail "tsconstr_to_node_id called on pred constraint" } @@ -304,12 +304,12 @@ type fn_ctxt = type crate_ctxt = {tcx: ty::ctxt, node_anns: node_ann_table, fm: fn_info_map}; -fn get_fn_info(ccx: &crate_ctxt, id: node_id) -> fn_info { +fn get_fn_info(ccx: crate_ctxt, id: node_id) -> fn_info { assert (ccx.fm.contains_key(id)); ret ccx.fm.get(id); } -fn add_node(ccx: &crate_ctxt, i: node_id, a: &ts_ann) { +fn add_node(ccx: crate_ctxt, i: node_id, a: ts_ann) { let sz = vec::len(*ccx.node_anns); if sz <= i as uint { vec::grow_mut(*ccx.node_anns, (i as uint) - sz + 1u, empty_ann(0u)); @@ -317,7 +317,7 @@ fn add_node(ccx: &crate_ctxt, i: node_id, a: &ts_ann) { ccx.node_anns[i] = a; } -fn get_ts_ann(ccx: &crate_ctxt, i: node_id) -> option::t<ts_ann> { +fn get_ts_ann(ccx: crate_ctxt, i: node_id) -> option::t<ts_ann> { if i as uint < vec::len(*ccx.node_anns) { ret some::<ts_ann>(ccx.node_anns[i]); } else { ret none::<ts_ann>; } @@ -325,7 +325,7 @@ fn get_ts_ann(ccx: &crate_ctxt, i: node_id) -> option::t<ts_ann> { /********* utils ********/ -fn node_id_to_ts_ann(ccx: &crate_ctxt, id: node_id) -> ts_ann { +fn node_id_to_ts_ann(ccx: crate_ctxt, id: node_id) -> ts_ann { alt get_ts_ann(ccx, id) { none. { log_err "node_id_to_ts_ann: no ts_ann for node_id " + int::str(id); @@ -335,12 +335,12 @@ fn node_id_to_ts_ann(ccx: &crate_ctxt, id: node_id) -> ts_ann { } } -fn node_id_to_poststate(ccx: &crate_ctxt, id: node_id) -> poststate { +fn node_id_to_poststate(ccx: crate_ctxt, id: node_id) -> poststate { log "node_id_to_poststate"; ret node_id_to_ts_ann(ccx, id).states.poststate; } -fn stmt_to_ann(ccx: &crate_ctxt, s: &stmt) -> ts_ann { +fn stmt_to_ann(ccx: crate_ctxt, s: stmt) -> ts_ann { log "stmt_to_ann"; alt s.node { stmt_decl(_, id) { ret node_id_to_ts_ann(ccx, id); } @@ -354,25 +354,25 @@ fn stmt_to_ann(ccx: &crate_ctxt, s: &stmt) -> ts_ann { /* fails if e has no annotation */ -fn expr_states(ccx: &crate_ctxt, e: @expr) -> pre_and_post_state { +fn expr_states(ccx: crate_ctxt, e: @expr) -> pre_and_post_state { log "expr_states"; ret node_id_to_ts_ann(ccx, e.id).states; } /* fails if e has no annotation */ -fn expr_pp(ccx: &crate_ctxt, e: @expr) -> pre_and_post { +fn expr_pp(ccx: crate_ctxt, e: @expr) -> pre_and_post { log "expr_pp"; ret node_id_to_ts_ann(ccx, e.id).conditions; } -fn stmt_pp(ccx: &crate_ctxt, s: &stmt) -> pre_and_post { +fn stmt_pp(ccx: crate_ctxt, s: stmt) -> pre_and_post { ret stmt_to_ann(ccx, s).conditions; } /* fails if b has no annotation */ -fn block_pp(ccx: &crate_ctxt, b: &blk) -> pre_and_post { +fn block_pp(ccx: crate_ctxt, b: blk) -> pre_and_post { log "block_pp"; ret node_id_to_ts_ann(ccx, b.node.id).conditions; } @@ -382,111 +382,109 @@ fn clear_pp(pp: pre_and_post) { ann::clear(pp.postcondition); } -fn clear_precond(ccx: &crate_ctxt, id: node_id) { +fn clear_precond(ccx: crate_ctxt, id: node_id) { let pp = node_id_to_ts_ann(ccx, id); ann::clear(pp.conditions.precondition); } -fn block_states(ccx: &crate_ctxt, b: &blk) -> pre_and_post_state { +fn block_states(ccx: crate_ctxt, b: blk) -> pre_and_post_state { log "block_states"; ret node_id_to_ts_ann(ccx, b.node.id).states; } -fn stmt_states(ccx: &crate_ctxt, s: &stmt) -> pre_and_post_state { +fn stmt_states(ccx: crate_ctxt, s: stmt) -> pre_and_post_state { ret stmt_to_ann(ccx, s).states; } -fn expr_precond(ccx: &crate_ctxt, e: @expr) -> precond { +fn expr_precond(ccx: crate_ctxt, e: @expr) -> precond { ret expr_pp(ccx, e).precondition; } -fn expr_postcond(ccx: &crate_ctxt, e: @expr) -> postcond { +fn expr_postcond(ccx: crate_ctxt, e: @expr) -> postcond { ret expr_pp(ccx, e).postcondition; } -fn expr_prestate(ccx: &crate_ctxt, e: @expr) -> prestate { +fn expr_prestate(ccx: crate_ctxt, e: @expr) -> prestate { ret expr_states(ccx, e).prestate; } -fn expr_poststate(ccx: &crate_ctxt, e: @expr) -> poststate { +fn expr_poststate(ccx: crate_ctxt, e: @expr) -> poststate { ret expr_states(ccx, e).poststate; } -fn stmt_precond(ccx: &crate_ctxt, s: &stmt) -> precond { +fn stmt_precond(ccx: crate_ctxt, s: stmt) -> precond { ret stmt_pp(ccx, s).precondition; } -fn stmt_postcond(ccx: &crate_ctxt, s: &stmt) -> postcond { +fn stmt_postcond(ccx: crate_ctxt, s: stmt) -> postcond { ret stmt_pp(ccx, s).postcondition; } -fn states_to_poststate(ss: &pre_and_post_state) -> poststate { +fn states_to_poststate(ss: pre_and_post_state) -> poststate { ret ss.poststate; } -fn stmt_prestate(ccx: &crate_ctxt, s: &stmt) -> prestate { +fn stmt_prestate(ccx: crate_ctxt, s: stmt) -> prestate { ret stmt_states(ccx, s).prestate; } -fn stmt_poststate(ccx: &crate_ctxt, s: &stmt) -> poststate { +fn stmt_poststate(ccx: crate_ctxt, s: stmt) -> poststate { ret stmt_states(ccx, s).poststate; } -fn block_precond(ccx: &crate_ctxt, b: &blk) -> precond { +fn block_precond(ccx: crate_ctxt, b: blk) -> precond { ret block_pp(ccx, b).precondition; } -fn block_postcond(ccx: &crate_ctxt, b: &blk) -> postcond { +fn block_postcond(ccx: crate_ctxt, b: blk) -> postcond { ret block_pp(ccx, b).postcondition; } -fn block_prestate(ccx: &crate_ctxt, b: &blk) -> prestate { +fn block_prestate(ccx: crate_ctxt, b: blk) -> prestate { ret block_states(ccx, b).prestate; } -fn block_poststate(ccx: &crate_ctxt, b: &blk) -> poststate { +fn block_poststate(ccx: crate_ctxt, b: blk) -> poststate { ret block_states(ccx, b).poststate; } -fn set_prestate_ann(ccx: &crate_ctxt, id: node_id, pre: &prestate) -> bool { +fn set_prestate_ann(ccx: crate_ctxt, id: node_id, pre: prestate) -> bool { log "set_prestate_ann"; ret set_prestate(node_id_to_ts_ann(ccx, id), pre); } -fn extend_prestate_ann(ccx: &crate_ctxt, id: node_id, pre: &prestate) -> - bool { +fn extend_prestate_ann(ccx: crate_ctxt, id: node_id, pre: prestate) -> bool { log "extend_prestate_ann"; ret extend_prestate(node_id_to_ts_ann(ccx, id).states.prestate, pre); } -fn set_poststate_ann(ccx: &crate_ctxt, id: node_id, post: &poststate) -> - bool { +fn set_poststate_ann(ccx: crate_ctxt, id: node_id, post: poststate) -> bool { log "set_poststate_ann"; ret set_poststate(node_id_to_ts_ann(ccx, id), post); } -fn extend_poststate_ann(ccx: &crate_ctxt, id: node_id, post: &poststate) -> +fn extend_poststate_ann(ccx: crate_ctxt, id: node_id, post: poststate) -> bool { log "extend_poststate_ann"; ret extend_poststate(node_id_to_ts_ann(ccx, id).states.poststate, post); } -fn set_pre_and_post(ccx: &crate_ctxt, id: node_id, pre: &precond, - post: &postcond) { +fn set_pre_and_post(ccx: crate_ctxt, id: node_id, pre: precond, + post: postcond) { log "set_pre_and_post"; let t = node_id_to_ts_ann(ccx, id); set_precondition(t, pre); set_postcondition(t, post); } -fn copy_pre_post(ccx: &crate_ctxt, id: node_id, sub: &@expr) { +fn copy_pre_post(ccx: crate_ctxt, id: node_id, sub: @expr) { log "set_pre_and_post"; let p = expr_pp(ccx, sub); copy_pre_post_(ccx, id, p.precondition, p.postcondition); } -fn copy_pre_post_(ccx: &crate_ctxt, id: node_id, pre: &prestate, - post: &poststate) { +fn copy_pre_post_(ccx: crate_ctxt, id: node_id, pre: prestate, + post: poststate) { log "set_pre_and_post"; let t = node_id_to_ts_ann(ccx, id); set_precondition(t, pre); @@ -494,12 +492,12 @@ fn copy_pre_post_(ccx: &crate_ctxt, id: node_id, pre: &prestate, } /* sets all bits to *1* */ -fn set_postcond_false(ccx: &crate_ctxt, id: node_id) { +fn set_postcond_false(ccx: crate_ctxt, id: node_id) { let p = node_id_to_ts_ann(ccx, id); ann::set(p.conditions.postcondition); } -fn pure_exp(ccx: &crate_ctxt, id: node_id, p: &prestate) -> bool { +fn pure_exp(ccx: crate_ctxt, id: node_id, p: prestate) -> bool { ret set_prestate_ann(ccx, id, p) | set_poststate_ann(ccx, id, p); } @@ -513,21 +511,21 @@ fn new_crate_ctxt(cx: ty::ctxt) -> crate_ctxt { /* Use e's type to determine whether it returns. If it has a function type with a ! annotation, the answer is noreturn. */ -fn controlflow_expr(ccx: &crate_ctxt, e: @expr) -> controlflow { +fn controlflow_expr(ccx: crate_ctxt, e: @expr) -> controlflow { alt ty::struct(ccx.tcx, ty::node_id_to_type(ccx.tcx, e.id)) { ty::ty_fn(_, _, _, cf, _) { ret cf; } _ { ret return; } } } -fn constraints_expr(cx: &ty::ctxt, e: @expr) -> [@ty::constr] { +fn constraints_expr(cx: ty::ctxt, e: @expr) -> [@ty::constr] { alt ty::struct(cx, ty::node_id_to_type(cx, e.id)) { ty::ty_fn(_, _, _, _, cs) { ret cs; } _ { ret []; } } } -fn node_id_to_def_strict(cx: &ty::ctxt, id: node_id) -> def { +fn node_id_to_def_strict(cx: ty::ctxt, id: node_id) -> def { alt cx.def_map.find(id) { none. { log_err "node_id_to_def: node_id " + int::str(id) + " has no def"; @@ -537,11 +535,11 @@ fn node_id_to_def_strict(cx: &ty::ctxt, id: node_id) -> def { } } -fn node_id_to_def(ccx: &crate_ctxt, id: node_id) -> option::t<def> { +fn node_id_to_def(ccx: crate_ctxt, id: node_id) -> option::t<def> { ret ccx.tcx.def_map.find(id); } -fn norm_a_constraint(id: def_id, c: &constraint) -> [norm_constraint] { +fn norm_a_constraint(id: def_id, c: constraint) -> [norm_constraint] { alt c { cinit(n, sp, i) { ret [{bit_num: n, c: respan(sp, ninit(id.node, i))}]; @@ -561,7 +559,7 @@ fn norm_a_constraint(id: def_id, c: &constraint) -> [norm_constraint] { // Tried to write this as an iterator, but I got a // non-exhaustive match in trans. -fn constraints(fcx: &fn_ctxt) -> [norm_constraint] { +fn constraints(fcx: fn_ctxt) -> [norm_constraint] { let rslt: [norm_constraint] = []; for each p: @{key: def_id, val: constraint} in fcx.enclosing.constrs.items() { @@ -573,13 +571,13 @@ fn constraints(fcx: &fn_ctxt) -> [norm_constraint] { // FIXME // Would rather take an immutable vec as an argument, // should freeze it at some earlier point. -fn match_args(fcx: &fn_ctxt, occs: &@mutable [pred_args], - occ: &[@constr_arg_use]) -> uint { +fn match_args(fcx: fn_ctxt, occs: @mutable [pred_args], + occ: [@constr_arg_use]) -> uint { log "match_args: looking at " + - constr_args_to_str(fn (i: &inst) -> str { ret i.ident; }, occ); + constr_args_to_str(fn (i: inst) -> str { ret i.ident; }, occ); for pd: pred_args in *occs { log "match_args: candidate " + pred_args_to_str(pd); - fn eq(p: &inst, q: &inst) -> bool { ret p.node == q.node; } + fn eq(p: inst, q: inst) -> bool { ret p.node == q.node; } if ty::args_eq(eq, pd.node.args, occ) { ret pd.node.bit_num; } } fcx.ccx.tcx.sess.bug("match_args: no match for occurring args"); @@ -595,7 +593,7 @@ fn def_id_for_constr(tcx: ty::ctxt, t: node_id) -> def_id { } } -fn expr_to_constr_arg(tcx: ty::ctxt, e: &@expr) -> @constr_arg_use { +fn expr_to_constr_arg(tcx: ty::ctxt, e: @expr) -> @constr_arg_use { alt e.node { expr_path(p) { alt tcx.def_map.find(e.id) { @@ -623,14 +621,14 @@ fn expr_to_constr_arg(tcx: ty::ctxt, e: &@expr) -> @constr_arg_use { } } -fn exprs_to_constr_args(tcx: ty::ctxt, args: &[@expr]) -> [@constr_arg_use] { +fn exprs_to_constr_args(tcx: ty::ctxt, args: [@expr]) -> [@constr_arg_use] { let f = bind expr_to_constr_arg(tcx, _); let rslt: [@constr_arg_use] = []; for e: @expr in args { rslt += [f(e)]; } rslt } -fn expr_to_constr(tcx: ty::ctxt, e: &@expr) -> sp_constr { +fn expr_to_constr(tcx: ty::ctxt, e: @expr) -> sp_constr { alt e.node { expr_call(operator, args) { alt operator.node { @@ -654,14 +652,14 @@ fn expr_to_constr(tcx: ty::ctxt, e: &@expr) -> sp_constr { } } -fn pred_args_to_str(p: &pred_args) -> str { +fn pred_args_to_str(p: pred_args) -> str { "<" + uint::str(p.node.bit_num) + ", " + - constr_args_to_str(fn (i: &inst) -> str { ret i.ident; }, p.node.args) + constr_args_to_str(fn (i: inst) -> str { ret i.ident; }, p.node.args) + ">" } -fn substitute_constr_args(cx: &ty::ctxt, actuals: &[@expr], c: &@ty::constr) - -> tsconstr { +fn substitute_constr_args(cx: ty::ctxt, actuals: [@expr], c: @ty::constr) -> + tsconstr { let rslt: [@constr_arg_use] = []; for a: @constr_arg in c.node.args { rslt += [substitute_arg(cx, actuals, a)]; @@ -669,7 +667,7 @@ fn substitute_constr_args(cx: &ty::ctxt, actuals: &[@expr], c: &@ty::constr) ret npred(c.node.path, c.node.id, rslt); } -fn substitute_arg(cx: &ty::ctxt, actuals: &[@expr], a: @constr_arg) -> +fn substitute_arg(cx: ty::ctxt, actuals: [@expr], a: @constr_arg) -> @constr_arg_use { let num_actuals = vec::len(actuals); alt a.node { @@ -685,8 +683,8 @@ fn substitute_arg(cx: &ty::ctxt, actuals: &[@expr], a: @constr_arg) -> } } -fn pred_args_matches(pattern: &[constr_arg_general_<inst>], desc: &pred_args) - -> bool { +fn pred_args_matches(pattern: [constr_arg_general_<inst>], desc: pred_args) -> + bool { let i = 0u; for c: @constr_arg_use in desc.node.args { let n = pattern[i]; @@ -710,8 +708,8 @@ fn pred_args_matches(pattern: &[constr_arg_general_<inst>], desc: &pred_args) ret true; } -fn find_instance_(pattern: &[constr_arg_general_<inst>], descs: &[pred_args]) - -> option::t<uint> { +fn find_instance_(pattern: [constr_arg_general_<inst>], descs: [pred_args]) -> + option::t<uint> { for d: pred_args in descs { if pred_args_matches(pattern, d) { ret some(d.node.bit_num); } } @@ -721,7 +719,7 @@ fn find_instance_(pattern: &[constr_arg_general_<inst>], descs: &[pred_args]) type inst = {ident: ident, node: node_id}; type subst = [{from: inst, to: inst}]; -fn find_instances(_fcx: &fn_ctxt, subst: &subst, c: &constraint) -> +fn find_instances(_fcx: fn_ctxt, subst: subst, c: constraint) -> [{from: uint, to: uint}] { let rslt = []; @@ -745,18 +743,18 @@ fn find_instances(_fcx: &fn_ctxt, subst: &subst, c: &constraint) -> rslt } -fn find_in_subst(id: node_id, s: &subst) -> option::t<inst> { +fn find_in_subst(id: node_id, s: subst) -> option::t<inst> { for p: {from: inst, to: inst} in s { if id == p.from.node { ret some(p.to); } } ret none; } -fn find_in_subst_bool(s: &subst, id: node_id) -> bool { +fn find_in_subst_bool(s: subst, id: node_id) -> bool { is_some(find_in_subst(id, s)) } -fn insts_to_str(stuff: &[constr_arg_general_<inst>]) -> str { +fn insts_to_str(stuff: [constr_arg_general_<inst>]) -> str { let rslt = "<"; for i: constr_arg_general_<inst> in stuff { rslt += @@ -802,7 +800,7 @@ fn replace(subst: subst, d: pred_args) -> [constr_arg_general_<inst>] { ret rslt; } -fn path_to_ident(cx: &ty::ctxt, p: &path) -> ident { +fn path_to_ident(cx: ty::ctxt, p: path) -> ident { alt vec::last(p.node.idents) { none. { cx.sess.span_fatal(p.span, "Malformed path"); } some(i) { ret i; } @@ -811,7 +809,7 @@ fn path_to_ident(cx: &ty::ctxt, p: &path) -> ident { tag if_ty { if_check; plain_if; } -fn local_node_id_to_def_id_strict(fcx: &fn_ctxt, sp: &span, i: &node_id) -> +fn local_node_id_to_def_id_strict(fcx: fn_ctxt, sp: span, i: node_id) -> def_id { alt local_node_id_to_def(fcx, i) { some(def_local(id)) | some(def_arg(id, _)) | some(def_upvar(id, _, _)) { @@ -831,11 +829,11 @@ fn local_node_id_to_def_id_strict(fcx: &fn_ctxt, sp: &span, i: &node_id) -> } } -fn local_node_id_to_def(fcx: &fn_ctxt, i: &node_id) -> option::t<def> { +fn local_node_id_to_def(fcx: fn_ctxt, i: node_id) -> option::t<def> { fcx.ccx.tcx.def_map.find(i) } -fn local_node_id_to_def_id(fcx: &fn_ctxt, i: &node_id) -> option::t<def_id> { +fn local_node_id_to_def_id(fcx: fn_ctxt, i: node_id) -> option::t<def_id> { alt local_node_id_to_def(fcx, i) { some(def_local(id)) | some(def_arg(id, _)) | some(def_binding(id)) | some(def_upvar(id, _, _)) { @@ -845,7 +843,7 @@ fn local_node_id_to_def_id(fcx: &fn_ctxt, i: &node_id) -> option::t<def_id> { } } -fn local_node_id_to_local_def_id(fcx: &fn_ctxt, i: &node_id) -> +fn local_node_id_to_local_def_id(fcx: fn_ctxt, i: node_id) -> option::t<node_id> { alt local_node_id_to_def_id(fcx, i) { some(did) { some(did.node) } @@ -853,7 +851,7 @@ fn local_node_id_to_local_def_id(fcx: &fn_ctxt, i: &node_id) -> } } -fn copy_in_postcond(fcx: &fn_ctxt, parent_exp: node_id, dest: inst, src: inst, +fn copy_in_postcond(fcx: fn_ctxt, parent_exp: node_id, dest: inst, src: inst, ty: oper_type) { let post = node_id_to_ts_ann(fcx.ccx, parent_exp).conditions.postcondition; @@ -861,7 +859,7 @@ fn copy_in_postcond(fcx: &fn_ctxt, parent_exp: node_id, dest: inst, src: inst, } // FIXME refactor -fn copy_in_poststate(fcx: &fn_ctxt, post: &poststate, dest: inst, src: inst, +fn copy_in_poststate(fcx: fn_ctxt, post: poststate, dest: inst, src: inst, ty: oper_type) { copy_in_poststate_two(fcx, post, post, dest, src, ty); } @@ -871,8 +869,8 @@ fn copy_in_poststate(fcx: &fn_ctxt, post: &poststate, dest: inst, src: inst, // dest substituted for src. // (This doesn't create any new constraints. If a new, substituted // constraint isn't already in the bit vector, it's ignored.) -fn copy_in_poststate_two(fcx: &fn_ctxt, src_post: &poststate, - target_post: &poststate, dest: inst, src: inst, +fn copy_in_poststate_two(fcx: fn_ctxt, src_post: poststate, + target_post: poststate, dest: inst, src: inst, ty: oper_type) { let subst; alt ty { @@ -899,7 +897,7 @@ fn copy_in_poststate_two(fcx: &fn_ctxt, src_post: &poststate, /* FIXME should refactor this better */ -fn forget_in_postcond(fcx: &fn_ctxt, parent_exp: node_id, dead_v: node_id) { +fn forget_in_postcond(fcx: fn_ctxt, parent_exp: node_id, dead_v: node_id) { // In the postcondition given by parent_exp, clear the bits // for any constraints mentioning dead_v let d = local_node_id_to_local_def_id(fcx, dead_v); @@ -917,7 +915,7 @@ fn forget_in_postcond(fcx: &fn_ctxt, parent_exp: node_id, dead_v: node_id) { } } -fn forget_in_postcond_still_init(fcx: &fn_ctxt, parent_exp: node_id, +fn forget_in_postcond_still_init(fcx: fn_ctxt, parent_exp: node_id, dead_v: node_id) { // In the postcondition given by parent_exp, clear the bits // for any constraints mentioning dead_v @@ -936,8 +934,7 @@ fn forget_in_postcond_still_init(fcx: &fn_ctxt, parent_exp: node_id, } } -fn forget_in_poststate(fcx: &fn_ctxt, p: &poststate, dead_v: node_id) -> - bool { +fn forget_in_poststate(fcx: fn_ctxt, p: poststate, dead_v: node_id) -> bool { // In the poststate given by parent_exp, clear the bits // for any constraints mentioning dead_v let d = local_node_id_to_local_def_id(fcx, dead_v); @@ -955,8 +952,8 @@ fn forget_in_poststate(fcx: &fn_ctxt, p: &poststate, dead_v: node_id) -> ret changed; } -fn forget_in_poststate_still_init(fcx: &fn_ctxt, p: &poststate, - dead_v: node_id) -> bool { +fn forget_in_poststate_still_init(fcx: fn_ctxt, p: poststate, dead_v: node_id) + -> bool { // In the poststate given by parent_exp, clear the bits // for any constraints mentioning dead_v let d = local_node_id_to_local_def_id(fcx, dead_v); @@ -974,12 +971,12 @@ fn forget_in_poststate_still_init(fcx: &fn_ctxt, p: &poststate, ret changed; } -fn any_eq(v: &[node_id], d: node_id) -> bool { +fn any_eq(v: [node_id], d: node_id) -> bool { for i: node_id in v { if i == d { ret true; } } false } -fn constraint_mentions(_fcx: &fn_ctxt, c: &norm_constraint, v: node_id) -> +fn constraint_mentions(_fcx: fn_ctxt, c: norm_constraint, v: node_id) -> bool { ret alt c.c.node { ninit(id, _) { v == id } @@ -987,16 +984,16 @@ fn constraint_mentions(_fcx: &fn_ctxt, c: &norm_constraint, v: node_id) -> }; } -fn non_init_constraint_mentions(_fcx: &fn_ctxt, c: &norm_constraint, - v: &node_id) -> bool { +fn non_init_constraint_mentions(_fcx: fn_ctxt, c: norm_constraint, v: node_id) + -> bool { ret alt c.c.node { ninit(_, _) { false } npred(_, _, args) { args_mention(args, any_eq, [v]) } }; } -fn args_mention<T>(args: &[@constr_arg_use], q: fn(&[T], node_id) -> bool, - s: &[T]) -> bool { +fn args_mention<T>(args: [@constr_arg_use], q: fn([T], node_id) -> bool, + s: [T]) -> bool { /* FIXME The following version causes an assertion in trans to fail @@ -1021,10 +1018,10 @@ fn args_mention<T>(args: &[@constr_arg_use], q: fn(&[T], node_id) -> bool, ret false; } -fn use_var(fcx: &fn_ctxt, v: &node_id) { *fcx.enclosing.used_vars += [v]; } +fn use_var(fcx: fn_ctxt, v: node_id) { *fcx.enclosing.used_vars += [v]; } // FIXME: This should be a function in std::vec::. -fn vec_contains(v: &@mutable [node_id], i: &node_id) -> bool { +fn vec_contains(v: @mutable [node_id], i: node_id) -> bool { for d: node_id in *v { if d == i { ret true; } } ret false; } @@ -1034,14 +1031,13 @@ fn op_to_oper_ty(io: init_op) -> oper_type { } // default function visitor -fn do_nothing<T>(_f: &_fn, _tp: &[ty_param], _sp: &span, _i: &fn_ident, - _iid: node_id, _cx: &T, _v: &visit::vt<T>) { +fn do_nothing<T>(_f: _fn, _tp: [ty_param], _sp: span, _i: fn_ident, + _iid: node_id, _cx: T, _v: visit::vt<T>) { } -fn args_to_constr_args(tcx: &ty::ctxt, args: &[arg], - indices: &[@sp_constr_arg<uint>]) -> - [@constr_arg_use] { +fn args_to_constr_args(tcx: ty::ctxt, args: [arg], + indices: [@sp_constr_arg<uint>]) -> [@constr_arg_use] { let actuals: [@constr_arg_use] = []; let num_args = vec::len(args); for a: @sp_constr_arg<uint> in indices { @@ -1065,14 +1061,14 @@ fn args_to_constr_args(tcx: &ty::ctxt, args: &[arg], ret actuals; } -fn ast_constr_to_ts_constr(tcx: &ty::ctxt, args: &[arg], c: &@constr) -> +fn ast_constr_to_ts_constr(tcx: ty::ctxt, args: [arg], c: @constr) -> tsconstr { let tconstr = ty::ast_constr_to_constr(tcx, c); ret npred(tconstr.node.path, tconstr.node.id, args_to_constr_args(tcx, args, tconstr.node.args)); } -fn ast_constr_to_sp_constr(tcx: &ty::ctxt, args: &[arg], c: &@constr) -> +fn ast_constr_to_sp_constr(tcx: ty::ctxt, args: [arg], c: @constr) -> sp_constr { let tconstr = ast_constr_to_ts_constr(tcx, args, c); ret respan(c.span, tconstr); @@ -1080,7 +1076,7 @@ fn ast_constr_to_sp_constr(tcx: &ty::ctxt, args: &[arg], c: &@constr) -> type binding = {lhs: [inst], rhs: option::t<initializer>}; -fn local_to_bindings(loc: &@local) -> binding { +fn local_to_bindings(loc: @local) -> binding { let lhs = []; for each p: @pat in pat_bindings(loc.node.pat) { let ident = alt p.node { pat_bind(name) { name } }; @@ -1089,11 +1085,11 @@ fn local_to_bindings(loc: &@local) -> binding { {lhs: lhs, rhs: loc.node.init} } -fn locals_to_bindings(locals: &[@local]) -> [binding] { +fn locals_to_bindings(locals: [@local]) -> [binding] { vec::map(local_to_bindings, locals) } -fn callee_modes(fcx: &fn_ctxt, callee: node_id) -> [ty::mode] { +fn callee_modes(fcx: fn_ctxt, callee: node_id) -> [ty::mode] { let ty = ty::type_autoderef(fcx.ccx.tcx, ty::node_id_to_type(fcx.ccx.tcx, callee)); @@ -1111,14 +1107,14 @@ fn callee_modes(fcx: &fn_ctxt, callee: node_id) -> [ty::mode] { } } -fn callee_arg_init_ops(fcx: &fn_ctxt, callee: node_id) -> [init_op] { - fn mode_to_op(m: &ty::mode) -> init_op { +fn callee_arg_init_ops(fcx: fn_ctxt, callee: node_id) -> [init_op] { + fn mode_to_op(m: ty::mode) -> init_op { alt m { by_move. { init_move } _ { init_assign } } } vec::map(mode_to_op, callee_modes(fcx, callee)) } -fn anon_bindings(ops: &[init_op], es: &[@expr]) -> [binding] { +fn anon_bindings(ops: [init_op], es: [@expr]) -> [binding] { let bindings: [binding] = []; let i = 0; for op: init_op in ops { diff --git a/src/comp/middle/tstate/bitvectors.rs b/src/comp/middle/tstate/bitvectors.rs index 8c37df3cec4..329c542fcdd 100644 --- a/src/comp/middle/tstate/bitvectors.rs +++ b/src/comp/middle/tstate/bitvectors.rs @@ -27,7 +27,7 @@ import tstate::ann::clear_in_poststate_; import tritv::*; import util::common::*; -fn bit_num(fcx: &fn_ctxt, c: &tsconstr) -> uint { +fn bit_num(fcx: fn_ctxt, c: tsconstr) -> uint { let d = tsconstr_to_def_id(c); assert (fcx.enclosing.constrs.contains_key(d)); let rslt = fcx.enclosing.constrs.get(d); @@ -53,11 +53,11 @@ fn bit_num(fcx: &fn_ctxt, c: &tsconstr) -> uint { } } -fn promises(fcx: &fn_ctxt, p: &poststate, c: &tsconstr) -> bool { +fn promises(fcx: fn_ctxt, p: poststate, c: tsconstr) -> bool { ret promises_(bit_num(fcx, c), p); } -fn promises_(n: uint, p: &poststate) -> bool { ret tritv_get(p, n) == ttrue; } +fn promises_(n: uint, p: poststate) -> bool { ret tritv_get(p, n) == ttrue; } // v "happens after" u fn seq_trit(u: trit, v: trit) -> trit { @@ -67,7 +67,7 @@ fn seq_trit(u: trit, v: trit) -> trit { // idea: q "happens after" p -- so if something is // 1 in q and 0 in p, it's 1 in the result; however, // if it's 0 in q and 1 in p, it's 0 in the result -fn seq_tritv(p: &postcond, q: &postcond) { +fn seq_tritv(p: postcond, q: postcond) { let i = 0u; assert (p.nbits == q.nbits); while i < p.nbits { @@ -76,7 +76,7 @@ fn seq_tritv(p: &postcond, q: &postcond) { } } -fn seq_postconds(fcx: &fn_ctxt, ps: &[postcond]) -> postcond { +fn seq_postconds(fcx: fn_ctxt, ps: [postcond]) -> postcond { let sz = vec::len(ps); if sz >= 1u { let prev = tritv_clone(ps[0]); @@ -89,12 +89,12 @@ fn seq_postconds(fcx: &fn_ctxt, ps: &[postcond]) -> postcond { // return the precondition for evaluating each expr in order. // So, if e0's post is {x} and e1's pre is {x, y, z}, the entire // precondition shouldn't include x. -fn seq_preconds(fcx: &fn_ctxt, pps: &[pre_and_post]) -> precond { +fn seq_preconds(fcx: fn_ctxt, pps: [pre_and_post]) -> precond { let sz: uint = vec::len(pps); let num_vars: uint = num_constraints(fcx.enclosing); - fn seq_preconds_go(fcx: &fn_ctxt, pps: &[pre_and_post], - first: &pre_and_post) -> precond { + fn seq_preconds_go(fcx: fn_ctxt, pps: [pre_and_post], first: pre_and_post) + -> precond { let sz: uint = vec::len(pps); if sz >= 1u { let second = pps[0]; @@ -119,18 +119,18 @@ fn seq_preconds(fcx: &fn_ctxt, pps: &[pre_and_post]) -> precond { } else { ret true_precond(num_vars); } } -fn intersect_states(p: &prestate, q: &prestate) -> prestate { +fn intersect_states(p: prestate, q: prestate) -> prestate { let rslt = tritv_clone(p); tritv_intersect(rslt, q); ret rslt; } -fn gen(fcx: &fn_ctxt, id: node_id, c: &tsconstr) -> bool { +fn gen(fcx: fn_ctxt, id: node_id, c: tsconstr) -> bool { ret set_in_postcond(bit_num(fcx, c), node_id_to_ts_ann(fcx.ccx, id).conditions); } -fn declare_var(fcx: &fn_ctxt, c: &tsconstr, pre: prestate) -> prestate { +fn declare_var(fcx: fn_ctxt, c: tsconstr, pre: prestate) -> prestate { let rslt = clone(pre); relax_prestate(bit_num(fcx, c), rslt); // idea is this is scoped @@ -138,27 +138,25 @@ fn declare_var(fcx: &fn_ctxt, c: &tsconstr, pre: prestate) -> prestate { ret rslt; } -fn relax_precond_expr(e: &@expr, cx: &relax_ctxt, - vt: &visit::vt<relax_ctxt>) { +fn relax_precond_expr(e: @expr, cx: relax_ctxt, vt: visit::vt<relax_ctxt>) { relax_precond(cx.i as uint, expr_precond(cx.fcx.ccx, e)); visit::visit_expr(e, cx, vt); } -fn relax_precond_stmt(s: &@stmt, cx: &relax_ctxt, - vt: &visit::vt<relax_ctxt>) { +fn relax_precond_stmt(s: @stmt, cx: relax_ctxt, vt: visit::vt<relax_ctxt>) { relax_precond(cx.i as uint, stmt_precond(cx.fcx.ccx, *s)); visit::visit_stmt(s, cx, vt); } type relax_ctxt = {fcx: fn_ctxt, i: node_id}; -fn relax_precond_block_inner(b: &blk, cx: &relax_ctxt, - vt: &visit::vt<relax_ctxt>) { +fn relax_precond_block_inner(b: blk, cx: relax_ctxt, + vt: visit::vt<relax_ctxt>) { relax_precond(cx.i as uint, block_precond(cx.fcx.ccx, b)); visit::visit_block(b, cx, vt); } -fn relax_precond_block(fcx: &fn_ctxt, i: node_id, b: &blk) { +fn relax_precond_block(fcx: fn_ctxt, i: node_id, b: blk) { let cx = {fcx: fcx, i: i}; let visitor = visit::default_visitor::<relax_ctxt>(); visitor = @@ -166,35 +164,35 @@ fn relax_precond_block(fcx: &fn_ctxt, i: node_id, b: &blk) { visit_expr: relax_precond_expr, visit_stmt: relax_precond_stmt, visit_item: - fn (_i: &@item, _cx: &relax_ctxt, _vt: &visit::vt<relax_ctxt>) { - } with *visitor}; + fn (_i: @item, _cx: relax_ctxt, _vt: visit::vt<relax_ctxt>) { } + with *visitor}; let v1 = visit::mk_vt(visitor); v1.visit_block(b, cx, v1); } -fn gen_poststate(fcx: &fn_ctxt, id: node_id, c: &tsconstr) -> bool { +fn gen_poststate(fcx: fn_ctxt, id: node_id, c: tsconstr) -> bool { log "gen_poststate"; ret set_in_poststate(bit_num(fcx, c), node_id_to_ts_ann(fcx.ccx, id).states); } -fn kill_prestate(fcx: &fn_ctxt, id: node_id, c: &tsconstr) -> bool { +fn kill_prestate(fcx: fn_ctxt, id: node_id, c: tsconstr) -> bool { ret clear_in_prestate(bit_num(fcx, c), node_id_to_ts_ann(fcx.ccx, id).states); } -fn kill_all_prestate(fcx: &fn_ctxt, id: node_id) { +fn kill_all_prestate(fcx: fn_ctxt, id: node_id) { tritv::tritv_kill(node_id_to_ts_ann(fcx.ccx, id).states.prestate); } -fn kill_poststate(fcx: &fn_ctxt, id: node_id, c: &tsconstr) -> bool { +fn kill_poststate(fcx: fn_ctxt, id: node_id, c: tsconstr) -> bool { log "kill_poststate"; ret clear_in_poststate(bit_num(fcx, c), node_id_to_ts_ann(fcx.ccx, id).states); } -fn clear_in_poststate_expr(fcx: &fn_ctxt, e: &@expr, t: &poststate) { +fn clear_in_poststate_expr(fcx: fn_ctxt, e: @expr, t: poststate) { alt e.node { expr_path(p) { alt vec::last(p.node.idents) { @@ -217,32 +215,32 @@ fn clear_in_poststate_expr(fcx: &fn_ctxt, e: &@expr, t: &poststate) { } } -fn kill_poststate_(fcx: &fn_ctxt, c: &tsconstr, post: &poststate) -> bool { +fn kill_poststate_(fcx: fn_ctxt, c: tsconstr, post: poststate) -> bool { log "kill_poststate_"; ret clear_in_poststate_(bit_num(fcx, c), post); } -fn set_in_poststate_ident(fcx: &fn_ctxt, id: &node_id, ident: &ident, - t: &poststate) -> bool { +fn set_in_poststate_ident(fcx: fn_ctxt, id: node_id, ident: ident, + t: poststate) -> bool { ret set_in_poststate_(bit_num(fcx, ninit(id, ident)), t); } -fn set_in_prestate_constr(fcx: &fn_ctxt, c: &tsconstr, t: &prestate) -> bool { +fn set_in_prestate_constr(fcx: fn_ctxt, c: tsconstr, t: prestate) -> bool { ret set_in_poststate_(bit_num(fcx, c), t); } -fn clear_in_poststate_ident(fcx: &fn_ctxt, id: &node_id, ident: &ident, - parent: &node_id) -> bool { +fn clear_in_poststate_ident(fcx: fn_ctxt, id: node_id, ident: ident, + parent: node_id) -> bool { ret kill_poststate(fcx, parent, ninit(id, ident)); } -fn clear_in_prestate_ident(fcx: &fn_ctxt, id: &node_id, ident: &ident, - parent: &node_id) -> bool { +fn clear_in_prestate_ident(fcx: fn_ctxt, id: node_id, ident: ident, + parent: node_id) -> bool { ret kill_prestate(fcx, parent, ninit(id, ident)); } -fn clear_in_poststate_ident_(fcx: &fn_ctxt, id: &node_id, ident: &ident, - post: &poststate) -> bool { +fn clear_in_poststate_ident_(fcx: fn_ctxt, id: node_id, ident: ident, + post: poststate) -> bool { ret kill_poststate_(fcx, ninit(id, ident), post); } diff --git a/src/comp/middle/tstate/ck.rs b/src/comp/middle/tstate/ck.rs index 8348fc27409..08af62f369c 100644 --- a/src/comp/middle/tstate/ck.rs +++ b/src/comp/middle/tstate/ck.rs @@ -47,7 +47,7 @@ import collect_locals::mk_f_to_fn_info; import pre_post_conditions::fn_pre_post; import states::find_pre_post_state_fn; -fn check_unused_vars(fcx: &fn_ctxt) { +fn check_unused_vars(fcx: fn_ctxt) { // FIXME: could be more efficient for c: norm_constraint in constraints(fcx) { @@ -63,7 +63,7 @@ fn check_unused_vars(fcx: &fn_ctxt) { } } -fn check_states_expr(e: &@expr, fcx: &fn_ctxt, v: &visit::vt<fn_ctxt>) { +fn check_states_expr(e: @expr, fcx: fn_ctxt, v: visit::vt<fn_ctxt>) { visit::visit_expr(e, fcx, v); let prec: precond = expr_precond(fcx.ccx, e); @@ -94,7 +94,7 @@ fn check_states_expr(e: &@expr, fcx: &fn_ctxt, v: &visit::vt<fn_ctxt>) { } } -fn check_states_stmt(s: &@stmt, fcx: &fn_ctxt, v: &visit::vt<fn_ctxt>) { +fn check_states_stmt(s: @stmt, fcx: fn_ctxt, v: visit::vt<fn_ctxt>) { visit::visit_stmt(s, fcx, v); let a = stmt_to_ann(fcx.ccx, *s); @@ -126,9 +126,8 @@ fn check_states_stmt(s: &@stmt, fcx: &fn_ctxt, v: &visit::vt<fn_ctxt>) { } } -fn check_states_against_conditions(fcx: &fn_ctxt, f: &_fn, - tps: &[ast::ty_param], id: node_id, - sp: &span, i: &fn_ident) { +fn check_states_against_conditions(fcx: fn_ctxt, f: _fn, tps: [ast::ty_param], + id: node_id, sp: span, i: fn_ident) { /* Postorder traversal instead of pre is important because we want the smallest possible erroneous statement or expression. */ @@ -173,8 +172,8 @@ fn check_states_against_conditions(fcx: &fn_ctxt, f: &_fn, check_unused_vars(fcx); } -fn check_fn_states(fcx: &fn_ctxt, f: &_fn, tps: &[ast::ty_param], id: node_id, - sp: &span, i: &fn_ident) { +fn check_fn_states(fcx: fn_ctxt, f: _fn, tps: [ast::ty_param], id: node_id, + sp: span, i: fn_ident) { /* Compute the pre- and post-states for this function */ // Fixpoint iteration @@ -186,8 +185,8 @@ fn check_fn_states(fcx: &fn_ctxt, f: &_fn, tps: &[ast::ty_param], id: node_id, check_states_against_conditions(fcx, f, tps, id, sp, i); } -fn fn_states(f: &_fn, tps: &[ast::ty_param], sp: &span, i: &fn_ident, - id: node_id, ccx: &crate_ctxt, v: &visit::vt<crate_ctxt>) { +fn fn_states(f: _fn, tps: [ast::ty_param], sp: span, i: fn_ident, id: node_id, + ccx: crate_ctxt, v: visit::vt<crate_ctxt>) { visit::visit_fn(f, tps, sp, i, id, ccx, v); /* Look up the var-to-bit-num map for this function */ diff --git a/src/comp/middle/tstate/collect_locals.rs b/src/comp/middle/tstate/collect_locals.rs index bac29c049da..03e889b5a4e 100644 --- a/src/comp/middle/tstate/collect_locals.rs +++ b/src/comp/middle/tstate/collect_locals.rs @@ -15,7 +15,7 @@ import syntax::ast_util::respan; type ctxt = {cs: @mutable [sp_constr], tcx: ty::ctxt}; -fn collect_local(loc: &@local, cx: &ctxt, v: &visit::vt<ctxt>) { +fn collect_local(loc: @local, cx: ctxt, v: visit::vt<ctxt>) { for each p: @pat in pat_bindings(loc.node.pat) { let ident = alt p.node { pat_bind(id) { id } }; log "collect_local: pushing " + ident;; @@ -24,13 +24,14 @@ fn collect_local(loc: &@local, cx: &ctxt, v: &visit::vt<ctxt>) { visit::visit_local(loc, cx, v); } -fn collect_pred(e: &@expr, cx: &ctxt, v: &visit::vt<ctxt>) { +fn collect_pred(e: @expr, cx: ctxt, v: visit::vt<ctxt>) { alt e.node { expr_check(_, ch) { *cx.cs += [expr_to_constr(cx.tcx, ch)]; } expr_if_check(ex, _, _) { *cx.cs += [expr_to_constr(cx.tcx, ex)]; } + // If it's a call, generate appropriate instances of the // call's constraints. expr_call(operator, operands) { @@ -47,8 +48,8 @@ fn collect_pred(e: &@expr, cx: &ctxt, v: &visit::vt<ctxt>) { visit::visit_expr(e, cx, v); } -fn find_locals(tcx: &ty::ctxt, f: &_fn, tps: &[ty_param], sp: &span, - i: &fn_ident, id: node_id) -> ctxt { +fn find_locals(tcx: ty::ctxt, f: _fn, tps: [ty_param], sp: span, i: fn_ident, + id: node_id) -> ctxt { let cx: ctxt = {cs: @mutable [], tcx: tcx}; let visitor = visit::default_visitor::<ctxt>(); @@ -60,8 +61,8 @@ fn find_locals(tcx: &ty::ctxt, f: &_fn, tps: &[ty_param], sp: &span, ret cx; } -fn add_constraint(tcx: &ty::ctxt, c: sp_constr, next: uint, tbl: constr_map) - -> uint { +fn add_constraint(tcx: ty::ctxt, c: sp_constr, next: uint, tbl: constr_map) -> + uint { log constraint_to_str(tcx, c) + " |-> " + std::uint::str(next); alt c.node { ninit(id, i) { tbl.insert(local_def(id), cinit(next, c.span, i)); } @@ -92,8 +93,8 @@ fn add_constraint(tcx: &ty::ctxt, c: sp_constr, next: uint, tbl: constr_map) /* builds a table mapping each local var defined in f to a bit number in the precondition/postcondition vectors */ -fn mk_fn_info(ccx: &crate_ctxt, f: &_fn, tp: &[ty_param], f_sp: &span, - f_name: &fn_ident, id: node_id) { +fn mk_fn_info(ccx: crate_ctxt, f: _fn, tp: [ty_param], f_sp: span, + f_name: fn_ident, id: node_id) { let name = fn_ident_to_string(id, f_name); let res_map = @new_def_hash::<constraint>(); let next: uint = 0u; @@ -155,7 +156,7 @@ fn mk_fn_info(ccx: &crate_ctxt, f: &_fn, tp: &[ty_param], f_sp: &span, /* initializes the global fn_info_map (mapping each function ID, including nested locally defined functions, onto a mapping from local variable name to bit number) */ -fn mk_f_to_fn_info(ccx: &crate_ctxt, c: @crate) { +fn mk_f_to_fn_info(ccx: crate_ctxt, c: @crate) { let visitor = visit::mk_simple_visitor(@{visit_fn: bind mk_fn_info(ccx, _, _, _, _, _) diff --git a/src/comp/middle/tstate/pre_post_conditions.rs b/src/comp/middle/tstate/pre_post_conditions.rs index 72fef222e7d..8f9e08b5533 100644 --- a/src/comp/middle/tstate/pre_post_conditions.rs +++ b/src/comp/middle/tstate/pre_post_conditions.rs @@ -34,18 +34,18 @@ import util::common::log_block; import syntax::codemap::span; import util::ppaux::fn_ident_to_string; -fn find_pre_post_mod(_m: &_mod) -> _mod { +fn find_pre_post_mod(_m: _mod) -> _mod { log "implement find_pre_post_mod!"; fail; } -fn find_pre_post_native_mod(_m: &native_mod) -> native_mod { +fn find_pre_post_native_mod(_m: native_mod) -> native_mod { log "implement find_pre_post_native_mod"; fail; } -fn find_pre_post_obj(ccx: &crate_ctxt, o: _obj) { - fn do_a_method(ccx: crate_ctxt, m: &@method) { +fn find_pre_post_obj(ccx: crate_ctxt, o: _obj) { + fn do_a_method(ccx: crate_ctxt, m: @method) { assert (ccx.fm.contains_key(m.node.id)); let fcx: fn_ctxt = {enclosing: ccx.fm.get(m.node.id), @@ -57,7 +57,7 @@ fn find_pre_post_obj(ccx: &crate_ctxt, o: _obj) { for m: @method in o.methods { do_a_method(ccx, m); } } -fn find_pre_post_item(ccx: &crate_ctxt, i: &item) { +fn find_pre_post_item(ccx: crate_ctxt, i: item) { alt i.node { item_const(_, e) { // make a fake fcx @@ -104,15 +104,15 @@ fn find_pre_post_item(ccx: &crate_ctxt, i: &item) { sets the precondition in a to be the result of combining the preconditions for <args>, and the postcondition in a to be the union of all postconditions for <args> */ -fn find_pre_post_exprs(fcx: &fn_ctxt, args: &[@expr], id: node_id) { +fn find_pre_post_exprs(fcx: fn_ctxt, args: [@expr], id: node_id) { if vec::len::<@expr>(args) > 0u { log "find_pre_post_exprs: oper ="; log_expr(*args[0]); } - fn do_one(fcx: fn_ctxt, e: &@expr) { find_pre_post_expr(fcx, e); } + fn do_one(fcx: fn_ctxt, e: @expr) { find_pre_post_expr(fcx, e); } for e: @expr in args { do_one(fcx, e); } - fn get_pp(ccx: crate_ctxt, e: &@expr) -> pre_and_post { + fn get_pp(ccx: crate_ctxt, e: @expr) -> pre_and_post { ret expr_pp(ccx, e); } let pps = vec::map::<@expr, pre_and_post>(bind get_pp(fcx.ccx, _), args); @@ -121,7 +121,7 @@ fn find_pre_post_exprs(fcx: &fn_ctxt, args: &[@expr], id: node_id) { seq_postconds(fcx, vec::map(get_post, pps))); } -fn find_pre_post_loop(fcx: &fn_ctxt, l: &@local, index: &@expr, body: &blk, +fn find_pre_post_loop(fcx: fn_ctxt, l: @local, index: @expr, body: blk, id: node_id) { find_pre_post_expr(fcx, index); find_pre_post_block(fcx, body); @@ -145,8 +145,8 @@ fn find_pre_post_loop(fcx: &fn_ctxt, l: &@local, index: &@expr, body: &blk, // Generates a pre/post assuming that a is the // annotation for an if-expression with consequent conseq // and alternative maybe_alt -fn join_then_else(fcx: &fn_ctxt, antec: &@expr, conseq: &blk, - maybe_alt: &option::t<@expr>, id: node_id, chck: &if_ty) { +fn join_then_else(fcx: fn_ctxt, antec: @expr, conseq: blk, + maybe_alt: option::t<@expr>, id: node_id, chck: if_ty) { find_pre_post_expr(fcx, antec); find_pre_post_block(fcx, conseq); alt maybe_alt { @@ -208,8 +208,8 @@ fn join_then_else(fcx: &fn_ctxt, antec: &@expr, conseq: &blk, } } -fn gen_if_local(fcx: &fn_ctxt, lhs: @expr, rhs: @expr, larger_id: node_id, - new_var: node_id, pth: &path) { +fn gen_if_local(fcx: fn_ctxt, lhs: @expr, rhs: @expr, larger_id: node_id, + new_var: node_id, pth: path) { alt node_id_to_def(fcx.ccx, new_var) { some(d) { alt d { @@ -228,7 +228,7 @@ fn gen_if_local(fcx: &fn_ctxt, lhs: @expr, rhs: @expr, larger_id: node_id, } } -fn handle_update(fcx: &fn_ctxt, parent: &@expr, lhs: &@expr, rhs: &@expr, +fn handle_update(fcx: fn_ctxt, parent: @expr, lhs: @expr, rhs: @expr, ty: oper_type) { find_pre_post_expr(fcx, rhs); alt lhs.node { @@ -291,12 +291,11 @@ fn handle_update(fcx: &fn_ctxt, parent: &@expr, lhs: &@expr, rhs: &@expr, } } -fn handle_var(fcx: &fn_ctxt, rslt: &pre_and_post, id: node_id, name: ident) { +fn handle_var(fcx: fn_ctxt, rslt: pre_and_post, id: node_id, name: ident) { handle_var_def(fcx, rslt, node_id_to_def_strict(fcx.ccx.tcx, id), name); } -fn handle_var_def(fcx: &fn_ctxt, rslt: &pre_and_post, def: &def, - name: ident) { +fn handle_var_def(fcx: fn_ctxt, rslt: pre_and_post, def: def, name: ident) { alt def { def_local(d_id) | def_arg(d_id, _) { use_var(fcx, d_id.node); @@ -307,8 +306,8 @@ fn handle_var_def(fcx: &fn_ctxt, rslt: &pre_and_post, def: &def, } } -fn forget_args_moved_in(fcx: &fn_ctxt, parent: &@expr, modes: &[ty::mode], - operands: &[@expr]) { +fn forget_args_moved_in(fcx: fn_ctxt, parent: @expr, modes: [ty::mode], + operands: [@expr]) { let i = 0u; for mode: ty::mode in modes { if mode == by_move { @@ -319,10 +318,10 @@ fn forget_args_moved_in(fcx: &fn_ctxt, parent: &@expr, modes: &[ty::mode], } /* Fills in annotations as a side effect. Does not rebuild the expr */ -fn find_pre_post_expr(fcx: &fn_ctxt, e: @expr) { +fn find_pre_post_expr(fcx: fn_ctxt, e: @expr) { let enclosing = fcx.enclosing; let num_local_vars = num_constraints(enclosing); - fn do_rand_(fcx: fn_ctxt, e: &@expr) { find_pre_post_expr(fcx, e); } + fn do_rand_(fcx: fn_ctxt, e: @expr) { find_pre_post_expr(fcx, e); } alt e.node { @@ -487,14 +486,14 @@ fn find_pre_post_expr(fcx: &fn_ctxt, e: @expr) { expr_index(val, sub) { find_pre_post_exprs(fcx, [val, sub], e.id); } expr_alt(ex, alts) { find_pre_post_expr(fcx, ex); - fn do_an_alt(fcx: &fn_ctxt, an_alt: &arm) -> pre_and_post { + fn do_an_alt(fcx: fn_ctxt, an_alt: arm) -> pre_and_post { find_pre_post_block(fcx, an_alt.body); ret block_pp(fcx.ccx, an_alt.body); } let alt_pps = []; for a: arm in alts { alt_pps += [do_an_alt(fcx, a)]; } - fn combine_pp(antec: pre_and_post, fcx: fn_ctxt, pp: &pre_and_post, - next: &pre_and_post) -> pre_and_post { + fn combine_pp(antec: pre_and_post, fcx: fn_ctxt, pp: pre_and_post, + next: pre_and_post) -> pre_and_post { union(pp.precondition, seq_preconds(fcx, [antec, next])); intersect(pp.postcondition, next.postcondition); ret pp; @@ -546,6 +545,7 @@ fn find_pre_post_expr(fcx: &fn_ctxt, e: @expr) { + expr_bind(operator, maybe_args) { let args = []; let cmodes = callee_modes(fcx, operator.id); @@ -578,7 +578,7 @@ fn find_pre_post_expr(fcx: &fn_ctxt, e: @expr) { } } -fn find_pre_post_stmt(fcx: &fn_ctxt, s: &stmt) { +fn find_pre_post_stmt(fcx: fn_ctxt, s: stmt) { log "stmt ="; log_stmt(s); alt s.node { @@ -681,7 +681,7 @@ fn find_pre_post_stmt(fcx: &fn_ctxt, s: &stmt) { } } -fn find_pre_post_block(fcx: &fn_ctxt, b: blk) { +fn find_pre_post_block(fcx: fn_ctxt, b: blk) { /* Want to say that if there is a break or cont in this block, then that invalidates the poststate upheld by any of the stmts after it. @@ -700,7 +700,7 @@ fn find_pre_post_block(fcx: &fn_ctxt, b: blk) { */ let nv = num_constraints(fcx.enclosing); - fn do_one_(fcx: fn_ctxt, s: &@stmt) { + fn do_one_(fcx: fn_ctxt, s: @stmt) { find_pre_post_stmt(fcx, *s); /* log_err "pre_post for stmt:"; @@ -710,7 +710,7 @@ fn find_pre_post_block(fcx: &fn_ctxt, b: blk) { */ } for s: @stmt in b.node.stmts { do_one_(fcx, s); } - fn do_inner_(fcx: fn_ctxt, e: &@expr) { find_pre_post_expr(fcx, e); } + fn do_inner_(fcx: fn_ctxt, e: @expr) { find_pre_post_expr(fcx, e); } let do_inner = bind do_inner_(fcx, _); option::map::<@expr, ()>(do_inner, b.node.expr); @@ -739,7 +739,7 @@ fn find_pre_post_block(fcx: &fn_ctxt, b: blk) { set_pre_and_post(fcx.ccx, b.node.id, block_precond, block_postcond); } -fn find_pre_post_fn(fcx: &fn_ctxt, f: &_fn) { +fn find_pre_post_fn(fcx: fn_ctxt, f: _fn) { // hack use_var(fcx, tsconstr_to_node_id(fcx.enclosing.i_return)); use_var(fcx, tsconstr_to_node_id(fcx.enclosing.i_diverge)); @@ -754,8 +754,8 @@ fn find_pre_post_fn(fcx: &fn_ctxt, f: &_fn) { } } -fn fn_pre_post(f: &_fn, tps: &[ty_param], sp: &span, i: &fn_ident, - id: node_id, ccx: &crate_ctxt, v: &visit::vt<crate_ctxt>) { +fn fn_pre_post(f: _fn, tps: [ty_param], sp: span, i: fn_ident, id: node_id, + ccx: crate_ctxt, v: visit::vt<crate_ctxt>) { visit::visit_fn(f, tps, sp, i, id, ccx, v); assert (ccx.fm.contains_key(id)); let fcx = diff --git a/src/comp/middle/tstate/states.rs b/src/comp/middle/tstate/states.rs index 6537487b1bb..b86edea26fa 100644 --- a/src/comp/middle/tstate/states.rs +++ b/src/comp/middle/tstate/states.rs @@ -32,24 +32,24 @@ import util::common::log_stmt; import util::common::log_stmt_err; import util::common::log_expr_err; -fn forbid_upvar(fcx: &fn_ctxt, rhs_id: &node_id, sp: &span, - t: oper_type) { +fn forbid_upvar(fcx: fn_ctxt, rhs_id: node_id, sp: span, t: oper_type) { alt t { oper_move. { alt local_node_id_to_def(fcx, rhs_id) { - some(def_upvar(_,_,_)) { - fcx.ccx.tcx.sess.span_err(sp, "Tried to deinitialize a variable \ + some(def_upvar(_, _, _)) { + fcx.ccx.tcx.sess.span_err(sp, + "Tried to deinitialize a variable \ declared in a different scope"); - } - _ {} + } + _ { } } } - _ { /* do nothing */ } + _ {/* do nothing */ } } } -fn handle_move_or_copy(fcx: &fn_ctxt, post: &poststate, rhs_path: &path, - rhs_id: &node_id, instlhs: &inst, init_op: &init_op) { +fn handle_move_or_copy(fcx: fn_ctxt, post: poststate, rhs_path: path, + rhs_id: node_id, instlhs: inst, init_op: init_op) { forbid_upvar(fcx, rhs_id, rhs_path.span, op_to_oper_ty(init_op)); let rhs_d_id = local_node_id_to_def_id(fcx, rhs_id); @@ -67,7 +67,7 @@ fn handle_move_or_copy(fcx: &fn_ctxt, post: &poststate, rhs_path: &path, } } -fn seq_states(fcx: &fn_ctxt, pres: &prestate, bindings: &[binding]) -> +fn seq_states(fcx: fn_ctxt, pres: prestate, bindings: [binding]) -> {changed: bool, post: poststate} { let changed = false; let post = tritv_clone(pres); @@ -105,7 +105,7 @@ fn seq_states(fcx: &fn_ctxt, pres: &prestate, bindings: &[binding]) -> ret {changed: changed, post: post}; } -fn find_pre_post_state_sub(fcx: &fn_ctxt, pres: &prestate, e: &@expr, +fn find_pre_post_state_sub(fcx: fn_ctxt, pres: prestate, e: @expr, parent: node_id, c: option::t<tsconstr>) -> bool { let changed = find_pre_post_state_expr(fcx, pres, e); @@ -121,8 +121,8 @@ fn find_pre_post_state_sub(fcx: &fn_ctxt, pres: &prestate, e: &@expr, ret changed; } -fn find_pre_post_state_two(fcx: &fn_ctxt, pres: &prestate, lhs: &@expr, - rhs: &@expr, parent: node_id, ty: oper_type) -> +fn find_pre_post_state_two(fcx: fn_ctxt, pres: prestate, lhs: @expr, + rhs: @expr, parent: node_id, ty: oper_type) -> bool { let changed = set_prestate_ann(fcx.ccx, parent, pres); changed = find_pre_post_state_expr(fcx, pres, lhs) || changed; @@ -184,8 +184,8 @@ fn find_pre_post_state_two(fcx: &fn_ctxt, pres: &prestate, lhs: &@expr, ret changed; } -fn find_pre_post_state_call(fcx: &fn_ctxt, pres: &prestate, a: &@expr, - id: node_id, ops: &[init_op], bs: &[@expr], +fn find_pre_post_state_call(fcx: fn_ctxt, pres: prestate, a: @expr, + id: node_id, ops: [init_op], bs: [@expr], cf: controlflow) -> bool { let changed = find_pre_post_state_expr(fcx, pres, a); // FIXME: This could be a typestate constraint @@ -199,9 +199,9 @@ fn find_pre_post_state_call(fcx: &fn_ctxt, pres: &prestate, a: &@expr, bs, cf) || changed; } -fn find_pre_post_state_exprs(fcx: &fn_ctxt, pres: &prestate, id: node_id, - ops: &[init_op], es: &[@expr], cf: controlflow) - -> bool { +fn find_pre_post_state_exprs(fcx: fn_ctxt, pres: prestate, id: node_id, + ops: [init_op], es: [@expr], cf: controlflow) -> + bool { let rs = seq_states(fcx, pres, anon_bindings(ops, es)); let changed = rs.changed | set_prestate_ann(fcx.ccx, id, pres); /* if this is a failing call, it sets everything as initialized */ @@ -215,8 +215,8 @@ fn find_pre_post_state_exprs(fcx: &fn_ctxt, pres: &prestate, id: node_id, ret changed; } -fn find_pre_post_state_loop(fcx: &fn_ctxt, pres: prestate, l: &@local, - index: &@expr, body: &blk, id: node_id) -> bool { +fn find_pre_post_state_loop(fcx: fn_ctxt, pres: prestate, l: @local, + index: @expr, body: blk, id: node_id) -> bool { let loop_pres = intersect_states(pres, block_poststate(fcx.ccx, body)); let changed = @@ -245,7 +245,7 @@ fn find_pre_post_state_loop(fcx: &fn_ctxt, pres: prestate, l: &@local, } } -fn gen_if_local(fcx: &fn_ctxt, p: &poststate, e: &@expr) -> bool { +fn gen_if_local(fcx: fn_ctxt, p: poststate, e: @expr) -> bool { alt e.node { expr_path(pth) { alt fcx.ccx.tcx.def_map.find(e.id) { @@ -260,9 +260,9 @@ fn gen_if_local(fcx: &fn_ctxt, p: &poststate, e: &@expr) -> bool { } } -fn join_then_else(fcx: &fn_ctxt, antec: &@expr, conseq: &blk, - maybe_alt: &option::t<@expr>, id: node_id, chk: &if_ty, - pres: &prestate) -> bool { +fn join_then_else(fcx: fn_ctxt, antec: @expr, conseq: blk, + maybe_alt: option::t<@expr>, id: node_id, chk: if_ty, + pres: prestate) -> bool { let changed = set_prestate_ann(fcx.ccx, id, pres) | find_pre_post_state_expr(fcx, pres, antec); @@ -291,18 +291,18 @@ fn join_then_else(fcx: &fn_ctxt, antec: &@expr, conseq: &blk, tritv_set(bit_num(fcx, c.node), conseq_prestate, ttrue); changed |= find_pre_post_state_block(fcx, conseq_prestate, conseq) | - set_poststate_ann(fcx.ccx, id, - expr_poststate(fcx.ccx, antec)); + set_poststate_ann(fcx.ccx, id, + expr_poststate(fcx.ccx, antec)); } _ { changed |= find_pre_post_state_block(fcx, expr_poststate(fcx.ccx, antec), conseq) | - set_poststate_ann(fcx.ccx, id, - expr_poststate(fcx.ccx, antec)); + set_poststate_ann(fcx.ccx, id, + expr_poststate(fcx.ccx, antec)); } } - } + } some(altern) { changed |= find_pre_post_state_expr(fcx, expr_poststate(fcx.ccx, antec), @@ -341,8 +341,7 @@ fn join_then_else(fcx: &fn_ctxt, antec: &@expr, conseq: &blk, ret changed; } -fn find_pre_post_state_expr(fcx: &fn_ctxt, pres: &prestate, e: @expr) -> - bool { +fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool { let num_constrs = num_constraints(fcx.enclosing); @@ -630,8 +629,7 @@ fn find_pre_post_state_expr(fcx: &fn_ctxt, pres: &prestate, e: @expr) -> } } -fn find_pre_post_state_stmt(fcx: &fn_ctxt, pres: &prestate, s: @stmt) -> - bool { +fn find_pre_post_state_stmt(fcx: fn_ctxt, pres: prestate, s: @stmt) -> bool { let stmt_ann = stmt_to_ann(fcx.ccx, *s); /* @@ -705,8 +703,7 @@ fn find_pre_post_state_stmt(fcx: &fn_ctxt, pres: &prestate, s: @stmt) -> /* Updates the pre- and post-states of statements in the block, returns a boolean flag saying whether any pre- or poststates changed */ -fn find_pre_post_state_block(fcx: &fn_ctxt, pres0: &prestate, b: &blk) -> - bool { +fn find_pre_post_state_block(fcx: fn_ctxt, pres0: prestate, b: blk) -> bool { /* First, set the pre-states and post-states for every expression */ let pres = pres0; @@ -748,7 +745,7 @@ fn find_pre_post_state_block(fcx: &fn_ctxt, pres0: &prestate, b: &blk) -> ret changed; } -fn find_pre_post_state_fn(fcx: &fn_ctxt, f: &_fn) -> bool { +fn find_pre_post_state_fn(fcx: fn_ctxt, f: _fn) -> bool { let num_constrs = num_constraints(fcx.enclosing); // All constraints are considered false until proven otherwise. // This ensures that intersect works correctly. diff --git a/src/comp/middle/tstate/tritv.rs b/src/comp/middle/tstate/tritv.rs index 60a724de524..bc8a6aa1ff2 100644 --- a/src/comp/middle/tstate/tritv.rs +++ b/src/comp/middle/tstate/tritv.rs @@ -56,6 +56,7 @@ fn trit_minus(a: trit, b: trit) -> trit { tfalse. { ttrue } + /* internally contradictory, but I guess it'll get flagged? */ dont_care. { @@ -68,6 +69,7 @@ fn trit_minus(a: trit, b: trit) -> trit { ttrue. { tfalse } + /* see above comment */ _ { tfalse @@ -86,6 +88,7 @@ fn trit_or(a: trit, b: trit) -> trit { ttrue. { dont_care } + /* FIXME: ?????? */ _ { tfalse @@ -105,12 +108,14 @@ fn trit_and(a: trit, b: trit) -> trit { dont_care. { b } + // also seems wrong for case b = ttrue ttrue. { alt b { dont_care. { ttrue } + // ??? Seems wrong ttrue. { ttrue @@ -118,6 +123,7 @@ fn trit_and(a: trit, b: trit) -> trit { + // false wins, since if something is uninit // on one path, we care // (Rationale: it's always safe to assume that @@ -131,6 +137,7 @@ fn trit_and(a: trit, b: trit) -> trit { + // Rationale: if it's uninit on one path, // we can consider it as uninit on all paths tfalse. { @@ -145,7 +152,7 @@ fn change(changed: bool, old: trit, new: trit) -> bool { changed || new != old } -fn tritv_difference(p1: &t, p2: &t) -> bool { +fn tritv_difference(p1: t, p2: t) -> bool { let i: uint = 0u; assert (p1.nbits == p2.nbits); let sz: uint = p1.nbits; @@ -160,7 +167,7 @@ fn tritv_difference(p1: &t, p2: &t) -> bool { ret changed; } -fn tritv_union(p1: &t, p2: &t) -> bool { +fn tritv_union(p1: t, p2: t) -> bool { let i: uint = 0u; assert (p1.nbits == p2.nbits); let sz: uint = p1.nbits; @@ -175,7 +182,7 @@ fn tritv_union(p1: &t, p2: &t) -> bool { ret changed; } -fn tritv_intersect(p1: &t, p2: &t) -> bool { +fn tritv_intersect(p1: t, p2: t) -> bool { let i: uint = 0u; assert (p1.nbits == p2.nbits); let sz: uint = p1.nbits; @@ -190,14 +197,14 @@ fn tritv_intersect(p1: &t, p2: &t) -> bool { ret changed; } -fn tritv_get(v: &t, i: uint) -> trit { +fn tritv_get(v: t, i: uint) -> trit { let b1 = bitv::get(v.uncertain, i); let b2 = bitv::get(v.val, i); assert (!(b1 && b2)); if b1 { dont_care } else if b2 { ttrue } else { tfalse } } -fn tritv_set(i: uint, v: &t, t: trit) -> bool { +fn tritv_set(i: uint, v: t, t: trit) -> bool { let old = tritv_get(v, i); alt t { dont_care. { @@ -213,7 +220,7 @@ fn tritv_set(i: uint, v: &t, t: trit) -> bool { ret change(false, old, t); } -fn tritv_copy(target: &t, source: &t) -> bool { +fn tritv_copy(target: t, source: t) -> bool { assert (target.nbits == source.nbits); let changed = !bitv::equal(target.uncertain, source.uncertain) || @@ -223,28 +230,28 @@ fn tritv_copy(target: &t, source: &t) -> bool { ret changed; } -fn tritv_set_all(v: &t) { +fn tritv_set_all(v: t) { let i: uint = 0u; while i < v.nbits { tritv_set(i, v, ttrue); i += 1u; } } -fn tritv_clear(v: &t) { +fn tritv_clear(v: t) { let i: uint = 0u; while i < v.nbits { tritv_set(i, v, dont_care); i += 1u; } } -fn tritv_kill(v: &t) { +fn tritv_kill(v: t) { let i: uint = 0u; while i < v.nbits { tritv_set(i, v, tfalse); i += 1u; } } -fn tritv_clone(v: &t) -> t { +fn tritv_clone(v: t) -> t { ret {uncertain: bitv::clone(v.uncertain), val: bitv::clone(v.val), nbits: v.nbits}; } -fn tritv_doesntcare(v: &t) -> bool { +fn tritv_doesntcare(v: t) -> bool { let i: uint = 0u; while i < v.nbits { if tritv_get(v, i) != dont_care { ret false; } @@ -253,7 +260,7 @@ fn tritv_doesntcare(v: &t) -> bool { ret true; } -fn to_vec(v: &t) -> [uint] { +fn to_vec(v: t) -> [uint] { let i: uint = 0u; let rslt: [uint] = []; while i < v.nbits { @@ -268,7 +275,7 @@ fn to_vec(v: &t) -> [uint] { ret rslt; } -fn to_str(v: &t) -> str { +fn to_str(v: t) -> str { let i: uint = 0u; let rs: str = ""; while i < v.nbits { diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index eb829a0760d..7e3d5572910 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -220,7 +220,7 @@ type ty_ctxt = ctxt; // Needed for disambiguation from unify::ctxt. // Convert from method type to function type. Pretty easy; we just drop // 'ident'. -fn method_ty_to_fn_ty(cx: &ctxt, m: method) -> t { +fn method_ty_to_fn_ty(cx: ctxt, m: method) -> t { ret mk_fn(cx, m.proto, m.inputs, m.output, m.cf, m.constrs); } @@ -344,7 +344,7 @@ type ty_param_substs_opt_and_ty = {substs: option::t<[ty::t]>, ty: ty::t}; type node_type_table = @smallintmap::smallintmap<ty::ty_param_substs_opt_and_ty>; -fn populate_type_store(cx: &ctxt) { +fn populate_type_store(cx: ctxt) { intern(cx, ty_nil, none); intern(cx, ty_bool, none); intern(cx, ty_int, none); @@ -369,10 +369,10 @@ fn populate_type_store(cx: &ctxt) { fn mk_rcache() -> creader_cache { type val = {cnum: int, pos: uint, len: uint}; - fn hash_cache_entry(k: &val) -> uint { + fn hash_cache_entry(k: val) -> uint { ret (k.cnum as uint) + k.pos + k.len; } - fn eq_cache_entries(a: &val, b: &val) -> bool { + fn eq_cache_entries(a: val, b: val) -> bool { ret a.cnum == b.cnum && a.pos == b.pos && a.len == b.len; } ret map::mk_hashmap(hash_cache_entry, eq_cache_entries); @@ -407,27 +407,27 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, // Type constructors -fn mk_raw_ty(cx: &ctxt, st: &sty, _in_cname: &option::t<str>) -> @raw_t { +fn mk_raw_ty(cx: ctxt, st: sty, _in_cname: option::t<str>) -> @raw_t { let cname: option::t<str> = none; let h = hash_type_info(st, cname); let has_params: bool = false; let has_vars: bool = false; - fn derive_flags_t(cx: &ctxt, has_params: &mutable bool, + fn derive_flags_t(cx: ctxt, has_params: &mutable bool, has_vars: &mutable bool, tt: t) { let rt = interner::get::<@raw_t>(*cx.ts, tt); has_params = has_params || rt.has_params; has_vars = has_vars || rt.has_vars; } - fn derive_flags_mt(cx: &ctxt, has_params: &mutable bool, - has_vars: &mutable bool, m: &mt) { + fn derive_flags_mt(cx: ctxt, has_params: &mutable bool, + has_vars: &mutable bool, m: mt) { derive_flags_t(cx, has_params, has_vars, m.ty); } - fn derive_flags_arg(cx: &ctxt, has_params: &mutable bool, - has_vars: &mutable bool, a: &arg) { + fn derive_flags_arg(cx: ctxt, has_params: &mutable bool, + has_vars: &mutable bool, a: arg) { derive_flags_t(cx, has_params, has_vars, a.ty); } - fn derive_flags_sig(cx: &ctxt, has_params: &mutable bool, - has_vars: &mutable bool, args: &[arg], tt: t) { + fn derive_flags_sig(cx: ctxt, has_params: &mutable bool, + has_vars: &mutable bool, args: [arg], tt: t) { for a: arg in args { derive_flags_arg(cx, has_params, has_vars, a); } derive_flags_t(cx, has_params, has_vars, tt); } @@ -484,11 +484,11 @@ fn mk_raw_ty(cx: &ctxt, st: &sty, _in_cname: &option::t<str>) -> @raw_t { has_vars: has_vars}; } -fn intern(cx: &ctxt, st: &sty, cname: &option::t<str>) { +fn intern(cx: ctxt, st: sty, cname: option::t<str>) { interner::intern(*cx.ts, mk_raw_ty(cx, st, cname)); } -fn gen_ty_full(cx: &ctxt, st: &sty, cname: &option::t<str>) -> t { +fn gen_ty_full(cx: ctxt, st: sty, cname: option::t<str>) -> t { let raw_type = mk_raw_ty(cx, st, cname); ret interner::intern(*cx.ts, raw_type); } @@ -496,21 +496,21 @@ fn gen_ty_full(cx: &ctxt, st: &sty, cname: &option::t<str>) -> t { // These are private constructors to this module. External users should always // use the mk_foo() functions below. -fn gen_ty(cx: &ctxt, st: &sty) -> t { ret gen_ty_full(cx, st, none); } +fn gen_ty(cx: ctxt, st: sty) -> t { ret gen_ty_full(cx, st, none); } -fn mk_nil(_cx: &ctxt) -> t { ret idx_nil; } +fn mk_nil(_cx: ctxt) -> t { ret idx_nil; } -fn mk_bot(_cx: &ctxt) -> t { ret idx_bot; } +fn mk_bot(_cx: ctxt) -> t { ret idx_bot; } -fn mk_bool(_cx: &ctxt) -> t { ret idx_bool; } +fn mk_bool(_cx: ctxt) -> t { ret idx_bool; } -fn mk_int(_cx: &ctxt) -> t { ret idx_int; } +fn mk_int(_cx: ctxt) -> t { ret idx_int; } -fn mk_float(_cx: &ctxt) -> t { ret idx_float; } +fn mk_float(_cx: ctxt) -> t { ret idx_float; } -fn mk_uint(_cx: &ctxt) -> t { ret idx_uint; } +fn mk_uint(_cx: ctxt) -> t { ret idx_uint; } -fn mk_mach(_cx: &ctxt, tm: &ast::ty_mach) -> t { +fn mk_mach(_cx: ctxt, tm: ast::ty_mach) -> t { alt tm { ast::ty_u8. { ret idx_u8; } ast::ty_u16. { ret idx_u16; } @@ -525,74 +525,74 @@ fn mk_mach(_cx: &ctxt, tm: &ast::ty_mach) -> t { } } -fn mk_char(_cx: &ctxt) -> t { ret idx_char; } +fn mk_char(_cx: ctxt) -> t { ret idx_char; } -fn mk_str(_cx: &ctxt) -> t { ret idx_str; } +fn mk_str(_cx: ctxt) -> t { ret idx_str; } -fn mk_tag(cx: &ctxt, did: &ast::def_id, tys: &[t]) -> t { +fn mk_tag(cx: ctxt, did: ast::def_id, tys: [t]) -> t { ret gen_ty(cx, ty_tag(did, tys)); } -fn mk_box(cx: &ctxt, tm: &mt) -> t { ret gen_ty(cx, ty_box(tm)); } +fn mk_box(cx: ctxt, tm: mt) -> t { ret gen_ty(cx, ty_box(tm)); } -fn mk_uniq(cx: &ctxt, typ: t) -> t { ret gen_ty(cx, ty_uniq(typ)); } +fn mk_uniq(cx: ctxt, typ: t) -> t { ret gen_ty(cx, ty_uniq(typ)); } -fn mk_ptr(cx: &ctxt, tm: &mt) -> t { ret gen_ty(cx, ty_ptr(tm)); } +fn mk_ptr(cx: ctxt, tm: mt) -> t { ret gen_ty(cx, ty_ptr(tm)); } -fn mk_imm_box(cx: &ctxt, ty: t) -> t { +fn mk_imm_box(cx: ctxt, ty: t) -> t { ret mk_box(cx, {ty: ty, mut: ast::imm}); } -fn mk_mut_ptr(cx: &ctxt, ty: t) -> t { +fn mk_mut_ptr(cx: ctxt, ty: t) -> t { ret mk_ptr(cx, {ty: ty, mut: ast::mut}); } -fn mk_vec(cx: &ctxt, tm: &mt) -> t { ret gen_ty(cx, ty_vec(tm)); } +fn mk_vec(cx: ctxt, tm: mt) -> t { ret gen_ty(cx, ty_vec(tm)); } -fn mk_rec(cx: &ctxt, fs: &[field]) -> t { ret gen_ty(cx, ty_rec(fs)); } +fn mk_rec(cx: ctxt, fs: [field]) -> t { ret gen_ty(cx, ty_rec(fs)); } -fn mk_constr(cx: &ctxt, t: t, cs: &[@type_constr]) -> t { +fn mk_constr(cx: ctxt, t: t, cs: [@type_constr]) -> t { ret gen_ty(cx, ty_constr(t, cs)); } -fn mk_tup(cx: &ctxt, ts: &[t]) -> t { ret gen_ty(cx, ty_tup(ts)); } +fn mk_tup(cx: ctxt, ts: [t]) -> t { ret gen_ty(cx, ty_tup(ts)); } -fn mk_fn(cx: &ctxt, proto: &ast::proto, args: &[arg], ty: t, cf: &controlflow, - constrs: &[@constr]) -> t { +fn mk_fn(cx: ctxt, proto: ast::proto, args: [arg], ty: t, cf: controlflow, + constrs: [@constr]) -> t { ret gen_ty(cx, ty_fn(proto, args, ty, cf, constrs)); } -fn mk_native_fn(cx: &ctxt, abi: &ast::native_abi, args: &[arg], ty: t) -> t { +fn mk_native_fn(cx: ctxt, abi: ast::native_abi, args: [arg], ty: t) -> t { ret gen_ty(cx, ty_native_fn(abi, args, ty)); } -fn mk_obj(cx: &ctxt, meths: &[method]) -> t { ret gen_ty(cx, ty_obj(meths)); } +fn mk_obj(cx: ctxt, meths: [method]) -> t { ret gen_ty(cx, ty_obj(meths)); } -fn mk_res(cx: &ctxt, did: &ast::def_id, inner: t, tps: &[t]) -> t { +fn mk_res(cx: ctxt, did: ast::def_id, inner: t, tps: [t]) -> t { ret gen_ty(cx, ty_res(did, inner, tps)); } -fn mk_var(cx: &ctxt, v: int) -> t { ret gen_ty(cx, ty_var(v)); } +fn mk_var(cx: ctxt, v: int) -> t { ret gen_ty(cx, ty_var(v)); } -fn mk_param(cx: &ctxt, n: uint, k: ast::kind) -> t { +fn mk_param(cx: ctxt, n: uint, k: ast::kind) -> t { ret gen_ty(cx, ty_param(n, k)); } -fn mk_type(_cx: &ctxt) -> t { ret idx_type; } +fn mk_type(_cx: ctxt) -> t { ret idx_type; } -fn mk_native(cx: &ctxt, did: &def_id) -> t { ret gen_ty(cx, ty_native(did)); } +fn mk_native(cx: ctxt, did: def_id) -> t { ret gen_ty(cx, ty_native(did)); } -fn mk_iter_body_fn(cx: &ctxt, output: t) -> t { +fn mk_iter_body_fn(cx: ctxt, output: t) -> t { ret mk_fn(cx, ast::proto_block, [{mode: ast::by_ref, ty: output}], ty::mk_nil(cx), ast::return, []); } // Returns the one-level-deep type structure of the given type. -fn struct(cx: &ctxt, typ: t) -> sty { ret interner::get(*cx.ts, typ).struct; } +fn struct(cx: ctxt, typ: t) -> sty { ret interner::get(*cx.ts, typ).struct; } // Returns the canonical name of the given type. -fn cname(cx: &ctxt, typ: t) -> option::t<str> { +fn cname(cx: ctxt, typ: t) -> option::t<str> { ret interner::get(*cx.ts, typ).cname; } @@ -600,7 +600,7 @@ fn cname(cx: &ctxt, typ: t) -> option::t<str> { // Type folds type ty_walk = fn(t); -fn walk_ty(cx: &ctxt, walker: ty_walk, ty: t) { +fn walk_ty(cx: ctxt, walker: ty_walk, ty: t) { alt struct(cx, ty) { ty_nil. {/* no-op */ } ty_bot. {/* no-op */ } @@ -655,7 +655,7 @@ tag fold_mode { fm_general(fn(t) -> t); } -fn fold_ty(cx: &ctxt, fld: fold_mode, ty_0: t) -> t { +fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t { let ty = ty_0; // Fast paths. @@ -767,33 +767,33 @@ fn fold_ty(cx: &ctxt, fld: fold_mode, ty_0: t) -> t { // Type utilities -fn rename(cx: &ctxt, typ: t, new_cname: &str) -> t { +fn rename(cx: ctxt, typ: t, new_cname: str) -> t { ret gen_ty_full(cx, struct(cx, typ), some(new_cname)); } -fn strip_cname(cx: &ctxt, typ: t) -> t { +fn strip_cname(cx: ctxt, typ: t) -> t { ret gen_ty_full(cx, struct(cx, typ), none); } // Returns a type with the structural part taken from `struct_ty` and the // canonical name from `cname_ty`. -fn copy_cname(cx: &ctxt, struct_ty: t, cname_ty: t) -> t { +fn copy_cname(cx: ctxt, struct_ty: t, cname_ty: t) -> t { ret gen_ty_full(cx, struct(cx, struct_ty), cname(cx, cname_ty)); } -fn type_is_nil(cx: &ctxt, ty: t) -> bool { +fn type_is_nil(cx: ctxt, ty: t) -> bool { alt struct(cx, ty) { ty_nil. { ret true; } _ { ret false; } } } -fn type_is_bot(cx: &ctxt, ty: t) -> bool { +fn type_is_bot(cx: ctxt, ty: t) -> bool { alt struct(cx, ty) { ty_bot. { ret true; } _ { ret false; } } } -fn type_is_bool(cx: &ctxt, ty: t) -> bool { +fn type_is_bool(cx: ctxt, ty: t) -> bool { alt struct(cx, ty) { ty_bool. { ret true; } _ { ret false; } } } -fn type_is_structural(cx: &ctxt, ty: t) -> bool { +fn type_is_structural(cx: ctxt, ty: t) -> bool { alt struct(cx, ty) { ty_rec(_) { ret true; } ty_tup(_) { ret true; } @@ -806,7 +806,7 @@ fn type_is_structural(cx: &ctxt, ty: t) -> bool { } } -fn type_is_copyable(cx: &ctxt, ty: t) -> bool { +fn type_is_copyable(cx: ctxt, ty: t) -> bool { ret alt struct(cx, ty) { ty_res(_, _, _) { false } ty_fn(proto_block., _, _, _, _) { false } @@ -814,7 +814,7 @@ fn type_is_copyable(cx: &ctxt, ty: t) -> bool { }; } -fn type_is_sequence(cx: &ctxt, ty: t) -> bool { +fn type_is_sequence(cx: ctxt, ty: t) -> bool { alt struct(cx, ty) { ty_str. { ret true; } ty_vec(_) { ret true; } @@ -822,11 +822,11 @@ fn type_is_sequence(cx: &ctxt, ty: t) -> bool { } } -fn type_is_str(cx: &ctxt, ty: t) -> bool { +fn type_is_str(cx: ctxt, ty: t) -> bool { alt struct(cx, ty) { ty_str. { ret true; } _ { ret false; } } } -fn sequence_element_type(cx: &ctxt, ty: t) -> t { +fn sequence_element_type(cx: ctxt, ty: t) -> t { alt struct(cx, ty) { ty_str. { ret mk_mach(cx, ast::ty_u8); } ty_vec(mt) { ret mt.ty; } @@ -834,7 +834,7 @@ fn sequence_element_type(cx: &ctxt, ty: t) -> t { } } -fn type_is_tup_like(cx: &ctxt, ty: t) -> bool { +fn type_is_tup_like(cx: ctxt, ty: t) -> bool { alt struct(cx, ty) { ty_box(_) { ret true; } ty_rec(_) { ret true; } @@ -844,7 +844,7 @@ fn type_is_tup_like(cx: &ctxt, ty: t) -> bool { } } -fn get_element_type(cx: &ctxt, ty: t, i: uint) -> t { +fn get_element_type(cx: ctxt, ty: t, i: uint) -> t { alt struct(cx, ty) { ty_rec(flds) { ret flds[i].mt.ty; } ty_tup(ts) { ret ts[i]; } @@ -858,15 +858,15 @@ fn get_element_type(cx: &ctxt, ty: t, i: uint) -> t { // tag. } -fn type_is_box(cx: &ctxt, ty: t) -> bool { +fn type_is_box(cx: ctxt, ty: t) -> bool { alt struct(cx, ty) { ty_box(_) { ret true; } _ { ret false; } } } -fn type_is_boxed(cx: &ctxt, ty: t) -> bool { +fn type_is_boxed(cx: ctxt, ty: t) -> bool { alt struct(cx, ty) { ty_box(_) { ret true; } _ { ret false; } } } -fn type_is_vec(cx: &ctxt, ty: t) -> bool { +fn type_is_vec(cx: ctxt, ty: t) -> bool { ret alt struct(cx, ty) { ty_vec(_) { true } ty_str. { true } @@ -874,7 +874,7 @@ fn type_is_vec(cx: &ctxt, ty: t) -> bool { }; } -fn type_is_unique(cx: &ctxt, ty: t) -> bool { +fn type_is_unique(cx: ctxt, ty: t) -> bool { alt struct(cx, ty) { ty_uniq(_) { ret true; } ty_vec(_) { true } @@ -883,7 +883,7 @@ fn type_is_unique(cx: &ctxt, ty: t) -> bool { } } -fn type_is_scalar(cx: &ctxt, ty: t) -> bool { +fn type_is_scalar(cx: ctxt, ty: t) -> bool { alt struct(cx, ty) { ty_nil. { ret true; } ty_bool. { ret true; } @@ -899,7 +899,7 @@ fn type_is_scalar(cx: &ctxt, ty: t) -> bool { } } -fn type_has_pointers(cx: &ctxt, ty: t) -> bool { +fn type_has_pointers(cx: ctxt, ty: t) -> bool { alt cx.has_pointer_cache.find(ty) { some(result) { ret result; } none. {/* fall through */ } @@ -908,6 +908,7 @@ fn type_has_pointers(cx: &ctxt, ty: t) -> bool { let result = false; alt struct(cx, ty) { + // scalar types ty_nil. { /* no-op */ @@ -952,7 +953,7 @@ fn type_has_pointers(cx: &ctxt, ty: t) -> bool { ret result; } -fn type_needs_drop(cx: &ctxt, ty: t) -> bool { +fn type_needs_drop(cx: ctxt, ty: t) -> bool { ret alt struct(cx, ty) { ty_res(_, _, _) { true } ty_param(_, _) { true } @@ -960,7 +961,7 @@ fn type_needs_drop(cx: &ctxt, ty: t) -> bool { }; } -fn type_kind(cx: &ctxt, ty: t) -> ast::kind { +fn type_kind(cx: ctxt, ty: t) -> ast::kind { alt cx.kind_cache.find(ty) { some(result) { ret result; } none. {/* fall through */ } @@ -975,6 +976,7 @@ fn type_kind(cx: &ctxt, ty: t) -> ast::kind { + // Scalar types are unique-kind, no substructure. ty_nil. | ty_bot. | ty_bool. | ty_int. | ty_uint. | ty_float. | ty_machine(_) | ty_char. | ty_native(_) { @@ -983,6 +985,7 @@ fn type_kind(cx: &ctxt, ty: t) -> ast::kind { + // A handful of other built-in are unique too. ty_type. | ty_str. | ty_native_fn(_, _, _) { // no-op @@ -990,6 +993,7 @@ fn type_kind(cx: &ctxt, ty: t) -> ast::kind { + // FIXME: obj is broken for now, since we aren't asserting // anything about its fields. ty_obj(_) { @@ -998,6 +1002,7 @@ fn type_kind(cx: &ctxt, ty: t) -> ast::kind { + // FIXME: the environment capture mode is not fully encoded // here yet, leading to weirdness around closure. ty_fn(proto, _, _, _, _) { @@ -1011,6 +1016,7 @@ fn type_kind(cx: &ctxt, ty: t) -> ast::kind { + // Those with refcounts-to-inner raise pinned to shared, // lower unique to shared. Therefore just set result to shared. ty_box(mt) { @@ -1019,6 +1025,7 @@ fn type_kind(cx: &ctxt, ty: t) -> ast::kind { + // Pointers and unique boxes / vecs raise pinned to shared, // otherwise pass through their pointee kind. ty_ptr(tm) | ty_vec(tm) { @@ -1029,6 +1036,7 @@ fn type_kind(cx: &ctxt, ty: t) -> ast::kind { + // Records lower to the lowest of their members. ty_rec(flds) { for f: field in flds { @@ -1038,6 +1046,7 @@ fn type_kind(cx: &ctxt, ty: t) -> ast::kind { } + // Tuples lower to the lowest of their members. ty_tup(tys) { for ty: t in tys { @@ -1048,6 +1057,7 @@ fn type_kind(cx: &ctxt, ty: t) -> ast::kind { + // Tags lower to the lowest of their variants. ty_tag(did, tps) { let variants = tag_variants(cx, did); @@ -1064,6 +1074,7 @@ fn type_kind(cx: &ctxt, ty: t) -> ast::kind { + // Resources are always pinned. ty_res(did, inner, tps) { result = ast::kind_pinned; @@ -1071,24 +1082,28 @@ fn type_kind(cx: &ctxt, ty: t) -> ast::kind { + ty_var(_) { fail; } + ty_param(_, k) { result = kind::lower_kind(result, k); } + ty_constr(t, _) { result = type_kind(cx, t); } + _ { cx.sess.bug("missed case: " + ty_to_str(cx, ty)); } @@ -1102,11 +1117,11 @@ fn type_kind(cx: &ctxt, ty: t) -> ast::kind { // FIXME: should we just return true for native types in // type_is_scalar? -fn type_is_native(cx: &ctxt, ty: t) -> bool { +fn type_is_native(cx: ctxt, ty: t) -> bool { alt struct(cx, ty) { ty_native(_) { ret true; } _ { ret false; } } } -fn type_structurally_contains(cx: &ctxt, ty: t, test: fn(&sty) -> bool) -> +fn type_structurally_contains(cx: ctxt, ty: t, test: fn(sty) -> bool) -> bool { let sty = struct(cx, ty); if test(sty) { ret true; } @@ -1140,7 +1155,8 @@ fn type_structurally_contains(cx: &ctxt, ty: t, test: fn(&sty) -> bool) -> } } -pure fn type_has_dynamic_size(cx: &ctxt, ty: t) -> bool { +pure fn type_has_dynamic_size(cx: ctxt, ty: t) -> bool { + /* type_structurally_contains can't be declared pure because it takes a function argument. But it should be referentially transparent, since a given type's size should @@ -1149,45 +1165,55 @@ pure fn type_has_dynamic_size(cx: &ctxt, ty: t) -> bool { actually checkable. It seems to me like a lot of properties that the type context tracks about types should be immutable.) */ - unchecked { - type_structurally_contains(cx, ty, fn(sty: &sty) -> bool { - ret alt sty { - ty_param(_, _) { true } - _ { false } - }; - }) + unchecked{ + type_structurally_contains(cx, ty, + fn (sty: sty) -> bool { + ret alt sty { + ty_param(_, _) { true } + _ { false } + }; + }) } } // Returns true for types where a copy of a value can be distinguished from // the value itself. I.e. types with mutable content that's not shared through // a pointer. -fn type_allows_implicit_copy(cx: &ctxt, ty: t) -> bool { - ret !type_structurally_contains(cx, ty, fn(sty: &sty) -> bool { - ret alt sty { - ty_param(_, _) { true } - ty_vec(mt) { mt.mut != ast::imm } - ty_rec(fields) { - for field in fields { if field.mt.mut != ast::imm { ret true; } } - false - } - _ { false } - }; - }); -} - -fn type_structurally_contains_uniques(cx: &ctxt, ty: t) -> bool { - ret type_structurally_contains(cx, ty, fn(sty: &sty) -> bool { - ret alt sty { - ty_uniq(_) { ret true; } - ty_vec(_) { true } - ty_str. { true } - _ { ret false; } - }; - }); -} - -fn type_is_integral(cx: &ctxt, ty: t) -> bool { +fn type_allows_implicit_copy(cx: ctxt, ty: t) -> bool { + ret !type_structurally_contains(cx, ty, + fn (sty: sty) -> bool { + ret alt sty { + ty_param(_, _) { true } + ty_vec(mt) { + mt.mut != ast::imm + } + ty_rec(fields) { + for field in fields { + if field.mt.mut != + ast::imm { + ret true; + } + } + false + } + _ { false } + }; + }); +} + +fn type_structurally_contains_uniques(cx: ctxt, ty: t) -> bool { + ret type_structurally_contains(cx, ty, + fn (sty: sty) -> bool { + ret alt sty { + ty_uniq(_) { ret true; } + ty_vec(_) { true } + ty_str. { true } + _ { ret false; } + }; + }); +} + +fn type_is_integral(cx: ctxt, ty: t) -> bool { alt struct(cx, ty) { ty_int. { ret true; } ty_uint. { ret true; } @@ -1210,7 +1236,7 @@ fn type_is_integral(cx: &ctxt, ty: t) -> bool { } } -fn type_is_fp(cx: &ctxt, ty: t) -> bool { +fn type_is_fp(cx: ctxt, ty: t) -> bool { alt struct(cx, ty) { ty_machine(tm) { alt tm { @@ -1224,7 +1250,7 @@ fn type_is_fp(cx: &ctxt, ty: t) -> bool { } } -fn type_is_signed(cx: &ctxt, ty: t) -> bool { +fn type_is_signed(cx: ctxt, ty: t) -> bool { alt struct(cx, ty) { ty_int. { ret true; } ty_machine(tm) { @@ -1241,11 +1267,12 @@ fn type_is_signed(cx: &ctxt, ty: t) -> bool { } // Whether a type is Plain Old Data (i.e. can be safely memmoved). -fn type_is_pod(cx: &ctxt, ty: t) -> bool { +fn type_is_pod(cx: ctxt, ty: t) -> bool { let result = true; alt struct(cx, ty) { + // Scalar types ty_nil. | ty_bot. | ty_bool. | ty_int. | ty_float. | ty_uint. | ty_machine(_) | ty_char. | ty_type. | ty_native(_) | ty_ptr(_) { @@ -1254,6 +1281,7 @@ fn type_is_pod(cx: &ctxt, ty: t) -> bool { + // Boxed types ty_str. | ty_box(_) | ty_vec(_) | ty_fn(_, _, _, _, _) | ty_native_fn(_, _, _) | ty_obj(_) { @@ -1262,6 +1290,7 @@ fn type_is_pod(cx: &ctxt, ty: t) -> bool { + // Structural types ty_tag(did, tps) { let variants = tag_variants(cx, did); @@ -1288,6 +1317,7 @@ fn type_is_pod(cx: &ctxt, ty: t) -> bool { + ty_var(_) { fail "ty_var in type_is_pod"; } @@ -1297,7 +1327,7 @@ fn type_is_pod(cx: &ctxt, ty: t) -> bool { ret result; } -fn type_param(cx: &ctxt, ty: t) -> option::t<uint> { +fn type_param(cx: ctxt, ty: t) -> option::t<uint> { alt struct(cx, ty) { ty_param(id, _) { ret some(id); } _ {/* fall through */ } @@ -1307,8 +1337,8 @@ fn type_param(cx: &ctxt, ty: t) -> option::t<uint> { // Returns a vec of all the type variables // occurring in t. It may contain duplicates. -fn vars_in_type(cx: &ctxt, ty: t) -> [int] { - fn collect_var(cx: &ctxt, vars: &@mutable [int], ty: t) { +fn vars_in_type(cx: ctxt, ty: t) -> [int] { + fn collect_var(cx: ctxt, vars: @mutable [int], ty: t) { alt struct(cx, ty) { ty_var(v) { *vars += [v]; } _ { } } } let rslt: @mutable [int] = @mutable []; @@ -1318,7 +1348,7 @@ fn vars_in_type(cx: &ctxt, ty: t) -> [int] { ret *rslt; } -fn type_autoderef(cx: &ctxt, t: ty::t) -> ty::t { +fn type_autoderef(cx: ctxt, t: ty::t) -> ty::t { let t1: ty::t = t; while true { alt struct(cx, t1) { @@ -1341,7 +1371,7 @@ fn type_autoderef(cx: &ctxt, t: ty::t) -> ty::t { // Type hashing. This function is private to this module (and slow); external // users should use `hash_ty()` instead. -fn hash_type_structure(st: &sty) -> uint { +fn hash_type_structure(st: sty) -> uint { fn hash_uint(id: uint, n: uint) -> uint { let h = id; h += h << 5u + n; @@ -1358,7 +1388,7 @@ fn hash_type_structure(st: &sty) -> uint { h += h << 5u + hash_ty(subty); ret h; } - fn hash_type_constr(id: uint, c: &@type_constr) -> uint { + fn hash_type_constr(id: uint, c: @type_constr) -> uint { let h = id; h += h << 5u + hash_def(h, c.node.id); ret hash_type_constr_args(h, c.node.args); @@ -1382,7 +1412,7 @@ fn hash_type_structure(st: &sty) -> uint { } - fn hash_fn(id: uint, args: &[arg], rty: t) -> uint { + fn hash_fn(id: uint, args: [arg], rty: t) -> uint { let h = id; for a: arg in args { h += h << 5u + hash_ty(a.ty); } h += h << 5u + hash_ty(rty); @@ -1430,6 +1460,7 @@ fn hash_type_structure(st: &sty) -> uint { + // ??? ty_fn(_, args, rty, _, _) { ret hash_fn(27u, args, rty); @@ -1460,7 +1491,7 @@ fn hash_type_structure(st: &sty) -> uint { } } -fn hash_type_info(st: &sty, cname_opt: &option::t<str>) -> uint { +fn hash_type_info(st: sty, cname_opt: option::t<str>) -> uint { let h = hash_type_structure(st); alt cname_opt { none. {/* no-op */ } @@ -1469,17 +1500,17 @@ fn hash_type_info(st: &sty, cname_opt: &option::t<str>) -> uint { ret h; } -fn hash_raw_ty(rt: &@raw_t) -> uint { ret rt.hash; } +fn hash_raw_ty(rt: @raw_t) -> uint { ret rt.hash; } -fn hash_ty(typ: &t) -> uint { ret typ; } +fn hash_ty(typ: t) -> uint { ret typ; } // Type equality. This function is private to this module (and slow); external // users should use `eq_ty()` instead. -fn eq_int(x: &uint, y: &uint) -> bool { ret x == y; } +fn eq_int(x: uint, y: uint) -> bool { ret x == y; } -fn arg_eq<T>(eq: &fn(&T, &T) -> bool, a: @sp_constr_arg<T>, - b: @sp_constr_arg<T>) -> bool { +fn arg_eq<T>(eq: fn(T, T) -> bool, a: @sp_constr_arg<T>, b: @sp_constr_arg<T>) + -> bool { alt a.node { ast::carg_base. { alt b.node { ast::carg_base. { ret true; } _ { ret false; } } @@ -1493,8 +1524,8 @@ fn arg_eq<T>(eq: &fn(&T, &T) -> bool, a: @sp_constr_arg<T>, } } -fn args_eq<T>(eq: fn(&T, &T) -> bool, a: &[@sp_constr_arg<T>], - b: &[@sp_constr_arg<T>]) -> bool { +fn args_eq<T>(eq: fn(T, T) -> bool, a: [@sp_constr_arg<T>], + b: [@sp_constr_arg<T>]) -> bool { let i: uint = 0u; for arg: @sp_constr_arg<T> in a { if !arg_eq(eq, arg, b[i]) { ret false; } @@ -1503,13 +1534,13 @@ fn args_eq<T>(eq: fn(&T, &T) -> bool, a: &[@sp_constr_arg<T>], ret true; } -fn constr_eq(c: &@constr, d: &@constr) -> bool { +fn constr_eq(c: @constr, d: @constr) -> bool { ret path_to_str(c.node.path) == path_to_str(d.node.path) && // FIXME: hack args_eq(eq_int, c.node.args, d.node.args); } -fn constrs_eq(cs: &[@constr], ds: &[@constr]) -> bool { +fn constrs_eq(cs: [@constr], ds: [@constr]) -> bool { if vec::len(cs) != vec::len(ds) { ret false; } let i = 0u; for c: @constr in cs { if !constr_eq(c, ds[i]) { ret false; } i += 1u; } @@ -1518,7 +1549,7 @@ fn constrs_eq(cs: &[@constr], ds: &[@constr]) -> bool { // An expensive type equality function. This function is private to this // module. -fn eq_raw_ty(a: &@raw_t, b: &@raw_t) -> bool { +fn eq_raw_ty(a: @raw_t, b: @raw_t) -> bool { // Check hashes (fast path). if a.hash != b.hash { ret false; } @@ -1541,11 +1572,11 @@ fn eq_raw_ty(a: &@raw_t, b: &@raw_t) -> bool { // This is the equality function the public should use. It works as long as // the types are interned. -fn eq_ty(a: &t, b: &t) -> bool { ret a == b; } +fn eq_ty(a: t, b: t) -> bool { ret a == b; } // Type lookups -fn node_id_to_ty_param_substs_opt_and_ty(cx: &ctxt, id: &ast::node_id) -> +fn node_id_to_ty_param_substs_opt_and_ty(cx: ctxt, id: ast::node_id) -> ty_param_substs_opt_and_ty { @@ -1560,26 +1591,26 @@ fn node_id_to_ty_param_substs_opt_and_ty(cx: &ctxt, id: &ast::node_id) -> } } -fn node_id_to_type(cx: &ctxt, id: &ast::node_id) -> t { +fn node_id_to_type(cx: ctxt, id: ast::node_id) -> t { ret node_id_to_ty_param_substs_opt_and_ty(cx, id).ty; } -fn node_id_to_type_params(cx: &ctxt, id: &ast::node_id) -> [t] { +fn node_id_to_type_params(cx: ctxt, id: ast::node_id) -> [t] { alt node_id_to_ty_param_substs_opt_and_ty(cx, id).substs { none. { ret []; } some(tps) { ret tps; } } } -fn node_id_has_type_params(cx: &ctxt, id: &ast::node_id) -> bool { +fn node_id_has_type_params(cx: ctxt, id: ast::node_id) -> bool { ret vec::len(node_id_to_type_params(cx, id)) > 0u; } // Returns a type with type parameter substitutions performed if applicable. -fn ty_param_substs_opt_and_ty_to_monotype(cx: &ctxt, - tpot: &ty_param_substs_opt_and_ty) - -> t { +fn ty_param_substs_opt_and_ty_to_monotype(cx: ctxt, + tpot: ty_param_substs_opt_and_ty) -> + t { alt tpot.substs { none. { ret tpot.ty; } some(tps) { ret substitute_type_params(cx, tps, tpot.ty); } @@ -1589,15 +1620,15 @@ fn ty_param_substs_opt_and_ty_to_monotype(cx: &ctxt, // Returns the type of an annotation, with type parameter substitutions // performed if applicable. -fn node_id_to_monotype(cx: &ctxt, id: ast::node_id) -> t { +fn node_id_to_monotype(cx: ctxt, id: ast::node_id) -> t { let tpot = node_id_to_ty_param_substs_opt_and_ty(cx, id); ret ty_param_substs_opt_and_ty_to_monotype(cx, tpot); } // Returns the number of distinct type parameters in the given type. -fn count_ty_params(cx: &ctxt, ty: t) -> uint { - fn counter(cx: &ctxt, param_indices: @mutable [uint], ty: t) { +fn count_ty_params(cx: ctxt, ty: t) -> uint { + fn counter(cx: ctxt, param_indices: @mutable [uint], ty: t) { alt struct(cx, ty) { ty_param(param_idx, _) { let seen = false; @@ -1615,17 +1646,17 @@ fn count_ty_params(cx: &ctxt, ty: t) -> uint { ret vec::len::<uint>(*param_indices); } -fn type_contains_vars(cx: &ctxt, typ: t) -> bool { +fn type_contains_vars(cx: ctxt, typ: t) -> bool { ret interner::get(*cx.ts, typ).has_vars; } -fn type_contains_params(cx: &ctxt, typ: t) -> bool { +fn type_contains_params(cx: ctxt, typ: t) -> bool { ret interner::get(*cx.ts, typ).has_params; } // Type accessors for substructures of types -fn ty_fn_args(cx: &ctxt, fty: t) -> [arg] { +fn ty_fn_args(cx: ctxt, fty: t) -> [arg] { alt struct(cx, fty) { ty::ty_fn(_, a, _, _, _) { ret a; } ty::ty_native_fn(_, a, _) { ret a; } @@ -1633,21 +1664,21 @@ fn ty_fn_args(cx: &ctxt, fty: t) -> [arg] { } } -fn ty_fn_proto(cx: &ctxt, fty: t) -> ast::proto { +fn ty_fn_proto(cx: ctxt, fty: t) -> ast::proto { alt struct(cx, fty) { ty::ty_fn(p, _, _, _, _) { ret p; } _ { cx.sess.bug("ty_fn_proto() called on non-fn type"); } } } -fn ty_fn_abi(cx: &ctxt, fty: t) -> ast::native_abi { +fn ty_fn_abi(cx: ctxt, fty: t) -> ast::native_abi { alt struct(cx, fty) { ty::ty_native_fn(a, _, _) { ret a; } _ { cx.sess.bug("ty_fn_abi() called on non-native-fn type"); } } } -fn ty_fn_ret(cx: &ctxt, fty: t) -> t { +fn ty_fn_ret(cx: ctxt, fty: t) -> t { alt struct(cx, fty) { ty::ty_fn(_, _, r, _, _) { ret r; } ty::ty_native_fn(_, _, r) { ret r; } @@ -1655,7 +1686,7 @@ fn ty_fn_ret(cx: &ctxt, fty: t) -> t { } } -fn is_fn_ty(cx: &ctxt, fty: t) -> bool { +fn is_fn_ty(cx: ctxt, fty: t) -> bool { alt struct(cx, fty) { ty::ty_fn(_, _, _, _, _) { ret true; } ty::ty_native_fn(_, _, _) { ret true; } @@ -1665,11 +1696,11 @@ fn is_fn_ty(cx: &ctxt, fty: t) -> bool { // Just checks whether it's a fn that returns bool, // not its purity. -fn is_pred_ty(cx: &ctxt, fty: t) -> bool { +fn is_pred_ty(cx: ctxt, fty: t) -> bool { is_fn_ty(cx, fty) && type_is_bool(cx, ty_fn_ret(cx, fty)) } -fn ty_var_id(cx: &ctxt, typ: t) -> int { +fn ty_var_id(cx: ctxt, typ: t) -> int { alt struct(cx, typ) { ty::ty_var(vid) { ret vid; } _ { log_err "ty_var_id called on non-var ty"; fail; } @@ -1678,14 +1709,14 @@ fn ty_var_id(cx: &ctxt, typ: t) -> int { // Type accessors for AST nodes -fn block_ty(cx: &ctxt, b: &ast::blk) -> t { +fn block_ty(cx: ctxt, b: ast::blk) -> t { ret node_id_to_type(cx, b.node.id); } // Returns the type of a pattern as a monotype. Like @expr_ty, this function // doesn't provide type parameter substitutions. -fn pat_ty(cx: &ctxt, pat: &@ast::pat) -> t { +fn pat_ty(cx: ctxt, pat: @ast::pat) -> t { ret node_id_to_monotype(cx, pat.id); } @@ -1696,21 +1727,20 @@ fn pat_ty(cx: &ctxt, pat: &@ast::pat) -> t { // ask for the type of "id" in "id(3)", it will return "fn(&int) -> int" // instead of "fn(t) -> T with T = int". If this isn't what you want, see // expr_ty_params_and_ty() below. -fn expr_ty(cx: &ctxt, expr: &@ast::expr) -> t { +fn expr_ty(cx: ctxt, expr: @ast::expr) -> t { ret node_id_to_monotype(cx, expr.id); } -fn expr_ty_params_and_ty(cx: &ctxt, expr: &@ast::expr) -> - {params: [t], ty: t} { +fn expr_ty_params_and_ty(cx: ctxt, expr: @ast::expr) -> {params: [t], ty: t} { ret {params: node_id_to_type_params(cx, expr.id), ty: node_id_to_type(cx, expr.id)}; } -fn expr_has_ty_params(cx: &ctxt, expr: &@ast::expr) -> bool { +fn expr_has_ty_params(cx: ctxt, expr: @ast::expr) -> bool { ret node_id_has_type_params(cx, expr.id); } -fn stmt_node_id(s: &@ast::stmt) -> ast::node_id { +fn stmt_node_id(s: @ast::stmt) -> ast::node_id { alt s.node { ast::stmt_decl(_, id) { ret id; } ast::stmt_expr(_, id) { ret id; } @@ -1721,28 +1751,28 @@ fn stmt_node_id(s: &@ast::stmt) -> ast::node_id { } } -fn field_idx(sess: &session::session, sp: &span, id: &ast::ident, - fields: &[field]) -> uint { +fn field_idx(sess: session::session, sp: span, id: ast::ident, + fields: [field]) -> uint { let i: uint = 0u; for f: field in fields { if str::eq(f.ident, id) { ret i; } i += 1u; } sess.span_fatal(sp, "unknown field '" + id + "' of record"); } -fn method_idx(sess: &session::session, sp: &span, id: &ast::ident, - meths: &[method]) -> uint { +fn method_idx(sess: session::session, sp: span, id: ast::ident, + meths: [method]) -> uint { let i: uint = 0u; for m: method in meths { if str::eq(m.ident, id) { ret i; } i += 1u; } sess.span_fatal(sp, "unknown method '" + id + "' of obj"); } -fn sort_methods(meths: &[method]) -> [method] { - fn method_lteq(a: &method, b: &method) -> bool { +fn sort_methods(meths: [method]) -> [method] { + fn method_lteq(a: method, b: method) -> bool { ret str::lteq(a.ident, b.ident); } ret std::sort::merge_sort::<method>(bind method_lteq(_, _), meths); } -fn is_lval(expr: &@ast::expr) -> bool { +fn is_lval(expr: @ast::expr) -> bool { alt expr.node { ast::expr_field(_, _) { ret true; } ast::expr_index(_, _) { ret true; } @@ -1752,7 +1782,7 @@ fn is_lval(expr: &@ast::expr) -> bool { } } -fn occurs_check_fails(tcx: &ctxt, sp: &option::t<span>, vid: int, rt: t) -> +fn occurs_check_fails(tcx: ctxt, sp: option::t<span>, vid: int, rt: t) -> bool { if !type_contains_vars(tcx, rt) { // Fast path @@ -1766,13 +1796,12 @@ fn occurs_check_fails(tcx: &ctxt, sp: &option::t<span>, vid: int, rt: t) -> // Maybe this should be span_err -- however, there's an // assertion later on that the type doesn't contain // variables, so in this case we have to be sure to die. - tcx.sess.span_fatal( - s, - "Type inference failed because I \ + tcx.sess.span_fatal(s, + "Type inference failed because I \ could not find a type\n that's both of the form " - + ty_to_str(tcx, ty::mk_var(tcx, vid)) + - " and of the form " + ty_to_str(tcx, rt) + - ". Such a type would have to be infinitely \ + + ty_to_str(tcx, ty::mk_var(tcx, vid)) + + " and of the form " + ty_to_str(tcx, rt) + + ". Such a type would have to be infinitely \ large."); } _ { ret true; } @@ -1815,13 +1844,13 @@ mod unify { } // Unifies two sets. - fn union(cx: &@ctxt, set_a: uint, set_b: uint) -> union_result { + fn union(cx: @ctxt, set_a: uint, set_b: uint) -> union_result { ufind::grow(cx.vb.sets, uint::max(set_a, set_b) + 1u); let root_a = ufind::find(cx.vb.sets, set_a); let root_b = ufind::find(cx.vb.sets, set_b); let replace_type = - bind fn (cx: &@ctxt, t: t, set_a: uint, set_b: uint) { + bind fn (cx: @ctxt, t: t, set_a: uint, set_b: uint) { ufind::union(cx.vb.sets, set_a, set_b); let root_c: uint = ufind::find(cx.vb.sets, set_a); smallintmap::insert::<t>(cx.vb.types, root_c, t); @@ -1848,7 +1877,7 @@ mod unify { } } } - fn record_var_binding(cx: &@ctxt, key: int, typ: t) -> result { + fn record_var_binding(cx: @ctxt, key: int, typ: t) -> result { ufind::grow(cx.vb.sets, (key as uint) + 1u); let root = ufind::find(cx.vb.sets, key as uint); let result_type = typ; @@ -1883,7 +1912,7 @@ mod unify { // Right now this just checks that the lists of constraints are // pairwise equal. fn unify_constrs(base_t: t, expected: [@type_constr], - actual: &[@type_constr]) -> result { + actual: [@type_constr]) -> result { let expected_len = vec::len(expected); let actual_len = vec::len(actual); @@ -1900,7 +1929,7 @@ mod unify { ret ures_ok(base_t); } fn unify_constr(base_t: t, expected: @type_constr, - actual_constr: &@type_constr) -> result { + actual_constr: @type_constr) -> result { let ok_res = ures_ok(base_t); let err_res = ures_err(terr_constr_mismatch(expected, actual_constr)); if expected.node.id != actual_constr.node.id { ret err_res; } @@ -1945,9 +1974,9 @@ mod unify { fn_common_res_err(result); fn_common_res_ok([arg], t); } - fn unify_fn_common(cx: &@ctxt, _expected: t, _actual: t, - expected_inputs: &[arg], expected_output: t, - actual_inputs: &[arg], actual_output: t) -> + fn unify_fn_common(cx: @ctxt, _expected: t, _actual: t, + expected_inputs: [arg], expected_output: t, + actual_inputs: [arg], actual_output: t) -> fn_common_res { let expected_len = vec::len::<arg>(expected_inputs); let actual_len = vec::len::<arg>(actual_inputs); @@ -1965,9 +1994,8 @@ mod unify { let result_mode; if expected_input.mode != actual_input.mode { - ret fn_common_res_err(ures_err( - terr_mode_mismatch(expected_input.mode, - actual_input.mode))); + ret fn_common_res_err(ures_err(terr_mode_mismatch(expected_input.mode, + actual_input.mode))); } else { result_mode = expected_input.mode; } let result = unify_step(cx, expected_input.ty, actual_input.ty); alt result { @@ -1984,17 +2012,18 @@ mod unify { _ { ret fn_common_res_err(result); } } } - fn unify_fn(cx: &@ctxt, e_proto: &ast::proto, a_proto: &ast::proto, - expected: t, actual: t, expected_inputs: &[arg], - expected_output: t, actual_inputs: &[arg], actual_output: t, - expected_cf: &controlflow, actual_cf: &controlflow, - _expected_constrs: &[@constr], actual_constrs: &[@constr]) -> + fn unify_fn(cx: @ctxt, e_proto: ast::proto, a_proto: ast::proto, + expected: t, actual: t, expected_inputs: [arg], + expected_output: t, actual_inputs: [arg], actual_output: t, + expected_cf: controlflow, actual_cf: controlflow, + _expected_constrs: [@constr], actual_constrs: [@constr]) -> result { if e_proto != a_proto { ret ures_err(terr_mismatch); } alt expected_cf { ast::return. { } + // ok ast::noreturn. { alt actual_cf { @@ -2027,10 +2056,10 @@ mod unify { } } } - fn unify_native_fn(cx: &@ctxt, e_abi: &ast::native_abi, - a_abi: &ast::native_abi, expected: t, actual: t, - expected_inputs: &[arg], expected_output: t, - actual_inputs: &[arg], actual_output: t) -> result { + fn unify_native_fn(cx: @ctxt, e_abi: ast::native_abi, + a_abi: ast::native_abi, expected: t, actual: t, + expected_inputs: [arg], expected_output: t, + actual_inputs: [arg], actual_output: t) -> result { if e_abi != a_abi { ret ures_err(terr_mismatch); } let t = unify_fn_common(cx, expected, actual, expected_inputs, @@ -2043,9 +2072,8 @@ mod unify { } } } - fn unify_obj(cx: &@ctxt, expected: t, actual: t, - expected_meths: &[method], actual_meths: &[method]) -> - result { + fn unify_obj(cx: @ctxt, expected: t, actual: t, expected_meths: [method], + actual_meths: [method]) -> result { let result_meths: [method] = []; let i: uint = 0u; let expected_len: uint = vec::len::<method>(expected_meths); @@ -2081,7 +2109,7 @@ mod unify { } // If the given type is a variable, returns the structure of that type. - fn resolve_type_structure(tcx: &ty_ctxt, vb: &@var_bindings, typ: t) -> + fn resolve_type_structure(tcx: ty_ctxt, vb: @var_bindings, typ: t) -> fixup_result { alt struct(tcx, typ) { ty_var(vid) { @@ -2095,7 +2123,7 @@ mod unify { _ { ret fix_ok(typ); } } } - fn unify_step(cx: &@ctxt, expected: t, actual: t) -> result { + fn unify_step(cx: @ctxt, expected: t, actual: t) -> result { // TODO: rewrite this using tuple pattern matching when available, to // avoid all this rightward drift and spikiness. @@ -2109,6 +2137,7 @@ mod unify { + // If the RHS is a variable type, then just do the // appropriate binding. ty::ty_var(actual_id) { @@ -2158,6 +2187,7 @@ mod unify { + // _|_ unifies with anything ty::ty_bot. { ret ures_ok(actual); @@ -2443,7 +2473,7 @@ mod unify { } } } - fn unify(expected: t, actual: t, vb: &@var_bindings, tcx: &ty_ctxt) -> + fn unify(expected: t, actual: t, vb: @var_bindings, tcx: ty_ctxt) -> result { let cx = @{vb: vb, tcx: tcx}; ret unify_step(cx, expected, actual); @@ -2471,9 +2501,9 @@ mod unify { // Takes an optional span - complain about occurs check violations // iff the span is present (so that if we already know we're going // to error anyway, we don't complain) - fn fixup_vars(tcx: ty_ctxt, sp: &option::t<span>, vb: @var_bindings, + fn fixup_vars(tcx: ty_ctxt, sp: option::t<span>, vb: @var_bindings, typ: t) -> fixup_result { - fn subst_vars(tcx: ty_ctxt, sp: &option::t<span>, vb: @var_bindings, + fn subst_vars(tcx: ty_ctxt, sp: option::t<span>, vb: @var_bindings, unresolved: @mutable option::t<int>, vid: int) -> t { // Should really return a fixup_result instead of a t, but fold_ty // doesn't allow returning anything but a t. @@ -2506,8 +2536,8 @@ mod unify { some(var_id) { ret fix_err(var_id); } } } - fn resolve_type_var(tcx: &ty_ctxt, sp: &option::t<span>, - vb: &@var_bindings, vid: int) -> fixup_result { + fn resolve_type_var(tcx: ty_ctxt, sp: option::t<span>, vb: @var_bindings, + vid: int) -> fixup_result { if vid as uint >= ufind::set_count(vb.sets) { ret fix_err(vid); } let root_id = ufind::find(vb.sets, vid as uint); alt smallintmap::find::<t>(vb.types, root_id) { @@ -2517,7 +2547,7 @@ mod unify { } } -fn type_err_to_str(err: &ty::type_err) -> str { +fn type_err_to_str(err: ty::type_err) -> str { alt err { terr_mismatch. { ret "types differ"; } terr_controlflow_mismatch. { @@ -2567,7 +2597,7 @@ fn type_err_to_str(err: &ty::type_err) -> str { // Converts type parameters in a type to type variables and returns the // resulting type along with a list of type variable IDs. -fn bind_params_in_type(sp: &span, cx: &ctxt, next_ty_var: fn() -> int, typ: t, +fn bind_params_in_type(sp: span, cx: ctxt, next_ty_var: fn() -> int, typ: t, ty_param_count: uint) -> {ids: [int], ty: t} { let param_var_ids: @mutable [int] = @mutable []; let i = 0u; @@ -2590,7 +2620,7 @@ fn bind_params_in_type(sp: &span, cx: &ctxt, next_ty_var: fn() -> int, typ: t, // Replaces type parameters in the given type using the given list of // substitions. -fn substitute_type_params(cx: &ctxt, substs: &[ty::t], typ: t) -> t { +fn substitute_type_params(cx: ctxt, substs: [ty::t], typ: t) -> t { if !type_contains_params(cx, typ) { ret typ; } fn substituter(_cx: ctxt, substs: @[ty::t], idx: uint, _kind: ast::kind) -> t { @@ -2600,7 +2630,7 @@ fn substitute_type_params(cx: &ctxt, substs: &[ty::t], typ: t) -> t { ret fold_ty(cx, fm_param(bind substituter(cx, @substs, _, _)), typ); } -fn def_has_ty_params(def: &ast::def) -> bool { +fn def_has_ty_params(def: ast::def) -> bool { alt def { ast::def_fn(_, _) { ret true; } ast::def_obj_field(_, _) { ret false; } @@ -2623,7 +2653,7 @@ fn def_has_ty_params(def: &ast::def) -> bool { // Tag information type variant_info = {args: [ty::t], ctor_ty: ty::t, id: ast::def_id}; -fn tag_variants(cx: &ctxt, id: &ast::def_id) -> [variant_info] { +fn tag_variants(cx: ctxt, id: ast::def_id) -> [variant_info] { if ast::local_crate != id.crate { ret csearch::get_tag_variants(cx, id); } let item = alt cx.items.find(id.node) { @@ -2658,8 +2688,8 @@ fn tag_variants(cx: &ctxt, id: &ast::def_id) -> [variant_info] { // Returns information about the tag variant with the given ID: -fn tag_variant_with_id(cx: &ctxt, tag_id: &ast::def_id, - variant_id: &ast::def_id) -> variant_info { +fn tag_variant_with_id(cx: ctxt, tag_id: ast::def_id, variant_id: ast::def_id) + -> variant_info { let variants = tag_variants(cx, tag_id); let i = 0u; while i < vec::len::<variant_info>(variants) { @@ -2705,7 +2735,7 @@ fn ret_ty_of_fn(cx: ctxt, id: ast::node_id) -> t { ret ret_ty_of_fn_ty(cx, node_id_to_type(cx, id)); } -fn is_binopable(cx: &ctxt, ty: t, op: ast::binop) -> bool { +fn is_binopable(cx: ctxt, ty: t, op: ast::binop) -> bool { const tycat_other: int = 0; const tycat_bool: int = 1; @@ -2749,7 +2779,7 @@ fn is_binopable(cx: &ctxt, ty: t, op: ast::binop) -> bool { } } - fn tycat(cx: &ctxt, ty: t) -> int { + fn tycat(cx: ctxt, ty: t) -> int { alt struct(cx, ty) { ty_bool. { tycat_bool } ty_int. { tycat_int } @@ -2799,7 +2829,7 @@ fn is_binopable(cx: &ctxt, ty: t, op: ast::binop) -> bool { ret tbl[tycat(cx, ty)][opcat(op)]; } -fn ast_constr_to_constr<T>(tcx: ty::ctxt, c: &@ast::constr_general<T>) -> +fn ast_constr_to_constr<T>(tcx: ty::ctxt, c: @ast::constr_general<T>) -> @ty::constr_general<T> { alt tcx.def_map.find(c.node.id) { some(ast::def_fn(pred_id, ast::pure_fn.)) { @@ -2809,10 +2839,9 @@ fn ast_constr_to_constr<T>(tcx: ty::ctxt, c: &@ast::constr_general<T>) -> id: pred_id}); } _ { - tcx.sess.span_fatal( - c.span, - "Predicate " + path_to_str(c.node.path) + - " is unbound or bound to a non-function or an \ + tcx.sess.span_fatal(c.span, + "Predicate " + path_to_str(c.node.path) + + " is unbound or bound to a non-function or an \ impure function"); } } diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 3d68eaabff7..3ea6bed549a 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -78,9 +78,9 @@ type fn_ctxt = // Used for ast_ty_to_ty() below. -type ty_getter = fn(&ast::def_id) -> ty::ty_param_kinds_and_ty; +type ty_getter = fn(ast::def_id) -> ty::ty_param_kinds_and_ty; -fn lookup_local(fcx: &@fn_ctxt, sp: &span, id: ast::node_id) -> int { +fn lookup_local(fcx: @fn_ctxt, sp: span, id: ast::node_id) -> int { alt fcx.locals.find(id) { some(x) { x } _ { @@ -90,7 +90,7 @@ fn lookup_local(fcx: &@fn_ctxt, sp: &span, id: ast::node_id) -> int { } } -fn lookup_def(fcx: &@fn_ctxt, sp: &span, id: ast::node_id) -> ast::def { +fn lookup_def(fcx: @fn_ctxt, sp: span, id: ast::node_id) -> ast::def { alt fcx.ccx.tcx.def_map.find(id) { some(x) { x } _ { @@ -100,7 +100,7 @@ fn lookup_def(fcx: &@fn_ctxt, sp: &span, id: ast::node_id) -> ast::def { } } -fn ident_for_local(loc: &@ast::local) -> ast::ident { +fn ident_for_local(loc: @ast::local) -> ast::ident { ret alt loc.node.pat.node { ast::pat_bind(name) { name } _ { "local" } @@ -108,8 +108,8 @@ fn ident_for_local(loc: &@ast::local) -> ast::ident { } // Returns the type parameter count and the type for the given definition. -fn ty_param_kinds_and_ty_for_def(fcx: &@fn_ctxt, sp: &span, defn: &ast::def) - -> ty_param_kinds_and_ty { +fn ty_param_kinds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) -> + ty_param_kinds_and_ty { let no_kinds: [ast::kind] = []; alt defn { ast::def_arg(id, _) { @@ -157,9 +157,8 @@ fn ty_param_kinds_and_ty_for_def(fcx: &@fn_ctxt, sp: &span, defn: &ast::def) // Instantiates the given path, which must refer to an item with the given // number of type parameters and type. -fn instantiate_path(fcx: &@fn_ctxt, pth: &ast::path, - tpt: &ty_param_kinds_and_ty, sp: &span) -> - ty_param_substs_opt_and_ty { +fn instantiate_path(fcx: @fn_ctxt, pth: ast::path, tpt: ty_param_kinds_and_ty, + sp: span) -> ty_param_substs_opt_and_ty { let ty_param_count = vec::len(tpt.kinds); let bind_result = bind_params_in_type(sp, fcx.ccx.tcx, bind next_ty_var_id(fcx), tpt.ty, @@ -170,16 +169,13 @@ fn instantiate_path(fcx: &@fn_ctxt, pth: &ast::path, if ty_substs_len > 0u { let param_var_len = vec::len(ty_param_vars); if param_var_len == 0u { - fcx.ccx.tcx.sess.span_fatal( - sp, - "this item does not take type parameters"); + fcx.ccx.tcx.sess.span_fatal(sp, + "this item does not take type parameters"); } else if ty_substs_len > param_var_len { - fcx.ccx.tcx.sess.span_fatal( - sp, - "too many type parameter provided for this item"); + fcx.ccx.tcx.sess.span_fatal(sp, + "too many type parameter provided for this item"); } else if ty_substs_len < param_var_len { - fcx.ccx.tcx.sess.span_fatal( - sp, + fcx.ccx.tcx.sess.span_fatal(sp, "not enough type parameters provided for this item"); } let ty_substs: [ty::t] = []; @@ -211,26 +207,25 @@ fn instantiate_path(fcx: &@fn_ctxt, pth: &ast::path, } // Type tests -fn structurally_resolved_type(fcx: &@fn_ctxt, sp: &span, tp: ty::t) -> ty::t { +fn structurally_resolved_type(fcx: @fn_ctxt, sp: span, tp: ty::t) -> ty::t { alt ty::unify::resolve_type_structure(fcx.ccx.tcx, fcx.var_bindings, tp) { fix_ok(typ_s) { ret typ_s; } fix_err(_) { - fcx.ccx.tcx.sess.span_fatal( - sp, - "the type of this value must be known in this context"); + fcx.ccx.tcx.sess.span_fatal(sp, + "the type of this value must be known in this context"); } } } // Returns the one-level-deep structure of the given type. -fn structure_of(fcx: &@fn_ctxt, sp: &span, typ: ty::t) -> ty::sty { +fn structure_of(fcx: @fn_ctxt, sp: span, typ: ty::t) -> ty::sty { ret ty::struct(fcx.ccx.tcx, structurally_resolved_type(fcx, sp, typ)); } // Returns the one-level-deep structure of the given type or none if it // is not known yet. -fn structure_of_maybe(fcx: &@fn_ctxt, _sp: &span, typ: ty::t) -> +fn structure_of_maybe(fcx: @fn_ctxt, _sp: span, typ: ty::t) -> option::t<ty::sty> { let r = ty::unify::resolve_type_structure(fcx.ccx.tcx, fcx.var_bindings, typ); @@ -240,12 +235,12 @@ fn structure_of_maybe(fcx: &@fn_ctxt, _sp: &span, typ: ty::t) -> } } -fn type_is_integral(fcx: &@fn_ctxt, sp: &span, typ: ty::t) -> bool { +fn type_is_integral(fcx: @fn_ctxt, sp: span, typ: ty::t) -> bool { let typ_s = structurally_resolved_type(fcx, sp, typ); ret ty::type_is_integral(fcx.ccx.tcx, typ_s); } -fn type_is_scalar(fcx: &@fn_ctxt, sp: &span, typ: ty::t) -> bool { +fn type_is_scalar(fcx: @fn_ctxt, sp: span, typ: ty::t) -> bool { let typ_s = structurally_resolved_type(fcx, sp, typ); ret ty::type_is_scalar(fcx.ccx.tcx, typ_s); } @@ -254,8 +249,7 @@ fn type_is_scalar(fcx: &@fn_ctxt, sp: &span, typ: ty::t) -> bool { // Parses the programmer's textual representation of a type into our internal // notion of a type. `getter` is a function that returns the type // corresponding to a definition ID: -fn ast_ty_to_ty(tcx: &ty::ctxt, getter: &ty_getter, ast_ty: &@ast::ty) -> - ty::t { +fn ast_ty_to_ty(tcx: ty::ctxt, getter: ty_getter, ast_ty: @ast::ty) -> ty::t { alt tcx.ast_ty_to_ty_cache.find(ast_ty) { some(some(ty)) { ret ty; } some(none.) { @@ -268,16 +262,15 @@ fn ast_ty_to_ty(tcx: &ty::ctxt, getter: &ty_getter, ast_ty: &@ast::ty) -> } /* go on */ tcx.ast_ty_to_ty_cache.insert(ast_ty, none::<ty::t>); - fn ast_arg_to_arg(tcx: &ty::ctxt, getter: &ty_getter, arg: &ast::ty_arg) - -> {mode: ty::mode, ty: ty::t} { + fn ast_arg_to_arg(tcx: ty::ctxt, getter: ty_getter, arg: ast::ty_arg) -> + {mode: ty::mode, ty: ty::t} { ret {mode: arg.node.mode, ty: ast_ty_to_ty(tcx, getter, arg.node.ty)}; } - fn ast_mt_to_mt(tcx: &ty::ctxt, getter: &ty_getter, mt: &ast::mt) -> - ty::mt { + fn ast_mt_to_mt(tcx: ty::ctxt, getter: ty_getter, mt: ast::mt) -> ty::mt { ret {ty: ast_ty_to_ty(tcx, getter, mt.ty), mut: mt.mut}; } - fn instantiate(tcx: &ty::ctxt, sp: &span, getter: &ty_getter, - id: &ast::def_id, args: &[@ast::ty]) -> ty::t { + fn instantiate(tcx: ty::ctxt, sp: span, getter: ty_getter, + id: ast::def_id, args: [@ast::ty]) -> ty::t { // TODO: maybe record cname chains so we can do // "foo = int" like OCaml? @@ -411,8 +404,8 @@ fn ast_ty_to_ty(tcx: &ty::ctxt, getter: &ty_getter, ast_ty: &@ast::ty) -> // A convenience function to use a crate_ctxt to resolve names for // ast_ty_to_ty. -fn ast_ty_to_ty_crate(ccx: @crate_ctxt, ast_ty: &@ast::ty) -> ty::t { - fn getter(ccx: @crate_ctxt, id: &ast::def_id) -> +fn ast_ty_to_ty_crate(ccx: @crate_ctxt, ast_ty: @ast::ty) -> ty::t { + fn getter(ccx: @crate_ctxt, id: ast::def_id) -> ty::ty_param_kinds_and_ty { ret ty::lookup_item_type(ccx.tcx, id); } @@ -421,7 +414,7 @@ fn ast_ty_to_ty_crate(ccx: @crate_ctxt, ast_ty: &@ast::ty) -> ty::t { } // A wrapper around ast_ty_to_ty_crate that handles ty_infer. -fn ast_ty_to_ty_crate_infer(ccx: @crate_ctxt, ast_ty: &@ast::ty) -> +fn ast_ty_to_ty_crate_infer(ccx: @crate_ctxt, ast_ty: @ast::ty) -> option::t<ty::t> { alt ast_ty.node { ast::ty_infer. { none } @@ -430,7 +423,7 @@ fn ast_ty_to_ty_crate_infer(ccx: @crate_ctxt, ast_ty: &@ast::ty) -> } // A wrapper around ast_ty_to_ty_infer that generates a new type variable if // there isn't a fixed type. -fn ast_ty_to_ty_crate_tyvar(fcx: &@fn_ctxt, ast_ty: &@ast::ty) -> ty::t { +fn ast_ty_to_ty_crate_tyvar(fcx: @fn_ctxt, ast_ty: @ast::ty) -> ty::t { alt ast_ty_to_ty_crate_infer(fcx.ccx, ast_ty) { some(ty) { ty } none. { next_ty_var(fcx) } @@ -440,14 +433,14 @@ fn ast_ty_to_ty_crate_tyvar(fcx: &@fn_ctxt, ast_ty: &@ast::ty) -> ty::t { // Functions that write types into the node type table. mod write { - fn inner(ntt: &node_type_table, node_id: ast::node_id, - tpot: &ty_param_substs_opt_and_ty) { + fn inner(ntt: node_type_table, node_id: ast::node_id, + tpot: ty_param_substs_opt_and_ty) { smallintmap::insert(*ntt, node_id as uint, tpot); } // Writes a type parameter count and type pair into the node type table. - fn ty(tcx: &ty::ctxt, node_id: ast::node_id, - tpot: &ty_param_substs_opt_and_ty) { + fn ty(tcx: ty::ctxt, node_id: ast::node_id, + tpot: ty_param_substs_opt_and_ty) { assert (!ty::type_contains_vars(tcx, tpot.ty)); inner(tcx.node_types, node_id, tpot); } @@ -456,7 +449,7 @@ mod write { // This function allows for the possibility of type variables, which will // be rewritten later during the fixup phase. fn ty_fixup(fcx: @fn_ctxt, node_id: ast::node_id, - tpot: &ty_param_substs_opt_and_ty) { + tpot: ty_param_substs_opt_and_ty) { inner(fcx.ccx.tcx.node_types, node_id, tpot); if ty::type_contains_vars(fcx.ccx.tcx, tpot.ty) { fcx.fixups += [node_id]; @@ -464,7 +457,7 @@ mod write { } // Writes a type with no type parameters into the node type table. - fn ty_only(tcx: &ty::ctxt, node_id: ast::node_id, typ: ty::t) { + fn ty_only(tcx: ty::ctxt, node_id: ast::node_id, typ: ty::t) { ty(tcx, node_id, {substs: none::<[ty::t]>, ty: typ}); } @@ -475,12 +468,12 @@ mod write { } // Writes a nil type into the node type table. - fn nil_ty(tcx: &ty::ctxt, node_id: ast::node_id) { + fn nil_ty(tcx: ty::ctxt, node_id: ast::node_id) { ret ty(tcx, node_id, {substs: none::<[ty::t]>, ty: ty::mk_nil(tcx)}); } // Writes the bottom type into the node type table. - fn bot_ty(tcx: &ty::ctxt, node_id: ast::node_id) { + fn bot_ty(tcx: ty::ctxt, node_id: ast::node_id) { ret ty(tcx, node_id, {substs: none::<[ty::t]>, ty: ty::mk_bot(tcx)}); } } @@ -488,7 +481,7 @@ mod write { // Determine the proto for a fn type given the proto for its associated // code. This is needed because fn and lambda have fn type while iter // has iter type and block has block type. This may end up changing. -fn proto_to_ty_proto(proto: &ast::proto) -> ast::proto { +fn proto_to_ty_proto(proto: ast::proto) -> ast::proto { ret alt proto { ast::proto_iter. | ast::proto_block. { proto } _ { ast::proto_fn } @@ -512,7 +505,7 @@ fn proto_to_ty_proto(proto: &ast::proto) -> ast::proto { mod collect { type ctxt = {tcx: ty::ctxt}; - fn mk_ty_params(cx: &@ctxt, atps: &[ast::ty_param]) -> [ty::t] { + fn mk_ty_params(cx: @ctxt, atps: [ast::ty_param]) -> [ty::t] { let tps = []; let i = 0u; for atp: ast::ty_param in atps { @@ -522,16 +515,16 @@ mod collect { ret tps; } - fn ty_param_kinds(tps: &[ast::ty_param]) -> [ast::kind] { + fn ty_param_kinds(tps: [ast::ty_param]) -> [ast::kind] { let k: [ast::kind] = []; for p: ast::ty_param in tps { k += [p.kind] } ret k; } - fn ty_of_fn_decl(cx: &@ctxt, convert: &fn(&@ast::ty) -> ty::t, - ty_of_arg: &fn(&ast::arg) -> arg, decl: &ast::fn_decl, - proto: ast::proto, ty_params: &[ast::ty_param], - def_id: &option::t<ast::def_id>) -> + fn ty_of_fn_decl(cx: @ctxt, convert: fn(@ast::ty) -> ty::t, + ty_of_arg: fn(ast::arg) -> arg, decl: ast::fn_decl, + proto: ast::proto, ty_params: [ast::ty_param], + def_id: option::t<ast::def_id>) -> ty::ty_param_kinds_and_ty { let input_tys = []; for a: ast::arg in decl.inputs { input_tys += [ty_of_arg(a)]; } @@ -548,10 +541,10 @@ mod collect { alt def_id { some(did) { cx.tcx.tcache.insert(did, tpt); } _ { } } ret tpt; } - fn ty_of_native_fn_decl(cx: &@ctxt, convert: &fn(&@ast::ty) -> ty::t, - ty_of_arg: &fn(&ast::arg) -> arg, - decl: &ast::fn_decl, abi: ast::native_abi, - ty_params: &[ast::ty_param], def_id: &ast::def_id) + fn ty_of_native_fn_decl(cx: @ctxt, convert: fn(@ast::ty) -> ty::t, + ty_of_arg: fn(ast::arg) -> arg, + decl: ast::fn_decl, abi: ast::native_abi, + ty_params: [ast::ty_param], def_id: ast::def_id) -> ty::ty_param_kinds_and_ty { let input_tys = []; for a: ast::arg in decl.inputs { input_tys += [ty_of_arg(a)]; } @@ -562,7 +555,7 @@ mod collect { cx.tcx.tcache.insert(def_id, tpt); ret tpt; } - fn getter(cx: @ctxt, id: &ast::def_id) -> ty::ty_param_kinds_and_ty { + fn getter(cx: @ctxt, id: ast::def_id) -> ty::ty_param_kinds_and_ty { if id.crate != ast::local_crate { // This is a type we need to load in from the crate reader. ret csearch::get_type(cx.tcx, id); @@ -578,12 +571,12 @@ mod collect { } ret tpt; } - fn ty_of_arg(cx: @ctxt, a: &ast::arg) -> ty::arg { + fn ty_of_arg(cx: @ctxt, a: ast::arg) -> ty::arg { let f = bind getter(cx, _); let tt = ast_ty_to_ty(cx.tcx, f, a.ty); ret {mode: a.mode, ty: tt}; } - fn ty_of_method(cx: @ctxt, m: &@ast::method) -> ty::method { + fn ty_of_method(cx: @ctxt, m: @ast::method) -> ty::method { let get = bind getter(cx, _); let convert = bind ast_ty_to_ty(cx.tcx, get, _); @@ -605,15 +598,15 @@ mod collect { cf: m.node.meth.decl.cf, constrs: out_constrs}; } - fn ty_of_obj(cx: @ctxt, id: &ast::ident, ob: &ast::_obj, - ty_params: &[ast::ty_param]) -> ty::ty_param_kinds_and_ty { + fn ty_of_obj(cx: @ctxt, id: ast::ident, ob: ast::_obj, + ty_params: [ast::ty_param]) -> ty::ty_param_kinds_and_ty { let methods = get_obj_method_types(cx, ob); let t_obj = ty::mk_obj(cx.tcx, ty::sort_methods(methods)); t_obj = ty::rename(cx.tcx, t_obj, id); ret {kinds: ty_param_kinds(ty_params), ty: t_obj}; } - fn ty_of_obj_ctor(cx: @ctxt, id: &ast::ident, ob: &ast::_obj, - ctor_id: ast::node_id, ty_params: &[ast::ty_param]) -> + fn ty_of_obj_ctor(cx: @ctxt, id: ast::ident, ob: ast::_obj, + ctor_id: ast::node_id, ty_params: [ast::ty_param]) -> ty::ty_param_kinds_and_ty { let t_obj = ty_of_obj(cx, id, ob, ty_params); @@ -631,7 +624,7 @@ mod collect { cx.tcx.tcache.insert(local_def(ctor_id), tpt); ret tpt; } - fn ty_of_item(cx: &@ctxt, it: &@ast::item) -> ty::ty_param_kinds_and_ty { + fn ty_of_item(cx: @ctxt, it: @ast::item) -> ty::ty_param_kinds_and_ty { let get = bind getter(cx, _); let convert = bind ast_ty_to_ty(cx.tcx, get, _); let no_kinds: [ast::kind] = []; @@ -687,7 +680,7 @@ mod collect { ast::item_native_mod(_) { fail; } } } - fn ty_of_native_item(cx: &@ctxt, it: &@ast::native_item, + fn ty_of_native_item(cx: @ctxt, it: @ast::native_item, abi: ast::native_abi) -> ty::ty_param_kinds_and_ty { let no_kinds: [ast::kind] = []; alt it.node { @@ -710,9 +703,9 @@ mod collect { } } } - fn get_tag_variant_types(cx: &@ctxt, tag_id: &ast::def_id, - variants: &[ast::variant], - ty_params: &[ast::ty_param]) { + fn get_tag_variant_types(cx: @ctxt, tag_id: ast::def_id, + variants: [ast::variant], + ty_params: [ast::ty_param]) { // Create a set of parameter types shared among all the variants. let ty_param_tys: [ty::t] = mk_ty_params(cx, ty_params); @@ -744,7 +737,7 @@ mod collect { write::ty_only(cx.tcx, variant.node.id, result_ty); } } - fn get_obj_method_types(cx: &@ctxt, object: &ast::_obj) -> [ty::method] { + fn get_obj_method_types(cx: @ctxt, object: ast::_obj) -> [ty::method] { let meths = []; for m: @ast::method in object.methods { meths += [ty_of_method(cx, m)]; @@ -752,7 +745,7 @@ mod collect { ret meths; } fn convert(cx: @ctxt, abi: @mutable option::t<ast::native_abi>, - it: &@ast::item) { + it: @ast::item) { alt it.node { ast::item_mod(_) { // ignore item_mod, it has no type. @@ -827,7 +820,7 @@ mod collect { } } fn convert_native(cx: @ctxt, abi: @mutable option::t<ast::native_abi>, - i: &@ast::native_item) { + i: @ast::native_item) { // As above, this call populates the type table with the converted // type of the native item. We simply write it into the node type // table. @@ -843,7 +836,7 @@ mod collect { } } } - fn collect_item_types(tcx: &ty::ctxt, crate: &@ast::crate) { + fn collect_item_types(tcx: ty::ctxt, crate: @ast::crate) { // We have to propagate the surrounding ABI to the native items // contained within the native module. let abi = @mutable none::<ast::native_abi>; @@ -853,7 +846,7 @@ mod collect { visit_native_item: bind convert_native(cx, abi, _) with - *visit::default_simple_visitor()}); + *visit::default_simple_visitor()}); visit::visit_crate(*crate, (), visit); } } @@ -861,7 +854,7 @@ mod collect { // Type unification mod unify { - fn unify(fcx: &@fn_ctxt, expected: ty::t, actual: ty::t) -> + fn unify(fcx: @fn_ctxt, expected: ty::t, actual: ty::t) -> ty::unify::result { ret ty::unify::unify(expected, actual, fcx.var_bindings, fcx.ccx.tcx); } @@ -870,7 +863,7 @@ mod unify { // FIXME This is almost a duplicate of ty::type_autoderef, with structure_of // instead of ty::struct. -fn do_autoderef(fcx: &@fn_ctxt, sp: &span, t: ty::t) -> ty::t { +fn do_autoderef(fcx: @fn_ctxt, sp: span, t: ty::t) -> ty::t { let t1 = t; while true { alt structure_of(fcx, sp, t1) { @@ -904,8 +897,8 @@ fn do_autoderef(fcx: &@fn_ctxt, sp: &span, t: ty::t) -> ty::t { fail; } -fn do_fn_block_coerce(fcx: &@fn_ctxt, sp: &span, actual: ty::t, - expected: ty::t) -> ty::t { +fn do_fn_block_coerce(fcx: @fn_ctxt, sp: span, actual: ty::t, expected: ty::t) + -> ty::t { // fns can be silently coerced to blocks when being used as // function call or bind arguments, but not the reverse. @@ -928,7 +921,7 @@ fn do_fn_block_coerce(fcx: &@fn_ctxt, sp: &span, actual: ty::t, } -fn resolve_type_vars_if_possible(fcx: &@fn_ctxt, typ: ty::t) -> ty::t { +fn resolve_type_vars_if_possible(fcx: @fn_ctxt, typ: ty::t) -> ty::t { alt ty::unify::fixup_vars(fcx.ccx.tcx, none, fcx.var_bindings, typ) { fix_ok(new_type) { ret new_type; } fix_err(_) { ret typ; } @@ -941,24 +934,24 @@ fn resolve_type_vars_if_possible(fcx: &@fn_ctxt, typ: ty::t) -> ty::t { type ty_param_substs_and_ty = {substs: [ty::t], ty: ty::t}; mod demand { - fn simple(fcx: &@fn_ctxt, sp: &span, expected: ty::t, actual: ty::t) -> + fn simple(fcx: @fn_ctxt, sp: span, expected: ty::t, actual: ty::t) -> ty::t { full(fcx, sp, expected, actual, [], false).ty } - fn block_coerce(fcx: &@fn_ctxt, sp: &span, expected: ty::t, actual: ty::t) + fn block_coerce(fcx: @fn_ctxt, sp: span, expected: ty::t, actual: ty::t) -> ty::t { full(fcx, sp, expected, actual, [], true).ty } - fn with_substs(fcx: &@fn_ctxt, sp: &span, expected: ty::t, actual: ty::t, - ty_param_substs_0: &[ty::t]) -> ty_param_substs_and_ty { + fn with_substs(fcx: @fn_ctxt, sp: span, expected: ty::t, actual: ty::t, + ty_param_substs_0: [ty::t]) -> ty_param_substs_and_ty { full(fcx, sp, expected, actual, ty_param_substs_0, false) } // Requires that the two types unify, and prints an error message if they // don't. Returns the unified type and the type parameter substitutions. - fn full(fcx: &@fn_ctxt, sp: &span, expected: ty::t, actual: ty::t, - ty_param_substs_0: &[ty::t], do_block_coerce: bool) -> + fn full(fcx: @fn_ctxt, sp: span, expected: ty::t, actual: ty::t, + ty_param_substs_0: [ty::t], do_block_coerce: bool) -> ty_param_substs_and_ty { if do_block_coerce { actual = do_fn_block_coerce(fcx, sp, actual, expected); @@ -975,8 +968,8 @@ mod demand { simple(fcx, sp, ty_param_subst, t_0); } - fn mk_result(fcx: &@fn_ctxt, result_ty: ty::t, - ty_param_subst_var_ids: &[int]) -> + fn mk_result(fcx: @fn_ctxt, result_ty: ty::t, + ty_param_subst_var_ids: [int]) -> ty_param_substs_and_ty { let result_ty_param_substs: [ty::t] = []; for var_id: int in ty_param_subst_var_ids { @@ -1006,7 +999,7 @@ mod demand { // Returns true if the two types unify and false if they don't. -fn are_compatible(fcx: &@fn_ctxt, expected: ty::t, actual: ty::t) -> bool { +fn are_compatible(fcx: @fn_ctxt, expected: ty::t, actual: ty::t) -> bool { alt unify::unify(fcx, expected, actual) { ures_ok(_) { ret true; } ures_err(_) { ret false; } @@ -1015,8 +1008,8 @@ fn are_compatible(fcx: &@fn_ctxt, expected: ty::t, actual: ty::t) -> bool { // Returns the types of the arguments to a tag variant. -fn variant_arg_types(ccx: &@crate_ctxt, _sp: &span, vid: &ast::def_id, - tag_ty_params: &[ty::t]) -> [ty::t] { +fn variant_arg_types(ccx: @crate_ctxt, _sp: span, vid: ast::def_id, + tag_ty_params: [ty::t]) -> [ty::t] { let result: [ty::t] = []; let tpt = ty::lookup_item_type(ccx.tcx, vid); alt ty::struct(ccx.tcx, tpt.ty) { @@ -1052,7 +1045,7 @@ mod writeback { export resolve_type_vars_in_block; export resolve_type_vars_in_expr; - fn resolve_type_vars_in_type(fcx: &@fn_ctxt, sp: &span, typ: ty::t) -> + fn resolve_type_vars_in_type(fcx: @fn_ctxt, sp: span, typ: ty::t) -> option::t<ty::t> { if !ty::type_contains_vars(fcx.ccx.tcx, typ) { ret some(typ); } alt ty::unify::fixup_vars(fcx.ccx.tcx, some(sp), fcx.var_bindings, @@ -1066,8 +1059,7 @@ mod writeback { } } } - fn resolve_type_vars_for_node(wbcx: &wb_ctxt, sp: &span, - id: ast::node_id) { + fn resolve_type_vars_for_node(wbcx: wb_ctxt, sp: span, id: ast::node_id) { let fcx = wbcx.fcx; let tpot = ty::node_id_to_ty_param_substs_opt_and_ty(fcx.ccx.tcx, id); let new_ty = @@ -1098,12 +1090,12 @@ mod writeback { {fcx: @fn_ctxt, mutable success: bool}; type wb_vt = visit::vt<wb_ctxt>; - fn visit_stmt(s: &@ast::stmt, wbcx: &wb_ctxt, v: &wb_vt) { + fn visit_stmt(s: @ast::stmt, wbcx: wb_ctxt, v: wb_vt) { if !wbcx.success { ret; } resolve_type_vars_for_node(wbcx, s.span, ty::stmt_node_id(s)); visit::visit_stmt(s, wbcx, v); } - fn visit_expr(e: &@ast::expr, wbcx: &wb_ctxt, v: &wb_vt) { + fn visit_expr(e: @ast::expr, wbcx: wb_ctxt, v: wb_vt) { if !wbcx.success { ret; } resolve_type_vars_for_node(wbcx, e.span, e.id); alt e.node { @@ -1116,17 +1108,17 @@ mod writeback { } visit::visit_expr(e, wbcx, v); } - fn visit_block(b: &ast::blk, wbcx: &wb_ctxt, v: &wb_vt) { + fn visit_block(b: ast::blk, wbcx: wb_ctxt, v: wb_vt) { if !wbcx.success { ret; } resolve_type_vars_for_node(wbcx, b.span, b.node.id); visit::visit_block(b, wbcx, v); } - fn visit_pat(p: &@ast::pat, wbcx: &wb_ctxt, v: &wb_vt) { + fn visit_pat(p: @ast::pat, wbcx: wb_ctxt, v: wb_vt) { if !wbcx.success { ret; } resolve_type_vars_for_node(wbcx, p.span, p.id); visit::visit_pat(p, wbcx, v); } - fn visit_local(l: &@ast::local, wbcx: &wb_ctxt, v: &wb_vt) { + fn visit_local(l: @ast::local, wbcx: wb_ctxt, v: wb_vt) { if !wbcx.success { ret; } let var_id = lookup_local(wbcx.fcx, l.span, l.node.id); let fix_rslt = @@ -1143,11 +1135,11 @@ mod writeback { } visit::visit_local(l, wbcx, v); } - fn visit_item(_item: &@ast::item, _wbcx: &wb_ctxt, _v: &wb_vt) { + fn visit_item(_item: @ast::item, _wbcx: wb_ctxt, _v: wb_vt) { // Ignore items } - fn resolve_type_vars_in_expr(fcx: &@fn_ctxt, e: &@ast::expr) -> bool { + fn resolve_type_vars_in_expr(fcx: @fn_ctxt, e: @ast::expr) -> bool { let wbcx = {fcx: fcx, mutable success: true}; let visit = visit::mk_vt(@{visit_item: visit_item, @@ -1161,7 +1153,7 @@ mod writeback { ret wbcx.success; } - fn resolve_type_vars_in_block(fcx: &@fn_ctxt, blk: &ast::blk) -> bool { + fn resolve_type_vars_in_block(fcx: @fn_ctxt, blk: ast::blk) -> bool { let wbcx = {fcx: fcx, mutable success: true}; let visit = visit::mk_vt(@{visit_item: visit_item, @@ -1186,8 +1178,8 @@ type gather_result = next_var_id: @mutable int}; // Used only as a helper for check_fn. -fn gather_locals(ccx: &@crate_ctxt, f: &ast::_fn, id: &ast::node_id, - old_fcx: &option::t<@fn_ctxt>) -> gather_result { +fn gather_locals(ccx: @crate_ctxt, f: ast::_fn, id: ast::node_id, + old_fcx: option::t<@fn_ctxt>) -> gather_result { let {vb: vb, locals: locals, local_names: local_names, nvi: nvi} = alt old_fcx { none. { @@ -1207,7 +1199,7 @@ fn gather_locals(ccx: &@crate_ctxt, f: &ast::_fn, id: &ast::node_id, let next_var_id = lambda () -> int { let rv = *nvi; *nvi += 1; ret rv; }; let assign = - lambda (nid: ast::node_id, ident: &ast::ident, + lambda (nid: ast::node_id, ident: ast::ident, ty_opt: option::t<ty::t>) { let var_id = next_var_id(); locals.insert(nid, var_id); @@ -1246,7 +1238,7 @@ fn gather_locals(ccx: &@crate_ctxt, f: &ast::_fn, id: &ast::node_id, // Add explicitly-declared locals. let visit_local = - lambda (local: &@ast::local, e: &(), v: &visit::vt<()>) { + lambda (local: @ast::local, e: (), v: visit::vt<()>) { let local_ty = ast_ty_to_ty_crate_infer(ccx, local.node.ty); assign(local.node.id, ident_for_local(local), local_ty); visit::visit_local(local, e, v); @@ -1254,7 +1246,7 @@ fn gather_locals(ccx: &@crate_ctxt, f: &ast::_fn, id: &ast::node_id, // Add pattern bindings. let visit_pat = - lambda (p: &@ast::pat, e: &(), v: &visit::vt<()>) { + lambda (p: @ast::pat, e: (), v: visit::vt<()>) { alt p.node { ast::pat_bind(ident) { assign(p.id, ident, none); } _ {/* no-op */ } @@ -1263,11 +1255,11 @@ fn gather_locals(ccx: &@crate_ctxt, f: &ast::_fn, id: &ast::node_id, }; // Don't descend into fns and items - fn visit_fn<E>(_f: &ast::_fn, _tp: &[ast::ty_param], _sp: &span, - _i: &ast::fn_ident, _id: ast::node_id, _e: &E, - _v: &visit::vt<E>) { + fn visit_fn<E>(_f: ast::_fn, _tp: [ast::ty_param], _sp: span, + _i: ast::fn_ident, _id: ast::node_id, _e: E, + _v: visit::vt<E>) { } - fn visit_item<E>(_i: &@ast::item, _e: &E, _v: &visit::vt<E>) { } + fn visit_item<E>(_i: @ast::item, _e: E, _v: visit::vt<E>) { } let visit = @{visit_local: visit_local, @@ -1282,7 +1274,7 @@ fn gather_locals(ccx: &@crate_ctxt, f: &ast::_fn, id: &ast::node_id, } // AST fragment checking -fn check_lit(ccx: @crate_ctxt, lit: &@ast::lit) -> ty::t { +fn check_lit(ccx: @crate_ctxt, lit: @ast::lit) -> ty::t { alt lit.node { ast::lit_str(_) { ret ty::mk_str(ccx.tcx); } ast::lit_char(_) { ret ty::mk_char(ccx.tcx); } @@ -1298,7 +1290,7 @@ fn check_lit(ccx: @crate_ctxt, lit: &@ast::lit) -> ty::t { // Pattern checking is top-down rather than bottom-up so that bindings get // their types immediately. -fn check_pat(fcx: &@fn_ctxt, map: &ast_util::pat_id_map, pat: &@ast::pat, +fn check_pat(fcx: @fn_ctxt, map: ast_util::pat_id_map, pat: @ast::pat, expected: ty::t) { alt pat.node { ast::pat_wild. { write::ty_only_fixup(fcx, pat.id, expected); } @@ -1372,9 +1364,8 @@ fn check_pat(fcx: &@fn_ctxt, map: &ast_util::pat_id_map, pat: &@ast::pat, } } else if subpats_len > 0u { // TODO: note definition of tag variant - fcx.ccx.tcx.sess.span_fatal( - pat.span, - #fmt["this pattern has %u field%s, \ + fcx.ccx.tcx.sess.span_fatal(pat.span, + #fmt["this pattern has %u field%s, \ but the corresponding \ variant has no fields", subpats_len, @@ -1387,11 +1378,10 @@ fn check_pat(fcx: &@fn_ctxt, map: &ast_util::pat_id_map, pat: &@ast::pat, _ { // FIXME: Switch expected and actual in this message? I // can never tell. - fcx.ccx.tcx.sess.span_fatal( - pat.span, - #fmt["mismatched types: expected %s, found tag", - ty_to_str(fcx.ccx.tcx, - expected)]); + fcx.ccx.tcx.sess.span_fatal(pat.span, + #fmt["mismatched types: expected %s, found tag", + ty_to_str(fcx.ccx.tcx, + expected)]); } } write::ty_fixup(fcx, pat.id, path_tpot); @@ -1401,9 +1391,8 @@ fn check_pat(fcx: &@fn_ctxt, map: &ast_util::pat_id_map, pat: &@ast::pat, alt structure_of(fcx, pat.span, expected) { ty::ty_rec(fields) { ex_fields = fields; } _ { - fcx.ccx.tcx.sess.span_fatal( - pat.span, - #fmt["mismatched types: expected %s, found record", + fcx.ccx.tcx.sess.span_fatal(pat.span, + #fmt["mismatched types: expected %s, found record", ty_to_str(fcx.ccx.tcx, expected)]); } @@ -1411,14 +1400,13 @@ fn check_pat(fcx: &@fn_ctxt, map: &ast_util::pat_id_map, pat: &@ast::pat, let f_count = vec::len(fields); let ex_f_count = vec::len(ex_fields); if ex_f_count < f_count || !etc && ex_f_count > f_count { - fcx.ccx.tcx.sess.span_fatal( - pat.span, - #fmt["mismatched types: expected a record \ + fcx.ccx.tcx.sess.span_fatal(pat.span, + #fmt["mismatched types: expected a record \ with %u fields, found one with %u \ fields", ex_f_count, f_count]); } - fn matches(name: &str, f: &ty::field) -> bool { + fn matches(name: str, f: ty::field) -> bool { ret str::eq(name, f.ident); } for f: ast::field_pat in fields { @@ -1439,8 +1427,7 @@ fn check_pat(fcx: &@fn_ctxt, map: &ast_util::pat_id_map, pat: &@ast::pat, alt structure_of(fcx, pat.span, expected) { ty::ty_tup(elts) { ex_elts = elts; } _ { - fcx.ccx.tcx.sess.span_fatal( - pat.span, + fcx.ccx.tcx.sess.span_fatal(pat.span, #fmt["mismatched types: expected %s, found tuple", ty_to_str(fcx.ccx.tcx, expected)]); @@ -1448,9 +1435,8 @@ fn check_pat(fcx: &@fn_ctxt, map: &ast_util::pat_id_map, pat: &@ast::pat, } let e_count = vec::len(elts); if e_count != vec::len(ex_elts) { - fcx.ccx.tcx.sess.span_fatal( - pat.span, - #fmt["mismatched types: expected a tuple \ + fcx.ccx.tcx.sess.span_fatal(pat.span, + #fmt["mismatched types: expected a tuple \ with %u fields, found one with %u \ fields", vec::len(ex_elts), e_count]); @@ -1476,8 +1462,7 @@ fn check_pat(fcx: &@fn_ctxt, map: &ast_util::pat_id_map, pat: &@ast::pat, } } -fn require_impure(sess: &session::session, f_purity: &ast::purity, - sp: &span) { +fn require_impure(sess: session::session, f_purity: ast::purity, sp: span) { alt f_purity { ast::impure_fn. { ret; } ast::pure_fn. { @@ -1486,46 +1471,44 @@ fn require_impure(sess: &session::session, f_purity: &ast::purity, } } -fn require_pure_call(ccx: @crate_ctxt, caller_purity: &ast::purity, - callee: &@ast::expr, sp: &span) { +fn require_pure_call(ccx: @crate_ctxt, caller_purity: ast::purity, + callee: @ast::expr, sp: span) { alt caller_purity { ast::impure_fn. { ret; } ast::pure_fn. { alt ccx.tcx.def_map.find(callee.id) { some(ast::def_fn(_, ast::pure_fn.)) { ret; } _ { - ccx.tcx.sess.span_fatal( - sp, - "Pure function calls function not known to be pure"); + ccx.tcx.sess.span_fatal(sp, + "Pure function calls function not known to be pure"); } } } } } -type unifier = fn(&@fn_ctxt, &span, ty::t, ty::t) -> ty::t; +type unifier = fn(@fn_ctxt, span, ty::t, ty::t) -> ty::t; -fn check_expr(fcx: &@fn_ctxt, expr: &@ast::expr) -> bool { - fn dummy_unify(_fcx: &@fn_ctxt, _sp: &span, _expected: ty::t, - actual: ty::t) -> ty::t { +fn check_expr(fcx: @fn_ctxt, expr: @ast::expr) -> bool { + fn dummy_unify(_fcx: @fn_ctxt, _sp: span, _expected: ty::t, actual: ty::t) + -> ty::t { actual } ret check_expr_with_unifier(fcx, expr, dummy_unify, 0u); } -fn check_expr_with(fcx: &@fn_ctxt, expr: &@ast::expr, expected: ty::t) -> - bool { +fn check_expr_with(fcx: @fn_ctxt, expr: @ast::expr, expected: ty::t) -> bool { ret check_expr_with_unifier(fcx, expr, demand::simple, expected); } -fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier, +fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier, expected: ty::t) -> bool { //log_err "typechecking expr " + syntax::print::pprust::expr_to_str(expr); // A generic function to factor out common logic from call and bind // expressions. - fn check_call_or_bind(fcx: &@fn_ctxt, sp: &span, f: &@ast::expr, - args: &[option::t<@ast::expr>], - call_kind: call_kind) -> bool { + fn check_call_or_bind(fcx: @fn_ctxt, sp: span, f: @ast::expr, + args: [option::t<@ast::expr>], call_kind: call_kind) + -> bool { // Check the function. let bot = check_expr(fcx, f); @@ -1545,16 +1528,14 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier, alt sty { ty::ty_fn(ast::proto_iter., _, _, _, _) { if call_kind != kind_for_each { - fcx.ccx.tcx.sess.span_err( - sp, - "calling iter outside of for each loop"); + fcx.ccx.tcx.sess.span_err(sp, + "calling iter outside of for each loop"); } } _ { if call_kind == kind_for_each { - fcx.ccx.tcx.sess.span_err( - sp, - "calling non-iter as sequence of for each loop"); + fcx.ccx.tcx.sess.span_err(sp, + "calling non-iter as sequence of for each loop"); } } } @@ -1633,8 +1614,8 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier, } // A generic function for checking assignment expressions - fn check_assignment(fcx: &@fn_ctxt, _sp: &span, lhs: &@ast::expr, - rhs: &@ast::expr, id: &ast::node_id) -> bool { + fn check_assignment(fcx: @fn_ctxt, _sp: span, lhs: @ast::expr, + rhs: @ast::expr, id: ast::node_id) -> bool { let t = next_ty_var(fcx); let bot = check_expr_with(fcx, lhs, t) | check_expr_with(fcx, rhs, t); write::ty_only_fixup(fcx, id, ty::mk_nil(fcx.ccx.tcx)); @@ -1642,8 +1623,8 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier, } // A generic function for checking call expressions - fn check_call(fcx: &@fn_ctxt, sp: &span, f: &@ast::expr, - args: &[@ast::expr], call_kind: call_kind) -> bool { + fn check_call(fcx: @fn_ctxt, sp: span, f: @ast::expr, args: [@ast::expr], + call_kind: call_kind) -> bool { let args_opt_0: [option::t<@ast::expr>] = []; for arg: @ast::expr in args { args_opt_0 += [some::<@ast::expr>(arg)]; @@ -1654,8 +1635,8 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier, } // A generic function for doing all of the checking for call expressions - fn check_call_full(fcx: &@fn_ctxt, sp: &span, f: &@ast::expr, - args: &[@ast::expr], call_kind: call_kind, + fn check_call_full(fcx: @fn_ctxt, sp: span, f: @ast::expr, + args: [@ast::expr], call_kind: call_kind, id: ast::node_id) -> bool { /* here we're kind of hosed, as f can be any expr need to restrict it to being an explicit expr_path if we're @@ -1680,8 +1661,8 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier, } // A generic function for checking for or for-each loops - fn check_for_or_for_each(fcx: &@fn_ctxt, local: &@ast::local, - element_ty: ty::t, body: &ast::blk, + fn check_for_or_for_each(fcx: @fn_ctxt, local: @ast::local, + element_ty: ty::t, body: ast::blk, node_id: ast::node_id) -> bool { let locid = lookup_local(fcx, local.span, local.node.id); element_ty = @@ -1700,9 +1681,9 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier, // A generic function for checking the then and else in an if // or if-check - fn check_then_else(fcx: &@fn_ctxt, thn: &ast::blk, - elsopt: &option::t<@ast::expr>, id: ast::node_id, - _sp: &span) -> bool { + fn check_then_else(fcx: @fn_ctxt, thn: ast::blk, + elsopt: option::t<@ast::expr>, id: ast::node_id, + _sp: span) -> bool { let then_bot = check_block(fcx, thn); let els_bot = false; let if_t = @@ -1722,7 +1703,7 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier, } // Checks the compatibility - fn check_binop_type_compat(fcx: &@fn_ctxt, span: span, ty: ty::t, + fn check_binop_type_compat(fcx: @fn_ctxt, span: span, ty: ty::t, binop: ast::binop) { let resolved_t = resolve_type_vars_if_possible(fcx, ty); if !ty::is_binopable(fcx.ccx.tcx, resolved_t, binop) { @@ -1777,11 +1758,10 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier, let variants = ty::tag_variants(tcx, id); if vec::len(variants) != 1u || vec::len(variants[0].args) != 1u { - tcx.sess.span_fatal( - expr.span, - "can only dereference tags " + - "with a single variant which has a " - + "single argument"); + tcx.sess.span_fatal(expr.span, + "can only dereference tags " + + "with a single variant which has a " + + "single argument"); } oper_t = ty::substitute_type_params(tcx, tps, variants[0].args[0]); @@ -1940,10 +1920,9 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier, ty::ty_vec(vec_elt_ty) { elt_ty = vec_elt_ty.ty; } ty::ty_str. { elt_ty = ty::mk_mach(tcx, ast::ty_u8); } _ { - tcx.sess.span_fatal( - expr.span, - "mismatched types: expected vector or string but " - + "found " + ty_to_str(tcx, ety)); + tcx.sess.span_fatal(expr.span, + "mismatched types: expected vector or string but " + + "found " + ty_to_str(tcx, ety)); } } bot |= check_for_or_for_each(fcx, decl, elt_ty, body, id); @@ -2003,7 +1982,7 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier, let cx = @{tcx: tcx}; let convert = bind ast_ty_to_ty_crate_tyvar(fcx, _); let ty_of_arg = - lambda (a: &ast::arg) -> ty::arg { + lambda (a: ast::arg) -> ty::arg { let tt = ast_ty_to_ty_crate_tyvar(fcx, a.ty); ret {mode: a.mode, ty: tt}; }; @@ -2042,6 +2021,7 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier, // Pull the argument and return types out. let proto, arg_tys, rt, cf, constrs; alt structure_of(fcx, expr.span, expr_ty(tcx, f)) { + // FIXME: // probably need to munge the constrs to drop constraints // for any bound args @@ -2060,7 +2040,7 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier, constrs = []; } _ { fail "LHS of bind expr didn't have a function type?!"; } - }; + } // For each blank argument, add the type of that argument // to the resulting function type. @@ -2179,7 +2159,7 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier, } alt base { none. { - fn get_node(f: &spanned<field>) -> field { f.node } + fn get_node(f: spanned<field>) -> field { f.node } let typ = ty::mk_rec(tcx, vec::map(get_node, fields_t)); write::ty_only_fixup(fcx, id, typ); } @@ -2276,11 +2256,11 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier, // FIXME: These next three functions are largely ripped off from // similar ones in collect::. Is there a better way to do this? - fn ty_of_arg(ccx: @crate_ctxt, a: &ast::arg) -> ty::arg { + fn ty_of_arg(ccx: @crate_ctxt, a: ast::arg) -> ty::arg { ret {mode: a.mode, ty: ast_ty_to_ty_crate(ccx, a.ty)}; } - fn ty_of_method(ccx: @crate_ctxt, m: &@ast::method) -> ty::method { + fn ty_of_method(ccx: @crate_ctxt, m: @ast::method) -> ty::method { let convert = bind ast_ty_to_ty_crate(ccx, _); let inputs = []; @@ -2333,11 +2313,9 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier, ty::ty_obj(ms) { inner_obj_methods = ms; } _ { // The user is trying to extend a non-object. - tcx.sess.span_fatal( - e.span, - syntax::print::pprust::expr_to_str(e) - + - " does not have object type"); + tcx.sess.span_fatal(e.span, + syntax::print::pprust::expr_to_str(e) + + " does not have object type"); } } } @@ -2352,7 +2330,7 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier, // Whenever an outer method overrides an inner, we need to remove // that inner from the type. Filter inner_obj_methods to remove // any methods that share a name with an outer method. - fn filtering_fn(ccx: @crate_ctxt, m: &ty::method, + fn filtering_fn(ccx: @crate_ctxt, m: ty::method, outer_obj_methods: [@ast::method]) -> option::t<ty::method> { @@ -2362,11 +2340,10 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier, // type. Check to make sure. let new_type = ty_of_method(ccx, om); if new_type != m { - ccx.tcx.sess.span_fatal( - om.span, - "Attempted to override method " - + m.ident + - " with one of a different type"); + ccx.tcx.sess.span_fatal(om.span, + "Attempted to override method " + + m.ident + + " with one of a different type"); } ret none; } @@ -2422,21 +2399,21 @@ fn next_ty_var_id(fcx: @fn_ctxt) -> int { ret id; } -fn next_ty_var(fcx: &@fn_ctxt) -> ty::t { +fn next_ty_var(fcx: @fn_ctxt) -> ty::t { ret ty::mk_var(fcx.ccx.tcx, next_ty_var_id(fcx)); } -fn get_obj_info(ccx: &@crate_ctxt) -> option::t<obj_info> { +fn get_obj_info(ccx: @crate_ctxt) -> option::t<obj_info> { ret vec::last::<obj_info>(ccx.obj_infos); } -fn check_decl_initializer(fcx: &@fn_ctxt, nid: ast::node_id, - init: &ast::initializer) -> bool { +fn check_decl_initializer(fcx: @fn_ctxt, nid: ast::node_id, + init: ast::initializer) -> bool { let lty = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, init.expr.span, nid)); ret check_expr_with(fcx, init.expr, lty); } -fn check_decl_local(fcx: &@fn_ctxt, local: &@ast::local) -> bool { +fn check_decl_local(fcx: @fn_ctxt, local: @ast::local) -> bool { let bot = false; alt fcx.locals.find(local.node.id) { @@ -2460,7 +2437,7 @@ fn check_decl_local(fcx: &@fn_ctxt, local: &@ast::local) -> bool { ret bot; } -fn check_stmt(fcx: &@fn_ctxt, stmt: &@ast::stmt) -> bool { +fn check_stmt(fcx: @fn_ctxt, stmt: @ast::stmt) -> bool { let node_id; let bot = false; alt stmt.node { @@ -2479,7 +2456,7 @@ fn check_stmt(fcx: &@fn_ctxt, stmt: &@ast::stmt) -> bool { ret bot; } -fn check_block(fcx: &@fn_ctxt, blk: &ast::blk) -> bool { +fn check_block(fcx: @fn_ctxt, blk: ast::blk) -> bool { let bot = false; let warned = false; for s: @ast::stmt in blk.node.stmts { @@ -2513,8 +2490,7 @@ fn check_block(fcx: &@fn_ctxt, blk: &ast::blk) -> bool { ret bot; } -fn check_const(ccx: &@crate_ctxt, _sp: &span, e: &@ast::expr, - id: &ast::node_id) { +fn check_const(ccx: @crate_ctxt, _sp: span, e: @ast::expr, id: ast::node_id) { // FIXME: this is kinda a kludge; we manufacture a fake function context // and statement context for checking the initializer expression. let rty = node_id_to_type(ccx.tcx, id); @@ -2534,7 +2510,7 @@ fn check_const(ccx: &@crate_ctxt, _sp: &span, e: &@ast::expr, // A generic function for checking the pred in a check // or if-check -fn check_pred_expr(fcx: &@fn_ctxt, e: &@ast::expr) -> bool { +fn check_pred_expr(fcx: @fn_ctxt, e: @ast::expr) -> bool { let bot = check_expr_with(fcx, e, ty::mk_bool(fcx.ccx.tcx)); /* e must be a call expr where all arguments are either @@ -2542,9 +2518,8 @@ fn check_pred_expr(fcx: &@fn_ctxt, e: &@ast::expr) -> bool { alt e.node { ast::expr_call(operator, operands) { if !ty::is_pred_ty(fcx.ccx.tcx, expr_ty(fcx.ccx.tcx, operator)) { - fcx.ccx.tcx.sess.span_fatal( - operator.span, - "Operator in constraint has non-boolean return type"); + fcx.ccx.tcx.sess.span_fatal(operator.span, + "Operator in constraint has non-boolean return type"); } alt operator.node { @@ -2581,7 +2556,7 @@ constraint name to be an explicit name"; ret bot; } -fn check_constraints(fcx: &@fn_ctxt, cs: [@ast::constr], args: [ast::arg]) { +fn check_constraints(fcx: @fn_ctxt, cs: [@ast::constr], args: [ast::arg]) { let c_args; let num_args = vec::len(args); for c: @ast::constr in cs { @@ -2617,10 +2592,9 @@ fn check_constraints(fcx: &@fn_ctxt, cs: [@ast::constr], args: [ast::arg]) { types: []}; let arg_occ_node_id = fcx.ccx.tcx.sess.next_node_id(); - fcx.ccx.tcx.def_map.insert( - arg_occ_node_id, - ast::def_arg(local_def(args[i].id), - args[i].mode)); + fcx.ccx.tcx.def_map.insert(arg_occ_node_id, + ast::def_arg(local_def(args[i].id), + args[i].mode)); {id: arg_occ_node_id, node: ast::expr_path(respan(a.span, p)), span: a.span} @@ -2644,8 +2618,8 @@ fn check_constraints(fcx: &@fn_ctxt, cs: [@ast::constr], args: [ast::arg]) { } } -fn check_fn(ccx: &@crate_ctxt, f: &ast::_fn, id: &ast::node_id, - old_fcx: &option::t<@fn_ctxt>) { +fn check_fn(ccx: @crate_ctxt, f: ast::_fn, id: ast::node_id, + old_fcx: option::t<@fn_ctxt>) { let decl = f.decl; let body = f.body; let gather_result = gather_locals(ccx, f, id, old_fcx); @@ -2694,11 +2668,11 @@ fn check_fn(ccx: &@crate_ctxt, f: &ast::_fn, id: &ast::node_id, } } -fn check_method(ccx: &@crate_ctxt, method: &@ast::method) { +fn check_method(ccx: @crate_ctxt, method: @ast::method) { check_fn(ccx, method.node.meth, method.node.id, none); } -fn check_item(ccx: @crate_ctxt, it: &@ast::item) { +fn check_item(ccx: @crate_ctxt, it: @ast::item) { alt it.node { ast::item_const(_, e) { check_const(ccx, it.span, e, it.id); } ast::item_fn(f, _) { check_fn(ccx, f, it.id, none); } @@ -2717,7 +2691,7 @@ fn check_item(ccx: @crate_ctxt, it: &@ast::item) { } } -fn arg_is_argv_ty(tcx: &ty::ctxt, a: &ty::arg) -> bool { +fn arg_is_argv_ty(tcx: ty::ctxt, a: ty::arg) -> bool { alt ty::struct(tcx, a.ty) { ty::ty_vec(mt) { if mt.mut != ast::imm { ret false; } @@ -2730,7 +2704,7 @@ fn arg_is_argv_ty(tcx: &ty::ctxt, a: &ty::arg) -> bool { } } -fn check_main_fn_ty(tcx: &ty::ctxt, main_id: &ast::node_id) { +fn check_main_fn_ty(tcx: ty::ctxt, main_id: ast::node_id) { let main_t = ty::node_id_to_monotype(tcx, main_id); alt ty::struct(tcx, main_t) { ty::ty_fn(ast::proto_fn., args, rs, ast::return., constrs) { @@ -2755,7 +2729,7 @@ fn check_main_fn_ty(tcx: &ty::ctxt, main_id: &ast::node_id) { } } -fn check_for_main_fn(tcx: &ty::ctxt, crate: &@ast::crate) { +fn check_for_main_fn(tcx: ty::ctxt, crate: @ast::crate) { if !tcx.sess.get_opts().library { alt tcx.sess.get_main_id() { some(id) { check_main_fn_ty(tcx, id); } @@ -2764,7 +2738,7 @@ fn check_for_main_fn(tcx: &ty::ctxt, crate: &@ast::crate) { } } -fn check_crate(tcx: &ty::ctxt, crate: &@ast::crate) { +fn check_crate(tcx: ty::ctxt, crate: @ast::crate) { collect::collect_item_types(tcx, crate); let obj_infos: [obj_info] = []; diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index 67d0f6022f7..7ab627ec2b9 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -293,10 +293,11 @@ tag ty_ { for this type. */ + /* bot represents the value of functions that don't return a value locally to their context. in contrast, things like log that do return, but don't return a meaningful value, have result type nil. */ - ty_bool; + ty_bool; ty_int; ty_uint; ty_float; @@ -381,6 +382,7 @@ tag controlflow { // raise an error or exit (i.e. never return to the caller) + return; // everything else } diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs index c5d769c1299..eaf6728838b 100644 --- a/src/comp/syntax/ast_util.rs +++ b/src/comp/syntax/ast_util.rs @@ -3,7 +3,7 @@ import std::option; import codemap::span; import ast::*; -fn respan<@T>(sp: &span, t: &T) -> spanned<T> { ret {node: t, span: sp}; } +fn respan<@T>(sp: span, t: T) -> spanned<T> { ret {node: t, span: sp}; } /* assuming that we're not in macro expansion */ fn mk_sp(lo: uint, hi: uint) -> span { @@ -13,13 +13,13 @@ fn mk_sp(lo: uint, hi: uint) -> span { // make this a const, once the compiler supports it fn dummy_sp() -> span { ret mk_sp(0u, 0u); } -fn path_name(p: &path) -> str { path_name_i(p.node.idents) } +fn path_name(p: path) -> str { path_name_i(p.node.idents) } -fn path_name_i(idents: &[ident]) -> str { str::connect(idents, "::") } +fn path_name_i(idents: [ident]) -> str { str::connect(idents, "::") } fn local_def(id: node_id) -> def_id { ret {crate: local_crate, node: id}; } -fn variant_def_ids(d: &def) -> {tg: def_id, var: def_id} { +fn variant_def_ids(d: def) -> {tg: def_id, var: def_id} { alt d { def_variant(tag_id, var_id) { ret {tg: tag_id, var: var_id}; } } } @@ -47,7 +47,7 @@ type pat_id_map = std::map::hashmap<str, node_id>; // This is used because same-named variables in alternative patterns need to // use the node_id of their namesake in the first pattern. -fn pat_id_map(pat: &@pat) -> pat_id_map { +fn pat_id_map(pat: @pat) -> pat_id_map { let map = std::map::new_str_hash::<node_id>(); for each bound in pat_bindings(pat) { let name = alt bound.node { pat_bind(n) { n } }; @@ -57,7 +57,7 @@ fn pat_id_map(pat: &@pat) -> pat_id_map { } // FIXME: could return a constrained type -iter pat_bindings(pat: &@pat) -> @pat { +iter pat_bindings(pat: @pat) -> @pat { alt pat.node { pat_bind(_) { put pat; } pat_tag(_, sub) { @@ -74,7 +74,7 @@ iter pat_bindings(pat: &@pat) -> @pat { } } -fn pat_binding_ids(pat: &@pat) -> [node_id] { +fn pat_binding_ids(pat: @pat) -> [node_id] { let found = []; for each b in pat_bindings(pat) { found += [b.id]; } ret found; @@ -117,7 +117,7 @@ fn unop_to_str(op: unop) -> str { } } -fn is_path(e: &@expr) -> bool { +fn is_path(e: @expr) -> bool { ret alt e.node { expr_path(_) { true } _ { false } }; } @@ -179,9 +179,9 @@ fn is_constraint_arg(e: @expr) -> bool { } } -fn eq_ty(a: &@ty, b: &@ty) -> bool { ret std::box::ptr_eq(a, b); } +fn eq_ty(a: @ty, b: @ty) -> bool { ret std::box::ptr_eq(a, b); } -fn hash_ty(t: &@ty) -> uint { ret t.span.lo << 16u + t.span.hi; } +fn hash_ty(t: @ty) -> uint { ret t.span.lo << 16u + t.span.hi; } fn block_from_expr(e: @expr) -> blk { let blk_ = checked_blk([], option::some::<@expr>(e), e.id); @@ -193,13 +193,13 @@ fn checked_blk(stmts1: [@stmt], expr1: option::t<@expr>, id1: node_id) -> ret {stmts: stmts1, expr: expr1, id: id1, rules: checked}; } -fn obj_field_from_anon_obj_field(f: &anon_obj_field) -> obj_field { +fn obj_field_from_anon_obj_field(f: anon_obj_field) -> obj_field { ret {mut: f.mut, ty: f.ty, ident: f.ident, id: f.id}; } // This is a convenience function to transfor ternary expressions to if // expressions so that they can be treated the same -fn ternary_to_if(e: &@expr) -> @expr { +fn ternary_to_if(e: @expr) -> @expr { alt e.node { expr_ternary(cond, then, els) { let then_blk = block_from_expr(then); diff --git a/src/comp/syntax/codemap.rs b/src/comp/syntax/codemap.rs index edb414b4e9b..b0f3bde73d9 100644 --- a/src/comp/syntax/codemap.rs +++ b/src/comp/syntax/codemap.rs @@ -73,7 +73,7 @@ tag opt_span { } type span = {lo: uint, hi: uint, expanded_from: opt_span}; -fn span_to_str(sp: &span, cm: &codemap) -> str { +fn span_to_str(sp: span, cm: codemap) -> str { let cur = sp; let res = ""; let prev_file = none; @@ -98,8 +98,8 @@ fn span_to_str(sp: &span, cm: &codemap) -> str { ret res; } -fn emit_diagnostic(sp: &option::t<span>, msg: &str, kind: &str, color: u8, - cm: &codemap) { +fn emit_diagnostic(sp: option::t<span>, msg: str, kind: str, color: u8, + cm: codemap) { let ss = ""; let maybe_lines: option::t<@file_lines> = none; alt sp { @@ -120,7 +120,7 @@ fn emit_diagnostic(sp: &option::t<span>, msg: &str, kind: &str, color: u8, maybe_highlight_lines(sp, cm, maybe_lines); } -fn maybe_highlight_lines(sp: &option::t<span>, cm: &codemap, +fn maybe_highlight_lines(sp: option::t<span>, cm: codemap, maybe_lines: option::t<@file_lines>) { alt maybe_lines { @@ -188,13 +188,13 @@ fn maybe_highlight_lines(sp: &option::t<span>, cm: &codemap, } } -fn emit_warning(sp: &option::t<span>, msg: &str, cm: &codemap) { +fn emit_warning(sp: option::t<span>, msg: str, cm: codemap) { emit_diagnostic(sp, msg, "warning", 11u8, cm); } -fn emit_error(sp: &option::t<span>, msg: &str, cm: &codemap) { +fn emit_error(sp: option::t<span>, msg: str, cm: codemap) { emit_diagnostic(sp, msg, "error", 9u8, cm); } -fn emit_note(sp: &option::t<span>, msg: &str, cm: &codemap) { +fn emit_note(sp: option::t<span>, msg: str, cm: codemap) { emit_diagnostic(sp, msg, "note", 10u8, cm); } @@ -210,7 +210,7 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines { ret @{name: lo.filename, lines: lines}; } -fn get_line(fm: filemap, line: int, file: &str) -> str { +fn get_line(fm: filemap, line: int, file: str) -> str { let begin: uint = fm.lines[line].byte - fm.start_pos.byte; let end: uint; if line as uint < vec::len(fm.lines) - 1u { diff --git a/src/comp/syntax/ext/base.rs b/src/comp/syntax/ext/base.rs index 298f90237bc..a77376edd6e 100644 --- a/src/comp/syntax/ext/base.rs +++ b/src/comp/syntax/ext/base.rs @@ -8,10 +8,10 @@ import std::map::new_str_hash; import codemap; type syntax_expander = - fn(&ext_ctxt, span, @ast::expr, &option::t<str>) -> @ast::expr; + fn(ext_ctxt, span, @ast::expr, option::t<str>) -> @ast::expr; type macro_def = {ident: str, ext: syntax_extension}; type macro_definer = - fn(&ext_ctxt, span, @ast::expr, &option::t<str>) -> macro_def; + fn(ext_ctxt, span, @ast::expr, option::t<str>) -> macro_def; tag syntax_extension { normal(syntax_expander); @@ -83,7 +83,7 @@ obj ext_ctxt(sess: @session, } -fn mk_ctxt(sess: &session) -> ext_ctxt { +fn mk_ctxt(sess: session) -> ext_ctxt { // FIXME: Some extensions work by building ASTs with paths to functions // they need to call at runtime. As those functions live in the std crate, // the paths are prefixed with "std::". Unfortunately, these paths can't @@ -96,7 +96,7 @@ fn mk_ctxt(sess: &session) -> ext_ctxt { ret ext_ctxt(@sess, crate_file_name_hack, codemap::os_none); } -fn expr_to_str(cx: &ext_ctxt, expr: @ast::expr, error: &str) -> str { +fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, error: str) -> str { alt expr.node { ast::expr_lit(l) { alt l.node { @@ -108,7 +108,7 @@ fn expr_to_str(cx: &ext_ctxt, expr: @ast::expr, error: &str) -> str { } } -fn expr_to_ident(cx: &ext_ctxt, expr: @ast::expr, error: &str) -> ast::ident { +fn expr_to_ident(cx: ext_ctxt, expr: @ast::expr, error: str) -> ast::ident { alt expr.node { ast::expr_path(p) { if vec::len(p.node.types) > 0u || vec::len(p.node.idents) != 1u { @@ -119,7 +119,7 @@ fn expr_to_ident(cx: &ext_ctxt, expr: @ast::expr, error: &str) -> ast::ident { } } -fn make_new_lit(cx: &ext_ctxt, sp: codemap::span, lit: ast::lit_) -> +fn make_new_lit(cx: ext_ctxt, sp: codemap::span, lit: ast::lit_) -> @ast::expr { let sp_lit = @{node: lit, span: sp}; ret @{id: cx.next_id(), node: ast::expr_lit(sp_lit), span: sp}; diff --git a/src/comp/syntax/ext/concat_idents.rs b/src/comp/syntax/ext/concat_idents.rs index 53ee6cb0397..b2f019f233d 100644 --- a/src/comp/syntax/ext/concat_idents.rs +++ b/src/comp/syntax/ext/concat_idents.rs @@ -2,8 +2,8 @@ import std::option; import base::*; import syntax::ast; -fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: &option::t<str>) -> @ast::expr { +fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr, + _body: option::t<str>) -> @ast::expr { let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } diff --git a/src/comp/syntax/ext/env.rs b/src/comp/syntax/ext/env.rs index 081bfd80c1d..2889487a6ae 100644 --- a/src/comp/syntax/ext/env.rs +++ b/src/comp/syntax/ext/env.rs @@ -11,8 +11,8 @@ import std::generic_os; import base::*; export expand_syntax_ext; -fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: &option::t<str>) -> @ast::expr { +fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr, + _body: option::t<str>) -> @ast::expr { let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } @@ -33,7 +33,7 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, } } -fn make_new_str(cx: &ext_ctxt, sp: codemap::span, s: &str) -> @ast::expr { +fn make_new_str(cx: ext_ctxt, sp: codemap::span, s: str) -> @ast::expr { ret make_new_lit(cx, sp, ast::lit_str(s)); } // diff --git a/src/comp/syntax/ext/expand.rs b/src/comp/syntax/ext/expand.rs index 7037139bd93..05128fdd62b 100644 --- a/src/comp/syntax/ext/expand.rs +++ b/src/comp/syntax/ext/expand.rs @@ -15,9 +15,8 @@ import syntax::fold::*; import syntax::ext::base::*; -fn expand_expr(exts: &hashmap<str, syntax_extension>, cx: &ext_ctxt, - e: &expr_, fld: ast_fold, orig: &fn(&expr_, ast_fold) -> expr_) - -> expr_ { +fn expand_expr(exts: hashmap<str, syntax_extension>, cx: ext_ctxt, e: expr_, + fld: ast_fold, orig: fn(expr_, ast_fold) -> expr_) -> expr_ { ret alt e { expr_mac(mac) { alt mac.node { @@ -53,7 +52,7 @@ fn expand_expr(exts: &hashmap<str, syntax_extension>, cx: &ext_ctxt, }; } -fn expand_crate(sess: &session::session, c: &@crate) -> @crate { +fn expand_crate(sess: session::session, c: @crate) -> @crate { let exts = syntax_expander_table(); let afp = default_ast_fold(); let cx: ext_ctxt = mk_ctxt(sess); diff --git a/src/comp/syntax/ext/fmt.rs b/src/comp/syntax/ext/fmt.rs index aef3cc46902..43a2cd03ec3 100644 --- a/src/comp/syntax/ext/fmt.rs +++ b/src/comp/syntax/ext/fmt.rs @@ -15,8 +15,8 @@ import base::*; import codemap::span; export expand_syntax_ext; -fn expand_syntax_ext(cx: &ext_ctxt, sp: span, arg: @ast::expr, - _body: &option::t<str>) -> @ast::expr { +fn expand_syntax_ext(cx: ext_ctxt, sp: span, arg: @ast::expr, + _body: option::t<str>) -> @ast::expr { let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } @@ -33,7 +33,7 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: span, arg: @ast::expr, let fmtspan = args[0].span; log "Format string:"; log fmt; - fn parse_fmt_err_(cx: &ext_ctxt, sp: span, msg: &str) -> ! { + fn parse_fmt_err_(cx: ext_ctxt, sp: span, msg: str) -> ! { cx.span_fatal(sp, msg); } let parse_fmt_err = bind parse_fmt_err_(cx, fmtspan, _); @@ -44,49 +44,49 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: span, arg: @ast::expr, // FIXME: A lot of these functions for producing expressions can probably // be factored out in common with other code that builds expressions. // FIXME: Cleanup the naming of these functions -fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], - args: &[@ast::expr]) -> @ast::expr { - fn make_new_lit(cx: &ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr { +fn pieces_to_expr(cx: ext_ctxt, sp: span, pieces: [piece], args: [@ast::expr]) + -> @ast::expr { + fn make_new_lit(cx: ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr { let sp_lit = @{node: lit, span: sp}; ret @{id: cx.next_id(), node: ast::expr_lit(sp_lit), span: sp}; } - fn make_new_str(cx: &ext_ctxt, sp: span, s: &str) -> @ast::expr { + fn make_new_str(cx: ext_ctxt, sp: span, s: str) -> @ast::expr { let lit = ast::lit_str(s); ret make_new_lit(cx, sp, lit); } - fn make_new_int(cx: &ext_ctxt, sp: span, i: int) -> @ast::expr { + fn make_new_int(cx: ext_ctxt, sp: span, i: int) -> @ast::expr { let lit = ast::lit_int(i); ret make_new_lit(cx, sp, lit); } - fn make_new_uint(cx: &ext_ctxt, sp: span, u: uint) -> @ast::expr { + fn make_new_uint(cx: ext_ctxt, sp: span, u: uint) -> @ast::expr { let lit = ast::lit_uint(u); ret make_new_lit(cx, sp, lit); } - fn make_add_expr(cx: &ext_ctxt, sp: span, lhs: @ast::expr, - rhs: @ast::expr) -> @ast::expr { + fn make_add_expr(cx: ext_ctxt, sp: span, lhs: @ast::expr, rhs: @ast::expr) + -> @ast::expr { let binexpr = ast::expr_binary(ast::add, lhs, rhs); ret @{id: cx.next_id(), node: binexpr, span: sp}; } - fn make_path_expr(cx: &ext_ctxt, sp: span, idents: &[ast::ident]) -> + fn make_path_expr(cx: ext_ctxt, sp: span, idents: [ast::ident]) -> @ast::expr { let path = {global: false, idents: idents, types: []}; let sp_path = {node: path, span: sp}; let pathexpr = ast::expr_path(sp_path); ret @{id: cx.next_id(), node: pathexpr, span: sp}; } - fn make_vec_expr(cx: &ext_ctxt, sp: span, exprs: &[@ast::expr]) -> + fn make_vec_expr(cx: ext_ctxt, sp: span, exprs: [@ast::expr]) -> @ast::expr { let vecexpr = ast::expr_vec(exprs, ast::imm); ret @{id: cx.next_id(), node: vecexpr, span: sp}; } - fn make_call(cx: &ext_ctxt, sp: span, fn_path: &[ast::ident], - args: &[@ast::expr]) -> @ast::expr { + fn make_call(cx: ext_ctxt, sp: span, fn_path: [ast::ident], + args: [@ast::expr]) -> @ast::expr { let pathexpr = make_path_expr(cx, sp, fn_path); let callexpr = ast::expr_call(pathexpr, args); ret @{id: cx.next_id(), node: callexpr, span: sp}; } - fn make_rec_expr(cx: &ext_ctxt, sp: span, - fields: &[{ident: ast::ident, ex: @ast::expr}]) -> + fn make_rec_expr(cx: ext_ctxt, sp: span, + fields: [{ident: ast::ident, ex: @ast::expr}]) -> @ast::expr { let astfields: [ast::field] = []; for field: {ident: ast::ident, ex: @ast::expr} in fields { @@ -99,23 +99,23 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], let recexpr = ast::expr_rec(astfields, option::none::<@ast::expr>); ret @{id: cx.next_id(), node: recexpr, span: sp}; } - fn make_path_vec(cx: &ext_ctxt, ident: &ast::ident) -> [ast::ident] { - fn compiling_std(cx: &ext_ctxt) -> bool { + fn make_path_vec(cx: ext_ctxt, ident: ast::ident) -> [ast::ident] { + fn compiling_std(cx: ext_ctxt) -> bool { ret str::find(cx.crate_file_name(), "std.rc") >= 0; } if compiling_std(cx) { ret ["extfmt", "rt", ident]; } else { ret ["std", "extfmt", "rt", ident]; } } - fn make_rt_path_expr(cx: &ext_ctxt, sp: span, ident: &str) -> @ast::expr { + fn make_rt_path_expr(cx: ext_ctxt, sp: span, ident: str) -> @ast::expr { let path = make_path_vec(cx, ident); ret make_path_expr(cx, sp, path); } // Produces an AST expression that represents a RT::conv record, // which tells the RT::conv* functions how to perform the conversion - fn make_rt_conv_expr(cx: &ext_ctxt, sp: span, cnv: &conv) -> @ast::expr { - fn make_flags(cx: &ext_ctxt, sp: span, flags: &[flag]) -> @ast::expr { + fn make_rt_conv_expr(cx: ext_ctxt, sp: span, cnv: conv) -> @ast::expr { + fn make_flags(cx: ext_ctxt, sp: span, flags: [flag]) -> @ast::expr { let flagexprs: [@ast::expr] = []; for f: flag in flags { let fstr; @@ -137,7 +137,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], } ret make_vec_expr(cx, sp, flagexprs); } - fn make_count(cx: &ext_ctxt, sp: span, cnt: &count) -> @ast::expr { + fn make_count(cx: ext_ctxt, sp: span, cnt: count) -> @ast::expr { alt cnt { count_implied. { ret make_rt_path_expr(cx, sp, "count_implied"); @@ -151,7 +151,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], _ { cx.span_unimpl(sp, "unimplemented #fmt conversion"); } } } - fn make_ty(cx: &ext_ctxt, sp: span, t: &ty) -> @ast::expr { + fn make_ty(cx: ext_ctxt, sp: span, t: ty) -> @ast::expr { let rt_type; alt t { ty_hex(c) { @@ -166,7 +166,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], } ret make_rt_path_expr(cx, sp, rt_type); } - fn make_conv_rec(cx: &ext_ctxt, sp: span, flags_expr: @ast::expr, + fn make_conv_rec(cx: ext_ctxt, sp: span, flags_expr: @ast::expr, width_expr: @ast::expr, precision_expr: @ast::expr, ty_expr: @ast::expr) -> @ast::expr { ret make_rec_expr(cx, sp, @@ -182,7 +182,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], ret make_conv_rec(cx, sp, rt_conv_flags, rt_conv_width, rt_conv_precision, rt_conv_ty); } - fn make_conv_call(cx: &ext_ctxt, sp: span, conv_type: &str, cnv: &conv, + fn make_conv_call(cx: ext_ctxt, sp: span, conv_type: str, cnv: conv, arg: @ast::expr) -> @ast::expr { let fname = "conv_" + conv_type; let path = make_path_vec(cx, fname); @@ -190,7 +190,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], let args = [cnv_expr, arg]; ret make_call(cx, arg.span, path, args); } - fn make_new_conv(cx: &ext_ctxt, sp: span, cnv: conv, arg: @ast::expr) -> + fn make_new_conv(cx: ext_ctxt, sp: span, cnv: conv, arg: @ast::expr) -> @ast::expr { // FIXME: Extract all this validation into extfmt::ct @@ -334,10 +334,9 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], let expected_nargs = n + 1u; // n conversions + the fmt string if expected_nargs < nargs { - cx.span_fatal( - sp, - #fmt["too many arguments to #fmt. found %u, expected %u", - nargs, expected_nargs]); + cx.span_fatal(sp, + #fmt["too many arguments to #fmt. found %u, expected %u", + nargs, expected_nargs]); } ret tmp_expr; } diff --git a/src/comp/syntax/ext/ident_to_str.rs b/src/comp/syntax/ext/ident_to_str.rs index 1cf015fcaf0..382e1ec3056 100644 --- a/src/comp/syntax/ext/ident_to_str.rs +++ b/src/comp/syntax/ext/ident_to_str.rs @@ -4,8 +4,8 @@ import std::option; import base::*; import syntax::ast; -fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: &option::t<str>) -> @ast::expr { +fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr, + _body: option::t<str>) -> @ast::expr { let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } diff --git a/src/comp/syntax/ext/log_syntax.rs b/src/comp/syntax/ext/log_syntax.rs index 50e7e307bdc..8f28e3b6c76 100644 --- a/src/comp/syntax/ext/log_syntax.rs +++ b/src/comp/syntax/ext/log_syntax.rs @@ -3,8 +3,8 @@ import base::*; import syntax::ast; import std::str; -fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: &option::t<str>) -> @ast::expr { +fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: @ast::expr, + _body: option::t<str>) -> @ast::expr { cx.print_backtrace(); std::io::stdout().write_line(print::pprust::expr_to_str(arg)); diff --git a/src/comp/syntax/ext/simplext.rs b/src/comp/syntax/ext/simplext.rs index 4e76ec0d787..dc3b40645c2 100644 --- a/src/comp/syntax/ext/simplext.rs +++ b/src/comp/syntax/ext/simplext.rs @@ -33,7 +33,7 @@ import ast::mac_invoc; export add_new_extension; -fn path_to_ident(pth: &path) -> option::t<ident> { +fn path_to_ident(pth: path) -> option::t<ident> { if vec::len(pth.node.idents) == 1u && vec::len(pth.node.types) == 0u { ret some(pth.node.idents[0u]); } @@ -57,7 +57,7 @@ tag matchable { } /* for when given an incompatible bit of AST */ -fn match_error(cx: &ext_ctxt, m: &matchable, expected: &str) -> ! { +fn match_error(cx: ext_ctxt, m: matchable, expected: str) -> ! { alt m { match_expr(x) { cx.span_fatal(x.span, @@ -90,9 +90,9 @@ fn match_error(cx: &ext_ctxt, m: &matchable, expected: &str) -> ! { // we'll want to return something indicating amount of progress and location // of failure instead of `none`. type match_result = option::t<arb_depth<matchable>>; -type selector = fn(&matchable) -> match_result; +type selector = fn(matchable) -> match_result; -fn elts_to_ell(cx: &ext_ctxt, elts: &[@expr]) -> +fn elts_to_ell(cx: ext_ctxt, elts: [@expr]) -> {pre: [@expr], rep: option::t<@expr>, post: [@expr]} { let idx: uint = 0u; let res = none; @@ -122,7 +122,7 @@ fn elts_to_ell(cx: &ext_ctxt, elts: &[@expr]) -> } } -fn option_flatten_map<T, U>(f: &fn(&T) -> option::t<U>, v: &[T]) -> +fn option_flatten_map<T, U>(f: fn(T) -> option::t<U>, v: [T]) -> option::t<[U]> { let res = []; for elem: T in v { @@ -131,7 +131,7 @@ fn option_flatten_map<T, U>(f: &fn(&T) -> option::t<U>, v: &[T]) -> ret some(res); } -fn a_d_map(ad: &arb_depth<matchable>, f: &selector) -> match_result { +fn a_d_map(ad: arb_depth<matchable>, f: selector) -> match_result { alt ad { leaf(x) { ret f(x); } seq(ads, span) { @@ -144,7 +144,7 @@ fn a_d_map(ad: &arb_depth<matchable>, f: &selector) -> match_result { } fn compose_sels(s1: selector, s2: selector) -> selector { - fn scomp(s1: selector, s2: selector, m: &matchable) -> match_result { + fn scomp(s1: selector, s2: selector, m: matchable) -> match_result { ret alt s1(m) { none. { none } some(matches) { a_d_map(matches, s2) } @@ -160,19 +160,19 @@ type binders = mutable literal_ast_matchers: [selector]}; type bindings = hashmap<ident, arb_depth<matchable>>; -fn acumm_bindings(_cx: &ext_ctxt, _b_dest: &bindings, _b_src: &bindings) { } +fn acumm_bindings(_cx: ext_ctxt, _b_dest: bindings, _b_src: bindings) { } /* these three functions are the big moving parts */ /* create the selectors needed to bind and verify the pattern */ -fn pattern_to_selectors(cx: &ext_ctxt, e: @expr) -> binders { +fn pattern_to_selectors(cx: ext_ctxt, e: @expr) -> binders { let res: binders = {real_binders: new_str_hash::<selector>(), mutable literal_ast_matchers: []}; //this oughta return binders instead, but macro args are a sequence of //expressions, rather than a single expression - fn trivial_selector(m: &matchable) -> match_result { ret some(leaf(m)); } + fn trivial_selector(m: matchable) -> match_result { ret some(leaf(m)); } p_t_s_rec(cx, match_expr(e), trivial_selector, res); ret res; } @@ -183,7 +183,7 @@ fn pattern_to_selectors(cx: &ext_ctxt, e: @expr) -> binders { bindings. Most of the work is done in p_t_s, which generates the selectors. */ -fn use_selectors_to_bind(b: &binders, e: @expr) -> option::t<bindings> { +fn use_selectors_to_bind(b: binders, e: @expr) -> option::t<bindings> { let res = new_str_hash::<arb_depth<matchable>>(); //need to do this first, to check vec lengths. for sel: selector in b.literal_ast_matchers { @@ -203,10 +203,10 @@ fn use_selectors_to_bind(b: &binders, e: @expr) -> option::t<bindings> { /* use the bindings on the body to generate the expanded code */ -fn transcribe(cx: &ext_ctxt, b: &bindings, body: @expr) -> @expr { +fn transcribe(cx: ext_ctxt, b: bindings, body: @expr) -> @expr { let idx_path: @mutable [uint] = @mutable []; - fn new_id(_old: node_id, cx: &ext_ctxt) -> node_id { ret cx.next_id(); } - fn new_span(cx: &ext_ctxt, sp: &span) -> span { + fn new_id(_old: node_id, cx: ext_ctxt) -> node_id { ret cx.next_id(); } + fn new_span(cx: ext_ctxt, sp: span) -> span { /* this discards information in the case of macro-defining macros */ ret {lo: sp.lo, hi: sp.hi, expanded_from: cx.backtrace()}; } @@ -231,7 +231,7 @@ fn transcribe(cx: &ext_ctxt, b: &bindings, body: @expr) -> @expr { /* helper: descend into a matcher */ -fn follow(m: &arb_depth<matchable>, idx_path: @mutable [uint]) -> +fn follow(m: arb_depth<matchable>, idx_path: @mutable [uint]) -> arb_depth<matchable> { let res: arb_depth<matchable> = m; for idx: uint in *idx_path { @@ -243,7 +243,7 @@ fn follow(m: &arb_depth<matchable>, idx_path: @mutable [uint]) -> ret res; } -fn follow_for_trans(cx: &ext_ctxt, mmaybe: &option::t<arb_depth<matchable>>, +fn follow_for_trans(cx: ext_ctxt, mmaybe: option::t<arb_depth<matchable>>, idx_path: @mutable [uint]) -> option::t<matchable> { alt mmaybe { none. { ret none } @@ -262,10 +262,10 @@ 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 { +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, - idents: &hashmap<ident, ()>) -> ident { + fn mark_ident(i: ident, _fld: ast_fold, b: bindings, + idents: hashmap<ident, ()>) -> ident { if b.contains_key(i) { idents.insert(i, ()); } ret i; } @@ -282,8 +282,8 @@ iter free_vars(b: &bindings, e: @expr) -> ident { /* handle sequences (anywhere in the AST) of exprs, either real or ...ed */ -fn transcribe_exprs(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], - recur: fn(&@expr) -> @expr, exprs: [@expr]) -> [@expr] { +fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint], + recur: fn(@expr) -> @expr, exprs: [@expr]) -> [@expr] { alt elts_to_ell(cx, exprs) { {pre: pre, rep: repeat_me_maybe, post: post} { let res = vec::map(recur, pre); @@ -344,8 +344,8 @@ 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 { +fn transcribe_ident(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint], + 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") } @@ -354,8 +354,8 @@ fn transcribe_ident(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], } -fn transcribe_path(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], - p: &path_, _fld: ast_fold) -> path_ { +fn transcribe_path(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint], + p: path_, _fld: ast_fold) -> path_ { // Don't substitute into qualified names. if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { ret p; } ret alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) { @@ -369,9 +369,9 @@ fn transcribe_path(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], } -fn transcribe_expr(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], - e: &ast::expr_, fld: ast_fold, - orig: fn(&ast::expr_, ast_fold) -> ast::expr_) -> +fn transcribe_expr(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint], + e: ast::expr_, fld: ast_fold, + orig: fn(ast::expr_, ast_fold) -> ast::expr_) -> ast::expr_ { ret alt e { expr_path(p) { @@ -396,9 +396,9 @@ fn transcribe_expr(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], } } -fn transcribe_type(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], - t: &ast::ty_, fld: ast_fold, - orig: fn(&ast::ty_, ast_fold) -> ast::ty_) -> ast::ty_ { +fn transcribe_type(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint], + t: ast::ty_, fld: ast_fold, + orig: fn(ast::ty_, ast_fold) -> ast::ty_) -> ast::ty_ { ret alt t { ast::ty_path(pth, _) { alt path_to_ident(pth) { @@ -420,9 +420,9 @@ fn transcribe_type(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], /* for parsing reasons, syntax variables bound to blocks must be used like `{v}` */ -fn transcribe_block(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], - blk: &blk_, fld: ast_fold, - orig: fn(&blk_, ast_fold) -> blk_) -> blk_ { +fn transcribe_block(cx: ext_ctxt, b: bindings, idx_path: @mutable [uint], + blk: blk_, fld: ast_fold, + orig: fn(blk_, ast_fold) -> blk_) -> blk_ { ret alt block_to_ident(blk) { some(id) { alt follow_for_trans(cx, b.find(id), idx_path) { @@ -430,6 +430,7 @@ fn transcribe_block(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], + // possibly allow promotion of ident/path/expr to blocks? some(m) { match_error(cx, m, "a block") @@ -444,7 +445,7 @@ fn transcribe_block(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], /* traverse the pattern, building instructions on how to bind the actual argument. ps accumulates instructions on navigating the tree.*/ -fn p_t_s_rec(cx: &ext_ctxt, m: &matchable, s: &selector, b: &binders) { +fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) { //it might be possible to traverse only exprs, not matchables alt m { @@ -478,12 +479,13 @@ fn p_t_s_rec(cx: &ext_ctxt, m: &matchable, s: &selector, b: &binders) { + /* TODO: handle embedded types and blocks, at least */ expr_mac(mac) { p_t_s_r_mac(cx, mac, s, b); } _ { - fn select(cx: &ext_ctxt, m: &matchable, pat: @expr) -> + fn select(cx: ext_ctxt, m: matchable, pat: @expr) -> match_result { ret alt m { match_expr(e) { @@ -501,7 +503,7 @@ fn p_t_s_rec(cx: &ext_ctxt, m: &matchable, s: &selector, b: &binders) { /* make a match more precise */ -fn specialize_match(m: &matchable) -> matchable { +fn specialize_match(m: matchable) -> matchable { ret alt m { match_expr(e) { alt e.node { @@ -519,10 +521,10 @@ fn specialize_match(m: &matchable) -> matchable { } /* pattern_to_selectors helper functions */ -fn p_t_s_r_path(cx: &ext_ctxt, p: &path, s: &selector, b: &binders) { +fn p_t_s_r_path(cx: ext_ctxt, p: path, s: selector, b: binders) { alt path_to_ident(p) { some(p_id) { - fn select(cx: &ext_ctxt, m: &matchable) -> match_result { + fn select(cx: ext_ctxt, m: matchable) -> match_result { ret alt m { match_expr(e) { some(leaf(specialize_match(m))) } _ { cx.bug("broken traversal in p_t_s_r") } @@ -537,7 +539,7 @@ fn p_t_s_r_path(cx: &ext_ctxt, p: &path, s: &selector, b: &binders) { } } -fn block_to_ident(blk: &blk_) -> option::t<ident> { +fn block_to_ident(blk: blk_) -> option::t<ident> { if vec::len(blk.stmts) != 0u { ret none; } ret alt blk.expr { some(expr) { @@ -547,9 +549,9 @@ fn block_to_ident(blk: &blk_) -> option::t<ident> { } } -fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) { - fn select_pt_1(cx: &ext_ctxt, m: &matchable, - fn_m: fn(&ast::mac) -> match_result) -> match_result { +fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, s: selector, b: binders) { + fn select_pt_1(cx: ext_ctxt, m: matchable, + fn_m: fn(ast::mac) -> match_result) -> match_result { ret alt m { match_expr(e) { alt e.node { expr_mac(mac) { fn_m(mac) } _ { none } } @@ -557,7 +559,7 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) { _ { cx.bug("broken traversal in p_t_s_r") } } } - fn no_des(cx: &ext_ctxt, sp: &span, syn: &str) -> ! { + fn no_des(cx: ext_ctxt, sp: span, syn: str) -> ! { cx.span_fatal(sp, "destructuring " + syn + " is not yet supported"); } alt mac.node { @@ -569,7 +571,7 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) { alt path_to_ident(pth) { some(id) { /* look for an embedded type */ - fn select_pt_2(m: &ast::mac) -> match_result { + fn select_pt_2(m: ast::mac) -> match_result { ret alt m.node { ast::mac_embed_type(t) { some(leaf(match_ty(t))) } _ { none } @@ -587,7 +589,7 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) { ast::mac_embed_block(blk) { alt block_to_ident(blk.node) { some(id) { - fn select_pt_2(m: &ast::mac) -> match_result { + fn select_pt_2(m: ast::mac) -> match_result { ret alt m.node { ast::mac_embed_block(blk) { some(leaf(match_block(blk))) @@ -604,9 +606,9 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) { } } -fn p_t_s_r_ellipses(cx: &ext_ctxt, repeat_me: @expr, offset: uint, - s: &selector, b: &binders) { - fn select(cx: &ext_ctxt, repeat_me: @expr, offset: uint, m: &matchable) -> +fn p_t_s_r_ellipses(cx: ext_ctxt, repeat_me: @expr, offset: uint, s: selector, + b: binders) { + fn select(cx: ext_ctxt, repeat_me: @expr, offset: uint, m: matchable) -> match_result { ret alt m { match_expr(e) { @@ -634,9 +636,9 @@ fn p_t_s_r_ellipses(cx: &ext_ctxt, repeat_me: @expr, offset: uint, } -fn p_t_s_r_length(cx: &ext_ctxt, len: uint, at_least: bool, s: selector, - b: &binders) { - fn len_select(_cx: &ext_ctxt, m: &matchable, at_least: bool, len: uint) -> +fn p_t_s_r_length(cx: ext_ctxt, len: uint, at_least: bool, s: selector, + b: binders) { + fn len_select(_cx: ext_ctxt, m: matchable, at_least: bool, len: uint) -> match_result { ret alt m { match_expr(e) { @@ -657,11 +659,11 @@ fn p_t_s_r_length(cx: &ext_ctxt, len: uint, at_least: bool, s: selector, [compose_sels(s, bind len_select(cx, _, at_least, len))]; } -fn p_t_s_r_actual_vector(cx: &ext_ctxt, elts: [@expr], _repeat_after: bool, - s: &selector, b: &binders) { +fn p_t_s_r_actual_vector(cx: ext_ctxt, elts: [@expr], _repeat_after: bool, + s: selector, b: binders) { let idx: uint = 0u; while idx < vec::len(elts) { - fn select(cx: &ext_ctxt, m: &matchable, idx: uint) -> match_result { + fn select(cx: ext_ctxt, m: matchable, idx: uint) -> match_result { ret alt m { match_expr(e) { alt e.node { @@ -680,8 +682,8 @@ fn p_t_s_r_actual_vector(cx: &ext_ctxt, elts: [@expr], _repeat_after: bool, } } -fn add_new_extension(cx: &ext_ctxt, sp: span, arg: @expr, - _body: &option::t<str>) -> base::macro_def { +fn add_new_extension(cx: ext_ctxt, sp: span, arg: @expr, + _body: option::t<str>) -> base::macro_def { let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } @@ -760,9 +762,8 @@ fn add_new_extension(cx: &ext_ctxt, sp: span, arg: @expr, }, ext: normal(ext)}; - fn generic_extension(cx: &ext_ctxt, sp: span, arg: @expr, - _body: &option::t<str>, clauses: [@clause]) -> - @expr { + fn generic_extension(cx: ext_ctxt, sp: span, arg: @expr, + _body: option::t<str>, clauses: [@clause]) -> @expr { for c: @clause in clauses { alt use_selectors_to_bind(c.params, arg) { some(bindings) { ret transcribe(cx, bindings, c.body) } diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs index 899d940b390..0a628214eda 100644 --- a/src/comp/syntax/fold.rs +++ b/src/comp/syntax/fold.rs @@ -21,92 +21,91 @@ type ast_fold = @mutable a_f; type ast_fold_precursor = //unlike the others, item_ is non-trivial - {fold_crate: fn(&crate_, ast_fold) -> crate_, - fold_crate_directive: - fn(&crate_directive_, ast_fold) -> crate_directive_, - fold_view_item: fn(&view_item_, ast_fold) -> view_item_, - fold_native_item: fn(&@native_item, ast_fold) -> @native_item, - fold_item: fn(&@item, ast_fold) -> @item, - fold_item_underscore: fn(&item_, ast_fold) -> item_, - fold_method: fn(&method_, ast_fold) -> method_, - fold_block: fn(&blk_, ast_fold) -> blk_, - fold_stmt: fn(&stmt_, ast_fold) -> stmt_, - fold_arm: fn(&arm, ast_fold) -> arm, - fold_pat: fn(&pat_, ast_fold) -> pat_, - fold_decl: fn(&decl_, ast_fold) -> decl_, - fold_expr: fn(&expr_, ast_fold) -> expr_, - fold_ty: fn(&ty_, ast_fold) -> ty_, - fold_constr: fn(&ast::constr_, ast_fold) -> constr_, - fold_fn: fn(&_fn, ast_fold) -> _fn, - 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_path: fn(&path_, ast_fold) -> path_, - fold_local: fn(&local_, ast_fold) -> local_, - map_exprs: fn(fn(&@expr) -> @expr, [@expr]) -> [@expr], + {fold_crate: fn(crate_, ast_fold) -> crate_, + fold_crate_directive: fn(crate_directive_, ast_fold) -> crate_directive_, + fold_view_item: fn(view_item_, ast_fold) -> view_item_, + fold_native_item: fn(@native_item, ast_fold) -> @native_item, + fold_item: fn(@item, ast_fold) -> @item, + fold_item_underscore: fn(item_, ast_fold) -> item_, + fold_method: fn(method_, ast_fold) -> method_, + fold_block: fn(blk_, ast_fold) -> blk_, + fold_stmt: fn(stmt_, ast_fold) -> stmt_, + fold_arm: fn(arm, ast_fold) -> arm, + fold_pat: fn(pat_, ast_fold) -> pat_, + fold_decl: fn(decl_, ast_fold) -> decl_, + fold_expr: fn(expr_, ast_fold) -> expr_, + fold_ty: fn(ty_, ast_fold) -> ty_, + fold_constr: fn(ast::constr_, ast_fold) -> constr_, + fold_fn: fn(_fn, ast_fold) -> _fn, + 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_path: fn(path_, ast_fold) -> path_, + fold_local: fn(local_, ast_fold) -> local_, + map_exprs: fn(fn(@expr) -> @expr, [@expr]) -> [@expr], new_id: fn(node_id) -> node_id, - new_span: fn(&span) -> span}; + new_span: fn(span) -> span}; type a_f = - {fold_crate: fn(&crate) -> crate, - fold_crate_directive: fn(&@crate_directive) -> @crate_directive, - fold_view_item: fn(&@view_item) -> @view_item, - fold_native_item: fn(&@native_item) -> @native_item, - fold_item: fn(&@item) -> @item, - fold_item_underscore: fn(&item_) -> item_, - fold_method: fn(&@method) -> @method, - fold_block: fn(&blk) -> blk, - fold_stmt: fn(&@stmt) -> @stmt, - fold_arm: fn(&arm) -> arm, - fold_pat: fn(&@pat) -> @pat, - fold_decl: fn(&@decl) -> @decl, - fold_expr: fn(&@expr) -> @expr, - fold_ty: fn(&@ty) -> @ty, - fold_constr: fn(&@constr) -> @constr, - fold_fn: fn(&_fn) -> _fn, - fold_mod: fn(&_mod) -> _mod, - fold_native_mod: fn(&native_mod) -> native_mod, - fold_variant: fn(&variant) -> variant, - fold_ident: fn(&ident) -> ident, - fold_path: fn(&path) -> path, - fold_local: fn(&@local) -> @local, - map_exprs: fn(fn(&@expr) -> @expr, [@expr]) -> [@expr], + {fold_crate: fn(crate) -> crate, + fold_crate_directive: fn(@crate_directive) -> @crate_directive, + fold_view_item: fn(@view_item) -> @view_item, + fold_native_item: fn(@native_item) -> @native_item, + fold_item: fn(@item) -> @item, + fold_item_underscore: fn(item_) -> item_, + fold_method: fn(@method) -> @method, + fold_block: fn(blk) -> blk, + fold_stmt: fn(@stmt) -> @stmt, + fold_arm: fn(arm) -> arm, + fold_pat: fn(@pat) -> @pat, + fold_decl: fn(@decl) -> @decl, + fold_expr: fn(@expr) -> @expr, + fold_ty: fn(@ty) -> @ty, + fold_constr: fn(@constr) -> @constr, + fold_fn: fn(_fn) -> _fn, + fold_mod: fn(_mod) -> _mod, + fold_native_mod: fn(native_mod) -> native_mod, + fold_variant: fn(variant) -> variant, + fold_ident: fn(ident) -> ident, + fold_path: fn(path) -> path, + fold_local: fn(@local) -> @local, + map_exprs: fn(fn(@expr) -> @expr, [@expr]) -> [@expr], new_id: fn(node_id) -> node_id, - new_span: fn(&span) -> span}; + new_span: fn(span) -> span}; //fn nf_dummy<T>(&T node) -> T { fail; } -fn nf_crate_dummy(_c: &crate) -> crate { fail; } -fn nf_crate_directive_dummy(_c: &@crate_directive) -> @crate_directive { +fn nf_crate_dummy(_c: crate) -> crate { fail; } +fn nf_crate_directive_dummy(_c: @crate_directive) -> @crate_directive { fail; } -fn nf_view_item_dummy(_v: &@view_item) -> @view_item { fail; } -fn nf_native_item_dummy(_n: &@native_item) -> @native_item { fail; } -fn nf_item_dummy(_i: &@item) -> @item { fail; } -fn nf_item_underscore_dummy(_i: &item_) -> item_ { fail; } -fn nf_method_dummy(_m: &@method) -> @method { fail; } -fn nf_blk_dummy(_b: &blk) -> blk { fail; } -fn nf_stmt_dummy(_s: &@stmt) -> @stmt { fail; } -fn nf_arm_dummy(_a: &arm) -> arm { fail; } -fn nf_pat_dummy(_p: &@pat) -> @pat { fail; } -fn nf_decl_dummy(_d: &@decl) -> @decl { fail; } -fn nf_expr_dummy(_e: &@expr) -> @expr { fail; } -fn nf_ty_dummy(_t: &@ty) -> @ty { fail; } -fn nf_constr_dummy(_c: &@constr) -> @constr { fail; } -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_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; } +fn nf_view_item_dummy(_v: @view_item) -> @view_item { fail; } +fn nf_native_item_dummy(_n: @native_item) -> @native_item { fail; } +fn nf_item_dummy(_i: @item) -> @item { fail; } +fn nf_item_underscore_dummy(_i: item_) -> item_ { fail; } +fn nf_method_dummy(_m: @method) -> @method { fail; } +fn nf_blk_dummy(_b: blk) -> blk { fail; } +fn nf_stmt_dummy(_s: @stmt) -> @stmt { fail; } +fn nf_arm_dummy(_a: arm) -> arm { fail; } +fn nf_pat_dummy(_p: @pat) -> @pat { fail; } +fn nf_decl_dummy(_d: @decl) -> @decl { fail; } +fn nf_expr_dummy(_e: @expr) -> @expr { fail; } +fn nf_ty_dummy(_t: @ty) -> @ty { fail; } +fn nf_constr_dummy(_c: @constr) -> @constr { fail; } +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_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; } /* some little folds that probably aren't useful to have in ast_fold itself*/ //used in noop_fold_item and noop_fold_crate and noop_fold_crate_directive -fn fold_meta_item_(mi: &@meta_item, fld: ast_fold) -> @meta_item { +fn fold_meta_item_(mi: @meta_item, fld: ast_fold) -> @meta_item { ret @{node: alt mi.node { meta_word(id) { meta_word(fld.fold_ident(id)) } @@ -121,20 +120,20 @@ fn fold_meta_item_(mi: &@meta_item, fld: ast_fold) -> @meta_item { span: mi.span}; } //used in noop_fold_item and noop_fold_crate -fn fold_attribute_(at: &attribute, fmi: fn(&@meta_item) -> @meta_item) -> +fn fold_attribute_(at: attribute, fmi: fn(@meta_item) -> @meta_item) -> attribute { ret {node: {style: at.node.style, value: *fmi(@at.node.value)}, span: at.span}; } //used in noop_fold_native_item and noop_fold_fn -fn fold_arg_(a: &arg, fld: ast_fold) -> arg { +fn fold_arg_(a: arg, fld: ast_fold) -> arg { ret {mode: a.mode, ty: fld.fold_ty(a.ty), ident: fld.fold_ident(a.ident), id: a.id}; } //used in noop_fold_expr, and possibly elsewhere in the future -fn fold_mac_(m: &mac, fld: ast_fold) -> mac { +fn fold_mac_(m: mac, fld: ast_fold) -> mac { ret {node: alt m.node { mac_invoc(pth, arg, body) { @@ -151,7 +150,7 @@ fn fold_mac_(m: &mac, fld: ast_fold) -> mac { -fn noop_fold_crate(c: &crate_, fld: ast_fold) -> crate_ { +fn noop_fold_crate(c: crate_, fld: ast_fold) -> crate_ { let fold_meta_item = bind fold_meta_item_(_, fld); let fold_attribute = bind fold_attribute_(_, fold_meta_item); @@ -161,7 +160,7 @@ fn noop_fold_crate(c: &crate_, fld: ast_fold) -> crate_ { config: vec::map(fold_meta_item, c.config)}; } -fn noop_fold_crate_directive(cd: &crate_directive_, fld: ast_fold) -> +fn noop_fold_crate_directive(cd: crate_directive_, fld: ast_fold) -> crate_directive_ { ret alt cd { cdir_src_mod(id, fname, attrs) { @@ -177,12 +176,12 @@ fn noop_fold_crate_directive(cd: &crate_directive_, fld: ast_fold) -> } } -fn noop_fold_view_item(vi: &view_item_, _fld: ast_fold) -> view_item_ { +fn noop_fold_view_item(vi: view_item_, _fld: ast_fold) -> view_item_ { ret vi; } -fn noop_fold_native_item(ni: &@native_item, fld: ast_fold) -> @native_item { +fn noop_fold_native_item(ni: @native_item, fld: ast_fold) -> @native_item { let fold_arg = bind fold_arg_(_, fld); let fold_meta_item = bind fold_meta_item_(_, fld); let fold_attribute = bind fold_attribute_(_, fold_meta_item); @@ -208,7 +207,7 @@ fn noop_fold_native_item(ni: &@native_item, fld: ast_fold) -> @native_item { span: ni.span}; } -fn noop_fold_item(i: &@item, fld: ast_fold) -> @item { +fn noop_fold_item(i: @item, fld: ast_fold) -> @item { let fold_meta_item = bind fold_meta_item_(_, fld); let fold_attribute = bind fold_attribute_(_, fold_meta_item); @@ -219,8 +218,8 @@ fn noop_fold_item(i: &@item, fld: ast_fold) -> @item { span: i.span}; } -fn noop_fold_item_underscore(i: &item_, fld: ast_fold) -> item_ { - fn fold_obj_field_(of: &obj_field, fld: ast_fold) -> obj_field { +fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ { + fn fold_obj_field_(of: obj_field, fld: ast_fold) -> obj_field { ret {mut: of.mut, ty: fld.fold_ty(of.ty), ident: fld.fold_ident(of.ident), @@ -248,19 +247,19 @@ fn noop_fold_item_underscore(i: &item_, fld: ast_fold) -> item_ { }; } -fn noop_fold_method(m: &method_, fld: ast_fold) -> method_ { +fn noop_fold_method(m: method_, fld: ast_fold) -> method_ { ret {ident: fld.fold_ident(m.ident), meth: fld.fold_fn(m.meth), id: m.id}; } -fn noop_fold_block(b: &blk_, fld: ast_fold) -> blk_ { +fn noop_fold_block(b: blk_, fld: ast_fold) -> blk_ { ret {stmts: vec::map(fld.fold_stmt, b.stmts), expr: option::map(fld.fold_expr, b.expr), id: b.id, rules: b.rules}; } -fn noop_fold_stmt(s: &stmt_, fld: ast_fold) -> stmt_ { +fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ { ret alt s { stmt_decl(d, nid) { stmt_decl(fld.fold_decl(d), nid) } stmt_expr(e, nid) { stmt_expr(fld.fold_expr(e), nid) } @@ -270,13 +269,13 @@ fn noop_fold_stmt(s: &stmt_, fld: ast_fold) -> stmt_ { }; } -fn noop_fold_arm(a: &arm, fld: ast_fold) -> arm { +fn noop_fold_arm(a: arm, fld: ast_fold) -> arm { ret {pats: vec::map(fld.fold_pat, a.pats), guard: option::map(fld.fold_expr, a.guard), body: fld.fold_block(a.body)}; } -fn noop_fold_pat(p: &pat_, fld: ast_fold) -> pat_ { +fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ { ret alt p { pat_wild. { p } pat_bind(ident) { pat_bind(fld.fold_ident(ident)) } @@ -296,15 +295,15 @@ fn noop_fold_pat(p: &pat_, fld: ast_fold) -> pat_ { }; } -fn noop_fold_decl(d: &decl_, fld: ast_fold) -> decl_ { +fn noop_fold_decl(d: decl_, fld: ast_fold) -> decl_ { ret alt d { decl_local(ls) { decl_local(vec::map(fld.fold_local, ls)) } decl_item(it) { decl_item(fld.fold_item(it)) } } } -fn noop_fold_expr(e: &expr_, fld: ast_fold) -> expr_ { - fn fold_field_(field: &field, fld: ast_fold) -> field { +fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ { + fn fold_field_(field: field, fld: ast_fold) -> field { ret {node: {mut: field.node.mut, ident: fld.fold_ident(field.node.ident), @@ -312,8 +311,8 @@ fn noop_fold_expr(e: &expr_, fld: ast_fold) -> expr_ { span: field.span}; } let fold_field = bind fold_field_(_, fld); - fn fold_anon_obj_(ao: &anon_obj, fld: ast_fold) -> anon_obj { - fn fold_anon_obj_field_(aof: &anon_obj_field, fld: ast_fold) -> + fn fold_anon_obj_(ao: anon_obj, fld: ast_fold) -> anon_obj { + fn fold_anon_obj_field_(aof: anon_obj_field, fld: ast_fold) -> anon_obj_field { ret {mut: aof.mut, ty: fld.fold_ty(aof.ty), @@ -427,17 +426,17 @@ fn noop_fold_expr(e: &expr_, fld: ast_fold) -> expr_ { } } -fn noop_fold_ty(t: &ty_, _fld: ast_fold) -> ty_ { +fn noop_fold_ty(t: ty_, _fld: ast_fold) -> ty_ { //drop in ty::fold_ty here if necessary ret t; } -fn noop_fold_constr(c: &constr_, fld: ast_fold) -> constr_ { +fn noop_fold_constr(c: constr_, fld: ast_fold) -> constr_ { {path: fld.fold_path(c.path), args: c.args, id: c.id} } // functions just don't get spans, for some reason -fn noop_fold_fn(f: &_fn, fld: ast_fold) -> _fn { +fn noop_fold_fn(f: _fn, fld: ast_fold) -> _fn { let fold_arg = bind fold_arg_(_, fld); ret {decl: @@ -452,35 +451,35 @@ fn noop_fold_fn(f: &_fn, fld: ast_fold) -> _fn { } // ...nor do modules -fn noop_fold_mod(m: &_mod, fld: ast_fold) -> _mod { +fn noop_fold_mod(m: _mod, fld: ast_fold) -> _mod { ret {view_items: vec::map(fld.fold_view_item, m.view_items), items: vec::map(fld.fold_item, m.items)}; } -fn noop_fold_native_mod(nm: &native_mod, fld: ast_fold) -> native_mod { +fn noop_fold_native_mod(nm: native_mod, fld: ast_fold) -> native_mod { ret {native_name: nm.native_name, abi: nm.abi, view_items: vec::map(fld.fold_view_item, nm.view_items), items: vec::map(fld.fold_native_item, nm.items)} } -fn noop_fold_variant(v: &variant_, fld: ast_fold) -> variant_ { - fn fold_variant_arg_(va: &variant_arg, fld: ast_fold) -> variant_arg { +fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ { + fn fold_variant_arg_(va: variant_arg, fld: ast_fold) -> variant_arg { ret {ty: fld.fold_ty(va.ty), id: va.id}; } let fold_variant_arg = bind fold_variant_arg_(_, fld); 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_ { +fn noop_fold_path(p: path_, fld: ast_fold) -> path_ { ret {global: p.global, idents: vec::map(fld.fold_ident, p.idents), types: vec::map(fld.fold_ty, p.types)}; } -fn noop_fold_local(l: &local_, fld: ast_fold) -> local_ { +fn noop_fold_local(l: local_, fld: ast_fold) -> local_ { ret {ty: fld.fold_ty(l.ty), pat: fld.fold_pat(l.pat), init: @@ -496,13 +495,13 @@ fn noop_fold_local(l: &local_, fld: ast_fold) -> local_ { /* temporarily eta-expand because of a compiler bug with using `fn<T>` as a value */ -fn noop_map_exprs(f: fn(&@expr) -> @expr, es: [@expr]) -> [@expr] { +fn noop_map_exprs(f: fn(@expr) -> @expr, es: [@expr]) -> [@expr] { ret vec::map(f, es); } fn noop_id(i: node_id) -> node_id { ret i; } -fn noop_span(sp: &span) -> span { ret sp; } +fn noop_span(sp: span) -> span { ret sp; } fn default_ast_fold() -> @ast_fold_precursor { @@ -563,7 +562,7 @@ fn dummy_out(a: ast_fold) { } -fn make_fold(afp: &ast_fold_precursor) -> ast_fold { +fn make_fold(afp: ast_fold_precursor) -> ast_fold { let result: ast_fold = @mutable {fold_crate: nf_crate_dummy, fold_crate_directive: nf_crate_directive_dummy, @@ -592,84 +591,83 @@ fn make_fold(afp: &ast_fold_precursor) -> ast_fold { new_span: noop_span}; /* naturally, a macro to write these would be nice */ - fn f_crate(afp: &ast_fold_precursor, f: ast_fold, c: &crate) -> crate { + fn f_crate(afp: ast_fold_precursor, f: ast_fold, c: crate) -> crate { ret {node: afp.fold_crate(c.node, f), span: afp.new_span(c.span)}; } - fn f_crate_directive(afp: &ast_fold_precursor, f: ast_fold, - c: &@crate_directive) -> @crate_directive { + fn f_crate_directive(afp: ast_fold_precursor, f: ast_fold, + c: @crate_directive) -> @crate_directive { ret @{node: afp.fold_crate_directive(c.node, f), span: afp.new_span(c.span)}; } - fn f_view_item(afp: &ast_fold_precursor, f: ast_fold, x: &@view_item) -> + fn f_view_item(afp: ast_fold_precursor, f: ast_fold, x: @view_item) -> @view_item { ret @{node: afp.fold_view_item(x.node, f), span: afp.new_span(x.span)}; } - fn f_native_item(afp: &ast_fold_precursor, f: ast_fold, x: &@native_item) - -> @native_item { + fn f_native_item(afp: ast_fold_precursor, f: ast_fold, x: @native_item) -> + @native_item { ret afp.fold_native_item(x, f); } - fn f_item(afp: &ast_fold_precursor, f: ast_fold, i: &@item) -> @item { + fn f_item(afp: ast_fold_precursor, f: ast_fold, i: @item) -> @item { ret afp.fold_item(i, f); } - fn f_item_underscore(afp: &ast_fold_precursor, f: ast_fold, i: &item_) -> + fn f_item_underscore(afp: ast_fold_precursor, f: ast_fold, i: item_) -> item_ { ret afp.fold_item_underscore(i, f); } - fn f_method(afp: &ast_fold_precursor, f: ast_fold, x: &@method) -> - @method { + fn f_method(afp: ast_fold_precursor, f: ast_fold, x: @method) -> @method { ret @{node: afp.fold_method(x.node, f), span: afp.new_span(x.span)}; } - fn f_block(afp: &ast_fold_precursor, f: ast_fold, x: &blk) -> blk { + fn f_block(afp: ast_fold_precursor, f: ast_fold, x: blk) -> blk { ret {node: afp.fold_block(x.node, f), span: afp.new_span(x.span)}; } - fn f_stmt(afp: &ast_fold_precursor, f: ast_fold, x: &@stmt) -> @stmt { + fn f_stmt(afp: ast_fold_precursor, f: ast_fold, x: @stmt) -> @stmt { ret @{node: afp.fold_stmt(x.node, f), span: afp.new_span(x.span)}; } - fn f_arm(afp: &ast_fold_precursor, f: ast_fold, x: &arm) -> arm { + fn f_arm(afp: ast_fold_precursor, f: ast_fold, x: arm) -> arm { ret afp.fold_arm(x, f); } - fn f_pat(afp: &ast_fold_precursor, f: ast_fold, x: &@pat) -> @pat { + fn f_pat(afp: ast_fold_precursor, f: ast_fold, x: @pat) -> @pat { ret @{id: afp.new_id(x.id), node: afp.fold_pat(x.node, f), span: afp.new_span(x.span)}; } - fn f_decl(afp: &ast_fold_precursor, f: ast_fold, x: &@decl) -> @decl { + fn f_decl(afp: ast_fold_precursor, f: ast_fold, x: @decl) -> @decl { ret @{node: afp.fold_decl(x.node, f), span: afp.new_span(x.span)}; } - fn f_expr(afp: &ast_fold_precursor, f: ast_fold, x: &@expr) -> @expr { + fn f_expr(afp: ast_fold_precursor, f: ast_fold, x: @expr) -> @expr { ret @{id: afp.new_id(x.id), node: afp.fold_expr(x.node, f), span: afp.new_span(x.span)}; } - fn f_ty(afp: &ast_fold_precursor, f: ast_fold, x: &@ty) -> @ty { + fn f_ty(afp: ast_fold_precursor, f: ast_fold, x: @ty) -> @ty { ret @{node: afp.fold_ty(x.node, f), span: afp.new_span(x.span)}; } - fn f_constr(afp: &ast_fold_precursor, f: ast_fold, x: &@ast::constr) -> + fn f_constr(afp: ast_fold_precursor, f: ast_fold, x: @ast::constr) -> @ast::constr { ret @{node: afp.fold_constr(x.node, f), span: afp.new_span(x.span)}; } - fn f_fn(afp: &ast_fold_precursor, f: ast_fold, x: &_fn) -> _fn { + fn f_fn(afp: ast_fold_precursor, f: ast_fold, x: _fn) -> _fn { ret afp.fold_fn(x, f); } - fn f_mod(afp: &ast_fold_precursor, f: ast_fold, x: &_mod) -> _mod { + fn f_mod(afp: ast_fold_precursor, f: ast_fold, x: _mod) -> _mod { ret afp.fold_mod(x, f); } - fn f_native_mod(afp: &ast_fold_precursor, f: ast_fold, x: &native_mod) -> + fn f_native_mod(afp: ast_fold_precursor, f: ast_fold, x: native_mod) -> native_mod { ret afp.fold_native_mod(x, f); } - fn f_variant(afp: &ast_fold_precursor, f: ast_fold, x: &variant) -> + fn f_variant(afp: ast_fold_precursor, f: ast_fold, x: variant) -> 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 { + fn f_path(afp: ast_fold_precursor, f: ast_fold, x: path) -> path { ret {node: afp.fold_path(x.node, f), span: afp.new_span(x.span)}; } - fn f_local(afp: &ast_fold_precursor, f: ast_fold, x: &@local) -> @local { + fn f_local(afp: ast_fold_precursor, f: ast_fold, x: @local) -> @local { ret @{node: afp.fold_local(x.node, f), span: afp.new_span(x.span)}; } diff --git a/src/comp/syntax/parse/eval.rs b/src/comp/syntax/parse/eval.rs index 6535ecfe586..147f1b9453e 100644 --- a/src/comp/syntax/parse/eval.rs +++ b/src/comp/syntax/parse/eval.rs @@ -25,23 +25,23 @@ type ctx = mutable byte_pos: uint, cfg: ast::crate_cfg}; -fn eval_crate_directives(cx: ctx, cdirs: &[@ast::crate_directive], - prefix: &str, view_items: &mutable [@ast::view_item], +fn eval_crate_directives(cx: ctx, cdirs: [@ast::crate_directive], prefix: str, + view_items: &mutable [@ast::view_item], items: &mutable [@ast::item]) { for sub_cdir: @ast::crate_directive in cdirs { eval_crate_directive(cx, sub_cdir, prefix, view_items, items); } } -fn eval_crate_directives_to_mod(cx: ctx, cdirs: &[@ast::crate_directive], - prefix: &str) -> ast::_mod { +fn eval_crate_directives_to_mod(cx: ctx, cdirs: [@ast::crate_directive], + prefix: str) -> ast::_mod { let view_items: [@ast::view_item] = []; let items: [@ast::item] = []; eval_crate_directives(cx, cdirs, prefix, view_items, items); ret {view_items: view_items, items: items}; } -fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: &str, +fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str, view_items: &mutable [@ast::view_item], items: &mutable [@ast::item]) { alt cdir.node { diff --git a/src/comp/syntax/parse/lexer.rs b/src/comp/syntax/parse/lexer.rs index f0d5bfeb729..c5a9eefdec2 100644 --- a/src/comp/syntax/parse/lexer.rs +++ b/src/comp/syntax/parse/lexer.rs @@ -25,10 +25,10 @@ type reader = fn get_byte_pos() -> uint; fn get_col() -> uint; fn get_filemap() -> codemap::filemap; - fn err(&str); + fn err(str); }; -fn new_reader(cm: &codemap::codemap, src: &str, filemap: codemap::filemap, +fn new_reader(cm: codemap::codemap, src: str, filemap: codemap::filemap, itr: @interner::interner<str>) -> reader { obj reader(cm: codemap::codemap, src: str, @@ -77,7 +77,7 @@ fn new_reader(cm: &codemap::codemap, src: &str, filemap: codemap::filemap, fn get_interner() -> @interner::interner<str> { ret itr; } fn get_col() -> uint { ret col; } fn get_filemap() -> codemap::filemap { ret fm; } - fn err(m: &str) { + fn err(m: str) { codemap::emit_error(some(ast_util::mk_sp(chpos, chpos)), m, cm); } } @@ -123,12 +123,12 @@ fn is_hex_digit(c: char) -> bool { fn is_bin_digit(c: char) -> bool { ret c == '0' || c == '1'; } -fn consume_whitespace_and_comments(rdr: &reader) { +fn consume_whitespace_and_comments(rdr: reader) { while is_whitespace(rdr.curr()) { rdr.bump(); } be consume_any_line_comment(rdr); } -fn consume_any_line_comment(rdr: &reader) { +fn consume_any_line_comment(rdr: reader) { if rdr.curr() == '/' { alt rdr.next() { '/' { @@ -143,7 +143,7 @@ fn consume_any_line_comment(rdr: &reader) { } } -fn consume_block_comment(rdr: &reader) { +fn consume_block_comment(rdr: reader) { let level: int = 1; while level > 0 { if rdr.is_eof() { rdr.err("unterminated block comment"); fail; } @@ -164,13 +164,13 @@ fn consume_block_comment(rdr: &reader) { be consume_whitespace_and_comments(rdr); } -fn digits_to_string(s: &str) -> int { +fn digits_to_string(s: str) -> int { let accum_int: int = 0; for c: u8 in s { accum_int *= 10; accum_int += dec_digit_val(c as char); } ret accum_int; } -fn scan_exponent(rdr: &reader) -> option::t<str> { +fn scan_exponent(rdr: reader) -> option::t<str> { let c = rdr.curr(); let rslt = ""; if c == 'e' || c == 'E' { @@ -188,7 +188,7 @@ fn scan_exponent(rdr: &reader) -> option::t<str> { } else { ret none::<str>; } } -fn scan_dec_digits(rdr: &reader) -> str { +fn scan_dec_digits(rdr: reader) -> str { let c = rdr.curr(); let rslt: str = ""; while is_dec_digit(c) || c == '_' { @@ -199,7 +199,7 @@ fn scan_dec_digits(rdr: &reader) -> str { ret rslt; } -fn scan_number(c: char, rdr: &reader) -> token::token { +fn scan_number(c: char, rdr: reader) -> token::token { let accum_int = 0; let dec_str: str = ""; let is_dec_integer: bool = false; @@ -312,7 +312,7 @@ fn scan_number(c: char, rdr: &reader) -> token::token { } } -fn scan_numeric_escape(rdr: &reader, n_hex_digits: uint) -> char { +fn scan_numeric_escape(rdr: reader, n_hex_digits: uint) -> char { let accum_int = 0; while n_hex_digits != 0u { let n = rdr.curr(); @@ -328,7 +328,7 @@ fn scan_numeric_escape(rdr: &reader, n_hex_digits: uint) -> char { ret accum_int as char; } -fn next_token(rdr: &reader) -> {tok: token::token, chpos: uint, bpos: uint} { +fn next_token(rdr: reader) -> {tok: token::token, chpos: uint, bpos: uint} { consume_whitespace_and_comments(rdr); let start_chpos = rdr.get_chpos(); let start_bpos = rdr.get_byte_pos(); @@ -336,7 +336,7 @@ fn next_token(rdr: &reader) -> {tok: token::token, chpos: uint, bpos: uint} { ret {tok: tok, chpos: start_chpos, bpos: start_bpos}; } -fn next_token_inner(rdr: &reader) -> token::token { +fn next_token_inner(rdr: reader) -> token::token { let accum_str = ""; let c = rdr.curr(); if is_alpha(c) || c == '_' { @@ -351,7 +351,7 @@ fn next_token_inner(rdr: &reader) -> token::token { accum_str), is_mod_name); } if is_dec_digit(c) { ret scan_number(c, rdr); } - fn binop(rdr: &reader, op: token::binop) -> token::token { + fn binop(rdr: reader, op: token::binop) -> token::token { rdr.bump(); if rdr.curr() == '=' { rdr.bump(); @@ -362,6 +362,7 @@ fn next_token_inner(rdr: &reader) -> token::token { + // One-byte tokens. '?' { rdr.bump(); @@ -402,6 +403,7 @@ fn next_token_inner(rdr: &reader) -> token::token { + // Multi-byte tokens. '=' { rdr.bump(); @@ -551,7 +553,7 @@ tag cmnt_style { type cmnt = {style: cmnt_style, lines: [str], pos: uint}; -fn read_to_eol(rdr: &reader) -> str { +fn read_to_eol(rdr: reader) -> str { let val = ""; while rdr.curr() != '\n' && !rdr.is_eof() { str::push_char(val, rdr.curr()); @@ -561,29 +563,29 @@ fn read_to_eol(rdr: &reader) -> str { ret val; } -fn read_one_line_comment(rdr: &reader) -> str { +fn read_one_line_comment(rdr: reader) -> str { let val = read_to_eol(rdr); assert (val[0] == '/' as u8 && val[1] == '/' as u8); ret val; } -fn consume_whitespace(rdr: &reader) { +fn consume_whitespace(rdr: reader) { while is_whitespace(rdr.curr()) && !rdr.is_eof() { rdr.bump(); } } -fn consume_non_eol_whitespace(rdr: &reader) { +fn consume_non_eol_whitespace(rdr: reader) { while is_whitespace(rdr.curr()) && rdr.curr() != '\n' && !rdr.is_eof() { rdr.bump(); } } -fn push_blank_line_comment(rdr: &reader, comments: &mutable [cmnt]) { +fn push_blank_line_comment(rdr: reader, comments: &mutable [cmnt]) { log ">>> blank-line comment"; let v: [str] = []; comments += [{style: blank_line, lines: v, pos: rdr.get_chpos()}]; } -fn consume_whitespace_counting_blank_lines(rdr: &reader, +fn consume_whitespace_counting_blank_lines(rdr: reader, comments: &mutable [cmnt]) { while is_whitespace(rdr.curr()) && !rdr.is_eof() { if rdr.get_col() == 0u && rdr.curr() == '\n' { @@ -593,7 +595,7 @@ fn consume_whitespace_counting_blank_lines(rdr: &reader, } } -fn read_line_comments(rdr: &reader, code_to_the_left: bool) -> cmnt { +fn read_line_comments(rdr: reader, code_to_the_left: bool) -> cmnt { log ">>> line comments"; let p = rdr.get_chpos(); let lines: [str] = []; @@ -609,13 +611,13 @@ fn read_line_comments(rdr: &reader, code_to_the_left: bool) -> cmnt { pos: p}; } -fn all_whitespace(s: &str, begin: uint, end: uint) -> bool { +fn all_whitespace(s: str, begin: uint, end: uint) -> bool { let i: uint = begin; while i != end { if !is_whitespace(s[i] as char) { ret false; } i += 1u; } ret true; } -fn trim_whitespace_prefix_and_push_line(lines: &mutable [str], s: &str, +fn trim_whitespace_prefix_and_push_line(lines: &mutable [str], s: str, col: uint) { let s1; if all_whitespace(s, 0u, col) { @@ -627,7 +629,7 @@ fn trim_whitespace_prefix_and_push_line(lines: &mutable [str], s: &str, lines += [s1]; } -fn read_block_comment(rdr: &reader, code_to_the_left: bool) -> cmnt { +fn read_block_comment(rdr: reader, code_to_the_left: bool) -> cmnt { log ">>> block comment"; let p = rdr.get_chpos(); let lines: [str] = []; @@ -672,12 +674,12 @@ fn read_block_comment(rdr: &reader, code_to_the_left: bool) -> cmnt { ret {style: style, lines: lines, pos: p}; } -fn peeking_at_comment(rdr: &reader) -> bool { +fn peeking_at_comment(rdr: reader) -> bool { ret rdr.curr() == '/' && rdr.next() == '/' || rdr.curr() == '/' && rdr.next() == '*'; } -fn consume_comment(rdr: &reader, code_to_the_left: bool, +fn consume_comment(rdr: reader, code_to_the_left: bool, comments: &mutable [cmnt]) { log ">>> consume comment"; if rdr.curr() == '/' && rdr.next() == '/' { @@ -688,7 +690,7 @@ fn consume_comment(rdr: &reader, code_to_the_left: bool, log "<<< consume comment"; } -fn is_lit(t: &token::token) -> bool { +fn is_lit(t: token::token) -> bool { ret alt t { token::LIT_INT(_) { true } token::LIT_UINT(_) { true } @@ -704,7 +706,7 @@ fn is_lit(t: &token::token) -> bool { type lit = {lit: str, pos: uint}; -fn gather_comments_and_literals(cm: &codemap::codemap, path: &str, +fn gather_comments_and_literals(cm: codemap::codemap, path: str, srdr: io::reader) -> {cmnts: [cmnt], lits: [lit]} { let src = str::unsafe_from_bytes(srdr.read_whole_stream()); diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index a6ffde02c55..3d115197794 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -25,7 +25,7 @@ tag ty_or_bang { a_ty(@ast::ty); a_bang; } type parse_sess = @{cm: codemap::codemap, mutable next_id: node_id}; -fn next_node_id(sess: &parse_sess) -> node_id { +fn next_node_id(sess: parse_sess) -> node_id { let rv = sess.next_id; sess.next_id += 1; ret rv; @@ -37,8 +37,8 @@ type parser = fn bump(); fn swap(token::token, uint, uint); fn look_ahead(uint) -> token::token; - fn fatal(&str) -> ! ; - fn warn(&str); + fn fatal(str) -> ! ; + fn warn(str); fn restrict(restriction); fn get_restriction() -> restriction; fn get_file_type() -> file_type; @@ -59,7 +59,7 @@ type parser = fn get_sess() -> parse_sess; }; -fn new_parser_from_file(sess: parse_sess, cfg: &ast::crate_cfg, path: &str, +fn new_parser_from_file(sess: parse_sess, cfg: ast::crate_cfg, path: str, chpos: uint, byte_pos: uint, ftype: file_type) -> parser { let src = io::read_whole_file_str(path); @@ -70,7 +70,7 @@ fn new_parser_from_file(sess: parse_sess, cfg: &ast::crate_cfg, path: &str, ret new_parser(sess, cfg, rdr, ftype); } -fn new_parser(sess: parse_sess, cfg: &ast::crate_cfg, rdr: lexer::reader, +fn new_parser(sess: parse_sess, cfg: ast::crate_cfg, rdr: lexer::reader, ftype: file_type) -> parser { obj stdio_parser(sess: parse_sess, cfg: ast::crate_cfg, @@ -108,11 +108,11 @@ fn new_parser(sess: parse_sess, cfg: &ast::crate_cfg, rdr: lexer::reader, } ret buffer[distance - 1u].tok; } - fn fatal(m: &str) -> ! { + fn fatal(m: str) -> ! { codemap::emit_error(some(self.get_span()), m, sess.cm); fail; } - fn warn(m: &str) { + fn warn(m: str) { codemap::emit_warning(some(self.get_span()), m, sess.cm); } fn restrict(r: restriction) { restr = r; } @@ -185,13 +185,13 @@ fn bad_expr_word_table() -> hashmap<str, ()> { ret words; } -fn unexpected(p: &parser, t: token::token) -> ! { +fn unexpected(p: parser, t: token::token) -> ! { let s: str = "unexpected token: "; s += token::to_str(p.get_reader(), t); p.fatal(s); } -fn expect(p: &parser, t: token::token) { +fn expect(p: parser, t: token::token) { if p.peek() == t { p.bump(); } else { @@ -203,7 +203,7 @@ fn expect(p: &parser, t: token::token) { } } -fn expect_gt(p: &parser) { +fn expect_gt(p: parser) { if p.peek() == token::GT { p.bump(); } else if p.peek() == token::BINOP(token::LSR) { @@ -219,34 +219,34 @@ fn expect_gt(p: &parser) { } } -fn spanned<@T>(lo: uint, hi: uint, node: &T) -> spanned<T> { +fn spanned<@T>(lo: uint, hi: uint, node: T) -> spanned<T> { ret {node: node, span: ast_util::mk_sp(lo, hi)}; } -fn parse_ident(p: &parser) -> ast::ident { +fn parse_ident(p: parser) -> ast::ident { alt p.peek() { token::IDENT(i, _) { p.bump(); ret p.get_str(i); } _ { p.fatal("expecting ident"); } } } -fn parse_value_ident(p: &parser) -> ast::ident { +fn parse_value_ident(p: parser) -> ast::ident { check_bad_word(p); ret parse_ident(p); } -fn eat(p: &parser, tok: &token::token) -> bool { +fn eat(p: parser, tok: token::token) -> bool { ret if p.peek() == tok { p.bump(); true } else { false }; } -fn is_word(p: &parser, word: &str) -> bool { +fn is_word(p: parser, word: str) -> bool { ret alt p.peek() { token::IDENT(sid, false) { str::eq(word, p.get_str(sid)) } _ { false } }; } -fn eat_word(p: &parser, word: &str) -> bool { +fn eat_word(p: parser, word: str) -> bool { alt p.peek() { token::IDENT(sid, false) { if str::eq(word, p.get_str(sid)) { @@ -258,14 +258,14 @@ fn eat_word(p: &parser, word: &str) -> bool { } } -fn expect_word(p: &parser, word: &str) { +fn expect_word(p: parser, word: str) { if !eat_word(p, word) { p.fatal("expecting " + word + ", found " + token::to_str(p.get_reader(), p.peek())); } } -fn check_bad_word(p: &parser) { +fn check_bad_word(p: parser) { alt p.peek() { token::IDENT(sid, false) { let w = p.get_str(sid); @@ -277,15 +277,16 @@ fn check_bad_word(p: &parser) { } } -fn parse_ty_fn(proto: ast::proto, p: &parser) -> ast::ty_ { - fn parse_fn_input_ty(p: &parser) -> ast::ty_arg { +fn parse_ty_fn(proto: ast::proto, p: parser) -> ast::ty_ { + fn parse_fn_input_ty(p: parser) -> ast::ty_arg { let lo = p.get_lo_pos(); + let mode = parse_arg_mode(p); // Ignore arg name, if present if is_plain_ident(p) && p.look_ahead(1u) == token::COLON { p.bump(); p.bump(); } - let mode = parse_arg_mode(p); + if mode == ast::by_ref { mode = parse_arg_mode(p); } let t = parse_ty(p, false); ret spanned(lo, t.span.hi, {mode: mode, ty: t}); } @@ -312,7 +313,7 @@ fn parse_ty_fn(proto: ast::proto, p: &parser) -> ast::ty_ { ret ast::ty_fn(proto, inputs.node, output, cf, constrs); } -fn parse_proto(p: &parser) -> ast::proto { +fn parse_proto(p: parser) -> ast::proto { if eat_word(p, "iter") { ret ast::proto_iter; } else if eat_word(p, "fn") { @@ -322,8 +323,8 @@ fn parse_proto(p: &parser) -> ast::proto { } else { unexpected(p, p.peek()); } } -fn parse_ty_obj(p: &parser, hi: &mutable uint) -> ast::ty_ { - fn parse_method_sig(p: &parser) -> ast::ty_method { +fn parse_ty_obj(p: parser, hi: &mutable uint) -> ast::ty_ { + fn parse_method_sig(p: parser) -> ast::ty_method { let flo = p.get_lo_pos(); let proto: ast::proto = parse_proto(p); let ident = parse_value_ident(p); @@ -347,13 +348,13 @@ fn parse_ty_obj(p: &parser, hi: &mutable uint) -> ast::ty_ { ret ast::ty_obj(meths.node); } -fn parse_mt(p: &parser) -> ast::mt { +fn parse_mt(p: parser) -> ast::mt { let mut = parse_mutability(p); let t = parse_ty(p, false); ret {ty: t, mut: mut}; } -fn parse_ty_field(p: &parser) -> ast::ty_field { +fn parse_ty_field(p: parser) -> ast::ty_field { let lo = p.get_lo_pos(); let mut = parse_mutability(p); let id = parse_ident(p); @@ -364,13 +365,13 @@ fn parse_ty_field(p: &parser) -> ast::ty_field { // if i is the jth ident in args, return j // otherwise, fail -fn ident_index(p: &parser, args: &[ast::arg], i: &ast::ident) -> uint { +fn ident_index(p: parser, args: [ast::arg], i: ast::ident) -> uint { let j = 0u; for a: ast::arg in args { if a.ident == i { ret j; } j += 1u; } p.fatal("Unbound variable " + i + " in constraint arg"); } -fn parse_type_constr_arg(p: &parser) -> @ast::ty_constr_arg { +fn parse_type_constr_arg(p: parser) -> @ast::ty_constr_arg { let sp = p.get_span(); let carg = ast::carg_base; expect(p, token::BINOP(token::STAR)); @@ -384,7 +385,7 @@ fn parse_type_constr_arg(p: &parser) -> @ast::ty_constr_arg { ret @{node: carg, span: sp}; } -fn parse_constr_arg(args: &[ast::arg], p: &parser) -> @ast::constr_arg { +fn parse_constr_arg(args: [ast::arg], p: parser) -> @ast::constr_arg { let sp = p.get_span(); let carg = ast::carg_base; if p.peek() == token::BINOP(token::STAR) { @@ -396,7 +397,7 @@ fn parse_constr_arg(args: &[ast::arg], p: &parser) -> @ast::constr_arg { ret @{node: carg, span: sp}; } -fn parse_ty_constr(fn_args: &[ast::arg], p: &parser) -> @ast::constr { +fn parse_ty_constr(fn_args: [ast::arg], p: parser) -> @ast::constr { let lo = p.get_lo_pos(); let path = parse_path(p); let pf = bind parse_constr_arg(fn_args, _); @@ -406,7 +407,7 @@ fn parse_ty_constr(fn_args: &[ast::arg], p: &parser) -> @ast::constr { {path: path, args: args.node, id: p.get_id()}); } -fn parse_constr_in_type(p: &parser) -> @ast::ty_constr { +fn parse_constr_in_type(p: parser) -> @ast::ty_constr { let lo = p.get_lo_pos(); let path = parse_path(p); let args: [@ast::ty_constr_arg] = @@ -418,8 +419,8 @@ fn parse_constr_in_type(p: &parser) -> @ast::ty_constr { } -fn parse_constrs<T>(pser: fn(&parser) -> @ast::constr_general<T>, p: &parser) - -> [@ast::constr_general<T>] { +fn parse_constrs<T>(pser: fn(parser) -> @ast::constr_general<T>, p: parser) -> + [@ast::constr_general<T>] { let constrs: [@ast::constr_general<T>] = []; while true { let constr = pser(p); @@ -429,11 +430,11 @@ fn parse_constrs<T>(pser: fn(&parser) -> @ast::constr_general<T>, p: &parser) constrs } -fn parse_type_constraints(p: &parser) -> [@ast::ty_constr] { +fn parse_type_constraints(p: parser) -> [@ast::ty_constr] { ret parse_constrs(parse_constr_in_type, p); } -fn parse_ty_postfix(orig_t: ast::ty_, p: &parser, colons_before_params: bool) +fn parse_ty_postfix(orig_t: ast::ty_, p: parser, colons_before_params: bool) -> @ast::ty { let lo = p.get_lo_pos(); @@ -460,14 +461,14 @@ fn parse_ty_postfix(orig_t: ast::ty_, p: &parser, colons_before_params: bool) } } -fn parse_ty_or_bang(p: &parser) -> ty_or_bang { +fn parse_ty_or_bang(p: parser) -> ty_or_bang { alt p.peek() { token::NOT. { p.bump(); ret a_bang; } _ { ret a_ty(parse_ty(p, false)); } } } -fn parse_ty(p: &parser, colons_before_params: bool) -> @ast::ty { +fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty { let lo = p.get_lo_pos(); let hi = lo; let t: ast::ty_; @@ -578,33 +579,35 @@ fn parse_ty(p: &parser, colons_before_params: bool) -> @ast::ty { ret parse_ty_postfix(t, p, colons_before_params); } -fn parse_arg_mode(p: &parser) -> ast::mode { - let mode = ast::by_ref; +fn parse_arg_mode(p: parser) -> ast::mode { if eat(p, token::BINOP(token::AND)) { - if eat_word(p, "mutable") { mode = ast::by_mut_ref; } + eat_word(p, "mutable"); + ret ast::by_mut_ref; } else if eat(p, token::BINOP(token::MINUS)) { - mode = ast::by_move; + ret ast::by_move; + } else { + ret ast::by_ref; } - ret mode; } -fn parse_arg(p: &parser) -> ast::arg { +fn parse_arg(p: parser) -> ast::arg { + let m = parse_arg_mode(p); let i = parse_value_ident(p); expect(p, token::COLON); - let m = parse_arg_mode(p); + if m == ast::by_ref { m = parse_arg_mode(p); } let t = parse_ty(p, false); ret {mode: m, ty: t, ident: i, id: p.get_id()}; } -fn parse_fn_block_arg(p: &parser) -> ast::arg { +fn parse_fn_block_arg(p: parser) -> ast::arg { let m = parse_arg_mode(p); let i = parse_value_ident(p); let t = @spanned(p.get_lo_pos(), p.get_hi_pos(), ast::ty_infer); ret {mode: m, ty: t, ident: i, id: p.get_id()}; } -fn parse_seq_to_before_gt<T>(sep: option::t<token::token>, - f: fn(&parser) -> T, p: &parser) -> [T] { +fn parse_seq_to_before_gt<T>(sep: option::t<token::token>, f: fn(parser) -> T, + p: parser) -> [T] { let first = true; let v = []; while p.peek() != token::GT && p.peek() != token::BINOP(token::LSR) && @@ -619,16 +622,16 @@ fn parse_seq_to_before_gt<T>(sep: option::t<token::token>, ret v; } -fn parse_seq_to_gt<T>(sep: option::t<token::token>, f: fn(&parser) -> T, - p: &parser) -> [T] { +fn parse_seq_to_gt<T>(sep: option::t<token::token>, f: fn(parser) -> T, + p: parser) -> [T] { let v = parse_seq_to_before_gt(sep, f, p); expect_gt(p); ret v; } -fn parse_seq_lt_gt<T>(sep: option::t<token::token>, f: fn(&parser) -> T, - p: &parser) -> spanned<[T]> { +fn parse_seq_lt_gt<T>(sep: option::t<token::token>, f: fn(parser) -> T, + p: parser) -> spanned<[T]> { let lo = p.get_lo_pos(); expect(p, token::LT); let result = parse_seq_to_before_gt::<T>(sep, f, p); @@ -638,14 +641,14 @@ fn parse_seq_lt_gt<T>(sep: option::t<token::token>, f: fn(&parser) -> T, } fn parse_seq_to_end<T>(ket: token::token, sep: option::t<token::token>, - f: fn(&parser) -> T, p: &parser) -> [T] { + f: fn(parser) -> T, p: parser) -> [T] { let val = parse_seq_to_before_end(ket, sep, f, p); p.bump(); ret val; } fn parse_seq_to_before_end<T>(ket: token::token, sep: option::t<token::token>, - f: fn(&parser) -> T, p: &parser) -> [T] { + f: fn(parser) -> T, p: parser) -> [T] { let first: bool = true; let v: [T] = []; while p.peek() != ket { @@ -660,7 +663,7 @@ fn parse_seq_to_before_end<T>(ket: token::token, sep: option::t<token::token>, fn parse_seq<T>(bra: token::token, ket: token::token, - sep: option::t<token::token>, f: fn(&parser) -> T, p: &parser) + sep: option::t<token::token>, f: fn(parser) -> T, p: parser) -> spanned<[T]> { let lo = p.get_lo_pos(); expect(p, bra); @@ -671,7 +674,7 @@ fn parse_seq<T>(bra: token::token, ket: token::token, } -fn parse_lit(p: &parser) -> ast::lit { +fn parse_lit(p: parser) -> ast::lit { let sp = p.get_span(); let lit: ast::lit_ = ast::lit_nil; if eat_word(p, "true") { @@ -712,11 +715,11 @@ fn is_ident(t: token::token) -> bool { ret false; } -fn is_plain_ident(p: &parser) -> bool { +fn is_plain_ident(p: parser) -> bool { ret alt p.peek() { token::IDENT(_, false) { true } _ { false } }; } -fn parse_path(p: &parser) -> ast::path { +fn parse_path(p: parser) -> ast::path { let lo = p.get_lo_pos(); let hi = lo; @@ -744,7 +747,7 @@ fn parse_path(p: &parser) -> ast::path { ret spanned(lo, hi, {global: global, idents: ids, types: []}); } -fn parse_path_and_ty_param_substs(p: &parser) -> ast::path { +fn parse_path_and_ty_param_substs(p: parser) -> ast::path { let lo = p.get_lo_pos(); let path = parse_path(p); if p.peek() == token::MOD_SEP { @@ -762,7 +765,7 @@ fn parse_path_and_ty_param_substs(p: &parser) -> ast::path { ret path; } -fn parse_mutability(p: &parser) -> ast::mutability { +fn parse_mutability(p: parser) -> ast::mutability { if eat_word(p, "mutable") { if p.peek() == token::QUES { p.bump(); ret ast::maybe_mut; } ret ast::mut; @@ -770,7 +773,7 @@ fn parse_mutability(p: &parser) -> ast::mutability { ret ast::imm; } -fn parse_field(p: &parser, sep: &token::token) -> ast::field { +fn parse_field(p: parser, sep: token::token) -> ast::field { let lo = p.get_lo_pos(); let m = parse_mutability(p); let i = parse_ident(p); @@ -779,17 +782,17 @@ fn parse_field(p: &parser, sep: &token::token) -> ast::field { ret spanned(lo, e.span.hi, {mut: m, ident: i, expr: e}); } -fn mk_expr(p: &parser, lo: uint, hi: uint, node: &ast::expr_) -> @ast::expr { +fn mk_expr(p: parser, lo: uint, hi: uint, node: ast::expr_) -> @ast::expr { ret @{id: p.get_id(), node: node, span: ast_util::mk_sp(lo, hi)}; } -fn mk_mac_expr(p: &parser, lo: uint, hi: uint, m: &ast::mac_) -> @ast::expr { +fn mk_mac_expr(p: parser, lo: uint, hi: uint, m: ast::mac_) -> @ast::expr { ret @{id: p.get_id(), node: ast::expr_mac({node: m, span: ast_util::mk_sp(lo, hi)}), span: ast_util::mk_sp(lo, hi)}; } -fn parse_bottom_expr(p: &parser) -> @ast::expr { +fn parse_bottom_expr(p: parser) -> @ast::expr { let lo = p.get_lo_pos(); let hi = p.get_hi_pos(); @@ -908,7 +911,7 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { ex = ast::expr_anon_obj(ob); } else if eat_word(p, "bind") { let e = parse_expr_res(p, RESTRICT_NO_CALL_EXPRS); - fn parse_expr_opt(p: &parser) -> option::t<@ast::expr> { + fn parse_expr_opt(p: parser) -> option::t<@ast::expr> { alt p.peek() { token::UNDERSCORE. { p.bump(); ret none; } _ { ret some(parse_expr(p)); } @@ -1014,13 +1017,13 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { ret mk_expr(p, lo, hi, ex); } -fn parse_syntax_ext(p: &parser) -> @ast::expr { +fn parse_syntax_ext(p: parser) -> @ast::expr { let lo = p.get_lo_pos(); expect(p, token::POUND); ret parse_syntax_ext_naked(p, lo); } -fn parse_syntax_ext_naked(p: &parser, lo: uint) -> @ast::expr { +fn parse_syntax_ext_naked(p: parser, lo: uint) -> @ast::expr { let pth = parse_path(p); if vec::len(pth.node.idents) == 0u { p.fatal("expected a syntax expander name"); @@ -1039,17 +1042,17 @@ fn parse_syntax_ext_naked(p: &parser, lo: uint) -> @ast::expr { ret mk_mac_expr(p, lo, hi, ast::mac_invoc(pth, e, none)); } -fn parse_self_method(p: &parser) -> @ast::expr { +fn parse_self_method(p: parser) -> @ast::expr { let sp = p.get_span(); let f_name: ast::ident = parse_ident(p); ret mk_expr(p, sp.lo, sp.hi, ast::expr_self_method(f_name)); } -fn parse_dot_or_call_expr(p: &parser) -> @ast::expr { +fn parse_dot_or_call_expr(p: parser) -> @ast::expr { ret parse_dot_or_call_expr_with(p, parse_bottom_expr(p)); } -fn parse_dot_or_call_expr_with(p: &parser, e: @ast::expr) -> @ast::expr { +fn parse_dot_or_call_expr_with(p: parser, e: @ast::expr) -> @ast::expr { let lo = e.span.lo; let hi = e.span.hi; while true { @@ -1092,7 +1095,7 @@ fn parse_dot_or_call_expr_with(p: &parser, e: @ast::expr) -> @ast::expr { ret e; } -fn parse_prefix_expr(p: &parser) -> @ast::expr { +fn parse_prefix_expr(p: parser) -> @ast::expr { if eat_word(p, "mutable") { p.warn("ignoring deprecated 'mutable' prefix operator"); } @@ -1136,7 +1139,7 @@ fn parse_prefix_expr(p: &parser) -> @ast::expr { ret mk_expr(p, lo, hi, ex); } -fn parse_ternary(p: &parser) -> @ast::expr { +fn parse_ternary(p: parser) -> @ast::expr { let cond_expr = parse_binops(p); if p.peek() == token::QUES { p.bump(); @@ -1175,7 +1178,7 @@ fn prec_table() -> @[op_spec] { {tok: token::OROR, op: ast::or, prec: 1}]; } -fn parse_binops(p: &parser) -> @ast::expr { +fn parse_binops(p: parser) -> @ast::expr { ret parse_more_binops(p, parse_prefix_expr(p), 0); } @@ -1184,7 +1187,7 @@ const unop_prec: int = 100; const as_prec: int = 5; const ternary_prec: int = 0; -fn parse_more_binops(p: &parser, lhs: @ast::expr, min_prec: int) -> +fn parse_more_binops(p: parser, lhs: @ast::expr, min_prec: int) -> @ast::expr { let peeked = p.peek(); for cur: op_spec in *p.get_prec_table() { @@ -1206,7 +1209,7 @@ fn parse_more_binops(p: &parser, lhs: @ast::expr, min_prec: int) -> ret lhs; } -fn parse_assign_expr(p: &parser) -> @ast::expr { +fn parse_assign_expr(p: parser) -> @ast::expr { let lo = p.get_lo_pos(); let lhs = parse_ternary(p); alt p.peek() { @@ -1249,7 +1252,7 @@ fn parse_assign_expr(p: &parser) -> @ast::expr { ret lhs; } -fn parse_if_expr_1(p: &parser) -> +fn parse_if_expr_1(p: parser) -> {cond: @ast::expr, then: ast::blk, els: option::t<@ast::expr>, @@ -1268,7 +1271,7 @@ fn parse_if_expr_1(p: &parser) -> ret {cond: cond, then: thn, els: els, lo: lo, hi: hi}; } -fn parse_if_expr(p: &parser) -> @ast::expr { +fn parse_if_expr(p: parser) -> @ast::expr { if eat_word(p, "check") { let q = parse_if_expr_1(p); ret mk_expr(p, q.lo, q.hi, ast::expr_if_check(q.cond, q.then, q.els)); @@ -1278,7 +1281,7 @@ fn parse_if_expr(p: &parser) -> @ast::expr { } } -fn parse_fn_expr(p: &parser, proto: ast::proto) -> @ast::expr { +fn parse_fn_expr(p: parser, proto: ast::proto) -> @ast::expr { let lo = p.get_last_lo_pos(); let decl = parse_fn_decl(p, ast::impure_fn, ast::il_normal); let body = parse_block(p); @@ -1286,7 +1289,7 @@ fn parse_fn_expr(p: &parser, proto: ast::proto) -> @ast::expr { ret mk_expr(p, lo, body.span.hi, ast::expr_fn(_fn)); } -fn parse_fn_block_expr(p: &parser) -> @ast::expr { +fn parse_fn_block_expr(p: parser) -> @ast::expr { let lo = p.get_last_lo_pos(); let decl = parse_fn_block_decl(p); let body = parse_block_tail(p, lo, ast::checked); @@ -1294,7 +1297,7 @@ fn parse_fn_block_expr(p: &parser) -> @ast::expr { ret mk_expr(p, lo, body.span.hi, ast::expr_fn(_fn)); } -fn parse_else_expr(p: &parser) -> @ast::expr { +fn parse_else_expr(p: parser) -> @ast::expr { if eat_word(p, "if") { ret parse_if_expr(p); } else { @@ -1303,7 +1306,7 @@ fn parse_else_expr(p: &parser) -> @ast::expr { } } -fn parse_for_expr(p: &parser) -> @ast::expr { +fn parse_for_expr(p: parser) -> @ast::expr { let lo = p.get_last_lo_pos(); let is_each = eat_word(p, "each"); let decl = parse_local(p, false); @@ -1316,7 +1319,7 @@ fn parse_for_expr(p: &parser) -> @ast::expr { } else { ret mk_expr(p, lo, hi, ast::expr_for(decl, seq, body)); } } -fn parse_while_expr(p: &parser) -> @ast::expr { +fn parse_while_expr(p: parser) -> @ast::expr { let lo = p.get_last_lo_pos(); let cond = parse_expr(p); let body = parse_block(p); @@ -1324,7 +1327,7 @@ fn parse_while_expr(p: &parser) -> @ast::expr { ret mk_expr(p, lo, hi, ast::expr_while(cond, body)); } -fn parse_do_while_expr(p: &parser) -> @ast::expr { +fn parse_do_while_expr(p: parser) -> @ast::expr { let lo = p.get_last_lo_pos(); let body = parse_block(p); expect_word(p, "while"); @@ -1333,7 +1336,7 @@ fn parse_do_while_expr(p: &parser) -> @ast::expr { ret mk_expr(p, lo, hi, ast::expr_do_while(body, cond)); } -fn parse_alt_expr(p: &parser) -> @ast::expr { +fn parse_alt_expr(p: parser) -> @ast::expr { let lo = p.get_last_lo_pos(); let discriminant = parse_expr(p); expect(p, token::LBRACE); @@ -1350,11 +1353,11 @@ fn parse_alt_expr(p: &parser) -> @ast::expr { ret mk_expr(p, lo, hi, ast::expr_alt(discriminant, arms)); } -fn parse_expr(p: &parser) -> @ast::expr { +fn parse_expr(p: parser) -> @ast::expr { ret parse_expr_res(p, UNRESTRICTED); } -fn parse_expr_res(p: &parser, r: restriction) -> @ast::expr { +fn parse_expr_res(p: parser, r: restriction) -> @ast::expr { let old = p.get_restriction(); p.restrict(r); let e = parse_assign_expr(p); @@ -1362,7 +1365,7 @@ fn parse_expr_res(p: &parser, r: restriction) -> @ast::expr { ret e; } -fn parse_initializer(p: &parser) -> option::t<ast::initializer> { +fn parse_initializer(p: parser) -> option::t<ast::initializer> { alt p.peek() { token::EQ. { p.bump(); @@ -1375,6 +1378,7 @@ fn parse_initializer(p: &parser) -> option::t<ast::initializer> { + // Now that the the channel is the first argument to receive, // combining it with an initializer doesn't really make sense. // case (token::RECV) { @@ -1388,7 +1392,7 @@ fn parse_initializer(p: &parser) -> option::t<ast::initializer> { } } -fn parse_pats(p: &parser) -> [@ast::pat] { +fn parse_pats(p: parser) -> [@ast::pat] { let pats = []; while true { pats += [parse_pat(p)]; @@ -1397,7 +1401,7 @@ fn parse_pats(p: &parser) -> [@ast::pat] { ret pats; } -fn parse_pat(p: &parser) -> @ast::pat { +fn parse_pat(p: parser) -> @ast::pat { let lo = p.get_lo_pos(); let hi = p.get_hi_pos(); let pat; @@ -1503,7 +1507,7 @@ fn parse_pat(p: &parser) -> @ast::pat { ret @{id: p.get_id(), node: pat, span: ast_util::mk_sp(lo, hi)}; } -fn parse_local(p: &parser, allow_init: bool) -> @ast::local { +fn parse_local(p: parser, allow_init: bool) -> @ast::local { let lo = p.get_lo_pos(); let pat = parse_pat(p); let ty = @spanned(lo, lo, ast::ty_infer); @@ -1513,7 +1517,7 @@ fn parse_local(p: &parser, allow_init: bool) -> @ast::local { {ty: ty, pat: pat, init: init, id: p.get_id()}); } -fn parse_let(p: &parser) -> @ast::decl { +fn parse_let(p: parser) -> @ast::decl { let lo = p.get_lo_pos(); let locals = [parse_local(p, true)]; while p.peek() == token::COMMA { @@ -1523,19 +1527,19 @@ fn parse_let(p: &parser) -> @ast::decl { ret @spanned(lo, p.get_last_hi_pos(), ast::decl_local(locals)); } -fn parse_stmt(p: &parser) -> @ast::stmt { +fn parse_stmt(p: parser) -> @ast::stmt { if p.get_file_type() == SOURCE_FILE { ret parse_source_stmt(p); } else { ret parse_crate_stmt(p); } } -fn parse_crate_stmt(p: &parser) -> @ast::stmt { +fn parse_crate_stmt(p: parser) -> @ast::stmt { let cdir = parse_crate_directive(p, []); ret @spanned(cdir.span.lo, cdir.span.hi, ast::stmt_crate_directive(@cdir)); } -fn parse_source_stmt(p: &parser) -> @ast::stmt { +fn parse_source_stmt(p: parser) -> @ast::stmt { let lo = p.get_lo_pos(); if eat_word(p, "let") { let decl = parse_let(p); @@ -1582,7 +1586,7 @@ fn stmt_to_expr(stmt: @ast::stmt) -> option::t<@ast::expr> { ret alt stmt.node { ast::stmt_expr(e, _) { some(e) } _ { none } }; } -fn stmt_ends_with_semi(stmt: &ast::stmt) -> bool { +fn stmt_ends_with_semi(stmt: ast::stmt) -> bool { alt stmt.node { ast::stmt_decl(d, _) { ret alt d.node { @@ -1636,6 +1640,7 @@ fn stmt_ends_with_semi(stmt: &ast::stmt) -> bool { + // We should not be calling this on a cdir. ast::stmt_crate_directive(cdir) { fail; @@ -1643,7 +1648,7 @@ fn stmt_ends_with_semi(stmt: &ast::stmt) -> bool { } } -fn parse_block(p: &parser) -> ast::blk { +fn parse_block(p: parser) -> ast::blk { let lo = p.get_lo_pos(); if eat_word(p, "unchecked") { be parse_block_tail(p, lo, ast::unchecked); @@ -1657,7 +1662,7 @@ fn parse_block(p: &parser) -> ast::blk { // I guess that also means "already parsed the 'impure'" if // necessary, and this should take a qualifier. // some blocks start with "#{"... -fn parse_block_tail(p: &parser, lo: uint, s: ast::check_mode) -> ast::blk { +fn parse_block_tail(p: parser, lo: uint, s: ast::check_mode) -> ast::blk { let stmts: [@ast::stmt] = []; let expr: option::t<@ast::expr> = none; while p.peek() != token::RBRACE { @@ -1702,7 +1707,7 @@ fn parse_block_tail(p: &parser, lo: uint, s: ast::check_mode) -> ast::blk { ret spanned(lo, hi, bloc); } -fn parse_ty_param(p: &parser) -> ast::ty_param { +fn parse_ty_param(p: parser) -> ast::ty_param { let k = alt p.peek() { token::TILDE. { p.bump(); ast::kind_unique } @@ -1712,7 +1717,7 @@ fn parse_ty_param(p: &parser) -> ast::ty_param { ret {ident: parse_ident(p), kind: k}; } -fn parse_ty_params(p: &parser) -> [ast::ty_param] { +fn parse_ty_params(p: parser) -> [ast::ty_param] { let ty_params: [ast::ty_param] = []; if p.peek() == token::LT { p.bump(); @@ -1726,7 +1731,7 @@ fn parse_ty_params(p: &parser) -> [ast::ty_param] { ret ty_params; } -fn parse_fn_decl(p: &parser, purity: ast::purity, il: ast::inlineness) -> +fn parse_fn_decl(p: parser, purity: ast::purity, il: ast::inlineness) -> ast::fn_decl { let inputs: ast::spanned<[ast::arg]> = parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), parse_arg, @@ -1766,7 +1771,7 @@ fn parse_fn_decl(p: &parser, purity: ast::purity, il: ast::inlineness) -> } } -fn parse_fn_block_decl(p: &parser) -> ast::fn_decl { +fn parse_fn_block_decl(p: parser) -> ast::fn_decl { let inputs: ast::spanned<[ast::arg]> = parse_seq(token::BINOP(token::OR), token::BINOP(token::OR), some(token::COMMA), parse_fn_block_arg, p); @@ -1778,21 +1783,21 @@ fn parse_fn_block_decl(p: &parser) -> ast::fn_decl { constraints: []}; } -fn parse_fn(p: &parser, proto: ast::proto, purity: ast::purity, +fn parse_fn(p: parser, proto: ast::proto, purity: ast::purity, il: ast::inlineness) -> ast::_fn { let decl = parse_fn_decl(p, purity, il); let body = parse_block(p); ret {decl: decl, proto: proto, body: body}; } -fn parse_fn_header(p: &parser) -> {ident: ast::ident, tps: [ast::ty_param]} { +fn parse_fn_header(p: parser) -> {ident: ast::ident, tps: [ast::ty_param]} { let id = parse_value_ident(p); let ty_params = parse_ty_params(p); ret {ident: id, tps: ty_params}; } -fn mk_item(p: &parser, lo: uint, hi: uint, ident: &ast::ident, - node: &ast::item_, attrs: &[ast::attribute]) -> @ast::item { +fn mk_item(p: parser, lo: uint, hi: uint, ident: ast::ident, node: ast::item_, + attrs: [ast::attribute]) -> @ast::item { ret @{ident: ident, attrs: attrs, id: p.get_id(), @@ -1800,8 +1805,8 @@ fn mk_item(p: &parser, lo: uint, hi: uint, ident: &ast::ident, span: ast_util::mk_sp(lo, hi)}; } -fn parse_item_fn_or_iter(p: &parser, purity: ast::purity, proto: ast::proto, - attrs: &[ast::attribute], il: ast::inlineness) -> +fn parse_item_fn_or_iter(p: parser, purity: ast::purity, proto: ast::proto, + attrs: [ast::attribute], il: ast::inlineness) -> @ast::item { let lo = p.get_last_lo_pos(); let t = parse_fn_header(p); @@ -1810,7 +1815,7 @@ fn parse_item_fn_or_iter(p: &parser, purity: ast::purity, proto: ast::proto, attrs); } -fn parse_obj_field(p: &parser) -> ast::obj_field { +fn parse_obj_field(p: parser) -> ast::obj_field { let mut = parse_mutability(p); let ident = parse_value_ident(p); expect(p, token::COLON); @@ -1818,7 +1823,7 @@ fn parse_obj_field(p: &parser) -> ast::obj_field { ret {mut: mut, ty: ty, ident: ident, id: p.get_id()}; } -fn parse_anon_obj_field(p: &parser) -> ast::anon_obj_field { +fn parse_anon_obj_field(p: parser) -> ast::anon_obj_field { let mut = parse_mutability(p); let ident = parse_value_ident(p); expect(p, token::COLON); @@ -1828,7 +1833,7 @@ fn parse_anon_obj_field(p: &parser) -> ast::anon_obj_field { ret {mut: mut, ty: ty, expr: expr, ident: ident, id: p.get_id()}; } -fn parse_method(p: &parser) -> @ast::method { +fn parse_method(p: parser) -> @ast::method { let lo = p.get_lo_pos(); let proto = parse_proto(p); let ident = parse_value_ident(p); @@ -1837,7 +1842,7 @@ fn parse_method(p: &parser) -> @ast::method { ret @spanned(lo, f.body.span.hi, meth); } -fn parse_item_obj(p: &parser, attrs: &[ast::attribute]) -> @ast::item { +fn parse_item_obj(p: parser, attrs: [ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let ident = parse_value_ident(p); let ty_params = parse_ty_params(p); @@ -1854,7 +1859,7 @@ fn parse_item_obj(p: &parser, attrs: &[ast::attribute]) -> @ast::item { attrs); } -fn parse_item_res(p: &parser, attrs: &[ast::attribute]) -> @ast::item { +fn parse_item_res(p: parser, attrs: [ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let ident = parse_value_ident(p); let ty_params = parse_ty_params(p); @@ -1866,10 +1871,7 @@ fn parse_item_res(p: &parser, attrs: &[ast::attribute]) -> @ast::item { let dtor = parse_block(p); let decl = {inputs: - [{mode: ast::by_ref, - ty: t, - ident: arg_ident, - id: p.get_id()}], + [{mode: ast::by_ref, ty: t, ident: arg_ident, id: p.get_id()}], output: @spanned(lo, lo, ast::ty_nil), purity: ast::impure_fn, il: ast::il_normal, @@ -1880,8 +1882,8 @@ fn parse_item_res(p: &parser, attrs: &[ast::attribute]) -> @ast::item { ast::item_res(f, p.get_id(), ty_params, p.get_id()), attrs); } -fn parse_mod_items(p: &parser, term: token::token, - first_item_attrs: &[ast::attribute]) -> ast::_mod { +fn parse_mod_items(p: parser, term: token::token, + first_item_attrs: [ast::attribute]) -> ast::_mod { // Shouldn't be any view items since we've already parsed an item attr let view_items = if vec::len(first_item_attrs) == 0u { parse_view(p) } else { [] }; @@ -1901,7 +1903,7 @@ fn parse_mod_items(p: &parser, term: token::token, ret {view_items: view_items, items: items}; } -fn parse_item_const(p: &parser, attrs: &[ast::attribute]) -> @ast::item { +fn parse_item_const(p: parser, attrs: [ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let id = parse_value_ident(p); expect(p, token::COLON); @@ -1913,7 +1915,7 @@ fn parse_item_const(p: &parser, attrs: &[ast::attribute]) -> @ast::item { ret mk_item(p, lo, hi, id, ast::item_const(ty, e), attrs); } -fn parse_item_mod(p: &parser, attrs: &[ast::attribute]) -> @ast::item { +fn parse_item_mod(p: parser, attrs: [ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let id = parse_ident(p); expect(p, token::LBRACE); @@ -1925,7 +1927,7 @@ fn parse_item_mod(p: &parser, attrs: &[ast::attribute]) -> @ast::item { ret mk_item(p, lo, hi, id, ast::item_mod(m), attrs + inner_attrs.inner); } -fn parse_item_native_type(p: &parser, attrs: &[ast::attribute]) -> +fn parse_item_native_type(p: parser, attrs: [ast::attribute]) -> @ast::native_item { let t = parse_type_decl(p); let hi = p.get_hi_pos(); @@ -1937,7 +1939,7 @@ fn parse_item_native_type(p: &parser, attrs: &[ast::attribute]) -> span: ast_util::mk_sp(t.lo, hi)}; } -fn parse_item_native_fn(p: &parser, attrs: &[ast::attribute]) -> +fn parse_item_native_fn(p: parser, attrs: [ast::attribute]) -> @ast::native_item { let lo = p.get_last_lo_pos(); let t = parse_fn_header(p); @@ -1953,7 +1955,7 @@ fn parse_item_native_fn(p: &parser, attrs: &[ast::attribute]) -> span: ast_util::mk_sp(lo, hi)}; } -fn parse_native_item(p: &parser, attrs: &[ast::attribute]) -> +fn parse_native_item(p: parser, attrs: [ast::attribute]) -> @ast::native_item { if eat_word(p, "type") { ret parse_item_native_type(p, attrs); @@ -1962,8 +1964,8 @@ fn parse_native_item(p: &parser, attrs: &[ast::attribute]) -> } else { unexpected(p, p.peek()); } } -fn parse_native_mod_items(p: &parser, native_name: &str, abi: ast::native_abi, - first_item_attrs: &[ast::attribute]) -> +fn parse_native_mod_items(p: parser, native_name: str, abi: ast::native_abi, + first_item_attrs: [ast::attribute]) -> ast::native_mod { // Shouldn't be any view items since we've already parsed an item attr let view_items = @@ -1983,7 +1985,7 @@ fn parse_native_mod_items(p: &parser, native_name: &str, abi: ast::native_abi, items: items}; } -fn parse_item_native_mod(p: &parser, attrs: &[ast::attribute]) -> @ast::item { +fn parse_item_native_mod(p: parser, attrs: [ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let abi = ast::native_abi_cdecl; if !is_word(p, "mod") { @@ -2017,13 +2019,13 @@ fn parse_item_native_mod(p: &parser, attrs: &[ast::attribute]) -> @ast::item { ret mk_item(p, lo, hi, id, ast::item_native_mod(m), attrs + inner_attrs); } -fn parse_type_decl(p: &parser) -> {lo: uint, ident: ast::ident} { +fn parse_type_decl(p: parser) -> {lo: uint, ident: ast::ident} { let lo = p.get_last_lo_pos(); let id = parse_ident(p); ret {lo: lo, ident: id}; } -fn parse_item_type(p: &parser, attrs: &[ast::attribute]) -> @ast::item { +fn parse_item_type(p: parser, attrs: [ast::attribute]) -> @ast::item { let t = parse_type_decl(p); let tps = parse_ty_params(p); expect(p, token::EQ); @@ -2033,7 +2035,7 @@ fn parse_item_type(p: &parser, attrs: &[ast::attribute]) -> @ast::item { ret mk_item(p, t.lo, hi, t.ident, ast::item_ty(ty, tps), attrs); } -fn parse_item_tag(p: &parser, attrs: &[ast::attribute]) -> @ast::item { +fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); let id = parse_ident(p); let ty_params = parse_ty_params(p); @@ -2093,13 +2095,13 @@ fn parse_item_tag(p: &parser, attrs: &[ast::attribute]) -> @ast::item { ret mk_item(p, lo, hi, id, ast::item_tag(variants, ty_params), attrs); } -fn parse_auth(p: &parser) -> ast::_auth { +fn parse_auth(p: parser) -> ast::_auth { if eat_word(p, "unsafe") { ret ast::auth_unsafe; } else { unexpected(p, p.peek()); } } -fn parse_item(p: &parser, attrs: &[ast::attribute]) -> option::t<@ast::item> { +fn parse_item(p: parser, attrs: [ast::attribute]) -> option::t<@ast::item> { if eat_word(p, "const") { ret some(parse_item_const(p, attrs)); } else if eat_word(p, "inline") { @@ -2138,7 +2140,7 @@ fn parse_item(p: &parser, attrs: &[ast::attribute]) -> option::t<@ast::item> { // extensions, which both begin with token.POUND type attr_or_ext = option::t<either::t<[ast::attribute], @ast::expr>>; -fn parse_outer_attrs_or_ext(p: &parser) -> attr_or_ext { +fn parse_outer_attrs_or_ext(p: parser) -> attr_or_ext { if p.peek() == token::POUND { let lo = p.get_lo_pos(); p.bump(); @@ -2152,7 +2154,7 @@ fn parse_outer_attrs_or_ext(p: &parser) -> attr_or_ext { } // Parse attributes that appear before an item -fn parse_outer_attributes(p: &parser) -> [ast::attribute] { +fn parse_outer_attributes(p: parser) -> [ast::attribute] { let attrs: [ast::attribute] = []; while p.peek() == token::POUND { attrs += [parse_attribute(p, ast::attr_outer)]; @@ -2160,13 +2162,13 @@ fn parse_outer_attributes(p: &parser) -> [ast::attribute] { ret attrs; } -fn parse_attribute(p: &parser, style: ast::attr_style) -> ast::attribute { +fn parse_attribute(p: parser, style: ast::attr_style) -> ast::attribute { let lo = p.get_lo_pos(); expect(p, token::POUND); ret parse_attribute_naked(p, style, lo); } -fn parse_attribute_naked(p: &parser, style: ast::attr_style, lo: uint) -> +fn parse_attribute_naked(p: parser, style: ast::attr_style, lo: uint) -> ast::attribute { expect(p, token::LBRACKET); let meta_item = parse_meta_item(p); @@ -2181,7 +2183,7 @@ fn parse_attribute_naked(p: &parser, style: ast::attr_style, lo: uint) -> // next item (since we can't know whether the attribute is an inner attribute // of the containing item or an outer attribute of the first contained item // until we see the semi). -fn parse_inner_attrs_and_next(p: &parser) -> +fn parse_inner_attrs_and_next(p: parser) -> {inner: [ast::attribute], next: [ast::attribute]} { let inner_attrs: [ast::attribute] = []; let next_outer_attrs: [ast::attribute] = []; @@ -2202,7 +2204,7 @@ fn parse_inner_attrs_and_next(p: &parser) -> ret {inner: inner_attrs, next: next_outer_attrs}; } -fn parse_meta_item(p: &parser) -> @ast::meta_item { +fn parse_meta_item(p: parser) -> @ast::meta_item { let lo = p.get_lo_pos(); let ident = parse_ident(p); alt p.peek() { @@ -2224,22 +2226,22 @@ fn parse_meta_item(p: &parser) -> @ast::meta_item { } } -fn parse_meta_seq(p: &parser) -> [@ast::meta_item] { +fn parse_meta_seq(p: parser) -> [@ast::meta_item] { ret parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), parse_meta_item, p).node; } -fn parse_optional_meta(p: &parser) -> [@ast::meta_item] { +fn parse_optional_meta(p: parser) -> [@ast::meta_item] { alt p.peek() { token::LPAREN. { ret parse_meta_seq(p); } _ { ret []; } } } -fn parse_use(p: &parser) -> ast::view_item_ { +fn parse_use(p: parser) -> ast::view_item_ { let ident = parse_ident(p); let metadata = parse_optional_meta(p); ret ast::view_item_use(ident, metadata, p.get_id()); } -fn parse_rest_import_name(p: &parser, first: &ast::ident, +fn parse_rest_import_name(p: parser, first: ast::ident, def_ident: option::t<ast::ident>) -> ast::view_item_ { let identifiers: [ast::ident] = [first]; @@ -2262,6 +2264,7 @@ fn parse_rest_import_name(p: &parser, first: &ast::ident, + //the lexer can't tell the different kinds of stars apart ) : token::BINOP(token::STAR.) { glob = true; @@ -2270,8 +2273,9 @@ fn parse_rest_import_name(p: &parser, first: &ast::ident, + token::LBRACE. { - fn parse_import_ident(p: &parser) -> ast::import_ident { + fn parse_import_ident(p: parser) -> ast::import_ident { let lo = p.get_lo_pos(); let ident = parse_ident(p); let hi = p.get_hi_pos(); @@ -2288,6 +2292,7 @@ fn parse_rest_import_name(p: &parser, first: &ast::ident, + _ { p.fatal("expecting an identifier, or '*'"); } @@ -2317,7 +2322,7 @@ fn parse_rest_import_name(p: &parser, first: &ast::ident, } } -fn parse_full_import_name(p: &parser, def_ident: &ast::ident) -> +fn parse_full_import_name(p: parser, def_ident: ast::ident) -> ast::view_item_ { alt p.peek() { token::IDENT(i, _) { @@ -2328,7 +2333,7 @@ fn parse_full_import_name(p: &parser, def_ident: &ast::ident) -> } } -fn parse_import(p: &parser) -> ast::view_item_ { +fn parse_import(p: parser) -> ast::view_item_ { alt p.peek() { token::IDENT(i, _) { p.bump(); @@ -2344,14 +2349,14 @@ fn parse_import(p: &parser) -> ast::view_item_ { } } -fn parse_export(p: &parser) -> ast::view_item_ { +fn parse_export(p: parser) -> ast::view_item_ { let ids = parse_seq_to_before_end(token::SEMI, option::some(token::COMMA), parse_ident, p); ret ast::view_item_export(ids, p.get_id()); } -fn parse_view_item(p: &parser) -> @ast::view_item { +fn parse_view_item(p: parser) -> @ast::view_item { let lo = p.get_lo_pos(); let the_item = if eat_word(p, "use") { @@ -2364,7 +2369,7 @@ fn parse_view_item(p: &parser) -> @ast::view_item { ret @spanned(lo, hi, the_item); } -fn is_view_item(p: &parser) -> bool { +fn is_view_item(p: parser) -> bool { alt p.peek() { token::IDENT(sid, false) { let st = p.get_str(sid); @@ -2375,26 +2380,26 @@ fn is_view_item(p: &parser) -> bool { } } -fn parse_view(p: &parser) -> [@ast::view_item] { +fn parse_view(p: parser) -> [@ast::view_item] { let items: [@ast::view_item] = []; while is_view_item(p) { items += [parse_view_item(p)]; } ret items; } -fn parse_native_view(p: &parser) -> [@ast::view_item] { +fn parse_native_view(p: parser) -> [@ast::view_item] { let items: [@ast::view_item] = []; while is_view_item(p) { items += [parse_view_item(p)]; } ret items; } -fn parse_crate_from_source_file(input: &str, cfg: &ast::crate_cfg, - sess: &parse_sess) -> @ast::crate { +fn parse_crate_from_source_file(input: str, cfg: ast::crate_cfg, + sess: parse_sess) -> @ast::crate { let p = new_parser_from_file(sess, cfg, input, 0u, 0u, SOURCE_FILE); ret parse_crate_mod(p, cfg); } -fn parse_crate_from_source_str(name: &str, source: &str, cfg: &ast::crate_cfg, - sess: &parse_sess) -> @ast::crate { +fn parse_crate_from_source_str(name: str, source: str, cfg: ast::crate_cfg, + sess: parse_sess) -> @ast::crate { let ftype = SOURCE_FILE; let filemap = codemap::new_filemap(name, 0u, 0u); sess.cm.files += [filemap]; @@ -2405,7 +2410,7 @@ fn parse_crate_from_source_str(name: &str, source: &str, cfg: &ast::crate_cfg, } // Parses a source module as a crate -fn parse_crate_mod(p: &parser, _cfg: &ast::crate_cfg) -> @ast::crate { +fn parse_crate_mod(p: parser, _cfg: ast::crate_cfg) -> @ast::crate { let lo = p.get_lo_pos(); let crate_attrs = parse_inner_attrs_and_next(p); let first_item_outer_attrs = crate_attrs.next; @@ -2417,7 +2422,7 @@ fn parse_crate_mod(p: &parser, _cfg: &ast::crate_cfg) -> @ast::crate { config: p.get_cfg()}); } -fn parse_str(p: &parser) -> str { +fn parse_str(p: parser) -> str { alt p.peek() { token::LIT_STR(s) { p.bump(); ret p.get_str(s); } _ { fail; } @@ -2429,7 +2434,7 @@ fn parse_str(p: &parser) -> str { // Each crate file is a sequence of directives. // // Each directive imperatively extends its environment with 0 or more items. -fn parse_crate_directive(p: &parser, first_outer_attr: &[ast::attribute]) -> +fn parse_crate_directive(p: parser, first_outer_attr: [ast::attribute]) -> ast::crate_directive { // Collect the next attributes @@ -2450,6 +2455,7 @@ fn parse_crate_directive(p: &parser, first_outer_attr: &[ast::attribute]) -> + // mod x = "foo.rs"; token::SEMI. { let hi = p.get_hi_pos(); @@ -2459,6 +2465,7 @@ fn parse_crate_directive(p: &parser, first_outer_attr: &[ast::attribute]) -> + // mod x = "foo_dir" { ...directives... } token::LBRACE. { p.bump(); @@ -2487,8 +2494,8 @@ fn parse_crate_directive(p: &parser, first_outer_attr: &[ast::attribute]) -> } else { ret p.fatal("expected crate directive"); } } -fn parse_crate_directives(p: &parser, term: token::token, - first_outer_attr: &[ast::attribute]) -> +fn parse_crate_directives(p: parser, term: token::token, + first_outer_attr: [ast::attribute]) -> [@ast::crate_directive] { // This is pretty ugly. If we have an outer attribute then we can't accept @@ -2506,8 +2513,8 @@ fn parse_crate_directives(p: &parser, term: token::token, ret cdirs; } -fn parse_crate_from_crate_file(input: &str, cfg: &ast::crate_cfg, - sess: &parse_sess) -> @ast::crate { +fn parse_crate_from_crate_file(input: str, cfg: ast::crate_cfg, + sess: parse_sess) -> @ast::crate { let p = new_parser_from_file(sess, cfg, input, 0u, 0u, CRATE_FILE); let lo = p.get_lo_pos(); let prefix = std::fs::dirname(p.get_filemap().name); @@ -2534,8 +2541,8 @@ fn parse_crate_from_crate_file(input: &str, cfg: &ast::crate_cfg, config: p.get_cfg()}); } -fn parse_crate_from_file(input: &str, cfg: &ast::crate_cfg, sess: &parse_sess) - -> @ast::crate { +fn parse_crate_from_file(input: str, cfg: ast::crate_cfg, sess: parse_sess) -> + @ast::crate { if str::ends_with(input, ".rc") { parse_crate_from_crate_file(input, cfg, sess) } else if str::ends_with(input, ".rs") { diff --git a/src/comp/syntax/parse/token.rs b/src/comp/syntax/parse/token.rs index 153f5236c4b..2846d3945dd 100644 --- a/src/comp/syntax/parse/token.rs +++ b/src/comp/syntax/parse/token.rs @@ -118,6 +118,7 @@ fn to_str(r: lexer::reader, t: token) -> str { + /* Structural symbols */ AT. { ret "@"; @@ -144,6 +145,7 @@ fn to_str(r: lexer::reader, t: token) -> str { + /* Literals */ LIT_INT(i) { ret int::to_str(i, 10u); @@ -171,6 +173,7 @@ fn to_str(r: lexer::reader, t: token) -> str { + /* Name components */ IDENT(s, _) { ret interner::get::<str>(*r.get_interner(), s); diff --git a/src/comp/syntax/print/pp.rs b/src/comp/syntax/print/pp.rs index fad670fbefb..280a36a3ac7 100644 --- a/src/comp/syntax/print/pp.rs +++ b/src/comp/syntax/print/pp.rs @@ -73,8 +73,8 @@ fn tok_str(t: token) -> str { } } -fn buf_str(toks: &[mutable token], szs: &[mutable int], left: uint, - right: uint, lim: uint) -> str { +fn buf_str(toks: [mutable token], szs: [mutable int], left: uint, right: uint, + lim: uint) -> str { let n = vec::len(toks); assert (n == vec::len(szs)); let i = left; @@ -404,7 +404,7 @@ obj printer(out: io::writer, if n != 0u { top = print_stack[n - 1u]; } ret top; } - fn write_str(s: &str) { + fn write_str(s: str) { while pending_indentation > 0 { out.write_str(" "); pending_indentation -= 1; @@ -492,15 +492,15 @@ fn end(p: printer) { p.pretty_print(END); } fn eof(p: printer) { p.pretty_print(EOF); } -fn word(p: printer, wrd: &str) { +fn word(p: printer, wrd: str) { p.pretty_print(STRING(wrd, str::char_len(wrd) as int)); } -fn huge_word(p: printer, wrd: &str) { +fn huge_word(p: printer, wrd: str) { p.pretty_print(STRING(wrd, size_infinity)); } -fn zero_word(p: printer, wrd: &str) { p.pretty_print(STRING(wrd, 0)); } +fn zero_word(p: printer, wrd: str) { p.pretty_print(STRING(wrd, 0)); } fn spaces(p: printer, n: uint) { break_offset(p, n, 0); } diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 38e2dbed5b6..b1ecf450c5d 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -33,10 +33,10 @@ tag ann_node { node_expr(ps, @ast::expr); node_pat(ps, @ast::pat); } -type pp_ann = {pre: fn(&ann_node), post: fn(&ann_node)}; +type pp_ann = {pre: fn(ann_node), post: fn(ann_node)}; fn no_ann() -> pp_ann { - fn ignore(_node: &ann_node) { } + fn ignore(_node: ann_node) { } ret {pre: ignore, post: ignore}; } @@ -50,9 +50,9 @@ type ps = mutable boxes: [pp::breaks], ann: pp_ann}; -fn ibox(s: &ps, u: uint) { s.boxes += [pp::inconsistent]; pp::ibox(s.s, u); } +fn ibox(s: ps, u: uint) { s.boxes += [pp::inconsistent]; pp::ibox(s.s, u); } -fn end(s: &ps) { vec::pop(s.boxes); pp::end(s.s); } +fn end(s: ps) { vec::pop(s.boxes); pp::end(s.s); } fn rust_printer(writer: io::writer) -> ps { let boxes: [pp::breaks] = []; @@ -74,8 +74,8 @@ const default_columns: uint = 78u; // Requires you to pass an input filename and reader so that // it can scan the input text for comments and literals to // copy forward. -fn print_crate(cm: &codemap, crate: @ast::crate, filename: &str, - in: io::reader, out: io::writer, ann: &pp_ann) { +fn print_crate(cm: codemap, crate: @ast::crate, filename: str, in: io::reader, + out: io::writer, ann: pp_ann) { let boxes: [pp::breaks] = []; let r = lexer::gather_comments_and_literals(cm, filename, in); let s = @@ -92,22 +92,21 @@ fn print_crate(cm: &codemap, crate: @ast::crate, filename: &str, eof(s.s); } -fn ty_to_str(ty: &@ast::ty) -> str { be to_str(ty, print_type); } +fn ty_to_str(ty: @ast::ty) -> str { be to_str(ty, print_type); } -fn pat_to_str(pat: &@ast::pat) -> str { be to_str(pat, print_pat); } +fn pat_to_str(pat: @ast::pat) -> str { be to_str(pat, print_pat); } -fn expr_to_str(e: &@ast::expr) -> str { be to_str(e, print_expr); } +fn expr_to_str(e: @ast::expr) -> str { be to_str(e, print_expr); } -fn stmt_to_str(s: &ast::stmt) -> str { be to_str(s, print_stmt); } +fn stmt_to_str(s: ast::stmt) -> str { be to_str(s, print_stmt); } -fn item_to_str(i: &@ast::item) -> str { be to_str(i, print_item); } +fn item_to_str(i: @ast::item) -> str { be to_str(i, print_item); } -fn path_to_str(p: &ast::path) -> str { +fn path_to_str(p: ast::path) -> str { be to_str(p, bind print_path(_, _, false)); } -fn fun_to_str(f: &ast::_fn, name: &ast::ident, params: &[ast::ty_param]) -> - str { +fn fun_to_str(f: ast::_fn, name: ast::ident, params: [ast::ty_param]) -> str { let writer = io::string_writer(); let s = rust_printer(writer.get_writer()); print_fn(s, f.decl, f.proto, name, params, f.decl.constraints); @@ -115,7 +114,7 @@ fn fun_to_str(f: &ast::_fn, name: &ast::ident, params: &[ast::ty_param]) -> ret writer.get_str(); } -fn block_to_str(blk: &ast::blk) -> str { +fn block_to_str(blk: ast::blk) -> str { let writer = io::string_writer(); let s = rust_printer(writer.get_writer()); // containing cbox, will be closed by print-block at } @@ -129,29 +128,29 @@ fn block_to_str(blk: &ast::blk) -> str { ret writer.get_str(); } -fn meta_item_to_str(mi: &ast::meta_item) -> str { +fn meta_item_to_str(mi: ast::meta_item) -> str { ret to_str(@mi, print_meta_item); } -fn attribute_to_str(attr: &ast::attribute) -> str { +fn attribute_to_str(attr: ast::attribute) -> str { be to_str(attr, print_attribute); } -fn cbox(s: &ps, u: uint) { s.boxes += [pp::consistent]; pp::cbox(s.s, u); } +fn cbox(s: ps, u: uint) { s.boxes += [pp::consistent]; pp::cbox(s.s, u); } -fn box(s: &ps, u: uint, b: pp::breaks) { s.boxes += [b]; pp::box(s.s, u, b); } +fn box(s: ps, u: uint, b: pp::breaks) { s.boxes += [b]; pp::box(s.s, u, b); } -fn nbsp(s: &ps) { word(s.s, " "); } +fn nbsp(s: ps) { word(s.s, " "); } -fn word_nbsp(s: &ps, w: &str) { word(s.s, w); nbsp(s); } +fn word_nbsp(s: ps, w: str) { word(s.s, w); nbsp(s); } -fn word_space(s: &ps, w: &str) { word(s.s, w); space(s.s); } +fn word_space(s: ps, w: str) { word(s.s, w); space(s.s); } -fn popen(s: &ps) { word(s.s, "("); } +fn popen(s: ps) { word(s.s, "("); } -fn pclose(s: &ps) { word(s.s, ")"); } +fn pclose(s: ps) { word(s.s, ")"); } -fn head(s: &ps, w: &str) { +fn head(s: ps, w: str) { // outer-box is consistent cbox(s, indent_unit); // head-box is inconsistent @@ -160,35 +159,35 @@ fn head(s: &ps, w: &str) { word_nbsp(s, w); } -fn bopen(s: &ps) { +fn bopen(s: ps) { word(s.s, "{"); end(s); // close the head-box } -fn bclose_(s: &ps, span: codemap::span, indented: uint) { +fn bclose_(s: ps, span: codemap::span, indented: uint) { maybe_print_comment(s, span.hi); break_offset_if_not_bol(s, 1u, -(indented as int)); word(s.s, "}"); end(s); // close the outer-box } -fn bclose(s: &ps, span: codemap::span) { bclose_(s, span, indent_unit); } +fn bclose(s: ps, span: codemap::span) { bclose_(s, span, indent_unit); } -fn is_begin(s: &ps) -> bool { +fn is_begin(s: ps) -> bool { alt s.s.last_token() { pp::BEGIN(_) { true } _ { false } } } -fn is_end(s: &ps) -> bool { +fn is_end(s: ps) -> bool { alt s.s.last_token() { pp::END. { true } _ { false } } } -fn is_bol(s: &ps) -> bool { +fn is_bol(s: ps) -> bool { ret s.s.last_token() == pp::EOF || s.s.last_token() == pp::hardbreak_tok(); } -fn hardbreak_if_not_bol(s: &ps) { if !is_bol(s) { hardbreak(s.s); } } -fn space_if_not_bol(s: &ps) { if !is_bol(s) { space(s.s); } } -fn break_offset_if_not_bol(s: &ps, n: uint, off: int) { +fn hardbreak_if_not_bol(s: ps) { if !is_bol(s) { hardbreak(s.s); } } +fn space_if_not_bol(s: ps) { if !is_bol(s) { space(s.s); } } +fn break_offset_if_not_bol(s: ps, n: uint, off: int) { if !is_bol(s) { break_offset(s.s, n, off); } else { @@ -203,7 +202,7 @@ fn break_offset_if_not_bol(s: &ps, n: uint, off: int) { // Synthesizes a comment that was not textually present in the original source // file. -fn synth_comment(s: &ps, text: &str) { +fn synth_comment(s: ps, text: str) { word(s.s, "/*"); space(s.s); word(s.s, text); @@ -211,7 +210,7 @@ fn synth_comment(s: &ps, text: &str) { word(s.s, "*/"); } -fn commasep<IN>(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN)) { +fn commasep<IN>(s: ps, b: breaks, elts: [IN], op: fn(ps, IN)) { box(s, 0u, b); let first = true; for elt: IN in elts { @@ -222,8 +221,8 @@ fn commasep<IN>(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN)) { } -fn commasep_cmnt<IN>(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN), - get_span: fn(&IN) -> codemap::span) { +fn commasep_cmnt<IN>(s: ps, b: breaks, elts: [IN], op: fn(ps, IN), + get_span: fn(IN) -> codemap::span) { box(s, 0u, b); let len = vec::len::<IN>(elts); let i = 0u; @@ -241,12 +240,12 @@ fn commasep_cmnt<IN>(s: &ps, b: breaks, elts: &[IN], op: fn(&ps, &IN), end(s); } -fn commasep_exprs(s: &ps, b: breaks, exprs: &[@ast::expr]) { - fn expr_span(expr: &@ast::expr) -> codemap::span { ret expr.span; } +fn commasep_exprs(s: ps, b: breaks, exprs: [@ast::expr]) { + fn expr_span(expr: @ast::expr) -> codemap::span { ret expr.span; } commasep_cmnt(s, b, exprs, print_expr, expr_span); } -fn print_mod(s: &ps, _mod: &ast::_mod, attrs: &[ast::attribute]) { +fn print_mod(s: ps, _mod: ast::_mod, attrs: [ast::attribute]) { print_inner_attributes(s, attrs); for vitem: @ast::view_item in _mod.view_items { print_view_item(s, vitem); @@ -254,8 +253,7 @@ fn print_mod(s: &ps, _mod: &ast::_mod, attrs: &[ast::attribute]) { for item: @ast::item in _mod.items { print_item(s, item); } } -fn print_native_mod(s: &ps, nmod: &ast::native_mod, - attrs: &[ast::attribute]) { +fn print_native_mod(s: ps, nmod: ast::native_mod, attrs: [ast::attribute]) { print_inner_attributes(s, attrs); for vitem: @ast::view_item in nmod.view_items { print_view_item(s, vitem); @@ -263,7 +261,7 @@ fn print_native_mod(s: &ps, nmod: &ast::native_mod, for item: @ast::native_item in nmod.items { print_native_item(s, item); } } -fn print_type(s: &ps, ty: &@ast::ty) { +fn print_type(s: ps, ty: @ast::ty) { maybe_print_comment(s, ty.span.lo); ibox(s, 0u); alt ty.node { @@ -301,7 +299,7 @@ fn print_type(s: &ps, ty: &@ast::ty) { } ast::ty_rec(fields) { word(s.s, "{"); - fn print_field(s: &ps, f: &ast::ty_field) { + fn print_field(s: ps, f: ast::ty_field) { cbox(s, indent_unit); print_mutability(s, f.node.mt.mut); word(s.s, f.node.ident); @@ -309,7 +307,7 @@ fn print_type(s: &ps, ty: &@ast::ty) { print_type(s, f.node.mt.ty); end(s); } - fn get_span(f: &ast::ty_field) -> codemap::span { ret f.span; } + fn get_span(f: ast::ty_field) -> codemap::span { ret f.span; } commasep_cmnt(s, consistent, fields, print_field, get_span); word(s.s, "}"); } @@ -346,7 +344,7 @@ fn print_type(s: &ps, ty: &@ast::ty) { end(s); } -fn print_native_item(s: &ps, item: &@ast::native_item) { +fn print_native_item(s: ps, item: @ast::native_item) { hardbreak_if_not_bol(s); maybe_print_comment(s, item.span.lo); print_outer_attributes(s, item.attrs); @@ -365,6 +363,7 @@ fn print_native_item(s: &ps, item: &@ast::native_item) { + ast::native_item_fn(lname, decl, typarams) { print_fn(s, decl, ast::proto_fn, item.ident, typarams, decl.constraints); @@ -379,7 +378,7 @@ fn print_native_item(s: &ps, item: &@ast::native_item) { } } -fn print_item(s: &ps, item: &@ast::item) { +fn print_item(s: ps, item: @ast::item) { hardbreak_if_not_bol(s); maybe_print_comment(s, item.span.lo); print_outer_attributes(s, item.attrs); @@ -473,7 +472,7 @@ fn print_item(s: &ps, item: &@ast::item) { word(s.s, v.node.name); if vec::len(v.node.args) > 0u { popen(s); - fn print_variant_arg(s: &ps, arg: &ast::variant_arg) { + fn print_variant_arg(s: ps, arg: ast::variant_arg) { print_type(s, arg.ty); } commasep(s, consistent, v.node.args, print_variant_arg); @@ -490,14 +489,14 @@ fn print_item(s: &ps, item: &@ast::item) { word(s.s, item.ident); print_type_params(s, params); popen(s); - fn print_field(s: &ps, field: &ast::obj_field) { + fn print_field(s: ps, field: ast::obj_field) { ibox(s, indent_unit); print_mutability(s, field.mut); word_space(s, field.ident + ":"); print_type(s, field.ty); end(s); } - fn get_span(f: &ast::obj_field) -> codemap::span { ret f.ty.span; } + fn get_span(f: ast::obj_field) -> codemap::span { ret f.ty.span; } commasep_cmnt(s, consistent, _obj.fields, print_field, get_span); pclose(s); space(s.s); @@ -528,7 +527,7 @@ fn print_item(s: &ps, item: &@ast::item) { s.ann.post(ann_node); } -fn print_outer_attributes(s: &ps, attrs: &[ast::attribute]) { +fn print_outer_attributes(s: ps, attrs: [ast::attribute]) { let count = 0; for attr: ast::attribute in attrs { alt attr.node.style { @@ -539,7 +538,7 @@ fn print_outer_attributes(s: &ps, attrs: &[ast::attribute]) { if count > 0 { hardbreak_if_not_bol(s); } } -fn print_inner_attributes(s: &ps, attrs: &[ast::attribute]) { +fn print_inner_attributes(s: ps, attrs: [ast::attribute]) { let count = 0; for attr: ast::attribute in attrs { alt attr.node.style { @@ -554,7 +553,7 @@ fn print_inner_attributes(s: &ps, attrs: &[ast::attribute]) { if count > 0 { hardbreak_if_not_bol(s); } } -fn print_attribute(s: &ps, attr: &ast::attribute) { +fn print_attribute(s: ps, attr: ast::attribute) { hardbreak_if_not_bol(s); maybe_print_comment(s, attr.span.lo); word(s.s, "#["); @@ -562,7 +561,7 @@ fn print_attribute(s: &ps, attr: &ast::attribute) { word(s.s, "]"); } -fn print_stmt(s: &ps, st: &ast::stmt) { +fn print_stmt(s: ps, st: ast::stmt) { maybe_print_comment(s, st.span.lo); alt st.node { ast::stmt_decl(decl, _) { print_decl(s, decl); } @@ -572,13 +571,13 @@ fn print_stmt(s: &ps, st: &ast::stmt) { maybe_print_trailing_comment(s, st.span, none::<uint>); } -fn print_block(s: &ps, blk: &ast::blk) { +fn print_block(s: ps, blk: ast::blk) { print_possibly_embedded_block(s, blk, block_normal, indent_unit); } tag embed_type { block_macro; block_block_fn; block_normal; } -fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type, +fn print_possibly_embedded_block(s: ps, blk: ast::blk, embedded: embed_type, indented: uint) { alt blk.node.rules { ast::unchecked. { word(s.s, "unchecked"); } _ { } } @@ -615,8 +614,8 @@ fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type, // followed by a unary op, square bracket, or paren. In those cases we // have to add an extra semi to make sure the output retains the same // meaning. - fn maybe_protect_block(s: &ps, last: &option::t<@ast::stmt>, - next: &expr_or_stmt) { + fn maybe_protect_block(s: ps, last: option::t<@ast::stmt>, + next: expr_or_stmt) { let last_expr_is_block = alt last { option::some(@{node: ast::stmt_expr(e, _), _}) { @@ -655,7 +654,7 @@ fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type, visit_expr(ex, env, visitor); ret *env; - fn visit_expr(ex: &@ast::expr, e: &env, v: &visit::vt<env>) { + fn visit_expr(ex: @ast::expr, e: env, v: visit::vt<env>) { assert (*e == false); if expr_is_ambig(ex) { *e = true; ret; } @@ -695,7 +694,7 @@ fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type, // ret and fail, without arguments cannot appear is the discriminant of if, // alt, do, & while unambiguously without being parenthesized -fn print_maybe_parens_discrim(s: &ps, e: &@ast::expr) { +fn print_maybe_parens_discrim(s: ps, e: @ast::expr) { let disambig = alt e.node { ast::expr_ret(option::none.) { true } _ { false } }; if disambig { popen(s) } @@ -703,20 +702,21 @@ fn print_maybe_parens_discrim(s: &ps, e: &@ast::expr) { if disambig { pclose(s) } } -fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk, - elseopt: &option::t<@ast::expr>, chk: bool) { +fn print_if(s: ps, test: @ast::expr, blk: ast::blk, + elseopt: option::t<@ast::expr>, chk: bool) { head(s, "if"); if chk { word_nbsp(s, "check"); } print_maybe_parens_discrim(s, test); space(s.s); print_block(s, blk); - fn do_else(s: &ps, els: option::t<@ast::expr>) { + fn do_else(s: ps, els: option::t<@ast::expr>) { alt els { some(_else) { alt _else.node { + // "another else-if" ast::expr_if(i, t, e) { cbox(s, indent_unit - 1u); @@ -730,6 +730,7 @@ fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk, + // "final else" ast::expr_block(b) { cbox(s, indent_unit - 1u); @@ -745,7 +746,7 @@ fn print_if(s: &ps, test: &@ast::expr, blk: &ast::blk, do_else(s, elseopt); } -fn print_mac(s: &ps, m: &ast::mac) { +fn print_mac(s: ps, m: ast::mac) { alt m.node { ast::mac_invoc(path, arg, body) { word(s.s, "#"); @@ -766,7 +767,7 @@ fn print_mac(s: &ps, m: &ast::mac) { } } -fn print_expr(s: &ps, expr: &@ast::expr) { +fn print_expr(s: ps, expr: @ast::expr) { maybe_print_comment(s, expr.span.lo); ibox(s, indent_unit); let ann_node = node_expr(s, expr); @@ -784,7 +785,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) { end(s); } ast::expr_rec(fields, wth) { - fn print_field(s: &ps, field: &ast::field) { + fn print_field(s: ps, field: ast::field) { ibox(s, indent_unit); if field.node.mut == ast::mut { word_nbsp(s, "mutable"); } word(s.s, field.node.ident); @@ -792,7 +793,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) { print_expr(s, field.node.expr); end(s); } - fn get_span(field: &ast::field) -> codemap::span { ret field.span; } + fn get_span(field: ast::field) -> codemap::span { ret field.span; } word(s.s, "{"); commasep_cmnt(s, consistent, fields, print_field, get_span); alt wth { @@ -823,7 +824,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) { print_ident(s, ident); } ast::expr_bind(func, args) { - fn print_opt(s: &ps, expr: &option::t<@ast::expr>) { + fn print_opt(s: ps, expr: option::t<@ast::expr>) { alt expr { some(expr) { print_expr(s, expr); } _ { word(s.s, "_"); } @@ -1036,7 +1037,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) { // Fields popen(s); - fn print_field(s: &ps, field: &ast::anon_obj_field) { + fn print_field(s: ps, field: ast::anon_obj_field) { ibox(s, indent_unit); print_mutability(s, field.mut); word_space(s, field.ident + ":"); @@ -1046,7 +1047,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) { print_expr(s, field.expr); end(s); } - fn get_span(f: &ast::anon_obj_field) -> codemap::span { + fn get_span(f: ast::anon_obj_field) -> codemap::span { ret f.ty.span; } alt anon_obj.fields { @@ -1083,14 +1084,14 @@ fn print_expr(s: &ps, expr: &@ast::expr) { end(s); } -fn print_expr_parens_if_unary(s: &ps, ex: &@ast::expr) { +fn print_expr_parens_if_unary(s: ps, ex: @ast::expr) { let parens = alt ex.node { ast::expr_unary(_, _) { true } _ { false } }; if parens { popen(s); } print_expr(s, ex); if parens { pclose(s); } } -fn print_local_decl(s: &ps, loc: &@ast::local) { +fn print_local_decl(s: ps, loc: @ast::local) { print_pat(s, loc.node.pat); alt loc.node.ty.node { ast::ty_infer. { } @@ -1098,14 +1099,14 @@ fn print_local_decl(s: &ps, loc: &@ast::local) { } } -fn print_decl(s: &ps, decl: &@ast::decl) { +fn print_decl(s: ps, decl: @ast::decl) { maybe_print_comment(s, decl.span.lo); alt decl.node { ast::decl_local(locs) { space_if_not_bol(s); ibox(s, indent_unit); word_nbsp(s, "let"); - fn print_local(s: &ps, loc: &@ast::local) { + fn print_local(s: ps, loc: @ast::local) { ibox(s, indent_unit); print_local_decl(s, loc); end(s); @@ -1128,16 +1129,16 @@ fn print_decl(s: &ps, decl: &@ast::decl) { } } -fn print_ident(s: &ps, ident: &ast::ident) { word(s.s, ident); } +fn print_ident(s: ps, ident: ast::ident) { word(s.s, ident); } -fn print_for_decl(s: &ps, loc: &@ast::local, coll: &@ast::expr) { +fn print_for_decl(s: ps, loc: @ast::local, coll: @ast::expr) { print_local_decl(s, loc); space(s.s); word_space(s, "in"); print_expr(s, coll); } -fn print_path(s: &ps, path: &ast::path, colons_before_params: bool) { +fn print_path(s: ps, path: ast::path, colons_before_params: bool) { maybe_print_comment(s, path.span.lo); if path.node.global { word(s.s, "::"); } let first = true; @@ -1153,7 +1154,7 @@ fn print_path(s: &ps, path: &ast::path, colons_before_params: bool) { } } -fn print_pat(s: &ps, pat: &@ast::pat) { +fn print_pat(s: ps, pat: @ast::pat) { maybe_print_comment(s, pat.span.lo); let ann_node = node_pat(s, pat); s.ann.pre(ann_node); @@ -1171,14 +1172,14 @@ fn print_pat(s: &ps, pat: &@ast::pat) { } ast::pat_rec(fields, etc) { word(s.s, "{"); - fn print_field(s: &ps, f: &ast::field_pat) { + fn print_field(s: ps, f: ast::field_pat) { cbox(s, indent_unit); word(s.s, f.ident); word_space(s, ":"); print_pat(s, f.pat); end(s); } - fn get_span(f: &ast::field_pat) -> codemap::span { ret f.pat.span; } + fn get_span(f: ast::field_pat) -> codemap::span { ret f.pat.span; } commasep_cmnt(s, consistent, fields, print_field, get_span); if etc { if vec::len(fields) != 0u { word_space(s, ","); } @@ -1196,8 +1197,8 @@ fn print_pat(s: &ps, pat: &@ast::pat) { s.ann.post(ann_node); } -fn print_fn(s: &ps, decl: ast::fn_decl, proto: ast::proto, name: &ast::ident, - typarams: &[ast::ty_param], constrs: [@ast::constr]) { +fn print_fn(s: ps, decl: ast::fn_decl, proto: ast::proto, name: ast::ident, + typarams: [ast::ty_param], constrs: [@ast::constr]) { alt decl.purity { ast::impure_fn. { head(s, proto_to_str(proto)); } _ { head(s, "pure fn"); } @@ -1207,10 +1208,9 @@ fn print_fn(s: &ps, decl: ast::fn_decl, proto: ast::proto, name: &ast::ident, print_fn_args_and_ret(s, decl, constrs); } -fn print_fn_args_and_ret(s: &ps, decl: &ast::fn_decl, - constrs: [@ast::constr]) { +fn print_fn_args_and_ret(s: ps, decl: ast::fn_decl, constrs: [@ast::constr]) { popen(s); - fn print_arg(s: &ps, x: &ast::arg) { + fn print_arg(s: ps, x: ast::arg) { ibox(s, indent_unit); word_space(s, x.ident + ":"); print_alias(s, x.mode); @@ -1228,9 +1228,9 @@ fn print_fn_args_and_ret(s: &ps, decl: &ast::fn_decl, } } -fn print_fn_block_args(s: &ps, decl: &ast::fn_decl) { +fn print_fn_block_args(s: ps, decl: ast::fn_decl) { word(s.s, "|"); - fn print_arg(s: &ps, x: &ast::arg) { + fn print_arg(s: ps, x: ast::arg) { ibox(s, indent_unit); print_alias(s, x.mode); word(s.s, x.ident); @@ -1241,7 +1241,7 @@ fn print_fn_block_args(s: &ps, decl: &ast::fn_decl) { maybe_print_comment(s, decl.output.span.lo); } -fn print_alias(s: &ps, m: ast::mode) { +fn print_alias(s: ps, m: ast::mode) { alt m { ast::by_mut_ref. { word_space(s, "&mutable"); } ast::by_move. { word(s.s, "-"); } @@ -1249,7 +1249,7 @@ fn print_alias(s: &ps, m: ast::mode) { } } -fn print_kind(s: &ps, kind: ast::kind) { +fn print_kind(s: ps, kind: ast::kind) { alt kind { ast::kind_unique. { word(s.s, "~"); } ast::kind_shared. { word(s.s, "@"); } @@ -1257,10 +1257,10 @@ fn print_kind(s: &ps, kind: ast::kind) { } } -fn print_type_params(s: &ps, params: &[ast::ty_param]) { +fn print_type_params(s: ps, params: [ast::ty_param]) { if vec::len(params) > 0u { word(s.s, "<"); - fn printParam(s: &ps, param: &ast::ty_param) { + fn printParam(s: ps, param: ast::ty_param) { print_kind(s, param.kind); word(s.s, param.ident); } @@ -1269,7 +1269,7 @@ fn print_type_params(s: &ps, params: &[ast::ty_param]) { } } -fn print_meta_item(s: &ps, item: &@ast::meta_item) { +fn print_meta_item(s: ps, item: @ast::meta_item) { ibox(s, indent_unit); alt item.node { ast::meta_word(name) { word(s.s, name); } @@ -1288,7 +1288,7 @@ fn print_meta_item(s: &ps, item: &@ast::meta_item) { end(s); } -fn print_view_item(s: &ps, item: &@ast::view_item) { +fn print_view_item(s: ps, item: @ast::view_item) { hardbreak_if_not_bol(s); maybe_print_comment(s, item.span.lo); alt item.node { @@ -1318,9 +1318,7 @@ fn print_view_item(s: &ps, item: &@ast::view_item) { for elt: ast::ident in mod_path { word(s.s, elt); word(s.s, "::"); } word(s.s, "{"); commasep(s, inconsistent, idents, - fn (s: &ps, w: &ast::import_ident) { - word(s.s, w.node.name) - }); + fn (s: ps, w: ast::import_ident) { word(s.s, w.node.name) }); word(s.s, "}"); } ast::view_item_import_glob(ids, _) { @@ -1335,7 +1333,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, ";"); @@ -1355,7 +1353,7 @@ fn operator_prec(op: ast::binop) -> int { fail; } -fn need_parens(expr: &@ast::expr, outer_prec: int) -> bool { +fn need_parens(expr: @ast::expr, outer_prec: int) -> bool { alt expr.node { ast::expr_binary(op, _, _) { operator_prec(op) < outer_prec } ast::expr_cast(_, _) { parse::parser::as_prec < outer_prec } @@ -1363,6 +1361,7 @@ fn need_parens(expr: &@ast::expr, outer_prec: int) -> bool { + // This may be too conservative in some cases ast::expr_assign(_, _) { true @@ -1380,14 +1379,14 @@ fn need_parens(expr: &@ast::expr, outer_prec: int) -> bool { } } -fn print_maybe_parens(s: &ps, expr: &@ast::expr, outer_prec: int) { +fn print_maybe_parens(s: ps, expr: @ast::expr, outer_prec: int) { let add_them = need_parens(expr, outer_prec); if add_them { popen(s); } print_expr(s, expr); if add_them { pclose(s); } } -fn print_mutability(s: &ps, mut: &ast::mutability) { +fn print_mutability(s: ps, mut: ast::mutability) { alt mut { ast::mut. { word_nbsp(s, "mutable"); } ast::maybe_mut. { word_nbsp(s, "mutable?"); } @@ -1395,20 +1394,20 @@ fn print_mutability(s: &ps, mut: &ast::mutability) { } } -fn print_mt(s: &ps, mt: &ast::mt) { +fn print_mt(s: ps, mt: ast::mt) { print_mutability(s, mt.mut); print_type(s, mt.ty); } -fn print_ty_fn(s: &ps, proto: &ast::proto, id: &option::t<ast::ident>, - inputs: &[ast::ty_arg], output: &@ast::ty, - cf: &ast::controlflow, constrs: &[@ast::constr]) { +fn print_ty_fn(s: ps, proto: ast::proto, id: option::t<ast::ident>, + inputs: [ast::ty_arg], output: @ast::ty, cf: ast::controlflow, + constrs: [@ast::constr]) { ibox(s, indent_unit); word(s.s, proto_to_str(proto)); alt id { some(id) { word(s.s, " "); word(s.s, id); } _ { } } zerobreak(s.s); popen(s); - fn print_arg(s: &ps, input: &ast::ty_arg) { + fn print_arg(s: ps, input: ast::ty_arg) { print_alias(s, input.node.mode); print_type(s, input.node.ty); } @@ -1429,7 +1428,7 @@ fn print_ty_fn(s: &ps, proto: &ast::proto, id: &option::t<ast::ident>, end(s); } -fn maybe_print_trailing_comment(s: &ps, span: codemap::span, +fn maybe_print_trailing_comment(s: ps, span: codemap::span, next_pos: option::t<uint>) { let cm; alt s.cm { some(ccm) { cm = ccm; } _ { ret; } } @@ -1450,7 +1449,7 @@ fn maybe_print_trailing_comment(s: &ps, span: codemap::span, } } -fn print_remaining_comments(s: &ps) { +fn print_remaining_comments(s: ps) { // If there aren't any remaining comments, then we need to manually // make sure there is a line break at the end. if option::is_none(next_comment(s)) { hardbreak(s.s); } @@ -1462,13 +1461,13 @@ fn print_remaining_comments(s: &ps) { } } -fn in_cbox(s: &ps) -> bool { +fn in_cbox(s: ps) -> bool { let len = vec::len(s.boxes); if len == 0u { ret false; } ret s.boxes[len - 1u] == pp::consistent; } -fn print_literal(s: &ps, lit: &@ast::lit) { +fn print_literal(s: ps, lit: @ast::lit) { maybe_print_comment(s, lit.span.lo); alt next_lit(s) { some(lt) { @@ -1502,9 +1501,9 @@ fn print_literal(s: &ps, lit: &@ast::lit) { } } -fn lit_to_str(l: &@ast::lit) -> str { be to_str(l, print_literal); } +fn lit_to_str(l: @ast::lit) -> str { be to_str(l, print_literal); } -fn next_lit(s: &ps) -> option::t<lexer::lit> { +fn next_lit(s: ps) -> option::t<lexer::lit> { alt s.literals { some(lits) { if s.cur_lit < vec::len(lits) { @@ -1515,7 +1514,7 @@ fn next_lit(s: &ps) -> option::t<lexer::lit> { } } -fn maybe_print_comment(s: &ps, pos: uint) { +fn maybe_print_comment(s: ps, pos: uint) { while true { alt next_comment(s) { some(cmnt) { @@ -1529,7 +1528,7 @@ fn maybe_print_comment(s: &ps, pos: uint) { } } -fn print_comment(s: &ps, cmnt: lexer::cmnt) { +fn print_comment(s: ps, cmnt: lexer::cmnt) { alt cmnt.style { lexer::mixed. { assert (vec::len(cmnt.lines) == 1u); @@ -1573,13 +1572,13 @@ fn print_comment(s: &ps, cmnt: lexer::cmnt) { } } -fn print_string(s: &ps, st: &str) { +fn print_string(s: ps, st: str) { word(s.s, "\""); word(s.s, escape_str(st, '"')); word(s.s, "\""); } -fn escape_str(st: &str, to_escape: char) -> str { +fn escape_str(st: str, to_escape: char) -> str { let out: str = ""; let len = str::byte_len(st); let i = 0u; @@ -1601,7 +1600,7 @@ fn escape_str(st: &str, to_escape: char) -> str { ret out; } -fn to_str<T>(t: &T, f: fn(&ps, &T)) -> str { +fn to_str<T>(t: T, f: fn(ps, T)) -> str { let writer = io::string_writer(); let s = rust_printer(writer.get_writer()); f(s, t); @@ -1609,7 +1608,7 @@ fn to_str<T>(t: &T, f: fn(&ps, &T)) -> str { ret writer.get_str(); } -fn next_comment(s: &ps) -> option::t<lexer::cmnt> { +fn next_comment(s: ps) -> option::t<lexer::cmnt> { alt s.comments { some(cmnts) { if s.cur_cmnt < vec::len(cmnts) { @@ -1622,8 +1621,8 @@ fn next_comment(s: &ps) -> option::t<lexer::cmnt> { // Removing the aliases from the type of f in the next two functions // triggers memory corruption, but I haven't isolated the bug yet. FIXME -fn constr_args_to_str<T>(f: &fn(&T) -> str, args: &[@ast::sp_constr_arg<T>]) - -> str { +fn constr_args_to_str<T>(f: fn(T) -> str, args: [@ast::sp_constr_arg<T>]) -> + str { let comma = false; let s = "("; for a: @ast::sp_constr_arg<T> in args { @@ -1634,7 +1633,7 @@ fn constr_args_to_str<T>(f: &fn(&T) -> str, args: &[@ast::sp_constr_arg<T>]) ret s; } -fn constr_arg_to_str<T>(f: &fn(&T) -> str, c: &ast::constr_arg_general_<T>) -> +fn constr_arg_to_str<T>(f: fn(T) -> str, c: ast::constr_arg_general_<T>) -> str { alt c { ast::carg_base. { ret "*"; } @@ -1646,15 +1645,15 @@ fn constr_arg_to_str<T>(f: &fn(&T) -> str, c: &ast::constr_arg_general_<T>) -> // needed b/c constr_args_to_str needs // something that takes an alias // (argh) -fn uint_to_str(i: &uint) -> str { ret uint::str(i); } +fn uint_to_str(i: uint) -> str { ret uint::str(i); } -fn ast_ty_fn_constr_to_str(c: &@ast::constr) -> str { +fn ast_ty_fn_constr_to_str(c: @ast::constr) -> str { ret path_to_str(c.node.path) + constr_args_to_str(uint_to_str, c.node.args); } // FIXME: fix repeated code -fn ast_ty_fn_constrs_str(constrs: &[@ast::constr]) -> str { +fn ast_ty_fn_constrs_str(constrs: [@ast::constr]) -> str { let s = ""; let colon = true; for c: @ast::constr in constrs { @@ -1664,18 +1663,18 @@ fn ast_ty_fn_constrs_str(constrs: &[@ast::constr]) -> str { ret s; } -fn fn_arg_idx_to_str(decl: &ast::fn_decl, idx: &uint) -> str { +fn fn_arg_idx_to_str(decl: ast::fn_decl, idx: uint) -> str { decl.inputs[idx].ident } -fn ast_fn_constr_to_str(decl: &ast::fn_decl, c: &@ast::constr) -> str { +fn ast_fn_constr_to_str(decl: ast::fn_decl, c: @ast::constr) -> str { let arg_to_str = bind fn_arg_idx_to_str(decl, _); ret path_to_str(c.node.path) + constr_args_to_str(arg_to_str, c.node.args); } // FIXME: fix repeated code -fn ast_fn_constrs_str(decl: &ast::fn_decl, constrs: &[@ast::constr]) -> str { +fn ast_fn_constrs_str(decl: ast::fn_decl, constrs: [@ast::constr]) -> str { let s = ""; let colon = true; for c: @ast::constr in constrs { @@ -1685,7 +1684,7 @@ fn ast_fn_constrs_str(decl: &ast::fn_decl, constrs: &[@ast::constr]) -> str { ret s; } -fn proto_to_str(p: &ast::proto) -> str { +fn proto_to_str(p: ast::proto) -> str { ret alt p { ast::proto_fn. { "fn" } ast::proto_iter. { "iter" } @@ -1694,8 +1693,8 @@ fn proto_to_str(p: &ast::proto) -> str { }; } -fn ty_constr_to_str(c: &@ast::ty_constr) -> str { - fn ty_constr_path_to_str(p: &ast::path) -> str { "*." + path_to_str(p) } +fn ty_constr_to_str(c: @ast::ty_constr) -> str { + fn ty_constr_path_to_str(p: ast::path) -> str { "*." + path_to_str(p) } ret path_to_str(c.node.path) + constr_args_to_str::<ast::path>(ty_constr_path_to_str, @@ -1703,7 +1702,7 @@ fn ty_constr_to_str(c: &@ast::ty_constr) -> str { } -fn ast_ty_constrs_str(constrs: &[@ast::ty_constr]) -> str { +fn ast_ty_constrs_str(constrs: [@ast::ty_constr]) -> str { let s = ""; let colon = true; for c: @ast::ty_constr in constrs { diff --git a/src/comp/syntax/util/interner.rs b/src/comp/syntax/util/interner.rs index 3d1a495fb2e..7261c357940 100644 --- a/src/comp/syntax/util/interner.rs +++ b/src/comp/syntax/util/interner.rs @@ -21,7 +21,7 @@ fn mk<@T>(hasher: hashfn<T>, eqer: eqfn<T>) -> interner<T> { ret {map: m, mutable vect: [], hasher: hasher, eqer: eqer}; } -fn intern<@T>(itr: &interner<T>, val: &T) -> uint { +fn intern<@T>(itr: interner<T>, val: T) -> uint { alt itr.map.find(val) { some(idx) { ret idx; } none. { @@ -33,7 +33,7 @@ fn intern<@T>(itr: &interner<T>, val: &T) -> uint { } } -fn get<@T>(itr: &interner<T>, idx: uint) -> T { ret itr.vect[idx]; } +fn get<@T>(itr: interner<T>, idx: uint) -> T { ret itr.vect[idx]; } -fn len<T>(itr: &interner<T>) -> uint { ret vec::len(itr.vect); } +fn len<T>(itr: interner<T>) -> uint { ret vec::len(itr.vect); } diff --git a/src/comp/syntax/visit.rs b/src/comp/syntax/visit.rs index e075b1d821c..e4d0abb8f19 100644 --- a/src/comp/syntax/visit.rs +++ b/src/comp/syntax/visit.rs @@ -19,20 +19,20 @@ tag vt<E> { mk_vt(visitor<E>); } type visitor<E> = // takes the components so that one function can be // generic over constr and ty_constr - @{visit_mod: fn(&_mod, &span, &E, &vt<E>), - visit_view_item: fn(&@view_item, &E, &vt<E>), - visit_native_item: fn(&@native_item, &E, &vt<E>), - visit_item: fn(&@item, &E, &vt<E>), - visit_local: fn(&@local, &E, &vt<E>), - visit_block: fn(&ast::blk, &E, &vt<E>), - visit_stmt: fn(&@stmt, &E, &vt<E>), - visit_arm: fn(&arm, &E, &vt<E>), - visit_pat: fn(&@pat, &E, &vt<E>), - visit_decl: fn(&@decl, &E, &vt<E>), - visit_expr: fn(&@expr, &E, &vt<E>), - visit_ty: fn(&@ty, &E, &vt<E>), - visit_constr: fn(&path, &span, node_id, &E, &vt<E>), - visit_fn: fn(&_fn, &[ty_param], &span, &fn_ident, node_id, &E, &vt<E>)}; + @{visit_mod: fn(_mod, span, E, vt<E>), + visit_view_item: fn(@view_item, E, vt<E>), + visit_native_item: fn(@native_item, E, vt<E>), + visit_item: fn(@item, E, vt<E>), + visit_local: fn(@local, E, vt<E>), + visit_block: fn(ast::blk, E, vt<E>), + visit_stmt: fn(@stmt, E, vt<E>), + visit_arm: fn(arm, E, vt<E>), + visit_pat: fn(@pat, E, vt<E>), + visit_decl: fn(@decl, E, vt<E>), + visit_expr: fn(@expr, E, vt<E>), + visit_ty: fn(@ty, E, vt<E>), + visit_constr: fn(path, span, node_id, E, vt<E>), + visit_fn: fn(_fn, [ty_param], span, fn_ident, node_id, E, vt<E>)}; fn default_visitor<E>() -> visitor<E> { ret @{visit_mod: bind visit_mod::<E>(_, _, _, _), @@ -51,11 +51,11 @@ fn default_visitor<E>() -> visitor<E> { visit_fn: bind visit_fn::<E>(_, _, _, _, _, _, _)}; } -fn visit_crate<E>(c: &crate, e: &E, v: &vt<E>) { +fn visit_crate<E>(c: crate, e: E, v: vt<E>) { v.visit_mod(c.node.module, c.span, e, v); } -fn visit_crate_directive<E>(cd: &@crate_directive, e: &E, v: &vt<E>) { +fn visit_crate_directive<E>(cd: @crate_directive, e: E, v: vt<E>) { alt cd.node { cdir_src_mod(_, _, _) { } cdir_dir_mod(_, _, cdirs, _) { @@ -69,20 +69,20 @@ fn visit_crate_directive<E>(cd: &@crate_directive, e: &E, v: &vt<E>) { } } -fn visit_mod<E>(m: &_mod, _sp: &span, e: &E, v: &vt<E>) { +fn visit_mod<E>(m: _mod, _sp: span, e: E, v: vt<E>) { for vi: @view_item in m.view_items { v.visit_view_item(vi, e, v); } for i: @item in m.items { v.visit_item(i, e, v); } } -fn visit_view_item<E>(_vi: &@view_item, _e: &E, _v: &vt<E>) { } +fn visit_view_item<E>(_vi: @view_item, _e: E, _v: vt<E>) { } -fn visit_local<E>(loc: &@local, e: &E, v: &vt<E>) { +fn visit_local<E>(loc: @local, e: E, v: vt<E>) { v.visit_pat(loc.node.pat, e, v); v.visit_ty(loc.node.ty, e, v); alt loc.node.init { none. { } some(i) { v.visit_expr(i.expr, e, v); } } } -fn visit_item<E>(i: &@item, e: &E, v: &vt<E>) { +fn visit_item<E>(i: @item, e: E, v: vt<E>) { alt i.node { item_const(t, ex) { v.visit_ty(t, e, v); v.visit_expr(ex, e, v); } item_fn(f, tp) { v.visit_fn(f, tp, i.span, some(i.ident), i.id, e, v); } @@ -110,7 +110,7 @@ fn visit_item<E>(i: &@item, e: &E, v: &vt<E>) { } } -fn visit_ty<E>(t: &@ty, e: &E, v: &vt<E>) { +fn visit_ty<E>(t: @ty, e: E, v: vt<E>) { alt t.node { ty_nil. {/* no-op */ } ty_bot. {/* no-op */ } @@ -156,12 +156,12 @@ fn visit_ty<E>(t: &@ty, e: &E, v: &vt<E>) { } } -fn visit_constr<E>(_operator: &path, _sp: &span, _id: node_id, _e: &E, - _v: &vt<E>) { +fn visit_constr<E>(_operator: path, _sp: span, _id: node_id, _e: E, + _v: vt<E>) { // default } -fn visit_pat<E>(p: &@pat, e: &E, v: &vt<E>) { +fn visit_pat<E>(p: @pat, e: E, v: vt<E>) { alt p.node { pat_tag(path, children) { for tp: @ty in path.node.types { v.visit_ty(tp, e, v); } @@ -176,14 +176,14 @@ fn visit_pat<E>(p: &@pat, e: &E, v: &vt<E>) { } } -fn visit_native_item<E>(ni: &@native_item, e: &E, v: &vt<E>) { +fn visit_native_item<E>(ni: @native_item, e: E, v: vt<E>) { alt ni.node { native_item_fn(_, fd, _) { visit_fn_decl(fd, e, v); } native_item_ty. { } } } -fn visit_fn_decl<E>(fd: &fn_decl, e: &E, v: &vt<E>) { +fn visit_fn_decl<E>(fd: fn_decl, e: E, v: vt<E>) { for a: arg in fd.inputs { v.visit_ty(a.ty, e, v); } for c: @constr in fd.constraints { v.visit_constr(c.node.path, c.span, c.node.id, e, v); @@ -191,18 +191,18 @@ fn visit_fn_decl<E>(fd: &fn_decl, e: &E, v: &vt<E>) { v.visit_ty(fd.output, e, v); } -fn visit_fn<E>(f: &_fn, _tp: &[ty_param], _sp: &span, _i: &fn_ident, - _id: node_id, e: &E, v: &vt<E>) { +fn visit_fn<E>(f: _fn, _tp: [ty_param], _sp: span, _i: fn_ident, _id: node_id, + e: E, v: vt<E>) { visit_fn_decl(f.decl, e, v); v.visit_block(f.body, e, v); } -fn visit_block<E>(b: &ast::blk, e: &E, v: &vt<E>) { +fn visit_block<E>(b: ast::blk, e: E, v: vt<E>) { for s: @stmt in b.node.stmts { v.visit_stmt(s, e, v); } visit_expr_opt(b.node.expr, e, v); } -fn visit_stmt<E>(s: &@stmt, e: &E, v: &vt<E>) { +fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) { alt s.node { stmt_decl(d, _) { v.visit_decl(d, e, v); } stmt_expr(ex, _) { v.visit_expr(ex, e, v); } @@ -210,7 +210,7 @@ fn visit_stmt<E>(s: &@stmt, e: &E, v: &vt<E>) { } } -fn visit_decl<E>(d: &@decl, e: &E, v: &vt<E>) { +fn visit_decl<E>(d: @decl, e: E, v: vt<E>) { alt d.node { decl_local(locs) { for loc: @ast::local in locs { v.visit_local(loc, e, v); } @@ -219,15 +219,15 @@ fn visit_decl<E>(d: &@decl, e: &E, v: &vt<E>) { } } -fn visit_expr_opt<E>(eo: option::t<@expr>, e: &E, v: &vt<E>) { +fn visit_expr_opt<E>(eo: option::t<@expr>, e: E, v: vt<E>) { alt eo { none. { } some(ex) { v.visit_expr(ex, e, v); } } } -fn visit_exprs<E>(exprs: &[@expr], e: &E, v: &vt<E>) { +fn visit_exprs<E>(exprs: [@expr], e: E, v: vt<E>) { for ex: @expr in exprs { v.visit_expr(ex, e, v); } } -fn visit_mac<E>(m: mac, e: &E, v: &vt<E>) { +fn visit_mac<E>(m: mac, e: E, v: vt<E>) { alt m.node { ast::mac_invoc(pth, arg, body) { visit_expr(arg, e, v); } ast::mac_embed_type(ty) { v.visit_ty(ty, e, v); } @@ -236,7 +236,7 @@ fn visit_mac<E>(m: mac, e: &E, v: &vt<E>) { } } -fn visit_expr<E>(ex: &@expr, e: &E, v: &vt<E>) { +fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) { alt ex.node { expr_vec(es, _) { visit_exprs(es, e, v); } expr_rec(flds, base) { @@ -329,7 +329,7 @@ fn visit_expr<E>(ex: &@expr, e: &E, v: &vt<E>) { } } -fn visit_arm<E>(a: &arm, e: &E, v: &vt<E>) { +fn visit_arm<E>(a: arm, e: E, v: vt<E>) { for p: @pat in a.pats { v.visit_pat(p, e, v); } visit_expr_opt(a.guard, e, v); v.visit_block(a.body, e, v); @@ -341,99 +341,99 @@ fn visit_arm<E>(a: &arm, e: &E, v: &vt<E>) { type simple_visitor = // takes the components so that one function can be // generic over constr and ty_constr - @{visit_mod: fn(&_mod, &span), - visit_view_item: fn(&@view_item), - visit_native_item: fn(&@native_item), - visit_item: fn(&@item), - visit_local: fn(&@local), - visit_block: fn(&ast::blk), - visit_stmt: fn(&@stmt), - visit_arm: fn(&arm), - visit_pat: fn(&@pat), - visit_decl: fn(&@decl), - visit_expr: fn(&@expr), - visit_ty: fn(&@ty), - visit_constr: fn(&path, &span, node_id), - visit_fn: fn(&_fn, &[ty_param], &span, &fn_ident, node_id)}; + @{visit_mod: fn(_mod, span), + visit_view_item: fn(@view_item), + visit_native_item: fn(@native_item), + visit_item: fn(@item), + visit_local: fn(@local), + visit_block: fn(ast::blk), + visit_stmt: fn(@stmt), + visit_arm: fn(arm), + visit_pat: fn(@pat), + visit_decl: fn(@decl), + visit_expr: fn(@expr), + visit_ty: fn(@ty), + visit_constr: fn(path, span, node_id), + visit_fn: fn(_fn, [ty_param], span, fn_ident, node_id)}; fn default_simple_visitor() -> simple_visitor { - ret @{visit_mod: fn (_m: &_mod, _sp: &span) { }, - visit_view_item: fn (_vi: &@view_item) { }, - visit_native_item: fn (_ni: &@native_item) { }, - visit_item: fn (_i: &@item) { }, - visit_local: fn (_l: &@local) { }, - visit_block: fn (_b: &ast::blk) { }, - visit_stmt: fn (_s: &@stmt) { }, - visit_arm: fn (_a: &arm) { }, - visit_pat: fn (_p: &@pat) { }, - visit_decl: fn (_d: &@decl) { }, - visit_expr: fn (_e: &@expr) { }, - visit_ty: fn (_t: &@ty) { }, - visit_constr: fn (_p: &path, _sp: &span, _id: node_id) { }, + ret @{visit_mod: fn (_m: _mod, _sp: span) { }, + visit_view_item: fn (_vi: @view_item) { }, + visit_native_item: fn (_ni: @native_item) { }, + visit_item: fn (_i: @item) { }, + visit_local: fn (_l: @local) { }, + visit_block: fn (_b: ast::blk) { }, + visit_stmt: fn (_s: @stmt) { }, + visit_arm: fn (_a: arm) { }, + visit_pat: fn (_p: @pat) { }, + visit_decl: fn (_d: @decl) { }, + visit_expr: fn (_e: @expr) { }, + visit_ty: fn (_t: @ty) { }, + visit_constr: fn (_p: path, _sp: span, _id: node_id) { }, visit_fn: - fn (_f: &_fn, _tps: &[ty_param], _sp: &span, _ident: &fn_ident, + fn (_f: _fn, _tps: [ty_param], _sp: span, _ident: fn_ident, _id: node_id) { }}; } -fn mk_simple_visitor(v: &simple_visitor) -> vt<()> { - fn v_mod(f: fn(&_mod, &span), m: &_mod, sp: &span, e: &(), v: &vt<()>) { +fn mk_simple_visitor(v: simple_visitor) -> vt<()> { + fn v_mod(f: fn(_mod, span), m: _mod, sp: span, e: (), v: vt<()>) { f(m, sp); visit_mod(m, sp, e, v); } - fn v_view_item(f: fn(&@view_item), vi: &@view_item, e: &(), v: &vt<()>) { + fn v_view_item(f: fn(@view_item), vi: @view_item, e: (), v: vt<()>) { f(vi); visit_view_item(vi, e, v); } - fn v_native_item(f: fn(&@native_item), ni: &@native_item, e: &(), - v: &vt<()>) { + fn v_native_item(f: fn(@native_item), ni: @native_item, e: (), + v: vt<()>) { f(ni); visit_native_item(ni, e, v); } - fn v_item(f: fn(&@item), i: &@item, e: &(), v: &vt<()>) { + fn v_item(f: fn(@item), i: @item, e: (), v: vt<()>) { f(i); visit_item(i, e, v); } - fn v_local(f: fn(&@local), l: &@local, e: &(), v: &vt<()>) { + fn v_local(f: fn(@local), l: @local, e: (), v: vt<()>) { f(l); visit_local(l, e, v); } - fn v_block(f: fn(&ast::blk), bl: &ast::blk, e: &(), v: &vt<()>) { + fn v_block(f: fn(ast::blk), bl: ast::blk, e: (), v: vt<()>) { f(bl); visit_block(bl, e, v); } - fn v_stmt(f: fn(&@stmt), st: &@stmt, e: &(), v: &vt<()>) { + fn v_stmt(f: fn(@stmt), st: @stmt, e: (), v: vt<()>) { f(st); visit_stmt(st, e, v); } - fn v_arm(f: fn(&arm), a: &arm, e: &(), v: &vt<()>) { + fn v_arm(f: fn(arm), a: arm, e: (), v: vt<()>) { f(a); visit_arm(a, e, v); } - fn v_pat(f: fn(&@pat), p: &@pat, e: &(), v: &vt<()>) { + fn v_pat(f: fn(@pat), p: @pat, e: (), v: vt<()>) { f(p); visit_pat(p, e, v); } - fn v_decl(f: fn(&@decl), d: &@decl, e: &(), v: &vt<()>) { + fn v_decl(f: fn(@decl), d: @decl, e: (), v: vt<()>) { f(d); visit_decl(d, e, v); } - fn v_expr(f: fn(&@expr), ex: &@expr, e: &(), v: &vt<()>) { + fn v_expr(f: fn(@expr), ex: @expr, e: (), v: vt<()>) { f(ex); visit_expr(ex, e, v); } - fn v_ty(f: fn(&@ty), ty: &@ty, e: &(), v: &vt<()>) { + fn v_ty(f: fn(@ty), ty: @ty, e: (), v: vt<()>) { f(ty); visit_ty(ty, e, v); } - fn v_constr(f: fn(&path, &span, node_id), pt: &path, sp: &span, - id: node_id, e: &(), v: &vt<()>) { + fn v_constr(f: fn(path, span, node_id), pt: path, sp: span, id: node_id, + e: (), v: vt<()>) { f(pt, sp, id); visit_constr(pt, sp, id, e, v); } - fn v_fn(f: fn(&_fn, &[ty_param], &span, &fn_ident, node_id), ff: &_fn, - tps: &[ty_param], sp: &span, ident: &fn_ident, id: node_id, - e: &(), v: &vt<()>) { + fn v_fn(f: fn(_fn, [ty_param], span, fn_ident, node_id), ff: _fn, + tps: [ty_param], sp: span, ident: fn_ident, id: node_id, e: (), + v: vt<()>) { f(ff, tps, sp, ident, id); visit_fn(ff, tps, sp, ident, id, e, v); } diff --git a/src/comp/util/common.rs b/src/comp/util/common.rs index ba86b99261f..81cafb0648e 100644 --- a/src/comp/util/common.rs +++ b/src/comp/util/common.rs @@ -30,11 +30,11 @@ import print::pp::mk_printer; type flag = hashmap<str, ()>; -fn def_eq(a: &ast::def_id, b: &ast::def_id) -> bool { +fn def_eq(a: ast::def_id, b: ast::def_id) -> bool { ret a.crate == b.crate && a.node == b.node; } -fn hash_def(d: &ast::def_id) -> uint { +fn hash_def(d: ast::def_id) -> uint { let h = 5381u; h = (h << 5u) + h ^ (d.crate as uint); h = (h << 5u) + h ^ (d.node as uint); @@ -47,43 +47,43 @@ fn new_def_hash<@V>() -> std::map::hashmap<ast::def_id, V> { ret std::map::mk_hashmap::<ast::def_id, V>(hasher, eqer); } -fn field_expr(f: &ast::field) -> @ast::expr { ret f.node.expr; } +fn field_expr(f: ast::field) -> @ast::expr { ret f.node.expr; } -fn field_exprs(fields: &[ast::field]) -> [@ast::expr] { +fn field_exprs(fields: [ast::field]) -> [@ast::expr] { let es = []; for f: ast::field in fields { es += [f.node.expr]; } ret es; } -fn log_expr(e: &ast::expr) { log print::pprust::expr_to_str(@e); } +fn log_expr(e: ast::expr) { log print::pprust::expr_to_str(@e); } -fn log_expr_err(e: &ast::expr) { log_err print::pprust::expr_to_str(@e); } +fn log_expr_err(e: ast::expr) { log_err print::pprust::expr_to_str(@e); } -fn log_ty_err(t: &@ty) { log_err print::pprust::ty_to_str(t); } +fn log_ty_err(t: @ty) { log_err print::pprust::ty_to_str(t); } -fn log_pat_err(p: &@pat) { log_err print::pprust::pat_to_str(p); } +fn log_pat_err(p: @pat) { log_err print::pprust::pat_to_str(p); } -fn log_block(b: &ast::blk) { log print::pprust::block_to_str(b); } +fn log_block(b: ast::blk) { log print::pprust::block_to_str(b); } -fn log_block_err(b: &ast::blk) { log_err print::pprust::block_to_str(b); } +fn log_block_err(b: ast::blk) { log_err print::pprust::block_to_str(b); } -fn log_item_err(i: &@ast::item) { log_err print::pprust::item_to_str(i); } +fn log_item_err(i: @ast::item) { log_err print::pprust::item_to_str(i); } -fn log_fn(f: &ast::_fn, name: &ast::ident, params: &[ast::ty_param]) { +fn log_fn(f: ast::_fn, name: ast::ident, params: [ast::ty_param]) { log print::pprust::fun_to_str(f, name, params); } -fn log_fn_err(f: &ast::_fn, name: &ast::ident, params: &[ast::ty_param]) { +fn log_fn_err(f: ast::_fn, name: ast::ident, params: [ast::ty_param]) { log_err print::pprust::fun_to_str(f, name, params); } -fn log_stmt(st: &ast::stmt) { log print::pprust::stmt_to_str(st); } +fn log_stmt(st: ast::stmt) { log print::pprust::stmt_to_str(st); } -fn log_stmt_err(st: &ast::stmt) { log_err print::pprust::stmt_to_str(st); } +fn log_stmt_err(st: ast::stmt) { log_err print::pprust::stmt_to_str(st); } -fn has_nonlocal_exits(b: &ast::blk) -> bool { +fn has_nonlocal_exits(b: ast::blk) -> bool { let has_exits = @mutable false; - fn visit_expr(flag: @mutable bool, e: &@ast::expr) { + fn visit_expr(flag: @mutable bool, e: @ast::expr) { alt e.node { ast::expr_break. { *flag = true; } ast::expr_cont. { *flag = true; } @@ -97,11 +97,11 @@ fn has_nonlocal_exits(b: &ast::blk) -> bool { ret *has_exits; } -fn local_rhs_span(l: &@ast::local, def: &span) -> span { +fn local_rhs_span(l: @ast::local, def: span) -> span { alt l.node.init { some(i) { ret i.expr.span; } _ { ret def; } } } -fn lit_eq(l: &@ast::lit, m: &@ast::lit) -> bool { +fn lit_eq(l: @ast::lit, m: @ast::lit) -> bool { alt l.node { ast::lit_str(s) { alt m.node { ast::lit_str(t) { ret s == t } _ { ret false; } } @@ -150,7 +150,7 @@ fn call_kind_str(c: call_kind) -> str { } } -fn is_main_name(path: &[ast::ident]) -> bool { +fn is_main_name(path: [ast::ident]) -> bool { str::eq(option::get(std::vec::last(path)), "main") } diff --git a/src/comp/util/ppaux.rs b/src/comp/util/ppaux.rs index ac2d2bd752c..51500ef2b11 100644 --- a/src/comp/util/ppaux.rs +++ b/src/comp/util/ppaux.rs @@ -21,7 +21,7 @@ import syntax::ast; import middle::ast_map; import metadata::csearch; -fn mode_str(m: &ty::mode) -> str { +fn mode_str(m: ty::mode) -> str { alt m { ast::by_ref. { "" } ast::by_mut_ref. { "&" } @@ -29,15 +29,15 @@ fn mode_str(m: &ty::mode) -> str { } } -fn mode_str_1(m: &ty::mode) -> str { +fn mode_str_1(m: ty::mode) -> str { alt m { ast::by_ref. { "ref" } _ { mode_str(m) } } } -fn fn_ident_to_string(id: ast::node_id, i: &ast::fn_ident) -> str { +fn fn_ident_to_string(id: ast::node_id, i: ast::fn_ident) -> str { ret alt i { none. { "anon" + int::str(id) } some(s) { s } }; } -fn get_id_ident(cx: &ctxt, id: ast::def_id) -> str { +fn get_id_ident(cx: ctxt, id: ast::def_id) -> str { if id.crate != ast::local_crate { alt cx.ext_map.find(id) { some(j) { str::connect(j, "::") } @@ -54,15 +54,15 @@ fn get_id_ident(cx: &ctxt, id: ast::def_id) -> str { } } -fn ty_to_str(cx: &ctxt, typ: &t) -> str { - fn fn_input_to_str(cx: &ctxt, input: &{mode: middle::ty::mode, ty: t}) -> +fn ty_to_str(cx: ctxt, typ: t) -> str { + fn fn_input_to_str(cx: ctxt, input: {mode: middle::ty::mode, ty: t}) -> str { let s = mode_str(input.mode); ret s + ty_to_str(cx, input.ty); } - fn fn_to_str(cx: &ctxt, proto: ast::proto, ident: option::t<ast::ident>, - inputs: &[arg], output: t, cf: ast::controlflow, - constrs: &[@constr]) -> str { + fn fn_to_str(cx: ctxt, proto: ast::proto, ident: option::t<ast::ident>, + inputs: [arg], output: t, cf: ast::controlflow, + constrs: [@constr]) -> str { let s = proto_to_str(proto); alt ident { some(i) { s += " "; s += i; } _ { } } s += "("; @@ -79,14 +79,14 @@ fn ty_to_str(cx: &ctxt, typ: &t) -> str { s += constrs_str(constrs); ret s; } - fn method_to_str(cx: &ctxt, m: &method) -> str { + fn method_to_str(cx: ctxt, m: method) -> str { ret fn_to_str(cx, m.proto, some::<ast::ident>(m.ident), m.inputs, m.output, m.cf, m.constrs) + ";"; } - fn field_to_str(cx: &ctxt, f: &field) -> str { + fn field_to_str(cx: ctxt, f: field) -> str { ret f.ident + ": " + mt_to_str(cx, f.mt); } - fn mt_to_str(cx: &ctxt, m: &mt) -> str { + fn mt_to_str(cx: ctxt, m: mt) -> str { let mstr; alt m.mut { ast::mut. { mstr = "mutable "; } @@ -151,18 +151,18 @@ fn ty_to_str(cx: &ctxt, typ: &t) -> str { } } -fn ty_to_short_str(cx: &ctxt, typ: t) -> str { +fn ty_to_short_str(cx: ctxt, typ: t) -> str { let s = encoder::encoded_ty(cx, typ); if str::byte_len(s) >= 32u { s = str::substr(s, 0u, 32u); } ret s; } -fn constr_to_str(c: &@constr) -> str { +fn constr_to_str(c: @constr) -> str { ret path_to_str(c.node.path) + pprust::constr_args_to_str(pprust::uint_to_str, c.node.args); } -fn constrs_str(constrs: &[@constr]) -> str { +fn constrs_str(constrs: [@constr]) -> str { let s = ""; let colon = true; for c: @constr in constrs { @@ -172,7 +172,7 @@ fn constrs_str(constrs: &[@constr]) -> str { ret s; } -fn ty_constr_to_str<Q>(c: &@ast::spanned<ast::constr_general_<ast::path, Q>>) +fn ty_constr_to_str<Q>(c: @ast::spanned<ast::constr_general_<ast::path, Q>>) -> str { ret path_to_str(c.node.path) + constr_args_to_str::<ast::path>(path_to_str, c.node.args); diff --git a/src/fuzzer/ast_match.rs b/src/fuzzer/ast_match.rs index de8696baf3f..e8cad5edce5 100644 --- a/src/fuzzer/ast_match.rs +++ b/src/fuzzer/ast_match.rs @@ -1,8 +1,8 @@ use std; import std::vec; -fn vec_equal<T>(v: &[T], u: &[T], element_equality_test: fn(&T, &T) -> bool) - -> bool { +fn vec_equal<T>(v: [T], u: [T], element_equality_test: fn(T, T) -> bool) -> + bool { let Lv = vec::len(v); if Lv != vec::len(u) { ret false; } let i = 0u; @@ -13,7 +13,7 @@ fn vec_equal<T>(v: &[T], u: &[T], element_equality_test: fn(&T, &T) -> bool) ret true; } -fn builtin_equal<T>(a: &T, b: &T) -> bool { ret a == b; } +fn builtin_equal<T>(a: T, b: T) -> bool { ret a == b; } fn main() { assert (builtin_equal(5, 5)); diff --git a/src/fuzzer/fuzzer.rs b/src/fuzzer/fuzzer.rs index 91aa770752a..95efec083f3 100644 --- a/src/fuzzer/fuzzer.rs +++ b/src/fuzzer/fuzzer.rs @@ -20,22 +20,22 @@ import rustc::syntax::codemap; import rustc::syntax::parse::parser; import rustc::syntax::print::pprust; -fn write_file(filename: &str, content: &str) { +fn write_file(filename: str, content: str) { io::file_writer(filename, [io::create, io::truncate]).write_str(content); // Work around https://github.com/graydon/rust/issues/726 std::run::run_program("chmod", ["644", filename]); } -fn file_contains(filename: &str, needle: &str) -> bool { +fn file_contains(filename: str, needle: str) -> bool { let contents = io::read_whole_file_str(filename); ret str::find(contents, needle) != -1; } -fn contains(haystack: &str, needle: &str) -> bool { +fn contains(haystack: str, needle: str) -> bool { str::find(haystack, needle) != -1 } -fn find_rust_files(files: &mutable [str], path: &str) { +fn find_rust_files(files: &[str], path: str) { if str::ends_with(path, ".rs") { if file_contains(path, "xfail-test") { //log_err "Skipping " + path + " because it is marked as xfail-test"; @@ -48,7 +48,7 @@ fn find_rust_files(files: &mutable [str], path: &str) { } } -fn safe_to_steal_expr(e: &@ast::expr) -> bool { +fn safe_to_steal_expr(e: @ast::expr) -> bool { alt e.node { // https://github.com/graydon/rust/issues/890 @@ -89,19 +89,19 @@ fn safe_to_steal_expr(e: &@ast::expr) -> bool { } } -fn safe_to_steal_ty(t: &@ast::ty) -> bool { +fn safe_to_steal_ty(t: @ast::ty) -> bool { // Same restrictions safe_to_replace_ty(t.node) } // Not type-parameterized: https://github.com/graydon/rust/issues/898 -fn stash_expr_if(c: fn(&@ast::expr)->bool, es: @mutable [ast::expr], e: &@ast::expr) { +fn stash_expr_if(c: fn(@ast::expr)->bool, es: @mutable [ast::expr], e: @ast::expr) { if c(e) { *es += [*e]; } else {/* now my indices are wrong :( */ } } -fn stash_ty_if(c: fn(&@ast::ty)->bool, es: @mutable [ast::ty], e: &@ast::ty) { +fn stash_ty_if(c: fn(@ast::ty)->bool, es: @mutable [ast::ty], e: @ast::ty) { if c(e) { *es += [*e]; } else {/* now my indices are wrong :( */ } @@ -109,7 +109,7 @@ fn stash_ty_if(c: fn(&@ast::ty)->bool, es: @mutable [ast::ty], e: &@ast::ty) { type stolen_stuff = {exprs: [ast::expr], tys: [ast::ty]}; -fn steal(crate: &ast::crate) -> stolen_stuff { +fn steal(crate: ast::crate) -> stolen_stuff { let exprs = @mutable []; let tys = @mutable []; let v = visit::mk_simple_visitor(@{ @@ -140,11 +140,11 @@ fn safe_to_replace_ty(t: ast::ty_) -> bool { } // Replace the |i|th expr (in fold order) of |crate| with |newexpr|. -fn replace_expr_in_crate(crate: &ast::crate, i: uint, newexpr: &ast::expr) -> +fn replace_expr_in_crate(crate: ast::crate, i: uint, newexpr: ast::expr) -> ast::crate { let j: @mutable uint = @mutable 0u; - fn fold_expr_rep(j_: @mutable uint, i_: uint, newexpr_: &ast::expr_, - original: &ast::expr_, fld: fold::ast_fold) -> + fn fold_expr_rep(j_: @mutable uint, i_: uint, newexpr_: ast::expr_, + original: ast::expr_, fld: fold::ast_fold) -> ast::expr_ { *j_ += 1u; if i_ + 1u == *j_ && safe_to_replace_expr(original) { @@ -161,11 +161,11 @@ fn replace_expr_in_crate(crate: &ast::crate, i: uint, newexpr: &ast::expr) -> } // Replace the |i|th ty (in fold order) of |crate| with |newty|. -fn replace_ty_in_crate(crate: &ast::crate, i: uint, newty: &ast::ty) -> +fn replace_ty_in_crate(crate: ast::crate, i: uint, newty: ast::ty) -> ast::crate { let j: @mutable uint = @mutable 0u; - fn fold_ty_rep(j_: @mutable uint, i_: uint, newty_: &ast::ty_, - original: &ast::ty_, fld: fold::ast_fold) -> + fn fold_ty_rep(j_: @mutable uint, i_: uint, newty_: ast::ty_, + original: ast::ty_, fld: fold::ast_fold) -> ast::ty_ { *j_ += 1u; if i_ + 1u == *j_ && safe_to_replace_ty(original) { @@ -194,21 +194,21 @@ fn as_str(f: fn(io::writer)) -> str { ret w.get_str(); } -fn check_variants_of_ast(crate: &ast::crate, codemap: &codemap::codemap, - filename: &str) { +fn check_variants_of_ast(crate: ast::crate, codemap: codemap::codemap, + filename: str) { let stolen = steal(crate); check_variants_T(crate, codemap, filename, "expr", stolen.exprs, pprust::expr_to_str, replace_expr_in_crate); check_variants_T(crate, codemap, filename, "ty", stolen.tys, pprust::ty_to_str, replace_ty_in_crate); } fn check_variants_T<T>( - crate: &ast::crate, - codemap: &codemap::codemap, - filename: &str, - thing_label: &str, + crate: ast::crate, + codemap: codemap::codemap, + filename: str, + thing_label: str, things: [T], - stringifier: fn(&@T) -> str, - replacer: fn(&ast::crate, uint, &T) -> ast::crate + stringifier: fn(@T) -> str, + replacer: fn(ast::crate, uint, T) -> ast::crate ) { log_err #fmt("%s contains %u %s objects", filename, vec::len(things), thing_label); @@ -235,7 +235,7 @@ fn check_variants_T<T>( } } -fn last_part(filename: &str) -> str { +fn last_part(filename: str) -> str { let ix = str::rindex(filename, 47u8 /* '/' */); assert ix >= 0; str::slice(filename, ix as uint + 1u, str::byte_len(filename) - 3u) @@ -247,7 +247,7 @@ tag compile_result { known_bug(str); passed(str); failed(str); } // - that would find many "false positives" or unimportant bugs // - that would be tricky, requiring use of tasks or serialization or randomness. // This seems to find plenty of bugs as it is :) -fn check_whole_compiler(code: &str, suggested_filename: &str) { +fn check_whole_compiler(code: str, suggested_filename: str) { let filename = "test.rs"; write_file(filename, code); alt check_whole_compiler_inner(filename) { @@ -263,7 +263,7 @@ fn check_whole_compiler(code: &str, suggested_filename: &str) { } } -fn check_whole_compiler_inner(filename: &str) -> compile_result { +fn check_whole_compiler_inner(filename: str) -> compile_result { let p = std::run::program_output( "/Users/jruderman/code/rust/build/stage1/rustc", ["-c", filename]); @@ -312,7 +312,7 @@ fn check_whole_compiler_inner(filename: &str) -> compile_result { } -fn parse_and_print(code: &str) -> str { +fn parse_and_print(code: str) -> str { let filename = "tmp.rs"; let sess = @{cm: codemap::new_codemap(), mutable next_id: 0}; //write_file(filename, code); @@ -324,7 +324,7 @@ fn parse_and_print(code: &str) -> str { pprust::no_ann())); } -fn content_is_dangerous_to_modify(code: &str) -> bool { +fn content_is_dangerous_to_modify(code: str) -> bool { let dangerous_patterns = ["#macro", // not safe to steal things inside of it, because they have a special syntax "#", // strange representation of the arguments to #fmt, for example @@ -335,7 +335,7 @@ fn content_is_dangerous_to_modify(code: &str) -> bool { ret false; } -fn content_is_confusing(code: &str) -> bool { +fn content_is_confusing(code: str) -> bool { let confusing_patterns = ["self", // crazy rules enforced by parser rather than typechecker? "spawn", // precedence issues? @@ -347,7 +347,7 @@ fn content_is_confusing(code: &str) -> bool { ret false; } -fn file_is_confusing(filename: &str) -> bool { +fn file_is_confusing(filename: str) -> bool { let confusing_files = []; for f in confusing_files { if contains(filename, f) { ret true; } } @@ -355,7 +355,7 @@ fn file_is_confusing(filename: &str) -> bool { ret false; } -fn check_roundtrip_convergence(code: &str, maxIters: uint) { +fn check_roundtrip_convergence(code: str, maxIters: uint) { let i = 0u; let new = code; @@ -382,7 +382,7 @@ fn check_roundtrip_convergence(code: &str, maxIters: uint) { } } -fn check_convergence(files: &[str]) { +fn check_convergence(files: [str]) { log_err #fmt["pp convergence tests: %u files", vec::len(files)]; for file in files { if !file_is_confusing(file) { @@ -396,7 +396,7 @@ fn check_convergence(files: &[str]) { } } -fn check_variants(files: &[str]) { +fn check_variants(files: [str]) { for file in files { if !file_is_confusing(file) { let s = io::read_whole_file_str(file); diff --git a/src/fuzzer/ivec_fuzz.rs b/src/fuzzer/ivec_fuzz.rs index 10742d687bd..ffff5f2f908 100644 --- a/src/fuzzer/ivec_fuzz.rs +++ b/src/fuzzer/ivec_fuzz.rs @@ -7,7 +7,7 @@ Idea: provide functions for 'exhaustive' and 'random' modification of vecs. two functions, "return the number of possible edits" and "return edit #n" It would be nice if this could be data-driven, so the two functions could share information: - type vec_modifier = rec(fn (&<T> v, uint i) -> [T] fun, uint lo, uint di); + type vec_modifier = rec(fn (<T> v, uint i) -> [T] fun, uint lo, uint di); const [vec_modifier] vec_modifiers = ~[rec(fun=vec_omit, 0u, 1u), ...]; But that gives me "error: internal compiler error unimplemented consts that's not a plain literal". https://github.com/graydon/rust/issues/570 @@ -22,22 +22,22 @@ import std::vec::slice; import std::vec::len; import std::int; -fn vec_omit<@T>(v: &[T], i: uint) -> [T] { +fn vec_omit<@T>(v: [T], i: uint) -> [T] { slice(v, 0u, i) + slice(v, i + 1u, len(v)) } -fn vec_dup<@T>(v: &[T], i: uint) -> [T] { +fn vec_dup<@T>(v: [T], i: uint) -> [T] { slice(v, 0u, i) + [v[i]] + slice(v, i, len(v)) } -fn vec_swadj<@T>(v: &[T], i: uint) -> [T] { +fn vec_swadj<@T>(v: [T], i: uint) -> [T] { slice(v, 0u, i) + [v[i + 1u], v[i]] + slice(v, i + 2u, len(v)) } -fn vec_prefix<@T>(v: &[T], i: uint) -> [T] { slice(v, 0u, i) } -fn vec_suffix<@T>(v: &[T], i: uint) -> [T] { slice(v, i, len(v)) } +fn vec_prefix<@T>(v: [T], i: uint) -> [T] { slice(v, 0u, i) } +fn vec_suffix<@T>(v: [T], i: uint) -> [T] { slice(v, i, len(v)) } -fn vec_poke<@T>(v: &[T], i: uint, x: &T) -> [T] { +fn vec_poke<@T>(v: [T], i: uint, x: T) -> [T] { slice(v, 0u, i) + [x] + slice(v, i + 1u, len(v)) } -fn vec_insert<@T>(v: &[T], i: uint, x: &T) -> [T] { +fn vec_insert<@T>(v: [T], i: uint, x: T) -> [T] { slice(v, 0u, i) + [x] + slice(v, i, len(v)) } @@ -48,7 +48,7 @@ iter ix(skip_low: uint, skip_high: uint, length: uint) -> uint { } // Returns a bunch of modified versions of v, some of which introduce new elements (borrowed from xs). -fn vec_edits<@T>(v: &[T], xs: &[T]) -> [[T]] { +fn vec_edits<@T>(v: [T], xs: [T]) -> [[T]] { let edits: [[T]] = []; let Lv: uint = len(v); @@ -79,7 +79,7 @@ fn vec_edits<@T>(v: &[T], xs: &[T]) -> [[T]] { } // Would be nice if this were built in: https://github.com/graydon/rust/issues/424 -fn vec_to_str(v: &[int]) -> str { +fn vec_to_str(v: [int]) -> str { let i = 0u; let s = "["; while i < len(v) { @@ -90,7 +90,7 @@ fn vec_to_str(v: &[int]) -> str { ret s + "]"; } -fn show_edits(a: &[int], xs: &[int]) { +fn show_edits(a: [int], xs: [int]) { log_err "=== Edits of " + vec_to_str(a) + " ==="; let b = vec_edits(a, xs); for each i: uint in ix(0u, 1u, len(b)) { log_err vec_to_str(b[i]); } diff --git a/src/lib/aio.rs b/src/lib/aio.rs index 8d8b036933d..0c4bcfd267d 100644 --- a/src/lib/aio.rs +++ b/src/lib/aio.rs @@ -14,11 +14,11 @@ native "rust" mod rustrt { fn aio_init(); fn aio_run(); fn aio_stop(); - fn aio_connect(host: *u8, port: int, connected: &chan<socket>); - fn aio_serve(host: *u8, port: int, acceptChan: &chan<socket>) -> server; - fn aio_writedata(s: socket, buf: *u8, size: uint, status: &chan<bool>); - fn aio_read(s: socket, reader: &chan<[u8]>); - fn aio_close_server(s: server, status: &chan<bool>); + fn aio_connect(host: *u8, port: int, connected: chan<socket>); + fn aio_serve(host: *u8, port: int, acceptChan: chan<socket>) -> server; + fn aio_writedata(s: socket, buf: *u8, size: uint, status: chan<bool>); + fn aio_read(s: socket, reader: chan<[u8]>); + fn aio_close_server(s: server, status: chan<bool>); fn aio_close_socket(s: socket); fn aio_is_null_client(s: socket) -> bool; } diff --git a/src/lib/bitv.rs b/src/lib/bitv.rs index 019aa32f36a..e47c72f1028 100644 --- a/src/lib/bitv.rs +++ b/src/lib/bitv.rs @@ -35,7 +35,7 @@ fn create(nbits: uint, init: bool) -> t { ret @{storage: storage, nbits: nbits}; } -fn process(op: &block(uint, uint) -> uint, v0: &t, v1: &t) -> bool { +fn process(op: block(uint, uint) -> uint, v0: t, v1: t) -> bool { let len = vec::len(v1.storage); assert (vec::len(v0.storage) == len); assert (v0.nbits == v1.nbits); @@ -51,21 +51,18 @@ fn process(op: &block(uint, uint) -> uint, v0: &t, v1: &t) -> bool { fn lor(w0: uint, w1: uint) -> uint { ret w0 | w1; } -fn union(v0: &t, v1: &t) -> bool { let sub = lor; ret process(sub, v0, v1); } +fn union(v0: t, v1: t) -> bool { let sub = lor; ret process(sub, v0, v1); } fn land(w0: uint, w1: uint) -> uint { ret w0 & w1; } -fn intersect(v0: &t, v1: &t) -> bool { +fn intersect(v0: t, v1: t) -> bool { let sub = land; ret process(sub, v0, v1); } fn right(_w0: uint, w1: uint) -> uint { ret w1; } -fn assign(v0: &t, v1: t) -> bool { - let sub = right; - ret process(sub, v0, v1); -} +fn assign(v0: t, v1: t) -> bool { let sub = right; ret process(sub, v0, v1); } fn clone(v: t) -> t { let storage = vec::init_elt_mut::<uint>(0u, v.nbits / uint_bits() + 1u); @@ -74,7 +71,7 @@ fn clone(v: t) -> t { ret @{storage: storage, nbits: v.nbits}; } -fn get(v: &t, i: uint) -> bool { +fn get(v: t, i: uint) -> bool { assert (i < v.nbits); let bits = uint_bits(); let w = i / bits; @@ -83,7 +80,7 @@ fn get(v: &t, i: uint) -> bool { ret x == 1u; } -fn equal(v0: &t, v1: &t) -> bool { +fn equal(v0: t, v1: t) -> bool { // FIXME: when we can break or return from inside an iterator loop, // we can eliminate this painful while-loop @@ -96,17 +93,17 @@ fn equal(v0: &t, v1: &t) -> bool { ret true; } -fn clear(v: &t) { +fn clear(v: t) { for each i: uint in uint::range(0u, vec::len(v.storage)) { v.storage[i] = 0u; } } -fn set_all(v: &t) { +fn set_all(v: t) { for each i: uint in uint::range(0u, v.nbits) { set(v, i, true); } } -fn invert(v: &t) { +fn invert(v: t) { for each i: uint in uint::range(0u, vec::len(v.storage)) { v.storage[i] = !v.storage[i]; } @@ -114,14 +111,14 @@ fn invert(v: &t) { /* v0 = v0 - v1 */ -fn difference(v0: &t, v1: &t) -> bool { +fn difference(v0: t, v1: t) -> bool { invert(v1); let b = intersect(v0, v1); invert(v1); ret b; } -fn set(v: &t, i: uint, x: bool) { +fn set(v: t, i: uint, x: bool) { assert (i < v.nbits); let bits = uint_bits(); let w = i / bits; @@ -132,32 +129,32 @@ fn set(v: &t, i: uint, x: bool) { /* true if all bits are 1 */ -fn is_true(v: &t) -> bool { +fn is_true(v: t) -> bool { for i: uint in to_vec(v) { if i != 1u { ret false; } } ret true; } /* true if all bits are non-1 */ -fn is_false(v: &t) -> bool { +fn is_false(v: t) -> bool { for i: uint in to_vec(v) { if i == 1u { ret false; } } ret true; } fn init_to_vec(v: t, i: uint) -> uint { ret if get(v, i) { 1u } else { 0u }; } -fn to_vec(v: &t) -> [uint] { +fn to_vec(v: t) -> [uint] { let sub = bind init_to_vec(v, _); ret vec::init_fn::<uint>(sub, v.nbits); } -fn to_str(v: &t) -> str { +fn to_str(v: t) -> str { let rs = ""; for i: uint in to_vec(v) { if i == 1u { rs += "1"; } else { rs += "0"; } } ret rs; } -fn eq_vec(v0: &t, v1: &[uint]) -> bool { +fn eq_vec(v0: t, v1: [uint]) -> bool { assert (v0.nbits == vec::len::<uint>(v1)); let len = v0.nbits; let i = 0u; diff --git a/src/lib/box.rs b/src/lib/box.rs index 94132a7f7f8..a4322c09be9 100644 --- a/src/lib/box.rs +++ b/src/lib/box.rs @@ -1,7 +1,7 @@ export ptr_eq; -fn ptr_eq<T>(a: &@T, b: &@T) -> bool { +fn ptr_eq<T>(a: @T, b: @T) -> bool { let a_ptr: uint = unsafe::reinterpret_cast(a); let b_ptr: uint = unsafe::reinterpret_cast(b); ret a_ptr == b_ptr; diff --git a/src/lib/comm.rs b/src/lib/comm.rs index f1ea9d485bc..7c3be729e83 100644 --- a/src/lib/comm.rs +++ b/src/lib/comm.rs @@ -38,7 +38,7 @@ resource port_ptr(po: *rustrt::rust_port) { tag port<~T> { port_t(@port_ptr); } -fn send<~T>(ch: &chan<T>, data: -T) { +fn send<~T>(ch: chan<T>, data: -T) { let chan_t(t, p) = ch; rustrt::chan_id_send(t, p, data); } @@ -47,8 +47,8 @@ fn port<~T>() -> port<T> { port_t(@port_ptr(rustrt::new_port(sys::size_of::<T>()))) } -fn recv<~T>(p: &port<T>) -> T { ret rusti::recv(***p) } +fn recv<~T>(p: port<T>) -> T { ret rusti::recv(***p) } -fn chan<~T>(p: &port<T>) -> chan<T> { +fn chan<~T>(p: port<T>) -> chan<T> { chan_t(task::get_task_id(), rustrt::get_port_id(***p)) } diff --git a/src/lib/dbg.rs b/src/lib/dbg.rs index 6858b30419a..6371eec349b 100644 --- a/src/lib/dbg.rs +++ b/src/lib/dbg.rs @@ -10,21 +10,21 @@ native "rust" mod rustrt { fn debug_tydesc<T>(); - fn debug_opaque<T>(x: &T); + fn debug_opaque<T>(x: T); fn debug_box<T>(x: @T); - fn debug_tag<T>(x: &T); - fn debug_obj<T>(x: &T, nmethods: uint, nbytes: uint); - fn debug_fn<T>(x: &T); + fn debug_tag<T>(x: T); + fn debug_obj<T>(x: T, nmethods: uint, nbytes: uint); + fn debug_fn<T>(x: T); fn debug_ptrcast<T, U>(x: @T) -> @U; } fn debug_tydesc<T>() { rustrt::debug_tydesc::<T>(); } -fn debug_opaque<T>(x: &T) { rustrt::debug_opaque::<T>(x); } +fn debug_opaque<T>(x: T) { rustrt::debug_opaque::<T>(x); } fn debug_box<T>(x: @T) { rustrt::debug_box::<T>(x); } -fn debug_tag<T>(x: &T) { rustrt::debug_tag::<T>(x); } +fn debug_tag<T>(x: T) { rustrt::debug_tag::<T>(x); } /** @@ -36,15 +36,15 @@ fn debug_tag<T>(x: &T) { rustrt::debug_tag::<T>(x); } * this to at least be 4u, since an implicit captured tydesc pointer sits in * the front of any obj's data tuple.x */ -fn debug_obj<T>(x: &T, nmethods: uint, nbytes: uint) { +fn debug_obj<T>(x: T, nmethods: uint, nbytes: uint) { rustrt::debug_obj::<T>(x, nmethods, nbytes); } -fn debug_fn<T>(x: &T) { rustrt::debug_fn::<T>(x); } +fn debug_fn<T>(x: T) { rustrt::debug_fn::<T>(x); } fn ptr_cast<T, U>(x: @T) -> @U { ret rustrt::debug_ptrcast::<T, U>(x); } -fn refcount<T>(a: &@T) -> uint { +fn refcount<T>(a: @T) -> uint { let p: *uint = unsafe::reinterpret_cast(a); ret *p; } diff --git a/src/lib/deque.rs b/src/lib/deque.rs index 3cc75e2f3b6..246806c8daa 100644 --- a/src/lib/deque.rs +++ b/src/lib/deque.rs @@ -7,8 +7,8 @@ type t<T> = obj { fn size() -> uint; - fn add_front(&T); - fn add_back(&T); + fn add_front(T); + fn add_back(T); fn pop_front() -> T; fn pop_back() -> T; fn peek_front() -> T; @@ -28,7 +28,8 @@ fn create<@T>() -> t<T> { - fn grow<@T>(nelts: uint, lo: uint, elts: &[mutable cell<T>]) -> + + fn grow<@T>(nelts: uint, lo: uint, elts: [mutable cell<T>]) -> [mutable cell<T>] { assert (nelts == vec::len(elts)); let rv = [mutable]; @@ -44,7 +45,7 @@ fn create<@T>() -> t<T> { ret rv; } - fn get<@T>(elts: &[mutable cell<T>], i: uint) -> T { + fn get<@T>(elts: [mutable cell<T>], i: uint) -> T { ret alt elts[i] { option::some(t) { t } _ { fail } }; } obj deque<@T>(mutable nelts: uint, @@ -52,7 +53,7 @@ fn create<@T>() -> t<T> { mutable hi: uint, mutable elts: [mutable cell<T>]) { fn size() -> uint { ret nelts; } - fn add_front(t: &T) { + fn add_front(t: T) { let oldlo: uint = lo; if lo == 0u { lo = vec::len::<cell<T>>(elts) - 1u; @@ -65,7 +66,7 @@ fn create<@T>() -> t<T> { elts[lo] = option::some::<T>(t); nelts += 1u; } - fn add_back(t: &T) { + fn add_back(t: T) { if lo == hi && nelts != 0u { elts = grow::<T>(nelts, lo, elts); lo = 0u; diff --git a/src/lib/ebml.rs b/src/lib/ebml.rs index 09d0bee1a60..6b380850a61 100644 --- a/src/lib/ebml.rs +++ b/src/lib/ebml.rs @@ -17,7 +17,7 @@ type ebml_state = {ebml_tag: ebml_tag, tag_pos: uint, data_pos: uint}; // ebml reading type doc = {data: @[u8], start: uint, end: uint}; -fn vint_at(data: &[u8], start: uint) -> {val: uint, next: uint} { +fn vint_at(data: [u8], start: uint) -> {val: uint, next: uint} { let a = data[start]; if a & 0x80u8 != 0u8 { ret {val: a & 0x7fu8 as uint, next: start + 1u}; } if a & 0x40u8 != 0u8 { @@ -39,11 +39,11 @@ fn vint_at(data: &[u8], start: uint) -> {val: uint, next: uint} { } else { log_err "vint too big"; fail; } } -fn new_doc(data: &@[u8]) -> doc { +fn new_doc(data: @[u8]) -> doc { ret {data: data, start: 0u, end: vec::len::<u8>(*data)}; } -fn doc_at(data: &@[u8], start: uint) -> doc { +fn doc_at(data: @[u8], start: uint) -> doc { let elt_tag = vint_at(*data, start); let elt_size = vint_at(*data, elt_tag.next); let end = elt_size.next + elt_size.val; @@ -98,7 +98,7 @@ iter tagged_docs(d: doc, tg: uint) -> doc { fn doc_data(d: doc) -> [u8] { ret vec::slice::<u8>(*d.data, d.start, d.end); } -fn be_uint_from_bytes(data: &@[u8], start: uint, size: uint) -> uint { +fn be_uint_from_bytes(data: @[u8], start: uint, size: uint) -> uint { let sz = size; assert (sz <= 4u); let val = 0u; @@ -119,7 +119,7 @@ fn doc_as_uint(d: doc) -> uint { // ebml writing type writer = {writer: io::buf_writer, mutable size_positions: [uint]}; -fn write_sized_vint(w: &io::buf_writer, n: uint, size: uint) { +fn write_sized_vint(w: io::buf_writer, n: uint, size: uint) { let buf: [u8]; alt size { 1u { buf = [0x80u8 | (n as u8)]; } @@ -139,7 +139,7 @@ fn write_sized_vint(w: &io::buf_writer, n: uint, size: uint) { w.write(buf); } -fn write_vint(w: &io::buf_writer, n: uint) { +fn write_vint(w: io::buf_writer, n: uint) { if n < 0x7fu { write_sized_vint(w, n, 1u); ret; } if n < 0x4000u { write_sized_vint(w, n, 2u); ret; } if n < 0x200000u { write_sized_vint(w, n, 3u); ret; } @@ -148,14 +148,14 @@ fn write_vint(w: &io::buf_writer, n: uint) { fail; } -fn create_writer(w: &io::buf_writer) -> writer { +fn create_writer(w: io::buf_writer) -> writer { let size_positions: [uint] = []; ret {writer: w, mutable size_positions: size_positions}; } // TODO: Provide a function to write the standard ebml header. -fn start_tag(w: &writer, tag_id: uint) { +fn start_tag(w: writer, tag_id: uint) { // Write the tag ID: write_vint(w.writer, tag_id); @@ -166,7 +166,7 @@ fn start_tag(w: &writer, tag_id: uint) { w.writer.write(zeroes); } -fn end_tag(w: &writer) { +fn end_tag(w: writer) { let last_size_pos = vec::pop::<uint>(w.size_positions); let cur_pos = w.writer.tell(); w.writer.seek(last_size_pos as int, io::seek_set); diff --git a/src/lib/either.rs b/src/lib/either.rs index 6f2a27a958d..73efdbb70f1 100644 --- a/src/lib/either.rs +++ b/src/lib/either.rs @@ -6,12 +6,12 @@ import option::none; tag t<T, U> { left(T); right(U); } fn either<T, U, - V>(f_left: &block(&T) -> V, f_right: &block(&U) -> V, - value: &t<T, U>) -> V { + V>(f_left: block(T) -> V, f_right: block(U) -> V, value: t<T, U>) -> + V { alt value { left(l) { f_left(l) } right(r) { f_right(r) } } } -fn lefts<T, U>(eithers: &[t<T, U>]) -> [T] { +fn lefts<T, U>(eithers: [t<T, U>]) -> [T] { let result: [T] = []; for elt: t<T, U> in eithers { alt elt { left(l) { result += [l] } _ {/* fallthrough */ } } @@ -19,7 +19,7 @@ fn lefts<T, U>(eithers: &[t<T, U>]) -> [T] { ret result; } -fn rights<T, U>(eithers: &[t<T, U>]) -> [U] { +fn rights<T, U>(eithers: [t<T, U>]) -> [U] { let result: [U] = []; for elt: t<T, U> in eithers { alt elt { right(r) { result += [r] } _ {/* fallthrough */ } } @@ -27,7 +27,7 @@ fn rights<T, U>(eithers: &[t<T, U>]) -> [U] { ret result; } -fn partition<T, U>(eithers: &[t<T, U>]) -> {lefts: [T], rights: [U]} { +fn partition<T, U>(eithers: [t<T, U>]) -> {lefts: [T], rights: [U]} { let lefts: [T] = []; let rights: [U] = []; for elt: t<T, U> in eithers { diff --git a/src/lib/extfmt.rs b/src/lib/extfmt.rs index edd99120872..7a645201741 100644 --- a/src/lib/extfmt.rs +++ b/src/lib/extfmt.rs @@ -68,13 +68,13 @@ mod ct { // A fragment of the output sequence tag piece { piece_string(str); piece_conv(conv); } - type error_fn = fn(&str) -> ! ; + type error_fn = fn(str) -> ! ; - fn parse_fmt_string(s: &str, error: error_fn) -> [piece] { + fn parse_fmt_string(s: str, error: error_fn) -> [piece] { let pieces: [piece] = []; let lim = str::byte_len(s); let buf = ""; - fn flush_buf(buf: &str, pieces: &mutable [piece]) -> str { + fn flush_buf(buf: str, pieces: &mutable [piece]) -> str { if str::byte_len(buf) > 0u { let piece = piece_string(buf); pieces += [piece]; @@ -103,7 +103,7 @@ mod ct { buf = flush_buf(buf, pieces); ret pieces; } - fn peek_num(s: &str, i: uint, lim: uint) -> + fn peek_num(s: str, i: uint, lim: uint) -> option::t<{num: uint, next: uint}> { if i >= lim { ret none; } let c = s[i]; @@ -118,7 +118,7 @@ mod ct { } }; } - fn parse_conversion(s: &str, i: uint, lim: uint, error: error_fn) -> + fn parse_conversion(s: str, i: uint, lim: uint, error: error_fn) -> {piece: piece, next: uint} { let parm = parse_parameter(s, i, lim); let flags = parse_flags(s, parm.next, lim); @@ -133,7 +133,7 @@ mod ct { ty: ty.ty}), next: ty.next}; } - fn parse_parameter(s: &str, i: uint, lim: uint) -> + fn parse_parameter(s: str, i: uint, lim: uint) -> {param: option::t<int>, next: uint} { if i >= lim { ret {param: none, next: i}; } let num = peek_num(s, i, lim); @@ -148,14 +148,14 @@ mod ct { } }; } - fn parse_flags(s: &str, i: uint, lim: uint) -> + fn parse_flags(s: str, i: uint, lim: uint) -> {flags: [flag], next: uint} { let noflags: [flag] = []; if i >= lim { ret {flags: noflags, next: i}; } // FIXME: This recursion generates illegal instructions if the return // value isn't boxed. Only started happening after the ivec conversion - fn more_(f: flag, s: &str, i: uint, lim: uint) -> + fn more_(f: flag, s: str, i: uint, lim: uint) -> @{flags: [flag], next: uint} { let next = parse_flags(s, i + 1u, lim); let rest = next.flags; @@ -177,8 +177,7 @@ mod ct { *more(flag_alternate) } else { {flags: noflags, next: i} }; } - fn parse_count(s: &str, i: uint, lim: uint) -> - {count: count, next: uint} { + fn parse_count(s: str, i: uint, lim: uint) -> {count: count, next: uint} { ret if i >= lim { {count: count_implied, next: i} } else if s[i] == '*' as u8 { @@ -198,7 +197,7 @@ mod ct { } }; } - fn parse_precision(s: &str, i: uint, lim: uint) -> + fn parse_precision(s: str, i: uint, lim: uint) -> {count: count, next: uint} { ret if i >= lim { {count: count_implied, next: i} @@ -214,7 +213,7 @@ mod ct { } } else { {count: count_implied, next: i} }; } - fn parse_type(s: &str, i: uint, lim: uint, error: error_fn) -> + fn parse_type(s: str, i: uint, lim: uint, error: error_fn) -> {ty: ty, next: uint} { if i >= lim { error("missing type in conversion"); } let tstr = str::substr(s, i, 1u); @@ -270,7 +269,7 @@ mod rt { // instead just use a bool per flag type conv = {flags: [flag], width: count, precision: count, ty: ty}; - fn conv_int(cv: &conv, i: int) -> str { + fn conv_int(cv: conv, i: int) -> str { let radix = 10u; let prec = get_int_precision(cv); let s = int_to_str_prec(i, radix, prec); @@ -283,7 +282,7 @@ mod rt { } ret pad(cv, s, pad_signed); } - fn conv_uint(cv: &conv, u: uint) -> str { + fn conv_uint(cv: conv, u: uint) -> str { let prec = get_int_precision(cv); let rs = alt cv.ty { @@ -295,17 +294,17 @@ mod rt { }; ret pad(cv, rs, pad_unsigned); } - fn conv_bool(cv: &conv, b: bool) -> str { + fn conv_bool(cv: conv, b: bool) -> str { let s = if b { "true" } else { "false" }; // run the boolean conversion through the string conversion logic, // giving it the same rules for precision, etc. ret conv_str(cv, s); } - fn conv_char(cv: &conv, c: char) -> str { + fn conv_char(cv: conv, c: char) -> str { ret pad(cv, str::from_char(c), pad_nozero); } - fn conv_str(cv: &conv, s: &str) -> str { + fn conv_str(cv: conv, s: str) -> str { // For strings, precision is the maximum characters // displayed @@ -346,7 +345,7 @@ mod rt { } else { s } }; } - fn get_int_precision(cv: &conv) -> uint { + fn get_int_precision(cv: conv) -> uint { ret alt cv.precision { count_is(c) { c as uint } count_implied. { 1u } @@ -360,7 +359,7 @@ mod rt { ret str::unsafe_from_bytes(svec); } tag pad_mode { pad_signed; pad_unsigned; pad_nozero; } - fn pad(cv: &conv, s: &str, mode: pad_mode) -> str { + fn pad(cv: conv, s: str, mode: pad_mode) -> str { let uwidth; alt cv.width { count_implied. { ret s; } @@ -388,7 +387,7 @@ mod rt { pad_signed. { might_zero_pad = true; signed = true; } pad_unsigned. { might_zero_pad = true; } } - fn have_precision(cv: &conv) -> bool { + fn have_precision(cv: conv) -> bool { ret alt cv.precision { count_implied. { false } _ { true } }; } let zero_padding = false; @@ -414,7 +413,7 @@ mod rt { } ret padstr + s; } - fn have_flag(flags: &[flag], f: flag) -> bool { + fn have_flag(flags: [flag], f: flag) -> bool { for candidate: flag in flags { if candidate == f { ret true; } } ret false; } diff --git a/src/lib/fs.rs b/src/lib/fs.rs index 3ab6d3f5786..d48c5487bd4 100644 --- a/src/lib/fs.rs +++ b/src/lib/fs.rs @@ -10,7 +10,7 @@ fn path_sep() -> str { ret str::from_char(os_fs::path_sep); } type path = str; -fn dirname(p: &path) -> path { +fn dirname(p: path) -> path { let i: int = str::rindex(p, os_fs::path_sep as u8); if i == -1 { i = str::rindex(p, os_fs::alt_path_sep as u8); @@ -19,7 +19,7 @@ fn dirname(p: &path) -> path { ret str::substr(p, 0u, i as uint); } -fn basename(p: &path) -> path { +fn basename(p: path) -> path { let i: int = str::rindex(p, os_fs::path_sep as u8); if i == -1 { i = str::rindex(p, os_fs::alt_path_sep as u8); @@ -32,7 +32,7 @@ fn basename(p: &path) -> path { // FIXME: Need some typestate to avoid bounds check when len(pre) == 0 -fn connect(pre: &path, post: &path) -> path { +fn connect(pre: path, post: path) -> path { let len = str::byte_len(pre); ret if pre[len - 1u] == os_fs::path_sep as u8 { @@ -41,11 +41,11 @@ fn connect(pre: &path, post: &path) -> path { } else { pre + path_sep() + post }; } -fn file_is_dir(p: &path) -> bool { +fn file_is_dir(p: path) -> bool { ret str::as_buf(p, {|buf| rustrt::rust_file_is_dir(buf) != 0 }); } -fn list_dir(p: &path) -> [str] { +fn list_dir(p: path) -> [str] { let p = p; let pl = str::byte_len(p); if pl == 0u || p[pl - 1u] as char != os_fs::path_sep { p += path_sep(); } @@ -58,11 +58,11 @@ fn list_dir(p: &path) -> [str] { ret full_paths; } -fn path_is_absolute(p: &path) -> bool { ret os_fs::path_is_absolute(p); } +fn path_is_absolute(p: path) -> bool { ret os_fs::path_is_absolute(p); } // FIXME: under Windows, we should prepend the current drive letter to paths // that start with a slash. -fn make_absolute(p: &path) -> path { +fn make_absolute(p: path) -> path { if path_is_absolute(p) { ret p; } else { ret connect(getcwd(), p); } } diff --git a/src/lib/fun_treemap.rs b/src/lib/fun_treemap.rs index 3d4894c4367..d8d6e217c95 100644 --- a/src/lib/fun_treemap.rs +++ b/src/lib/fun_treemap.rs @@ -29,7 +29,7 @@ type treemap<@K, @V> = @tree_node<K, V>; fn init<@K, @V>() -> treemap<K, V> { @empty } -fn insert<@K, @V>(m: &treemap<K, V>, k: &K, v: &V) -> treemap<K, V> { +fn insert<@K, @V>(m: treemap<K, V>, k: K, v: V) -> treemap<K, V> { @alt m { @empty. { node(@k, @v, @empty, @empty) } @node(@kk, vv, left, right) { @@ -42,7 +42,7 @@ fn insert<@K, @V>(m: &treemap<K, V>, k: &K, v: &V) -> treemap<K, V> { } } -fn find<@K, @V>(m: &treemap<K, V>, k: &K) -> option<V> { +fn find<@K, @V>(m: treemap<K, V>, k: K) -> option<V> { alt *m { empty. { none } node(@kk, @v, left, right) { @@ -55,7 +55,7 @@ fn find<@K, @V>(m: &treemap<K, V>, k: &K) -> option<V> { // Performs an in-order traversal -fn traverse<@K, @V>(m: &treemap<K, V>, f: fn(&K, &V)) { +fn traverse<@K, @V>(m: treemap<K, V>, f: fn(K, V)) { alt *m { empty. { } node(@k, @v, _, _) { diff --git a/src/lib/generic_os.rs b/src/lib/generic_os.rs index 8a34f76a387..9137df4acf5 100644 --- a/src/lib/generic_os.rs +++ b/src/lib/generic_os.rs @@ -3,7 +3,7 @@ import str::sbuf; #[cfg(target_os = "linux")] #[cfg(target_os = "macos")] -fn getenv(n: &str) -> option::t<str> { +fn getenv(n: str) -> option::t<str> { let s = str::as_buf(n, {|buf| os::libc::getenv(buf) }); ret if unsafe::reinterpret_cast(s) == 0 { option::none::<str> @@ -15,7 +15,7 @@ fn getenv(n: &str) -> option::t<str> { #[cfg(target_os = "linux")] #[cfg(target_os = "macos")] -fn setenv(n: &str, v: &str) { +fn setenv(n: str, v: str) { // FIXME (868) let _: () = str::as_buf(n, @@ -30,7 +30,7 @@ fn setenv(n: &str, v: &str) { } #[cfg(target_os = "win32")] -fn getenv(n: &str) -> option::t<str> { +fn getenv(n: str) -> option::t<str> { let nsize = 256u; while true { let v: [u8] = []; @@ -53,13 +53,18 @@ fn getenv(n: &str) -> option::t<str> { } #[cfg(target_os = "win32")] -fn setenv(n: &str, v: &str) { +fn setenv(n: str, v: str) { // FIXME (868) - let _: () = str::as_buf(n, {|nbuf| - let _: () = str::as_buf(v, {|vbuf| - os::kernel32::SetEnvironmentVariableA(nbuf, vbuf); - }); - }); + let _: () = + str::as_buf(n, + {|nbuf| + let _: () = + str::as_buf(v, + {|vbuf| + os::kernel32::SetEnvironmentVariableA(nbuf, + vbuf); + }); + }); } // Local Variables: diff --git a/src/lib/getopts.rs b/src/lib/getopts.rs index c36f766a5dc..de2573c13b3 100644 --- a/src/lib/getopts.rs +++ b/src/lib/getopts.rs @@ -37,29 +37,29 @@ tag occur { req; optional; multi; } type opt = {name: name, hasarg: hasarg, occur: occur}; -fn mkname(nm: &str) -> name { +fn mkname(nm: str) -> name { ret if str::char_len(nm) == 1u { short(str::char_at(nm, 0u)) } else { long(nm) }; } -fn reqopt(name: &str) -> opt { +fn reqopt(name: str) -> opt { ret {name: mkname(name), hasarg: yes, occur: req}; } -fn optopt(name: &str) -> opt { +fn optopt(name: str) -> opt { ret {name: mkname(name), hasarg: yes, occur: optional}; } -fn optflag(name: &str) -> opt { +fn optflag(name: str) -> opt { ret {name: mkname(name), hasarg: no, occur: optional}; } -fn optflagopt(name: &str) -> opt { +fn optflagopt(name: str) -> opt { ret {name: mkname(name), hasarg: maybe, occur: optional}; } -fn optmulti(name: &str) -> opt { +fn optmulti(name: str) -> opt { ret {name: mkname(name), hasarg: yes, occur: multi}; } @@ -67,15 +67,15 @@ tag optval { val(str); given; } type match = {opts: [opt], vals: [mutable [optval]], free: [str]}; -fn is_arg(arg: &str) -> bool { +fn is_arg(arg: str) -> bool { ret str::byte_len(arg) > 1u && arg[0] == '-' as u8; } -fn name_str(nm: &name) -> str { +fn name_str(nm: name) -> str { ret alt nm { short(ch) { str::from_char(ch) } long(s) { s } }; } -fn find_opt(opts: &[opt], nm: &name) -> option::t<uint> { +fn find_opt(opts: [opt], nm: name) -> option::t<uint> { let i = 0u; let l = vec::len::<opt>(opts); while i < l { if opts[i].name == nm { ret some::<uint>(i); } i += 1u; } @@ -90,7 +90,7 @@ tag fail_ { unexpected_argument(str); } -fn fail_str(f: &fail_) -> str { +fn fail_str(f: fail_) -> str { ret alt f { argument_missing(nm) { "Argument to option '" + nm + "' missing." } unrecognized_option(nm) { "Unrecognized option: '" + nm + "'." } @@ -106,7 +106,7 @@ fn fail_str(f: &fail_) -> str { tag result { success(match); failure(fail_); } -fn getopts(args: &[str], opts: &[opt]) -> result { +fn getopts(args: [str], opts: [opt]) -> result { let n_opts = vec::len::<opt>(opts); fn f(_x: uint) -> [optval] { ret []; } let vals = vec::init_fn_mut::<[optval]>(f, n_opts); @@ -200,24 +200,24 @@ fn getopts(args: &[str], opts: &[opt]) -> result { ret success({opts: opts, vals: vals, free: free}); } -fn opt_vals(m: &match, nm: &str) -> [optval] { +fn opt_vals(m: match, nm: str) -> [optval] { ret alt find_opt(m.opts, mkname(nm)) { some(id) { m.vals[id] } none. { log_err "No option '" + nm + "' defined."; fail } }; } -fn opt_val(m: &match, nm: &str) -> optval { ret opt_vals(m, nm)[0]; } +fn opt_val(m: match, nm: str) -> optval { ret opt_vals(m, nm)[0]; } -fn opt_present(m: &match, nm: &str) -> bool { +fn opt_present(m: match, nm: str) -> bool { ret vec::len::<optval>(opt_vals(m, nm)) > 0u; } -fn opt_str(m: &match, nm: &str) -> str { +fn opt_str(m: match, nm: str) -> str { ret alt opt_val(m, nm) { val(s) { s } _ { fail } }; } -fn opt_strs(m: &match, nm: &str) -> [str] { +fn opt_strs(m: match, nm: str) -> [str] { let acc: [str] = []; for v: optval in opt_vals(m, nm) { alt v { val(s) { acc += [s]; } _ { } } @@ -225,7 +225,7 @@ fn opt_strs(m: &match, nm: &str) -> [str] { ret acc; } -fn opt_maybe_str(m: &match, nm: &str) -> option::t<str> { +fn opt_maybe_str(m: match, nm: str) -> option::t<str> { let vals = opt_vals(m, nm); if vec::len::<optval>(vals) == 0u { ret none::<str>; } ret alt vals[0] { val(s) { some::<str>(s) } _ { none::<str> } }; @@ -235,7 +235,7 @@ fn opt_maybe_str(m: &match, nm: &str) -> option::t<str> { /// Returns none if the option was not present, `def` if the option was /// present but no argument was provided, and the argument if the option was /// present and an argument was provided. -fn opt_default(m: &match, nm: &str, def: &str) -> option::t<str> { +fn opt_default(m: match, nm: str, def: str) -> option::t<str> { let vals = opt_vals(m, nm); if vec::len::<optval>(vals) == 0u { ret none::<str>; } ret alt vals[0] { val(s) { some::<str>(s) } _ { some::<str>(def) } } diff --git a/src/lib/int.rs b/src/lib/int.rs index ef80852c8d3..98d8bb5e157 100644 --- a/src/lib/int.rs +++ b/src/lib/int.rs @@ -32,9 +32,9 @@ pure fn nonnegative(x: int) -> bool { ret x >= 0; } // FIXME: Make sure this works with negative integers. -fn hash(x: &int) -> uint { ret x as uint; } +fn hash(x: int) -> uint { ret x as uint; } -fn eq_alias(x: &int, y: &int) -> bool { ret x == y; } +fn eq_alias(x: int, y: int) -> bool { ret x == y; } iter range(lo: int, hi: int) -> int { let lo_: int = lo; diff --git a/src/lib/io.rs b/src/lib/io.rs index 0889d3ec454..73460e50588 100644 --- a/src/lib/io.rs +++ b/src/lib/io.rs @@ -174,7 +174,7 @@ fn stdin() -> reader { ret new_reader(FILE_buf_reader(rustrt::rust_get_stdin(), option::none)); } -fn file_reader(path: &str) -> reader { +fn file_reader(path: str) -> reader { let f = str::as_buf(path, {|pathbuf| @@ -218,11 +218,11 @@ obj byte_buf_reader(bbuf: byte_buf) { fn tell() -> uint { ret bbuf.pos; } } -fn new_byte_buf_reader(buf: &[u8]) -> buf_reader { +fn new_byte_buf_reader(buf: [u8]) -> buf_reader { ret byte_buf_reader(@{buf: buf, mutable pos: 0u}); } -fn string_reader(s: &str) -> reader { +fn string_reader(s: str) -> reader { ret new_reader(new_byte_buf_reader(str::bytes(s))); } @@ -236,13 +236,13 @@ type buf_writer = // FIXME: eventually u64 obj { - fn write(&[u8]); + fn write([u8]); fn seek(int, seek_style); fn tell() -> uint; }; obj FILE_writer(f: os::libc::FILE, res: option::t<@FILE_res>) { - fn write(v: &[u8]) { + fn write(v: [u8]) { let len = vec::len::<u8>(v); let vbuf = vec::unsafe::to_ptr::<u8>(v); let nout = os::libc::fwrite(vbuf, len, 1u, f); @@ -257,7 +257,7 @@ obj FILE_writer(f: os::libc::FILE, res: option::t<@FILE_res>) { resource fd_res(fd: int) { os::libc::close(fd); } obj fd_buf_writer(fd: int, res: option::t<@fd_res>) { - fn write(v: &[u8]) { + fn write(v: [u8]) { let len = vec::len::<u8>(v); let count = 0u; let vbuf; @@ -282,7 +282,7 @@ obj fd_buf_writer(fd: int, res: option::t<@fd_res>) { } } -fn file_buf_writer(path: &str, flags: &[fileflag]) -> buf_writer { +fn file_buf_writer(path: str, flags: [fileflag]) -> buf_writer { let fflags: int = os::libc_constants::O_WRONLY() | os::libc_constants::O_BINARY(); for f: fileflag in flags { @@ -313,12 +313,12 @@ type writer = // function will be provided for general encoded string output obj { fn get_buf_writer() -> buf_writer; - fn write_str(&str); - fn write_line(&str); + fn write_str(str); + fn write_line(str); fn write_char(char); fn write_int(int); fn write_uint(uint); - fn write_bytes(&[u8]); + fn write_bytes([u8]); fn write_le_uint(uint, uint); fn write_le_int(int, uint); fn write_be_uint(uint, uint); @@ -339,8 +339,8 @@ fn uint_to_be_bytes(n: uint, size: uint) -> [u8] { obj new_writer(out: buf_writer) { fn get_buf_writer() -> buf_writer { ret out; } - fn write_str(s: &str) { out.write(str::bytes(s)); } - fn write_line(s: &str) { + fn write_str(s: str) { out.write(str::bytes(s)); } + fn write_line(s: str) { out.write(str::bytes(s)); out.write(str::bytes("\n")); } @@ -351,7 +351,7 @@ obj new_writer(out: buf_writer) { } fn write_int(n: int) { out.write(str::bytes(int::to_str(n, 10u))); } fn write_uint(n: uint) { out.write(str::bytes(uint::to_str(n, 10u))); } - fn write_bytes(bytes: &[u8]) { out.write(bytes); } + fn write_bytes(bytes: [u8]) { out.write(bytes); } fn write_le_uint(n: uint, size: uint) { out.write(uint_to_le_bytes(n, size)); } @@ -363,13 +363,13 @@ obj new_writer(out: buf_writer) { } } -fn file_writer(path: &str, flags: &[fileflag]) -> writer { +fn file_writer(path: str, flags: [fileflag]) -> writer { ret new_writer(file_buf_writer(path, flags)); } // FIXME: fileflags -fn buffered_file_buf_writer(path: &str) -> buf_writer { +fn buffered_file_buf_writer(path: str) -> buf_writer { let f = str::as_buf(path, {|pathbuf| @@ -396,7 +396,7 @@ type str_writer = type mutable_byte_buf = @{mutable buf: [mutable u8], mutable pos: uint}; obj byte_buf_writer(buf: mutable_byte_buf) { - fn write(v: &[u8]) { + fn write(v: [u8]) { // Fast path. if buf.pos == vec::len(buf.buf) { @@ -453,11 +453,11 @@ fn seek_in_buf(offset: int, pos: uint, len: uint, whence: seek_style) -> ret bpos as uint; } -fn read_whole_file_str(file: &str) -> str { +fn read_whole_file_str(file: str) -> str { str::unsafe_from_bytes(read_whole_file(file)) } -fn read_whole_file(file: &str) -> [u8] { +fn read_whole_file(file: str) -> [u8] { // FIXME: There's a lot of copying here file_reader(file).read_whole_stream() diff --git a/src/lib/linux_os.rs b/src/lib/linux_os.rs index b393d9a1e08..5cd71d13b79 100644 --- a/src/lib/linux_os.rs +++ b/src/lib/linux_os.rs @@ -54,7 +54,7 @@ fn exec_suffix() -> str { ret ""; } fn target_os() -> str { ret "linux"; } -fn dylib_filename(base: &str) -> str { ret "lib" + base + ".so"; } +fn dylib_filename(base: str) -> str { ret "lib" + base + ".so"; } fn pipe() -> {in: int, out: int} { let fds = {mutable in: 0, mutable out: 0}; diff --git a/src/lib/list.rs b/src/lib/list.rs index 4f3cc5b2238..b3484281b1c 100644 --- a/src/lib/list.rs +++ b/src/lib/list.rs @@ -3,7 +3,7 @@ import option::none; tag list<T> { cons(T, @list<T>); nil; } -fn from_vec<@T>(v: &[T]) -> list<T> { +fn from_vec<@T>(v: [T]) -> list<T> { let l = nil::<T>; // FIXME: This would be faster and more space efficient if it looped over // a reverse vector iterator. Unfortunately generic iterators seem not to @@ -13,7 +13,7 @@ fn from_vec<@T>(v: &[T]) -> list<T> { ret l; } -fn foldl<@T, @U>(ls_: &list<T>, u: &U, f: &block(&T, &U) -> U) -> U { +fn foldl<@T, @U>(ls_: list<T>, u: U, f: block(T, U) -> U) -> U { let accum: U = u; let ls = ls_; while true { @@ -25,8 +25,7 @@ fn foldl<@T, @U>(ls_: &list<T>, u: &U, f: &block(&T, &U) -> U) -> U { ret accum; } -fn find<@T, @U>(ls_: &list<T>, f: &block(&T) -> option::t<U>) -> - option::t<U> { +fn find<@T, @U>(ls_: list<T>, f: block(T) -> option::t<U>) -> option::t<U> { let ls = ls_; while true { alt ls { @@ -39,7 +38,7 @@ fn find<@T, @U>(ls_: &list<T>, f: &block(&T) -> option::t<U>) -> ret none; } -fn has<@T>(ls_: &list<T>, elt: &T) -> bool { +fn has<@T>(ls_: list<T>, elt: T) -> bool { let ls = ls_; while true { alt ls { @@ -50,20 +49,20 @@ fn has<@T>(ls_: &list<T>, elt: &T) -> bool { ret false; } -fn length<@T>(ls: &list<T>) -> uint { - fn count<T>(_t: &T, u: &uint) -> uint { ret u + 1u; } +fn length<@T>(ls: list<T>) -> uint { + fn count<T>(_t: T, u: uint) -> uint { ret u + 1u; } ret foldl(ls, 0u, count); } -fn cdr<@T>(ls: &list<T>) -> list<T> { +fn cdr<@T>(ls: list<T>) -> list<T> { alt ls { cons(_, tl) { ret *tl; } nil. { fail "list empty" } } } -fn car<@T>(ls: &list<T>) -> T { +fn car<@T>(ls: list<T>) -> T { alt ls { cons(hd, _) { ret hd; } nil. { fail "list empty" } } } -fn append<@T>(l: &list<T>, m: &list<T>) -> list<T> { +fn append<@T>(l: list<T>, m: list<T>) -> list<T> { alt l { nil. { ret m; } cons(x, xs) { let rest = append(*xs, m); ret cons(x, @rest); } diff --git a/src/lib/macos_os.rs b/src/lib/macos_os.rs index e18fdd5b32f..3a63a9d2ffb 100644 --- a/src/lib/macos_os.rs +++ b/src/lib/macos_os.rs @@ -51,7 +51,7 @@ fn exec_suffix() -> str { ret ""; } fn target_os() -> str { ret "macos"; } -fn dylib_filename(base: &str) -> str { ret "lib" + base + ".dylib"; } +fn dylib_filename(base: str) -> str { ret "lib" + base + ".dylib"; } fn pipe() -> {in: int, out: int} { let fds = {mutable in: 0, mutable out: 0}; diff --git a/src/lib/map.rs b/src/lib/map.rs index d54eae03d10..81be20a6620 100644 --- a/src/lib/map.rs +++ b/src/lib/map.rs @@ -1,27 +1,27 @@ /** * Hashmap implementation. */ -type hashfn<K> = fn(&K) -> uint; +type hashfn<K> = fn(K) -> uint; -type eqfn<K> = fn(&K, &K) -> bool; +type eqfn<K> = fn(K, K) -> bool; type hashmap<K, V> = obj { fn size() -> uint; - fn insert(&K, &V) -> bool; - fn contains_key(&K) -> bool; - fn get(&K) -> V; - fn find(&K) -> option::t<V>; - fn remove(&K) -> option::t<V>; + fn insert(K, V) -> bool; + fn contains_key(K) -> bool; + fn get(K) -> V; + fn find(K) -> option::t<V>; + fn remove(K) -> option::t<V>; fn rehash(); iter items() -> @{key: K, val: V}; iter keys() -> K; }; type hashset<K> = hashmap<K, ()>; -fn set_add<@K>(set: hashset<K>, key: &K) -> bool { ret set.insert(key, ()); } +fn set_add<@K>(set: hashset<K>, key: K) -> bool { ret set.insert(key, ()); } -fn mk_hashmap<@K, @V>(hasher: &hashfn<K>, eqer: &eqfn<K>) -> hashmap<K, V> { +fn mk_hashmap<@K, @V>(hasher: hashfn<K>, eqer: eqfn<K>) -> hashmap<K, V> { let initial_capacity: uint = 32u; // 2^5 let load_factor: util::rational = {num: 3, den: 4}; @@ -54,9 +54,9 @@ fn mk_hashmap<@K, @V>(hasher: &hashfn<K>, eqer: &eqfn<K>) -> hashmap<K, V> { */ fn insert_common<@K, - @V>(hasher: &hashfn<K>, eqer: &eqfn<K>, - bkts: &[mutable bucket<K, V>], nbkts: uint, key: &K, - val: &V) -> bool { + @V>(hasher: hashfn<K>, eqer: eqfn<K>, + bkts: [mutable bucket<K, V>], nbkts: uint, key: K, + val: V) -> bool { let i: uint = 0u; let h: uint = hasher(key); while i < nbkts { @@ -75,8 +75,8 @@ fn mk_hashmap<@K, @V>(hasher: &hashfn<K>, eqer: &eqfn<K>) -> hashmap<K, V> { fail; // full table } fn find_common<@K, - @V>(hasher: &hashfn<K>, eqer: &eqfn<K>, - bkts: &[mutable bucket<K, V>], nbkts: uint, key: &K) -> + @V>(hasher: hashfn<K>, eqer: eqfn<K>, + bkts: [mutable bucket<K, V>], nbkts: uint, key: K) -> option::t<V> { let i: uint = 0u; let h: uint = hasher(key); @@ -97,9 +97,9 @@ fn mk_hashmap<@K, @V>(hasher: &hashfn<K>, eqer: &eqfn<K>) -> hashmap<K, V> { ret option::none; } fn rehash<@K, - @V>(hasher: &hashfn<K>, eqer: &eqfn<K>, - oldbkts: &[mutable bucket<K, V>], _noldbkts: uint, - newbkts: &[mutable bucket<K, V>], nnewbkts: uint) { + @V>(hasher: hashfn<K>, eqer: eqfn<K>, + oldbkts: [mutable bucket<K, V>], _noldbkts: uint, + newbkts: [mutable bucket<K, V>], nnewbkts: uint) { for b: bucket<K, V> in oldbkts { alt b { some(k_, v_) { @@ -119,7 +119,7 @@ fn mk_hashmap<@K, @V>(hasher: &hashfn<K>, eqer: &eqfn<K>) -> hashmap<K, V> { mutable nelts: uint, lf: util::rational) { fn size() -> uint { ret nelts; } - fn insert(key: &K, val: &V) -> bool { + fn insert(key: K, val: V) -> bool { let load: util::rational = {num: nelts + 1u as int, den: nbkts as int}; if !util::rational_leq(load, lf) { @@ -135,22 +135,22 @@ fn mk_hashmap<@K, @V>(hasher: &hashfn<K>, eqer: &eqfn<K>) -> hashmap<K, V> { } ret false; } - fn contains_key(key: &K) -> bool { + fn contains_key(key: K) -> bool { ret alt find_common(hasher, eqer, bkts, nbkts, key) { option::some(_) { true } _ { false } }; } - fn get(key: &K) -> V { + fn get(key: K) -> V { ret alt find_common(hasher, eqer, bkts, nbkts, key) { option::some(val) { val } _ { fail } }; } - fn find(key: &K) -> option::t<V> { + fn find(key: K) -> option::t<V> { be find_common(hasher, eqer, bkts, nbkts, key); } - fn remove(key: &K) -> option::t<V> { + fn remove(key: K) -> option::t<V> { let i: uint = 0u; let h: uint = hasher(key); while i < nbkts { @@ -199,14 +199,14 @@ fn new_str_hash<@V>() -> hashmap<str, V> { } fn new_int_hash<@V>() -> hashmap<int, V> { - fn hash_int(x: &int) -> uint { ret x as uint; } - fn eq_int(a: &int, b: &int) -> bool { ret a == b; } + fn hash_int(x: int) -> uint { ret x as uint; } + fn eq_int(a: int, b: int) -> bool { ret a == b; } ret mk_hashmap(hash_int, eq_int); } fn new_uint_hash<@V>() -> hashmap<uint, V> { - fn hash_uint(x: &uint) -> uint { ret x; } - fn eq_uint(a: &uint, b: &uint) -> bool { ret a == b; } + fn hash_uint(x: uint) -> uint { ret x; } + fn eq_uint(a: uint, b: uint) -> bool { ret a == b; } ret mk_hashmap(hash_uint, eq_uint); } diff --git a/src/lib/net.rs b/src/lib/net.rs index be778d9858e..c7c042a54a9 100644 --- a/src/lib/net.rs +++ b/src/lib/net.rs @@ -12,8 +12,8 @@ fn format_addr(ip: ip_addr) -> str { } } -fn parse_addr(ip: &str) -> ip_addr { - let parts = vec::map({|&s| uint::from_str(s) }, str::split(ip, "."[0])); +fn parse_addr(ip: str) -> ip_addr { + let parts = vec::map({|s| uint::from_str(s) }, str::split(ip, "."[0])); if vec::len(parts) != 4u { fail "Too many dots in IP address"; } for i in parts { if i > 255u { fail "Invalid IP Address part."; } } ipv4(parts[0] as u8, parts[1] as u8, parts[2] as u8, parts[3] as u8) diff --git a/src/lib/option.rs b/src/lib/option.rs index ea14ef2b867..c10c22ae18d 100644 --- a/src/lib/option.rs +++ b/src/lib/option.rs @@ -2,30 +2,30 @@ tag t<@T> { none; some(T); } -fn get<@T>(opt: &t<T>) -> T { +fn get<@T>(opt: t<T>) -> T { alt opt { some(x) { x } none. { fail "option none" } } } -fn map<@T, @U>(f: &block(&T) -> U, opt: &t<T>) -> t<U> { +fn map<@T, @U>(f: block(T) -> U, opt: t<T>) -> t<U> { alt opt { some(x) { some(f(x)) } none. { none } } } -fn is_none<@T>(opt: &t<T>) -> bool { +fn is_none<@T>(opt: t<T>) -> bool { alt opt { none. { true } some(_) { false } } } -fn is_some<@T>(opt: &t<T>) -> bool { !is_none(opt) } +fn is_some<@T>(opt: t<T>) -> bool { !is_none(opt) } -fn from_maybe<@T>(def: &T, opt: &t<T>) -> T { +fn from_maybe<@T>(def: T, opt: t<T>) -> T { alt opt { some(x) { x } none. { def } } } -fn maybe<@T, @U>(def: &U, f: &block(&T) -> U, opt: &t<T>) -> U { +fn maybe<@T, @U>(def: U, f: block(T) -> U, opt: t<T>) -> U { alt opt { none. { def } some(t) { f(t) } } } // Can be defined in terms of the above when/if we have const bind. -fn may<@T>(f: &block(&T), opt: &t<T>) { +fn may<@T>(f: block(T), opt: t<T>) { alt opt { none. {/* nothing */ } some(t) { f(t); } } } diff --git a/src/lib/posix_fs.rs b/src/lib/posix_fs.rs index 8b4f06a6a9b..a20f9d7711f 100644 --- a/src/lib/posix_fs.rs +++ b/src/lib/posix_fs.rs @@ -1,9 +1,9 @@ native "rust" mod rustrt { - fn rust_list_files(path: &str) -> [str]; + fn rust_list_files(path: str) -> [str]; } -fn list_dir(path: &str) -> [str] { +fn list_dir(path: str) -> [str] { ret rustrt::rust_list_files(path); // FIXME: No idea why, but this appears to corrupt memory on OSX. I @@ -30,7 +30,7 @@ fn list_dir(path: &str) -> [str] { } -fn path_is_absolute(p: &str) -> bool { ret str::char_at(p, 0u) == '/'; } +fn path_is_absolute(p: str) -> bool { ret str::char_at(p, 0u) == '/'; } const path_sep: char = '/'; diff --git a/src/lib/ptr.rs b/src/lib/ptr.rs index 42815845e47..8d730732c3c 100644 --- a/src/lib/ptr.rs +++ b/src/lib/ptr.rs @@ -1,11 +1,11 @@ // Unsafe pointer utility functions. native "rust-intrinsic" mod rusti { - fn addr_of<T>(val: &T) -> *mutable T; + fn addr_of<T>(val: T) -> *mutable T; fn ptr_offset<T>(ptr: *T, count: uint) -> *T; } -fn addr_of<T>(val: &T) -> *mutable T { ret rusti::addr_of(val); } +fn addr_of<T>(val: T) -> *mutable T { ret rusti::addr_of(val); } fn offset<T>(ptr: *T, count: uint) -> *T { ret rusti::ptr_offset(ptr, count); } diff --git a/src/lib/run_program.rs b/src/lib/run_program.rs index a4adaace38a..43fe4bc3d95 100644 --- a/src/lib/run_program.rs +++ b/src/lib/run_program.rs @@ -12,19 +12,19 @@ native "rust" mod rustrt { int; } -fn arg_vec(prog: &str, args: &[@str]) -> [sbuf] { +fn arg_vec(prog: str, args: [@str]) -> [sbuf] { let argptrs = str::as_buf(prog, {|buf| [buf] }); for arg in args { argptrs += str::as_buf(*arg, {|buf| [buf] }); } argptrs += [unsafe::reinterpret_cast(0)]; ret argptrs; } -fn spawn_process(prog: &str, args: &[str], in_fd: int, out_fd: int, - err_fd: int) -> int { +fn spawn_process(prog: str, args: [str], in_fd: int, out_fd: int, err_fd: int) + -> int { // Note: we have to hold on to these vector references while we hold a // pointer to their buffers let prog = prog; - let args = vec::map({|&arg| @arg }, args); + let args = vec::map({|arg| @arg }, args); let argv = arg_vec(prog, args); let pid = rustrt::rust_run_program(vec::unsafe::to_ptr(argv), in_fd, out_fd, @@ -32,7 +32,7 @@ fn spawn_process(prog: &str, args: &[str], in_fd: int, out_fd: int, ret pid; } -fn run_program(prog: &str, args: &[str]) -> int { +fn run_program(prog: str, args: [str]) -> int { ret os::waitpid(spawn_process(prog, args, 0, 0, 0)); } @@ -49,7 +49,7 @@ type program = resource program_res(p: program) { p.destroy(); } -fn start_program(prog: &str, args: &[str]) -> @program_res { +fn start_program(prog: str, args: [str]) -> @program_res { let pipe_input = os::pipe(); let pipe_output = os::pipe(); let pipe_err = os::pipe(); @@ -100,7 +100,7 @@ fn start_program(prog: &str, args: &[str]) -> @program_res { os::fd_FILE(pipe_err.in), false)); } -fn read_all(rd: &io::reader) -> str { +fn read_all(rd: io::reader) -> str { let buf = ""; while !rd.eof() { let bytes = rd.read_bytes(4096u); @@ -109,7 +109,7 @@ fn read_all(rd: &io::reader) -> str { ret buf; } -fn program_output(prog: &str, args: &[str]) -> +fn program_output(prog: str, args: [str]) -> {status: int, out: str, err: str} { let pr = start_program(prog, args); pr.close_input(); diff --git a/src/lib/sha1.rs b/src/lib/sha1.rs index 25003a4b128..313ec407e26 100644 --- a/src/lib/sha1.rs +++ b/src/lib/sha1.rs @@ -15,8 +15,8 @@ type sha1 = // Reset the sha1 state for reuse. This is called // automatically during construction obj { - fn input(&[u8]); - fn input_str(&str); + fn input([u8]); + fn input_str(str); fn result() -> [u8]; fn result_str() -> str; fn reset(); @@ -44,7 +44,7 @@ fn mk_sha1() -> sha1 { mutable computed: bool, work_buf: [mutable u32]}; - fn add_input(st: &sha1state, msg: &[u8]) { + fn add_input(st: sha1state, msg: [u8]) { // FIXME: Should be typestate precondition assert (!st.computed); for element: u8 in msg { @@ -62,7 +62,7 @@ fn mk_sha1() -> sha1 { if st.msg_block_idx == msg_block_len { process_msg_block(st); } } } - fn process_msg_block(st: &sha1state) { + fn process_msg_block(st: sha1state) { // FIXME: Make precondition assert (vec::len(st.h) == digest_buf_len); assert (vec::len(st.work_buf) == work_buf_len); @@ -142,7 +142,7 @@ fn mk_sha1() -> sha1 { fn circular_shift(bits: u32, word: u32) -> u32 { ret word << bits | word >> 32u32 - bits; } - fn mk_result(st: &sha1state) -> [u8] { + fn mk_result(st: sha1state) -> [u8] { if !st.computed { pad_msg(st); st.computed = true; } let rs: [u8] = []; for hpart: u32 in st.h { @@ -164,7 +164,7 @@ fn mk_sha1() -> sha1 { * call process_msg_block() appropriately. When it returns, it * can be assumed that the message digest has been computed. */ - fn pad_msg(st: &sha1state) { + fn pad_msg(st: sha1state) { // FIXME: Should be a precondition assert (vec::len(st.msg_block) == msg_block_len); @@ -215,8 +215,8 @@ fn mk_sha1() -> sha1 { st.h[4] = 0xC3D2E1F0u32; st.computed = false; } - fn input(msg: &[u8]) { add_input(st, msg); } - fn input_str(msg: &str) { add_input(st, str::bytes(msg)); } + fn input(msg: [u8]) { add_input(st, msg); } + fn input_str(msg: str) { add_input(st, str::bytes(msg)); } fn result() -> [u8] { ret mk_result(st); } fn result_str() -> str { let r = mk_result(st); diff --git a/src/lib/smallintmap.rs b/src/lib/smallintmap.rs index d5dcd6bcc78..5d706ea4b4f 100644 --- a/src/lib/smallintmap.rs +++ b/src/lib/smallintmap.rs @@ -14,31 +14,31 @@ fn mk<@T>() -> smallintmap<T> { ret @{mutable v: v}; } -fn insert<@T>(m: &smallintmap<T>, key: uint, val: &T) { +fn insert<@T>(m: smallintmap<T>, key: uint, val: T) { vec::grow_set::<option::t<T>>(m.v, key, none::<T>, some::<T>(val)); } -fn find<@T>(m: &smallintmap<T>, key: uint) -> option::t<T> { +fn find<@T>(m: smallintmap<T>, key: uint) -> option::t<T> { if key < vec::len::<option::t<T>>(m.v) { ret m.v[key]; } ret none::<T>; } -fn get<@T>(m: &smallintmap<T>, key: uint) -> T { +fn get<@T>(m: smallintmap<T>, key: uint) -> T { alt find::<T>(m, key) { none::<T>. { log_err "smallintmap::get(): key not present"; fail; } some::<T>(v) { ret v; } } } -fn contains_key<@T>(m: &smallintmap<T>, key: uint) -> bool { +fn contains_key<@T>(m: smallintmap<T>, key: uint) -> bool { ret !option::is_none(find::<T>(m, key)); } -fn truncate<@T>(m: &smallintmap<T>, len: uint) { +fn truncate<@T>(m: smallintmap<T>, len: uint) { m.v = vec::slice_mut::<option::t<T>>(m.v, 0u, len); } -fn max_key<T>(m: &smallintmap<T>) -> uint { +fn max_key<T>(m: smallintmap<T>) -> uint { ret vec::len::<option::t<T>>(m.v); } diff --git a/src/lib/sort.rs b/src/lib/sort.rs index 2a43bde42be..17e7c90ae38 100644 --- a/src/lib/sort.rs +++ b/src/lib/sort.rs @@ -6,10 +6,10 @@ export merge_sort; export quick_sort; export quick_sort3; -type lteq<T> = block(&T, &T) -> bool; +type lteq<T> = block(T, T) -> bool; -fn merge_sort<@T>(le: <eq<T>, v: &[T]) -> [T] { - fn merge<@T>(le: <eq<T>, a: &[T], b: &[T]) -> [T] { +fn merge_sort<@T>(le: lteq<T>, v: [T]) -> [T] { + fn merge<@T>(le: lteq<T>, a: [T], b: [T]) -> [T] { let rs: [T] = []; let a_len: uint = len::<T>(a); let a_ix: uint = 0u; @@ -33,14 +33,14 @@ fn merge_sort<@T>(le: <eq<T>, v: &[T]) -> [T] { ret merge::<T>(le, merge_sort::<T>(le, a), merge_sort::<T>(le, b)); } -fn swap<@T>(arr: &[mutable T], x: uint, y: uint) { +fn swap<@T>(arr: [mutable T], x: uint, y: uint) { let a = arr[x]; arr[x] = arr[y]; arr[y] = a; } -fn part<@T>(compare_func: <eq<T>, arr: &[mutable T], left: uint, - right: uint, pivot: uint) -> uint { +fn part<@T>(compare_func: lteq<T>, arr: [mutable T], left: uint, right: uint, + pivot: uint) -> uint { let pivot_value = arr[pivot]; swap::<T>(arr, pivot, right); let storage_index: uint = left; @@ -56,7 +56,7 @@ fn part<@T>(compare_func: <eq<T>, arr: &[mutable T], left: uint, ret storage_index; } -fn qsort<@T>(compare_func: <eq<T>, arr: &[mutable T], left: uint, +fn qsort<@T>(compare_func: lteq<T>, arr: [mutable T], left: uint, right: uint) { if right > left { let pivot = (left + right) / 2u; @@ -69,7 +69,7 @@ fn qsort<@T>(compare_func: <eq<T>, arr: &[mutable T], left: uint, } } -fn quick_sort<@T>(compare_func: <eq<T>, arr: &[mutable T]) { +fn quick_sort<@T>(compare_func: lteq<T>, arr: [mutable T]) { if len::<T>(arr) == 0u { ret; } qsort::<T>(compare_func, arr, 0u, len::<T>(arr) - 1u); } @@ -79,8 +79,8 @@ fn quick_sort<@T>(compare_func: <eq<T>, arr: &[mutable T]) { // http://www.cs.princeton.edu/~rs/talks/QuicksortIsOptimal.pdf // According to these slides this is the algorithm of choice for // 'randomly ordered keys, abstract compare' & 'small number of key values' -fn qsort3<@T>(compare_func_lt: <eq<T>, compare_func_eq: <eq<T>, - arr: &[mutable T], left: int, right: int) { +fn qsort3<@T>(compare_func_lt: lteq<T>, compare_func_eq: lteq<T>, + arr: [mutable T], left: int, right: int) { if right <= left { ret; } let v: T = arr[right]; let i: int = left - 1; @@ -127,8 +127,8 @@ fn qsort3<@T>(compare_func_lt: <eq<T>, compare_func_eq: <eq<T>, qsort3::<T>(compare_func_lt, compare_func_eq, arr, i, right); } -fn quick_sort3<@T>(compare_func_lt: <eq<T>, compare_func_eq: <eq<T>, - arr: &[mutable T]) { +fn quick_sort3<@T>(compare_func_lt: lteq<T>, compare_func_eq: lteq<T>, + arr: [mutable T]) { if len::<T>(arr) == 0u { ret; } qsort3::<T>(compare_func_lt, compare_func_eq, arr, 0, (len::<T>(arr) as int) - 1); diff --git a/src/lib/str.rs b/src/lib/str.rs index 1d03f768101..c6edc5cb574 100644 --- a/src/lib/str.rs +++ b/src/lib/str.rs @@ -10,11 +10,11 @@ native "rust" mod rustrt { fn rust_str_push(s: &mutable 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. @@ -37,7 +37,7 @@ const tag_five_b: uint = 248u; const max_five_b: uint = 67108864u; const tag_six_b: uint = 252u; -fn is_utf8(v: &[u8]) -> bool { +fn is_utf8(v: [u8]) -> bool { let i = 0u; let total = vec::len::<u8>(v); while i < total { @@ -54,19 +54,19 @@ fn is_utf8(v: &[u8]) -> bool { ret true; } -fn is_ascii(s: &str) -> bool { +fn is_ascii(s: str) -> bool { let i: uint = byte_len(s); while i > 0u { i -= 1u; if s[i] & 128u8 != 0u8 { ret false; } } ret true; } /// Returns true if the string has length 0 -pure fn is_empty(s: &str) -> bool { for c: u8 in s { ret false; } ret true; } +pure fn is_empty(s: str) -> bool { for c: u8 in s { ret false; } ret true; } /// Returns true if the string has length greater than 0 -pure fn is_not_empty(s: &str) -> bool { !is_empty(s) } +pure fn is_not_empty(s: str) -> bool { !is_empty(s) } -fn is_whitespace(s: &str) -> bool { +fn is_whitespace(s: str) -> bool { let i = 0u; let len = char_len(s); while i < len { @@ -76,7 +76,7 @@ fn is_whitespace(s: &str) -> bool { ret true; } -fn byte_len(s: &str) -> uint { +fn byte_len(s: str) -> uint { let v: [u8] = unsafe::reinterpret_cast(s); let vlen = vec::len(v); unsafe::leak(v); @@ -85,14 +85,14 @@ fn byte_len(s: &str) -> uint { ret vlen - 1u; } -fn bytes(s: &str) -> [u8] { +fn bytes(s: str) -> [u8] { let v = unsafe::reinterpret_cast(s); let vcopy = vec::slice(v, 0u, vec::len(v) - 1u); unsafe::leak(v); ret vcopy; } -fn unsafe_from_bytes(v: &[mutable? u8]) -> str { +fn unsafe_from_bytes(v: [mutable? u8]) -> str { let vcopy: [u8] = v + [0u8]; let scopy: str = unsafe::reinterpret_cast(vcopy); unsafe::leak(vcopy); @@ -136,7 +136,7 @@ fn from_char(ch: char) -> str { ret buf; } -fn from_chars(chs: &[char]) -> str { +fn from_chars(chs: [char]) -> str { let buf = ""; for ch: char in chs { push_utf8_bytes(buf, ch); } ret buf; @@ -156,7 +156,7 @@ fn utf8_char_width(b: u8) -> uint { ret 6u; } -fn char_range_at(s: &str, i: uint) -> {ch: char, next: uint} { +fn char_range_at(s: str, i: uint) -> {ch: char, next: uint} { let b0 = s[i]; let w = utf8_char_width(b0); assert (w != 0u); @@ -178,9 +178,9 @@ fn char_range_at(s: &str, i: uint) -> {ch: char, next: uint} { ret {ch: val as char, next: i}; } -fn char_at(s: &str, i: uint) -> char { ret char_range_at(s, i).ch; } +fn char_at(s: str, i: uint) -> char { ret char_range_at(s, i).ch; } -fn char_len(s: &str) -> uint { +fn char_len(s: str) -> uint { let i = 0u; let len = 0u; let total = byte_len(s); @@ -194,7 +194,7 @@ fn char_len(s: &str) -> uint { ret len; } -fn to_chars(s: &str) -> [char] { +fn to_chars(s: str) -> [char] { let buf: [char] = []; let i = 0u; let len = byte_len(s); @@ -225,23 +225,23 @@ fn shift_char(s: &mutable str) -> char { fn unshift_char(s: &mutable str, ch: char) { s = from_char(ch) + s; } -fn index(s: &str, c: u8) -> int { +fn index(s: str, c: u8) -> int { let i: int = 0; for k: u8 in s { if k == c { ret i; } i += 1; } ret -1; } -fn rindex(s: &str, c: u8) -> int { +fn rindex(s: str, c: u8) -> int { let n: int = byte_len(s) as int; while n >= 0 { if s[n] == c { ret n; } n -= 1; } ret n; } -fn find(haystack: &str, needle: &str) -> int { +fn find(haystack: str, needle: str) -> int { let haystack_len: int = byte_len(haystack) as int; let needle_len: int = byte_len(needle) as int; if needle_len == 0 { ret 0; } - fn match_at(haystack: &str, needle: &str, i: int) -> bool { + fn match_at(haystack: str, needle: str, i: int) -> bool { let j: int = i; for c: u8 in needle { if haystack[j] != c { ret false; } j += 1; } ret true; @@ -254,7 +254,7 @@ fn find(haystack: &str, needle: &str) -> int { ret -1; } -fn starts_with(haystack: &str, needle: &str) -> bool { +fn starts_with(haystack: str, needle: str) -> bool { let haystack_len: uint = byte_len(haystack); let needle_len: uint = byte_len(needle); if needle_len == 0u { ret true; } @@ -262,7 +262,7 @@ fn starts_with(haystack: &str, needle: &str) -> bool { ret eq(substr(haystack, 0u, needle_len), needle); } -fn ends_with(haystack: &str, needle: &str) -> bool { +fn ends_with(haystack: str, needle: str) -> bool { let haystack_len: uint = byte_len(haystack); let needle_len: uint = byte_len(needle); ret if needle_len == 0u { @@ -275,11 +275,11 @@ fn ends_with(haystack: &str, needle: &str) -> bool { }; } -fn substr(s: &str, begin: uint, len: uint) -> str { +fn substr(s: str, begin: uint, len: uint) -> str { ret slice(s, begin, begin + len); } -fn slice(s: &str, begin: uint, end: uint) -> str { +fn slice(s: str, begin: uint, end: uint) -> str { // FIXME: Typestate precondition assert (begin <= end); assert (end <= byte_len(s)); @@ -293,7 +293,7 @@ fn slice(s: &str, begin: uint, end: uint) -> str { ret s2; } -fn safe_slice(s: &str, begin: uint, end: uint) : uint::le(begin, end) -> str { +fn safe_slice(s: str, begin: uint, end: uint) : uint::le(begin, end) -> str { // would need some magic to make this a precondition assert (end <= byte_len(s)); ret slice(s, begin, end); @@ -317,11 +317,11 @@ fn pop_byte(s: &mutable str) -> u8 { fn push_byte(s: &mutable str, b: u8) { rustrt::rust_str_push(s, b); } -fn push_bytes(s: &mutable str, bytes: &[u8]) { +fn push_bytes(s: &mutable str, bytes: [u8]) { for byte in bytes { rustrt::rust_str_push(s, byte); } } -fn split(s: &str, sep: u8) -> [str] { +fn split(s: str, sep: u8) -> [str] { let v: [str] = []; let accum: str = ""; let ends_with_sep: bool = false; @@ -336,13 +336,13 @@ fn split(s: &str, sep: u8) -> [str] { ret v; } -fn concat(v: &[str]) -> str { +fn concat(v: [str]) -> str { let s: str = ""; for ss: str in v { s += ss; } ret s; } -fn connect(v: &[str], sep: &str) -> str { +fn connect(v: [str], sep: str) -> str { let s: str = ""; let first: bool = true; for ss: str in v { @@ -353,7 +353,7 @@ fn connect(v: &[str], sep: &str) -> str { } // FIXME: This only handles ASCII -fn to_upper(s: &str) -> str { +fn to_upper(s: str) -> str { let outstr = ""; let ascii_a = 'a' as u8; let ascii_z = 'z' as u8; @@ -369,7 +369,7 @@ fn to_upper(s: &str) -> str { } // FIXME: This is super-inefficient -fn replace(s: &str, from: &str, to: &str) : is_not_empty(from) -> str { +fn replace(s: str, from: str, to: str) : is_not_empty(from) -> str { // FIXME (694): Shouldn't have to check this check (is_not_empty(from)); if byte_len(s) == 0u { @@ -383,12 +383,12 @@ fn replace(s: &str, from: &str, to: &str) : is_not_empty(from) -> str { } // FIXME: Also not efficient -fn char_slice(s: &str, begin: uint, end: uint) -> str { +fn char_slice(s: str, begin: uint, end: uint) -> str { from_chars(vec::slice(to_chars(s), begin, end)) } -fn trim_left(s: &str) -> str { - fn count_whities(s: &[char]) -> uint { +fn trim_left(s: str) -> str { + fn count_whities(s: [char]) -> uint { let i = 0u; while i < vec::len(s) { if !char::is_whitespace(s[i]) { break; } @@ -401,8 +401,8 @@ fn trim_left(s: &str) -> str { ret from_chars(vec::slice(chars, whities, vec::len(chars))); } -fn trim_right(s: &str) -> str { - fn count_whities(s: &[char]) -> uint { +fn trim_right(s: str) -> str { + fn count_whities(s: [char]) -> uint { let i = vec::len(s); while 0u < i { if !char::is_whitespace(s[i - 1u]) { break; } @@ -415,18 +415,18 @@ fn trim_right(s: &str) -> str { ret from_chars(vec::slice(chars, 0u, whities)); } -fn trim(s: &str) -> str { trim_left(trim_right(s)) } +fn trim(s: str) -> str { trim_left(trim_right(s)) } type sbuf = *u8; -fn buf(s: &str) -> sbuf { +fn buf(s: str) -> sbuf { let saddr = ptr::addr_of(s); let vaddr: *[u8] = unsafe::reinterpret_cast(saddr); let buf = vec::to_ptr(*vaddr); ret buf; } -fn as_buf<T>(s: &str, f: &block(sbuf) -> T) -> T { let buf = buf(s); f(buf) } +fn as_buf<T>(s: str, f: block(sbuf) -> T) -> T { let buf = buf(s); f(buf) } fn str_from_cstr(cstr: sbuf) -> str { let res = ""; diff --git a/src/lib/task.rs b/src/lib/task.rs index b00e6c19991..24a9582ba4c 100644 --- a/src/lib/task.rs +++ b/src/lib/task.rs @@ -124,8 +124,8 @@ fn spawn_inner(thunk: -fn(), notify: option<comm::chan<task_notification>>) -> let ptrsize = sys::size_of::<*u8>(); let thunkfn: *mutable uint = cast(sp - ptrsize * 2u); let thunkenv: *mutable uint = cast(sp - ptrsize); - *thunkfn = cast(raw_thunk.code); - *thunkenv = cast(raw_thunk.env); + *thunkfn = cast(raw_thunk.code);; + *thunkenv = cast(raw_thunk.env);; // align the stack to 16 bytes (**task_ptr).stack_ptr = cast(sp - ptrsize * 4u); @@ -136,7 +136,7 @@ fn spawn_inner(thunk: -fn(), notify: option<comm::chan<task_notification>>) -> (**task_ptr).notify_chan = c; } none { } - }; + } // give the thunk environment's allocation to the new task rustrt::migrate_alloc(cast(raw_thunk.env), id); diff --git a/src/lib/test.rs b/src/lib/test.rs index 37fec12e9ce..1ad70db6f17 100644 --- a/src/lib/test.rs +++ b/src/lib/test.rs @@ -49,7 +49,7 @@ type test_desc = {name: test_name, fn: test_fn, ignore: bool}; // The default console test runner. It accepts the command line // arguments and a vector of test_descs (generated at compile time). -fn test_main(args: &[str], tests: &[test_desc]) { +fn test_main(args: [str], tests: [test_desc]) { check (vec::is_not_empty(args)); let opts = alt parse_opts(args) { @@ -64,7 +64,7 @@ type test_opts = {filter: option::t<str>, run_ignored: bool}; type opt_res = either::t<test_opts, str>; // Parses command line arguments into test options -fn parse_opts(args: &[str]) : vec::is_not_empty(args) -> opt_res { +fn parse_opts(args: [str]) : vec::is_not_empty(args) -> opt_res { let args_ = vec::tail(args); let opts = [getopts::optflag("ignored")]; @@ -94,15 +94,15 @@ type joinable = (task, comm::port<task::task_notification>); // In cases where test functions and closures it is not ok to just dump them // into a task and run them, so this transformation gives the caller a chance // to create the test task. -type test_to_task = fn(&fn()) -> joinable; +type test_to_task = fn(fn()) -> joinable; // A simple console test runner -fn run_tests_console(opts: &test_opts, tests: &[test_desc]) -> bool { +fn run_tests_console(opts: test_opts, tests: [test_desc]) -> bool { run_tests_console_(opts, tests, default_test_to_task) } -fn run_tests_console_(opts: &test_opts, tests: &[test_desc], - to_task: &test_to_task) -> bool { +fn run_tests_console_(opts: test_opts, tests: [test_desc], + to_task: test_to_task) -> bool { type test_state = @{out: io::writer, @@ -175,20 +175,19 @@ fn run_tests_console_(opts: &test_opts, tests: &[test_desc], ret success; - fn write_ok(out: &io::writer, use_color: bool) { + fn write_ok(out: io::writer, use_color: bool) { write_pretty(out, "ok", term::color_green, use_color); } - fn write_failed(out: &io::writer, use_color: bool) { + fn write_failed(out: io::writer, use_color: bool) { write_pretty(out, "FAILED", term::color_red, use_color); } - fn write_ignored(out: &io::writer, use_color: bool) { + fn write_ignored(out: io::writer, use_color: bool) { write_pretty(out, "ignored", term::color_yellow, use_color); } - fn write_pretty(out: &io::writer, word: &str, color: u8, - use_color: bool) { + fn write_pretty(out: io::writer, word: str, color: u8, use_color: bool) { if use_color && term::color_supported() { term::fg(out.get_buf_writer(), color); } @@ -207,7 +206,7 @@ tag testevent { te_result(test_desc, test_result); } -fn run_tests(opts: &test_opts, tests: &[test_desc], to_task: &test_to_task, +fn run_tests(opts: test_opts, tests: [test_desc], to_task: test_to_task, callback: fn(testevent)) { let filtered_tests = filter_tests(opts, tests); @@ -241,7 +240,7 @@ fn run_tests(opts: &test_opts, tests: &[test_desc], to_task: &test_to_task, fn get_concurrency() -> uint { rustrt::sched_threads() } -fn filter_tests(opts: &test_opts, tests: &[test_desc]) -> [test_desc] { +fn filter_tests(opts: test_opts, tests: [test_desc]) -> [test_desc] { let filtered = tests; // Remove tests that don't match the test filter @@ -256,7 +255,7 @@ fn filter_tests(opts: &test_opts, tests: &[test_desc]) -> [test_desc] { }; let filter = - bind fn (test: &test_desc, filter_str: &str) -> + bind fn (test: test_desc, filter_str: str) -> option::t<test_desc> { if str::find(test.name, filter_str) >= 0 { ret option::some(test); @@ -273,7 +272,7 @@ fn filter_tests(opts: &test_opts, tests: &[test_desc]) -> [test_desc] { filtered } else { let filter = - fn (test: &test_desc) -> option::t<test_desc> { + fn (test: test_desc) -> option::t<test_desc> { if test.ignore { ret option::some({name: test.name, fn: test.fn, @@ -288,7 +287,7 @@ fn filter_tests(opts: &test_opts, tests: &[test_desc]) -> [test_desc] { // Sort the tests alphabetically filtered = { - fn lteq(t1: &test_desc, t2: &test_desc) -> bool { + fn lteq(t1: test_desc, t2: test_desc) -> bool { str::lteq(t1.name, t2.name) } sort::merge_sort(lteq, filtered) @@ -299,7 +298,7 @@ fn filter_tests(opts: &test_opts, tests: &[test_desc]) -> [test_desc] { type test_future = {test: test_desc, wait: fn() -> test_result}; -fn run_test(test: &test_desc, to_task: &test_to_task) -> test_future { +fn run_test(test: test_desc, to_task: test_to_task) -> test_future { if !test.ignore { let test_task = to_task(test.fn); ret {test: test, @@ -315,7 +314,7 @@ fn run_test(test: &test_desc, to_task: &test_to_task) -> test_future { // We need to run our tests in another task in order to trap test failures. // This function only works with functions that don't contain closures. -fn default_test_to_task(f: &fn()) -> joinable { +fn default_test_to_task(f: fn()) -> joinable { fn run_task(f: fn()) { configure_test_task(); f(); } ret task::spawn_joinable(bind run_task(f)); } diff --git a/src/lib/treemap.rs b/src/lib/treemap.rs index cdf9a67042b..bd65a58a8b3 100644 --- a/src/lib/treemap.rs +++ b/src/lib/treemap.rs @@ -23,7 +23,7 @@ type treemap<@K, @V> = @mutable tree_node<K, V>; fn init<@K, @V>() -> treemap<K, V> { @mutable empty } -fn insert<@K, @V>(m: &treemap<K, V>, k: &K, v: &V) { +fn insert<@K, @V>(m: treemap<K, V>, k: K, v: V) { alt m { @empty. { *m = node(@k, @v, @mutable empty, @mutable empty); } @node(@kk, _, _, _) { @@ -37,13 +37,14 @@ fn insert<@K, @V>(m: &treemap<K, V>, k: &K, v: &V) { } } -fn find<@K, @V>(m: &treemap<K, V>, k: &K) -> option<V> { +fn find<@K, @V>(m: treemap<K, V>, k: K) -> option<V> { alt *m { empty. { none } node(@kk, @v, _, _) { if k == kk { some(v) } else if k < kk { + // Again, ugliness to unpack left and right individually. alt *m { node(_, _, left, _) { find(left, k) } } } else { alt *m { node(_, _, _, right) { find(right, k) } } } @@ -52,7 +53,7 @@ fn find<@K, @V>(m: &treemap<K, V>, k: &K) -> option<V> { } // Performs an in-order traversal -fn traverse<@K, @V>(m: &treemap<K, V>, f: fn(&K, &V)) { +fn traverse<@K, @V>(m: treemap<K, V>, f: fn(K, V)) { alt *m { empty. { } node(k, v, _, _) { diff --git a/src/lib/ufind.rs b/src/lib/ufind.rs index f225a2a7ca3..1a8aacae1da 100644 --- a/src/lib/ufind.rs +++ b/src/lib/ufind.rs @@ -12,7 +12,7 @@ type ufind = {mutable nodes: [mutable node]}; fn make() -> ufind { ret {mutable nodes: [mutable]}; } -fn make_set(ufnd: &ufind) -> uint { +fn make_set(ufnd: ufind) -> uint { let idx = vec::len(ufnd.nodes); ufnd.nodes += [mutable none::<uint>]; ret idx; @@ -21,18 +21,18 @@ fn make_set(ufnd: &ufind) -> uint { /// Creates sets as necessary to ensure that least `n` sets are present in the /// data structure. -fn grow(ufnd: &ufind, n: uint) { +fn grow(ufnd: ufind, n: uint) { while set_count(ufnd) < n { make_set(ufnd); } } -fn find(ufnd: &ufind, n: uint) -> uint { +fn find(ufnd: ufind, n: uint) -> uint { alt ufnd.nodes[n] { none. { ret n; } some(m) { let m_ = m; be find(ufnd, m_); } } } -fn union(ufnd: &ufind, m: uint, n: uint) { +fn union(ufnd: ufind, m: uint, n: uint) { let m_root = find(ufnd, m); let n_root = find(ufnd, n); if m_root < n_root { @@ -40,11 +40,11 @@ fn union(ufnd: &ufind, m: uint, n: uint) { } else if m_root > n_root { ufnd.nodes[m_root] = some::<uint>(n_root); } } -fn set_count(ufnd: &ufind) -> uint { ret vec::len::<node>(ufnd.nodes); } +fn set_count(ufnd: ufind) -> uint { ret vec::len::<node>(ufnd.nodes); } // Removes all sets with IDs greater than or equal to the given value. -fn prune(ufnd: &ufind, n: uint) { +fn prune(ufnd: ufind, n: uint) { // TODO: Use "slice" once we get rid of "mutable?" let len = vec::len::<node>(ufnd.nodes); diff --git a/src/lib/uint.rs b/src/lib/uint.rs index 3553dc7e2cf..d992ade5a72 100644 --- a/src/lib/uint.rs +++ b/src/lib/uint.rs @@ -39,7 +39,7 @@ fn next_power_of_two(n: uint) -> uint { ret tmp + 1u; } -fn parse_buf(buf: &[u8], radix: uint) -> uint { +fn parse_buf(buf: [u8], radix: uint) -> uint { if vec::len::<u8>(buf) == 0u { log_err "parse_buf(): buf is empty"; fail; @@ -56,7 +56,7 @@ fn parse_buf(buf: &[u8], radix: uint) -> uint { fail; } -fn from_str(s: &str) -> uint { parse_buf(str::bytes(s), 10u) } +fn from_str(s: str) -> uint { parse_buf(str::bytes(s), 10u) } fn to_str(num: uint, radix: uint) -> str { let n = num; diff --git a/src/lib/unsafe.rs b/src/lib/unsafe.rs index 79e409d27fc..d5f2a363409 100644 --- a/src/lib/unsafe.rs +++ b/src/lib/unsafe.rs @@ -1,7 +1,7 @@ // Unsafe operations. native "rust-intrinsic" mod rusti { - fn cast<T, U>(src: &T) -> U; + fn cast<T, U>(src: T) -> U; } native "rust" mod rustrt { @@ -9,6 +9,6 @@ native "rust" mod rustrt { } // Casts the value at `src` to U. The two types must have the same length. -fn reinterpret_cast<T, @U>(src: &T) -> U { ret rusti::cast(src); } +fn reinterpret_cast<T, @U>(src: T) -> U { ret rusti::cast(src); } fn leak<@T>(thing: -T) { rustrt::leak(thing); } diff --git a/src/lib/util.rs b/src/lib/util.rs index 6041da4d0d0..69418267e9e 100644 --- a/src/lib/util.rs +++ b/src/lib/util.rs @@ -1,6 +1,6 @@ -fn id<@T>(x: &T) -> T { ret x; } +fn id<@T>(x: T) -> T { ret x; } /* FIXME (issue #141): See test/run-pass/constrained-type.rs. Uncomment @@ -9,13 +9,13 @@ type rational = {num: int, den: int}; // : int::positive(*.den); -fn rational_leq(x: &rational, y: &rational) -> bool { +fn rational_leq(x: rational, y: rational) -> bool { // NB: Uses the fact that rationals have positive denominators WLOG: ret x.num * y.den <= y.num * x.den; } -fn orb(a: &bool, b: &bool) -> bool { ret a || b; } +fn orb(a: bool, b: bool) -> bool { ret a || b; } // Local Variables: // mode: rust; // fill-column: 78; diff --git a/src/lib/vec.rs b/src/lib/vec.rs index 1ec736c6e87..c9970ccb5fc 100644 --- a/src/lib/vec.rs +++ b/src/lib/vec.rs @@ -6,7 +6,7 @@ import uint::next_power_of_two; import ptr::addr_of; native "rust-intrinsic" mod rusti { - fn vec_len<T>(v: &[T]) -> uint; + fn vec_len<T>(v: [T]) -> uint; } native "rust" mod rustrt { @@ -19,11 +19,11 @@ fn reserve<@T>(v: &mutable [mutable? T], n: uint) { rustrt::vec_reserve_shared(v, n); } -fn len<T>(v: &[mutable? T]) -> uint { ret rusti::vec_len(v); } +fn len<T>(v: [mutable? T]) -> uint { ret rusti::vec_len(v); } type init_op<T> = fn(uint) -> T; -fn init_fn<@T>(op: &init_op<T>, n_elts: uint) -> [T] { +fn init_fn<@T>(op: init_op<T>, n_elts: uint) -> [T] { let v = []; reserve(v, n_elts); let i: uint = 0u; @@ -32,7 +32,7 @@ fn init_fn<@T>(op: &init_op<T>, n_elts: uint) -> [T] { } // TODO: Remove me once we have slots. -fn init_fn_mut<@T>(op: &init_op<T>, n_elts: uint) -> [mutable T] { +fn init_fn_mut<@T>(op: init_op<T>, n_elts: uint) -> [mutable T] { let v = [mutable]; reserve(v, n_elts); let i: uint = 0u; @@ -40,7 +40,7 @@ fn init_fn_mut<@T>(op: &init_op<T>, n_elts: uint) -> [mutable T] { ret v; } -fn init_elt<@T>(t: &T, n_elts: uint) -> [T] { +fn init_elt<@T>(t: T, n_elts: uint) -> [T] { let v = []; reserve(v, n_elts); let i: uint = 0u; @@ -49,7 +49,7 @@ fn init_elt<@T>(t: &T, n_elts: uint) -> [T] { } // TODO: Remove me once we have slots. -fn init_elt_mut<@T>(t: &T, n_elts: uint) -> [mutable T] { +fn init_elt_mut<@T>(t: T, n_elts: uint) -> [mutable T] { let v = [mutable]; reserve(v, n_elts); let i: uint = 0u; @@ -59,51 +59,51 @@ fn init_elt_mut<@T>(t: &T, n_elts: uint) -> [mutable T] { // FIXME: Possible typestate postcondition: // len(result) == len(v) (needs issue #586) -fn to_mut<@T>(v: &[T]) -> [mutable T] { +fn to_mut<@T>(v: [T]) -> [mutable T] { let vres = [mutable]; for t: T in v { vres += [mutable t]; } ret vres; } // Same comment as from_mut -fn from_mut<@T>(v: &[mutable T]) -> [T] { +fn from_mut<@T>(v: [mutable T]) -> [T] { let vres = []; for t: T in v { vres += [t]; } ret vres; } // Predicates -pure fn is_empty<T>(v: &[mutable? T]) -> bool { +pure fn is_empty<T>(v: [mutable? T]) -> bool { // FIXME: This would be easier if we could just call len for t: T in v { ret false; } ret true; } -pure fn is_not_empty<T>(v: &[mutable? T]) -> bool { ret !is_empty(v); } +pure fn is_not_empty<T>(v: [mutable? T]) -> bool { ret !is_empty(v); } // Accessors /// Returns the first element of a vector -fn head<@T>(v: &[mutable? T]) : is_not_empty(v) -> T { ret v[0]; } +fn head<@T>(v: [mutable? T]) : is_not_empty(v) -> T { ret v[0]; } /// Returns all but the first element of a vector -fn tail<@T>(v: &[mutable? T]) : is_not_empty(v) -> [mutable? T] { +fn tail<@T>(v: [mutable? T]) : is_not_empty(v) -> [mutable? T] { ret slice(v, 1u, len(v)); } /// Returns the last element of `v`. -fn last<@T>(v: &[mutable? T]) -> option::t<T> { +fn last<@T>(v: [mutable? T]) -> option::t<T> { if len(v) == 0u { ret none; } ret some(v[len(v) - 1u]); } /// Returns the last element of a non-empty vector `v`. -fn last_total<@T>(v: &[mutable? T]) : is_not_empty(v) -> T { +fn last_total<@T>(v: [mutable? T]) : is_not_empty(v) -> T { ret v[len(v) - 1u]; } /// Returns a copy of the elements from [`start`..`end`) from `v`. -fn slice<@T>(v: &[mutable? T], start: uint, end: uint) -> [T] { +fn slice<@T>(v: [mutable? T], start: uint, end: uint) -> [T] { assert (start <= end); assert (end <= len(v)); let result = []; @@ -114,7 +114,7 @@ fn slice<@T>(v: &[mutable? T], start: uint, end: uint) -> [T] { } // TODO: Remove me once we have slots. -fn slice_mut<@T>(v: &[mutable? T], start: uint, end: uint) -> [mutable T] { +fn slice_mut<@T>(v: [mutable? T], start: uint, end: uint) -> [mutable T] { assert (start <= end); assert (end <= len(v)); let result = [mutable]; @@ -151,14 +151,14 @@ fn pop<@T>(v: &mutable [mutable? T]) -> T { // Appending /// Expands the given vector in-place by appending `n` copies of `initval`. -fn grow<@T>(v: &mutable [T], n: uint, initval: &T) { +fn grow<@T>(v: &mutable [T], n: uint, initval: T) { reserve(v, next_power_of_two(len(v) + n)); let i: uint = 0u; while i < n { v += [initval]; i += 1u; } } // TODO: Remove me once we have slots. -fn grow_mut<@T>(v: &mutable [mutable T], n: uint, initval: &T) { +fn grow_mut<@T>(v: &mutable [mutable T], n: uint, initval: T) { reserve(v, next_power_of_two(len(v) + n)); let i: uint = 0u; while i < n { v += [mutable initval]; i += 1u; } @@ -175,7 +175,7 @@ fn grow_fn<@T>(v: &mutable [T], n: uint, init_fn: fn(uint) -> T) { /// Sets the element at position `index` to `val`. If `index` is past the end /// of the vector, expands the vector by replicating `initval` to fill the /// intervening space. -fn grow_set<@T>(v: &mutable [mutable T], index: uint, initval: &T, val: &T) { +fn grow_set<@T>(v: &mutable [mutable T], index: uint, initval: T, val: T) { if index >= len(v) { grow_mut(v, index - len(v) + 1u, initval); } v[index] = val; } @@ -183,7 +183,7 @@ fn grow_set<@T>(v: &mutable [mutable T], index: uint, initval: &T, val: &T) { // Functional utilities -fn map<@T, @U>(f: &block(&T) -> U, v: &[mutable? T]) -> [U] { +fn map<@T, @U>(f: block(T) -> U, v: [mutable? T]) -> [U] { let result = []; reserve(result, len(v)); for elem: T in v { @@ -193,7 +193,7 @@ fn map<@T, @U>(f: &block(&T) -> U, v: &[mutable? T]) -> [U] { ret result; } -fn map2<@T, @U, @V>(f: &block(&T, &U) -> V, v0: &[T], v1: &[U]) -> [V] { +fn map2<@T, @U, @V>(f: block(T, U) -> V, v0: [T], v1: [U]) -> [V] { let v0_len = len::<T>(v0); if v0_len != len::<U>(v1) { fail; } let u: [V] = []; @@ -202,8 +202,7 @@ fn map2<@T, @U, @V>(f: &block(&T, &U) -> V, v0: &[T], v1: &[U]) -> [V] { ret u; } -fn filter_map<@T, @U>(f: &block(&T) -> option::t<U>, v: &[mutable? T]) -> - [U] { +fn filter_map<@T, @U>(f: block(T) -> option::t<U>, v: [mutable? T]) -> [U] { let result = []; for elem: T in v { let elem2 = elem; // satisfies alias checker @@ -215,7 +214,7 @@ fn filter_map<@T, @U>(f: &block(&T) -> option::t<U>, v: &[mutable? T]) -> ret result; } -fn foldl<@T, @U>(p: &block(&U, &T) -> U, z: &U, v: &[mutable? T]) -> U { +fn foldl<@T, @U>(p: block(U, T) -> U, z: U, v: [mutable? T]) -> U { let sz = len(v); if sz == 0u { ret z; } let first = v[0]; @@ -223,45 +222,45 @@ fn foldl<@T, @U>(p: &block(&U, &T) -> U, z: &U, v: &[mutable? T]) -> U { ret p(foldl(p, z, rest), first); } -fn any<T>(f: &block(&T) -> bool, v: &[T]) -> bool { +fn any<T>(f: block(T) -> bool, v: [T]) -> bool { for elem: T in v { if f(elem) { ret true; } } ret false; } -fn all<T>(f: &block(&T) -> bool, v: &[T]) -> bool { +fn all<T>(f: block(T) -> bool, v: [T]) -> bool { for elem: T in v { if !f(elem) { ret false; } } ret true; } -fn member<T>(x: &T, v: &[T]) -> bool { +fn member<T>(x: T, v: [T]) -> bool { for elt: T in v { if x == elt { ret true; } } ret false; } -fn count<T>(x: &T, v: &[mutable? T]) -> uint { +fn count<T>(x: T, v: [mutable? T]) -> uint { let cnt = 0u; for elt: T in v { if x == elt { cnt += 1u; } } ret cnt; } -fn find<@T>(f: &block(&T) -> bool, v: &[T]) -> option::t<T> { +fn find<@T>(f: block(T) -> bool, v: [T]) -> option::t<T> { for elt: T in v { if f(elt) { ret some(elt); } } ret none; } -fn position<@T>(x: &T, v: &[T]) -> option::t<uint> { +fn position<@T>(x: T, v: [T]) -> option::t<uint> { let i: uint = 0u; while i < len(v) { if x == v[i] { ret some::<uint>(i); } i += 1u; } ret none; } -fn position_pred<T>(f: fn(&T) -> bool, v: &[T]) -> option::t<uint> { +fn position_pred<T>(f: fn(T) -> bool, v: [T]) -> option::t<uint> { let i: uint = 0u; while i < len(v) { if f(v[i]) { ret some::<uint>(i); } i += 1u; } ret none; } -pure fn same_length<T, U>(xs: &[T], ys: &[U]) -> bool { +pure fn same_length<T, U>(xs: [T], ys: [U]) -> bool { let xlen = unchecked{ vec::len(xs) }; let ylen = unchecked{ vec::len(ys) }; xlen == ylen @@ -271,13 +270,13 @@ pure fn same_length<T, U>(xs: &[T], ys: &[U]) -> bool { // saying the two result lists have the same length -- or, could // return a nominal record with a constraint saying that, instead of // returning a tuple (contingent on issue #869) -fn unzip<@T, @U>(v: &[(T, U)]) -> ([T], [U]) { +fn unzip<@T, @U>(v: [(T, U)]) -> ([T], [U]) { let as = [], bs = []; for (a, b) in v { as += [a]; bs += [b]; } ret (as, bs); } -fn zip<@T, @U>(v: &[T], u: &[U]) : same_length(v, u) -> [(T, U)] { +fn zip<@T, @U>(v: [T], u: [U]) : same_length(v, u) -> [(T, U)] { let zipped = []; let sz = len(v), i = 0u; assert (sz == len(u)); @@ -286,14 +285,14 @@ fn zip<@T, @U>(v: &[T], u: &[U]) : same_length(v, u) -> [(T, U)] { } // Swaps two elements in a vector -fn swap<@T>(v: &[mutable T], a: uint, b: uint) { +fn swap<@T>(v: [mutable T], a: uint, b: uint) { let t: T = v[a]; v[a] = v[b]; v[b] = t; } // In place vector reversal -fn reverse<@T>(v: &[mutable T]) { +fn reverse<@T>(v: [mutable T]) { let i: uint = 0u; let ln = len::<T>(v); while i < ln / 2u { swap(v, i, ln - i - 1u); i += 1u; } @@ -301,7 +300,7 @@ fn reverse<@T>(v: &[mutable T]) { // Functional vector reversal. Returns a reversed copy of v. -fn reversed<@T>(v: &[T]) -> [T] { +fn reversed<@T>(v: [T]) -> [T] { let rs: [T] = []; let i = len::<T>(v); if i == 0u { ret rs; } else { i -= 1u; } @@ -326,7 +325,7 @@ fn enum_uints(start: uint, end: uint) : uint::le(start, end) -> [uint] { } // Iterate over a list with with the indexes -iter iter2<@T>(v: &[T]) -> (uint, T) { +iter iter2<@T>(v: [T]) -> (uint, T) { let i = 0u; for x in v { put (i, x); i += 1u; } } @@ -343,13 +342,13 @@ mod unsafe { (**repr).fill = new_len * sys::size_of::<T>(); } - fn to_ptr<T>(v: &[T]) -> *T { + fn to_ptr<T>(v: [T]) -> *T { let repr: **vec_repr = ::unsafe::reinterpret_cast(addr_of(v)); ret ::unsafe::reinterpret_cast(addr_of((**repr).data)); } } -fn to_ptr<T>(v: &[T]) -> *T { ret unsafe::to_ptr(v); } +fn to_ptr<T>(v: [T]) -> *T { ret unsafe::to_ptr(v); } // Local Variables: // mode: rust; diff --git a/src/lib/win32_fs.rs b/src/lib/win32_fs.rs index 8052d0280fe..06701249150 100644 --- a/src/lib/win32_fs.rs +++ b/src/lib/win32_fs.rs @@ -1,16 +1,16 @@ native "rust" mod rustrt { - fn rust_list_files(path: &str) -> [str]; + fn rust_list_files(path: str) -> [str]; fn rust_file_is_dir(path: str) -> int; } -fn list_dir(path: &str) -> [str] { +fn list_dir(path: str) -> [str] { let path = path + "*"; ret rustrt::rust_list_files(path); } -fn path_is_absolute(p: &str) -> bool { +fn path_is_absolute(p: str) -> bool { ret str::char_at(p, 0u) == '/' || str::char_at(p, 1u) == ':' && str::char_at(p, 2u) == '\\'; } diff --git a/src/lib/win32_os.rs b/src/lib/win32_os.rs index bf94439099f..7cd3f58cdca 100644 --- a/src/lib/win32_os.rs +++ b/src/lib/win32_os.rs @@ -49,7 +49,7 @@ fn exec_suffix() -> str { ret ".exe"; } fn target_os() -> str { ret "win32"; } -fn dylib_filename(base: &str) -> str { ret base + ".dll"; } +fn dylib_filename(base: str) -> str { ret base + ".dll"; } fn pipe() -> {in: int, out: int} { // Windows pipes work subtly differently than unix pipes, and their diff --git a/src/test/bench/99bob-iter.rs b/src/test/bench/99bob-iter.rs index a1a3e1b984a..aa79590a246 100644 --- a/src/test/bench/99bob-iter.rs +++ b/src/test/bench/99bob-iter.rs @@ -22,7 +22,7 @@ fn b8() -> str { ret "Go to the store and buy some more, # of beer on the wall."; } -fn sub(t: &str, n: int) -> str { +fn sub(t: str, n: int) -> str { let b: str = ""; let i: uint = 0u; let ns: str; diff --git a/src/test/bench/99bob-simple.rs b/src/test/bench/99bob-simple.rs index ae1c30fb9ec..2db6321d257 100644 --- a/src/test/bench/99bob-simple.rs +++ b/src/test/bench/99bob-simple.rs @@ -22,7 +22,7 @@ fn b8() -> str { ret "Go to the store and buy some more, # of beer on the wall."; } -fn sub(t: &str, n: int) -> str { +fn sub(t: str, n: int) -> str { let b: str = ""; let i: uint = 0u; let ns: str; diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs index 99b06a98416..2fbadc2461c 100644 --- a/src/test/bench/shootout-fasta.rs +++ b/src/test/bench/shootout-fasta.rs @@ -23,16 +23,16 @@ obj myrandom(mutable last: u32) { type aminoacids = {ch: char, prob: u32}; -fn make_cumulative(aa: &[aminoacids]) -> [aminoacids] { +fn make_cumulative(aa: [aminoacids]) -> [aminoacids] { let cp: u32 = 0u32; let ans: [aminoacids] = []; for a: aminoacids in aa { cp += a.prob; ans += [{ch: a.ch, prob: cp}]; } ret ans; } -fn select_random(r: u32, genelist: &[aminoacids]) -> char { +fn select_random(r: u32, genelist: [aminoacids]) -> char { if r < genelist[0].prob { ret genelist[0].ch; } - fn bisect(v: &[aminoacids], lo: uint, hi: uint, target: u32) -> char { + fn bisect(v: [aminoacids], lo: uint, hi: uint, target: u32) -> char { if hi > lo + 1u { let mid: uint = lo + (hi - lo) / 2u; if target < v[mid].prob { @@ -43,7 +43,7 @@ fn select_random(r: u32, genelist: &[aminoacids]) -> char { ret bisect(genelist, 0u, vec::len::<aminoacids>(genelist) - 1u, r); } -fn make_random_fasta(id: &str, desc: &str, genelist: &[aminoacids], n: int) { +fn make_random_fasta(id: str, desc: str, genelist: [aminoacids], n: int) { log ">" + id + " " + desc; let rng = myrandom(std::rand::mk_rng().next()); let op: str = ""; @@ -54,7 +54,7 @@ fn make_random_fasta(id: &str, desc: &str, genelist: &[aminoacids], n: int) { if str::byte_len(op) > 0u { log op; } } -fn make_repeat_fasta(id: &str, desc: &str, s: &str, n: int) { +fn make_repeat_fasta(id: str, desc: str, s: str, n: int) { log ">" + id + " " + desc; let op: str = ""; let sl: uint = str::byte_len(s); diff --git a/src/test/bench/shootout-nbody.rs b/src/test/bench/shootout-nbody.rs index 5e888041981..92da06f186a 100644 --- a/src/test/bench/shootout-nbody.rs +++ b/src/test/bench/shootout-nbody.rs @@ -56,7 +56,7 @@ mod NBodySystem { ret bodies; } - fn advance(bodies: &[Body::props], dt: float) { + fn advance(bodies: [Body::props], dt: float) { let i: int = 0; while i < 5 { @@ -70,7 +70,7 @@ mod NBodySystem { while i < 5 { move(bodies[i], dt); i += 1; } } - fn advance_one(bi: &Body::props, bj: &Body::props, dt: float) { + fn advance_one(bi: Body::props, bj: Body::props, dt: float) { let dx: float = bi.x - bj.x; let dy: float = bi.y - bj.y; let dz: float = bi.z - bj.z; @@ -89,13 +89,13 @@ mod NBodySystem { bj.vz += dz * bi.mass * mag; } - fn move(b: &Body::props, dt: float) { + fn move(b: Body::props, dt: float) { b.x += dt * b.vx; b.y += dt * b.vy; b.z += dt * b.vz; } - fn energy(bodies: &[Body::props]) -> float { + fn energy(bodies: [Body::props]) -> float { let dx: float; let dy: float; let dz: float; @@ -194,7 +194,7 @@ mod Body { mass: SOLAR_MASS}; } - fn offsetMomentum(props: &Body::props, px: float, py: float, pz: float) { + fn offsetMomentum(props: Body::props, px: float, py: float, pz: float) { props.vx = -px / SOLAR_MASS; props.vy = -py / SOLAR_MASS; props.vz = -pz / SOLAR_MASS; diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index 9551aa6b982..1531a3f61b2 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -49,7 +49,7 @@ fn fib(n: int) -> int { type config = {stress: bool}; -fn parse_opts(argv: &[str]) -> config { +fn parse_opts(argv: [str]) -> config { let opts = [getopts::optflag("stress")]; let opt_args = vec::slice(argv, 1u, vec::len(argv)); diff --git a/src/test/bench/task-perf-word-count-generic.rs b/src/test/bench/task-perf-word-count-generic.rs index adb5040fa25..24df1508f9f 100644 --- a/src/test/bench/task-perf-word-count-generic.rs +++ b/src/test/bench/task-perf-word-count-generic.rs @@ -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 } } } @@ -53,15 +53,15 @@ mod map_reduce { export reducer; export map_reduce; - type putter<~K, ~V> = fn(&K, &V); + type putter<~K, ~V> = fn(K, V); // FIXME: the first K1 parameter should probably be a -, but that // doesn't parse at the moment. - type mapper<~K1, ~K2, ~V> = fn(&K1, &putter<K2, V>); + type mapper<~K1, ~K2, ~V> = fn(K1, putter<K2, V>); type getter<~V> = fn() -> option<V>; - type reducer<~K, ~V> = fn(&K, &getter<V>); + type reducer<~K, ~V> = fn(K, getter<V>); tag ctrl_proto<~K, ~V> { find_reducer(K, chan<chan<reduce_proto<V>>>); @@ -72,7 +72,7 @@ mod map_reduce { fn start_mappers<~K1, ~K2, ~V>(map: mapper<K1, K2, V>, - ctrl: chan<ctrl_proto<K2, V>>, inputs: &[K1]) -> + ctrl: chan<ctrl_proto<K2, V>>, inputs: [K1]) -> [joinable_task] { let tasks = []; for i in inputs { @@ -89,8 +89,8 @@ mod map_reduce { let intermediates = treemap::init(); fn emit<~K2, - ~V>(im: &treemap::treemap<K2, chan<reduce_proto<V>>>, - ctrl: &chan<ctrl_proto<K2, V>>, key: &K2, val: &V) { + ~V>(im: treemap::treemap<K2, chan<reduce_proto<V>>>, + ctrl: chan<ctrl_proto<K2, V>>, key: K2, val: V) { let c; alt treemap::find(im, key) { some(_c) { c = _c } @@ -107,7 +107,7 @@ mod map_reduce { map(input, bind emit(intermediates, ctrl, _, _)); - fn finish<~K, ~V>(k: &K, v: &chan<reduce_proto<V>>) { + fn finish<~K, ~V>(k: K, v: chan<reduce_proto<V>>) { send(v, release); } treemap::traverse(intermediates, finish); @@ -124,7 +124,7 @@ mod map_reduce { let ref_count = 0; let is_done = false; - fn get<~V>(p: &port<reduce_proto<V>>, ref_count: &mutable int, + fn get<~V>(p: port<reduce_proto<V>>, ref_count: &mutable int, is_done: &mutable bool) -> option<V> { while !is_done || ref_count > 0 { alt recv(p) { @@ -148,7 +148,7 @@ mod map_reduce { fn map_reduce<~K1, ~K2, ~V>(map: mapper<K1, K2, V>, reduce: reducer<K2, V>, - inputs: &[K1]) { + inputs: [K1]) { let ctrl = port(); // This task becomes the master control task. It task::_spawns @@ -190,7 +190,7 @@ mod map_reduce { } } - fn finish<~K, ~V>(k: &K, v: &chan<reduce_proto<V>>) { send(v, done); } + fn finish<~K, ~V>(k: K, v: chan<reduce_proto<V>>) { send(v, done); } treemap::traverse(reducers, finish); for t in tasks { task::join(t); } diff --git a/src/test/bench/task-perf-word-count.rs b/src/test/bench/task-perf-word-count.rs index a90abd9e526..9ec856b9c47 100644 --- a/src/test/bench/task-perf-word-count.rs +++ b/src/test/bench/task-perf-word-count.rs @@ -29,7 +29,7 @@ import std::comm::port; import std::comm::recv; import std::comm::send; -fn map(filename: &str, emit: map_reduce::putter) { +fn map(filename: str, emit: map_reduce::putter) { let f = io::file_reader(filename); @@ -38,7 +38,7 @@ fn map(filename: &str, emit: map_reduce::putter) { } } -fn reduce(word: &str, get: map_reduce::getter) { +fn reduce(word: str, get: map_reduce::getter) { let count = 0; @@ -52,13 +52,13 @@ mod map_reduce { export reducer; export map_reduce; - type putter = fn(&str, int); + type putter = fn(str, int); - type mapper = fn(&str, putter); + type mapper = fn(str, putter); type getter = fn() -> option<int>; - type reducer = fn(&str, getter); + type reducer = fn(str, getter); tag ctrl_proto { find_reducer(str, chan<chan<reduce_proto>>); @@ -67,7 +67,7 @@ mod map_reduce { tag reduce_proto { emit_val(int); done; ref; release; } - fn start_mappers(ctrl: chan<ctrl_proto>, inputs: &[str]) -> + fn start_mappers(ctrl: chan<ctrl_proto>, inputs: [str]) -> [joinable_task] { let tasks = []; for i: str in inputs { @@ -76,12 +76,12 @@ mod map_reduce { ret tasks; } - fn map_task(ctrl: chan<ctrl_proto>, input: &str) { + fn map_task(ctrl: chan<ctrl_proto>, input: str) { // log_err "map_task " + input; let intermediates = map::new_str_hash(); - fn emit(im: &map::hashmap<str, chan<reduce_proto>>, - ctrl: chan<ctrl_proto>, key: &str, val: int) { + fn emit(im: map::hashmap<str, chan<reduce_proto>>, + ctrl: chan<ctrl_proto>, key: str, val: int) { let c; alt im.find(key) { some(_c) { @@ -109,7 +109,7 @@ mod map_reduce { send(ctrl, mapper_done); } - fn reduce_task(key: &str, out: chan<chan<reduce_proto>>) { + fn reduce_task(key: str, out: chan<chan<reduce_proto>>) { let p = port(); send(out, chan(p)); @@ -117,7 +117,7 @@ mod map_reduce { let ref_count = 0; let is_done = false; - fn get(p: &port<reduce_proto>, ref_count: &mutable int, + fn get(p: port<reduce_proto>, ref_count: &mutable int, is_done: &mutable bool) -> option<int> { while !is_done || ref_count > 0 { alt recv(p) { @@ -139,7 +139,7 @@ mod map_reduce { reduce(key, bind get(p, ref_count, is_done)); } - fn map_reduce(inputs: &[str]) { + fn map_reduce(inputs: [str]) { let ctrl = port::<ctrl_proto>(); // This task becomes the master control task. It task::_spawns diff --git a/src/test/compile-fail/block-coerce-no.rs b/src/test/compile-fail/block-coerce-no.rs index bb3e53028c2..37d56439c11 100644 --- a/src/test/compile-fail/block-coerce-no.rs +++ b/src/test/compile-fail/block-coerce-no.rs @@ -3,9 +3,9 @@ // Make sure that fn-to-block coercion isn't incorrectly lifted over // other tycons. -fn coerce(b: &block()) -> fn() { - fn lol(f: &fn(&block()) -> fn(), g: &block()) -> fn() { ret f(g); } - fn fn_id(f: &fn()) -> fn() { ret f } +fn coerce(b: block()) -> fn() { + fn lol(f: fn(block()) -> fn(), g: block()) -> fn() { ret f(g); } + fn fn_id(f: fn()) -> fn() { ret f } ret lol(fn_id, b); } diff --git a/src/test/compile-fail/block-copy.rs b/src/test/compile-fail/block-copy.rs index 76b05792f2f..f6819fee5c6 100644 --- a/src/test/compile-fail/block-copy.rs +++ b/src/test/compile-fail/block-copy.rs @@ -1,4 +1,4 @@ // error-pattern: mismatched kinds -fn lol(f: &block()) -> block() { ret f; } +fn lol(f: block()) -> block() { ret f; } fn main() { let i = 8; let f = lol(block () { log_err i; }); f(); } diff --git a/src/test/compile-fail/block-deinitializes-upvar.rs b/src/test/compile-fail/block-deinitializes-upvar.rs index bc1292021a9..72cd09b18ab 100644 --- a/src/test/compile-fail/block-deinitializes-upvar.rs +++ b/src/test/compile-fail/block-deinitializes-upvar.rs @@ -1,10 +1,10 @@ // error-pattern:Tried to deinitialize a variable declared in a different -fn force(f: &block() -> int) -> int { ret f(); } +fn force(f: block() -> int) -> int { ret f(); } fn main() { - let x = @{x:17, y:2}; - let y = @{x:5, y:5}; + let x = @{x: 17, y: 2}; + let y = @{x: 5, y: 5}; - let f = {|&i| log_err i; x <- y; ret 7; }; + let f = {|i| log_err i; x <- y; ret 7; }; assert (f(5) == 7); log_err x; log_err y; diff --git a/src/test/compile-fail/block-require-return.rs b/src/test/compile-fail/block-require-return.rs index f2796296da4..f7d895ac383 100644 --- a/src/test/compile-fail/block-require-return.rs +++ b/src/test/compile-fail/block-require-return.rs @@ -1,3 +1,3 @@ // error-pattern: not all control paths return -fn force(f: &block() -> int) -> int { f() } -fn main() { log_err force({ | | }); } +fn force(f: block() -> int) -> int { f() } +fn main() { log_err force({|| }); } diff --git a/src/test/compile-fail/block-uninit.rs b/src/test/compile-fail/block-uninit.rs index 9028d5fa435..7ad58e45a43 100644 --- a/src/test/compile-fail/block-uninit.rs +++ b/src/test/compile-fail/block-uninit.rs @@ -1,4 +1,4 @@ // error-pattern: Unsatisfied precondition constraint -fn force(f: &block()) { f(); } +fn force(f: block()) { f(); } fn main() { let x: int; force(block () { log_err x; }); } diff --git a/src/test/compile-fail/nested-ty-params.rs b/src/test/compile-fail/nested-ty-params.rs index 7a249c657fd..a78546e0412 100644 --- a/src/test/compile-fail/nested-ty-params.rs +++ b/src/test/compile-fail/nested-ty-params.rs @@ -1,6 +1,6 @@ // error-pattern:Attempt to use a type argument out of scope -fn hd<U>(v: &[U]) -> U { - fn hd1(w: &[U]) -> U { ret w[0]; } +fn hd<U>(v: [U]) -> U { + fn hd1(w: [U]) -> U { ret w[0]; } ret hd1(v); } diff --git a/src/test/compile-fail/not-a-pred-2.rs b/src/test/compile-fail/not-a-pred-2.rs index 2226c5cbf32..b1bfb15bff3 100644 --- a/src/test/compile-fail/not-a-pred-2.rs +++ b/src/test/compile-fail/not-a-pred-2.rs @@ -9,4 +9,5 @@ fn main() { + } diff --git a/src/test/compile-fail/type-arg-out-of-scope.rs b/src/test/compile-fail/type-arg-out-of-scope.rs index 19be0933c48..334cba2a271 100644 --- a/src/test/compile-fail/type-arg-out-of-scope.rs +++ b/src/test/compile-fail/type-arg-out-of-scope.rs @@ -1,5 +1,5 @@ // error-pattern:Attempt to use a type argument out of scope -fn foo<T>(x: &T) { - fn bar(f: fn(&T) -> T) { } +fn foo<T>(x: T) { + fn bar(f: fn(T) -> T) { } } fn main() { foo(1); } diff --git a/src/test/compile-fail/unsafe-alias.rs b/src/test/compile-fail/unsafe-alias.rs index 9b3e277a1fa..7038f6bdbb1 100644 --- a/src/test/compile-fail/unsafe-alias.rs +++ b/src/test/compile-fail/unsafe-alias.rs @@ -1,10 +1,8 @@ // error-pattern:may alias with argument -fn foo(x: &{mutable x: int}, f: fn()) { log x; } +fn foo(x: {mutable x: int}, f: fn()) { log x; } -fn whoknows(x: @mutable {mutable x: int}) { - *x = {mutable x: 10}; -} +fn whoknows(x: @mutable {mutable x: int}) { *x = {mutable x: 10}; } fn main() { let box = @mutable {mutable x: 1}; diff --git a/src/test/compile-fail/unsafe-mutable-alias.rs b/src/test/compile-fail/unsafe-mutable-alias.rs index c94fca11d5a..3fac666bad4 100644 --- a/src/test/compile-fail/unsafe-mutable-alias.rs +++ b/src/test/compile-fail/unsafe-mutable-alias.rs @@ -1,7 +1,8 @@ // error-pattern:mutable alias to a variable that roots another alias -fn f(a: &{mutable x: int}, b: &mutable {mutable x: int}) -> int { - b.x += 1; ret a.x + b.x; +fn f(a: {mutable x: int}, b: &mutable {mutable x: int}) -> int { + b.x += 1; + ret a.x + b.x; } fn main() { let i = {mutable x: 4}; log f(i, i); } diff --git a/src/test/compile-fail/writing-through-read-alias.rs b/src/test/compile-fail/writing-through-read-alias.rs index 9de010eca93..d4dec3c3f00 100644 --- a/src/test/compile-fail/writing-through-read-alias.rs +++ b/src/test/compile-fail/writing-through-read-alias.rs @@ -4,6 +4,6 @@ type point = {x: int, y: int, z: int}; -fn f(p: &point) { p.x = 13; } +fn f(p: point) { p.x = 13; } fn main() { let x: point = {x: 10, y: 11, z: 12}; f(x); } diff --git a/src/test/compiletest/compiletest.rs b/src/test/compiletest/compiletest.rs index c931369cfc7..6f0b853e6a9 100644 --- a/src/test/compiletest/compiletest.rs +++ b/src/test/compiletest/compiletest.rs @@ -27,7 +27,7 @@ fn main(args: [str]) { run_tests(config); } -fn parse_config(args: &[str]) -> config { +fn parse_config(args: [str]) -> config { let opts = [getopts::reqopt("compile-lib-path"), getopts::reqopt("run-lib-path"), getopts::reqopt("rustc-path"), getopts::reqopt("src-base"), @@ -61,7 +61,7 @@ fn parse_config(args: &[str]) -> config { verbose: getopts::opt_present(match, "verbose")}; } -fn log_config(config: &config) { +fn log_config(config: config) { let c = config; logv(c, #fmt["configuration:"]); logv(c, #fmt["compile_lib_path: %s", config.compile_lib_path]); @@ -83,11 +83,11 @@ fn opt_str(maybestr: option::t<str>) -> str { alt maybestr { option::some(s) { s } option::none. { "(none)" } } } -fn str_opt(maybestr: &str) -> option::t<str> { +fn str_opt(maybestr: str) -> option::t<str> { if maybestr != "(none)" { option::some(maybestr) } else { option::none } } -fn str_mode(s: &str) -> mode { +fn str_mode(s: str) -> mode { alt s { "compile-fail" { mode_compile_fail } "run-fail" { mode_run_fail } @@ -106,7 +106,7 @@ fn mode_str(mode: mode) -> str { } } -fn run_tests(config: &config) { +fn run_tests(config: config) { let opts = test_opts(config); let cx = {config: config, procsrv: procsrv::mk()}; let tests = make_tests(cx); @@ -114,7 +114,7 @@ fn run_tests(config: &config) { procsrv::close(cx.procsrv); } -fn test_opts(config: &config) -> test::test_opts { +fn test_opts(config: config) -> test::test_opts { {filter: alt config.filter { option::some(s) { option::some(s) } @@ -124,9 +124,9 @@ fn test_opts(config: &config) -> test::test_opts { } type tests_and_conv_fn = - {tests: [test::test_desc], to_task: fn(&fn()) -> test::joinable}; + {tests: [test::test_desc], to_task: fn(fn()) -> test::joinable}; -fn make_tests(cx: &cx) -> tests_and_conv_fn { +fn make_tests(cx: cx) -> tests_and_conv_fn { log #fmt["making tests from %s", cx.config.src_base]; let configport = port::<[u8]>(); let tests = []; @@ -140,7 +140,7 @@ fn make_tests(cx: &cx) -> tests_and_conv_fn { ret {tests: tests, to_task: bind closure_to_task(cx, configport, _)}; } -fn is_test(config: &config, testfile: &str) -> bool { +fn is_test(config: config, testfile: str) -> bool { // Pretty-printer does not work with .rc files yet let valid_extensions = alt config.mode { mode_pretty. { [".rs"] } _ { [".rc", ".rs"] } }; @@ -160,14 +160,14 @@ fn is_test(config: &config, testfile: &str) -> bool { ret valid; } -fn make_test(cx: &cx, testfile: &str, configport: &port<[u8]>) -> +fn make_test(cx: cx, testfile: str, configport: port<[u8]>) -> test::test_desc { {name: make_test_name(cx.config, testfile), fn: make_test_closure(testfile, chan(configport)), ignore: header::is_test_ignored(cx.config, testfile)} } -fn make_test_name(config: &config, testfile: &str) -> str { +fn make_test_name(config: config, testfile: str) -> str { #fmt["[%s] %s", mode_str(config.mode), testfile] } @@ -190,8 +190,7 @@ up. Then we'll spawn that data into another task and return the task. Really convoluted. Need to think up of a better definition for tests. */ -fn make_test_closure(testfile: &str, configchan: chan<[u8]>) -> - test::test_fn { +fn make_test_closure(testfile: str, configchan: chan<[u8]>) -> test::test_fn { bind send_config(testfile, configchan) } @@ -209,7 +208,7 @@ break up the config record and pass everything individually to the spawned function. */ -fn closure_to_task(cx: cx, configport: port<[u8]>, testfn: &fn()) -> +fn closure_to_task(cx: cx, configport: port<[u8]>, testfn: fn()) -> test::joinable { testfn(); let testfile = recv(configport); diff --git a/src/test/compiletest/header.rs b/src/test/compiletest/header.rs index 8a03378742b..9f896c48e74 100644 --- a/src/test/compiletest/header.rs +++ b/src/test/compiletest/header.rs @@ -23,7 +23,7 @@ type test_props = { }; // Load any test directives embedded in the file -fn load_props(testfile: &str) -> test_props { +fn load_props(testfile: str) -> test_props { let error_patterns = []; let compile_flags = option::none; let pp_exact = option::none; @@ -54,7 +54,7 @@ fn load_props(testfile: &str) -> test_props { }; } -fn is_test_ignored(config: &config, testfile: &str) -> bool { +fn is_test_ignored(config: config, testfile: str) -> bool { let found = false; for each ln: str in iter_header(testfile) { // FIXME: Can't return or break from iterator @@ -66,7 +66,7 @@ fn is_test_ignored(config: &config, testfile: &str) -> bool { ret found; } -iter iter_header(testfile: &str) -> str { +iter iter_header(testfile: str) -> str { let rdr = io::file_reader(testfile); while !rdr.eof() { let ln = rdr.read_line(); @@ -81,15 +81,15 @@ iter iter_header(testfile: &str) -> str { } } -fn parse_error_pattern(line: &str) -> option::t<str> { +fn parse_error_pattern(line: str) -> option::t<str> { parse_name_value_directive(line, "error-pattern") } -fn parse_compile_flags(line: &str) -> option::t<str> { +fn parse_compile_flags(line: str) -> option::t<str> { parse_name_value_directive(line, "compile-flags") } -fn parse_pp_exact(line: &str, testfile: &str) -> option::t<str> { +fn parse_pp_exact(line: str, testfile: str) -> option::t<str> { alt parse_name_value_directive(line, "pp-exact") { option::some(s) { option::some(s) } option::none. { @@ -102,12 +102,12 @@ fn parse_pp_exact(line: &str, testfile: &str) -> option::t<str> { } } -fn parse_name_directive(line: &str, directive: &str) -> bool { +fn parse_name_directive(line: str, directive: str) -> bool { str::find(line, directive) >= 0 } -fn parse_name_value_directive(line: &str, - directive: &str) -> option::t<str> { +fn parse_name_value_directive(line: str, + directive: str) -> option::t<str> { let keycolon = directive + ":"; if str::find(line, keycolon) >= 0 { let colon = str::find(line, keycolon) as uint; diff --git a/src/test/compiletest/procsrv.rs b/src/test/compiletest/procsrv.rs index 63a3807f6a5..ae98853976e 100644 --- a/src/test/compiletest/procsrv.rs +++ b/src/test/compiletest/procsrv.rs @@ -47,15 +47,15 @@ fn mk() -> handle { ret {task: option::some(task), chan: recv(setupport)}; } -fn from_chan(ch: &reqchan) -> handle { {task: option::none, chan: ch} } +fn from_chan(ch: reqchan) -> handle { {task: option::none, chan: ch} } -fn close(handle: &handle) { +fn close(handle: handle) { send(handle.chan, stop); task::join(option::get(handle.task)); } -fn run(handle: &handle, lib_path: &str, prog: &str, args: &[str], - input: &option::t<str>) -> {status: int, out: str, err: str} { +fn run(handle: handle, lib_path: str, prog: str, args: [str], + input: option::t<str>) -> {status: int, out: str, err: str} { let p = port(); let ch = chan(p); send(handle.chan, @@ -70,7 +70,7 @@ fn run(handle: &handle, lib_path: &str, prog: &str, args: &[str], ret {status: status, out: output, err: errput}; } -fn writeclose(fd: int, s: &option::t<str>) { +fn writeclose(fd: int, s: option::t<str>) { if option::is_some(s) { let writer = io::new_writer(io::fd_buf_writer(fd, option::none)); writer.write_str(option::get(s)); @@ -151,7 +151,7 @@ fn worker(p: port<request>) { } } -fn with_lib_path<@T>(path: &str, f: fn() -> T) -> T { +fn with_lib_path<@T>(path: str, f: fn() -> T) -> T { let maybe_oldpath = getenv(util::lib_path_env_var()); append_lib_path(path); let res = f(); @@ -164,17 +164,17 @@ fn with_lib_path<@T>(path: &str, f: fn() -> T) -> T { ret res; } -fn append_lib_path(path: &str) { export_lib_path(util::make_new_path(path)); } +fn append_lib_path(path: str) { export_lib_path(util::make_new_path(path)); } -fn export_lib_path(path: &str) { setenv(util::lib_path_env_var(), path); } +fn export_lib_path(path: str) { setenv(util::lib_path_env_var(), path); } -fn clone_vecstr(v: &[str]) -> [[u8]] { +fn clone_vecstr(v: [str]) -> [[u8]] { let r = []; for t: str in vec::slice(v, 0u, vec::len(v)) { r += [str::bytes(t)]; } ret r; } -fn clone_vecu8str(v: &[[u8]]) -> [str] { +fn clone_vecu8str(v: [[u8]]) -> [str] { let r = []; for t in vec::slice(v, 0u, vec::len(v)) { r += [str::unsafe_from_bytes(t)]; diff --git a/src/test/compiletest/runtest.rs b/src/test/compiletest/runtest.rs index 87ae7750e03..a715985b2cd 100644 --- a/src/test/compiletest/runtest.rs +++ b/src/test/compiletest/runtest.rs @@ -18,7 +18,7 @@ import util::logv; export run; -fn run(cx: &cx, _testfile: -[u8]) { +fn run(cx: cx, _testfile: -[u8]) { let testfile = str::unsafe_from_bytes(_testfile); if cx.config.verbose { // We're going to be dumping a lot of info. Start on a new line. @@ -34,7 +34,7 @@ fn run(cx: &cx, _testfile: -[u8]) { } } -fn run_cfail_test(cx: &cx, props: &test_props, testfile: &str) { +fn run_cfail_test(cx: cx, props: test_props, testfile: str) { let procres = compile_test(cx, props, testfile); if procres.status == 0 { @@ -44,7 +44,7 @@ fn run_cfail_test(cx: &cx, props: &test_props, testfile: &str) { check_error_patterns(props, testfile, procres); } -fn run_rfail_test(cx: &cx, props: &test_props, testfile: &str) { +fn run_rfail_test(cx: cx, props: test_props, testfile: str) { let procres = compile_test(cx, props, testfile); if procres.status != 0 { fatal_procres("compilation failed!", procres); } @@ -67,7 +67,7 @@ fn run_rfail_test(cx: &cx, props: &test_props, testfile: &str) { check_error_patterns(props, testfile, procres); } -fn run_rpass_test(cx: &cx, props: &test_props, testfile: &str) { +fn run_rpass_test(cx: cx, props: test_props, testfile: str) { let procres = compile_test(cx, props, testfile); if procres.status != 0 { fatal_procres("compilation failed!", procres); } @@ -78,7 +78,7 @@ fn run_rpass_test(cx: &cx, props: &test_props, testfile: &str) { if procres.status != 0 { fatal_procres("test run failed!", procres); } } -fn run_pretty_test(cx: &cx, props: &test_props, testfile: &str) { +fn run_pretty_test(cx: cx, props: test_props, testfile: str) { if option::is_some(props.pp_exact) { logv(cx.config, "testing for exact pretty-printing"); } else { logv(cx.config, "testing for converging pretty-printing"); } @@ -131,18 +131,18 @@ fn run_pretty_test(cx: &cx, props: &test_props, testfile: &str) { ret; - fn print_source(cx: &cx, testfile: &str, src: &str) -> procres { + fn print_source(cx: cx, testfile: str, src: str) -> procres { compose_and_run(cx, testfile, make_pp_args, cx.config.compile_lib_path, option::some(src)) } - fn make_pp_args(config: &config, _testfile: &str) -> procargs { + fn make_pp_args(config: config, _testfile: str) -> procargs { let prog = config.rustc_path; let args = ["-", "--pretty", "normal"]; ret {prog: prog, args: args}; } - fn compare_source(expected: &str, actual: &str) { + fn compare_source(expected: str, actual: str) { if expected != actual { error("pretty-printed source does match expected source"); let msg = @@ -162,20 +162,19 @@ actual:\n\ } } - fn typecheck_source(cx: &cx, testfile: &str, src: &str) -> procres { + fn typecheck_source(cx: cx, testfile: str, src: str) -> procres { compose_and_run(cx, testfile, make_typecheck_args, cx.config.compile_lib_path, option::some(src)) } - fn make_typecheck_args(config: &config, _testfile: &str) -> procargs { + fn make_typecheck_args(config: config, _testfile: str) -> procargs { let prog = config.rustc_path; let args = ["-", "--no-trans", "--lib"]; ret {prog: prog, args: args}; } } -fn check_error_patterns(props: &test_props, testfile: &str, - procres: &procres) { +fn check_error_patterns(props: test_props, testfile: str, procres: procres) { if vec::is_empty(props.error_patterns) { fatal("no error pattern specified in " + testfile); } @@ -216,26 +215,25 @@ type procargs = {prog: str, args: [str]}; type procres = {status: int, stdout: str, stderr: str, cmdline: str}; -fn compile_test(cx: &cx, props: &test_props, testfile: &str) -> procres { +fn compile_test(cx: cx, props: test_props, testfile: str) -> procres { compose_and_run(cx, testfile, bind make_compile_args(_, props, _), cx.config.compile_lib_path, option::none) } -fn exec_compiled_test(cx: &cx, props: &test_props, testfile: &str) -> - procres { +fn exec_compiled_test(cx: cx, props: test_props, testfile: str) -> procres { compose_and_run(cx, testfile, bind make_run_args(_, props, _), cx.config.run_lib_path, option::none) } -fn compose_and_run(cx: &cx, testfile: &str, - make_args: fn(&config, &str) -> procargs, lib_path: &str, +fn compose_and_run(cx: cx, testfile: str, + make_args: fn(config, str) -> procargs, lib_path: str, input: option::t<str>) -> procres { let procargs = make_args(cx.config, testfile); ret program_output(cx, testfile, lib_path, procargs.prog, procargs.args, input); } -fn make_compile_args(config: &config, props: &test_props, testfile: &str) -> +fn make_compile_args(config: config, props: test_props, testfile: str) -> procargs { let prog = config.rustc_path; let args = [testfile, "-o", make_exe_name(config, testfile)]; @@ -249,11 +247,11 @@ fn make_compile_args(config: &config, props: &test_props, testfile: &str) -> ret {prog: prog, args: args}; } -fn make_exe_name(config: &config, testfile: &str) -> str { +fn make_exe_name(config: config, testfile: str) -> str { output_base_name(config, testfile) + os::exec_suffix() } -fn make_run_args(config: &config, props: &test_props, testfile: &str) -> +fn make_run_args(config: config, props: test_props, testfile: str) -> procargs { let toolargs = if !props.no_valgrind { @@ -271,14 +269,14 @@ fn make_run_args(config: &config, props: &test_props, testfile: &str) -> ret {prog: args[0], args: vec::slice(args, 1u, vec::len(args))}; } -fn split_maybe_args(argstr: &option::t<str>) -> [str] { - fn rm_whitespace(v: &[str]) -> [str] { - fn flt(s: &str) -> option::t<str> { +fn split_maybe_args(argstr: option::t<str>) -> [str] { + fn rm_whitespace(v: [str]) -> [str] { + fn flt(s: str) -> option::t<str> { if !is_whitespace(s) { option::some(s) } else { option::none } } // FIXME: This should be in std - fn is_whitespace(s: &str) -> bool { + fn is_whitespace(s: str) -> bool { for c: u8 in s { if c != ' ' as u8 { ret false; } } ret true; } @@ -291,8 +289,8 @@ fn split_maybe_args(argstr: &option::t<str>) -> [str] { } } -fn program_output(cx: &cx, testfile: &str, lib_path: &str, prog: &str, - args: &[str], input: option::t<str>) -> procres { +fn program_output(cx: cx, testfile: str, lib_path: str, prog: str, + args: [str], input: option::t<str>) -> procres { let cmdline = { let cmdline = make_cmdline(lib_path, prog, args); @@ -307,18 +305,18 @@ fn program_output(cx: &cx, testfile: &str, lib_path: &str, prog: &str, cmdline: cmdline}; } -fn make_cmdline(libpath: &str, prog: &str, args: &[str]) -> str { +fn make_cmdline(libpath: str, prog: str, args: [str]) -> str { #fmt["%s %s %s", lib_path_cmd_prefix(libpath), prog, str::connect(args, " ")] } // Build the LD_LIBRARY_PATH variable as it would be seen on the command line // for diagnostic purposes -fn lib_path_cmd_prefix(path: &str) -> str { +fn lib_path_cmd_prefix(path: str) -> str { #fmt["%s=\"%s\"", util::lib_path_env_var(), util::make_new_path(path)] } -fn dump_output(config: &config, testfile: &str, out: &str, err: &str) { +fn dump_output(config: config, testfile: str, out: str, err: str) { dump_output_file(config, testfile, out, "out"); dump_output_file(config, testfile, err, "err"); maybe_dump_to_stdout(config, out, err); @@ -326,8 +324,7 @@ fn dump_output(config: &config, testfile: &str, out: &str, err: &str) { #[cfg(target_os = "win32")] #[cfg(target_os = "linux")] -fn dump_output_file(config: &config, testfile: &str, out: &str, - extension: &str) { +fn dump_output_file(config: config, testfile: str, out: str, extension: str) { let outfile = make_out_name(config, testfile, extension); let writer = io::file_writer(outfile, [io::create, io::truncate]); writer.write_str(out); @@ -335,15 +332,14 @@ fn dump_output_file(config: &config, testfile: &str, out: &str, // FIXME (726): Can't use file_writer on mac #[cfg(target_os = "macos")] -fn dump_output_file(config: &config, testfile: &str, out: &str, - extension: &str) { +fn dump_output_file(config: config, testfile: str, out: str, extension: str) { } -fn make_out_name(config: &config, testfile: &str, extension: &str) -> str { +fn make_out_name(config: config, testfile: str, extension: str) -> str { output_base_name(config, testfile) + "." + extension } -fn output_base_name(config: &config, testfile: &str) -> str { +fn output_base_name(config: config, testfile: str) -> str { let base = config.build_base; let filename = { @@ -354,7 +350,7 @@ fn output_base_name(config: &config, testfile: &str) -> str { #fmt["%s%s.%s", base, filename, config.stage_id] } -fn maybe_dump_to_stdout(config: &config, out: &str, err: &str) { +fn maybe_dump_to_stdout(config: config, out: str, err: str) { if config.verbose { let sep1 = #fmt["------%s------------------------------", "stdout"]; let sep2 = #fmt["------%s------------------------------", "stderr"]; @@ -367,11 +363,11 @@ fn maybe_dump_to_stdout(config: &config, out: &str, err: &str) { } } -fn error(err: &str) { io::stdout().write_line(#fmt["\nerror: %s", err]); } +fn error(err: str) { io::stdout().write_line(#fmt["\nerror: %s", err]); } -fn fatal(err: &str) -> ! { error(err); fail; } +fn fatal(err: str) -> ! { error(err); fail; } -fn fatal_procres(err: &str, procres: procres) -> ! { +fn fatal_procres(err: str, procres: procres) -> ! { let msg = #fmt["\n\ error: %s\n\ diff --git a/src/test/compiletest/util.rs b/src/test/compiletest/util.rs index 769b409ea43..855aeb26e99 100644 --- a/src/test/compiletest/util.rs +++ b/src/test/compiletest/util.rs @@ -5,7 +5,7 @@ import std::str; import common::config; -fn make_new_path(path: &str) -> str { +fn make_new_path(path: str) -> str { // Windows just uses PATH as the library search path, so we have to // maintain the current value while adding our own @@ -24,7 +24,7 @@ fn lib_path_env_var() -> str { "DYLD_LIBRARY_PATH" } #[cfg(target_os = "win32")] fn lib_path_env_var() -> str { "PATH" } -fn logv(config: &config, s: &str) { +fn logv(config: config, s: str) { log s; if config.verbose { io::stdout().write_line(s); } } diff --git a/src/test/run-fail/port-type.rs b/src/test/run-fail/port-type.rs index 65b15b56d72..75474a17a75 100644 --- a/src/test/run-fail/port-type.rs +++ b/src/test/run-fail/port-type.rs @@ -5,7 +5,7 @@ import std::comm::port; import std::comm::send; import std::comm::recv; -fn echo<~T>(c: &chan<T>, oc: &chan<chan<T>>) { +fn echo<~T>(c: chan<T>, oc: chan<chan<T>>) { // Tests that the type argument in port gets // visited let p = port::<T>(); diff --git a/src/test/run-pass/alias-uninit-value.rs b/src/test/run-pass/alias-uninit-value.rs index 22a14dc3e50..9b7e0001f3c 100644 --- a/src/test/run-pass/alias-uninit-value.rs +++ b/src/test/run-pass/alias-uninit-value.rs @@ -9,7 +9,7 @@ tag sty { ty_nil; } type raw_t = {struct: sty, cname: option::t<str>, hash: uint}; -fn mk_raw_ty(st: sty, cname: &option::t<str>) -> raw_t { +fn mk_raw_ty(st: sty, cname: option::t<str>) -> raw_t { ret {struct: st, cname: cname, hash: 0u}; } diff --git a/src/test/run-pass/alt-join.rs b/src/test/run-pass/alt-join.rs index 4d1be53cdf3..e6cf1dec958 100644 --- a/src/test/run-pass/alt-join.rs +++ b/src/test/run-pass/alt-join.rs @@ -5,7 +5,7 @@ import std::option::t; import std::option::none; import std::option::some; -fn foo<T>(y: &option::t<T>) { +fn foo<T>(y: option::t<T>) { let x: int; let rs: [int] = []; /* tests that x doesn't get put in the precondition for the diff --git a/src/test/run-pass/argument-passing.rs b/src/test/run-pass/argument-passing.rs index 1e4ca8e9dff..32ce6ed6ef9 100644 --- a/src/test/run-pass/argument-passing.rs +++ b/src/test/run-pass/argument-passing.rs @@ -6,13 +6,13 @@ fn f1(a: {mutable x: int}, b: &mutable int, c: -int) -> int { ret r; } -fn f2(a: int, f: block(x: int)) -> int { f(1); ret a; } +fn f2(a: int, f: block(int)) -> int { f(1); ret a; } fn main() { let a = {mutable x: 1}, b = 2, c = 3; assert (f1(a, b, c) == 6); assert (a.x == 0); assert (b == 10); - assert (f2(a.x, {| x | a.x = 50; }) == 0); + assert (f2(a.x, {|x| a.x = 50; }) == 0); assert (a.x == 50); } diff --git a/src/test/run-pass/auto-instantiate.rs b/src/test/run-pass/auto-instantiate.rs index e06da60789c..8def06bfe98 100644 --- a/src/test/run-pass/auto-instantiate.rs +++ b/src/test/run-pass/auto-instantiate.rs @@ -2,6 +2,6 @@ // -*- rust -*- -fn f<@T, @U>(x: &T, y: &U) -> {a: T, b: U} { ret {a: x, b: y}; } +fn f<@T, @U>(x: T, y: U) -> {a: T, b: U} { ret {a: x, b: y}; } fn main() { log f({x: 3, y: 4, z: 5}, 4).a.x; log f(5, 6).a; } diff --git a/src/test/run-pass/autobind.rs b/src/test/run-pass/autobind.rs index ebf2bd432d4..29a8527e6f3 100644 --- a/src/test/run-pass/autobind.rs +++ b/src/test/run-pass/autobind.rs @@ -1,9 +1,9 @@ -fn f<@T>(x: &[T]) -> T { ret x[0]; } +fn f<@T>(x: [T]) -> T { ret x[0]; } -fn g(act: fn(&[int]) -> int) -> int { ret act([1, 2, 3]); } +fn g(act: fn([int]) -> int) -> int { ret act([1, 2, 3]); } fn main() { assert (g(f) == 1); - let f1: fn(&[str]) -> str = f; + let f1: fn([str]) -> str = f; assert (f1(["x", "y", "z"]) == "x"); } diff --git a/src/test/run-pass/bind-parameterized-args-2.rs b/src/test/run-pass/bind-parameterized-args-2.rs index 68d47073413..266ad2ddbed 100644 --- a/src/test/run-pass/bind-parameterized-args-2.rs +++ b/src/test/run-pass/bind-parameterized-args-2.rs @@ -1,7 +1,7 @@ fn main() { - fn echo<T>(c: int, x: fn(&T)) { log_err "wee"; } + fn echo<T>(c: int, x: fn(T)) { log_err "wee"; } let y = bind echo(42, _); - y(fn (i: &str) { }); + y(fn (i: str) { }); } diff --git a/src/test/run-pass/bind-parameterized-args.rs b/src/test/run-pass/bind-parameterized-args.rs index 1f3e8efbf37..d1feb5ac91d 100644 --- a/src/test/run-pass/bind-parameterized-args.rs +++ b/src/test/run-pass/bind-parameterized-args.rs @@ -1,7 +1,7 @@ fn main() { - fn echo<T>(c: int, x: &[T]) { } + fn echo<T>(c: int, x: [T]) { } - let y: fn(&[int]) = bind echo(42, _); + let y: fn([int]) = bind echo(42, _); y([1]); } diff --git a/src/test/run-pass/block-fn-coerce.rs b/src/test/run-pass/block-fn-coerce.rs index 163d99ee5d6..7e70c9d633a 100644 --- a/src/test/run-pass/block-fn-coerce.rs +++ b/src/test/run-pass/block-fn-coerce.rs @@ -1,4 +1,4 @@ -fn force(f: &block() -> int) -> int { ret f(); } +fn force(f: block() -> int) -> int { ret f(); } fn main() { let f = fn () -> int { ret 7 }; assert (force(f) == 7); diff --git a/src/test/run-pass/block-iter-1.rs b/src/test/run-pass/block-iter-1.rs index 006d4f18fe4..7b10e124c64 100644 --- a/src/test/run-pass/block-iter-1.rs +++ b/src/test/run-pass/block-iter-1.rs @@ -1,10 +1,9 @@ -fn iter_vec<T>(v: &[T], f: &block(&T)) { for x: T in v { f(x); } } +fn iter_vec<T>(v: [T], f: block(T)) { for x: T in v { f(x); } } fn main() { let v = [1, 2, 3, 4, 5, 6, 7]; let odds = 0; - iter_vec(v, - {|&i| log_err i; if i % 2 == 1 { odds += 1; } log_err odds; }); + iter_vec(v, {|i| log_err i; if i % 2 == 1 { odds += 1; } log_err odds; }); log_err odds; assert (odds == 4); } diff --git a/src/test/run-pass/block-iter-2.rs b/src/test/run-pass/block-iter-2.rs index d49cffbcc72..f80cd270440 100644 --- a/src/test/run-pass/block-iter-2.rs +++ b/src/test/run-pass/block-iter-2.rs @@ -1,9 +1,9 @@ -fn iter_vec<T>(v: &[T], f: &block(&T)) { for x: T in v { f(x); } } +fn iter_vec<T>(v: [T], f: block(T)) { for x: T in v { f(x); } } fn main() { let v = [1, 2, 3, 4, 5]; let sum = 0; - iter_vec(v, {|&i| iter_vec(v, {|&j| log_err i * j; sum += i * j; }); }); + iter_vec(v, {|i| iter_vec(v, {|j| log_err i * j; sum += i * j; }); }); log_err sum; assert (sum == 225); } diff --git a/src/test/run-pass/block-vec-map2.rs b/src/test/run-pass/block-vec-map2.rs index 35b979b3694..da677abebac 100644 --- a/src/test/run-pass/block-vec-map2.rs +++ b/src/test/run-pass/block-vec-map2.rs @@ -3,7 +3,7 @@ import std::vec; fn main() { let v = - std::vec::map2({|&i, &b| if b { -i } else { i } }, [1, 2, 3, 4, 5], + std::vec::map2({|i, b| if b { -i } else { i } }, [1, 2, 3, 4, 5], [true, false, false, true, true]); log_err v; assert (v == [-1, 2, 3, -4, -5]); diff --git a/src/test/run-pass/box-unbox.rs b/src/test/run-pass/box-unbox.rs index 08633a572a3..54558d1785a 100644 --- a/src/test/run-pass/box-unbox.rs +++ b/src/test/run-pass/box-unbox.rs @@ -2,7 +2,7 @@ type box<T> = {c: @T}; -fn unbox<@T>(b: &box<T>) -> T { ret *b.c; } +fn unbox<@T>(b: box<T>) -> T { ret *b.c; } fn main() { let foo: int = 17; diff --git a/src/test/run-pass/double-unbox.rs b/src/test/run-pass/double-unbox.rs index aacfbb91509..827dbb908b4 100644 --- a/src/test/run-pass/double-unbox.rs +++ b/src/test/run-pass/double-unbox.rs @@ -1,6 +1,6 @@ type quux = {bar: int}; -fn g(i: &int) { } +fn g(i: int) { } fn f(foo: @@quux) { g(foo.bar); } fn main() { } diff --git a/src/test/run-pass/drop-parametric-closure-with-bound-box.rs b/src/test/run-pass/drop-parametric-closure-with-bound-box.rs index f24cf65e70e..ce270d7b06b 100644 --- a/src/test/run-pass/drop-parametric-closure-with-bound-box.rs +++ b/src/test/run-pass/drop-parametric-closure-with-bound-box.rs @@ -1,5 +1,5 @@ -fn f<T>(i: @int, t: &T) { } +fn f<T>(i: @int, t: T) { } fn main() { let x = bind f::<char>(@0xdeafbeef, _); } diff --git a/src/test/run-pass/expr-alt-generic-box1.rs b/src/test/run-pass/expr-alt-generic-box1.rs index 763f303bbd6..ce11b0a990e 100644 --- a/src/test/run-pass/expr-alt-generic-box1.rs +++ b/src/test/run-pass/expr-alt-generic-box1.rs @@ -4,7 +4,7 @@ // -*- rust -*- type compare<T> = fn(@T, @T) -> bool; -fn test_generic<T>(expected: @T, eq: &compare<T>) { +fn test_generic<T>(expected: @T, eq: compare<T>) { let actual: @T = alt true { true { expected } }; assert (eq(expected, actual)); } diff --git a/src/test/run-pass/expr-alt-generic-box2.rs b/src/test/run-pass/expr-alt-generic-box2.rs index 046d77cd438..ec67c72ae0d 100644 --- a/src/test/run-pass/expr-alt-generic-box2.rs +++ b/src/test/run-pass/expr-alt-generic-box2.rs @@ -2,15 +2,15 @@ // -*- rust -*- -type compare<T> = fn(&T, &T) -> bool; +type compare<T> = fn(T, T) -> bool; -fn test_generic<T>(expected: &T, eq: &compare<T>) { +fn test_generic<T>(expected: T, eq: compare<T>) { let actual: T = alt true { true { expected } }; assert (eq(expected, actual)); } fn test_vec() { - fn compare_box(v1: &@int, v2: &@int) -> bool { ret v1 == v2; } + fn compare_box(v1: @int, v2: @int) -> bool { ret v1 == v2; } let eq = bind compare_box(_, _); test_generic::<@int>(@1, eq); } diff --git a/src/test/run-pass/expr-alt-generic.rs b/src/test/run-pass/expr-alt-generic.rs index c9990a0c756..d42e669b9ed 100644 --- a/src/test/run-pass/expr-alt-generic.rs +++ b/src/test/run-pass/expr-alt-generic.rs @@ -2,15 +2,15 @@ // -*- rust -*- -type compare<T> = fn(&T, &T) -> bool; +type compare<T> = fn(T, T) -> bool; -fn test_generic<T>(expected: &T, eq: &compare<T>) { +fn test_generic<T>(expected: T, eq: compare<T>) { let actual: T = alt true { true { expected } }; assert (eq(expected, actual)); } fn test_bool() { - fn compare_bool(b1: &bool, b2: &bool) -> bool { ret b1 == b2; } + fn compare_bool(b1: bool, b2: bool) -> bool { ret b1 == b2; } let eq = bind compare_bool(_, _); test_generic::<bool>(true, eq); } @@ -18,7 +18,7 @@ fn test_bool() { fn test_rec() { type t = {a: int, b: int}; - fn compare_rec(t1: &t, t2: &t) -> bool { ret t1 == t2; } + fn compare_rec(t1: t, t2: t) -> bool { ret t1 == t2; } let eq = bind compare_rec(_, _); test_generic::<t>({a: 1, b: 2}, eq); } diff --git a/src/test/run-pass/expr-block-generic-box1.rs b/src/test/run-pass/expr-block-generic-box1.rs index 5ab310cb309..28e5de3a830 100644 --- a/src/test/run-pass/expr-block-generic-box1.rs +++ b/src/test/run-pass/expr-block-generic-box1.rs @@ -4,7 +4,7 @@ // -*- rust -*- type compare<T> = fn(@T, @T) -> bool; -fn test_generic<T>(expected: @T, eq: &compare<T>) { +fn test_generic<T>(expected: @T, eq: compare<T>) { let actual: @T = { expected }; assert (eq(expected, actual)); } diff --git a/src/test/run-pass/expr-block-generic-box2.rs b/src/test/run-pass/expr-block-generic-box2.rs index 3f8293490f3..e51e30525e0 100644 --- a/src/test/run-pass/expr-block-generic-box2.rs +++ b/src/test/run-pass/expr-block-generic-box2.rs @@ -2,15 +2,15 @@ // -*- rust -*- -type compare<T> = fn(&T, &T) -> bool; +type compare<T> = fn(T, T) -> bool; -fn test_generic<T>(expected: &T, eq: &compare<T>) { +fn test_generic<T>(expected: T, eq: compare<T>) { let actual: T = { expected }; assert (eq(expected, actual)); } fn test_vec() { - fn compare_vec(v1: &@int, v2: &@int) -> bool { ret v1 == v2; } + fn compare_vec(v1: @int, v2: @int) -> bool { ret v1 == v2; } let eq = bind compare_vec(_, _); test_generic::<@int>(@1, eq); } diff --git a/src/test/run-pass/expr-block-generic.rs b/src/test/run-pass/expr-block-generic.rs index 52d463eae2a..48e4a9dff20 100644 --- a/src/test/run-pass/expr-block-generic.rs +++ b/src/test/run-pass/expr-block-generic.rs @@ -4,15 +4,15 @@ // -*- rust -*- // Tests for standalone blocks as expressions with dynamic type sizes -type compare<T> = fn(&T, &T) -> bool; +type compare<T> = fn(T, T) -> bool; -fn test_generic<T>(expected: &T, eq: &compare<T>) { +fn test_generic<T>(expected: T, eq: compare<T>) { let actual: T = { expected }; assert (eq(expected, actual)); } fn test_bool() { - fn compare_bool(b1: &bool, b2: &bool) -> bool { ret b1 == b2; } + fn compare_bool(b1: bool, b2: bool) -> bool { ret b1 == b2; } let eq = bind compare_bool(_, _); test_generic::<bool>(true, eq); } @@ -20,7 +20,7 @@ fn test_bool() { fn test_rec() { type t = {a: int, b: int}; - fn compare_rec(t1: &t, t2: &t) -> bool { ret t1 == t2; } + fn compare_rec(t1: t, t2: t) -> bool { ret t1 == t2; } let eq = bind compare_rec(_, _); test_generic::<t>({a: 1, b: 2}, eq); } diff --git a/src/test/run-pass/expr-fn.rs b/src/test/run-pass/expr-fn.rs index b7070ead5ed..30ba5fa79e4 100644 --- a/src/test/run-pass/expr-fn.rs +++ b/src/test/run-pass/expr-fn.rs @@ -9,7 +9,7 @@ fn test_vec() { } fn test_generic() { - fn f<T>(t: &T) -> T { t } + fn f<T>(t: T) -> T { t } assert (f(10) == 10); } diff --git a/src/test/run-pass/expr-if-generic-box1.rs b/src/test/run-pass/expr-if-generic-box1.rs index 6d69cce9a1b..4b23d1a6e3f 100644 --- a/src/test/run-pass/expr-if-generic-box1.rs +++ b/src/test/run-pass/expr-if-generic-box1.rs @@ -4,7 +4,7 @@ // -*- rust -*- type compare<T> = fn(@T, @T) -> bool; -fn test_generic<T>(expected: @T, not_expected: @T, eq: &compare<T>) { +fn test_generic<T>(expected: @T, not_expected: @T, eq: compare<T>) { let actual: @T = if true { expected } else { not_expected }; assert (eq(expected, actual)); } diff --git a/src/test/run-pass/expr-if-generic-box2.rs b/src/test/run-pass/expr-if-generic-box2.rs index b31fb91f229..fd56d79dab9 100644 --- a/src/test/run-pass/expr-if-generic-box2.rs +++ b/src/test/run-pass/expr-if-generic-box2.rs @@ -2,15 +2,15 @@ // -*- rust -*- -type compare<T> = fn(&T, &T) -> bool; +type compare<T> = fn(T, T) -> bool; -fn test_generic<T>(expected: &T, not_expected: &T, eq: &compare<T>) { +fn test_generic<T>(expected: T, not_expected: T, eq: compare<T>) { let actual: T = if true { expected } else { not_expected }; assert (eq(expected, actual)); } fn test_vec() { - fn compare_box(v1: &@int, v2: &@int) -> bool { ret v1 == v2; } + fn compare_box(v1: @int, v2: @int) -> bool { ret v1 == v2; } let eq = bind compare_box(_, _); test_generic::<@int>(@1, @2, eq); } diff --git a/src/test/run-pass/expr-if-generic.rs b/src/test/run-pass/expr-if-generic.rs index 99709ea396c..154290319c1 100644 --- a/src/test/run-pass/expr-if-generic.rs +++ b/src/test/run-pass/expr-if-generic.rs @@ -4,15 +4,15 @@ // -*- rust -*- // Tests for if as expressions with dynamic type sizes -type compare<T> = fn(&T, &T) -> bool; +type compare<T> = fn(T, T) -> bool; -fn test_generic<T>(expected: &T, not_expected: &T, eq: &compare<T>) { +fn test_generic<T>(expected: T, not_expected: T, eq: compare<T>) { let actual: T = if true { expected } else { not_expected }; assert (eq(expected, actual)); } fn test_bool() { - fn compare_bool(b1: &bool, b2: &bool) -> bool { ret b1 == b2; } + fn compare_bool(b1: bool, b2: bool) -> bool { ret b1 == b2; } let eq = bind compare_bool(_, _); test_generic::<bool>(true, false, eq); } @@ -20,7 +20,7 @@ fn test_bool() { fn test_rec() { type t = {a: int, b: int}; - fn compare_rec(t1: &t, t2: &t) -> bool { ret t1 == t2; } + fn compare_rec(t1: t, t2: t) -> bool { ret t1 == t2; } let eq = bind compare_rec(_, _); test_generic::<t>({a: 1, b: 2}, {a: 2, b: 3}, eq); } diff --git a/src/test/run-pass/fixed-point-bind-box.rs b/src/test/run-pass/fixed-point-bind-box.rs index 57dcc98b2a8..53f93347c74 100644 --- a/src/test/run-pass/fixed-point-bind-box.rs +++ b/src/test/run-pass/fixed-point-bind-box.rs @@ -1,12 +1,12 @@ -fn fix_help<A, @B>(f: @fn(@fn(&A) -> B, &A) -> B, x: &A) -> B { +fn fix_help<A, @B>(f: @fn(@fn(A) -> B, A) -> B, x: A) -> B { ret f(@bind fix_help(f, _), x); } -fn fix<A, @B>(f: @fn(@fn(&A) -> B, &A) -> B) -> @fn(&A) -> B { +fn fix<A, @B>(f: @fn(@fn(A) -> B, A) -> B) -> @fn(A) -> B { ret @bind fix_help(f, _); } -fn fact_(f: @fn(&int) -> int, n: &int) -> int { +fn fact_(f: @fn(int) -> int, n: int) -> int { // fun fact 0 = 1 ret if n == 0 { 1 } else { n * f(n - 1) }; } diff --git a/src/test/run-pass/foreach-box-drop.rs b/src/test/run-pass/foreach-box-drop.rs index 5ad4d1ca607..960ef4e20a6 100644 --- a/src/test/run-pass/foreach-box-drop.rs +++ b/src/test/run-pass/foreach-box-drop.rs @@ -4,6 +4,6 @@ obj ob<K>(k: K) { iter foo() -> @{a: K} { put @{a: k}; } } -fn x(o: &ob<str>) { for each i: @{a: str} in o.foo() { } } +fn x(o: ob<str>) { for each i: @{a: str} in o.foo() { } } fn main() { let o = ob::<str>("hi" + "there"); x(o); } diff --git a/src/test/run-pass/generic-alias-box.rs b/src/test/run-pass/generic-alias-box.rs index 3250b88ab82..cf7e8ba499c 100644 --- a/src/test/run-pass/generic-alias-box.rs +++ b/src/test/run-pass/generic-alias-box.rs @@ -1,6 +1,6 @@ -fn id<@T>(t: &T) -> T { ret t; } +fn id<@T>(t: T) -> T { ret t; } fn main() { let expected = @100; diff --git a/src/test/run-pass/generic-bind-2.rs b/src/test/run-pass/generic-bind-2.rs index 5c149ad5936..8d584534fd8 100644 --- a/src/test/run-pass/generic-bind-2.rs +++ b/src/test/run-pass/generic-bind-2.rs @@ -1,6 +1,6 @@ -fn id<@T>(t: &T) -> T { ret t; } +fn id<@T>(t: T) -> T { ret t; } fn main() { let t = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7}; diff --git a/src/test/run-pass/generic-bind.rs b/src/test/run-pass/generic-bind.rs index 01156f57900..320b22c0bee 100644 --- a/src/test/run-pass/generic-bind.rs +++ b/src/test/run-pass/generic-bind.rs @@ -1,6 +1,6 @@ -fn id<@T>(t: &T) -> T { ret t; } +fn id<@T>(t: T) -> T { ret t; } fn main() { let t = {_0: 1, _1: 2, _2: 3, _3: 4, _4: 5, _5: 6, _6: 7}; diff --git a/src/test/run-pass/generic-box.rs b/src/test/run-pass/generic-box.rs index 5762847139d..3e37834f47b 100644 --- a/src/test/run-pass/generic-box.rs +++ b/src/test/run-pass/generic-box.rs @@ -1,6 +1,6 @@ -fn box<T>(x: &{x: T, y: T, z: T}) -> @{x: T, y: T, z: T} { ret @x; } +fn box<T>(x: {x: T, y: T, z: T}) -> @{x: T, y: T, z: T} { ret @x; } fn main() { let x: @{x: int, y: int, z: int} = box::<int>({x: 1, y: 2, z: 3}); diff --git a/src/test/run-pass/generic-derived-type.rs b/src/test/run-pass/generic-derived-type.rs index c11dce2ac7b..a889021378f 100644 --- a/src/test/run-pass/generic-derived-type.rs +++ b/src/test/run-pass/generic-derived-type.rs @@ -1,8 +1,8 @@ -fn g<@X>(x: &X) -> X { ret x; } +fn g<@X>(x: X) -> X { ret x; } -fn f<@T>(t: &T) -> {a: T, b: T} { +fn f<@T>(t: T) -> {a: T, b: T} { type pair = {a: T, b: T}; let x: pair = {a: t, b: t}; diff --git a/src/test/run-pass/generic-drop-glue.rs b/src/test/run-pass/generic-drop-glue.rs index ffadf46e8dd..ad89b7fe556 100644 --- a/src/test/run-pass/generic-drop-glue.rs +++ b/src/test/run-pass/generic-drop-glue.rs @@ -1,5 +1,5 @@ -fn f<T>(t: &T) { let t1: T = t; } +fn f<T>(t: T) { let t1: T = t; } fn main() { let x = {x: @10, y: @12}; f(x); } diff --git a/src/test/run-pass/generic-exterior-box.rs b/src/test/run-pass/generic-exterior-box.rs index 266fa987c3c..7573bff74e8 100644 --- a/src/test/run-pass/generic-exterior-box.rs +++ b/src/test/run-pass/generic-exterior-box.rs @@ -2,7 +2,7 @@ type recbox<T> = {x: @T}; -fn reclift<T>(t: &T) -> recbox<T> { ret {x: @t}; } +fn reclift<T>(t: T) -> recbox<T> { ret {x: @t}; } fn main() { let foo: int = 17; diff --git a/src/test/run-pass/generic-fn-infer.rs b/src/test/run-pass/generic-fn-infer.rs index 559fa4d0446..b1f5a06ee34 100644 --- a/src/test/run-pass/generic-fn-infer.rs +++ b/src/test/run-pass/generic-fn-infer.rs @@ -4,6 +4,6 @@ // -*- rust -*- // Issue #45: infer type parameters in function applications -fn id<@T>(x: &T) -> T { ret x; } +fn id<@T>(x: T) -> T { ret x; } fn main() { let x: int = 42; let y: int = id(x); assert (x == y); } diff --git a/src/test/run-pass/generic-fn.rs b/src/test/run-pass/generic-fn.rs index 940e0fe5aed..d72f32eeb10 100644 --- a/src/test/run-pass/generic-fn.rs +++ b/src/test/run-pass/generic-fn.rs @@ -2,7 +2,7 @@ // -*- rust -*- -fn id<@T>(x: &T) -> T { ret x; } +fn id<@T>(x: T) -> T { ret x; } type triple = {x: int, y: int, z: int}; diff --git a/src/test/run-pass/generic-iter-frame.rs b/src/test/run-pass/generic-iter-frame.rs index b575fe4809b..9d363906487 100644 --- a/src/test/run-pass/generic-iter-frame.rs +++ b/src/test/run-pass/generic-iter-frame.rs @@ -4,6 +4,6 @@ // Contrived example? No. It showed up in rustc's resolve pass. iter i() { put (); } -fn foo<T>(t: &T) { let x: int = 10; for each j: () in i() { log x; } } +fn foo<T>(t: T) { let x: int = 10; for each j: () in i() { log x; } } fn main() { foo(0xdeadbeef_u); } diff --git a/src/test/run-pass/generic-obj.rs b/src/test/run-pass/generic-obj.rs index 6653014b024..7226345d9c0 100644 --- a/src/test/run-pass/generic-obj.rs +++ b/src/test/run-pass/generic-obj.rs @@ -6,8 +6,8 @@ obj buf<@T>(data: {_0: T, _1: T, _2: T}) { ret data._0; } else { if i == 1 { ret data._1; } else { ret data._2; } } } - fn take(t: &T) { } - fn take2(t: &T) { } + fn take(t: T) { } + fn take2(t: T) { } } fn main() { diff --git a/src/test/run-pass/generic-tag-alt.rs b/src/test/run-pass/generic-tag-alt.rs index 0041e0fd268..d6f8dad88bc 100644 --- a/src/test/run-pass/generic-tag-alt.rs +++ b/src/test/run-pass/generic-tag-alt.rs @@ -2,7 +2,7 @@ tag foo<T> { arm(T); } -fn altfoo<T>(f: &foo<T>) { +fn altfoo<T>(f: foo<T>) { let hit = false; alt f { arm::<T>(x) { log "in arm"; hit = true; } } assert (hit); diff --git a/src/test/run-pass/generic-temporary.rs b/src/test/run-pass/generic-temporary.rs index afac9e176ee..36955938ef3 100644 --- a/src/test/run-pass/generic-temporary.rs +++ b/src/test/run-pass/generic-temporary.rs @@ -2,12 +2,12 @@ fn mk() -> int { ret 1; } -fn chk(a: &int) { log a; assert (a == 1); } +fn chk(a: int) { log a; assert (a == 1); } -fn apply<T>(produce: fn() -> T, consume: fn(&T)) { consume(produce()); } +fn apply<T>(produce: fn() -> T, consume: fn(T)) { consume(produce()); } fn main() { let produce: fn() -> int = mk; - let consume: fn(&int) = chk; + let consume: fn(int) = chk; apply::<int>(produce, consume); } diff --git a/src/test/run-pass/generic-tup.rs b/src/test/run-pass/generic-tup.rs index ac15998c1cc..08bf75b733b 100644 --- a/src/test/run-pass/generic-tup.rs +++ b/src/test/run-pass/generic-tup.rs @@ -1,4 +1,4 @@ -fn get_third<@T>(t: &(T, T, T)) -> T { let (_, _, x) = t; ret x; } +fn get_third<@T>(t: (T, T, T)) -> T { let (_, _, x) = t; ret x; } fn main() { log get_third((1, 2, 3)); diff --git a/src/test/run-pass/generic-type-synonym.rs b/src/test/run-pass/generic-type-synonym.rs index d05e9218a56..ebfbd8b4c7b 100644 --- a/src/test/run-pass/generic-type-synonym.rs +++ b/src/test/run-pass/generic-type-synonym.rs @@ -4,6 +4,6 @@ type foo<T> = {a: T}; type bar<T> = foo<T>; -fn takebar<T>(b: &bar<T>) { } +fn takebar<T>(b: bar<T>) { } fn main() { } diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index 6d5203f4884..0b6b07791d9 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -19,20 +19,20 @@ import std::comm::send; import std::comm::recv; import std::comm; -fn map(filename: &str, emit: map_reduce::putter) { emit(filename, "1"); } +fn map(filename: str, emit: map_reduce::putter) { emit(filename, "1"); } mod map_reduce { export putter; export mapper; export map_reduce; - type putter = fn(&str, &str); + type putter = fn(str, str); - type mapper = fn(&str, putter); + type mapper = fn(str, putter); tag ctrl_proto { find_reducer([u8], chan<int>); mapper_done; } - fn start_mappers(ctrl: chan<ctrl_proto>, inputs: &[str]) { + fn start_mappers(ctrl: chan<ctrl_proto>, inputs: [str]) { for i: str in inputs { task::spawn(bind map_task(ctrl, i)); } } @@ -40,8 +40,8 @@ mod map_reduce { let intermediates = map::new_str_hash(); - fn emit(im: &map::hashmap<str, int>, ctrl: chan<ctrl_proto>, - key: &str, val: &str) { + fn emit(im: map::hashmap<str, int>, ctrl: chan<ctrl_proto>, key: str, + val: str) { let c; alt im.find(key) { some(_c) { c = _c } @@ -61,7 +61,7 @@ mod map_reduce { send(ctrl, mapper_done); } - fn map_reduce(inputs: &[str]) { + fn map_reduce(inputs: [str]) { let ctrl = port(); // This task becomes the master control task. It spawns others diff --git a/src/test/run-pass/interior-vec.rs b/src/test/run-pass/interior-vec.rs index 956c97f23ec..20487ed6f4c 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<T>(v: &[T]) -> uint; + fn vec_len<T>(v: [T]) -> uint; } fn main() { diff --git a/src/test/run-pass/issue-333.rs b/src/test/run-pass/issue-333.rs index b5304234b98..27bbc2506b0 100644 --- a/src/test/run-pass/issue-333.rs +++ b/src/test/run-pass/issue-333.rs @@ -1,5 +1,5 @@ -fn quux<@T>(x: &T) -> T { let f = id::<T>; ret f(x); } +fn quux<@T>(x: T) -> T { let f = id::<T>; ret f(x); } -fn id<@T>(x: &T) -> T { ret x; } +fn id<@T>(x: T) -> T { ret x; } fn main() { assert (quux(10) == 10); } diff --git a/src/test/run-pass/ivec-add.rs b/src/test/run-pass/ivec-add.rs index 17b0a77d6ad..f9378b21317 100644 --- a/src/test/run-pass/ivec-add.rs +++ b/src/test/run-pass/ivec-add.rs @@ -1,4 +1,4 @@ -fn double<T>(a: &T) -> [T] { ret [a] + [a]; } +fn double<T>(a: T) -> [T] { ret [a] + [a]; } fn double_int(a: int) -> [int] { ret [a] + [a]; } diff --git a/src/test/run-pass/lambda-no-leak.rs b/src/test/run-pass/lambda-no-leak.rs index 0643de4bcfb..2c527e4953d 100644 --- a/src/test/run-pass/lambda-no-leak.rs +++ b/src/test/run-pass/lambda-no-leak.rs @@ -1,5 +1,5 @@ // Make sure we don't leak lambdas in silly ways. -fn force(f: &fn()) { f() } +fn force(f: fn()) { f() } fn main() { let x = 7; lambda () { log_err x; } diff --git a/src/test/run-pass/leak-box-as-tydesc.rs b/src/test/run-pass/leak-box-as-tydesc.rs index 5a5cb1e4da4..6fb6d759723 100644 --- a/src/test/run-pass/leak-box-as-tydesc.rs +++ b/src/test/run-pass/leak-box-as-tydesc.rs @@ -1,5 +1,5 @@ -fn leaky<T>(t: &T) { } +fn leaky<T>(t: T) { } fn main() { let x = @10; leaky::<@int>(x); } diff --git a/src/test/run-pass/newtype-polymorphic.rs b/src/test/run-pass/newtype-polymorphic.rs index 27fbaee6a77..191e3e4b3c7 100644 --- a/src/test/run-pass/newtype-polymorphic.rs +++ b/src/test/run-pass/newtype-polymorphic.rs @@ -1,8 +1,8 @@ tag myvec<X> = [X]; -fn myvec_deref<@X>(mv: &myvec<X>) -> [X] { ret *mv; } +fn myvec_deref<@X>(mv: myvec<X>) -> [X] { ret *mv; } -fn myvec_elt<@X>(mv: &myvec<X>) -> X { ret mv[0]; } +fn myvec_elt<@X>(mv: myvec<X>) -> X { ret mv[0]; } fn main() { let mv = myvec([1, 2, 3]); diff --git a/src/test/run-pass/newtype.rs b/src/test/run-pass/newtype.rs index 0b0a8c7b2d9..f1869f8e21b 100644 --- a/src/test/run-pass/newtype.rs +++ b/src/test/run-pass/newtype.rs @@ -1,6 +1,6 @@ -tag mytype = {compute: fn(&mytype) -> int, val: int}; +tag mytype = {compute: fn(mytype) -> int, val: int}; -fn compute(i: &mytype) -> int { ret i.val + 20; } +fn compute(i: mytype) -> int { ret i.val + 20; } fn main() { let myval = mytype({compute: compute, val: 30}); diff --git a/src/test/run-pass/non-boolean-pure-fns.rs b/src/test/run-pass/non-boolean-pure-fns.rs index 9478735d932..0f1558975a2 100644 --- a/src/test/run-pass/non-boolean-pure-fns.rs +++ b/src/test/run-pass/non-boolean-pure-fns.rs @@ -2,19 +2,19 @@ use std; import std::list::*; -pure fn pure_length_go<@T>(ls: &list<T>, acc: uint) -> uint { +pure fn pure_length_go<@T>(ls: list<T>, acc: uint) -> uint { alt ls { nil. { acc } cons(_, tl) { pure_length_go(*tl, acc + 1u) } } } -pure fn pure_length<@T>(ls: &list<T>) -> uint { pure_length_go(ls, 0u) } +pure fn pure_length<@T>(ls: list<T>) -> uint { pure_length_go(ls, 0u) } -pure fn nonempty_list<@T>(ls: &list<T>) -> bool { pure_length(ls) > 0u } +pure fn nonempty_list<@T>(ls: list<T>) -> bool { pure_length(ls) > 0u } // Of course, the compiler can't take advantage of the // knowledge that ls is a cons node. Future work. // Also, this is pretty contrived since nonempty_list // could be a "tag refinement", if we implement those. -fn safe_head<@T>(ls: &list<T>) : nonempty_list(ls) -> T { car(ls) } +fn safe_head<@T>(ls: list<T>) : nonempty_list(ls) -> T { car(ls) } fn main() { let mylist = cons(@1u, @nil); diff --git a/src/test/run-pass/or-pattern.rs b/src/test/run-pass/or-pattern.rs index 99682e0977a..9aa6694892d 100644 --- a/src/test/run-pass/or-pattern.rs +++ b/src/test/run-pass/or-pattern.rs @@ -1,6 +1,6 @@ tag blah { a(int, int, uint); b(int, int); c; } -fn or_alt(q: &blah) -> int { +fn or_alt(q: blah) -> int { alt q { a(x, y, _) | b(x, y) { ret x + y; } c. { ret 0; } } } diff --git a/src/test/run-pass/readalias.rs b/src/test/run-pass/readalias.rs index 93b8b22aef5..adc6432d016 100644 --- a/src/test/run-pass/readalias.rs +++ b/src/test/run-pass/readalias.rs @@ -4,6 +4,6 @@ // -*- rust -*- type point = {x: int, y: int, z: int}; -fn f(p: &point) { assert (p.z == 12); } +fn f(p: point) { assert (p.z == 12); } fn main() { let x: point = {x: 10, y: 11, z: 12}; f(x); } diff --git a/src/test/run-pass/rec-tup.rs b/src/test/run-pass/rec-tup.rs index 66cf866de9d..e5375403dfe 100644 --- a/src/test/run-pass/rec-tup.rs +++ b/src/test/run-pass/rec-tup.rs @@ -3,8 +3,8 @@ type point = {x: int, y: int}; type rect = (point, point); -fn fst(r: &rect) -> point { let (fst, _) = r; ret fst; } -fn snd(r: &rect) -> point { let (_, snd) = r; ret snd; } +fn fst(r: rect) -> point { let (fst, _) = r; ret fst; } +fn snd(r: rect) -> point { let (_, snd) = r; ret snd; } fn f(r: rect, x1: int, y1: int, x2: int, y2: int) { assert (fst(r).x == x1); diff --git a/src/test/run-pass/record-pat.rs b/src/test/run-pass/record-pat.rs index f2f4c6af2c7..06228674e3f 100644 --- a/src/test/run-pass/record-pat.rs +++ b/src/test/run-pass/record-pat.rs @@ -2,7 +2,7 @@ tag t1 { a(int); b(uint); } type t2 = {x: t1, y: int}; tag t3 { c(t2, uint); } -fn m(in: &t3) -> int { +fn m(in: t3) -> int { alt in { c({x: a(m), _}, _) { ret m; } c({x: b(m), y: y}, z) { ret (m + z as int) + y; } diff --git a/src/test/run-pass/resource-destruct.rs b/src/test/run-pass/resource-destruct.rs index 25a3c79e1c3..2df6dddb2a4 100644 --- a/src/test/run-pass/resource-destruct.rs +++ b/src/test/run-pass/resource-destruct.rs @@ -1,6 +1,6 @@ resource shrinky_pointer(i: @mutable int) { *i -= 1; } -fn look_at(pt: &shrinky_pointer) -> int { ret **pt; } +fn look_at(pt: shrinky_pointer) -> int { ret **pt; } fn main() { let my_total = @mutable 10; diff --git a/src/test/run-pass/resource-generic.rs b/src/test/run-pass/resource-generic.rs index 34ecc55f2e4..814503c194b 100644 --- a/src/test/run-pass/resource-generic.rs +++ b/src/test/run-pass/resource-generic.rs @@ -1,8 +1,8 @@ -resource finish<T>(arg: {val: T, fin: fn(&T)}) { arg.fin(arg.val); } +resource finish<T>(arg: {val: T, fin: fn(T)}) { arg.fin(arg.val); } fn main() { let box = @mutable 10; - fn dec_box(i: &@mutable int) { *i -= 1; } + fn dec_box(i: @mutable int) { *i -= 1; } { let i <- finish({val: box, fin: dec_box}); } assert (*box == 9); diff --git a/src/test/run-pass/send-type-inference.rs b/src/test/run-pass/send-type-inference.rs index cfc358a9106..9ab1d758fea 100644 --- a/src/test/run-pass/send-type-inference.rs +++ b/src/test/run-pass/send-type-inference.rs @@ -6,7 +6,7 @@ import std::comm::port; // tests that ctrl's type gets inferred properly type command<~K, ~V> = {key: K, val: V}; -fn cache_server<~K, ~V>(c: &chan<chan<command<K, V>>>) { +fn cache_server<~K, ~V>(c: chan<chan<command<K, V>>>) { let ctrl = port(); send(c, chan(ctrl)); } diff --git a/src/test/run-pass/size-and-align.rs b/src/test/run-pass/size-and-align.rs index 929ce3500f1..10c1e45017d 100644 --- a/src/test/run-pass/size-and-align.rs +++ b/src/test/run-pass/size-and-align.rs @@ -4,7 +4,7 @@ // -*- rust -*- tag clam<T> { a(T, int); b; } -fn uhoh<T>(v: &[clam<T>]) { +fn uhoh<T>(v: [clam<T>]) { alt v[1] { a::<T>(t, u) { log "incorrect"; log u; fail; } b::<T>. { log "correct"; } diff --git a/src/test/run-pass/swap-2.rs b/src/test/run-pass/swap-2.rs index 5caf36f9b92..71c3fb99d03 100644 --- a/src/test/run-pass/swap-2.rs +++ b/src/test/run-pass/swap-2.rs @@ -1,4 +1,4 @@ -fn swap<@T>(v: &[mutable T], i: int, j: int) { v[i] <-> v[j]; } +fn swap<@T>(v: [mutable T], i: int, j: int) { v[i] <-> v[j]; } fn main() { let a: [mutable int] = [mutable 0, 1, 2, 3, 4, 5, 6]; diff --git a/src/test/run-pass/syntax-extension-fmt.rs b/src/test/run-pass/syntax-extension-fmt.rs index 88204cfffeb..c241a68e7f1 100644 --- a/src/test/run-pass/syntax-extension-fmt.rs +++ b/src/test/run-pass/syntax-extension-fmt.rs @@ -1,7 +1,7 @@ use std; import std::str; -fn test(actual: &str, expected: &str) { +fn test(actual: str, expected: str) { log actual; log expected; assert (str::eq(actual, expected)); diff --git a/src/test/run-pass/tag-and-generic-obj.rs b/src/test/run-pass/tag-and-generic-obj.rs index de38f08cbf8..529bb14a9b6 100644 --- a/src/test/run-pass/tag-and-generic-obj.rs +++ b/src/test/run-pass/tag-and-generic-obj.rs @@ -3,7 +3,7 @@ tag colour { red; green; } obj foo<T>() { - fn meth(x: &T) { } + fn meth(x: T) { } } fn main() { foo::<colour>().meth(red); } diff --git a/src/test/run-pass/type-param-constraints.rs b/src/test/run-pass/type-param-constraints.rs index a5ea4c223d4..2d6a88e625c 100644 --- a/src/test/run-pass/type-param-constraints.rs +++ b/src/test/run-pass/type-param-constraints.rs @@ -1,6 +1,6 @@ -fn p_foo<T>(pinned: &T) { } -fn s_foo<@T>(shared: &T) { } -fn u_foo<~T>(unique: &T) { } +fn p_foo<T>(pinned: T) { } +fn s_foo<@T>(shared: T) { } +fn u_foo<~T>(unique: T) { } resource r(i: int) { } diff --git a/src/test/run-pass/type-param.rs b/src/test/run-pass/type-param.rs index be55ba86cac..56ad610fcdf 100644 --- a/src/test/run-pass/type-param.rs +++ b/src/test/run-pass/type-param.rs @@ -1,5 +1,5 @@ -type lteq<T> = fn(&T) -> bool; +type lteq<T> = fn(T) -> bool; fn main(args: [str]) { } diff --git a/src/test/run-pass/type-params-in-for-each.rs b/src/test/run-pass/type-params-in-for-each.rs index 760e5dadfa1..d734769c769 100644 --- a/src/test/run-pass/type-params-in-for-each.rs +++ b/src/test/run-pass/type-params-in-for-each.rs @@ -5,7 +5,7 @@ iter range(lo: uint, hi: uint) -> uint { while lo_ < hi { put lo_; lo_ += 1u; } } -fn create_index<T>(index: &[{a: T, b: uint}], hash_fn: fn(&T) -> uint) { +fn create_index<T>(index: [{a: T, b: uint}], hash_fn: fn(T) -> uint) { for each i: uint in range(0u, 256u) { let bucket: [T] = []; } } diff --git a/src/test/run-pass/unchecked-predicates.rs b/src/test/run-pass/unchecked-predicates.rs index d456f1f2e90..9c7cfc39963 100644 --- a/src/test/run-pass/unchecked-predicates.rs +++ b/src/test/run-pass/unchecked-predicates.rs @@ -5,24 +5,24 @@ import std::list::*; // Can't easily be written as a "pure fn" because there's // no syntax for specifying that f is pure. -fn pure_foldl<@T, @U>(ls: &list<T>, u: &U, f: &block(&T, &U) -> U) -> U { +fn pure_foldl<@T, @U>(ls: list<T>, u: U, f: block(T, U) -> U) -> U { alt ls { nil. { u } cons(hd, tl) { f(hd, pure_foldl(*tl, f(hd, u), f)) } } } // Shows how to use an "unchecked" block to call a general // fn from a pure fn -pure fn pure_length<@T>(ls: &list<T>) -> uint { - fn count<T>(_t: &T, u: &uint) -> uint { u + 1u } +pure fn pure_length<@T>(ls: list<T>) -> uint { + fn count<T>(_t: T, u: uint) -> uint { u + 1u } unchecked{ pure_foldl(ls, 0u, count) } } -pure fn nonempty_list<@T>(ls: &list<T>) -> bool { pure_length(ls) > 0u } +pure fn nonempty_list<@T>(ls: list<T>) -> bool { pure_length(ls) > 0u } // Of course, the compiler can't take advantage of the // knowledge that ls is a cons node. Future work. // Also, this is pretty contrived since nonempty_list // could be a "tag refinement", if we implement those. -fn safe_head<@T>(ls: &list<T>) : nonempty_list(ls) -> T { car(ls) } +fn safe_head<@T>(ls: list<T>) : nonempty_list(ls) -> T { car(ls) } fn main() { let mylist = cons(@1u, @nil); diff --git a/src/test/run-pass/use-uninit-alt.rs b/src/test/run-pass/use-uninit-alt.rs index 7315bf08fef..e1656c8dda9 100644 --- a/src/test/run-pass/use-uninit-alt.rs +++ b/src/test/run-pass/use-uninit-alt.rs @@ -1,6 +1,6 @@ -fn foo<T>(o: &myoption<T>) -> int { +fn foo<T>(o: myoption<T>) -> int { let x: int = 5; alt o { none::<T>. { } some::<T>(t) { x += 1; } } ret x; diff --git a/src/test/run-pass/use-uninit-alt2.rs b/src/test/run-pass/use-uninit-alt2.rs index 615296d974f..f702694d75a 100644 --- a/src/test/run-pass/use-uninit-alt2.rs +++ b/src/test/run-pass/use-uninit-alt2.rs @@ -1,6 +1,6 @@ -fn foo<T>(o: &myoption<T>) -> int { +fn foo<T>(o: myoption<T>) -> int { let x: int; alt o { none::<T>. { fail; } some::<T>(t) { x = 5; } } ret x; diff --git a/src/test/run-pass/vec-push.rs b/src/test/run-pass/vec-push.rs index c2f49311b1e..725dec057a9 100644 --- a/src/test/run-pass/vec-push.rs +++ b/src/test/run-pass/vec-push.rs @@ -1,5 +1,5 @@ -fn push<T>(v: &mutable [mutable? T], t: &T) { v += [t]; } +fn push<T>(v: &mutable [mutable? T], t: T) { v += [t]; } fn main() { let v = [1, 2, 3]; push(v, 1); } diff --git a/src/test/stdtest/deque.rs b/src/test/stdtest/deque.rs index acdde57b86e..104d68f03bb 100644 --- a/src/test/stdtest/deque.rs +++ b/src/test/stdtest/deque.rs @@ -79,9 +79,9 @@ fn test_boxes(a: @int, b: @int, c: @int, d: @int) { assert (deq.get(3) == d); } -type eqfn<T> = fn(&T, &T) -> bool; +type eqfn<T> = fn(T, T) -> bool; -fn test_parameterized<@T>(e: eqfn<T>, a: &T, b: &T, c: &T, d: &T) { +fn test_parameterized<@T>(e: eqfn<T>, a: T, b: T, c: T, d: T) { let deq: deque::t<T> = deque::create::<T>(); assert (deq.size() == 0u); deq.add_front(a); @@ -119,9 +119,9 @@ type reccy = {x: int, y: int, t: taggy}; #[test] fn test() { - fn inteq(a: &int, b: &int) -> bool { ret a == b; } - fn intboxeq(a: &@int, b: &@int) -> bool { ret a == b; } - fn taggyeq(a: &taggy, b: &taggy) -> bool { + fn inteq(a: int, b: int) -> bool { ret a == b; } + fn intboxeq(a: @int, b: @int) -> bool { ret a == b; } + fn taggyeq(a: taggy, b: taggy) -> bool { alt a { one(a1) { alt b { one(b1) { ret a1 == b1; } _ { ret false; } } } two(a1, a2) { @@ -138,7 +138,7 @@ fn test() { } } } - fn taggypareq<@T>(a: &taggypar<T>, b: &taggypar<T>) -> bool { + fn taggypareq<@T>(a: taggypar<T>, b: taggypar<T>) -> bool { alt a { onepar::<T>(a1) { alt b { onepar::<T>(b1) { ret a1 == b1; } _ { ret false; } } @@ -159,7 +159,7 @@ fn test() { } } } - fn reccyeq(a: &reccy, b: &reccy) -> bool { + fn reccyeq(a: reccy, b: reccy) -> bool { ret a.x == b.x && a.y == b.y && taggyeq(a.t, b.t); } log "*** test boxes"; diff --git a/src/test/stdtest/either.rs b/src/test/stdtest/either.rs index 5b3a3959cb3..966a04f70f4 100644 --- a/src/test/stdtest/either.rs +++ b/src/test/stdtest/either.rs @@ -5,16 +5,16 @@ import std::vec::len; #[test] fn test_either_left() { let val = left(10); - fn f_left(x: &int) -> bool { x == 10 } - fn f_right(_x: &uint) -> bool { false } + fn f_left(x: int) -> bool { x == 10 } + fn f_right(_x: uint) -> bool { false } assert (either(f_left, f_right, val)); } #[test] fn test_either_right() { let val = right(10u); - fn f_left(_x: &int) -> bool { false } - fn f_right(x: &uint) -> bool { x == 10u } + fn f_left(_x: int) -> bool { false } + fn f_right(x: uint) -> bool { x == 10u } assert (either(f_left, f_right, val)); } diff --git a/src/test/stdtest/list.rs b/src/test/stdtest/list.rs index 3880ee8d613..7906d277a10 100644 --- a/src/test/stdtest/list.rs +++ b/src/test/stdtest/list.rs @@ -17,7 +17,7 @@ fn test_from_vec() { #[test] fn test_foldl() { let l = from_vec([0, 1, 2, 3, 4]); - fn add(a: &int, b: &uint) -> uint { ret (a as uint) + b; } + fn add(a: int, b: uint) -> uint { ret (a as uint) + b; } let rs = list::foldl(l, 0u, add); assert (rs == 10u); } @@ -25,7 +25,7 @@ fn test_foldl() { #[test] fn test_find_success() { let l = from_vec([0, 1, 2]); - fn match(i: &int) -> option::t<int> { + fn match(i: int) -> option::t<int> { ret if i == 2 { option::some(i) } else { option::none::<int> }; } let rs = list::find(l, match); @@ -35,7 +35,7 @@ fn test_find_success() { #[test] fn test_find_fail() { let l = from_vec([0, 1, 2]); - fn match(_i: &int) -> option::t<int> { ret option::none::<int>; } + fn match(_i: int) -> option::t<int> { ret option::none::<int>; } let rs = list::find(l, match); assert (rs == option::none::<int>); } diff --git a/src/test/stdtest/map.rs b/src/test/stdtest/map.rs index 67240a7c69b..ff978085a27 100644 --- a/src/test/stdtest/map.rs +++ b/src/test/stdtest/map.rs @@ -11,7 +11,7 @@ import std::option; #[test] fn test_simple() { log "*** starting test_simple"; - fn eq_uint(x: &uint, y: &uint) -> bool { ret x == y; } + fn eq_uint(x: uint, y: uint) -> bool { ret x == y; } let hasher_uint: map::hashfn<uint> = util::id; let eqer_uint: map::eqfn<uint> = eq_uint; let hasher_str: map::hashfn<str> = str::hash; @@ -83,7 +83,7 @@ fn test_simple() { fn test_growth() { log "*** starting test_growth"; let num_to_insert: uint = 64u; - fn eq_uint(x: &uint, y: &uint) -> bool { ret x == y; } + fn eq_uint(x: uint, y: uint) -> bool { ret x == y; } log "uint -> uint"; let hasher_uint: map::hashfn<uint> = util::id; let eqer_uint: map::eqfn<uint> = eq_uint; @@ -157,8 +157,8 @@ fn test_growth() { fn test_removal() { log "*** starting test_removal"; let num_to_insert: uint = 64u; - fn eq(x: &uint, y: &uint) -> bool { ret x == y; } - fn hash(u: &uint) -> uint { + fn eq(x: uint, y: uint) -> bool { ret x == y; } + fn hash(u: uint) -> uint { // This hash function intentionally causes collisions between // consecutive integer pairs. diff --git a/src/test/stdtest/qsort.rs b/src/test/stdtest/qsort.rs index 609adf3afe4..ad2a82ef426 100644 --- a/src/test/stdtest/qsort.rs +++ b/src/test/stdtest/qsort.rs @@ -5,9 +5,9 @@ import std::sort; import std::vec; import std::int; -fn check_sort(v1: &[mutable int], v2: &[mutable int]) { +fn check_sort(v1: [mutable int], v2: [mutable int]) { let len = std::vec::len::<int>(v1); - fn ltequal(a: &int, b: &int) -> bool { ret a <= b; } + fn ltequal(a: int, b: int) -> bool { ret a <= b; } let f = ltequal; std::sort::quick_sort::<int>(f, v1); let i = 0u; @@ -46,7 +46,7 @@ fn test_simple() { let expected = [1, 2, 3]; - fn lteq(a: &int, b: &int) -> bool { int::le(a, b) } + fn lteq(a: int, b: int) -> bool { int::le(a, b) } sort::quick_sort(lteq, names); let immut_names = vec::from_mut(names); diff --git a/src/test/stdtest/qsort3.rs b/src/test/stdtest/qsort3.rs index 6c8df212218..6688a175e8d 100644 --- a/src/test/stdtest/qsort3.rs +++ b/src/test/stdtest/qsort3.rs @@ -1,10 +1,10 @@ use std; -fn check_sort(v1: &[mutable int], v2: &[mutable int]) { +fn check_sort(v1: [mutable int], v2: [mutable int]) { let len = std::vec::len::<int>(v1); - fn lt(a: &int, b: &int) -> bool { ret a < b; } - fn equal(a: &int, b: &int) -> bool { ret a == b; } + fn lt(a: int, b: int) -> bool { ret a < b; } + fn equal(a: int, b: int) -> bool { ret a == b; } let f1 = lt; let f2 = equal; std::sort::quick_sort3::<int>(f1, f2, v1); diff --git a/src/test/stdtest/run.rs b/src/test/stdtest/run.rs index b60a3935500..218889c766b 100644 --- a/src/test/stdtest/run.rs +++ b/src/test/stdtest/run.rs @@ -45,7 +45,7 @@ fn test_pipes() { log actual; assert (expected == actual); - fn writeclose(fd: int, s: &str) { + fn writeclose(fd: int, s: str) { let writer = io::new_writer(io::fd_buf_writer(fd, option::none)); writer.write_str(s); diff --git a/src/test/stdtest/sha1.rs b/src/test/stdtest/sha1.rs index 6b72be20dd5..9b47b7f1f09 100644 --- a/src/test/stdtest/sha1.rs +++ b/src/test/stdtest/sha1.rs @@ -50,7 +50,7 @@ fn test() { 0xfau8, 0xd3u8, 0xe8u8, 0x5au8, 0x0bu8, 0xd1u8, 0x7du8, 0x9bu8, 0x10u8, 0x0du8, 0xb4u8, 0xb3u8]}]; let tests = fips_180_1_tests + wikipedia_tests; - fn check_vec_eq(v0: &[u8], v1: &[u8]) { + fn check_vec_eq(v0: [u8], v1: [u8]) { assert (vec::len::<u8>(v0) == vec::len::<u8>(v1)); let len = vec::len::<u8>(v0); let i = 0u; diff --git a/src/test/stdtest/sort.rs b/src/test/stdtest/sort.rs index c42f950ce6b..e27124dd015 100644 --- a/src/test/stdtest/sort.rs +++ b/src/test/stdtest/sort.rs @@ -1,9 +1,9 @@ use std; -fn check_sort(v1: &[int], v2: &[int]) { +fn check_sort(v1: [int], v2: [int]) { let len = std::vec::len::<int>(v1); - fn lteq(a: &int, b: &int) -> bool { ret a <= b; } + fn lteq(a: int, b: int) -> bool { ret a <= b; } let f = lteq; let v3 = std::sort::merge_sort::<int>(f, v1); let i = 0u; diff --git a/src/test/stdtest/str.rs b/src/test/stdtest/str.rs index 2852822f8d4..5e79bb6fc20 100644 --- a/src/test/stdtest/str.rs +++ b/src/test/stdtest/str.rs @@ -39,7 +39,7 @@ fn test_index_and_rindex() { #[test] fn test_split() { - fn t(s: &str, c: char, i: int, k: &str) { + fn t(s: str, c: char, i: int, k: str) { log "splitting: " + s; log i; let v = str::split(s, c as u8); @@ -59,7 +59,7 @@ fn test_split() { #[test] fn test_find() { - fn t(haystack: &str, needle: &str, i: int) { + fn t(haystack: str, needle: str, i: int) { let j: int = str::find(haystack, needle); log "searched for " + needle; log j; @@ -74,7 +74,7 @@ fn test_find() { #[test] fn test_substr() { - fn t(a: &str, b: &str, start: int) { + fn t(a: str, b: str, start: int) { assert (str::eq(str::substr(a, start as uint, str::byte_len(b)), b)); } t("hello", "llo", 2); @@ -84,7 +84,7 @@ fn test_substr() { #[test] fn test_concat() { - fn t(v: &[str], s: &str) { assert (str::eq(str::concat(v), s)); } + fn t(v: [str], s: str) { assert (str::eq(str::concat(v), s)); } t(["you", "know", "I'm", "no", "good"], "youknowI'mnogood"); let v: [str] = []; t(v, ""); @@ -93,7 +93,7 @@ fn test_concat() { #[test] fn test_connect() { - fn t(v: &[str], sep: &str, s: &str) { + fn t(v: [str], sep: str, s: str) { assert (str::eq(str::connect(v, sep), s)); } t(["you", "know", "I'm", "no", "good"], " ", "you know I'm no good"); diff --git a/src/test/stdtest/treemap.rs b/src/test/stdtest/treemap.rs index 0f4119c6c3d..3d7bd4fd747 100644 --- a/src/test/stdtest/treemap.rs +++ b/src/test/stdtest/treemap.rs @@ -40,7 +40,7 @@ fn traverse_in_order() { insert(m, 1, ()); let n = 0; - fn t(n: &mutable int, k: &int, v: &()) { assert (n == k); n += 1; } + fn t(n: &mutable int, k: int, v: ()) { assert (n == k); n += 1; } traverse(m, bind t(n, _, _)); } diff --git a/src/test/stdtest/vec.rs b/src/test/stdtest/vec.rs index 6194c461c15..a9cda6c73d6 100644 --- a/src/test/stdtest/vec.rs +++ b/src/test/stdtest/vec.rs @@ -8,15 +8,15 @@ import std::option::some; fn square(n: uint) -> uint { ret n * n; } -fn square_alias(n: &uint) -> uint { ret n * n; } +fn square_alias(n: uint) -> uint { ret n * n; } -pure fn is_three(n: &uint) -> bool { ret n == 3u; } +pure fn is_three(n: uint) -> bool { ret n == 3u; } -fn square_if_odd(n: &uint) -> option::t<uint> { +fn square_if_odd(n: uint) -> option::t<uint> { ret if n % 2u == 1u { some(n * n) } else { none }; } -fn add(x: &uint, y: &uint) -> uint { ret x + y; } +fn add(x: uint, y: uint) -> uint { ret x + y; } #[test] fn test_unsafe_ptrs() { @@ -228,7 +228,7 @@ fn test_map() { #[test] fn test_map2() { - fn times(x: &int, y: &int) -> int { ret x * y; } + fn times(x: int, y: int) -> int { ret x * y; } let f = times; let v0 = [1, 2, 3, 4, 5]; let v1 = [5, 4, 3, 2, 1]; @@ -254,12 +254,12 @@ fn test_filter_map() { assert (w[1] == 9u); assert (w[2] == 25u); - fn halve(i: &int) -> option::t<int> { + fn halve(i: int) -> option::t<int> { if i % 2 == 0 { ret option::some::<int>(i / 2); } else { ret option::none::<int>; } } - fn halve_for_sure(i: &int) -> int { ret i / 2; } + fn halve_for_sure(i: int) -> int { ret i / 2; } let all_even: [int] = [0, 2, 8, 6]; let all_odd1: [int] = [1, 7, 3]; let all_odd2: [int] = []; @@ -328,8 +328,8 @@ fn test_position() { #[test] fn test_position_pred() { - fn less_than_three(i: &int) -> bool { ret i < 3; } - fn is_eighteen(i: &int) -> bool { ret i == 18; } + fn less_than_three(i: int) -> bool { ret i < 3; } + fn is_eighteen(i: int) -> bool { ret i == 18; } let v1: [int] = [5, 4, 3, 2, 1]; assert (position_pred(less_than_three, v1) == option::some::<uint>(3u)); assert (position_pred(is_eighteen, v1) == option::none::<uint>); |
