From d8f57c3804c083a24d1f6713cc8d64ea29b3a51e Mon Sep 17 00:00:00 2001
From: Eduard Burtescu <edy.burt@gmail.com>
Date: Thu, 18 Dec 2014 21:03:56 +0200
Subject: [PATCH] rustc: middle: move DefMap from resolve to def.

---
 src/librustc/middle/check_static_recursion.rs | 11 +++++------
 src/librustc/middle/def.rs                    |  6 ++++++
 src/librustc/middle/pat_util.rs               | 17 ++++++++---------
 src/librustc/middle/resolve.rs                |  3 ---
 src/librustc/middle/resolve_lifetime.rs       |  3 +--
 src/librustc/middle/ty.rs                     |  7 +++----
 src/librustc_trans/trans/_match.rs            |  3 +--
 7 files changed, 24 insertions(+), 26 deletions(-)

diff --git a/src/librustc/middle/check_static_recursion.rs b/src/librustc/middle/check_static_recursion.rs
index b32eb64025f..90242a3252e 100644
--- a/src/librustc/middle/check_static_recursion.rs
+++ b/src/librustc/middle/check_static_recursion.rs
@@ -12,8 +12,7 @@
 // recursively.
 
 use session::Session;
-use middle::resolve;
-use middle::def::{DefStatic, DefConst};
+use middle::def::{DefStatic, DefConst, DefMap};
 
 use syntax::ast;
 use syntax::{ast_util, ast_map};
@@ -22,7 +21,7 @@ use syntax::visit;
 
 struct CheckCrateVisitor<'a, 'ast: 'a> {
     sess: &'a Session,
-    def_map: &'a resolve::DefMap,
+    def_map: &'a DefMap,
     ast_map: &'a ast_map::Map<'ast>
 }
 
