Skip to content

Commit 53f41f0

Browse files
committed
librustc: Make vectors no longer implicitly copyable in rustc. r=graydon
~20% perf win for trans on -O0, with other minor improvements across the board. No effect on -O2.
1 parent 09758f7 commit 53f41f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+1216
-867
lines changed

src/librustc/back/link.rs

+43-29
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
1112
use back::rpath;
1213
use driver::session;
1314
use lib::llvm::llvm;
@@ -56,11 +57,13 @@ impl output_type : cmp::Eq {
5657
pure fn ne(&self, other: &output_type) -> bool { !(*self).eq(other) }
5758
}
5859

59-
fn llvm_err(sess: Session, msg: ~str) -> ! unsafe {
60+
fn llvm_err(sess: Session, +msg: ~str) -> ! unsafe {
6061
let cstr = llvm::LLVMRustGetLastError();
6162
if cstr == ptr::null() {
6263
sess.fatal(msg);
63-
} else { sess.fatal(msg + ~": " + str::raw::from_c_str(cstr)); }
64+
} else {
65+
sess.fatal(msg + ~": " + str::raw::from_c_str(cstr));
66+
}
6467
}
6568
6669
fn WriteOutputFile(sess: Session,
@@ -147,7 +150,7 @@ pub mod jit {
147150
};
148151
let func: fn(++argv: ~[~str]) = cast::transmute(move closure);
149152

150-
func(~[sess.opts.binary]);
153+
func(~[/*bad*/copy sess.opts.binary]);
151154
}
152155
}
153156
}
@@ -177,7 +180,7 @@ mod write {
177180
if sess.time_llvm_passes() { llvm::LLVMRustEnableTimePasses(); }
178181
let mut pm = mk_pass_manager();
179182
let td = mk_target_data(
180-
sess.targ_cfg.target_strs.data_layout);
183+
/*bad*/copy sess.targ_cfg.target_strs.data_layout);
181184
llvm::LLVMAddTargetData(td.lltd, pm.llpm);
182185
// FIXME (#2812): run the linter here also, once there are llvm-c
183186
// bindings for it.
@@ -438,17 +441,19 @@ fn build_link_meta(sess: Session, c: ast::crate, output: &Path,
438441
let mut name: Option<~str> = None;
439442
let mut vers: Option<~str> = None;
440443
let mut cmh_items: ~[@ast::meta_item] = ~[];
441-
let linkage_metas = attr::find_linkage_metas(c.node.attrs);
442-
attr::require_unique_names(sess.diagnostic(), linkage_metas);
444+
let linkage_metas =
445+
attr::find_linkage_metas(/*bad*/copy c.node.attrs);
446+
// XXX: Bad copy.
447+
attr::require_unique_names(sess.diagnostic(), copy linkage_metas);
443448
for linkage_metas.each |meta| {
444449
if attr::get_meta_item_name(*meta) == ~"name" {
445450
match attr::get_meta_item_value_str(*meta) {
446-
Some(ref v) => { name = Some((*v)); }
451+
Some(ref v) => { name = Some((/*bad*/copy *v)); }
447452
None => cmh_items.push(*meta)
448453
}
449454
} else if attr::get_meta_item_name(*meta) == ~"vers" {
450455
match attr::get_meta_item_value_str(*meta) {
451-
Some(ref v) => { vers = Some((*v)); }
456+
Some(ref v) => { vers = Some((/*bad*/copy *v)); }
452457
None => cmh_items.push(*meta)
453458
}
454459
} else { cmh_items.push(*meta); }
@@ -469,7 +474,7 @@ fn build_link_meta(sess: Session, c: ast::crate, output: &Path,
469474
return len_and_str(pprust::lit_to_str(@l));
470475
}
471476

472-
let cmh_items = attr::sort_meta_items(metas.cmh_items);
477+
let cmh_items = attr::sort_meta_items(/*bad*/copy metas.cmh_items);
473478

474479
symbol_hasher.reset();
475480
for cmh_items.each |m| {
@@ -504,15 +509,16 @@ fn build_link_meta(sess: Session, c: ast::crate, output: &Path,
504509
fn crate_meta_name(sess: Session, _crate: ast::crate,
505510
output: &Path, metas: provided_metas) -> ~str {
506511
return match metas.name {
507-
Some(ref v) => (*v),
512+
Some(ref v) => (/*bad*/copy *v),
508513
None => {
509514
let name = match output.filestem() {
510515
None => sess.fatal(fmt!("output file name `%s` doesn't\
511516
appear to have a stem",
512517
output.to_str())),
513-
Some(ref s) => (*s)
518+
Some(ref s) => (/*bad*/copy *s)
514519
};
515-
warn_missing(sess, ~"name", name);
520+
// XXX: Bad copy.
521+
warn_missing(sess, ~"name", copy name);
516522
name
517523
}
518524
};
@@ -521,10 +527,11 @@ fn build_link_meta(sess: Session, c: ast::crate, output: &Path,
521527
fn crate_meta_vers(sess: Session, _crate: ast::crate,
522528
metas: provided_metas) -> ~str {
523529
return match metas.vers {
524-
Some(ref v) => (*v),
530+
Some(ref v) => (/*bad*/copy *v),
525531
None => {
526532
let vers = ~"0.0";
527-
warn_missing(sess, ~"vers", vers);
533+
// Bad copy.
534+
warn_missing(sess, ~"vers", copy vers);
528535
vers
529536
}
530537
};
@@ -565,10 +572,11 @@ fn symbol_hash(tcx: ty::ctxt, symbol_hasher: &hash::State, t: ty::t,
565572

566573
fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> ~str {
567574
match ccx.type_hashcodes.find(t) {
568-
Some(ref h) => return (*h),
575+
Some(ref h) => return (/*bad*/copy *h),
569576
None => {
570577
let hash = symbol_hash(ccx.tcx, ccx.symbol_hasher, t, ccx.link_meta);
571-
ccx.type_hashcodes.insert(t, hash);
578+
// XXX: Bad copy. Prefer `@str`?
579+
ccx.type_hashcodes.insert(t, copy hash);
572580
return hash;
573581
}
574582
}
@@ -625,21 +633,26 @@ fn mangle(sess: Session, ss: path) -> ~str {
625633
n
626634
}
627635

628-
fn exported_name(sess: Session, path: path, hash: ~str, vers: ~str) -> ~str {
636+
fn exported_name(sess: Session,
637+
+path: path,
638+
+hash: ~str,
639+
+vers: ~str) -> ~str {
629640
return mangle(sess,
630641
vec::append_one(
631642
vec::append_one(path, path_name(sess.ident_of(hash))),
632643
path_name(sess.ident_of(vers))));
633644
}
634645

635-
fn mangle_exported_name(ccx: @crate_ctxt, path: path, t: ty::t) -> ~str {
646+
fn mangle_exported_name(ccx: @crate_ctxt, +path: path, t: ty::t) -> ~str {
636647
let hash = get_symbol_hash(ccx, t);
637-
return exported_name(ccx.sess, path, hash, ccx.link_meta.vers);
648+
return exported_name(ccx.sess, path,
649+
hash,
650+
/*bad*/copy ccx.link_meta.vers);
638651
}
639652

640653
fn mangle_internal_name_by_type_only(ccx: @crate_ctxt,
641-
t: ty::t, name: ~str) ->
642-
~str {
654+
t: ty::t,
655+
+name: ~str) -> ~str {
643656
let s = ppaux::ty_to_short_str(ccx.tcx, t);
644657
let hash = get_symbol_hash(ccx, t);
645658
return mangle(ccx.sess,
@@ -648,17 +661,18 @@ fn mangle_internal_name_by_type_only(ccx: @crate_ctxt,
648661
path_name(ccx.sess.ident_of(hash))]);
649662
}
650663

651-
fn mangle_internal_name_by_path_and_seq(ccx: @crate_ctxt, path: path,
652-
flav: ~str) -> ~str {
664+
fn mangle_internal_name_by_path_and_seq(ccx: @crate_ctxt,
665+
+path: path,
666+
+flav: ~str) -> ~str {
653667
return mangle(ccx.sess,
654668
vec::append_one(path, path_name((ccx.names)(flav))));
655669
}
656670

657-
fn mangle_internal_name_by_path(ccx: @crate_ctxt, path: path) -> ~str {
671+
fn mangle_internal_name_by_path(ccx: @crate_ctxt, +path: path) -> ~str {
658672
return mangle(ccx.sess, path);
659673
}
660674

661-
fn mangle_internal_name_by_seq(ccx: @crate_ctxt, flav: ~str) -> ~str {
675+
fn mangle_internal_name_by_seq(ccx: @crate_ctxt, +flav: ~str) -> ~str {
662676
return fmt!("%s_%u", flav, (ccx.names)(flav).repr);
663677
}
664678

@@ -669,7 +683,7 @@ fn link_binary(sess: Session,
669683
out_filename: &Path,
670684
lm: link_meta) {
671685
// Converts a library file-stem into a cc -l argument
672-
fn unlib(config: @session::config, stem: ~str) -> ~str {
686+
fn unlib(config: @session::config, +stem: ~str) -> ~str {
673687
if stem.starts_with("lib") &&
674688
config.os != session::os_win32 {
675689
stem.slice(3, stem.len())
@@ -689,7 +703,7 @@ fn link_binary(sess: Session,
689703

690704
out_filename.dir_path().push(long_libname)
691705
} else {
692-
*out_filename
706+
/*bad*/copy *out_filename
693707
};
694708

695709
log(debug, ~"output: " + output.to_str());
@@ -736,7 +750,7 @@ fn link_binary(sess: Session,
736750
}
737751

738752
let ula = cstore::get_used_link_args(cstore);
739-
for ula.each |arg| { cc_args.push(*arg); }
753+
for ula.each |arg| { cc_args.push(/*bad*/copy *arg); }
740754

741755
// # Extern library linking
742756

@@ -746,7 +760,7 @@ fn link_binary(sess: Session,
746760
// to be found at compile time so it is still entirely up to outside
747761
// forces to make sure that library can be found at runtime.
748762

749-
let addl_paths = sess.opts.addl_lib_search_paths;
763+
let addl_paths = /*bad*/copy sess.opts.addl_lib_search_paths;
750764
for addl_paths.each |path| { cc_args.push(~"-L" + path.to_str()); }
751765

752766
// The names of the extern libraries

src/librustc/back/rpath.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
1112
use driver::session;
1213
use metadata::cstore;
1314
use metadata::filesearch;
@@ -45,7 +46,7 @@ fn get_rpath_flags(sess: session::Session, out_filename: &Path) -> ~[~str] {
4546
// where rustrt is and we know every rust program needs it
4647
let libs = vec::append_one(libs, get_sysroot_absolute_rt_lib(sess));
4748

48-
let target_triple = sess.opts.target_triple;
49+
let target_triple = /*bad*/copy sess.opts.target_triple;
4950
let rpaths = get_rpaths(os, &sysroot, output, libs, target_triple);
5051
rpaths_to_flags(rpaths)
5152
}
@@ -139,8 +140,8 @@ fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
139140
let abs2 = abs2.normalize();
140141
debug!("finding relative path from %s to %s",
141142
abs1.to_str(), abs2.to_str());
142-
let split1 = abs1.components;
143-
let split2 = abs2.components;
143+
let split1 = /*bad*/copy abs1.components;
144+
let split2 = /*bad*/copy abs2.components;
144145
let len1 = vec::len(split1);
145146
let len2 = vec::len(split2);
146147
assert len1 > 0;
@@ -190,7 +191,7 @@ fn minimize_rpaths(rpaths: &[Path]) -> ~[Path] {
190191
for rpaths.each |rpath| {
191192
let s = rpath.to_str();
192193
if !set.contains_key(s) {
193-
minimized.push(*rpath);
194+
minimized.push(/*bad*/copy *rpath);
194195
set.insert(s, ());
195196
}
196197
}

src/librustc/back/target_strs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
1112
type t = {
1213
module_asm: ~str,
1314
meta_sect_name: ~str,

src/librustc/back/upcall.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ fn declare_upcalls(targ_cfg: @session::config,
3636
fn nothrow(f: ValueRef) -> ValueRef {
3737
base::set_no_unwind(f); f
3838
}
39-
let d = |a,b,c| decl(llmod, ~"upcall_", a, b, c);
40-
let dv = |a,b| decl(llmod, ~"upcall_", a, b, T_void());
39+
let d: &fn(+a: ~str, +b: ~[TypeRef], +c: TypeRef) -> ValueRef =
40+
|a,b,c| decl(llmod, ~"upcall_", a, b, c);
41+
let dv: &fn(+a: ~str, +b: ~[TypeRef]) -> ValueRef =
42+
|a,b| decl(llmod, ~"upcall_", a, b, T_void());
4143

4244
let int_t = T_int(targ_cfg);
4345

src/librustc/back/x86.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
1112
use back::target_strs;
1213
use driver::session;
1314
use metadata::loader::meta_section_name;

src/librustc/back/x86_64.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
1112
use back::target_strs;
1213
use driver::session;
1314
use metadata::loader::meta_section_name;

0 commit comments

Comments
 (0)