7
7
8
8
use std:: iter;
9
9
10
+ use base_db:: salsa:: { self , InternValue } ;
10
11
use span:: { MacroCallId , Span , SyntaxContextId } ;
11
12
12
- use crate :: db:: ExpandDatabase ;
13
+ use crate :: db:: { ExpandDatabase , InternSyntaxContextQuery } ;
13
14
14
15
#[ derive( Copy , Clone , Hash , PartialEq , Eq ) ]
15
16
pub struct SyntaxContextData {
@@ -22,6 +23,14 @@ pub struct SyntaxContextData {
22
23
pub opaque_and_semitransparent : SyntaxContextId ,
23
24
}
24
25
26
+ impl InternValue for SyntaxContextData {
27
+ type Key = ( SyntaxContextId , Option < MacroCallId > , Transparency ) ;
28
+
29
+ fn into_key ( & self ) -> Self :: Key {
30
+ ( self . parent , self . outer_expn , self . outer_transparency )
31
+ }
32
+ }
33
+
25
34
impl std:: fmt:: Debug for SyntaxContextData {
26
35
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
27
36
f. debug_struct ( "SyntaxContextData" )
@@ -149,38 +158,36 @@ fn apply_mark_internal(
149
158
transparency : Transparency ,
150
159
) -> SyntaxContextId {
151
160
let syntax_context_data = db. lookup_intern_syntax_context ( ctxt) ;
152
- let mut opaque = handle_self_ref ( ctxt, syntax_context_data. opaque ) ;
153
- let mut opaque_and_semitransparent =
154
- handle_self_ref ( ctxt, syntax_context_data. opaque_and_semitransparent ) ;
161
+ let mut opaque = syntax_context_data. opaque ;
162
+ let mut opaque_and_semitransparent = syntax_context_data. opaque_and_semitransparent ;
155
163
156
164
if transparency >= Transparency :: Opaque {
157
165
let parent = opaque;
158
- // Unlike rustc, with salsa we can't prefetch the to be allocated ID to create cycles with
159
- // salsa when interning, so we use a sentinel value that effectively means the current
160
- // syntax context.
161
- let new_opaque = SyntaxContextId :: SELF_REF ;
162
- opaque = db. intern_syntax_context ( SyntaxContextData {
163
- outer_expn : call_id,
164
- outer_transparency : transparency,
165
- parent,
166
- opaque : new_opaque,
167
- opaque_and_semitransparent : new_opaque,
168
- } ) ;
166
+ opaque = salsa:: plumbing:: get_query_table :: < InternSyntaxContextQuery > ( db) . get_or_insert (
167
+ ( parent, call_id, transparency) ,
168
+ |new_opaque| SyntaxContextData {
169
+ outer_expn : call_id,
170
+ outer_transparency : transparency,
171
+ parent,
172
+ opaque : new_opaque,
173
+ opaque_and_semitransparent : new_opaque,
174
+ } ,
175
+ ) ;
169
176
}
170
177
171
178
if transparency >= Transparency :: SemiTransparent {
172
179
let parent = opaque_and_semitransparent;
173
- // Unlike rustc, with salsa we can't prefetch the to be allocated ID to create cycles with
174
- // salsa when interning, so we use a sentinel value that effectively means the current
175
- // syntax context.
176
- let new_opaque_and_semitransparent = SyntaxContextId :: SELF_REF ;
177
- opaque_and_semitransparent = db . intern_syntax_context ( SyntaxContextData {
178
- outer_expn : call_id ,
179
- outer_transparency : transparency ,
180
- parent ,
181
- opaque ,
182
- opaque_and_semitransparent : new_opaque_and_semitransparent ,
183
- } ) ;
180
+ opaque_and_semitransparent =
181
+ salsa :: plumbing :: get_query_table :: < InternSyntaxContextQuery > ( db ) . get_or_insert (
182
+ ( parent , call_id , transparency ) ,
183
+ | new_opaque_and_semitransparent| SyntaxContextData {
184
+ outer_expn : call_id ,
185
+ outer_transparency : transparency ,
186
+ parent ,
187
+ opaque ,
188
+ opaque_and_semitransparent : new_opaque_and_semitransparent ,
189
+ } ,
190
+ ) ;
184
191
}
185
192
186
193
let parent = ctxt;
@@ -201,20 +208,12 @@ pub trait SyntaxContextExt {
201
208
fn marks ( self , db : & dyn ExpandDatabase ) -> Vec < ( Option < MacroCallId > , Transparency ) > ;
202
209
}
203
210
204
- #[ inline( always) ]
205
- fn handle_self_ref ( p : SyntaxContextId , n : SyntaxContextId ) -> SyntaxContextId {
206
- match n {
207
- SyntaxContextId :: SELF_REF => p,
208
- _ => n,
209
- }
210
- }
211
-
212
211
impl SyntaxContextExt for SyntaxContextId {
213
212
fn normalize_to_macro_rules ( self , db : & dyn ExpandDatabase ) -> Self {
214
- handle_self_ref ( self , db. lookup_intern_syntax_context ( self ) . opaque_and_semitransparent )
213
+ db. lookup_intern_syntax_context ( self ) . opaque_and_semitransparent
215
214
}
216
215
fn normalize_to_macros_2_0 ( self , db : & dyn ExpandDatabase ) -> Self {
217
- handle_self_ref ( self , db. lookup_intern_syntax_context ( self ) . opaque )
216
+ db. lookup_intern_syntax_context ( self ) . opaque
218
217
}
219
218
fn parent_ctxt ( self , db : & dyn ExpandDatabase ) -> Self {
220
219
db. lookup_intern_syntax_context ( self ) . parent
0 commit comments