@@ -34,7 +33,7 @@ impl<'v, 'a, 'ast> Visitor<'v> for CheckCrateVisitor<'a, 'ast> {
 
 pub fn check_crate<'ast>(sess: &Session,
                          krate: &ast::Crate,
-                         def_map: &resolve::DefMap,
+                         def_map: &DefMap,
                          ast_map: &ast_map::Map<'ast>) {
     let mut visitor = CheckCrateVisitor {
         sess: sess,
@@ -60,7 +59,7 @@ struct CheckItemRecursionVisitor<'a, 'ast: 'a> {
     root_it: &'a ast::Item,
     sess: &'a Session,
     ast_map: &'a ast_map::Map<'ast>,
-    def_map: &'a resolve::DefMap,
+    def_map: &'a DefMap,
     idstack: Vec<ast::NodeId>
 }
 
@@ -68,7 +67,7 @@ struct CheckItemRecursionVisitor<'a, 'ast: 'a> {
 // FIXME: Should use the dependency graph when it's available (#1356)
 pub fn check_item_recursion<'a>(sess: &'a Session,
                                 ast_map: &'a ast_map::Map,
-                                def_map: &'a resolve::DefMap,
+                                def_map: &'a DefMap,
                                 it: &'a ast::Item) {
 
     let mut visitor = CheckItemRecursionVisitor {
diff --git a/src/librustc/middle/def.rs b/src/librustc/middle/def.rs
index 20a0dbdc1ee..ae79e0f3fd1 100644
--- a/src/librustc/middle/def.rs
+++ b/src/librustc/middle/def.rs
@@ -12,9 +12,12 @@ pub use self::Def::*;
 pub use self::MethodProvenance::*;
 
 use middle::subst::ParamSpace;
+use util::nodemap::NodeMap;
 use syntax::ast;
 use syntax::ast_util::local_def;
 
+use std::cell::RefCell;
+
 #[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
 pub enum Def {
     DefFn(ast::DefId, bool /* is_ctor */),
@@ -56,6 +59,9 @@ pub enum Def {
     DefMethod(ast::DefId /* method */, Option<ast::DefId> /* trait */, MethodProvenance),
 }
 
+// Definition mapping
+pub type DefMap = RefCell<NodeMap<Def>>;
+
 #[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
 pub enum MethodProvenance {
     FromTrait(ast::DefId),
diff --git a/src/librustc/middle/pat_util.rs b/src/librustc/middle/pat_util.rs
index 8ef8e091c94..0a6c29d1cb6 100644
--- a/src/librustc/middle/pat_util.rs
+++ b/src/librustc/middle/pat_util.rs
@@ -9,7 +9,6 @@
 // except according to those terms.
 
 use middle::def::*;
-use middle::resolve;
 use middle::ty;
 use util::nodemap::FnvHashMap;
 
@@ -21,7 +20,7 @@ pub type PatIdMap = FnvHashMap<ast::Ident, ast::NodeId>;
 
 // This is used because same-named variables in alternative patterns need to
 // use the NodeId of their namesake in the first pattern.
-pub fn pat_id_map(dm: &resolve::DefMap, pat: &ast::Pat) -> PatIdMap {
+pub fn pat_id_map(dm: &DefMap, pat: &ast::Pat) -> PatIdMap {
     let mut map = FnvHashMap::new();
     pat_bindings(dm, pat, |_bm, p_id, _s, path1| {
         map.insert(path1.node, p_id);
@@ -29,7 +28,7 @@ pub fn pat_id_map(dm: &resolve::DefMap, pat: &ast::Pat) -> PatIdMap {
     map
 }
 
-pub fn pat_is_refutable(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
+pub fn pat_is_refutable(dm: &DefMap, pat: &ast::Pat) -> bool {
     match pat.node {
         ast::PatLit(_) | ast::PatRange(_, _) => true,
         ast::PatEnum(_, _) |
@@ -45,7 +44,7 @@ pub fn pat_is_refutable(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
     }
 }
 
-pub fn pat_is_variant_or_struct(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
+pub fn pat_is_variant_or_struct(dm: &DefMap, pat: &ast::Pat) -> bool {
     match pat.node {
         ast::PatEnum(_, _) |
         ast::PatIdent(_, _, None) |
@@ -59,7 +58,7 @@ pub fn pat_is_variant_or_struct(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
     }
 }
 
-pub fn pat_is_const(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
+pub fn pat_is_const(dm: &DefMap, pat: &ast::Pat) -> bool {
     match pat.node {
         ast::PatIdent(_, _, None) | ast::PatEnum(..) => {
             match dm.borrow().get(&pat.id) {
@@ -71,7 +70,7 @@ pub fn pat_is_const(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
     }
 }
 
-pub fn pat_is_binding(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
+pub fn pat_is_binding(dm: &DefMap, pat: &ast::Pat) -> bool {
     match pat.node {
         ast::PatIdent(..) => {
             !pat_is_variant_or_struct(dm, pat) &&
@@ -81,7 +80,7 @@ pub fn pat_is_binding(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
     }
 }
 
-pub fn pat_is_binding_or_wild(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
+pub fn pat_is_binding_or_wild(dm: &DefMap, pat: &ast::Pat) -> bool {
     match pat.node {
         ast::PatIdent(..) => pat_is_binding(dm, pat),
         ast::PatWild(_) => true,
@@ -91,7 +90,7 @@ pub fn pat_is_binding_or_wild(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
 
 /// Call `it` on every "binding" in a pattern, e.g., on `a` in
 /// `match foo() { Some(a) => (), None => () }`
-pub fn pat_bindings<I>(dm: &resolve::DefMap, pat: &ast::Pat, mut it: I) where
+pub fn pat_bindings<I>(dm: &DefMap, pat: &ast::Pat, mut it: I) where
     I: FnMut(ast::BindingMode, ast::NodeId, Span, &ast::SpannedIdent),
 {
     walk_pat(pat, |p| {
@@ -107,7 +106,7 @@ pub fn pat_bindings<I>(dm: &resolve::DefMap, pat: &ast::Pat, mut it: I) where
 
 /// Checks if the pattern contains any patterns that bind something to
 /// an ident, e.g. `foo`, or `Foo(foo)` or `foo @ Bar(..)`.
-pub fn pat_contains_bindings(dm: &resolve::DefMap, pat: &ast::Pat) -> bool {
+pub fn pat_contains_bindings(dm: &DefMap, pat: &ast::Pat) -> bool {
     let mut contains_bindings = false;
     walk_pat(pat, |p| {
         if pat_is_binding(dm, p) {
diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs
index d72ecb7cd8d..be46b80b54d 100644
--- a/src/librustc/middle/resolve.rs
+++ b/src/librustc/middle/resolve.rs
@@ -84,9 +84,6 @@ use std::mem::replace;
 use std::rc::{Rc, Weak};
 use std::uint;
 
-// Definition mapping
-pub type DefMap = RefCell<NodeMap<Def>>;
-
 #[deriving(Copy)]
 struct BindingInfo {
     span: Span,
diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs
index 2202137d149..c8f53df6727 100644
--- a/src/librustc/middle/resolve_lifetime.rs
+++ b/src/librustc/middle/resolve_lifetime.rs
@@ -19,9 +19,8 @@ pub use self::DefRegion::*;
 use self::ScopeChain::*;
 
 use session::Session;
-use middle::def;
+use middle::def::{mod, DefMap};
 use middle::region;
-use middle::resolve::DefMap;
 use middle::subst;
 use middle::ty;
 use std::fmt;
diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs
index 0efe4a1a569..e93f3ca7d2e 100644
--- a/src/librustc/middle/ty.rs
+++ b/src/librustc/middle/ty.rs
@@ -46,13 +46,12 @@ use lint;
 use metadata::csearch;
 use middle;
 use middle::const_eval;
-use middle::def;
+use middle::def::{mod, DefMap};
 use middle::dependency_format;
 use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem};
 use middle::lang_items::{FnOnceTraitLangItem, TyDescStructLangItem};
 use middle::mem_categorization as mc;
 use middle::region;
-use middle::resolve;
 use middle::resolve_lifetime;
 use middle::infer;
 use middle::stability;
@@ -615,7 +614,7 @@ pub struct ctxt<'tcx> {
     // queried from a HashSet.
     interner: RefCell<FnvHashMap<InternedTy<'tcx>, Ty<'tcx>>>,
     pub sess: Session,
-    pub def_map: resolve::DefMap,
+    pub def_map: DefMap,
 
     pub named_region_map: resolve_lifetime::NamedRegionMap,
 
@@ -1967,7 +1966,7 @@ impl UnboxedClosureKind {
 
 pub fn mk_ctxt<'tcx>(s: Session,
                      type_arena: &'tcx TypedArena<TyS<'tcx>>,
-                     dm: resolve::DefMap,
+                     dm: DefMap,
                      named_region_map: resolve_lifetime::NamedRegionMap,
                      map: ast_map::Map<'tcx>,
                      freevars: RefCell<FreevarMap>,
diff --git a/src/librustc_trans/trans/_match.rs b/src/librustc_trans/trans/_match.rs
index 1401f1ad1f5..2bcd723fc83 100644
--- a/src/librustc_trans/trans/_match.rs
+++ b/src/librustc_trans/trans/_match.rs
@@ -193,12 +193,11 @@ use llvm::{ValueRef, BasicBlockRef};
 use middle::check_match::StaticInliner;
 use middle::check_match;
 use middle::const_eval;
-use middle::def;
+use middle::def::{mod, DefMap};
 use middle::expr_use_visitor as euv;
 use middle::lang_items::StrEqFnLangItem;
 use middle::mem_categorization as mc;
 use middle::pat_util::*;
-use middle::resolve::DefMap;
 use trans::adt;
 use trans::base::*;
 use trans::build::{AddCase, And, BitCast, Br, CondBr, GEPi, InBoundsGEP, Load};