Skip to content

Commit 0017056

Browse files
committed
auto merge of #12768 : pnkfelix/rust/fsk-devecing, r=pnkfelix
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! :)
2 parents 96e8c00 + f978c77 commit 0017056

Some content is hidden

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

106 files changed

+2053
-1514
lines changed

src/librustc/back/archive.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use metadata::filesearch;
1616
use lib::llvm::{ArchiveRef, llvm};
1717

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

44-
let mut args = ~[args.to_owned()];
45+
let mut args = vec!(args.to_owned());
4546
let mut paths = paths.iter().map(|p| p.as_str().unwrap().to_owned());
4647
args.extend(&mut paths);
4748
debug!("{} {}", ar, args.connect(" "));
@@ -89,17 +90,25 @@ impl Archive {
8990
}
9091

9192
/// Read a file in the archive
92-
pub fn read(&self, file: &str) -> ~[u8] {
93+
pub fn read(&self, file: &str) -> Vec<u8> {
9394
// Apparently if "ar p" is used on windows, it generates a corrupt file
9495
// which has bad headers and LLVM will immediately choke on it
9596
if cfg!(windows) && cfg!(windows) { // FIXME(#10734) double-and
9697
let loc = TempDir::new("rsar").unwrap();
9798
let archive = os::make_absolute(&self.dst);
9899
run_ar(self.sess, "x", Some(loc.path()), [&archive,
99100
&Path::new(file)]);
100-
fs::File::open(&loc.path().join(file)).read_to_end().unwrap()
101+
let result: Vec<u8> =
102+
fs::File::open(&loc.path().join(file)).read_to_end()
103+
.unwrap()
104+
.move_iter()
105+
.collect();
106+
result
101107
} else {
102-
run_ar(self.sess, "p", None, [&self.dst, &Path::new(file)]).output
108+
run_ar(self.sess,
109+
"p",
110+
None,
111+
[&self.dst, &Path::new(file)]).output.move_iter().collect()
103112
}
104113
}
105114

@@ -119,11 +128,11 @@ impl Archive {
119128
lto: bool) -> io::IoResult<()> {
120129
let object = format!("{}.o", name);
121130
let bytecode = format!("{}.bc", name);
122-
let mut ignore = ~[METADATA_FILENAME, bytecode.as_slice()];
131+
let mut ignore = vec!(METADATA_FILENAME, bytecode.as_slice());
123132
if lto {
124133
ignore.push(object.as_slice());
125134
}
126-
self.add_archive(rlib, name, ignore)
135+
self.add_archive(rlib, name, ignore.as_slice())
127136
}
128137

129138
/// Adds an arbitrary file to this archive
@@ -143,7 +152,7 @@ impl Archive {
143152
}
144153

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

184193
// Finally, add all the renamed files to this archive
185-
let mut args = ~[&self.dst];
194+
let mut args = vec!(&self.dst);
186195
args.extend(&mut inputs.iter());
187196
run_ar(self.sess, "r", None, args.as_slice());
188197
Ok(())

src/librustc/back/arm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use syntax::abi;
1515

1616
pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::t {
1717
let cc_args = if target_triple.contains("thumb") {
18-
~[~"-mthumb"]
18+
vec!(~"-mthumb")
1919
} else {
20-
~[~"-marm"]
20+
vec!(~"-marm")
2121
};
2222
return target_strs::t {
2323
module_asm: ~"",

src/librustc/back/link.rs

+22-19
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use std::str;
3434
use std::io;
3535
use std::io::Process;
3636
use std::io::fs;
37+
use std::vec_ng::Vec;
3738
use flate;
3839
use serialize::hex::ToHex;
3940
use extra::tempfile::TempDir;
@@ -106,6 +107,7 @@ pub mod write {
106107
use std::io::Process;
107108
use std::libc::{c_uint, c_int};
108109
use std::str;
110+
use std::vec_ng::Vec;
109111

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

223225
if sess.lto() {
224226
time(sess.time_passes(), "all lto passes", (), |()|
225-
lto::run(sess, llmod, tm, trans.reachable));
227+
lto::run(sess, llmod, tm, trans.reachable.as_slice()));
226228

227229
if sess.opts.cg.save_temps {
228230
output.with_extension("lto.bc").with_c_str(|buf| {
@@ -363,8 +365,8 @@ pub mod write {
363365
let vectorize_slp = !sess.opts.cg.no_vectorize_slp &&
364366
sess.opts.optimize == session::Aggressive;
365367

366-
let mut llvm_c_strs = ~[];
367-
let mut llvm_args = ~[];
368+
let mut llvm_c_strs = Vec::new();
369+
let mut llvm_args = Vec::new();
368370
{
369371
let add = |arg: &str| {
370372
let s = arg.to_c_str();
@@ -781,8 +783,8 @@ fn remove(sess: Session, path: &Path) {
781783
pub fn link_binary(sess: Session,
782784
trans: &CrateTranslation,
783785
outputs: &OutputFilenames,
784-
id: &CrateId) -> ~[Path] {
785-
let mut out_filenames = ~[];
786+
id: &CrateId) -> Vec<Path> {
787+
let mut out_filenames = Vec::new();
786788
let crate_types = sess.crate_types.borrow();
787789
for &crate_type in crate_types.get().iter() {
788790
let out_file = link_binary_output(sess, trans, crate_type, outputs, id);
@@ -931,7 +933,8 @@ fn link_rlib(sess: Session,
931933
// the same filename for metadata (stomping over one another)
932934
let tmpdir = TempDir::new("rustc").expect("needs a temp dir");
933935
let metadata = tmpdir.path().join(METADATA_FILENAME);
934-
match fs::File::create(&metadata).write(trans.metadata) {
936+
match fs::File::create(&metadata).write(trans.metadata
937+
.as_slice()) {
935938
Ok(..) => {}
936939
Err(e) => {
937940
sess.err(format!("failed to write {}: {}",
@@ -1035,7 +1038,7 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
10351038
// Invoke the system linker
10361039
debug!("{} {}", cc_prog, cc_args.connect(" "));
10371040
let prog = time(sess.time_passes(), "running linker", (), |()|
1038-
Process::output(cc_prog, cc_args));
1041+
Process::output(cc_prog, cc_args.as_slice()));
10391042
match prog {
10401043
Ok(prog) => {
10411044
if !prog.status.success() {
@@ -1071,15 +1074,15 @@ fn link_args(sess: Session,
10711074
dylib: bool,
10721075
tmpdir: &Path,
10731076
obj_filename: &Path,
1074-
out_filename: &Path) -> ~[~str] {
1077+
out_filename: &Path) -> Vec<~str> {
10751078

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

1082-
let mut args = ~[stage];
1085+
let mut args = vec!(stage);
10831086

10841087
// FIXME (#9639): This needs to handle non-utf8 paths
10851088
args.push_all([
@@ -1198,7 +1201,7 @@ fn link_args(sess: Session,
11981201
// where extern libraries might live, based on the
11991202
// addl_lib_search_paths
12001203
if !sess.opts.cg.no_rpath {
1201-
args.push_all(rpath::get_rpath_flags(sess, out_filename));
1204+
args.push_all(rpath::get_rpath_flags(sess, out_filename).as_slice());
12021205
}
12031206

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

12111214
// Finally add all the linker arguments provided on the command line along
12121215
// with any #[link_args] attributes found inside the crate
1213-
args.push_all(sess.opts.cg.link_args);
1216+
args.push_all(sess.opts.cg.link_args.as_slice());
12141217
let used_link_args = sess.cstore.get_used_link_args();
12151218
let used_link_args = used_link_args.borrow();
12161219
for arg in used_link_args.get().iter() {
@@ -1230,7 +1233,7 @@ fn link_args(sess: Session,
12301233
// Also note that the native libraries linked here are only the ones located
12311234
// in the current crate. Upstream crates with native library dependencies
12321235
// may have their native library pulled in above.
1233-
fn add_local_native_libraries(args: &mut ~[~str], sess: Session) {
1236+
fn add_local_native_libraries(args: &mut Vec<~str> , sess: Session) {
12341237
let addl_lib_search_paths = sess.opts.addl_lib_search_paths.borrow();
12351238
for path in addl_lib_search_paths.get().iter() {
12361239
// FIXME (#9639): This needs to handle non-utf8 paths
@@ -1263,7 +1266,7 @@ fn add_local_native_libraries(args: &mut ~[~str], sess: Session) {
12631266
// Rust crates are not considered at all when creating an rlib output. All
12641267
// dependencies will be linked when producing the final output (instead of
12651268
// the intermediate rlib version)
1266-
fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
1269+
fn add_upstream_rust_crates(args: &mut Vec<~str> , sess: Session,
12671270
dylib: bool, tmpdir: &Path) {
12681271

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

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

14071410
// Same thing as above, but for dynamic crates instead of static crates.
1408-
fn add_dynamic_crates(args: &mut ~[~str], sess: Session,
1409-
crates: ~[(ast::CrateNum, Path)]) {
1411+
fn add_dynamic_crates(args: &mut Vec<~str> , sess: Session,
1412+
crates: Vec<(ast::CrateNum, Path)> ) {
14101413
// If we're performing LTO, then it should have been previously required
14111414
// that all upstream rust dependencies were available in an rlib format.
14121415
assert!(!sess.lto());
@@ -1440,7 +1443,7 @@ fn add_upstream_rust_crates(args: &mut ~[~str], sess: Session,
14401443
// generic function calls a native function, then the generic function must
14411444
// be instantiated in the target crate, meaning that the native symbol must
14421445
// also be resolved in the target crate.
1443-
fn add_upstream_native_libraries(args: &mut ~[~str], sess: Session) {
1446+
fn add_upstream_native_libraries(args: &mut Vec<~str> , sess: Session) {
14441447
let cstore = sess.cstore;
14451448
cstore.iter_crate_data(|cnum, _| {
14461449
let libs = csearch::get_native_libraries(cstore, cnum);

src/librustc/back/mips.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use back::target_strs;
1212
use driver::session::sess_os_to_meta_os;
1313
use metadata::loader::meta_section_name;
14+
use std::vec_ng::Vec;
1415
use syntax::abi;
1516

1617
pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::t {
@@ -63,6 +64,6 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::
6364

6465
target_triple: target_triple,
6566

66-
cc_args: ~[],
67+
cc_args: Vec::new(),
6768
};
6869
}

src/librustc/back/rpath.rs

+20-19
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,22 @@ use metadata::filesearch;
1515

1616
use collections::HashSet;
1717
use std::{os, vec};
18+
use std::vec_ng::Vec;
1819
use syntax::abi;
1920

2021
fn not_win32(os: abi::Os) -> bool {
2122
os != abi::OsWin32
2223
}
2324

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

2728
// No rpath on windows
2829
if os == abi::OsWin32 {
29-
return ~[];
30+
return Vec::new();
3031
}
3132

32-
let mut flags = ~[];
33+
let mut flags = Vec::new();
3334

3435
if sess.targ_cfg.os == abi::OsFreebsd {
3536
flags.push_all([~"-Wl,-rpath,/usr/local/lib/gcc46",
@@ -49,7 +50,7 @@ pub fn get_rpath_flags(sess: session::Session, out_filename: &Path) -> ~[~str] {
4950

5051
let rpaths = get_rpaths(os, sysroot, output, libs,
5152
sess.opts.target_triple);
52-
flags.push_all(rpaths_to_flags(rpaths));
53+
flags.push_all(rpaths_to_flags(rpaths.as_slice()).as_slice());
5354
flags
5455
}
5556

@@ -60,8 +61,8 @@ fn get_sysroot_absolute_rt_lib(sess: session::Session) -> Path {
6061
p
6162
}
6263

63-
pub fn rpaths_to_flags(rpaths: &[~str]) -> ~[~str] {
64-
let mut ret = ~[];
64+
pub fn rpaths_to_flags(rpaths: &[~str]) -> Vec<~str> {
65+
let mut ret = Vec::new();
6566
for rpath in rpaths.iter() {
6667
ret.push("-Wl,-rpath," + *rpath);
6768
}
@@ -72,7 +73,7 @@ fn get_rpaths(os: abi::Os,
7273
sysroot: &Path,
7374
output: &Path,
7475
libs: &[Path],
75-
target_triple: &str) -> ~[~str] {
76+
target_triple: &str) -> Vec<~str> {
7677
debug!("sysroot: {}", sysroot.display());
7778
debug!("output: {}", output.display());
7879
debug!("libs:");
@@ -91,7 +92,7 @@ fn get_rpaths(os: abi::Os,
9192
let abs_rpaths = get_absolute_rpaths(libs);
9293

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

9697
fn log_rpaths(desc: &str, rpaths: &[~str]) {
9798
debug!("{} rpaths:", desc);
@@ -100,22 +101,22 @@ fn get_rpaths(os: abi::Os,
100101
}
101102
}
102103

103-
log_rpaths("relative", rel_rpaths);
104-
log_rpaths("absolute", abs_rpaths);
105-
log_rpaths("fallback", fallback_rpaths);
104+
log_rpaths("relative", rel_rpaths.as_slice());
105+
log_rpaths("absolute", abs_rpaths.as_slice());
106+
log_rpaths("fallback", fallback_rpaths.as_slice());
106107

107108
let mut rpaths = rel_rpaths;
108-
rpaths.push_all(abs_rpaths);
109-
rpaths.push_all(fallback_rpaths);
109+
rpaths.push_all(abs_rpaths.as_slice());
110+
rpaths.push_all(fallback_rpaths.as_slice());
110111

111112
// Remove duplicates
112-
let rpaths = minimize_rpaths(rpaths);
113+
let rpaths = minimize_rpaths(rpaths.as_slice());
113114
return rpaths;
114115
}
115116

116117
fn get_rpaths_relative_to_output(os: abi::Os,
117118
output: &Path,
118-
libs: &[Path]) -> ~[~str] {
119+
libs: &[Path]) -> Vec<~str> {
119120
libs.iter().map(|a| get_rpath_relative_to_output(os, output, a)).collect()
120121
}
121122

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

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

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

170-
pub fn minimize_rpaths(rpaths: &[~str]) -> ~[~str] {
171+
pub fn minimize_rpaths(rpaths: &[~str]) -> Vec<~str> {
171172
let mut set = HashSet::new();
172-
let mut minimized = ~[];
173+
let mut minimized = Vec::new();
173174
for rpath in rpaths.iter() {
174175
if set.insert(rpath.as_slice()) {
175176
minimized.push(rpath.clone());
@@ -190,7 +191,7 @@ mod test {
190191
#[test]
191192
fn test_rpaths_to_flags() {
192193
let flags = rpaths_to_flags([~"path1", ~"path2"]);
193-
assert_eq!(flags, ~[~"-Wl,-rpath,path1", ~"-Wl,-rpath,path2"]);
194+
assert_eq!(flags, vec!(~"-Wl,-rpath,path1", ~"-Wl,-rpath,path2"));
194195
}
195196
196197
#[test]

0 commit comments

Comments
 (0)