@@ -41,7 +41,6 @@ pub struct SyntaxContextData {
41
41
pub struct Mark ( u32 ) ;
42
42
43
43
struct MarkData {
44
- parent : Mark ,
45
44
kind : MarkKind ,
46
45
expn_info : Option < ExpnInfo > ,
47
46
}
@@ -54,9 +53,9 @@ pub enum MarkKind {
54
53
}
55
54
56
55
impl Mark {
57
- pub fn fresh ( parent : Mark ) -> Self {
56
+ pub fn fresh ( _parent : Mark ) -> Self {
58
57
HygieneData :: with ( |data| {
59
- data. marks . push ( MarkData { parent : parent , kind : MarkKind :: Legacy , expn_info : None } ) ;
58
+ data. marks . push ( MarkData { kind : MarkKind :: Legacy , expn_info : None } ) ;
60
59
Mark ( data. marks . len ( ) as u32 - 1 )
61
60
} )
62
61
}
@@ -93,7 +92,8 @@ impl Mark {
93
92
if self == Mark :: root ( ) || data. marks [ self . 0 as usize ] . kind == MarkKind :: Modern {
94
93
return self ;
95
94
}
96
- self = data. marks [ self . 0 as usize ] . parent ;
95
+
96
+ self = self . call_site_mark ( data) ;
97
97
}
98
98
} )
99
99
}
@@ -114,7 +114,8 @@ impl Mark {
114
114
if self == Mark :: root ( ) {
115
115
return false ;
116
116
}
117
- self = data. marks [ self . 0 as usize ] . parent ;
117
+
118
+ self = self . call_site_mark ( data) ;
118
119
}
119
120
true
120
121
} )
@@ -134,17 +135,25 @@ impl Mark {
134
135
let mut a_path = FxHashSet :: < Mark > ( ) ;
135
136
while a != Mark :: root ( ) {
136
137
a_path. insert ( a) ;
137
- a = data. marks [ a. 0 as usize ] . parent ;
138
+
139
+ a = a. call_site_mark ( data) ;
138
140
}
139
141
140
142
// While the path from b to the root hasn't intersected, move up the tree
141
143
while !a_path. contains ( & b) {
142
- b = data . marks [ b . 0 as usize ] . parent ;
144
+ b = b . call_site_mark ( data ) ;
143
145
}
144
146
145
147
b
146
148
} )
147
149
}
150
+
151
+ /// Private helpers not acquiring a lock around global data
152
+ fn call_site_mark ( self , data : & HygieneData ) -> Mark {
153
+ data. marks [ self . 0 as usize ] . expn_info . as_ref ( )
154
+ . map ( |einfo| data. syntax_contexts [ einfo. call_site . ctxt ( ) . 0 as usize ] . outer_mark )
155
+ . unwrap_or ( Mark :: root ( ) )
156
+ }
148
157
}
149
158
150
159
pub struct HygieneData {
@@ -159,7 +168,6 @@ impl HygieneData {
159
168
pub fn new ( ) -> Self {
160
169
HygieneData {
161
170
marks : vec ! [ MarkData {
162
- parent: Mark :: root( ) ,
163
171
kind: MarkKind :: Builtin ,
164
172
expn_info: None ,
165
173
} ] ,
@@ -198,14 +206,13 @@ impl SyntaxContext {
198
206
199
207
// Allocate a new SyntaxContext with the given ExpnInfo. This is used when
200
208
// deserializing Spans from the incr. comp. cache.
201
- // FIXME(mw): This method does not restore MarkData::parent or
202
- // SyntaxContextData::prev_ctxt or SyntaxContextData:: modern. These things
209
+ // FIXME(mw): This method does not restore SyntaxContextData::prev_ctxt or
210
+ // SyntaxContextData::modern. These things
203
211
// don't seem to be used after HIR lowering, so everything should be fine
204
212
// as long as incremental compilation does not kick in before that.
205
213
pub fn allocate_directly ( expansion_info : ExpnInfo ) -> Self {
206
214
HygieneData :: with ( |data| {
207
215
data. marks . push ( MarkData {
208
- parent : Mark :: root ( ) ,
209
216
kind : MarkKind :: Legacy ,
210
217
expn_info : Some ( expansion_info)
211
218
} ) ;
0 commit comments