Skip to content

Commit 797eb57

Browse files
committed
Refactor field expansion_data of Resolver to use a Mark instead of a u32.
1 parent 5c2d76d commit 797eb57

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

src/librustc/hir/map/def_collector.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use hir::def_id::{CRATE_DEF_INDEX, DefId, DefIndex};
1717
use middle::cstore::InlinedItem;
1818

1919
use syntax::ast::*;
20+
use syntax::ext::hygiene::Mark;
2021
use syntax::visit;
2122
use syntax::parse::token::{self, keywords};
2223

@@ -31,7 +32,7 @@ pub struct DefCollector<'a> {
3132
}
3233

3334
pub struct MacroInvocationData {
34-
pub id: NodeId,
35+
pub mark: Mark,
3536
pub def_index: DefIndex,
3637
pub const_integer: bool,
3738
}
@@ -126,7 +127,7 @@ impl<'a> DefCollector<'a> {
126127
fn visit_macro_invoc(&mut self, id: NodeId, const_integer: bool) {
127128
if let Some(ref mut visit) = self.visit_macro_invoc {
128129
visit(MacroInvocationData {
129-
id: id,
130+
mark: Mark::from_placeholder_id(id),
130131
const_integer: const_integer,
131132
def_index: self.parent_def.unwrap(),
132133
})

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ pub struct BuildReducedGraphVisitor<'a, 'b: 'a> {
531531

532532
impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
533533
fn visit_invoc(&mut self, id: ast::NodeId) {
534-
self.resolver.expansion_data.get_mut(&id.as_u32()).unwrap().module =
534+
self.resolver.expansion_data.get_mut(&Mark::from_placeholder_id(id)).unwrap().module =
535535
self.resolver.current_module;
536536
}
537537
}

src/librustc_resolve/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ pub struct Resolver<'a> {
10841084
macro_names: FnvHashSet<Name>,
10851085

10861086
// Maps the `Mark` of an expansion to its containing module or block.
1087-
expansion_data: FnvHashMap<u32, macros::ExpansionData<'a>>,
1087+
expansion_data: FnvHashMap<Mark, macros::ExpansionData<'a>>,
10881088
}
10891089

10901090
pub struct ResolverArenas<'a> {
@@ -1202,7 +1202,7 @@ impl<'a> Resolver<'a> {
12021202
DefCollector::new(&mut definitions).collect_root();
12031203

12041204
let mut expansion_data = FnvHashMap();
1205-
expansion_data.insert(0, macros::ExpansionData::root(graph_root)); // Crate root expansion
1205+
expansion_data.insert(Mark::root(), macros::ExpansionData::root(graph_root));
12061206

12071207
Resolver {
12081208
session: session,

src/librustc_resolve/macros.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'a> base::Resolver for Resolver<'a> {
5555
fn get_module_scope(&mut self, id: ast::NodeId) -> Mark {
5656
let mark = Mark::fresh();
5757
let module = self.module_map[&id];
58-
self.expansion_data.insert(mark.as_u32(), ExpansionData {
58+
self.expansion_data.insert(mark, ExpansionData {
5959
module: module,
6060
def_index: module.def_id().unwrap().index,
6161
const_integer: false,
@@ -65,7 +65,7 @@ impl<'a> base::Resolver for Resolver<'a> {
6565

6666
fn visit_expansion(&mut self, mark: Mark, expansion: &Expansion) {
6767
self.collect_def_ids(mark, expansion);
68-
self.current_module = self.expansion_data[&mark.as_u32()].module;
68+
self.current_module = self.expansion_data[&mark].module;
6969
expansion.visit_with(&mut BuildReducedGraphVisitor { resolver: self });
7070
}
7171

@@ -88,7 +88,7 @@ impl<'a> base::Resolver for Resolver<'a> {
8888
self.macro_names.insert(ident.name);
8989
}
9090

91-
let mut module = self.expansion_data[&scope.as_u32()].module;
91+
let mut module = self.expansion_data[&scope].module;
9292
while module.macros_escape {
9393
module = module.parent.unwrap();
9494
}
@@ -104,7 +104,7 @@ impl<'a> base::Resolver for Resolver<'a> {
104104
fn find_attr_invoc(&mut self, attrs: &mut Vec<ast::Attribute>) -> Option<ast::Attribute> {
105105
for i in 0..attrs.len() {
106106
let name = intern(&attrs[i].name());
107-
match self.expansion_data[&0].module.macros.borrow().get(&name) {
107+
match self.expansion_data[&Mark::root()].module.macros.borrow().get(&name) {
108108
Some(binding) => match *binding.ext {
109109
MultiModifier(..) | MultiDecorator(..) | SyntaxExtension::AttrProcMacro(..) => {
110110
return Some(attrs.remove(i))
@@ -132,7 +132,7 @@ impl<'a> base::Resolver for Resolver<'a> {
132132
InvocationKind::Attr { ref attr, .. } => (intern(&*attr.name()), attr.span),
133133
};
134134

135-
let mut module = self.expansion_data[&scope.as_u32()].module;
135+
let mut module = self.expansion_data[&scope].module;
136136
loop {
137137
if let Some(binding) = module.macros.borrow().get(&name) {
138138
return Some(binding.ext.clone());
@@ -168,9 +168,9 @@ impl<'a> Resolver<'a> {
168168

169169
fn collect_def_ids(&mut self, mark: Mark, expansion: &Expansion) {
170170
let expansion_data = &mut self.expansion_data;
171-
let ExpansionData { def_index, const_integer, module } = expansion_data[&mark.as_u32()];
171+
let ExpansionData { def_index, const_integer, module } = expansion_data[&mark];
172172
let visit_macro_invoc = &mut |invoc: map::MacroInvocationData| {
173-
expansion_data.entry(invoc.id.as_u32()).or_insert(ExpansionData {
173+
expansion_data.entry(invoc.mark).or_insert(ExpansionData {
174174
def_index: invoc.def_index,
175175
const_integer: invoc.const_integer,
176176
module: module,

src/libsyntax/ext/hygiene.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//! and definition contexts*. J. Funct. Program. 22, 2 (March 2012), 181-216.
1616
//! DOI=10.1017/S0956796812000093 http://dx.doi.org/10.1017/S0956796812000093
1717
18+
use ast::NodeId;
1819
use std::cell::RefCell;
1920
use std::collections::HashMap;
2021
use std::fmt;
@@ -46,6 +47,10 @@ impl Mark {
4647
Mark(0)
4748
}
4849

50+
pub fn from_placeholder_id(id: NodeId) -> Self {
51+
Mark(id.as_u32())
52+
}
53+
4954
pub fn as_u32(&self) -> u32 {
5055
self.0
5156
}

0 commit comments

Comments
 (0)