Skip to content

Commit 8a69a00

Browse files
committed
Unwrap the RefCell around DefMap
1 parent effcd29 commit 8a69a00

File tree

7 files changed

+33
-31
lines changed

7 files changed

+33
-31
lines changed

src/librustc/middle/check_static_recursion.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use std::cell::RefCell;
2727

2828
struct CheckCrateVisitor<'a, 'ast: 'a> {
2929
sess: &'a Session,
30-
def_map: &'a DefMap,
30+
def_map: &'a RefCell<DefMap>,
3131
ast_map: &'a ast_map::Map<'ast>,
3232
// `discriminant_map` is a cache that associates the `NodeId`s of local
3333
// variant definitions with the discriminant expression that applies to
@@ -92,7 +92,7 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckCrateVisitor<'a, 'ast> {
9292

9393
pub fn check_crate<'ast>(sess: &Session,
9494
krate: &'ast hir::Crate,
95-
def_map: &DefMap,
95+
def_map: &RefCell<DefMap>,
9696
ast_map: &ast_map::Map<'ast>) {
9797
let mut visitor = CheckCrateVisitor {
9898
sess: sess,
@@ -108,7 +108,7 @@ struct CheckItemRecursionVisitor<'a, 'ast: 'a> {
108108
root_span: &'a Span,
109109
sess: &'a Session,
110110
ast_map: &'a ast_map::Map<'ast>,
111-
def_map: &'a DefMap,
111+
def_map: &'a RefCell<DefMap>,
112112
discriminant_map: &'a RefCell<NodeMap<Option<&'ast hir::Expr>>>,
113113
idstack: Vec<ast::NodeId>,
114114
}

src/librustc/middle/def.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ use util::nodemap::NodeMap;
1717
use syntax::ast;
1818
use rustc_front::hir;
1919

20-
use std::cell::RefCell;
21-
2220
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
2321
pub enum Def {
2422
DefFn(DefId, bool /* is_ctor */),
@@ -103,7 +101,7 @@ impl PathResolution {
103101
}
104102

105103
// Definition mapping
106-
pub type DefMap = RefCell<NodeMap<PathResolution>>;
104+
pub type DefMap = NodeMap<PathResolution>;
107105
// This is the replacement export map. It maps a module to all of the exports
108106
// within.
109107
pub type ExportMap = NodeMap<Vec<Export>>;

src/librustc/middle/pat_util.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@ use rustc_front::hir;
1818
use rustc_front::util::walk_pat;
1919
use syntax::codemap::{respan, Span, Spanned, DUMMY_SP};
2020

21+
use std::cell::RefCell;
22+
2123
pub type PatIdMap = FnvHashMap<ast::Name, ast::NodeId>;
2224

2325
// This is used because same-named variables in alternative patterns need to
2426
// use the NodeId of their namesake in the first pattern.
25-
pub fn pat_id_map(dm: &DefMap, pat: &hir::Pat) -> PatIdMap {
27+
pub fn pat_id_map(dm: &RefCell<DefMap>, pat: &hir::Pat) -> PatIdMap {
2628
let mut map = FnvHashMap();
2729
pat_bindings(dm, pat, |_bm, p_id, _s, path1| {
2830
map.insert(path1.node, p_id);
2931
});
3032
map
3133
}
3234

33-
pub fn pat_is_refutable(dm: &DefMap, pat: &hir::Pat) -> bool {
35+
pub fn pat_is_refutable(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
3436
match pat.node {
3537
hir::PatLit(_) | hir::PatRange(_, _) | hir::PatQPath(..) => true,
3638
hir::PatEnum(_, _) |
@@ -46,7 +48,7 @@ pub fn pat_is_refutable(dm: &DefMap, pat: &hir::Pat) -> bool {
4648
}
4749
}
4850

49-
pub fn pat_is_variant_or_struct(dm: &DefMap, pat: &hir::Pat) -> bool {
51+
pub fn pat_is_variant_or_struct(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
5052
match pat.node {
5153
hir::PatEnum(_, _) |
5254
hir::PatIdent(_, _, None) |
@@ -60,7 +62,7 @@ pub fn pat_is_variant_or_struct(dm: &DefMap, pat: &hir::Pat) -> bool {
6062
}
6163
}
6264

63-
pub fn pat_is_const(dm: &DefMap, pat: &hir::Pat) -> bool {
65+
pub fn pat_is_const(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
6466
match pat.node {
6567
hir::PatIdent(_, _, None) | hir::PatEnum(..) | hir::PatQPath(..) => {
6668
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 {
7476

7577
// Same as above, except that partially-resolved defs cause `false` to be
7678
// returned instead of a panic.
77-
pub fn pat_is_resolved_const(dm: &DefMap, pat: &hir::Pat) -> bool {
79+
pub fn pat_is_resolved_const(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
7880
match pat.node {
7981
hir::PatIdent(_, _, None) | hir::PatEnum(..) | hir::PatQPath(..) => {
8082
match dm.borrow().get(&pat.id)
@@ -88,7 +90,7 @@ pub fn pat_is_resolved_const(dm: &DefMap, pat: &hir::Pat) -> bool {
8890
}
8991
}
9092

91-
pub fn pat_is_binding(dm: &DefMap, pat: &hir::Pat) -> bool {
93+
pub fn pat_is_binding(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
9294
match pat.node {
9395
hir::PatIdent(..) => {
9496
!pat_is_variant_or_struct(dm, pat) &&
@@ -98,7 +100,7 @@ pub fn pat_is_binding(dm: &DefMap, pat: &hir::Pat) -> bool {
98100
}
99101
}
100102

101-
pub fn pat_is_binding_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
103+
pub fn pat_is_binding_or_wild(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
102104
match pat.node {
103105
hir::PatIdent(..) => pat_is_binding(dm, pat),
104106
hir::PatWild => true,
@@ -108,7 +110,7 @@ pub fn pat_is_binding_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
108110

109111
/// Call `it` on every "binding" in a pattern, e.g., on `a` in
110112
/// `match foo() { Some(a) => (), None => () }`
111-
pub fn pat_bindings<I>(dm: &DefMap, pat: &hir::Pat, mut it: I) where
113+
pub fn pat_bindings<I>(dm: &RefCell<DefMap>, pat: &hir::Pat, mut it: I) where
112114
I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned<ast::Name>),
113115
{
114116
walk_pat(pat, |p| {
@@ -122,7 +124,7 @@ pub fn pat_bindings<I>(dm: &DefMap, pat: &hir::Pat, mut it: I) where
122124
});
123125
}
124126

125-
pub fn pat_bindings_hygienic<I>(dm: &DefMap, pat: &hir::Pat, mut it: I) where
127+
pub fn pat_bindings_hygienic<I>(dm: &RefCell<DefMap>, pat: &hir::Pat, mut it: I) where
126128
I: FnMut(hir::BindingMode, ast::NodeId, Span, &Spanned<ast::Ident>),
127129
{
128130
walk_pat(pat, |p| {
@@ -138,7 +140,7 @@ pub fn pat_bindings_hygienic<I>(dm: &DefMap, pat: &hir::Pat, mut it: I) where
138140

139141
/// Checks if the pattern contains any patterns that bind something to
140142
/// an ident, e.g. `foo`, or `Foo(foo)` or `foo @ Bar(..)`.
141-
pub fn pat_contains_bindings(dm: &DefMap, pat: &hir::Pat) -> bool {
143+
pub fn pat_contains_bindings(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
142144
let mut contains_bindings = false;
143145
walk_pat(pat, |p| {
144146
if pat_is_binding(dm, p) {
@@ -153,7 +155,7 @@ pub fn pat_contains_bindings(dm: &DefMap, pat: &hir::Pat) -> bool {
153155

154156
/// Checks if the pattern contains any `ref` or `ref mut` bindings,
155157
/// and if yes wether its containing mutable ones or just immutables ones.
156-
pub fn pat_contains_ref_binding(dm: &DefMap, pat: &hir::Pat) -> Option<hir::Mutability> {
158+
pub fn pat_contains_ref_binding(dm: &RefCell<DefMap>, pat: &hir::Pat) -> Option<hir::Mutability> {
157159
let mut result = None;
158160
pat_bindings(dm, pat, |mode, _, _, _| {
159161
match mode {
@@ -172,7 +174,7 @@ pub fn pat_contains_ref_binding(dm: &DefMap, pat: &hir::Pat) -> Option<hir::Muta
172174

173175
/// Checks if the patterns for this arm contain any `ref` or `ref mut`
174176
/// bindings, and if yes wether its containing mutable ones or just immutables ones.
175-
pub fn arm_contains_ref_binding(dm: &DefMap, arm: &hir::Arm) -> Option<hir::Mutability> {
177+
pub fn arm_contains_ref_binding(dm: &RefCell<DefMap>, arm: &hir::Arm) -> Option<hir::Mutability> {
176178
arm.pats.iter()
177179
.filter_map(|pat| pat_contains_ref_binding(dm, pat))
178180
.max_by(|m| match *m {
@@ -183,7 +185,7 @@ pub fn arm_contains_ref_binding(dm: &DefMap, arm: &hir::Arm) -> Option<hir::Muta
183185

184186
/// Checks if the pattern contains any patterns that bind something to
185187
/// an ident or wildcard, e.g. `foo`, or `Foo(_)`, `foo @ Bar(..)`,
186-
pub fn pat_contains_bindings_or_wild(dm: &DefMap, pat: &hir::Pat) -> bool {
188+
pub fn pat_contains_bindings_or_wild(dm: &RefCell<DefMap>, pat: &hir::Pat) -> bool {
187189
let mut contains_bindings = false;
188190
walk_pat(pat, |p| {
189191
if pat_is_binding_or_wild(dm, p) {
@@ -219,7 +221,7 @@ pub fn def_to_path(tcx: &ty::ctxt, id: DefId) -> hir::Path {
219221
}
220222

221223
/// Return variants that are necessary to exist for the pattern to match.
222-
pub fn necessary_variants(dm: &DefMap, pat: &hir::Pat) -> Vec<DefId> {
224+
pub fn necessary_variants(dm: &RefCell<DefMap>, pat: &hir::Pat) -> Vec<DefId> {
223225
let mut variants = vec![];
224226
walk_pat(pat, |p| {
225227
match p.node {

src/librustc/middle/resolve_lifetime.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use middle::def::{self, DefMap};
2323
use middle::region;
2424
use middle::subst;
2525
use middle::ty;
26+
use std::cell::RefCell;
2627
use std::fmt;
2728
use std::mem::replace;
2829
use syntax::ast;
@@ -54,7 +55,7 @@ struct LifetimeContext<'a> {
5455
sess: &'a Session,
5556
named_region_map: &'a mut NamedRegionMap,
5657
scope: Scope<'a>,
57-
def_map: &'a DefMap,
58+
def_map: &'a RefCell<DefMap>,
5859
// Deep breath. Our representation for poly trait refs contains a single
5960
// binder and thus we only allow a single level of quantification. However,
6061
// 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>;
9394

9495
static ROOT_SCOPE: ScopeChain<'static> = RootScope;
9596

96-
pub fn krate(sess: &Session, krate: &hir::Crate, def_map: &DefMap) -> NamedRegionMap {
97+
pub fn krate(sess: &Session, krate: &hir::Crate, def_map: &RefCell<DefMap>) -> NamedRegionMap {
9798
let mut named_region_map = NodeMap();
9899
visit::walk_crate(&mut LifetimeContext {
99100
sess: sess,

src/librustc/middle/ty/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ pub struct ctxt<'tcx> {
228228
pub types: CommonTypes<'tcx>,
229229

230230
pub sess: &'tcx Session,
231-
pub def_map: DefMap,
231+
pub def_map: RefCell<DefMap>,
232232

233233
pub named_region_map: resolve_lifetime::NamedRegionMap,
234234

@@ -453,7 +453,7 @@ impl<'tcx> ctxt<'tcx> {
453453
/// reference to the context, to allow formatting values that need it.
454454
pub fn create_and_enter<F, R>(s: &'tcx Session,
455455
arenas: &'tcx CtxtArenas<'tcx>,
456-
def_map: DefMap,
456+
def_map: RefCell<DefMap>,
457457
named_region_map: resolve_lifetime::NamedRegionMap,
458458
map: ast_map::Map<'tcx>,
459459
freevars: FreevarMap,

src/librustc_resolve/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ pub struct Resolver<'a, 'tcx:'a> {
11501150
// The idents for the primitive types.
11511151
primitive_type_table: PrimitiveTypeTable,
11521152

1153-
def_map: DefMap,
1153+
def_map: RefCell<DefMap>,
11541154
freevars: FreevarMap,
11551155
freevars_seen: NodeMap<NodeMap<usize>>,
11561156
export_map: ExportMap,
@@ -4026,7 +4026,7 @@ fn module_to_string(module: &Module) -> String {
40264026

40274027

40284028
pub struct CrateMap {
4029-
pub def_map: DefMap,
4029+
pub def_map: RefCell<DefMap>,
40304030
pub freevars: FreevarMap,
40314031
pub export_map: ExportMap,
40324032
pub trait_map: TraitMap,

src/librustc_trans/trans/_match.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ use util::nodemap::FnvHashMap;
222222
use util::ppaux;
223223

224224
use std;
225+
use std::cell::RefCell;
225226
use std::cmp::Ordering;
226227
use std::fmt;
227228
use std::rc::Rc;
@@ -495,7 +496,7 @@ fn expand_nested_bindings<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
495496
}
496497

497498
fn enter_match<'a, 'b, 'p, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
498-
dm: &DefMap,
499+
dm: &RefCell<DefMap>,
499500
m: &[Match<'a, 'p, 'blk, 'tcx>],
500501
col: usize,
501502
val: MatchInput,
@@ -541,7 +542,7 @@ fn enter_match<'a, 'b, 'p, 'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
541542
}
542543

543544
fn enter_default<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
544-
dm: &DefMap,
545+
dm: &RefCell<DefMap>,
545546
m: &[Match<'a, 'p, 'blk, 'tcx>],
546547
col: usize,
547548
val: MatchInput)
@@ -596,7 +597,7 @@ fn enter_default<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
596597
fn enter_opt<'a, 'p, 'blk, 'tcx>(
597598
bcx: Block<'blk, 'tcx>,
598599
_: ast::NodeId,
599-
dm: &DefMap,
600+
dm: &RefCell<DefMap>,
600601
m: &[Match<'a, 'p, 'blk, 'tcx>],
601602
opt: &Opt,
602603
col: usize,
@@ -842,8 +843,8 @@ impl FailureHandler {
842843
}
843844
}
844845

845-
fn pick_column_to_specialize(def_map: &DefMap, m: &[Match]) -> Option<usize> {
846-
fn pat_score(def_map: &DefMap, pat: &hir::Pat) -> usize {
846+
fn pick_column_to_specialize(def_map: &RefCell<DefMap>, m: &[Match]) -> Option<usize> {
847+
fn pat_score(def_map: &RefCell<DefMap>, pat: &hir::Pat) -> usize {
847848
match pat.node {
848849
hir::PatIdent(_, _, Some(ref inner)) => pat_score(def_map, &**inner),
849850
_ if pat_is_refutable(def_map, pat) => 1,

0 commit comments

Comments
 (0)