Skip to content

Commit f1a8b58

Browse files
committed
rustc: De-mode some bits of trans
1 parent 4b79a58 commit f1a8b58

File tree

9 files changed

+61
-63
lines changed

9 files changed

+61
-63
lines changed

src/librustc/middle/trans/base.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ pub fn get_extern_const(externs: ExternMap, llmod: ModuleRef,
197197
}
198198

199199
pub fn trans_foreign_call(cx: block, externs: ExternMap,
200-
llmod: ModuleRef, name: @str, args: ~[ValueRef]) ->
200+
llmod: ModuleRef, name: @str, args: &[ValueRef]) ->
201201
ValueRef {
202202
let _icx = cx.insn_ctxt("trans_foreign_call");
203203
let n = args.len() as int;
@@ -242,7 +242,7 @@ pub fn bump_ptr(bcx: block, t: ty::t, base: ValueRef, sz: ValueRef) ->
242242
// @llblobptr is the data part of a enum value; its actual type
243243
// is meaningless, as it will be cast away.
244244
pub fn GEP_enum(bcx: block, llblobptr: ValueRef, enum_id: ast::def_id,
245-
variant_id: ast::def_id, ty_substs: ~[ty::t],
245+
variant_id: ast::def_id, ty_substs: &[ty::t],
246246
ix: uint) -> ValueRef {
247247
let _icx = bcx.insn_ctxt("GEP_enum");
248248
let ccx = bcx.ccx();
@@ -449,7 +449,7 @@ pub fn set_inline_hint(f: ValueRef) {
449449
}
450450
}
451451

452-
pub fn set_inline_hint_if_appr(attrs: ~[ast::attribute],
452+
pub fn set_inline_hint_if_appr(attrs: &[ast::attribute],
453453
llfn: ValueRef) {
454454
match attr::find_inline_attr(attrs) {
455455
attr::ia_hint => set_inline_hint(llfn),
@@ -489,7 +489,7 @@ pub fn note_unique_llvm_symbol(ccx: @CrateContext, +sym: ~str) {
489489
490490
491491
pub fn get_res_dtor(ccx: @CrateContext, did: ast::def_id,
492-
parent_id: ast::def_id, substs: ~[ty::t])
492+
parent_id: ast::def_id, substs: &[ty::t])
493493
-> ValueRef {
494494
let _icx = ccx.insn_ctxt("trans_res_dtor");
495495
if !substs.is_empty() {
@@ -516,7 +516,7 @@ pub fn get_res_dtor(ccx: @CrateContext, did: ast::def_id,
516516
}
517517

518518
// Structural comparison: a rather involved form of glue.
519-
pub fn maybe_name_value(cx: @CrateContext, v: ValueRef, s: ~str) {
519+
pub fn maybe_name_value(cx: @CrateContext, v: ValueRef, s: &str) {
520520
if cx.sess.opts.save_temps {
521521
let _: () = str::as_c_str(s, |buf| {
522522
unsafe {
@@ -641,7 +641,7 @@ pub fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
641641

642642
fn iter_variant(cx: block, a_tup: ValueRef,
643643
variant: ty::VariantInfo,
644-
tps: ~[ty::t], tid: ast::def_id,
644+
tps: &[ty::t], tid: ast::def_id,
645645
f: val_and_ty_fn) -> block {
646646
let _icx = cx.insn_ctxt("iter_variant");
647647
if variant.args.len() == 0u { return cx; }
@@ -916,7 +916,7 @@ pub fn have_cached_lpad(bcx: block) -> bool {
916916
return res;
917917
}
918918

919-
pub fn in_lpad_scope_cx(bcx: block, f: fn(&mut scope_info)) {
919+
pub fn in_lpad_scope_cx(bcx: block, f: fn(+si: &mut scope_info)) {
920920
let mut bcx = bcx;
921921
loop {
922922
{
@@ -1652,7 +1652,7 @@ pub fn new_fn_ctxt(ccx: @CrateContext,
16521652
// field of the fn_ctxt with
16531653
pub fn create_llargs_for_fn_args(cx: fn_ctxt,
16541654
ty_self: self_arg,
1655-
args: ~[ast::arg]) -> ~[ValueRef] {
1655+
args: &[ast::arg]) -> ~[ValueRef] {
16561656
let _icx = cx.insn_ctxt("create_llargs_for_fn_args");
16571657

16581658
match ty_self {
@@ -1865,7 +1865,7 @@ pub fn trans_fn(ccx: @CrateContext,
18651865
debug!("trans_fn(ty_self=%?)", ty_self);
18661866
let _icx = ccx.insn_ctxt("trans_fn");
18671867
ccx.stats.n_fns += 1;
1868-
let the_path_str = path_str(ccx.sess, path);
1868+
let the_path_str = path_str(ccx.sess, &path);
18691869
trans_closure(ccx, path, decl, body, llfndecl, ty_self,
18701870
param_substs, id, impl_id,
18711871
|fcx| {
@@ -1883,7 +1883,7 @@ pub fn trans_fn(ccx: @CrateContext,
18831883
pub fn trans_enum_variant(ccx: @CrateContext,
18841884
enum_id: ast::node_id,
18851885
variant: ast::variant,
1886-
args: ~[ast::variant_arg],
1886+
args: &[ast::variant_arg],
18871887
disr: int,
18881888
is_degen: bool,
18891889
param_substs: Option<@param_substs>,
@@ -1946,7 +1946,7 @@ pub fn trans_enum_variant(ccx: @CrateContext,
19461946
// NB: In theory this should be merged with the function above. But the AST
19471947
// structures are completely different, so very little code would be shared.
19481948
pub fn trans_tuple_struct(ccx: @CrateContext,
1949-
fields: ~[@ast::struct_field],
1949+
fields: &[@ast::struct_field],
19501950
ctor_id: ast::node_id,
19511951
param_substs: Option<@param_substs>,
19521952
llfndecl: ValueRef) {
@@ -2847,7 +2847,7 @@ pub fn trap(bcx: block) {
28472847
}
28482848
}
28492849
2850-
pub fn decl_gc_metadata(ccx: @CrateContext, llmod_id: ~str) {
2850+
pub fn decl_gc_metadata(ccx: @CrateContext, llmod_id: &str) {
28512851
if !ccx.sess.opts.gc || !*ccx.uses_gc {
28522852
return;
28532853
}
@@ -3014,7 +3014,7 @@ pub fn trans_crate(sess: session::Session,
30143014
tcx: ty::ctxt,
30153015
output: &Path,
30163016
emap2: resolve::ExportMap2,
3017-
maps: astencode::Maps) -> (ModuleRef, LinkMeta) {
3017+
+maps: astencode::Maps) -> (ModuleRef, LinkMeta) {
30183018
30193019
let symbol_hasher = @hash::default_state();
30203020
let link_meta =

src/librustc/middle/trans/build.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub fn Ret(cx: block, V: ValueRef) {
117117
}
118118
}
119119
120-
pub fn AggregateRet(cx: block, RetVals: ~[ValueRef]) {
120+
pub fn AggregateRet(cx: block, RetVals: &[ValueRef]) {
121121
if cx.unreachable { return; }
122122
check_not_terminated(cx);
123123
terminate(cx, "AggregateRet");
@@ -184,7 +184,7 @@ pub fn noname() -> *libc::c_char {
184184
}
185185
}
186186
187-
pub fn Invoke(cx: block, Fn: ValueRef, Args: ~[ValueRef],
187+
pub fn Invoke(cx: block, Fn: ValueRef, Args: &[ValueRef],
188188
Then: BasicBlockRef, Catch: BasicBlockRef) {
189189
if cx.unreachable { return; }
190190
check_not_terminated(cx);
@@ -202,7 +202,7 @@ pub fn Invoke(cx: block, Fn: ValueRef, Args: ~[ValueRef],
202202
}
203203
}
204204
205-
pub fn FastInvoke(cx: block, Fn: ValueRef, Args: ~[ValueRef],
205+
pub fn FastInvoke(cx: block, Fn: ValueRef, Args: &[ValueRef],
206206
Then: BasicBlockRef, Catch: BasicBlockRef) {
207207
if cx.unreachable { return; }
208208
check_not_terminated(cx);
@@ -567,7 +567,7 @@ pub fn Store(cx: block, Val: ValueRef, Ptr: ValueRef) {
567567
}
568568
}
569569
570-
pub fn GEP(cx: block, Pointer: ValueRef, Indices: ~[ValueRef]) -> ValueRef {
570+
pub fn GEP(cx: block, Pointer: ValueRef, Indices: &[ValueRef]) -> ValueRef {
571571
unsafe {
572572
if cx.unreachable { return llvm::LLVMGetUndef(T_ptr(T_nil())); }
573573
count_insn(cx, "gep");
@@ -810,7 +810,7 @@ pub fn EmptyPhi(cx: block, Ty: TypeRef) -> ValueRef {
810810
}
811811
}
812812
813-
pub fn Phi(cx: block, Ty: TypeRef, vals: ~[ValueRef], bbs: ~[BasicBlockRef])
813+
pub fn Phi(cx: block, Ty: TypeRef, vals: &[ValueRef], bbs: &[BasicBlockRef])
814814
-> ValueRef {
815815
unsafe {
816816
if cx.unreachable { return llvm::LLVMGetUndef(Ty); }
@@ -844,11 +844,10 @@ pub fn _UndefReturn(cx: block, Fn: ValueRef) -> ValueRef {
844844
}
845845
}
846846
847-
pub fn add_span_comment(bcx: block, sp: span, text: ~str) {
847+
pub fn add_span_comment(bcx: block, sp: span, text: &str) {
848848
let ccx = bcx.ccx();
849849
if !ccx.sess.no_asm_comments() {
850-
let s = text + ~" (" + ccx.sess.codemap.span_to_str(sp)
851-
+ ~")";
850+
let s = fmt!("%s (%s)", text, ccx.sess.codemap.span_to_str(sp));
852851
log(debug, copy s);
853852
add_comment(bcx, s);
854853
}
@@ -888,7 +887,7 @@ pub fn Call(cx: block, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef {
888887
}
889888
}
890889
891-
pub fn FastCall(cx: block, Fn: ValueRef, Args: ~[ValueRef]) -> ValueRef {
890+
pub fn FastCall(cx: block, Fn: ValueRef, Args: &[ValueRef]) -> ValueRef {
892891
if cx.unreachable { return _UndefReturn(cx, Fn); }
893892
unsafe {
894893
count_insn(cx, "fastcall");
@@ -899,7 +898,7 @@ pub fn FastCall(cx: block, Fn: ValueRef, Args: ~[ValueRef]) -> ValueRef {
899898
}
900899
}
901900
902-
pub fn CallWithConv(cx: block, Fn: ValueRef, Args: ~[ValueRef],
901+
pub fn CallWithConv(cx: block, Fn: ValueRef, Args: &[ValueRef],
903902
Conv: CallConv) -> ValueRef {
904903
if cx.unreachable { return _UndefReturn(cx, Fn); }
905904
unsafe {

src/librustc/middle/trans/callee.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pub fn trans_fn_ref_with_vtables_to_callee(
187187
bcx: block,
188188
def_id: ast::def_id,
189189
ref_id: ast::node_id,
190-
+type_params: ~[ty::t],
190+
type_params: &[ty::t],
191191
vtables: Option<typeck::vtable_res>)
192192
-> Callee {
193193
Callee {bcx: bcx,
@@ -199,7 +199,7 @@ pub fn trans_fn_ref_with_vtables(
199199
bcx: block, //
200200
def_id: ast::def_id, // def id of fn
201201
ref_id: ast::node_id, // node id of use of fn; may be zero if N/A
202-
+type_params: ~[ty::t], // values for fn's ty params
202+
type_params: &[ty::t], // values for fn's ty params
203203
vtables: Option<typeck::vtable_res>)
204204
-> FnData {
205205
//!
@@ -378,7 +378,7 @@ pub fn trans_lang_call(bcx: block,
378378
pub fn trans_lang_call_with_type_params(bcx: block,
379379
did: ast::def_id,
380380
args: &[ValueRef],
381-
type_params: ~[ty::t],
381+
type_params: &[ty::t],
382382
dest: expr::Dest)
383383
-> block {
384384
let fty;
@@ -394,7 +394,7 @@ pub fn trans_lang_call_with_type_params(bcx: block,
394394
|bcx| {
395395
let callee =
396396
trans_fn_ref_with_vtables_to_callee(bcx, did, 0,
397-
copy type_params,
397+
type_params,
398398
None);
399399

400400
let new_llval;
@@ -636,8 +636,8 @@ pub enum AutorefArg {
636636
pub fn trans_arg_expr(bcx: block,
637637
formal_ty: ty::arg,
638638
arg_expr: @ast::expr,
639-
temp_cleanups: &mut ~[ValueRef],
640-
ret_flag: Option<ValueRef>,
639+
+temp_cleanups: &mut ~[ValueRef],
640+
+ret_flag: Option<ValueRef>,
641641
+autoref_arg: AutorefArg) -> Result {
642642
let _icx = bcx.insn_ctxt("trans_arg_expr");
643643
let ccx = bcx.ccx();

src/librustc/middle/trans/common.rs

+19-20
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,12 @@ use syntax::codemap::span;
5757
use syntax::parse::token::ident_interner;
5858
use syntax::{ast, ast_map};
5959

60-
pub type namegen = @fn(~str) -> ident;
60+
pub type namegen = @fn(+s: ~str) -> ident;
6161
pub fn new_namegen(intr: @ident_interner) -> namegen {
62-
let f: @fn(~str) -> ident = |prefix| {
63-
// XXX: Bad copies.
62+
let f: @fn(+s: ~str) -> ident = |prefix| {
6463
intr.gensym(@fmt!("%s_%u",
6564
prefix,
66-
intr.gensym(@copy prefix).repr))
65+
intr.gensym(@prefix).repr))
6766
};
6867
f
6968
}
@@ -325,10 +324,10 @@ pub struct fn_ctxt_ {
325324

326325
pub type fn_ctxt = @mut fn_ctxt_;
327326

328-
pub fn warn_not_to_commit(ccx: @CrateContext, msg: ~str) {
327+
pub fn warn_not_to_commit(ccx: @CrateContext, msg: &str) {
329328
if !*ccx.do_not_commit_warning_issued {
330329
*ccx.do_not_commit_warning_issued = true;
331-
ccx.sess.warn(msg + ~" -- do not commit like this!");
330+
ccx.sess.warn(msg.to_str() + ~" -- do not commit like this!");
332331
}
333332
}
334333
@@ -358,7 +357,7 @@ pub struct cleanup_path {
358357
dest: BasicBlockRef
359358
}
360359
361-
pub fn scope_clean_changed(scope_info: &mut scope_info) {
360+
pub fn scope_clean_changed(+scope_info: &mut scope_info) {
362361
if scope_info.cleanup_paths.len() > 0u { scope_info.cleanup_paths = ~[]; }
363362
scope_info.landing_pad = None;
364363
}
@@ -625,7 +624,7 @@ pub fn rslt(bcx: block, val: ValueRef) -> Result {
625624
}
626625

627626
pub impl Result {
628-
fn unpack(&self, bcx: &mut block) -> ValueRef {
627+
fn unpack(&self, +bcx: &mut block) -> ValueRef {
629628
*bcx = self.bcx;
630629
return self.val;
631630
}
@@ -645,7 +644,7 @@ pub fn val_str(tn: @TypeNames, v: ValueRef) -> @str {
645644
return ty_str(tn, val_ty(v));
646645
}
647646

648-
pub fn in_scope_cx(cx: block, f: &fn(&mut scope_info)) {
647+
pub fn in_scope_cx(cx: block, f: &fn(+si: &mut scope_info)) {
649648
let mut cur = cx;
650649
loop {
651650
{
@@ -811,7 +810,7 @@ pub fn T_size_t(targ_cfg: @session::config) -> TypeRef {
811810
return T_int(targ_cfg);
812811
}
813812

814-
pub fn T_fn(inputs: ~[TypeRef], output: TypeRef) -> TypeRef {
813+
pub fn T_fn(inputs: &[TypeRef], output: TypeRef) -> TypeRef {
815814
unsafe {
816815
return llvm::LLVMFunctionType(output, to_ptr(inputs),
817816
inputs.len() as c_uint,
@@ -835,22 +834,22 @@ pub fn T_root(t: TypeRef, addrspace: addrspace) -> TypeRef {
835834
}
836835
}
837836

838-
pub fn T_struct(elts: ~[TypeRef]) -> TypeRef {
837+
pub fn T_struct(elts: &[TypeRef]) -> TypeRef {
839838
unsafe {
840839
return llvm::LLVMStructType(to_ptr(elts),
841840
elts.len() as c_uint,
842841
False);
843842
}
844843
}
845844

846-
pub fn T_named_struct(name: ~str) -> TypeRef {
845+
pub fn T_named_struct(name: &str) -> TypeRef {
847846
unsafe {
848847
let c = llvm::LLVMGetGlobalContext();
849848
return str::as_c_str(name, |buf| llvm::LLVMStructCreateNamed(c, buf));
850849
}
851850
}
852851

853-
pub fn set_struct_body(t: TypeRef, elts: ~[TypeRef]) {
852+
pub fn set_struct_body(t: TypeRef, elts: &[TypeRef]) {
854853
unsafe {
855854
llvm::LLVMStructSetBody(t,
856855
to_ptr(elts),
@@ -1094,7 +1093,7 @@ pub fn C_integral(t: TypeRef, u: u64, sign_extend: Bool) -> ValueRef {
10941093
}
10951094
}
10961095

1097-
pub fn C_floating(s: ~str, t: TypeRef) -> ValueRef {
1096+
pub fn C_floating(s: &str, t: TypeRef) -> ValueRef {
10981097
unsafe {
10991098
return str::as_c_str(s, |buf| llvm::LLVMConstRealOfString(t, buf));
11001099
}
@@ -1169,7 +1168,7 @@ pub fn C_estr_slice(cx: @CrateContext, s: @~str) -> ValueRef {
11691168
}
11701169
11711170
// Returns a Plain Old LLVM String:
1172-
pub fn C_postr(s: ~str) -> ValueRef {
1171+
pub fn C_postr(s: &str) -> ValueRef {
11731172
unsafe {
11741173
return do str::as_c_str(s) |buf| {
11751174
llvm::LLVMConstString(buf, str::len(s) as c_uint, False)
@@ -1212,22 +1211,22 @@ pub fn C_named_struct(T: TypeRef, elts: &[ValueRef]) -> ValueRef {
12121211
}
12131212
}
12141213
1215-
pub fn C_array(ty: TypeRef, elts: ~[ValueRef]) -> ValueRef {
1214+
pub fn C_array(ty: TypeRef, elts: &[ValueRef]) -> ValueRef {
12161215
unsafe {
12171216
return llvm::LLVMConstArray(ty, vec::raw::to_ptr(elts),
12181217
elts.len() as c_uint);
12191218
}
12201219
}
12211220
1222-
pub fn C_bytes(bytes: ~[u8]) -> ValueRef {
1221+
pub fn C_bytes(bytes: &[u8]) -> ValueRef {
12231222
unsafe {
12241223
return llvm::LLVMConstString(
12251224
cast::reinterpret_cast(&vec::raw::to_ptr(bytes)),
12261225
bytes.len() as c_uint, True);
12271226
}
12281227
}
12291228
1230-
pub fn C_bytes_plus_null(bytes: ~[u8]) -> ValueRef {
1229+
pub fn C_bytes_plus_null(bytes: &[u8]) -> ValueRef {
12311230
unsafe {
12321231
return llvm::LLVMConstString(
12331232
cast::reinterpret_cast(&vec::raw::to_ptr(bytes)),
@@ -1311,9 +1310,9 @@ pub fn align_to(cx: block, off: ValueRef, align: ValueRef) -> ValueRef {
13111310
return build::And(cx, bumped, build::Not(cx, mask));
13121311
}
13131312
1314-
pub fn path_str(sess: session::Session, p: path) -> ~str {
1313+
pub fn path_str(sess: session::Session, p: &path) -> ~str {
13151314
let mut r = ~"", first = true;
1316-
for vec::each(p) |e| {
1315+
for vec::each(*p) |e| {
13171316
match *e {
13181317
ast_map::path_name(s) | ast_map::path_mod(s) => {
13191318
if first { first = false; }

0 commit comments

Comments
 (0)