1
Fork 0

rustc: Anti-copy police

In this case, some copies are still necessary to convert from
a mutable to an immutable @-box. It's still an improvement,
I hope.
This commit is contained in:
Tim Chevalier 2013-04-16 17:30:31 -07:00
parent 18db9a2954
commit 3d43af15d8
8 changed files with 33 additions and 32 deletions

View file

@ -898,9 +898,9 @@ mod test {
getopts::fail_str(f)) getopts::fail_str(f))
}; };
let sessopts = build_session_options( let sessopts = build_session_options(
~"rustc", matches, diagnostic::emit); @~"rustc", matches, diagnostic::emit);
let sess = build_session(sessopts, diagnostic::emit); let sess = build_session(sessopts, diagnostic::emit);
let cfg = build_configuration(sess, ~"whatever", str_input(~"")); let cfg = build_configuration(sess, @~"whatever", str_input(~""));
assert!((attr::contains_name(cfg, ~"test"))); assert!((attr::contains_name(cfg, ~"test")));
} }
@ -917,9 +917,9 @@ mod test {
} }
}; };
let sessopts = build_session_options( let sessopts = build_session_options(
~"rustc", matches, diagnostic::emit); @~"rustc", matches, diagnostic::emit);
let sess = build_session(sessopts, diagnostic::emit); let sess = build_session(sessopts, diagnostic::emit);
let cfg = build_configuration(sess, ~"whatever", str_input(~"")); let cfg = build_configuration(sess, @~"whatever", str_input(~""));
let test_items = attr::find_meta_items_by_name(cfg, ~"test"); let test_items = attr::find_meta_items_by_name(cfg, ~"test");
assert!((vec::len(test_items) == 1u)); assert!((vec::len(test_items) == 1u));
} }

View file

