Unwrap the RefCell around DefMap
This commit is contained in:
parent
effcd29652
commit
8a69a00941
7 changed files with 33 additions and 31 deletions
|
@ -27,7 +27,7 @@ use std::cell::RefCell;
|
|||
|
||||
struct CheckCrateVisitor<'a, 'ast: 'a> {
|
||||
sess: &'a Session,
|
||||
def_map: &'a DefMap,
|
||||
def_map: &'a RefCell<DefMap>,
|
||||
ast_map: &'a ast_map::Map<'ast>,
|
||||
// `discriminant_map` is a cache that associates the `NodeId`s of local
|
||||
// variant definitions with the discriminant expression that applies to
|
||||
|
@ -92,7 +92,7 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckCrateVisitor<'a, 'ast> {
|
|||
|
||||
pub fn check_crate<'ast>(sess: &Session,
|
||||
krate: &'ast hir::Crate,
|
||||
def_map: &DefMap,
|
||||
def_map: &RefCell<DefMap>,
|
||||
ast_map: &ast_map::Map<'ast>) {
|
||||
let mut visitor = CheckCrateVisitor {
|
||||
sess: sess,
|
||||
|
@ -108,7 +108,7 @@ struct CheckItemRecursionVisitor<'a, 'ast: 'a> {
|
|||
root_span: &'a Span,
|
||||
sess: &'a Session,
|
||||
ast_map: &'a ast_map::Map<'ast>,
|
||||
def_map: &'a DefMap,
|
||||
def_map: &'a RefCell<DefMap>,
|
||||
discriminant_map: &'a RefCell<NodeMap<Option<&'ast hir::Expr>>>,
|
||||
idstack: Vec<ast::NodeId>,
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@ use util::nodemap::NodeMap;
|
|||
use syntax::ast;
|
||||
use rustc_front::hir;
|
||||
|
||||
use std::cell::RefCell;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub enum Def {
|
||||
DefFn(DefId, bool /* is_ctor */),
|
||||
|
@ -103,7 +101,7 @@ impl PathResolution {
|
|||
}
|
||||
|
||||
// Definition mapping
|
||||
pub type DefMap = RefCell<NodeMap<PathResolution>>;
|
||||
pub type DefMap = NodeMap<PathResolution>;
|
||||
// This is the replacement export map. It maps a module to all of the exports
|
||||
// within.
|
||||
pub type ExportMap = NodeMap<Vec<Export>>;
|
||||
|
|
|
@ -18,11 +18,13 @@ use rustc_front::hir;
|
|||
use rustc_front::util::walk_pat;
|
||||
use syntax::codemap::{respan, Span, Spanned, DUMMY_SP};
|
||||
|
||||
use std::cell::RefCell;
|
||||
|
||||
pub type PatIdMap = FnvHashMap<ast::Name, 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: &DefMap, pat: &hir::Pat) -> PatIdMap {
|
||||
pub fn pat_id_map(dm: &RefCell<DefMap>, pat: &hir::Pat) -> PatIdMap {
|
||||
let mut map = FnvHashMap();
|
||||
pat_bindings(dm, pat, |_bm, p_id, _s, path1| {
|
||||
map.insert(path1.node, p_id);
|
||||
|
@ -30,7 +32,7 @@ pub fn pat_id_map(dm: &DefMap, pat: &hir::Pat) -> PatIdMap {
|
|||
map
|
||||
}
|
||||
|
||||
pub fn pat_is_refutable(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
pub fn pat_is_refutable(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
match pat.node {
|
||||
hir::PatLit(_) | hir::PatRange(_, _) | hir::PatQPath(..) => true,
|
||||
hir::PatEnum(_, _) |
|
||||
|
@ -46,7 +48,7 @@ pub fn pat_is_refutable(dm: &DefMap, pat: &hir::Pat) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn pat_is_variant_or_struct(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
pub fn pat_is_variant_or_struct(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
match pat.node {
|
||||
hir::PatEnum(_, _) |
|
||||
hir::PatIdent(_, _, None) |
|
||||
|
@ -60,7 +62,7 @@ pub fn pat_is_variant_or_struct(dm: &DefMap, pat: &hir::Pat) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn pat_is_const(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
pub fn pat_is_const(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
match pat.node {
|
||||
hir::PatIdent(_, _, None) | hir::PatEnum(..) | hir::PatQPath(..) => {
|
||||
match dm.borrow().get(&pat.id).map(|d| d.full_def()) {
|
||||
|
@ -74,7 +76,7 @@ pub fn pat_is_const(dm: &DefMap, pat: &hir::Pat) -> bool {
|
|||
|
||||
// Same as above, except that partially-resolved defs cause `false` to be
|
||||
// returned instead of a panic.
|
||||
pub fn pat_is_resolved_const(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
pub fn pat_is_resolved_const(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
match pat.node {
|
||||
hir::PatIdent(_, _, None) | hir::PatEnum(..) | hir::PatQPath(..) => {
|
||||
match dm.borrow().get(&pat.id)
|
||||
|
@ -88,7 +90,7 @@ pub fn pat_is_resolved_const(dm: &DefMap, pat: &hir::Pat) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn pat_is_binding(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
pub fn pat_is_binding(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
match pat.node {
|
||||
hir::PatIdent(..) => {
|
||||
!pat_is_variant_or_struct(dm, pat) &&
|
||||
|
@ -98,7 +100,7 @@ pub fn pat_is_binding(dm: &DefMap, pat: &hir::Pat) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn pat_is_binding_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
pub fn pat_is_binding_or_wild(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
match pat.node {
|
||||
hir::PatIdent(..) => pat_is_binding(dm, pat),
|
||||
hir::PatWild => true,
|
||||
|
@ -108,7 +110,7 @@ pub fn pat_is_binding_or_wild(dm: &DefMap, pat: &hir::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: &DefMap, pat: &hir::Pat, mut it: I) where
|
||||
pub fn pat_bindings<I>(dm: &RefCell<DefMap>, pat: &hir::Pat, mut it: I) where
|
||||
I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned<ast::Name>),
|
||||
{
|
||||
walk_pat(pat, |p| {
|
||||
|
@ -122,7 +124,7 @@ pub fn pat_bindings<I>(dm: &DefMap, pat: &hir::Pat, mut it: I) where
|
|||
});
|
||||
}
|
||||
|
||||
pub fn pat_bindings_hygienic<I>(dm: &DefMap, pat: &hir::Pat, mut it: I) where
|
||||
pub fn pat_bindings_hygienic<I>(dm: &RefCell<DefMap>, pat: &hir::Pat, mut it: I) where
|
||||
I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned<ast::Ident>),
|
||||
{
|
||||
walk_pat(pat, |p| {
|
||||
|
@ -138,7 +140,7 @@ pub fn pat_bindings_hygienic<I>(dm: &DefMap, pat: &hir::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: &DefMap, pat: &hir::Pat) -> bool {
|
||||
pub fn pat_contains_bindings(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
let mut contains_bindings = false;
|
||||
walk_pat(pat, |p| {
|
||||
if pat_is_binding(dm, p) {
|
||||
|
@ -153,7 +155,7 @@ pub fn pat_contains_bindings(dm: &DefMap, pat: &hir::Pat) -> bool {
|
|||
|
||||
/// Checks if the pattern contains any `ref` or `ref mut` bindings,
|
||||
/// and if yes wether its containing mutable ones or just immutables ones.
|
||||
pub fn pat_contains_ref_binding(dm: &DefMap, pat: &hir::Pat) -> Option<hir::Mutability> {
|
||||
pub fn pat_contains_ref_binding(dm: &RefCell<DefMap>, pat: &hir::Pat) -> Option<hir::Mutability> {
|
||||
let mut result = None;
|
||||
pat_bindings(dm, pat, |mode, _, _, _| {
|
||||
match mode {
|
||||
|
@ -172,7 +174,7 @@ pub fn pat_contains_ref_binding(dm: &DefMap, pat: &hir::Pat) -> Option<hir::Muta
|
|||
|
||||
/// Checks if the patterns for this arm contain any `ref` or `ref mut`
|
||||
/// bindings, and if yes wether its containing mutable ones or just immutables ones.
|
||||
pub fn arm_contains_ref_binding(dm: &DefMap, arm: &hir::Arm) -> Option<hir::Mutability> {
|
||||
pub fn arm_contains_ref_binding(dm: &RefCell<DefMap>, arm: &hir::Arm) -> Option<hir::Mutability> {
|
||||
arm.pats.iter()
|
||||
.filter_map(|pat| pat_contains_ref_binding(dm, pat))
|
||||
.max_by(|m| match *m {
|
||||
|
@ -183,7 +185,7 @@ pub fn arm_contains_ref_binding(dm: &DefMap, arm: &hir::Arm) -> Option<hir::Muta
|
|||
|
||||
/// Checks if the pattern contains any patterns that bind something to
|
||||
/// an ident or wildcard, e.g. `foo`, or `Foo(_)`, `foo @ Bar(..)`,
|
||||
pub fn pat_contains_bindings_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
|
||||
pub fn pat_contains_bindings_or_wild(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
|
||||
let mut contains_bindings = false;
|
||||
walk_pat(pat, |p| {
|
||||
if pat_is_binding_or_wild(dm, p) {
|
||||
|
@ -219,7 +221,7 @@ pub fn def_to_path(tcx: &ty::ctxt, id: DefId) -> hir::Path {
|
|||
}
|
||||
|
||||
/// Return variants that are necessary to exist for the pattern to match.
|
||||
pub fn necessary_variants(dm: &DefMap, pat: &hir::Pat) -> Vec<DefId> {
|
||||
pub fn necessary_variants(dm: &RefCell<DefMap>, pat: &hir::Pat) -> Vec<DefId> {
|
||||
let mut variants = vec![];
|
||||
walk_pat(pat, |p| {
|
||||
match p.node {
|
||||
|
|
|
@ -23,6 +23,7 @@ use middle::def::{self, DefMap};
|
|||
use middle::region;
|
||||
use middle::subst;
|
||||
use middle::ty;
|
||||
use std::cell::RefCell;
|
||||
use std::fmt;
|
||||
use std::mem::replace;
|
||||
use syntax::ast;
|
||||
|
@ -54,7 +55,7 @@ struct LifetimeContext<'a> {
|
|||
sess: &'a Session,
|
||||
named_region_map: &'a mut NamedRegionMap,
|
||||
scope: Scope<'a>,
|
||||
def_map: &'a DefMap,
|
||||
def_map: &'a RefCell<DefMap>,
|
||||
// Deep breath. Our representation for poly trait refs contains a single
|
||||
// binder and thus we only allow a single level of quantification. However,
|
||||
// the syntax of Rust permits quantification in two places, e.g., `T: for <'a> Foo<'a>`
|
||||
|
@ -93,7 +94,7 @@ type Scope<'a> = &'a ScopeChain<'a>;
|
|||
|
||||
static ROOT_SCOPE: ScopeChain<'static> = RootScope;
|
||||
|
||||
pub fn krate(sess: &Session, krate: &hir::Crate, def_map: &DefMap) -> NamedRegionMap {
|
||||
pub fn krate(sess: &Session, krate: &hir::Crate, def_map: &RefCell<DefMap>) -> NamedRegionMap {
|
||||
let mut named_region_map = NodeMap();
|
||||
visit::walk_crate(&mut LifetimeContext {
|
||||
sess: sess,
|
||||
|
|
|
@ -228,7 +228,7 @@ pub struct ctxt<'tcx> {
|
|||
pub types: CommonTypes<'tcx>,
|
||||
|
||||
pub sess: &'tcx Session,
|
||||
pub def_map: DefMap,
|
||||
pub def_map: RefCell<DefMap>,
|
||||
|
||||
pub named_region_map: resolve_lifetime::NamedRegionMap,
|
||||
|
||||
|
@ -453,7 +453,7 @@ impl<'tcx> ctxt<'tcx> {
|
|||
/// reference to the context, to allow formatting values that need it.
|
||||
pub fn create_and_enter<F, R>(s: &'tcx Session,
|
||||
arenas: &'tcx CtxtArenas<'tcx>,
|
||||
def_map: DefMap,
|
||||
def_map: RefCell<DefMap>,
|
||||
named_region_map: resolve_lifetime::NamedRegionMap,
|
||||
map: ast_map::Map<'tcx>,
|
||||
freevars: FreevarMap,
|
||||
|
|
|
@ -1150,7 +1150,7 @@ pub struct Resolver<'a, 'tcx:'a> {
|
|||
// The idents for the primitive types.
|
||||
primitive_type_table: PrimitiveTypeTable,
|
||||
|
||||
def_map: DefMap,
|
||||
def_map: RefCell<DefMap>,
|
||||
freevars: FreevarMap,
|
||||
freevars_seen: NodeMap<NodeMap<usize>>,
|
||||
export_map: ExportMap,
|
||||
|
@ -4026,7 +4026,7 @@ fn module_to_string(module: &Module) -> String {
|
|||
|
||||
|
||||
pub struct CrateMap {
|
||||
pub def_map: DefMap,
|
||||
pub def_map: RefCell<DefMap>,
|
||||
pub freevars: FreevarMap,
|
||||
pub export_map: ExportMap,
|
||||
pub trait_map: TraitMap,
|
||||
|
|
|
@ -222,6 +222,7 @@ use util::nodemap::FnvHashMap;
|
|||
use util::ppaux;
|
||||
|
||||
use std;
|
||||
use std::cell::RefCell;
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt;
|
||||
use std::rc::Rc;
|
||||
|
@ -495,7 +496,7 @@ fn expand_nested_bindings<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
}
|
||||
|
||||
fn enter_match<'a, 'b, 'p, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
|
||||
dm: &DefMap,
|
||||
dm: &RefCell<DefMap>,
|
||||
m: &[Match<'a, 'p, 'blk, 'tcx>],
|
||||
col: usize,
|
||||
val: MatchInput,
|
||||
|
@ -541,7 +542,7 @@ fn enter_match<'a, 'b, 'p, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
|
|||
}
|
||||
|
||||
fn enter_default<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
dm: &DefMap,
|
||||
dm: &RefCell<DefMap>,
|
||||
m: &[Match<'a, 'p, 'blk, 'tcx>],
|
||||
col: usize,
|
||||
val: MatchInput)
|
||||
|
@ -596,7 +597,7 @@ fn enter_default<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
|||
fn enter_opt<'a, 'p, 'blk, 'tcx>(
|
||||
bcx: Block<'blk, 'tcx>,
|
||||
_: ast::NodeId,
|
||||
dm: &DefMap,
|
||||
dm: &RefCell<DefMap>,
|
||||
m: &[Match<'a, 'p, 'blk, 'tcx>],
|
||||
opt: &Opt,
|
||||
col: usize,
|
||||
|
@ -842,8 +843,8 @@ impl FailureHandler {
|
|||
}
|
||||
}
|
||||
|
||||
fn pick_column_to_specialize(def_map: &DefMap, m: &[Match]) -> Option<usize> {
|
||||
fn pat_score(def_map: &DefMap, pat: &hir::Pat) -> usize {
|
||||
fn pick_column_to_specialize(def_map: &RefCell<DefMap>, m: &[Match]) -> Option<usize> {
|
||||
fn pat_score(def_map: &RefCell<DefMap>, pat: &hir::Pat) -> usize {
|
||||
match pat.node {
|
||||
hir::PatIdent(_, _, Some(ref inner)) => pat_score(def_map, &**inner),
|
||||
_ if pat_is_refutable(def_map, pat) => 1,
|
||||
|
|
Loading…
Add table
Reference in a new issue