From 604c9534c226f54afaf50816a6181e471cb9a7cf Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Thu, 26 Sep 2013 21:02:20 -0400 Subject: [PATCH] librustc: Don't pass around Session with @ and make building_library just bool instead of @mut bool. --- src/librustc/back/link.rs | 56 +++++----- src/librustc/back/rpath.rs | 4 +- src/librustc/driver/driver.rs | 127 ++++++++++------------ src/librustc/driver/session.rs | 10 +- src/librustc/front/assign_node_ids.rs | 8 +- src/librustc/front/std_inject.rs | 10 +- src/librustc/front/test.rs | 47 ++++---- src/librustc/middle/astencode.rs | 2 +- src/librustc/middle/check_const.rs | 89 +++++++-------- src/librustc/middle/entry.rs | 12 +- src/librustc/middle/lang_items.rs | 6 +- src/librustc/middle/lint.rs | 2 +- src/librustc/middle/region.rs | 27 ++--- src/librustc/middle/resolve.rs | 15 ++- src/librustc/middle/trans/_match.rs | 18 +-- src/librustc/middle/trans/adt.rs | 16 +-- src/librustc/middle/trans/base.rs | 127 +++++++++++----------- src/librustc/middle/trans/builder.rs | 10 +- src/librustc/middle/trans/cabi.rs | 2 +- src/librustc/middle/trans/cabi_x86.rs | 2 +- src/librustc/middle/trans/callee.rs | 2 +- src/librustc/middle/trans/closure.rs | 4 +- src/librustc/middle/trans/common.rs | 13 +-- src/librustc/middle/trans/consts.rs | 38 +++---- src/librustc/middle/trans/context.rs | 22 ++-- src/librustc/middle/trans/controlflow.rs | 5 +- src/librustc/middle/trans/datum.rs | 3 +- src/librustc/middle/trans/debuginfo.rs | 85 ++++++++------- src/librustc/middle/trans/expr.rs | 24 ++-- src/librustc/middle/trans/foreign.rs | 20 ++-- src/librustc/middle/trans/glue.rs | 4 +- src/librustc/middle/trans/inline.rs | 4 +- src/librustc/middle/trans/intrinsic.rs | 16 +-- src/librustc/middle/trans/macros.rs | 4 +- src/librustc/middle/trans/meth.rs | 6 +- src/librustc/middle/trans/monomorphize.rs | 8 +- src/librustc/middle/trans/reflect.rs | 4 +- src/librustc/middle/trans/type_of.rs | 14 +-- src/librustc/middle/trans/write_guard.rs | 2 +- src/librustc/middle/ty.rs | 11 +- src/librustc/middle/typeck/coherence.rs | 34 +++--- src/librustc/middle/typeck/mod.rs | 2 +- src/librustc/rustc.rs | 10 +- src/librustdoc/core.rs | 18 +-- src/librusti/rusti.rs | 68 ++++++------ src/librustpkg/rustpkg.rs | 18 ++- src/librustpkg/util.rs | 28 +++-- 47 files changed, 523 insertions(+), 534 deletions(-) diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index ee7fbed9e9f11..0aa5ace70ac4e 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -54,7 +54,7 @@ fn write_string(writer: &mut W, string: &str) { writer.write(string.as_bytes()); } -pub fn llvm_err(sess: Session, msg: ~str) -> ! { +pub fn llvm_err(sess: &Session, msg: ~str) -> ! { unsafe { let cstr = llvm::LLVMRustGetLastError(); if cstr == ptr::null() { @@ -66,7 +66,7 @@ pub fn llvm_err(sess: Session, msg: ~str) -> ! { } pub fn WriteOutputFile( - sess: Session, + sess: &Session, Target: lib::llvm::TargetMachineRef, PM: lib::llvm::PassManagerRef, M: ModuleRef, @@ -113,7 +113,7 @@ pub mod jit { } } - pub fn exec(sess: Session, + pub fn exec(sess: &Session, c: ContextRef, m: ModuleRef, stacks: bool) { @@ -220,7 +220,7 @@ pub mod write { use std::run; use std::str; - pub fn run_passes(sess: Session, + pub fn run_passes(sess: &Session, llcx: ContextRef, llmod: ModuleRef, output_type: output_type, @@ -370,7 +370,7 @@ pub mod write { } } - pub fn run_assembler(sess: Session, assembly: &Path, object: &Path) { + pub fn run_assembler(sess: &Session, assembly: &Path, object: &Path) { let cc_prog = super::get_cc_prog(sess); let cc_args = ~[ @@ -390,7 +390,7 @@ pub mod write { } } - unsafe fn configure_llvm(sess: Session) { + unsafe fn configure_llvm(sess: &Session) { // Copy what clan does by turning on loop vectorization at O2 and // slp vectorization at O3 let vectorize_loop = !sess.no_vectorize_loops() && @@ -511,7 +511,7 @@ pub mod write { * */ -pub fn build_link_meta(sess: Session, +pub fn build_link_meta(sess: &Session, c: &ast::Crate, output: &Path, symbol_hasher: &mut hash::State) @@ -523,7 +523,7 @@ pub fn build_link_meta(sess: Session, cmh_items: ~[@ast::MetaItem] } - fn provided_link_metas(sess: Session, c: &ast::Crate) -> + fn provided_link_metas(sess: &Session, c: &ast::Crate) -> ProvidedMetas { let mut name = None; let mut vers = None; @@ -597,13 +597,13 @@ pub fn build_link_meta(sess: Session, return truncated_hash_result(symbol_hasher).to_managed(); } - fn warn_missing(sess: Session, name: &str, default: &str) { - if !*sess.building_library { return; } + fn warn_missing(sess: &Session, name: &str, default: &str) { + if !sess.building_library { return; } sess.warn(fmt!("missing crate link meta `%s`, using `%s` as default", name, default)); } - fn crate_meta_name(sess: Session, output: &Path, opt_name: Option<@str>) + fn crate_meta_name(sess: &Session, output: &Path, opt_name: Option<@str>) -> @str { match opt_name { Some(v) if !v.is_empty() => v, @@ -625,7 +625,7 @@ pub fn build_link_meta(sess: Session, } } - fn crate_meta_vers(sess: Session, opt_vers: Option<@str>) -> @str { + fn crate_meta_vers(sess: &Session, opt_vers: Option<@str>) -> @str { match opt_vers { Some(v) if !v.is_empty() => v, _ => { @@ -742,7 +742,7 @@ pub fn sanitize(s: &str) -> ~str { return result; } -pub fn mangle(sess: Session, ss: path, +pub fn mangle(sess: &Session, ss: path, hash: Option<&str>, vers: Option<&str>) -> ~str { // Follow C++ namespace-mangling style, see // http://en.wikipedia.org/wiki/Name_mangling for more info. @@ -805,7 +805,7 @@ pub fn mangle(sess: Session, ss: path, n } -pub fn exported_name(sess: Session, +pub fn exported_name(sess: &Session, path: path, hash: &str, vers: &str) -> ~str { @@ -824,7 +824,7 @@ pub fn mangle_exported_name(ccx: &mut CrateContext, path: path, t: ty::t) -> ~str { let hash = get_symbol_hash(ccx, t); - return exported_name(ccx.sess, path, + return exported_name(ccx.tcx.sess, path, hash, ccx.link_meta.vers); } @@ -834,9 +834,9 @@ pub fn mangle_internal_name_by_type_only(ccx: &mut CrateContext, name: &str) -> ~str { let s = ppaux::ty_to_short_str(ccx.tcx, t); let hash = get_symbol_hash(ccx, t); - return mangle(ccx.sess, - ~[path_name(ccx.sess.ident_of(name)), - path_name(ccx.sess.ident_of(s))], + return mangle(ccx.tcx.sess, + ~[path_name(ccx.tcx.sess.ident_of(name)), + path_name(ccx.tcx.sess.ident_of(s))], Some(hash.as_slice()), None); } @@ -847,8 +847,8 @@ pub fn mangle_internal_name_by_type_and_seq(ccx: &mut CrateContext, let s = ppaux::ty_to_str(ccx.tcx, t); let hash = get_symbol_hash(ccx, t); let (_, name) = gensym_name(name); - return mangle(ccx.sess, - ~[path_name(ccx.sess.ident_of(s)), name], + return mangle(ccx.tcx.sess, + ~[path_name(ccx.tcx.sess.ident_of(s)), name], Some(hash.as_slice()), None); } @@ -858,11 +858,11 @@ pub fn mangle_internal_name_by_path_and_seq(ccx: &mut CrateContext, flav: &str) -> ~str { let (_, name) = gensym_name(flav); path.push(name); - mangle(ccx.sess, path, None, None) + mangle(ccx.tcx.sess, path, None, None) } pub fn mangle_internal_name_by_path(ccx: &mut CrateContext, path: path) -> ~str { - mangle(ccx.sess, path, None, None) + mangle(ccx.tcx.sess, path, None, None) } @@ -877,7 +877,7 @@ pub fn output_dll_filename(os: session::Os, lm: LinkMeta) -> ~str { fmt!("%s%s-%s-%s%s", dll_prefix, lm.name, lm.extras_hash, lm.vers, dll_suffix) } -pub fn get_cc_prog(sess: Session) -> ~str { +pub fn get_cc_prog(sess: &Session) -> ~str { // In the future, FreeBSD will use clang as default compiler. // It would be flexible to use cc (system's default C compiler) // instead of hard-coded gcc. @@ -905,7 +905,7 @@ pub fn get_cc_prog(sess: Session) -> ~str { // If the user wants an exe generated we need to invoke // cc to link the object file with some libs -pub fn link_binary(sess: Session, +pub fn link_binary(sess: &Session, obj_filename: &Path, out_filename: &Path, lm: LinkMeta) { @@ -913,7 +913,7 @@ pub fn link_binary(sess: Session, let cc_prog = get_cc_prog(sess); // The invocations of cc share some flags across platforms - let output = if *sess.building_library { + let output = if sess.building_library { let long_libname = output_dll_filename(sess.targ_cfg.os, lm); debug!("link_meta.name: %s", lm.name); debug!("long_libname: %s", long_libname); @@ -957,7 +957,7 @@ pub fn link_binary(sess: Session, } } -pub fn link_args(sess: Session, +pub fn link_args(sess: &Session, obj_filename: &Path, out_filename: &Path, lm:LinkMeta) -> ~[~str] { @@ -973,7 +973,7 @@ pub fn link_args(sess: Session, } - let output = if *sess.building_library { + let output = if sess.building_library { let long_libname = output_dll_filename(sess.targ_cfg.os, lm); out_filename.dir_path().push(long_libname) } else { @@ -1042,7 +1042,7 @@ pub fn link_args(sess: Session, let used_libs = cstore::get_used_libraries(cstore); for l in used_libs.iter() { args.push(~"-l" + *l); } - if *sess.building_library { + if sess.building_library { args.push(lib_cmd); // On mac we need to tell the linker to let this library diff --git a/src/librustc/back/rpath.rs b/src/librustc/back/rpath.rs index fa111a0161577..3af60db9f5d94 100644 --- a/src/librustc/back/rpath.rs +++ b/src/librustc/back/rpath.rs @@ -20,7 +20,7 @@ fn not_win32(os: session::Os) -> bool { os != session::OsWin32 } -pub fn get_rpath_flags(sess: session::Session, out_filename: &Path) +pub fn get_rpath_flags(sess: &session::Session, out_filename: &Path) -> ~[~str] { let os = sess.targ_cfg.os; @@ -43,7 +43,7 @@ pub fn get_rpath_flags(sess: session::Session, out_filename: &Path) rpaths_to_flags(rpaths) } -fn get_sysroot_absolute_rt_lib(sess: session::Session) -> Path { +fn get_sysroot_absolute_rt_lib(sess: &session::Session) -> Path { let r = filesearch::relative_target_lib_path(sess.opts.target_triple); sess.filesearch.sysroot().push_rel(&r).push(os::dll_filename("rustrt")) } diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index df3a40c228942..f43c392367b06 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -12,7 +12,7 @@ use back::link; use back::{arm, x86, x86_64, mips}; use driver::session::{Aggressive}; -use driver::session::{Session, Session_, No, Less, Default}; +use driver::session::{Session, No, Less, Default}; use driver::session; use front; use lib::llvm::llvm; @@ -63,7 +63,7 @@ pub fn source_name(input: &input) -> @str { } } -pub fn default_configuration(sess: Session) -> +pub fn default_configuration(sess: &Session) -> ast::CrateConfig { let tos = match sess.targ_cfg.os { session::OsWin32 => @"win32", @@ -75,7 +75,7 @@ pub fn default_configuration(sess: Session) -> // ARM is bi-endian, however using NDK seems to default // to little-endian unless a flag is provided. - let (end,arch,wordsz) = match sess.targ_cfg.arch { + let (end, arch, wordsz) = match sess.targ_cfg.arch { abi::X86 => (@"little", @"x86", @"32"), abi::X86_64 => (@"little", @"x86_64", @"64"), abi::Arm => (@"little", @"arm", @"32"), @@ -99,8 +99,7 @@ pub fn append_configuration(cfg: &mut ast::CrateConfig, name: @str) { } } -pub fn build_configuration(sess: Session) -> - ast::CrateConfig { +pub fn build_configuration(sess: &Session) -> ast::CrateConfig { // Combine the configuration requested by the session (command line) with // some default and generated configuration items let default_cfg = default_configuration(sess); @@ -113,8 +112,7 @@ pub fn build_configuration(sess: Session) -> } // Convert strings provided as --cfg [cfgspec] into a crate_cfg -fn parse_cfgspecs(cfgspecs: ~[~str], demitter: @diagnostic::Emitter) - -> ast::CrateConfig { +fn parse_cfgspecs(cfgspecs: ~[~str], demitter: @diagnostic::Emitter) -> ast::CrateConfig { do cfgspecs.move_iter().map |s| { let sess = parse::new_parse_sess(Some(demitter)); parse::parse_meta_from_source_str(@"cfgspec", s.to_managed(), ~[], sess) @@ -129,7 +127,7 @@ pub enum input { str_input(@str) } -pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &input) +pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &input) -> @ast::Crate { time(sess.time_passes(), ~"parsing", || { match *input { @@ -151,13 +149,13 @@ pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &input) /// syntax expansion, secondary `cfg` expansion, synthesis of a test /// harness if one is to be provided and injection of a dependency on the /// standard library and prelude. -pub fn phase_2_configure_and_expand(sess: Session, +pub fn phase_2_configure_and_expand(sess: &mut Session, cfg: ast::CrateConfig, mut crate: @ast::Crate) -> @ast::Crate { let time_passes = sess.time_passes(); - *sess.building_library = session::building_library(sess.opts.crate_type, - crate, sess.opts.test); + sess.building_library = session::building_library(sess.opts.crate_type, + crate, sess.opts.test); // strip before expansion to allow macros to depend on @@ -184,13 +182,13 @@ pub fn phase_2_configure_and_expand(sess: Session, front::config::strip_unconfigured_items(crate)); crate = time(time_passes, ~"maybe building test harness", || - front::test::modify_for_testing(sess, crate)); + front::test::modify_for_testing(&*sess, crate)); crate = time(time_passes, ~"std injection", || - front::std_inject::maybe_inject_libstd_ref(sess, crate)); + front::std_inject::maybe_inject_libstd_ref(&*sess, crate)); crate = time(time_passes, ~"assigning node ids", || - front::assign_node_ids::assign_node_ids(sess, crate)); + front::assign_node_ids::assign_node_ids(&*sess, crate)); return crate; } @@ -206,8 +204,7 @@ pub struct CrateAnalysis { /// Run the resolution, typechecking, region checking and other /// miscellaneous analysis passes on the crate. Return various /// structures carrying the results of the analysis. -pub fn phase_3_run_analysis_passes(sess: Session, - crate: @ast::Crate) -> CrateAnalysis { +pub fn phase_3_run_analysis_passes(sess: &Session, crate: @ast::Crate) -> CrateAnalysis { let time_passes = sess.time_passes(); @@ -242,22 +239,20 @@ pub fn phase_3_run_analysis_passes(sess: Session, middle::region::resolve_crate(sess, def_map, crate)); let rp_set = time(time_passes, ~"region parameterization inference", || - middle::region::determine_rp_in_crate(sess, ast_map, def_map, crate)); + middle::region::determine_rp_in_crate(sess.cstore, ast_map, def_map, crate)); let ty_cx = ty::mk_ctxt(sess, def_map, ast_map, freevars, region_map, rp_set, lang_items); // passes are timed inside typeck - let (method_map, vtable_map) = typeck::check_crate( - ty_cx, trait_map, crate); + let (method_map, vtable_map) = typeck::check_crate(ty_cx, trait_map, crate); // These next two const passes can probably be merged time(time_passes, ~"const marking", || middle::const_eval::process_crate(crate, ty_cx)); time(time_passes, ~"const checking", || - middle::check_const::check_crate(sess, crate, ast_map, def_map, - method_map, ty_cx)); + middle::check_const::check_crate(crate, ast_map, def_map, method_map, ty_cx)); let exported_items = time(time_passes, ~"privacy checking", || @@ -278,12 +273,10 @@ pub fn phase_3_run_analysis_passes(sess: Session, middle::moves::compute_moves(ty_cx, method_map, crate)); time(time_passes, ~"match checking", || - middle::check_match::check_crate(ty_cx, method_map, - moves_map, crate)); + middle::check_match::check_crate(ty_cx, method_map, moves_map, crate)); time(time_passes, ~"liveness checking", || - middle::liveness::check_crate(ty_cx, method_map, - capture_map, crate)); + middle::liveness::check_crate(ty_cx, method_map, capture_map, crate)); let (root_map, write_guard_map) = time(time_passes, ~"borrow checking", || @@ -324,18 +317,16 @@ pub struct CrateTranslation { /// Run the translation phase to LLVM, after which the AST and analysis can /// be discarded. -pub fn phase_4_translate_to_llvm(sess: Session, - crate: @ast::Crate, +pub fn phase_4_translate_to_llvm(crate: @ast::Crate, analysis: &CrateAnalysis, outputs: &OutputFilenames) -> CrateTranslation { - time(sess.time_passes(), ~"translation", || - trans::base::trans_crate(sess, crate, analysis, - &outputs.obj_filename)) + time(analysis.ty_cx.sess.time_passes(), ~"translation", || + trans::base::trans_crate(crate, analysis, &outputs.obj_filename)) } /// Run LLVM itself, producing a bitcode file, assembly file or object file /// as a side effect. -pub fn phase_5_run_llvm_passes(sess: Session, +pub fn phase_5_run_llvm_passes(sess: &Session, trans: &CrateTranslation, outputs: &OutputFilenames) { @@ -374,7 +365,7 @@ pub fn phase_5_run_llvm_passes(sess: Session, /// Run the linker on any artifacts that resulted from the LLVM run. /// This should produce either a finished executable or library. -pub fn phase_6_link_output(sess: Session, +pub fn phase_6_link_output(sess: &Session, trans: &CrateTranslation, outputs: &OutputFilenames) { time(sess.time_passes(), ~"linking", || @@ -384,7 +375,7 @@ pub fn phase_6_link_output(sess: Session, trans.link)); } -pub fn stop_after_phase_3(sess: Session) -> bool { +pub fn stop_after_phase_3(sess: &Session) -> bool { if sess.opts.no_trans { debug!("invoked with --no-trans, returning early from compile_input"); return true; @@ -392,7 +383,7 @@ pub fn stop_after_phase_3(sess: Session) -> bool { return false; } -pub fn stop_after_phase_1(sess: Session) -> bool { +pub fn stop_after_phase_1(sess: &Session) -> bool { if sess.opts.parse_only { debug!("invoked with --parse-only, returning early from compile_input"); return true; @@ -400,13 +391,13 @@ pub fn stop_after_phase_1(sess: Session) -> bool { return false; } -pub fn stop_after_phase_5(sess: Session) -> bool { +pub fn stop_after_phase_5(sess: &Session) -> bool { if sess.opts.output_type != link::output_type_exe { debug!("not building executable, returning early from compile_input"); return true; } - if sess.opts.is_static && *sess.building_library { + if sess.opts.is_static && sess.building_library { debug!("building static library, returning early from compile_input"); return true; } @@ -419,27 +410,26 @@ pub fn stop_after_phase_5(sess: Session) -> bool { } #[fixed_stack_segment] -pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &input, +pub fn compile_input(sess: &mut Session, cfg: ast::CrateConfig, input: &input, outdir: &Option, output: &Option) { // We need nested scopes here, because the intermediate results can keep // large chunks of memory alive and we want to free them as soon as // possible to keep the peak memory usage low let (outputs, trans) = { let expanded_crate = { - let crate = phase_1_parse_input(sess, cfg.clone(), input); - if stop_after_phase_1(sess) { return; } + let crate = phase_1_parse_input(&*sess, cfg.clone(), input); + if stop_after_phase_1(&*sess) { return; } phase_2_configure_and_expand(sess, cfg, crate) }; - let analysis = phase_3_run_analysis_passes(sess, expanded_crate); - if stop_after_phase_3(sess) { return; } - let outputs = build_output_filenames(input, outdir, output, [], sess); - let trans = phase_4_translate_to_llvm(sess, expanded_crate, - &analysis, outputs); + let analysis = phase_3_run_analysis_passes(&*sess, expanded_crate); + if stop_after_phase_3(&*sess) { return; } + let outputs = build_output_filenames(input, outdir, output, [], &*sess); + let trans = phase_4_translate_to_llvm(expanded_crate, &analysis, outputs); (outputs, trans) }; - phase_5_run_llvm_passes(sess, &trans, outputs); - if stop_after_phase_5(sess) { return; } - phase_6_link_output(sess, &trans, outputs); + phase_5_run_llvm_passes(&*sess, &trans, outputs); + if stop_after_phase_5(&*sess) { return; } + phase_6_link_output(&*sess, &trans, outputs); } struct IdentifiedAnnotation { @@ -502,7 +492,7 @@ impl pprust::pp_ann for TypedAnnotation { } } -pub fn pretty_print_input(sess: Session, +pub fn pretty_print_input(mut sess: Session, cfg: ast::CrateConfig, input: &input, ppm: PpMode) { @@ -519,15 +509,18 @@ pub fn pretty_print_input(sess: Session, } } - let crate = phase_1_parse_input(sess, cfg.clone(), input); + let crate = phase_1_parse_input(&sess, cfg.clone(), input); let (crate, is_expanded) = match ppm { PpmExpanded | PpmExpandedIdentified | PpmTyped => { - (phase_2_configure_and_expand(sess, cfg, crate), true) + (phase_2_configure_and_expand(&mut sess, cfg, crate), true) } _ => (crate, false) }; + let codemap = sess.codemap; + let span_diag = sess.span_diagnostic; + let annotation = match ppm { PpmIdentified | PpmExpandedIdentified => { @IdentifiedAnnotation { @@ -535,7 +528,7 @@ pub fn pretty_print_input(sess: Session, } as @pprust::pp_ann } PpmTyped => { - let analysis = phase_3_run_analysis_passes(sess, crate); + let analysis = phase_3_run_analysis_passes(&sess, crate); @TypedAnnotation { analysis: analysis } as @pprust::pp_ann @@ -543,11 +536,11 @@ pub fn pretty_print_input(sess: Session, _ => @pprust::no_ann::new() as @pprust::pp_ann, }; - let src = sess.codemap.get_filemap(source_name(input)).src; + let src = codemap.get_filemap(source_name(input)).src; do io::with_str_reader(src) |rdr| { - pprust::print_crate(sess.codemap, + pprust::print_crate(codemap, token::get_ident_interner(), - sess.span_diagnostic, + span_diag, crate, source_name(input), rdr, @@ -591,9 +584,9 @@ static architecture_abis : &'static [(&'static str, abi::Architecture)] = &'stat ("mips", abi::Mips)]; -pub fn build_target_config(sopts: @session::options, - demitter: @diagnostic::Emitter) - -> @session::config { +pub fn build_target_config(sopts: @session::options, demitter: @diagnostic::Emitter) + -> @session::config { + let os = match get_os(sopts.target_triple) { Some(os) => os, None => early_error(demitter, ~"unknown operating system") @@ -831,7 +824,7 @@ pub fn build_session_(sopts: @session::options, &sopts.maybe_sysroot, sopts.target_triple, sopts.addl_lib_search_paths); - @Session_ { + Session { targ_cfg: target_cfg, opts: sopts, cstore: cstore, @@ -842,14 +835,14 @@ pub fn build_session_(sopts: @session::options, entry_type: @mut None, span_diagnostic: span_diagnostic_handler, filesearch: filesearch, - building_library: @mut false, + building_library: false, working_dir: os::getcwd(), lints: @mut HashMap::new(), node_id: @mut 1 } } -pub fn parse_pretty(sess: Session, name: &str) -> PpMode { +pub fn parse_pretty(sess: &Session, name: &str) -> PpMode { match name { &"normal" => PpmNormal, &"expanded" => PpmExpanded, @@ -948,14 +941,14 @@ pub fn build_output_filenames(input: &input, odir: &Option, ofile: &Option, attrs: &[ast::Attribute], - sess: Session) + sess: &Session) -> ~OutputFilenames { let obj_path; let out_path; let sopts = sess.opts; let stop_after_codegen = sopts.output_type != link::output_type_exe || - sopts.is_static && *sess.building_library; + sopts.is_static && sess.building_library; let obj_suffix = match sopts.output_type { @@ -998,7 +991,7 @@ pub fn build_output_filenames(input: &input, // version } - if *sess.building_library { + if sess.building_library { out_path = dirpath.push(os::dll_filename(stem)); obj_path = dirpath.push(stem).with_filetype(obj_suffix); } else { @@ -1015,7 +1008,7 @@ pub fn build_output_filenames(input: &input, (*out_file).with_filetype(obj_suffix) }; - if *sess.building_library { + if sess.building_library { sess.warn("ignoring specified output filename for library."); } @@ -1036,7 +1029,7 @@ pub fn early_error(emitter: @diagnostic::Emitter, msg: ~str) -> ! { fail!(); } -pub fn list_metadata(sess: Session, path: &Path, out: @io::Writer) { +pub fn list_metadata(sess: &Session, path: &Path, out: @io::Writer) { metadata::loader::list_file_metadata( token::get_ident_interner(), session::sess_os_to_meta_os(sess.targ_cfg.os), path, out); @@ -1067,7 +1060,7 @@ mod test { let sess = build_session(sessopts, @diagnostic::DefaultEmitter as @diagnostic::Emitter); - let cfg = build_configuration(sess); + let cfg = build_configuration(&sess); assert!((attr::contains_name(cfg, "test"))); } @@ -1089,7 +1082,7 @@ mod test { let sess = build_session(sessopts, @diagnostic::DefaultEmitter as @diagnostic::Emitter); - let cfg = build_configuration(sess); + let cfg = build_configuration(&sess); let mut test_items = cfg.iter().filter(|m| "test" == m.name()); assert!(test_items.next().is_some()); assert!(test_items.next().is_none()); diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index 19e866c70a3fe..fe860949ea019 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -200,7 +200,7 @@ pub enum EntryFnType { EntryNone, } -pub struct Session_ { +pub struct Session { targ_cfg: @config, opts: @options, cstore: @mut metadata::cstore::CStore, @@ -211,15 +211,13 @@ pub struct Session_ { entry_type: @mut Option, span_diagnostic: @mut diagnostic::span_handler, filesearch: @filesearch::FileSearch, - building_library: @mut bool, + building_library: bool, working_dir: Path, lints: @mut HashMap, node_id: @mut uint, } -pub type Session = @Session_; - -impl Session_ { +impl Session { pub fn span_fatal(&self, sp: Span, msg: &str) -> ! { self.span_diagnostic.span_fatal(sp, msg) } @@ -389,7 +387,7 @@ pub fn basic_options() -> @options { } // Seems out of place, but it uses session, so I'm putting it here -pub fn expect(sess: Session, opt: Option, msg: &fn() -> ~str) +pub fn expect(sess: &Session, opt: Option, msg: &fn() -> ~str) -> T { diagnostic::expect(sess.diagnostic(), opt, msg) } diff --git a/src/librustc/front/assign_node_ids.rs b/src/librustc/front/assign_node_ids.rs index fc1b034de97e1..dce8b52881fde 100644 --- a/src/librustc/front/assign_node_ids.rs +++ b/src/librustc/front/assign_node_ids.rs @@ -13,18 +13,18 @@ use driver::session::Session; use syntax::ast; use syntax::fold::ast_fold; -struct NodeIdAssigner { - sess: Session, +struct NodeIdAssigner<'self> { + sess: &'self Session, } -impl ast_fold for NodeIdAssigner { +impl<'self> ast_fold for NodeIdAssigner<'self> { fn new_id(&self, old_id: ast::NodeId) -> ast::NodeId { assert_eq!(old_id, ast::DUMMY_NODE_ID); self.sess.next_node_id() } } -pub fn assign_node_ids(sess: Session, crate: @ast::Crate) -> @ast::Crate { +pub fn assign_node_ids(sess: &Session, crate: @ast::Crate) -> @ast::Crate { let fold = NodeIdAssigner { sess: sess, }; diff --git a/src/librustc/front/std_inject.rs b/src/librustc/front/std_inject.rs index ad5575f14a74e..79b74ac6c4549 100644 --- a/src/librustc/front/std_inject.rs +++ b/src/librustc/front/std_inject.rs @@ -22,7 +22,7 @@ use syntax::opt_vec; static STD_VERSION: &'static str = "0.9-pre"; -pub fn maybe_inject_libstd_ref(sess: Session, crate: @ast::Crate) +pub fn maybe_inject_libstd_ref(sess: &Session, crate: @ast::Crate) -> @ast::Crate { if use_std(crate) { inject_libstd_ref(sess, crate) @@ -46,11 +46,11 @@ fn spanned(x: T) -> codemap::Spanned { } } -struct StandardLibraryInjector { - sess: Session, +struct StandardLibraryInjector<'self> { + sess: &'self Session, } -impl fold::ast_fold for StandardLibraryInjector { +impl<'self> fold::ast_fold for StandardLibraryInjector<'self> { fn fold_crate(&self, crate: &ast::Crate) -> ast::Crate { let version = STD_VERSION.to_managed(); let vi1 = ast::view_item { @@ -133,7 +133,7 @@ impl fold::ast_fold for StandardLibraryInjector { } } -fn inject_libstd_ref(sess: Session, crate: &ast::Crate) -> @ast::Crate { +fn inject_libstd_ref(sess: &Session, crate: &ast::Crate) -> @ast::Crate { let fold = StandardLibraryInjector { sess: sess, }; diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index 4ac398d351fda..1de439bc99c11 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -24,6 +24,7 @@ use syntax::ext::base::ExtCtxt; use syntax::fold::ast_fold; use syntax::fold; use syntax::opt_vec; +use syntax::parse::token; use syntax::print::pprust; use syntax::{ast, ast_util}; @@ -36,7 +37,6 @@ struct Test { } struct TestCtxt { - sess: session::Session, crate: @ast::Crate, path: ~[ast::Ident], ext_cx: @ExtCtxt, @@ -45,9 +45,8 @@ struct TestCtxt { // Traverse the crate, collecting all the test functions, eliding any // existing main functions, and synthesizing a main test harness -pub fn modify_for_testing(sess: session::Session, - crate: @ast::Crate) - -> @ast::Crate { +pub fn modify_for_testing(sess: &session::Session, + crate: @ast::Crate) -> @ast::Crate { // We generate the test harness when building in the 'test' // configuration, either with the '--test' or '--cfg test' // command line options. @@ -60,11 +59,12 @@ pub fn modify_for_testing(sess: session::Session, } } -struct TestHarnessGenerator { +struct TestHarnessGenerator<'self> { cx: @mut TestCtxt, + sess: &'self session::Session } -impl fold::ast_fold for TestHarnessGenerator { +impl<'self> fold::ast_fold for TestHarnessGenerator<'self> { fn fold_crate(&self, c: &ast::Crate) -> ast::Crate { let folded = fold::noop_fold_crate(c, self); @@ -81,14 +81,13 @@ impl fold::ast_fold for TestHarnessGenerator { debug!("current path: %s", ast_util::path_name_i(self.cx.path.clone())); - if is_test_fn(self.cx, i) || is_bench_fn(i) { + if is_test_fn(i, self.sess) || is_bench_fn(i) { match i.node { ast::item_fn(_, purity, _, _, _) if purity == ast::unsafe_fn => { - let sess = self.cx.sess; - sess.span_fatal(i.span, - "unsafe functions cannot be used for \ - tests"); + self.sess.span_fatal(i.span, + "unsafe functions cannot be used for \ + tests"); } _ => { debug!("this is a test function"); @@ -115,8 +114,8 @@ impl fold::ast_fold for TestHarnessGenerator { // Remove any #[main] from the AST so it doesn't clash with // the one we're going to add. Only if compiling an executable. - fn nomain(cx: @mut TestCtxt, item: @ast::item) -> @ast::item { - if !*cx.sess.building_library { + fn nomain(item: @ast::item, lib: bool) -> @ast::item { + if !lib { @ast::item { attrs: do item.attrs.iter().filter_map |attr| { if "main" != attr.name() { @@ -134,17 +133,16 @@ impl fold::ast_fold for TestHarnessGenerator { let mod_nomain = ast::_mod { view_items: m.view_items.clone(), - items: m.items.iter().map(|i| nomain(self.cx, *i)).collect(), + items: m.items.iter().map(|i| nomain(*i, self.sess.building_library)).collect() }; fold::noop_fold_mod(&mod_nomain, self) } } -fn generate_test_harness(sess: session::Session, crate: @ast::Crate) - -> @ast::Crate { +fn generate_test_harness(sess: &session::Session, crate: @ast::Crate) -> @ast::Crate { + let cx: @mut TestCtxt = @mut TestCtxt { - sess: sess, crate: crate, ext_cx: ExtCtxt::new(sess.parse_sess, sess.opts.cfg.clone()), path: ~[], @@ -161,11 +159,13 @@ fn generate_test_harness(sess: session::Session, crate: @ast::Crate) }); let fold = TestHarnessGenerator { - cx: cx + cx: cx, + sess: sess }; let res = @fold.fold_crate(&*crate); ext_cx.bt_pop(); - return res; + + res } fn strip_test_functions(crate: &ast::Crate) -> @ast::Crate { @@ -177,7 +177,7 @@ fn strip_test_functions(crate: &ast::Crate) -> @ast::Crate { } } -fn is_test_fn(cx: @mut TestCtxt, i: @ast::item) -> bool { +fn is_test_fn(i: @ast::item, sess: &session::Session) -> bool { let has_test_attr = attr::contains_name(i.attrs, "test"); fn has_test_signature(i: @ast::item) -> bool { @@ -196,7 +196,6 @@ fn is_test_fn(cx: @mut TestCtxt, i: @ast::item) -> bool { } if has_test_attr && !has_test_signature(i) { - let sess = cx.sess; sess.span_err( i.span, "functions used as tests must have signature fn() -> ()." @@ -272,7 +271,7 @@ mod __test { */ fn mk_std(cx: &TestCtxt) -> ast::view_item { - let id_extra = cx.sess.ident_of("extra"); + let id_extra = token::str_to_ident("extra"); let vi = if is_extra(cx) { ast::view_item_use( ~[@nospan(ast::view_path_simple(id_extra, @@ -318,7 +317,7 @@ fn mk_test_module(cx: &TestCtxt) -> @ast::item { attr::mk_attr(attr::mk_word_item(@"!resolve_unexported")); let item = ast::item { - ident: cx.sess.ident_of("__test"), + ident: token::str_to_ident("__test"), attrs: ~[resolve_unexported_attr], id: ast::DUMMY_NODE_ID, node: item_, @@ -327,7 +326,7 @@ fn mk_test_module(cx: &TestCtxt) -> @ast::item { }; debug!("Synthetic test module:\n%s\n", - pprust::item_to_str(@item.clone(), cx.sess.intr())); + pprust::item_to_str(@item.clone(), token::get_ident_interner())); return @item; } diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 683fbba09cc52..01f5b49ec6edd 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -153,7 +153,7 @@ pub fn decode_inlined_item(cdata: @cstore::crate_metadata, // ______________________________________________________________________ // Enumerating the IDs which appear in an AST -fn reserve_id_range(sess: Session, +fn reserve_id_range(sess: &Session, from_id_range: ast_util::id_range) -> ast_util::id_range { // Handle the case of an empty range: if from_id_range.empty() { return from_id_range; } diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 3a50306bb8766..87b365d8284f9 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -22,7 +22,6 @@ use syntax::visit::Visitor; use syntax::visit; struct CheckCrateVisitor { - sess: Session, ast_map: ast_map::map, def_map: resolve::DefMap, method_map: typeck::method_map, @@ -31,36 +30,33 @@ struct CheckCrateVisitor { impl Visitor for CheckCrateVisitor { fn visit_item(&mut self, i:@item, env:bool) { - check_item(self, self.sess, self.ast_map, self.def_map, i, env); + check_item(self, self.tcx.sess, self.ast_map, self.def_map, i, env); } fn visit_pat(&mut self, p:@Pat, env:bool) { check_pat(self, p, env); } fn visit_expr(&mut self, ex:@Expr, env:bool) { - check_expr(self, self.sess, self.def_map, self.method_map, - self.tcx, ex, env); + check_expr(self, self.def_map, self.method_map, self.tcx, ex, env); } } -pub fn check_crate(sess: Session, - crate: &Crate, +pub fn check_crate(crate: &Crate, ast_map: ast_map::map, def_map: resolve::DefMap, method_map: typeck::method_map, tcx: ty::ctxt) { let mut v = CheckCrateVisitor { - sess: sess, ast_map: ast_map, def_map: def_map, method_map: method_map, tcx: tcx, }; visit::walk_crate(&mut v, crate, false); - sess.abort_if_errors(); + tcx.sess.abort_if_errors(); } pub fn check_item(v: &mut CheckCrateVisitor, - sess: Session, + sess: &Session, ast_map: ast_map::map, def_map: resolve::DefMap, it: @item, @@ -106,7 +102,6 @@ pub fn check_pat(v: &mut CheckCrateVisitor, p: @Pat, _is_const: bool) { } pub fn check_expr(v: &mut CheckCrateVisitor, - sess: Session, def_map: resolve::DefMap, method_map: typeck::method_map, tcx: ty::ctxt, @@ -116,24 +111,24 @@ pub fn check_expr(v: &mut CheckCrateVisitor, match e.node { ExprUnary(_, UnDeref, _) => { } ExprUnary(_, UnBox(_), _) | ExprUnary(_, UnUniq, _) => { - sess.span_err(e.span, - "disallowed operator in constant expression"); + tcx.sess.span_err(e.span, + "disallowed operator in constant expression"); return; } ExprLit(@codemap::Spanned {node: lit_str(_), _}) => { } ExprBinary(*) | ExprUnary(*) => { if method_map.contains_key(&e.id) { - sess.span_err(e.span, "user-defined operators are not \ - allowed in constant expressions"); + tcx.sess.span_err(e.span, "user-defined operators are not \ + allowed in constant expressions"); } } ExprLit(_) => (), ExprCast(_, _) => { let ety = ty::expr_ty(tcx, e); if !ty::type_is_numeric(ety) && !ty::type_is_unsafe_ptr(ety) { - sess.span_err(e.span, ~"can not cast to `" + - ppaux::ty_to_str(tcx, ety) + - "` in a constant expression"); + tcx.sess.span_err(e.span, ~"can not cast to `" + + ppaux::ty_to_str(tcx, ety) + + "` in a constant expression"); } } ExprPath(ref pth) => { @@ -142,9 +137,9 @@ pub fn check_expr(v: &mut CheckCrateVisitor, // foo:: in a const. Currently that is only done on // a path in trans::callee that only works in block contexts. if !pth.segments.iter().all(|segment| segment.types.is_empty()) { - sess.span_err( - e.span, "paths in constants may only refer to \ - items without type parameters"); + tcx.sess.span_err( + e.span, "paths in constants may only refer to \ + items without type parameters"); } match def_map.find(&e.id) { Some(&DefStatic(*)) | @@ -154,13 +149,13 @@ pub fn check_expr(v: &mut CheckCrateVisitor, Some(&def) => { debug!("(checking const) found bad def: %?", def); - sess.span_err( - e.span, - "paths in constants may only refer to \ - constants or functions"); + tcx.sess.span_err( + e.span, + "paths in constants may only refer to \ + constants or functions"); } None => { - sess.span_bug(e.span, "unbound path in const?!"); + tcx.sess.span_bug(e.span, "unbound path in const?!"); } } } @@ -169,14 +164,14 @@ pub fn check_expr(v: &mut CheckCrateVisitor, Some(&DefStruct(*)) => {} // OK. Some(&DefVariant(*)) => {} // OK. _ => { - sess.span_err( - e.span, - "function calls in constants are limited to \ - struct and enum constructors"); + tcx.sess.span_err( + e.span, + "function calls in constants are limited to \ + struct and enum constructors"); } } } - ExprParen(e) => { check_expr(v, sess, def_map, method_map, + ExprParen(e) => { check_expr(v, def_map, method_map, tcx, e, is_const); } ExprVstore(_, ExprVstoreSlice) | ExprVec(_, MutImmutable) | @@ -187,14 +182,14 @@ pub fn check_expr(v: &mut CheckCrateVisitor, ExprRepeat(*) | ExprStruct(*) => { } ExprAddrOf(*) => { - sess.span_err( - e.span, - "borrowed pointers in constants may only refer to \ - immutable values"); + tcx.sess.span_err( + e.span, + "borrowed pointers in constants may only refer to \ + immutable values"); } _ => { - sess.span_err(e.span, - "constant contains unimplemented expression type"); + tcx.sess.span_err(e.span, + "constant contains unimplemented expression type"); return; } } @@ -202,14 +197,14 @@ pub fn check_expr(v: &mut CheckCrateVisitor, match e.node { ExprLit(@codemap::Spanned {node: lit_int(v, t), _}) => { if (v as u64) > ast_util::int_ty_max( - if t == ty_i { sess.targ_cfg.int_type } else { t }) { - sess.span_err(e.span, "literal out of range for its type"); + if t == ty_i { tcx.sess.targ_cfg.int_type } else { t }) { + tcx.sess.span_err(e.span, "literal out of range for its type"); } } ExprLit(@codemap::Spanned {node: lit_uint(v, t), _}) => { if v > ast_util::uint_ty_max( - if t == ty_u { sess.targ_cfg.uint_type } else { t }) { - sess.span_err(e.span, "literal out of range for its type"); + if t == ty_u { tcx.sess.targ_cfg.uint_type } else { t }) { + tcx.sess.span_err(e.span, "literal out of range for its type"); } } _ => () @@ -218,25 +213,25 @@ pub fn check_expr(v: &mut CheckCrateVisitor, } #[deriving(Clone)] -struct env { +struct Env<'self> { root_it: @item, - sess: Session, + sess: &'self Session, ast_map: ast_map::map, def_map: resolve::DefMap, idstack: @mut ~[NodeId] } -struct CheckItemRecursionVisitor { - env: env, +struct CheckItemRecursionVisitor<'self> { + env: Env<'self> } // Make sure a const item doesn't recursively refer to itself // FIXME: Should use the dependency graph when it's available (#1356) -pub fn check_item_recursion(sess: Session, +pub fn check_item_recursion(sess: &Session, ast_map: ast_map::map, def_map: resolve::DefMap, it: @item) { - let env = env { + let env = Env { root_it: it, sess: sess, ast_map: ast_map, @@ -248,7 +243,7 @@ pub fn check_item_recursion(sess: Session, visitor.visit_item(it, ()); } -impl Visitor<()> for CheckItemRecursionVisitor { +impl<'self> Visitor<()> for CheckItemRecursionVisitor<'self> { fn visit_item(&mut self, it: @item, _: ()) { if self.env.idstack.iter().any(|x| x == &(it.id)) { self.env.sess.span_fatal(self.env.root_it.span, "recursive constant"); diff --git a/src/librustc/middle/entry.rs b/src/librustc/middle/entry.rs index 2ebb6e6926ef9..654e487c0f636 100644 --- a/src/librustc/middle/entry.rs +++ b/src/librustc/middle/entry.rs @@ -19,8 +19,8 @@ use syntax::parse::token::special_idents; use syntax::visit; use syntax::visit::Visitor; -struct EntryContext { - session: Session, +struct EntryContext<'self> { + session: &'self Session, ast_map: ast_map::map, @@ -38,16 +38,16 @@ struct EntryContext { non_main_fns: ~[(NodeId, Span)], } -impl Visitor<()> for EntryContext { +impl<'self> Visitor<()> for EntryContext<'self> { fn visit_item(&mut self, item:@item, _:()) { find_item(item, self); } } -pub fn find_entry_point(session: Session, crate: &Crate, ast_map: ast_map::map) { +pub fn find_entry_point(session: &Session, crate: &Crate, ast_map: ast_map::map) { // FIXME #4404 android JNI hacks - if *session.building_library && + if session.building_library && session.targ_cfg.os != session::OsAndroid { // No need to find a main function return; @@ -134,7 +134,7 @@ fn configure_main(this: &mut EntryContext) { *this.session.entry_fn = this.main_fn; *this.session.entry_type = Some(session::EntryMain); } else { - if !*this.session.building_library { + if !this.session.building_library { // No main function this.session.err("main function not found"); if !this.non_main_fns.is_empty() { diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index 1d5ed61154a3e..d8a579a088d17 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -296,7 +296,7 @@ struct LanguageItemCollector<'self> { items: LanguageItems, crate: &'self Crate, - session: Session, + session: &'self Session, item_refs: HashMap<@str, uint>, } @@ -323,7 +323,7 @@ impl<'self> Visitor<()> for LanguageItemVisitor<'self> { } impl<'self> LanguageItemCollector<'self> { - pub fn new<'a>(crate: &'a Crate, session: Session) + pub fn new<'a>(crate: &'a Crate, session: &'a Session) -> LanguageItemCollector<'a> { let mut item_refs = HashMap::new(); @@ -456,7 +456,7 @@ impl<'self> LanguageItemCollector<'self> { } pub fn collect_language_items(crate: &Crate, - session: Session) + session: &Session) -> LanguageItems { let mut collector = LanguageItemCollector::new(crate, session); collector.collect(); diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 331bd25e359ed..f4302b893340d 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -601,7 +601,7 @@ impl Context { } } -pub fn each_lint(sess: session::Session, +pub fn each_lint(sess: &session::Session, attrs: &[ast::Attribute], f: &fn(@ast::MetaItem, level, @str) -> bool) -> bool { let xs = [allow, warn, deny, forbid]; diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 5b6bb3a7b752a..cbf2d4f167668 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -22,6 +22,7 @@ Most of the documentation on regions can be found in use driver::session::Session; +use metadata; use metadata::csearch; use middle::resolve; use middle::ty::{region_variance, rv_covariant, rv_invariant}; @@ -72,8 +73,8 @@ pub struct Context { parent: Option, } -struct RegionResolutionVisitor { - sess: Session, +struct RegionResolutionVisitor<'self> { + sess: &'self Session, def_map: resolve::DefMap, // Generated maps: @@ -473,7 +474,7 @@ fn resolve_fn(visitor: &mut RegionResolutionVisitor, visitor.visit_block(body, body_cx); } -impl Visitor for RegionResolutionVisitor { +impl<'self> Visitor for RegionResolutionVisitor<'self> { fn visit_block(&mut self, b:&Block, cx:Context) { resolve_block(self, b, cx); @@ -503,7 +504,7 @@ impl Visitor for RegionResolutionVisitor { } } -pub fn resolve_crate(sess: Session, +pub fn resolve_crate(sess: &Session, def_map: resolve::DefMap, crate: &ast::Crate) -> @mut RegionMaps { @@ -551,7 +552,6 @@ pub struct region_dep { } pub struct DetermineRpCtxt { - sess: Session, ast_map: ast_map::map, def_map: resolve::DefMap, region_paramd_items: region_paramd_items, @@ -568,6 +568,8 @@ pub struct DetermineRpCtxt { // encodes the context of the current type; invariant if // mutable, covariant otherwise ambient_variance: region_variance, + + cstore: @mut metadata::cstore::CStore, } pub fn join_variance(variance1: region_variance, @@ -784,11 +786,10 @@ fn determine_rp_in_ty(visitor: &mut DetermineRpVisitor, // respect to &r, because &'r ty can be used whereever a *smaller* // region is expected (and hence is a supertype of those // locations) - let sess = cx.sess; match ty.node { ast::ty_rptr(ref r, _) => { debug!("referenced rptr type %s", - pprust::ty_to_str(ty, sess.intr())); + pprust::ty_to_str(ty, token::get_ident_interner())); if cx.region_is_relevant(r) { let rv = cx.add_variance(rv_contravariant); @@ -798,7 +799,7 @@ fn determine_rp_in_ty(visitor: &mut DetermineRpVisitor, ast::ty_closure(ref f) => { debug!("referenced fn type: %s", - pprust::ty_to_str(ty, sess.intr())); + pprust::ty_to_str(ty, token::get_ident_interner())); match f.region { Some(_) => { if cx.region_is_relevant(&f.region) { @@ -833,12 +834,12 @@ fn determine_rp_in_ty(visitor: &mut DetermineRpVisitor, cx.add_dep(did.node); } } else { - let cstore = sess.cstore; + let cstore = cx.cstore; match csearch::get_region_param(cstore, did) { None => {} Some(variance) => { debug!("reference to external, rp'd type %s", - pprust::ty_to_str(ty, sess.intr())); + pprust::ty_to_str(ty, token::get_ident_interner())); if cx.region_is_relevant(&path.segments.last().lifetime) { let rv = cx.add_variance(variance); cx.add_rp(cx.item_id, rv) @@ -932,13 +933,12 @@ impl Visitor<()> for DetermineRpVisitor { } -pub fn determine_rp_in_crate(sess: Session, +pub fn determine_rp_in_crate(cstore: @mut metadata::cstore::CStore, ast_map: ast_map::map, def_map: resolve::DefMap, crate: &ast::Crate) -> region_paramd_items { let cx = @mut DetermineRpCtxt { - sess: sess, ast_map: ast_map, def_map: def_map, region_paramd_items: @mut HashMap::new(), @@ -946,7 +946,8 @@ pub fn determine_rp_in_crate(sess: Session, worklist: ~[], item_id: 0, anon_implies_rp: false, - ambient_variance: rv_covariant + ambient_variance: rv_covariant, + cstore: cstore }; // Gather up the base set, worklist and dep_map diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index a01f4f042462c..8d9d04cb4b7e3 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -37,6 +37,7 @@ use syntax::opt_vec::OptVec; use syntax::visit; use syntax::visit::Visitor; +use std::cast; use std::str; use std::uint; use std::hashmap::{HashMap, HashSet}; @@ -801,7 +802,7 @@ pub fn namespace_error_to_str(ns: NamespaceError) -> &'static str { } } -pub fn Resolver(session: Session, +pub fn Resolver(session: &Session, lang_items: LanguageItems, crate: @Crate) -> Resolver { @@ -816,8 +817,14 @@ pub fn Resolver(session: Session, let current_module = graph_root.get_module(); + // NOTE: Since threading the lifetime of the Session through + // Resolver triggers conflicting lifetime errors and + // we know that the Session outlives the Resolver + // we cheat a little bit here. + let session: &'static Session = unsafe { cast::transmute(session) }; + let this = Resolver { - session: @session, + session: session, lang_items: lang_items, crate: crate, @@ -860,7 +867,7 @@ pub fn Resolver(session: Session, /// The main resolver class. pub struct Resolver { - session: @Session, + session: &'static Session, lang_items: LanguageItems, crate: @Crate, @@ -5547,7 +5554,7 @@ pub struct CrateMap { } /// Entry point to crate resolution. -pub fn resolve_crate(session: Session, +pub fn resolve_crate(session: &Session, lang_items: LanguageItems, crate: @Crate) -> CrateMap { diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 0de01bced1f7c..8f1eb68814d95 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -363,7 +363,7 @@ fn variant_opt(bcx: @mut Block, pat_id: ast::NodeId) return lit(UnitLikeStructLit(pat_id)); } _ => { - ccx.sess.bug("non-variant or struct in variant_opt()"); + ccx.tcx.sess.bug("non-variant or struct in variant_opt()"); } } } @@ -470,7 +470,7 @@ fn expand_nested_bindings<'r>(bcx: @mut Block, fn assert_is_binding_or_wild(bcx: @mut Block, p: @ast::Pat) { if !pat_is_binding_or_wild(bcx.tcx().def_map, p) { - bcx.sess().span_bug( + bcx.tcx().sess.span_bug( p.span, fmt!("Expected an identifier pattern but found p: %s", p.repr(bcx.tcx()))); @@ -1386,7 +1386,7 @@ fn insert_lllocals(bcx: @mut Block, debug!("binding %? to %s", binding_info.id, bcx.val_to_str(llval)); llmap.insert(binding_info.id, llval); - if bcx.sess().opts.extra_debuginfo { + if bcx.tcx().sess.opts.extra_debuginfo { debuginfo::create_match_binding_metadata(bcx, ident, binding_info.id, @@ -1558,7 +1558,7 @@ fn compile_submatch_continue(mut bcx: @mut Block, let tup_repr = adt::represent_type(bcx.ccx(), tup_ty); let n_tup_elts = match ty::get(tup_ty).sty { ty::ty_tup(ref elts) => elts.len(), - _ => ccx.sess.bug("non-tuple type in tuple pattern") + _ => ccx.tcx.sess.bug("non-tuple type in tuple pattern") }; let tup_vals = do vec::from_fn(n_tup_elts) |i| { adt::trans_field_ptr(bcx, tup_repr, val, 0, i) @@ -1577,7 +1577,7 @@ fn compile_submatch_continue(mut bcx: @mut Block, ty::lookup_struct_fields(tcx, struct_id).len(); } _ => { - ccx.sess.bug("non-struct type in tuple struct pattern"); + ccx.tcx.sess.bug("non-struct type in tuple struct pattern"); } } @@ -1696,7 +1696,7 @@ fn compile_submatch_continue(mut bcx: @mut Block, } } _ => { - bcx.sess().bug( + bcx.tcx().sess.bug( "in compile_submatch, expected \ trans_opt to return a single_result") } @@ -2002,7 +2002,7 @@ pub fn store_local(bcx: @mut Block, if ty::type_is_bot(expr_ty(bcx, init_expr)) { create_dummy_locals(bcx, pat) } else { - if bcx.sess().asm_comments() { + if bcx.tcx().sess.asm_comments() { add_comment(bcx, "creating zeroable ref llval"); } let llptr = init_datum.to_zeroable_ref_llval(bcx); @@ -2055,7 +2055,7 @@ pub fn store_arg(mut bcx: @mut Block, // Debug information (the llvm.dbg.declare intrinsic to be precise) always expects to get an // alloca, which only is the case on the general path, so lets disable the optimized path when // debug info is enabled. - let fast_path = !bcx.ccx().sess.opts.extra_debuginfo && simple_identifier(pat).is_some(); + let fast_path = !bcx.tcx().sess.opts.extra_debuginfo && simple_identifier(pat).is_some(); if fast_path { // Optimized path for `x: T` case. This just adopts @@ -2118,7 +2118,7 @@ fn bind_irrefutable_pat(bcx: @mut Block, pat.repr(bcx.tcx()), binding_mode); - if bcx.sess().asm_comments() { + if bcx.tcx().sess.asm_comments() { add_comment(bcx, fmt!("bind_irrefutable_pat(pat=%s)", pat.repr(bcx.tcx()))); } diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs index 5c255ad081811..24b97738ffea7 100644 --- a/src/librustc/middle/trans/adt.rs +++ b/src/librustc/middle/trans/adt.rs @@ -179,9 +179,9 @@ fn represent_type_uncached(cx: &mut CrateContext, t: ty::t) -> Repr { // non-empty body, explicit discriminants should have // been rejected by a checker before this point. if !cases.iter().enumerate().all(|(i,c)| c.discr == (i as Disr)) { - cx.sess.bug(fmt!("non-C-like enum %s with specified \ - discriminants", - ty::item_path_str(cx.tcx, def_id))) + cx.tcx.sess.bug(fmt!("non-C-like enum %s with specified \ + discriminants", + ty::item_path_str(cx.tcx, def_id))) } if cases.len() == 2 { @@ -210,7 +210,7 @@ fn represent_type_uncached(cx: &mut CrateContext, t: ty::t) -> Repr { let discr = ~[ty::mk_uint()]; return General(cases.map(|c| mk_struct(cx, discr + c.tys, false))) } - _ => cx.sess.bug("adt::represent_type called on non-ADT type") + _ => cx.tcx.sess.bug("adt::represent_type called on non-ADT type") } } @@ -354,7 +354,7 @@ pub fn trans_case(bcx: @mut Block, r: &Repr, discr: Disr) -> _match::opt_result _match::single_result(rslt(bcx, C_disr(bcx.ccx(), discr))) } Univariant(*) => { - bcx.ccx().sess.bug("no cases for univariants or structs") + bcx.ccx().tcx.sess.bug("no cases for univariants or structs") } General(*) => { _match::single_result(rslt(bcx, C_disr(bcx.ccx(), discr))) @@ -424,7 +424,7 @@ pub fn trans_field_ptr(bcx: @mut Block, r: &Repr, val: ValueRef, discr: Disr, // someday), it will need to return a possibly-new bcx as well. match *r { CEnum(*) => { - bcx.ccx().sess.bug("element access in C-like enum") + bcx.ccx().tcx.sess.bug("element access in C-like enum") } Univariant(ref st, _dtor) => { assert_eq!(discr, 0); @@ -470,7 +470,7 @@ fn struct_field_ptr(bcx: @mut Block, st: &Struct, val: ValueRef, ix: uint, pub fn trans_drop_flag_ptr(bcx: @mut Block, r: &Repr, val: ValueRef) -> ValueRef { match *r { Univariant(ref st, true) => GEPi(bcx, val, [0, st.fields.len() - 1]), - _ => bcx.ccx().sess.bug("tried to get drop flag of non-droppable type") + _ => bcx.ccx().tcx.sess.bug("tried to get drop flag of non-droppable type") } } @@ -608,7 +608,7 @@ pub fn const_get_discrim(ccx: &mut CrateContext, r: &Repr, val: ValueRef) pub fn const_get_field(ccx: &mut CrateContext, r: &Repr, val: ValueRef, _discr: Disr, ix: uint) -> ValueRef { match *r { - CEnum(*) => ccx.sess.bug("element access in C-like enum const"), + CEnum(*) => ccx.tcx.sess.bug("element access in C-like enum const"), Univariant(*) => const_struct_field(ccx, val, ix), General(*) => const_struct_field(ccx, val, ix + 1), NullablePointer{ _ } => const_struct_field(ccx, val, ix) diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 3f021881b27cb..8b6b116f88106 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -142,7 +142,7 @@ struct StatRecorder<'self> { impl<'self> StatRecorder<'self> { pub fn new(ccx: @mut CrateContext, name: &'self str) -> StatRecorder<'self> { - let start = if ccx.sess.trans_stats() { + let start = if ccx.tcx.sess.trans_stats() { time::precise_time_ns() } else { 0 @@ -160,7 +160,7 @@ impl<'self> StatRecorder<'self> { #[unsafe_destructor] impl<'self> Drop for StatRecorder<'self> { fn drop(&mut self) { - if self.ccx.sess.trans_stats() { + if self.ccx.tcx.sess.trans_stats() { let end = time::precise_time_ns(); let elapsed = ((end - self.start) / 1_000_000) as uint; let iend = self.ccx.stats.n_llvm_insns; @@ -545,7 +545,7 @@ pub fn set_glue_inlining(f: ValueRef, t: ty::t) { // silently mangles such symbols, breaking our linkage model. pub fn note_unique_llvm_symbol(ccx: &mut CrateContext, sym: @str) { if ccx.all_llvm_symbols.contains(&sym) { - ccx.sess.bug(~"duplicate LLVM symbol: " + sym); + ccx.tcx.sess.bug(~"duplicate LLVM symbol: " + sym); } ccx.all_llvm_symbols.insert(sym); } @@ -579,7 +579,7 @@ pub fn get_res_dtor(ccx: @mut CrateContext, get_item_val(ccx, did.node) } else { let tcx = ccx.tcx; - let name = csearch::get_symbol(ccx.sess.cstore, did); + let name = csearch::get_symbol(ccx.tcx.sess.cstore, did); let class_ty = ty::subst_tps(tcx, substs, None, @@ -595,7 +595,7 @@ pub fn get_res_dtor(ccx: @mut CrateContext, // Structural comparison: a rather involved form of glue. pub fn maybe_name_value(cx: &CrateContext, v: ValueRef, s: &str) { - if cx.sess.opts.save_temps { + if cx.tcx.sess.opts.save_temps { do s.with_c_str |buf| { unsafe { llvm::LLVMSetValueName(v, buf) @@ -633,7 +633,7 @@ pub fn compare_scalar_types(cx: @mut Block, } _ => { // Should never get here, because t is scalar. - cx.sess().bug("non-scalar type passed to \ + cx.tcx().sess.bug("non-scalar type passed to \ compare_scalar_types") } } @@ -789,18 +789,18 @@ pub fn iter_structural_ty(cx: @mut Block, av: ValueRef, t: ty::t, _match::single_result(r) => { AddCase(llswitch, r.val, variant_cx.llbb) } - _ => ccx.sess.unimpl("value from adt::trans_case \ + _ => ccx.tcx.sess.unimpl("value from adt::trans_case \ in iter_structural_ty") } Br(variant_cx, next_cx.llbb); } cx = next_cx; } - _ => ccx.sess.unimpl("value from adt::trans_switch \ + _ => ccx.tcx.sess.unimpl("value from adt::trans_switch \ in iter_structural_ty") } } - _ => cx.sess().unimpl("type in iter_structural_ty") + _ => cx.tcx().sess.unimpl("type in iter_structural_ty") } return cx; } @@ -877,10 +877,10 @@ pub fn null_env_ptr(ccx: &CrateContext) -> ValueRef { } pub fn trans_external_path(ccx: &mut CrateContext, did: ast::DefId, t: ty::t) -> ValueRef { - let name = csearch::get_symbol(ccx.sess.cstore, did); + let name = csearch::get_symbol(ccx.tcx.sess.cstore, did); match ty::get(t).sty { ty::ty_bare_fn(ref fn_ty) => { - match fn_ty.abis.for_arch(ccx.sess.targ_cfg.arch) { + match fn_ty.abis.for_arch(ccx.tcx.sess.targ_cfg.arch) { Some(Rust) | Some(RustIntrinsic) => { get_extern_rust_fn(ccx, fn_ty.sig.inputs, fn_ty.sig.output, name) } @@ -914,7 +914,7 @@ pub fn invoke(bcx: @mut Block, llfn: ValueRef, llargs: ~[ValueRef], None => debug!("invoke at ???"), Some(node_info) => { debug!("invoke at %s", - bcx.sess().codemap.span_to_str(node_info.span)); + bcx.tcx().sess.codemap.span_to_str(node_info.span)); } } @@ -950,7 +950,7 @@ pub fn invoke(bcx: @mut Block, llfn: ValueRef, llargs: ~[ValueRef], } pub fn need_invoke(bcx: @mut Block) -> bool { - if (bcx.ccx().sess.opts.debugging_opts & session::no_landing_pads != 0) { + if (bcx.tcx().sess.opts.debugging_opts & session::no_landing_pads != 0) { return false; } @@ -1132,14 +1132,13 @@ pub fn load_if_immediate(cx: @mut Block, v: ValueRef, t: ty::t) -> ValueRef { } pub fn trans_trace(bcx: @mut Block, sp_opt: Option, trace_str: @str) { - if !bcx.sess().trace() { return; } + if !bcx.tcx().sess.trace() { return; } let _icx = push_ctxt("trans_trace"); add_comment(bcx, trace_str); let V_trace_str = C_cstr(bcx.ccx(), trace_str); let (V_filename, V_line) = match sp_opt { Some(sp) => { - let sess = bcx.sess(); - let loc = sess.parse_sess.cm.lookup_char_pos(sp.lo); + let loc = bcx.tcx().sess.parse_sess.cm.lookup_char_pos(sp.lo); (C_cstr(bcx.ccx(), loc.file.name), loc.line as int) } None => { @@ -1184,8 +1183,8 @@ pub fn trans_stmt(cx: @mut Block, s: &ast::Stmt) -> @mut Block { let _icx = push_ctxt("trans_stmt"); debug!("trans_stmt(%s)", stmt_to_str(s, cx.tcx().sess.intr())); - if cx.sess().asm_comments() { - add_span_comment(cx, s.span, stmt_to_str(s, cx.ccx().sess.intr())); + if cx.tcx().sess.asm_comments() { + add_span_comment(cx, s.span, stmt_to_str(s, cx.tcx().sess.intr())); } let mut bcx = cx; @@ -1198,7 +1197,7 @@ pub fn trans_stmt(cx: @mut Block, s: &ast::Stmt) -> @mut Block { match d.node { ast::DeclLocal(ref local) => { bcx = init_local(bcx, *local); - if cx.sess().opts.extra_debuginfo { + if bcx.tcx().sess.opts.extra_debuginfo { debuginfo::create_local_var_metadata(bcx, *local); } } @@ -1317,7 +1316,7 @@ pub fn trans_block_cleanups_(bcx: @mut Block, // NB: Don't short-circuit even if this block is unreachable because // GC-based cleanup needs to the see that the roots are live. let no_lpads = - bcx.ccx().sess.opts.debugging_opts & session::no_landing_pads != 0; + bcx.tcx().sess.opts.debugging_opts & session::no_landing_pads != 0; if bcx.unreachable && !no_lpads { return bcx; } let mut bcx = bcx; for cu in cleanups.rev_iter() { @@ -1347,7 +1346,7 @@ pub fn cleanup_and_leave(bcx: @mut Block, loop { debug!("cleanup_and_leave: leaving %s", cur.to_str()); - if bcx.sess().trace() { + if bcx.tcx().sess.trace() { trans_trace( bcx, None, (fmt!("cleanup_and_leave(%s)", cur.to_str())).to_managed()); @@ -1418,7 +1417,7 @@ pub fn cleanup_block(bcx: @mut Block, upto: Option) -> @mut Block loop { debug!("cleanup_block: %s", cur.to_str()); - if bcx.sess().trace() { + if bcx.tcx().sess.trace() { trans_trace( bcx, None, (fmt!("cleanup_block(%s)", cur.to_str())).to_managed()); @@ -1534,7 +1533,7 @@ pub fn with_cond(bcx: @mut Block, val: ValueRef, f: &fn(@mut Block) -> @mut Bloc pub fn call_memcpy(cx: @mut Block, dst: ValueRef, src: ValueRef, n_bytes: ValueRef, align: u32) { let _icx = push_ctxt("call_memcpy"); let ccx = cx.ccx(); - let key = match ccx.sess.targ_cfg.arch { + let key = match ccx.tcx.sess.targ_cfg.arch { X86 | Arm | Mips => "llvm.memcpy.p0i8.p0i8.i32", X86_64 => "llvm.memcpy.p0i8.p0i8.i64" }; @@ -1578,7 +1577,7 @@ pub fn memzero(b: &Builder, llptr: ValueRef, ty: Type) { let _icx = push_ctxt("memzero"); let ccx = b.ccx; - let intrinsic_key = match ccx.sess.targ_cfg.arch { + let intrinsic_key = match ccx.tcx.sess.targ_cfg.arch { X86 | Arm | Mips => "llvm.memset.p0i8.i32", X86_64 => "llvm.memset.p0i8.i64" }; @@ -1687,7 +1686,7 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext, debug!("new_fn_ctxt_w_id(path=%s, id=%?, \ param_substs=%s)", - path_str(ccx.sess, path), + path_str(ccx.tcx.sess, path), id, param_substs.repr(ccx.tcx)); @@ -1821,7 +1820,7 @@ pub fn copy_args_to_allocas(fcx: @mut FunctionContext, fcx.llself = Some(ValSelfData {v: self_val, ..slf}); add_clean(bcx, self_val, slf.t); - if fcx.ccx.sess.opts.extra_debuginfo { + if fcx.ccx.tcx.sess.opts.extra_debuginfo { debuginfo::create_self_argument_metadata(bcx, slf.t, self_val); } } @@ -1848,7 +1847,7 @@ pub fn copy_args_to_allocas(fcx: @mut FunctionContext, }; bcx = _match::store_arg(bcx, args[arg_n].pat, llarg); - if fcx.ccx.sess.opts.extra_debuginfo { + if fcx.ccx.tcx.sess.opts.extra_debuginfo { debuginfo::create_argument_metadata(bcx, &args[arg_n]); } } @@ -2001,7 +2000,7 @@ pub fn trans_fn(ccx: @mut CrateContext, id: ast::NodeId, attrs: &[ast::Attribute]) { - let the_path_str = path_str(ccx.sess, path); + let the_path_str = path_str(ccx.tcx.sess, path); let _s = StatRecorder::new(ccx, the_path_str); debug!("trans_fn(self_arg=%?, param_substs=%s)", self_arg, @@ -2137,7 +2136,7 @@ pub fn trans_enum_variant_or_tuple_like_struct( let result_ty = match ty::get(ctor_ty).sty { ty::ty_bare_fn(ref bft) => bft.sig.output, - _ => ccx.sess.bug( + _ => ccx.tcx.sess.bug( fmt!("trans_enum_variant_or_tuple_like_struct: \ unexpected ctor return type %s", ty_to_str(ccx.tcx, ctor_ty))) @@ -2271,14 +2270,14 @@ pub fn trans_item(ccx: @mut CrateContext, item: &ast::item) { // because we need to get the value of the bool out of LLVM if attr::contains_name(item.attrs, "static_assert") { if m == ast::MutMutable { - ccx.sess.span_fatal(expr.span, + ccx.tcx.sess.span_fatal(expr.span, "cannot have static_assert on a mutable \ static"); } let v = ccx.const_values.get_copy(&item.id); unsafe { if !(llvm::LLVMConstIntGetZExtValue(v) != 0) { - ccx.sess.span_fatal(expr.span, "static assertion failed"); + ccx.tcx.sess.span_fatal(expr.span, "static assertion failed"); } } } @@ -2333,14 +2332,14 @@ fn finish_register_fn(ccx: @mut CrateContext, sp: Span, sym: ~str, node_id: ast: llfn: ValueRef) { ccx.item_symbols.insert(node_id, sym); - if !*ccx.sess.building_library { + if !ccx.tcx.sess.building_library { lib::llvm::SetLinkage(llfn, lib::llvm::InternalLinkage); } // FIXME #4404 android JNI hacks - let is_entry = is_entry_fn(&ccx.sess, node_id) && (!*ccx.sess.building_library || - (*ccx.sess.building_library && - ccx.sess.targ_cfg.os == session::OsAndroid)); + let is_entry = is_entry_fn(ccx.tcx.sess, node_id) && (!ccx.tcx.sess.building_library || + (ccx.tcx.sess.building_library && + ccx.tcx.sess.targ_cfg.os == session::OsAndroid)); if is_entry { create_entry_wrapper(ccx, sp, llfn); } @@ -2394,7 +2393,7 @@ pub fn is_entry_fn(sess: &Session, node_id: ast::NodeId) -> bool { pub fn create_entry_wrapper(ccx: @mut CrateContext, _sp: Span, main_llfn: ValueRef) { - let et = ccx.sess.entry_type.unwrap(); + let et = ccx.tcx.sess.entry_type.unwrap(); match et { session::EntryMain => { create_entry_fn(ccx, main_llfn, true); @@ -2410,7 +2409,7 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext, &ccx.int_type); // FIXME #4404 android JNI hacks - let main_name = if *ccx.sess.building_library { + let main_name = if ccx.tcx.sess.building_library { "amain" } else { "main" @@ -2526,7 +2525,7 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef { let sym = match ccx.external_srcs.find(&i.id) { Some(&did) => { debug!("but found in other crate..."); - csearch::get_symbol(ccx.sess.cstore, did) + csearch::get_symbol(ccx.tcx.sess.cstore, did) } None => sym }; @@ -2544,7 +2543,7 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef { llvm::LLVMAddGlobal(ccx.llmod, llty, buf) }; - if !*ccx.sess.building_library { + if !ccx.tcx.sess.building_library { lib::llvm::SetLinkage(g, lib::llvm::InternalLinkage); } @@ -2616,7 +2615,7 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef { debug!("get_item_val(): processing a node_trait_method"); match *trait_method { ast::required(_) => { - ccx.sess.bug("unexpected variant: required trait method in \ + ccx.tcx.sess.bug("unexpected variant: required trait method in \ get_item_val()"); } ast::provided(m) => { @@ -2701,7 +2700,7 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef { } ref variant => { - ccx.sess.bug(fmt!("get_item_val(): unexpected variant: %?", + ccx.tcx.sess.bug(fmt!("get_item_val(): unexpected variant: %?", variant)) } }; @@ -2890,12 +2889,12 @@ pub fn declare_dbg_intrinsics(llmod: ModuleRef, intrinsics: &mut HashMap<&'stati pub fn trap(bcx: @mut Block) { match bcx.ccx().intrinsics.find_equiv(& &"llvm.trap") { Some(&x) => { Call(bcx, x, [], []); }, - _ => bcx.sess().bug("unbound llvm.trap in trap") + _ => bcx.tcx().sess.bug("unbound llvm.trap in trap") } } pub fn decl_gc_metadata(ccx: &mut CrateContext, llmod_id: &str) { - if !ccx.sess.opts.gc || !ccx.uses_gc { + if !ccx.tcx.sess.opts.gc || !ccx.uses_gc { return; } @@ -2948,14 +2947,14 @@ pub fn create_module_map(ccx: &mut CrateContext) -> ValueRef { } -pub fn decl_crate_map(sess: session::Session, mapmeta: LinkMeta, +pub fn decl_crate_map(sess: &session::Session, mapmeta: LinkMeta, llmod: ModuleRef) -> ValueRef { let targ_cfg = sess.targ_cfg; let int_type = Type::int(targ_cfg.arch); let mut n_subcrates = 1; let cstore = sess.cstore; while cstore::have_crate_data(cstore, n_subcrates) { n_subcrates += 1; } - let mapname = if *sess.building_library { + let mapname = if sess.building_library { fmt!("%s_%s_%s", mapmeta.name, mapmeta.vers, mapmeta.extras_hash) } else { ~"toplevel" @@ -2982,7 +2981,7 @@ pub fn decl_crate_map(sess: session::Session, mapmeta: LinkMeta, pub fn fill_crate_map(ccx: @mut CrateContext, map: ValueRef) { let mut subcrates: ~[ValueRef] = ~[]; let mut i = 1; - let cstore = ccx.sess.cstore; + let cstore = ccx.tcx.sess.cstore; while cstore::have_crate_data(cstore, i) { let cdata = cstore::get_crate_data(cstore, i); let nm = fmt!("_rust_crate_map_%s_%s_%s", @@ -3011,7 +3010,7 @@ pub fn fill_crate_map(ccx: @mut CrateContext, map: ValueRef) { pub fn crate_ctxt_to_encode_parms<'r>(cx: &'r CrateContext, ie: encoder::encode_inlined_item<'r>) -> encoder::EncodeParams<'r> { - let diag = cx.sess.diagnostic(); + let diag = cx.tcx.sess.diagnostic(); let item_symbols = &cx.item_symbols; let discrim_symbols = &cx.discrim_symbols; let link_meta = &cx.link_meta; @@ -3024,14 +3023,14 @@ pub fn crate_ctxt_to_encode_parms<'r>(cx: &'r CrateContext, ie: encoder::encode_ discrim_symbols: discrim_symbols, non_inlineable_statics: &cx.non_inlineable_statics, link_meta: link_meta, - cstore: cx.sess.cstore, + cstore: cx.tcx.sess.cstore, encode_inlined_item: ie, reachable: cx.reachable, } } pub fn write_metadata(cx: &mut CrateContext, crate: &ast::Crate) { - if !*cx.sess.building_library { return; } + if !cx.tcx.sess.building_library { return; } let encode_inlined_item: encoder::encode_inlined_item = |ecx, ebml_w, path, ii| @@ -3047,7 +3046,7 @@ pub fn write_metadata(cx: &mut CrateContext, crate: &ast::Crate) { }; unsafe { llvm::LLVMSetInitializer(llglobal, llconst); - do cx.sess.targ_cfg.target_strs.meta_sect_name.with_c_str |buf| { + do cx.tcx.sess.targ_cfg.target_strs.meta_sect_name.with_c_str |buf| { llvm::LLVMSetSection(llglobal, buf) }; lib::llvm::SetLinkage(llglobal, lib::llvm::InternalLinkage); @@ -3074,17 +3073,16 @@ pub fn write_abi_version(ccx: &mut CrateContext) { } } -pub fn trans_crate(sess: session::Session, - crate: &ast::Crate, - analysis: &CrateAnalysis, - output: &Path) -> CrateTranslation { +pub fn trans_crate(crate: &ast::Crate, analysis: &CrateAnalysis, output: &Path) + -> CrateTranslation { + // Before we touch LLVM, make sure that multithreading is enabled. if unsafe { !llvm::LLVMRustStartMultithreading() } { //sess.bug("couldn't enable multi-threaded LLVM"); } let mut symbol_hasher = hash::default_state(); - let link_meta = link::build_link_meta(sess, crate, output, &mut symbol_hasher); + let link_meta = link::build_link_meta(analysis.ty_cx.sess, crate, output, &mut symbol_hasher); // Append ".rc" to crate name as LLVM module identifier. // @@ -3096,8 +3094,7 @@ pub fn trans_crate(sess: session::Session, // 1. http://llvm.org/bugs/show_bug.cgi?id=11479 let llmod_id = link_meta.name.to_owned() + ".rc"; - let ccx = @mut CrateContext::new(sess, - llmod_id, + let ccx = @mut CrateContext::new(llmod_id, analysis.ty_cx, analysis.exp_map2, analysis.exported_items, @@ -3106,7 +3103,7 @@ pub fn trans_crate(sess: session::Session, link_meta, analysis.reachable); - if ccx.sess.opts.debuginfo { + if ccx.tcx.sess.opts.debuginfo { debuginfo::initialize(ccx, crate); } @@ -3124,8 +3121,8 @@ pub fn trans_crate(sess: session::Session, // __rust_crate_map_toplevel symbol (extra underscore) which it will // subsequently fail to find. So to mitigate that we just introduce // an alias from the symbol it expects to the one that actually exists. - if ccx.sess.targ_cfg.os == session::OsWin32 && - !*ccx.sess.building_library { + if ccx.tcx.sess.targ_cfg.os == session::OsWin32 && + !ccx.tcx.sess.building_library { let maptype = val_ty(ccx.crate_map).to_ref(); @@ -3139,13 +3136,13 @@ pub fn trans_crate(sess: session::Session, glue::emit_tydescs(ccx); write_abi_version(ccx); - if ccx.sess.opts.debuginfo { + if ccx.tcx.sess.opts.debuginfo { debuginfo::finalize(ccx); } // Translate the metadata. write_metadata(ccx, crate); - if ccx.sess.trans_stats() { + if ccx.tcx.sess.trans_stats() { io::println("--- trans stats ---"); println!("n_static_tydescs: {}", ccx.stats.n_static_tydescs); println!("n_glues_created: {}", ccx.stats.n_glues_created); @@ -3168,7 +3165,7 @@ pub fn trans_crate(sess: session::Session, } } } - if ccx.sess.count_llvm_insns() { + if ccx.tcx.sess.count_llvm_insns() { for (k, v) in ccx.stats.llvm_insns.iter() { println!("{:7u} {}", *v, *k); } @@ -3178,9 +3175,9 @@ pub fn trans_crate(sess: session::Session, let link_meta = ccx.link_meta; let llmod = ccx.llmod; - return CrateTranslation { + CrateTranslation { context: llcx, module: llmod, link: link_meta - }; + } } diff --git a/src/librustc/middle/trans/builder.rs b/src/librustc/middle/trans/builder.rs index d7a4dbb3510fe..9350be68d1a78 100644 --- a/src/librustc/middle/trans/builder.rs +++ b/src/librustc/middle/trans/builder.rs @@ -47,10 +47,10 @@ impl Builder { } pub fn count_insn(&self, category: &str) { - if self.ccx.sess.trans_stats() { + if self.ccx.tcx.sess.trans_stats() { self.ccx.stats.n_llvm_insns += 1; } - if self.ccx.sess.count_llvm_insns() { + if self.ccx.tcx.sess.count_llvm_insns() { do base::with_insn_ctxt |v| { let h = &mut self.ccx.stats.llvm_insns; @@ -724,15 +724,15 @@ impl Builder { } pub fn add_span_comment(&self, sp: Span, text: &str) { - if self.ccx.sess.asm_comments() { - let s = fmt!("%s (%s)", text, self.ccx.sess.codemap.span_to_str(sp)); + if self.ccx.tcx.sess.asm_comments() { + let s = fmt!("%s (%s)", text, self.ccx.tcx.sess.codemap.span_to_str(sp)); debug!("%s", s); self.add_comment(s); } } pub fn add_comment(&self, text: &str) { - if self.ccx.sess.asm_comments() { + if self.ccx.tcx.sess.asm_comments() { let sanitized = text.replace("$", ""); let comment_text = fmt!("# %s", sanitized.replace("\n", "\n\t# ")); self.count_insn("inlineasm"); diff --git a/src/librustc/middle/trans/cabi.rs b/src/librustc/middle/trans/cabi.rs index 005483a075f8d..d33942918d728 100644 --- a/src/librustc/middle/trans/cabi.rs +++ b/src/librustc/middle/trans/cabi.rs @@ -52,7 +52,7 @@ pub fn compute_abi_info(ccx: &mut CrateContext, atys: &[Type], rty: Type, ret_def: bool) -> FnType { - match ccx.sess.targ_cfg.arch { + match ccx.tcx.sess.targ_cfg.arch { X86 => cabi_x86::compute_abi_info(ccx, atys, rty, ret_def), X86_64 => cabi_x86_64::compute_abi_info(ccx, atys, rty, ret_def), Arm => cabi_arm::compute_abi_info(ccx, atys, rty, ret_def), diff --git a/src/librustc/middle/trans/cabi_x86.rs b/src/librustc/middle/trans/cabi_x86.rs index de53d8dd3dada..974e2e4bf7b89 100644 --- a/src/librustc/middle/trans/cabi_x86.rs +++ b/src/librustc/middle/trans/cabi_x86.rs @@ -41,7 +41,7 @@ pub fn compute_abi_info(ccx: &mut CrateContext, // Clang's ABI handling is in lib/CodeGen/TargetInfo.cpp enum Strategy { RetValue(Type), RetPointer } - let strategy = match ccx.sess.targ_cfg.os { + let strategy = match ccx.tcx.sess.targ_cfg.os { OsWin32 | OsMacos => { match llsize_of_alloc(ccx, rty) { 1 => RetValue(Type::i8()), diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index a327b2e193939..0035748d472af 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -363,7 +363,7 @@ pub fn trans_fn_ref_with_vtables( must_monomorphise = true; } else if def_id.crate == ast::LOCAL_CRATE { let map_node = session::expect( - ccx.sess, + ccx.tcx.sess, ccx.tcx.items.find(&def_id.node), || fmt!("local item should be in ast map")); diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs index b5b181e22a6eb..fcbb1d101cd06 100644 --- a/src/librustc/middle/trans/closure.rs +++ b/src/librustc/middle/trans/closure.rs @@ -231,7 +231,7 @@ pub fn store_environment(bcx: @mut Block, for (i, bv) in bound_values.iter().enumerate() { debug!("Copy %s into closure", bv.to_str(ccx)); - if ccx.sess.asm_comments() { + if ccx.tcx.sess.asm_comments() { add_comment(bcx, fmt!("Copy %s into closure", bv.to_str(ccx))); } @@ -311,7 +311,7 @@ pub fn load_environment(fcx: @mut FunctionContext, // Store the pointer to closure data in an alloca for debug info because that's what the // llvm.dbg.declare intrinsic expects - let env_pointer_alloca = if fcx.ccx.sess.opts.extra_debuginfo { + let env_pointer_alloca = if fcx.ccx.tcx.sess.opts.extra_debuginfo { let alloc = alloc_ty(bcx, ty::mk_mut_ptr(bcx.tcx(), cdata_ty), "__debuginfo_env_ptr"); Store(bcx, llcdata, alloc); Some(alloc) diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 377144b38e78c..b6a1bf957e829 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -275,7 +275,7 @@ impl FunctionContext { pub fn warn_not_to_commit(ccx: &mut CrateContext, msg: &str) { if !ccx.do_not_commit_warning_issued { ccx.do_not_commit_warning_issued = true; - ccx.sess.warn(msg.to_str() + " -- do not commit like this!"); + ccx.tcx.sess.warn(msg.to_str() + " -- do not commit like this!"); } } @@ -660,14 +660,13 @@ impl Block { pub fn ccx(&self) -> @mut CrateContext { self.fcx.ccx } pub fn tcx(&self) -> ty::ctxt { self.fcx.ccx.tcx } - pub fn sess(&self) -> Session { self.fcx.ccx.sess } pub fn ident(&self, ident: Ident) -> @str { token::ident_to_str(&ident) } pub fn node_id_to_str(&self, id: ast::NodeId) -> ~str { - ast_map::node_id_to_str(self.tcx().items, id, self.sess().intr()) + ast_map::node_id_to_str(self.tcx().items, id, self.tcx().sess.intr()) } pub fn expr_to_str(&self, e: @ast::Expr) -> ~str { @@ -769,7 +768,7 @@ pub fn in_scope_cx(cx: @mut Block, scope_id: Option, f: &fn(si: &mu pub fn block_parent(cx: @mut Block) -> @mut Block { match cx.parent { Some(b) => b, - None => cx.sess().bug(fmt!("block_parent called on root block %?", + None => cx.tcx().sess.bug(fmt!("block_parent called on root block %?", cx)) } } @@ -1042,7 +1041,7 @@ pub fn align_to(cx: @mut Block, off: ValueRef, align: ValueRef) -> ValueRef { return build::And(cx, bumped, build::Not(cx, mask)); } -pub fn path_str(sess: session::Session, p: &[path_elt]) -> ~str { +pub fn path_str(sess: &session::Session, p: &[path_elt]) -> ~str { let mut r = ~""; let mut first = true; for e in p.iter() { @@ -1095,7 +1094,7 @@ pub fn node_id_type_params(bcx: @mut Block, id: ast::NodeId) -> ~[ty::t] { let params = ty::node_id_to_type_params(tcx, id); if !params.iter().all(|t| !ty::type_needs_infer(*t)) { - bcx.sess().bug( + bcx.tcx().sess.bug( fmt!("Type parameters for node %d include inference types: %s", id, params.map(|t| bcx.ty_to_str(*t)).connect(","))); } @@ -1212,7 +1211,7 @@ pub fn dummy_substs(tps: ~[ty::t]) -> ty::substs { pub fn filename_and_line_num_from_span(bcx: @mut Block, span: Span) -> (ValueRef, ValueRef) { - let loc = bcx.sess().parse_sess.cm.lookup_char_pos(span.lo); + let loc = bcx.tcx().sess.parse_sess.cm.lookup_char_pos(span.lo); let filename_cstr = C_cstr(bcx.ccx(), loc.file.name); let filename = build::PointerCast(bcx, filename_cstr, Type::i8p()); let line = C_int(bcx.ccx(), loc.line as int); diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index a7a04627981a9..4a1778bee3aed 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -51,7 +51,7 @@ pub fn const_lit(cx: &mut CrateContext, e: &ast::Expr, lit: ast::lit) ty::ty_uint(t) => { C_integral(Type::uint_from_ty(cx, t), i as u64, false) } - _ => cx.sess.span_bug(lit.span, + _ => cx.tcx.sess.span_bug(lit.span, fmt!("integer literal has type %s (expected int or uint)", ty_to_str(cx.tcx, lit_int_ty))) } @@ -64,7 +64,7 @@ pub fn const_lit(cx: &mut CrateContext, e: &ast::Expr, lit: ast::lit) C_floating(fs, Type::float_from_ty(cx, t)) } _ => { - cx.sess.span_bug(lit.span, + cx.tcx.sess.span_bug(lit.span, "floating point literal doesn't have the right type"); } } @@ -144,14 +144,14 @@ fn const_deref(cx: &mut CrateContext, v: ValueRef, t: ty::t, explicit: bool) const_deref_newtype(cx, v, t) } _ => { - cx.sess.bug(fmt!("Unexpected dereferenceable type %s", + cx.tcx.sess.bug(fmt!("Unexpected dereferenceable type %s", ty_to_str(cx.tcx, t))) } }; (dv, mt.ty) } None => { - cx.sess.bug(fmt!("Can't dereference const of type %s", + cx.tcx.sess.bug(fmt!("Can't dereference const of type %s", ty_to_str(cx.tcx, t))) } } @@ -189,7 +189,7 @@ pub fn const_expr(cx: @mut CrateContext, e: @ast::Expr) -> (ValueRef, bool) { llconst = C_struct([llconst, C_null(Type::opaque_box(cx).ptr_to())]) } Some(@ty::AutoAddEnv(ref r, ref s)) => { - cx.sess.span_bug(e.span, fmt!("unexpected static function: \ + cx.tcx.sess.span_bug(e.span, fmt!("unexpected static function: \ region %? sigil %?", *r, *s)) } Some(@ty::AutoDerefRef(ref adj)) => { @@ -233,7 +233,7 @@ pub fn const_expr(cx: @mut CrateContext, e: @ast::Expr) -> (ValueRef, bool) { } } _ => { - cx.sess.span_bug(e.span, + cx.tcx.sess.span_bug(e.span, fmt!("unimplemented const \ autoref %?", autoref)) } @@ -253,7 +253,7 @@ pub fn const_expr(cx: @mut CrateContext, e: @ast::Expr) -> (ValueRef, bool) { llvm::LLVMDumpValue(llconst); llvm::LLVMDumpValue(C_undef(llty)); } - cx.sess.bug(fmt!("const %s of type %s has size %u instead of %u", + cx.tcx.sess.bug(fmt!("const %s of type %s has size %u instead of %u", e.repr(cx.tcx), ty_to_str(cx.tcx, ety), csize, tsize)); } @@ -402,7 +402,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, let iv = match const_eval::eval_const_expr(cx.tcx, index) { const_eval::const_int(i) => i as u64, const_eval::const_uint(u) => u, - _ => cx.sess.span_bug(index.span, + _ => cx.tcx.sess.span_bug(index.span, "index is not an integer-constant expression") }; let (arr, len) = match ty::get(bt).sty { @@ -421,10 +421,10 @@ fn const_expr_unadjusted(cx: @mut CrateContext, llvm::LLVMConstUDiv(const_get_elt(cx, bv, [1]), unit_sz)) }, - _ => cx.sess.span_bug(base.span, + _ => cx.tcx.sess.span_bug(base.span, "index-expr base must be fixed-size or slice") }, - _ => cx.sess.span_bug(base.span, + _ => cx.tcx.sess.span_bug(base.span, "index-expr base must be a vector or string type") }; @@ -436,7 +436,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, if iv >= len { // FIXME #3170: report this earlier on in the const-eval // pass. Reporting here is a bit late. - cx.sess.span_err(e.span, + cx.tcx.sess.span_err(e.span, "const index-expr is out of bounds"); } (const_get_elt(cx, arr, [iv as c_uint]), inlineable) @@ -479,7 +479,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, llvm::LLVMConstIntCast(iv, llty.to_ref(), s) } expr::cast_float => llvm::LLVMConstUIToFP(iv, llty.to_ref()), - _ => cx.sess.bug("enum cast destination is not \ + _ => cx.tcx.sess.bug("enum cast destination is not \ integral or float") } } @@ -490,7 +490,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, llvm::LLVMConstIntToPtr(v, llty.to_ref()) } _ => { - cx.sess.impossible_case(e.span, + cx.tcx.sess.impossible_case(e.span, "bad combination of types for cast") } }, inlineable) @@ -546,7 +546,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, ast::ExprLit(ref lit) => { match lit.node { ast::lit_str(*) => { const_expr(cx, sub) } - _ => { cx.sess.span_bug(e.span, "bad const-slice lit") } + _ => { cx.tcx.sess.span_bug(e.span, "bad const-slice lit") } } } ast::ExprVec(ref es, ast::MutImmutable) => { @@ -561,7 +561,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, let p = const_ptrcast(cx, gv, llunitty); (C_struct([p, sz]), false) } - _ => cx.sess.span_bug(e.span, "bad const-slice expr") + _ => cx.tcx.sess.span_bug(e.span, "bad const-slice expr") } } ast::ExprRepeat(elem, count, _) => { @@ -571,7 +571,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, let n = match const_eval::eval_const_expr(cx.tcx, count) { const_eval::const_int(i) => i as uint, const_eval::const_uint(i) => i as uint, - _ => cx.sess.span_bug(count.span, "count must be integral const expression.") + _ => cx.tcx.sess.span_bug(count.span, "count must be integral const expression.") }; let vs = vec::from_elem(n, const_expr(cx, elem).first()); let v = if vs.iter().any(|vi| val_ty(*vi) != llunitty) { @@ -613,7 +613,7 @@ fn const_expr_unadjusted(cx: @mut CrateContext, (C_null(llty), true) } _ => { - cx.sess.span_bug(e.span, "expected a const, fn, struct, or variant def") + cx.tcx.sess.span_bug(e.span, "expected a const, fn, struct, or variant def") } } } @@ -636,11 +636,11 @@ fn const_expr_unadjusted(cx: @mut CrateContext, (adt::trans_const(cx, repr, vinfo.disr_val, arg_vals), inlineable) } - _ => cx.sess.span_bug(e.span, "expected a struct or variant def") + _ => cx.tcx.sess.span_bug(e.span, "expected a struct or variant def") } } ast::ExprParen(e) => { const_expr(cx, e) } - _ => cx.sess.span_bug(e.span, + _ => cx.tcx.sess.span_bug(e.span, "bad constant expression type in consts::const_expr") }; } diff --git a/src/librustc/middle/trans/context.rs b/src/librustc/middle/trans/context.rs index 36757374b0b06..2789d60188f97 100644 --- a/src/librustc/middle/trans/context.rs +++ b/src/librustc/middle/trans/context.rs @@ -10,7 +10,6 @@ use back::{upcall}; -use driver::session; use lib::llvm::{ContextRef, ModuleRef, ValueRef}; use lib::llvm::{llvm, TargetData, TypeNames}; use lib::llvm::mk_target_data; @@ -40,7 +39,6 @@ use middle::trans::common::{mono_id,ExternMap,tydesc_info,BuilderRef_res,Stats}; use middle::trans::base::{decl_crate_map}; pub struct CrateContext { - sess: session::Session, llmod: ModuleRef, llcx: ContextRef, td: TargetData, @@ -122,8 +120,7 @@ pub struct CrateContext { } impl CrateContext { - pub fn new(sess: session::Session, - name: &str, + pub fn new(name: &str, tcx: ty::ctxt, emap2: resolve::ExportMap2, exported_items: @privacy::ExportedItems, @@ -138,21 +135,21 @@ impl CrateContext { let llmod = do name.with_c_str |buf| { llvm::LLVMModuleCreateWithNameInContext(buf, llcx) }; - let data_layout: &str = sess.targ_cfg.target_strs.data_layout; - let targ_triple: &str = sess.targ_cfg.target_strs.target_triple; + let data_layout: &str = tcx.sess.targ_cfg.target_strs.data_layout; + let targ_triple: &str = tcx.sess.targ_cfg.target_strs.target_triple; do data_layout.with_c_str |buf| { llvm::LLVMSetDataLayout(llmod, buf) }; do targ_triple.with_c_str |buf| { llvm::LLVMRustSetNormalizedTarget(llmod, buf) }; - let targ_cfg = sess.targ_cfg; + let targ_cfg = tcx.sess.targ_cfg; - let td = mk_target_data(sess.targ_cfg.target_strs.data_layout); + let td = mk_target_data(tcx.sess.targ_cfg.target_strs.data_layout); let mut tn = TypeNames::new(); let mut intrinsics = base::declare_intrinsics(llmod); - if sess.opts.extra_debuginfo { + if tcx.sess.opts.extra_debuginfo { base::declare_dbg_intrinsics(llmod, &mut intrinsics); } let int_type = Type::int(targ_cfg.arch); @@ -166,19 +163,18 @@ impl CrateContext { tn.associate_type("tydesc", &tydesc_type); tn.associate_type("str_slice", &str_slice_ty); - let crate_map = decl_crate_map(sess, link_meta, llmod); - let dbg_cx = if sess.opts.debuginfo { + let crate_map = decl_crate_map(tcx.sess, link_meta, llmod); + let dbg_cx = if tcx.sess.opts.debuginfo { Some(debuginfo::CrateDebugContext::new(llmod, name.to_owned())) } else { None }; - if sess.count_llvm_insns() { + if tcx.sess.count_llvm_insns() { base::init_insn_ctxt() } CrateContext { - sess: sess, llmod: llmod, llcx: llcx, td: td, diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index bfa7beace8ced..16d13f7f6fc78 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -310,7 +310,7 @@ pub fn trans_fail_expr(bcx: @mut Block, } else if bcx.unreachable || ty::type_is_bot(arg_datum.ty) { return bcx; } else { - bcx.sess().span_bug( + bcx.tcx().sess.span_bug( arg_expr.span, ~"fail called with unsupported type " + ppaux::ty_to_str(tcx, arg_datum.ty)); } @@ -336,8 +336,7 @@ fn trans_fail_value(bcx: @mut Block, let ccx = bcx.ccx(); let (V_filename, V_line) = match sp_opt { Some(sp) => { - let sess = bcx.sess(); - let loc = sess.parse_sess.cm.lookup_char_pos(sp.lo); + let loc = bcx.tcx().sess.parse_sess.cm.lookup_char_pos(sp.lo); (C_cstr(bcx.ccx(), loc.file.name), loc.line as int) } diff --git a/src/librustc/middle/trans/datum.rs b/src/librustc/middle/trans/datum.rs index 8ee38b950bf52..4c4dc3ec8427a 100644 --- a/src/librustc/middle/trans/datum.rs +++ b/src/librustc/middle/trans/datum.rs @@ -731,8 +731,7 @@ impl Datum { match self.try_deref(bcx, expr.span, expr.id, derefs, false) { (Some(lvres), bcx) => DatumBlock { bcx: bcx, datum: lvres }, (None, _) => { - bcx.ccx().sess.span_bug(expr.span, - "Cannot deref this expression"); + bcx.tcx().sess.span_bug(expr.span, "Cannot deref this expression"); } } } diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index c36d427a06cae..37c13599abc8f 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -170,10 +170,10 @@ impl FunctionDebugContext { match *self { FunctionDebugContext(~ref data) => data, DebugInfoDisabled => { - cx.sess.span_bug(span, FunctionDebugContext::debuginfo_disabled_message()); + cx.tcx.sess.span_bug(span, FunctionDebugContext::debuginfo_disabled_message()); } FunctionWithoutDebugInfo => { - cx.sess.span_bug(span, FunctionDebugContext::should_be_ignored_message()); + cx.tcx.sess.span_bug(span, FunctionDebugContext::should_be_ignored_message()); } } } @@ -185,10 +185,10 @@ impl FunctionDebugContext { match *self { FunctionDebugContext(~ref mut data) => data, DebugInfoDisabled => { - cx.sess.span_bug(span, FunctionDebugContext::debuginfo_disabled_message()); + cx.tcx.sess.span_bug(span, FunctionDebugContext::debuginfo_disabled_message()); } FunctionWithoutDebugInfo => { - cx.sess.span_bug(span, FunctionDebugContext::should_be_ignored_message()); + cx.tcx.sess.span_bug(span, FunctionDebugContext::should_be_ignored_message()); } } } @@ -303,14 +303,15 @@ pub fn create_captured_var_metadata(bcx: @mut Block, let ast_item = cx.tcx.items.find_copy(&node_id); let variable_ident = match ast_item { None => { - cx.sess.span_bug(span, "debuginfo::create_captured_var_metadata() - NodeId not found"); + cx.tcx.sess.span_bug(span, + "debuginfo::create_captured_var_metadata() - NodeId not found"); } Some(ast_map::node_local(ident)) => ident, Some(ast_map::node_arg(@ast::Pat { node: ast::PatIdent(_, ref path, _), _ })) => { ast_util::path_to_ident(path) } _ => { - cx.sess.span_bug(span, fmt!("debuginfo::create_captured_var_metadata() - \ + cx.tcx.sess.span_bug(span, fmt!("debuginfo::create_captured_var_metadata() - \ Captured var-id refers to unexpected ast_map variant: %?", ast_item)); } }; @@ -407,7 +408,7 @@ pub fn create_self_argument_metadata(bcx: @mut Block, _) => { explicit_self.span } - _ => bcx.ccx().sess.bug( + _ => bcx.ccx().tcx.sess.bug( fmt!("create_self_argument_metadata: unexpected sort of node: %?", fnitem)) }; @@ -464,7 +465,7 @@ pub fn create_argument_metadata(bcx: @mut Block, }; if unsafe { llvm::LLVMIsAAllocaInst(llptr) } == ptr::null() { - cx.sess.span_bug(span, "debuginfo::create_argument_metadata() - \ + cx.tcx.sess.span_bug(span, "debuginfo::create_argument_metadata() - \ Referenced variable location is not an alloca!"); } @@ -501,7 +502,7 @@ pub fn set_source_location(fcx: &FunctionContext, let cx = fcx.ccx; - debug!("set_source_location: %s", cx.sess.codemap.span_to_str(span)); + debug!("set_source_location: %s", cx.tcx.sess.codemap.span_to_str(span)); if fcx.debug_context.get_ref(cx, span).source_locations_enabled { let loc = span_start(cx, span); @@ -535,7 +536,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext, fn_ast_id: ast::NodeId, param_substs: Option<@param_substs>, llfn: ValueRef) -> FunctionDebugContext { - if !cx.sess.opts.debuginfo { + if !cx.tcx.sess.opts.debuginfo { return DebugInfoDisabled; } @@ -553,7 +554,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext, (item.ident, fn_decl, generics, top_level_block, item.span) } _ => { - cx.sess.span_bug(item.span, + cx.tcx.sess.span_bug(item.span, "create_function_debug_context: item bound to non-function"); } } @@ -583,7 +584,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext, top_level_block, expr.span) } - _ => cx.sess.span_bug(expr.span, + _ => cx.tcx.sess.span_bug(expr.span, "create_function_debug_context: expected an expr_fn_block here") } } @@ -606,7 +607,8 @@ pub fn create_function_debug_context(cx: &mut CrateContext, ast_map::node_struct_ctor(*) => { return FunctionWithoutDebugInfo; } - _ => cx.sess.bug(fmt!("create_function_debug_context: unexpected sort of node: %?", fnitem)) + _ => cx.tcx.sess.bug(fmt!("create_function_debug_context: unexpected sort of node: %?", + fnitem)) }; // This can be the case for functions inlined from another crate @@ -637,7 +639,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext, } None => { // This branch is only hit when there is a bug in the NamespaceVisitor. - cx.sess.span_warn(span, fmt!("debuginfo: Could not find namespace node for function + cx.tcx.sess.span_warn(span, fmt!("debuginfo: Could not find namespace node for function with name %s. This is a bug! Please report this to github.com/mozilla/rust/issues", function_name)); (function_name.clone(), file_metadata) @@ -661,7 +663,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext, true, scope_line as c_uint, FlagPrototyped as c_uint, - cx.sess.opts.optimize != session::No, + cx.tcx.sess.opts.optimize != session::No, llfn, template_parameters, ptr::null()) @@ -696,7 +698,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext, fn_decl: &ast::fn_decl, param_substs: Option<@param_substs>, error_span: Span) -> DIArray { - if !cx.sess.opts.extra_debuginfo { + if !cx.tcx.sess.opts.extra_debuginfo { return create_DIArray(DIB(cx), []); } @@ -774,7 +776,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext, } // Only create type information if extra_debuginfo is enabled - if cx.sess.opts.extra_debuginfo { + if cx.tcx.sess.opts.extra_debuginfo { let actual_self_type_metadata = type_metadata(cx, actual_self_type, codemap::dummy_sp()); @@ -817,7 +819,7 @@ pub fn create_function_debug_context(cx: &mut CrateContext, } // Again, only create type information if extra_debuginfo is enabled - if cx.sess.opts.extra_debuginfo { + if cx.tcx.sess.opts.extra_debuginfo { let actual_type_metadata = type_metadata(cx, actual_type, codemap::dummy_sp()); let param_metadata = do token::ident_to_str(&ident).with_c_str |name| { unsafe { @@ -872,7 +874,7 @@ fn compile_unit_metadata(cx: @mut CrateContext) { debug!("compile_unit_metadata: %?", crate_name); - let work_dir = cx.sess.working_dir.to_str(); + let work_dir = cx.tcx.sess.working_dir.to_str(); let producer = fmt!("rustc version %s", env!("CFG_VERSION")); do crate_name.with_c_str |crate_name| { @@ -887,7 +889,7 @@ fn compile_unit_metadata(cx: @mut CrateContext) { crate_name, work_dir, producer, - cx.sess.opts.optimize != session::No, + cx.tcx.sess.opts.optimize != session::No, flags, 0, split_name); @@ -930,7 +932,7 @@ fn declare_local(bcx: @mut Block, file_metadata, loc.line as c_uint, type_metadata, - cx.sess.opts.optimize != session::No, + cx.tcx.sess.opts.optimize != session::No, 0, argument_index) } @@ -982,7 +984,7 @@ fn file_metadata(cx: &mut CrateContext, full_path: &str) -> DIFile { debug!("file_metadata: %s", full_path); - let work_dir = cx.sess.working_dir.to_str(); + let work_dir = cx.tcx.sess.working_dir.to_str(); let file_name = if full_path.starts_with(work_dir) { full_path.slice(work_dir.len() + 1u, full_path.len()) @@ -1014,7 +1016,7 @@ fn scope_metadata(fcx: &FunctionContext, None => { let node = fcx.ccx.tcx.items.get_copy(&node_id); - fcx.ccx.sess.span_bug(span, + fcx.ccx.tcx.sess.span_bug(span, fmt!("debuginfo: Could not find scope info for node %?", node)); } } @@ -1047,7 +1049,7 @@ fn basic_type_metadata(cx: &mut CrateContext, t: ty::t) -> DIType { ast::ty_f32 => (~"f32", DW_ATE_float), ast::ty_f64 => (~"f64", DW_ATE_float) }, - _ => cx.sess.bug("debuginfo::basic_type_metadata - t is invalid type") + _ => cx.tcx.sess.bug("debuginfo::basic_type_metadata - t is invalid type") }; let llvm_type = type_of::type_of(cx, t); @@ -1263,7 +1265,7 @@ impl MemberDescriptionFactory for GeneralMemberDescriptionFactory { // Capture type_rep, so we don't have to copy the struct_defs array let struct_defs = match *self.type_rep { adt::General(ref struct_defs) => struct_defs, - _ => cx.sess.bug("unreachable") + _ => cx.tcx.sess.bug("unreachable") }; do struct_defs @@ -1339,7 +1341,7 @@ fn describe_variant(cx: &mut CrateContext, match cx.tcx.items.find(&variant_info.id.node) { Some(&ast_map::node_variant(ref variant, _, _)) => variant.span, ref node => { - cx.sess.span_warn(span, + cx.tcx.sess.span_warn(span, fmt!("debuginfo::enum_metadata()::adt_struct_metadata() - Unexpected node \ type: %?. This is a bug.", node)); codemap::dummy_sp() @@ -1767,7 +1769,7 @@ fn vec_metadata(cx: &mut CrateContext, let element_llvm_type = type_of::type_of(cx, element_type); let (element_size, element_align) = size_and_align_of(cx, element_llvm_type); - let vec_llvm_type = Type::vec(cx.sess.targ_cfg.arch, &element_llvm_type); + let vec_llvm_type = Type::vec(cx.tcx.sess.targ_cfg.arch, &element_llvm_type); let vec_type_name: &str = fmt!("[%s]", ppaux::ty_to_str(cx.tcx, element_type)); let member_llvm_types = vec_llvm_type.field_types(); @@ -1823,7 +1825,7 @@ fn boxed_vec_metadata(cx: &mut CrateContext, span: Span) -> DICompositeType { let element_llvm_type = type_of::type_of(cx, element_type); - let vec_llvm_type = Type::vec(cx.sess.targ_cfg.arch, &element_llvm_type); + let vec_llvm_type = Type::vec(cx.tcx.sess.targ_cfg.arch, &element_llvm_type); let vec_type_name: &str = fmt!("[%s]", ppaux::ty_to_str(cx.tcx, element_type)); let vec_metadata = vec_metadata(cx, element_type, span); @@ -2095,7 +2097,7 @@ fn type_metadata(cx: &mut CrateContext, ty::ty_opaque_box => { create_pointer_to_box_metadata(cx, t, ty::mk_nil()) } - _ => cx.sess.bug(fmt!("debuginfo: unexpected type in type_metadata: %?", sty)) + _ => cx.tcx.sess.bug(fmt!("debuginfo: unexpected type in type_metadata: %?", sty)) }; debug_context(cx).created_types.insert(cache_id, type_metadata); @@ -2159,7 +2161,7 @@ fn roundup(x: uint, a: uint) -> uint { /// Return codemap::Loc corresponding to the beginning of the span fn span_start(cx: &CrateContext, span: Span) -> codemap::Loc { - cx.sess.codemap.lookup_char_pos(span.lo) + cx.tcx.sess.codemap.lookup_char_pos(span.lo) } fn size_and_align_of(cx: &mut CrateContext, llvm_type: Type) -> (uint, uint) { @@ -2189,7 +2191,7 @@ fn fn_should_be_ignored(fcx: &FunctionContext) -> bool { fn assert_type_for_node_id(cx: &CrateContext, node_id: ast::NodeId, error_span: Span) { if !cx.tcx.node_types.contains_key(&(node_id as uint)) { - cx.sess.span_bug(error_span, "debuginfo: Could not find type for node id!"); + cx.tcx.sess.span_bug(error_span, "debuginfo: Could not find type for node id!"); } } @@ -2202,8 +2204,9 @@ fn get_namespace_and_span_for_item(cx: &mut CrateContext, let definition_span = match cx.tcx.items.find(&def_id.node) { Some(&ast_map::node_item(@ast::item { span, _ }, _)) => span, ref node => { - cx.sess.span_warn(warning_span, fmt!("debuginfo::get_namespace_and_span_for_item() \ - - Unexpected node type: %?", *node)); + cx.tcx.sess.span_warn(warning_span, + fmt!("debuginfo::get_namespace_and_span_for_item() \ + - Unexpected node type: %?", *node)); codemap::dummy_sp() } }; @@ -2256,7 +2259,7 @@ fn populate_scope_map(cx: &mut CrateContext, &mut ~[ScopeStackEntry], &mut HashMap)) { // Create a new lexical scope and push it onto the stack - let loc = cx.sess.codemap.lookup_char_pos(scope_span.lo); + let loc = cx.tcx.sess.codemap.lookup_char_pos(scope_span.lo); let file_metadata = file_metadata(cx, loc.file.name); let parent_scope = scope_stack.last().scope_metadata; @@ -2279,7 +2282,7 @@ fn populate_scope_map(cx: &mut CrateContext, } if scope_stack.last().scope_metadata != scope_metadata { - cx.sess.span_bug(scope_span, "debuginfo: Inconsistency in scope management."); + cx.tcx.sess.span_bug(scope_span, "debuginfo: Inconsistency in scope management."); } scope_stack.pop(); @@ -2372,7 +2375,7 @@ fn populate_scope_map(cx: &mut CrateContext, if need_new_scope { // Create a new lexical scope and push it onto the stack - let loc = cx.sess.codemap.lookup_char_pos(pat.span.lo); + let loc = cx.tcx.sess.codemap.lookup_char_pos(pat.span.lo); let file_metadata = file_metadata(cx, loc.file.name); let parent_scope = scope_stack.last().scope_metadata; @@ -2551,12 +2554,12 @@ fn populate_scope_map(cx: &mut CrateContext, } ast::ExprForLoop(_, _, _, _) => { - cx.sess.span_bug(exp.span, "debuginfo::populate_scope_map() - \ + cx.tcx.sess.span_bug(exp.span, "debuginfo::populate_scope_map() - \ Found unexpanded for-loop."); } ast::ExprMac(_) => { - cx.sess.span_bug(exp.span, "debuginfo::populate_scope_map() - \ + cx.tcx.sess.span_bug(exp.span, "debuginfo::populate_scope_map() - \ Found unexpanded macro."); } @@ -2589,7 +2592,7 @@ fn populate_scope_map(cx: &mut CrateContext, }; if !inner_expr_is_expr_fn_block { - cx.sess.span_bug(inner_exp.span, "debuginfo: Inner expression was expected \ + cx.tcx.sess.span_bug(inner_exp.span, "debuginfo: Inner expression was expected \ to be an ast::expr_fn_block."); } @@ -2704,7 +2707,7 @@ fn namespace_for_external_item(cx: &mut CrateContext, item_path: &ast_map::path) -> @NamespaceTreeNode { if item_path.len() < 2 { - cx.sess.bug(fmt!("debuginfo::namespace_for_external_item() - Invalid item_path: %s", + cx.tcx.sess.bug(fmt!("debuginfo::namespace_for_external_item() - Invalid item_path: %s", ast_map::path_to_str(*item_path, token::get_ident_interner()))); } @@ -2763,7 +2766,7 @@ fn namespace_for_external_item(cx: &mut CrateContext, } } - cx.sess.bug("debuginfo::namespace_for_external_item() - Code path should be unreachable"); + cx.tcx.sess.bug("debuginfo::namespace_for_external_item() - Code path should be unreachable"); } struct NamespaceVisitor<'self> { diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 01702e749a356..35b4b475ebe40 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -318,7 +318,7 @@ pub fn trans_to_datum(bcx: @mut Block, expr: @ast::Expr) -> DatumBlock { let (source_store, source_mutbl) = match ty::get(source_datum.ty).sty { ty::ty_trait(_, _, s, m, _) => (s, m), _ => { - bcx.sess().span_bug( + bcx.tcx().sess.span_bug( expr.span, fmt!("auto_borrow_trait_obj expected a trait, found %s", source_datum.ty.repr(bcx.tcx()))); @@ -488,7 +488,7 @@ fn trans_lvalue(bcx: @mut Block, expr: @ast::Expr) -> DatumBlock { return match bcx.tcx().adjustments.find(&expr.id) { None => trans_lvalue_unadjusted(bcx, expr), Some(_) => { - bcx.sess().span_bug( + bcx.tcx().sess.span_bug( expr.span, fmt!("trans_lvalue() called on an expression \ with adjustments")); @@ -1042,7 +1042,7 @@ fn trans_lvalue_unadjusted(bcx: @mut Block, expr: @ast::Expr) -> DatumBlock { unsafe { let llty = type_of(bcx.ccx(), const_ty); let symbol = csearch::get_symbol( - bcx.ccx().sess.cstore, + bcx.tcx().sess.cstore, did); let llval = do symbol.with_c_str |buf| { llvm::LLVMAddGlobal(bcx.ccx().llmod, @@ -1091,7 +1091,7 @@ pub fn trans_local_var(bcx: @mut Block, def: ast::Def) -> Datum { } } None => { - bcx.sess().bug(fmt!( + bcx.tcx().sess.bug(fmt!( "trans_local_var: no llval for upvar %? found", nid)); } } @@ -1106,7 +1106,7 @@ pub fn trans_local_var(bcx: @mut Block, def: ast::Def) -> Datum { let self_info: ValSelfData = match bcx.fcx.llself { Some(ref self_info) => *self_info, None => { - bcx.sess().bug(fmt!( + bcx.tcx().sess.bug(fmt!( "trans_local_var: reference to self \ out of context with id %?", nid)); } @@ -1122,7 +1122,7 @@ pub fn trans_local_var(bcx: @mut Block, def: ast::Def) -> Datum { } } _ => { - bcx.sess().unimpl(fmt!( + bcx.tcx().sess.unimpl(fmt!( "unsupported def type in trans_local_var: %?", def)); } }; @@ -1133,7 +1133,7 @@ pub fn trans_local_var(bcx: @mut Block, def: ast::Def) -> Datum { let v = match table.find(&nid) { Some(&v) => v, None => { - bcx.sess().bug(fmt!( + bcx.tcx().sess.bug(fmt!( "trans_local_var: no llval for local/arg %? found", nid)); } }; @@ -1383,7 +1383,7 @@ fn trans_unary_datum(bcx: @mut Block, trans_boxed_expr(bcx, un_ty, sub_expr, sub_ty, heap) } ast::UnDeref => { - bcx.sess().bug("deref expressions should have been \ + bcx.tcx().sess.bug("deref expressions should have been \ translated using trans_lvalue(), not \ trans_unary_datum()") } @@ -1733,13 +1733,13 @@ fn trans_imm_cast(bcx: @mut Block, expr: @ast::Expr, val_ty(lldiscrim_a), lldiscrim_a, true), cast_float => SIToFP(bcx, lldiscrim_a, ll_t_out), - _ => ccx.sess.bug(fmt!("translating unsupported cast: \ + _ => ccx.tcx.sess.bug(fmt!("translating unsupported cast: \ %s (%?) -> %s (%?)", t_in.repr(ccx.tcx), k_in, t_out.repr(ccx.tcx), k_out)) } } - _ => ccx.sess.bug(fmt!("translating unsupported cast: \ + _ => ccx.tcx.sess.bug(fmt!("translating unsupported cast: \ %s (%?) -> %s (%?)", t_in.repr(ccx.tcx), k_in, t_out.repr(ccx.tcx), k_out)) @@ -1798,14 +1798,14 @@ pub fn trans_log_level(bcx: @mut Block) -> DatumBlock { let (modpath, modname) = { let path = &mut bcx.fcx.path; - let mut modpath = ~[path_mod(ccx.sess.ident_of(ccx.link_meta.name))]; + let mut modpath = ~[path_mod(ccx.tcx.sess.ident_of(ccx.link_meta.name))]; for e in path.iter() { match *e { path_mod(_) => { modpath.push(*e) } _ => {} } } - let modname = path_str(ccx.sess, modpath); + let modname = path_str(ccx.tcx.sess, modpath); (modpath, modname) }; diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index f28f5449e0046..fb0868e5c29a3 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -75,17 +75,17 @@ struct LlvmSignature { pub fn llvm_calling_convention(ccx: &mut CrateContext, abis: AbiSet) -> Option { - let arch = ccx.sess.targ_cfg.arch; + let arch = ccx.tcx.sess.targ_cfg.arch; abis.for_arch(arch).map(|abi| { match *abi { RustIntrinsic => { // Intrinsics are emitted by monomorphic fn - ccx.sess.bug(fmt!("Asked to register intrinsic fn")); + ccx.tcx.sess.bug(fmt!("Asked to register intrinsic fn")); } Rust => { // FIXME(#3678) Implement linking to foreign fns with Rust ABI - ccx.sess.unimpl( + ccx.tcx.sess.unimpl( fmt!("Foreign functions with Rust ABI")); } @@ -121,13 +121,13 @@ pub fn register_foreign_item_fn(ccx: @mut CrateContext, Some(cc) => cc, None => { // FIXME(#8357) We really ought to report a span here - ccx.sess.fatal( + ccx.tcx.sess.fatal( fmt!("ABI `%s` has no suitable ABI \ for target architecture \ in module %s", abis.user_string(ccx.tcx), ast_map::path_to_str(*path, - ccx.sess.intr()))); + ccx.tcx.sess.intr()))); } }; @@ -174,7 +174,7 @@ pub fn trans_native_call(bcx: @mut Block, let (fn_abis, fn_sig) = match ty::get(callee_ty).sty { ty::ty_bare_fn(ref fn_ty) => (fn_ty.abis, fn_ty.sig.clone()), - _ => ccx.sess.bug("trans_native_call called on non-function type") + _ => ccx.tcx.sess.bug("trans_native_call called on non-function type") }; let llsig = foreign_signature(ccx, &fn_sig); let ret_def = !ty::type_is_voidish(fn_sig.output); @@ -257,7 +257,7 @@ pub fn trans_native_call(bcx: @mut Block, Some(cc) => cc, None => { // FIXME(#8357) We really ought to report a span here - ccx.sess.fatal( + ccx.tcx.sess.fatal( fmt!("ABI string `%s` has no suitable ABI \ for target architecture", fn_abis.user_string(ccx.tcx))); @@ -416,7 +416,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: @mut CrateContext, f } _ => { - ccx.sess.bug(fmt!("build_rust_fn: extern fn %s has ty %s, \ + ccx.tcx.sess.bug(fmt!("build_rust_fn: extern fn %s has ty %s, \ expected a bare fn ty", path.repr(tcx), t.repr(tcx))); @@ -682,7 +682,7 @@ pub fn trans_rust_fn_with_foreign_abi(ccx: @mut CrateContext, pub fn link_name(ccx: &CrateContext, i: @ast::foreign_item) -> @str { match attr::first_attr_value_str_by_name(i.attrs, "link_name") { - None => ccx.sess.str_of(i.ident), + None => ccx.tcx.sess.str_of(i.ident), Some(ln) => ln, } } @@ -715,7 +715,7 @@ fn foreign_types_for_fn_ty(ccx: &mut CrateContext, ty: ty::t) -> ForeignTypes { let fn_sig = match ty::get(ty).sty { ty::ty_bare_fn(ref fn_ty) => fn_ty.sig.clone(), - _ => ccx.sess.bug("foreign_types_for_fn_ty called on non-function type") + _ => ccx.tcx.sess.bug("foreign_types_for_fn_ty called on non-function type") }; let llsig = foreign_signature(ccx, &fn_sig); let ret_def = !ty::type_is_voidish(fn_sig.output); diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index 28fffb6a80a2d..d9ba45436bdd5 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -285,7 +285,7 @@ pub fn call_tydesc_glue_full(bcx: @mut Block, // NB: Don't short-circuit even if this block is unreachable because // GC-based cleanup needs to the see that the roots are live. let no_lpads = - ccx.sess.opts.debugging_opts & session::no_landing_pads != 0; + ccx.tcx.sess.opts.debugging_opts & session::no_landing_pads != 0; if bcx.unreachable && !no_lpads { return; } let static_glue_fn = match static_ti { @@ -645,7 +645,7 @@ pub fn declare_tydesc(ccx: &mut CrateContext, t: ty::t) -> @mut tydesc_info { let llty = type_of(ccx, t); - if ccx.sess.count_type_sizes() { + if ccx.tcx.sess.count_type_sizes() { println!("{}\t{}", llsize_of_real(ccx, llty), ppaux::ty_to_str(ccx.tcx, t)); } diff --git a/src/librustc/middle/trans/inline.rs b/src/librustc/middle/trans/inline.rs index 8900b50b49df2..5b1324232d18a 100644 --- a/src/librustc/middle/trans/inline.rs +++ b/src/librustc/middle/trans/inline.rs @@ -99,14 +99,14 @@ pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::DefId) ccx.external.insert(there.id, Some(here.id.node)); } } - _ => ccx.sess.bug("maybe_instantiate_inline: item has a \ + _ => ccx.tcx.sess.bug("maybe_instantiate_inline: item has a \ non-enum parent") } trans_item(ccx, item); local_def(my_id) } csearch::found_parent(_, _) => { - ccx.sess.bug("maybe_get_item_ast returned a found_parent \ + ccx.tcx.sess.bug("maybe_get_item_ast returned a found_parent \ with a non-item parent"); } csearch::found(ast::ii_method(impl_did, is_provided, mth)) => { diff --git a/src/librustc/middle/trans/intrinsic.rs b/src/librustc/middle/trans/intrinsic.rs index d17773d3302f1..40beb15218ed8 100644 --- a/src/librustc/middle/trans/intrinsic.rs +++ b/src/librustc/middle/trans/intrinsic.rs @@ -39,7 +39,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext, substs: @param_substs, attributes: &[ast::Attribute], ref_id: Option) { - debug!("trans_intrinsic(item.ident=%s)", ccx.sess.str_of(item.ident)); + debug!("trans_intrinsic(item.ident=%s)", ccx.tcx.sess.str_of(item.ident)); fn simple_llvm_intrinsic(bcx: @mut Block, name: &'static str, num_args: uint) { assert!(num_args <= 4); @@ -77,7 +77,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext, let size = match sizebits { 32 => C_i32(machine::llsize_of_real(ccx, lltp_ty) as i32), 64 => C_i64(machine::llsize_of_real(ccx, lltp_ty) as i64), - _ => ccx.sess.fatal("Invalid value for sizebits") + _ => ccx.tcx.sess.fatal("Invalid value for sizebits") }; let decl = bcx.fcx.llfn; @@ -98,7 +98,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext, let size = match sizebits { 32 => C_i32(machine::llsize_of_real(ccx, lltp_ty) as i32), 64 => C_i64(machine::llsize_of_real(ccx, lltp_ty) as i64), - _ => ccx.sess.fatal("Invalid value for sizebits") + _ => ccx.tcx.sess.fatal("Invalid value for sizebits") }; let decl = bcx.fcx.llfn; @@ -141,7 +141,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext, let mut bcx = fcx.entry_bcx.unwrap(); let first_real_arg = fcx.arg_pos(0u); - let nm = ccx.sess.str_of(item.ident); + let nm = ccx.tcx.sess.str_of(item.ident); let name = nm.as_slice(); // This requires that atomic intrinsics follow a specific naming pattern: @@ -157,7 +157,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext, "acq" => lib::llvm::Acquire, "rel" => lib::llvm::Release, "acqrel" => lib::llvm::AcquireRelease, - _ => ccx.sess.fatal("Unknown ordering in atomic intrinsic") + _ => ccx.tcx.sess.fatal("Unknown ordering in atomic intrinsic") } }; @@ -198,7 +198,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext, "min" => lib::llvm::Min, "umax" => lib::llvm::UMax, "umin" => lib::llvm::UMin, - _ => ccx.sess.fatal("Unknown atomic operation") + _ => ccx.tcx.sess.fatal("Unknown atomic operation") }; let old = AtomicRMW(bcx, atom_op, get_param(decl, first_real_arg), @@ -300,7 +300,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext, _ => fail!("transmute has non-expr arg"), }; let pluralize = |n| if 1u == n { "" } else { "s" }; - ccx.sess.span_fatal(sp, + ccx.tcx.sess.span_fatal(sp, fmt!("transmute called on types with \ different sizes: %s (%u bit%s) to \ %s (%u bit%s)", @@ -491,7 +491,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext, _ => { // Could we make this an enum rather than a string? does it get // checked earlier? - ccx.sess.span_bug(item.span, "unknown intrinsic"); + ccx.tcx.sess.span_bug(item.span, "unknown intrinsic"); } } fcx.cleanup(); diff --git a/src/librustc/middle/trans/macros.rs b/src/librustc/middle/trans/macros.rs index 43cc66c556867..92348e28ace8e 100644 --- a/src/librustc/middle/trans/macros.rs +++ b/src/librustc/middle/trans/macros.rs @@ -34,7 +34,7 @@ macro_rules! trace_span( ($bcx: ident, $sp: expr, $str: expr) => ( { let bcx = $bcx; - if bcx.sess().trace() { + if bcx.tcx().sess.trace() { trans_trace(bcx, Some($sp), $str); } } @@ -45,7 +45,7 @@ macro_rules! trace( ($bcx: ident, $str: expr) => ( { let bcx = $bcx; - if bcx.sess().trace() { + if bcx.tcx().sess.trace() { trans_trace(bcx, None, $str); } } diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index ce4c1011e8064..cfd089521ebb0 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -260,7 +260,7 @@ pub fn trans_static_method_callee(bcx: @mut Block, } }; debug!("trans_static_method_callee: method_id=%?, callee_id=%?, \ - name=%s", method_id, callee_id, ccx.sess.str_of(mname)); + name=%s", method_id, callee_id, ccx.tcx.sess.str_of(mname)); let vtbls = resolve_vtables_in_fn_ctxt( bcx.fcx, ccx.maps.vtable_map.get_copy(&callee_id)); @@ -550,7 +550,7 @@ pub fn get_vtable(bcx: @mut Block, typeck::vtable_static(id, ref substs, sub_vtables) => { emit_vtable_methods(bcx, id, *substs, sub_vtables) } - _ => ccx.sess.bug("get_vtable: expected a static origin"), + _ => ccx.tcx.sess.bug("get_vtable: expected a static origin"), } }; @@ -598,7 +598,7 @@ fn emit_vtable_methods(bcx: @mut Block, let trt_id = match ty::impl_trait_ref(tcx, impl_id) { Some(t_id) => t_id.def_id, - None => ccx.sess.bug("make_impl_vtable: don't know how to \ + None => ccx.tcx.sess.bug("make_impl_vtable: don't know how to \ make a vtable for a type impl!") }; diff --git a/src/librustc/middle/trans/monomorphize.rs b/src/librustc/middle/trans/monomorphize.rs index 034320008cd14..7417fa6a55b7c 100644 --- a/src/librustc/middle/trans/monomorphize.rs +++ b/src/librustc/middle/trans/monomorphize.rs @@ -93,7 +93,7 @@ pub fn monomorphic_fn(ccx: @mut CrateContext, let mut is_static_provided = None; let map_node = session::expect( - ccx.sess, + ccx.tcx.sess, ccx.tcx.items.find_copy(&fn_id.node), || fmt!("While monomorphizing %?, couldn't find it in the item map \ (may have attempted to monomorphize an item \ @@ -188,12 +188,12 @@ pub fn monomorphic_fn(ccx: @mut CrateContext, // recursively more than thirty times can probably safely be assumed to be // causing an infinite expansion. if depth > 30 { - ccx.sess.span_fatal( + ccx.tcx.sess.span_fatal( span, "overly deep expansion of inlined function"); } ccx.monomorphizing.insert(fn_id, depth + 1); - let (_, elt) = gensym_name(ccx.sess.str_of(name)); + let (_, elt) = gensym_name(ccx.tcx.sess.str_of(name)); let mut pt = (*pt).clone(); pt.push(elt); let s = mangle_exported_name(ccx, pt.clone(), mono_ty); @@ -313,10 +313,10 @@ pub fn make_mono_id(ccx: @mut CrateContext, None => substs_iter.map(|subst| (*subst, None::<@~[mono_id]>)).collect() }; - let param_ids = precise_param_ids.iter().map(|x| { let (a, b) = *x; mono_precise(a, b) }).collect(); + @mono_id_ {def: item, params: param_ids} } diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs index 23b87c63d6a2c..55fcdf0df37ca 100644 --- a/src/librustc/middle/trans/reflect.rs +++ b/src/librustc/middle/trans/reflect.rs @@ -266,7 +266,7 @@ impl Reflector { do self.bracketed("class", extra) |this| { for (i, field) in fields.iter().enumerate() { let extra = ~[this.c_uint(i), - this.c_slice(bcx.ccx().sess.str_of(field.ident)), + this.c_slice(bcx.ccx().tcx.sess.str_of(field.ident)), this.c_bool(named_fields)] + this.c_mt(&field.mt); this.visit("class_field", extra); @@ -323,7 +323,7 @@ impl Reflector { + self.c_size_and_align(t); do self.bracketed("enum", enum_args) |this| { for (i, v) in variants.iter().enumerate() { - let name = ccx.sess.str_of(v.name); + let name = ccx.tcx.sess.str_of(v.name); let variant_args = ~[this.c_uint(i), C_integral(self.bcx.ccx().int_type, v.disr_val, false), this.c_uint(v.args.len()), diff --git a/src/librustc/middle/trans/type_of.rs b/src/librustc/middle/trans/type_of.rs index 945d5a048bb0b..f18fa5cae5d96 100644 --- a/src/librustc/middle/trans/type_of.rs +++ b/src/librustc/middle/trans/type_of.rs @@ -83,7 +83,7 @@ pub fn type_of_fn_from_ty(cx: &mut CrateContext, fty: ty::t) -> Type { } } _ => { - cx.sess.bug("type_of_fn_from_ty given non-closure, non-bare-fn") + cx.tcx.sess.bug("type_of_fn_from_ty given non-closure, non-bare-fn") } }; } @@ -141,7 +141,7 @@ pub fn sizing_type_of(cx: &mut CrateContext, t: ty::t) -> Type { ty::ty_unboxed_vec(mt) => { let sz_ty = sizing_type_of(cx, mt.ty); - Type::vec(cx.sess.targ_cfg.arch, &sz_ty) + Type::vec(cx.tcx.sess.targ_cfg.arch, &sz_ty) } ty::ty_tup(*) | ty::ty_enum(*) => { @@ -201,7 +201,7 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type { ty::ty_uint(t) => Type::uint_from_ty(cx, t), ty::ty_float(t) => Type::float_from_ty(cx, t), ty::ty_estr(ty::vstore_uniq) => { - Type::vec(cx.sess.targ_cfg.arch, &Type::i8()).ptr_to() + Type::vec(cx.tcx.sess.targ_cfg.arch, &Type::i8()).ptr_to() } ty::ty_enum(did, ref substs) => { // Only create the named struct, but don't fill it in. We @@ -212,11 +212,11 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type { Type::named_struct(llvm_type_name(cx, an_enum, did, substs.tps)) } ty::ty_estr(ty::vstore_box) => { - Type::box(cx, &Type::vec(cx.sess.targ_cfg.arch, &Type::i8())).ptr_to() + Type::box(cx, &Type::vec(cx.tcx.sess.targ_cfg.arch, &Type::i8())).ptr_to() } ty::ty_evec(ref mt, ty::vstore_box) => { let e_ty = type_of(cx, mt.ty); - let v_ty = Type::vec(cx.sess.targ_cfg.arch, &e_ty); + let v_ty = Type::vec(cx.tcx.sess.targ_cfg.arch, &e_ty); Type::box(cx, &v_ty).ptr_to() } ty::ty_box(ref mt) => { @@ -234,7 +234,7 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type { } ty::ty_evec(ref mt, ty::vstore_uniq) => { let ty = type_of(cx, mt.ty); - let ty = Type::vec(cx.sess.targ_cfg.arch, &ty); + let ty = Type::vec(cx.tcx.sess.targ_cfg.arch, &ty); if ty::type_contents(cx.tcx, mt.ty).contains_managed() { Type::unique(cx, &ty).ptr_to() } else { @@ -243,7 +243,7 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type { } ty::ty_unboxed_vec(ref mt) => { let ty = type_of(cx, mt.ty); - Type::vec(cx.sess.targ_cfg.arch, &ty) + Type::vec(cx.tcx.sess.targ_cfg.arch, &ty) } ty::ty_ptr(ref mt) => type_of(cx, mt.ty).ptr_to(), ty::ty_rptr(_, ref mt) => type_of(cx, mt.ty).ptr_to(), diff --git a/src/librustc/middle/trans/write_guard.rs b/src/librustc/middle/trans/write_guard.rs index ad999e0c1aabc..8a96c155a2aef 100644 --- a/src/librustc/middle/trans/write_guard.rs +++ b/src/librustc/middle/trans/write_guard.rs @@ -114,7 +114,7 @@ fn root(datum: &Datum, debug!("write_guard::root(root_key=%?, root_info=%?, datum=%?)", root_key, root_info, datum.to_str(bcx.ccx())); - if bcx.sess().trace() { + if bcx.tcx().sess.trace() { trans_trace( bcx, None, (fmt!("preserving until end of scope %d", diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index bcf4de0807339..1ff4934a3a6ff 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -254,7 +254,7 @@ struct ctxt_ { interner: @mut HashMap, next_id: @mut uint, cstore: @mut metadata::cstore::CStore, - sess: session::Session, + sess: &'static session::Session, def_map: resolve::DefMap, region_maps: @mut middle::region::RegionMaps, @@ -910,7 +910,7 @@ pub fn new_ty_hash() -> @mut HashMap { @mut HashMap::new() } -pub fn mk_ctxt(s: session::Session, +pub fn mk_ctxt(s: &session::Session, dm: resolve::DefMap, amap: ast_map::map, freevars: freevars::freevar_map, @@ -918,6 +918,13 @@ pub fn mk_ctxt(s: session::Session, region_paramd_items: middle::region::region_paramd_items, lang_items: middle::lang_items::LanguageItems) -> ctxt { + // NOTE: we can't thread the session through the type context + // because it hides behind @ :( + // since we know the session will outlive it, we just cheat + // and tell it the session has a static lifetime + let s: &'static session::Session = unsafe { + cast::transmute(s) + }; @ctxt_ { diag: s.diagnostic(), interner: @mut HashMap::new(), diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 61d00dff58465..565c37c076b58 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -193,11 +193,11 @@ impl visit::Visitor<()> for PrivilegedScopeVisitor { item_impl(_, None, ref ast_ty, _) => { if !self.cc.ast_type_is_defined_in_local_crate(ast_ty) { // This is an error. - let session = self.cc.crate_context.tcx.sess; - session.span_err(item.span, - "cannot associate methods with a type outside the \ - crate the type is defined in; define and implement \ - a trait or new type instead"); + let tcx = self.cc.crate_context.tcx; + tcx.sess.span_err(item.span, + "cannot associate methods with a type outside the \ + crate the type is defined in; define and implement \ + a trait or new type instead"); } } item_impl(_, Some(ref trait_ref), _, _) => { @@ -214,10 +214,10 @@ impl visit::Visitor<()> for PrivilegedScopeVisitor { self.cc.trait_ref_to_trait_def_id(trait_ref); if trait_def_id.crate != LOCAL_CRATE { - let session = self.cc.crate_context.tcx.sess; - session.span_err(item.span, - "cannot provide an extension implementation \ - for a trait not defined in this crate"); + let tcx = self.cc.crate_context.tcx; + tcx.sess.span_err(item.span, + "cannot provide an extension implementation \ + for a trait not defined in this crate"); } } @@ -274,10 +274,10 @@ impl CoherenceChecker { item.span, self_type.ty) { None => { - let session = self.crate_context.tcx.sess; - session.span_err(item.span, - "no base type found for inherent implementation; \ - implement a trait or new type instead"); + let tcx = self.crate_context.tcx; + tcx.sess.span_err(item.span, + "no base type found for inherent implementation; \ + implement a trait or new type instead"); } Some(_) => { // Nothing to do. @@ -437,14 +437,14 @@ impl CoherenceChecker { implementation_b); if self.polytypes_unify(polytype_a, polytype_b) { - let session = self.crate_context.tcx.sess; - session.span_err( + let tcx = self.crate_context.tcx; + tcx.sess.span_err( self.span_of_impl(implementation_b), fmt!("conflicting implementations for trait `%s`", ty::item_path_str(self.crate_context.tcx, trait_def_id))); - session.span_note(self.span_of_impl(implementation_a), - "note conflicting implementation here"); + tcx.sess.span_note(self.span_of_impl(implementation_a), + "note conflicting implementation here"); } } } diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index 45a65f954a3a9..f881e6b2ef29b 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -422,7 +422,7 @@ fn check_start_fn_ty(ccx: &CrateCtxt, fn check_for_entry_fn(ccx: &CrateCtxt) { let tcx = ccx.tcx; - if !*tcx.sess.building_library { + if !tcx.sess.building_library { match *tcx.sess.entry_fn { Some((id, sp)) => match *tcx.sess.entry_type { Some(session::EntryMain) => check_main_fn_ty(ccx, id, sp), diff --git a/src/librustc/rustc.rs b/src/librustc/rustc.rs index 320feae2ce732..3e7f504eaeb13 100644 --- a/src/librustc/rustc.rs +++ b/src/librustc/rustc.rs @@ -257,12 +257,12 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) { }; let sopts = build_session_options(binary, matches, demitter); - let sess = build_session(sopts, demitter); + let mut sess = build_session(sopts, demitter); let odir = matches.opt_str("out-dir").map_move(|o| Path(o)); let ofile = matches.opt_str("o").map_move(|o| Path(o)); - let cfg = build_configuration(sess); + let cfg = build_configuration(&sess); let pretty = do matches.opt_default("pretty", "normal").map_move |a| { - parse_pretty(sess, a) + parse_pretty(&sess, a) }; match pretty { Some::(ppm) => { @@ -275,7 +275,7 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) { if ls { match input { file_input(ref ifile) => { - list_metadata(sess, &(*ifile), io::stdout()); + list_metadata(&sess, &(*ifile), io::stdout()); } str_input(_) => { early_error(demitter, ~"can not list metadata for stdin"); @@ -284,7 +284,7 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) { return; } - compile_input(sess, cfg, &input, &odir, &ofile); + compile_input(&mut sess, cfg, &input, &odir, &ofile); } #[deriving(Eq)] diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 8a7bb1f934615..749ab55721599 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -49,18 +49,18 @@ fn get_ast_and_resolve(cpath: &Path, libs: ~[Path]) -> DocContext { let span_diagnostic_handler = syntax::diagnostic::mk_span_handler(diagnostic_handler, parsesess.cm); - let sess = driver::driver::build_session_(sessopts, - parsesess.cm, - @diagnostic::DefaultEmitter as - @diagnostic::Emitter, - span_diagnostic_handler); + let mut sess = driver::driver::build_session_(sessopts, + parsesess.cm, + @diagnostic::DefaultEmitter as + @diagnostic::Emitter, + span_diagnostic_handler); - let mut cfg = build_configuration(sess); + let mut cfg = build_configuration(&sess); cfg.push(@dummy_spanned(ast::MetaWord(@"stage2"))); - let mut crate = phase_1_parse_input(sess, cfg.clone(), &input); - crate = phase_2_configure_and_expand(sess, cfg, crate); - let analysis = phase_3_run_analysis_passes(sess, crate); + let mut crate = phase_1_parse_input(&sess, cfg.clone(), &input); + crate = phase_2_configure_and_expand(&mut sess, cfg, crate); + let analysis = phase_3_run_analysis_passes(&sess, crate); debug!("crate: %?", crate); DocContext { crate: crate, tycx: analysis.ty_cx, sess: sess } diff --git a/src/librusti/rusti.rs b/src/librusti/rusti.rs index ae6c36b886132..cfa3e7c252e3c 100644 --- a/src/librusti/rusti.rs +++ b/src/librusti/rusti.rs @@ -148,20 +148,20 @@ fn run(mut program: ~Program, binary: ~str, lib_search_paths: ~[~str], // extra helpful information if the error crops up. Otherwise people are // bound to be very confused when they find out code is running that they // never typed in... - let sess = driver::build_session(options, - @EncodableWarningEmitter as - @diagnostic::Emitter); + let mut sess = driver::build_session(options, + @EncodableWarningEmitter as + @diagnostic::Emitter); let intr = token::get_ident_interner(); // // Stage 1: parse the input and filter it into the program (as necessary) // debug!("parsing: %s", input); - let crate = parse_input(sess, input); + let crate = parse_input(&sess, input); let mut to_run = ~[]; // statements to run (emitted back into code) let new_locals = @mut ~[]; // new locals being defined let mut result = None; // resultant expression (to print via pp) - do find_main(crate, sess) |blk| { + do find_main(crate, &sess) |blk| { // Fish out all the view items, be sure to record 'extern mod' items // differently beause they must appear before all 'use' statements for vi in blk.view_items.iter() { @@ -237,15 +237,15 @@ fn run(mut program: ~Program, binary: ~str, lib_search_paths: ~[~str], let test = program.test_code(input, &result, *new_locals); debug!("testing with ^^^^^^ %?", (||{ println(test) })()); let dinput = driver::str_input(test.to_managed()); - let cfg = driver::build_configuration(sess); + let cfg = driver::build_configuration(&sess); - let crate = driver::phase_1_parse_input(sess, cfg.clone(), &dinput); - let expanded_crate = driver::phase_2_configure_and_expand(sess, cfg, crate); - let analysis = driver::phase_3_run_analysis_passes(sess, expanded_crate); + let crate = driver::phase_1_parse_input(&sess, cfg.clone(), &dinput); + let expanded_crate = driver::phase_2_configure_and_expand(&mut sess, cfg, crate); + let analysis = driver::phase_3_run_analysis_passes(&sess, expanded_crate); // Once we're typechecked, record the types of all local variables defined // in this input - do find_main(crate, sess) |blk| { + do find_main(crate, &sess) |blk| { program.register_new_vars(blk, analysis.ty_cx); } @@ -256,17 +256,17 @@ fn run(mut program: ~Program, binary: ~str, lib_search_paths: ~[~str], let code = program.code(input, &result); debug!("actually running ^^^^^^ %?", (||{ println(code) })()); let input = driver::str_input(code.to_managed()); - let cfg = driver::build_configuration(sess); - let outputs = driver::build_output_filenames(&input, &None, &None, [], sess); - let sess = driver::build_session(options, - @diagnostic::DefaultEmitter as - @diagnostic::Emitter); - - let crate = driver::phase_1_parse_input(sess, cfg.clone(), &input); - let expanded_crate = driver::phase_2_configure_and_expand(sess, cfg, crate); - let analysis = driver::phase_3_run_analysis_passes(sess, expanded_crate); - let trans = driver::phase_4_translate_to_llvm(sess, expanded_crate, &analysis, outputs); - driver::phase_5_run_llvm_passes(sess, &trans, outputs); + let cfg = driver::build_configuration(&sess); + let outputs = driver::build_output_filenames(&input, &None, &None, [], &sess); + let mut sess = driver::build_session(options, + @diagnostic::DefaultEmitter as + @diagnostic::Emitter); + + let crate = driver::phase_1_parse_input(&sess, cfg.clone(), &input); + let expanded_crate = driver::phase_2_configure_and_expand(&mut sess, cfg, crate); + let analysis = driver::phase_3_run_analysis_passes(&sess, expanded_crate); + let trans = driver::phase_4_translate_to_llvm(expanded_crate, &analysis, outputs); + driver::phase_5_run_llvm_passes(&sess, &trans, outputs); // // Stage 4: Inform the program that computation is done so it can update all @@ -283,14 +283,14 @@ fn run(mut program: ~Program, binary: ~str, lib_search_paths: ~[~str], // return (program, jit::consume_engine()); - fn parse_input(sess: session::Session, input: &str) -> @ast::Crate { + fn parse_input(sess: &session::Session, input: &str) -> @ast::Crate { let code = fmt!("fn main() {\n %s \n}", input); let input = driver::str_input(code.to_managed()); let cfg = driver::build_configuration(sess); driver::phase_1_parse_input(sess, cfg.clone(), &input) } - fn find_main(crate: @ast::Crate, sess: session::Session, + fn find_main(crate: @ast::Crate, sess: &session::Session, f: &fn(&ast::Block)) { for item in crate.module.items.iter() { match item.node { @@ -322,13 +322,13 @@ fn compile_crate(src_filename: ~str, binary: ~str) -> Option { .. (*session::basic_options()).clone() }; let input = driver::file_input(src_path.clone()); - let sess = driver::build_session(options, - @diagnostic::DefaultEmitter as - @diagnostic::Emitter); - *sess.building_library = true; - let cfg = driver::build_configuration(sess); + let mut sess = driver::build_session(options, + @diagnostic::DefaultEmitter as + @diagnostic::Emitter); + sess.building_library = true; + let cfg = driver::build_configuration(&sess); let outputs = driver::build_output_filenames( - &input, &None, &None, [], sess); + &input, &None, &None, [], &sess); // If the library already exists and is newer than the source // file, skip compilation and return None. let mut should_compile = true; @@ -356,11 +356,11 @@ fn compile_crate(src_filename: ~str, binary: ~str) -> Option { } if (should_compile) { println(fmt!("compiling %s...", src_filename)); - let crate = driver::phase_1_parse_input(sess, cfg.clone(), &input); - let expanded_crate = driver::phase_2_configure_and_expand(sess, cfg, crate); - let analysis = driver::phase_3_run_analysis_passes(sess, expanded_crate); - let trans = driver::phase_4_translate_to_llvm(sess, expanded_crate, &analysis, outputs); - driver::phase_5_run_llvm_passes(sess, &trans, outputs); + let crate = driver::phase_1_parse_input(&sess, cfg.clone(), &input); + let expanded_crate = driver::phase_2_configure_and_expand(&mut sess, cfg, crate); + let analysis = driver::phase_3_run_analysis_passes(&sess, expanded_crate); + let trans = driver::phase_4_translate_to_llvm(expanded_crate, &analysis, outputs); + driver::phase_5_run_llvm_passes(&sess, &trans, outputs); true } else { false } } { diff --git a/src/librustpkg/rustpkg.rs b/src/librustpkg/rustpkg.rs index 76edd7feff7ea..b77707539c2da 100644 --- a/src/librustpkg/rustpkg.rs +++ b/src/librustpkg/rustpkg.rs @@ -110,12 +110,12 @@ impl<'self> PkgScript<'self> { .. (*session::basic_options()).clone() }; let input = driver::file_input(script.clone()); - let sess = driver::build_session(options, - @diagnostic::DefaultEmitter as - @diagnostic::Emitter); - let cfg = driver::build_configuration(sess); - let crate = driver::phase_1_parse_input(sess, cfg.clone(), &input); - let crate = driver::phase_2_configure_and_expand(sess, cfg.clone(), crate); + let mut sess = driver::build_session(options, + @diagnostic::DefaultEmitter as + @diagnostic::Emitter); + let cfg = driver::build_configuration(&sess); + let crate = driver::phase_1_parse_input(&sess, cfg.clone(), &input); + let crate = driver::phase_2_configure_and_expand(&mut sess, cfg.clone(), crate); let work_dir = build_pkg_id_in_workspace(id, workspace); debug!("Returning package script with id %s", id.to_str()); @@ -135,11 +135,9 @@ impl<'self> PkgScript<'self> { /// Returns a pair of an exit code and list of configs (obtained by /// calling the package script's configs() function if it exists fn run_custom(&self, exec: &mut workcache::Exec, sysroot: &Path) -> (~[~str], ExitCode) { - let sess = self.sess; - debug!("Working directory = %s", self.build_dir.to_str()); // Collect together any user-defined commands in the package script - let crate = util::ready_crate(sess, self.crate); + let crate = util::ready_crate(&self.sess, self.crate); debug!("Building output filenames with script name %s", driver::source_name(&driver::file_input(self.input.clone()))); let exe = self.build_dir.push(~"pkg" + util::exe_suffix()); @@ -147,7 +145,7 @@ impl<'self> PkgScript<'self> { exec, Nothing, &self.build_dir, - sess, + &self.sess, crate); debug!("Running program: %s %s %s", exe.to_str(), sysroot.to_str(), "install"); diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index b30ad6f2c9297..5e30cfb4a9d94 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -67,7 +67,6 @@ struct ListenerFn { } struct ReadyCtx { - sess: session::Session, crate: @ast::Crate, ext_cx: @ExtCtxt, path: ~[ast::Ident], @@ -150,10 +149,9 @@ impl fold::ast_fold for CrateSetup { } /// Generate/filter main function, add the list of commands, etc. -pub fn ready_crate(sess: session::Session, +pub fn ready_crate(sess: &session::Session, crate: @ast::Crate) -> @ast::Crate { let ctx = @mut ReadyCtx { - sess: sess, crate: crate, ext_cx: ExtCtxt::new(sess.parse_sess, sess.opts.cfg.clone()), path: ~[], @@ -252,17 +250,17 @@ pub fn compile_input(context: &BuildContext, } } - let sess = driver::build_session(options, - @diagnostic::DefaultEmitter as - @diagnostic::Emitter); + let mut sess = driver::build_session(options, + @diagnostic::DefaultEmitter as + @diagnostic::Emitter); // Infer dependencies that rustpkg needs to build, by scanning for // `extern mod` directives. - let cfg = driver::build_configuration(sess); - let mut crate = driver::phase_1_parse_input(sess, cfg.clone(), &input); - crate = driver::phase_2_configure_and_expand(sess, cfg.clone(), crate); + let cfg = driver::build_configuration(&sess); + let mut crate = driver::phase_1_parse_input(&sess, cfg.clone(), &input); + crate = driver::phase_2_configure_and_expand(&mut sess, cfg.clone(), crate); - find_and_install_dependencies(context, pkg_id, sess, exec, crate, + find_and_install_dependencies(context, pkg_id, &sess, exec, crate, |p| { debug!("a dependency: %s", p.to_str()); // Pass the directory containing a dependency @@ -301,7 +299,7 @@ pub fn compile_input(context: &BuildContext, exec, context.compile_upto(), &out_dir, - sess, + &sess, crate); // Discover the output let discovered_output = if what == Lib { @@ -331,7 +329,7 @@ pub fn compile_crate_from_input(input: &Path, stop_before: StopBefore, // should be of the form /build/ out_dir: &Path, - sess: session::Session, + sess: &session::Session, // Returns None if one of the flags that suppresses compilation output was // given crate: @ast::Crate) -> Option { @@ -354,7 +352,7 @@ pub fn compile_crate_from_input(input: &Path, } let analysis = driver::phase_3_run_analysis_passes(sess, crate); if driver::stop_after_phase_3(sess) { return None; } - let translation = driver::phase_4_translate_to_llvm(sess, crate, + let translation = driver::phase_4_translate_to_llvm(crate, &analysis, outputs); driver::phase_5_run_llvm_passes(sess, &translation, outputs); @@ -400,7 +398,7 @@ pub fn compile_crate(ctxt: &BuildContext, struct ViewItemVisitor<'self> { context: &'self BuildContext, parent: &'self PkgId, - sess: session::Session, + sess: &'self session::Session, exec: &'self mut workcache::Exec, c: &'self ast::Crate, save: &'self fn(Path), @@ -502,7 +500,7 @@ impl<'self> Visitor<()> for ViewItemVisitor<'self> { /// can't be found. pub fn find_and_install_dependencies(context: &BuildContext, parent: &PkgId, - sess: session::Session, + sess: &session::Session, exec: &mut workcache::Exec, c: &ast::Crate, save: &fn(Path)) {