1
Fork 0

Refactor Resolver field def_map from RefCell<DefMap> to DefMap

This commit is contained in:
Jeffrey Seyfried 2016-05-03 20:44:27 +00:00
parent 8c2fa93e81
commit a988c9a839
2 changed files with 12 additions and 13 deletions

View file

@ -1009,7 +1009,7 @@ pub struct Resolver<'a, 'tcx: 'a> {
// The idents for the primitive types. // The idents for the primitive types.
primitive_type_table: PrimitiveTypeTable, primitive_type_table: PrimitiveTypeTable,
def_map: RefCell<DefMap>, def_map: DefMap,
freevars: FreevarMap, freevars: FreevarMap,
freevars_seen: NodeMap<NodeMap<usize>>, freevars_seen: NodeMap<NodeMap<usize>>,
export_map: ExportMap, export_map: ExportMap,
@ -1133,7 +1133,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
primitive_type_table: PrimitiveTypeTable::new(), primitive_type_table: PrimitiveTypeTable::new(),
def_map: RefCell::new(NodeMap()), def_map: NodeMap(),
freevars: NodeMap(), freevars: NodeMap(),
freevars_seen: NodeMap(), freevars_seen: NodeMap(),
export_map: NodeMap(), export_map: NodeMap(),
@ -2001,7 +2001,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
// user and one 'x' came from the macro. // user and one 'x' came from the macro.
fn binding_mode_map(&mut self, pat: &Pat) -> BindingMap { fn binding_mode_map(&mut self, pat: &Pat) -> BindingMap {
let mut result = HashMap::new(); let mut result = HashMap::new();
pat_bindings(&self.def_map, pat, |binding_mode, _id, sp, path1| { let def_map = RefCell::new(::std::mem::replace(&mut self.def_map, NodeMap()));
pat_bindings(&def_map, pat, |binding_mode, _id, sp, path1| {
let name = path1.node; let name = path1.node;
result.insert(name, result.insert(name,
BindingInfo { BindingInfo {
@ -2009,6 +2010,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
binding_mode: binding_mode, binding_mode: binding_mode,
}); });
}); });
self.def_map = def_map.into_inner();
return result; return result;
} }
@ -2799,7 +2801,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
if let Some(node_id) = self.current_self_type.as_ref().and_then(extract_node_id) { if let Some(node_id) = self.current_self_type.as_ref().and_then(extract_node_id) {
// Look for a field with the same name in the current self_type. // Look for a field with the same name in the current self_type.
match self.def_map.borrow().get(&node_id).map(|d| d.full_def()) { match self.def_map.get(&node_id).map(|d| d.full_def()) {
Some(Def::Enum(did)) | Some(Def::Enum(did)) |
Some(Def::TyAlias(did)) | Some(Def::TyAlias(did)) |
Some(Def::Struct(did)) | Some(Def::Struct(did)) |
@ -3273,7 +3275,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
fn record_def(&mut self, node_id: NodeId, resolution: PathResolution) { fn record_def(&mut self, node_id: NodeId, resolution: PathResolution) {
debug!("(recording def) recording {:?} for {}", resolution, node_id); debug!("(recording def) recording {:?} for {}", resolution, node_id);
if let Some(prev_res) = self.def_map.borrow_mut().insert(node_id, resolution) { if let Some(prev_res) = self.def_map.insert(node_id, resolution) {
let span = self.ast_map.opt_span(node_id).unwrap_or(codemap::DUMMY_SP); let span = self.ast_map.opt_span(node_id).unwrap_or(codemap::DUMMY_SP);
span_bug!(span, span_bug!(span,
"path resolved multiple times ({:?} before, {:?} now)", "path resolved multiple times ({:?} before, {:?} now)",
@ -3314,7 +3316,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
Success(module) => { Success(module) => {
let def = module.def.unwrap(); let def = module.def.unwrap();
let path_resolution = PathResolution { base_def: def, depth: 0 }; let path_resolution = PathResolution { base_def: def, depth: 0 };
self.def_map.borrow_mut().insert(id, path_resolution); self.def_map.insert(id, path_resolution);
ty::Visibility::Restricted(self.ast_map.as_local_node_id(def.def_id()).unwrap()) ty::Visibility::Restricted(self.ast_map.as_local_node_id(def.def_id()).unwrap())
} }
Failed(Some((span, msg))) => { Failed(Some((span, msg))) => {
@ -3568,7 +3570,7 @@ pub fn resolve_crate<'a, 'tcx>(session: &'a Session,
resolver.report_privacy_errors(); resolver.report_privacy_errors();
CrateMap { CrateMap {
def_map: resolver.def_map, def_map: RefCell::new(resolver.def_map),
freevars: resolver.freevars, freevars: resolver.freevars,
maybe_unused_trait_imports: resolver.maybe_unused_trait_imports, maybe_unused_trait_imports: resolver.maybe_unused_trait_imports,
export_map: resolver.export_map, export_map: resolver.export_map,

View file

@ -608,7 +608,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
None => value_result.success().and_then(NameBinding::def).unwrap(), None => value_result.success().and_then(NameBinding::def).unwrap(),
}; };
let path_resolution = PathResolution { base_def: def, depth: 0 }; let path_resolution = PathResolution { base_def: def, depth: 0 };
self.resolver.def_map.borrow_mut().insert(directive.id, path_resolution); self.resolver.def_map.insert(directive.id, path_resolution);
debug!("(resolving single import) successfully resolved import"); debug!("(resolving single import) successfully resolved import");
return Success(()); return Success(());
@ -653,11 +653,8 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
// Record the destination of this import // Record the destination of this import
if let Some(did) = target_module.def_id() { if let Some(did) = target_module.def_id() {
self.resolver.def_map.borrow_mut().insert(directive.id, let resolution = PathResolution { base_def: Def::Mod(did), depth: 0 };
PathResolution { self.resolver.def_map.insert(directive.id, resolution);
base_def: Def::Mod(did),
depth: 0,
});
} }
debug!("(resolving glob import) successfully resolved import"); debug!("(resolving glob import) successfully resolved import");