Skip to content

Anti-copy police #5914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ pub mod jit {
code: entry,
env: ptr::null()
};
let func: &fn(++argv: ~[~str]) = cast::transmute(closure);
let func: &fn(++argv: ~[@~str]) = cast::transmute(closure);

func(~[/*bad*/copy sess.opts.binary]);
func(~[sess.opts.binary]);
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn source_name(input: input) -> ~str {
}
}

pub fn default_configuration(sess: Session, +argv0: ~str, input: input) ->
pub fn default_configuration(sess: Session, argv0: @~str, input: input) ->
ast::crate_cfg {
let libc = match sess.targ_cfg.os {
session::os_win32 => ~"msvcrt.dll",
Expand Down Expand Up @@ -101,7 +101,7 @@ pub fn default_configuration(sess: Session, +argv0: ~str, input: input) ->
mk(@~"target_word_size", @wordsz),
mk(@~"target_libc", @libc),
// Build bindings.
mk(@~"build_compiler", @argv0),
mk(@~"build_compiler", argv0),
mk(@~"build_input", @source_name(input))];
}

Expand All @@ -114,7 +114,7 @@ pub fn append_configuration(+cfg: ast::crate_cfg, +name: ~str)
}
}

pub fn build_configuration(sess: Session, +argv0: ~str, input: input) ->
pub fn build_configuration(sess: Session, argv0: @~str, input: input) ->
ast::crate_cfg {
// Combine the configuration requested by the session (command line) with
// some default and generated configuration items
Expand Down Expand Up @@ -523,7 +523,7 @@ pub fn host_triple() -> ~str {
};
}

pub fn build_session_options(+binary: ~str,
pub fn build_session_options(binary: @~str,
matches: &getopts::Matches,
demitter: diagnostic::Emitter)
-> @session::options {
Expand Down Expand Up @@ -898,9 +898,9 @@ mod test {
getopts::fail_str(f))
};
let sessopts = build_session_options(
~"rustc", matches, diagnostic::emit);
@~"rustc", matches, 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")));
}

