Skip to content

Commit

Permalink
librustc: Automatically change uses of ~[T] to Vec<T> in rustc.
Browse files Browse the repository at this point in the history
  • Loading branch information
pcwalton authored and pnkfelix committed Mar 8, 2014
1 parent f690cc2 commit 3b6e9d4
Show file tree
Hide file tree
Showing 98 changed files with 811 additions and 817 deletions.
13 changes: 7 additions & 6 deletions src/librustc/back/archive.rs
Expand Up @@ -16,6 +16,7 @@ use metadata::filesearch;
use lib::llvm::{ArchiveRef, llvm};

use std::cast;
use std::vec_ng::Vec;
use std::io::fs;
use std::io;
use std::libc;
Expand All @@ -41,7 +42,7 @@ fn run_ar(sess: Session, args: &str, cwd: Option<&Path>,
paths: &[&Path]) -> ProcessOutput {
let ar = get_ar_prog(sess);

let mut args = ~[args.to_owned()];
let mut args = vec!(args.to_owned());
let mut paths = paths.iter().map(|p| p.as_str().unwrap().to_owned());
args.extend(&mut paths);
debug!("{} {}", ar, args.connect(" "));
Expand Down Expand Up @@ -89,7 +90,7 @@ impl Archive {
}

/// Read a file in the archive
pub fn read(&self, file: &str) -> ~[u8] {
pub fn read(&self, file: &str) -> Vec<u8> {
// Apparently if "ar p" is used on windows, it generates a corrupt file
// which has bad headers and LLVM will immediately choke on it
if cfg!(windows) && cfg!(windows) { // FIXME(#10734) double-and
Expand Down Expand Up @@ -119,7 +120,7 @@ impl Archive {
lto: bool) -> io::IoResult<()> {
let object = format!("{}.o", name);
let bytecode = format!("{}.bc", name);
let mut ignore = ~[METADATA_FILENAME, bytecode.as_slice()];
let mut ignore = vec!(METADATA_FILENAME, bytecode.as_slice());
if lto {
ignore.push(object.as_slice());
}
Expand All @@ -143,7 +144,7 @@ impl Archive {
}

/// Lists all files in an archive
pub fn files(&self) -> ~[~str] {
pub fn files(&self) -> Vec<~str> {
let output = run_ar(self.sess, "t", None, [&self.dst]);
let output = str::from_utf8(output.output).unwrap();
// use lines_any because windows delimits output with `\r\n` instead of
Expand All @@ -168,7 +169,7 @@ impl Archive {
// all SYMDEF files as these are just magical placeholders which get
// re-created when we make a new archive anyway.
let files = try!(fs::readdir(loc.path()));
let mut inputs = ~[];
let mut inputs = Vec::new();
for file in files.iter() {
let filename = file.filename_str().unwrap();
if skip.iter().any(|s| *s == filename) { continue }
Expand All @@ -182,7 +183,7 @@ impl Archive {
if inputs.len() == 0 { return Ok(()) }

// Finally, add all the renamed files to this archive
let mut args = ~[&self.dst];
let mut args = vec!(&self.dst);
args.extend(&mut inputs.iter());
run_ar(self.sess, "r", None, args.as_slice());
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/back/arm.rs
Expand Up @@ -15,9 +15,9 @@ use syntax::abi;

pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::t {
let cc_args = if target_triple.contains("thumb") {
~[~"-mthumb"]
vec!(~"-mthumb")
} else {
~[~"-marm"]
vec!(~"-marm")
};
return target_strs::t {
module_asm: ~"",
Expand Down
28 changes: 14 additions & 14 deletions src/librustc/back/link.rs
Expand Up @@ -363,8 +363,8 @@ pub mod write {
let vectorize_slp = !sess.opts.cg.no_vectorize_slp &&
sess.opts.optimize == session::Aggressive;

let mut llvm_c_strs = ~[];
let mut llvm_args = ~[];
let mut llvm_c_strs = Vec::new();
let mut llvm_args = Vec::new();
{
let add = |arg: &str| {
let s = arg.to_c_str();
Expand Down Expand Up @@ -781,8 +781,8 @@ fn remove(sess: Session, path: &Path) {
pub fn link_binary(sess: Session,
trans: &CrateTranslation,
outputs: &OutputFilenames,
id: &CrateId) -> ~[Path] {
let mut out_filenames = ~[];
id: &CrateId) -> Vec<Path> {
let mut out_filenames = Vec::new();
let crate_types = sess.crate_types.borrow();
for &crate_type in crate_types.get().iter() {
let out_file = link_binary_output(sess, trans, crate_type, outputs, id);
Expand Down Expand Up @@ -1071,15 +1071,15 @@ fn link_args(sess: Session,
dylib: bool,
tmpdir: &Path,
obj_filename: &Path,
out_filename: &Path) -> ~[~str] {
out_filename: &Path) -> Vec<~str> {

// The default library location, we need this to find the runtime.
// The location of crates will be determined as needed.
// FIXME (#9639): This needs to handle non-utf8 paths
let lib_path = sess.filesearch.get_target_lib_path();
let stage: ~str = ~"-L" + lib_path.as_str().unwrap();

let mut args = ~[stage];
let mut args = vec!(stage);

// FIXME (#9639): This needs to handle non-utf8 paths
args.push_all([
Expand Down Expand Up @@ -1230,7 +1230,7 @@ fn link_args(sess: Session,
// Also note that the native libraries linked here are only the ones located
// in the current crate. Upstream crates with native library dependencies
// may have their native library pulled in above.
fn add_local_native_libraries(args: &mut ~[~str], sess: Session) {
fn add_local_native_libraries(args: &mut Vec<~str> , sess: Session) {
let addl_lib_search_paths = sess.opts.addl_lib_search_paths.borrow();
for path in addl_lib_search_paths.get().iter() {
// FIXME (#9639): This needs to handle non-utf8 paths
Expand Down Expand Up @@ -1263,7 +1263,7 @@ fn add_local_native_libraries(args: &mut ~[~str], sess: Session) {
// Rust crates are not considered at all when creating an rlib output. All
// dependencies will be linked when producing the final output (instead of
// the intermediate rlib version)
fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
fn add_upstream_rust_crates(args: &mut Vec<~str> , sess: Session,
dylib: bool, tmpdir: &Path) {

// As a limitation of the current implementation, we require that everything
Expand Down Expand Up @@ -1347,7 +1347,7 @@ fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
// returning `None` if not all libraries could be found with that
// preference.
fn get_deps(cstore: &cstore::CStore, preference: cstore::LinkagePreference)
-> Option<~[(ast::CrateNum, Path)]>
-> Option<Vec<(ast::CrateNum, Path)> >
{
let crates = cstore.get_used_crates(preference);
if crates.iter().all(|&(_, ref p)| p.is_some()) {
Expand All @@ -1358,8 +1358,8 @@ fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
}

// Adds the static "rlib" versions of all crates to the command line.
fn add_static_crates(args: &mut ~[~str], sess: Session, tmpdir: &Path,
crates: ~[(ast::CrateNum, Path)]) {
fn add_static_crates(args: &mut Vec<~str> , sess: Session, tmpdir: &Path,
crates: Vec<(ast::CrateNum, Path)> ) {
for (cnum, cratepath) in crates.move_iter() {
// When performing LTO on an executable output, all of the
// bytecode from the upstream libraries has already been
Expand Down Expand Up @@ -1405,8 +1405,8 @@ fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
}

// Same thing as above, but for dynamic crates instead of static crates.
fn add_dynamic_crates(args: &mut ~[~str], sess: Session,
crates: ~[(ast::CrateNum, Path)]) {
fn add_dynamic_crates(args: &mut Vec<~str> , sess: Session,
crates: Vec<(ast::CrateNum, Path)> ) {
// If we're performing LTO, then it should have been previously required
// that all upstream rust dependencies were available in an rlib format.
assert!(!sess.lto());
Expand Down Expand Up @@ -1440,7 +1440,7 @@ fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
// generic function calls a native function, then the generic function must
// be instantiated in the target crate, meaning that the native symbol must
// also be resolved in the target crate.
fn add_upstream_native_libraries(args: &mut ~[~str], sess: Session) {
fn add_upstream_native_libraries(args: &mut Vec<~str> , sess: Session) {
let cstore = sess.cstore;
cstore.iter_crate_data(|cnum, _| {
let libs = csearch::get_native_libraries(cstore, cnum);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/back/mips.rs
Expand Up @@ -63,6 +63,6 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::

target_triple: target_triple,

cc_args: ~[],
cc_args: Vec::new(),
};
}
24 changes: 12 additions & 12 deletions src/librustc/back/rpath.rs
Expand Up @@ -21,15 +21,15 @@ fn not_win32(os: abi::Os) -> bool {
os != abi::OsWin32
}

pub fn get_rpath_flags(sess: session::Session, out_filename: &Path) -> ~[~str] {
pub fn get_rpath_flags(sess: session::Session, out_filename: &Path) -> Vec<~str> {
let os = sess.targ_cfg.os;

// No rpath on windows
if os == abi::OsWin32 {
return ~[];
return Vec::new();
}

let mut flags = ~[];
let mut flags = Vec::new();

if sess.targ_cfg.os == abi::OsFreebsd {
flags.push_all([~"-Wl,-rpath,/usr/local/lib/gcc46",
Expand Down Expand Up @@ -60,8 +60,8 @@ fn get_sysroot_absolute_rt_lib(sess: session::Session) -> Path {
p
}

pub fn rpaths_to_flags(rpaths: &[~str]) -> ~[~str] {
let mut ret = ~[];
pub fn rpaths_to_flags(rpaths: &[~str]) -> Vec<~str> {
let mut ret = Vec::new();
for rpath in rpaths.iter() {
ret.push("-Wl,-rpath," + *rpath);
}
Expand All @@ -72,7 +72,7 @@ fn get_rpaths(os: abi::Os,
sysroot: &Path,
output: &Path,
libs: &[Path],
target_triple: &str) -> ~[~str] {
target_triple: &str) -> Vec<~str> {
debug!("sysroot: {}", sysroot.display());
debug!("output: {}", output.display());
debug!("libs:");
Expand All @@ -91,7 +91,7 @@ fn get_rpaths(os: abi::Os,
let abs_rpaths = get_absolute_rpaths(libs);

// And a final backup rpath to the global library location.
let fallback_rpaths = ~[get_install_prefix_rpath(target_triple)];
let fallback_rpaths = vec!(get_install_prefix_rpath(target_triple));

fn log_rpaths(desc: &str, rpaths: &[~str]) {
debug!("{} rpaths:", desc);
Expand All @@ -115,7 +115,7 @@ fn get_rpaths(os: abi::Os,

fn get_rpaths_relative_to_output(os: abi::Os,
output: &Path,
libs: &[Path]) -> ~[~str] {
libs: &[Path]) -> Vec<~str> {
libs.iter().map(|a| get_rpath_relative_to_output(os, output, a)).collect()
}

Expand Down Expand Up @@ -145,7 +145,7 @@ pub fn get_rpath_relative_to_output(os: abi::Os,
prefix+"/"+relative.as_str().expect("non-utf8 component in path")
}

fn get_absolute_rpaths(libs: &[Path]) -> ~[~str] {
fn get_absolute_rpaths(libs: &[Path]) -> Vec<~str> {
libs.iter().map(|a| get_absolute_rpath(a)).collect()
}

Expand All @@ -167,9 +167,9 @@ pub fn get_install_prefix_rpath(target_triple: &str) -> ~str {
path.as_str().expect("non-utf8 component in rpath").to_owned()
}

pub fn minimize_rpaths(rpaths: &[~str]) -> ~[~str] {
pub fn minimize_rpaths(rpaths: &[~str]) -> Vec<~str> {
let mut set = HashSet::new();
let mut minimized = ~[];
let mut minimized = Vec::new();
for rpath in rpaths.iter() {
if set.insert(rpath.as_slice()) {
minimized.push(rpath.clone());
Expand All @@ -190,7 +190,7 @@ mod test {
#[test]
fn test_rpaths_to_flags() {
let flags = rpaths_to_flags([~"path1", ~"path2"]);
assert_eq!(flags, ~[~"-Wl,-rpath,path1", ~"-Wl,-rpath,path2"]);
assert_eq!(flags, vec!(~"-Wl,-rpath,path1", ~"-Wl,-rpath,path2"));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/back/target_strs.rs
Expand Up @@ -15,5 +15,5 @@ pub struct t {
meta_sect_name: ~str,
data_layout: ~str,
target_triple: ~str,
cc_args: ~[~str],
cc_args: Vec<~str> ,
}
2 changes: 1 addition & 1 deletion src/librustc/back/x86.rs
Expand Up @@ -46,6 +46,6 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::

target_triple: target_triple,

cc_args: ~[~"-m32"],
cc_args: vec!(~"-m32"),
};
}
2 changes: 1 addition & 1 deletion src/librustc/back/x86_64.rs
Expand Up @@ -54,6 +54,6 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::

target_triple: target_triple,

cc_args: ~[~"-m64"],
cc_args: vec!(~"-m64"),
};
}
25 changes: 12 additions & 13 deletions src/librustc/driver/driver.rs
Expand Up @@ -145,7 +145,7 @@ pub fn build_configuration(sess: Session) -> ast::CrateConfig {
}

// Convert strings provided as --cfg [cfgspec] into a crate_cfg
fn parse_cfgspecs(cfgspecs: ~[~str])
fn parse_cfgspecs(cfgspecs: Vec<~str> )
-> ast::CrateConfig {
cfgspecs.move_iter().map(|s| {
let sess = parse::new_parse_sess();
Expand Down Expand Up @@ -399,8 +399,8 @@ pub struct CrateTranslation {
module: ModuleRef,
metadata_module: ModuleRef,
link: LinkMeta,
metadata: ~[u8],
reachable: ~[~str],
metadata: Vec<u8> ,
reachable: Vec<~str> ,
}

/// Run the translation phase to LLVM, after which the AST and analysis can
Expand Down Expand Up @@ -489,7 +489,7 @@ fn write_out_deps(sess: Session,
krate: &ast::Crate) -> io::IoResult<()> {
let id = link::find_crate_id(krate.attrs.as_slice(), outputs);

let mut out_filenames = ~[];
let mut out_filenames = Vec::new();
for output_type in sess.opts.output_types.iter() {
let file = outputs.path(*output_type);
match *output_type {
Expand Down Expand Up @@ -524,7 +524,7 @@ fn write_out_deps(sess: Session,

// Build a list of files used to compile the output and
// write Makefile-compatible dependency rules
let files: ~[~str] = {
let files: Vec<~str> = {
let files = sess.codemap.files.borrow();
files.get()
.iter()
Expand Down Expand Up @@ -786,14 +786,14 @@ pub fn build_session_options(matches: &getopts::Matches)

let lint_levels = [lint::allow, lint::warn,
lint::deny, lint::forbid];
let mut lint_opts = ~[];
let mut lint_opts = Vec::new();
let lint_dict = lint::get_lint_dict();
for level in lint_levels.iter() {
let level_name = lint::level_to_str(*level);

let level_short = level_name.slice_chars(0, 1);
let level_short = level_short.to_ascii().to_upper().into_str();
let flags = vec::append(matches.opt_strs(level_short),
let flags = vec_ng::append(matches.opt_strs(level_short),
matches.opt_strs(level_name));
for lint_name in flags.iter() {
let lint_name = lint_name.replace("-", "_");
Expand Down Expand Up @@ -829,7 +829,7 @@ pub fn build_session_options(matches: &getopts::Matches)
}

let mut output_types = if parse_only || no_trans {
~[]
Vec::new()
} else {
matches.opt_strs("emit").flat_map(|s| {
s.split(',').map(|part| {
Expand Down Expand Up @@ -1005,7 +1005,7 @@ pub fn build_session_(sopts: @session::Options,
working_dir: os::getcwd(),
lints: RefCell::new(HashMap::new()),
node_id: Cell::new(1),
crate_types: @RefCell::new(~[]),
crate_types: @RefCell::new(Vec::new()),
features: front::feature_gate::Features::new()
}
}
Expand All @@ -1026,8 +1026,8 @@ pub fn parse_pretty(sess: Session, name: &str) -> PpMode {
}

// rustc command line options
pub fn optgroups() -> ~[getopts::OptGroup] {
~[
pub fn optgroups() -> Vec<getopts::OptGroup> {
vec!(
optflag("h", "help", "Display this message"),
optmulti("", "cfg", "Configure the compilation environment", "SPEC"),
optmulti("L", "", "Add a directory to the library search path", "PATH"),
Expand Down Expand Up @@ -1071,8 +1071,7 @@ pub fn optgroups() -> ~[getopts::OptGroup] {
optmulti("F", "forbid", "Set lint forbidden", "OPT"),
optmulti("C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
optmulti("Z", "", "Set internal debugging options", "FLAG"),
optflag( "v", "version", "Print version info and exit"),
]
optflag( "v", "version", "Print version info and exit"))
}

pub struct OutputFilenames {
Expand Down

0 comments on commit 3b6e9d4

Please sign in to comment.