@ -184,7 +184,7 @@ pub struct CrateContext {
monomorphized: @mut HashMap<mono_id, ValueRef>, monomorphized: @mut HashMap<mono_id, ValueRef>,
monomorphizing: @mut HashMap<ast::def_id, uint>, monomorphizing: @mut HashMap<ast::def_id, uint>,
// Cache computed type parameter uses (see type_use.rs) // Cache computed type parameter uses (see type_use.rs)
type_use_cache: @mut HashMap<ast::def_id, ~[type_use::type_uses]>, type_use_cache: @mut HashMap<ast::def_id, @~[type_use::type_uses]>,
// Cache generated vtables // Cache generated vtables
vtables: @mut HashMap<mono_id, ValueRef>, vtables: @mut HashMap<mono_id, ValueRef>,
// Cache of constant strings, // Cache of constant strings,

View file

@ -342,7 +342,7 @@ pub fn make_mono_id(ccx: @CrateContext,
substs: &[ty::t], substs: &[ty::t],
vtables: Option<typeck::vtable_res>, vtables: Option<typeck::vtable_res>,
impl_did_opt: Option<ast::def_id>, impl_did_opt: Option<ast::def_id>,
+param_uses: Option<~[type_use::type_uses]>) -> mono_id { param_uses: Option<@~[type_use::type_uses]>) -> mono_id {
let precise_param_ids = match vtables { let precise_param_ids = match vtables {
Some(vts) => { Some(vts) => {
let item_ty = ty::lookup_item_type(ccx.tcx, item); let item_ty = ty::lookup_item_type(ccx.tcx, item);
@ -353,12 +353,12 @@ pub fn make_mono_id(ccx: @CrateContext,
match *bound { match *bound {
ty::bound_trait(_) => { ty::bound_trait(_) => {
v.push(meth::vtable_id(ccx, /*bad*/copy vts[i])); v.push(meth::vtable_id(ccx, /*bad*/copy vts[i]));
i += 1u; i += 1;
} }
_ => () _ => ()
} }
} }
(*subst, if v.len() > 0u { Some(v) } else { None }) (*subst, if !v.is_empty() { Some(v) } else { None })
}) })
} }
None => { None => {
@ -367,7 +367,7 @@ pub fn make_mono_id(ccx: @CrateContext,
}; };
let param_ids = match param_uses { let param_ids = match param_uses {
Some(ref uses) => { Some(ref uses) => {
vec::map2(precise_param_ids, *uses, |id, uses| { vec::map2(precise_param_ids, **uses, |id, uses| {
if ccx.sess.no_monomorphic_collapse() { if ccx.sess.no_monomorphic_collapse() {
match copy *id { match copy *id {
(a, b) => mono_precise(a, b) (a, b) => mono_precise(a, b)
@ -377,7 +377,7 @@ pub fn make_mono_id(ccx: @CrateContext,
// XXX: Bad copy. // XXX: Bad copy.
(a, copy b@Some(_)) => mono_precise(a, b), (a, copy b@Some(_)) => mono_precise(a, b),
(subst, None) => { (subst, None) => {
if *uses == 0u { if *uses == 0 {
mono_any mono_any
} else if *uses == type_use::use_repr && } else if *uses == type_use::use_repr &&
!ty::type_needs_drop(ccx.tcx, subst) !ty::type_needs_drop(ccx.tcx, subst)

View file

@ -47,9 +47,9 @@ use syntax::ast_util;
use syntax::visit; use syntax::visit;
pub type type_uses = uint; // Bitmask pub type type_uses = uint; // Bitmask
pub static use_repr: uint = 1u; /* Dependency on size/alignment/mode and pub static use_repr: uint = 1; /* Dependency on size/alignment/mode and
take/drop glue */ take/drop glue */
pub static use_tydesc: uint = 2u; /* Takes the tydesc, or compares */ pub static use_tydesc: uint = 2; /* Takes the tydesc, or compares */
pub struct Context { pub struct Context {
ccx: @CrateContext, ccx: @CrateContext,
@ -57,9 +57,9 @@ pub struct Context {
} }
pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint) pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
-> ~[type_uses] { -> @~[type_uses] {
match ccx.type_use_cache.find(&fn_id) { match ccx.type_use_cache.find(&fn_id) {
Some(uses) => return /*bad*/ copy *uses, Some(uses) => return *uses,
None => () None => ()
} }
@ -70,11 +70,11 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
}; };
// Conservatively assume full use for recursive loops // Conservatively assume full use for recursive loops
ccx.type_use_cache.insert(fn_id, vec::from_elem(n_tps, 3u)); ccx.type_use_cache.insert(fn_id, @vec::from_elem(n_tps, 3u));
let cx = Context { let cx = Context {
ccx: ccx, ccx: ccx,
uses: @mut vec::from_elem(n_tps, 0u) uses: @mut vec::from_elem(n_tps, 0)
}; };
match ty::get(ty::lookup_item_type(cx.ccx.tcx, fn_id).ty).sty { match ty::get(ty::lookup_item_type(cx.ccx.tcx, fn_id).ty).sty {
ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, _}) | ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, _}) |
@ -92,8 +92,9 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
} }
if fn_id_loc.crate != local_crate { if fn_id_loc.crate != local_crate {
let uses = copy *cx.uses; let Context { uses: @uses, _ } = cx;
ccx.type_use_cache.insert(fn_id, copy uses); let uses = @uses; // mutability
ccx.type_use_cache.insert(fn_id, uses);
return uses; return uses;
} }
let map_node = match ccx.tcx.items.find(&fn_id_loc.node) { let map_node = match ccx.tcx.items.find(&fn_id_loc.node) {
@ -179,9 +180,9 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
ccx.tcx.sess.parse_sess.interner))); ccx.tcx.sess.parse_sess.interner)));
} }
} }
// XXX: Bad copies, use @vec instead? let Context { uses: @uses, _ } = cx;
let uses = copy *cx.uses; let uses = @uses; // mutability
ccx.type_use_cache.insert(fn_id, copy uses); ccx.type_use_cache.insert(fn_id, uses);
uses uses
} }
@ -253,7 +254,7 @@ pub fn mark_for_method_call(cx: Context, e_id: node_id, callee_id: node_id) {
// before stage2 // before stage2
let ts = /*bad*/ copy **ts; let ts = /*bad*/ copy **ts;
let type_uses = type_uses_for(cx.ccx, did, ts.len()); let type_uses = type_uses_for(cx.ccx, did, ts.len());
for vec::each2(type_uses, ts) |uses, subst| { for vec::each2(*type_uses, ts) |uses, subst| {
type_needs(cx, *uses, *subst) type_needs(cx, *uses, *subst)
} }
} }
@ -302,7 +303,7 @@ pub fn mark_for_expr(cx: Context, e: @expr) {
let ts = copy **ts; let ts = copy **ts;
let id = ast_util::def_id_of_def(*cx.ccx.tcx.def_map.get(&e.id)); let id = ast_util::def_id_of_def(*cx.ccx.tcx.def_map.get(&e.id));
let uses_for_ts = type_uses_for(cx.ccx, id, ts.len()); let uses_for_ts = type_uses_for(cx.ccx, id, ts.len());
for vec::each2(uses_for_ts, ts) |uses, subst| { for vec::each2(*uses_for_ts, ts) |uses, subst| {
type_needs(cx, *uses, *subst) type_needs(cx, *uses, *subst)
} }
} }

View file

@ -39,5 +39,5 @@ pub fn from_str_sess(sess: session::Session, source: ~str) -> @ast::crate {
} }
fn cfg(sess: session::Session, input: driver::input) -> ast::crate_cfg { fn cfg(sess: session::Session, input: driver::input) -> ast::crate_cfg {
driver::build_configuration(sess, ~"rustdoc", input) driver::build_configuration(sess, @~"rustdoc", input)
} }

