From f1a8b58811da99da00a41c1f6a68f1c83e64c4c2 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 5 Mar 2013 17:36:39 -0800 Subject: [PATCH] rustc: De-mode some bits of trans --- src/librustc/middle/trans/base.rs | 26 +++++++-------- src/librustc/middle/trans/build.rs | 19 ++++++----- src/librustc/middle/trans/callee.rs | 12 +++---- src/librustc/middle/trans/common.rs | 39 +++++++++++------------ src/librustc/middle/trans/controlflow.rs | 11 +++---- src/librustc/middle/trans/datum.rs | 2 +- src/librustc/middle/trans/glue.rs | 4 +-- src/librustc/middle/trans/monomorphize.rs | 9 +++--- src/librustc/middle/trans/type_of.rs | 2 +- 9 files changed, 61 insertions(+), 63 deletions(-) diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 1926b2f2e5df7..f9b704e267a06 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -197,7 +197,7 @@ pub fn get_extern_const(externs: ExternMap, llmod: ModuleRef, } pub fn trans_foreign_call(cx: block, externs: ExternMap, - llmod: ModuleRef, name: @str, args: ~[ValueRef]) -> + llmod: ModuleRef, name: @str, args: &[ValueRef]) -> ValueRef { let _icx = cx.insn_ctxt("trans_foreign_call"); let n = args.len() as int; @@ -242,7 +242,7 @@ pub fn bump_ptr(bcx: block, t: ty::t, base: ValueRef, sz: ValueRef) -> // @llblobptr is the data part of a enum value; its actual type // is meaningless, as it will be cast away. pub fn GEP_enum(bcx: block, llblobptr: ValueRef, enum_id: ast::def_id, - variant_id: ast::def_id, ty_substs: ~[ty::t], + variant_id: ast::def_id, ty_substs: &[ty::t], ix: uint) -> ValueRef { let _icx = bcx.insn_ctxt("GEP_enum"); let ccx = bcx.ccx(); @@ -449,7 +449,7 @@ pub fn set_inline_hint(f: ValueRef) { } } -pub fn set_inline_hint_if_appr(attrs: ~[ast::attribute], +pub fn set_inline_hint_if_appr(attrs: &[ast::attribute], llfn: ValueRef) { match attr::find_inline_attr(attrs) { attr::ia_hint => set_inline_hint(llfn), @@ -489,7 +489,7 @@ pub fn note_unique_llvm_symbol(ccx: @CrateContext, +sym: ~str) { pub fn get_res_dtor(ccx: @CrateContext, did: ast::def_id, - parent_id: ast::def_id, substs: ~[ty::t]) + parent_id: ast::def_id, substs: &[ty::t]) -> ValueRef { let _icx = ccx.insn_ctxt("trans_res_dtor"); if !substs.is_empty() { @@ -516,7 +516,7 @@ pub fn get_res_dtor(ccx: @CrateContext, did: ast::def_id, } // Structural comparison: a rather involved form of glue. -pub fn maybe_name_value(cx: @CrateContext, v: ValueRef, s: ~str) { +pub fn maybe_name_value(cx: @CrateContext, v: ValueRef, s: &str) { if cx.sess.opts.save_temps { let _: () = str::as_c_str(s, |buf| { unsafe { @@ -641,7 +641,7 @@ pub fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t, fn iter_variant(cx: block, a_tup: ValueRef, variant: ty::VariantInfo, - tps: ~[ty::t], tid: ast::def_id, + tps: &[ty::t], tid: ast::def_id, f: val_and_ty_fn) -> block { let _icx = cx.insn_ctxt("iter_variant"); if variant.args.len() == 0u { return cx; } @@ -916,7 +916,7 @@ pub fn have_cached_lpad(bcx: block) -> bool { return res; } -pub fn in_lpad_scope_cx(bcx: block, f: fn(&mut scope_info)) { +pub fn in_lpad_scope_cx(bcx: block, f: fn(+si: &mut scope_info)) { let mut bcx = bcx; loop { { @@ -1652,7 +1652,7 @@ pub fn new_fn_ctxt(ccx: @CrateContext, // field of the fn_ctxt with pub fn create_llargs_for_fn_args(cx: fn_ctxt, ty_self: self_arg, - args: ~[ast::arg]) -> ~[ValueRef] { + args: &[ast::arg]) -> ~[ValueRef] { let _icx = cx.insn_ctxt("create_llargs_for_fn_args"); match ty_self { @@ -1865,7 +1865,7 @@ pub fn trans_fn(ccx: @CrateContext, debug!("trans_fn(ty_self=%?)", ty_self); let _icx = ccx.insn_ctxt("trans_fn"); ccx.stats.n_fns += 1; - let the_path_str = path_str(ccx.sess, path); + let the_path_str = path_str(ccx.sess, &path); trans_closure(ccx, path, decl, body, llfndecl, ty_self, param_substs, id, impl_id, |fcx| { @@ -1883,7 +1883,7 @@ pub fn trans_fn(ccx: @CrateContext, pub fn trans_enum_variant(ccx: @CrateContext, enum_id: ast::node_id, variant: ast::variant, - args: ~[ast::variant_arg], + args: &[ast::variant_arg], disr: int, is_degen: bool, param_substs: Option<@param_substs>, @@ -1946,7 +1946,7 @@ pub fn trans_enum_variant(ccx: @CrateContext, // NB: In theory this should be merged with the function above. But the AST // structures are completely different, so very little code would be shared. pub fn trans_tuple_struct(ccx: @CrateContext, - fields: ~[@ast::struct_field], + fields: &[@ast::struct_field], ctor_id: ast::node_id, param_substs: Option<@param_substs>, llfndecl: ValueRef) { @@ -2847,7 +2847,7 @@ pub fn trap(bcx: block) { } } -pub fn decl_gc_metadata(ccx: @CrateContext, llmod_id: ~str) { +pub fn decl_gc_metadata(ccx: @CrateContext, llmod_id: &str) { if !ccx.sess.opts.gc || !*ccx.uses_gc { return; } @@ -3014,7 +3014,7 @@ pub fn trans_crate(sess: session::Session, tcx: ty::ctxt, output: &Path, emap2: resolve::ExportMap2, - maps: astencode::Maps) -> (ModuleRef, LinkMeta) { + +maps: astencode::Maps) -> (ModuleRef, LinkMeta) { let symbol_hasher = @hash::default_state(); let link_meta = diff --git a/src/librustc/middle/trans/build.rs b/src/librustc/middle/trans/build.rs index 353109f7dd851..897d898eae6c0 100644 --- a/src/librustc/middle/trans/build.rs +++ b/src/librustc/middle/trans/build.rs @@ -117,7 +117,7 @@ pub fn Ret(cx: block, V: ValueRef) { } } -pub fn AggregateRet(cx: block, RetVals: ~[ValueRef]) { +pub fn AggregateRet(cx: block, RetVals: &[ValueRef]) { if cx.unreachable { return; } check_not_terminated(cx); terminate(cx, "AggregateRet"); @@ -184,7 +184,7 @@ pub fn noname() -> *libc::c_char { } } -pub fn Invoke(cx: block, Fn: ValueRef, Args: ~[ValueRef], +pub fn Invoke(cx: block, Fn: ValueRef, Args: &[ValueRef], Then: BasicBlockRef, Catch: BasicBlockRef) { if cx.unreachable { return; } check_not_terminated(cx); @@ -202,7 +202,7 @@ pub fn Invoke(cx: block, Fn: ValueRef, Args: ~[ValueRef], } } -pub fn FastInvoke(cx: block, Fn: ValueRef, Args: ~[ValueRef], +pub fn FastInvoke(cx: block, Fn: ValueRef, Args: &[ValueRef], Then: BasicBlockRef, Catch: BasicBlockRef) { if cx.unreachable { return; } check_not_terminated(cx); @@ -567,7 +567,7 @@ pub fn Store(cx: block, Val: ValueRef, Ptr: ValueRef) { } } -pub fn GEP(cx: block, Pointer: ValueRef, Indices: ~[ValueRef]) -> ValueRef { +pub fn GEP(cx: block, Pointer: ValueRef, Indices: &[ValueRef]) -> ValueRef { unsafe { if cx.unreachable { return llvm::LLVMGetUndef(T_ptr(T_nil())); } count_insn(cx, "gep"); @@ -810,7 +810,7 @@ pub fn EmptyPhi(cx: block, Ty: TypeRef) -> ValueRef { } } -pub fn Phi(cx: block, Ty: TypeRef, vals: ~[ValueRef], bbs: ~[BasicBlockRef]) +pub fn Phi(cx: block, Ty: TypeRef, vals: &[ValueRef], bbs: &[BasicBlockRef]) -> ValueRef { unsafe { if cx.unreachable { return llvm::LLVMGetUndef(Ty); } @@ -844,11 +844,10 @@ pub fn _UndefReturn(cx: block, Fn: ValueRef) -> ValueRef { } } -pub fn add_span_comment(bcx: block, sp: span, text: ~str) { +pub fn add_span_comment(bcx: block, sp: span, text: &str) { let ccx = bcx.ccx(); if !ccx.sess.no_asm_comments() { - let s = text + ~" (" + ccx.sess.codemap.span_to_str(sp) - + ~")"; + let s = fmt!("%s (%s)", text, ccx.sess.codemap.span_to_str(sp)); log(debug, copy s); add_comment(bcx, s); } @@ -888,7 +887,7 @@ pub fn Call(cx: block, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef { } } -pub fn FastCall(cx: block, Fn: ValueRef, Args: ~[ValueRef]) -> ValueRef { +pub fn FastCall(cx: block, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef { if cx.unreachable { return _UndefReturn(cx, Fn); } unsafe { count_insn(cx, "fastcall"); @@ -899,7 +898,7 @@ pub fn FastCall(cx: block, Fn: ValueRef, Args: ~[ValueRef]) -> ValueRef { } } -pub fn CallWithConv(cx: block, Fn: ValueRef, Args: ~[ValueRef], +pub fn CallWithConv(cx: block, Fn: ValueRef, Args: &[ValueRef], Conv: CallConv) -> ValueRef { if cx.unreachable { return _UndefReturn(cx, Fn); } unsafe { diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 8bc47531d7208..e8d542efa1689 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -187,7 +187,7 @@ pub fn trans_fn_ref_with_vtables_to_callee( bcx: block, def_id: ast::def_id, ref_id: ast::node_id, - +type_params: ~[ty::t], + type_params: &[ty::t], vtables: Option) -> Callee { Callee {bcx: bcx, @@ -199,7 +199,7 @@ pub fn trans_fn_ref_with_vtables( bcx: block, // def_id: ast::def_id, // def id of fn ref_id: ast::node_id, // node id of use of fn; may be zero if N/A - +type_params: ~[ty::t], // values for fn's ty params + type_params: &[ty::t], // values for fn's ty params vtables: Option) -> FnData { //! @@ -378,7 +378,7 @@ pub fn trans_lang_call(bcx: block, pub fn trans_lang_call_with_type_params(bcx: block, did: ast::def_id, args: &[ValueRef], - type_params: ~[ty::t], + type_params: &[ty::t], dest: expr::Dest) -> block { let fty; @@ -394,7 +394,7 @@ pub fn trans_lang_call_with_type_params(bcx: block, |bcx| { let callee = trans_fn_ref_with_vtables_to_callee(bcx, did, 0, - copy type_params, + type_params, None); let new_llval; @@ -636,8 +636,8 @@ pub enum AutorefArg { pub fn trans_arg_expr(bcx: block, formal_ty: ty::arg, arg_expr: @ast::expr, - temp_cleanups: &mut ~[ValueRef], - ret_flag: Option, + +temp_cleanups: &mut ~[ValueRef], + +ret_flag: Option, +autoref_arg: AutorefArg) -> Result { let _icx = bcx.insn_ctxt("trans_arg_expr"); let ccx = bcx.ccx(); diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 33b52c6e6b6ca..2d7149fdfb2bb 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -57,13 +57,12 @@ use syntax::codemap::span; use syntax::parse::token::ident_interner; use syntax::{ast, ast_map}; -pub type namegen = @fn(~str) -> ident; +pub type namegen = @fn(+s: ~str) -> ident; pub fn new_namegen(intr: @ident_interner) -> namegen { - let f: @fn(~str) -> ident = |prefix| { - // XXX: Bad copies. + let f: @fn(+s: ~str) -> ident = |prefix| { intr.gensym(@fmt!("%s_%u", prefix, - intr.gensym(@copy prefix).repr)) + intr.gensym(@prefix).repr)) }; f } @@ -325,10 +324,10 @@ pub struct fn_ctxt_ { pub type fn_ctxt = @mut fn_ctxt_; -pub fn warn_not_to_commit(ccx: @CrateContext, msg: ~str) { +pub fn warn_not_to_commit(ccx: @CrateContext, msg: &str) { if !*ccx.do_not_commit_warning_issued { *ccx.do_not_commit_warning_issued = true; - ccx.sess.warn(msg + ~" -- do not commit like this!"); + ccx.sess.warn(msg.to_str() + ~" -- do not commit like this!"); } } @@ -358,7 +357,7 @@ pub struct cleanup_path { dest: BasicBlockRef } -pub fn scope_clean_changed(scope_info: &mut scope_info) { +pub fn scope_clean_changed(+scope_info: &mut scope_info) { if scope_info.cleanup_paths.len() > 0u { scope_info.cleanup_paths = ~[]; } scope_info.landing_pad = None; } @@ -625,7 +624,7 @@ pub fn rslt(bcx: block, val: ValueRef) -> Result { } pub impl Result { - fn unpack(&self, bcx: &mut block) -> ValueRef { + fn unpack(&self, +bcx: &mut block) -> ValueRef { *bcx = self.bcx; return self.val; } @@ -645,7 +644,7 @@ pub fn val_str(tn: @TypeNames, v: ValueRef) -> @str { return ty_str(tn, val_ty(v)); } -pub fn in_scope_cx(cx: block, f: &fn(&mut scope_info)) { +pub fn in_scope_cx(cx: block, f: &fn(+si: &mut scope_info)) { let mut cur = cx; loop { { @@ -811,7 +810,7 @@ pub fn T_size_t(targ_cfg: @session::config) -> TypeRef { return T_int(targ_cfg); } -pub fn T_fn(inputs: ~[TypeRef], output: TypeRef) -> TypeRef { +pub fn T_fn(inputs: &[TypeRef], output: TypeRef) -> TypeRef { unsafe { return llvm::LLVMFunctionType(output, to_ptr(inputs), inputs.len() as c_uint, @@ -835,7 +834,7 @@ pub fn T_root(t: TypeRef, addrspace: addrspace) -> TypeRef { } } -pub fn T_struct(elts: ~[TypeRef]) -> TypeRef { +pub fn T_struct(elts: &[TypeRef]) -> TypeRef { unsafe { return llvm::LLVMStructType(to_ptr(elts), elts.len() as c_uint, @@ -843,14 +842,14 @@ pub fn T_struct(elts: ~[TypeRef]) -> TypeRef { } } -pub fn T_named_struct(name: ~str) -> TypeRef { +pub fn T_named_struct(name: &str) -> TypeRef { unsafe { let c = llvm::LLVMGetGlobalContext(); return str::as_c_str(name, |buf| llvm::LLVMStructCreateNamed(c, buf)); } } -pub fn set_struct_body(t: TypeRef, elts: ~[TypeRef]) { +pub fn set_struct_body(t: TypeRef, elts: &[TypeRef]) { unsafe { llvm::LLVMStructSetBody(t, to_ptr(elts), @@ -1094,7 +1093,7 @@ pub fn C_integral(t: TypeRef, u: u64, sign_extend: Bool) -> ValueRef { } } -pub fn C_floating(s: ~str, t: TypeRef) -> ValueRef { +pub fn C_floating(s: &str, t: TypeRef) -> ValueRef { unsafe { return str::as_c_str(s, |buf| llvm::LLVMConstRealOfString(t, buf)); } @@ -1169,7 +1168,7 @@ pub fn C_estr_slice(cx: @CrateContext, s: @~str) -> ValueRef { } // Returns a Plain Old LLVM String: -pub fn C_postr(s: ~str) -> ValueRef { +pub fn C_postr(s: &str) -> ValueRef { unsafe { return do str::as_c_str(s) |buf| { llvm::LLVMConstString(buf, str::len(s) as c_uint, False) @@ -1212,14 +1211,14 @@ pub fn C_named_struct(T: TypeRef, elts: &[ValueRef]) -> ValueRef { } } -pub fn C_array(ty: TypeRef, elts: ~[ValueRef]) -> ValueRef { +pub fn C_array(ty: TypeRef, elts: &[ValueRef]) -> ValueRef { unsafe { return llvm::LLVMConstArray(ty, vec::raw::to_ptr(elts), elts.len() as c_uint); } } -pub fn C_bytes(bytes: ~[u8]) -> ValueRef { +pub fn C_bytes(bytes: &[u8]) -> ValueRef { unsafe { return llvm::LLVMConstString( cast::reinterpret_cast(&vec::raw::to_ptr(bytes)), @@ -1227,7 +1226,7 @@ pub fn C_bytes(bytes: ~[u8]) -> ValueRef { } } -pub fn C_bytes_plus_null(bytes: ~[u8]) -> ValueRef { +pub fn C_bytes_plus_null(bytes: &[u8]) -> ValueRef { unsafe { return llvm::LLVMConstString( cast::reinterpret_cast(&vec::raw::to_ptr(bytes)), @@ -1311,9 +1310,9 @@ pub fn align_to(cx: block, off: ValueRef, align: ValueRef) -> ValueRef { return build::And(cx, bumped, build::Not(cx, mask)); } -pub fn path_str(sess: session::Session, p: path) -> ~str { +pub fn path_str(sess: session::Session, p: &path) -> ~str { let mut r = ~"", first = true; - for vec::each(p) |e| { + for vec::each(*p) |e| { match *e { ast_map::path_name(s) | ast_map::path_mod(s) => { if first { first = false; } diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index be6f1582e13de..911cd347ed0cf 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -108,7 +108,7 @@ pub fn trans_if(bcx: block, } -pub fn join_blocks(parent_bcx: block, in_cxs: ~[block]) -> block { +pub fn join_blocks(parent_bcx: block, in_cxs: &[block]) -> block { let out = sub_block(parent_bcx, ~"join"); let mut reachable = false; for vec::each(in_cxs) |bcx| { @@ -192,8 +192,7 @@ pub fn trans_log(log_ex: @ast::expr, bcx.fcx.path.filtered(|e| match *e { path_mod(_) => true, _ => false } )); - // XXX: Bad copy. - let modname = path_str(ccx.sess, copy modpath); + let modname = path_str(ccx.sess, &modpath); let global = if ccx.module_data.contains_key(&modname) { ccx.module_data.get(&modname) @@ -326,11 +325,11 @@ pub fn trans_ret(bcx: block, e: Option<@ast::expr>) -> block { pub fn trans_check_expr(bcx: block, chk_expr: @ast::expr, pred_expr: @ast::expr, - s: ~str) + s: &str) -> block { let _icx = bcx.insn_ctxt("trans_check_expr"); - let expr_str = @(s + ~" " + expr_to_str(pred_expr, bcx.ccx().sess.intr()) - + ~" failed"); + let expr_str = @(fmt!("%s %s failed", + s, expr_to_str(pred_expr, bcx.ccx().sess.intr()))); let Result {bcx, val} = { do with_scope_result(bcx, chk_expr.info(), ~"check") |bcx| { expr::trans_to_datum(bcx, pred_expr).to_result() diff --git a/src/librustc/middle/trans/datum.rs b/src/librustc/middle/trans/datum.rs index 59897ff150241..ce472fd9f1fdb 100644 --- a/src/librustc/middle/trans/datum.rs +++ b/src/librustc/middle/trans/datum.rs @@ -815,7 +815,7 @@ pub impl Datum { } pub impl DatumBlock { - fn unpack(&self, bcx: &mut block) -> Datum { + fn unpack(&self, +bcx: &mut block) -> Datum { *bcx = self.bcx; return self.datum; } diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index de6d22cd6b899..7bed3e86190a2 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -756,7 +756,7 @@ pub fn make_generic_glue_inner(ccx: @CrateContext, } pub fn make_generic_glue(ccx: @CrateContext, t: ty::t, llfn: ValueRef, - helper: glue_helper, name: ~str) + helper: glue_helper, name: &str) -> ValueRef { let _icx = ccx.insn_ctxt("make_generic_glue"); if !ccx.sess.trans_stats() { @@ -766,7 +766,7 @@ pub fn make_generic_glue(ccx: @CrateContext, t: ty::t, llfn: ValueRef, let start = time::get_time(); let llval = make_generic_glue_inner(ccx, t, llfn, helper); let end = time::get_time(); - log_fn_time(ccx, ~"glue " + name + ~" " + ty_to_short_str(ccx.tcx, t), + log_fn_time(ccx, fmt!("glue %s %s", name, ty_to_short_str(ccx.tcx, t)), start, end); return llval; } diff --git a/src/librustc/middle/trans/monomorphize.rs b/src/librustc/middle/trans/monomorphize.rs index b4b2f6afd1f4c..c0af1f4fad2a7 100644 --- a/src/librustc/middle/trans/monomorphize.rs +++ b/src/librustc/middle/trans/monomorphize.rs @@ -42,7 +42,7 @@ use syntax::parse::token::special_idents; pub fn monomorphic_fn(ccx: @CrateContext, fn_id: ast::def_id, - real_substs: ~[ty::t], + real_substs: &[ty::t], vtables: Option, impl_did_opt: Option, ref_id: Option) -> @@ -150,7 +150,8 @@ pub fn monomorphic_fn(ccx: @CrateContext, ccx.monomorphizing.insert(fn_id, depth + 1); let pt = vec::append(/*bad*/copy *pt, - ~[path_name((ccx.names)(*ccx.sess.str_of(name)))]); + ~[path_name((ccx.names)( + copy *ccx.sess.str_of(name)))]); let s = mangle_exported_name(ccx, /*bad*/copy pt, mono_ty); let mk_lldecl = || { @@ -322,10 +323,10 @@ pub fn normalize_for_monomorphization(tcx: ty::ctxt, } } -pub fn make_mono_id(ccx: @CrateContext, item: ast::def_id, substs: ~[ty::t], +pub fn make_mono_id(ccx: @CrateContext, item: ast::def_id, substs: &[ty::t], vtables: Option, impl_did_opt: Option, - param_uses: Option<~[type_use::type_uses]>) -> mono_id { + +param_uses: Option<~[type_use::type_uses]>) -> mono_id { let precise_param_ids = match vtables { Some(vts) => { let bounds = ty::lookup_item_type(ccx.tcx, item).bounds; diff --git a/src/librustc/middle/trans/type_of.rs b/src/librustc/middle/trans/type_of.rs index b8bca3e8346e3..26cf91b03e145 100644 --- a/src/librustc/middle/trans/type_of.rs +++ b/src/librustc/middle/trans/type_of.rs @@ -360,7 +360,7 @@ pub enum named_ty { a_struct, an_enum } pub fn llvm_type_name(cx: @CrateContext, what: named_ty, did: ast::def_id, - tps: ~[ty::t]) -> ~str { + tps: &[ty::t]) -> ~str { let name = match what { a_struct => { "~struct" } an_enum => { "~enum" }