diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index d46eecc1d63d2..4c71c2df44d3e 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -32,6 +32,7 @@ use serialize::{json, Encodable}; use std::io; use std::io::fs; +use arena::TypedArena; use syntax::ast; use syntax::attr; use syntax::attr::{AttrMetaMethods}; @@ -86,8 +87,9 @@ pub fn compile_input(sess: Session, if stop_after_phase_2(&sess) { return; } + let type_arena = TypedArena::new(); let analysis = phase_3_run_analysis_passes(sess, &expanded_crate, - ast_map, id); + ast_map, &type_arena, id); phase_save_analysis(&analysis.ty_cx.sess, &expanded_crate, &analysis, outdir); if stop_after_phase_3(&analysis.ty_cx.sess) { return; } let (tcx, trans) = phase_4_translate_to_llvm(expanded_crate, analysis); @@ -299,11 +301,11 @@ pub fn phase_2_configure_and_expand(sess: &Session, Some((krate, map)) } -pub struct CrateAnalysis { +pub struct CrateAnalysis<'tcx> { pub exp_map2: middle::resolve::ExportMap2, pub exported_items: middle::privacy::ExportedItems, pub public_items: middle::privacy::PublicItems, - pub ty_cx: ty::ctxt, + pub ty_cx: ty::ctxt<'tcx>, pub reachable: NodeSet, pub name: String, } @@ -312,10 +314,11 @@ 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, - krate: &ast::Crate, - ast_map: syntax::ast_map::Map, - name: String) -> CrateAnalysis { +pub fn phase_3_run_analysis_passes<'tcx>(sess: Session, + krate: &ast::Crate, + ast_map: syntax::ast_map::Map, + type_arena: &'tcx TypedArena, + name: String) -> CrateAnalysis<'tcx> { let time_passes = sess.time_passes(); time(time_passes, "external crate/lib resolution", (), |_| @@ -362,6 +365,7 @@ pub fn phase_3_run_analysis_passes(sess: Session, stability::Index::build(krate)); let ty_cx = ty::mk_ctxt(sess, + type_arena, def_map, named_region_map, ast_map, diff --git a/src/librustc/driver/pretty.rs b/src/librustc/driver/pretty.rs index 67dbc6f6a301d..a3227e4dbf1d4 100644 --- a/src/librustc/driver/pretty.rs +++ b/src/librustc/driver/pretty.rs @@ -33,7 +33,7 @@ use graphviz as dot; use std::io::{mod, MemReader}; use std::from_str::FromStr; use std::option; - +use arena::TypedArena; #[deriving(PartialEq, Show)] pub enum PpSourceMode { @@ -114,7 +114,9 @@ impl PpSourceMode { } PpmTyped => { let ast_map = ast_map.expect("--pretty=typed missing ast_map"); - let analysis = driver::phase_3_run_analysis_passes(sess, krate, ast_map, id); + let type_arena = TypedArena::new(); + let analysis = driver::phase_3_run_analysis_passes(sess, krate, ast_map, + &type_arena, id); let annotation = TypedAnnotation { analysis: analysis }; f(&annotation, payload) } @@ -260,25 +262,25 @@ impl pprust::PpAnn for HygieneAnnotation { } -struct TypedAnnotation { - analysis: CrateAnalysis, +struct TypedAnnotation<'tcx> { + analysis: CrateAnalysis<'tcx>, } -impl PrinterSupport for TypedAnnotation { +impl<'tcx> PrinterSupport for TypedAnnotation<'tcx> { fn pp_ann<'a>(&'a self) -> &'a pprust::PpAnn { self as &pprust::PpAnn } } -impl SessionCarrier for TypedAnnotation { +impl<'tcx> SessionCarrier for TypedAnnotation<'tcx> { fn sess<'a>(&'a self) -> &'a Session { &self.analysis.ty_cx.sess } } -impl AstMapCarrier for TypedAnnotation { +impl<'tcx> AstMapCarrier for TypedAnnotation<'tcx> { fn ast_map<'a>(&'a self) -> Option<&'a ast_map::Map> { Some(&self.analysis.ty_cx.map) } } -impl pprust::PpAnn for TypedAnnotation { +impl<'tcx> pprust::PpAnn for TypedAnnotation<'tcx> { fn pre(&self, s: &mut pprust::State, node: pprust::AnnNode) -> io::IoResult<()> { @@ -531,8 +533,9 @@ pub fn pretty_print_input(sess: Session, match code { Some(code) => { let variants = gather_flowgraph_variants(&sess); + let type_arena = TypedArena::new(); let analysis = driver::phase_3_run_analysis_passes(sess, &krate, - ast_map, id); + ast_map, &type_arena, id); print_flowgraph(variants, analysis, code, out) } None => { diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 355cd8203c5d6..c3c4cf51f5775 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -340,11 +340,11 @@ impl LintPass for TypeLimits { declare_lint!(CTYPES, Warn, "proper use of libc types in foreign modules") -struct CTypesVisitor<'a> { - cx: &'a Context<'a> +struct CTypesVisitor<'a, 'tcx: 'a> { + cx: &'a Context<'a, 'tcx> } -impl<'a> CTypesVisitor<'a> { +impl<'a, 'tcx> CTypesVisitor<'a, 'tcx> { fn check_def(&mut self, sp: Span, ty_id: ast::NodeId, path_id: ast::NodeId) { match self.cx.tcx.def_map.borrow().get_copy(&path_id) { def::DefPrimTy(ast::TyInt(ast::TyI)) => { @@ -375,7 +375,7 @@ impl<'a> CTypesVisitor<'a> { } } -impl<'a> Visitor<()> for CTypesVisitor<'a> { +impl<'a, 'tcx> Visitor<()> for CTypesVisitor<'a, 'tcx> { fn visit_ty(&mut self, ty: &ast::Ty, _: ()) { match ty.node { ast::TyPath(_, _, id) => self.check_def(ty.span, ty.id, id), @@ -505,11 +505,11 @@ impl LintPass for HeapMemory { declare_lint!(RAW_POINTER_DERIVING, Warn, "uses of #[deriving] with raw pointers are rarely correct") -struct RawPtrDerivingVisitor<'a> { - cx: &'a Context<'a> +struct RawPtrDerivingVisitor<'a, 'tcx: 'a> { + cx: &'a Context<'a, 'tcx> } -impl<'a> Visitor<()> for RawPtrDerivingVisitor<'a> { +impl<'a, 'tcx> Visitor<()> for RawPtrDerivingVisitor<'a, 'tcx> { fn visit_ty(&mut self, ty: &ast::Ty, _: ()) { static MSG: &'static str = "use of `#[deriving]` with a raw pointer"; match ty.node { diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 18e44cbac373f..26ed5cbfb2cc1 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -231,9 +231,9 @@ impl LintStore { } /// Context for lint checking. -pub struct Context<'a> { +pub struct Context<'a, 'tcx: 'a> { /// Type context we're checking in. - pub tcx: &'a ty::ctxt, + pub tcx: &'a ty::ctxt<'tcx>, /// The crate being checked. pub krate: &'a ast::Crate, @@ -345,10 +345,10 @@ pub fn raw_emit_lint(sess: &Session, lint: &'static Lint, } } -impl<'a> Context<'a> { - fn new(tcx: &'a ty::ctxt, +impl<'a, 'tcx> Context<'a, 'tcx> { + fn new(tcx: &'a ty::ctxt<'tcx>, krate: &'a ast::Crate, - exported_items: &'a ExportedItems) -> Context<'a> { + exported_items: &'a ExportedItems) -> Context<'a, 'tcx> { // We want to own the lint store, so move it out of the session. let lint_store = mem::replace(&mut *tcx.sess.lint_store.borrow_mut(), LintStore::new()); @@ -476,8 +476,8 @@ impl<'a> Context<'a> { } } -impl<'a> AstConv for Context<'a>{ - fn tcx<'a>(&'a self) -> &'a ty::ctxt { self.tcx } +impl<'a, 'tcx> AstConv<'tcx> for Context<'a, 'tcx>{ + fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.tcx } fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype { ty::lookup_item_type(self.tcx, id) @@ -492,7 +492,7 @@ impl<'a> AstConv for Context<'a>{ } } -impl<'a> Visitor<()> for Context<'a> { +impl<'a, 'tcx> Visitor<()> for Context<'a, 'tcx> { fn visit_item(&mut self, it: &ast::Item, _: ()) { self.with_lint_attrs(it.attrs.as_slice(), |cx| { run_lints!(cx, check_item, it); @@ -663,7 +663,7 @@ impl<'a> Visitor<()> for Context<'a> { } // Output any lints that were previously added to the session. -impl<'a> IdVisitingOperation for Context<'a> { +impl<'a, 'tcx> IdVisitingOperation for Context<'a, 'tcx> { fn visit_id(&self, id: ast::NodeId) { match self.tcx.sess.lints.borrow_mut().pop(&id) { None => {} diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index da73f25b6d164..a105a56a09b15 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -71,9 +71,9 @@ pub type EncodeInlinedItem<'a> = |ecx: &EncodeContext, rbml_w: &mut Encoder, ii: InlinedItemRef|: 'a; -pub struct EncodeParams<'a> { +pub struct EncodeParams<'a, 'tcx: 'a> { pub diag: &'a SpanHandler, - pub tcx: &'a ty::ctxt, + pub tcx: &'a ty::ctxt<'tcx>, pub reexports2: &'a middle::resolve::ExportMap2, pub item_symbols: &'a RefCell>, pub non_inlineable_statics: &'a RefCell, @@ -83,9 +83,9 @@ pub struct EncodeParams<'a> { pub reachable: &'a NodeSet, } -pub struct EncodeContext<'a> { +pub struct EncodeContext<'a, 'tcx: 'a> { pub diag: &'a SpanHandler, - pub tcx: &'a ty::ctxt, + pub tcx: &'a ty::ctxt<'tcx>, pub reexports2: &'a middle::resolve::ExportMap2, pub item_symbols: &'a RefCell>, pub non_inlineable_statics: &'a RefCell, @@ -1793,12 +1793,12 @@ fn encode_struct_field_attrs(rbml_w: &mut Encoder, krate: &Crate) { -struct ImplVisitor<'a,'b:'a,'c:'a> { - ecx: &'a EncodeContext<'b>, +struct ImplVisitor<'a, 'b:'a, 'c:'a, 'tcx:'b> { + ecx: &'a EncodeContext<'b, 'tcx>, rbml_w: &'a mut Encoder<'c>, } -impl<'a,'b,'c> Visitor<()> for ImplVisitor<'a,'b,'c> { +impl<'a, 'b, 'c, 'tcx> Visitor<()> for ImplVisitor<'a, 'b, 'c, 'tcx> { fn visit_item(&mut self, item: &Item, _: ()) { match item.node { ItemImpl(_, Some(ref trait_ref), _, _) => { diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index c18d2a7ebf404..53203663bb16e 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -59,11 +59,11 @@ pub enum DefIdSource { pub type conv_did<'a> = |source: DefIdSource, ast::DefId|: 'a -> ast::DefId; -pub struct PState<'a> { +pub struct PState<'a, 'tcx: 'a> { data: &'a [u8], krate: ast::CrateNum, pos: uint, - tcx: &'a ty::ctxt + tcx: &'a ty::ctxt<'tcx> } fn peek(st: &PState) -> char { @@ -105,8 +105,9 @@ fn parse_ident_(st: &mut PState, is_last: |char| -> bool) -> ast::Ident { }) } -pub fn parse_state_from_data<'a>(data: &'a [u8], crate_num: ast::CrateNum, - pos: uint, tcx: &'a ty::ctxt) -> PState<'a> { +pub fn parse_state_from_data<'a, 'tcx>(data: &'a [u8], crate_num: ast::CrateNum, + pos: uint, tcx: &'a ty::ctxt<'tcx>) + -> PState<'a, 'tcx> { PState { data: data, krate: crate_num, diff --git a/src/librustc/metadata/tyencode.rs b/src/librustc/metadata/tyencode.rs index 09be5094dc578..cbf558b6b483e 100644 --- a/src/librustc/metadata/tyencode.rs +++ b/src/librustc/metadata/tyencode.rs @@ -31,12 +31,12 @@ use rbml::io::SeekableMemWriter; macro_rules! mywrite( ($($arg:tt)*) => ({ write!($($arg)*); }) ) -pub struct ctxt<'a> { +pub struct ctxt<'a, 'tcx: 'a> { pub diag: &'a SpanHandler, // Def -> str Callback: pub ds: fn(DefId) -> String, // The type context. - pub tcx: &'a ty::ctxt, + pub tcx: &'a ty::ctxt<'tcx>, pub abbrevs: &'a abbrev_map } diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index ee964c729fca3..0e64be3d0b70b 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -54,13 +54,13 @@ use serialize::{EncoderHelpers}; #[cfg(test)] use syntax::print::pprust; #[cfg(test)] use std::gc::Gc; -struct DecodeContext<'a> { +struct DecodeContext<'a, 'tcx: 'a> { cdata: &'a cstore::crate_metadata, - tcx: &'a ty::ctxt, + tcx: &'a ty::ctxt<'tcx>, } -struct ExtendedDecodeContext<'a> { - dcx: &'a DecodeContext<'a>, +struct ExtendedDecodeContext<'a, 'tcx: 'a> { + dcx: &'a DecodeContext<'a, 'tcx>, from_id_range: ast_util::IdRange, to_id_range: ast_util::IdRange } @@ -176,7 +176,7 @@ fn reserve_id_range(sess: &Session, ast_util::IdRange { min: to_id_min, max: to_id_max } } -impl<'a> ExtendedDecodeContext<'a> { +impl<'a, 'tcx> ExtendedDecodeContext<'a, 'tcx> { pub fn tr_id(&self, id: ast::NodeId) -> ast::NodeId { /*! * Translates an internal id, meaning a node id that is known @@ -382,11 +382,11 @@ fn decode_ast(par_doc: rbml::Doc) -> ast::InlinedItem { Decodable::decode(&mut d).unwrap() } -struct AstRenumberer<'a> { - xcx: &'a ExtendedDecodeContext<'a>, +struct AstRenumberer<'a, 'tcx: 'a> { + xcx: &'a ExtendedDecodeContext<'a, 'tcx>, } -impl<'a> ast_map::FoldOps for AstRenumberer<'a> { +impl<'a, 'tcx> ast_map::FoldOps for AstRenumberer<'a, 'tcx> { fn new_id(&self, id: ast::NodeId) -> ast::NodeId { if id == ast::DUMMY_NODE_ID { // Used by ast_map to map the NodeInlinedParent. @@ -914,12 +914,12 @@ fn encode_vec_per_param_space(rbml_w: &mut Encoder, // ______________________________________________________________________ // Encoding and decoding the side tables -trait get_ty_str_ctxt { - fn ty_str_ctxt<'a>(&'a self) -> tyencode::ctxt<'a>; +trait get_ty_str_ctxt<'tcx> { + fn ty_str_ctxt<'a>(&'a self) -> tyencode::ctxt<'a, 'tcx>; } -impl<'a> get_ty_str_ctxt for e::EncodeContext<'a> { - fn ty_str_ctxt<'a>(&'a self) -> tyencode::ctxt<'a> { +impl<'a, 'tcx> get_ty_str_ctxt<'tcx> for e::EncodeContext<'a, 'tcx> { + fn ty_str_ctxt<'a>(&'a self) -> tyencode::ctxt<'a, 'tcx> { tyencode::ctxt { diag: self.tcx.sess.diagnostic(), ds: e::def_to_string, diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index a69fe6958e175..df637e7a052dd 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -79,14 +79,14 @@ fn owned_ptr_base_path_rc(loan_path: &Rc) -> Rc { } } -struct CheckLoanCtxt<'a> { - bccx: &'a BorrowckCtxt<'a>, - dfcx_loans: &'a LoanDataFlow<'a>, - move_data: move_data::FlowedMoveData<'a>, +struct CheckLoanCtxt<'a, 'tcx: 'a> { + bccx: &'a BorrowckCtxt<'a, 'tcx>, + dfcx_loans: &'a LoanDataFlow<'a, 'tcx>, + move_data: move_data::FlowedMoveData<'a, 'tcx>, all_loans: &'a [Loan], } -impl<'a> euv::Delegate for CheckLoanCtxt<'a> { +impl<'a, 'tcx> euv::Delegate for CheckLoanCtxt<'a, 'tcx> { fn consume(&mut self, consume_id: ast::NodeId, consume_span: Span, @@ -179,12 +179,12 @@ impl<'a> euv::Delegate for CheckLoanCtxt<'a> { fn decl_without_init(&mut self, _id: ast::NodeId, _span: Span) { } } -pub fn check_loans(bccx: &BorrowckCtxt, - dfcx_loans: &LoanDataFlow, - move_data: move_data::FlowedMoveData, - all_loans: &[Loan], - decl: &ast::FnDecl, - body: &ast::Block) { +pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, + dfcx_loans: &LoanDataFlow<'b, 'tcx>, + move_data: move_data::FlowedMoveData<'c, 'tcx>, + all_loans: &[Loan], + decl: &ast::FnDecl, + body: &ast::Block) { debug!("check_loans(body id={:?})", body.id); let mut clcx = CheckLoanCtxt { @@ -212,8 +212,8 @@ fn compatible_borrow_kinds(borrow_kind1: ty::BorrowKind, borrow_kind1 == ty::ImmBorrow && borrow_kind2 == ty::ImmBorrow } -impl<'a> CheckLoanCtxt<'a> { - pub fn tcx(&self) -> &'a ty::ctxt { self.bccx.tcx } +impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { + pub fn tcx(&self) -> &'a ty::ctxt<'tcx> { self.bccx.tcx } pub fn each_issued_loan(&self, scope_id: ast::NodeId, op: |&Loan| -> bool) -> bool { diff --git a/src/librustc/middle/borrowck/gather_loans/lifetime.rs b/src/librustc/middle/borrowck/gather_loans/lifetime.rs index c6fbbed1f8a16..e13717e5abd31 100644 --- a/src/librustc/middle/borrowck/gather_loans/lifetime.rs +++ b/src/librustc/middle/borrowck/gather_loans/lifetime.rs @@ -45,8 +45,8 @@ pub fn guarantee_lifetime(bccx: &BorrowckCtxt, /////////////////////////////////////////////////////////////////////////// // Private -struct GuaranteeLifetimeContext<'a> { - bccx: &'a BorrowckCtxt<'a>, +struct GuaranteeLifetimeContext<'a, 'tcx: 'a> { + bccx: &'a BorrowckCtxt<'a, 'tcx>, // the node id of the function body for the enclosing item item_scope_id: ast::NodeId, @@ -57,7 +57,7 @@ struct GuaranteeLifetimeContext<'a> { cmt_original: mc::cmt } -impl<'a> GuaranteeLifetimeContext<'a> { +impl<'a, 'tcx> GuaranteeLifetimeContext<'a, 'tcx> { fn check(&self, cmt: &mc::cmt, discr_scope: Option) -> R { //! Main routine. Walks down `cmt` until we find the "guarantor". diff --git a/src/librustc/middle/borrowck/gather_loans/mod.rs b/src/librustc/middle/borrowck/gather_loans/mod.rs index 82e1748465f61..11189390df565 100644 --- a/src/librustc/middle/borrowck/gather_loans/mod.rs +++ b/src/librustc/middle/borrowck/gather_loans/mod.rs @@ -57,15 +57,15 @@ pub fn gather_loans_in_fn(bccx: &BorrowckCtxt, (all_loans, move_data) } -struct GatherLoanCtxt<'a> { - bccx: &'a BorrowckCtxt<'a>, +struct GatherLoanCtxt<'a, 'tcx: 'a> { + bccx: &'a BorrowckCtxt<'a, 'tcx>, move_data: move_data::MoveData, move_error_collector: move_error::MoveErrorCollector, all_loans: Vec, item_ub: ast::NodeId, } -impl<'a> euv::Delegate for GatherLoanCtxt<'a> { +impl<'a, 'tcx> euv::Delegate for GatherLoanCtxt<'a, 'tcx> { fn consume(&mut self, consume_id: ast::NodeId, _consume_span: Span, @@ -204,8 +204,8 @@ fn check_aliasability(bccx: &BorrowckCtxt, } } -impl<'a> GatherLoanCtxt<'a> { - pub fn tcx(&self) -> &'a ty::ctxt { self.bccx.tcx } +impl<'a, 'tcx> GatherLoanCtxt<'a, 'tcx> { + pub fn tcx(&self) -> &'a ty::ctxt<'tcx> { self.bccx.tcx } fn guarantee_valid(&mut self, borrow_id: ast::NodeId, @@ -467,11 +467,11 @@ impl<'a> GatherLoanCtxt<'a> { /// /// This visitor walks static initializer's expressions and makes /// sure the loans being taken are sound. -struct StaticInitializerCtxt<'a> { - bccx: &'a BorrowckCtxt<'a> +struct StaticInitializerCtxt<'a, 'tcx: 'a> { + bccx: &'a BorrowckCtxt<'a, 'tcx> } -impl<'a> visit::Visitor<()> for StaticInitializerCtxt<'a> { +impl<'a, 'tcx> visit::Visitor<()> for StaticInitializerCtxt<'a, 'tcx> { fn visit_expr(&mut self, ex: &Expr, _: ()) { match ex.node { ast::ExprAddrOf(mutbl, ref base) => { diff --git a/src/librustc/middle/borrowck/gather_loans/restrictions.rs b/src/librustc/middle/borrowck/gather_loans/restrictions.rs index a686084a4a2bc..90e17e4d79cbb 100644 --- a/src/librustc/middle/borrowck/gather_loans/restrictions.rs +++ b/src/librustc/middle/borrowck/gather_loans/restrictions.rs @@ -44,14 +44,14 @@ pub fn compute_restrictions(bccx: &BorrowckCtxt, /////////////////////////////////////////////////////////////////////////// // Private -struct RestrictionsContext<'a> { - bccx: &'a BorrowckCtxt<'a>, +struct RestrictionsContext<'a, 'tcx: 'a> { + bccx: &'a BorrowckCtxt<'a, 'tcx>, span: Span, loan_region: ty::Region, cause: euv::LoanCause, } -impl<'a> RestrictionsContext<'a> { +impl<'a, 'tcx> RestrictionsContext<'a, 'tcx> { fn restrict(&self, cmt: mc::cmt) -> RestrictionResult { debug!("restrict(cmt={})", cmt.repr(self.bccx.tcx)); diff --git a/src/librustc/middle/borrowck/graphviz.rs b/src/librustc/middle/borrowck/graphviz.rs index b19d01187281a..e75378de5a5c7 100644 --- a/src/librustc/middle/borrowck/graphviz.rs +++ b/src/librustc/middle/borrowck/graphviz.rs @@ -43,14 +43,14 @@ impl Variant { } } -pub struct DataflowLabeller<'a> { +pub struct DataflowLabeller<'a, 'tcx: 'a> { pub inner: cfg_dot::LabelledCFG<'a>, pub variants: Vec, - pub borrowck_ctxt: &'a BorrowckCtxt<'a>, - pub analysis_data: &'a borrowck::AnalysisData<'a>, + pub borrowck_ctxt: &'a BorrowckCtxt<'a, 'tcx>, + pub analysis_data: &'a borrowck::AnalysisData<'a, 'tcx>, } -impl<'a> DataflowLabeller<'a> { +impl<'a, 'tcx> DataflowLabeller<'a, 'tcx> { fn dataflow_for(&self, e: EntryOrExit, n: &Node<'a>) -> String { let id = n.val1().data.id; debug!("dataflow_for({}, id={}) {}", e, id, self.variants); @@ -77,7 +77,7 @@ impl<'a> DataflowLabeller<'a> { fn build_set(&self, e: EntryOrExit, cfgidx: CFGIndex, - dfcx: &DataFlowContext<'a, O>, + dfcx: &DataFlowContext<'a, 'tcx, O>, to_lp: |uint| -> Rc) -> String { let mut saw_some = false; let mut set = "{".to_string(); @@ -126,7 +126,7 @@ impl<'a> DataflowLabeller<'a> { } } -impl<'a> dot::Labeller<'a, Node<'a>, Edge<'a>> for DataflowLabeller<'a> { +impl<'a, 'tcx> dot::Labeller<'a, Node<'a>, Edge<'a>> for DataflowLabeller<'a, 'tcx> { fn graph_id(&'a self) -> dot::Id<'a> { self.inner.graph_id() } fn node_id(&'a self, n: &Node<'a>) -> dot::Id<'a> { self.inner.node_id(n) } fn node_label(&'a self, n: &Node<'a>) -> dot::LabelText<'a> { @@ -140,7 +140,7 @@ impl<'a> dot::Labeller<'a, Node<'a>, Edge<'a>> for DataflowLabeller<'a> { fn edge_label(&'a self, e: &Edge<'a>) -> dot::LabelText<'a> { self.inner.edge_label(e) } } -impl<'a> dot::GraphWalk<'a, Node<'a>, Edge<'a>> for DataflowLabeller<'a> { +impl<'a, 'tcx> dot::GraphWalk<'a, Node<'a>, Edge<'a>> for DataflowLabeller<'a, 'tcx> { fn nodes(&self) -> dot::Nodes<'a, Node<'a>> { self.inner.nodes() } fn edges(&self) -> dot::Edges<'a, Edge<'a>> { self.inner.edges() } fn source(&self, edge: &Edge<'a>) -> Node<'a> { self.inner.source(edge) } diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index 230786924d7c4..f4d3678271c0d 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -58,9 +58,9 @@ pub mod move_data; #[deriving(Clone)] pub struct LoanDataFlowOperator; -pub type LoanDataFlow<'a> = DataFlowContext<'a, LoanDataFlowOperator>; +pub type LoanDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, LoanDataFlowOperator>; -impl<'a> Visitor<()> for BorrowckCtxt<'a> { +impl<'a, 'tcx> Visitor<()> for BorrowckCtxt<'a, 'tcx> { fn visit_fn(&mut self, fk: &FnKind, fd: &FnDecl, b: &Block, s: Span, n: NodeId, _: ()) { borrowck_fn(self, fk, fd, b, s, n); @@ -120,10 +120,10 @@ fn borrowck_item(this: &mut BorrowckCtxt, item: &ast::Item) { } /// Collection of conclusions determined via borrow checker analyses. -pub struct AnalysisData<'a> { +pub struct AnalysisData<'a, 'tcx: 'a> { pub all_loans: Vec, - pub loans: DataFlowContext<'a, LoanDataFlowOperator>, - pub move_data: move_data::FlowedMoveData<'a>, + pub loans: DataFlowContext<'a, 'tcx, LoanDataFlowOperator>, + pub move_data: move_data::FlowedMoveData<'a, 'tcx>, } fn borrowck_fn(this: &mut BorrowckCtxt, @@ -145,13 +145,13 @@ fn borrowck_fn(this: &mut BorrowckCtxt, visit::walk_fn(this, fk, decl, body, sp, ()); } -fn build_borrowck_dataflow_data<'a>(this: &mut BorrowckCtxt<'a>, - fk: &FnKind, - decl: &ast::FnDecl, - cfg: &cfg::CFG, - body: &ast::Block, - sp: Span, - id: ast::NodeId) -> AnalysisData<'a> { +fn build_borrowck_dataflow_data<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>, + fk: &FnKind, + decl: &ast::FnDecl, + cfg: &cfg::CFG, + body: &ast::Block, + sp: Span, + id: ast::NodeId) -> AnalysisData<'a, 'tcx> { // Check the body of fn items. let id_range = ast_util::compute_id_range_for_fn_body(fk, decl, body, sp, id); let (all_loans, move_data) = @@ -200,9 +200,9 @@ impl<'a> FnPartsWithCFG<'a> { /// Accessor for introspective clients inspecting `AnalysisData` and /// the `BorrowckCtxt` itself , e.g. the flowgraph visualizer. -pub fn build_borrowck_dataflow_data_for_fn<'a>( - tcx: &'a ty::ctxt, - input: FnPartsWithCFG<'a>) -> (BorrowckCtxt<'a>, AnalysisData<'a>) { +pub fn build_borrowck_dataflow_data_for_fn<'a, 'tcx>( + tcx: &'a ty::ctxt<'tcx>, + input: FnPartsWithCFG<'a>) -> (BorrowckCtxt<'a, 'tcx>, AnalysisData<'a, 'tcx>) { let mut bccx = BorrowckCtxt { tcx: tcx, @@ -230,8 +230,8 @@ pub fn build_borrowck_dataflow_data_for_fn<'a>( // ---------------------------------------------------------------------- // Type definitions -pub struct BorrowckCtxt<'a> { - tcx: &'a ty::ctxt, +pub struct BorrowckCtxt<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx>, // Statistics: stats: Gc, @@ -390,7 +390,7 @@ pub enum MovedValueUseKind { /////////////////////////////////////////////////////////////////////////// // Misc -impl<'a> BorrowckCtxt<'a> { +impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { pub fn is_subregion_of(&self, r_sub: ty::Region, r_sup: ty::Region) -> bool { self.tcx.region_maps.is_subregion_of(r_sub, r_sup) @@ -401,7 +401,7 @@ impl<'a> BorrowckCtxt<'a> { self.tcx.region_maps.is_subscope_of(r_sub, r_sup) } - pub fn mc(&self) -> mc::MemCategorizationContext<'a,ty::ctxt> { + pub fn mc(&self) -> mc::MemCategorizationContext<'a, ty::ctxt<'tcx>> { mc::MemCategorizationContext::new(self.tcx) } diff --git a/src/librustc/middle/borrowck/move_data.rs b/src/librustc/middle/borrowck/move_data.rs index 340056875f2b9..fdd16c886866d 100644 --- a/src/librustc/middle/borrowck/move_data.rs +++ b/src/librustc/middle/borrowck/move_data.rs @@ -56,15 +56,15 @@ pub struct MoveData { pub assignee_ids: RefCell>, } -pub struct FlowedMoveData<'a> { +pub struct FlowedMoveData<'a, 'tcx: 'a> { pub move_data: MoveData, - pub dfcx_moves: MoveDataFlow<'a>, + pub dfcx_moves: MoveDataFlow<'a, 'tcx>, // We could (and maybe should, for efficiency) combine both move // and assign data flow into one, but this way it's easier to // distinguish the bits that correspond to moves and assignments. - pub dfcx_assign: AssignDataFlow<'a> + pub dfcx_assign: AssignDataFlow<'a, 'tcx> } /// Index into `MoveData.paths`, used like a pointer @@ -154,12 +154,12 @@ pub struct Assignment { #[deriving(Clone)] pub struct MoveDataFlowOperator; -pub type MoveDataFlow<'a> = DataFlowContext<'a, MoveDataFlowOperator>; +pub type MoveDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, MoveDataFlowOperator>; #[deriving(Clone)] pub struct AssignDataFlowOperator; -pub type AssignDataFlow<'a> = DataFlowContext<'a, AssignDataFlowOperator>; +pub type AssignDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, AssignDataFlowOperator>; fn loan_path_is_precise(loan_path: &LoanPath) -> bool { match *loan_path { @@ -531,14 +531,14 @@ impl MoveData { } } -impl<'a> FlowedMoveData<'a> { +impl<'a, 'tcx> FlowedMoveData<'a, 'tcx> { pub fn new(move_data: MoveData, - tcx: &'a ty::ctxt, + tcx: &'a ty::ctxt<'tcx>, cfg: &cfg::CFG, id_range: ast_util::IdRange, decl: &ast::FnDecl, body: &ast::Block) - -> FlowedMoveData<'a> { + -> FlowedMoveData<'a, 'tcx> { let mut dfcx_moves = DataFlowContext::new(tcx, "flowed_move_data_moves", diff --git a/src/librustc/middle/cfg/construct.rs b/src/librustc/middle/cfg/construct.rs index 776067d49a218..ec414b858187a 100644 --- a/src/librustc/middle/cfg/construct.rs +++ b/src/librustc/middle/cfg/construct.rs @@ -19,8 +19,8 @@ use util::nodemap::NodeMap; use std::gc::Gc; -struct CFGBuilder<'a> { - tcx: &'a ty::ctxt, +struct CFGBuilder<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx>, exit_map: NodeMap, graph: CFGGraph, fn_exit: CFGIndex, @@ -65,7 +65,7 @@ fn add_initial_dummy_node(g: &mut CFGGraph) -> CFGIndex { g.add_node(CFGNodeData { id: ast::DUMMY_NODE_ID }) } -impl<'a> CFGBuilder<'a> { +impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { fn block(&mut self, blk: &ast::Block, pred: CFGIndex) -> CFGIndex { let mut stmts_exit = pred; for stmt in blk.stmts.iter() { diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 629aba8092c27..3c8db8d048076 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -21,11 +21,11 @@ use syntax::{ast_util, ast_map}; use syntax::visit::Visitor; use syntax::visit; -pub struct CheckCrateVisitor<'a> { - tcx: &'a ty::ctxt, +pub struct CheckCrateVisitor<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx>, } -impl<'a> Visitor for CheckCrateVisitor<'a> { +impl<'a, 'tcx> Visitor for CheckCrateVisitor<'a, 'tcx> { fn visit_item(&mut self, i: &Item, env: bool) { check_item(self, i, env); } diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index c234682471080..6676ea9851db0 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -86,8 +86,8 @@ impl FromIterator>> for Matrix { } } -pub struct MatchCheckCtxt<'a> { - pub tcx: &'a ty::ctxt +pub struct MatchCheckCtxt<'a, 'tcx: 'a> { + pub tcx: &'a ty::ctxt<'tcx> } #[deriving(Clone, PartialEq)] @@ -119,7 +119,7 @@ enum WitnessPreference { LeaveOutWitness } -impl<'a> Visitor<()> for MatchCheckCtxt<'a> { +impl<'a, 'tcx> Visitor<()> for MatchCheckCtxt<'a, 'tcx> { fn visit_expr(&mut self, ex: &Expr, _: ()) { check_expr(self, ex); } @@ -304,13 +304,13 @@ fn const_val_to_expr(value: &const_val) -> Gc { } } -pub struct StaticInliner<'a> { - pub tcx: &'a ty::ctxt, +pub struct StaticInliner<'a, 'tcx: 'a> { + pub tcx: &'a ty::ctxt<'tcx>, pub failed: bool } -impl<'a> StaticInliner<'a> { - pub fn new<'a>(tcx: &'a ty::ctxt) -> StaticInliner<'a> { +impl<'a, 'tcx> StaticInliner<'a, 'tcx> { + pub fn new<'a>(tcx: &'a ty::ctxt<'tcx>) -> StaticInliner<'a, 'tcx> { StaticInliner { tcx: tcx, failed: false @@ -318,7 +318,7 @@ impl<'a> StaticInliner<'a> { } } -impl<'a> Folder for StaticInliner<'a> { +impl<'a, 'tcx> Folder for StaticInliner<'a, 'tcx> { fn fold_pat(&mut self, pat: Gc) -> Gc { match pat.node { PatIdent(..) | PatEnum(..) => { @@ -963,7 +963,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt, /// Ensures that a pattern guard doesn't borrow by mutable reference or /// assign. -fn check_for_mutation_in_guard<'a>(cx: &'a MatchCheckCtxt<'a>, guard: &Expr) { +fn check_for_mutation_in_guard<'a, 'tcx>(cx: &'a MatchCheckCtxt<'a, 'tcx>, guard: &Expr) { let mut checker = MutationChecker { cx: cx, }; @@ -971,11 +971,11 @@ fn check_for_mutation_in_guard<'a>(cx: &'a MatchCheckCtxt<'a>, guard: &Expr) { visitor.walk_expr(guard); } -struct MutationChecker<'a> { - cx: &'a MatchCheckCtxt<'a>, +struct MutationChecker<'a, 'tcx: 'a> { + cx: &'a MatchCheckCtxt<'a, 'tcx>, } -impl<'a> Delegate for MutationChecker<'a> { +impl<'a, 'tcx> Delegate for MutationChecker<'a, 'tcx> { fn consume(&mut self, _: NodeId, _: Span, _: cmt, _: ConsumeMode) {} fn consume_pat(&mut self, _: &Pat, _: cmt, _: ConsumeMode) {} fn borrow(&mut self, @@ -1020,11 +1020,11 @@ fn check_legality_of_bindings_in_at_patterns(cx: &MatchCheckCtxt, pat: &Pat) { visitor.visit_pat(pat, true); } -struct AtBindingPatternVisitor<'a,'b:'a> { - cx: &'a MatchCheckCtxt<'b>, +struct AtBindingPatternVisitor<'a, 'b:'a, 'tcx:'b> { + cx: &'a MatchCheckCtxt<'b, 'tcx>, } -impl<'a,'b> Visitor for AtBindingPatternVisitor<'a,'b> { +impl<'a, 'b, 'tcx> Visitor for AtBindingPatternVisitor<'a, 'b, 'tcx> { fn visit_pat(&mut self, pat: &Pat, bindings_allowed: bool) { if !bindings_allowed && pat_is_binding(&self.cx.tcx.def_map, pat) { self.cx.tcx.sess.span_err(pat.span, diff --git a/src/librustc/middle/check_rvalues.rs b/src/librustc/middle/check_rvalues.rs index 0ac6f21dc1f98..f851ddbeeac23 100644 --- a/src/librustc/middle/check_rvalues.rs +++ b/src/librustc/middle/check_rvalues.rs @@ -26,11 +26,11 @@ pub fn check_crate(tcx: &ty::ctxt, visit::walk_crate(&mut rvcx, krate, ()); } -struct RvalueContext<'a> { - tcx: &'a ty::ctxt +struct RvalueContext<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx> } -impl<'a> visit::Visitor<()> for RvalueContext<'a> { +impl<'a, 'tcx> visit::Visitor<()> for RvalueContext<'a, 'tcx> { fn visit_fn(&mut self, _: &visit::FnKind, fd: &ast::FnDecl, @@ -43,7 +43,7 @@ impl<'a> visit::Visitor<()> for RvalueContext<'a> { } } -impl<'a> euv::Delegate for RvalueContext<'a> { +impl<'a, 'tcx> euv::Delegate for RvalueContext<'a, 'tcx> { fn consume(&mut self, _: ast::NodeId, span: Span, diff --git a/src/librustc/middle/check_static.rs b/src/librustc/middle/check_static.rs index 042a5b8f60aaf..7b00bb4589c71 100644 --- a/src/librustc/middle/check_static.rs +++ b/src/librustc/middle/check_static.rs @@ -52,15 +52,15 @@ fn safe_type_for_static_mut(cx: &ty::ctxt, e: &ast::Expr) -> Option { Some(format!("mutable static items are not allowed to have {}", suffix)) } -struct CheckStaticVisitor<'a> { - tcx: &'a ty::ctxt, +struct CheckStaticVisitor<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx>, } pub fn check_crate(tcx: &ty::ctxt, krate: &ast::Crate) { visit::walk_crate(&mut CheckStaticVisitor { tcx: tcx }, krate, false) } -impl<'a> CheckStaticVisitor<'a> { +impl<'a, 'tcx> CheckStaticVisitor<'a, 'tcx> { fn report_error(&self, span: Span, result: Option) -> bool { match result { None => { false } @@ -72,7 +72,7 @@ impl<'a> CheckStaticVisitor<'a> { } } -impl<'a> Visitor for CheckStaticVisitor<'a> { +impl<'a, 'tcx> Visitor for CheckStaticVisitor<'a, 'tcx> { fn visit_item(&mut self, i: &ast::Item, _is_const: bool) { debug!("visit_item(item={})", pprust::item_to_string(i)); diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 2a00724cafbe5..e853b5961ec4f 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -176,12 +176,12 @@ pub fn lookup_const_by_id(tcx: &ty::ctxt, def_id: ast::DefId) } } -struct ConstEvalVisitor<'a> { - tcx: &'a ty::ctxt, +struct ConstEvalVisitor<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx>, ccache: constness_cache, } -impl<'a> ConstEvalVisitor<'a> { +impl<'a, 'tcx> ConstEvalVisitor<'a, 'tcx> { fn classify(&mut self, e: &Expr) -> constness { let did = ast_util::local_def(e.id); match self.ccache.find(&did) { @@ -266,7 +266,7 @@ impl<'a> ConstEvalVisitor<'a> { } -impl<'a> Visitor<()> for ConstEvalVisitor<'a> { +impl<'a, 'tcx> Visitor<()> for ConstEvalVisitor<'a, 'tcx> { fn visit_ty(&mut self, t: &Ty, _: ()) { match t.node { TyFixedLengthVec(_, expr) => { @@ -365,8 +365,7 @@ pub fn eval_const_expr(tcx: &ty::ctxt, e: &Expr) -> const_val { } } -pub fn eval_const_expr_partial(tcx: &T, e: &Expr) - -> Result { +pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result { fn fromb(b: bool) -> Result { Ok(const_int(b as i64)) } match e.node { ExprUnary(UnNeg, ref inner) => { @@ -494,12 +493,11 @@ pub fn eval_const_expr_partial(tcx: &T, e: &Expr) // This tends to get called w/o the type actually having been // populated in the ctxt, which was causing things to blow up // (#5900). Fall back to doing a limited lookup to get past it. - let ety = ty::expr_ty_opt(tcx.ty_ctxt(), e) - .or_else(|| astconv::ast_ty_to_prim_ty(tcx.ty_ctxt(), &**target_ty)) + let ety = ty::expr_ty_opt(tcx, e) + .or_else(|| astconv::ast_ty_to_prim_ty(tcx, &**target_ty)) .unwrap_or_else(|| { - tcx.ty_ctxt().sess.span_fatal(target_ty.span, - "target type not found for \ - const cast") + tcx.sess.span_fatal(target_ty.span, + "target type not found for const cast") }); let base = eval_const_expr_partial(tcx, &**base); @@ -540,8 +538,8 @@ pub fn eval_const_expr_partial(tcx: &T, e: &Expr) } } ExprPath(_) => { - match lookup_const(tcx.ty_ctxt(), e) { - Some(actual_e) => eval_const_expr_partial(tcx.ty_ctxt(), &*actual_e), + match lookup_const(tcx, e) { + Some(actual_e) => eval_const_expr_partial(tcx, &*actual_e), None => Err("non-constant path in constant expr".to_string()) } } diff --git a/src/librustc/middle/dataflow.rs b/src/librustc/middle/dataflow.rs index 097f49a1e6e55..c32f8db2380e4 100644 --- a/src/librustc/middle/dataflow.rs +++ b/src/librustc/middle/dataflow.rs @@ -32,8 +32,8 @@ use util::nodemap::NodeMap; pub enum EntryOrExit { Entry, Exit } #[deriving(Clone)] -pub struct DataFlowContext<'a, O> { - tcx: &'a ty::ctxt, +pub struct DataFlowContext<'a, 'tcx: 'a, O> { + tcx: &'a ty::ctxt<'tcx>, /// a name for the analysis using this dataflow instance analysis_name: &'static str, @@ -80,8 +80,8 @@ pub trait DataFlowOperator : BitwiseOperator { fn initial_value(&self) -> bool; } -struct PropagationContext<'a, 'b:'a, O:'a> { - dfcx: &'a mut DataFlowContext<'b, O>, +struct PropagationContext<'a, 'b: 'a, 'tcx: 'b, O: 'a> { + dfcx: &'a mut DataFlowContext<'b, 'tcx, O>, changed: bool } @@ -92,14 +92,14 @@ fn to_cfgidx_or_die(id: ast::NodeId, index: &NodeMap) -> CFGIndex { }) } -impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> { +impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> { fn has_bitset_for_nodeid(&self, n: ast::NodeId) -> bool { assert!(n != ast::DUMMY_NODE_ID); self.nodeid_to_index.contains_key(&n) } } -impl<'a, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, O> { +impl<'a, 'tcx, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, 'tcx, O> { fn pre(&self, ps: &mut pprust::State, node: pprust::AnnNode) -> io::IoResult<()> { @@ -182,14 +182,14 @@ fn build_nodeid_to_index(decl: Option<&ast::FnDecl>, } } -impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> { - pub fn new(tcx: &'a ty::ctxt, +impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> { + pub fn new(tcx: &'a ty::ctxt<'tcx>, analysis_name: &'static str, decl: Option<&ast::FnDecl>, cfg: &cfg::CFG, oper: O, id_range: IdRange, - bits_per_id: uint) -> DataFlowContext<'a, O> { + bits_per_id: uint) -> DataFlowContext<'a, 'tcx, O> { let words_per_id = (bits_per_id + uint::BITS - 1) / uint::BITS; let num_nodes = cfg.graph.all_nodes().len(); @@ -427,8 +427,8 @@ impl<'a, O:DataFlowOperator> DataFlowContext<'a, O> { } } -impl<'a, O:DataFlowOperator+Clone+'static> DataFlowContext<'a, O> { -// ^^^^^^^^^^^^^ only needed for pretty printing +impl<'a, 'tcx, O:DataFlowOperator+Clone+'static> DataFlowContext<'a, 'tcx, O> { +// ^^^^^^^^^^^^^ only needed for pretty printing pub fn propagate(&mut self, cfg: &cfg::CFG, blk: &ast::Block) { //! Performs the data flow analysis. @@ -469,7 +469,7 @@ impl<'a, O:DataFlowOperator+Clone+'static> DataFlowContext<'a, O> { } } -impl<'a, 'b, O:DataFlowOperator> PropagationContext<'a, 'b, O> { +impl<'a, 'b, 'tcx, O:DataFlowOperator> PropagationContext<'a, 'b, 'tcx, O> { fn walk_cfg(&mut self, cfg: &cfg::CFG, in_out: &mut [uint]) { diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 0dfdf45574356..b7cddd0c23f96 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -47,9 +47,9 @@ fn should_explore(tcx: &ty::ctxt, def_id: ast::DefId) -> bool { } } -struct MarkSymbolVisitor<'a> { +struct MarkSymbolVisitor<'a, 'tcx: 'a> { worklist: Vec, - tcx: &'a ty::ctxt, + tcx: &'a ty::ctxt<'tcx>, live_symbols: Box>, } @@ -58,9 +58,9 @@ struct MarkSymbolVisitorContext { struct_has_extern_repr: bool } -impl<'a> MarkSymbolVisitor<'a> { - fn new(tcx: &'a ty::ctxt, - worklist: Vec) -> MarkSymbolVisitor<'a> { +impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { + fn new(tcx: &'a ty::ctxt<'tcx>, + worklist: Vec) -> MarkSymbolVisitor<'a, 'tcx> { MarkSymbolVisitor { worklist: worklist, tcx: tcx, @@ -232,7 +232,7 @@ impl<'a> MarkSymbolVisitor<'a> { } } -impl<'a> Visitor for MarkSymbolVisitor<'a> { +impl<'a, 'tcx> Visitor for MarkSymbolVisitor<'a, 'tcx> { fn visit_struct_def(&mut self, def: &ast::StructDef, _: ast::Ident, _: &ast::Generics, _: ast::NodeId, ctxt: MarkSymbolVisitorContext) { @@ -418,12 +418,12 @@ fn get_struct_ctor_id(item: &ast::Item) -> Option { } } -struct DeadVisitor<'a> { - tcx: &'a ty::ctxt, +struct DeadVisitor<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx>, live_symbols: Box>, } -impl<'a> DeadVisitor<'a> { +impl<'a, 'tcx> DeadVisitor<'a, 'tcx> { fn should_warn_about_field(&mut self, node: &ast::StructField_) -> bool { let is_named = node.ident().is_some(); let field_type = ty::node_id_to_type(self.tcx, node.id); @@ -490,7 +490,7 @@ impl<'a> DeadVisitor<'a> { } } -impl<'a> Visitor<()> for DeadVisitor<'a> { +impl<'a, 'tcx> Visitor<()> for DeadVisitor<'a, 'tcx> { fn visit_item(&mut self, item: &ast::Item, _: ()) { let ctor_id = get_struct_ctor_id(item); if !self.symbol_is_live(item.id, ctor_id) && should_warn(item) { diff --git a/src/librustc/middle/effect.rs b/src/librustc/middle/effect.rs index dc4ecb358308d..ec1430edcddb9 100644 --- a/src/librustc/middle/effect.rs +++ b/src/librustc/middle/effect.rs @@ -37,14 +37,14 @@ fn type_is_unsafe_function(ty: ty::t) -> bool { } } -struct EffectCheckVisitor<'a> { - tcx: &'a ty::ctxt, +struct EffectCheckVisitor<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx>, /// Whether we're in an unsafe context. unsafe_context: UnsafeContext, } -impl<'a> EffectCheckVisitor<'a> { +impl<'a, 'tcx> EffectCheckVisitor<'a, 'tcx> { fn require_unsafe(&mut self, span: Span, description: &str) { match self.unsafe_context { SafeContext => { @@ -86,7 +86,7 @@ impl<'a> EffectCheckVisitor<'a> { } } -impl<'a> Visitor<()> for EffectCheckVisitor<'a> { +impl<'a, 'tcx> Visitor<()> for EffectCheckVisitor<'a, 'tcx> { fn visit_fn(&mut self, fn_kind: &visit::FnKind, fn_decl: &ast::FnDecl, block: &ast::Block, span: Span, _: ast::NodeId, _:()) { diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index a7e49edbc8e4a..207620b182907 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -214,7 +214,7 @@ macro_rules! return_if_err( ) ) -impl<'d,'t,TYPER:mc::Typer> ExprUseVisitor<'d,'t,TYPER> { +impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,TYPER> { pub fn new(delegate: &'d mut Delegate, typer: &'t TYPER) -> ExprUseVisitor<'d,'t,TYPER> { @@ -246,7 +246,7 @@ impl<'d,'t,TYPER:mc::Typer> ExprUseVisitor<'d,'t,TYPER> { } } - fn tcx<'a>(&'a self) -> &'a ty::ctxt { + fn tcx(&self) -> &'t ty::ctxt<'tcx> { self.typer.tcx() } diff --git a/src/librustc/middle/freevars.rs b/src/librustc/middle/freevars.rs index 1a2d21baa210a..df5a6b6d2a113 100644 --- a/src/librustc/middle/freevars.rs +++ b/src/librustc/middle/freevars.rs @@ -180,7 +180,7 @@ pub fn with_freevars(tcx: &ty::ctxt, fid: ast::NodeId, f: |&[freevar_entry]| } } -pub fn get_capture_mode(tcx: &T, closure_expr_id: ast::NodeId) - -> CaptureMode { +pub fn get_capture_mode<'tcx, T:Typer<'tcx>>(tcx: &T, closure_expr_id: ast::NodeId) + -> CaptureMode { tcx.capture_mode(closure_expr_id) } diff --git a/src/librustc/middle/intrinsicck.rs b/src/librustc/middle/intrinsicck.rs index be587c255742c..25a8555565c93 100644 --- a/src/librustc/middle/intrinsicck.rs +++ b/src/librustc/middle/intrinsicck.rs @@ -67,11 +67,11 @@ fn type_size_is_affected_by_type_parameters(tcx: &ty::ctxt, typ: ty::t) result } -struct IntrinsicCheckingVisitor<'a> { - tcx: &'a ctxt, +struct IntrinsicCheckingVisitor<'a, 'tcx: 'a> { + tcx: &'a ctxt<'tcx>, } -impl<'a> IntrinsicCheckingVisitor<'a> { +impl<'a, 'tcx> IntrinsicCheckingVisitor<'a, 'tcx> { fn def_id_is_transmute(&self, def_id: DefId) -> bool { let intrinsic = match ty::get(ty::lookup_item_type(self.tcx, def_id).ty).sty { ty::ty_bare_fn(ref bfty) => bfty.abi == RustIntrinsic, @@ -116,7 +116,7 @@ impl<'a> IntrinsicCheckingVisitor<'a> { } } -impl<'a> Visitor<()> for IntrinsicCheckingVisitor<'a> { +impl<'a, 'tcx> Visitor<()> for IntrinsicCheckingVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &ast::Expr, (): ()) { match expr.node { ast::ExprPath(..) => { diff --git a/src/librustc/middle/kind.rs b/src/librustc/middle/kind.rs index 99c1d65d2b5b4..e556c5a59c224 100644 --- a/src/librustc/middle/kind.rs +++ b/src/librustc/middle/kind.rs @@ -50,13 +50,13 @@ use syntax::visit; // primitives in the stdlib are explicitly annotated to only take sendable // types. -pub struct Context<'a> { - tcx: &'a ty::ctxt, +pub struct Context<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx>, struct_and_enum_bounds_checked: HashSet, parameter_environments: Vec, } -impl<'a> Visitor<()> for Context<'a> { +impl<'a, 'tcx> Visitor<()> for Context<'a, 'tcx> { fn visit_expr(&mut self, ex: &Expr, _: ()) { check_expr(self, ex); } @@ -94,11 +94,11 @@ pub fn check_crate(tcx: &ty::ctxt, tcx.sess.abort_if_errors(); } -struct EmptySubstsFolder<'a> { - tcx: &'a ty::ctxt +struct EmptySubstsFolder<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx> } -impl<'a> ty_fold::TypeFolder for EmptySubstsFolder<'a> { - fn tcx<'a>(&'a self) -> &'a ty::ctxt { +impl<'a, 'tcx> ty_fold::TypeFolder<'tcx> for EmptySubstsFolder<'a, 'tcx> { + fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.tcx } fn fold_substs(&mut self, _: &subst::Substs) -> subst::Substs { diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 6ff09916b35ae..26aa51b909944 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -179,7 +179,7 @@ fn live_node_kind_to_string(lnk: LiveNodeKind, cx: &ty::ctxt) -> String { } } -impl<'a> Visitor<()> for IrMaps<'a> { +impl<'a, 'tcx> Visitor<()> for IrMaps<'a, 'tcx> { fn visit_fn(&mut self, fk: &FnKind, fd: &FnDecl, b: &Block, s: Span, n: NodeId, _: ()) { visit_fn(self, fk, fd, b, s, n); } @@ -252,8 +252,8 @@ enum VarKind { ImplicitRet } -struct IrMaps<'a> { - tcx: &'a ty::ctxt, +struct IrMaps<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx>, num_live_nodes: uint, num_vars: uint, @@ -264,8 +264,8 @@ struct IrMaps<'a> { lnks: Vec, } -impl<'a> IrMaps<'a> { - fn new(tcx: &'a ty::ctxt) -> IrMaps<'a> { +impl<'a, 'tcx> IrMaps<'a, 'tcx> { + fn new(tcx: &'a ty::ctxt<'tcx>) -> IrMaps<'a, 'tcx> { IrMaps { tcx: tcx, num_live_nodes: 0, @@ -343,7 +343,7 @@ impl<'a> IrMaps<'a> { } } -impl<'a> Visitor<()> for Liveness<'a> { +impl<'a, 'tcx> Visitor<()> for Liveness<'a, 'tcx> { fn visit_fn(&mut self, fk: &FnKind, fd: &FnDecl, b: &Block, s: Span, n: NodeId, _: ()) { check_fn(self, fk, fd, b, s, n); } @@ -555,8 +555,8 @@ static ACC_READ: uint = 1u; static ACC_WRITE: uint = 2u; static ACC_USE: uint = 4u; -struct Liveness<'a> { - ir: &'a mut IrMaps<'a>, +struct Liveness<'a, 'tcx: 'a> { + ir: &'a mut IrMaps<'a, 'tcx>, s: Specials, successors: Vec, users: Vec, @@ -570,8 +570,8 @@ struct Liveness<'a> { cont_ln: NodeMap } -impl<'a> Liveness<'a> { - fn new(ir: &'a mut IrMaps<'a>, specials: Specials) -> Liveness<'a> { +impl<'a, 'tcx> Liveness<'a, 'tcx> { + fn new(ir: &'a mut IrMaps<'a, 'tcx>, specials: Specials) -> Liveness<'a, 'tcx> { let num_live_nodes = ir.num_live_nodes; let num_vars = ir.num_vars; Liveness { @@ -607,7 +607,7 @@ impl<'a> Liveness<'a> { fn pat_bindings(&mut self, pat: &Pat, - f: |&mut Liveness<'a>, LiveNode, Variable, Span, NodeId|) { + f: |&mut Liveness<'a, 'tcx>, LiveNode, Variable, Span, NodeId|) { pat_util::pat_bindings(&self.ir.tcx.def_map, pat, |_bm, p_id, sp, _n| { let ln = self.live_node(p_id, sp); let var = self.variable(p_id, sp); @@ -617,7 +617,7 @@ impl<'a> Liveness<'a> { fn arm_pats_bindings(&mut self, pats: &[Gc], - f: |&mut Liveness<'a>, LiveNode, Variable, Span, NodeId|) { + f: |&mut Liveness<'a, 'tcx>, LiveNode, Variable, Span, NodeId|) { // only consider the first pattern; any later patterns must have // the same bindings, and we also consider the first pattern to be // the "authoritative" set of ids @@ -683,7 +683,7 @@ impl<'a> Liveness<'a> { fn indices2(&mut self, ln: LiveNode, succ_ln: LiveNode, - op: |&mut Liveness<'a>, uint, uint|) { + op: |&mut Liveness<'a, 'tcx>, uint, uint|) { let node_base_idx = self.idx(ln, Variable(0u)); let succ_base_idx = self.idx(succ_ln, Variable(0u)); for var_idx in range(0u, self.ir.num_vars) { @@ -1376,7 +1376,7 @@ impl<'a> Liveness<'a> { loop_node_id: NodeId, break_ln: LiveNode, cont_ln: LiveNode, - f: |&mut Liveness<'a>| -> R) + f: |&mut Liveness<'a, 'tcx>| -> R) -> R { debug!("with_loop_nodes: {} {}", loop_node_id, break_ln.get()); self.loop_scope.push(loop_node_id); @@ -1465,7 +1465,7 @@ fn check_fn(_v: &Liveness, // do not check contents of nested fns } -impl<'a> Liveness<'a> { +impl<'a, 'tcx> Liveness<'a, 'tcx> { fn check_ret(&self, id: NodeId, sp: Span, diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 56e501388f1e8..abed04c8f33ac 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -264,8 +264,8 @@ pub type McResult = Result; * know that no errors have occurred, so we simply consult the tcx and we * can be sure that only `Ok` results will occur. */ -pub trait Typer { - fn tcx<'a>(&'a self) -> &'a ty::ctxt; +pub trait Typer<'tcx> { + fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx>; fn node_ty(&self, id: ast::NodeId) -> McResult; fn node_method_ty(&self, method_call: typeck::MethodCall) -> Option; fn adjustments<'a>(&'a self) -> &'a RefCell>; @@ -375,12 +375,12 @@ macro_rules! if_ok( ) ) -impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> { +impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> { pub fn new(typer: &'t TYPER) -> MemCategorizationContext<'t,TYPER> { MemCategorizationContext { typer: typer } } - fn tcx(&self) -> &'t ty::ctxt { + fn tcx(&self) -> &'t ty::ctxt<'tcx> { self.typer.tcx() } diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 42d6cee965476..6017444267a4f 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -133,8 +133,8 @@ impl Visitor<()> for ParentVisitor { /// The embargo visitor, used to determine the exports of the ast //////////////////////////////////////////////////////////////////////////////// -struct EmbargoVisitor<'a> { - tcx: &'a ty::ctxt, +struct EmbargoVisitor<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx>, exp_map2: &'a resolve::ExportMap2, // This flag is an indicator of whether the previous item in the @@ -163,7 +163,7 @@ struct EmbargoVisitor<'a> { prev_public: bool, } -impl<'a> EmbargoVisitor<'a> { +impl<'a, 'tcx> EmbargoVisitor<'a, 'tcx> { // There are checks inside of privacy which depend on knowing whether a // trait should be exported or not. The two current consumers of this are: // @@ -180,7 +180,7 @@ impl<'a> EmbargoVisitor<'a> { } } -impl<'a> Visitor<()> for EmbargoVisitor<'a> { +impl<'a, 'tcx> Visitor<()> for EmbargoVisitor<'a, 'tcx> { fn visit_item(&mut self, item: &ast::Item, _: ()) { let orig_all_pub = self.prev_public; self.prev_public = orig_all_pub && item.vis == ast::Public; @@ -355,8 +355,8 @@ impl<'a> Visitor<()> for EmbargoVisitor<'a> { /// The privacy visitor, where privacy checks take place (violations reported) //////////////////////////////////////////////////////////////////////////////// -struct PrivacyVisitor<'a> { - tcx: &'a ty::ctxt, +struct PrivacyVisitor<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx>, curitem: ast::NodeId, in_foreign: bool, parents: NodeMap, @@ -376,7 +376,7 @@ enum FieldName { NamedField(ast::Ident), } -impl<'a> PrivacyVisitor<'a> { +impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { // used when debugging fn nodestr(&self, id: ast::NodeId) -> String { self.tcx.map.node_to_string(id).to_string() @@ -802,7 +802,7 @@ impl<'a> PrivacyVisitor<'a> { } } -impl<'a> Visitor<()> for PrivacyVisitor<'a> { +impl<'a, 'tcx> Visitor<()> for PrivacyVisitor<'a, 'tcx> { fn visit_item(&mut self, item: &ast::Item, _: ()) { let orig_curitem = replace(&mut self.curitem, item.id); visit::walk_item(self, item, ()); @@ -1023,12 +1023,12 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> { /// The privacy sanity check visitor, ensures unnecessary visibility isn't here //////////////////////////////////////////////////////////////////////////////// -struct SanePrivacyVisitor<'a> { - tcx: &'a ty::ctxt, +struct SanePrivacyVisitor<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx>, in_fn: bool, } -impl<'a> Visitor<()> for SanePrivacyVisitor<'a> { +impl<'a, 'tcx> Visitor<()> for SanePrivacyVisitor<'a, 'tcx> { fn visit_item(&mut self, item: &ast::Item, _: ()) { if self.in_fn { self.check_all_inherited(item); @@ -1076,7 +1076,7 @@ impl<'a> Visitor<()> for SanePrivacyVisitor<'a> { } } -impl<'a> SanePrivacyVisitor<'a> { +impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> { /// Validates all of the visibility qualifiers placed on the item given. This /// ensures that there are no extraneous qualifiers that don't actually do /// anything. In theory these qualifiers wouldn't parse, but that may happen @@ -1215,14 +1215,14 @@ impl<'a> SanePrivacyVisitor<'a> { } } -struct VisiblePrivateTypesVisitor<'a> { - tcx: &'a ty::ctxt, +struct VisiblePrivateTypesVisitor<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx>, exported_items: &'a ExportedItems, public_items: &'a PublicItems, } -struct CheckTypeForPrivatenessVisitor<'a, 'b:'a> { - inner: &'a VisiblePrivateTypesVisitor<'b>, +struct CheckTypeForPrivatenessVisitor<'a, 'b: 'a, 'tcx: 'b> { + inner: &'a VisiblePrivateTypesVisitor<'b, 'tcx>, /// whether the type refers to private types. contains_private: bool, /// whether we've recurred at all (i.e. if we're pointing at the @@ -1232,7 +1232,7 @@ struct CheckTypeForPrivatenessVisitor<'a, 'b:'a> { outer_type_is_public_path: bool, } -impl<'a> VisiblePrivateTypesVisitor<'a> { +impl<'a, 'tcx> VisiblePrivateTypesVisitor<'a, 'tcx> { fn path_is_private_type(&self, path_id: ast::NodeId) -> bool { let did = match self.tcx.def_map.borrow().find_copy(&path_id) { // `int` etc. (None doesn't seem to occur.) @@ -1256,7 +1256,7 @@ impl<'a> VisiblePrivateTypesVisitor<'a> { } } -impl<'a, 'b> Visitor<()> for CheckTypeForPrivatenessVisitor<'a, 'b> { +impl<'a, 'b, 'tcx> Visitor<()> for CheckTypeForPrivatenessVisitor<'a, 'b, 'tcx> { fn visit_ty(&mut self, ty: &ast::Ty, _: ()) { match ty.node { ast::TyPath(_, _, path_id) => { @@ -1279,7 +1279,7 @@ impl<'a, 'b> Visitor<()> for CheckTypeForPrivatenessVisitor<'a, 'b> { fn visit_expr(&mut self, _: &ast::Expr, _: ()) {} } -impl<'a> Visitor<()> for VisiblePrivateTypesVisitor<'a> { +impl<'a, 'tcx> Visitor<()> for VisiblePrivateTypesVisitor<'a, 'tcx> { fn visit_item(&mut self, item: &ast::Item, _: ()) { match item.node { // contents of a private mod can be reexported, so we need diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 5dfc43daa646f..7ba5144985ef2 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -89,9 +89,9 @@ fn method_might_be_inlined(tcx: &ty::ctxt, method: &ast::Method, } // Information needed while computing reachability. -struct ReachableContext<'a> { +struct ReachableContext<'a, 'tcx: 'a> { // The type context. - tcx: &'a ty::ctxt, + tcx: &'a ty::ctxt<'tcx>, // The set of items which must be exported in the linkage sense. reachable_symbols: NodeSet, // A worklist of item IDs. Each item ID in this worklist will be inlined @@ -101,7 +101,7 @@ struct ReachableContext<'a> { any_library: bool, } -impl<'a> Visitor<()> for ReachableContext<'a> { +impl<'a, 'tcx> Visitor<()> for ReachableContext<'a, 'tcx> { fn visit_expr(&mut self, expr: &ast::Expr, _: ()) { @@ -164,9 +164,9 @@ impl<'a> Visitor<()> for ReachableContext<'a> { } } -impl<'a> ReachableContext<'a> { +impl<'a, 'tcx> ReachableContext<'a, 'tcx> { // Creates a new reachability computation context. - fn new(tcx: &'a ty::ctxt) -> ReachableContext<'a> { + fn new(tcx: &'a ty::ctxt<'tcx>) -> ReachableContext<'a, 'tcx> { let any_library = tcx.sess.crate_types.borrow().iter().any(|ty| { *ty != config::CrateTypeExecutable }); diff --git a/src/librustc/middle/save/mod.rs b/src/librustc/middle/save/mod.rs index cd3f47e8b2f7a..7c7960e0918f4 100644 --- a/src/librustc/middle/save/mod.rs +++ b/src/librustc/middle/save/mod.rs @@ -74,9 +74,9 @@ fn generated_code(span: Span) -> bool { span.expn_info.is_some() || span == DUMMY_SP } -struct DxrVisitor<'l> { +struct DxrVisitor<'l, 'tcx: 'l> { sess: &'l Session, - analysis: &'l CrateAnalysis, + analysis: &'l CrateAnalysis<'tcx>, collected_paths: Vec<(NodeId, ast::Path, bool, recorder::Row)>, collecting: bool, @@ -85,7 +85,7 @@ struct DxrVisitor<'l> { fmt: FmtStrs<'l>, } -impl <'l> DxrVisitor<'l> { +impl <'l, 'tcx> DxrVisitor<'l, 'tcx> { fn dump_crate_info(&mut self, name: &str, krate: &ast::Crate) { // the current crate self.fmt.crate_str(krate.span, name); @@ -1023,7 +1023,7 @@ impl <'l> DxrVisitor<'l> { } } -impl<'l> Visitor for DxrVisitor<'l> { +impl<'l, 'tcx> Visitor for DxrVisitor<'l, 'tcx> { fn visit_item(&mut self, item:&ast::Item, e: DxrVisitorEnv) { if generated_code(item.span) { return diff --git a/src/librustc/middle/subst.rs b/src/librustc/middle/subst.rs index d992e840b4636..c1c23dff98406 100644 --- a/src/librustc/middle/subst.rs +++ b/src/librustc/middle/subst.rs @@ -548,8 +548,8 @@ impl Subst for T { /////////////////////////////////////////////////////////////////////////// // The actual substitution engine itself is a type folder. -struct SubstFolder<'a> { - tcx: &'a ty::ctxt, +struct SubstFolder<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx>, substs: &'a Substs, // The location for which the substitution is performed, if available. @@ -562,8 +562,8 @@ struct SubstFolder<'a> { ty_stack_depth: uint, } -impl<'a> TypeFolder for SubstFolder<'a> { - fn tcx<'a>(&'a self) -> &'a ty::ctxt { self.tcx } +impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> { + fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.tcx } fn fold_region(&mut self, r: ty::Region) -> ty::Region { // Note: This routine only handles regions that are bound on diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 1b93e1974419c..dd0668b8fa0e7 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -225,14 +225,14 @@ use syntax::ast::Ident; use syntax::codemap::Span; use syntax::fold::Folder; -struct ConstantExpr<'a>(&'a ty::ctxt, Gc); +struct ConstantExpr<'a, 'tcx: 'a>(&'a ty::ctxt<'tcx>, Gc); -impl<'a> Eq for ConstantExpr<'a> { +impl<'a, 'tcx> Eq for ConstantExpr<'a, 'tcx> { fn assert_receiver_is_total_eq(&self) {} } -impl<'a> PartialEq for ConstantExpr<'a> { - fn eq(&self, other: &ConstantExpr<'a>) -> bool { +impl<'a, 'tcx> PartialEq for ConstantExpr<'a, 'tcx> { + fn eq(&self, other: &ConstantExpr<'a, 'tcx>) -> bool { let &ConstantExpr(tcx, expr) = self; let &ConstantExpr(_, other_expr) = other; match const_eval::compare_lit_exprs(tcx, &*expr, &*other_expr) { @@ -244,16 +244,16 @@ impl<'a> PartialEq for ConstantExpr<'a> { // An option identifying a branch (either a literal, an enum variant or a range) #[deriving(Eq, PartialEq)] -enum Opt<'a> { - ConstantValue(ConstantExpr<'a>), - ConstantRange(ConstantExpr<'a>, ConstantExpr<'a>), +enum Opt<'blk, 'tcx: 'blk> { + ConstantValue(ConstantExpr<'blk, 'tcx>), + ConstantRange(ConstantExpr<'blk, 'tcx>, ConstantExpr<'blk, 'tcx>), Variant(ty::Disr, Rc, ast::DefId), SliceLengthEqual(uint), SliceLengthGreaterOrEqual(/* prefix length */ uint, /* suffix length */ uint), } -impl<'a> Opt<'a> { - fn trans(&self, mut bcx: &'a Block<'a>) -> OptResult<'a> { +impl<'blk, 'tcx> Opt<'blk, 'tcx> { + fn trans(&self, mut bcx: Block<'blk, 'tcx>) -> OptResult<'blk, 'tcx> { let _icx = push_ctxt("match::trans_opt"); let ccx = bcx.ccx(); match *self { @@ -293,10 +293,10 @@ pub enum BranchKind { CompareSliceLength } -pub enum OptResult<'a> { - SingleResult(Result<'a>), - RangeResult(Result<'a>, Result<'a>), - LowerBound(Result<'a>) +pub enum OptResult<'blk, 'tcx: 'blk> { + SingleResult(Result<'blk, 'tcx>), + RangeResult(Result<'blk, 'tcx>, Result<'blk, 'tcx>), + LowerBound(Result<'blk, 'tcx>) } #[deriving(Clone)] @@ -325,8 +325,8 @@ pub struct BindingInfo { type BindingsMap = HashMap; -struct ArmData<'a, 'b> { - bodycx: &'b Block<'b>, +struct ArmData<'a, 'blk, 'tcx: 'blk> { + bodycx: Block<'blk, 'tcx>, arm: &'a ast::Arm, bindings_map: BindingsMap } @@ -337,13 +337,13 @@ struct ArmData<'a, 'b> { * As we proceed `bound_ptrs` are filled with pointers to values to be bound, * these pointers are stored in llmatch variables just before executing `data` arm. */ -struct Match<'a, 'b:'a> { +struct Match<'a, 'blk: 'a, 'tcx: 'blk> { pats: Vec>, - data: &'a ArmData<'a, 'b>, + data: &'a ArmData<'a, 'blk, 'tcx>, bound_ptrs: Vec<(Ident, ValueRef)> } -impl<'a, 'b> Repr for Match<'a, 'b> { +impl<'a, 'blk, 'tcx> Repr for Match<'a, 'blk, 'tcx> { fn repr(&self, tcx: &ty::ctxt) -> String { if tcx.sess.verbose() { // for many programs, this just take too long to serialize @@ -364,12 +364,11 @@ fn has_nested_bindings(m: &[Match], col: uint) -> bool { return false; } -fn expand_nested_bindings<'a, 'b>( - bcx: &'b Block<'b>, - m: &'a [Match<'a, 'b>], - col: uint, - val: ValueRef) - -> Vec> { +fn expand_nested_bindings<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + m: &'a [Match<'a, 'blk, 'tcx>], + col: uint, + val: ValueRef) + -> Vec> { debug!("expand_nested_bindings(bcx={}, m={}, col={}, val={})", bcx.to_str(), m.repr(bcx.tcx()), @@ -402,14 +401,13 @@ fn expand_nested_bindings<'a, 'b>( type EnterPatterns<'a> = |&[Gc]|: 'a -> Option>>; -fn enter_match<'a, 'b>( - bcx: &'b Block<'b>, - dm: &DefMap, - m: &'a [Match<'a, 'b>], - col: uint, - val: ValueRef, - e: EnterPatterns) - -> Vec> { +fn enter_match<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + dm: &DefMap, + m: &'a [Match<'a, 'blk, 'tcx>], + col: uint, + val: ValueRef, + e: EnterPatterns) + -> Vec> { debug!("enter_match(bcx={}, m={}, col={}, val={})", bcx.to_str(), m.repr(bcx.tcx()), @@ -450,13 +448,12 @@ fn enter_match<'a, 'b>( }).collect() } -fn enter_default<'a, 'b>( - bcx: &'b Block<'b>, - dm: &DefMap, - m: &'a [Match<'a, 'b>], - col: uint, - val: ValueRef) - -> Vec> { +fn enter_default<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + dm: &DefMap, + m: &'a [Match<'a, 'blk, 'tcx>], + col: uint, + val: ValueRef) + -> Vec> { debug!("enter_default(bcx={}, m={}, col={}, val={})", bcx.to_str(), m.repr(bcx.tcx()), @@ -502,16 +499,16 @@ fn enter_default<'a, 'b>( /// takes the complete row of patterns rather than just the first one. /// Also, most of the enter_() family functions have been unified with /// the check_match specialization step. -fn enter_opt<'a, 'b>( - bcx: &'b Block<'b>, +fn enter_opt<'a, 'blk, 'tcx>( + bcx: Block<'blk, 'tcx>, _: ast::NodeId, dm: &DefMap, - m: &'a [Match<'a, 'b>], + m: &'a [Match<'a, 'blk, 'tcx>], opt: &Opt, col: uint, variant_size: uint, val: ValueRef) - -> Vec> { + -> Vec> { debug!("enter_opt(bcx={}, m={}, opt={:?}, col={}, val={})", bcx.to_str(), m.repr(bcx.tcx()), @@ -545,10 +542,12 @@ fn enter_opt<'a, 'b>( // Returns the options in one column of matches. An option is something that // needs to be conditionally matched at runtime; for example, the discriminant // on a set of enum variants or a literal. -fn get_branches<'a>(bcx: &'a Block, m: &[Match], col: uint) -> Vec> { +fn get_branches<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + m: &[Match], col: uint) + -> Vec> { let ccx = bcx.ccx(); - fn add_to_set<'a>(set: &mut Vec>, opt: Opt<'a>) { + fn add_to_set<'blk, 'tcx>(set: &mut Vec>, opt: Opt<'blk, 'tcx>) { if !set.contains(&opt) { set.push(opt); } @@ -593,17 +592,16 @@ fn get_branches<'a>(bcx: &'a Block, m: &[Match], col: uint) -> Vec> { found } -struct ExtractedBlock<'a> { - vals: Vec , - bcx: &'a Block<'a>, +struct ExtractedBlock<'blk, 'tcx: 'blk> { + vals: Vec, + bcx: Block<'blk, 'tcx>, } -fn extract_variant_args<'a>( - bcx: &'a Block<'a>, - repr: &adt::Repr, - disr_val: ty::Disr, - val: ValueRef) - -> ExtractedBlock<'a> { +fn extract_variant_args<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + repr: &adt::Repr, + disr_val: ty::Disr, + val: ValueRef) + -> ExtractedBlock<'blk, 'tcx> { let _icx = push_ctxt("match::extract_variant_args"); let args = Vec::from_fn(adt::num_args(repr, disr_val), |i| { adt::trans_field_ptr(bcx, repr, val, disr_val, i) @@ -621,12 +619,11 @@ fn match_datum(val: ValueRef, left_ty: ty::t) -> Datum { Datum::new(val, left_ty, Lvalue) } -fn bind_subslice_pat<'a>( - bcx: &'a Block<'a>, - pat_id: ast::NodeId, - val: ValueRef, - offset_left: uint, - offset_right: uint) -> ValueRef { +fn bind_subslice_pat(bcx: Block, + pat_id: ast::NodeId, + val: ValueRef, + offset_left: uint, + offset_right: uint) -> ValueRef { let _icx = push_ctxt("match::bind_subslice_pat"); let vec_ty = node_id_type(bcx, pat_id); let vt = tvec::vec_types(bcx, ty::sequence_element_type(bcx.tcx(), ty::type_content(vec_ty))); @@ -647,13 +644,12 @@ fn bind_subslice_pat<'a>( scratch.val } -fn extract_vec_elems<'a>( - bcx: &'a Block<'a>, - left_ty: ty::t, - before: uint, - after: uint, - val: ValueRef) - -> ExtractedBlock<'a> { +fn extract_vec_elems<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + left_ty: ty::t, + before: uint, + after: uint, + val: ValueRef) + -> ExtractedBlock<'blk, 'tcx> { let _icx = push_ctxt("match::extract_vec_elems"); let vec_datum = match_datum(val, left_ty); let (base, len) = vec_datum.get_vec_base_and_len(bcx); @@ -714,13 +710,13 @@ fn any_irrefutable_adt_pat(tcx: &ty::ctxt, m: &[Match], col: uint) -> bool { } /// What to do when the pattern match fails. -enum FailureHandler<'a> { +enum FailureHandler { Infallible, JumpToBasicBlock(BasicBlockRef), Unreachable } -impl<'a> FailureHandler<'a> { +impl FailureHandler { fn is_fallible(&self) -> bool { match *self { Infallible => false, @@ -732,7 +728,7 @@ impl<'a> FailureHandler<'a> { !self.is_fallible() } - fn handle_fail(&self, bcx: &Block) { + fn handle_fail(&self, bcx: Block) { match *self { Infallible => fail!("attempted to fail in an infallible failure handler!"), @@ -774,17 +770,16 @@ fn pick_col(m: &[Match]) -> uint { } // Compiles a comparison between two things. -fn compare_values<'a>( - cx: &'a Block<'a>, - lhs: ValueRef, - rhs: ValueRef, - rhs_t: ty::t) - -> Result<'a> { - fn compare_str<'a>(cx: &'a Block<'a>, - lhs: ValueRef, - rhs: ValueRef, - rhs_t: ty::t) - -> Result<'a> { +fn compare_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>, + lhs: ValueRef, + rhs: ValueRef, + rhs_t: ty::t) + -> Result<'blk, 'tcx> { + fn compare_str<'blk, 'tcx>(cx: Block<'blk, 'tcx>, + lhs: ValueRef, + rhs: ValueRef, + rhs_t: ty::t) + -> Result<'blk, 'tcx> { let did = langcall(cx, None, format!("comparison of `{}`", @@ -819,9 +814,10 @@ fn compare_values<'a>( } } -fn insert_lllocals<'a>(mut bcx: &'a Block<'a>, bindings_map: &BindingsMap, - cs: Option) - -> &'a Block<'a> { +fn insert_lllocals<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, + bindings_map: &BindingsMap, + cs: Option) + -> Block<'blk, 'tcx> { /*! * For each binding in `data.bindings_map`, adds an appropriate entry into * the `fcx.lllocals` map @@ -874,15 +870,14 @@ fn insert_lllocals<'a>(mut bcx: &'a Block<'a>, bindings_map: &BindingsMap, bcx } -fn compile_guard<'a, 'b>( - bcx: &'b Block<'b>, - guard_expr: &ast::Expr, - data: &ArmData, - m: &'a [Match<'a, 'b>], - vals: &[ValueRef], - chk: &FailureHandler, - has_genuine_default: bool) - -> &'b Block<'b> { +fn compile_guard<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + guard_expr: &ast::Expr, + data: &ArmData, + m: &'a [Match<'a, 'blk, 'tcx>], + vals: &[ValueRef], + chk: &FailureHandler, + has_genuine_default: bool) + -> Block<'blk, 'tcx> { debug!("compile_guard(bcx={}, guard_expr={}, m={}, vals={})", bcx.to_str(), bcx.expr_to_string(guard_expr), @@ -923,12 +918,11 @@ fn compile_guard<'a, 'b>( }) } -fn compile_submatch<'a, 'b>( - bcx: &'b Block<'b>, - m: &'a [Match<'a, 'b>], - vals: &[ValueRef], - chk: &FailureHandler, - has_genuine_default: bool) { +fn compile_submatch<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + m: &'a [Match<'a, 'blk, 'tcx>], + vals: &[ValueRef], + chk: &FailureHandler, + has_genuine_default: bool) { debug!("compile_submatch(bcx={}, m={}, vals={})", bcx.to_str(), m.repr(bcx.tcx()), @@ -984,14 +978,13 @@ fn compile_submatch<'a, 'b>( } } -fn compile_submatch_continue<'a, 'b>( - mut bcx: &'b Block<'b>, - m: &'a [Match<'a, 'b>], - vals: &[ValueRef], - chk: &FailureHandler, - col: uint, - val: ValueRef, - has_genuine_default: bool) { +fn compile_submatch_continue<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, + m: &'a [Match<'a, 'blk, 'tcx>], + vals: &[ValueRef], + chk: &FailureHandler, + col: uint, + val: ValueRef, + has_genuine_default: bool) { let fcx = bcx.fcx; let tcx = bcx.tcx(); let dm = &tcx.def_map; @@ -1218,19 +1211,18 @@ fn compile_submatch_continue<'a, 'b>( } } -pub fn trans_match<'a>( - bcx: &'a Block<'a>, - match_expr: &ast::Expr, - discr_expr: &ast::Expr, - arms: &[ast::Arm], - dest: Dest) - -> &'a Block<'a> { +pub fn trans_match<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + match_expr: &ast::Expr, + discr_expr: &ast::Expr, + arms: &[ast::Arm], + dest: Dest) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("match::trans_match"); trans_match_inner(bcx, match_expr.id, discr_expr, arms, dest) } /// Checks whether the binding in `discr` is assigned to anywhere in the expression `body` -fn is_discr_reassigned(bcx: &Block, discr: &ast::Expr, body: &ast::Expr) -> bool { +fn is_discr_reassigned(bcx: Block, discr: &ast::Expr, body: &ast::Expr) -> bool { match discr.node { ast::ExprPath(..) => match bcx.def(discr.id) { def::DefArg(vid, _) | def::DefBinding(vid, _) | @@ -1272,7 +1264,7 @@ impl euv::Delegate for ReassignmentChecker { } } -fn create_bindings_map(bcx: &Block, pat: Gc, +fn create_bindings_map(bcx: Block, pat: Gc, discr: &ast::Expr, body: &ast::Expr) -> BindingsMap { // Create the bindings map, which is a mapping from each binding name // to an alloca() that will be the value for that local variable. @@ -1327,11 +1319,11 @@ fn create_bindings_map(bcx: &Block, pat: Gc, return bindings_map; } -fn trans_match_inner<'a>(scope_cx: &'a Block<'a>, - match_id: ast::NodeId, - discr_expr: &ast::Expr, - arms: &[ast::Arm], - dest: Dest) -> &'a Block<'a> { +fn trans_match_inner<'blk, 'tcx>(scope_cx: Block<'blk, 'tcx>, + match_id: ast::NodeId, + discr_expr: &ast::Expr, + arms: &[ast::Arm], + dest: Dest) -> Block<'blk, 'tcx> { let _icx = push_ctxt("match::trans_match_inner"); let fcx = scope_cx.fcx; let mut bcx = scope_cx; @@ -1402,9 +1394,9 @@ enum IrrefutablePatternBindingMode { BindArgument } -pub fn store_local<'a>(bcx: &'a Block<'a>, - local: &ast::Local) - -> &'a Block<'a> { +pub fn store_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + local: &ast::Local) + -> Block<'blk, 'tcx> { /*! * Generates code for a local variable declaration like * `let ;` or `let = `. @@ -1457,9 +1449,9 @@ pub fn store_local<'a>(bcx: &'a Block<'a>, } }; - fn create_dummy_locals<'a>(mut bcx: &'a Block<'a>, - pat: Gc) - -> &'a Block<'a> { + fn create_dummy_locals<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, + pat: Gc) + -> Block<'blk, 'tcx> { // create dummy memory for the variables if we have no // value to store into them immediately let tcx = bcx.tcx(); @@ -1473,11 +1465,11 @@ pub fn store_local<'a>(bcx: &'a Block<'a>, } } -pub fn store_arg<'a>(mut bcx: &'a Block<'a>, - pat: Gc, - arg: Datum, - arg_scope: cleanup::ScopeId) - -> &'a Block<'a> { +pub fn store_arg<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, + pat: Gc, + arg: Datum, + arg_scope: cleanup::ScopeId) + -> Block<'blk, 'tcx> { /*! * Generates code for argument patterns like `fn foo(: T)`. * Creates entries in the `llargs` map for each of the bindings @@ -1527,12 +1519,11 @@ pub fn store_arg<'a>(mut bcx: &'a Block<'a>, /// Generates code for the pattern binding in a `for` loop like /// `for in { ... }`. -pub fn store_for_loop_binding<'a>( - bcx: &'a Block<'a>, - pat: Gc, - llvalue: ValueRef, - body_scope: cleanup::ScopeId) - -> &'a Block<'a> { +pub fn store_for_loop_binding<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + pat: Gc, + llvalue: ValueRef, + body_scope: cleanup::ScopeId) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("match::store_for_loop_binding"); if simple_identifier(&*pat).is_some() { @@ -1550,14 +1541,15 @@ pub fn store_for_loop_binding<'a>( bind_irrefutable_pat(bcx, pat, llvalue, BindLocal, body_scope) } -fn mk_binding_alloca<'a,A>(bcx: &'a Block<'a>, - p_id: ast::NodeId, - ident: &ast::Ident, - binding_mode: IrrefutablePatternBindingMode, - cleanup_scope: cleanup::ScopeId, - arg: A, - populate: |A, &'a Block<'a>, ValueRef, ty::t| -> &'a Block<'a>) - -> &'a Block<'a> { +fn mk_binding_alloca<'blk, 'tcx, A>(bcx: Block<'blk, 'tcx>, + p_id: ast::NodeId, + ident: &ast::Ident, + binding_mode: IrrefutablePatternBindingMode, + cleanup_scope: cleanup::ScopeId, + arg: A, + populate: |A, Block<'blk, 'tcx>, ValueRef, ty::t| + -> Block<'blk, 'tcx>) + -> Block<'blk, 'tcx> { let var_ty = node_id_type(bcx, p_id); // Allocate memory on stack for the binding. @@ -1580,13 +1572,12 @@ fn mk_binding_alloca<'a,A>(bcx: &'a Block<'a>, bcx } -fn bind_irrefutable_pat<'a>( - bcx: &'a Block<'a>, - pat: Gc, - val: ValueRef, - binding_mode: IrrefutablePatternBindingMode, - cleanup_scope: cleanup::ScopeId) - -> &'a Block<'a> { +fn bind_irrefutable_pat<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + pat: Gc, + val: ValueRef, + binding_mode: IrrefutablePatternBindingMode, + cleanup_scope: cleanup::ScopeId) + -> Block<'blk, 'tcx> { /*! * A simple version of the pattern matching code that only handles * irrefutable patterns. This is used in let/argument patterns, diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs index 21673a67ea8ac..e62e3563a0a2c 100644 --- a/src/librustc/middle/trans/adt.rs +++ b/src/librustc/middle/trans/adt.rs @@ -143,7 +143,7 @@ pub struct Struct { * these, for places in trans where the `ty::t` isn't directly * available. */ -pub fn represent_node(bcx: &Block, node: ast::NodeId) -> Rc { +pub fn represent_node(bcx: Block, node: ast::NodeId) -> Rc { represent_type(bcx.ccx(), node_id_type(bcx, node)) } @@ -574,7 +574,7 @@ fn struct_llfields(cx: &CrateContext, st: &Struct, sizing: bool, dst: bool) -> V * * This should ideally be less tightly tied to `_match`. */ -pub fn trans_switch(bcx: &Block, r: &Repr, scrutinee: ValueRef) +pub fn trans_switch(bcx: Block, r: &Repr, scrutinee: ValueRef) -> (_match::BranchKind, Option) { match *r { CEnum(..) | General(..) | @@ -590,7 +590,7 @@ pub fn trans_switch(bcx: &Block, r: &Repr, scrutinee: ValueRef) /// Obtain the actual discriminant of a value. -pub fn trans_get_discr(bcx: &Block, r: &Repr, scrutinee: ValueRef, cast_to: Option) +pub fn trans_get_discr(bcx: Block, r: &Repr, scrutinee: ValueRef, cast_to: Option) -> ValueRef { let signed; let val; @@ -625,7 +625,7 @@ pub fn trans_get_discr(bcx: &Block, r: &Repr, scrutinee: ValueRef, cast_to: Opti } } -fn struct_wrapped_nullable_bitdiscr(bcx: &Block, nndiscr: Disr, ptrfield: PointerField, +fn struct_wrapped_nullable_bitdiscr(bcx: Block, nndiscr: Disr, ptrfield: PointerField, scrutinee: ValueRef) -> ValueRef { let llptrptr = match ptrfield { ThinPointer(field) => GEPi(bcx, scrutinee, [0, field]), @@ -637,7 +637,7 @@ fn struct_wrapped_nullable_bitdiscr(bcx: &Block, nndiscr: Disr, ptrfield: Pointe } /// Helper for cases where the discriminant is simply loaded. -fn load_discr(bcx: &Block, ity: IntType, ptr: ValueRef, min: Disr, max: Disr) +fn load_discr(bcx: Block, ity: IntType, ptr: ValueRef, min: Disr, max: Disr) -> ValueRef { let llty = ll_inttype(bcx.ccx(), ity); assert_eq!(val_ty(ptr), llty.ptr_to()); @@ -666,8 +666,8 @@ fn load_discr(bcx: &Block, ity: IntType, ptr: ValueRef, min: Disr, max: Disr) * * This should ideally be less tightly tied to `_match`. */ -pub fn trans_case<'a>(bcx: &'a Block<'a>, r: &Repr, discr: Disr) - -> _match::OptResult<'a> { +pub fn trans_case<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr, discr: Disr) + -> _match::OptResult<'blk, 'tcx> { match *r { CEnum(ity, _, _) => { _match::SingleResult(Result::new(bcx, C_integral(ll_inttype(bcx.ccx(), ity), @@ -692,7 +692,7 @@ pub fn trans_case<'a>(bcx: &'a Block<'a>, r: &Repr, discr: Disr) * Set the discriminant for a new value of the given case of the given * representation. */ -pub fn trans_set_discr(bcx: &Block, r: &Repr, val: ValueRef, discr: Disr) { +pub fn trans_set_discr(bcx: Block, r: &Repr, val: ValueRef, discr: Disr) { match *r { CEnum(ity, min, max) => { assert_discr_in_range(ity, min, max, discr); @@ -770,7 +770,7 @@ pub fn num_args(r: &Repr, discr: Disr) -> uint { } /// Access a field, at a point when the value's case is known. -pub fn trans_field_ptr(bcx: &Block, r: &Repr, val: ValueRef, discr: Disr, +pub fn trans_field_ptr(bcx: Block, r: &Repr, val: ValueRef, discr: Disr, ix: uint) -> ValueRef { // Note: if this ever needs to generate conditionals (e.g., if we // decide to do some kind of cdr-coding-like non-unique repr @@ -809,7 +809,7 @@ pub fn trans_field_ptr(bcx: &Block, r: &Repr, val: ValueRef, discr: Disr, } } -pub fn struct_field_ptr(bcx: &Block, st: &Struct, val: ValueRef, +pub fn struct_field_ptr(bcx: Block, st: &Struct, val: ValueRef, ix: uint, needs_cast: bool) -> ValueRef { let val = if needs_cast { let ccx = bcx.ccx(); @@ -823,10 +823,10 @@ pub fn struct_field_ptr(bcx: &Block, st: &Struct, val: ValueRef, GEPi(bcx, val, [0, ix]) } -pub fn fold_variants<'r, 'b>( - bcx: &'b Block<'b>, r: &Repr, value: ValueRef, - f: |&'b Block<'b>, &Struct, ValueRef|: 'r -> &'b Block<'b> -) -> &'b Block<'b> { +pub fn fold_variants<'blk, 'tcx>( + bcx: Block<'blk, 'tcx>, r: &Repr, value: ValueRef, + f: |Block<'blk, 'tcx>, &Struct, ValueRef| -> Block<'blk, 'tcx>) + -> Block<'blk, 'tcx> { let fcx = bcx.fcx; match *r { Univariant(ref st, _) => { @@ -864,8 +864,8 @@ pub fn fold_variants<'r, 'b>( } /// Access the struct drop flag, if present. -pub fn trans_drop_flag_ptr<'b>(mut bcx: &'b Block<'b>, r: &Repr, - val: ValueRef) -> datum::DatumBlock<'b, datum::Expr> { +pub fn trans_drop_flag_ptr<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, r: &Repr, val: ValueRef) + -> datum::DatumBlock<'blk, 'tcx, datum::Expr> { let ptr_ty = ty::mk_imm_ptr(bcx.tcx(), ty::mk_bool()); match *r { Univariant(ref st, true) => { diff --git a/src/librustc/middle/trans/asm.rs b/src/librustc/middle/trans/asm.rs index be5f586bb97fe..7fb692c270ee3 100644 --- a/src/librustc/middle/trans/asm.rs +++ b/src/librustc/middle/trans/asm.rs @@ -27,8 +27,8 @@ use std::string::String; use syntax::ast; // Take an inline assembly expression and splat it out via LLVM -pub fn trans_inline_asm<'a>(bcx: &'a Block<'a>, ia: &ast::InlineAsm) - -> &'a Block<'a> { +pub fn trans_inline_asm<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ia: &ast::InlineAsm) + -> Block<'blk, 'tcx> { let fcx = bcx.fcx; let mut bcx = bcx; let mut constraints = Vec::new(); diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 30f50067bdd8e..dc2aa16eb7284 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -137,15 +137,16 @@ pub fn push_ctxt(s: &'static str) -> _InsnCtxt { _InsnCtxt { _cannot_construct_outside_of_this_module: () } } -pub struct StatRecorder<'a> { - ccx: &'a CrateContext<'a>, +pub struct StatRecorder<'a, 'tcx: 'a> { + ccx: &'a CrateContext<'a, 'tcx>, name: Option, start: u64, istart: uint, } -impl<'a> StatRecorder<'a> { - pub fn new(ccx: &'a CrateContext, name: String) -> StatRecorder<'a> { +impl<'a, 'tcx> StatRecorder<'a, 'tcx> { + pub fn new(ccx: &'a CrateContext<'a, 'tcx>, name: String) + -> StatRecorder<'a, 'tcx> { let start = if ccx.sess().trans_stats() { time::precise_time_ns() } else { @@ -162,7 +163,7 @@ impl<'a> StatRecorder<'a> { } #[unsafe_destructor] -impl<'a> Drop for StatRecorder<'a> { +impl<'a, 'tcx> Drop for StatRecorder<'a, 'tcx> { fn drop(&mut self) { if self.ccx.sess().trans_stats() { let end = time::precise_time_ns(); @@ -343,7 +344,7 @@ pub fn get_extern_const(externs: &mut ExternMap, llmod: ModuleRef, // Returns a pointer to the body for the box. The box may be an opaque // box. The result will be casted to the type of body_t, if it is statically // known. -pub fn at_box_body(bcx: &Block, body_t: ty::t, boxptr: ValueRef) -> ValueRef { +pub fn at_box_body(bcx: Block, body_t: ty::t, boxptr: ValueRef) -> ValueRef { let _icx = push_ctxt("at_box_body"); let ccx = bcx.ccx(); let ty = Type::at_box(ccx, type_of(ccx, body_t)); @@ -351,7 +352,7 @@ pub fn at_box_body(bcx: &Block, body_t: ty::t, boxptr: ValueRef) -> ValueRef { GEPi(bcx, boxptr, [0u, abi::box_field_body]) } -fn require_alloc_fn(bcx: &Block, info_ty: ty::t, it: LangItem) -> ast::DefId { +fn require_alloc_fn(bcx: Block, info_ty: ty::t, it: LangItem) -> ast::DefId { match bcx.tcx().lang_items.require(it) { Ok(id) => id, Err(s) => { @@ -365,12 +366,12 @@ fn require_alloc_fn(bcx: &Block, info_ty: ty::t, it: LangItem) -> ast::DefId { // The following malloc_raw_dyn* functions allocate a box to contain // a given type, but with a potentially dynamic size. -pub fn malloc_raw_dyn<'a>(bcx: &'a Block<'a>, - llty_ptr: Type, - info_ty: ty::t, - size: ValueRef, - align: ValueRef) - -> Result<'a> { +pub fn malloc_raw_dyn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + llty_ptr: Type, + info_ty: ty::t, + size: ValueRef, + align: ValueRef) + -> Result<'blk, 'tcx> { let _icx = push_ctxt("malloc_raw_exchange"); // Allocate space: @@ -382,9 +383,9 @@ pub fn malloc_raw_dyn<'a>(bcx: &'a Block<'a>, Result::new(r.bcx, PointerCast(r.bcx, r.val, llty_ptr)) } -pub fn malloc_raw_dyn_proc<'a>( - bcx: &'a Block<'a>, - t: ty::t, alloc_fn: LangItem) -> Result<'a> { +pub fn malloc_raw_dyn_proc<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + t: ty::t, alloc_fn: LangItem) + -> Result<'blk, 'tcx> { let _icx = push_ctxt("malloc_raw_dyn_proc"); let ccx = bcx.ccx(); @@ -413,12 +414,11 @@ pub fn malloc_raw_dyn_proc<'a>( } -pub fn malloc_raw_dyn_managed<'a>( - bcx: &'a Block<'a>, - t: ty::t, - alloc_fn: LangItem, - size: ValueRef) - -> Result<'a> { +pub fn malloc_raw_dyn_managed<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + t: ty::t, + alloc_fn: LangItem, + size: ValueRef) + -> Result<'blk, 'tcx> { let _icx = push_ctxt("malloc_raw_dyn_managed"); let ccx = bcx.ccx(); @@ -584,13 +584,12 @@ pub fn maybe_name_value(cx: &CrateContext, v: ValueRef, s: &str) { // Used only for creating scalar comparison glue. pub enum scalar_type { nil_type, signed_int, unsigned_int, floating_point, } -pub fn compare_scalar_types<'a>( - cx: &'a Block<'a>, - lhs: ValueRef, - rhs: ValueRef, - t: ty::t, - op: ast::BinOp) - -> Result<'a> { +pub fn compare_scalar_types<'blk, 'tcx>(cx: Block<'blk, 'tcx>, + lhs: ValueRef, + rhs: ValueRef, + t: ty::t, + op: ast::BinOp) + -> Result<'blk, 'tcx> { let f = |a| Result::new(cx, compare_scalar_values(cx, lhs, rhs, a, op)); match ty::get(t).sty { @@ -606,15 +605,14 @@ pub fn compare_scalar_types<'a>( // A helper function to do the actual comparison of scalar values. -pub fn compare_scalar_values<'a>( - cx: &'a Block<'a>, - lhs: ValueRef, - rhs: ValueRef, - nt: scalar_type, - op: ast::BinOp) - -> ValueRef { +pub fn compare_scalar_values<'blk, 'tcx>(cx: Block<'blk, 'tcx>, + lhs: ValueRef, + rhs: ValueRef, + nt: scalar_type, + op: ast::BinOp) + -> ValueRef { let _icx = push_ctxt("compare_scalar_values"); - fn die(cx: &Block) -> ! { + fn die(cx: Block) -> ! { cx.sess().bug("compare_scalar_values: must be a comparison operator"); } match nt { @@ -668,7 +666,7 @@ pub fn compare_scalar_values<'a>( } pub fn compare_simd_types( - cx: &Block, + cx: Block, lhs: ValueRef, rhs: ValueRef, t: ty::t, @@ -705,28 +703,24 @@ pub fn compare_simd_types( } } -pub type val_and_ty_fn<'r,'b> = - |&'b Block<'b>, ValueRef, ty::t|: 'r -> &'b Block<'b>; +pub type val_and_ty_fn<'a, 'blk, 'tcx> = + |Block<'blk, 'tcx>, ValueRef, ty::t|: 'a -> Block<'blk, 'tcx>; // Iterates through the elements of a structural type. -pub fn iter_structural_ty<'r, - 'b>( - cx: &'b Block<'b>, - av: ValueRef, - t: ty::t, - f: val_and_ty_fn<'r,'b>) - -> &'b Block<'b> { +pub fn iter_structural_ty<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>, + av: ValueRef, + t: ty::t, + f: val_and_ty_fn<'a, 'blk, 'tcx>) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("iter_structural_ty"); - fn iter_variant<'r, - 'b>( - cx: &'b Block<'b>, - repr: &adt::Repr, - av: ValueRef, - variant: &ty::VariantInfo, - substs: &subst::Substs, - f: val_and_ty_fn<'r,'b>) - -> &'b Block<'b> { + fn iter_variant<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>, + repr: &adt::Repr, + av: ValueRef, + variant: &ty::VariantInfo, + substs: &subst::Substs, + f: val_and_ty_fn<'a, 'blk, 'tcx>) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("iter_variant"); let tcx = cx.tcx(); let mut cx = cx; @@ -846,8 +840,7 @@ pub fn iter_structural_ty<'r, return cx; } -pub fn cast_shift_expr_rhs<'a>( - cx: &'a Block<'a>, +pub fn cast_shift_expr_rhs(cx: Block, op: ast::BinOp, lhs: ValueRef, rhs: ValueRef) @@ -894,14 +887,14 @@ pub fn cast_shift_rhs(op: ast::BinOp, } } -pub fn fail_if_zero_or_overflows<'a>( - cx: &'a Block<'a>, - span: Span, - divrem: ast::BinOp, - lhs: ValueRef, - rhs: ValueRef, - rhs_t: ty::t) - -> &'a Block<'a> { +pub fn fail_if_zero_or_overflows<'blk, 'tcx>( + cx: Block<'blk, 'tcx>, + span: Span, + divrem: ast::BinOp, + lhs: ValueRef, + rhs: ValueRef, + rhs_t: ty::t) + -> Block<'blk, 'tcx> { let (zero_text, overflow_text) = if divrem == ast::BiDiv { ("attempted to divide by zero", "attempted to divide with overflow") @@ -998,16 +991,15 @@ pub fn trans_external_path(ccx: &CrateContext, did: ast::DefId, t: ty::t) -> Val } } -pub fn invoke<'a>( - bcx: &'a Block<'a>, - llfn: ValueRef, - llargs: Vec , - fn_ty: ty::t, - call_info: Option, - // FIXME(15064) is_lang_item is a horrible hack, please remove it - // at the soonest opportunity. - is_lang_item: bool) - -> (ValueRef, &'a Block<'a>) { +pub fn invoke<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + llfn: ValueRef, + llargs: Vec , + fn_ty: ty::t, + call_info: Option, + // FIXME(15064) is_lang_item is a horrible hack, please remove it + // at the soonest opportunity. + is_lang_item: bool) + -> (ValueRef, Block<'blk, 'tcx>) { let _icx = push_ctxt("invoke_"); if bcx.unreachable.get() { return (C_null(Type::i8(bcx.ccx())), bcx); @@ -1066,7 +1058,7 @@ pub fn invoke<'a>( } } -pub fn need_invoke(bcx: &Block) -> bool { +pub fn need_invoke(bcx: Block) -> bool { if bcx.sess().no_landing_pads() { return false; } @@ -1079,13 +1071,13 @@ pub fn need_invoke(bcx: &Block) -> bool { bcx.fcx.needs_invoke() } -pub fn load_if_immediate(cx: &Block, v: ValueRef, t: ty::t) -> ValueRef { +pub fn load_if_immediate(cx: Block, v: ValueRef, t: ty::t) -> ValueRef { let _icx = push_ctxt("load_if_immediate"); if type_is_immediate(cx.ccx(), t) { return load_ty(cx, v, t); } return v; } -pub fn load_ty(cx: &Block, ptr: ValueRef, t: ty::t) -> ValueRef { +pub fn load_ty(cx: Block, ptr: ValueRef, t: ty::t) -> ValueRef { /*! * Helper for loading values from memory. Does the necessary conversion if * the in-memory type differs from the type used for SSA values. Also @@ -1105,7 +1097,7 @@ pub fn load_ty(cx: &Block, ptr: ValueRef, t: ty::t) -> ValueRef { } } -pub fn store_ty(cx: &Block, v: ValueRef, dst: ValueRef, t: ty::t) { +pub fn store_ty(cx: Block, v: ValueRef, dst: ValueRef, t: ty::t) { /*! * Helper for storing values in memory. Does the necessary conversion if * the in-memory type differs from the type used for SSA values. @@ -1117,33 +1109,31 @@ pub fn store_ty(cx: &Block, v: ValueRef, dst: ValueRef, t: ty::t) { }; } -pub fn ignore_lhs(_bcx: &Block, local: &ast::Local) -> bool { +pub fn ignore_lhs(_bcx: Block, local: &ast::Local) -> bool { match local.pat.node { ast::PatWild(ast::PatWildSingle) => true, _ => false } } -pub fn init_local<'a>(bcx: &'a Block<'a>, local: &ast::Local) - -> &'a Block<'a> { +pub fn init_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, local: &ast::Local) + -> Block<'blk, 'tcx> { debug!("init_local(bcx={}, local.id={:?})", bcx.to_str(), local.id); let _indenter = indenter(); let _icx = push_ctxt("init_local"); _match::store_local(bcx, local) } -pub fn raw_block<'a>( - fcx: &'a FunctionContext<'a>, - is_lpad: bool, - llbb: BasicBlockRef) - -> &'a Block<'a> { - common::Block::new(llbb, is_lpad, None, fcx) +pub fn raw_block<'blk, 'tcx>(fcx: &'blk FunctionContext<'blk, 'tcx>, + is_lpad: bool, + llbb: BasicBlockRef) + -> Block<'blk, 'tcx> { + common::BlockS::new(llbb, is_lpad, None, fcx) } -pub fn with_cond<'a>( - bcx: &'a Block<'a>, - val: ValueRef, - f: |&'a Block<'a>| -> &'a Block<'a>) - -> &'a Block<'a> { +pub fn with_cond<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + val: ValueRef, + f: |Block<'blk, 'tcx>| -> Block<'blk, 'tcx>) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("with_cond"); let fcx = bcx.fcx; let next_cx = fcx.new_temp_block("next"); @@ -1156,7 +1146,7 @@ pub fn with_cond<'a>( next_cx } -pub fn call_lifetime_start(cx: &Block, ptr: ValueRef) { +pub fn call_lifetime_start(cx: Block, ptr: ValueRef) { if cx.sess().opts.optimize == config::No { return; } @@ -1170,7 +1160,7 @@ pub fn call_lifetime_start(cx: &Block, ptr: ValueRef) { Call(cx, lifetime_start, [llsize, ptr], None); } -pub fn call_lifetime_end(cx: &Block, ptr: ValueRef) { +pub fn call_lifetime_end(cx: Block, ptr: ValueRef) { if cx.sess().opts.optimize == config::No { return; } @@ -1184,7 +1174,7 @@ pub fn call_lifetime_end(cx: &Block, ptr: ValueRef) { Call(cx, lifetime_end, [llsize, ptr], None); } -pub fn call_memcpy(cx: &Block, dst: ValueRef, src: ValueRef, n_bytes: ValueRef, align: u32) { +pub fn call_memcpy(cx: 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 { @@ -1200,7 +1190,7 @@ pub fn call_memcpy(cx: &Block, dst: ValueRef, src: ValueRef, n_bytes: ValueRef, Call(cx, memcpy, [dst_ptr, src_ptr, size, align, volatile], None); } -pub fn memcpy_ty(bcx: &Block, dst: ValueRef, src: ValueRef, t: ty::t) { +pub fn memcpy_ty(bcx: Block, dst: ValueRef, src: ValueRef, t: ty::t) { let _icx = push_ctxt("memcpy_ty"); let ccx = bcx.ccx(); if ty::type_is_structural(t) { @@ -1213,7 +1203,7 @@ pub fn memcpy_ty(bcx: &Block, dst: ValueRef, src: ValueRef, t: ty::t) { } } -pub fn zero_mem(cx: &Block, llptr: ValueRef, t: ty::t) { +pub fn zero_mem(cx: Block, llptr: ValueRef, t: ty::t) { if cx.unreachable.get() { return; } let _icx = push_ctxt("zero_mem"); let bcx = cx; @@ -1245,7 +1235,7 @@ fn memzero(b: &Builder, llptr: ValueRef, ty: ty::t) { b.call(llintrinsicfn, [llptr, llzeroval, size, align, volatile], None); } -pub fn alloc_ty(bcx: &Block, t: ty::t, name: &str) -> ValueRef { +pub fn alloc_ty(bcx: Block, t: ty::t, name: &str) -> ValueRef { let _icx = push_ctxt("alloc_ty"); let ccx = bcx.ccx(); let ty = type_of::type_of(ccx, t); @@ -1254,13 +1244,13 @@ pub fn alloc_ty(bcx: &Block, t: ty::t, name: &str) -> ValueRef { return val; } -pub fn alloca(cx: &Block, ty: Type, name: &str) -> ValueRef { +pub fn alloca(cx: Block, ty: Type, name: &str) -> ValueRef { let p = alloca_no_lifetime(cx, ty, name); call_lifetime_start(cx, p); p } -pub fn alloca_no_lifetime(cx: &Block, ty: Type, name: &str) -> ValueRef { +pub fn alloca_no_lifetime(cx: Block, ty: Type, name: &str) -> ValueRef { let _icx = push_ctxt("alloca"); if cx.unreachable.get() { unsafe { @@ -1271,7 +1261,7 @@ pub fn alloca_no_lifetime(cx: &Block, ty: Type, name: &str) -> ValueRef { Alloca(cx, ty, name) } -pub fn alloca_zeroed(cx: &Block, ty: ty::t, name: &str) -> ValueRef { +pub fn alloca_zeroed(cx: Block, ty: ty::t, name: &str) -> ValueRef { let llty = type_of::type_of(cx.ccx(), ty); if cx.unreachable.get() { unsafe { @@ -1285,7 +1275,7 @@ pub fn alloca_zeroed(cx: &Block, ty: ty::t, name: &str) -> ValueRef { p } -pub fn arrayalloca(cx: &Block, ty: Type, v: ValueRef) -> ValueRef { +pub fn arrayalloca(cx: Block, ty: Type, v: ValueRef) -> ValueRef { let _icx = push_ctxt("arrayalloca"); if cx.unreachable.get() { unsafe { @@ -1440,15 +1430,15 @@ fn has_nested_returns(tcx: &ty::ctxt, id: ast::NodeId) -> bool { // // Be warned! You must call `init_function` before doing anything with the // returned function context. -pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext, - llfndecl: ValueRef, - id: ast::NodeId, - has_env: bool, - output_type: ty::t, - param_substs: &'a param_substs, - sp: Option, - block_arena: &'a TypedArena>) - -> FunctionContext<'a> { +pub fn new_fn_ctxt<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>, + llfndecl: ValueRef, + id: ast::NodeId, + has_env: bool, + output_type: ty::t, + param_substs: &'a param_substs, + sp: Option, + block_arena: &'a TypedArena>) + -> FunctionContext<'a, 'tcx> { param_substs.validate(); debug!("new_fn_ctxt(path={}, id={}, param_substs={})", @@ -1494,9 +1484,9 @@ pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext, /// Performs setup on a newly created function, creating the entry scope block /// and allocating space for the return pointer. -pub fn init_function<'a>(fcx: &'a FunctionContext<'a>, - skip_retptr: bool, - output_type: ty::t) -> &'a Block<'a> { +pub fn init_function<'a, 'tcx>(fcx: &'a FunctionContext<'a, 'tcx>, + skip_retptr: bool, + output_type: ty::t) -> Block<'a, 'tcx> { let entry_bcx = fcx.new_temp_block("entry-block"); // Use a dummy instruction as the insertion point for all allocas. @@ -1564,9 +1554,8 @@ pub fn create_datums_for_fn_args(fcx: &FunctionContext, /// datums. /// /// FIXME(pcwalton): Reduce the amount of code bloat this is responsible for. -fn create_datums_for_fn_args_under_call_abi< - 'a>( - mut bcx: &'a Block<'a>, +fn create_datums_for_fn_args_under_call_abi( + mut bcx: Block, arg_scope: cleanup::CustomScopeIndex, arg_tys: &[ty::t]) -> Vec { @@ -1632,12 +1621,12 @@ fn create_datums_for_fn_args_under_call_abi< result } -fn copy_args_to_allocas<'a>(fcx: &FunctionContext<'a>, - arg_scope: cleanup::CustomScopeIndex, - bcx: &'a Block<'a>, - args: &[ast::Arg], - arg_datums: Vec ) - -> &'a Block<'a> { +fn copy_args_to_allocas<'blk, 'tcx>(fcx: &FunctionContext<'blk, 'tcx>, + arg_scope: cleanup::CustomScopeIndex, + bcx: Block<'blk, 'tcx>, + args: &[ast::Arg], + arg_datums: Vec ) + -> Block<'blk, 'tcx> { debug!("copy_args_to_allocas"); let _icx = push_ctxt("copy_args_to_allocas"); @@ -1664,13 +1653,13 @@ fn copy_args_to_allocas<'a>(fcx: &FunctionContext<'a>, bcx } -fn copy_unboxed_closure_args_to_allocas<'a>( - mut bcx: &'a Block<'a>, +fn copy_unboxed_closure_args_to_allocas<'blk, 'tcx>( + mut bcx: Block<'blk, 'tcx>, arg_scope: cleanup::CustomScopeIndex, args: &[ast::Arg], arg_datums: Vec, monomorphized_arg_types: &[ty::t]) - -> &'a Block<'a> { + -> Block<'blk, 'tcx> { let _icx = push_ctxt("copy_unboxed_closure_args_to_allocas"); let arg_scope_id = cleanup::CustomScope(arg_scope); @@ -1720,9 +1709,9 @@ fn copy_unboxed_closure_args_to_allocas<'a>( // Ties up the llstaticallocas -> llloadenv -> lltop edges, // and builds the return block. -pub fn finish_fn<'a>(fcx: &'a FunctionContext<'a>, - last_bcx: &'a Block<'a>, - retty: ty::t) { +pub fn finish_fn<'blk, 'tcx>(fcx: &'blk FunctionContext<'blk, 'tcx>, + last_bcx: Block<'blk, 'tcx>, + retty: ty::t) { let _icx = push_ctxt("finish_fn"); // This shouldn't need to recompute the return type, @@ -1744,7 +1733,7 @@ pub fn finish_fn<'a>(fcx: &'a FunctionContext<'a>, } // Builds the return block for a function. -pub fn build_return_block(fcx: &FunctionContext, ret_cx: &Block, retty: ty::t) { +pub fn build_return_block(fcx: &FunctionContext, ret_cx: Block, retty: ty::t) { if fcx.llretslotptr.get().is_none() || (!fcx.needs_ret_allocas && fcx.caller_expects_out_pointer) { return RetVoid(ret_cx); @@ -1813,8 +1802,8 @@ pub fn trans_closure(ccx: &CrateContext, abi: Abi, has_env: bool, is_unboxed_closure: IsUnboxedClosureFlag, - maybe_load_env: <'a>|&'a Block<'a>, ScopeId| - -> &'a Block<'a>) { + maybe_load_env: <'blk, 'tcx> |Block<'blk, 'tcx>, ScopeId| + -> Block<'blk, 'tcx>) { ccx.stats().n_closures.set(ccx.stats().n_closures.get() + 1); let _icx = push_ctxt("trans_closure"); @@ -1980,11 +1969,11 @@ pub fn trans_enum_variant(ccx: &CrateContext, llfndecl); } -pub fn trans_named_tuple_constructor<'a>(mut bcx: &'a Block<'a>, - ctor_ty: ty::t, - disr: ty::Disr, - args: callee::CallArgs, - dest: expr::Dest) -> Result<'a> { +pub fn trans_named_tuple_constructor<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, + ctor_ty: ty::t, + disr: ty::Disr, + args: callee::CallArgs, + dest: expr::Dest) -> Result<'blk, 'tcx> { let ccx = bcx.fcx.ccx; let tcx = ccx.tcx(); @@ -2142,11 +2131,11 @@ fn enum_variant_size_lint(ccx: &CrateContext, enum_def: &ast::EnumDef, sp: Span, } } -pub struct TransItemVisitor<'a> { - pub ccx: &'a CrateContext<'a>, +pub struct TransItemVisitor<'a, 'tcx: 'a> { + pub ccx: &'a CrateContext<'a, 'tcx>, } -impl<'a> Visitor<()> for TransItemVisitor<'a> { +impl<'a, 'tcx> Visitor<()> for TransItemVisitor<'a, 'tcx> { fn visit_item(&mut self, i: &ast::Item, _:()) { trans_item(self.ccx, i); } @@ -2911,20 +2900,20 @@ pub fn p2i(ccx: &CrateContext, v: ValueRef) -> ValueRef { } } -pub fn crate_ctxt_to_encode_parms<'r>(cx: &'r SharedCrateContext, - ie: encoder::EncodeInlinedItem<'r>) - -> encoder::EncodeParams<'r> { - encoder::EncodeParams { - diag: cx.sess().diagnostic(), - tcx: cx.tcx(), - reexports2: cx.exp_map2(), - item_symbols: cx.item_symbols(), - non_inlineable_statics: cx.non_inlineable_statics(), - link_meta: cx.link_meta(), - cstore: &cx.sess().cstore, - encode_inlined_item: ie, - reachable: cx.reachable(), - } +pub fn crate_ctxt_to_encode_parms<'a, 'tcx>(cx: &'a SharedCrateContext<'tcx>, + ie: encoder::EncodeInlinedItem<'a>) + -> encoder::EncodeParams<'a, 'tcx> { + encoder::EncodeParams { + diag: cx.sess().diagnostic(), + tcx: cx.tcx(), + reexports2: cx.exp_map2(), + item_symbols: cx.item_symbols(), + non_inlineable_statics: cx.non_inlineable_statics(), + link_meta: cx.link_meta(), + cstore: &cx.sess().cstore, + encode_inlined_item: ie, + reachable: cx.reachable(), + } } pub fn write_metadata(cx: &SharedCrateContext, krate: &ast::Crate) -> Vec { diff --git a/src/librustc/middle/trans/build.rs b/src/librustc/middle/trans/build.rs index fd988eb7fc137..e30f9af02c6a6 100644 --- a/src/librustc/middle/trans/build.rs +++ b/src/librustc/middle/trans/build.rs @@ -23,18 +23,18 @@ use middle::trans::type_::Type; use libc::{c_uint, c_ulonglong, c_char}; -pub fn terminate(cx: &Block, _: &str) { +pub fn terminate(cx: Block, _: &str) { debug!("terminate({})", cx.to_str()); cx.terminated.set(true); } -pub fn check_not_terminated(cx: &Block) { +pub fn check_not_terminated(cx: Block) { if cx.terminated.get() { fail!("already terminated!"); } } -pub fn B<'a>(cx: &'a Block) -> Builder<'a> { +pub fn B<'blk, 'tcx>(cx: Block<'blk, 'tcx>) -> Builder<'blk, 'tcx> { let b = cx.fcx.ccx.builder(); b.position_at_end(cx.llbb); b @@ -48,35 +48,35 @@ pub fn B<'a>(cx: &'a Block) -> Builder<'a> { // for (fail/break/return statements, call to diverging functions, etc), and // further instructions to the block should simply be ignored. -pub fn RetVoid(cx: &Block) { +pub fn RetVoid(cx: Block) { if cx.unreachable.get() { return; } check_not_terminated(cx); terminate(cx, "RetVoid"); B(cx).ret_void(); } -pub fn Ret(cx: &Block, v: ValueRef) { +pub fn Ret(cx: Block, v: ValueRef) { if cx.unreachable.get() { return; } check_not_terminated(cx); terminate(cx, "Ret"); B(cx).ret(v); } -pub fn AggregateRet(cx: &Block, ret_vals: &[ValueRef]) { +pub fn AggregateRet(cx: Block, ret_vals: &[ValueRef]) { if cx.unreachable.get() { return; } check_not_terminated(cx); terminate(cx, "AggregateRet"); B(cx).aggregate_ret(ret_vals); } -pub fn Br(cx: &Block, dest: BasicBlockRef) { +pub fn Br(cx: Block, dest: BasicBlockRef) { if cx.unreachable.get() { return; } check_not_terminated(cx); terminate(cx, "Br"); B(cx).br(dest); } -pub fn CondBr(cx: &Block, +pub fn CondBr(cx: Block, if_: ValueRef, then: BasicBlockRef, else_: BasicBlockRef) { @@ -86,7 +86,7 @@ pub fn CondBr(cx: &Block, B(cx).cond_br(if_, then, else_); } -pub fn Switch(cx: &Block, v: ValueRef, else_: BasicBlockRef, num_cases: uint) +pub fn Switch(cx: Block, v: ValueRef, else_: BasicBlockRef, num_cases: uint) -> ValueRef { if cx.unreachable.get() { return _Undef(v); } check_not_terminated(cx); @@ -101,14 +101,14 @@ pub fn AddCase(s: ValueRef, on_val: ValueRef, dest: BasicBlockRef) { } } -pub fn IndirectBr(cx: &Block, addr: ValueRef, num_dests: uint) { +pub fn IndirectBr(cx: Block, addr: ValueRef, num_dests: uint) { if cx.unreachable.get() { return; } check_not_terminated(cx); terminate(cx, "IndirectBr"); B(cx).indirect_br(addr, num_dests); } -pub fn Invoke(cx: &Block, +pub fn Invoke(cx: Block, fn_: ValueRef, args: &[ValueRef], then: BasicBlockRef, @@ -126,7 +126,7 @@ pub fn Invoke(cx: &Block, B(cx).invoke(fn_, args, then, catch, attributes) } -pub fn Unreachable(cx: &Block) { +pub fn Unreachable(cx: Block) { if cx.unreachable.get() { return } @@ -143,163 +143,163 @@ pub fn _Undef(val: ValueRef) -> ValueRef { } /* Arithmetic */ -pub fn Add(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn Add(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).add(lhs, rhs) } -pub fn NSWAdd(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn NSWAdd(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).nswadd(lhs, rhs) } -pub fn NUWAdd(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn NUWAdd(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).nuwadd(lhs, rhs) } -pub fn FAdd(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn FAdd(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).fadd(lhs, rhs) } -pub fn Sub(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn Sub(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).sub(lhs, rhs) } -pub fn NSWSub(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn NSWSub(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).nswsub(lhs, rhs) } -pub fn NUWSub(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn NUWSub(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).nuwsub(lhs, rhs) } -pub fn FSub(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn FSub(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).fsub(lhs, rhs) } -pub fn Mul(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn Mul(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).mul(lhs, rhs) } -pub fn NSWMul(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn NSWMul(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).nswmul(lhs, rhs) } -pub fn NUWMul(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn NUWMul(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).nuwmul(lhs, rhs) } -pub fn FMul(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn FMul(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).fmul(lhs, rhs) } -pub fn UDiv(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn UDiv(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).udiv(lhs, rhs) } -pub fn SDiv(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn SDiv(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).sdiv(lhs, rhs) } -pub fn ExactSDiv(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn ExactSDiv(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).exactsdiv(lhs, rhs) } -pub fn FDiv(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn FDiv(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).fdiv(lhs, rhs) } -pub fn URem(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn URem(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).urem(lhs, rhs) } -pub fn SRem(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn SRem(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).srem(lhs, rhs) } -pub fn FRem(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn FRem(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).frem(lhs, rhs) } -pub fn Shl(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn Shl(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).shl(lhs, rhs) } -pub fn LShr(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn LShr(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).lshr(lhs, rhs) } -pub fn AShr(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn AShr(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).ashr(lhs, rhs) } -pub fn And(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn And(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).and(lhs, rhs) } -pub fn Or(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn Or(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).or(lhs, rhs) } -pub fn Xor(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn Xor(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).xor(lhs, rhs) } -pub fn BinOp(cx: &Block, op: Opcode, lhs: ValueRef, rhs: ValueRef) +pub fn BinOp(cx: Block, op: Opcode, lhs: ValueRef, rhs: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(lhs); } B(cx).binop(op, lhs, rhs) } -pub fn Neg(cx: &Block, v: ValueRef) -> ValueRef { +pub fn Neg(cx: Block, v: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(v); } B(cx).neg(v) } -pub fn NSWNeg(cx: &Block, v: ValueRef) -> ValueRef { +pub fn NSWNeg(cx: Block, v: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(v); } B(cx).nswneg(v) } -pub fn NUWNeg(cx: &Block, v: ValueRef) -> ValueRef { +pub fn NUWNeg(cx: Block, v: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(v); } B(cx).nuwneg(v) } -pub fn FNeg(cx: &Block, v: ValueRef) -> ValueRef { +pub fn FNeg(cx: Block, v: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(v); } B(cx).fneg(v) } -pub fn Not(cx: &Block, v: ValueRef) -> ValueRef { +pub fn Not(cx: Block, v: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(v); } B(cx).not(v) } /* Memory */ -pub fn Malloc(cx: &Block, ty: Type) -> ValueRef { +pub fn Malloc(cx: Block, ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::i8p(cx.ccx()).to_ref()); @@ -308,7 +308,7 @@ pub fn Malloc(cx: &Block, ty: Type) -> ValueRef { } } -pub fn ArrayMalloc(cx: &Block, ty: Type, val: ValueRef) -> ValueRef { +pub fn ArrayMalloc(cx: Block, ty: Type, val: ValueRef) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::i8p(cx.ccx()).to_ref()); @@ -317,7 +317,7 @@ pub fn ArrayMalloc(cx: &Block, ty: Type, val: ValueRef) -> ValueRef { } } -pub fn Alloca(cx: &Block, ty: Type, name: &str) -> ValueRef { +pub fn Alloca(cx: Block, ty: Type, name: &str) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(ty.ptr_to().to_ref()); } AllocaFcx(cx.fcx, ty, name) @@ -330,7 +330,7 @@ pub fn AllocaFcx(fcx: &FunctionContext, ty: Type, name: &str) -> ValueRef { b.alloca(ty, name) } -pub fn ArrayAlloca(cx: &Block, ty: Type, val: ValueRef) -> ValueRef { +pub fn ArrayAlloca(cx: Block, ty: Type, val: ValueRef) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(ty.ptr_to().to_ref()); } let b = cx.fcx.ccx.builder(); @@ -339,12 +339,12 @@ pub fn ArrayAlloca(cx: &Block, ty: Type, val: ValueRef) -> ValueRef { } } -pub fn Free(cx: &Block, pointer_val: ValueRef) { +pub fn Free(cx: Block, pointer_val: ValueRef) { if cx.unreachable.get() { return; } B(cx).free(pointer_val) } -pub fn Load(cx: &Block, pointer_val: ValueRef) -> ValueRef { +pub fn Load(cx: Block, pointer_val: ValueRef) -> ValueRef { unsafe { let ccx = cx.fcx.ccx; if cx.unreachable.get() { @@ -360,7 +360,7 @@ pub fn Load(cx: &Block, pointer_val: ValueRef) -> ValueRef { } } -pub fn VolatileLoad(cx: &Block, pointer_val: ValueRef) -> ValueRef { +pub fn VolatileLoad(cx: Block, pointer_val: ValueRef) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil(cx.ccx()).to_ref()); @@ -369,7 +369,7 @@ pub fn VolatileLoad(cx: &Block, pointer_val: ValueRef) -> ValueRef { } } -pub fn AtomicLoad(cx: &Block, pointer_val: ValueRef, order: AtomicOrdering) -> ValueRef { +pub fn AtomicLoad(cx: Block, pointer_val: ValueRef, order: AtomicOrdering) -> ValueRef { unsafe { let ccx = cx.fcx.ccx; if cx.unreachable.get() { @@ -380,7 +380,7 @@ pub fn AtomicLoad(cx: &Block, pointer_val: ValueRef, order: AtomicOrdering) -> V } -pub fn LoadRangeAssert(cx: &Block, pointer_val: ValueRef, lo: c_ulonglong, +pub fn LoadRangeAssert(cx: Block, pointer_val: ValueRef, lo: c_ulonglong, hi: c_ulonglong, signed: llvm::Bool) -> ValueRef { if cx.unreachable.get() { let ccx = cx.fcx.ccx; @@ -398,22 +398,22 @@ pub fn LoadRangeAssert(cx: &Block, pointer_val: ValueRef, lo: c_ulonglong, } } -pub fn Store(cx: &Block, val: ValueRef, ptr: ValueRef) { +pub fn Store(cx: Block, val: ValueRef, ptr: ValueRef) { if cx.unreachable.get() { return; } B(cx).store(val, ptr) } -pub fn VolatileStore(cx: &Block, val: ValueRef, ptr: ValueRef) { +pub fn VolatileStore(cx: Block, val: ValueRef, ptr: ValueRef) { if cx.unreachable.get() { return; } B(cx).volatile_store(val, ptr) } -pub fn AtomicStore(cx: &Block, val: ValueRef, ptr: ValueRef, order: AtomicOrdering) { +pub fn AtomicStore(cx: Block, val: ValueRef, ptr: ValueRef, order: AtomicOrdering) { if cx.unreachable.get() { return; } B(cx).atomic_store(val, ptr, order) } -pub fn GEP(cx: &Block, pointer: ValueRef, indices: &[ValueRef]) -> ValueRef { +pub fn GEP(cx: Block, pointer: ValueRef, indices: &[ValueRef]) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil(cx.ccx()).ptr_to().to_ref()); @@ -425,7 +425,7 @@ pub fn GEP(cx: &Block, pointer: ValueRef, indices: &[ValueRef]) -> ValueRef { // Simple wrapper around GEP that takes an array of ints and wraps them // in C_i32() #[inline] -pub fn GEPi(cx: &Block, base: ValueRef, ixs: &[uint]) -> ValueRef { +pub fn GEPi(cx: Block, base: ValueRef, ixs: &[uint]) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil(cx.ccx()).ptr_to().to_ref()); @@ -434,7 +434,7 @@ pub fn GEPi(cx: &Block, base: ValueRef, ixs: &[uint]) -> ValueRef { } } -pub fn InBoundsGEP(cx: &Block, pointer: ValueRef, indices: &[ValueRef]) -> ValueRef { +pub fn InBoundsGEP(cx: Block, pointer: ValueRef, indices: &[ValueRef]) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil(cx.ccx()).ptr_to().to_ref()); @@ -443,7 +443,7 @@ pub fn InBoundsGEP(cx: &Block, pointer: ValueRef, indices: &[ValueRef]) -> Value } } -pub fn StructGEP(cx: &Block, pointer: ValueRef, idx: uint) -> ValueRef { +pub fn StructGEP(cx: Block, pointer: ValueRef, idx: uint) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil(cx.ccx()).ptr_to().to_ref()); @@ -452,7 +452,7 @@ pub fn StructGEP(cx: &Block, pointer: ValueRef, idx: uint) -> ValueRef { } } -pub fn GlobalString(cx: &Block, _str: *const c_char) -> ValueRef { +pub fn GlobalString(cx: Block, _str: *const c_char) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::i8p(cx.ccx()).to_ref()); @@ -461,7 +461,7 @@ pub fn GlobalString(cx: &Block, _str: *const c_char) -> ValueRef { } } -pub fn GlobalStringPtr(cx: &Block, _str: *const c_char) -> ValueRef { +pub fn GlobalStringPtr(cx: Block, _str: *const c_char) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::i8p(cx.ccx()).to_ref()); @@ -471,112 +471,112 @@ pub fn GlobalStringPtr(cx: &Block, _str: *const c_char) -> ValueRef { } /* Casts */ -pub fn Trunc(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef { +pub fn Trunc(cx: Block, val: ValueRef, dest_ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(dest_ty.to_ref()); } B(cx).trunc(val, dest_ty) } } -pub fn ZExt(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef { +pub fn ZExt(cx: Block, val: ValueRef, dest_ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(dest_ty.to_ref()); } B(cx).zext(val, dest_ty) } } -pub fn SExt(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef { +pub fn SExt(cx: Block, val: ValueRef, dest_ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(dest_ty.to_ref()); } B(cx).sext(val, dest_ty) } } -pub fn FPToUI(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef { +pub fn FPToUI(cx: Block, val: ValueRef, dest_ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(dest_ty.to_ref()); } B(cx).fptoui(val, dest_ty) } } -pub fn FPToSI(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef { +pub fn FPToSI(cx: Block, val: ValueRef, dest_ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(dest_ty.to_ref()); } B(cx).fptosi(val, dest_ty) } } -pub fn UIToFP(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef { +pub fn UIToFP(cx: Block, val: ValueRef, dest_ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(dest_ty.to_ref()); } B(cx).uitofp(val, dest_ty) } } -pub fn SIToFP(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef { +pub fn SIToFP(cx: Block, val: ValueRef, dest_ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(dest_ty.to_ref()); } B(cx).sitofp(val, dest_ty) } } -pub fn FPTrunc(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef { +pub fn FPTrunc(cx: Block, val: ValueRef, dest_ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(dest_ty.to_ref()); } B(cx).fptrunc(val, dest_ty) } } -pub fn FPExt(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef { +pub fn FPExt(cx: Block, val: ValueRef, dest_ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(dest_ty.to_ref()); } B(cx).fpext(val, dest_ty) } } -pub fn PtrToInt(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef { +pub fn PtrToInt(cx: Block, val: ValueRef, dest_ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(dest_ty.to_ref()); } B(cx).ptrtoint(val, dest_ty) } } -pub fn IntToPtr(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef { +pub fn IntToPtr(cx: Block, val: ValueRef, dest_ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(dest_ty.to_ref()); } B(cx).inttoptr(val, dest_ty) } } -pub fn BitCast(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef { +pub fn BitCast(cx: Block, val: ValueRef, dest_ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(dest_ty.to_ref()); } B(cx).bitcast(val, dest_ty) } } -pub fn ZExtOrBitCast(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef { +pub fn ZExtOrBitCast(cx: Block, val: ValueRef, dest_ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(dest_ty.to_ref()); } B(cx).zext_or_bitcast(val, dest_ty) } } -pub fn SExtOrBitCast(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef { +pub fn SExtOrBitCast(cx: Block, val: ValueRef, dest_ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(dest_ty.to_ref()); } B(cx).sext_or_bitcast(val, dest_ty) } } -pub fn TruncOrBitCast(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef { +pub fn TruncOrBitCast(cx: Block, val: ValueRef, dest_ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(dest_ty.to_ref()); } B(cx).trunc_or_bitcast(val, dest_ty) } } -pub fn Cast(cx: &Block, op: Opcode, val: ValueRef, dest_ty: Type, +pub fn Cast(cx: Block, op: Opcode, val: ValueRef, dest_ty: Type, _: *const u8) -> ValueRef { unsafe { @@ -585,21 +585,21 @@ pub fn Cast(cx: &Block, op: Opcode, val: ValueRef, dest_ty: Type, } } -pub fn PointerCast(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef { +pub fn PointerCast(cx: Block, val: ValueRef, dest_ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(dest_ty.to_ref()); } B(cx).pointercast(val, dest_ty) } } -pub fn IntCast(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef { +pub fn IntCast(cx: Block, val: ValueRef, dest_ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(dest_ty.to_ref()); } B(cx).intcast(val, dest_ty) } } -pub fn FPCast(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef { +pub fn FPCast(cx: Block, val: ValueRef, dest_ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(dest_ty.to_ref()); } B(cx).fpcast(val, dest_ty) @@ -608,7 +608,7 @@ pub fn FPCast(cx: &Block, val: ValueRef, dest_ty: Type) -> ValueRef { /* Comparisons */ -pub fn ICmp(cx: &Block, op: IntPredicate, lhs: ValueRef, rhs: ValueRef) +pub fn ICmp(cx: Block, op: IntPredicate, lhs: ValueRef, rhs: ValueRef) -> ValueRef { unsafe { if cx.unreachable.get() { @@ -618,7 +618,7 @@ pub fn ICmp(cx: &Block, op: IntPredicate, lhs: ValueRef, rhs: ValueRef) } } -pub fn FCmp(cx: &Block, op: RealPredicate, lhs: ValueRef, rhs: ValueRef) +pub fn FCmp(cx: Block, op: RealPredicate, lhs: ValueRef, rhs: ValueRef) -> ValueRef { unsafe { if cx.unreachable.get() { @@ -629,14 +629,14 @@ pub fn FCmp(cx: &Block, op: RealPredicate, lhs: ValueRef, rhs: ValueRef) } /* Miscellaneous instructions */ -pub fn EmptyPhi(cx: &Block, ty: Type) -> ValueRef { +pub fn EmptyPhi(cx: Block, ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(ty.to_ref()); } B(cx).empty_phi(ty) } } -pub fn Phi(cx: &Block, ty: Type, vals: &[ValueRef], +pub fn Phi(cx: Block, ty: Type, vals: &[ValueRef], bbs: &[BasicBlockRef]) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(ty.to_ref()); } @@ -651,7 +651,7 @@ pub fn AddIncomingToPhi(phi: ValueRef, val: ValueRef, bb: BasicBlockRef) { } } -pub fn _UndefReturn(cx: &Block, fn_: ValueRef) -> ValueRef { +pub fn _UndefReturn(cx: Block, fn_: ValueRef) -> ValueRef { unsafe { let ccx = cx.fcx.ccx; let ty = val_ty(fn_); @@ -665,51 +665,51 @@ pub fn _UndefReturn(cx: &Block, fn_: ValueRef) -> ValueRef { } } -pub fn add_span_comment(cx: &Block, sp: Span, text: &str) { +pub fn add_span_comment(cx: Block, sp: Span, text: &str) { B(cx).add_span_comment(sp, text) } -pub fn add_comment(cx: &Block, text: &str) { +pub fn add_comment(cx: Block, text: &str) { B(cx).add_comment(text) } -pub fn InlineAsmCall(cx: &Block, asm: *const c_char, cons: *const c_char, +pub fn InlineAsmCall(cx: Block, asm: *const c_char, cons: *const c_char, inputs: &[ValueRef], output: Type, volatile: bool, alignstack: bool, dia: AsmDialect) -> ValueRef { B(cx).inline_asm_call(asm, cons, inputs, output, volatile, alignstack, dia) } -pub fn Call(cx: &Block, fn_: ValueRef, args: &[ValueRef], +pub fn Call(cx: Block, fn_: ValueRef, args: &[ValueRef], attributes: Option) -> ValueRef { if cx.unreachable.get() { return _UndefReturn(cx, fn_); } B(cx).call(fn_, args, attributes) } -pub fn CallWithConv(cx: &Block, fn_: ValueRef, args: &[ValueRef], conv: CallConv, +pub fn CallWithConv(cx: Block, fn_: ValueRef, args: &[ValueRef], conv: CallConv, attributes: Option) -> ValueRef { if cx.unreachable.get() { return _UndefReturn(cx, fn_); } B(cx).call_with_conv(fn_, args, conv, attributes) } -pub fn AtomicFence(cx: &Block, order: AtomicOrdering) { +pub fn AtomicFence(cx: Block, order: AtomicOrdering) { if cx.unreachable.get() { return; } B(cx).atomic_fence(order) } -pub fn Select(cx: &Block, if_: ValueRef, then: ValueRef, else_: ValueRef) -> ValueRef { +pub fn Select(cx: Block, if_: ValueRef, then: ValueRef, else_: ValueRef) -> ValueRef { if cx.unreachable.get() { return _Undef(then); } B(cx).select(if_, then, else_) } -pub fn VAArg(cx: &Block, list: ValueRef, ty: Type) -> ValueRef { +pub fn VAArg(cx: Block, list: ValueRef, ty: Type) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(ty.to_ref()); } B(cx).va_arg(list, ty) } } -pub fn ExtractElement(cx: &Block, vec_val: ValueRef, index: ValueRef) -> ValueRef { +pub fn ExtractElement(cx: Block, vec_val: ValueRef, index: ValueRef) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil(cx.ccx()).to_ref()); @@ -718,7 +718,7 @@ pub fn ExtractElement(cx: &Block, vec_val: ValueRef, index: ValueRef) -> ValueRe } } -pub fn InsertElement(cx: &Block, vec_val: ValueRef, elt_val: ValueRef, +pub fn InsertElement(cx: Block, vec_val: ValueRef, elt_val: ValueRef, index: ValueRef) -> ValueRef { unsafe { if cx.unreachable.get() { @@ -728,7 +728,7 @@ pub fn InsertElement(cx: &Block, vec_val: ValueRef, elt_val: ValueRef, } } -pub fn ShuffleVector(cx: &Block, v1: ValueRef, v2: ValueRef, +pub fn ShuffleVector(cx: Block, v1: ValueRef, v2: ValueRef, mask: ValueRef) -> ValueRef { unsafe { if cx.unreachable.get() { @@ -738,7 +738,7 @@ pub fn ShuffleVector(cx: &Block, v1: ValueRef, v2: ValueRef, } } -pub fn VectorSplat(cx: &Block, num_elts: uint, elt_val: ValueRef) -> ValueRef { +pub fn VectorSplat(cx: Block, num_elts: uint, elt_val: ValueRef) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil(cx.ccx()).to_ref()); @@ -747,7 +747,7 @@ pub fn VectorSplat(cx: &Block, num_elts: uint, elt_val: ValueRef) -> ValueRef { } } -pub fn ExtractValue(cx: &Block, agg_val: ValueRef, index: uint) -> ValueRef { +pub fn ExtractValue(cx: Block, agg_val: ValueRef, index: uint) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil(cx.ccx()).to_ref()); @@ -756,7 +756,7 @@ pub fn ExtractValue(cx: &Block, agg_val: ValueRef, index: uint) -> ValueRef { } } -pub fn InsertValue(cx: &Block, agg_val: ValueRef, elt_val: ValueRef, index: uint) -> ValueRef { +pub fn InsertValue(cx: Block, agg_val: ValueRef, elt_val: ValueRef, index: uint) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::nil(cx.ccx()).to_ref()); @@ -765,7 +765,7 @@ pub fn InsertValue(cx: &Block, agg_val: ValueRef, elt_val: ValueRef, index: uint } } -pub fn IsNull(cx: &Block, val: ValueRef) -> ValueRef { +pub fn IsNull(cx: Block, val: ValueRef) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::i1(cx.ccx()).to_ref()); @@ -774,7 +774,7 @@ pub fn IsNull(cx: &Block, val: ValueRef) -> ValueRef { } } -pub fn IsNotNull(cx: &Block, val: ValueRef) -> ValueRef { +pub fn IsNotNull(cx: Block, val: ValueRef) -> ValueRef { unsafe { if cx.unreachable.get() { return llvm::LLVMGetUndef(Type::i1(cx.ccx()).to_ref()); @@ -783,7 +783,7 @@ pub fn IsNotNull(cx: &Block, val: ValueRef) -> ValueRef { } } -pub fn PtrDiff(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { +pub fn PtrDiff(cx: Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { unsafe { let ccx = cx.fcx.ccx; if cx.unreachable.get() { return llvm::LLVMGetUndef(ccx.int_type().to_ref()); } @@ -791,36 +791,36 @@ pub fn PtrDiff(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef { } } -pub fn Trap(cx: &Block) { +pub fn Trap(cx: Block) { if cx.unreachable.get() { return; } B(cx).trap(); } -pub fn LandingPad(cx: &Block, ty: Type, pers_fn: ValueRef, +pub fn LandingPad(cx: Block, ty: Type, pers_fn: ValueRef, num_clauses: uint) -> ValueRef { check_not_terminated(cx); assert!(!cx.unreachable.get()); B(cx).landing_pad(ty, pers_fn, num_clauses) } -pub fn SetCleanup(cx: &Block, landing_pad: ValueRef) { +pub fn SetCleanup(cx: Block, landing_pad: ValueRef) { B(cx).set_cleanup(landing_pad) } -pub fn Resume(cx: &Block, exn: ValueRef) -> ValueRef { +pub fn Resume(cx: Block, exn: ValueRef) -> ValueRef { check_not_terminated(cx); terminate(cx, "Resume"); B(cx).resume(exn) } // Atomic Operations -pub fn AtomicCmpXchg(cx: &Block, dst: ValueRef, +pub fn AtomicCmpXchg(cx: Block, dst: ValueRef, cmp: ValueRef, src: ValueRef, order: AtomicOrdering, failure_order: AtomicOrdering) -> ValueRef { B(cx).atomic_cmpxchg(dst, cmp, src, order, failure_order) } -pub fn AtomicRMW(cx: &Block, op: AtomicBinOp, +pub fn AtomicRMW(cx: Block, op: AtomicBinOp, dst: ValueRef, src: ValueRef, order: AtomicOrdering) -> ValueRef { B(cx).atomic_rmw(op, dst, src, order) diff --git a/src/librustc/middle/trans/builder.rs b/src/librustc/middle/trans/builder.rs index 322a6a3cc909e..ca7adb97f3d54 100644 --- a/src/librustc/middle/trans/builder.rs +++ b/src/librustc/middle/trans/builder.rs @@ -23,9 +23,9 @@ use libc::{c_uint, c_ulonglong, c_char}; use std::string::String; use syntax::codemap::Span; -pub struct Builder<'a> { +pub struct Builder<'a, 'tcx: 'a> { pub llbuilder: BuilderRef, - pub ccx: &'a CrateContext<'a>, + pub ccx: &'a CrateContext<'a, 'tcx>, } // This is a really awful way to get a zero-length c-string, but better (and a @@ -35,8 +35,8 @@ pub fn noname() -> *const c_char { &cnull as *const c_char } -impl<'a> Builder<'a> { - pub fn new(ccx: &'a CrateContext) -> Builder<'a> { +impl<'a, 'tcx> Builder<'a, 'tcx> { + pub fn new(ccx: &'a CrateContext<'a, 'tcx>) -> Builder<'a, 'tcx> { Builder { llbuilder: ccx.raw_builder(), ccx: ccx, diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 794e42563a9f0..5d66ec0a4b936 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -80,12 +80,13 @@ pub enum CalleeData { TraitItem(MethodData) } -pub struct Callee<'a> { - pub bcx: &'a Block<'a>, +pub struct Callee<'blk, 'tcx: 'blk> { + pub bcx: Block<'blk, 'tcx>, pub data: CalleeData, } -fn trans<'a>(bcx: &'a Block<'a>, expr: &ast::Expr) -> Callee<'a> { +fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr) + -> Callee<'blk, 'tcx> { let _icx = push_ctxt("trans_callee"); debug!("callee::trans(expr={})", expr.repr(bcx.tcx())); @@ -100,7 +101,8 @@ fn trans<'a>(bcx: &'a Block<'a>, expr: &ast::Expr) -> Callee<'a> { // any other expressions are closures: return datum_callee(bcx, expr); - fn datum_callee<'a>(bcx: &'a Block<'a>, expr: &ast::Expr) -> Callee<'a> { + fn datum_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, expr: &ast::Expr) + -> Callee<'blk, 'tcx> { let DatumBlock {bcx: mut bcx, datum} = expr::trans(bcx, expr); match ty::get(datum.ty).sty { ty::ty_bare_fn(..) => { @@ -128,15 +130,16 @@ fn trans<'a>(bcx: &'a Block<'a>, expr: &ast::Expr) -> Callee<'a> { } } - fn fn_callee<'a>(bcx: &'a Block<'a>, llfn: ValueRef) -> Callee<'a> { + fn fn_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, llfn: ValueRef) + -> Callee<'blk, 'tcx> { return Callee { bcx: bcx, data: Fn(llfn), }; } - fn trans_def<'a>(bcx: &'a Block<'a>, def: def::Def, ref_expr: &ast::Expr) - -> Callee<'a> { + fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, def: def::Def, ref_expr: &ast::Expr) + -> Callee<'blk, 'tcx> { debug!("trans_def(def={}, ref_expr={})", def.repr(bcx.tcx()), ref_expr.repr(bcx.tcx())); let expr_ty = node_id_type(bcx, ref_expr.id); match def { @@ -214,7 +217,7 @@ fn trans<'a>(bcx: &'a Block<'a>, expr: &ast::Expr) -> Callee<'a> { } } -pub fn trans_fn_ref(bcx: &Block, def_id: ast::DefId, node: ExprOrMethodCall) -> ValueRef { +pub fn trans_fn_ref(bcx: Block, def_id: ast::DefId, node: ExprOrMethodCall) -> ValueRef { /*! * Translates a reference (with id `ref_id`) to the fn/method * with id `def_id` into a function pointer. This may require @@ -237,12 +240,12 @@ pub fn trans_fn_ref(bcx: &Block, def_id: ast::DefId, node: ExprOrMethodCall) -> trans_fn_ref_with_vtables(bcx, def_id, node, substs, vtables) } -fn trans_fn_ref_with_vtables_to_callee<'a>(bcx: &'a Block<'a>, - def_id: ast::DefId, - ref_id: ast::NodeId, - substs: subst::Substs, - vtables: typeck::vtable_res) - -> Callee<'a> { +fn trans_fn_ref_with_vtables_to_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + def_id: ast::DefId, + ref_id: ast::NodeId, + substs: subst::Substs, + vtables: typeck::vtable_res) + -> Callee<'blk, 'tcx> { Callee { bcx: bcx, data: Fn(trans_fn_ref_with_vtables(bcx, @@ -253,7 +256,7 @@ fn trans_fn_ref_with_vtables_to_callee<'a>(bcx: &'a Block<'a>, } } -fn resolve_default_method_vtables(bcx: &Block, +fn resolve_default_method_vtables(bcx: Block, impl_id: ast::DefId, substs: &subst::Substs, impl_vtables: typeck::vtable_res) @@ -281,7 +284,7 @@ fn resolve_default_method_vtables(bcx: &Block, /// Translates the adapter that deconstructs a `Box` object into /// `Trait` so that a by-value self method can be called. -pub fn trans_unboxing_shim(bcx: &Block, +pub fn trans_unboxing_shim(bcx: Block, llshimmedfn: ValueRef, fty: &ty::BareFnTy, method_id: ast::DefId, @@ -406,7 +409,7 @@ pub fn trans_unboxing_shim(bcx: &Block, } pub fn trans_fn_ref_with_vtables( - bcx: &Block, // + bcx: Block, // def_id: ast::DefId, // def id of fn node: ExprOrMethodCall, // node id of use of fn; may be zero if N/A substs: subst::Substs, // values for fn's ty params @@ -625,13 +628,12 @@ pub fn trans_fn_ref_with_vtables( // ______________________________________________________________________ // Translating calls -pub fn trans_call<'a>( - in_cx: &'a Block<'a>, - call_ex: &ast::Expr, - f: &ast::Expr, - args: CallArgs, - dest: expr::Dest) - -> &'a Block<'a> { +pub fn trans_call<'blk, 'tcx>(in_cx: Block<'blk, 'tcx>, + call_ex: &ast::Expr, + f: &ast::Expr, + args: CallArgs, + dest: expr::Dest) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_call"); trans_call_inner(in_cx, Some(common::expr_info(call_ex)), @@ -641,13 +643,12 @@ pub fn trans_call<'a>( Some(dest)).bcx } -pub fn trans_method_call<'a>( - bcx: &'a Block<'a>, - call_ex: &ast::Expr, - rcvr: &ast::Expr, - args: CallArgs, - dest: expr::Dest) - -> &'a Block<'a> { +pub fn trans_method_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + call_ex: &ast::Expr, + rcvr: &ast::Expr, + args: CallArgs, + dest: expr::Dest) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_method_call"); debug!("trans_method_call(call_ex={})", call_ex.repr(bcx.tcx())); let method_call = MethodCall::expr(call_ex.id); @@ -663,12 +664,11 @@ pub fn trans_method_call<'a>( Some(dest)).bcx } -pub fn trans_lang_call<'a>( - bcx: &'a Block<'a>, - did: ast::DefId, - args: &[ValueRef], - dest: Option) - -> Result<'a> { +pub fn trans_lang_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + did: ast::DefId, + args: &[ValueRef], + dest: Option) + -> Result<'blk, 'tcx> { let fty = if did.krate == ast::LOCAL_CRATE { ty::node_id_to_type(bcx.tcx(), did.node) } else { @@ -688,16 +688,15 @@ pub fn trans_lang_call<'a>( dest) } -pub fn trans_call_inner<'a>( - bcx: &'a Block<'a>, - call_info: Option, - callee_ty: ty::t, - get_callee: |bcx: &'a Block<'a>, - arg_cleanup_scope: cleanup::ScopeId| - -> Callee<'a>, - args: CallArgs, - dest: Option) - -> Result<'a> { +pub fn trans_call_inner<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + call_info: Option, + callee_ty: ty::t, + get_callee: |bcx: Block<'blk, 'tcx>, + arg_cleanup_scope: cleanup::ScopeId| + -> Callee<'blk, 'tcx>, + args: CallArgs, + dest: Option) + -> Result<'blk, 'tcx> { /*! * This behemoth of a function translates function calls. * Unfortunately, in order to generate more efficient LLVM @@ -920,14 +919,14 @@ pub enum CallArgs<'a> { ArgOverloadedCall(&'a [Gc]), } -fn trans_args_under_call_abi<'a>( - mut bcx: &'a Block<'a>, +fn trans_args_under_call_abi<'blk, 'tcx>( + mut bcx: Block<'blk, 'tcx>, arg_exprs: &[Gc], fn_ty: ty::t, llargs: &mut Vec, arg_cleanup_scope: cleanup::ScopeId, ignore_self: bool) - -> &'a Block<'a> { + -> Block<'blk, 'tcx> { // Translate the `self` argument first. let arg_tys = ty::ty_fn_args(fn_ty); if !ignore_self { @@ -981,14 +980,14 @@ fn trans_args_under_call_abi<'a>( bcx } -fn trans_overloaded_call_args<'a>( - mut bcx: &'a Block<'a>, +fn trans_overloaded_call_args<'blk, 'tcx>( + mut bcx: Block<'blk, 'tcx>, arg_exprs: &[Gc], fn_ty: ty::t, llargs: &mut Vec, arg_cleanup_scope: cleanup::ScopeId, ignore_self: bool) - -> &'a Block<'a> { + -> Block<'blk, 'tcx> { // Translate the `self` argument first. let arg_tys = ty::ty_fn_args(fn_ty); if !ignore_self { @@ -1028,15 +1027,14 @@ fn trans_overloaded_call_args<'a>( bcx } -pub fn trans_args<'a>( - cx: &'a Block<'a>, - args: CallArgs, - fn_ty: ty::t, - llargs: &mut Vec , - arg_cleanup_scope: cleanup::ScopeId, - ignore_self: bool, - abi: synabi::Abi) - -> &'a Block<'a> { +pub fn trans_args<'blk, 'tcx>(cx: Block<'blk, 'tcx>, + args: CallArgs, + fn_ty: ty::t, + llargs: &mut Vec , + arg_cleanup_scope: cleanup::ScopeId, + ignore_self: bool, + abi: synabi::Abi) + -> Block<'blk, 'tcx> { debug!("trans_args(abi={})", abi); let _icx = push_ctxt("trans_args"); @@ -1124,13 +1122,12 @@ pub enum AutorefArg { DoAutorefArg(ast::NodeId) } -pub fn trans_arg_datum<'a>( - bcx: &'a Block<'a>, - formal_arg_ty: ty::t, - arg_datum: Datum, - arg_cleanup_scope: cleanup::ScopeId, - autoref_arg: AutorefArg) - -> Result<'a> { +pub fn trans_arg_datum<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + formal_arg_ty: ty::t, + arg_datum: Datum, + arg_cleanup_scope: cleanup::ScopeId, + autoref_arg: AutorefArg) + -> Result<'blk, 'tcx> { let _icx = push_ctxt("trans_arg_datum"); let mut bcx = bcx; let ccx = bcx.ccx(); diff --git a/src/librustc/middle/trans/cleanup.rs b/src/librustc/middle/trans/cleanup.rs index cdfb8e48a460e..4d54308031e92 100644 --- a/src/librustc/middle/trans/cleanup.rs +++ b/src/librustc/middle/trans/cleanup.rs @@ -25,13 +25,13 @@ use middle::ty; use syntax::ast; use util::ppaux::Repr; -pub struct CleanupScope<'a> { +pub struct CleanupScope<'blk, 'tcx: 'blk> { // The id of this cleanup scope. If the id is None, // this is a *temporary scope* that is pushed during trans to // cleanup miscellaneous garbage that trans may generate whose // lifetime is a subset of some expression. See module doc for // more details. - kind: CleanupScopeKind<'a>, + kind: CleanupScopeKind<'blk, 'tcx>, // Cleanups to run upon scope exit. cleanups: Vec, @@ -48,10 +48,10 @@ pub static EXIT_BREAK: uint = 0; pub static EXIT_LOOP: uint = 1; pub static EXIT_MAX: uint = 2; -pub enum CleanupScopeKind<'a> { +pub enum CleanupScopeKind<'blk, 'tcx: 'blk> { CustomScopeKind, AstScopeKind(ast::NodeId), - LoopScopeKind(ast::NodeId, [&'a Block<'a>, ..EXIT_MAX]) + LoopScopeKind(ast::NodeId, [Block<'blk, 'tcx>, ..EXIT_MAX]) } #[deriving(PartialEq)] @@ -69,7 +69,7 @@ pub struct CachedEarlyExit { pub trait Cleanup { fn must_unwind(&self) -> bool; fn clean_on_unwind(&self) -> bool; - fn trans<'a>(&self, bcx: &'a Block<'a>) -> &'a Block<'a>; + fn trans<'blk, 'tcx>(&self, bcx: Block<'blk, 'tcx>) -> Block<'blk, 'tcx>; } pub type CleanupObj = Box; @@ -79,7 +79,7 @@ pub enum ScopeId { CustomScope(CustomScopeIndex) } -impl<'a> CleanupMethods<'a> for FunctionContext<'a> { +impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> { fn push_ast_cleanup_scope(&self, id: ast::NodeId) { /*! * Invoked when we start to trans the code contained @@ -109,7 +109,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> { fn push_loop_cleanup_scope(&self, id: ast::NodeId, - exits: [&'a Block<'a>, ..EXIT_MAX]) { + exits: [Block<'blk, 'tcx>, ..EXIT_MAX]) { debug!("push_loop_cleanup_scope({})", self.ccx.tcx().map.node_to_string(id)); assert_eq!(Some(id), self.top_ast_scope()); @@ -125,9 +125,9 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> { } fn pop_and_trans_ast_cleanup_scope(&self, - bcx: &'a Block<'a>, + bcx: Block<'blk, 'tcx>, cleanup_scope: ast::NodeId) - -> &'a Block<'a> { + -> Block<'blk, 'tcx> { /*! * Removes the cleanup scope for id `cleanup_scope`, which * must be at the top of the cleanup stack, and generates the @@ -175,9 +175,9 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> { } fn pop_and_trans_custom_cleanup_scope(&self, - bcx: &'a Block<'a>, + bcx: Block<'blk, 'tcx>, custom_scope: CustomScopeIndex) - -> &'a Block<'a> { + -> Block<'blk, 'tcx> { /*! * Removes the top cleanup scope from the stack, which must be * a temporary scope, and generates the code to do its @@ -207,7 +207,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> { self.ccx.sess().bug("no loop scope found"); } - fn normal_exit_block(&'a self, + fn normal_exit_block(&'blk self, cleanup_scope: ast::NodeId, exit: uint) -> BasicBlockRef { /*! @@ -219,7 +219,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> { self.trans_cleanups_to_exit_scope(LoopExit(cleanup_scope, exit)) } - fn return_exit_block(&'a self) -> BasicBlockRef { + fn return_exit_block(&'blk self) -> BasicBlockRef { /*! * Returns a block to branch to which will perform all pending * cleanups and then return from this function @@ -426,7 +426,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> { self.scopes.borrow().iter().rev().any(|s| s.needs_invoke()) } - fn get_landing_pad(&'a self) -> BasicBlockRef { + fn get_landing_pad(&'blk self) -> BasicBlockRef { /*! * Returns a basic block to branch to in the event of a failure. * This block will run the failure cleanups and eventually @@ -464,7 +464,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> { } } -impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> { +impl<'blk, 'tcx> CleanupHelperMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> { fn top_ast_scope(&self) -> Option { /*! * Returns the id of the current top-most AST scope, if any. @@ -496,8 +496,8 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> { } fn trans_scope_cleanups(&self, // cannot borrow self, will recurse - bcx: &'a Block<'a>, - scope: &CleanupScope) -> &'a Block<'a> { + bcx: Block<'blk, 'tcx>, + scope: &CleanupScope) -> Block<'blk, 'tcx> { /*! Generates the cleanups for `scope` into `bcx` */ let mut bcx = bcx; @@ -513,11 +513,11 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> { self.scopes.borrow().len() } - fn push_scope(&self, scope: CleanupScope<'a>) { + fn push_scope(&self, scope: CleanupScope<'blk, 'tcx>) { self.scopes.borrow_mut().push(scope) } - fn pop_scope(&self) -> CleanupScope<'a> { + fn pop_scope(&self) -> CleanupScope<'blk, 'tcx> { debug!("popping cleanup scope {}, {} scopes remaining", self.top_scope(|s| s.block_name("")), self.scopes_len() - 1); @@ -525,11 +525,11 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> { self.scopes.borrow_mut().pop().unwrap() } - fn top_scope(&self, f: |&CleanupScope<'a>| -> R) -> R { + fn top_scope(&self, f: |&CleanupScope<'blk, 'tcx>| -> R) -> R { f(self.scopes.borrow().last().unwrap()) } - fn trans_cleanups_to_exit_scope(&'a self, + fn trans_cleanups_to_exit_scope(&'blk self, label: EarlyExitLabel) -> BasicBlockRef { /*! @@ -691,7 +691,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> { prev_llbb } - fn get_or_create_landing_pad(&'a self) -> BasicBlockRef { + fn get_or_create_landing_pad(&'blk self) -> BasicBlockRef { /*! * Creates a landing pad for the top scope, if one does not * exist. The landing pad will perform all cleanups necessary @@ -784,8 +784,8 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> { } } -impl<'a> CleanupScope<'a> { - fn new(kind: CleanupScopeKind<'a>) -> CleanupScope<'a> { +impl<'blk, 'tcx> CleanupScope<'blk, 'tcx> { + fn new(kind: CleanupScopeKind<'blk, 'tcx>) -> CleanupScope<'blk, 'tcx> { CleanupScope { kind: kind, cleanups: vec!(), @@ -836,7 +836,7 @@ impl<'a> CleanupScope<'a> { } } -impl<'a> CleanupScopeKind<'a> { +impl<'blk, 'tcx> CleanupScopeKind<'blk, 'tcx> { fn is_temp(&self) -> bool { match *self { CustomScopeKind => true, @@ -902,7 +902,7 @@ impl Cleanup for DropValue { self.must_unwind } - fn trans<'a>(&self, bcx: &'a Block<'a>) -> &'a Block<'a> { + fn trans<'blk, 'tcx>(&self, bcx: Block<'blk, 'tcx>) -> Block<'blk, 'tcx> { let bcx = if self.is_immediate { glue::drop_ty_immediate(bcx, self.val, self.ty) } else { @@ -935,7 +935,7 @@ impl Cleanup for FreeValue { true } - fn trans<'a>(&self, bcx: &'a Block<'a>) -> &'a Block<'a> { + fn trans<'blk, 'tcx>(&self, bcx: Block<'blk, 'tcx>) -> Block<'blk, 'tcx> { match self.heap { HeapManaged => { glue::trans_free(bcx, self.ptr) @@ -963,7 +963,7 @@ impl Cleanup for FreeSlice { true } - fn trans<'a>(&self, bcx: &'a Block<'a>) -> &'a Block<'a> { + fn trans<'blk, 'tcx>(&self, bcx: Block<'blk, 'tcx>) -> Block<'blk, 'tcx> { match self.heap { HeapManaged => { glue::trans_free(bcx, self.ptr) @@ -988,7 +988,7 @@ impl Cleanup for LifetimeEnd { true } - fn trans<'a>(&self, bcx: &'a Block<'a>) -> &'a Block<'a> { + fn trans<'blk, 'tcx>(&self, bcx: Block<'blk, 'tcx>) -> Block<'blk, 'tcx> { base::call_lifetime_end(bcx, self.ptr); bcx } @@ -1026,29 +1026,29 @@ fn cleanup_is_suitable_for(c: &Cleanup, /////////////////////////////////////////////////////////////////////////// // These traits just exist to put the methods into this file. -pub trait CleanupMethods<'a> { +pub trait CleanupMethods<'blk, 'tcx> { fn push_ast_cleanup_scope(&self, id: ast::NodeId); fn push_loop_cleanup_scope(&self, id: ast::NodeId, - exits: [&'a Block<'a>, ..EXIT_MAX]); + exits: [Block<'blk, 'tcx>, ..EXIT_MAX]); fn push_custom_cleanup_scope(&self) -> CustomScopeIndex; fn pop_and_trans_ast_cleanup_scope(&self, - bcx: &'a Block<'a>, + bcx: Block<'blk, 'tcx>, cleanup_scope: ast::NodeId) - -> &'a Block<'a>; + -> Block<'blk, 'tcx>; fn pop_loop_cleanup_scope(&self, cleanup_scope: ast::NodeId); fn pop_custom_cleanup_scope(&self, custom_scope: CustomScopeIndex); fn pop_and_trans_custom_cleanup_scope(&self, - bcx: &'a Block<'a>, + bcx: Block<'blk, 'tcx>, custom_scope: CustomScopeIndex) - -> &'a Block<'a>; + -> Block<'blk, 'tcx>; fn top_loop_scope(&self) -> ast::NodeId; - fn normal_exit_block(&'a self, + fn normal_exit_block(&'blk self, cleanup_scope: ast::NodeId, exit: uint) -> BasicBlockRef; - fn return_exit_block(&'a self) -> BasicBlockRef; + fn return_exit_block(&'blk self) -> BasicBlockRef; fn schedule_lifetime_end(&self, cleanup_scope: ScopeId, val: ValueRef); @@ -1085,23 +1085,23 @@ pub trait CleanupMethods<'a> { custom_scope: CustomScopeIndex, cleanup: CleanupObj); fn needs_invoke(&self) -> bool; - fn get_landing_pad(&'a self) -> BasicBlockRef; + fn get_landing_pad(&'blk self) -> BasicBlockRef; } -trait CleanupHelperMethods<'a> { +trait CleanupHelperMethods<'blk, 'tcx> { fn top_ast_scope(&self) -> Option; fn top_nonempty_cleanup_scope(&self) -> Option; fn is_valid_to_pop_custom_scope(&self, custom_scope: CustomScopeIndex) -> bool; fn is_valid_custom_scope(&self, custom_scope: CustomScopeIndex) -> bool; fn trans_scope_cleanups(&self, - bcx: &'a Block<'a>, - scope: &CleanupScope<'a>) -> &'a Block<'a>; - fn trans_cleanups_to_exit_scope(&'a self, + bcx: Block<'blk, 'tcx>, + scope: &CleanupScope<'blk, 'tcx>) -> Block<'blk, 'tcx>; + fn trans_cleanups_to_exit_scope(&'blk self, label: EarlyExitLabel) -> BasicBlockRef; - fn get_or_create_landing_pad(&'a self) -> BasicBlockRef; + fn get_or_create_landing_pad(&'blk self) -> BasicBlockRef; fn scopes_len(&self) -> uint; - fn push_scope(&self, scope: CleanupScope<'a>); - fn pop_scope(&self) -> CleanupScope<'a>; - fn top_scope(&self, f: |&CleanupScope<'a>| -> R) -> R; + fn push_scope(&self, scope: CleanupScope<'blk, 'tcx>); + fn pop_scope(&self) -> CleanupScope<'blk, 'tcx>; + fn top_scope(&self, f: |&CleanupScope<'blk, 'tcx>| -> R) -> R; } diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs index b90ac39cf1d28..7bbdf332fe11f 100644 --- a/src/librustc/middle/trans/closure.rs +++ b/src/librustc/middle/trans/closure.rs @@ -135,10 +135,10 @@ fn tuplify_box_ty(tcx: &ty::ctxt, t: ty::t) -> ty::t { ty::mk_tup(tcx, vec!(ty::mk_uint(), ty::mk_nil_ptr(tcx), ptr, ptr, t)) } -fn allocate_cbox<'a>(bcx: &'a Block<'a>, - store: ty::TraitStore, - cdata_ty: ty::t) - -> Result<'a> { +fn allocate_cbox<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + store: ty::TraitStore, + cdata_ty: ty::t) + -> Result<'blk, 'tcx> { let _icx = push_ctxt("closure::allocate_cbox"); let tcx = bcx.tcx(); @@ -155,21 +155,20 @@ fn allocate_cbox<'a>(bcx: &'a Block<'a>, } } -pub struct ClosureResult<'a> { +pub struct ClosureResult<'blk, 'tcx: 'blk> { llbox: ValueRef, // llvalue of ptr to closure cdata_ty: ty::t, // type of the closure data - bcx: &'a Block<'a> // final bcx + bcx: Block<'blk, 'tcx> // final bcx } // Given a block context and a list of tydescs and values to bind // construct a closure out of them. If copying is true, it is a // heap allocated closure that copies the upvars into environment. // Otherwise, it is stack allocated and copies pointers to the upvars. -pub fn store_environment<'a>( - bcx: &'a Block<'a>, - bound_values: Vec , - store: ty::TraitStore) - -> ClosureResult<'a> { +pub fn store_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + bound_values: Vec , + store: ty::TraitStore) + -> ClosureResult<'blk, 'tcx> { let _icx = push_ctxt("closure::store_environment"); let ccx = bcx.ccx(); let tcx = ccx.tcx(); @@ -224,12 +223,11 @@ pub fn store_environment<'a>( // Given a context and a list of upvars, build a closure. This just // collects the upvars and packages them up for store_environment. -fn build_closure<'a>(bcx0: &'a Block<'a>, - freevar_mode: freevars::CaptureMode, - freevars: &Vec, - store: ty::TraitStore) - -> ClosureResult<'a> -{ +fn build_closure<'blk, 'tcx>(bcx0: Block<'blk, 'tcx>, + freevar_mode: freevars::CaptureMode, + freevars: &Vec, + store: ty::TraitStore) + -> ClosureResult<'blk, 'tcx> { let _icx = push_ctxt("closure::build_closure"); // If we need to, package up the iterator body to call @@ -248,11 +246,11 @@ fn build_closure<'a>(bcx0: &'a Block<'a>, // Given an enclosing block context, a new function context, a closure type, // and a list of upvars, generate code to load and populate the environment // with the upvars and type descriptors. -fn load_environment<'a>(bcx: &'a Block<'a>, - cdata_ty: ty::t, - freevars: &Vec, - store: ty::TraitStore) - -> &'a Block<'a> { +fn load_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + cdata_ty: ty::t, + freevars: &Vec, + store: ty::TraitStore) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("closure::load_environment"); // Don't bother to create the block if there's nothing to load @@ -301,12 +299,12 @@ fn load_environment<'a>(bcx: &'a Block<'a>, bcx } -fn load_unboxed_closure_environment<'a>( - bcx: &'a Block<'a>, +fn load_unboxed_closure_environment<'blk, 'tcx>( + bcx: Block<'blk, 'tcx>, arg_scope_id: ScopeId, freevars: &Vec, closure_id: ast::DefId) - -> &'a Block<'a> { + -> Block<'blk, 'tcx> { let _icx = push_ctxt("closure::load_environment"); if freevars.len() == 0 { @@ -343,20 +341,19 @@ fn load_unboxed_closure_environment<'a>( bcx } -fn fill_fn_pair(bcx: &Block, pair: ValueRef, llfn: ValueRef, llenvptr: ValueRef) { +fn fill_fn_pair(bcx: Block, pair: ValueRef, llfn: ValueRef, llenvptr: ValueRef) { Store(bcx, llfn, GEPi(bcx, pair, [0u, abi::fn_field_code])); let llenvptr = PointerCast(bcx, llenvptr, Type::i8p(bcx.ccx())); Store(bcx, llenvptr, GEPi(bcx, pair, [0u, abi::fn_field_box])); } -pub fn trans_expr_fn<'a>( - bcx: &'a Block<'a>, - store: ty::TraitStore, - decl: &ast::FnDecl, - body: &ast::Block, - id: ast::NodeId, - dest: expr::Dest) - -> &'a Block<'a> { +pub fn trans_expr_fn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + store: ty::TraitStore, + decl: &ast::FnDecl, + body: &ast::Block, + id: ast::NodeId, + dest: expr::Dest) + -> Block<'blk, 'tcx> { /*! * * Translates the body of a closure expression. @@ -458,13 +455,13 @@ pub fn get_or_create_declaration_if_unboxed_closure(ccx: &CrateContext, Some(llfn) } -pub fn trans_unboxed_closure<'a>( - mut bcx: &'a Block<'a>, +pub fn trans_unboxed_closure<'blk, 'tcx>( + mut bcx: Block<'blk, 'tcx>, decl: &ast::FnDecl, body: &ast::Block, id: ast::NodeId, dest: expr::Dest) - -> &'a Block<'a> { + -> Block<'blk, 'tcx> { let _icx = push_ctxt("closure::trans_unboxed_closure"); debug!("trans_unboxed_closure()"); @@ -620,11 +617,11 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext, llfn } -pub fn make_closure_from_bare_fn<'a>(bcx: &'a Block<'a>, - closure_ty: ty::t, - def: def::Def, - fn_ptr: ValueRef) - -> DatumBlock<'a, Expr> { +pub fn make_closure_from_bare_fn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + closure_ty: ty::t, + def: def::Def, + fn_ptr: ValueRef) + -> DatumBlock<'blk, 'tcx, Expr> { let scratch = rvalue_scratch_datum(bcx, closure_ty, "__adjust"); let wrapper = get_wrapper_for_bare_fn(bcx.ccx(), closure_ty, def, fn_ptr, true); fill_fn_pair(bcx, scratch.val, wrapper, C_null(Type::i8p(bcx.ccx()))); diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 4ea60a4e128ad..4ac9ae64d5a08 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -233,7 +233,7 @@ pub type LvalueDatum = datum::Datum; // Function context. Every LLVM function we create will have one of // these. -pub struct FunctionContext<'a> { +pub struct FunctionContext<'a, 'tcx: 'a> { // The ValueRef returned from a call to llvm::LLVMAddFunction; the // address of the first instruction in the sequence of // instructions for this function that will go in the .text @@ -294,19 +294,19 @@ pub struct FunctionContext<'a> { pub span: Option, // The arena that blocks are allocated from. - pub block_arena: &'a TypedArena>, + pub block_arena: &'a TypedArena>, // This function's enclosing crate context. - pub ccx: &'a CrateContext<'a>, + pub ccx: &'a CrateContext<'a, 'tcx>, // Used and maintained by the debuginfo module. pub debug_context: debuginfo::FunctionDebugContext, // Cleanup scopes. - pub scopes: RefCell> >, + pub scopes: RefCell>>, } -impl<'a> FunctionContext<'a> { +impl<'a, 'tcx> FunctionContext<'a, 'tcx> { pub fn arg_pos(&self, arg: uint) -> uint { let arg = self.env_arg_pos() + arg; if self.llenv.is_some() { @@ -350,7 +350,7 @@ impl<'a> FunctionContext<'a> { self.llreturn.get().unwrap() } - pub fn get_ret_slot(&self, bcx: &Block, ty: ty::t, name: &str) -> ValueRef { + pub fn get_ret_slot(&self, bcx: Block, ty: ty::t, name: &str) -> ValueRef { if self.needs_ret_allocas { base::alloca_no_lifetime(bcx, type_of::type_of(bcx.ccx(), ty), name) } else { @@ -362,34 +362,34 @@ impl<'a> FunctionContext<'a> { is_lpad: bool, name: &str, opt_node_id: Option) - -> &'a Block<'a> { + -> Block<'a, 'tcx> { unsafe { let llbb = name.with_c_str(|buf| { llvm::LLVMAppendBasicBlockInContext(self.ccx.llcx(), self.llfn, buf) }); - Block::new(llbb, is_lpad, opt_node_id, self) + BlockS::new(llbb, is_lpad, opt_node_id, self) } } pub fn new_id_block(&'a self, name: &str, node_id: ast::NodeId) - -> &'a Block<'a> { + -> Block<'a, 'tcx> { self.new_block(false, name, Some(node_id)) } pub fn new_temp_block(&'a self, name: &str) - -> &'a Block<'a> { + -> Block<'a, 'tcx> { self.new_block(false, name, None) } pub fn join_blocks(&'a self, id: ast::NodeId, - in_cxs: &[&'a Block<'a>]) - -> &'a Block<'a> { + in_cxs: &[Block<'a, 'tcx>]) + -> Block<'a, 'tcx> { let out = self.new_id_block("join", id); let mut reachable = false; for bcx in in_cxs.iter() { @@ -410,7 +410,7 @@ impl<'a> FunctionContext<'a> { // code. Each basic block we generate is attached to a function, typically // with many basic blocks per function. All the basic blocks attached to a // function are organized as a directed graph. -pub struct Block<'a> { +pub struct BlockS<'blk, 'tcx: 'blk> { // The BasicBlockRef returned from a call to // llvm::LLVMAppendBasicBlock(llfn, name), which adds a basic // block to the function pointed to by llfn. We insert @@ -429,17 +429,18 @@ pub struct Block<'a> { // The function context for the function to which this block is // attached. - pub fcx: &'a FunctionContext<'a>, + pub fcx: &'blk FunctionContext<'blk, 'tcx>, } -impl<'a> Block<'a> { - pub fn new<'a>( - llbb: BasicBlockRef, +pub type Block<'blk, 'tcx> = &'blk BlockS<'blk, 'tcx>; + +impl<'blk, 'tcx> BlockS<'blk, 'tcx> { + pub fn new(llbb: BasicBlockRef, is_lpad: bool, opt_node_id: Option, - fcx: &'a FunctionContext<'a>) - -> &'a Block<'a> { - fcx.block_arena.alloc(Block { + fcx: &'blk FunctionContext<'blk, 'tcx>) + -> Block<'blk, 'tcx> { + fcx.block_arena.alloc(BlockS { llbb: llbb, terminated: Cell::new(false), unreachable: Cell::new(false), @@ -449,11 +450,13 @@ impl<'a> Block<'a> { }) } - pub fn ccx(&self) -> &'a CrateContext<'a> { self.fcx.ccx } - pub fn tcx(&self) -> &'a ty::ctxt { + pub fn ccx(&self) -> &'blk CrateContext<'blk, 'tcx> { + self.fcx.ccx + } + pub fn tcx(&self) -> &'blk ty::ctxt<'tcx> { self.fcx.ccx.tcx() } - pub fn sess(&self) -> &'a Session { self.fcx.ccx.sess() } + pub fn sess(&self) -> &'blk Session { self.fcx.ccx.sess() } pub fn ident(&self, ident: Ident) -> String { token::get_ident(ident).get().to_string() @@ -490,13 +493,12 @@ impl<'a> Block<'a> { } pub fn to_str(&self) -> String { - let blk: *const Block = self; - format!("[block {}]", blk) + format!("[block {:p}]", self) } } -impl<'a> mc::Typer for Block<'a> { - fn tcx<'a>(&'a self) -> &'a ty::ctxt { +impl<'blk, 'tcx> mc::Typer<'tcx> for BlockS<'blk, 'tcx> { + fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.tcx() } @@ -535,13 +537,13 @@ impl<'a> mc::Typer for Block<'a> { } } -pub struct Result<'a> { - pub bcx: &'a Block<'a>, +pub struct Result<'blk, 'tcx: 'blk> { + pub bcx: Block<'blk, 'tcx>, pub val: ValueRef } -impl<'a> Result<'a> { - pub fn new(bcx: &'a Block<'a>, val: ValueRef) -> Result<'a> { +impl<'b, 'tcx> Result<'b, 'tcx> { + pub fn new(bcx: Block<'b, 'tcx>, val: ValueRef) -> Result<'b, 'tcx> { Result { bcx: bcx, val: val, @@ -746,21 +748,21 @@ pub fn is_null(val: ValueRef) -> bool { } } -pub fn monomorphize_type(bcx: &Block, t: ty::t) -> ty::t { +pub fn monomorphize_type(bcx: &BlockS, t: ty::t) -> ty::t { t.subst(bcx.tcx(), &bcx.fcx.param_substs.substs) } -pub fn node_id_type(bcx: &Block, id: ast::NodeId) -> ty::t { +pub fn node_id_type(bcx: &BlockS, id: ast::NodeId) -> ty::t { let tcx = bcx.tcx(); let t = ty::node_id_to_type(tcx, id); monomorphize_type(bcx, t) } -pub fn expr_ty(bcx: &Block, ex: &ast::Expr) -> ty::t { +pub fn expr_ty(bcx: Block, ex: &ast::Expr) -> ty::t { node_id_type(bcx, ex.id) } -pub fn expr_ty_adjusted(bcx: &Block, ex: &ast::Expr) -> ty::t { +pub fn expr_ty_adjusted(bcx: Block, ex: &ast::Expr) -> ty::t { monomorphize_type(bcx, ty::expr_ty_adjusted(bcx.tcx(), ex)) } @@ -774,7 +776,7 @@ pub enum ExprOrMethodCall { MethodCall(typeck::MethodCall) } -pub fn node_id_substs(bcx: &Block, +pub fn node_id_substs(bcx: Block, node: ExprOrMethodCall) -> subst::Substs { let tcx = bcx.tcx(); @@ -799,7 +801,7 @@ pub fn node_id_substs(bcx: &Block, substs.substp(tcx, bcx.fcx.param_substs) } -pub fn node_vtables(bcx: &Block, id: typeck::MethodCall) +pub fn node_vtables(bcx: Block, id: typeck::MethodCall) -> typeck::vtable_res { bcx.tcx().vtable_map.borrow().find(&id).map(|vts| { resolve_vtables_in_fn_ctxt(bcx.fcx, vts) @@ -877,7 +879,7 @@ pub fn find_vtable(tcx: &ty::ctxt, param_bounds.get(n_bound).clone() } -pub fn langcall(bcx: &Block, +pub fn langcall(bcx: Block, span: Option, msg: &str, li: LangItem) diff --git a/src/librustc/middle/trans/context.rs b/src/librustc/middle/trans/context.rs index 5bdd5f6739d61..3b4b50c7e85ac 100644 --- a/src/librustc/middle/trans/context.rs +++ b/src/librustc/middle/trans/context.rs @@ -55,7 +55,7 @@ pub struct Stats { /// per crate. The data here is shared between all compilation units of the /// crate, so it must not contain references to any LLVM data structures /// (aside from metadata-related ones). -pub struct SharedCrateContext { +pub struct SharedCrateContext<'tcx> { local_ccxs: Vec, metadata_llmod: ModuleRef, @@ -70,7 +70,7 @@ pub struct SharedCrateContext { /// that is generated non_inlineable_statics: RefCell, symbol_hasher: RefCell, - tcx: ty::ctxt, + tcx: ty::ctxt<'tcx>, stats: Stats, available_monomorphizations: RefCell>, @@ -152,21 +152,21 @@ pub struct LocalCrateContext { n_llvm_insns: Cell, } -pub struct CrateContext<'a> { - shared: &'a SharedCrateContext, +pub struct CrateContext<'a, 'tcx: 'a> { + shared: &'a SharedCrateContext<'tcx>, local: &'a LocalCrateContext, /// The index of `local` in `shared.local_ccxs`. This is used in /// `maybe_iter(true)` to identify the original `LocalCrateContext`. index: uint, } -pub struct CrateContextIterator<'a> { - shared: &'a SharedCrateContext, +pub struct CrateContextIterator<'a, 'tcx: 'a> { + shared: &'a SharedCrateContext<'tcx>, index: uint, } -impl<'a> Iterator> for CrateContextIterator<'a> { - fn next(&mut self) -> Option> { +impl<'a, 'tcx> Iterator> for CrateContextIterator<'a,'tcx> { + fn next(&mut self) -> Option> { if self.index >= self.shared.local_ccxs.len() { return None; } @@ -183,15 +183,15 @@ impl<'a> Iterator> for CrateContextIterator<'a> { } /// The iterator produced by `CrateContext::maybe_iter`. -pub struct CrateContextMaybeIterator<'a> { - shared: &'a SharedCrateContext, +pub struct CrateContextMaybeIterator<'a, 'tcx: 'a> { + shared: &'a SharedCrateContext<'tcx>, index: uint, single: bool, origin: uint, } -impl<'a> Iterator<(CrateContext<'a>, bool)> for CrateContextMaybeIterator<'a> { - fn next(&mut self) -> Option<(CrateContext<'a>, bool)> { +impl<'a, 'tcx> Iterator<(CrateContext<'a, 'tcx>, bool)> for CrateContextMaybeIterator<'a, 'tcx> { + fn next(&mut self) -> Option<(CrateContext<'a, 'tcx>, bool)> { if self.index >= self.shared.local_ccxs.len() { return None; } @@ -234,15 +234,15 @@ unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextR (llcx, llmod) } -impl SharedCrateContext { +impl<'tcx> SharedCrateContext<'tcx> { pub fn new(crate_name: &str, local_count: uint, - tcx: ty::ctxt, + tcx: ty::ctxt<'tcx>, emap2: resolve::ExportMap2, symbol_hasher: Sha256, link_meta: LinkMeta, reachable: NodeSet) - -> SharedCrateContext { + -> SharedCrateContext<'tcx> { let (metadata_llcx, metadata_llmod) = unsafe { create_context_and_module(&tcx.sess, "metadata") }; @@ -293,14 +293,14 @@ impl SharedCrateContext { shared_ccx } - pub fn iter<'a>(&'a self) -> CrateContextIterator<'a> { + pub fn iter<'a>(&'a self) -> CrateContextIterator<'a, 'tcx> { CrateContextIterator { shared: self, index: 0, } } - pub fn get_ccx<'a>(&'a self, index: uint) -> CrateContext<'a> { + pub fn get_ccx<'a>(&'a self, index: uint) -> CrateContext<'a, 'tcx> { CrateContext { shared: self, local: &self.local_ccxs[index], @@ -308,7 +308,7 @@ impl SharedCrateContext { } } - fn get_smallest_ccx<'a>(&'a self) -> CrateContext<'a> { + fn get_smallest_ccx<'a>(&'a self) -> CrateContext<'a, 'tcx> { let (local_ccx, index) = self.local_ccxs .iter() @@ -355,11 +355,11 @@ impl SharedCrateContext { &self.symbol_hasher } - pub fn tcx<'a>(&'a self) -> &'a ty::ctxt { + pub fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { &self.tcx } - pub fn take_tcx(self) -> ty::ctxt { + pub fn take_tcx(self) -> ty::ctxt<'tcx> { self.tcx } @@ -459,7 +459,8 @@ impl LocalCrateContext { /// This is used in the `LocalCrateContext` constructor to allow calling /// functions that expect a complete `CrateContext`, even before the local /// portion is fully initialized and attached to the `SharedCrateContext`. - fn dummy_ccx<'a>(&'a self, shared: &'a SharedCrateContext) -> CrateContext<'a> { + fn dummy_ccx<'a, 'tcx>(&'a self, shared: &'a SharedCrateContext<'tcx>) + -> CrateContext<'a, 'tcx> { CrateContext { shared: shared, local: self, @@ -468,8 +469,8 @@ impl LocalCrateContext { } } -impl<'b> CrateContext<'b> { - pub fn shared(&self) -> &'b SharedCrateContext { +impl<'b, 'tcx> CrateContext<'b, 'tcx> { + pub fn shared(&self) -> &'b SharedCrateContext<'tcx> { self.shared } @@ -480,7 +481,7 @@ impl<'b> CrateContext<'b> { /// Get a (possibly) different `CrateContext` from the same /// `SharedCrateContext`. - pub fn rotate(&self) -> CrateContext<'b> { + pub fn rotate(&self) -> CrateContext<'b, 'tcx> { self.shared.get_smallest_ccx() } @@ -490,7 +491,7 @@ impl<'b> CrateContext<'b> { /// otherwise. This method is useful for avoiding code duplication in /// cases where it may or may not be necessary to translate code into every /// context. - pub fn maybe_iter(&self, iter_all: bool) -> CrateContextMaybeIterator<'b> { + pub fn maybe_iter(&self, iter_all: bool) -> CrateContextMaybeIterator<'b, 'tcx> { CrateContextMaybeIterator { shared: self.shared, index: if iter_all { 0 } else { self.index }, @@ -500,7 +501,7 @@ impl<'b> CrateContext<'b> { } - pub fn tcx<'a>(&'a self) -> &'a ty::ctxt { + pub fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { &self.shared.tcx } @@ -508,7 +509,7 @@ impl<'b> CrateContext<'b> { &self.shared.tcx.sess } - pub fn builder<'a>(&'a self) -> Builder<'a> { + pub fn builder<'a>(&'a self) -> Builder<'a, 'tcx> { Builder::new(self) } diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index 9ec5234134817..dd9e41a61bf87 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -41,9 +41,9 @@ use syntax::visit::Visitor; use std::gc::Gc; -pub fn trans_stmt<'a>(cx: &'a Block<'a>, - s: &ast::Stmt) - -> &'a Block<'a> { +pub fn trans_stmt<'blk, 'tcx>(cx: Block<'blk, 'tcx>, + s: &ast::Stmt) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_stmt"); let fcx = cx.fcx; debug!("trans_stmt({})", s.repr(cx.tcx())); @@ -83,7 +83,8 @@ pub fn trans_stmt<'a>(cx: &'a Block<'a>, return bcx; } -pub fn trans_stmt_semi<'a>(cx: &'a Block<'a>, e: &ast::Expr) -> &'a Block<'a> { +pub fn trans_stmt_semi<'blk, 'tcx>(cx: Block<'blk, 'tcx>, e: &ast::Expr) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_stmt_semi"); let ty = expr_ty(cx, e); if ty::type_needs_drop(cx.tcx(), ty) { @@ -93,10 +94,10 @@ pub fn trans_stmt_semi<'a>(cx: &'a Block<'a>, e: &ast::Expr) -> &'a Block<'a> { } } -pub fn trans_block<'a>(bcx: &'a Block<'a>, - b: &ast::Block, - mut dest: expr::Dest) - -> &'a Block<'a> { +pub fn trans_block<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + b: &ast::Block, + mut dest: expr::Dest) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_block"); let fcx = bcx.fcx; let mut bcx = bcx; @@ -128,13 +129,13 @@ pub fn trans_block<'a>(bcx: &'a Block<'a>, return bcx; } -pub fn trans_if<'a>(bcx: &'a Block<'a>, - if_id: ast::NodeId, - cond: &ast::Expr, - thn: ast::P, - els: Option>, - dest: expr::Dest) - -> &'a Block<'a> { +pub fn trans_if<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + if_id: ast::NodeId, + cond: &ast::Expr, + thn: ast::P, + els: Option>, + dest: expr::Dest) + -> Block<'blk, 'tcx> { debug!("trans_if(bcx={}, if_id={}, cond={}, thn={:?}, dest={})", bcx.to_str(), if_id, bcx.expr_to_string(cond), thn.id, dest.to_string(bcx.ccx())); @@ -204,11 +205,11 @@ pub fn trans_if<'a>(bcx: &'a Block<'a>, next_bcx } -pub fn trans_while<'a>(bcx: &'a Block<'a>, - loop_id: ast::NodeId, - cond: &ast::Expr, - body: &ast::Block) - -> &'a Block<'a> { +pub fn trans_while<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + loop_id: ast::NodeId, + cond: &ast::Expr, + body: &ast::Block) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_while"); let fcx = bcx.fcx; @@ -248,13 +249,12 @@ pub fn trans_while<'a>(bcx: &'a Block<'a>, } /// Translates a `for` loop. -pub fn trans_for<'a>( - mut bcx: &'a Block<'a>, - loop_info: NodeInfo, - pat: Gc, - head: &ast::Expr, - body: &ast::Block) - -> &'a Block<'a> { +pub fn trans_for<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, + loop_info: NodeInfo, + pat: Gc, + head: &ast::Expr, + body: &ast::Block) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_for"); // bcx @@ -369,10 +369,10 @@ pub fn trans_for<'a>( next_bcx_in } -pub fn trans_loop<'a>(bcx:&'a Block<'a>, - loop_id: ast::NodeId, - body: &ast::Block) - -> &'a Block<'a> { +pub fn trans_loop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + loop_id: ast::NodeId, + body: &ast::Block) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_loop"); let fcx = bcx.fcx; @@ -405,11 +405,11 @@ pub fn trans_loop<'a>(bcx:&'a Block<'a>, return next_bcx_in; } -pub fn trans_break_cont<'a>(bcx: &'a Block<'a>, - expr_id: ast::NodeId, - opt_label: Option, - exit: uint) - -> &'a Block<'a> { +pub fn trans_break_cont<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr_id: ast::NodeId, + opt_label: Option, + exit: uint) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_break_cont"); let fcx = bcx.fcx; @@ -438,23 +438,23 @@ pub fn trans_break_cont<'a>(bcx: &'a Block<'a>, return bcx; } -pub fn trans_break<'a>(bcx: &'a Block<'a>, - expr_id: ast::NodeId, - label_opt: Option) - -> &'a Block<'a> { +pub fn trans_break<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr_id: ast::NodeId, + label_opt: Option) + -> Block<'blk, 'tcx> { return trans_break_cont(bcx, expr_id, label_opt, cleanup::EXIT_BREAK); } -pub fn trans_cont<'a>(bcx: &'a Block<'a>, - expr_id: ast::NodeId, - label_opt: Option) - -> &'a Block<'a> { +pub fn trans_cont<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr_id: ast::NodeId, + label_opt: Option) + -> Block<'blk, 'tcx> { return trans_break_cont(bcx, expr_id, label_opt, cleanup::EXIT_LOOP); } -pub fn trans_ret<'a>(bcx: &'a Block<'a>, - e: Option>) - -> &'a Block<'a> { +pub fn trans_ret<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + e: Option>) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_ret"); let fcx = bcx.fcx; let mut bcx = bcx; @@ -483,11 +483,10 @@ pub fn trans_ret<'a>(bcx: &'a Block<'a>, return bcx; } -pub fn trans_fail<'a>( - bcx: &'a Block<'a>, - sp: Span, - fail_str: InternedString) - -> &'a Block<'a> { +pub fn trans_fail<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + sp: Span, + fail_str: InternedString) + -> Block<'blk, 'tcx> { let ccx = bcx.ccx(); let _icx = push_ctxt("trans_fail_value"); @@ -508,12 +507,11 @@ pub fn trans_fail<'a>( return bcx; } -pub fn trans_fail_bounds_check<'a>( - bcx: &'a Block<'a>, - sp: Span, - index: ValueRef, - len: ValueRef) - -> &'a Block<'a> { +pub fn trans_fail_bounds_check<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + sp: Span, + index: ValueRef, + len: ValueRef) + -> Block<'blk, 'tcx> { let ccx = bcx.ccx(); let _icx = push_ctxt("trans_fail_bounds_check"); diff --git a/src/librustc/middle/trans/datum.rs b/src/librustc/middle/trans/datum.rs index 008af804a60ba..84d9f2cb740a3 100644 --- a/src/librustc/middle/trans/datum.rs +++ b/src/librustc/middle/trans/datum.rs @@ -47,8 +47,8 @@ pub struct Datum { pub kind: K, } -pub struct DatumBlock<'a, K> { - pub bcx: &'a Block<'a>, +pub struct DatumBlock<'blk, 'tcx: 'blk, K> { + pub bcx: Block<'blk, 'tcx>, pub datum: Datum, } @@ -94,23 +94,23 @@ pub fn immediate_rvalue(val: ValueRef, ty: ty::t) -> Datum { return Datum::new(val, ty, Rvalue::new(ByValue)); } -pub fn immediate_rvalue_bcx<'a>(bcx: &'a Block<'a>, - val: ValueRef, - ty: ty::t) - -> DatumBlock<'a, Rvalue> { +pub fn immediate_rvalue_bcx<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + val: ValueRef, + ty: ty::t) + -> DatumBlock<'blk, 'tcx, Rvalue> { return DatumBlock::new(bcx, immediate_rvalue(val, ty)) } -pub fn lvalue_scratch_datum<'a, A>(bcx: &'a Block<'a>, - ty: ty::t, - name: &str, - zero: bool, - scope: cleanup::ScopeId, - arg: A, - populate: |A, &'a Block<'a>, ValueRef| - -> &'a Block<'a>) - -> DatumBlock<'a, Lvalue> { +pub fn lvalue_scratch_datum<'blk, 'tcx, A>(bcx: Block<'blk, 'tcx>, + ty: ty::t, + name: &str, + zero: bool, + scope: cleanup::ScopeId, + arg: A, + populate: |A, Block<'blk, 'tcx>, ValueRef| + -> Block<'blk, 'tcx>) + -> DatumBlock<'blk, 'tcx, Lvalue> { /*! * Allocates temporary space on the stack using alloca() and * returns a by-ref Datum pointing to it. The memory will be @@ -135,7 +135,7 @@ pub fn lvalue_scratch_datum<'a, A>(bcx: &'a Block<'a>, DatumBlock::new(bcx, Datum::new(scratch, ty, Lvalue)) } -pub fn rvalue_scratch_datum(bcx: &Block, +pub fn rvalue_scratch_datum(bcx: Block, ty: ty::t, name: &str) -> Datum { @@ -188,11 +188,11 @@ pub trait KindOps { * Take appropriate action after the value in `datum` has been * stored to a new location. */ - fn post_store<'a>(&self, - bcx: &'a Block<'a>, - val: ValueRef, - ty: ty::t) - -> &'a Block<'a>; + fn post_store<'blk, 'tcx>(&self, + bcx: Block<'blk, 'tcx>, + val: ValueRef, + ty: ty::t) + -> Block<'blk, 'tcx>; /** * True if this mode is a reference mode, meaning that the datum's @@ -208,11 +208,11 @@ pub trait KindOps { } impl KindOps for Rvalue { - fn post_store<'a>(&self, - bcx: &'a Block<'a>, - _val: ValueRef, - _ty: ty::t) - -> &'a Block<'a> { + fn post_store<'blk, 'tcx>(&self, + bcx: Block<'blk, 'tcx>, + _val: ValueRef, + _ty: ty::t) + -> Block<'blk, 'tcx> { // No cleanup is scheduled for an rvalue, so we don't have // to do anything after a move to cancel or duplicate it. bcx @@ -228,11 +228,11 @@ impl KindOps for Rvalue { } impl KindOps for Lvalue { - fn post_store<'a>(&self, - bcx: &'a Block<'a>, - val: ValueRef, - ty: ty::t) - -> &'a Block<'a> { + fn post_store<'blk, 'tcx>(&self, + bcx: Block<'blk, 'tcx>, + val: ValueRef, + ty: ty::t) + -> Block<'blk, 'tcx> { /*! * If an lvalue is moved, we must zero out the memory in which * it resides so as to cancel cleanup. If an @T lvalue is @@ -263,11 +263,11 @@ impl KindOps for Lvalue { } impl KindOps for Expr { - fn post_store<'a>(&self, - bcx: &'a Block<'a>, - val: ValueRef, - ty: ty::t) - -> &'a Block<'a> { + fn post_store<'blk, 'tcx>(&self, + bcx: Block<'blk, 'tcx>, + val: ValueRef, + ty: ty::t) + -> Block<'blk, 'tcx> { match *self { LvalueExpr => Lvalue.post_store(bcx, val, ty), RvalueExpr(ref r) => r.post_store(bcx, val, ty), @@ -302,11 +302,11 @@ impl Datum { self.val } - pub fn to_lvalue_datum_in_scope<'a>(self, - bcx: &'a Block<'a>, - name: &str, - scope: cleanup::ScopeId) - -> DatumBlock<'a, Lvalue> { + pub fn to_lvalue_datum_in_scope<'blk, 'tcx>(self, + bcx: Block<'blk, 'tcx>, + name: &str, + scope: cleanup::ScopeId) + -> DatumBlock<'blk, 'tcx, Lvalue> { /*! * Returns an lvalue datum (that is, a by ref datum with * cleanup scheduled). If `self` is not already an lvalue, @@ -328,7 +328,8 @@ impl Datum { } } - pub fn to_ref_datum<'a>(self, bcx: &'a Block<'a>) -> DatumBlock<'a, Rvalue> { + pub fn to_ref_datum<'blk, 'tcx>(self, bcx: Block<'blk, 'tcx>) + -> DatumBlock<'blk, 'tcx, Rvalue> { let mut bcx = bcx; match self.kind.mode { ByRef => DatumBlock::new(bcx, self), @@ -340,9 +341,9 @@ impl Datum { } } - pub fn to_appropriate_datum<'a>(self, - bcx: &'a Block<'a>) - -> DatumBlock<'a, Rvalue> { + pub fn to_appropriate_datum<'blk, 'tcx>(self, + bcx: Block<'blk, 'tcx>) + -> DatumBlock<'blk, 'tcx, Rvalue> { match self.appropriate_rvalue_mode(bcx.ccx()) { ByRef => { self.to_ref_datum(bcx) @@ -381,7 +382,7 @@ impl Datum { } #[allow(dead_code)] // potentially useful - pub fn assert_lvalue(self, bcx: &Block) -> Datum { + pub fn assert_lvalue(self, bcx: Block) -> Datum { /*! * Asserts that this datum *is* an lvalue and returns it. */ @@ -391,7 +392,7 @@ impl Datum { |_| bcx.sess().bug("assert_lvalue given rvalue")) } - pub fn assert_rvalue(self, bcx: &Block) -> Datum { + pub fn assert_rvalue(self, bcx: Block) -> Datum { /*! * Asserts that this datum *is* an lvalue and returns it. */ @@ -401,11 +402,11 @@ impl Datum { |r| r) } - pub fn store_to_dest<'a>(self, - bcx: &'a Block<'a>, - dest: expr::Dest, - expr_id: ast::NodeId) - -> &'a Block<'a> { + pub fn store_to_dest<'blk, 'tcx>(self, + bcx: Block<'blk, 'tcx>, + dest: expr::Dest, + expr_id: ast::NodeId) + -> Block<'blk, 'tcx> { match dest { expr::Ignore => { self.add_clean_if_rvalue(bcx, expr_id); @@ -417,9 +418,9 @@ impl Datum { } } - pub fn add_clean_if_rvalue<'a>(self, - bcx: &'a Block<'a>, - expr_id: ast::NodeId) { + pub fn add_clean_if_rvalue<'blk, 'tcx>(self, + bcx: Block<'blk, 'tcx>, + expr_id: ast::NodeId) { /*! * Arranges cleanup for `self` if it is an rvalue. Use when * you are done working with a value that may need drop. @@ -433,11 +434,11 @@ impl Datum { }) } - pub fn clean<'a>(self, - bcx: &'a Block<'a>, - name: &'static str, - expr_id: ast::NodeId) - -> &'a Block<'a> { + pub fn clean<'blk, 'tcx>(self, + bcx: Block<'blk, 'tcx>, + name: &'static str, + expr_id: ast::NodeId) + -> Block<'blk, 'tcx> { /*! * Ensures that `self` will get cleaned up, if it is not an lvalue * already. @@ -446,11 +447,11 @@ impl Datum { self.to_lvalue_datum(bcx, name, expr_id).bcx } - pub fn to_lvalue_datum<'a>(self, - bcx: &'a Block<'a>, - name: &str, - expr_id: ast::NodeId) - -> DatumBlock<'a, Lvalue> { + pub fn to_lvalue_datum<'blk, 'tcx>(self, + bcx: Block<'blk, 'tcx>, + name: &str, + expr_id: ast::NodeId) + -> DatumBlock<'blk, 'tcx, Lvalue> { debug!("to_lvalue_datum self: {}", self.to_string(bcx.ccx())); assert!(ty::lltype_is_sized(bcx.tcx(), self.ty), @@ -463,10 +464,10 @@ impl Datum { }) } - pub fn to_rvalue_datum<'a>(self, - bcx: &'a Block<'a>, - name: &'static str) - -> DatumBlock<'a, Rvalue> { + pub fn to_rvalue_datum<'blk, 'tcx>(self, + bcx: Block<'blk, 'tcx>, + name: &'static str) + -> DatumBlock<'blk, 'tcx, Rvalue> { /*! * Ensures that we have an rvalue datum (that is, a datum with * no cleanup scheduled). @@ -514,11 +515,9 @@ impl Datum { // datum may also be unsized _without the size information_. It is the // callers responsibility to package the result in some way to make a valid // datum in that case (e.g., by making a fat pointer or opened pair). - pub fn get_element<'a>(&self, - bcx: &'a Block<'a>, - ty: ty::t, - gep: |ValueRef| -> ValueRef) - -> Datum { + pub fn get_element(&self, bcx: Block, ty: ty::t, + gep: |ValueRef| -> ValueRef) + -> Datum { let val = match ty::get(self.ty).sty { _ if ty::type_is_sized(bcx.tcx(), self.ty) => gep(self.val), ty::ty_open(_) => { @@ -536,7 +535,7 @@ impl Datum { } } - pub fn get_vec_base_and_len<'a>(&self, bcx: &'a Block<'a>) -> (ValueRef, ValueRef) { + pub fn get_vec_base_and_len(&self, bcx: Block) -> (ValueRef, ValueRef) { //! Converts a vector into the slice pair. tvec::get_base_and_len(bcx, self.val, self.ty) @@ -556,10 +555,10 @@ impl Datum { Datum { val: val, ty: ty, kind: kind.to_expr_kind() } } - pub fn store_to<'a>(self, - bcx: &'a Block<'a>, - dst: ValueRef) - -> &'a Block<'a> { + pub fn store_to<'blk, 'tcx>(self, + bcx: Block<'blk, 'tcx>, + dst: ValueRef) + -> Block<'blk, 'tcx> { /*! * Moves or copies this value into a new home, as appropriate * depending on the type of the datum. This method consumes @@ -573,10 +572,10 @@ impl Datum { self.kind.post_store(bcx, self.val, self.ty) } - fn shallow_copy<'a>(&self, - bcx: &'a Block<'a>, - dst: ValueRef) - -> &'a Block<'a> { + fn shallow_copy<'blk, 'tcx>(&self, + bcx: Block<'blk, 'tcx>, + dst: ValueRef) + -> Block<'blk, 'tcx> { /*! * Helper function that performs a shallow copy of this value * into `dst`, which should be a pointer to a memory location @@ -606,10 +605,10 @@ impl Datum { return bcx; } - pub fn shallow_copy_and_take<'a>(&self, - bcx: &'a Block<'a>, - dst: ValueRef) - -> &'a Block<'a> { + pub fn shallow_copy_and_take<'blk, 'tcx>(&self, + bcx: Block<'blk, 'tcx>, + dst: ValueRef) + -> Block<'blk, 'tcx> { /*! * Copies the value into a new location and runs any necessary * take glue on the new location. This function always @@ -638,7 +637,7 @@ impl Datum { appropriate_rvalue_mode(ccx, self.ty) } - pub fn to_llscalarish<'a>(self, bcx: &'a Block<'a>) -> ValueRef { + pub fn to_llscalarish(self, bcx: Block) -> ValueRef { /*! * Converts `self` into a by-value `ValueRef`. Consumes this * datum (i.e., absolves you of responsibility to cleanup the @@ -657,33 +656,33 @@ impl Datum { } } - pub fn to_llbool<'a>(self, bcx: &'a Block<'a>) -> ValueRef { + pub fn to_llbool(self, bcx: Block) -> ValueRef { assert!(ty::type_is_bool(self.ty) || ty::type_is_bot(self.ty)) self.to_llscalarish(bcx) } } -impl <'a, K> DatumBlock<'a, K> { - pub fn new(bcx: &'a Block<'a>, datum: Datum) -> DatumBlock<'a, K> { +impl<'blk, 'tcx, K> DatumBlock<'blk, 'tcx, K> { + pub fn new(bcx: Block<'blk, 'tcx>, datum: Datum) -> DatumBlock<'blk, 'tcx, K> { DatumBlock { bcx: bcx, datum: datum } } } -impl<'a, K:KindOps> DatumBlock<'a, K> { - pub fn to_expr_datumblock(self) -> DatumBlock<'a, Expr> { +impl<'blk, 'tcx, K:KindOps> DatumBlock<'blk, 'tcx, K> { + pub fn to_expr_datumblock(self) -> DatumBlock<'blk, 'tcx, Expr> { DatumBlock::new(self.bcx, self.datum.to_expr_datum()) } } -impl<'a> DatumBlock<'a, Expr> { +impl<'blk, 'tcx> DatumBlock<'blk, 'tcx, Expr> { pub fn store_to_dest(self, dest: expr::Dest, - expr_id: ast::NodeId) -> &'a Block<'a> { + expr_id: ast::NodeId) -> Block<'blk, 'tcx> { let DatumBlock { bcx, datum } = self; datum.store_to_dest(bcx, dest, expr_id) } - pub fn to_llbool(self) -> Result<'a> { + pub fn to_llbool(self) -> Result<'blk, 'tcx> { let DatumBlock { datum, bcx } = self; Result::new(bcx, datum.to_llbool(bcx)) } diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 01633bea9565c..b640f9ef5af11 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -832,7 +832,7 @@ pub fn create_global_var_metadata(cx: &CrateContext, /// Creates debug information for the given local variable. /// /// Adds the created metadata nodes directly to the crate's IR. -pub fn create_local_var_metadata(bcx: &Block, local: &ast::Local) { +pub fn create_local_var_metadata(bcx: Block, local: &ast::Local) { if fn_should_be_ignored(bcx.fcx) { return; } @@ -867,7 +867,7 @@ pub fn create_local_var_metadata(bcx: &Block, local: &ast::Local) { /// Creates debug information for a variable captured in a closure. /// /// Adds the created metadata nodes directly to the crate's IR. -pub fn create_captured_var_metadata(bcx: &Block, +pub fn create_captured_var_metadata(bcx: Block, node_id: ast::NodeId, env_data_type: ty::t, env_pointer: ValueRef, @@ -954,7 +954,7 @@ pub fn create_captured_var_metadata(bcx: &Block, /// match-statement arm. /// /// Adds the created metadata nodes directly to the crate's IR. -pub fn create_match_binding_metadata(bcx: &Block, +pub fn create_match_binding_metadata(bcx: Block, variable_ident: ast::Ident, binding: BindingInfo) { if fn_should_be_ignored(bcx.fcx) { @@ -994,7 +994,7 @@ pub fn create_match_binding_metadata(bcx: &Block, /// Creates debug information for the given function argument. /// /// Adds the created metadata nodes directly to the crate's IR. -pub fn create_argument_metadata(bcx: &Block, arg: &ast::Arg) { +pub fn create_argument_metadata(bcx: Block, arg: &ast::Arg) { if fn_should_be_ignored(bcx.fcx) { return; } @@ -1518,7 +1518,7 @@ fn compile_unit_metadata(cx: &CrateContext) { } } -fn declare_local(bcx: &Block, +fn declare_local(bcx: Block, variable_ident: ast::Ident, variable_type: ty::t, scope_metadata: DIScope, diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 303594cba8f21..0421aef45ef9c 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -100,10 +100,10 @@ impl Dest { } } -pub fn trans_into<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr, - dest: Dest) - -> &'a Block<'a> { +pub fn trans_into<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + dest: Dest) + -> Block<'blk, 'tcx> { /*! * This function is equivalent to `trans(bcx, expr).store_to_dest(dest)` * but it may generate better optimized LLVM code. @@ -139,9 +139,9 @@ pub fn trans_into<'a>(bcx: &'a Block<'a>, bcx.fcx.pop_and_trans_ast_cleanup_scope(bcx, expr.id) } -pub fn trans<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr) - -> DatumBlock<'a, Expr> { +pub fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr) + -> DatumBlock<'blk, 'tcx, Expr> { /*! * Translates an expression, returning a datum (and new block) * encapsulating the result. When possible, it is preferred to @@ -161,18 +161,18 @@ pub fn trans<'a>(bcx: &'a Block<'a>, return DatumBlock::new(bcx, datum); } -pub fn get_len(bcx: &Block, fat_ptr: ValueRef) -> ValueRef { +pub fn get_len(bcx: Block, fat_ptr: ValueRef) -> ValueRef { GEPi(bcx, fat_ptr, [0u, abi::slice_elt_len]) } -pub fn get_dataptr(bcx: &Block, fat_ptr: ValueRef) -> ValueRef { +pub fn get_dataptr(bcx: Block, fat_ptr: ValueRef) -> ValueRef { GEPi(bcx, fat_ptr, [0u, abi::slice_elt_base]) } -fn apply_adjustments<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr, - datum: Datum) - -> DatumBlock<'a, Expr> { +fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + datum: Datum) + -> DatumBlock<'blk, 'tcx, Expr> { /*! * Helper for trans that apply adjustments from `expr` to `datum`, * which should be the unadjusted translation of `expr`. @@ -245,11 +245,11 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>, debug!("after adjustments, datum={}", datum.to_string(bcx.ccx())); return DatumBlock::new(bcx, datum); - fn apply_autoref<'a>(autoref: &ty::AutoRef, - bcx: &'a Block<'a>, - expr: &ast::Expr, - datum: Datum) - -> DatumBlock<'a, Expr> { + fn apply_autoref<'blk, 'tcx>(autoref: &ty::AutoRef, + bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + datum: Datum) + -> DatumBlock<'blk, 'tcx, Expr> { let mut bcx = bcx; let mut datum = datum; @@ -281,10 +281,10 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>, DatumBlock::new(bcx, datum) } - fn ref_ptr<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr, - datum: Datum) - -> DatumBlock<'a, Expr> { + fn ref_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + datum: Datum) + -> DatumBlock<'blk, 'tcx, Expr> { if !ty::type_is_sized(bcx.tcx(), datum.ty) { debug!("Taking address of unsized type {}", bcx.ty_to_string(datum.ty)); @@ -303,11 +303,11 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>, // into a type to be destructed. If we want to end up with a Box pointer, // then mk_ty should make a Box pointer (T -> Box), if we want a // borrowed reference then it should be T -> &T. - fn unsized_info<'a>(bcx: &'a Block<'a>, - kind: &ty::UnsizeKind, - id: ast::NodeId, - unsized_ty: ty::t, - mk_ty: |ty::t| -> ty::t) -> ValueRef { + fn unsized_info<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + kind: &ty::UnsizeKind, + id: ast::NodeId, + unsized_ty: ty::t, + mk_ty: |ty::t| -> ty::t) -> ValueRef { match kind { &ty::UnsizeLength(len) => C_uint(bcx.ccx(), len), &ty::UnsizeStruct(box ref k, tp_index) => match ty::get(unsized_ty).sty { @@ -327,11 +327,11 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>, } } - fn unsize_expr<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr, - datum: Datum, - k: &ty::UnsizeKind) - -> DatumBlock<'a, Expr> { + fn unsize_expr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + datum: Datum, + k: &ty::UnsizeKind) + -> DatumBlock<'blk, 'tcx, Expr> { let tcx = bcx.tcx(); let datum_ty = datum.ty; let unsized_ty = ty::unsize_ty(tcx, datum_ty, k, expr.span); @@ -361,10 +361,10 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>, into_fat_ptr(bcx, expr, datum, dest_ty, base, info) } - fn ref_fat_ptr<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr, - datum: Datum) - -> DatumBlock<'a, Expr> { + fn ref_fat_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + datum: Datum) + -> DatumBlock<'blk, 'tcx, Expr> { let tcx = bcx.tcx(); let dest_ty = ty::close_type(tcx, datum.ty); let base = |bcx, val| Load(bcx, get_dataptr(bcx, val)); @@ -372,13 +372,13 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>, into_fat_ptr(bcx, expr, datum, dest_ty, base, len) } - fn into_fat_ptr<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr, - datum: Datum, - dest_ty: ty::t, - base: |&'a Block<'a>, ValueRef| -> ValueRef, - info: |&'a Block<'a>, ValueRef| -> ValueRef) - -> DatumBlock<'a, Expr> { + fn into_fat_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + datum: Datum, + dest_ty: ty::t, + base: |Block<'blk, 'tcx>, ValueRef| -> ValueRef, + info: |Block<'blk, 'tcx>, ValueRef| -> ValueRef) + -> DatumBlock<'blk, 'tcx, Expr> { let mut bcx = bcx; // Arrange cleanup @@ -394,11 +394,11 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>, DatumBlock::new(bcx, scratch.to_expr_datum()) } - fn unsize_unique_vec<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr, - datum: Datum, - len: uint) - -> DatumBlock<'a, Expr> { + fn unsize_unique_vec<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + datum: Datum, + len: uint) + -> DatumBlock<'blk, 'tcx, Expr> { let mut bcx = bcx; let tcx = bcx.tcx(); @@ -440,11 +440,11 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>, DatumBlock::new(bcx, scratch.to_expr_datum()) } - fn unsize_unique_expr<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr, - datum: Datum, - k: &ty::UnsizeKind) - -> DatumBlock<'a, Expr> { + fn unsize_unique_expr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + datum: Datum, + k: &ty::UnsizeKind) + -> DatumBlock<'blk, 'tcx, Expr> { let mut bcx = bcx; let tcx = bcx.tcx(); @@ -475,10 +475,10 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>, DatumBlock::new(bcx, scratch.to_expr_datum()) } - fn add_env<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr, - datum: Datum) - -> DatumBlock<'a, Expr> { + fn add_env<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + datum: Datum) + -> DatumBlock<'blk, 'tcx, Expr> { // This is not the most efficient thing possible; since closures // are two words it'd be better if this were compiled in // 'dest' mode, but I can't find a nice way to structure the @@ -492,10 +492,10 @@ fn apply_adjustments<'a>(bcx: &'a Block<'a>, } } -pub fn trans_to_lvalue<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr, - name: &str) - -> DatumBlock<'a, Lvalue> { +pub fn trans_to_lvalue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + name: &str) + -> DatumBlock<'blk, 'tcx, Lvalue> { /*! * Translates an expression in "lvalue" mode -- meaning that it * returns a reference to the memory that the expr represents. @@ -512,9 +512,9 @@ pub fn trans_to_lvalue<'a>(bcx: &'a Block<'a>, return datum.to_lvalue_datum(bcx, name, expr.id); } -fn trans_unadjusted<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr) - -> DatumBlock<'a, Expr> { +fn trans_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr) + -> DatumBlock<'blk, 'tcx, Expr> { /*! * A version of `trans` that ignores adjustments. You almost * certainly do not want to call this directly. @@ -568,16 +568,17 @@ fn trans_unadjusted<'a>(bcx: &'a Block<'a>, } }; - fn nil<'a>(bcx: &'a Block<'a>, ty: ty::t) -> DatumBlock<'a, Expr> { + fn nil<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ty: ty::t) + -> DatumBlock<'blk, 'tcx, Expr> { let llval = C_undef(type_of::type_of(bcx.ccx(), ty)); let datum = immediate_rvalue(llval, ty); DatumBlock::new(bcx, datum.to_expr_datum()) } } -fn trans_datum_unadjusted<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr) - -> DatumBlock<'a, Expr> { +fn trans_datum_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr) + -> DatumBlock<'blk, 'tcx, Expr> { let mut bcx = bcx; let fcx = bcx.fcx; let _icx = push_ctxt("trans_datum_unadjusted"); @@ -665,10 +666,10 @@ fn trans_datum_unadjusted<'a>(bcx: &'a Block<'a>, } } -fn trans_rec_field<'a>(bcx: &'a Block<'a>, - base: &ast::Expr, - field: ast::Ident) - -> DatumBlock<'a, Expr> { +fn trans_rec_field<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + base: &ast::Expr, + field: ast::Ident) + -> DatumBlock<'blk, 'tcx, Expr> { //! Translates `base.field`. let mut bcx = bcx; @@ -698,12 +699,12 @@ fn trans_rec_field<'a>(bcx: &'a Block<'a>, }) } -fn trans_index<'a>(bcx: &'a Block<'a>, - index_expr: &ast::Expr, - base: &ast::Expr, - idx: &ast::Expr, - method_call: MethodCall) - -> DatumBlock<'a, Expr> { +fn trans_index<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + index_expr: &ast::Expr, + base: &ast::Expr, + idx: &ast::Expr, + method_call: MethodCall) + -> DatumBlock<'blk, 'tcx, Expr> { //! Translates `base[idx]`. let _icx = push_ctxt("trans_index"); @@ -803,11 +804,10 @@ fn trans_index<'a>(bcx: &'a Block<'a>, DatumBlock::new(bcx, elt_datum) } -fn trans_def<'a>(bcx: &'a Block<'a>, - ref_expr: &ast::Expr, - def: def::Def) - -> DatumBlock<'a, Expr> -{ +fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + ref_expr: &ast::Expr, + def: def::Def) + -> DatumBlock<'blk, 'tcx, Expr> { //! Translates a reference to a path. let _icx = push_ctxt("trans_def_lvalue"); @@ -830,8 +830,8 @@ fn trans_def<'a>(bcx: &'a Block<'a>, // an external global, and return a pointer to that. let const_ty = expr_ty(bcx, ref_expr); - fn get_val<'a>(bcx: &'a Block<'a>, did: ast::DefId, const_ty: ty::t) - -> ValueRef { + fn get_val<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, did: ast::DefId, const_ty: ty::t) + -> ValueRef { // For external constants, we don't inline. if did.krate == ast::LOCAL_CRATE { // Case 1 or 2. (The inlining in case 2 produces a new @@ -880,9 +880,9 @@ fn trans_def<'a>(bcx: &'a Block<'a>, } } -fn trans_rvalue_stmt_unadjusted<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr) - -> &'a Block<'a> { +fn trans_rvalue_stmt_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr) + -> Block<'blk, 'tcx> { let mut bcx = bcx; let _icx = push_ctxt("trans_rvalue_stmt"); @@ -961,10 +961,10 @@ fn trans_rvalue_stmt_unadjusted<'a>(bcx: &'a Block<'a>, } } -fn trans_rvalue_dps_unadjusted<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr, - dest: Dest) - -> &'a Block<'a> { +fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + dest: Dest) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_rvalue_dps_unadjusted"); let mut bcx = bcx; let tcx = bcx.tcx(); @@ -1091,12 +1091,11 @@ fn trans_rvalue_dps_unadjusted<'a>(bcx: &'a Block<'a>, } } -fn trans_def_dps_unadjusted<'a>( - bcx: &'a Block<'a>, - ref_expr: &ast::Expr, - def: def::Def, - dest: Dest) - -> &'a Block<'a> { +fn trans_def_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + ref_expr: &ast::Expr, + def: def::Def, + dest: Dest) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_def_dps_unadjusted"); let lldest = match dest { @@ -1140,9 +1139,10 @@ fn trans_def_dps_unadjusted<'a>( } } -fn trans_def_fn_unadjusted<'a>(bcx: &'a Block<'a>, - ref_expr: &ast::Expr, - def: def::Def) -> DatumBlock<'a, Expr> { +fn trans_def_fn_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + ref_expr: &ast::Expr, + def: def::Def) + -> DatumBlock<'blk, 'tcx, Expr> { let _icx = push_ctxt("trans_def_datum_unadjusted"); let llfn = match def { @@ -1167,9 +1167,9 @@ fn trans_def_fn_unadjusted<'a>(bcx: &'a Block<'a>, DatumBlock::new(bcx, Datum::new(llfn, fn_ty, RvalueExpr(Rvalue::new(ByValue)))) } -pub fn trans_local_var<'a>(bcx: &'a Block<'a>, - def: def::Def) - -> Datum { +pub fn trans_local_var<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + def: def::Def) + -> Datum { /*! * Translates a reference to a local variable or argument. * This always results in an lvalue datum. @@ -1203,10 +1203,10 @@ pub fn trans_local_var<'a>(bcx: &'a Block<'a>, } }; - fn take_local<'a>(bcx: &'a Block<'a>, - table: &NodeMap>, - nid: ast::NodeId) - -> Datum { + fn take_local<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + table: &NodeMap>, + nid: ast::NodeId) + -> Datum { let datum = match table.find(&nid) { Some(&v) => v, None => { @@ -1275,12 +1275,12 @@ pub fn with_field_tys(tcx: &ty::ctxt, } } -fn trans_struct<'a>(bcx: &'a Block<'a>, - fields: &[ast::Field], - base: Option>, - expr_span: codemap::Span, - id: ast::NodeId, - dest: Dest) -> &'a Block<'a> { +fn trans_struct<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + fields: &[ast::Field], + base: Option>, + expr_span: codemap::Span, + id: ast::NodeId, + dest: Dest) -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_rec"); let ty = node_id_type(bcx, id); @@ -1350,12 +1350,12 @@ pub struct StructBaseInfo { * - `optbase` contains information on the base struct (if any) from * which remaining fields are copied; see comments on `StructBaseInfo`. */ -pub fn trans_adt<'a>(mut bcx: &'a Block<'a>, - ty: ty::t, - discr: ty::Disr, - fields: &[(uint, Gc)], - optbase: Option, - dest: Dest) -> &'a Block<'a> { +pub fn trans_adt<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, + ty: ty::t, + discr: ty::Disr, + fields: &[(uint, Gc)], + optbase: Option, + dest: Dest) -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_adt"); let fcx = bcx.fcx; let repr = adt::represent_type(bcx.ccx(), ty); @@ -1419,10 +1419,10 @@ pub fn trans_adt<'a>(mut bcx: &'a Block<'a>, } -fn trans_immediate_lit<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr, - lit: ast::Lit) - -> DatumBlock<'a, Expr> { +fn trans_immediate_lit<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + lit: ast::Lit) + -> DatumBlock<'blk, 'tcx, Expr> { // must not be a string constant, that is a RvalueDpsExpr let _icx = push_ctxt("trans_immediate_lit"); let ty = expr_ty(bcx, expr); @@ -1430,11 +1430,11 @@ fn trans_immediate_lit<'a>(bcx: &'a Block<'a>, immediate_rvalue_bcx(bcx, v, ty).to_expr_datumblock() } -fn trans_unary<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr, - op: ast::UnOp, - sub_expr: &ast::Expr) - -> DatumBlock<'a, Expr> { +fn trans_unary<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + op: ast::UnOp, + sub_expr: &ast::Expr) + -> DatumBlock<'blk, 'tcx, Expr> { let ccx = bcx.ccx(); let mut bcx = bcx; let _icx = push_ctxt("trans_unary_datum"); @@ -1481,11 +1481,11 @@ fn trans_unary<'a>(bcx: &'a Block<'a>, } } -fn trans_uniq_expr<'a>(bcx: &'a Block<'a>, - box_ty: ty::t, - contents: &ast::Expr, - contents_ty: ty::t) - -> DatumBlock<'a, Expr> { +fn trans_uniq_expr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + box_ty: ty::t, + contents: &ast::Expr, + contents_ty: ty::t) + -> DatumBlock<'blk, 'tcx, Expr> { let _icx = push_ctxt("trans_uniq_expr"); let fcx = bcx.fcx; assert!(ty::type_is_sized(bcx.tcx(), contents_ty)); @@ -1510,11 +1510,11 @@ fn trans_uniq_expr<'a>(bcx: &'a Block<'a>, immediate_rvalue_bcx(bcx, val, box_ty).to_expr_datumblock() } -fn trans_managed_expr<'a>(bcx: &'a Block<'a>, - box_ty: ty::t, - contents: &ast::Expr, - contents_ty: ty::t) - -> DatumBlock<'a, Expr> { +fn trans_managed_expr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + box_ty: ty::t, + contents: &ast::Expr, + contents_ty: ty::t) + -> DatumBlock<'blk, 'tcx, Expr> { let _icx = push_ctxt("trans_managed_expr"); let fcx = bcx.fcx; let ty = type_of::type_of(bcx.ccx(), contents_ty); @@ -1530,10 +1530,10 @@ fn trans_managed_expr<'a>(bcx: &'a Block<'a>, immediate_rvalue_bcx(bcx, bx, box_ty).to_expr_datumblock() } -fn trans_addr_of<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr, - subexpr: &ast::Expr) - -> DatumBlock<'a, Expr> { +fn trans_addr_of<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + subexpr: &ast::Expr) + -> DatumBlock<'blk, 'tcx, Expr> { let _icx = push_ctxt("trans_addr_of"); let mut bcx = bcx; let sub_datum = unpack_datum!(bcx, trans_to_lvalue(bcx, subexpr, "addr_of")); @@ -1563,16 +1563,15 @@ fn trans_addr_of<'a>(bcx: &'a Block<'a>, // Important to get types for both lhs and rhs, because one might be _|_ // and the other not. -fn trans_eager_binop<'a>( - bcx: &'a Block<'a>, - binop_expr: &ast::Expr, - binop_ty: ty::t, - op: ast::BinOp, - lhs_t: ty::t, - lhs: ValueRef, - rhs_t: ty::t, - rhs: ValueRef) - -> DatumBlock<'a, Expr> { +fn trans_eager_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + binop_expr: &ast::Expr, + binop_ty: ty::t, + op: ast::BinOp, + lhs_t: ty::t, + lhs: ValueRef, + rhs_t: ty::t, + rhs: ValueRef) + -> DatumBlock<'blk, 'tcx, Expr> { let _icx = push_ctxt("trans_eager_binop"); let tcx = bcx.tcx(); @@ -1663,13 +1662,12 @@ enum lazy_binop_ty { lazy_or, } -fn trans_lazy_binop<'a>( - bcx: &'a Block<'a>, - binop_expr: &ast::Expr, - op: lazy_binop_ty, - a: &ast::Expr, - b: &ast::Expr) - -> DatumBlock<'a, Expr> { +fn trans_lazy_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + binop_expr: &ast::Expr, + op: lazy_binop_ty, + a: &ast::Expr, + b: &ast::Expr) + -> DatumBlock<'blk, 'tcx, Expr> { let _icx = push_ctxt("trans_lazy_binop"); let binop_ty = expr_ty(bcx, binop_expr); let fcx = bcx.fcx; @@ -1703,12 +1701,12 @@ fn trans_lazy_binop<'a>( return immediate_rvalue_bcx(join, phi, binop_ty).to_expr_datumblock(); } -fn trans_binary<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr, - op: ast::BinOp, - lhs: &ast::Expr, - rhs: &ast::Expr) - -> DatumBlock<'a, Expr> { +fn trans_binary<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + op: ast::BinOp, + lhs: &ast::Expr, + rhs: &ast::Expr) + -> DatumBlock<'blk, 'tcx, Expr> { let _icx = push_ctxt("trans_binary"); let ccx = bcx.ccx(); @@ -1745,14 +1743,13 @@ fn trans_binary<'a>(bcx: &'a Block<'a>, } } -fn trans_overloaded_op<'a, 'b>( - bcx: &'a Block<'a>, - expr: &ast::Expr, - method_call: MethodCall, - lhs: Datum, - rhs: Option<(Datum, ast::NodeId)>, - dest: Option) - -> Result<'a> { +fn trans_overloaded_op<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + method_call: MethodCall, + lhs: Datum, + rhs: Option<(Datum, ast::NodeId)>, + dest: Option) + -> Result<'blk, 'tcx> { let method_ty = bcx.tcx().method_map.borrow().get(&method_call).ty; callee::trans_call_inner(bcx, Some(expr_info(expr)), @@ -1767,13 +1764,12 @@ fn trans_overloaded_op<'a, 'b>( dest) } -fn trans_overloaded_call<'a>( - mut bcx: &'a Block<'a>, - expr: &ast::Expr, - callee: Gc, - args: &[Gc], - dest: Option) - -> &'a Block<'a> { +fn trans_overloaded_call<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + callee: Gc, + args: &[Gc], + dest: Option) + -> Block<'blk, 'tcx> { let method_call = MethodCall::expr(expr.id); let method_type = bcx.tcx() .method_map @@ -1800,7 +1796,7 @@ fn trans_overloaded_call<'a>( bcx } -fn int_cast(bcx: &Block, +fn int_cast(bcx: Block, lldsttype: Type, llsrctype: Type, llsrc: ValueRef, @@ -1822,7 +1818,7 @@ fn int_cast(bcx: &Block, } } -fn float_cast(bcx: &Block, +fn float_cast(bcx: Block, lldsttype: Type, llsrctype: Type, llsrc: ValueRef) @@ -1879,10 +1875,10 @@ fn cast_is_noop(t_in: ty::t, t_out: ty::t) -> bool { } } -fn trans_imm_cast<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr, - id: ast::NodeId) - -> DatumBlock<'a, Expr> { +fn trans_imm_cast<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + id: ast::NodeId) + -> DatumBlock<'blk, 'tcx, Expr> { let _icx = push_ctxt("trans_cast"); let mut bcx = bcx; let ccx = bcx.ccx(); @@ -1971,13 +1967,12 @@ fn trans_imm_cast<'a>(bcx: &'a Block<'a>, return immediate_rvalue_bcx(bcx, newval, t_out).to_expr_datumblock(); } -fn trans_assign_op<'a>( - bcx: &'a Block<'a>, - expr: &ast::Expr, - op: ast::BinOp, - dst: &ast::Expr, - src: Gc) - -> &'a Block<'a> { +fn trans_assign_op<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + op: ast::BinOp, + dst: &ast::Expr, + src: Gc) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_assign_op"); let mut bcx = bcx; @@ -2004,10 +1999,10 @@ fn trans_assign_op<'a>( return result_datum.store_to(bcx, dst_datum.val); } -fn auto_ref<'a>(bcx: &'a Block<'a>, - datum: Datum, - expr: &ast::Expr) - -> DatumBlock<'a, Expr> { +fn auto_ref<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + datum: Datum, + expr: &ast::Expr) + -> DatumBlock<'blk, 'tcx, Expr> { let mut bcx = bcx; // Ensure cleanup of `datum` if not already scheduled and obtain @@ -2028,11 +2023,11 @@ fn auto_ref<'a>(bcx: &'a Block<'a>, DatumBlock::new(bcx, Datum::new(llref, ptr_ty, RvalueExpr(Rvalue::new(ByValue)))) } -fn deref_multiple<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr, - datum: Datum, - times: uint) - -> DatumBlock<'a, Expr> { +fn deref_multiple<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + datum: Datum, + times: uint) + -> DatumBlock<'blk, 'tcx, Expr> { let mut bcx = bcx; let mut datum = datum; for i in range(0, times) { @@ -2042,11 +2037,11 @@ fn deref_multiple<'a>(bcx: &'a Block<'a>, DatumBlock { bcx: bcx, datum: datum } } -fn deref_once<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr, - datum: Datum, - method_call: MethodCall) - -> DatumBlock<'a, Expr> { +fn deref_once<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + datum: Datum, + method_call: MethodCall) + -> DatumBlock<'blk, 'tcx, Expr> { let ccx = bcx.ccx(); debug!("deref_once(expr={}, datum={}, method_call={})", @@ -2146,11 +2141,11 @@ fn deref_once<'a>(bcx: &'a Block<'a>, return r; - fn deref_owned_pointer<'a>(bcx: &'a Block<'a>, - expr: &ast::Expr, - datum: Datum, - content_ty: ty::t) - -> DatumBlock<'a, Expr> { + fn deref_owned_pointer<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + datum: Datum, + content_ty: ty::t) + -> DatumBlock<'blk, 'tcx, Expr> { /*! * We microoptimize derefs of owned pointers a bit here. * Basically, the idea is to make the deref of an rvalue diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index 8ed45f89c29e4..2cb8c86094496 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -247,14 +247,13 @@ pub fn register_foreign_item_fn(ccx: &CrateContext, abi: Abi, fty: ty::t, llfn } -pub fn trans_native_call<'a>( - bcx: &'a Block<'a>, - callee_ty: ty::t, - llfn: ValueRef, - llretptr: ValueRef, - llargs_rust: &[ValueRef], - passed_arg_tys: Vec ) - -> &'a Block<'a> { +pub fn trans_native_call<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + callee_ty: ty::t, + llfn: ValueRef, + llretptr: ValueRef, + llargs_rust: &[ValueRef], + passed_arg_tys: Vec ) + -> Block<'blk, 'tcx> { /*! * Prepares a call to a native function. This requires adapting * from the Rust argument passing rules to the native rules. diff --git a/src/librustc/middle/trans/glue.rs b/src/librustc/middle/trans/glue.rs index 09d28f03392cf..259f85098afee 100644 --- a/src/librustc/middle/trans/glue.rs +++ b/src/librustc/middle/trans/glue.rs @@ -45,7 +45,8 @@ use libc::c_uint; use syntax::ast; use syntax::parse::token; -pub fn trans_free<'a>(cx: &'a Block<'a>, v: ValueRef) -> &'a Block<'a> { +pub fn trans_free<'blk, 'tcx>(cx: Block<'blk, 'tcx>, v: ValueRef) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_free"); callee::trans_lang_call(cx, langcall(cx, None, "", FreeFnLangItem), @@ -53,8 +54,9 @@ pub fn trans_free<'a>(cx: &'a Block<'a>, v: ValueRef) -> &'a Block<'a> { Some(expr::Ignore)).bcx } -pub fn trans_exchange_free_dyn<'a>(cx: &'a Block<'a>, v: ValueRef, size: ValueRef, - align: ValueRef) -> &'a Block<'a> { +pub fn trans_exchange_free_dyn<'blk, 'tcx>(cx: Block<'blk, 'tcx>, v: ValueRef, + size: ValueRef, align: ValueRef) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_exchange_free"); let ccx = cx.ccx(); callee::trans_lang_call(cx, @@ -63,14 +65,14 @@ pub fn trans_exchange_free_dyn<'a>(cx: &'a Block<'a>, v: ValueRef, size: ValueRe Some(expr::Ignore)).bcx } -pub fn trans_exchange_free<'a>(cx: &'a Block<'a>, v: ValueRef, size: u64, - align: u64) -> &'a Block<'a> { +pub fn trans_exchange_free<'blk, 'tcx>(cx: Block<'blk, 'tcx>, v: ValueRef, + size: u64, align: u64) -> Block<'blk, 'tcx> { trans_exchange_free_dyn(cx, v, C_uint(cx.ccx(), size as uint), C_uint(cx.ccx(), align as uint)) } -pub fn trans_exchange_free_ty<'a>(bcx: &'a Block<'a>, ptr: ValueRef, - content_ty: ty::t) -> &'a Block<'a> { +pub fn trans_exchange_free_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ptr: ValueRef, + content_ty: ty::t) -> Block<'blk, 'tcx> { assert!(ty::type_is_sized(bcx.ccx().tcx(), content_ty)); let sizing_type = sizing_type_of(bcx.ccx(), content_ty); let content_size = llsize_of_alloc(bcx.ccx(), sizing_type); @@ -84,8 +86,8 @@ pub fn trans_exchange_free_ty<'a>(bcx: &'a Block<'a>, ptr: ValueRef, } } -pub fn take_ty<'a>(bcx: &'a Block<'a>, v: ValueRef, t: ty::t) - -> &'a Block<'a> { +pub fn take_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v: ValueRef, t: ty::t) + -> Block<'blk, 'tcx> { // NB: v is an *alias* of type t here, not a direct value. let _icx = push_ctxt("take_ty"); match ty::get(t).sty { @@ -123,8 +125,8 @@ pub fn get_drop_glue_type(ccx: &CrateContext, t: ty::t) -> ty::t { } } -pub fn drop_ty<'a>(bcx: &'a Block<'a>, v: ValueRef, t: ty::t) - -> &'a Block<'a> { +pub fn drop_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v: ValueRef, t: ty::t) + -> Block<'blk, 'tcx> { // NB: v is an *alias* of type t here, not a direct value. debug!("drop_ty(t={})", t.repr(bcx.tcx())); let _icx = push_ctxt("drop_ty"); @@ -142,8 +144,8 @@ pub fn drop_ty<'a>(bcx: &'a Block<'a>, v: ValueRef, t: ty::t) bcx } -pub fn drop_ty_immediate<'a>(bcx: &'a Block<'a>, v: ValueRef, t: ty::t) - -> &'a Block<'a> { +pub fn drop_ty_immediate<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v: ValueRef, t: ty::t) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("drop_ty_immediate"); let vp = alloca(bcx, type_of(bcx.ccx(), t), ""); Store(bcx, v, vp); @@ -232,7 +234,7 @@ pub fn lazily_emit_visit_glue(ccx: &CrateContext, ti: &tydesc_info) -> ValueRef } // See [Note-arg-mode] -pub fn call_visit_glue(bcx: &Block, v: ValueRef, tydesc: ValueRef) { +pub fn call_visit_glue(bcx: Block, v: ValueRef, tydesc: ValueRef) { let _icx = push_ctxt("call_visit_glue"); // Select the glue function to call from the tydesc @@ -242,8 +244,8 @@ pub fn call_visit_glue(bcx: &Block, v: ValueRef, tydesc: ValueRef) { Call(bcx, llfn, [llrawptr], None); } -fn make_visit_glue<'a>(bcx: &'a Block<'a>, v: ValueRef, t: ty::t) - -> &'a Block<'a> { +fn make_visit_glue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v: ValueRef, t: ty::t) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("make_visit_glue"); let mut bcx = bcx; let (visitor_trait, object_ty) = match ty::visitor_object_ty(bcx.tcx(), @@ -259,13 +261,13 @@ fn make_visit_glue<'a>(bcx: &'a Block<'a>, v: ValueRef, t: ty::t) bcx } -fn trans_struct_drop_flag<'a>(mut bcx: &'a Block<'a>, - t: ty::t, - v0: ValueRef, - dtor_did: ast::DefId, - class_did: ast::DefId, - substs: &subst::Substs) - -> &'a Block<'a> { +fn trans_struct_drop_flag<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, + t: ty::t, + v0: ValueRef, + dtor_did: ast::DefId, + class_did: ast::DefId, + substs: &subst::Substs) + -> Block<'blk, 'tcx> { let repr = adt::represent_type(bcx.ccx(), t); let struct_data = if ty::type_is_sized(bcx.tcx(), t) { v0 @@ -279,13 +281,13 @@ fn trans_struct_drop_flag<'a>(mut bcx: &'a Block<'a>, }) } -fn trans_struct_drop<'a>(bcx: &'a Block<'a>, - t: ty::t, - v0: ValueRef, - dtor_did: ast::DefId, - class_did: ast::DefId, - substs: &subst::Substs) - -> &'a Block<'a> { +fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + t: ty::t, + v0: ValueRef, + dtor_did: ast::DefId, + class_did: ast::DefId, + substs: &subst::Substs) + -> Block<'blk, 'tcx> { let repr = adt::represent_type(bcx.ccx(), t); // Find and call the actual destructor @@ -371,7 +373,7 @@ fn trans_struct_drop<'a>(bcx: &'a Block<'a>, }) } -fn size_and_align_of_dst<'a>(bcx: &'a Block<'a>, t :ty::t, info: ValueRef) -> (ValueRef, ValueRef) { +fn size_and_align_of_dst(bcx: Block, t :ty::t, info: ValueRef) -> (ValueRef, ValueRef) { debug!("calculate size of DST: {}; with lost info: {}", bcx.ty_to_string(t), bcx.val_to_string(info)); if ty::type_is_sized(bcx.tcx(), t) { @@ -426,7 +428,8 @@ fn size_and_align_of_dst<'a>(bcx: &'a Block<'a>, t :ty::t, info: ValueRef) -> (V } } -fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<'a> { +fn make_drop_glue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v0: ValueRef, t: ty::t) + -> Block<'blk, 'tcx> { // NB: v0 is an *alias* of type t here, not a direct value. let _icx = push_ctxt("make_drop_glue"); match ty::get(t).sty { @@ -549,9 +552,9 @@ fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<' } } -fn decr_refcnt_maybe_free<'a>(bcx: &'a Block<'a>, - box_ptr_ptr: ValueRef, - t: ty::t) -> &'a Block<'a> { +fn decr_refcnt_maybe_free<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + box_ptr_ptr: ValueRef, + t: ty::t) -> Block<'blk, 'tcx> { let _icx = push_ctxt("decr_refcnt_maybe_free"); let fcx = bcx.fcx; let ccx = bcx.ccx(); @@ -578,8 +581,8 @@ fn decr_refcnt_maybe_free<'a>(bcx: &'a Block<'a>, next_bcx } -fn incr_refcnt_of_boxed<'a>(bcx: &'a Block<'a>, - box_ptr_ptr: ValueRef) -> &'a Block<'a> { +fn incr_refcnt_of_boxed<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + box_ptr_ptr: ValueRef) -> Block<'blk, 'tcx> { let _icx = push_ctxt("incr_refcnt_of_boxed"); let ccx = bcx.ccx(); let box_ptr = Load(bcx, box_ptr_ptr); @@ -645,8 +648,8 @@ fn declare_generic_glue(ccx: &CrateContext, t: ty::t, llfnty: Type, fn make_generic_glue(ccx: &CrateContext, t: ty::t, llfn: ValueRef, - helper: <'a> |&'a Block<'a>, ValueRef, ty::t| - -> &'a Block<'a>, + helper: <'blk, 'tcx> |Block<'blk, 'tcx>, ValueRef, ty::t| + -> Block<'blk, 'tcx>, name: &str) -> ValueRef { let _icx = push_ctxt("make_generic_glue"); diff --git a/src/librustc/middle/trans/intrinsic.rs b/src/librustc/middle/trans/intrinsic.rs index f10df00ca9184..36184b2eed37e 100644 --- a/src/librustc/middle/trans/intrinsic.rs +++ b/src/librustc/middle/trans/intrinsic.rs @@ -134,10 +134,11 @@ pub fn check_intrinsics(ccx: &CrateContext) { ccx.sess().abort_if_errors(); } -pub fn trans_intrinsic_call<'a>(mut bcx: &'a Block<'a>, node: ast::NodeId, - callee_ty: ty::t, cleanup_scope: cleanup::CustomScopeIndex, - args: callee::CallArgs, dest: expr::Dest, - substs: subst::Substs, call_info: NodeInfo) -> Result<'a> { +pub fn trans_intrinsic_call<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, node: ast::NodeId, + callee_ty: ty::t, cleanup_scope: cleanup::CustomScopeIndex, + args: callee::CallArgs, dest: expr::Dest, + substs: subst::Substs, call_info: NodeInfo) + -> Result<'blk, 'tcx> { let fcx = bcx.fcx; let ccx = fcx.ccx; @@ -548,7 +549,7 @@ pub fn trans_intrinsic_call<'a>(mut bcx: &'a Block<'a>, node: ast::NodeId, Result::new(bcx, llresult) } -fn copy_intrinsic(bcx: &Block, allow_overlap: bool, volatile: bool, +fn copy_intrinsic(bcx: Block, allow_overlap: bool, volatile: bool, tp_ty: ty::t, dst: ValueRef, src: ValueRef, count: ValueRef) -> ValueRef { let ccx = bcx.ccx(); let lltp_ty = type_of::type_of(ccx, tp_ty); @@ -577,7 +578,7 @@ fn copy_intrinsic(bcx: &Block, allow_overlap: bool, volatile: bool, C_bool(ccx, volatile)], None) } -fn memset_intrinsic(bcx: &Block, volatile: bool, tp_ty: ty::t, +fn memset_intrinsic(bcx: Block, volatile: bool, tp_ty: ty::t, dst: ValueRef, val: ValueRef, count: ValueRef) -> ValueRef { let ccx = bcx.ccx(); let lltp_ty = type_of::type_of(ccx, tp_ty); @@ -596,13 +597,13 @@ fn memset_intrinsic(bcx: &Block, volatile: bool, tp_ty: ty::t, C_bool(ccx, volatile)], None) } -fn count_zeros_intrinsic(bcx: &Block, name: &'static str, val: ValueRef) -> ValueRef { +fn count_zeros_intrinsic(bcx: Block, name: &'static str, val: ValueRef) -> ValueRef { let y = C_bool(bcx.ccx(), false); let llfn = bcx.ccx().get_intrinsic(&name); Call(bcx, llfn, [val, y], None) } -fn with_overflow_intrinsic(bcx: &Block, name: &'static str, t: ty::t, +fn with_overflow_intrinsic(bcx: Block, name: &'static str, t: ty::t, a: ValueRef, b: ValueRef) -> ValueRef { let llfn = bcx.ccx().get_intrinsic(&name); diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index c002f3e72c89f..fb1a764f0fce5 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -102,12 +102,11 @@ pub fn trans_impl(ccx: &CrateContext, } } -pub fn trans_method_callee<'a>( - bcx: &'a Block<'a>, - method_call: MethodCall, - self_expr: Option<&ast::Expr>, - arg_cleanup_scope: cleanup::ScopeId) - -> Callee<'a> { +pub fn trans_method_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + method_call: MethodCall, + self_expr: Option<&ast::Expr>, + arg_cleanup_scope: cleanup::ScopeId) + -> Callee<'blk, 'tcx> { let _icx = push_ctxt("meth::trans_method_callee"); let (origin, method_ty) = match bcx.tcx().method_map @@ -166,7 +165,7 @@ pub fn trans_method_callee<'a>( } } -pub fn trans_static_method_callee(bcx: &Block, +pub fn trans_static_method_callee(bcx: Block, method_id: ast::DefId, trait_id: ast::DefId, expr_id: ast::NodeId) @@ -262,13 +261,12 @@ fn method_with_name(ccx: &CrateContext, impl_id: ast::DefId, name: ast::Name) meth_did.def_id() } -fn trans_monomorphized_callee<'a>( - bcx: &'a Block<'a>, - method_call: MethodCall, - trait_id: ast::DefId, - n_method: uint, - vtbl: typeck::vtable_origin) - -> Callee<'a> { +fn trans_monomorphized_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + method_call: MethodCall, + trait_id: ast::DefId, + n_method: uint, + vtbl: typeck::vtable_origin) + -> Callee<'blk, 'tcx> { let _icx = push_ctxt("meth::trans_monomorphized_callee"); match vtbl { typeck::vtable_static(impl_did, rcvr_substs, rcvr_origins) => { @@ -324,7 +322,7 @@ fn trans_monomorphized_callee<'a>( } } -fn combine_impl_and_methods_tps(bcx: &Block, +fn combine_impl_and_methods_tps(bcx: Block, node: ExprOrMethodCall, rcvr_substs: subst::Substs, rcvr_origins: typeck::vtable_res) @@ -378,12 +376,12 @@ fn combine_impl_and_methods_tps(bcx: &Block, (ty_substs, vtables) } -fn trans_trait_callee<'a>(bcx: &'a Block<'a>, - method_ty: ty::t, - n_method: uint, - self_expr: &ast::Expr, - arg_cleanup_scope: cleanup::ScopeId) - -> Callee<'a> { +fn trans_trait_callee<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + method_ty: ty::t, + n_method: uint, + self_expr: &ast::Expr, + arg_cleanup_scope: cleanup::ScopeId) + -> Callee<'blk, 'tcx> { /*! * Create a method callee where the method is coming from a trait * object (e.g., Box type). In this case, we must pull the fn @@ -422,11 +420,11 @@ fn trans_trait_callee<'a>(bcx: &'a Block<'a>, trans_trait_callee_from_llval(bcx, method_ty, n_method, llval) } -pub fn trans_trait_callee_from_llval<'a>(bcx: &'a Block<'a>, - callee_ty: ty::t, - n_method: uint, - llpair: ValueRef) - -> Callee<'a> { +pub fn trans_trait_callee_from_llval<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + callee_ty: ty::t, + n_method: uint, + llpair: ValueRef) + -> Callee<'blk, 'tcx> { /*! * Same as `trans_trait_callee()` above, except that it is given * a by-ref pointer to the object pair. @@ -476,7 +474,7 @@ pub fn trans_trait_callee_from_llval<'a>(bcx: &'a Block<'a>, /// Creates the self type and (fake) callee substitutions for an unboxed /// closure with the given def ID. The static region and type parameters are /// lies, but we're in trans so it doesn't matter. -fn get_callee_substitutions_for_unboxed_closure(bcx: &Block, +fn get_callee_substitutions_for_unboxed_closure(bcx: Block, def_id: ast::DefId) -> subst::Substs { let self_ty = ty::mk_unboxed_closure(bcx.tcx(), def_id, ty::ReStatic); @@ -495,7 +493,7 @@ fn get_callee_substitutions_for_unboxed_closure(bcx: &Block, /// Creates a returns a dynamic vtable for the given type and vtable origin. /// This is used only for objects. -fn get_vtable(bcx: &Block, +fn get_vtable(bcx: Block, self_ty: ty::t, origins: typeck::vtable_param_res) -> ValueRef @@ -630,7 +628,7 @@ pub fn make_vtable>(ccx: &CrateContext, } } -fn emit_vtable_methods(bcx: &Block, +fn emit_vtable_methods(bcx: Block, impl_id: ast::DefId, substs: subst::Substs, vtables: typeck::vtable_res) @@ -686,9 +684,9 @@ fn emit_vtable_methods(bcx: &Block, }).collect() } -pub fn vtable_ptr<'a>(bcx: &'a Block<'a>, - id: ast::NodeId, - self_ty: ty::t) -> ValueRef { +pub fn vtable_ptr(bcx: Block, + id: ast::NodeId, + self_ty: ty::t) -> ValueRef { let ccx = bcx.ccx(); let origins = { let vtable_map = ccx.tcx().vtable_map.borrow(); @@ -706,11 +704,11 @@ pub fn vtable_ptr<'a>(bcx: &'a Block<'a>, get_vtable(bcx, self_ty, origins) } -pub fn trans_trait_cast<'a>(bcx: &'a Block<'a>, - datum: Datum, - id: ast::NodeId, - dest: expr::Dest) - -> &'a Block<'a> { +pub fn trans_trait_cast<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + datum: Datum, + id: ast::NodeId, + dest: expr::Dest) + -> Block<'blk, 'tcx> { /*! * Generates the code to convert from a pointer (`Box`, `&T`, etc) * into an object (`Box`, `&Trait`, etc). This means creating a diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs index 1fcf4c189129b..214726edd778d 100644 --- a/src/librustc/middle/trans/reflect.rs +++ b/src/librustc/middle/trans/reflect.rs @@ -33,15 +33,15 @@ use syntax::ast_map; use syntax::parse::token::{InternedString, special_idents}; use syntax::parse::token; -pub struct Reflector<'a, 'b> { +pub struct Reflector<'a, 'blk, 'tcx: 'blk> { visitor_val: ValueRef, visitor_items: &'a [ty::ImplOrTraitItem], - final_bcx: &'b Block<'b>, + final_bcx: Block<'blk, 'tcx>, tydesc_ty: Type, - bcx: &'b Block<'b> + bcx: Block<'blk, 'tcx> } -impl<'a, 'b> Reflector<'a, 'b> { +impl<'a, 'blk, 'tcx> Reflector<'a, 'blk, 'tcx> { pub fn c_uint(&mut self, u: uint) -> ValueRef { C_uint(self.bcx.ccx(), u) } @@ -419,12 +419,11 @@ impl<'a, 'b> Reflector<'a, 'b> { } // Emit a sequence of calls to visit_ty::visit_foo -pub fn emit_calls_to_trait_visit_ty<'a>( - bcx: &'a Block<'a>, - t: ty::t, - visitor_val: ValueRef, - visitor_trait_id: DefId) - -> &'a Block<'a> { +pub fn emit_calls_to_trait_visit_ty<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + t: ty::t, + visitor_val: ValueRef, + visitor_trait_id: DefId) + -> Block<'blk, 'tcx> { let fcx = bcx.fcx; let final = fcx.new_temp_block("final"); let tydesc_ty = ty::get_tydesc_ty(bcx.tcx()).unwrap(); diff --git a/src/librustc/middle/trans/tvec.rs b/src/librustc/middle/trans/tvec.rs index 285105d22f675..00b9977c7523c 100644 --- a/src/librustc/middle/trans/tvec.rs +++ b/src/librustc/middle/trans/tvec.rs @@ -35,29 +35,28 @@ use util::ppaux::ty_to_string; use syntax::ast; use syntax::parse::token::InternedString; -fn get_len(bcx: &Block, vptr: ValueRef) -> ValueRef { +fn get_len(bcx: Block, vptr: ValueRef) -> ValueRef { let _icx = push_ctxt("tvec::get_lenl"); Load(bcx, expr::get_len(bcx, vptr)) } -fn get_dataptr(bcx: &Block, vptr: ValueRef) -> ValueRef { +fn get_dataptr(bcx: Block, vptr: ValueRef) -> ValueRef { let _icx = push_ctxt("tvec::get_dataptr"); Load(bcx, expr::get_dataptr(bcx, vptr)) } -pub fn pointer_add_byte(bcx: &Block, ptr: ValueRef, bytes: ValueRef) -> ValueRef { +pub fn pointer_add_byte(bcx: Block, ptr: ValueRef, bytes: ValueRef) -> ValueRef { let _icx = push_ctxt("tvec::pointer_add_byte"); let old_ty = val_ty(ptr); let bptr = PointerCast(bcx, ptr, Type::i8p(bcx.ccx())); return PointerCast(bcx, InBoundsGEP(bcx, bptr, [bytes]), old_ty); } -pub fn make_drop_glue_unboxed<'a>( - bcx: &'a Block<'a>, - vptr: ValueRef, - unit_ty: ty::t, - should_deallocate: bool) - -> &'a Block<'a> { +pub fn make_drop_glue_unboxed<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + vptr: ValueRef, + unit_ty: ty::t, + should_deallocate: bool) + -> Block<'blk, 'tcx> { let not_null = IsNotNull(bcx, vptr); with_cond(bcx, not_null, |bcx| { let ccx = bcx.ccx(); @@ -105,11 +104,10 @@ impl VecTypes { } } -pub fn trans_fixed_vstore<'a>( - bcx: &'a Block<'a>, - expr: &ast::Expr, - dest: expr::Dest) - -> &'a Block<'a> { +pub fn trans_fixed_vstore<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + expr: &ast::Expr, + dest: expr::Dest) + -> Block<'blk, 'tcx> { //! // // [...] allocates a fixed-size array and moves it around "by value". @@ -133,10 +131,10 @@ pub fn trans_fixed_vstore<'a>( }; } -pub fn trans_slice_vec<'a>(bcx: &'a Block<'a>, - slice_expr: &ast::Expr, - content_expr: &ast::Expr) - -> DatumBlock<'a, Expr> { +pub fn trans_slice_vec<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + slice_expr: &ast::Expr, + content_expr: &ast::Expr) + -> DatumBlock<'blk, 'tcx, Expr> { /*! * &[...] allocates memory on the stack and writes the values into it, * returning the vector (the caller must make the reference). "..." is @@ -207,12 +205,11 @@ pub fn trans_slice_vec<'a>(bcx: &'a Block<'a>, immediate_rvalue_bcx(bcx, llfixed, vec_ty).to_expr_datumblock() } -pub fn trans_lit_str<'a>( - bcx: &'a Block<'a>, - lit_expr: &ast::Expr, - str_lit: InternedString, - dest: Dest) - -> &'a Block<'a> { +pub fn trans_lit_str<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + lit_expr: &ast::Expr, + str_lit: InternedString, + dest: Dest) + -> Block<'blk, 'tcx> { /*! * Literal strings translate to slices into static memory. This is * different from trans_slice_vstore() above because it doesn't need to copy @@ -239,10 +236,10 @@ pub fn trans_lit_str<'a>( } } -pub fn trans_uniq_vec<'a>(bcx: &'a Block<'a>, - uniq_expr: &ast::Expr, - content_expr: &ast::Expr) - -> DatumBlock<'a, Expr> { +pub fn trans_uniq_vec<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + uniq_expr: &ast::Expr, + content_expr: &ast::Expr) + -> DatumBlock<'blk, 'tcx, Expr> { /*! * Box<[...]> and "...".to_string() allocate boxes in the exchange heap and write * the array elements into them. @@ -327,13 +324,12 @@ pub fn trans_uniq_vec<'a>(bcx: &'a Block<'a>, } } -pub fn write_content<'a>( - bcx: &'a Block<'a>, - vt: &VecTypes, - vstore_expr: &ast::Expr, - content_expr: &ast::Expr, - dest: Dest) - -> &'a Block<'a> { +pub fn write_content<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + vt: &VecTypes, + vstore_expr: &ast::Expr, + content_expr: &ast::Expr, + dest: Dest) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("tvec::write_content"); let fcx = bcx.fcx; let mut bcx = bcx; @@ -429,12 +425,12 @@ pub fn write_content<'a>( } } -pub fn vec_types_from_expr(bcx: &Block, vec_expr: &ast::Expr) -> VecTypes { +pub fn vec_types_from_expr(bcx: Block, vec_expr: &ast::Expr) -> VecTypes { let vec_ty = node_id_type(bcx, vec_expr.id); vec_types(bcx, ty::sequence_element_type(bcx.tcx(), vec_ty)) } -pub fn vec_types(bcx: &Block, unit_ty: ty::t) -> VecTypes { +pub fn vec_types(bcx: Block, unit_ty: ty::t) -> VecTypes { let ccx = bcx.ccx(); let llunit_ty = type_of::type_of(ccx, unit_ty); let llunit_size = nonzero_llsize_of(ccx, llunit_ty); @@ -448,7 +444,7 @@ pub fn vec_types(bcx: &Block, unit_ty: ty::t) -> VecTypes { } } -pub fn elements_required(bcx: &Block, content_expr: &ast::Expr) -> uint { +pub fn elements_required(bcx: Block, content_expr: &ast::Expr) -> uint { //! Figure out the number of elements we need to store this content match content_expr.node { @@ -470,7 +466,7 @@ pub fn elements_required(bcx: &Block, content_expr: &ast::Expr) -> uint { } } -pub fn get_fixed_base_and_len(bcx: &Block, +pub fn get_fixed_base_and_len(bcx: Block, llval: ValueRef, vec_length: uint) -> (ValueRef, ValueRef) { @@ -486,7 +482,7 @@ pub fn get_fixed_base_and_len(bcx: &Block, (base, len) } -fn get_slice_base_and_len(bcx: &Block, +fn get_slice_base_and_len(bcx: Block, llval: ValueRef) -> (ValueRef, ValueRef) { let base = Load(bcx, GEPi(bcx, llval, [0u, abi::slice_elt_base])); @@ -494,7 +490,7 @@ fn get_slice_base_and_len(bcx: &Block, (base, len) } -pub fn get_base_and_len(bcx: &Block, +pub fn get_base_and_len(bcx: Block, llval: ValueRef, vec_ty: ty::t) -> (ValueRef, ValueRef) { @@ -528,17 +524,15 @@ pub fn get_base_and_len(bcx: &Block, } } -pub type iter_vec_block<'r,'b> = - |&'b Block<'b>, ValueRef, ty::t|: 'r -> &'b Block<'b>; - -pub fn iter_vec_loop<'r, - 'b>( - bcx: &'b Block<'b>, - data_ptr: ValueRef, - vt: &VecTypes, - count: ValueRef, - f: iter_vec_block<'r,'b>) - -> &'b Block<'b> { +pub type iter_vec_block<'a, 'blk, 'tcx> = + |Block<'blk, 'tcx>, ValueRef, ty::t|: 'a -> Block<'blk, 'tcx>; + +pub fn iter_vec_loop<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + data_ptr: ValueRef, + vt: &VecTypes, + count: ValueRef, + f: iter_vec_block<'a, 'blk, 'tcx>) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("tvec::iter_vec_loop"); let fcx = bcx.fcx; @@ -589,14 +583,12 @@ pub fn iter_vec_loop<'r, next_bcx } -pub fn iter_vec_raw<'r, - 'b>( - bcx: &'b Block<'b>, - data_ptr: ValueRef, - unit_ty: ty::t, - len: ValueRef, - f: iter_vec_block<'r,'b>) - -> &'b Block<'b> { +pub fn iter_vec_raw<'a, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, + data_ptr: ValueRef, + unit_ty: ty::t, + len: ValueRef, + f: iter_vec_block<'a, 'blk, 'tcx>) + -> Block<'blk, 'tcx> { let _icx = push_ctxt("tvec::iter_vec_raw"); let fcx = bcx.fcx; diff --git a/src/librustc/middle/trans/value.rs b/src/librustc/middle/trans/value.rs index 2db6a87a9dc53..dfa4ae6b285c8 100644 --- a/src/librustc/middle/trans/value.rs +++ b/src/librustc/middle/trans/value.rs @@ -55,7 +55,7 @@ impl Value { /// This only performs a search for a trivially dominating store. The store /// must be the only user of this value, and there must not be any conditional /// branches between the store and the given block. - pub fn get_dominating_store(self, bcx: &Block) -> Option { + pub fn get_dominating_store(self, bcx: Block) -> Option { match self.get_single_user().and_then(|user| user.as_store_inst()) { Some(store) => { store.get_parent().and_then(|store_bb| { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 7f2f1151e30ca..feed76233d68a 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -50,6 +50,7 @@ use std::mem; use std::ops; use std::rc::Rc; use std::collections::{HashMap, HashSet}; +use arena::TypedArena; use syntax::abi; use syntax::ast::{CrateNum, DefId, FnStyle, Ident, ItemTrait, LOCAL_CRATE}; use syntax::ast::{MutImmutable, MutMutable, Name, NamedField, NodeId}; @@ -418,10 +419,13 @@ pub struct TransmuteRestriction { /// The data structure to keep track of all the information that typechecker /// generates so that so that it can be reused and doesn't have to be redone /// later on. -pub struct ctxt { +pub struct ctxt<'tcx> { + /// The arena that types are allocated from. + type_arena: &'tcx TypedArena, + /// Specifically use a speedy hash algorithm for this hash map, it's used /// quite often. - pub interner: RefCell>>, + interner: RefCell>, pub next_id: Cell, pub sess: Session, pub def_map: resolve::DefMap, @@ -1373,21 +1377,22 @@ impl UnboxedClosureKind { } } -pub fn mk_ctxt(s: Session, - dm: resolve::DefMap, - named_region_map: resolve_lifetime::NamedRegionMap, - map: ast_map::Map, - freevars: freevars::freevar_map, - capture_modes: freevars::CaptureModeMap, - region_maps: middle::region::RegionMaps, - lang_items: middle::lang_items::LanguageItems, - stability: stability::Index) - -> ctxt { +pub fn mk_ctxt<'tcx>(s: Session, + type_arena: &'tcx TypedArena, + dm: resolve::DefMap, + named_region_map: resolve_lifetime::NamedRegionMap, + map: ast_map::Map, + freevars: freevars::freevar_map, + capture_modes: freevars::CaptureModeMap, + region_maps: middle::region::RegionMaps, + lang_items: middle::lang_items::LanguageItems, + stability: stability::Index) -> ctxt<'tcx> { ctxt { + type_arena: type_arena, + interner: RefCell::new(FnvHashMap::new()), named_region_map: named_region_map, item_variance_map: RefCell::new(DefIdMap::new()), variance_computed: Cell::new(false), - interner: RefCell::new(FnvHashMap::new()), next_id: Cell::new(primitives::LAST_PRIMITIVE_ID), sess: s, def_map: dm, @@ -1554,11 +1559,11 @@ pub fn mk_t(cx: &ctxt, st: sty) -> t { } } - let t = box t_box_ { + let t = cx.type_arena.alloc(t_box_ { sty: st, id: cx.next_id.get(), flags: flags, - }; + }); let sty_ptr = &t.sty as *const sty; @@ -3463,10 +3468,10 @@ impl AutoRef { } } -pub fn method_call_type_param_defs(typer: &T, - origin: typeck::MethodOrigin) - -> VecPerParamSpace - where T: mc::Typer { +pub fn method_call_type_param_defs<'tcx, T>(typer: &T, + origin: typeck::MethodOrigin) + -> VecPerParamSpace + where T: mc::Typer<'tcx> { match origin { typeck::MethodStatic(did) => { ty::lookup_item_type(typer.tcx(), did).generics.types.clone() @@ -4655,10 +4660,10 @@ pub fn normalize_ty(cx: &ctxt, t: t) -> t { let u = TypeNormalizer(cx).fold_ty(t); return u; - struct TypeNormalizer<'a>(&'a ctxt); + struct TypeNormalizer<'a, 'tcx: 'a>(&'a ctxt<'tcx>); - impl<'a> TypeFolder for TypeNormalizer<'a> { - fn tcx<'a>(&'a self) -> &'a ctxt { let TypeNormalizer(c) = *self; c } + impl<'a, 'tcx> TypeFolder<'tcx> for TypeNormalizer<'a, 'tcx> { + fn tcx<'a>(&'a self) -> &'a ctxt<'tcx> { let TypeNormalizer(c) = *self; c } fn fold_ty(&mut self, t: ty::t) -> ty::t { match self.tcx().normalized_cache.borrow().find_copy(&t) { @@ -4697,70 +4702,55 @@ pub fn normalize_ty(cx: &ctxt, t: t) -> t { } } -pub trait ExprTyProvider { - fn expr_ty(&self, ex: &ast::Expr) -> t; - fn ty_ctxt<'a>(&'a self) -> &'a ctxt; -} - -impl ExprTyProvider for ctxt { - fn expr_ty(&self, ex: &ast::Expr) -> t { - expr_ty(self, ex) - } - - fn ty_ctxt<'a>(&'a self) -> &'a ctxt { - self - } -} - // Returns the repeat count for a repeating vector expression. -pub fn eval_repeat_count(tcx: &T, count_expr: &ast::Expr) -> uint { +pub fn eval_repeat_count(tcx: &ctxt, count_expr: &ast::Expr) -> uint { match const_eval::eval_const_expr_partial(tcx, count_expr) { Ok(ref const_val) => match *const_val { const_eval::const_int(count) => if count < 0 { - tcx.ty_ctxt().sess.span_err(count_expr.span, - "expected positive integer for \ - repeat count, found negative integer"); - return 0; + tcx.sess.span_err(count_expr.span, + "expected positive integer for \ + repeat count, found negative integer"); + 0 } else { - return count as uint + count as uint }, - const_eval::const_uint(count) => return count as uint, + const_eval::const_uint(count) => count as uint, const_eval::const_float(count) => { - tcx.ty_ctxt().sess.span_err(count_expr.span, - "expected positive integer for \ - repeat count, found float"); - return count as uint; + tcx.sess.span_err(count_expr.span, + "expected positive integer for \ + repeat count, found float"); + count as uint } const_eval::const_str(_) => { - tcx.ty_ctxt().sess.span_err(count_expr.span, - "expected positive integer for \ - repeat count, found string"); - return 0; + tcx.sess.span_err(count_expr.span, + "expected positive integer for \ + repeat count, found string"); + 0 } const_eval::const_bool(_) => { - tcx.ty_ctxt().sess.span_err(count_expr.span, - "expected positive integer for \ - repeat count, found boolean"); - return 0; + tcx.sess.span_err(count_expr.span, + "expected positive integer for \ + repeat count, found boolean"); + 0 } const_eval::const_binary(_) => { - tcx.ty_ctxt().sess.span_err(count_expr.span, - "expected positive integer for \ - repeat count, found binary array"); - return 0; + tcx.sess.span_err(count_expr.span, + "expected positive integer for \ + repeat count, found binary array"); + 0 } const_eval::const_nil => { - tcx.ty_ctxt().sess.span_err(count_expr.span, - "expected positive integer for \ - repeat count, found ()"); - return 0; + tcx.sess.span_err(count_expr.span, + "expected positive integer for \ + repeat count, found ()"); + 0 } }, Err(..) => { - tcx.ty_ctxt().sess.span_err(count_expr.span, - "expected constant integer for repeat count, \ - found variable"); - return 0; + tcx.sess.span_err(count_expr.span, + "expected constant integer for repeat count, \ + found variable"); + 0 } } } @@ -5397,8 +5387,8 @@ impl BorrowKind { } } -impl mc::Typer for ty::ctxt { - fn tcx<'a>(&'a self) -> &'a ty::ctxt { +impl<'tcx> mc::Typer<'tcx> for ty::ctxt<'tcx> { + fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self } diff --git a/src/librustc/middle/ty_fold.rs b/src/librustc/middle/ty_fold.rs index 07c8573ef853b..bc53568694df6 100644 --- a/src/librustc/middle/ty_fold.rs +++ b/src/librustc/middle/ty_fold.rs @@ -25,7 +25,7 @@ use util::ppaux::Repr; /// The TypeFoldable trait is implemented for every type that can be folded. /// Basically, every type that has a corresponding method in TypeFolder. pub trait TypeFoldable { - fn fold_with(&self, folder: &mut F) -> Self; + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self; } /// The TypeFolder trait defines the actual *folding*. There is a @@ -33,8 +33,8 @@ pub trait TypeFoldable { /// default implementation that does an "identity" fold. Within each /// identity fold, it should invoke `foo.fold_with(self)` to fold each /// sub-item. -pub trait TypeFolder { - fn tcx<'a>(&'a self) -> &'a ty::ctxt; +pub trait TypeFolder<'tcx> { + fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx>; fn fold_ty(&mut self, t: ty::t) -> ty::t { super_fold_ty(self, t) @@ -111,97 +111,97 @@ pub trait TypeFolder { // needed. impl TypeFoldable for Option { - fn fold_with(&self, folder: &mut F) -> Option { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Option { self.as_ref().map(|t| t.fold_with(folder)) } } impl TypeFoldable for Rc { - fn fold_with(&self, folder: &mut F) -> Rc { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Rc { Rc::new((**self).fold_with(folder)) } } impl TypeFoldable for Vec { - fn fold_with(&self, folder: &mut F) -> Vec { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Vec { self.iter().map(|t| t.fold_with(folder)).collect() } } impl TypeFoldable for OwnedSlice { - fn fold_with(&self, folder: &mut F) -> OwnedSlice { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> OwnedSlice { self.iter().map(|t| t.fold_with(folder)).collect() } } impl TypeFoldable for VecPerParamSpace { - fn fold_with(&self, folder: &mut F) -> VecPerParamSpace { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> VecPerParamSpace { self.map(|t| t.fold_with(folder)) } } impl TypeFoldable for ty::TraitStore { - fn fold_with(&self, folder: &mut F) -> ty::TraitStore { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::TraitStore { folder.fold_trait_store(*self) } } impl TypeFoldable for ty::t { - fn fold_with(&self, folder: &mut F) -> ty::t { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::t { folder.fold_ty(*self) } } impl TypeFoldable for ty::BareFnTy { - fn fold_with(&self, folder: &mut F) -> ty::BareFnTy { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::BareFnTy { folder.fold_bare_fn_ty(self) } } impl TypeFoldable for ty::ClosureTy { - fn fold_with(&self, folder: &mut F) -> ty::ClosureTy { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::ClosureTy { folder.fold_closure_ty(self) } } impl TypeFoldable for ty::mt { - fn fold_with(&self, folder: &mut F) -> ty::mt { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::mt { folder.fold_mt(self) } } impl TypeFoldable for ty::FnSig { - fn fold_with(&self, folder: &mut F) -> ty::FnSig { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::FnSig { folder.fold_sig(self) } } impl TypeFoldable for ty::sty { - fn fold_with(&self, folder: &mut F) -> ty::sty { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::sty { folder.fold_sty(self) } } impl TypeFoldable for ty::TraitRef { - fn fold_with(&self, folder: &mut F) -> ty::TraitRef { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::TraitRef { folder.fold_trait_ref(self) } } impl TypeFoldable for ty::Region { - fn fold_with(&self, folder: &mut F) -> ty::Region { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::Region { folder.fold_region(*self) } } impl TypeFoldable for subst::Substs { - fn fold_with(&self, folder: &mut F) -> subst::Substs { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> subst::Substs { folder.fold_substs(self) } } impl TypeFoldable for ty::ItemSubsts { - fn fold_with(&self, folder: &mut F) -> ty::ItemSubsts { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::ItemSubsts { ty::ItemSubsts { substs: self.substs.fold_with(folder), } @@ -209,13 +209,13 @@ impl TypeFoldable for ty::ItemSubsts { } impl TypeFoldable for ty::AutoRef { - fn fold_with(&self, folder: &mut F) -> ty::AutoRef { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::AutoRef { folder.fold_autoref(self) } } impl TypeFoldable for typeck::vtable_origin { - fn fold_with(&self, folder: &mut F) -> typeck::vtable_origin { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> typeck::vtable_origin { match *self { typeck::vtable_static(def_id, ref substs, ref origins) => { let r_substs = substs.fold_with(folder); @@ -236,19 +236,19 @@ impl TypeFoldable for typeck::vtable_origin { } impl TypeFoldable for ty::BuiltinBounds { - fn fold_with(&self, _folder: &mut F) -> ty::BuiltinBounds { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, _folder: &mut F) -> ty::BuiltinBounds { *self } } impl TypeFoldable for ty::ExistentialBounds { - fn fold_with(&self, folder: &mut F) -> ty::ExistentialBounds { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::ExistentialBounds { folder.fold_existential_bounds(*self) } } impl TypeFoldable for ty::ParamBounds { - fn fold_with(&self, folder: &mut F) -> ty::ParamBounds { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::ParamBounds { ty::ParamBounds { opt_region_bound: self.opt_region_bound.fold_with(folder), builtin_bounds: self.builtin_bounds.fold_with(folder), @@ -258,7 +258,7 @@ impl TypeFoldable for ty::ParamBounds { } impl TypeFoldable for ty::TypeParameterDef { - fn fold_with(&self, folder: &mut F) -> ty::TypeParameterDef { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::TypeParameterDef { ty::TypeParameterDef { ident: self.ident, def_id: self.def_id, @@ -271,7 +271,7 @@ impl TypeFoldable for ty::TypeParameterDef { } impl TypeFoldable for ty::RegionParameterDef { - fn fold_with(&self, folder: &mut F) -> ty::RegionParameterDef { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::RegionParameterDef { ty::RegionParameterDef { name: self.name, def_id: self.def_id, @@ -283,7 +283,7 @@ impl TypeFoldable for ty::RegionParameterDef { } impl TypeFoldable for ty::Generics { - fn fold_with(&self, folder: &mut F) -> ty::Generics { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::Generics { ty::Generics { types: self.types.fold_with(folder), regions: self.regions.fold_with(folder), @@ -292,7 +292,7 @@ impl TypeFoldable for ty::Generics { } impl TypeFoldable for ty::UnsizeKind { - fn fold_with(&self, folder: &mut F) -> ty::UnsizeKind { + fn fold_with<'tcx, F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::UnsizeKind { match *self { ty::UnsizeLength(len) => ty::UnsizeLength(len), ty::UnsizeStruct(box ref k, n) => ty::UnsizeStruct(box k.fold_with(folder), n), @@ -307,17 +307,16 @@ impl TypeFoldable for ty::UnsizeKind { // "super" routines: these are the default implementations for TypeFolder. // // They should invoke `foo.fold_with()` to do recursive folding. - -pub fn super_fold_ty(this: &mut T, - t: ty::t) - -> ty::t { +pub fn super_fold_ty<'tcx, T: TypeFolder<'tcx>>(this: &mut T, + t: ty::t) + -> ty::t { let sty = ty::get(t).sty.fold_with(this); ty::mk_t(this.tcx(), sty) } -pub fn super_fold_substs(this: &mut T, - substs: &subst::Substs) - -> subst::Substs { +pub fn super_fold_substs<'tcx, T: TypeFolder<'tcx>>(this: &mut T, + substs: &subst::Substs) + -> subst::Substs { let regions = match substs.regions { subst::ErasedRegions => { subst::ErasedRegions @@ -331,27 +330,27 @@ pub fn super_fold_substs(this: &mut T, types: substs.types.fold_with(this) } } -pub fn super_fold_sig(this: &mut T, - sig: &ty::FnSig) - -> ty::FnSig { +pub fn super_fold_sig<'tcx, T: TypeFolder<'tcx>>(this: &mut T, + sig: &ty::FnSig) + -> ty::FnSig { ty::FnSig { binder_id: sig.binder_id, inputs: sig.inputs.fold_with(this), output: sig.output.fold_with(this), variadic: sig.variadic } } -pub fn super_fold_bare_fn_ty(this: &mut T, - fty: &ty::BareFnTy) - -> ty::BareFnTy +pub fn super_fold_bare_fn_ty<'tcx, T: TypeFolder<'tcx>>(this: &mut T, + fty: &ty::BareFnTy) + -> ty::BareFnTy { ty::BareFnTy { sig: fty.sig.fold_with(this), abi: fty.abi, fn_style: fty.fn_style } } -pub fn super_fold_closure_ty(this: &mut T, - fty: &ty::ClosureTy) - -> ty::ClosureTy +pub fn super_fold_closure_ty<'tcx, T: TypeFolder<'tcx>>(this: &mut T, + fty: &ty::ClosureTy) + -> ty::ClosureTy { ty::ClosureTy { store: fty.store.fold_with(this), @@ -362,24 +361,23 @@ pub fn super_fold_closure_ty(this: &mut T, abi: fty.abi, } } - -pub fn super_fold_trait_ref(this: &mut T, - t: &ty::TraitRef) - -> ty::TraitRef { +pub fn super_fold_trait_ref<'tcx, T: TypeFolder<'tcx>>(this: &mut T, + t: &ty::TraitRef) + -> ty::TraitRef { ty::TraitRef { def_id: t.def_id, substs: t.substs.fold_with(this), } } -pub fn super_fold_mt(this: &mut T, - mt: &ty::mt) -> ty::mt { +pub fn super_fold_mt<'tcx, T: TypeFolder<'tcx>>(this: &mut T, + mt: &ty::mt) -> ty::mt { ty::mt {ty: mt.ty.fold_with(this), mutbl: mt.mutbl} } -pub fn super_fold_sty(this: &mut T, - sty: &ty::sty) -> ty::sty { +pub fn super_fold_sty<'tcx, T: TypeFolder<'tcx>>(this: &mut T, + sty: &ty::sty) -> ty::sty { match *sty { ty::ty_box(typ) => { ty::ty_box(typ.fold_with(this)) @@ -437,9 +435,9 @@ pub fn super_fold_sty(this: &mut T, } } -pub fn super_fold_trait_store(this: &mut T, - trait_store: ty::TraitStore) - -> ty::TraitStore { +pub fn super_fold_trait_store<'tcx, T: TypeFolder<'tcx>>(this: &mut T, + trait_store: ty::TraitStore) + -> ty::TraitStore { match trait_store { ty::UniqTraitStore => ty::UniqTraitStore, ty::RegionTraitStore(r, m) => { @@ -448,18 +446,18 @@ pub fn super_fold_trait_store(this: &mut T, } } -pub fn super_fold_existential_bounds(this: &mut T, - bounds: ty::ExistentialBounds) - -> ty::ExistentialBounds { +pub fn super_fold_existential_bounds<'tcx, T: TypeFolder<'tcx>>(this: &mut T, + bounds: ty::ExistentialBounds) + -> ty::ExistentialBounds { ty::ExistentialBounds { region_bound: bounds.region_bound.fold_with(this), builtin_bounds: bounds.builtin_bounds, } } -pub fn super_fold_autoref(this: &mut T, - autoref: &ty::AutoRef) - -> ty::AutoRef +pub fn super_fold_autoref<'tcx, T: TypeFolder<'tcx>>(this: &mut T, + autoref: &ty::AutoRef) + -> ty::AutoRef { match *autoref { ty::AutoPtr(r, m, None) => ty::AutoPtr(this.fold_region(r), m, None), @@ -475,9 +473,9 @@ pub fn super_fold_autoref(this: &mut T, } } -pub fn super_fold_item_substs(this: &mut T, - substs: ty::ItemSubsts) - -> ty::ItemSubsts +pub fn super_fold_item_substs<'tcx, T: TypeFolder<'tcx>>(this: &mut T, + substs: ty::ItemSubsts) + -> ty::ItemSubsts { ty::ItemSubsts { substs: substs.substs.fold_with(this), @@ -487,13 +485,13 @@ pub fn super_fold_item_substs(this: &mut T, /////////////////////////////////////////////////////////////////////////// // Some sample folders -pub struct BottomUpFolder<'a> { - pub tcx: &'a ty::ctxt, +pub struct BottomUpFolder<'a, 'tcx: 'a> { + pub tcx: &'a ty::ctxt<'tcx>, pub fldop: |ty::t|: 'a -> ty::t, } -impl<'a> TypeFolder for BottomUpFolder<'a> { - fn tcx<'a>(&'a self) -> &'a ty::ctxt { self.tcx } +impl<'a, 'tcx> TypeFolder<'tcx> for BottomUpFolder<'a, 'tcx> { + fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.tcx } fn fold_ty(&mut self, ty: ty::t) -> ty::t { let t1 = super_fold_ty(self, ty); @@ -516,18 +514,18 @@ impl<'a> TypeFolder for BottomUpFolder<'a> { /// (The distinction between "free" and "bound" is represented by /// keeping track of each `FnSig` in the lexical context of the /// current position of the fold.) -pub struct RegionFolder<'a> { - tcx: &'a ty::ctxt, +pub struct RegionFolder<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx>, fld_t: |ty::t|: 'a -> ty::t, fld_r: |ty::Region|: 'a -> ty::Region, within_binder_ids: Vec, } -impl<'a> RegionFolder<'a> { - pub fn general(tcx: &'a ty::ctxt, +impl<'a, 'tcx> RegionFolder<'a, 'tcx> { + pub fn general(tcx: &'a ty::ctxt<'tcx>, fld_r: |ty::Region|: 'a -> ty::Region, fld_t: |ty::t|: 'a -> ty::t) - -> RegionFolder<'a> { + -> RegionFolder<'a, 'tcx> { RegionFolder { tcx: tcx, fld_t: fld_t, @@ -536,8 +534,8 @@ impl<'a> RegionFolder<'a> { } } - pub fn regions(tcx: &'a ty::ctxt, fld_r: |ty::Region|: 'a -> ty::Region) - -> RegionFolder<'a> { + pub fn regions(tcx: &'a ty::ctxt<'tcx>, fld_r: |ty::Region|: 'a -> ty::Region) + -> RegionFolder<'a, 'tcx> { fn noop(t: ty::t) -> ty::t { t } RegionFolder { @@ -559,8 +557,8 @@ fn opt_binder_id_of_function(t: ty::t) -> Option { } } -impl<'a> TypeFolder for RegionFolder<'a> { - fn tcx<'a>(&'a self) -> &'a ty::ctxt { self.tcx } +impl<'a, 'tcx> TypeFolder<'tcx> for RegionFolder<'a, 'tcx> { + fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.tcx } fn fold_ty(&mut self, ty: ty::t) -> ty::t { debug!("RegionFolder.fold_ty({})", ty.repr(self.tcx())); diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index 6cd61a8c3f85c..f5fa6168a415c 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -71,8 +71,8 @@ use syntax::abi; use syntax::{ast, ast_util}; use syntax::codemap::Span; -pub trait AstConv { - fn tcx<'a>(&'a self) -> &'a ty::ctxt; +pub trait AstConv<'tcx> { + fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx>; fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype; fn get_trait_def(&self, id: ast::DefId) -> Rc; @@ -118,7 +118,7 @@ pub fn ast_region_to_region(tcx: &ty::ctxt, lifetime: &ast::Lifetime) r } -pub fn opt_ast_region_to_region( +pub fn opt_ast_region_to_region<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( this: &AC, rscope: &RS, default_span: Span, @@ -152,7 +152,7 @@ pub fn opt_ast_region_to_region( r } -fn ast_path_substs( +fn ast_path_substs<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( this: &AC, rscope: &RS, decl_generics: &ty::Generics, @@ -271,7 +271,7 @@ fn ast_path_substs( substs } -pub fn ast_path_to_trait_ref( +pub fn ast_path_to_trait_ref<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( this: &AC, rscope: &RS, trait_def_id: ast::DefId, @@ -284,7 +284,7 @@ pub fn ast_path_to_trait_ref( }) } -pub fn ast_path_to_ty( +pub fn ast_path_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( this: &AC, rscope: &RS, did: ast::DefId, @@ -307,7 +307,7 @@ pub fn ast_path_to_ty( /// and/or region variables are substituted. /// /// This is used when checking the constructor in struct literals. -pub fn ast_path_to_ty_relaxed, RS:RegionScope>( this: &AC, rscope: &RS, @@ -412,12 +412,11 @@ pub fn ast_ty_to_prim_ty(tcx: &ty::ctxt, ast_ty: &ast::Ty) -> Option { /// Converts the given AST type to a built-in type. A "built-in type" is, at /// present, either a core numeric type, a string, or `Box`. -pub fn ast_ty_to_builtin_ty( - this: &AC, - rscope: &RS, - ast_ty: &ast::Ty) - -> Option { +pub fn ast_ty_to_builtin_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( + this: &AC, + rscope: &RS, + ast_ty: &ast::Ty) + -> Option { match ast_ty_to_prim_ty(this.tcx(), ast_ty) { Some(typ) => return Some(typ), None => {} @@ -531,7 +530,7 @@ impl PointerTy { } } -pub fn trait_ref_for_unboxed_function, RS:RegionScope>( this: &AC, rscope: &RS, @@ -576,14 +575,13 @@ pub fn trait_ref_for_unboxed_function( - this: &AC, - rscope: &RS, - a_seq_ty: &ast::MutTy, - ptr_ty: PointerTy, - constr: |ty::t| -> ty::t) - -> ty::t { +fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( + this: &AC, + rscope: &RS, + a_seq_ty: &ast::MutTy, + ptr_ty: PointerTy, + constr: |ty::t| -> ty::t) + -> ty::t { let tcx = this.tcx(); debug!("mk_pointer(ptr_ty={})", ptr_ty); @@ -695,8 +693,8 @@ fn mk_pointer( - this: &AC, rscope: &RS, ast_ty: &ast::Ty) -> ty::t { +pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>( + this: &AC, rscope: &RS, ast_ty: &ast::Ty) -> ty::t { let tcx = this.tcx(); @@ -914,8 +912,10 @@ pub fn ast_ty_to_ty( return typ; } -pub fn ty_of_arg(this: &AC, rscope: &RS, a: &ast::Arg, - expected_ty: Option) -> ty::t { +pub fn ty_of_arg<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(this: &AC, rscope: &RS, + a: &ast::Arg, + expected_ty: Option) + -> ty::t { match a.ty.node { ast::TyInfer if expected_ty.is_some() => expected_ty.unwrap(), ast::TyInfer => this.ty_infer(a.ty.span), @@ -928,7 +928,7 @@ struct SelfInfo<'a> { explicit_self: ast::ExplicitSelf, } -pub fn ty_of_method( +pub fn ty_of_method<'tcx, AC: AstConv<'tcx>>( this: &AC, id: ast::NodeId, fn_style: ast::FnStyle, @@ -951,15 +951,15 @@ pub fn ty_of_method( (bare_fn_ty, optional_explicit_self_category.unwrap()) } -pub fn ty_of_bare_fn(this: &AC, id: ast::NodeId, - fn_style: ast::FnStyle, abi: abi::Abi, - decl: &ast::FnDecl) -> ty::BareFnTy { +pub fn ty_of_bare_fn<'tcx, AC: AstConv<'tcx>>(this: &AC, id: ast::NodeId, + fn_style: ast::FnStyle, abi: abi::Abi, + decl: &ast::FnDecl) -> ty::BareFnTy { let (bare_fn_ty, _) = ty_of_method_or_bare_fn(this, id, fn_style, abi, None, decl); bare_fn_ty } -fn ty_of_method_or_bare_fn( +fn ty_of_method_or_bare_fn<'tcx, AC: AstConv<'tcx>>( this: &AC, id: ast::NodeId, fn_style: ast::FnStyle, @@ -1070,7 +1070,7 @@ fn ty_of_method_or_bare_fn( }, explicit_self_category_result) } -fn determine_explicit_self_category, RS:RegionScope>( this: &AC, rscope: &RS, @@ -1145,7 +1145,7 @@ fn determine_explicit_self_category( +pub fn ty_of_closure<'tcx, AC: AstConv<'tcx>>( this: &AC, id: ast::NodeId, fn_style: ast::FnStyle, @@ -1196,7 +1196,7 @@ pub fn ty_of_closure( } } -pub fn conv_existential_bounds( +pub fn conv_existential_bounds<'tcx, AC: AstConv<'tcx>, RS:RegionScope>( this: &AC, rscope: &RS, span: Span, @@ -1330,7 +1330,7 @@ pub fn compute_opt_region_bound(tcx: &ty::ctxt, return Some(r); } -fn compute_region_bound( +fn compute_region_bound<'tcx, AC: AstConv<'tcx>, RS:RegionScope>( this: &AC, rscope: &RS, span: Span, diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 77e5fbae6ee1c..247178770d21a 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -107,8 +107,8 @@ pub fn check_match(fcx: &FnCtxt, fcx.write_ty(expr.id, result_ty); } -pub struct pat_ctxt<'a> { - pub fcx: &'a FnCtxt<'a>, +pub struct pat_ctxt<'a, 'tcx: 'a> { + pub fcx: &'a FnCtxt<'a, 'tcx>, pub map: PatIdMap, } diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index 3c15135807b9f..88d9a58ab141a 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -123,8 +123,8 @@ pub enum StaticMethodsFlag { IgnoreStaticMethods, } -pub fn lookup<'a>( - fcx: &'a FnCtxt<'a>, +pub fn lookup<'a, 'tcx>( + fcx: &'a FnCtxt<'a, 'tcx>, // In a call `a.b::(...)`: expr: &ast::Expr, // The expression `a.b(...)`. @@ -170,8 +170,8 @@ pub fn lookup<'a>( lcx.search(self_ty) } -pub fn lookup_in_trait<'a>( - fcx: &'a FnCtxt<'a>, +pub fn lookup_in_trait<'a, 'tcx>( + fcx: &'a FnCtxt<'a, 'tcx>, // In a call `a.b::(...)`: span: Span, // The expression `a.b(...)`'s span. @@ -303,8 +303,8 @@ fn construct_transformed_self_ty_for_object( } } -struct LookupContext<'a> { - fcx: &'a FnCtxt<'a>, +struct LookupContext<'a, 'tcx: 'a> { + fcx: &'a FnCtxt<'a, 'tcx>, span: Span, // The receiver to the method call. Only `None` in the case of @@ -350,7 +350,7 @@ pub enum RcvrMatchCondition { RcvrMatchesIfSubtype(ty::t), } -impl<'a> LookupContext<'a> { +impl<'a, 'tcx> LookupContext<'a, 'tcx> { fn search(&self, self_ty: ty::t) -> Option { let span = self.self_expr.map_or(self.span, |e| e.span); let self_expr_id = self.self_expr.map(|e| e.id); @@ -1615,11 +1615,11 @@ impl<'a> LookupContext<'a> { idx + 1u, ty::item_path_str(self.tcx(), did)); } - fn infcx(&'a self) -> &'a infer::InferCtxt<'a> { + fn infcx(&'a self) -> &'a infer::InferCtxt<'a, 'tcx> { &self.fcx.inh.infcx } - fn tcx(&self) -> &'a ty::ctxt { + fn tcx(&self) -> &'a ty::ctxt<'tcx> { self.fcx.tcx() } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index c70e85051749c..01b5fd6e429ee 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -89,7 +89,7 @@ use middle::subst; use middle::subst::{Subst, Substs, VecPerParamSpace, ParamSpace}; use middle::ty::{FnSig, VariantInfo}; use middle::ty::{Polytype}; -use middle::ty::{Disr, ExprTyProvider, ParamTy, ParameterEnvironment}; +use middle::ty::{Disr, ParamTy, ParameterEnvironment}; use middle::ty; use middle::ty_fold::TypeFolder; use middle::typeck::astconv::AstConv; @@ -159,8 +159,8 @@ pub mod method; /// Here, the function `foo()` and the closure passed to /// `bar()` will each have their own `FnCtxt`, but they will /// share the inherited fields. -pub struct Inherited<'a> { - infcx: infer::InferCtxt<'a>, +pub struct Inherited<'a, 'tcx: 'a> { + infcx: infer::InferCtxt<'a, 'tcx>, locals: RefCell>, param_env: ty::ParameterEnvironment, @@ -267,7 +267,7 @@ enum IsBinopAssignment{ } #[deriving(Clone)] -pub struct FnCtxt<'a> { +pub struct FnCtxt<'a, 'tcx: 'a> { body_id: ast::NodeId, // This flag is set to true if, during the writeback phase, we encounter @@ -284,13 +284,13 @@ pub struct FnCtxt<'a> { ps: RefCell, - inh: &'a Inherited<'a>, + inh: &'a Inherited<'a, 'tcx>, - ccx: &'a CrateCtxt<'a>, + ccx: &'a CrateCtxt<'a, 'tcx>, } -impl<'a> mem_categorization::Typer for FnCtxt<'a> { - fn tcx<'a>(&'a self) -> &'a ty::ctxt { +impl<'a, 'tcx> mem_categorization::Typer<'tcx> for FnCtxt<'a, 'tcx> { + fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.ccx.tcx } fn node_ty(&self, id: ast::NodeId) -> McResult { @@ -322,10 +322,10 @@ impl<'a> mem_categorization::Typer for FnCtxt<'a> { } } -impl<'a> Inherited<'a> { - fn new(tcx: &'a ty::ctxt, +impl<'a, 'tcx> Inherited<'a, 'tcx> { + fn new(tcx: &'a ty::ctxt<'tcx>, param_env: ty::ParameterEnvironment) - -> Inherited<'a> { + -> Inherited<'a, 'tcx> { Inherited { infcx: infer::new_infer_ctxt(tcx), locals: RefCell::new(NodeMap::new()), @@ -344,12 +344,11 @@ impl<'a> Inherited<'a> { } // Used by check_const and check_enum_variants -pub fn blank_fn_ctxt<'a>( - ccx: &'a CrateCtxt<'a>, - inh: &'a Inherited<'a>, - rty: ty::t, - body_id: ast::NodeId) - -> FnCtxt<'a> { +pub fn blank_fn_ctxt<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>, + inh: &'a Inherited<'a, 'tcx>, + rty: ty::t, + body_id: ast::NodeId) + -> FnCtxt<'a, 'tcx> { FnCtxt { body_id: body_id, writeback_errors: Cell::new(false), @@ -361,7 +360,8 @@ pub fn blank_fn_ctxt<'a>( } } -fn static_inherited_fields<'a>(ccx: &'a CrateCtxt<'a>) -> Inherited<'a> { +fn static_inherited_fields<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>) + -> Inherited<'a, 'tcx> { // It's kind of a kludge to manufacture a fake function context // and statement context, but we might as well do write the code only once let param_env = ty::ParameterEnvironment { @@ -372,37 +372,29 @@ fn static_inherited_fields<'a>(ccx: &'a CrateCtxt<'a>) -> Inherited<'a> { Inherited::new(ccx.tcx, param_env) } -impl<'a> ExprTyProvider for FnCtxt<'a> { - fn expr_ty(&self, ex: &ast::Expr) -> ty::t { - self.expr_ty(ex) - } - - fn ty_ctxt<'a>(&'a self) -> &'a ty::ctxt { - self.ccx.tcx - } -} - -struct CheckTypeWellFormedVisitor<'a> { ccx: &'a CrateCtxt<'a> } +struct CheckItemTypesVisitor<'a, 'tcx: 'a> { ccx: &'a CrateCtxt<'a, 'tcx> } +struct CheckTypeWellFormedVisitor<'a, 'tcx: 'a> { ccx: &'a CrateCtxt<'a, 'tcx> } -impl<'a> Visitor<()> for CheckTypeWellFormedVisitor<'a> { +impl<'a, 'tcx> Visitor<()> for CheckTypeWellFormedVisitor<'a, 'tcx> { fn visit_item(&mut self, i: &ast::Item, _: ()) { check_type_well_formed(self.ccx, i); visit::walk_item(self, i, ()); } } -struct CheckItemTypesVisitor<'a> { ccx: &'a CrateCtxt<'a> } -impl<'a> Visitor<()> for CheckItemTypesVisitor<'a> { +impl<'a, 'tcx> Visitor<()> for CheckItemTypesVisitor<'a, 'tcx> { fn visit_item(&mut self, i: &ast::Item, _: ()) { check_item(self.ccx, i); visit::walk_item(self, i, ()); } } -struct CheckItemSizedTypesVisitor<'a> { ccx: &'a CrateCtxt<'a> } +struct CheckItemSizedTypesVisitor<'a, 'tcx: 'a> { + ccx: &'a CrateCtxt<'a, 'tcx> +} -impl<'a> Visitor<()> for CheckItemSizedTypesVisitor<'a> { +impl<'a, 'tcx> Visitor<()> for CheckItemSizedTypesVisitor<'a, 'tcx> { fn visit_item(&mut self, i: &ast::Item, _: ()) { check_item_sized(self.ccx, i); visit::walk_item(self, i, ()); @@ -451,11 +443,11 @@ fn check_bare_fn(ccx: &CrateCtxt, } } -struct GatherLocalsVisitor<'a> { - fcx: &'a FnCtxt<'a> +struct GatherLocalsVisitor<'a, 'tcx: 'a> { + fcx: &'a FnCtxt<'a, 'tcx> } -impl<'a> GatherLocalsVisitor<'a> { +impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> { fn assign(&mut self, nid: ast::NodeId, ty_opt: Option) { match ty_opt { None => { @@ -472,7 +464,7 @@ impl<'a> GatherLocalsVisitor<'a> { } } -impl<'a> Visitor<()> for GatherLocalsVisitor<'a> { +impl<'a, 'tcx> Visitor<()> for GatherLocalsVisitor<'a, 'tcx> { // Add explicitly-declared locals. fn visit_local(&mut self, local: &ast::Local, _: ()) { let o_ty = match local.ty.node { @@ -530,17 +522,15 @@ impl<'a> Visitor<()> for GatherLocalsVisitor<'a> { } -fn check_fn<'a>( - ccx: &'a CrateCtxt<'a>, - fn_style: ast::FnStyle, - fn_style_id: ast::NodeId, - fn_sig: &ty::FnSig, - decl: &ast::FnDecl, - fn_id: ast::NodeId, - body: &ast::Block, - inherited: &'a Inherited<'a>) - -> FnCtxt<'a> -{ +fn check_fn<'a, 'tcx>(ccx: &'a CrateCtxt<'a, 'tcx>, + fn_style: ast::FnStyle, + fn_style_id: ast::NodeId, + fn_sig: &ty::FnSig, + decl: &ast::FnDecl, + fn_id: ast::NodeId, + body: &ast::Block, + inherited: &'a Inherited<'a, 'tcx>) + -> FnCtxt<'a, 'tcx> { /*! * Helper used by check_bare_fn and check_expr_fn. Does the * grungy work of checking a function body and returns the @@ -1563,8 +1553,8 @@ fn check_cast(fcx: &FnCtxt, fcx.write_ty(id, t_1); } -impl<'a> AstConv for FnCtxt<'a> { - fn tcx<'a>(&'a self) -> &'a ty::ctxt { self.ccx.tcx } +impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { + fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.ccx.tcx } fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype { ty::lookup_item_type(self.tcx(), id) @@ -1579,10 +1569,10 @@ impl<'a> AstConv for FnCtxt<'a> { } } -impl<'a> FnCtxt<'a> { - fn tcx<'a>(&'a self) -> &'a ty::ctxt { self.ccx.tcx } +impl<'a, 'tcx> FnCtxt<'a, 'tcx> { + fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.ccx.tcx } - pub fn infcx<'b>(&'b self) -> &'b infer::InferCtxt<'a> { + pub fn infcx<'b>(&'b self) -> &'b infer::InferCtxt<'a, 'tcx> { &self.inh.infcx } @@ -1590,7 +1580,7 @@ impl<'a> FnCtxt<'a> { self.ccx.tcx.sess.err_count() - self.err_count_on_creation } - pub fn vtable_context<'a>(&'a self) -> VtableContext<'a> { + pub fn vtable_context<'a>(&'a self) -> VtableContext<'a, 'tcx> { VtableContext { infcx: self.infcx(), param_env: &self.inh.param_env, @@ -1599,7 +1589,7 @@ impl<'a> FnCtxt<'a> { } } -impl<'a> RegionScope for infer::InferCtxt<'a> { +impl<'a, 'tcx> RegionScope for infer::InferCtxt<'a, 'tcx> { fn default_region_bound(&self, span: Span) -> Option { Some(self.next_region_var(infer::MiscVariable(span))) } @@ -1612,7 +1602,7 @@ impl<'a> RegionScope for infer::InferCtxt<'a> { } } -impl<'a> FnCtxt<'a> { +impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn tag(&self) -> String { format!("{}", self as *const FnCtxt) } @@ -3919,7 +3909,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt, } ast::ExprRepeat(ref element, ref count_expr) => { check_expr_has_type(fcx, &**count_expr, ty::mk_uint()); - let count = ty::eval_repeat_count(fcx, &**count_expr); + let count = ty::eval_repeat_count(fcx.tcx(), &**count_expr); let uty = match expected { ExpectHasType(uty) => { diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index 16ecaa9714ec7..eb630d0fc7bbe 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -196,8 +196,8 @@ macro_rules! ignore_err( ) ) -pub struct Rcx<'a> { - fcx: &'a FnCtxt<'a>, +pub struct Rcx<'a, 'tcx: 'a> { + fcx: &'a FnCtxt<'a, 'tcx>, region_param_pairs: Vec<(ty::Region, ty::ParamTy)>, @@ -250,15 +250,15 @@ fn region_of_def(fcx: &FnCtxt, def: def::Def) -> ty::Region { } } -impl<'a> Rcx<'a> { - pub fn new(fcx: &'a FnCtxt<'a>, - initial_repeating_scope: ast::NodeId) -> Rcx<'a> { +impl<'a, 'tcx> Rcx<'a, 'tcx> { + pub fn new(fcx: &'a FnCtxt<'a, 'tcx>, + initial_repeating_scope: ast::NodeId) -> Rcx<'a, 'tcx> { Rcx { fcx: fcx, repeating_scope: initial_repeating_scope, region_param_pairs: Vec::new() } } - pub fn tcx(&self) -> &'a ty::ctxt { + pub fn tcx(&self) -> &'a ty::ctxt<'tcx> { self.fcx.ccx.tcx } @@ -438,8 +438,8 @@ impl<'a> Rcx<'a> { } } -impl<'fcx> mc::Typer for Rcx<'fcx> { - fn tcx<'a>(&'a self) -> &'a ty::ctxt { +impl<'fcx, 'tcx> mc::Typer<'tcx> for Rcx<'fcx, 'tcx> { + fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.fcx.ccx.tcx } @@ -479,7 +479,7 @@ impl<'fcx> mc::Typer for Rcx<'fcx> { } } -impl<'a> Visitor<()> for Rcx<'a> { +impl<'a, 'tcx> Visitor<()> for Rcx<'a, 'tcx> { // (..) FIXME(#3238) should use visit_pat, not visit_arm/visit_local, // However, right now we run into an issue whereby some free // regions are not properly related if they appear within the diff --git a/src/librustc/middle/typeck/check/regionmanip.rs b/src/librustc/middle/typeck/check/regionmanip.rs index 577da159162fc..60e502786ab3d 100644 --- a/src/librustc/middle/typeck/check/regionmanip.rs +++ b/src/librustc/middle/typeck/check/regionmanip.rs @@ -51,8 +51,8 @@ pub enum WfConstraint { RegionSubParamConstraint(Option, ty::Region, ty::ParamTy), } -struct Wf<'a> { - tcx: &'a ty::ctxt, +struct Wf<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx>, stack: Vec<(ty::Region, Option)>, out: Vec, } @@ -78,7 +78,7 @@ pub fn region_wf_constraints( wf.out } -impl<'a> Wf<'a> { +impl<'a, 'tcx> Wf<'a, 'tcx> { fn accumulate_from_ty(&mut self, ty: ty::t) { debug!("Wf::accumulate_from_ty(ty={})", ty.repr(self.tcx)); diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index da4bc4dbc7694..16136fcf3e840 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -68,14 +68,14 @@ use syntax::visit::Visitor; /// A vtable context includes an inference context, a parameter environment, /// and a list of unboxed closure types. -pub struct VtableContext<'a> { - pub infcx: &'a infer::InferCtxt<'a>, +pub struct VtableContext<'a, 'tcx: 'a> { + pub infcx: &'a infer::InferCtxt<'a, 'tcx>, pub param_env: &'a ty::ParameterEnvironment, pub unboxed_closures: &'a RefCell>, } -impl<'a> VtableContext<'a> { - pub fn tcx(&self) -> &'a ty::ctxt { self.infcx.tcx } +impl<'a, 'tcx> VtableContext<'a, 'tcx> { + pub fn tcx(&self) -> &'a ty::ctxt<'tcx> { self.infcx.tcx } } fn lookup_vtables(vcx: &VtableContext, @@ -1025,7 +1025,7 @@ pub fn trans_resolve_method(tcx: &ty::ctxt, id: ast::NodeId, false) } -impl<'a, 'b> visit::Visitor<()> for &'a FnCtxt<'b> { +impl<'a, 'b, 'tcx> visit::Visitor<()> for &'a FnCtxt<'b, 'tcx> { fn visit_expr(&mut self, ex: &ast::Expr, _: ()) { early_resolve_expr(ex, *self, false); visit::walk_expr(self, ex, ()); diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc/middle/typeck/check/writeback.rs index 7951c8dfc1980..d65172cc0c167 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc/middle/typeck/check/writeback.rs @@ -84,16 +84,16 @@ pub fn resolve_impl_res(infcx: &infer::InferCtxt, // there, it applies a few ad-hoc checks that were not convenient to // do elsewhere. -struct WritebackCx<'cx> { - fcx: &'cx FnCtxt<'cx>, +struct WritebackCx<'cx, 'tcx: 'cx> { + fcx: &'cx FnCtxt<'cx, 'tcx>, } -impl<'cx> WritebackCx<'cx> { - fn new(fcx: &'cx FnCtxt) -> WritebackCx<'cx> { +impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { + fn new(fcx: &'cx FnCtxt<'cx, 'tcx>) -> WritebackCx<'cx, 'tcx> { WritebackCx { fcx: fcx } } - fn tcx(&self) -> &'cx ty::ctxt { + fn tcx(&self) -> &'cx ty::ctxt<'tcx> { self.fcx.tcx() } } @@ -106,7 +106,7 @@ impl<'cx> WritebackCx<'cx> { // below. In general, a function is made into a `visitor` if it must // traffic in node-ids or update tables in the type context etc. -impl<'cx> Visitor<()> for WritebackCx<'cx> { +impl<'cx, 'tcx> Visitor<()> for WritebackCx<'cx, 'tcx> { fn visit_item(&mut self, _: &ast::Item, _: ()) { // Ignore items } @@ -192,7 +192,7 @@ impl<'cx> Visitor<()> for WritebackCx<'cx> { } } -impl<'cx> WritebackCx<'cx> { +impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { fn visit_upvar_borrow_map(&self) { if self.fcx.writeback_errors.get() { return; @@ -400,17 +400,17 @@ impl ResolveIn for T { // The Resolver. This is the type folding engine that detects // unresolved types and so forth. -struct Resolver<'cx> { - tcx: &'cx ty::ctxt, - infcx: &'cx infer::InferCtxt<'cx>, +struct Resolver<'cx, 'tcx: 'cx> { + tcx: &'cx ty::ctxt<'tcx>, + infcx: &'cx infer::InferCtxt<'cx, 'tcx>, writeback_errors: &'cx Cell, reason: ResolveReason, } -impl<'cx> Resolver<'cx> { - fn new(fcx: &'cx FnCtxt<'cx>, +impl<'cx, 'tcx> Resolver<'cx, 'tcx> { + fn new(fcx: &'cx FnCtxt<'cx, 'tcx>, reason: ResolveReason) - -> Resolver<'cx> + -> Resolver<'cx, 'tcx> { Resolver { infcx: fcx.infcx(), tcx: fcx.tcx(), @@ -418,10 +418,10 @@ impl<'cx> Resolver<'cx> { reason: reason } } - fn from_infcx(infcx: &'cx infer::InferCtxt<'cx>, + fn from_infcx(infcx: &'cx infer::InferCtxt<'cx, 'tcx>, writeback_errors: &'cx Cell, reason: ResolveReason) - -> Resolver<'cx> + -> Resolver<'cx, 'tcx> { Resolver { infcx: infcx, tcx: infcx.tcx, @@ -475,8 +475,8 @@ impl<'cx> Resolver<'cx> { } } -impl<'cx> TypeFolder for Resolver<'cx> { - fn tcx<'a>(&'a self) -> &'a ty::ctxt { +impl<'cx, 'tcx> TypeFolder<'tcx> for Resolver<'cx, 'tcx> { + fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.tcx } diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 9c58a4c79f057..2c6dc94f182b4 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -182,16 +182,16 @@ fn get_base_type_def_id(inference_context: &InferCtxt, } } -struct CoherenceChecker<'a> { - crate_context: &'a CrateCtxt<'a>, - inference_context: InferCtxt<'a>, +struct CoherenceChecker<'a, 'tcx: 'a> { + crate_context: &'a CrateCtxt<'a, 'tcx>, + inference_context: InferCtxt<'a, 'tcx>, } -struct CoherenceCheckVisitor<'a> { - cc: &'a CoherenceChecker<'a> +struct CoherenceCheckVisitor<'a, 'tcx: 'a> { + cc: &'a CoherenceChecker<'a, 'tcx> } -impl<'a> visit::Visitor<()> for CoherenceCheckVisitor<'a> { +impl<'a, 'tcx> visit::Visitor<()> for CoherenceCheckVisitor<'a, 'tcx> { fn visit_item(&mut self, item: &Item, _: ()) { //debug!("(checking coherence) item '{}'", token::get_ident(item.ident)); @@ -214,9 +214,11 @@ impl<'a> visit::Visitor<()> for CoherenceCheckVisitor<'a> { } } -struct PrivilegedScopeVisitor<'a> { cc: &'a CoherenceChecker<'a> } +struct PrivilegedScopeVisitor<'a, 'tcx: 'a> { + cc: &'a CoherenceChecker<'a, 'tcx> +} -impl<'a> visit::Visitor<()> for PrivilegedScopeVisitor<'a> { +impl<'a, 'tcx> visit::Visitor<()> for PrivilegedScopeVisitor<'a, 'tcx> { fn visit_item(&mut self, item: &Item, _: ()) { match item.node { @@ -263,7 +265,7 @@ impl<'a> visit::Visitor<()> for PrivilegedScopeVisitor<'a> { } } -impl<'a> CoherenceChecker<'a> { +impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { fn check(&self, krate: &Crate) { // Check implementations and traits. This populates the tables // containing the inherent methods and extension methods. It also diff --git a/src/librustc/middle/typeck/collect.rs b/src/librustc/middle/typeck/collect.rs index c22baa1d9e5d3..742d22cc3793f 100644 --- a/src/librustc/middle/typeck/collect.rs +++ b/src/librustc/middle/typeck/collect.rs @@ -95,11 +95,11 @@ pub fn collect_item_types(ccx: &CrateCtxt, krate: &ast::Crate) { // of type parameters and supertraits. This is information we need to // know later when parsing field defs. -struct CollectTraitDefVisitor<'a> { - ccx: &'a CrateCtxt<'a> +struct CollectTraitDefVisitor<'a, 'tcx: 'a> { + ccx: &'a CrateCtxt<'a, 'tcx> } -impl<'a> visit::Visitor<()> for CollectTraitDefVisitor<'a> { +impl<'a, 'tcx> visit::Visitor<()> for CollectTraitDefVisitor<'a, 'tcx> { fn visit_item(&mut self, i: &ast::Item, _: ()) { match i.node { ast::ItemTrait(..) => { @@ -116,11 +116,11 @@ impl<'a> visit::Visitor<()> for CollectTraitDefVisitor<'a> { /////////////////////////////////////////////////////////////////////////// // Second phase: collection proper. -struct CollectItemTypesVisitor<'a> { - ccx: &'a CrateCtxt<'a> +struct CollectItemTypesVisitor<'a, 'tcx: 'a> { + ccx: &'a CrateCtxt<'a, 'tcx> } -impl<'a> visit::Visitor<()> for CollectItemTypesVisitor<'a> { +impl<'a, 'tcx> visit::Visitor<()> for CollectItemTypesVisitor<'a, 'tcx> { fn visit_item(&mut self, i: &ast::Item, _: ()) { convert(self.ccx, i); visit::walk_item(self, i, ()); @@ -138,14 +138,14 @@ pub trait ToTy { fn to_ty(&self, rs: &RS, ast_ty: &ast::Ty) -> ty::t; } -impl<'a> ToTy for CrateCtxt<'a> { +impl<'a, 'tcx> ToTy for CrateCtxt<'a, 'tcx> { fn to_ty(&self, rs: &RS, ast_ty: &ast::Ty) -> ty::t { ast_ty_to_ty(self, rs, ast_ty) } } -impl<'a> AstConv for CrateCtxt<'a> { - fn tcx<'a>(&'a self) -> &'a ty::ctxt { self.tcx } +impl<'a, 'tcx> AstConv<'tcx> for CrateCtxt<'a, 'tcx> { + fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.tcx } fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype { if id.krate != ast::LOCAL_CRATE { diff --git a/src/librustc/middle/typeck/infer/coercion.rs b/src/librustc/middle/typeck/infer/coercion.rs index 7763a992c8f94..44141f25418e4 100644 --- a/src/librustc/middle/typeck/infer/coercion.rs +++ b/src/librustc/middle/typeck/infer/coercion.rs @@ -82,10 +82,10 @@ use syntax::ast; // Note: Coerce is not actually a combiner, in that it does not // conform to the same interface, though it performs a similar // function. -pub struct Coerce<'f>(pub CombineFields<'f>); +pub struct Coerce<'f, 'tcx: 'f>(pub CombineFields<'f, 'tcx>); -impl<'f> Coerce<'f> { - pub fn get_ref<'a>(&'a self) -> &'a CombineFields<'f> { +impl<'f, 'tcx> Coerce<'f, 'tcx> { + pub fn get_ref<'a>(&'a self) -> &'a CombineFields<'f, 'tcx> { let Coerce(ref v) = *self; v } diff --git a/src/librustc/middle/typeck/infer/combine.rs b/src/librustc/middle/typeck/infer/combine.rs index 2a44ef9de2b1b..66caf10cb408c 100644 --- a/src/librustc/middle/typeck/infer/combine.rs +++ b/src/librustc/middle/typeck/infer/combine.rs @@ -57,16 +57,16 @@ use syntax::ast::{Onceness, FnStyle}; use syntax::ast; use syntax::abi; -pub trait Combine { - fn infcx<'a>(&'a self) -> &'a InferCtxt<'a>; +pub trait Combine<'tcx> { + fn infcx<'a>(&'a self) -> &'a InferCtxt<'a, 'tcx>; fn tag(&self) -> String; fn a_is_expected(&self) -> bool; fn trace(&self) -> TypeTrace; - fn equate<'a>(&'a self) -> Equate<'a>; - fn sub<'a>(&'a self) -> Sub<'a>; - fn lub<'a>(&'a self) -> Lub<'a>; - fn glb<'a>(&'a self) -> Glb<'a>; + fn equate<'a>(&'a self) -> Equate<'a, 'tcx>; + fn sub<'a>(&'a self) -> Sub<'a, 'tcx>; + fn lub<'a>(&'a self) -> Lub<'a, 'tcx>; + fn glb<'a>(&'a self) -> Glb<'a, 'tcx>; fn mts(&self, a: &ty::mt, b: &ty::mt) -> cres; fn contratys(&self, a: ty::t, b: ty::t) -> cres; @@ -138,13 +138,12 @@ pub trait Combine { return Ok(substs); - fn relate_region_params(this: &C, - item_def_id: ast::DefId, - variances: &[ty::Variance], - a_rs: &[ty::Region], - b_rs: &[ty::Region]) - -> cres> - { + fn relate_region_params<'tcx, C: Combine<'tcx>>(this: &C, + item_def_id: ast::DefId, + variances: &[ty::Variance], + a_rs: &[ty::Region], + b_rs: &[ty::Region]) + -> cres> { let tcx = this.infcx().tcx; let num_region_params = variances.len(); @@ -305,13 +304,13 @@ pub trait Combine { } #[deriving(Clone)] -pub struct CombineFields<'a> { - pub infcx: &'a InferCtxt<'a>, +pub struct CombineFields<'a, 'tcx: 'a> { + pub infcx: &'a InferCtxt<'a, 'tcx>, pub a_is_expected: bool, pub trace: TypeTrace, } -pub fn expected_found( +pub fn expected_found<'tcx, C: Combine<'tcx>, T>( this: &C, a: T, b: T) -> ty::expected_found { if this.a_is_expected() { ty::expected_found {expected: a, found: b} @@ -320,9 +319,15 @@ pub fn expected_found( } } -pub fn super_fn_sigs(this: &C, a: &ty::FnSig, b: &ty::FnSig) -> cres { +pub fn super_fn_sigs<'tcx, C: Combine<'tcx>>(this: &C, + a: &ty::FnSig, + b: &ty::FnSig) + -> cres { - fn argvecs(this: &C, a_args: &[ty::t], b_args: &[ty::t]) -> cres > { + fn argvecs<'tcx, C: Combine<'tcx>>(this: &C, + a_args: &[ty::t], + b_args: &[ty::t]) + -> cres> { if a_args.len() == b_args.len() { result::collect(a_args.iter().zip(b_args.iter()) .map(|(a, b)| this.args(*a, *b))) @@ -345,18 +350,18 @@ pub fn super_fn_sigs(this: &C, a: &ty::FnSig, b: &ty::FnSig) -> cres< variadic: a.variadic}) } -pub fn super_tys(this: &C, a: ty::t, b: ty::t) -> cres { +pub fn super_tys<'tcx, C: Combine<'tcx>>(this: &C, a: ty::t, b: ty::t) -> cres { // This is a horrible hack - historically, [T] was not treated as a type, // so, for example, &T and &[U] should not unify. In fact the only thing // &[U] should unify with is &[T]. We preserve that behaviour with this // check. - fn check_ptr_to_unsized(this: &C, - a: ty::t, - b: ty::t, - a_inner: ty::t, - b_inner: ty::t, - result: ty::t) -> cres { + fn check_ptr_to_unsized<'tcx, C: Combine<'tcx>>(this: &C, + a: ty::t, + b: ty::t, + a_inner: ty::t, + b_inner: ty::t, + result: ty::t) -> cres { match (&ty::get(a_inner).sty, &ty::get(b_inner).sty) { (&ty::ty_vec(_, None), &ty::ty_vec(_, None)) | (&ty::ty_str, &ty::ty_str) | @@ -547,7 +552,7 @@ pub fn super_tys(this: &C, a: ty::t, b: ty::t) -> cres { _ => Err(ty::terr_sorts(expected_found(this, a, b))) }; - fn unify_integral_variable( + fn unify_integral_variable<'tcx, C: Combine<'tcx>>( this: &C, vid_is_expected: bool, vid: ty::IntVid, @@ -560,7 +565,7 @@ pub fn super_tys(this: &C, a: ty::t, b: ty::t) -> cres { } } - fn unify_float_variable( + fn unify_float_variable<'tcx, C: Combine<'tcx>>( this: &C, vid_is_expected: bool, vid: ty::FloatVid, @@ -571,19 +576,19 @@ pub fn super_tys(this: &C, a: ty::t, b: ty::t) -> cres { } } -impl<'f> CombineFields<'f> { - pub fn switch_expected(&self) -> CombineFields<'f> { +impl<'f, 'tcx> CombineFields<'f, 'tcx> { + pub fn switch_expected(&self) -> CombineFields<'f, 'tcx> { CombineFields { a_is_expected: !self.a_is_expected, ..(*self).clone() } } - fn equate(&self) -> Equate<'f> { + fn equate(&self) -> Equate<'f, 'tcx> { Equate((*self).clone()) } - fn sub(&self) -> Sub<'f> { + fn sub(&self) -> Sub<'f, 'tcx> { Sub((*self).clone()) } diff --git a/src/librustc/middle/typeck/infer/equate.rs b/src/librustc/middle/typeck/infer/equate.rs index 223d37ee1ea62..fd4a592736218 100644 --- a/src/librustc/middle/typeck/infer/equate.rs +++ b/src/librustc/middle/typeck/infer/equate.rs @@ -23,25 +23,25 @@ use util::ppaux::{Repr}; use syntax::ast::{Onceness, FnStyle}; -pub struct Equate<'f> { - fields: CombineFields<'f> +pub struct Equate<'f, 'tcx: 'f> { + fields: CombineFields<'f, 'tcx> } #[allow(non_snake_case)] -pub fn Equate<'f>(cf: CombineFields<'f>) -> Equate<'f> { +pub fn Equate<'f, 'tcx>(cf: CombineFields<'f, 'tcx>) -> Equate<'f, 'tcx> { Equate { fields: cf } } -impl<'f> Combine for Equate<'f> { - fn infcx<'a>(&'a self) -> &'a InferCtxt<'a> { self.fields.infcx } +impl<'f, 'tcx> Combine<'tcx> for Equate<'f, 'tcx> { + fn infcx<'a>(&'a self) -> &'a InferCtxt<'a, 'tcx> { self.fields.infcx } fn tag(&self) -> String { "eq".to_string() } fn a_is_expected(&self) -> bool { self.fields.a_is_expected } fn trace(&self) -> TypeTrace { self.fields.trace.clone() } - fn equate<'a>(&'a self) -> Equate<'a> { Equate(self.fields.clone()) } - fn sub<'a>(&'a self) -> Sub<'a> { Sub(self.fields.clone()) } - fn lub<'a>(&'a self) -> Lub<'a> { Lub(self.fields.clone()) } - fn glb<'a>(&'a self) -> Glb<'a> { Glb(self.fields.clone()) } + fn equate<'a>(&'a self) -> Equate<'a, 'tcx> { Equate(self.fields.clone()) } + fn sub<'a>(&'a self) -> Sub<'a, 'tcx> { Sub(self.fields.clone()) } + fn lub<'a>(&'a self) -> Lub<'a, 'tcx> { Lub(self.fields.clone()) } + fn glb<'a>(&'a self) -> Glb<'a, 'tcx> { Glb(self.fields.clone()) } fn contratys(&self, a: ty::t, b: ty::t) -> cres { self.tys(a, b) diff --git a/src/librustc/middle/typeck/infer/error_reporting.rs b/src/librustc/middle/typeck/infer/error_reporting.rs index bd355d2f580b9..e602e6a7b3c56 100644 --- a/src/librustc/middle/typeck/infer/error_reporting.rs +++ b/src/librustc/middle/typeck/infer/error_reporting.rs @@ -166,7 +166,7 @@ trait ErrorReportingHelpers { span: codemap::Span); } -impl<'a> ErrorReporting for InferCtxt<'a> { +impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> { fn report_region_errors(&self, errors: &Vec) { let p_errors = self.process_errors(errors); @@ -900,8 +900,8 @@ struct RebuildPathInfo<'a> { region_names: &'a HashSet } -struct Rebuilder<'a> { - tcx: &'a ty::ctxt, +struct Rebuilder<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx>, fn_decl: ast::P, expl_self_opt: Option, generics: &'a ast::Generics, @@ -916,14 +916,14 @@ enum FreshOrKept { Kept } -impl<'a> Rebuilder<'a> { - fn new(tcx: &'a ty::ctxt, +impl<'a, 'tcx> Rebuilder<'a, 'tcx> { + fn new(tcx: &'a ty::ctxt<'tcx>, fn_decl: ast::P, expl_self_opt: Option, generics: &'a ast::Generics, same_regions: &'a [SameRegions], life_giver: &'a LifeGiver) - -> Rebuilder<'a> { + -> Rebuilder<'a, 'tcx> { Rebuilder { tcx: tcx, fn_decl: fn_decl, @@ -1403,7 +1403,7 @@ impl<'a> Rebuilder<'a> { } } -impl<'a> ErrorReportingHelpers for InferCtxt<'a> { +impl<'a, 'tcx> ErrorReportingHelpers for InferCtxt<'a, 'tcx> { fn give_expl_lifetime_param(&self, decl: &ast::FnDecl, fn_style: ast::FnStyle, diff --git a/src/librustc/middle/typeck/infer/glb.rs b/src/librustc/middle/typeck/infer/glb.rs index 8ae141ea19cc2..08d4f9f3a86e5 100644 --- a/src/librustc/middle/typeck/infer/glb.rs +++ b/src/librustc/middle/typeck/infer/glb.rs @@ -30,25 +30,25 @@ use util::ppaux::mt_to_string; use util::ppaux::Repr; /// "Greatest lower bound" (common subtype) -pub struct Glb<'f> { - fields: CombineFields<'f> +pub struct Glb<'f, 'tcx: 'f> { + fields: CombineFields<'f, 'tcx> } #[allow(non_snake_case)] -pub fn Glb<'f>(cf: CombineFields<'f>) -> Glb<'f> { +pub fn Glb<'f, 'tcx>(cf: CombineFields<'f, 'tcx>) -> Glb<'f, 'tcx> { Glb { fields: cf } } -impl<'f> Combine for Glb<'f> { - fn infcx<'a>(&'a self) -> &'a InferCtxt<'a> { self.fields.infcx } +impl<'f, 'tcx> Combine<'tcx> for Glb<'f, 'tcx> { + fn infcx<'a>(&'a self) -> &'a InferCtxt<'a, 'tcx> { self.fields.infcx } fn tag(&self) -> String { "glb".to_string() } fn a_is_expected(&self) -> bool { self.fields.a_is_expected } fn trace(&self) -> TypeTrace { self.fields.trace.clone() } - fn equate<'a>(&'a self) -> Equate<'a> { Equate(self.fields.clone()) } - fn sub<'a>(&'a self) -> Sub<'a> { Sub(self.fields.clone()) } - fn lub<'a>(&'a self) -> Lub<'a> { Lub(self.fields.clone()) } - fn glb<'a>(&'a self) -> Glb<'a> { Glb(self.fields.clone()) } + fn equate<'a>(&'a self) -> Equate<'a, 'tcx> { Equate(self.fields.clone()) } + fn sub<'a>(&'a self) -> Sub<'a, 'tcx> { Sub(self.fields.clone()) } + fn lub<'a>(&'a self) -> Lub<'a, 'tcx> { Lub(self.fields.clone()) } + fn glb<'a>(&'a self) -> Glb<'a, 'tcx> { Glb(self.fields.clone()) } fn mts(&self, a: &ty::mt, b: &ty::mt) -> cres { let tcx = self.fields.infcx.tcx; diff --git a/src/librustc/middle/typeck/infer/lattice.rs b/src/librustc/middle/typeck/infer/lattice.rs index f09773d30b514..6095e5b050423 100644 --- a/src/librustc/middle/typeck/infer/lattice.rs +++ b/src/librustc/middle/typeck/infer/lattice.rs @@ -51,7 +51,7 @@ pub trait LatticeDir { fn relate_bound<'a>(&'a self, v: ty::t, a: ty::t, b: ty::t) -> cres<()>; } -impl<'a> LatticeDir for Lub<'a> { +impl<'a, 'tcx> LatticeDir for Lub<'a, 'tcx> { fn ty_bot(&self, t: ty::t) -> cres { Ok(t) } @@ -64,7 +64,7 @@ impl<'a> LatticeDir for Lub<'a> { } } -impl<'a> LatticeDir for Glb<'a> { +impl<'a, 'tcx> LatticeDir for Glb<'a, 'tcx> { fn ty_bot(&self, _: ty::t) -> cres { Ok(ty::mk_bot()) } @@ -77,10 +77,10 @@ impl<'a> LatticeDir for Glb<'a> { } } -pub fn super_lattice_tys(this: &L, - a: ty::t, - b: ty::t) - -> cres +pub fn super_lattice_tys<'tcx, L:LatticeDir+Combine<'tcx>>(this: &L, + a: ty::t, + b: ty::t) + -> cres { debug!("{}.lattice_tys({}, {})", this.tag(), @@ -115,9 +115,9 @@ pub fn super_lattice_tys(this: &L, // Random utility functions used by LUB/GLB when computing LUB/GLB of // fn types -pub fn var_ids(this: &T, - map: &HashMap) - -> Vec { +pub fn var_ids<'tcx, T: Combine<'tcx>>(this: &T, + map: &HashMap) + -> Vec { map.iter().map(|(_, r)| match *r { ty::ReInfer(ty::ReVar(r)) => { r } r => { diff --git a/src/librustc/middle/typeck/infer/lub.rs b/src/librustc/middle/typeck/infer/lub.rs index 49760ac92bf7d..276a226483741 100644 --- a/src/librustc/middle/typeck/infer/lub.rs +++ b/src/librustc/middle/typeck/infer/lub.rs @@ -29,25 +29,25 @@ use util::ppaux::mt_to_string; use util::ppaux::Repr; /// "Least upper bound" (common supertype) -pub struct Lub<'f> { - fields: CombineFields<'f> +pub struct Lub<'f, 'tcx: 'f> { + fields: CombineFields<'f, 'tcx> } #[allow(non_snake_case)] -pub fn Lub<'f>(cf: CombineFields<'f>) -> Lub<'f> { +pub fn Lub<'f, 'tcx>(cf: CombineFields<'f, 'tcx>) -> Lub<'f, 'tcx> { Lub { fields: cf } } -impl<'f> Combine for Lub<'f> { - fn infcx<'a>(&'a self) -> &'a InferCtxt<'a> { self.fields.infcx } +impl<'f, 'tcx> Combine<'tcx> for Lub<'f, 'tcx> { + fn infcx<'a>(&'a self) -> &'a InferCtxt<'a, 'tcx> { self.fields.infcx } fn tag(&self) -> String { "lub".to_string() } fn a_is_expected(&self) -> bool { self.fields.a_is_expected } fn trace(&self) -> TypeTrace { self.fields.trace.clone() } - fn equate<'a>(&'a self) -> Equate<'a> { Equate(self.fields.clone()) } - fn sub<'a>(&'a self) -> Sub<'a> { Sub(self.fields.clone()) } - fn lub<'a>(&'a self) -> Lub<'a> { Lub(self.fields.clone()) } - fn glb<'a>(&'a self) -> Glb<'a> { Glb(self.fields.clone()) } + fn equate<'a>(&'a self) -> Equate<'a, 'tcx> { Equate(self.fields.clone()) } + fn sub<'a>(&'a self) -> Sub<'a, 'tcx> { Sub(self.fields.clone()) } + fn lub<'a>(&'a self) -> Lub<'a, 'tcx> { Lub(self.fields.clone()) } + fn glb<'a>(&'a self) -> Glb<'a, 'tcx> { Glb(self.fields.clone()) } fn mts(&self, a: &ty::mt, b: &ty::mt) -> cres { let tcx = self.fields.infcx.tcx; diff --git a/src/librustc/middle/typeck/infer/mod.rs b/src/librustc/middle/typeck/infer/mod.rs index f86857f97f654..44ee7ba2de6e4 100644 --- a/src/librustc/middle/typeck/infer/mod.rs +++ b/src/librustc/middle/typeck/infer/mod.rs @@ -75,8 +75,8 @@ pub type ures = cres<()>; // "unify result" pub type fres = Result; // "fixup result" pub type CoerceResult = cres>; -pub struct InferCtxt<'a> { - pub tcx: &'a ty::ctxt, +pub struct InferCtxt<'a, 'tcx: 'a> { + pub tcx: &'a ty::ctxt<'tcx>, // We instantiate UnificationTable with bounds because the // types that might instantiate a general type variable have an @@ -93,7 +93,7 @@ pub struct InferCtxt<'a> { // For region variables. region_vars: - RegionVarBindings<'a>, + RegionVarBindings<'a, 'tcx>, } /// Why did we require that the two types be related? @@ -291,7 +291,8 @@ pub fn fixup_err_to_string(f: fixup_err) -> String { } } -pub fn new_infer_ctxt<'a>(tcx: &'a ty::ctxt) -> InferCtxt<'a> { +pub fn new_infer_ctxt<'a, 'tcx>(tcx: &'a ty::ctxt<'tcx>) + -> InferCtxt<'a, 'tcx> { InferCtxt { tcx: tcx, type_variables: RefCell::new(type_variable::TypeVariableTable::new()), @@ -518,23 +519,23 @@ pub struct CombinedSnapshot { region_vars_snapshot: RegionSnapshot, } -impl<'a> InferCtxt<'a> { +impl<'a, 'tcx> InferCtxt<'a, 'tcx> { pub fn combine_fields<'a>(&'a self, a_is_expected: bool, trace: TypeTrace) - -> CombineFields<'a> { + -> CombineFields<'a, 'tcx> { CombineFields {infcx: self, a_is_expected: a_is_expected, trace: trace} } - pub fn equate<'a>(&'a self, a_is_expected: bool, trace: TypeTrace) -> Equate<'a> { + pub fn equate<'a>(&'a self, a_is_expected: bool, trace: TypeTrace) -> Equate<'a, 'tcx> { Equate(self.combine_fields(a_is_expected, trace)) } - pub fn sub<'a>(&'a self, a_is_expected: bool, trace: TypeTrace) -> Sub<'a> { + pub fn sub<'a>(&'a self, a_is_expected: bool, trace: TypeTrace) -> Sub<'a, 'tcx> { Sub(self.combine_fields(a_is_expected, trace)) } - pub fn lub<'a>(&'a self, a_is_expected: bool, trace: TypeTrace) -> Lub<'a> { + pub fn lub<'a>(&'a self, a_is_expected: bool, trace: TypeTrace) -> Lub<'a, 'tcx> { Lub(self.combine_fields(a_is_expected, trace)) } @@ -635,7 +636,7 @@ impl<'a> InferCtxt<'a> { } } -impl<'a> InferCtxt<'a> { +impl<'a, 'tcx> InferCtxt<'a, 'tcx> { pub fn next_ty_var_id(&self) -> TyVid { self.type_variables .borrow_mut() diff --git a/src/librustc/middle/typeck/infer/region_inference/mod.rs b/src/librustc/middle/typeck/infer/region_inference/mod.rs index f34894346f64a..7e61c254a656b 100644 --- a/src/librustc/middle/typeck/infer/region_inference/mod.rs +++ b/src/librustc/middle/typeck/infer/region_inference/mod.rs @@ -151,8 +151,8 @@ impl SameRegions { pub type CombineMap = HashMap; -pub struct RegionVarBindings<'a> { - tcx: &'a ty::ctxt, +pub struct RegionVarBindings<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx>, var_origins: RefCell>, // Constraints of the form `A <= B` introduced by the region @@ -217,8 +217,8 @@ pub struct RegionMark { length: uint } -impl<'a> RegionVarBindings<'a> { - pub fn new(tcx: &'a ty::ctxt) -> RegionVarBindings<'a> { +impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { + pub fn new(tcx: &'a ty::ctxt<'tcx>) -> RegionVarBindings<'a, 'tcx> { RegionVarBindings { tcx: tcx, var_origins: RefCell::new(Vec::new()), @@ -711,9 +711,7 @@ impl<'a> RegionVarBindings<'a> { *self.values.borrow_mut() = Some(v); errors } -} -impl<'a> RegionVarBindings<'a> { fn is_subregion_of(&self, sub: Region, sup: Region) -> bool { self.tcx.region_maps.is_subregion_of(sub, sup) } @@ -959,7 +957,7 @@ struct RegionAndOrigin { type RegionGraph = graph::Graph<(), Constraint>; -impl<'a> RegionVarBindings<'a> { +impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { fn infer_variable_values(&self, errors: &mut Vec) -> Vec diff --git a/src/librustc/middle/typeck/infer/resolve.rs b/src/librustc/middle/typeck/infer/resolve.rs index f9742c522dac4..dcdae7ed29c8d 100644 --- a/src/librustc/middle/typeck/infer/resolve.rs +++ b/src/librustc/middle/typeck/infer/resolve.rs @@ -74,18 +74,18 @@ pub static try_resolve_tvar_shallow: uint = 0; pub static resolve_and_force_all_but_regions: uint = (resolve_all | force_all) & not_regions; -pub struct ResolveState<'a> { - infcx: &'a InferCtxt<'a>, +pub struct ResolveState<'a, 'tcx: 'a> { + infcx: &'a InferCtxt<'a, 'tcx>, modes: uint, err: Option, v_seen: Vec , type_depth: uint, } -pub fn resolver<'a>(infcx: &'a InferCtxt, - modes: uint, - _: Option) - -> ResolveState<'a> { +pub fn resolver<'a, 'tcx>(infcx: &'a InferCtxt<'a, 'tcx>, + modes: uint, + _: Option) + -> ResolveState<'a, 'tcx> { ResolveState { infcx: infcx, modes: modes, @@ -95,8 +95,8 @@ pub fn resolver<'a>(infcx: &'a InferCtxt, } } -impl<'a> ty_fold::TypeFolder for ResolveState<'a> { - fn tcx<'a>(&'a self) -> &'a ty::ctxt { +impl<'a, 'tcx> ty_fold::TypeFolder<'tcx> for ResolveState<'a, 'tcx> { + fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.infcx.tcx } @@ -109,7 +109,7 @@ impl<'a> ty_fold::TypeFolder for ResolveState<'a> { } } -impl<'a> ResolveState<'a> { +impl<'a, 'tcx> ResolveState<'a, 'tcx> { pub fn should(&mut self, mode: uint) -> bool { (self.modes & mode) == mode } diff --git a/src/librustc/middle/typeck/infer/sub.rs b/src/librustc/middle/typeck/infer/sub.rs index be4abb1ad8261..7403d50a2109c 100644 --- a/src/librustc/middle/typeck/infer/sub.rs +++ b/src/librustc/middle/typeck/infer/sub.rs @@ -28,25 +28,25 @@ use syntax::ast::{Onceness, FnStyle, MutImmutable, MutMutable}; /// "Greatest lower bound" (common subtype) -pub struct Sub<'f> { - fields: CombineFields<'f> +pub struct Sub<'f, 'tcx: 'f> { + fields: CombineFields<'f, 'tcx> } #[allow(non_snake_case)] -pub fn Sub<'f>(cf: CombineFields<'f>) -> Sub<'f> { +pub fn Sub<'f, 'tcx>(cf: CombineFields<'f, 'tcx>) -> Sub<'f, 'tcx> { Sub { fields: cf } } -impl<'f> Combine for Sub<'f> { - fn infcx<'a>(&'a self) -> &'a InferCtxt<'a> { self.fields.infcx } +impl<'f, 'tcx> Combine<'tcx> for Sub<'f, 'tcx> { + fn infcx<'a>(&'a self) -> &'a InferCtxt<'a, 'tcx> { self.fields.infcx } fn tag(&self) -> String { "sub".to_string() } fn a_is_expected(&self) -> bool { self.fields.a_is_expected } fn trace(&self) -> TypeTrace { self.fields.trace.clone() } - fn equate<'a>(&'a self) -> Equate<'a> { Equate(self.fields.clone()) } - fn sub<'a>(&'a self) -> Sub<'a> { Sub(self.fields.clone()) } - fn lub<'a>(&'a self) -> Lub<'a> { Lub(self.fields.clone()) } - fn glb<'a>(&'a self) -> Glb<'a> { Glb(self.fields.clone()) } + fn equate<'a>(&'a self) -> Equate<'a, 'tcx> { Equate(self.fields.clone()) } + fn sub<'a>(&'a self) -> Sub<'a, 'tcx> { Sub(self.fields.clone()) } + fn lub<'a>(&'a self) -> Lub<'a, 'tcx> { Lub(self.fields.clone()) } + fn glb<'a>(&'a self) -> Glb<'a, 'tcx> { Glb(self.fields.clone()) } fn contratys(&self, a: ty::t, b: ty::t) -> cres { Sub(self.fields.switch_expected()).tys(b, a) diff --git a/src/librustc/middle/typeck/infer/test.rs b/src/librustc/middle/typeck/infer/test.rs index dd00fc6207981..198857fca5055 100644 --- a/src/librustc/middle/typeck/infer/test.rs +++ b/src/librustc/middle/typeck/infer/test.rs @@ -39,10 +39,11 @@ use syntax::diagnostic::{Level, RenderSpan, Bug, Fatal, Error, Warning, Note}; use syntax::ast; use util::ppaux::{ty_to_string, UserString}; -struct Env<'a> { +use arena::TypedArena; + +struct Env<'a, 'tcx: 'a> { krate: ast::Crate, - tcx: &'a ty::ctxt, - infcx: &'a infer::InferCtxt<'a>, + infcx: &'a infer::InferCtxt<'a, 'tcx>, } struct RH<'a> { @@ -129,7 +130,9 @@ fn test_env(_test_name: &str, let named_region_map = resolve_lifetime::krate(&sess, &krate); let region_map = region::resolve_crate(&sess, &krate); let stability_index = stability::Index::build(&krate); + let type_arena = TypedArena::new(); let tcx = ty::mk_ctxt(sess, + &type_arena, def_map, named_region_map, ast_map, @@ -139,19 +142,20 @@ fn test_env(_test_name: &str, lang_items, stability_index); let infcx = infer::new_infer_ctxt(&tcx); - let env = Env {krate: krate, - tcx: &tcx, - infcx: &infcx}; + let env = Env { + krate: krate, + infcx: &infcx + }; body(env); infcx.resolve_regions_and_report_errors(); assert_eq!(tcx.sess.err_count(), expected_err_count); } -impl<'a> Env<'a> { +impl<'a, 'tcx> Env<'a, 'tcx> { pub fn create_region_hierarchy(&self, rh: &RH) { for child_rh in rh.sub.iter() { self.create_region_hierarchy(child_rh); - self.tcx.region_maps.record_encl_scope(child_rh.id, rh.id); + self.infcx.tcx.region_maps.record_encl_scope(child_rh.id, rh.id); } } @@ -181,7 +185,7 @@ impl<'a> Env<'a> { -> Option { assert!(idx < names.len()); for item in m.items.iter() { - if item.ident.user_string(this.tcx) == names[idx] { + if item.ident.user_string(this.infcx.tcx) == names[idx] { return search(this, &**item, idx+1, names); } } @@ -220,7 +224,7 @@ impl<'a> Env<'a> { match infer::mk_subty(self.infcx, true, infer::Misc(DUMMY_SP), a, b) { Ok(_) => true, Err(ref e) => fail!("Encountered error: {}", - ty::type_err_to_str(self.tcx, e)) + ty::type_err_to_str(self.infcx.tcx, e)) } } @@ -253,7 +257,7 @@ impl<'a> Env<'a> { } pub fn ty_to_string(&self, a: ty::t) -> String { - ty_to_string(self.tcx, a) + ty_to_string(self.infcx.tcx, a) } pub fn t_fn(&self, @@ -262,7 +266,7 @@ impl<'a> Env<'a> { output_ty: ty::t) -> ty::t { - ty::mk_ctor_fn(self.tcx, binder_id, input_tys, output_ty) + ty::mk_ctor_fn(self.infcx.tcx, binder_id, input_tys, output_ty) } pub fn t_int(&self) -> ty::t { @@ -270,23 +274,23 @@ impl<'a> Env<'a> { } pub fn t_rptr_late_bound(&self, binder_id: ast::NodeId, id: uint) -> ty::t { - ty::mk_imm_rptr(self.tcx, ty::ReLateBound(binder_id, ty::BrAnon(id)), + ty::mk_imm_rptr(self.infcx.tcx, ty::ReLateBound(binder_id, ty::BrAnon(id)), self.t_int()) } pub fn t_rptr_scope(&self, id: ast::NodeId) -> ty::t { - ty::mk_imm_rptr(self.tcx, ty::ReScope(id), self.t_int()) + ty::mk_imm_rptr(self.infcx.tcx, ty::ReScope(id), self.t_int()) } pub fn t_rptr_free(&self, nid: ast::NodeId, id: uint) -> ty::t { - ty::mk_imm_rptr(self.tcx, + ty::mk_imm_rptr(self.infcx.tcx, ty::ReFree(ty::FreeRegion {scope_id: nid, bound_region: ty::BrAnon(id)}), self.t_int()) } pub fn t_rptr_static(&self) -> ty::t { - ty::mk_imm_rptr(self.tcx, ty::ReStatic, self.t_int()) + ty::mk_imm_rptr(self.infcx.tcx, ty::ReStatic, self.t_int()) } pub fn dummy_type_trace(&self) -> infer::TypeTrace { @@ -299,12 +303,12 @@ impl<'a> Env<'a> { } } - pub fn lub(&self) -> Lub<'a> { + pub fn lub(&self) -> Lub<'a, 'tcx> { let trace = self.dummy_type_trace(); Lub(self.infcx.combine_fields(true, trace)) } - pub fn glb(&self) -> Glb<'a> { + pub fn glb(&self) -> Glb<'a, 'tcx> { let trace = self.dummy_type_trace(); Glb(self.infcx.combine_fields(true, trace)) } @@ -317,7 +321,7 @@ impl<'a> Env<'a> { match self.lub().tys(t1, t2) { Ok(t) => t, Err(ref e) => fail!("unexpected error computing LUB: {:?}", - ty::type_err_to_str(self.tcx, e)) + ty::type_err_to_str(self.infcx.tcx, e)) } } @@ -329,7 +333,7 @@ impl<'a> Env<'a> { } Err(ref e) => { fail!("unexpected error in LUB: {}", - ty::type_err_to_str(self.tcx, e)) + ty::type_err_to_str(self.infcx.tcx, e)) } } } diff --git a/src/librustc/middle/typeck/infer/unify.rs b/src/librustc/middle/typeck/infer/unify.rs index adf0a25ce4002..22d78340e9637 100644 --- a/src/librustc/middle/typeck/infer/unify.rs +++ b/src/librustc/middle/typeck/infer/unify.rs @@ -288,8 +288,8 @@ pub trait InferCtxtMethodsForSimplyUnifiableTypes ures; } -impl<'tcx,V:SimplyUnifiable,K:UnifyKey>> - InferCtxtMethodsForSimplyUnifiableTypes for InferCtxt<'tcx> +impl<'a,'tcx,V:SimplyUnifiable,K:UnifyKey>> + InferCtxtMethodsForSimplyUnifiableTypes for InferCtxt<'a, 'tcx> { fn simple_vars(&self, a_is_expected: bool, diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index 4000807ec1b8e..7104cb9584444 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -281,10 +281,10 @@ pub type vtable_map = RefCell>; pub type impl_vtable_map = RefCell>; -pub struct CrateCtxt<'a> { +pub struct CrateCtxt<'a, 'tcx: 'a> { // A mapping from method call sites to traits that have that method. trait_map: resolve::TraitMap, - tcx: &'a ty::ctxt + tcx: &'a ty::ctxt<'tcx> } // Functions that write types into the node type table diff --git a/src/librustc/middle/typeck/variance.rs b/src/librustc/middle/typeck/variance.rs index e6227b9c12829..7e8c53159fb8d 100644 --- a/src/librustc/middle/typeck/variance.rs +++ b/src/librustc/middle/typeck/variance.rs @@ -254,8 +254,8 @@ impl<'a> fmt::Show for VarianceTerm<'a> { * The first pass over the crate simply builds up the set of inferreds. */ -struct TermsContext<'a> { - tcx: &'a ty::ctxt, +struct TermsContext<'a, 'tcx: 'a> { + tcx: &'a ty::ctxt<'tcx>, arena: &'a Arena, empty_variances: Rc, @@ -283,10 +283,10 @@ struct InferredInfo<'a> { term: VarianceTermPtr<'a>, } -fn determine_parameters_to_be_inferred<'a>(tcx: &'a ty::ctxt, - arena: &'a mut Arena, - krate: &ast::Crate) - -> TermsContext<'a> { +fn determine_parameters_to_be_inferred<'a, 'tcx>(tcx: &'a ty::ctxt<'tcx>, + arena: &'a mut Arena, + krate: &ast::Crate) + -> TermsContext<'a, 'tcx> { let mut terms_cx = TermsContext { tcx: tcx, arena: arena, @@ -306,7 +306,7 @@ fn determine_parameters_to_be_inferred<'a>(tcx: &'a ty::ctxt, terms_cx } -impl<'a> TermsContext<'a> { +impl<'a, 'tcx> TermsContext<'a, 'tcx> { fn add_inferred(&mut self, item_id: ast::NodeId, kind: ParamKind, @@ -337,7 +337,7 @@ impl<'a> TermsContext<'a> { } } -impl<'a> Visitor<()> for TermsContext<'a> { +impl<'a, 'tcx> Visitor<()> for TermsContext<'a, 'tcx> { fn visit_item(&mut self, item: &ast::Item, _: ()) { debug!("add_inferreds for item {}", item.repr(self.tcx)); @@ -402,8 +402,8 @@ impl<'a> Visitor<()> for TermsContext<'a> { * We walk the set of items and, for each member, generate new constraints. */ -struct ConstraintContext<'a> { - terms_cx: TermsContext<'a>, +struct ConstraintContext<'a, 'tcx: 'a> { + terms_cx: TermsContext<'a, 'tcx>, // These are the def-id of the std::kinds::marker::InvariantType, // std::kinds::marker::InvariantLifetime, and so on. The arrays @@ -431,9 +431,9 @@ struct Constraint<'a> { variance: &'a VarianceTerm<'a>, } -fn add_constraints_from_crate<'a>(terms_cx: TermsContext<'a>, - krate: &ast::Crate) - -> ConstraintContext<'a> { +fn add_constraints_from_crate<'a, 'tcx>(terms_cx: TermsContext<'a, 'tcx>, + krate: &ast::Crate) + -> ConstraintContext<'a, 'tcx> { let mut invariant_lang_items = [None, ..2]; let mut covariant_lang_items = [None, ..2]; let mut contravariant_lang_items = [None, ..2]; @@ -477,7 +477,7 @@ fn add_constraints_from_crate<'a>(terms_cx: TermsContext<'a>, constraint_cx } -impl<'a> Visitor<()> for ConstraintContext<'a> { +impl<'a, 'tcx> Visitor<()> for ConstraintContext<'a, 'tcx> { fn visit_item(&mut self, item: &ast::Item, _: ()) { let did = ast_util::local_def(item.id); let tcx = self.terms_cx.tcx; @@ -546,8 +546,8 @@ fn is_lifetime(map: &ast_map::Map, param_id: ast::NodeId) -> bool { } } -impl<'a> ConstraintContext<'a> { - fn tcx(&self) -> &'a ty::ctxt { +impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { + fn tcx(&self) -> &'a ty::ctxt<'tcx> { self.terms_cx.tcx } @@ -942,8 +942,8 @@ impl<'a> ConstraintContext<'a> { * inferred is then written into the `variance_map` in the tcx. */ -struct SolveContext<'a> { - terms_cx: TermsContext<'a>, +struct SolveContext<'a, 'tcx: 'a> { + terms_cx: TermsContext<'a, 'tcx>, constraints: Vec> , // Maps from an InferredIndex to the inferred value for that variable. @@ -961,7 +961,7 @@ fn solve_constraints(constraints_cx: ConstraintContext) { solutions_cx.write(); } -impl<'a> SolveContext<'a> { +impl<'a, 'tcx> SolveContext<'a, 'tcx> { fn solve(&mut self) { // Propagate constraints until a fixed point is reached. Note // that the maximum number of iterations is 2C where C is the diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index f7962455c03e3..e0afb80ad37f5 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -21,7 +21,7 @@ use rustc::middle::ty; use rustc::middle::subst; use rustc::middle::stability; -use core; +use core::DocContext; use doctree; use clean; @@ -39,12 +39,11 @@ use super::Clean; /// /// The returned value is `None` if the `id` could not be inlined, and `Some` /// of a vector of items if it was successfully expanded. -pub fn try_inline(id: ast::NodeId, into: Option) +pub fn try_inline(cx: &DocContext, id: ast::NodeId, into: Option) -> Option> { - let cx = ::ctxtkey.get().unwrap(); - let tcx = match cx.maybe_typed { - core::Typed(ref tycx) => tycx, - core::NotTyped(_) => return None, + let tcx = match cx.tcx_opt() { + Some(tcx) => tcx, + None => return None, }; let def = match tcx.def_map.borrow().find(&id) { Some(def) => *def, @@ -52,11 +51,11 @@ pub fn try_inline(id: ast::NodeId, into: Option) }; let did = def.def_id(); if ast_util::is_local(did) { return None } - try_inline_def(&**cx, tcx, def).map(|vec| { + try_inline_def(cx, tcx, def).map(|vec| { vec.move_iter().map(|mut item| { match into { Some(into) if item.name.is_some() => { - item.name = Some(into.clean()); + item.name = Some(into.clean(cx)); } _ => {} } @@ -65,15 +64,14 @@ pub fn try_inline(id: ast::NodeId, into: Option) }) } -fn try_inline_def(cx: &core::DocContext, - tcx: &ty::ctxt, +fn try_inline_def(cx: &DocContext, tcx: &ty::ctxt, def: def::Def) -> Option> { let mut ret = Vec::new(); let did = def.def_id(); let inner = match def { def::DefTrait(did) => { record_extern_fqn(cx, did, clean::TypeTrait); - clean::TraitItem(build_external_trait(tcx, did)) + clean::TraitItem(build_external_trait(cx, tcx, did)) } def::DefFn(did, style) => { // If this function is a tuple struct constructor, we just skip it @@ -82,17 +80,17 @@ fn try_inline_def(cx: &core::DocContext, return None } record_extern_fqn(cx, did, clean::TypeFunction); - clean::FunctionItem(build_external_function(tcx, did, style)) + clean::FunctionItem(build_external_function(cx, tcx, did, style)) } def::DefStruct(did) => { record_extern_fqn(cx, did, clean::TypeStruct); ret.extend(build_impls(cx, tcx, did).move_iter()); - clean::StructItem(build_struct(tcx, did)) + clean::StructItem(build_struct(cx, tcx, did)) } def::DefTy(did) => { record_extern_fqn(cx, did, clean::TypeEnum); ret.extend(build_impls(cx, tcx, did).move_iter()); - build_type(tcx, did) + build_type(cx, tcx, did) } // Assume that the enum type is reexported next to the variant, and // variants don't show up in documentation specially. @@ -103,7 +101,7 @@ fn try_inline_def(cx: &core::DocContext, } def::DefStatic(did, mtbl) => { record_extern_fqn(cx, did, clean::TypeStatic); - clean::StaticItem(build_static(tcx, did, mtbl)) + clean::StaticItem(build_static(cx, tcx, did, mtbl)) } _ => return None, }; @@ -112,20 +110,21 @@ fn try_inline_def(cx: &core::DocContext, ret.push(clean::Item { source: clean::Span::empty(), name: Some(fqn.last().unwrap().to_string()), - attrs: load_attrs(tcx, did), + attrs: load_attrs(cx, tcx, did), inner: inner, visibility: Some(ast::Public), - stability: stability::lookup(tcx, did).clean(), + stability: stability::lookup(tcx, did).clean(cx), def_id: did, }); Some(ret) } -pub fn load_attrs(tcx: &ty::ctxt, did: ast::DefId) -> Vec { +pub fn load_attrs(cx: &DocContext, tcx: &ty::ctxt, + did: ast::DefId) -> Vec { let mut attrs = Vec::new(); csearch::get_item_attrs(&tcx.sess.cstore, did, |v| { attrs.extend(v.move_iter().map(|a| { - a.clean() + a.clean(cx) })); }); attrs @@ -135,22 +134,21 @@ pub fn load_attrs(tcx: &ty::ctxt, did: ast::DefId) -> Vec { /// /// These names are used later on by HTML rendering to generate things like /// source links back to the original item. -pub fn record_extern_fqn(cx: &core::DocContext, - did: ast::DefId, - kind: clean::TypeKind) { - match cx.maybe_typed { - core::Typed(ref tcx) => { +pub fn record_extern_fqn(cx: &DocContext, did: ast::DefId, kind: clean::TypeKind) { + match cx.tcx_opt() { + Some(tcx) => { let fqn = csearch::get_item_path(tcx, did); let fqn = fqn.move_iter().map(|i| i.to_string()).collect(); cx.external_paths.borrow_mut().as_mut().unwrap().insert(did, (fqn, kind)); } - core::NotTyped(..) => {} + None => {} } } -pub fn build_external_trait(tcx: &ty::ctxt, did: ast::DefId) -> clean::Trait { +pub fn build_external_trait(cx: &DocContext, tcx: &ty::ctxt, + did: ast::DefId) -> clean::Trait { let def = ty::lookup_trait_def(tcx, did); - let trait_items = ty::trait_items(tcx, did).clean(); + let trait_items = ty::trait_items(tcx, did).clean(cx); let provided = ty::provided_trait_methods(tcx, did); let mut items = trait_items.move_iter().map(|trait_item| { if provided.iter().any(|a| a.def_id == trait_item.def_id) { @@ -160,29 +158,29 @@ pub fn build_external_trait(tcx: &ty::ctxt, did: ast::DefId) -> clean::Trait { } }); let trait_def = ty::lookup_trait_def(tcx, did); - let bounds = trait_def.bounds.clean(); + let bounds = trait_def.bounds.clean(cx); clean::Trait { - generics: (&def.generics, subst::TypeSpace).clean(), + generics: (&def.generics, subst::TypeSpace).clean(cx), items: items.collect(), bounds: bounds, } } -fn build_external_function(tcx: &ty::ctxt, +fn build_external_function(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId, style: ast::FnStyle) -> clean::Function { let t = ty::lookup_item_type(tcx, did); clean::Function { decl: match ty::get(t.ty).sty { - ty::ty_bare_fn(ref f) => (did, &f.sig).clean(), + ty::ty_bare_fn(ref f) => (did, &f.sig).clean(cx), _ => fail!("bad function"), }, - generics: (&t.generics, subst::FnSpace).clean(), + generics: (&t.generics, subst::FnSpace).clean(cx), fn_style: style, } } -fn build_struct(tcx: &ty::ctxt, did: ast::DefId) -> clean::Struct { +fn build_struct(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) -> clean::Struct { use syntax::parse::token::special_idents::unnamed_field; let t = ty::lookup_item_type(tcx, did); @@ -195,33 +193,32 @@ fn build_struct(tcx: &ty::ctxt, did: ast::DefId) -> clean::Struct { [ref f, ..] if f.name == unnamed_field.name => doctree::Tuple, _ => doctree::Plain, }, - generics: (&t.generics, subst::TypeSpace).clean(), - fields: fields.clean(), + generics: (&t.generics, subst::TypeSpace).clean(cx), + fields: fields.clean(cx), fields_stripped: false, } } -fn build_type(tcx: &ty::ctxt, did: ast::DefId) -> clean::ItemEnum { +fn build_type(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) -> clean::ItemEnum { let t = ty::lookup_item_type(tcx, did); match ty::get(t.ty).sty { ty::ty_enum(edid, _) if !csearch::is_typedef(&tcx.sess.cstore, did) => { return clean::EnumItem(clean::Enum { - generics: (&t.generics, subst::TypeSpace).clean(), + generics: (&t.generics, subst::TypeSpace).clean(cx), variants_stripped: false, - variants: ty::enum_variants(tcx, edid).clean(), + variants: ty::enum_variants(tcx, edid).clean(cx), }) } _ => {} } clean::TypedefItem(clean::Typedef { - type_: t.ty.clean(), - generics: (&t.generics, subst::TypeSpace).clean(), + type_: t.ty.clean(cx), + generics: (&t.generics, subst::TypeSpace).clean(cx), }) } -fn build_impls(cx: &core::DocContext, - tcx: &ty::ctxt, +fn build_impls(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) -> Vec { ty::populate_implementations_for_type_if_necessary(tcx, did); let mut impls = Vec::new(); @@ -248,8 +245,7 @@ fn build_impls(cx: &core::DocContext, populate_impls(cx, tcx, def, &mut impls) }); - fn populate_impls(cx: &core::DocContext, - tcx: &ty::ctxt, + fn populate_impls(cx: &DocContext, tcx: &ty::ctxt, def: decoder::DefLike, impls: &mut Vec>) { match def { @@ -269,8 +265,7 @@ fn build_impls(cx: &core::DocContext, impls.move_iter().filter_map(|a| a).collect() } -fn build_impl(cx: &core::DocContext, - tcx: &ty::ctxt, +fn build_impl(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) -> Option { if !cx.inlined.borrow_mut().as_mut().unwrap().insert(did) { return None @@ -280,7 +275,7 @@ fn build_impl(cx: &core::DocContext, // If this is an impl for a #[doc(hidden)] trait, be sure to not inline it. match associated_trait { Some(ref t) => { - let trait_attrs = load_attrs(tcx, t.def_id); + let trait_attrs = load_attrs(cx, tcx, t.def_id); if trait_attrs.iter().any(|a| is_doc_hidden(a)) { return None } @@ -288,7 +283,7 @@ fn build_impl(cx: &core::DocContext, None => {} } - let attrs = load_attrs(tcx, did); + let attrs = load_attrs(cx, tcx, did); let ty = ty::lookup_item_type(tcx, did); let trait_items = csearch::get_impl_items(&tcx.sess.cstore, did) .iter() @@ -300,7 +295,7 @@ fn build_impl(cx: &core::DocContext, if method.vis != ast::Public && associated_trait.is_none() { return None } - let mut item = method.clean(); + let mut item = method.clean(cx); item.inner = match item.inner.clone() { clean::TyMethodItem(clean::TyMethod { fn_style, decl, self_, generics @@ -321,21 +316,21 @@ fn build_impl(cx: &core::DocContext, return Some(clean::Item { inner: clean::ImplItem(clean::Impl { derived: clean::detect_derived(attrs.as_slice()), - trait_: associated_trait.clean().map(|bound| { + trait_: associated_trait.clean(cx).map(|bound| { match bound { clean::TraitBound(ty) => ty, clean::RegionBound => unreachable!(), } }), - for_: ty.ty.clean(), - generics: (&ty.generics, subst::TypeSpace).clean(), + for_: ty.ty.clean(cx), + generics: (&ty.generics, subst::TypeSpace).clean(cx), items: trait_items, }), source: clean::Span::empty(), name: None, attrs: attrs, visibility: Some(ast::Inherited), - stability: stability::lookup(tcx, did).clean(), + stability: stability::lookup(tcx, did).clean(cx), def_id: did, }); @@ -354,7 +349,7 @@ fn build_impl(cx: &core::DocContext, } } -fn build_module(cx: &core::DocContext, tcx: &ty::ctxt, +fn build_module(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) -> clean::Module { let mut items = Vec::new(); fill_in(cx, tcx, did, &mut items); @@ -365,7 +360,7 @@ fn build_module(cx: &core::DocContext, tcx: &ty::ctxt, // FIXME: this doesn't handle reexports inside the module itself. // Should they be handled? - fn fill_in(cx: &core::DocContext, tcx: &ty::ctxt, did: ast::DefId, + fn fill_in(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId, items: &mut Vec) { csearch::each_child_of_item(&tcx.sess.cstore, did, |def, _, vis| { match def { @@ -387,11 +382,11 @@ fn build_module(cx: &core::DocContext, tcx: &ty::ctxt, } } -fn build_static(tcx: &ty::ctxt, +fn build_static(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId, mutable: bool) -> clean::Static { clean::Static { - type_: ty::lookup_item_type(tcx, did).ty.clean(), + type_: ty::lookup_item_type(tcx, did).ty.clean(cx), mutability: if mutable {clean::Mutable} else {clean::Immutable}, expr: "\n\n\n".to_string(), // trigger the "[definition]" links } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index a630d6bb5f67a..c1a91f26dbf80 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -36,7 +36,7 @@ use std::rc::Rc; use std::u32; use std::gc::{Gc, GC}; -use core; +use core::DocContext; use doctree; use visit_ast; @@ -46,57 +46,51 @@ pub static SCHEMA_VERSION: &'static str = "0.8.3"; mod inline; -// load the current DocContext from TLD -fn get_cx() -> Gc { - *super::ctxtkey.get().unwrap() -} - -// extract the stability index for a node from TLD, if possible -fn get_stability(def_id: ast::DefId) -> Option { - get_cx().tcx_opt().and_then(|tcx| stability::lookup(tcx, def_id)) - .map(|stab| stab.clean()) +// extract the stability index for a node from tcx, if possible +fn get_stability(cx: &DocContext, def_id: ast::DefId) -> Option { + cx.tcx_opt().and_then(|tcx| stability::lookup(tcx, def_id)).clean(cx) } pub trait Clean { - fn clean(&self) -> T; + fn clean(&self, cx: &DocContext) -> T; } impl, U> Clean> for Vec { - fn clean(&self) -> Vec { - self.iter().map(|x| x.clean()).collect() + fn clean(&self, cx: &DocContext) -> Vec { + self.iter().map(|x| x.clean(cx)).collect() } } impl, U> Clean> for VecPerParamSpace { - fn clean(&self) -> VecPerParamSpace { - self.map(|x| x.clean()) + fn clean(&self, cx: &DocContext) -> VecPerParamSpace { + self.map(|x| x.clean(cx)) } } impl, U> Clean for Gc { - fn clean(&self) -> U { - (**self).clean() + fn clean(&self, cx: &DocContext) -> U { + (**self).clean(cx) } } impl, U> Clean for Rc { - fn clean(&self) -> U { - (**self).clean() + fn clean(&self, cx: &DocContext) -> U { + (**self).clean(cx) } } impl, U> Clean> for Option { - fn clean(&self) -> Option { + fn clean(&self, cx: &DocContext) -> Option { match self { &None => None, - &Some(ref v) => Some(v.clean()) + &Some(ref v) => Some(v.clean(cx)) } } } impl, U> Clean> for syntax::owned_slice::OwnedSlice { - fn clean(&self) -> Vec { - self.iter().map(|x| x.clean()).collect() + fn clean(&self, cx: &DocContext) -> Vec { + self.iter().map(|x| x.clean(cx)).collect() } } @@ -108,13 +102,11 @@ pub struct Crate { pub primitives: Vec, } -impl<'a> Clean for visit_ast::RustdocVisitor<'a> { - fn clean(&self) -> Crate { - let cx = get_cx(); - +impl<'a, 'tcx> Clean for visit_ast::RustdocVisitor<'a, 'tcx> { + fn clean(&self, cx: &DocContext) -> Crate { let mut externs = Vec::new(); cx.sess().cstore.iter_crate_data(|n, meta| { - externs.push((n, meta.clean())); + externs.push((n, meta.clean(cx))); }); externs.sort_by(|&(a, _), &(b, _)| a.cmp(&b)); @@ -124,7 +116,7 @@ impl<'a> Clean for visit_ast::RustdocVisitor<'a> { // Clean the crate, translating the entire libsyntax AST to one that is // understood by rustdoc. - let mut module = self.module.clean(); + let mut module = self.module.clean(cx); // Collect all inner modules which are tagged as implementations of // primitives. @@ -199,9 +191,9 @@ pub struct ExternalCrate { } impl Clean for cstore::crate_metadata { - fn clean(&self) -> ExternalCrate { + fn clean(&self, cx: &DocContext) -> ExternalCrate { let mut primitives = Vec::new(); - get_cx().tcx_opt().map(|tcx| { + cx.tcx_opt().map(|tcx| { csearch::each_top_level_item_of_crate(&tcx.sess.cstore, self.cnum, |def, _, _| { @@ -209,13 +201,13 @@ impl Clean for cstore::crate_metadata { decoder::DlDef(def::DefMod(did)) => did, _ => return }; - let attrs = inline::load_attrs(tcx, did); + let attrs = inline::load_attrs(cx, tcx, did); Primitive::find(attrs.as_slice()).map(|prim| primitives.push(prim)); }) }); ExternalCrate { name: self.name.to_string(), - attrs: decoder::get_crate_attributes(self.data()).clean(), + attrs: decoder::get_crate_attributes(self.data()).clean(cx), primitives: primitives, } } @@ -334,38 +326,37 @@ pub struct Module { } impl Clean for doctree::Module { - fn clean(&self) -> Item { + fn clean(&self, cx: &DocContext) -> Item { let name = if self.name.is_some() { - self.name.unwrap().clean() + self.name.unwrap().clean(cx) } else { "".to_string() }; let mut foreigns = Vec::new(); - for subforeigns in self.foreigns.clean().move_iter() { + for subforeigns in self.foreigns.clean(cx).move_iter() { for foreign in subforeigns.move_iter() { foreigns.push(foreign) } } let items: Vec > = vec!( - self.structs.clean(), - self.enums.clean(), - self.fns.clean(), + self.structs.clean(cx), + self.enums.clean(cx), + self.fns.clean(cx), foreigns, - self.mods.clean(), - self.typedefs.clean(), - self.statics.clean(), - self.traits.clean(), - self.impls.clean(), - self.view_items.clean().move_iter() + self.mods.clean(cx), + self.typedefs.clean(cx), + self.statics.clean(cx), + self.traits.clean(cx), + self.impls.clean(cx), + self.view_items.clean(cx).move_iter() .flat_map(|s| s.move_iter()).collect(), - self.macros.clean(), + self.macros.clean(cx), ); // determine if we should display the inner contents or // the outer `mod` item for the source code. let whence = { - let ctxt = super::ctxtkey.get().unwrap(); - let cm = ctxt.sess().codemap(); + let cm = cx.sess().codemap(); let outer = cm.lookup_char_pos(self.where_outer.lo); let inner = cm.lookup_char_pos(self.where_inner.lo); if outer.file.start_pos == inner.file.start_pos { @@ -379,10 +370,10 @@ impl Clean for doctree::Module { Item { name: Some(name), - attrs: self.attrs.clean(), - source: whence.clean(), - visibility: self.vis.clean(), - stability: self.stab.clean(), + attrs: self.attrs.clean(cx), + source: whence.clean(cx), + visibility: self.vis.clean(cx), + stability: self.stab.clean(cx), def_id: ast_util::local_def(self.id), inner: ModuleItem(Module { is_crate: self.is_crate, @@ -402,11 +393,11 @@ pub enum Attribute { } impl Clean for ast::MetaItem { - fn clean(&self) -> Attribute { + fn clean(&self, cx: &DocContext) -> Attribute { match self.node { ast::MetaWord(ref s) => Word(s.get().to_string()), ast::MetaList(ref s, ref l) => { - List(s.get().to_string(), l.clean()) + List(s.get().to_string(), l.clean(cx)) } ast::MetaNameValue(ref s, ref v) => { NameValue(s.get().to_string(), lit_to_string(v)) @@ -416,8 +407,8 @@ impl Clean for ast::MetaItem { } impl Clean for ast::Attribute { - fn clean(&self) -> Attribute { - self.desugar_doc().node.value.clean() + fn clean(&self, cx: &DocContext) -> Attribute { + self.desugar_doc().node.value.clean(cx) } } @@ -456,25 +447,25 @@ pub struct TyParam { } impl Clean for ast::TyParam { - fn clean(&self) -> TyParam { + fn clean(&self, cx: &DocContext) -> TyParam { TyParam { - name: self.ident.clean(), + name: self.ident.clean(cx), did: ast::DefId { krate: ast::LOCAL_CRATE, node: self.id }, - bounds: self.bounds.clean(), - default: self.default.clean() + bounds: self.bounds.clean(cx), + default: self.default.clean(cx) } } } impl Clean for ty::TypeParameterDef { - fn clean(&self) -> TyParam { - get_cx().external_typarams.borrow_mut().as_mut().unwrap() - .insert(self.def_id, self.ident.clean()); + fn clean(&self, cx: &DocContext) -> TyParam { + cx.external_typarams.borrow_mut().as_mut().unwrap() + .insert(self.def_id, self.ident.clean(cx)); TyParam { - name: self.ident.clean(), + name: self.ident.clean(cx), did: self.def_id, - bounds: self.bounds.clean(), - default: self.default.clean() + bounds: self.bounds.clean(cx), + default: self.default.clean(cx) } } } @@ -486,35 +477,35 @@ pub enum TyParamBound { } impl Clean for ast::TyParamBound { - fn clean(&self) -> TyParamBound { + fn clean(&self, cx: &DocContext) -> TyParamBound { match *self { ast::RegionTyParamBound(_) => RegionBound, ast::UnboxedFnTyParamBound(_) => { // FIXME(pcwalton): Wrong. RegionBound } - ast::TraitTyParamBound(ref t) => TraitBound(t.clean()), + ast::TraitTyParamBound(ref t) => TraitBound(t.clean(cx)), } } } impl Clean> for ty::ExistentialBounds { - fn clean(&self) -> Vec { + fn clean(&self, cx: &DocContext) -> Vec { let mut vec = vec!(RegionBound); for bb in self.builtin_bounds.iter() { - vec.push(bb.clean()); + vec.push(bb.clean(cx)); } vec } } -fn external_path(name: &str, substs: &subst::Substs) -> Path { +fn external_path(cx: &DocContext, name: &str, substs: &subst::Substs) -> Path { let lifetimes = substs.regions().get_slice(subst::TypeSpace) .iter() - .filter_map(|v| v.clean()) + .filter_map(|v| v.clean(cx)) .collect(); let types = Vec::from_slice(substs.types.get_slice(subst::TypeSpace)); - let types = types.clean(); + let types = types.clean(cx); Path { global: false, segments: vec![PathSegment { @@ -526,26 +517,25 @@ fn external_path(name: &str, substs: &subst::Substs) -> Path { } impl Clean for ty::BuiltinBound { - fn clean(&self) -> TyParamBound { - let cx = get_cx(); - let tcx = match cx.maybe_typed { - core::Typed(ref tcx) => tcx, - core::NotTyped(_) => return RegionBound, + fn clean(&self, cx: &DocContext) -> TyParamBound { + let tcx = match cx.tcx_opt() { + Some(tcx) => tcx, + None => return RegionBound, }; let empty = subst::Substs::empty(); let (did, path) = match *self { ty::BoundSend => (tcx.lang_items.send_trait().unwrap(), - external_path("Send", &empty)), + external_path(cx, "Send", &empty)), ty::BoundSized => (tcx.lang_items.sized_trait().unwrap(), - external_path("Sized", &empty)), + external_path(cx, "Sized", &empty)), ty::BoundCopy => (tcx.lang_items.copy_trait().unwrap(), - external_path("Copy", &empty)), + external_path(cx, "Copy", &empty)), ty::BoundSync => (tcx.lang_items.sync_trait().unwrap(), - external_path("Sync", &empty)), + external_path(cx, "Sync", &empty)), }; let fqn = csearch::get_item_path(tcx, did); let fqn = fqn.move_iter().map(|i| i.to_string()).collect(); @@ -560,16 +550,15 @@ impl Clean for ty::BuiltinBound { } impl Clean for ty::TraitRef { - fn clean(&self) -> TyParamBound { - let cx = get_cx(); - let tcx = match cx.maybe_typed { - core::Typed(ref tcx) => tcx, - core::NotTyped(_) => return RegionBound, + fn clean(&self, cx: &DocContext) -> TyParamBound { + let tcx = match cx.tcx_opt() { + Some(tcx) => tcx, + None => return RegionBound, }; let fqn = csearch::get_item_path(tcx, self.def_id); let fqn = fqn.move_iter().map(|i| i.to_string()) .collect::>(); - let path = external_path(fqn.last().unwrap().as_slice(), + let path = external_path(cx, fqn.last().unwrap().as_slice(), &self.substs); cx.external_paths.borrow_mut().as_mut().unwrap().insert(self.def_id, (fqn, TypeTrait)); @@ -582,25 +571,25 @@ impl Clean for ty::TraitRef { } impl Clean> for ty::ParamBounds { - fn clean(&self) -> Vec { + fn clean(&self, cx: &DocContext) -> Vec { let mut v = Vec::new(); for b in self.builtin_bounds.iter() { if b != ty::BoundSized { - v.push(b.clean()); + v.push(b.clean(cx)); } } for t in self.trait_bounds.iter() { - v.push(t.clean()); + v.push(t.clean(cx)); } return v; } } impl Clean>> for subst::Substs { - fn clean(&self) -> Option> { + fn clean(&self, cx: &DocContext) -> Option> { let mut v = Vec::new(); v.extend(self.regions().iter().map(|_| RegionBound)); - v.extend(self.types.iter().map(|t| TraitBound(t.clean()))); + v.extend(self.types.iter().map(|t| TraitBound(t.clean(cx)))); if v.len() > 0 {Some(v)} else {None} } } @@ -617,30 +606,30 @@ impl Lifetime { } impl Clean for ast::Lifetime { - fn clean(&self) -> Lifetime { + fn clean(&self, _: &DocContext) -> Lifetime { Lifetime(token::get_name(self.name).get().to_string()) } } impl Clean for ast::LifetimeDef { - fn clean(&self) -> Lifetime { + fn clean(&self, _: &DocContext) -> Lifetime { Lifetime(token::get_name(self.lifetime.name).get().to_string()) } } impl Clean for ty::RegionParameterDef { - fn clean(&self) -> Lifetime { + fn clean(&self, _: &DocContext) -> Lifetime { Lifetime(token::get_name(self.name).get().to_string()) } } impl Clean> for ty::Region { - fn clean(&self) -> Option { + fn clean(&self, cx: &DocContext) -> Option { match *self { ty::ReStatic => Some(Lifetime("'static".to_string())), ty::ReLateBound(_, ty::BrNamed(_, name)) => Some(Lifetime(token::get_name(name).get().to_string())), - ty::ReEarlyBound(_, _, _, name) => Some(Lifetime(name.clean())), + ty::ReEarlyBound(_, _, _, name) => Some(Lifetime(name.clean(cx))), ty::ReLateBound(..) | ty::ReFree(..) | @@ -659,20 +648,20 @@ pub struct Generics { } impl Clean for ast::Generics { - fn clean(&self) -> Generics { + fn clean(&self, cx: &DocContext) -> Generics { Generics { - lifetimes: self.lifetimes.clean(), - type_params: self.ty_params.clean(), + lifetimes: self.lifetimes.clean(cx), + type_params: self.ty_params.clean(cx), } } } impl<'a> Clean for (&'a ty::Generics, subst::ParamSpace) { - fn clean(&self) -> Generics { + fn clean(&self, cx: &DocContext) -> Generics { let (me, space) = *self; Generics { - type_params: Vec::from_slice(me.types.get_slice(space)).clean(), - lifetimes: Vec::from_slice(me.regions.get_slice(space)).clean(), + type_params: Vec::from_slice(me.types.get_slice(space)).clean(cx), + lifetimes: Vec::from_slice(me.regions.get_slice(space)).clean(cx), } } } @@ -686,7 +675,7 @@ pub struct Method { } impl Clean for ast::Method { - fn clean(&self) -> Item { + fn clean(&self, cx: &DocContext) -> Item { let all_inputs = &self.pe_fn_decl().inputs; let inputs = match self.pe_explicit_self().node { ast::SelfStatic => all_inputs.as_slice(), @@ -694,22 +683,22 @@ impl Clean for ast::Method { }; let decl = FnDecl { inputs: Arguments { - values: inputs.iter().map(|x| x.clean()).collect(), + values: inputs.iter().map(|x| x.clean(cx)).collect(), }, - output: (self.pe_fn_decl().output.clean()), - cf: self.pe_fn_decl().cf.clean(), + output: (self.pe_fn_decl().output.clean(cx)), + cf: self.pe_fn_decl().cf.clean(cx), attrs: Vec::new() }; Item { - name: Some(self.pe_ident().clean()), - attrs: self.attrs.clean(), - source: self.span.clean(), + name: Some(self.pe_ident().clean(cx)), + attrs: self.attrs.clean(cx), + source: self.span.clean(cx), def_id: ast_util::local_def(self.id), - visibility: self.pe_vis().clean(), - stability: get_stability(ast_util::local_def(self.id)), + visibility: self.pe_vis().clean(cx), + stability: get_stability(cx, ast_util::local_def(self.id)), inner: MethodItem(Method { - generics: self.pe_generics().clean(), - self_: self.pe_explicit_self().node.clean(), + generics: self.pe_generics().clean(cx), + self_: self.pe_explicit_self().node.clean(cx), fn_style: self.pe_fn_style().clone(), decl: decl, }), @@ -726,31 +715,31 @@ pub struct TyMethod { } impl Clean for ast::TypeMethod { - fn clean(&self) -> Item { + fn clean(&self, cx: &DocContext) -> Item { let inputs = match self.explicit_self.node { ast::SelfStatic => self.decl.inputs.as_slice(), _ => self.decl.inputs.slice_from(1) }; let decl = FnDecl { inputs: Arguments { - values: inputs.iter().map(|x| x.clean()).collect(), + values: inputs.iter().map(|x| x.clean(cx)).collect(), }, - output: (self.decl.output.clean()), - cf: self.decl.cf.clean(), + output: (self.decl.output.clean(cx)), + cf: self.decl.cf.clean(cx), attrs: Vec::new() }; Item { - name: Some(self.ident.clean()), - attrs: self.attrs.clean(), - source: self.span.clean(), + name: Some(self.ident.clean(cx)), + attrs: self.attrs.clean(cx), + source: self.span.clean(cx), def_id: ast_util::local_def(self.id), visibility: None, - stability: get_stability(ast_util::local_def(self.id)), + stability: get_stability(cx, ast_util::local_def(self.id)), inner: TyMethodItem(TyMethod { fn_style: self.fn_style.clone(), decl: decl, - self_: self.explicit_self.node.clean(), - generics: self.generics.clean(), + self_: self.explicit_self.node.clean(cx), + generics: self.generics.clean(cx), }), } } @@ -765,14 +754,14 @@ pub enum SelfTy { } impl Clean for ast::ExplicitSelf_ { - fn clean(&self) -> SelfTy { + fn clean(&self, cx: &DocContext) -> SelfTy { match *self { ast::SelfStatic => SelfStatic, ast::SelfValue(_) => SelfValue, ast::SelfRegion(lt, mt, _) => { - SelfBorrowed(lt.clean(), mt.clean()) + SelfBorrowed(lt.clean(cx), mt.clean(cx)) } - ast::SelfExplicit(typ, _) => SelfExplicit(typ.clean()), + ast::SelfExplicit(typ, _) => SelfExplicit(typ.clean(cx)), } } } @@ -785,17 +774,17 @@ pub struct Function { } impl Clean for doctree::Function { - fn clean(&self) -> Item { + fn clean(&self, cx: &DocContext) -> Item { Item { - name: Some(self.name.clean()), - attrs: self.attrs.clean(), - source: self.whence.clean(), - visibility: self.vis.clean(), - stability: self.stab.clean(), + name: Some(self.name.clean(cx)), + attrs: self.attrs.clean(cx), + source: self.whence.clean(cx), + visibility: self.vis.clean(cx), + stability: self.stab.clean(cx), def_id: ast_util::local_def(self.id), inner: FunctionItem(Function { - decl: self.decl.clean(), - generics: self.generics.clean(), + decl: self.decl.clean(cx), + generics: self.generics.clean(cx), fn_style: self.fn_style, }), } @@ -812,13 +801,13 @@ pub struct ClosureDecl { } impl Clean for ast::ClosureTy { - fn clean(&self) -> ClosureDecl { + fn clean(&self, cx: &DocContext) -> ClosureDecl { ClosureDecl { - lifetimes: self.lifetimes.clean(), - decl: self.decl.clean(), + lifetimes: self.lifetimes.clean(cx), + decl: self.decl.clean(cx), onceness: self.onceness, fn_style: self.fn_style, - bounds: self.bounds.clean() + bounds: self.bounds.clean(cx) } } } @@ -837,21 +826,20 @@ pub struct Arguments { } impl Clean for ast::FnDecl { - fn clean(&self) -> FnDecl { + fn clean(&self, cx: &DocContext) -> FnDecl { FnDecl { inputs: Arguments { - values: self.inputs.iter().map(|x| x.clean()).collect(), + values: self.inputs.clean(cx), }, - output: (self.output.clean()), - cf: self.cf.clean(), + output: self.output.clean(cx), + cf: self.cf.clean(cx), attrs: Vec::new() } } } impl<'a> Clean for (ast::DefId, &'a ty::FnSig) { - fn clean(&self) -> FnDecl { - let cx = get_cx(); + fn clean(&self, cx: &DocContext) -> FnDecl { let (did, sig) = *self; let mut names = if did.node != 0 { csearch::get_method_arg_names(&cx.tcx().sess.cstore, did).move_iter() @@ -862,13 +850,13 @@ impl<'a> Clean for (ast::DefId, &'a ty::FnSig) { let _ = names.next(); } FnDecl { - output: sig.output.clean(), + output: sig.output.clean(cx), cf: Return, attrs: Vec::new(), inputs: Arguments { values: sig.inputs.iter().map(|t| { Argument { - type_: t.clean(), + type_: t.clean(cx), id: 0, name: names.next().unwrap_or("".to_string()), } @@ -886,10 +874,10 @@ pub struct Argument { } impl Clean for ast::Arg { - fn clean(&self) -> Argument { + fn clean(&self, cx: &DocContext) -> Argument { Argument { name: name_from_pat(&*self.pat), - type_: (self.ty.clean()), + type_: (self.ty.clean(cx)), id: self.id } } @@ -902,7 +890,7 @@ pub enum RetStyle { } impl Clean for ast::RetStyle { - fn clean(&self) -> RetStyle { + fn clean(&self, _: &DocContext) -> RetStyle { match *self { ast::Return => Return, ast::NoReturn => NoReturn @@ -918,26 +906,26 @@ pub struct Trait { } impl Clean for doctree::Trait { - fn clean(&self) -> Item { + fn clean(&self, cx: &DocContext) -> Item { Item { - name: Some(self.name.clean()), - attrs: self.attrs.clean(), - source: self.whence.clean(), + name: Some(self.name.clean(cx)), + attrs: self.attrs.clean(cx), + source: self.whence.clean(cx), def_id: ast_util::local_def(self.id), - visibility: self.vis.clean(), - stability: self.stab.clean(), + visibility: self.vis.clean(cx), + stability: self.stab.clean(cx), inner: TraitItem(Trait { - items: self.items.clean(), - generics: self.generics.clean(), - bounds: self.bounds.clean(), + items: self.items.clean(cx), + generics: self.generics.clean(cx), + bounds: self.bounds.clean(cx), }), } } } impl Clean for ast::TraitRef { - fn clean(&self) -> Type { - resolve_type(self.path.clean(), None, self.ref_id) + fn clean(&self, cx: &DocContext) -> Type { + resolve_type(cx, self.path.clean(cx), None, self.ref_id) } } @@ -969,10 +957,10 @@ impl TraitItem { } impl Clean for ast::TraitItem { - fn clean(&self) -> TraitItem { + fn clean(&self, cx: &DocContext) -> TraitItem { match self { - &ast::RequiredMethod(ref t) => RequiredMethod(t.clean()), - &ast::ProvidedMethod(ref t) => ProvidedMethod(t.clean()), + &ast::RequiredMethod(ref t) => RequiredMethod(t.clean(cx)), + &ast::ProvidedMethod(ref t) => ProvidedMethod(t.clean(cx)), } } } @@ -983,18 +971,17 @@ pub enum ImplItem { } impl Clean for ast::ImplItem { - fn clean(&self) -> ImplItem { + fn clean(&self, cx: &DocContext) -> ImplItem { match self { - &ast::MethodImplItem(ref t) => MethodImplItem(t.clean()), + &ast::MethodImplItem(ref t) => MethodImplItem(t.clean(cx)), } } } impl Clean for ty::Method { - fn clean(&self) -> Item { - let cx = get_cx(); + fn clean(&self, cx: &DocContext) -> Item { let (self_, sig) = match self.explicit_self { - ty::StaticExplicitSelfCategory => (ast::SelfStatic.clean(), + ty::StaticExplicitSelfCategory => (ast::SelfStatic.clean(cx), self.fty.sig.clone()), s => { let sig = ty::FnSig { @@ -1006,13 +993,13 @@ impl Clean for ty::Method { ty::ByReferenceExplicitSelfCategory(..) => { match ty::get(self.fty.sig.inputs[0]).sty { ty::ty_rptr(r, mt) => { - SelfBorrowed(r.clean(), mt.mutbl.clean()) + SelfBorrowed(r.clean(cx), mt.mutbl.clean(cx)) } _ => unreachable!(), } } ty::ByBoxExplicitSelfCategory => { - SelfExplicit(self.fty.sig.inputs[0].clean()) + SelfExplicit(self.fty.sig.inputs[0].clean(cx)) } ty::StaticExplicitSelfCategory => unreachable!(), }; @@ -1021,26 +1008,26 @@ impl Clean for ty::Method { }; Item { - name: Some(self.ident.clean()), + name: Some(self.ident.clean(cx)), visibility: Some(ast::Inherited), - stability: get_stability(self.def_id), + stability: get_stability(cx, self.def_id), def_id: self.def_id, - attrs: inline::load_attrs(cx.tcx(), self.def_id), + attrs: inline::load_attrs(cx, cx.tcx(), self.def_id), source: Span::empty(), inner: TyMethodItem(TyMethod { fn_style: self.fty.fn_style, - generics: (&self.generics, subst::FnSpace).clean(), + generics: (&self.generics, subst::FnSpace).clean(cx), self_: self_, - decl: (self.def_id, &sig).clean(), + decl: (self.def_id, &sig).clean(cx), }) } } } impl Clean for ty::ImplOrTraitItem { - fn clean(&self) -> Item { + fn clean(&self, cx: &DocContext) -> Item { match *self { - ty::MethodTraitItem(ref mti) => mti.clean(), + ty::MethodTraitItem(ref mti) => mti.clean(cx), } } } @@ -1194,29 +1181,27 @@ impl Primitive { } impl Clean for ast::Ty { - fn clean(&self) -> Type { + fn clean(&self, cx: &DocContext) -> Type { use syntax::ast::*; match self.node { TyNil => Primitive(Unit), - TyPtr(ref m) => RawPointer(m.mutbl.clean(), box m.ty.clean()), + TyPtr(ref m) => RawPointer(m.mutbl.clean(cx), box m.ty.clean(cx)), TyRptr(ref l, ref m) => - BorrowedRef {lifetime: l.clean(), mutability: m.mutbl.clean(), - type_: box m.ty.clean()}, - TyBox(ty) => Managed(box ty.clean()), - TyUniq(ty) => Unique(box ty.clean()), - TyVec(ty) => Vector(box ty.clean()), - TyFixedLengthVec(ty, ref e) => FixedVector(box ty.clean(), - e.span.to_src()), - TyTup(ref tys) => Tuple(tys.iter().map(|x| x.clean()).collect()), + BorrowedRef {lifetime: l.clean(cx), mutability: m.mutbl.clean(cx), + type_: box m.ty.clean(cx)}, + TyBox(ty) => Managed(box ty.clean(cx)), + TyUniq(ty) => Unique(box ty.clean(cx)), + TyVec(ty) => Vector(box ty.clean(cx)), + TyFixedLengthVec(ty, ref e) => FixedVector(box ty.clean(cx), + e.span.to_src(cx)), + TyTup(ref tys) => Tuple(tys.clean(cx)), TyPath(ref p, ref tpbs, id) => { - resolve_type(p.clean(), - tpbs.clean().map(|x| x), - id) + resolve_type(cx, p.clean(cx), tpbs.clean(cx), id) } - TyClosure(ref c) => Closure(box c.clean()), - TyProc(ref c) => Proc(box c.clean()), - TyBareFn(ref barefn) => BareFunction(box barefn.clean()), - TyParen(ref ty) => ty.clean(), + TyClosure(ref c) => Closure(box c.clean(cx)), + TyProc(ref c) => Proc(box c.clean(cx)), + TyBareFn(ref barefn) => BareFunction(box barefn.clean(cx)), + TyParen(ref ty) => ty.clean(cx), TyBot => Bottom, ref x => fail!("Unimplemented type {:?}", x), } @@ -1224,7 +1209,7 @@ impl Clean for ast::Ty { } impl Clean for ty::t { - fn clean(&self) -> Type { + fn clean(&self, cx: &DocContext) -> Type { match ty::get(*self).sty { ty::ty_bot => Bottom, ty::ty_nil => Primitive(Unit), @@ -1244,41 +1229,41 @@ impl Clean for ty::t { ty::ty_float(ast::TyF64) => Primitive(F64), ty::ty_str => Primitive(Str), ty::ty_box(t) => { - let gc_did = get_cx().tcx_opt().and_then(|tcx| { + let gc_did = cx.tcx_opt().and_then(|tcx| { tcx.lang_items.gc() }); - lang_struct(gc_did, t, "Gc", Managed) + lang_struct(cx, gc_did, t, "Gc", Managed) } ty::ty_uniq(t) => { - let box_did = get_cx().tcx_opt().and_then(|tcx| { + let box_did = cx.tcx_opt().and_then(|tcx| { tcx.lang_items.owned_box() }); - lang_struct(box_did, t, "Box", Unique) + lang_struct(cx, box_did, t, "Box", Unique) } - ty::ty_vec(ty, None) => Vector(box ty.clean()), - ty::ty_vec(ty, Some(i)) => FixedVector(box ty.clean(), + ty::ty_vec(ty, None) => Vector(box ty.clean(cx)), + ty::ty_vec(ty, Some(i)) => FixedVector(box ty.clean(cx), format!("{}", i)), - ty::ty_ptr(mt) => RawPointer(mt.mutbl.clean(), box mt.ty.clean()), + ty::ty_ptr(mt) => RawPointer(mt.mutbl.clean(cx), box mt.ty.clean(cx)), ty::ty_rptr(r, mt) => BorrowedRef { - lifetime: r.clean(), - mutability: mt.mutbl.clean(), - type_: box mt.ty.clean(), + lifetime: r.clean(cx), + mutability: mt.mutbl.clean(cx), + type_: box mt.ty.clean(cx), }, ty::ty_bare_fn(ref fty) => BareFunction(box BareFunctionDecl { fn_style: fty.fn_style, generics: Generics { lifetimes: Vec::new(), type_params: Vec::new() }, - decl: (ast_util::local_def(0), &fty.sig).clean(), + decl: (ast_util::local_def(0), &fty.sig).clean(cx), abi: fty.abi.to_string(), }), ty::ty_closure(ref fty) => { let decl = box ClosureDecl { lifetimes: Vec::new(), // FIXME: this looks wrong... - decl: (ast_util::local_def(0), &fty.sig).clean(), + decl: (ast_util::local_def(0), &fty.sig).clean(cx), onceness: fty.onceness, fn_style: fty.fn_style, - bounds: fty.bounds.clean(), + bounds: fty.bounds.clean(cx), }; match fty.store { ty::UniqTraitStore => Proc(decl), @@ -1288,7 +1273,7 @@ impl Clean for ty::t { ty::ty_struct(did, ref substs) | ty::ty_enum(did, ref substs) | ty::ty_trait(box ty::TyTrait { def_id: did, ref substs, .. }) => { - let fqn = csearch::get_item_path(get_cx().tcx(), did); + let fqn = csearch::get_item_path(cx.tcx(), did); let fqn: Vec = fqn.move_iter().map(|i| { i.to_string() }).collect(); @@ -1297,17 +1282,16 @@ impl Clean for ty::t { ty::ty_trait(..) => TypeTrait, _ => TypeEnum, }; - let path = external_path(fqn.last().unwrap().to_string().as_slice(), + let path = external_path(cx, fqn.last().unwrap().to_string().as_slice(), substs); - get_cx().external_paths.borrow_mut().as_mut().unwrap() - .insert(did, (fqn, kind)); + cx.external_paths.borrow_mut().as_mut().unwrap().insert(did, (fqn, kind)); ResolvedPath { path: path, typarams: None, did: did, } } - ty::ty_tup(ref t) => Tuple(t.iter().map(|t| t.clean()).collect()), + ty::ty_tup(ref t) => Tuple(t.clean(cx)), ty::ty_param(ref p) => { if p.space == subst::SelfSpace { @@ -1333,51 +1317,46 @@ pub enum StructField { } impl Clean for ast::StructField { - fn clean(&self) -> Item { + fn clean(&self, cx: &DocContext) -> Item { let (name, vis) = match self.node.kind { ast::NamedField(id, vis) => (Some(id), vis), ast::UnnamedField(vis) => (None, vis) }; Item { - name: name.clean(), - attrs: self.node.attrs.clean(), - source: self.span.clean(), + name: name.clean(cx), + attrs: self.node.attrs.clean(cx), + source: self.span.clean(cx), visibility: Some(vis), - stability: get_stability(ast_util::local_def(self.node.id)), + stability: get_stability(cx, ast_util::local_def(self.node.id)), def_id: ast_util::local_def(self.node.id), - inner: StructFieldItem(TypedStructField(self.node.ty.clean())), + inner: StructFieldItem(TypedStructField(self.node.ty.clean(cx))), } } } impl Clean for ty::field_ty { - fn clean(&self) -> Item { + fn clean(&self, cx: &DocContext) -> Item { use syntax::parse::token::special_idents::unnamed_field; use rustc::metadata::csearch; - let cx = get_cx(); - let attrs; - let attr_map = csearch::get_struct_field_attrs(&cx.tcx().sess.cstore, self.id); - let name = if self.name == unnamed_field.name { - attrs = None; - None + let (name, attrs) = if self.name == unnamed_field.name { + (None, None) } else { - attrs = Some(attr_map.find(&self.id.node).unwrap()); - Some(self.name) + (Some(self.name), Some(attr_map.find(&self.id.node).unwrap())) }; let ty = ty::lookup_item_type(cx.tcx(), self.id); Item { - name: name.clean(), - attrs: attrs.unwrap_or(&Vec::new()).clean(), + name: name.clean(cx), + attrs: attrs.unwrap_or(&Vec::new()).clean(cx), source: Span::empty(), visibility: Some(self.vis), - stability: get_stability(self.id), + stability: get_stability(cx, self.id), def_id: self.id, - inner: StructFieldItem(TypedStructField(ty.ty.clean())), + inner: StructFieldItem(TypedStructField(ty.ty.clean(cx))), } } } @@ -1385,7 +1364,7 @@ impl Clean for ty::field_ty { pub type Visibility = ast::Visibility; impl Clean> for ast::Visibility { - fn clean(&self) -> Option { + fn clean(&self, _: &DocContext) -> Option { Some(*self) } } @@ -1399,18 +1378,18 @@ pub struct Struct { } impl Clean for doctree::Struct { - fn clean(&self) -> Item { + fn clean(&self, cx: &DocContext) -> Item { Item { - name: Some(self.name.clean()), - attrs: self.attrs.clean(), - source: self.whence.clean(), + name: Some(self.name.clean(cx)), + attrs: self.attrs.clean(cx), + source: self.whence.clean(cx), def_id: ast_util::local_def(self.id), - visibility: self.vis.clean(), - stability: self.stab.clean(), + visibility: self.vis.clean(cx), + stability: self.stab.clean(cx), inner: StructItem(Struct { struct_type: self.struct_type, - generics: self.generics.clean(), - fields: self.fields.clean(), + generics: self.generics.clean(cx), + fields: self.fields.clean(cx), fields_stripped: false, }), } @@ -1428,10 +1407,10 @@ pub struct VariantStruct { } impl Clean for syntax::ast::StructDef { - fn clean(&self) -> VariantStruct { + fn clean(&self, cx: &DocContext) -> VariantStruct { VariantStruct { struct_type: doctree::struct_type_from_def(self), - fields: self.fields.clean(), + fields: self.fields.clean(cx), fields_stripped: false, } } @@ -1445,17 +1424,17 @@ pub struct Enum { } impl Clean for doctree::Enum { - fn clean(&self) -> Item { + fn clean(&self, cx: &DocContext) -> Item { Item { - name: Some(self.name.clean()), - attrs: self.attrs.clean(), - source: self.whence.clean(), + name: Some(self.name.clean(cx)), + attrs: self.attrs.clean(cx), + source: self.whence.clean(cx), def_id: ast_util::local_def(self.id), - visibility: self.vis.clean(), - stability: self.stab.clean(), + visibility: self.vis.clean(cx), + stability: self.stab.clean(cx), inner: EnumItem(Enum { - variants: self.variants.clean(), - generics: self.generics.clean(), + variants: self.variants.clean(cx), + generics: self.generics.clean(cx), variants_stripped: false, }), } @@ -1468,29 +1447,28 @@ pub struct Variant { } impl Clean for doctree::Variant { - fn clean(&self) -> Item { + fn clean(&self, cx: &DocContext) -> Item { Item { - name: Some(self.name.clean()), - attrs: self.attrs.clean(), - source: self.whence.clean(), - visibility: self.vis.clean(), - stability: self.stab.clean(), + name: Some(self.name.clean(cx)), + attrs: self.attrs.clean(cx), + source: self.whence.clean(cx), + visibility: self.vis.clean(cx), + stability: self.stab.clean(cx), def_id: ast_util::local_def(self.id), inner: VariantItem(Variant { - kind: self.kind.clean(), + kind: self.kind.clean(cx), }), } } } impl Clean for ty::VariantInfo { - fn clean(&self) -> Item { + fn clean(&self, cx: &DocContext) -> Item { // use syntax::parse::token::special_idents::unnamed_field; - let cx = get_cx(); let kind = match self.arg_names.as_ref().map(|s| s.as_slice()) { None | Some([]) if self.args.len() == 0 => CLikeVariant, None | Some([]) => { - TupleVariant(self.args.iter().map(|t| t.clean()).collect()) + TupleVariant(self.args.clean(cx)) } Some(s) => { StructVariant(VariantStruct { @@ -1499,7 +1477,7 @@ impl Clean for ty::VariantInfo { fields: s.iter().zip(self.args.iter()).map(|(name, ty)| { Item { source: Span::empty(), - name: Some(name.clean()), + name: Some(name.clean(cx)), attrs: Vec::new(), visibility: Some(ast::Public), // FIXME: this is not accurate, we need an id for @@ -1510,9 +1488,9 @@ impl Clean for ty::VariantInfo { // more infrastructure work before we can get // at the needed information here. def_id: self.id, - stability: get_stability(self.id), + stability: get_stability(cx, self.id), inner: StructFieldItem( - TypedStructField(ty.clean()) + TypedStructField(ty.clean(cx)) ) } }).collect() @@ -1520,13 +1498,13 @@ impl Clean for ty::VariantInfo { } }; Item { - name: Some(self.name.clean()), - attrs: inline::load_attrs(cx.tcx(), self.id), + name: Some(self.name.clean(cx)), + attrs: inline::load_attrs(cx, cx.tcx(), self.id), source: Span::empty(), visibility: Some(ast::Public), def_id: self.id, inner: VariantItem(Variant { kind: kind }), - stability: get_stability(self.id), + stability: get_stability(cx, self.id), } } } @@ -1539,16 +1517,16 @@ pub enum VariantKind { } impl Clean for ast::VariantKind { - fn clean(&self) -> VariantKind { + fn clean(&self, cx: &DocContext) -> VariantKind { match self { &ast::TupleVariantKind(ref args) => { if args.len() == 0 { CLikeVariant } else { - TupleVariant(args.iter().map(|x| x.ty.clean()).collect()) + TupleVariant(args.iter().map(|x| x.ty.clean(cx)).collect()) } }, - &ast::StructVariantKind(ref sd) => StructVariant(sd.clean()), + &ast::StructVariantKind(ref sd) => StructVariant(sd.clean(cx)), } } } @@ -1573,9 +1551,8 @@ impl Span { } impl Clean for syntax::codemap::Span { - fn clean(&self) -> Span { - let ctxt = super::ctxtkey.get().unwrap(); - let cm = ctxt.sess().codemap(); + fn clean(&self, cx: &DocContext) -> Span { + let cm = cx.sess().codemap(); let filename = cm.span_to_filename(*self); let lo = cm.lookup_char_pos(self.lo); let hi = cm.lookup_char_pos(self.hi); @@ -1596,10 +1573,10 @@ pub struct Path { } impl Clean for ast::Path { - fn clean(&self) -> Path { + fn clean(&self, cx: &DocContext) -> Path { Path { global: self.global, - segments: self.segments.clean(), + segments: self.segments.clean(cx), } } } @@ -1612,11 +1589,11 @@ pub struct PathSegment { } impl Clean for ast::PathSegment { - fn clean(&self) -> PathSegment { + fn clean(&self, cx: &DocContext) -> PathSegment { PathSegment { - name: self.identifier.clean(), - lifetimes: self.lifetimes.clean(), - types: self.types.clean(), + name: self.identifier.clean(cx), + lifetimes: self.lifetimes.clean(cx), + types: self.types.clean(cx), } } } @@ -1636,13 +1613,13 @@ fn path_to_string(p: &ast::Path) -> String { } impl Clean for ast::Ident { - fn clean(&self) -> String { + fn clean(&self, _: &DocContext) -> String { token::get_ident(*self).get().to_string() } } impl Clean for ast::Name { - fn clean(&self) -> String { + fn clean(&self, _: &DocContext) -> String { token::get_name(*self).get().to_string() } } @@ -1654,17 +1631,17 @@ pub struct Typedef { } impl Clean for doctree::Typedef { - fn clean(&self) -> Item { + fn clean(&self, cx: &DocContext) -> Item { Item { - name: Some(self.name.clean()), - attrs: self.attrs.clean(), - source: self.whence.clean(), + name: Some(self.name.clean(cx)), + attrs: self.attrs.clean(cx), + source: self.whence.clean(cx), def_id: ast_util::local_def(self.id.clone()), - visibility: self.vis.clean(), - stability: self.stab.clean(), + visibility: self.vis.clean(cx), + stability: self.stab.clean(cx), inner: TypedefItem(Typedef { - type_: self.ty.clean(), - generics: self.gen.clean(), + type_: self.ty.clean(cx), + generics: self.gen.clean(cx), }), } } @@ -1679,14 +1656,14 @@ pub struct BareFunctionDecl { } impl Clean for ast::BareFnTy { - fn clean(&self) -> BareFunctionDecl { + fn clean(&self, cx: &DocContext) -> BareFunctionDecl { BareFunctionDecl { fn_style: self.fn_style, generics: Generics { - lifetimes: self.lifetimes.clean(), + lifetimes: self.lifetimes.clean(cx), type_params: Vec::new(), }, - decl: self.decl.clean(), + decl: self.decl.clean(cx), abi: self.abi.to_string(), } } @@ -1703,19 +1680,19 @@ pub struct Static { } impl Clean for doctree::Static { - fn clean(&self) -> Item { - debug!("claning static {}: {:?}", self.name.clean(), self); + fn clean(&self, cx: &DocContext) -> Item { + debug!("claning static {}: {:?}", self.name.clean(cx), self); Item { - name: Some(self.name.clean()), - attrs: self.attrs.clean(), - source: self.whence.clean(), + name: Some(self.name.clean(cx)), + attrs: self.attrs.clean(cx), + source: self.whence.clean(cx), def_id: ast_util::local_def(self.id), - visibility: self.vis.clean(), - stability: self.stab.clean(), + visibility: self.vis.clean(cx), + stability: self.stab.clean(cx), inner: StaticItem(Static { - type_: self.type_.clean(), - mutability: self.mutability.clean(), - expr: self.expr.span.to_src(), + type_: self.type_.clean(cx), + mutability: self.mutability.clean(cx), + expr: self.expr.span.to_src(cx), }), } } @@ -1728,7 +1705,7 @@ pub enum Mutability { } impl Clean for ast::Mutability { - fn clean(&self) -> Mutability { + fn clean(&self, _: &DocContext) -> Mutability { match self { &ast::MutMutable => Mutable, &ast::MutImmutable => Immutable, @@ -1750,19 +1727,19 @@ fn detect_derived(attrs: &[M]) -> bool { } impl Clean for doctree::Impl { - fn clean(&self) -> Item { + fn clean(&self, cx: &DocContext) -> Item { Item { name: None, - attrs: self.attrs.clean(), - source: self.whence.clean(), + attrs: self.attrs.clean(cx), + source: self.whence.clean(cx), def_id: ast_util::local_def(self.id), - visibility: self.vis.clean(), - stability: self.stab.clean(), + visibility: self.vis.clean(cx), + stability: self.stab.clean(cx), inner: ImplItem(Impl { - generics: self.generics.clean(), - trait_: self.trait_.clean(), - for_: self.for_.clean(), - items: self.items.clean().move_iter().map(|ti| { + generics: self.generics.clean(cx), + trait_: self.trait_.clean(cx), + for_: self.for_.clean(cx), + items: self.items.clean(cx).move_iter().map(|ti| { match ti { MethodImplItem(i) => i, } @@ -1779,7 +1756,7 @@ pub struct ViewItem { } impl Clean> for ast::ViewItem { - fn clean(&self) -> Vec { + fn clean(&self, cx: &DocContext) -> Vec { // We consider inlining the documentation of `pub use` statements, but we // forcefully don't inline if this is not public or if the // #[doc(no_inline)] attribute is present. @@ -1792,12 +1769,12 @@ impl Clean> for ast::ViewItem { let convert = |node: &ast::ViewItem_| { Item { name: None, - attrs: self.attrs.clean(), - source: self.span.clean(), + attrs: self.attrs.clean(cx), + source: self.span.clean(cx), def_id: ast_util::local_def(0), - visibility: self.vis.clean(), + visibility: self.vis.clean(cx), stability: None, - inner: ViewItemItem(ViewItem { inner: node.clean() }), + inner: ViewItemItem(ViewItem { inner: node.clean(cx) }), } }; let mut ret = Vec::new(); @@ -1810,7 +1787,7 @@ impl Clean> for ast::ViewItem { // to keep any non-inlineable reexports so they can be // listed in the documentation. let remaining = list.iter().filter(|path| { - match inline::try_inline(path.node.id(), None) { + match inline::try_inline(cx, path.node.id(), None) { Some(items) => { ret.extend(items.move_iter()); false } @@ -1826,7 +1803,7 @@ impl Clean> for ast::ViewItem { } } ast::ViewPathSimple(ident, _, id) => { - match inline::try_inline(id, Some(ident)) { + match inline::try_inline(cx, id, Some(ident)) { Some(items) => ret.extend(items.move_iter()), None => ret.push(convert(&self.node)), } @@ -1846,17 +1823,17 @@ pub enum ViewItemInner { } impl Clean for ast::ViewItem_ { - fn clean(&self) -> ViewItemInner { + fn clean(&self, cx: &DocContext) -> ViewItemInner { match self { &ast::ViewItemExternCrate(ref i, ref p, ref id) => { let string = match *p { None => None, Some((ref x, _)) => Some(x.get().to_string()), }; - ExternCrate(i.clean(), string, *id) + ExternCrate(i.clean(cx), string, *id) } &ast::ViewItemUse(ref vp) => { - Import(vp.clean()) + Import(vp.clean(cx)) } } } @@ -1879,15 +1856,15 @@ pub struct ImportSource { } impl Clean for ast::ViewPath { - fn clean(&self) -> ViewPath { + fn clean(&self, cx: &DocContext) -> ViewPath { match self.node { ast::ViewPathSimple(ref i, ref p, id) => - SimpleImport(i.clean(), resolve_use_source(p.clean(), id)), + SimpleImport(i.clean(cx), resolve_use_source(cx, p.clean(cx), id)), ast::ViewPathGlob(ref p, id) => - GlobImport(resolve_use_source(p.clean(), id)), + GlobImport(resolve_use_source(cx, p.clean(cx), id)), ast::ViewPathList(ref p, ref pl, id) => { - ImportList(resolve_use_source(p.clean(), id), - pl.clean()) + ImportList(resolve_use_source(cx, p.clean(cx), id), + pl.clean(cx)) } } } @@ -1900,51 +1877,51 @@ pub struct ViewListIdent { } impl Clean for ast::PathListItem { - fn clean(&self) -> ViewListIdent { + fn clean(&self, cx: &DocContext) -> ViewListIdent { match self.node { ast::PathListIdent { id, name } => ViewListIdent { - name: name.clean(), - source: resolve_def(id) + name: name.clean(cx), + source: resolve_def(cx, id) }, ast::PathListMod { id } => ViewListIdent { name: "mod".to_string(), - source: resolve_def(id) + source: resolve_def(cx, id) } } } } impl Clean> for ast::ForeignMod { - fn clean(&self) -> Vec { - self.items.clean() + fn clean(&self, cx: &DocContext) -> Vec { + self.items.clean(cx) } } impl Clean for ast::ForeignItem { - fn clean(&self) -> Item { + fn clean(&self, cx: &DocContext) -> Item { let inner = match self.node { ast::ForeignItemFn(ref decl, ref generics) => { ForeignFunctionItem(Function { - decl: decl.clean(), - generics: generics.clean(), + decl: decl.clean(cx), + generics: generics.clean(cx), fn_style: ast::UnsafeFn, }) } ast::ForeignItemStatic(ref ty, mutbl) => { ForeignStaticItem(Static { - type_: ty.clean(), + type_: ty.clean(cx), mutability: if mutbl {Mutable} else {Immutable}, expr: "".to_string(), }) } }; Item { - name: Some(self.ident.clean()), - attrs: self.attrs.clean(), - source: self.span.clean(), + name: Some(self.ident.clean(cx)), + attrs: self.attrs.clean(cx), + source: self.span.clean(cx), def_id: ast_util::local_def(self.id), - visibility: self.vis.clean(), - stability: get_stability(ast_util::local_def(self.id)), + visibility: self.vis.clean(cx), + stability: get_stability(cx, ast_util::local_def(self.id)), inner: inner, } } @@ -1953,15 +1930,13 @@ impl Clean for ast::ForeignItem { // Utilities trait ToSource { - fn to_src(&self) -> String; + fn to_src(&self, cx: &DocContext) -> String; } impl ToSource for syntax::codemap::Span { - fn to_src(&self) -> String { - debug!("converting span {:?} to snippet", self.clean()); - let ctxt = super::ctxtkey.get().unwrap(); - let cm = ctxt.sess().codemap().clone(); - let sn = match cm.span_to_snippet(*self) { + fn to_src(&self, cx: &DocContext) -> String { + debug!("converting span {:?} to snippet", self.clean(cx)); + let sn = match cx.sess().codemap().span_to_snippet(*self) { Some(x) => x.to_string(), None => "".to_string() }; @@ -2030,16 +2005,16 @@ fn name_from_pat(p: &ast::Pat) -> String { } /// Given a Type, resolve it using the def_map -fn resolve_type(path: Path, tpbs: Option>, +fn resolve_type(cx: &DocContext, path: Path, + tpbs: Option>, id: ast::NodeId) -> Type { - let cx = get_cx(); - let tycx = match cx.maybe_typed { - core::Typed(ref tycx) => tycx, + let tcx = match cx.tcx_opt() { + Some(tcx) => tcx, // If we're extracting tests, this return value doesn't matter. - core::NotTyped(_) => return Primitive(Bool), + None => return Primitive(Bool), }; debug!("searching for {:?} in defmap", id); - let def = match tycx.def_map.borrow().find(&id) { + let def = match tcx.def_map.borrow().find(&id) { Some(&k) => k, None => fail!("unresolved id not in defmap") }; @@ -2071,7 +2046,7 @@ fn resolve_type(path: Path, tpbs: Option>, ResolvedPath { path: path, typarams: tpbs, did: did } } -fn register_def(cx: &core::DocContext, def: def::Def) -> ast::DefId { +fn register_def(cx: &DocContext, def: def::Def) -> ast::DefId { let (did, kind) = match def { def::DefFn(i, _) => (i, TypeFunction), def::DefTy(i) => (i, TypeEnum), @@ -2083,14 +2058,14 @@ fn register_def(cx: &core::DocContext, def: def::Def) -> ast::DefId { _ => return def.def_id() }; if ast_util::is_local(did) { return did } - let tcx = match cx.maybe_typed { - core::Typed(ref t) => t, - core::NotTyped(_) => return did + let tcx = match cx.tcx_opt() { + Some(tcx) => tcx, + None => return did }; inline::record_extern_fqn(cx, did, kind); match kind { TypeTrait => { - let t = inline::build_external_trait(tcx, did); + let t = inline::build_external_trait(cx, tcx, did); cx.external_traits.borrow_mut().as_mut().unwrap().insert(did, t); } _ => {} @@ -2098,16 +2073,16 @@ fn register_def(cx: &core::DocContext, def: def::Def) -> ast::DefId { return did; } -fn resolve_use_source(path: Path, id: ast::NodeId) -> ImportSource { +fn resolve_use_source(cx: &DocContext, path: Path, id: ast::NodeId) -> ImportSource { ImportSource { path: path, - did: resolve_def(id), + did: resolve_def(cx, id), } } -fn resolve_def(id: ast::NodeId) -> Option { - get_cx().tcx_opt().and_then(|tcx| { - tcx.def_map.borrow().find(&id).map(|&def| register_def(&*get_cx(), def)) +fn resolve_def(cx: &DocContext, id: ast::NodeId) -> Option { + cx.tcx_opt().and_then(|tcx| { + tcx.def_map.borrow().find(&id).map(|&def| register_def(cx, def)) }) } @@ -2117,16 +2092,16 @@ pub struct Macro { } impl Clean for doctree::Macro { - fn clean(&self) -> Item { + fn clean(&self, cx: &DocContext) -> Item { Item { - name: Some(format!("{}!", self.name.clean())), - attrs: self.attrs.clean(), - source: self.whence.clean(), - visibility: ast::Public.clean(), - stability: self.stab.clean(), + name: Some(format!("{}!", self.name.clean(cx))), + attrs: self.attrs.clean(cx), + source: self.whence.clean(cx), + visibility: ast::Public.clean(cx), + stability: self.stab.clean(cx), def_id: ast_util::local_def(self.id), inner: MacroItem(Macro { - source: self.whence.to_src(), + source: self.whence.to_src(cx), }), } } @@ -2139,7 +2114,7 @@ pub struct Stability { } impl Clean for attr::Stability { - fn clean(&self) -> Stability { + fn clean(&self, _: &DocContext) -> Stability { Stability { level: self.level, text: self.text.as_ref().map_or("".to_string(), @@ -2148,18 +2123,18 @@ impl Clean for attr::Stability { } } -fn lang_struct(did: Option, t: ty::t, name: &str, +fn lang_struct(cx: &DocContext, did: Option, + t: ty::t, name: &str, fallback: fn(Box) -> Type) -> Type { let did = match did { Some(did) => did, - None => return fallback(box t.clean()), + None => return fallback(box t.clean(cx)), }; - let fqn = csearch::get_item_path(get_cx().tcx(), did); + let fqn = csearch::get_item_path(cx.tcx(), did); let fqn: Vec = fqn.move_iter().map(|i| { i.to_string() }).collect(); - get_cx().external_paths.borrow_mut().as_mut().unwrap() - .insert(did, (fqn, TypeStruct)); + cx.external_paths.borrow_mut().as_mut().unwrap().insert(did, (fqn, TypeStruct)); ResolvedPath { typarams: None, did: did, @@ -2168,7 +2143,7 @@ fn lang_struct(did: Option, t: ty::t, name: &str, segments: vec![PathSegment { name: name.to_string(), lifetimes: vec![], - types: vec![t.clean()], + types: vec![t.clean(cx)], }], }, } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 908a8ed11e7e8..a8cd9f18d60a5 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -22,23 +22,24 @@ use std::cell::RefCell; use std::gc::GC; use std::os; use std::collections::{HashMap, HashSet}; +use arena::TypedArena; use visit_ast::RustdocVisitor; use clean; use clean::Clean; /// Are we generating documentation (`Typed`) or tests (`NotTyped`)? -pub enum MaybeTyped { - Typed(middle::ty::ctxt), +pub enum MaybeTyped<'tcx> { + Typed(middle::ty::ctxt<'tcx>), NotTyped(driver::session::Session) } pub type ExternalPaths = RefCell, clean::TypeKind)>>>; -pub struct DocContext { +pub struct DocContext<'tcx> { pub krate: ast::Crate, - pub maybe_typed: MaybeTyped, + pub maybe_typed: MaybeTyped<'tcx>, pub src: Path, pub external_paths: ExternalPaths, pub external_traits: RefCell>>, @@ -47,7 +48,7 @@ pub struct DocContext { pub populated_crate_impls: RefCell>, } -impl DocContext { +impl<'tcx> DocContext<'tcx> { pub fn sess<'a>(&'a self) -> &'a driver::session::Session { match self.maybe_typed { Typed(ref tcx) => &tcx.sess, @@ -55,14 +56,14 @@ impl DocContext { } } - pub fn tcx_opt<'a>(&'a self) -> Option<&'a ty::ctxt> { + pub fn tcx_opt<'a>(&'a self) -> Option<&'a ty::ctxt<'tcx>> { match self.maybe_typed { Typed(ref tcx) => Some(tcx), NotTyped(_) => None } } - pub fn tcx<'a>(&'a self) -> &'a ty::ctxt { + pub fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { let tcx_opt = self.tcx_opt(); tcx_opt.expect("tcx not present") } @@ -80,9 +81,10 @@ pub struct CrateAnalysis { pub type Externs = HashMap>; /// Parses, resolves, and typechecks the given crate -fn get_ast_and_resolve(cpath: &Path, libs: Vec, cfgs: Vec, - externs: Externs, triple: Option) - -> (DocContext, CrateAnalysis) { +fn get_ast_and_resolve<'tcx>(cpath: &Path, libs: Vec, cfgs: Vec, + externs: Externs, triple: Option, + type_arena: &'tcx TypedArena) + -> (DocContext<'tcx>, CrateAnalysis) { use syntax::codemap::dummy_spanned; use rustc::driver::driver::{FileInput, phase_1_parse_input, @@ -131,7 +133,7 @@ fn get_ast_and_resolve(cpath: &Path, libs: Vec, cfgs: Vec, let driver::driver::CrateAnalysis { exported_items, public_items, ty_cx, .. - } = phase_3_run_analysis_passes(sess, &krate, ast_map, name); + } = phase_3_run_analysis_passes(sess, &krate, ast_map, type_arena, name); debug!("crate: {:?}", krate); (DocContext { @@ -156,14 +158,14 @@ fn get_ast_and_resolve(cpath: &Path, libs: Vec, cfgs: Vec, pub fn run_core(libs: Vec, cfgs: Vec, externs: Externs, path: &Path, triple: Option) -> (clean::Crate, CrateAnalysis) { - let (ctxt, analysis) = get_ast_and_resolve(path, libs, cfgs, externs, triple); - let ctxt = box(GC) ctxt; - super::ctxtkey.replace(Some(ctxt)); + let type_arena = TypedArena::new(); + let (ctxt, analysis) = get_ast_and_resolve(path, libs, cfgs, externs, + triple, &type_arena); let krate = { - let mut v = RustdocVisitor::new(&*ctxt, Some(&analysis)); + let mut v = RustdocVisitor::new(&ctxt, Some(&analysis)); v.visit(&ctxt.krate); - v.clean() + v.clean(&ctxt) }; let external_paths = ctxt.external_paths.borrow_mut().take(); diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 4adb7f1617ac3..758af6758c2c4 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -17,6 +17,7 @@ #![feature(globs, struct_variant, managed_boxes, macro_rules, phase)] +extern crate arena; extern crate debug; extern crate getopts; extern crate libc; @@ -29,7 +30,6 @@ extern crate time; use std::io; use std::io::{File, MemWriter}; -use std::gc::Gc; use std::collections::HashMap; use serialize::{json, Decodable, Encodable}; use externalfiles::ExternalHtml; @@ -83,7 +83,6 @@ static DEFAULT_PASSES: &'static [&'static str] = &[ "unindent-comments", ]; -local_data_key!(pub ctxtkey: Gc) local_data_key!(pub analysiskey: core::CrateAnalysis) type Output = (clean::Crate, Vec ); diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index adf8cfa45b512..0eb0a9afd751c 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -74,7 +74,7 @@ pub fn run(input: &str, "rustdoc-test", None) .expect("phase_2_configure_and_expand aborted in rustdoc!"); - let ctx = box(GC) core::DocContext { + let ctx = core::DocContext { krate: krate, maybe_typed: core::NotTyped(sess), src: input_path, @@ -84,11 +84,10 @@ pub fn run(input: &str, inlined: RefCell::new(None), populated_crate_impls: RefCell::new(HashSet::new()), }; - super::ctxtkey.replace(Some(ctx)); - let mut v = RustdocVisitor::new(&*ctx, None); + let mut v = RustdocVisitor::new(&ctx, None); v.visit(&ctx.krate); - let mut krate = v.clean(); + let mut krate = v.clean(&ctx); match crate_name { Some(name) => krate.name = name, None => {} diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 1706ebfbcf445..79576cac20af3 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -34,16 +34,16 @@ use doctree::*; // also, is there some reason that this doesn't use the 'visit' // framework from syntax? -pub struct RustdocVisitor<'a> { +pub struct RustdocVisitor<'a, 'tcx: 'a> { pub module: Module, pub attrs: Vec, - pub cx: &'a core::DocContext, + pub cx: &'a core::DocContext<'tcx>, pub analysis: Option<&'a core::CrateAnalysis>, } -impl<'a> RustdocVisitor<'a> { - pub fn new<'b>(cx: &'b core::DocContext, - analysis: Option<&'b core::CrateAnalysis>) -> RustdocVisitor<'b> { +impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { + pub fn new(cx: &'a core::DocContext<'tcx>, + analysis: Option<&'a core::CrateAnalysis>) -> RustdocVisitor<'a, 'tcx> { RustdocVisitor { module: Module::new(None), attrs: Vec::new(), @@ -53,11 +53,7 @@ impl<'a> RustdocVisitor<'a> { } fn stability(&self, id: ast::NodeId) -> Option { - let tcx = match self.cx.maybe_typed { - core::Typed(ref tcx) => tcx, - core::NotTyped(_) => return None - }; - stability::lookup(tcx, ast_util::local_def(id)) + self.cx.tcx_opt().and_then(|tcx| stability::lookup(tcx, ast_util::local_def(id))) } pub fn visit(&mut self, krate: &ast::Crate) { @@ -225,9 +221,9 @@ impl<'a> RustdocVisitor<'a> { fn resolve_id(&mut self, id: ast::NodeId, renamed: Option, glob: bool, om: &mut Module, please_inline: bool) -> bool { - let tcx = match self.cx.maybe_typed { - core::Typed(ref tcx) => tcx, - core::NotTyped(_) => return false + let tcx = match self.cx.tcx_opt() { + Some(tcx) => tcx, + None => return false }; let def = (*tcx.def_map.borrow())[id].def_id(); if !ast_util::is_local(def) { return false }