@@ -30,7 +30,7 @@ use std::{
30
30
use la_arena:: { Arena , Idx , RawIdx } ;
31
31
use rustc_hash:: { FxBuildHasher , FxHashMap } ;
32
32
use syntax:: {
33
- AstNode , AstPtr , SyntaxNode , SyntaxNodePtr ,
33
+ AstNode , AstPtr , SyntaxKind , SyntaxNode , SyntaxNodePtr ,
34
34
ast:: { self , HasName } ,
35
35
match_ast,
36
36
} ;
@@ -92,6 +92,7 @@ impl fmt::Debug for ErasedFileAstId {
92
92
Use ,
93
93
Impl ,
94
94
BlockExpr ,
95
+ AsmExpr ,
95
96
Fixup ,
96
97
) ;
97
98
if f. alternate ( ) {
@@ -144,6 +145,10 @@ enum ErasedFileAstIdKind {
144
145
Impl ,
145
146
/// Associated with [`BlockExprFileAstId`].
146
147
BlockExpr ,
148
+ // `global_asm!()` is an item, so we need to give it an `AstId`. So we give to all inline asm
149
+ // because incrementality is not a problem, they will always be the only item in the macro file,
150
+ // and memory usage also not because they're rare.
151
+ AsmExpr ,
147
152
/// Keep this last.
148
153
Root ,
149
154
}
@@ -204,14 +209,17 @@ impl ErasedFileAstId {
204
209
. or_else ( || extern_block_ast_id ( node, index_map) )
205
210
. or_else ( || use_ast_id ( node, index_map) )
206
211
. or_else ( || impl_ast_id ( node, index_map) )
212
+ . or_else ( || asm_expr_ast_id ( node, index_map) )
207
213
}
208
214
209
215
fn should_alloc ( node : & SyntaxNode ) -> bool {
210
- should_alloc_has_name ( node)
211
- || should_alloc_assoc_item ( node)
212
- || ast:: ExternBlock :: can_cast ( node. kind ( ) )
213
- || ast:: Use :: can_cast ( node. kind ( ) )
214
- || ast:: Impl :: can_cast ( node. kind ( ) )
216
+ let kind = node. kind ( ) ;
217
+ should_alloc_has_name ( kind)
218
+ || should_alloc_assoc_item ( kind)
219
+ || ast:: ExternBlock :: can_cast ( kind)
220
+ || ast:: Use :: can_cast ( kind)
221
+ || ast:: Impl :: can_cast ( kind)
222
+ || ast:: AsmExpr :: can_cast ( kind)
215
223
}
216
224
217
225
#[ inline]
@@ -331,6 +339,19 @@ fn use_ast_id(
331
339
}
332
340
}
333
341
342
+ impl AstIdNode for ast:: AsmExpr { }
343
+
344
+ fn asm_expr_ast_id (
345
+ node : & SyntaxNode ,
346
+ index_map : & mut ErasedAstIdNextIndexMap ,
347
+ ) -> Option < ErasedFileAstId > {
348
+ if ast:: AsmExpr :: can_cast ( node. kind ( ) ) {
349
+ Some ( index_map. new_id ( ErasedFileAstIdKind :: AsmExpr , ( ) ) )
350
+ } else {
351
+ None
352
+ }
353
+ }
354
+
334
355
impl AstIdNode for ast:: Impl { }
335
356
336
357
fn impl_ast_id (
@@ -449,8 +470,7 @@ macro_rules! register_has_name_ast_id {
449
470
}
450
471
}
451
472
452
- fn should_alloc_has_name( node: & SyntaxNode ) -> bool {
453
- let kind = node. kind( ) ;
473
+ fn should_alloc_has_name( kind: SyntaxKind ) -> bool {
454
474
false $( || ast:: $ident:: can_cast( kind) ) *
455
475
}
456
476
} ;
@@ -501,8 +521,7 @@ macro_rules! register_assoc_item_ast_id {
501
521
}
502
522
}
503
523
504
- fn should_alloc_assoc_item( node: & SyntaxNode ) -> bool {
505
- let kind = node. kind( ) ;
524
+ fn should_alloc_assoc_item( kind: SyntaxKind ) -> bool {
506
525
false $( || ast:: $ident:: can_cast( kind) ) *
507
526
}
508
527
} ;
0 commit comments