]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/region.rs
Instrument a bunch of tasks that employ the HIR map in one way or
[rust.git] / src / librustc / middle / region.rs
index c9f26ffe4163bffe7a1d6543e0e7d6ec7175d4e5..bf21b607b778d7f57dab82347ca0742dc520db36 100644 (file)
 //! region parameterized.
 //!
 //! Most of the documentation on regions can be found in
-//! `middle/typeck/infer/region_inference.rs`
+//! `middle/infer/region_inference/README.md`
 
+use dep_graph::DepNode;
 use front::map as ast_map;
 use session::Session;
 use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
 use middle::cstore::InlinedItem;
-use middle::ty::{self, Ty};
+use middle::ty;
 
 use std::cell::RefCell;
 use std::collections::hash_map::Entry;
@@ -125,6 +126,10 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 pub enum CodeExtentData {
     Misc(ast::NodeId),
 
+    // extent of the call-site for a function or closure (outlives
+    // the parameters as well as the body).
+    CallSiteScope { fn_id: ast::NodeId, body_id: ast::NodeId },
+
     // extent of parameters passed to a function or closure (they
     // outlive its body)
     ParameterScope { fn_id: ast::NodeId, body_id: ast::NodeId },
@@ -136,20 +141,20 @@ pub enum CodeExtentData {
     Remainder(BlockRemainder)
 }
 
-/// extent of destructors for temporaries of node-id
+/// extent of call-site for a function/method.
 #[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, RustcEncodable,
            RustcDecodable, Debug, Copy)]
-pub struct DestructionScopeData {
-    pub node_id: ast::NodeId
+pub struct CallSiteScopeData {
+    pub fn_id: ast::NodeId, pub body_id: ast::NodeId,
 }
 
-impl DestructionScopeData {
-    pub fn new(node_id: ast::NodeId) -> DestructionScopeData {
-        DestructionScopeData { node_id: node_id }
-    }
+impl CallSiteScopeData {
     pub fn to_code_extent(&self, region_maps: &RegionMaps) -> CodeExtent {
         region_maps.lookup_code_extent(
-            CodeExtentData::DestructionScope(self.node_id))
+            match *self {
+                CallSiteScopeData { fn_id, body_id } =>
+                    CodeExtentData::CallSiteScope { fn_id: fn_id, body_id: body_id },
+            })
     }
 }
 
@@ -190,6 +195,7 @@ pub fn node_id(&self) -> ast::NodeId {
             // precise extent denoted by `self`.
             CodeExtentData::Remainder(br) => br.block,
             CodeExtentData::DestructionScope(node_id) => node_id,
+            CodeExtentData::CallSiteScope { fn_id: _, body_id } |
             CodeExtentData::ParameterScope { fn_id: _, body_id } => body_id,
         }
     }
@@ -215,6 +221,7 @@ pub fn span(&self, region_maps: &RegionMaps, ast_map: &ast_map::Map) -> Option<S
         match ast_map.find(self.node_id(region_maps)) {
             Some(ast_map::NodeBlock(ref blk)) => {
                 match region_maps.code_extent_data(*self) {
+                    CodeExtentData::CallSiteScope { .. } |
                     CodeExtentData::ParameterScope { .. } |
                     CodeExtentData::Misc(_) |
                     CodeExtentData::DestructionScope(_) => Some(blk.span),
@@ -346,6 +353,10 @@ pub fn node_extent(&self, n: ast::NodeId) -> CodeExtent {
     pub fn item_extent(&self, n: ast::NodeId) -> CodeExtent {
         self.lookup_code_extent(CodeExtentData::DestructionScope(n))
     }
+    pub fn call_site_extent(&self, fn_id: ast::NodeId, body_id: ast::NodeId) -> CodeExtent {
+        assert!(fn_id != body_id);
+        self.lookup_code_extent(CodeExtentData::CallSiteScope { fn_id: fn_id, body_id: body_id })
+    }
     pub fn opt_destruction_extent(&self, n: ast::NodeId) -> Option<CodeExtent> {
         self.code_extent_interner.borrow().get(&CodeExtentData::DestructionScope(n)).cloned()
     }
@@ -1101,6 +1112,9 @@ fn resolve_fn(visitor: &mut RegionResolutionVisitor,
            body.id,
            visitor.cx.parent);
 
+    visitor.cx.parent = visitor.new_code_extent(
+        CodeExtentData::CallSiteScope { fn_id: id, body_id: body.id });
+
     let fn_decl_scope = visitor.new_code_extent(
         CodeExtentData::ParameterScope { fn_id: id, body_id: body.id });
 
@@ -1211,7 +1225,10 @@ fn visit_local(&mut self, l: &Local) {
     }
 }
 
-pub fn resolve_crate(sess: &Session, krate: &hir::Crate) -> RegionMaps {
+pub fn resolve_crate(sess: &Session, map: &ast_map::Map) -> RegionMaps {
+    let _task = map.dep_graph.in_task(DepNode::RegionResolveCrate);
+    let krate = map.krate();
+
     let maps = RegionMaps {
         code_extents: RefCell::new(vec![]),
         code_extent_interner: RefCell::new(FnvHashMap()),