View file

@ -127,7 +127,7 @@ fn record(repl: Repl, blk: @ast::blk, intr: @token::ident_interner) -> Repl {
fn run(repl: Repl, input: ~str) -> Repl { fn run(repl: Repl, input: ~str) -> Repl {
let options = @session::options { let options = @session::options {
crate_type: session::unknown_crate, crate_type: session::unknown_crate,
binary: repl.binary, binary: @repl.binary,
addl_lib_search_paths: repl.lib_search_paths.map(|p| Path(*p)), addl_lib_search_paths: repl.lib_search_paths.map(|p| Path(*p)),
jit: true, jit: true,
.. *session::basic_options() .. *session::basic_options()
@ -146,7 +146,7 @@ fn run(repl: Repl, input: ~str) -> Repl {
debug!("building driver configuration"); debug!("building driver configuration");
let cfg = driver::build_configuration(sess, let cfg = driver::build_configuration(sess,
repl.binary, @repl.binary,
wrapped); wrapped);
let outputs = driver::build_output_filenames(wrapped, &None, &None, sess); let outputs = driver::build_output_filenames(wrapped, &None, &None, sess);
@ -191,14 +191,14 @@ fn compile_crate(src_filename: ~str, binary: ~str) -> Option<bool> {
match do task::try { match do task::try {
let src_path = Path(src_filename); let src_path = Path(src_filename);
let options = @session::options { let options = @session::options {
binary: binary, binary: @binary,
addl_lib_search_paths: ~[os::getcwd()], addl_lib_search_paths: ~[os::getcwd()],
.. *session::basic_options() .. *session::basic_options()
}; };
let input = driver::file_input(src_path); let input = driver::file_input(src_path);
let sess = driver::build_session(options, diagnostic::emit); let sess = driver::build_session(options, diagnostic::emit);
*sess.building_library = true; *sess.building_library = true;
let cfg = driver::build_configuration(sess, binary, input); let cfg = driver::build_configuration(sess, @binary, input);
let outputs = driver::build_output_filenames( let outputs = driver::build_output_filenames(
input, &None, &None, sess); input, &None, &None, sess);
// If the library already exists and is newer than the source // If the library already exists and is newer than the source

View file

@ -76,13 +76,13 @@ impl PkgScript {
// Build the rustc session data structures to pass // Build the rustc session data structures to pass
// to the compiler // to the compiler
let options = @session::options { let options = @session::options {
binary: binary, binary: @binary,
crate_type: session::bin_crate, crate_type: session::bin_crate,
.. *session::basic_options() .. *session::basic_options()
}; };
let input = driver::file_input(script); let input = driver::file_input(script);
let sess = driver::build_session(options, diagnostic::emit); let sess = driver::build_session(options, diagnostic::emit);
let cfg = driver::build_configuration(sess, binary, input); let cfg = driver::build_configuration(sess, @binary, input);
let (crate, _) = driver::compile_upto(sess, cfg, input, let (crate, _) = driver::compile_upto(sess, cfg, input,
driver::cu_parse, None); driver::cu_parse, None);
let work_dir = dest_dir(id); let work_dir = dest_dir(id);

View file

@ -467,7 +467,7 @@ pub fn compile_input(sysroot: Option<Path>,
test: test, test: test,
maybe_sysroot: sysroot, maybe_sysroot: sysroot,
addl_lib_search_paths: ~[copy *out_dir], addl_lib_search_paths: ~[copy *out_dir],
.. *driver::build_session_options(binary, &matches, diagnostic::emit) .. *driver::build_session_options(@binary, &matches, diagnostic::emit)
}; };
let mut crate_cfg = options.cfg; let mut crate_cfg = options.cfg;
@ -499,7 +499,7 @@ pub fn compile_crate_from_input(input: driver::input, build_dir_opt: Option<Path
debug!("Calling build_output_filenames with %?", build_dir_opt); debug!("Calling build_output_filenames with %?", build_dir_opt);
let outputs = driver::build_output_filenames(input, &build_dir_opt, &None, sess); let outputs = driver::build_output_filenames(input, &build_dir_opt, &None, sess);
debug!("Outputs are %? and output type = %?", outputs, sess.opts.output_type); debug!("Outputs are %? and output type = %?", outputs, sess.opts.output_type);
let cfg = driver::build_configuration(sess, binary, input); let cfg = driver::build_configuration(sess, @binary, input);
match crate_opt { match crate_opt {
Some(c) => { Some(c) => {
debug!("Calling compile_rest, outputs = %?", outputs); debug!("Calling compile_rest, outputs = %?", outputs);