]> git.lizzy.rs Git - rust.git/commitdiff
push `borrowck` into its own task
authorNiko Matsakis <niko@alum.mit.edu>
Tue, 4 Apr 2017 16:06:35 +0000 (12:06 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Tue, 4 Apr 2017 16:06:35 +0000 (12:06 -0400)
src/librustc/hir/map/mod.rs
src/librustc/ty/maps.rs
src/librustc_borrowck/borrowck/mod.rs
src/librustc_borrowck/lib.rs
src/librustc_driver/driver.rs

index d7aa36b24f94279ba345399f7276a1e6fe609fff..cfafec00ae20def83507206f4855bc71b0a4cc53 100644 (file)
@@ -442,6 +442,27 @@ pub fn body_owner_def_id(&self, id: BodyId) -> DefId {
         self.local_def_id(self.body_owner(id))
     }
 
+    /// Given a body owner's id, returns the `BodyId` associated with it.
+    pub fn body_owned_by(&self, id: NodeId) -> BodyId {
+        if let Some(entry) = self.find_entry(id) {
+            if let Some(body_id) = entry.associated_body() {
+                // For item-like things and closures, the associated
+                // body has its own distinct id, and that is returned
+                // by `associated_body`.
+                body_id
+            } else {
+                // For some expressions, the expression is its own body.
+                if let EntryExpr(_, expr) = entry {
+                    BodyId { node_id: expr.id }
+                } else {
+                    span_bug!(self.span(id), "id `{}` has no associated body", id);
+                }
+            }
+        } else {
+            bug!("no entry for id `{}`", id)
+        }
+    }
+
     pub fn ty_param_owner(&self, id: NodeId) -> NodeId {
         match self.get(id) {
             NodeItem(&Item { node: ItemTrait(..), .. }) => id,
index 4a183191cef29c70c82920b26f1873cf04e37c73..219dbc4998e04343277bcbc6377bd45af72da3df 100644 (file)
@@ -423,6 +423,8 @@ fn default() -> Self {
 
     pub coherent_trait: coherent_trait_dep_node((CrateNum, DefId)) -> (),
 
+    pub borrowck: BorrowCheck(DefId) -> (),
+
     /// Gets a complete map from all types to their inherent impls.
     /// Not meant to be used directly outside of coherence.
     /// (Defined only for LOCAL_CRATE)
index 0915c57b588eb1a7c2c33b091682fd4fce4790e7..e0b4a23010d2f7391e2484633aaed4686d5d8665 100644 (file)
@@ -22,7 +22,6 @@
 
 use self::InteriorKind::*;
 
-use rustc::dep_graph::DepNode;
 use rustc::hir::map as hir_map;
 use rustc::hir::map::blocks::FnLikeNode;
 use rustc::cfg;
 use rustc::middle::mem_categorization::ImmutabilityBlame;
 use rustc::middle::region;
 use rustc::ty::{self, TyCtxt};
+use rustc::ty::maps::Providers;
 
 use std::fmt;
 use std::rc::Rc;
 use std::hash::{Hash, Hasher};
 use syntax::ast;
-use syntax_pos::{MultiSpan, Span};
+use syntax_pos::{DUMMY_SP, MultiSpan, Span};
 use errors::DiagnosticBuilder;
 
 use rustc::hir;
 pub type LoanDataFlow<'a, 'tcx> = DataFlowContext<'a, 'tcx, LoanDataFlowOperator>;
 
 pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
-    tcx.dep_graph.with_task(DepNode::BorrowCheckKrate, tcx, (), check_crate_task);
-
-    fn check_crate_task<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, (): ()) {
-        tcx.visit_all_bodies_in_krate(|body_owner_def_id, body_id| {
-            tcx.dep_graph.with_task(DepNode::BorrowCheck(body_owner_def_id),
-                                    tcx,
-                                    body_id,
-                                    borrowck_fn);
-        });
-    }
+    tcx.visit_all_bodies_in_krate(|body_owner_def_id, _body_id| {
+        ty::queries::borrowck::get(tcx, DUMMY_SP, body_owner_def_id);
+    });
+}
+
+pub fn provide(providers: &mut Providers) {
+    *providers = Providers {
+        borrowck: borrowck,
+        ..*providers
+    };
 }
 
 /// Collection of conclusions determined via borrow checker analyses.
@@ -81,11 +81,11 @@ pub struct AnalysisData<'a, 'tcx: 'a> {
     pub move_data: move_data::FlowedMoveData<'a, 'tcx>,
 }
 
-fn borrowck_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, body_id: hir::BodyId) {
-    debug!("borrowck_fn(body_id={:?})", body_id);
+fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId) {
+    debug!("borrowck(body_owner_def_id={:?})", owner_def_id);
 
-    let owner_id = tcx.hir.body_owner(body_id);
-    let owner_def_id = tcx.hir.local_def_id(owner_id);
+    let owner_id = tcx.hir.as_local_node_id(owner_def_id).unwrap();
+    let body_id = tcx.hir.body_owned_by(owner_id);
     let attributes = tcx.get_attrs(owner_def_id);
     let tables = tcx.item_tables(owner_def_id);
 
index d3b22884a3d8c037e6b67c4adfc3636d121e27fc..a1d3357faf56684931ee9e2899c59e93bb665555 100644 (file)
@@ -51,4 +51,6 @@
 
 pub mod graphviz;
 
+pub use borrowck::provide;
+
 __build_diagnostic_array! { librustc_borrowck, DIAGNOSTICS }
index 977382b33adf75a429eb566390c9471f3793d65c..13486d898cff30cea432e667d35a5ceebe07ad44 100644 (file)
@@ -887,6 +887,7 @@ macro_rules! try_with_f {
     let mut local_providers = ty::maps::Providers::default();
     mir::provide(&mut local_providers);
     rustc_privacy::provide(&mut local_providers);
+    borrowck::provide(&mut local_providers);
     typeck::provide(&mut local_providers);
     ty::provide(&mut local_providers);