From ea1c6df81eecad62ca25191042b7871291162933 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 11 May 2017 16:10:47 +0300 Subject: [PATCH] rustc: stop interning CodeExtent, it's small enough. --- src/librustc/cfg/construct.rs | 5 +- src/librustc/ich/impls_ty.rs | 16 +- src/librustc/infer/error_reporting/mod.rs | 12 +- src/librustc/infer/mod.rs | 2 +- .../infer/region_inference/graphviz.rs | 22 +- src/librustc/middle/expr_use_visitor.rs | 4 +- src/librustc/middle/free_region.rs | 4 +- src/librustc/middle/mem_categorization.rs | 8 +- src/librustc/middle/region.rs | 232 ++++++++---------- src/librustc/ty/context.rs | 38 +-- src/librustc/ty/fold.rs | 2 +- src/librustc/ty/maps.rs | 2 +- src/librustc/ty/mod.rs | 3 +- src/librustc/ty/sty.rs | 10 +- src/librustc/util/ppaux.rs | 4 +- src/librustc_borrowck/borrowck/check_loans.rs | 8 +- .../borrowck/gather_loans/lifetime.rs | 4 +- .../borrowck/gather_loans/mod.rs | 16 +- src/librustc_borrowck/borrowck/mod.rs | 10 +- src/librustc_const_eval/check_match.rs | 2 +- src/librustc_driver/test.rs | 11 +- src/librustc_metadata/decoder.rs | 7 - src/librustc_mir/build/expr/as_operand.rs | 4 +- src/librustc_mir/build/expr/as_rvalue.rs | 4 +- src/librustc_mir/build/expr/as_temp.rs | 4 +- src/librustc_mir/build/mod.rs | 6 +- src/librustc_mir/build/scope.rs | 30 +-- src/librustc_mir/hair/cx/block.rs | 14 +- src/librustc_mir/hair/cx/expr.rs | 22 +- src/librustc_mir/hair/cx/mod.rs | 2 +- src/librustc_mir/hair/mod.rs | 18 +- src/librustc_typeck/check/dropck.rs | 2 +- src/librustc_typeck/check/mod.rs | 9 +- src/librustc_typeck/check/regionck.rs | 20 +- src/librustdoc/clean/mod.rs | 2 +- 35 files changed, 239 insertions(+), 320 deletions(-) diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index a8ad49c6582..c1c195852f9 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -10,6 +10,7 @@ use rustc_data_structures::graph; use cfg::*; +use middle::region::CodeExtent; use ty::{self, TyCtxt}; use syntax::ast; use syntax::ptr::P; @@ -586,8 +587,8 @@ fn add_exiting_edge(&mut self, scope_id: ast::NodeId, to_index: CFGIndex) { let mut data = CFGEdgeData { exiting_scopes: vec![] }; - let mut scope = self.tcx.node_extent(from_expr.id); - let target_scope = self.tcx.node_extent(scope_id); + let mut scope = CodeExtent::Misc(from_expr.id); + let target_scope = CodeExtent::Misc(scope_id); let region_maps = self.tcx.region_maps(self.owner_def_id); while scope != target_scope { data.exiting_scopes.push(scope.node_id()); diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index 6d6520adc4e..3bbac8d6a64 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -39,7 +39,7 @@ fn hash_stable(&self, } } -impl<'a, 'tcx> HashStable> for ty::RegionKind<'tcx> { +impl<'a, 'tcx> HashStable> for ty::RegionKind { fn hash_stable(&self, hcx: &mut StableHashingContext<'a, 'tcx>, hasher: &mut StableHasher) { @@ -428,24 +428,24 @@ fn hash_stable(&self, FnPtrAddrCast }); -impl<'a, 'tcx> HashStable> for ::middle::region::CodeExtentData +impl<'a, 'tcx> HashStable> for ::middle::region::CodeExtent { fn hash_stable(&self, hcx: &mut StableHashingContext<'a, 'tcx>, hasher: &mut StableHasher) { - use middle::region::CodeExtentData; + use middle::region::CodeExtent; mem::discriminant(self).hash_stable(hcx, hasher); match *self { - CodeExtentData::Misc(node_id) | - CodeExtentData::DestructionScope(node_id) => { + CodeExtent::Misc(node_id) | + CodeExtent::DestructionScope(node_id) => { node_id.hash_stable(hcx, hasher); } - CodeExtentData::CallSiteScope(body_id) | - CodeExtentData::ParameterScope(body_id) => { + CodeExtent::CallSiteScope(body_id) | + CodeExtent::ParameterScope(body_id) => { body_id.hash_stable(hcx, hasher); } - CodeExtentData::Remainder(block_remainder) => { + CodeExtent::Remainder(block_remainder) => { block_remainder.hash_stable(hcx, hasher); } } diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 009dfbd5402..c07b3b3c4be 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -151,19 +151,19 @@ fn explain_span<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, return; } }; - let scope_decorated_tag = match *scope { - region::CodeExtentData::Misc(_) => tag, - region::CodeExtentData::CallSiteScope(_) => { + let scope_decorated_tag = match scope { + region::CodeExtent::Misc(_) => tag, + region::CodeExtent::CallSiteScope(_) => { "scope of call-site for function" } - region::CodeExtentData::ParameterScope(_) => { + region::CodeExtent::ParameterScope(_) => { "scope of function body" } - region::CodeExtentData::DestructionScope(_) => { + region::CodeExtent::DestructionScope(_) => { new_string = format!("destruction scope surrounding {}", tag); &new_string[..] } - region::CodeExtentData::Remainder(r) => { + region::CodeExtent::Remainder(r) => { new_string = format!("block suffix following statement {}", r.first_statement_index); &new_string[..] diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index e42280124a1..1ecc277c7ca 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -1324,7 +1324,7 @@ pub fn expr_ty(&self, ex: &hir::Expr) -> Ty<'tcx> { pub fn resolve_regions_and_report_errors(&self, region_context: DefId, - region_map: &RegionMaps<'tcx>, + region_map: &RegionMaps, free_regions: &FreeRegionMap<'tcx>) { let region_rels = RegionRelations::new(self.tcx, region_context, diff --git a/src/librustc/infer/region_inference/graphviz.rs b/src/librustc/infer/region_inference/graphviz.rs index c48b8f610a2..cce253c1a1a 100644 --- a/src/librustc/infer/region_inference/graphviz.rs +++ b/src/librustc/infer/region_inference/graphviz.rs @@ -124,20 +124,20 @@ struct ConstraintGraph<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { graph_name: String, region_rels: &'a RegionRelations<'a, 'gcx, 'tcx>, map: &'a FxHashMap, SubregionOrigin<'tcx>>, - node_ids: FxHashMap, usize>, + node_ids: FxHashMap, } #[derive(Clone, Hash, PartialEq, Eq, Debug, Copy)] -enum Node<'tcx> { +enum Node { RegionVid(ty::RegionVid), - Region(ty::RegionKind<'tcx>), + Region(ty::RegionKind), } // type Edge = Constraint; #[derive(Clone, PartialEq, Eq, Debug, Copy)] enum Edge<'tcx> { Constraint(Constraint<'tcx>), - EnclScope(CodeExtent<'tcx>, CodeExtent<'tcx>), + EnclScope(CodeExtent, CodeExtent), } impl<'a, 'gcx, 'tcx> ConstraintGraph<'a, 'gcx, 'tcx> { @@ -176,7 +176,7 @@ fn new(name: String, } impl<'a, 'gcx, 'tcx> dot::Labeller<'a> for ConstraintGraph<'a, 'gcx, 'tcx> { - type Node = Node<'tcx>; + type Node = Node; type Edge = Edge<'tcx>; fn graph_id(&self) -> dot::Id { dot::Id::new(&*self.graph_name).unwrap() @@ -209,7 +209,7 @@ fn edge_label(&self, e: &Edge) -> dot::LabelText { } } -fn constraint_to_nodes<'tcx>(c: &Constraint<'tcx>) -> (Node<'tcx>, Node<'tcx>) { +fn constraint_to_nodes(c: &Constraint) -> (Node, Node) { match *c { Constraint::ConstrainVarSubVar(rv_1, rv_2) => (Node::RegionVid(rv_1), Node::RegionVid(rv_2)), @@ -222,7 +222,7 @@ fn constraint_to_nodes<'tcx>(c: &Constraint<'tcx>) -> (Node<'tcx>, Node<'tcx>) { } } -fn edge_to_nodes<'tcx>(e: &Edge<'tcx>) -> (Node<'tcx>, Node<'tcx>) { +fn edge_to_nodes(e: &Edge) -> (Node, Node) { match *e { Edge::Constraint(ref c) => constraint_to_nodes(c), Edge::EnclScope(sub, sup) => { @@ -233,9 +233,9 @@ fn edge_to_nodes<'tcx>(e: &Edge<'tcx>) -> (Node<'tcx>, Node<'tcx>) { } impl<'a, 'gcx, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'gcx, 'tcx> { - type Node = Node<'tcx>; + type Node = Node; type Edge = Edge<'tcx>; - fn nodes(&self) -> dot::Nodes> { + fn nodes(&self) -> dot::Nodes { let mut set = FxHashSet(); for node in self.node_ids.keys() { set.insert(*node); @@ -250,12 +250,12 @@ fn edges(&self) -> dot::Edges> { debug!("region graph has {} edges", v.len()); Cow::Owned(v) } - fn source(&self, edge: &Edge<'tcx>) -> Node<'tcx> { + fn source(&self, edge: &Edge<'tcx>) -> Node { let (n1, _) = edge_to_nodes(edge); debug!("edge {:?} has source {:?}", edge, n1); n1 } - fn target(&self, edge: &Edge<'tcx>) -> Node<'tcx> { + fn target(&self, edge: &Edge<'tcx>) -> Node { let (_, n2) = edge_to_nodes(edge); debug!("edge {:?} has target {:?}", edge, n2); n2 diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 41f9311dd80..99b140f690a 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -271,7 +271,7 @@ enum PassArgs { impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { pub fn new(delegate: &'a mut (Delegate<'tcx>+'a), - region_maps: &'a RegionMaps<'tcx>, + region_maps: &'a RegionMaps, infcx: &'a InferCtxt<'a, 'gcx, 'tcx>) -> Self { @@ -283,7 +283,7 @@ pub fn new(delegate: &'a mut (Delegate<'tcx>+'a), pub fn with_options(delegate: &'a mut (Delegate<'tcx>+'a), infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, - region_maps: &'a RegionMaps<'tcx>, + region_maps: &'a RegionMaps, options: mc::MemCategorizationOptions) -> Self { diff --git a/src/librustc/middle/free_region.rs b/src/librustc/middle/free_region.rs index 8168837b1f5..6a21bdc19e0 100644 --- a/src/librustc/middle/free_region.rs +++ b/src/librustc/middle/free_region.rs @@ -35,7 +35,7 @@ pub struct RegionRelations<'a, 'gcx: 'tcx, 'tcx: 'a> { pub context: DefId, /// region maps for the given context - pub region_maps: &'a RegionMaps<'tcx>, + pub region_maps: &'a RegionMaps, /// free-region relationships pub free_regions: &'a FreeRegionMap<'tcx>, @@ -45,7 +45,7 @@ impl<'a, 'gcx, 'tcx> RegionRelations<'a, 'gcx, 'tcx> { pub fn new( tcx: TyCtxt<'a, 'gcx, 'tcx>, context: DefId, - region_maps: &'a RegionMaps<'tcx>, + region_maps: &'a RegionMaps, free_regions: &'a FreeRegionMap<'tcx>, ) -> Self { Self { diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 8e25c6facf2..d0adf51d79e 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -290,7 +290,7 @@ fn span(&self) -> Span { self.span } #[derive(Clone)] pub struct MemCategorizationContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { pub infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, - pub region_maps: &'a RegionMaps<'tcx>, + pub region_maps: &'a RegionMaps, options: MemCategorizationOptions, } @@ -406,7 +406,7 @@ pub fn to_user_str(&self) -> &'static str { impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { /// Context should be the `DefId` we use to fetch region-maps. pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, - region_maps: &'a RegionMaps<'tcx>) + region_maps: &'a RegionMaps) -> MemCategorizationContext<'a, 'gcx, 'tcx> { MemCategorizationContext::with_options(infcx, region_maps, @@ -414,7 +414,7 @@ pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, } pub fn with_options(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, - region_maps: &'a RegionMaps<'tcx>, + region_maps: &'a RegionMaps, options: MemCategorizationOptions) -> MemCategorizationContext<'a, 'gcx, 'tcx> { MemCategorizationContext { @@ -839,7 +839,7 @@ fn env_deref(&self, pub fn temporary_scope(&self, id: ast::NodeId) -> (ty::Region<'tcx>, ty::Region<'tcx>) { let (scope, old_scope) = - self.region_maps.old_and_new_temporary_scope(self.tcx(), id); + self.region_maps.old_and_new_temporary_scope(id); (self.tcx().mk_region(match scope { Some(scope) => ty::ReScope(scope), None => ty::ReStatic diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 2940d250dd3..331683381a4 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -22,7 +22,6 @@ use std::mem; use std::rc::Rc; -use serialize; use syntax::codemap; use syntax::ast; use syntax_pos::Span; @@ -35,11 +34,6 @@ use hir::{Block, Arm, Pat, PatKind, Stmt, Expr, Local}; use mir::transform::MirSource; -pub type CodeExtent<'tcx> = &'tcx CodeExtentData; - -impl<'tcx> serialize::UseSpecializedEncodable for CodeExtent<'tcx> {} -impl<'tcx> serialize::UseSpecializedDecodable for CodeExtent<'tcx> {} - /// CodeExtent represents a statically-describable extent that can be /// used to bound the lifetime/region for values. /// @@ -102,7 +96,7 @@ impl<'tcx> serialize::UseSpecializedDecodable for CodeExtent<'tcx> {} /// actually attach a more meaningful ordering to scopes than the one /// generated via deriving here. #[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Debug, Copy, RustcEncodable, RustcDecodable)] -pub enum CodeExtentData { +pub enum CodeExtent { Misc(ast::NodeId), // extent of the call-site for a function or closure (outlives @@ -131,9 +125,9 @@ pub enum CodeExtentData { /// * the subscope with `first_statement_index == 0` is scope of both /// `a` and `b`; it does not include EXPR_1, but does include /// everything after that first `let`. (If you want a scope that -/// includes EXPR_1 as well, then do not use `CodeExtentData::Remainder`, +/// includes EXPR_1 as well, then do not use `CodeExtent::Remainder`, /// but instead another `CodeExtent` that encompasses the whole block, -/// e.g. `CodeExtentData::Misc`. +/// e.g. `CodeExtent::Misc`. /// /// * the subscope with `first_statement_index == 1` is scope of `c`, /// and thus does not include EXPR_2, but covers the `...`. @@ -144,21 +138,21 @@ pub struct BlockRemainder { pub first_statement_index: u32, } -impl CodeExtentData { +impl CodeExtent { /// Returns a node id associated with this scope. /// /// NB: likely to be replaced as API is refined; e.g. pnkfelix /// anticipates `fn entry_node_id` and `fn each_exit_node_id`. pub fn node_id(&self) -> ast::NodeId { match *self { - CodeExtentData::Misc(node_id) => node_id, + CodeExtent::Misc(node_id) => node_id, // These cases all return rough approximations to the // precise extent denoted by `self`. - CodeExtentData::Remainder(br) => br.block, - CodeExtentData::DestructionScope(node_id) => node_id, - CodeExtentData::CallSiteScope(body_id) | - CodeExtentData::ParameterScope(body_id) => body_id.node_id, + CodeExtent::Remainder(br) => br.block, + CodeExtent::DestructionScope(node_id) => node_id, + CodeExtent::CallSiteScope(body_id) | + CodeExtent::ParameterScope(body_id) => body_id.node_id, } } @@ -169,12 +163,12 @@ pub fn span(&self, hir_map: &hir_map::Map) -> Option { match hir_map.find(self.node_id()) { Some(hir_map::NodeBlock(ref blk)) => { match *self { - CodeExtentData::CallSiteScope(_) | - CodeExtentData::ParameterScope(_) | - CodeExtentData::Misc(_) | - CodeExtentData::DestructionScope(_) => Some(blk.span), + CodeExtent::CallSiteScope(_) | + CodeExtent::ParameterScope(_) | + CodeExtent::Misc(_) | + CodeExtent::DestructionScope(_) => Some(blk.span), - CodeExtentData::Remainder(r) => { + CodeExtent::Remainder(r) => { assert_eq!(r.block, blk.id); // Want span for extent starting after the // indexed statement and ending at end of @@ -197,7 +191,7 @@ pub fn span(&self, hir_map: &hir_map::Map) -> Option { } /// The region maps encode information about region relationships. -pub struct RegionMaps<'tcx> { +pub struct RegionMaps { /// If not empty, this body is the root of this region hierarchy. root_body: Option, @@ -212,14 +206,14 @@ pub struct RegionMaps<'tcx> { /// conditional expression or repeating block. (Note that the /// enclosing scope id for the block associated with a closure is /// the closure itself.) - scope_map: FxHashMap, CodeExtent<'tcx>>, + scope_map: FxHashMap, /// `var_map` maps from a variable or binding id to the block in /// which that variable is declared. - var_map: NodeMap>, + var_map: NodeMap, /// maps from a node-id to the associated destruction scope (if any) - destruction_scopes: NodeMap>, + destruction_scopes: NodeMap, /// `rvalue_scopes` includes entries for those expressions whose cleanup scope is /// larger than the default. The map goes from the expression id @@ -227,14 +221,14 @@ pub struct RegionMaps<'tcx> { /// table, the appropriate cleanup scope is the innermost /// enclosing statement, conditional expression, or repeating /// block (see `terminating_scopes`). - rvalue_scopes: NodeMap>, + rvalue_scopes: NodeMap, /// Records the value of rvalue scopes before they were shrunk by /// #36082, for error reporting. /// /// FIXME: this should be temporary. Remove this by 1.18.0 or /// so. - shrunk_rvalue_scopes: NodeMap>, + shrunk_rvalue_scopes: NodeMap, /// Encodes the hierarchy of fn bodies. Every fn body (including /// closures) forms its own distinct region hierarchy, rooted in @@ -250,7 +244,7 @@ pub struct RegionMaps<'tcx> { } #[derive(Debug, Copy, Clone)] -pub struct Context<'tcx> { +pub struct Context { /// the root of the current region tree. This is typically the id /// of the innermost fn body. Each fn forms its own disjoint tree /// in the region hierarchy. These fn bodies are themselves @@ -260,19 +254,19 @@ pub struct Context<'tcx> { root_id: Option, /// the scope that contains any new variables declared - var_parent: Option>, + var_parent: Option, /// region parent of expressions etc - parent: Option>, + parent: Option, } struct RegionResolutionVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, // Generated maps: - region_maps: &'a mut RegionMaps<'tcx>, + region_maps: &'a mut RegionMaps, - cx: Context<'tcx>, + cx: Context, map: &'a hir_map::Map<'tcx>, @@ -300,7 +294,7 @@ struct RegionResolutionVisitor<'a, 'tcx: 'a> { } -impl<'tcx> RegionMaps<'tcx> { +impl<'tcx> RegionMaps { pub fn new() -> Self { RegionMaps { root_body: None, @@ -315,8 +309,8 @@ pub fn new() -> Self { } pub fn record_code_extent(&mut self, - child: CodeExtent<'tcx>, - parent: Option>) { + child: CodeExtent, + parent: Option) { debug!("{:?}.parent = {:?}", child, parent); if let Some(p) = parent { @@ -325,24 +319,24 @@ pub fn record_code_extent(&mut self, } // record the destruction scopes for later so we can query them - if let &CodeExtentData::DestructionScope(n) = child { + if let CodeExtent::DestructionScope(n) = child { self.destruction_scopes.insert(n, child); } } - pub fn each_encl_scope(&self, mut e:E) where E: FnMut(CodeExtent<'tcx>, CodeExtent<'tcx>) { + pub fn each_encl_scope(&self, mut e:E) where E: FnMut(CodeExtent, CodeExtent) { for (&child, &parent) in &self.scope_map { e(child, parent) } } - pub fn each_var_scope(&self, mut e:E) where E: FnMut(&ast::NodeId, CodeExtent<'tcx>) { - for (child, parent) in self.var_map.iter() { + pub fn each_var_scope(&self, mut e:E) where E: FnMut(&ast::NodeId, CodeExtent) { + for (child, &parent) in self.var_map.iter() { e(child, parent) } } - pub fn opt_destruction_extent(&self, n: ast::NodeId) -> Option> { + pub fn opt_destruction_extent(&self, n: ast::NodeId) -> Option { self.destruction_scopes.get(&n).cloned() } @@ -366,48 +360,46 @@ fn fn_is_enclosed_by(&self, mut sub_fn: ast::NodeId, sup_fn: ast::NodeId) -> boo } } - fn record_var_scope(&mut self, var: ast::NodeId, lifetime: CodeExtent<'tcx>) { + fn record_var_scope(&mut self, var: ast::NodeId, lifetime: CodeExtent) { debug!("record_var_scope(sub={:?}, sup={:?})", var, lifetime); assert!(var != lifetime.node_id()); self.var_map.insert(var, lifetime); } - fn record_rvalue_scope(&mut self, var: ast::NodeId, lifetime: CodeExtent<'tcx>) { + fn record_rvalue_scope(&mut self, var: ast::NodeId, lifetime: CodeExtent) { debug!("record_rvalue_scope(sub={:?}, sup={:?})", var, lifetime); assert!(var != lifetime.node_id()); self.rvalue_scopes.insert(var, lifetime); } - fn record_shrunk_rvalue_scope(&mut self, var: ast::NodeId, lifetime: CodeExtent<'tcx>) { + fn record_shrunk_rvalue_scope(&mut self, var: ast::NodeId, lifetime: CodeExtent) { debug!("record_rvalue_scope(sub={:?}, sup={:?})", var, lifetime); assert!(var != lifetime.node_id()); self.shrunk_rvalue_scopes.insert(var, lifetime); } - pub fn opt_encl_scope(&self, id: CodeExtent<'tcx>) -> Option> { + pub fn opt_encl_scope(&self, id: CodeExtent) -> Option { //! Returns the narrowest scope that encloses `id`, if any. self.scope_map.get(&id).cloned() } #[allow(dead_code)] // used in cfg - pub fn encl_scope(&self, id: CodeExtent<'tcx>) -> CodeExtent<'tcx> { + pub fn encl_scope(&self, id: CodeExtent) -> CodeExtent { //! Returns the narrowest scope that encloses `id`, if any. self.opt_encl_scope(id).unwrap() } /// Returns the lifetime of the local variable `var_id` - pub fn var_scope(&self, var_id: ast::NodeId) -> CodeExtent<'tcx> { + pub fn var_scope(&self, var_id: ast::NodeId) -> CodeExtent { match self.var_map.get(&var_id) { Some(&r) => r, None => { bug!("no enclosing scope for id {:?}", var_id); } } } - pub fn temporary_scope2<'a, 'gcx: 'tcx>(&self, - tcx: TyCtxt<'a, 'gcx, 'tcx>, - expr_id: ast::NodeId) - -> (Option>, bool) { - let temporary_scope = self.temporary_scope(tcx, expr_id); + pub fn temporary_scope2(&self, expr_id: ast::NodeId) + -> (Option, bool) { + let temporary_scope = self.temporary_scope(expr_id); let was_shrunk = match self.shrunk_rvalue_scopes.get(&expr_id) { Some(&s) => { info!("temporary_scope2({:?}, scope={:?}, shrunk={:?})", @@ -420,23 +412,18 @@ pub fn temporary_scope2<'a, 'gcx: 'tcx>(&self, (temporary_scope, was_shrunk) } - pub fn old_and_new_temporary_scope<'a, 'gcx: 'tcx>(&self, - tcx: TyCtxt<'a, 'gcx, 'tcx>, - expr_id: ast::NodeId) - -> (Option>, - Option>) + pub fn old_and_new_temporary_scope(&self, expr_id: ast::NodeId) + -> (Option, + Option) { - let temporary_scope = self.temporary_scope(tcx, expr_id); + let temporary_scope = self.temporary_scope(expr_id); (temporary_scope, self.shrunk_rvalue_scopes .get(&expr_id).cloned() .or(temporary_scope)) } - pub fn temporary_scope<'a, 'gcx: 'tcx>(&self, - tcx: TyCtxt<'a, 'gcx, 'tcx>, - expr_id: ast::NodeId) - -> Option> { + pub fn temporary_scope(&self, expr_id: ast::NodeId) -> Option { //! Returns the scope when temp created by expr_id will be cleaned up // check for a designated rvalue scope @@ -449,11 +436,11 @@ pub fn temporary_scope<'a, 'gcx: 'tcx>(&self, // if there's one. Static items, for instance, won't // have an enclosing scope, hence no scope will be // returned. - let mut id = tcx.node_extent(expr_id); + let mut id = CodeExtent::Misc(expr_id); - while let Some(&p) = self.scope_map.get(id) { - match *p { - CodeExtentData::DestructionScope(..) => { + while let Some(&p) = self.scope_map.get(&id) { + match p { + CodeExtent::DestructionScope(..) => { debug!("temporary_scope({:?}) = {:?} [enclosing]", expr_id, id); return Some(id); @@ -466,7 +453,7 @@ pub fn temporary_scope<'a, 'gcx: 'tcx>(&self, return None; } - pub fn var_region(&self, id: ast::NodeId) -> ty::RegionKind<'tcx> { + pub fn var_region(&self, id: ast::NodeId) -> ty::RegionKind { //! Returns the lifetime of the variable `id`. let scope = ty::ReScope(self.var_scope(id)); @@ -508,9 +495,9 @@ pub fn is_subscope_of(&self, /// Finds the nearest common ancestor (if any) of two scopes. That is, finds the smallest /// scope which is greater than or equal to both `scope_a` and `scope_b`. pub fn nearest_common_ancestor(&self, - scope_a: CodeExtent<'tcx>, - scope_b: CodeExtent<'tcx>) - -> CodeExtent<'tcx> { + scope_a: CodeExtent, + scope_b: CodeExtent) + -> CodeExtent { if scope_a == scope_b { return scope_a; } /// [1] The initial values for `a_buf` and `b_buf` are not used. @@ -518,9 +505,9 @@ pub fn nearest_common_ancestor(&self, /// is re-initialized with new values (or else fallback to a /// heap-allocated vector). let mut a_buf: [CodeExtent; 32] = [scope_a /* [1] */; 32]; - let mut a_vec: Vec> = vec![]; + let mut a_vec: Vec = vec![]; let mut b_buf: [CodeExtent; 32] = [scope_b /* [1] */; 32]; - let mut b_vec: Vec> = vec![]; + let mut b_vec: Vec = vec![]; let scope_map = &self.scope_map; let a_ancestors = ancestors_of(scope_map, scope_a, &mut a_buf, &mut a_vec); let b_ancestors = ancestors_of(scope_map, scope_b, &mut b_buf, &mut b_vec); @@ -544,8 +531,8 @@ pub fn nearest_common_ancestor(&self, let a_root_scope = a_ancestors[a_index]; let b_root_scope = a_ancestors[a_index]; return match (a_root_scope, b_root_scope) { - (&CodeExtentData::DestructionScope(a_root_id), - &CodeExtentData::DestructionScope(b_root_id)) => { + (CodeExtent::DestructionScope(a_root_id), + CodeExtent::DestructionScope(b_root_id)) => { if self.fn_is_enclosed_by(a_root_id, b_root_id) { // `a` is enclosed by `b`, hence `b` is the ancestor of everything in `a` scope_b @@ -576,11 +563,11 @@ pub fn nearest_common_ancestor(&self, } } - fn ancestors_of<'a, 'tcx>(scope_map: &FxHashMap, CodeExtent<'tcx>>, - scope: CodeExtent<'tcx>, - buf: &'a mut [CodeExtent<'tcx>; 32], - vec: &'a mut Vec>) - -> &'a [CodeExtent<'tcx>] { + fn ancestors_of<'a, 'tcx>(scope_map: &FxHashMap, + scope: CodeExtent, + buf: &'a mut [CodeExtent; 32], + vec: &'a mut Vec) + -> &'a [CodeExtent] { // debug!("ancestors_of(scope={:?})", scope); let mut scope = scope; @@ -588,7 +575,7 @@ fn ancestors_of<'a, 'tcx>(scope_map: &FxHashMap, CodeExtent<'tc while i < 32 { buf[i] = scope; match scope_map.get(&scope) { - Some(superscope) => scope = superscope, + Some(&superscope) => scope = superscope, _ => return &buf[..i+1] } i += 1; @@ -599,7 +586,7 @@ fn ancestors_of<'a, 'tcx>(scope_map: &FxHashMap, CodeExtent<'tc loop { vec.push(scope); match scope_map.get(&scope) { - Some(superscope) => scope = superscope, + Some(&superscope) => scope = superscope, _ => return &*vec } } @@ -610,7 +597,7 @@ fn ancestors_of<'a, 'tcx>(scope_map: &FxHashMap, CodeExtent<'tc /// returns the outermost `CodeExtent` that the region outlives. pub fn early_free_extent<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, br: &ty::EarlyBoundRegion) - -> CodeExtent<'tcx> { + -> CodeExtent { let param_owner = tcx.parent_def_id(br.def_id).unwrap(); let param_owner_id = tcx.hir.as_local_node_id(param_owner).unwrap(); @@ -627,13 +614,13 @@ pub fn early_free_extent<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, self.root_body.unwrap() }); - tcx.intern_code_extent(CodeExtentData::CallSiteScope(body_id)) + CodeExtent::CallSiteScope(body_id) } /// Assuming that the provided region was defined within this `RegionMaps`, /// returns the outermost `CodeExtent` that the region outlives. pub fn free_extent<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, fr: &ty::FreeRegion) - -> CodeExtent<'tcx> { + -> CodeExtent { let param_owner = match fr.bound_region { ty::BoundRegion::BrNamed(def_id, _) => { tcx.parent_def_id(def_id).unwrap() @@ -646,9 +633,7 @@ pub fn free_extent<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, fr: &ty::FreeRe assert_eq!(param_owner, fr.scope); let param_owner_id = tcx.hir.as_local_node_id(param_owner).unwrap(); - let body_id = tcx.hir.body_owned_by(param_owner_id); - - tcx.intern_code_extent(CodeExtentData::CallSiteScope(body_id)) + CodeExtent::CallSiteScope(tcx.hir.body_owned_by(param_owner_id)) } } @@ -671,7 +656,6 @@ fn resolve_block<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, blk: debug!("resolve_block(blk.id={:?})", blk.id); let prev_cx = visitor.cx; - let block_extent = visitor.new_node_extent_with_dtor(blk.id); // We treat the tail expression in the block (if any) somewhat // differently from the statements. The issue has to do with @@ -698,11 +682,8 @@ fn resolve_block<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, blk: // `other_argument()` has run and also the call to `quux(..)` // itself has returned. - visitor.cx = Context { - root_id: prev_cx.root_id, - var_parent: Some(block_extent), - parent: Some(block_extent), - }; + visitor.enter_node_extent_with_dtor(blk.id); + visitor.cx.var_parent = visitor.cx.parent; { // This block should be kept approximately in sync with @@ -718,17 +699,13 @@ fn resolve_block<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, blk: // has the previous subscope in the block as a parent, // except for the first such subscope, which has the // block itself as a parent. - let stmt_extent = visitor.new_code_extent( - CodeExtentData::Remainder(BlockRemainder { + visitor.enter_code_extent( + CodeExtent::Remainder(BlockRemainder { block: blk.id, first_statement_index: i as u32 }) ); - visitor.cx = Context { - root_id: prev_cx.root_id, - var_parent: Some(stmt_extent), - parent: Some(stmt_extent), - }; + visitor.cx.var_parent = visitor.cx.parent; } visitor.visit_stmt(statement) } @@ -749,7 +726,7 @@ fn resolve_arm<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, arm: & } fn resolve_pat<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, pat: &'tcx hir::Pat) { - visitor.new_node_extent(pat.id); + visitor.record_code_extent(CodeExtent::Misc(pat.id)); // If this is a binding then record the lifetime of that binding. if let PatKind::Binding(..) = pat.node { @@ -769,20 +746,20 @@ fn resolve_stmt<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, stmt: // statement plus its destructors, and thus the extent for which // regions referenced by the destructors need to survive. visitor.terminating_scopes.insert(stmt_id); - let stmt_extent = visitor.new_node_extent_with_dtor(stmt_id); let prev_parent = visitor.cx.parent; - visitor.cx.parent = Some(stmt_extent); + visitor.enter_node_extent_with_dtor(stmt_id); + intravisit::walk_stmt(visitor, stmt); + visitor.cx.parent = prev_parent; } fn resolve_expr<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, expr: &'tcx hir::Expr) { debug!("resolve_expr(expr.id={:?})", expr.id); - let expr_extent = visitor.new_node_extent_with_dtor(expr.id); let prev_cx = visitor.cx; - visitor.cx.parent = Some(expr_extent); + visitor.enter_node_extent_with_dtor(expr.id); { let terminating_scopes = &mut visitor.terminating_scopes; @@ -822,7 +799,7 @@ fn resolve_expr<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, expr: } hir::ExprMatch(..) => { - visitor.cx.var_parent = Some(expr_extent); + visitor.cx.var_parent = visitor.cx.parent; } hir::ExprAssignOp(..) | hir::ExprIndex(..) | @@ -1009,7 +986,7 @@ fn is_borrowed_ty(ty: &hir::Ty) -> bool { fn record_rvalue_scope_if_borrow_expr<'a, 'tcx>( visitor: &mut RegionResolutionVisitor<'a, 'tcx>, expr: &hir::Expr, - blk_id: CodeExtent<'tcx>) + blk_id: CodeExtent) { match expr.node { hir::ExprAddrOf(_, ref subexpr) => { @@ -1059,7 +1036,7 @@ fn record_rvalue_scope_if_borrow_expr<'a, 'tcx>( /// Note: ET is intended to match "rvalues or lvalues based on rvalues". fn record_rvalue_scope<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, expr: &hir::Expr, - blk_scope: CodeExtent<'tcx>, + blk_scope: CodeExtent, is_shrunk: bool) { let mut expr = expr; loop { @@ -1092,43 +1069,28 @@ fn record_rvalue_scope<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx> } impl<'a, 'tcx> RegionResolutionVisitor<'a, 'tcx> { - pub fn intern_code_extent(&mut self, - data: CodeExtentData, - parent: Option>) - -> CodeExtent<'tcx> { - let code_extent = self.tcx.intern_code_extent(data); - self.region_maps.record_code_extent(code_extent, parent); - code_extent - } - - pub fn intern_node(&mut self, - n: ast::NodeId, - parent: Option>) -> CodeExtent<'tcx> { - self.intern_code_extent(CodeExtentData::Misc(n), parent) - } - /// Records the current parent (if any) as the parent of `child_scope`. - fn new_code_extent(&mut self, child_scope: CodeExtentData) -> CodeExtent<'tcx> { + fn record_code_extent(&mut self, child_scope: CodeExtent) { let parent = self.cx.parent; - self.intern_code_extent(child_scope, parent) + self.region_maps.record_code_extent(child_scope, parent); } - fn new_node_extent(&mut self, child_scope: ast::NodeId) -> CodeExtent<'tcx> { - self.new_code_extent(CodeExtentData::Misc(child_scope)) + /// Records the current parent (if any) as the parent of `child_scope`, + /// and sets `child_scope` as the new current parent. + fn enter_code_extent(&mut self, child_scope: CodeExtent) { + self.record_code_extent(child_scope); + self.cx.parent = Some(child_scope); } - fn new_node_extent_with_dtor(&mut self, id: ast::NodeId) -> CodeExtent<'tcx> { + fn enter_node_extent_with_dtor(&mut self, id: ast::NodeId) { // If node was previously marked as a terminating scope during the // recursive visit of its parent node in the AST, then we need to // account for the destruction scope representing the extent of // the destructors that run immediately after it completes. if self.terminating_scopes.contains(&id) { - let ds = self.new_code_extent( - CodeExtentData::DestructionScope(id)); - self.intern_node(id, Some(ds)) - } else { - self.new_node_extent(id) + self.enter_code_extent(CodeExtent::DestructionScope(id)); } + self.enter_code_extent(CodeExtent::Misc(id)); } } @@ -1165,10 +1127,8 @@ fn visit_body(&mut self, body: &'tcx hir::Body) { } self.cx.root_id = Some(body_id.node_id); - self.cx.parent = Some(self.new_code_extent( - CodeExtentData::CallSiteScope(body_id))); - self.cx.parent = Some(self.new_code_extent( - CodeExtentData::ParameterScope(body_id))); + self.enter_code_extent(CodeExtent::CallSiteScope(body_id)); + self.enter_code_extent(CodeExtent::ParameterScope(body_id)); // The arguments and `self` are parented to the fn. self.cx.var_parent = self.cx.parent.take(); @@ -1203,7 +1163,7 @@ fn visit_local(&mut self, l: &'tcx Local) { } fn region_maps<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) - -> Rc> + -> Rc { let closure_base_def_id = tcx.closure_base_def_id(def_id); if closure_base_def_id != def_id { diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 39ab2abcc0e..b9355c264b3 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -21,7 +21,6 @@ use hir::map::DisambiguatedDefPathData; use middle::free_region::FreeRegionMap; use middle::lang_items; -use middle::region::{CodeExtent, CodeExtentData}; use middle::resolve_lifetime; use middle::stability; use mir::Mir; @@ -99,7 +98,7 @@ pub struct CtxtInterners<'tcx> { type_: RefCell>>>, type_list: RefCell>>>>, substs: RefCell>>>, - region: RefCell>>>, + region: RefCell>>, existential_predicates: RefCell>>>>, predicates: RefCell>>>>, } @@ -548,8 +547,6 @@ pub struct GlobalCtxt<'tcx> { layout_interner: RefCell>, - code_extent_interner: RefCell>>, - /// A vector of every trait accessible in the whole crate /// (i.e. including those from subcrates). This is used only for /// error reporting, and so is lazily initialised and generally @@ -651,32 +648,6 @@ pub fn intern_stability(self, stab: attr::Stability) -> &'gcx attr::Stability { interned } - pub fn node_extent(self, n: ast::NodeId) -> CodeExtent<'gcx> { - self.intern_code_extent(CodeExtentData::Misc(n)) - } - - pub fn call_site_extent(self, fn_id: ast::NodeId) -> CodeExtent<'gcx> { - self.intern_code_extent(CodeExtentData::CallSiteScope( - self.hir.body_owned_by(fn_id))) - } - - pub fn parameter_extent(self, fn_id: ast::NodeId) -> CodeExtent<'gcx> { - self.intern_code_extent(CodeExtentData::ParameterScope( - self.hir.body_owned_by(fn_id))) - } - - pub fn intern_code_extent(self, data: CodeExtentData) -> CodeExtent<'gcx> { - if let Some(st) = self.code_extent_interner.borrow().get(&data) { - return st; - } - - let interned = self.global_interners.arena.alloc(data); - if let Some(prev) = self.code_extent_interner.borrow_mut().replace(interned) { - bug!("Tried to overwrite interned code-extent: {:?}", prev) - } - interned - } - pub fn intern_layout(self, layout: Layout) -> &'gcx Layout { if let Some(layout) = self.layout_interner.borrow().get(&layout) { return layout; @@ -764,7 +735,6 @@ pub fn create_and_enter(s: &'tcx Session, data_layout: data_layout, layout_cache: RefCell::new(FxHashMap()), layout_interner: RefCell::new(FxHashSet()), - code_extent_interner: RefCell::new(FxHashSet()), layout_depth: Cell::new(0), derive_macros: RefCell::new(NodeMap()), stability_interner: RefCell::new(FxHashSet()), @@ -1106,8 +1076,8 @@ fn borrow<'a>(&'a self) -> &'a [Kind<'lcx>] { } } -impl<'tcx> Borrow> for Interned<'tcx, RegionKind<'tcx>> { - fn borrow<'a>(&'a self) -> &'a RegionKind<'tcx> { +impl<'tcx> Borrow for Interned<'tcx, RegionKind> { + fn borrow<'a>(&'a self) -> &'a RegionKind { &self.0 } } @@ -1206,7 +1176,7 @@ fn keep_local<'tcx, T: ty::TypeFoldable<'tcx>>(x: &T) -> bool { &ty::ReVar(_) | &ty::ReSkolemized(..) => true, _ => false } - }) -> RegionKind<'tcx> + }) -> RegionKind ); macro_rules! slice_interners { diff --git a/src/librustc/ty/fold.rs b/src/librustc/ty/fold.rs index 6820b9af940..6de3c018bda 100644 --- a/src/librustc/ty/fold.rs +++ b/src/librustc/ty/fold.rs @@ -536,7 +536,7 @@ fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> { // regions. See comment on `shift_regions_through_binders` method in // `subst.rs` for more details. -pub fn shift_region<'tcx>(region: ty::RegionKind<'tcx>, amount: u32) -> ty::RegionKind<'tcx> { +pub fn shift_region(region: ty::RegionKind, amount: u32) -> ty::RegionKind { match region { ty::ReLateBound(debruijn, br) => { ty::ReLateBound(debruijn.shifted(amount), br) diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index 3b5dc2ae164..1fd9e8f7375 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -801,7 +801,7 @@ fn default() -> Self { /// Per-function `RegionMaps`. The `DefId` should be the owner-def-id for the fn body; /// in the case of closures or "inline" expressions, this will be redirected to the enclosing /// fn item. - [] region_maps: RegionMaps(DefId) -> Rc>, + [] region_maps: RegionMaps(DefId) -> Rc, [] mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx mir::Mir<'tcx>, diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 51bd0b88bac..6ca401d27ac 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -24,6 +24,7 @@ use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem}; use middle::privacy::AccessLevels; use middle::resolve_lifetime::ObjectLifetimeDefault; +use middle::region::CodeExtent; use mir::Mir; use traits; use ty; @@ -2435,7 +2436,7 @@ pub fn parameter_environment(self, def_id: DefId) -> ParameterEnvironment<'gcx> } pub fn node_scope_region(self, id: NodeId) -> Region<'tcx> { - self.mk_region(ty::ReScope(self.node_extent(id))) + self.mk_region(ty::ReScope(CodeExtent::Misc(id))) } /// Looks up the span of `impl_did` if the impl is local; otherwise returns `Err` diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 4faefc0fca9..cfbf1244db3 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -684,7 +684,7 @@ pub struct DebruijnIndex { pub depth: u32, } -pub type Region<'tcx> = &'tcx RegionKind<'tcx>; +pub type Region<'tcx> = &'tcx RegionKind; /// Representation of regions. /// @@ -743,7 +743,7 @@ pub struct DebruijnIndex { /// [1] http://smallcultfollowing.com/babysteps/blog/2013/10/29/intermingled-parameter-lists/ /// [2] http://smallcultfollowing.com/babysteps/blog/2013/11/04/intermingled-parameter-lists/ #[derive(Clone, PartialEq, Eq, Hash, Copy, RustcEncodable, RustcDecodable)] -pub enum RegionKind<'tcx> { +pub enum RegionKind { // Region bound in a type or fn declaration which will be // substituted 'early' -- that is, at the same time when type // parameters are substituted. @@ -761,7 +761,7 @@ pub enum RegionKind<'tcx> { /// A concrete region naming some statically determined extent /// (e.g. an expression or sequence of statements) within the /// current function. - ReScope(region::CodeExtent<'tcx>), + ReScope(region::CodeExtent), /// Static data that has an "infinite" lifetime. Top in the region lattice. ReStatic, @@ -906,7 +906,7 @@ pub fn shifted(&self, amount: u32) -> DebruijnIndex { } /// Region utilities -impl<'tcx> RegionKind<'tcx> { +impl RegionKind { pub fn is_late_bound(&self) -> bool { match *self { ty::ReLateBound(..) => true, @@ -929,7 +929,7 @@ pub fn escapes_depth(&self, depth: u32) -> bool { } /// Returns the depth of `self` from the (1-based) binding level `depth` - pub fn from_depth(&self, depth: u32) -> RegionKind<'tcx> { + pub fn from_depth(&self, depth: u32) -> RegionKind { match *self { ty::ReLateBound(debruijn, r) => ty::ReLateBound(DebruijnIndex { depth: debruijn.depth - (depth - 1) diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 27cc5faaf20..8ca699339d3 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -458,7 +458,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { } } -impl<'tcx> fmt::Debug for ty::RegionKind<'tcx> { +impl fmt::Debug for ty::RegionKind { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { ty::ReEarlyBound(ref data) => { @@ -510,7 +510,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { } } -impl<'tcx> fmt::Display for ty::RegionKind<'tcx> { +impl<'tcx> fmt::Display for ty::RegionKind { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if verbose() { return write!(f, "{:?}", *self); diff --git a/src/librustc_borrowck/borrowck/check_loans.rs b/src/librustc_borrowck/borrowck/check_loans.rs index adabbe11f5e..eeb5a3fb957 100644 --- a/src/librustc_borrowck/borrowck/check_loans.rs +++ b/src/librustc_borrowck/borrowck/check_loans.rs @@ -232,7 +232,7 @@ pub fn each_issued_loan(&self, node: ast::NodeId, mut op: F) -> bool where }) } - pub fn each_in_scope_loan(&self, scope: region::CodeExtent<'tcx>, mut op: F) -> bool where + pub fn each_in_scope_loan(&self, scope: region::CodeExtent, mut op: F) -> bool where F: FnMut(&Loan<'tcx>) -> bool, { //! Like `each_issued_loan()`, but only considers loans that are @@ -248,7 +248,7 @@ pub fn each_in_scope_loan(&self, scope: region::CodeExtent<'tcx>, mut op: F) } fn each_in_scope_loan_affecting_path(&self, - scope: region::CodeExtent<'tcx>, + scope: region::CodeExtent, loan_path: &LoanPath<'tcx>, mut op: F) -> bool where @@ -708,7 +708,7 @@ pub fn analyze_restrictions_on_use(&self, let mut ret = UseOk; self.each_in_scope_loan_affecting_path( - self.tcx().node_extent(expr_id), use_path, |loan| { + region::CodeExtent::Misc(expr_id), use_path, |loan| { if !compatible_borrow_kinds(loan.kind, borrow_kind) { ret = UseWhileBorrowed(loan.loan_path.clone(), loan.span); false @@ -822,7 +822,7 @@ fn check_assignment(&self, // Check that we don't invalidate any outstanding loans if let Some(loan_path) = opt_loan_path(&assignee_cmt) { - let scope = self.tcx().node_extent(assignment_id); + let scope = region::CodeExtent::Misc(assignment_id); self.each_in_scope_loan_affecting_path(scope, &loan_path, |loan| { self.report_illegal_mutation(assignment_span, &loan_path, loan); false diff --git a/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs b/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs index 12854d3c979..5fc5682a60b 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/lifetime.rs @@ -24,7 +24,7 @@ type R = Result<(),()>; pub fn guarantee_lifetime<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, - item_scope: region::CodeExtent<'tcx>, + item_scope: region::CodeExtent, span: Span, cause: euv::LoanCause, cmt: mc::cmt<'tcx>, @@ -52,7 +52,7 @@ struct GuaranteeLifetimeContext<'a, 'tcx: 'a> { bccx: &'a BorrowckCtxt<'a, 'tcx>, // the scope of the function body for the enclosing item - item_scope: region::CodeExtent<'tcx>, + item_scope: region::CodeExtent, span: Span, cause: euv::LoanCause, diff --git a/src/librustc_borrowck/borrowck/gather_loans/mod.rs b/src/librustc_borrowck/borrowck/gather_loans/mod.rs index cbb6f7bce50..4cfee36359c 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/mod.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/mod.rs @@ -45,7 +45,7 @@ pub fn gather_loans_in_fn<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, bccx: bccx, infcx: &infcx, all_loans: Vec::new(), - item_ub: bccx.tcx.node_extent(body.node_id), + item_ub: region::CodeExtent::Misc(body.node_id), move_data: MoveData::new(), move_error_collector: move_error::MoveErrorCollector::new(), }; @@ -66,7 +66,7 @@ struct GatherLoanCtxt<'a, 'tcx: 'a> { all_loans: Vec>, /// `item_ub` is used as an upper-bound on the lifetime whenever we /// ask for the scope of an expression categorized as an upvar. - item_ub: region::CodeExtent<'tcx>, + item_ub: region::CodeExtent, } impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> { @@ -376,7 +376,7 @@ fn guarantee_valid(&mut self, }; debug!("loan_scope = {:?}", loan_scope); - let borrow_scope = self.tcx().node_extent(borrow_id); + let borrow_scope = region::CodeExtent::Misc(borrow_id); let gen_scope = self.compute_gen_scope(borrow_scope, loan_scope); debug!("gen_scope = {:?}", gen_scope); @@ -455,9 +455,9 @@ pub fn mark_loan_path_as_mutated(&self, loan_path: &LoanPath) { } pub fn compute_gen_scope(&self, - borrow_scope: region::CodeExtent<'tcx>, - loan_scope: region::CodeExtent<'tcx>) - -> region::CodeExtent<'tcx> { + borrow_scope: region::CodeExtent, + loan_scope: region::CodeExtent) + -> region::CodeExtent { //! Determine when to introduce the loan. Typically the loan //! is introduced at the point of the borrow, but in some cases, //! notably method arguments, the loan may be introduced only @@ -470,8 +470,8 @@ pub fn compute_gen_scope(&self, } } - pub fn compute_kill_scope(&self, loan_scope: region::CodeExtent<'tcx>, lp: &LoanPath<'tcx>) - -> region::CodeExtent<'tcx> { + pub fn compute_kill_scope(&self, loan_scope: region::CodeExtent, lp: &LoanPath<'tcx>) + -> region::CodeExtent { //! Determine when the loan restrictions go out of scope. //! This is either when the lifetime expires or when the //! local variable which roots the loan-path goes out of scope, diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 07fd966f570..99df1431265 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -208,7 +208,7 @@ pub struct BorrowckCtxt<'a, 'tcx: 'a> { // Some in `borrowck_fn` and cleared later tables: &'a ty::TypeckTables<'tcx>, - region_maps: Rc>, + region_maps: Rc, owner_def_id: DefId, } @@ -228,13 +228,13 @@ pub struct Loan<'tcx> { /// cases, notably method arguments, the loan may be introduced /// only later, once it comes into scope. See also /// `GatherLoanCtxt::compute_gen_scope`. - gen_scope: region::CodeExtent<'tcx>, + gen_scope: region::CodeExtent, /// kill_scope indicates when the loan goes out of scope. This is /// either when the lifetime expires or when the local variable /// which roots the loan-path goes out of scope, whichever happens /// faster. See also `GatherLoanCtxt::compute_kill_scope`. - kill_scope: region::CodeExtent<'tcx>, + kill_scope: region::CodeExtent, span: Span, cause: euv::LoanCause, } @@ -334,12 +334,12 @@ pub fn closure_to_block(closure_id: ast::NodeId, } impl<'a, 'tcx> LoanPath<'tcx> { - pub fn kill_scope(&self, bccx: &BorrowckCtxt<'a, 'tcx>) -> region::CodeExtent<'tcx> { + pub fn kill_scope(&self, bccx: &BorrowckCtxt<'a, 'tcx>) -> region::CodeExtent { match self.kind { LpVar(local_id) => bccx.region_maps.var_scope(local_id), LpUpvar(upvar_id) => { let block_id = closure_to_block(upvar_id.closure_expr_id, bccx.tcx); - bccx.tcx.node_extent(block_id) + region::CodeExtent::Misc(block_id) } LpDowncast(ref base, _) | LpExtend(ref base, ..) => base.kill_scope(bccx), diff --git a/src/librustc_const_eval/check_match.rs b/src/librustc_const_eval/check_match.rs index a3dab6a938d..a18f91a9ee3 100644 --- a/src/librustc_const_eval/check_match.rs +++ b/src/librustc_const_eval/check_match.rs @@ -70,7 +70,7 @@ struct MatchVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, tables: &'a ty::TypeckTables<'tcx>, param_env: &'a ty::ParameterEnvironment<'tcx>, - region_maps: &'a RegionMaps<'tcx>, + region_maps: &'a RegionMaps, } impl<'a, 'tcx> Visitor<'tcx> for MatchVisitor<'a, 'tcx> { diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index 1de6749200f..e2cbc480715 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -17,7 +17,6 @@ use rustc::middle::lang_items; use rustc::middle::free_region::FreeRegionMap; use rustc::middle::region::{CodeExtent, RegionMaps}; -use rustc::middle::region::CodeExtentData; use rustc::middle::resolve_lifetime; use rustc::middle::stability; use rustc::ty::subst::{Kind, Subst}; @@ -45,7 +44,7 @@ struct Env<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { infcx: &'a infer::InferCtxt<'a, 'gcx, 'tcx>, - region_maps: &'a mut RegionMaps<'tcx>, + region_maps: &'a mut RegionMaps, } struct RH<'a> { @@ -168,8 +167,8 @@ pub fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> { self.infcx.tcx } - pub fn create_region_hierarchy(&mut self, rh: &RH, parent: CodeExtent<'tcx>) { - let me = self.tcx().intern_code_extent(CodeExtentData::Misc(rh.id)); + pub fn create_region_hierarchy(&mut self, rh: &RH, parent: CodeExtent) { + let me = CodeExtent::Misc(rh.id); self.region_maps.record_code_extent(me, Some(parent)); for child_rh in rh.sub { self.create_region_hierarchy(child_rh, me); @@ -181,7 +180,7 @@ pub fn create_simple_region_hierarchy(&mut self) { // children of 1, etc let node = ast::NodeId::from_u32; - let dscope = self.tcx().intern_code_extent(CodeExtentData::DestructionScope(node(1))); + let dscope = CodeExtent::DestructionScope(node(1)); self.region_maps.record_code_extent(dscope, None); self.create_region_hierarchy(&RH { id: node(1), @@ -327,7 +326,7 @@ pub fn t_rptr_late_bound_with_debruijn(&self, } pub fn t_rptr_scope(&self, id: u32) -> Ty<'tcx> { - let r = ty::ReScope(self.tcx().node_extent(ast::NodeId::from_u32(id))); + let r = ty::ReScope(CodeExtent::Misc(ast::NodeId::from_u32(id))); self.infcx.tcx.mk_imm_ref(self.infcx.tcx.mk_region(r), self.tcx().types.isize) } diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index ea845f722c3..819095e2628 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -21,7 +21,6 @@ use rustc::hir::def::{self, Def, CtorKind}; use rustc::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc::middle::lang_items; -use rustc::middle::region; use rustc::session::Session; use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::subst::Substs; @@ -360,12 +359,6 @@ fn specialized_decode(&mut self) -> Result, Self::Error> { } } -impl<'a, 'tcx> SpecializedDecoder> for DecodeContext<'a, 'tcx> { - fn specialized_decode(&mut self) -> Result, Self::Error> { - Ok(self.tcx().intern_code_extent(Decodable::decode(self)?)) - } -} - impl<'a, 'tcx> SpecializedDecoder<&'tcx ty::Slice>> for DecodeContext<'a, 'tcx> { fn specialized_decode(&mut self) -> Result<&'tcx ty::Slice>, Self::Error> { Ok(self.tcx().mk_type_list((0..self.read_usize()?).map(|_| Decodable::decode(self)))?) diff --git a/src/librustc_mir/build/expr/as_operand.rs b/src/librustc_mir/build/expr/as_operand.rs index f7534737edc..a3680214432 100644 --- a/src/librustc_mir/build/expr/as_operand.rs +++ b/src/librustc_mir/build/expr/as_operand.rs @@ -39,7 +39,7 @@ pub fn as_local_operand(&mut self, block: BasicBlock, expr: M) /// The operand is known to be live until the end of `scope`. pub fn as_operand(&mut self, block: BasicBlock, - scope: Option>, + scope: Option, expr: M) -> BlockAnd> where M: Mirror<'tcx, Output = Expr<'tcx>> { @@ -49,7 +49,7 @@ pub fn as_operand(&mut self, fn expr_as_operand(&mut self, mut block: BasicBlock, - scope: Option>, + scope: Option, expr: Expr<'tcx>) -> BlockAnd> { debug!("expr_as_operand(block={:?}, expr={:?})", block, expr); diff --git a/src/librustc_mir/build/expr/as_rvalue.rs b/src/librustc_mir/build/expr/as_rvalue.rs index 46e2408c38d..7b29cd970d7 100644 --- a/src/librustc_mir/build/expr/as_rvalue.rs +++ b/src/librustc_mir/build/expr/as_rvalue.rs @@ -38,7 +38,7 @@ pub fn as_local_rvalue(&mut self, block: BasicBlock, expr: M) } /// Compile `expr`, yielding an rvalue. - pub fn as_rvalue(&mut self, block: BasicBlock, scope: Option>, expr: M) + pub fn as_rvalue(&mut self, block: BasicBlock, scope: Option, expr: M) -> BlockAnd> where M: Mirror<'tcx, Output = Expr<'tcx>> { @@ -48,7 +48,7 @@ pub fn as_rvalue(&mut self, block: BasicBlock, scope: Option fn expr_as_rvalue(&mut self, mut block: BasicBlock, - scope: Option>, + scope: Option, expr: Expr<'tcx>) -> BlockAnd> { debug!("expr_as_rvalue(block={:?}, expr={:?})", block, expr); diff --git a/src/librustc_mir/build/expr/as_temp.rs b/src/librustc_mir/build/expr/as_temp.rs index db4561af734..a334923546f 100644 --- a/src/librustc_mir/build/expr/as_temp.rs +++ b/src/librustc_mir/build/expr/as_temp.rs @@ -21,7 +21,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { /// up rvalues so as to freeze the value that will be consumed. pub fn as_temp(&mut self, block: BasicBlock, - temp_lifetime: Option>, + temp_lifetime: Option, expr: M) -> BlockAnd> where M: Mirror<'tcx, Output = Expr<'tcx>> @@ -32,7 +32,7 @@ pub fn as_temp(&mut self, fn expr_as_temp(&mut self, mut block: BasicBlock, - temp_lifetime: Option>, + temp_lifetime: Option, expr: Expr<'tcx>) -> BlockAnd> { debug!("expr_as_temp(block={:?}, expr={:?})", block, expr); diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index a3b1b24f20a..fb173e2487b 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -338,8 +338,8 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>, let span = tcx.hir.span(fn_id); let mut builder = Builder::new(hir.clone(), span, arguments.len(), return_ty); - let call_site_extent = tcx.call_site_extent(fn_id); - let arg_extent = tcx.parameter_extent(fn_id); + let call_site_extent = CodeExtent::CallSiteScope(body.id()); + let arg_extent = CodeExtent::ParameterScope(body.id()); let mut block = START_BLOCK; unpack!(block = builder.in_scope(call_site_extent, block, |builder| { unpack!(block = builder.in_scope(arg_extent, block, |builder| { @@ -480,7 +480,7 @@ fn finish(self, fn args_and_body(&mut self, mut block: BasicBlock, arguments: &[(Ty<'gcx>, Option<&'gcx hir::Pat>)], - argument_extent: CodeExtent<'tcx>, + argument_extent: CodeExtent, ast_body: &'gcx hir::Expr) -> BlockAnd<()> { diff --git a/src/librustc_mir/build/scope.rs b/src/librustc_mir/build/scope.rs index 56ce4727d5f..ae47f4c4244 100644 --- a/src/librustc_mir/build/scope.rs +++ b/src/librustc_mir/build/scope.rs @@ -87,7 +87,7 @@ */ use build::{BlockAnd, BlockAndExtension, Builder, CFG}; -use rustc::middle::region::{CodeExtent, CodeExtentData}; +use rustc::middle::region::CodeExtent; use rustc::middle::lang_items; use rustc::middle::const_val::ConstVal; use rustc::ty::subst::{Kind, Subst}; @@ -102,7 +102,7 @@ pub struct Scope<'tcx> { visibility_scope: VisibilityScope, /// the extent of this scope within source code. - extent: CodeExtent<'tcx>, + extent: CodeExtent, /// Whether there's anything to do for the cleanup path, that is, /// when unwinding through this scope. This includes destructors, @@ -137,7 +137,7 @@ pub struct Scope<'tcx> { free: Option>, /// The cache for drop chain on “normal” exit into a particular BasicBlock. - cached_exits: FxHashMap<(BasicBlock, CodeExtent<'tcx>), BasicBlock>, + cached_exits: FxHashMap<(BasicBlock, CodeExtent), BasicBlock>, } struct DropData<'tcx> { @@ -180,7 +180,7 @@ struct FreeData<'tcx> { #[derive(Clone, Debug)] pub struct BreakableScope<'tcx> { /// Extent of the loop - pub extent: CodeExtent<'tcx>, + pub extent: CodeExtent, /// Where the body of the loop begins. `None` if block pub continue_block: Option, /// Block to branch into when the loop or block terminates (either by being `break`-en out @@ -271,7 +271,7 @@ pub fn in_breakable_scope(&mut self, /// Convenience wrapper that pushes a scope and then executes `f` /// to build its contents, popping the scope afterwards. pub fn in_scope(&mut self, - extent: CodeExtent<'tcx>, + extent: CodeExtent, mut block: BasicBlock, f: F) -> BlockAnd @@ -289,7 +289,7 @@ pub fn in_scope(&mut self, /// scope and call `pop_scope` afterwards. Note that these two /// calls must be paired; using `in_scope` as a convenience /// wrapper maybe preferable. - pub fn push_scope(&mut self, extent: CodeExtent<'tcx>) { + pub fn push_scope(&mut self, extent: CodeExtent) { debug!("push_scope({:?})", extent); let vis_scope = self.visibility_scope; self.scopes.push(Scope { @@ -306,7 +306,7 @@ pub fn push_scope(&mut self, extent: CodeExtent<'tcx>) { /// drops onto the end of `block` that are needed. This must /// match 1-to-1 with `push_scope`. pub fn pop_scope(&mut self, - extent: CodeExtent<'tcx>, + extent: CodeExtent, mut block: BasicBlock) -> BlockAnd<()> { debug!("pop_scope({:?}, {:?})", extent, block); @@ -330,7 +330,7 @@ pub fn pop_scope(&mut self, /// module comment for details. pub fn exit_scope(&mut self, span: Span, - extent: CodeExtent<'tcx>, + extent: CodeExtent, mut block: BasicBlock, target: BasicBlock) { debug!("exit_scope(extent={:?}, block={:?}, target={:?})", extent, block, target); @@ -391,7 +391,7 @@ pub fn new_visibility_scope(&mut self, span: Span) -> VisibilityScope { /// resolving `break` and `continue`. pub fn find_breakable_scope(&mut self, span: Span, - label: CodeExtent<'tcx>) + label: CodeExtent) -> &mut BreakableScope<'tcx> { // find the loop-scope with the correct id self.breakable_scopes.iter_mut() @@ -411,12 +411,12 @@ pub fn source_info(&self, span: Span) -> SourceInfo { /// Returns the extent of the scope which should be exited by a /// return. - pub fn extent_of_return_scope(&self) -> CodeExtent<'tcx> { + pub fn extent_of_return_scope(&self) -> CodeExtent { // The outermost scope (`scopes[0]`) will be the `CallSiteScope`. // We want `scopes[1]`, which is the `ParameterScope`. assert!(self.scopes.len() >= 2); - assert!(match *self.scopes[1].extent { - CodeExtentData::ParameterScope(_) => true, + assert!(match self.scopes[1].extent { + CodeExtent::ParameterScope(_) => true, _ => false, }); self.scopes[1].extent @@ -424,7 +424,7 @@ pub fn extent_of_return_scope(&self) -> CodeExtent<'tcx> { /// Returns the topmost active scope, which is known to be alive until /// the next scope expression. - pub fn topmost_scope(&self) -> CodeExtent<'tcx> { + pub fn topmost_scope(&self) -> CodeExtent { self.scopes.last().expect("topmost_scope: no scopes present").extent } @@ -434,7 +434,7 @@ pub fn topmost_scope(&self) -> CodeExtent<'tcx> { /// `extent`. pub fn schedule_drop(&mut self, span: Span, - extent: CodeExtent<'tcx>, + extent: CodeExtent, lvalue: &Lvalue<'tcx>, lvalue_ty: Ty<'tcx>) { let needs_drop = self.hir.needs_drop(lvalue_ty); @@ -524,7 +524,7 @@ pub fn schedule_drop(&mut self, /// There may only be one “free” scheduled in any given scope. pub fn schedule_box_free(&mut self, span: Span, - extent: CodeExtent<'tcx>, + extent: CodeExtent, value: &Lvalue<'tcx>, item_ty: Ty<'tcx>) { for scope in self.scopes.iter_mut().rev() { diff --git a/src/librustc_mir/hair/cx/block.rs b/src/librustc_mir/hair/cx/block.rs index 2ec4a8a07df..920da306116 100644 --- a/src/librustc_mir/hair/cx/block.rs +++ b/src/librustc_mir/hair/cx/block.rs @@ -11,7 +11,7 @@ use hair::*; use hair::cx::Cx; use hair::cx::to_ref::ToRef; -use rustc::middle::region::{BlockRemainder, CodeExtentData}; +use rustc::middle::region::{BlockRemainder, CodeExtent}; use rustc::hir; use syntax::ast; @@ -24,7 +24,7 @@ fn make_mirror<'a, 'gcx>(self, cx: &mut Cx<'a, 'gcx, 'tcx>) -> Block<'tcx> { let stmts = mirror_stmts(cx, self.id, &*self.stmts); Block { targeted_by_break: self.targeted_by_break, - extent: cx.tcx.node_extent(self.id), + extent: CodeExtent::Misc(self.id), span: self.span, stmts: stmts, expr: self.expr.to_ref(), @@ -44,7 +44,7 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, result.push(StmtRef::Mirror(Box::new(Stmt { span: stmt.span, kind: StmtKind::Expr { - scope: cx.tcx.node_extent(id), + scope: CodeExtent::Misc(id), expr: expr.to_ref(), }, }))) @@ -55,19 +55,17 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, // ignore for purposes of the MIR } hir::DeclLocal(ref local) => { - let remainder_extent = CodeExtentData::Remainder(BlockRemainder { + let remainder_extent = CodeExtent::Remainder(BlockRemainder { block: block_id, first_statement_index: index as u32, }); - let remainder_extent = - cx.tcx.intern_code_extent(remainder_extent); let pattern = Pattern::from_hir(cx.tcx, cx.tables(), &local.pat); result.push(StmtRef::Mirror(Box::new(Stmt { span: stmt.span, kind: StmtKind::Let { remainder_scope: remainder_extent, - init_scope: cx.tcx.node_extent(id), + init_scope: CodeExtent::Misc(id), pattern: pattern, initializer: local.init.to_ref(), }, @@ -84,7 +82,7 @@ pub fn to_expr_ref<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, block: &'tcx hir::Block) -> ExprRef<'tcx> { let block_ty = cx.tables().node_id_to_type(block.id); - let (temp_lifetime, was_shrunk) = cx.region_maps.temporary_scope2(cx.tcx, block.id); + let (temp_lifetime, was_shrunk) = cx.region_maps.temporary_scope2(block.id); let expr = Expr { ty: block_ty, temp_lifetime: temp_lifetime, diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index a692e987761..b180d982e86 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -25,8 +25,8 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr { type Output = Expr<'tcx>; fn make_mirror<'a, 'gcx>(self, cx: &mut Cx<'a, 'gcx, 'tcx>) -> Expr<'tcx> { - let (temp_lifetime, was_shrunk) = cx.region_maps.temporary_scope2(cx.tcx, self.id); - let expr_extent = cx.tcx.node_extent(self.id); + let (temp_lifetime, was_shrunk) = cx.region_maps.temporary_scope2(self.id); + let expr_extent = CodeExtent::Misc(self.id); debug!("Expr::make_mirror(): id={}, span={:?}", self.id, self.span); @@ -237,7 +237,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, expr: &'tcx hir::Expr) -> Expr<'tcx> { let expr_ty = cx.tables().expr_ty(expr); - let (temp_lifetime, was_shrunk) = cx.region_maps.temporary_scope2(cx.tcx, expr.id); + let (temp_lifetime, was_shrunk) = cx.region_maps.temporary_scope2(expr.id); let kind = match expr.node { // Here comes the interesting stuff: @@ -609,7 +609,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, match dest.target_id { hir::ScopeTarget::Block(target_id) | hir::ScopeTarget::Loop(hir::LoopIdResult::Ok(target_id)) => ExprKind::Break { - label: cx.tcx.node_extent(target_id), + label: CodeExtent::Misc(target_id), value: value.to_ref(), }, hir::ScopeTarget::Loop(hir::LoopIdResult::Err(err)) => @@ -620,7 +620,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, match dest.target_id { hir::ScopeTarget::Block(_) => bug!("cannot continue to blocks"), hir::ScopeTarget::Loop(hir::LoopIdResult::Ok(loop_id)) => ExprKind::Continue { - label: cx.tcx.node_extent(loop_id), + label: CodeExtent::Misc(loop_id), }, hir::ScopeTarget::Loop(hir::LoopIdResult::Err(err)) => bug!("invalid loop id for continue: {}", err) @@ -685,7 +685,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, hir::ExprBox(ref value) => { ExprKind::Box { value: value.to_ref(), - value_extents: cx.tcx.node_extent(value.id), + value_extents: CodeExtent::Misc(value.id), } } hir::ExprArray(ref fields) => ExprKind::Array { fields: fields.to_ref() }, @@ -706,7 +706,7 @@ fn method_callee<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, method_call: ty::MethodCall) -> Expr<'tcx> { let callee = cx.tables().method_map[&method_call]; - let (temp_lifetime, was_shrunk) = cx.region_maps.temporary_scope2(cx.tcx, expr.id); + let (temp_lifetime, was_shrunk) = cx.region_maps.temporary_scope2(expr.id); Expr { temp_lifetime: temp_lifetime, temp_lifetime_was_shrunk: was_shrunk, @@ -790,7 +790,7 @@ fn convert_var<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, expr: &'tcx hir::Expr, def: Def) -> ExprKind<'tcx> { - let (temp_lifetime, was_shrunk) = cx.region_maps.temporary_scope2(cx.tcx, expr.id); + let (temp_lifetime, was_shrunk) = cx.region_maps.temporary_scope2(expr.id); match def { Def::Local(def_id) => { @@ -965,7 +965,7 @@ fn overloaded_operator<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, PassArgs::ByRef => { let region = cx.tcx.node_scope_region(expr.id); let (temp_lifetime, was_shrunk) = - cx.region_maps.temporary_scope2(cx.tcx, expr.id); + cx.region_maps.temporary_scope2(expr.id); argrefs.extend(args.iter() .map(|arg| { let arg_ty = cx.tables().expr_ty_adjusted(arg); @@ -1017,7 +1017,7 @@ fn overloaded_lvalue<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, // construct the complete expression `foo()` for the overloaded call, // which will yield the &T type - let (temp_lifetime, was_shrunk) = cx.region_maps.temporary_scope2(cx.tcx, expr.id); + let (temp_lifetime, was_shrunk) = cx.region_maps.temporary_scope2(expr.id); let ref_kind = overloaded_operator(cx, expr, method_call, pass_args, receiver, args); let ref_expr = Expr { temp_lifetime: temp_lifetime, @@ -1042,7 +1042,7 @@ fn capture_freevar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, closure_expr_id: closure_expr.id, }; let upvar_capture = cx.tables().upvar_capture(upvar_id).unwrap(); - let (temp_lifetime, was_shrunk) = cx.region_maps.temporary_scope2(cx.tcx, closure_expr.id); + let (temp_lifetime, was_shrunk) = cx.region_maps.temporary_scope2(closure_expr.id); let var_ty = cx.tables().node_id_to_type(id_var); let captured_var = Expr { temp_lifetime: temp_lifetime, diff --git a/src/librustc_mir/hair/cx/mod.rs b/src/librustc_mir/hair/cx/mod.rs index ee8547e5dd6..9ffce18fe15 100644 --- a/src/librustc_mir/hair/cx/mod.rs +++ b/src/librustc_mir/hair/cx/mod.rs @@ -35,7 +35,7 @@ pub struct Cx<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { tcx: TyCtxt<'a, 'gcx, 'tcx>, infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, - pub region_maps: Rc>, + pub region_maps: Rc, constness: hir::Constness, /// True if this constant/function needs overflow checks. diff --git a/src/librustc_mir/hair/mod.rs b/src/librustc_mir/hair/mod.rs index 0e8992e62ea..1af9d722599 100644 --- a/src/librustc_mir/hair/mod.rs +++ b/src/librustc_mir/hair/mod.rs @@ -32,7 +32,7 @@ #[derive(Clone, Debug)] pub struct Block<'tcx> { pub targeted_by_break: bool, - pub extent: CodeExtent<'tcx>, + pub extent: CodeExtent, pub span: Span, pub stmts: Vec>, pub expr: Option>, @@ -53,7 +53,7 @@ pub struct Stmt<'tcx> { pub enum StmtKind<'tcx> { Expr { /// scope for this statement; may be used as lifetime of temporaries - scope: CodeExtent<'tcx>, + scope: CodeExtent, /// expression being evaluated in this statement expr: ExprRef<'tcx>, @@ -62,11 +62,11 @@ pub enum StmtKind<'tcx> { Let { /// scope for variables bound in this let; covers this and /// remaining statements in block - remainder_scope: CodeExtent<'tcx>, + remainder_scope: CodeExtent, /// scope for the initialization itself; might be used as /// lifetime of temporaries - init_scope: CodeExtent<'tcx>, + init_scope: CodeExtent, /// let = ... pattern: Pattern<'tcx>, @@ -97,7 +97,7 @@ pub struct Expr<'tcx> { /// lifetime of this expression if it should be spilled into a /// temporary; should be None only if in a constant context - pub temp_lifetime: Option>, + pub temp_lifetime: Option, /// whether this temp lifetime was shrunk by #36082. pub temp_lifetime_was_shrunk: bool, @@ -112,12 +112,12 @@ pub struct Expr<'tcx> { #[derive(Clone, Debug)] pub enum ExprKind<'tcx> { Scope { - extent: CodeExtent<'tcx>, + extent: CodeExtent, value: ExprRef<'tcx>, }, Box { value: ExprRef<'tcx>, - value_extents: CodeExtent<'tcx>, + value_extents: CodeExtent, }, Call { ty: ty::Ty<'tcx>, @@ -210,11 +210,11 @@ pub enum ExprKind<'tcx> { arg: ExprRef<'tcx>, }, Break { - label: CodeExtent<'tcx>, + label: CodeExtent, value: Option>, }, Continue { - label: CodeExtent<'tcx>, + label: CodeExtent, }, Return { value: Option>, diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index 8e3329e2720..e0293325596 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -270,7 +270,7 @@ pub fn check_safety_of_destructor_if_necessary<'a, 'gcx, 'tcx>( rcx: &mut RegionCtxt<'a, 'gcx, 'tcx>, ty: ty::Ty<'tcx>, span: Span, - scope: region::CodeExtent<'tcx>) + scope: region::CodeExtent) -> Result<(), ErrorReported> { debug!("check_safety_of_destructor_if_necessary typ: {:?} scope: {:?}", diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 3755dfd3f40..70d2867c08c 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -88,6 +88,7 @@ use rustc_back::slice::ref_slice; use rustc::infer::{self, InferCtxt, InferOk, RegionVariableOrigin}; use rustc::infer::type_variable::{TypeVariableOrigin}; +use rustc::middle::region::CodeExtent; use rustc::ty::subst::{Kind, Subst, Substs}; use rustc::traits::{self, FulfillmentContext, ObligationCause, ObligationCauseCode, Reveal}; use rustc::ty::{ParamTy, LvaluePreference, NoPreference, PreferMutLvalue}; @@ -560,12 +561,8 @@ fn new(infcx: InferCtxt<'a, 'gcx, 'tcx>, def_id: DefId) -> Self { let tcx = infcx.tcx; let item_id = tcx.hir.as_local_node_id(def_id); let body_id = item_id.and_then(|id| tcx.hir.maybe_body_owned_by(id)); - let implicit_region_bound = item_id.and_then(|id| { - if body_id.is_some() { - Some(tcx.mk_region(ty::ReScope(tcx.call_site_extent(id)))) - } else { - None - } + let implicit_region_bound = body_id.map(|body| { + tcx.mk_region(ty::ReScope(CodeExtent::CallSiteScope(body))) }); Inherited { diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 3da01764243..754bd288bfa 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -178,7 +178,7 @@ pub struct RegionCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { region_bound_pairs: Vec<(ty::Region<'tcx>, GenericKind<'tcx>)>, - pub region_maps: Rc>, + pub region_maps: Rc, free_region_map: FreeRegionMap<'tcx>, @@ -186,7 +186,7 @@ pub struct RegionCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { body_id: ast::NodeId, // call_site scope of innermost fn - call_site_scope: Option>, + call_site_scope: Option, // id of innermost fn or loop repeating_scope: ast::NodeId, @@ -224,8 +224,8 @@ pub fn new(fcx: &'a FnCtxt<'a, 'gcx, 'tcx>, } } - fn set_call_site_scope(&mut self, call_site_scope: Option>) - -> Option> { + fn set_call_site_scope(&mut self, call_site_scope: Option) + -> Option { mem::replace(&mut self.call_site_scope, call_site_scope) } @@ -286,7 +286,7 @@ fn visit_fn_body(&mut self, let body_id = body.id(); - let call_site = self.tcx.call_site_extent(id); + let call_site = CodeExtent::CallSiteScope(body_id); let old_call_site_scope = self.set_call_site_scope(Some(call_site)); let fn_sig = { @@ -311,7 +311,7 @@ fn visit_fn_body(&mut self, let old_body_id = self.set_body_id(body_id.node_id); self.relate_free_regions(&fn_sig_tys[..], body_id.node_id, span); - self.link_fn_args(self.tcx.node_extent(body_id.node_id), &body.arguments); + self.link_fn_args(CodeExtent::Misc(body_id.node_id), &body.arguments); self.visit_body(body); self.visit_region_obligations(body_id.node_id); @@ -877,7 +877,7 @@ fn constrain_call<'b, I: Iterator>(&mut self, // call occurs. // // FIXME(#6268) to support nested method calls, should be callee_id - let callee_scope = self.tcx.node_extent(call_expr.id); + let callee_scope = CodeExtent::Misc(call_expr.id); let callee_region = self.tcx.mk_region(ty::ReScope(callee_scope)); debug!("callee_region={:?}", callee_region); @@ -1030,7 +1030,7 @@ fn constrain_index(&mut self, debug!("constrain_index(index_expr=?, indexed_ty={}", self.ty_to_string(indexed_ty)); - let r_index_expr = ty::ReScope(self.tcx.node_extent(index_expr.id)); + let r_index_expr = ty::ReScope(CodeExtent::Misc(index_expr.id)); if let ty::TyRef(r_ptr, mt) = indexed_ty.sty { match mt.ty.sty { ty::TySlice(_) | ty::TyStr => { @@ -1110,7 +1110,7 @@ fn link_match(&self, discr: &hir::Expr, arms: &[hir::Arm]) { /// Computes the guarantors for any ref bindings in a match and /// then ensures that the lifetime of the resulting pointer is /// linked to the lifetime of its guarantor (if any). - fn link_fn_args(&self, body_scope: CodeExtent<'tcx>, args: &[hir::Arg]) { + fn link_fn_args(&self, body_scope: CodeExtent, args: &[hir::Arg]) { debug!("regionck::link_fn_args(body_scope={:?})", body_scope); let mc = &mc::MemCategorizationContext::new(self, &self.region_maps); for arg in args { @@ -1176,7 +1176,7 @@ fn link_autoref(&self, /// must outlive `callee_scope`. fn link_by_ref(&self, expr: &hir::Expr, - callee_scope: CodeExtent<'tcx>) { + callee_scope: CodeExtent) { debug!("link_by_ref(expr={:?}, callee_scope={:?})", expr, callee_scope); let mc = mc::MemCategorizationContext::new(self, &self.region_maps); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 2dde6d9d4ee..61f941e57b2 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -820,7 +820,7 @@ fn clean(&self, _: &DocContext) -> Lifetime { } } -impl<'tcx> Clean> for ty::RegionKind<'tcx> { +impl Clean> for ty::RegionKind { fn clean(&self, cx: &DocContext) -> Option { match *self { ty::ReStatic => Some(Lifetime::statik()), -- 2.44.0