Skip to content

Commit e4c91e6

Browse files
committed
auto merge of #12735 : eddyb/rust/at-exodus-chapter-11, r=cmr
2 parents b6d5b8f + e2ebc8f commit e4c91e6

File tree

137 files changed

+5578
-6160
lines changed

Some content is hidden

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

137 files changed

+5578
-6160
lines changed

src/librustc/back/archive.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ use syntax::abi;
2828

2929
pub static METADATA_FILENAME: &'static str = "rust.metadata.bin";
3030

31-
pub struct Archive {
32-
priv sess: Session,
31+
pub struct Archive<'a> {
32+
priv sess: &'a Session,
3333
priv dst: Path,
3434
}
3535

3636
pub struct ArchiveRO {
3737
priv ptr: ArchiveRef,
3838
}
3939

40-
fn run_ar(sess: Session, args: &str, cwd: Option<&Path>,
41-
paths: &[&Path]) -> ProcessOutput {
40+
fn run_ar(sess: &Session, args: &str, cwd: Option<&Path>,
41+
paths: &[&Path]) -> ProcessOutput {
4242
let ar = get_ar_prog(sess);
4343

4444
let mut args = vec!(args.to_owned());
@@ -74,16 +74,16 @@ fn run_ar(sess: Session, args: &str, cwd: Option<&Path>,
7474
}
7575
}
7676

77-
impl Archive {
77+
impl<'a> Archive<'a> {
7878
/// Initializes a new static archive with the given object file
79-
pub fn create<'a>(sess: Session, dst: &'a Path,
80-
initial_object: &'a Path) -> Archive {
79+
pub fn create<'b>(sess: &'a Session, dst: &'b Path,
80+
initial_object: &'b Path) -> Archive<'a> {
8181
run_ar(sess, "crus", None, [dst, initial_object]);
8282
Archive { sess: sess, dst: dst.clone() }
8383
}
8484

8585
/// Opens an existing static archive
86-
pub fn open(sess: Session, dst: Path) -> Archive {
86+
pub fn open(sess: &'a Session, dst: Path) -> Archive<'a> {
8787
assert!(dst.exists());
8888
Archive { sess: sess, dst: dst }
8989
}
@@ -206,7 +206,7 @@ impl Archive {
206206
let unixlibname = format!("lib{}.a", name);
207207

208208
let mut rustpath = filesearch::rust_path();
209-
rustpath.push(self.sess.filesearch.get_target_lib_path());
209+
rustpath.push(self.sess.filesearch().get_target_lib_path());
210210
let addl_lib_search_paths = self.sess
211211
.opts
212212
.addl_lib_search_paths

src/librustc/back/link.rs

+38-39
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub enum OutputType {
5454
OutputTypeExe,
5555
}
5656

57-
pub fn llvm_err(sess: Session, msg: ~str) -> ! {
57+
pub fn llvm_err(sess: &Session, msg: ~str) -> ! {
5858
unsafe {
5959
let cstr = llvm::LLVMRustGetLastError();
6060
if cstr == ptr::null() {
@@ -68,7 +68,7 @@ pub fn llvm_err(sess: Session, msg: ~str) -> ! {
6868
}
6969

7070
pub fn WriteOutputFile(
71-
sess: Session,
71+
sess: &Session,
7272
target: lib::llvm::TargetMachineRef,
7373
pm: lib::llvm::PassManagerRef,
7474
m: ModuleRef,
@@ -125,7 +125,7 @@ pub mod write {
125125
}
126126
}
127127

128-
pub fn run_passes(sess: Session,
128+
pub fn run_passes(sess: &Session,
129129
trans: &CrateTranslation,
130130
output_types: &[OutputType],
131131
output: &OutputFilenames) {
@@ -156,7 +156,7 @@ pub mod write {
156156

157157
let tm = sess.targ_cfg.target_strs.target_triple.with_c_str(|t| {
158158
sess.opts.cg.target_cpu.with_c_str(|cpu| {
159-
target_feature(&sess).with_c_str(|features| {
159+
target_feature(sess).with_c_str(|features| {
160160
llvm::LLVMRustCreateTargetMachine(
161161
t, cpu, features,
162162
lib::llvm::CodeModelDefault,
@@ -323,7 +323,7 @@ pub mod write {
323323
}
324324
}
325325

326-
pub fn run_assembler(sess: Session, outputs: &OutputFilenames) {
326+
pub fn run_assembler(sess: &Session, outputs: &OutputFilenames) {
327327
let cc = super::get_cc_prog(sess);
328328
let assembly = outputs.temp_path(OutputTypeAssembly);
329329
let object = outputs.path(OutputTypeObject);
@@ -351,7 +351,7 @@ pub mod write {
351351
}
352352
}
353353

354-
unsafe fn configure_llvm(sess: Session) {
354+
unsafe fn configure_llvm(sess: &Session) {
355355
use sync::one::{Once, ONCE_INIT};
356356
static mut INIT: Once = ONCE_INIT;
357357

@@ -534,7 +534,7 @@ fn truncated_hash_result(symbol_hasher: &mut Sha256) -> ~str {
534534

535535

536536
// This calculates STH for a symbol, as defined above
537-
fn symbol_hash(tcx: ty::ctxt, symbol_hasher: &mut Sha256,
537+
fn symbol_hash(tcx: &ty::ctxt, symbol_hasher: &mut Sha256,
538538
t: ty::t, link_meta: &LinkMeta) -> ~str {
539539
// NB: do *not* use abbrevs here as we want the symbol names
540540
// to be independent of one another in the crate.
@@ -559,7 +559,7 @@ fn get_symbol_hash(ccx: &CrateContext, t: ty::t) -> ~str {
559559

560560
let mut type_hashcodes = ccx.type_hashcodes.borrow_mut();
561561
let mut symbol_hasher = ccx.symbol_hasher.borrow_mut();
562-
let hash = symbol_hash(ccx.tcx, symbol_hasher.get(), t, &ccx.link_meta);
562+
let hash = symbol_hash(ccx.tcx(), symbol_hasher.get(), t, &ccx.link_meta);
563563
type_hashcodes.get().insert(t, hash.clone());
564564
hash
565565
}
@@ -694,7 +694,7 @@ pub fn mangle_exported_name(ccx: &CrateContext, path: PathElems,
694694
pub fn mangle_internal_name_by_type_only(ccx: &CrateContext,
695695
t: ty::t,
696696
name: &str) -> ~str {
697-
let s = ppaux::ty_to_short_str(ccx.tcx, t);
697+
let s = ppaux::ty_to_short_str(ccx.tcx(), t);
698698
let path = [PathName(token::intern(name)),
699699
PathName(token::intern(s))];
700700
let hash = get_symbol_hash(ccx, t);
@@ -704,7 +704,7 @@ pub fn mangle_internal_name_by_type_only(ccx: &CrateContext,
704704
pub fn mangle_internal_name_by_type_and_seq(ccx: &CrateContext,
705705
t: ty::t,
706706
name: &str) -> ~str {
707-
let s = ppaux::ty_to_str(ccx.tcx, t);
707+
let s = ppaux::ty_to_str(ccx.tcx(), t);
708708
let path = [PathName(token::intern(s)),
709709
gensym_name(name)];
710710
let hash = get_symbol_hash(ccx, t);
@@ -719,7 +719,7 @@ pub fn output_lib_filename(id: &CrateId) -> ~str {
719719
format!("{}-{}-{}", id.name, crate_id_hash(id), id.version_or_default())
720720
}
721721

722-
pub fn get_cc_prog(sess: Session) -> ~str {
722+
pub fn get_cc_prog(sess: &Session) -> ~str {
723723
match sess.opts.cg.linker {
724724
Some(ref linker) => return linker.to_owned(),
725725
None => {}
@@ -737,7 +737,7 @@ pub fn get_cc_prog(sess: Session) -> ~str {
737737
get_system_tool(sess, "cc")
738738
}
739739

740-
pub fn get_ar_prog(sess: Session) -> ~str {
740+
pub fn get_ar_prog(sess: &Session) -> ~str {
741741
match sess.opts.cg.ar {
742742
Some(ref ar) => return ar.to_owned(),
743743
None => {}
@@ -746,7 +746,7 @@ pub fn get_ar_prog(sess: Session) -> ~str {
746746
get_system_tool(sess, "ar")
747747
}
748748

749-
fn get_system_tool(sess: Session, tool: &str) -> ~str {
749+
fn get_system_tool(sess: &Session, tool: &str) -> ~str {
750750
match sess.targ_cfg.os {
751751
abi::OsAndroid => match sess.opts.cg.android_cross_path {
752752
Some(ref path) => {
@@ -765,7 +765,7 @@ fn get_system_tool(sess: Session, tool: &str) -> ~str {
765765
}
766766
}
767767

768-
fn remove(sess: Session, path: &Path) {
768+
fn remove(sess: &Session, path: &Path) {
769769
match fs::unlink(path) {
770770
Ok(..) => {}
771771
Err(e) => {
@@ -776,7 +776,7 @@ fn remove(sess: Session, path: &Path) {
776776

777777
/// Perform the linkage portion of the compilation phase. This will generate all
778778
/// of the requested outputs for this compilation session.
779-
pub fn link_binary(sess: Session,
779+
pub fn link_binary(sess: &Session,
780780
trans: &CrateTranslation,
781781
outputs: &OutputFilenames,
782782
id: &CrateId) -> Vec<Path> {
@@ -830,7 +830,7 @@ pub fn filename_for_input(sess: &Session, crate_type: session::CrateType,
830830
}
831831
}
832832

833-
fn link_binary_output(sess: Session,
833+
fn link_binary_output(sess: &Session,
834834
trans: &CrateTranslation,
835835
crate_type: session::CrateType,
836836
outputs: &OutputFilenames,
@@ -840,7 +840,7 @@ fn link_binary_output(sess: Session,
840840
Some(ref file) => file.clone(),
841841
None => {
842842
let out_filename = outputs.path(OutputTypeExe);
843-
filename_for_input(&sess, crate_type, id, &out_filename)
843+
filename_for_input(sess, crate_type, id, &out_filename)
844844
}
845845
};
846846

@@ -883,10 +883,10 @@ fn link_binary_output(sess: Session,
883883
// rlib primarily contains the object file of the crate, but it also contains
884884
// all of the object files from native libraries. This is done by unzipping
885885
// native libraries and inserting all of the contents into this archive.
886-
fn link_rlib(sess: Session,
887-
trans: Option<&CrateTranslation>, // None == no metadata/bytecode
888-
obj_filename: &Path,
889-
out_filename: &Path) -> Archive {
886+
fn link_rlib<'a>(sess: &'a Session,
887+
trans: Option<&CrateTranslation>, // None == no metadata/bytecode
888+
obj_filename: &Path,
889+
out_filename: &Path) -> Archive<'a> {
890890
let mut a = Archive::create(sess, out_filename, obj_filename);
891891

892892
let used_libraries = sess.cstore.get_used_libraries();
@@ -985,7 +985,7 @@ fn link_rlib(sess: Session,
985985
// There's no need to include metadata in a static archive, so ensure to not
986986
// link in the metadata object file (and also don't prepare the archive with a
987987
// metadata file).
988-
fn link_staticlib(sess: Session, obj_filename: &Path, out_filename: &Path) {
988+
fn link_staticlib(sess: &Session, obj_filename: &Path, out_filename: &Path) {
989989
let mut a = link_rlib(sess, None, obj_filename, out_filename);
990990
a.add_native_library("morestack").unwrap();
991991
a.add_native_library("compiler-rt").unwrap();
@@ -1000,7 +1000,7 @@ fn link_staticlib(sess: Session, obj_filename: &Path, out_filename: &Path) {
10001000
}
10011001
};
10021002
a.add_rlib(&p, name, sess.lto()).unwrap();
1003-
let native_libs = csearch::get_native_libraries(sess.cstore, cnum);
1003+
let native_libs = csearch::get_native_libraries(&sess.cstore, cnum);
10041004
for &(kind, ref lib) in native_libs.iter() {
10051005
let name = match kind {
10061006
cstore::NativeStatic => "static library",
@@ -1016,7 +1016,7 @@ fn link_staticlib(sess: Session, obj_filename: &Path, out_filename: &Path) {
10161016
//
10171017
// This will invoke the system linker/cc to create the resulting file. This
10181018
// links to all upstream files as well.
1019-
fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
1019+
fn link_natively(sess: &Session, dylib: bool, obj_filename: &Path,
10201020
out_filename: &Path) {
10211021
let tmpdir = TempDir::new("rustc").expect("needs a temp dir");
10221022
// The invocations of cc share some flags across platforms
@@ -1066,7 +1066,7 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
10661066
}
10671067
}
10681068

1069-
fn link_args(sess: Session,
1069+
fn link_args(sess: &Session,
10701070
dylib: bool,
10711071
tmpdir: &Path,
10721072
obj_filename: &Path,
@@ -1075,7 +1075,7 @@ fn link_args(sess: Session,
10751075
// The default library location, we need this to find the runtime.
10761076
// The location of crates will be determined as needed.
10771077
// FIXME (#9639): This needs to handle non-utf8 paths
1078-
let lib_path = sess.filesearch.get_target_lib_path();
1078+
let lib_path = sess.filesearch().get_target_lib_path();
10791079
let stage: ~str = ~"-L" + lib_path.as_str().unwrap();
10801080

10811081
let mut args = vec!(stage);
@@ -1248,7 +1248,7 @@ fn link_args(sess: Session,
12481248
// Also note that the native libraries linked here are only the ones located
12491249
// in the current crate. Upstream crates with native library dependencies
12501250
// may have their native library pulled in above.
1251-
fn add_local_native_libraries(args: &mut Vec<~str> , sess: Session) {
1251+
fn add_local_native_libraries(args: &mut Vec<~str>, sess: &Session) {
12521252
let addl_lib_search_paths = sess.opts.addl_lib_search_paths.borrow();
12531253
for path in addl_lib_search_paths.get().iter() {
12541254
// FIXME (#9639): This needs to handle non-utf8 paths
@@ -1281,7 +1281,7 @@ fn add_local_native_libraries(args: &mut Vec<~str> , sess: Session) {
12811281
// Rust crates are not considered at all when creating an rlib output. All
12821282
// dependencies will be linked when producing the final output (instead of
12831283
// the intermediate rlib version)
1284-
fn add_upstream_rust_crates(args: &mut Vec<~str> , sess: Session,
1284+
fn add_upstream_rust_crates(args: &mut Vec<~str>, sess: &Session,
12851285
dylib: bool, tmpdir: &Path) {
12861286

12871287
// As a limitation of the current implementation, we require that everything
@@ -1302,8 +1302,8 @@ fn add_upstream_rust_crates(args: &mut Vec<~str> , sess: Session,
13021302
// * If one form of linking fails, the second is also attempted
13031303
// * If both forms fail, then we emit an error message
13041304

1305-
let dynamic = get_deps(sess.cstore, cstore::RequireDynamic);
1306-
let statik = get_deps(sess.cstore, cstore::RequireStatic);
1305+
let dynamic = get_deps(&sess.cstore, cstore::RequireDynamic);
1306+
let statik = get_deps(&sess.cstore, cstore::RequireStatic);
13071307
match (dynamic, statik, sess.opts.cg.prefer_dynamic, dylib) {
13081308
(_, Some(deps), false, false) => {
13091309
add_static_crates(args, sess, tmpdir, deps)
@@ -1352,9 +1352,8 @@ fn add_upstream_rust_crates(args: &mut Vec<~str> , sess: Session,
13521352
}
13531353

13541354
// Converts a library file-stem into a cc -l argument
1355-
fn unlib(config: @session::Config, stem: &str) -> ~str {
1356-
if stem.starts_with("lib") &&
1357-
config.os != abi::OsWin32 {
1355+
fn unlib(config: &session::Config, stem: &str) -> ~str {
1356+
if stem.starts_with("lib") && config.os != abi::OsWin32 {
13581357
stem.slice(3, stem.len()).to_owned()
13591358
} else {
13601359
stem.to_owned()
@@ -1376,8 +1375,8 @@ fn add_upstream_rust_crates(args: &mut Vec<~str> , sess: Session,
13761375
}
13771376

13781377
// Adds the static "rlib" versions of all crates to the command line.
1379-
fn add_static_crates(args: &mut Vec<~str> , sess: Session, tmpdir: &Path,
1380-
crates: Vec<(ast::CrateNum, Path)> ) {
1378+
fn add_static_crates(args: &mut Vec<~str>, sess: &Session, tmpdir: &Path,
1379+
crates: Vec<(ast::CrateNum, Path)>) {
13811380
for (cnum, cratepath) in crates.move_iter() {
13821381
// When performing LTO on an executable output, all of the
13831382
// bytecode from the upstream libraries has already been
@@ -1423,7 +1422,7 @@ fn add_upstream_rust_crates(args: &mut Vec<~str> , sess: Session,
14231422
}
14241423

14251424
// Same thing as above, but for dynamic crates instead of static crates.
1426-
fn add_dynamic_crates(args: &mut Vec<~str> , sess: Session,
1425+
fn add_dynamic_crates(args: &mut Vec<~str>, sess: &Session,
14271426
crates: Vec<(ast::CrateNum, Path)> ) {
14281427
// If we're performing LTO, then it should have been previously required
14291428
// that all upstream rust dependencies were available in an rlib format.
@@ -1434,7 +1433,7 @@ fn add_upstream_rust_crates(args: &mut Vec<~str> , sess: Session,
14341433
// what its name is
14351434
let dir = cratepath.dirname_str().unwrap();
14361435
if !dir.is_empty() { args.push("-L" + dir); }
1437-
let libarg = unlib(sess.targ_cfg, cratepath.filestem_str().unwrap());
1436+
let libarg = unlib(&sess.targ_cfg, cratepath.filestem_str().unwrap());
14381437
args.push("-l" + libarg);
14391438
}
14401439
}
@@ -1458,8 +1457,8 @@ fn add_upstream_rust_crates(args: &mut Vec<~str> , sess: Session,
14581457
// generic function calls a native function, then the generic function must
14591458
// be instantiated in the target crate, meaning that the native symbol must
14601459
// also be resolved in the target crate.
1461-
fn add_upstream_native_libraries(args: &mut Vec<~str> , sess: Session) {
1462-
let cstore = sess.cstore;
1460+
fn add_upstream_native_libraries(args: &mut Vec<~str>, sess: &Session) {
1461+
let cstore = &sess.cstore;
14631462
cstore.iter_crate_data(|cnum, _| {
14641463
let libs = csearch::get_native_libraries(cstore, cnum);
14651464
for &(kind, ref lib) in libs.iter() {

src/librustc/back/lto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use util::common::time;
1818
use std::libc;
1919
use flate;
2020

21-
pub fn run(sess: session::Session, llmod: ModuleRef,
21+
pub fn run(sess: &session::Session, llmod: ModuleRef,
2222
tm: TargetMachineRef, reachable: &[~str]) {
2323
if sess.opts.cg.prefer_dynamic {
2424
sess.err("cannot prefer dynamic linking when performing LTO");

src/librustc/back/rpath.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111

12-
use driver::session;
12+
use driver::session::Session;
1313
use metadata::cstore;
1414
use metadata::filesearch;
1515

@@ -22,7 +22,7 @@ fn not_win32(os: abi::Os) -> bool {
2222
os != abi::OsWin32
2323
}
2424

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

2828
// No rpath on windows
@@ -40,7 +40,7 @@ pub fn get_rpath_flags(sess: session::Session, out_filename: &Path) -> Vec<~str>
4040

4141
debug!("preparing the RPATH!");
4242

43-
let sysroot = sess.filesearch.sysroot;
43+
let sysroot = sess.filesearch().sysroot;
4444
let output = out_filename;
4545
let libs = sess.cstore.get_used_crates(cstore::RequireDynamic);
4646
let libs = libs.move_iter().filter_map(|(_, l)| l.map(|p| p.clone())).collect();
@@ -54,9 +54,9 @@ pub fn get_rpath_flags(sess: session::Session, out_filename: &Path) -> Vec<~str>
5454
flags
5555
}
5656

57-
fn get_sysroot_absolute_rt_lib(sess: session::Session) -> Path {
57+
fn get_sysroot_absolute_rt_lib(sess: &Session) -> Path {
5858
let r = filesearch::relative_target_lib_path(sess.opts.target_triple);
59-
let mut p = sess.filesearch.sysroot.join(&r);
59+
let mut p = sess.filesearch().sysroot.join(&r);
6060
p.push(os::dll_filename("rustrt"));
6161
p
6262
}

0 commit comments

Comments
 (0)