File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ use symbol::{Ident, Symbol};
21
21
22
22
use serialize:: { Encodable , Decodable , Encoder , Decoder } ;
23
23
use std:: collections:: HashMap ;
24
+ use rustc_data_structures:: fx:: FxHashSet ;
24
25
use std:: fmt;
25
26
26
27
/// A SyntaxContext represents a chain of macro expansions (represented by marks).
@@ -117,6 +118,32 @@ impl Mark {
117
118
true
118
119
} )
119
120
}
121
+
122
+ /// Computes a mark such that both input marks are descendants of (or equal to) the returned
123
+ /// mark. That is, the following holds:
124
+ ///
125
+ /// ```rust
126
+ /// let lub = lub(a, b);
127
+ /// assert!(a.is_descendant_of(lub))
128
+ /// assert!(b.is_descendant_of(lub))
129
+ /// ```
130
+ pub fn lub ( mut a : Mark , mut b : Mark ) -> Mark {
131
+ HygieneData :: with ( |data| {
132
+ // Compute the path from a to the root
133
+ let mut a_path = FxHashSet :: < Mark > ( ) ;
134
+ while a != Mark :: root ( ) {
135
+ a_path. insert ( a) ;
136
+ a = data. marks [ a. 0 as usize ] . parent ;
137
+ }
138
+
139
+ // While the path from b to the root hasn't intersected, move up the tree
140
+ while !a_path. contains ( & b) {
141
+ b = data. marks [ b. 0 as usize ] . parent ;
142
+ }
143
+
144
+ b
145
+ } )
146
+ }
120
147
}
121
148
122
149
pub struct HygieneData {
You can’t perform that action at this time.
0 commit comments