Expand All @@ -917,9 +917,9 @@ mod test {
}
};
let sessopts = build_session_options(
~"rustc", matches, diagnostic::emit);
@~"rustc", matches, 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");
assert!((vec::len(test_items) == 1u));
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub struct options {
// will be added to the crate AST node. This should not be used for
// anything except building the full crate config prior to parsing.
cfg: ast::crate_cfg,
binary: ~str,
binary: @~str,
test: bool,
parse_only: bool,
no_trans: bool,
Expand Down Expand Up @@ -303,7 +303,7 @@ pub fn basic_options() -> @options {
maybe_sysroot: None,
target_triple: host_triple(),
cfg: ~[],
binary: ~"rustc",
binary: @~"rustc",
test: false,
parse_only: false,
no_trans: false,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub struct CrateContext {
monomorphized: @mut HashMap<mono_id, ValueRef>,
monomorphizing: @mut HashMap<ast::def_id, uint>,
// 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
vtables: @mut HashMap<mono_id, ValueRef>,
// Cache of constant strings,
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/middle/trans/monomorphize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ pub fn make_mono_id(ccx: @CrateContext,
substs: &[ty::t],
vtables: Option<typeck::vtable_res>,
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 {
Some(vts) => {
let item_ty = ty::lookup_item_type(ccx.tcx, item);
Expand All @@ -353,12 +353,12 @@ pub fn make_mono_id(ccx: @CrateContext,
match *bound {
ty::bound_trait(_) => {
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 => {
Expand All @@ -367,7 +367,7 @@ pub fn make_mono_id(ccx: @CrateContext,
};
let param_ids = match param_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() {
match copy *id {
(a, b) => mono_precise(a, b)
Expand All @@ -377,7 +377,7 @@ pub fn make_mono_id(ccx: @CrateContext,
// XXX: Bad copy.
(a, copy b@Some(_)) => mono_precise(a, b),
(subst, None) => {
if *uses == 0u {
if *uses == 0 {
mono_any
} else if *uses == type_use::use_repr &&
!ty::type_needs_drop(ccx.tcx, subst)
Expand Down
27 changes: 14 additions & 13 deletions src/librustc/middle/trans/type_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ use syntax::ast_util;
use syntax::visit;

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 */
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 {
ccx: @CrateContext,
uses: @mut ~[type_uses]
}

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) {
Some(uses) => return /*bad*/ copy *uses,
Some(uses) => return *uses,
None => ()
}

Expand All @@ -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
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 {
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 {
ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, _}) |
Expand All @@ -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 {
let uses = copy *cx.uses;
ccx.type_use_cache.insert(fn_id, copy uses);
let Context { uses: @uses, _ } = cx;
let uses = @uses; // mutability
ccx.type_use_cache.insert(fn_id, uses);
return uses;
}
let map_node = match ccx.tcx.items.find(&fn_id_loc.node) {
Expand Down Expand Up @@ -179,9 +180,9 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
ccx.tcx.sess.parse_sess.interner)));
}
}
// XXX: Bad copies, use @vec instead?
let uses = copy *cx.uses;
ccx.type_use_cache.insert(fn_id, copy uses);
let Context { uses: @uses, _ } = cx;
let uses = @uses; // mutability
ccx.type_use_cache.insert(fn_id, uses);
uses
}

Expand Down Expand Up @@ -253,7 +254,7 @@ pub fn mark_for_method_call(cx: Context, e_id: node_id, callee_id: node_id) {
// before stage2
let ts = /*bad*/ copy **ts;
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)
}
}
Expand Down Expand Up @@ -302,7 +303,7 @@ pub fn mark_for_expr(cx: Context, e: @expr) {
let ts = copy **ts;
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());
for vec::each2(uses_for_ts, ts) |uses, subst| {
for vec::each2(*uses_for_ts, ts) |uses, subst| {
type_needs(cx, *uses, *subst)
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/librustc/rustc.rc
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ pub fn run_compiler(args: &~[~str], demitter: diagnostic::Emitter) {
::core::logging::console_off();

let mut args = /*bad*/copy *args;
let binary = args.shift();
let binary = @args.shift();

if args.is_empty() { usage(binary); return; }
if args.is_empty() { usage(*binary); return; }

let matches =
&match getopts::groups::getopts(args, optgroups()) {
Expand All @@ -219,7 +219,7 @@ pub fn run_compiler(args: &~[~str], demitter: diagnostic::Emitter) {
};

if opt_present(matches, ~"h") || opt_present(matches, ~"help") {
usage(binary);
usage(*binary);
return;
}

Expand All @@ -236,7 +236,7 @@ pub fn run_compiler(args: &~[~str], demitter: diagnostic::Emitter) {
}

if opt_present(matches, ~"v") || opt_present(matches, ~"version") {
version(binary);
version(*binary);
return;
}
let input = match vec::len(matches.free) {
Expand All @@ -253,8 +253,7 @@ pub fn run_compiler(args: &~[~str], demitter: diagnostic::Emitter) {
_ => early_error(demitter, ~"multiple input filenames provided")
};

// XXX: Bad copy.
let sopts = build_session_options(copy binary, matches, demitter);
let sopts = build_session_options(binary, matches, demitter);
let sess = build_session(sopts, demitter);
let odir = getopts::opt_maybe_str(matches, ~"out-dir");
let odir = odir.map(|o| Path(*o));
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
driver::build_configuration(sess, ~"rustdoc", input)
driver::build_configuration(sess, @~"rustdoc", input)
}
8 changes: 4 additions & 4 deletions src/librusti/rusti.rc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn record(repl: Repl, blk: @ast::blk, intr: @token::ident_interner) -> Repl {
fn run(repl: Repl, input: ~str) -> Repl {
let options = @session::options {
crate_type: session::unknown_crate,
binary: repl.binary,
binary: @repl.binary,
addl_lib_search_paths: repl.lib_search_paths.map(|p| Path(*p)),
jit: true,
.. *session::basic_options()
Expand All @@ -146,7 +146,7 @@ fn run(repl: Repl, input: ~str) -> Repl {

debug!("building driver configuration");
let cfg = driver::build_configuration(sess,
repl.binary,
@repl.binary,
wrapped);

let outputs = driver::build_output_filenames(wrapped, &None, &None, sess);
Expand Down Expand Up @@ -191,14 +191,14 @@ fn compile_crate(src_filename: ~str, binary: ~str) -> Option<bool> {
match do task::try {
let src_path = Path(src_filename);
let options = @session::options {
binary: binary,
binary: @binary,
addl_lib_search_paths: ~[os::getcwd()],
.. *session::basic_options()
};
let input = driver::file_input(src_path);
let sess = driver::build_session(options, diagnostic::emit);
*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(
input, &None, &None, sess);
// If the library already exists and is newer than the source
Expand Down
4 changes: 2 additions & 2 deletions src/librustpkg/rustpkg.rc
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ impl PkgScript {
// Build the rustc session data structures to pass
// to the compiler
let options = @session::options {
binary: binary,
binary: @binary,
crate_type: session::bin_crate,
.. *session::basic_options()
};
let input = driver::file_input(script);
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,
driver::cu_parse, None);
let work_dir = dest_dir(id);
Expand Down
4 changes: 2 additions & 2 deletions src/librustpkg/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ pub fn compile_input(sysroot: Option<Path>,
test: test,
maybe_sysroot: sysroot,
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;

Expand Down Expand Up @@ -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);
let outputs = driver::build_output_filenames(input, &build_dir_opt, &None, sess);
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 {
Some(c) => {
debug!("Calling compile_rest, outputs = %?", outputs);
Expand Down