Skip to content

Commit

Permalink
auto merge of #12768 : pnkfelix/rust/fsk-devecing, r=pnkfelix
Browse files Browse the repository at this point in the history
Change `~[T]` to Vec<T> in librustc.  Rebased and amended version of PR #12716.

Original author (or perhaps I should say meta-author) was @pcwalton, as is reflected in the commits.

I clean up!  :)
  • Loading branch information
bors committed Mar 8, 2014
2 parents 96e8c00 + f978c77 commit 0017056
Show file tree
Hide file tree
Showing 106 changed files with 2,053 additions and 1,514 deletions.
27 changes: 18 additions & 9 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,17 +90,25 @@ 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
let loc = TempDir::new("rsar").unwrap();
let archive = os::make_absolute(&self.dst);
run_ar(self.sess, "x", Some(loc.path()), [&archive,
&Path::new(file)]);
fs::File::open(&loc.path().join(file)).read_to_end().unwrap()
let result: Vec<u8> =
fs::File::open(&loc.path().join(file)).read_to_end()
.unwrap()
.move_iter()
.collect();
result
} else {
run_ar(self.sess, "p", None, [&self.dst, &Path::new(file)]).output
run_ar(self.sess,
"p",
None,
[&self.dst, &Path::new(file)]).output.move_iter().collect()
}
}

Expand All @@ -119,11 +128,11 @@ 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());
}
self.add_archive(rlib, name, ignore)
self.add_archive(rlib, name, ignore.as_slice())
}

/// Adds an arbitrary file to this archive
Expand All @@ -143,7 +152,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 +177,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 +191,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
41 changes: 22 additions & 19 deletions src/librustc/back/link.rs
Expand Up @@ -34,6 +34,7 @@ use std::str;
use std::io;
use std::io::Process;
use std::io::fs;
use std::vec_ng::Vec;
use flate;
use serialize::hex::ToHex;
use extra::tempfile::TempDir;
Expand Down Expand Up @@ -106,6 +107,7 @@ pub mod write {
use std::io::Process;
use std::libc::{c_uint, c_int};
use std::str;
use std::vec_ng::Vec;

// On android, we by default compile for armv7 processors. This enables
// things like double word CAS instructions (rather than emulating them)
Expand Down Expand Up @@ -222,7 +224,7 @@ pub mod write {

if sess.lto() {
time(sess.time_passes(), "all lto passes", (), |()|
lto::run(sess, llmod, tm, trans.reachable));
lto::run(sess, llmod, tm, trans.reachable.as_slice()));

if sess.opts.cg.save_temps {
output.with_extension("lto.bc").with_c_str(|buf| {
Expand Down Expand Up @@ -363,8 +365,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 +783,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 @@ -931,7 +933,8 @@ fn link_rlib(sess: Session,
// the same filename for metadata (stomping over one another)
let tmpdir = TempDir::new("rustc").expect("needs a temp dir");
let metadata = tmpdir.path().join(METADATA_FILENAME);
match fs::File::create(&metadata).write(trans.metadata) {
match fs::File::create(&metadata).write(trans.metadata
.as_slice()) {
Ok(..) => {}
Err(e) => {
sess.err(format!("failed to write {}: {}",
Expand Down Expand Up @@ -1035,7 +1038,7 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
// Invoke the system linker
debug!("{} {}", cc_prog, cc_args.connect(" "));
let prog = time(sess.time_passes(), "running linker", (), |()|
Process::output(cc_prog, cc_args));
Process::output(cc_prog, cc_args.as_slice()));
match prog {
Ok(prog) => {
if !prog.status.success() {
Expand Down Expand Up @@ -1071,15 +1074,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 @@ -1198,7 +1201,7 @@ fn link_args(sess: Session,
// where extern libraries might live, based on the
// addl_lib_search_paths
if !sess.opts.cg.no_rpath {
args.push_all(rpath::get_rpath_flags(sess, out_filename));
args.push_all(rpath::get_rpath_flags(sess, out_filename).as_slice());
}

// Stack growth requires statically linking a __morestack function
Expand All @@ -1210,7 +1213,7 @@ fn link_args(sess: Session,

// Finally add all the linker arguments provided on the command line along
// with any #[link_args] attributes found inside the crate
args.push_all(sess.opts.cg.link_args);
args.push_all(sess.opts.cg.link_args.as_slice());
let used_link_args = sess.cstore.get_used_link_args();
let used_link_args = used_link_args.borrow();
for arg in used_link_args.get().iter() {
Expand All @@ -1230,7 +1233,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 +1266,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 +1350,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 +1361,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 +1408,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 +1443,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
3 changes: 2 additions & 1 deletion src/librustc/back/mips.rs
Expand Up @@ -11,6 +11,7 @@
use back::target_strs;
use driver::session::sess_os_to_meta_os;
use metadata::loader::meta_section_name;
use std::vec_ng::Vec;
use syntax::abi;

pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::t {
Expand Down Expand Up @@ -63,6 +64,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(),
};
}
39 changes: 20 additions & 19 deletions src/librustc/back/rpath.rs
Expand Up @@ -15,21 +15,22 @@ use metadata::filesearch;

use collections::HashSet;
use std::{os, vec};
use std::vec_ng::Vec;
use syntax::abi;

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 All @@ -49,7 +50,7 @@ pub fn get_rpath_flags(sess: session::Session, out_filename: &Path) -> ~[~str] {

let rpaths = get_rpaths(os, sysroot, output, libs,
sess.opts.target_triple);
flags.push_all(rpaths_to_flags(rpaths));
flags.push_all(rpaths_to_flags(rpaths.as_slice()).as_slice());
flags
}

Expand All @@ -60,8 +61,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 +73,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 +92,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 @@ -100,22 +101,22 @@ fn get_rpaths(os: abi::Os,
}
}

log_rpaths("relative", rel_rpaths);
log_rpaths("absolute", abs_rpaths);
log_rpaths("fallback", fallback_rpaths);
log_rpaths("relative", rel_rpaths.as_slice());
log_rpaths("absolute", abs_rpaths.as_slice());
log_rpaths("fallback", fallback_rpaths.as_slice());

let mut rpaths = rel_rpaths;
rpaths.push_all(abs_rpaths);
rpaths.push_all(fallback_rpaths);
rpaths.push_all(abs_rpaths.as_slice());
rpaths.push_all(fallback_rpaths.as_slice());

// Remove duplicates
let rpaths = minimize_rpaths(rpaths);
let rpaths = minimize_rpaths(rpaths.as_slice());
return rpaths;
}

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 +146,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 +168,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 +191,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

0 comments on commit 0017056

Please sign in to comment.