@@ -136,8 +136,6 @@ pub struct Semantics<'db, DB> {
136
136
pub struct SemanticsImpl < ' db > {
137
137
pub db : & ' db dyn HirDatabase ,
138
138
s2d_cache : RefCell < SourceToDefCache > ,
139
- /// Rootnode to HirFileId cache
140
- root_to_file_cache : RefCell < FxHashMap < SyntaxNode , HirFileId > > ,
141
139
/// MacroCall to its expansion's MacroFileId cache
142
140
macro_call_cache : RefCell < FxHashMap < InFile < ast:: MacroCall > , MacroFileId > > ,
143
141
}
@@ -304,12 +302,7 @@ impl<DB: HirDatabase> Semantics<'_, DB> {
304
302
305
303
impl < ' db > SemanticsImpl < ' db > {
306
304
fn new ( db : & ' db dyn HirDatabase ) -> Self {
307
- SemanticsImpl {
308
- db,
309
- s2d_cache : Default :: default ( ) ,
310
- root_to_file_cache : Default :: default ( ) ,
311
- macro_call_cache : Default :: default ( ) ,
312
- }
305
+ SemanticsImpl { db, s2d_cache : Default :: default ( ) , macro_call_cache : Default :: default ( ) }
313
306
}
314
307
315
308
pub fn parse ( & self , file_id : EditionedFileId ) -> ast:: SourceFile {
@@ -483,7 +476,7 @@ impl<'db> SemanticsImpl<'db> {
483
476
Some (
484
477
calls
485
478
. into_iter ( )
486
- . map ( |call| macro_call_to_macro_id ( self , ctx, call?) . map ( |id| Macro { id } ) )
479
+ . map ( |call| macro_call_to_macro_id ( ctx, call?) . map ( |id| Macro { id } ) )
487
480
. collect ( ) ,
488
481
)
489
482
} )
@@ -962,7 +955,7 @@ impl<'db> SemanticsImpl<'db> {
962
955
let InMacroFile { file_id, value : mapped_tokens } = self . with_ctx ( |ctx| {
963
956
Some (
964
957
ctx. cache
965
- . get_or_insert_expansion ( self , macro_file)
958
+ . get_or_insert_expansion ( ctx . db , macro_file)
966
959
. map_range_down ( span) ?
967
960
. map ( SmallVec :: < [ _ ; 2 ] > :: from_iter) ,
968
961
)
@@ -1287,7 +1280,7 @@ impl<'db> SemanticsImpl<'db> {
1287
1280
let macro_file = file_id. macro_file ( ) ?;
1288
1281
1289
1282
self . with_ctx ( |ctx| {
1290
- let expansion_info = ctx. cache . get_or_insert_expansion ( self , macro_file) ;
1283
+ let expansion_info = ctx. cache . get_or_insert_expansion ( ctx . db , macro_file) ;
1291
1284
expansion_info. arg ( ) . map ( |node| node?. parent ( ) ) . transpose ( )
1292
1285
} )
1293
1286
}
@@ -1318,8 +1311,8 @@ impl<'db> SemanticsImpl<'db> {
1318
1311
}
1319
1312
1320
1313
pub fn resolve_label ( & self , label : & ast:: Lifetime ) -> Option < Label > {
1321
- let ( parent , label_id ) = self
1322
- . with_ctx ( |ctx| ctx. label_ref_to_def ( self . wrap_node_infile ( label . clone ( ) ) . as_ref ( ) ) ) ?;
1314
+ let src = self . wrap_node_infile ( label . clone ( ) ) ;
1315
+ let ( parent , label_id ) = self . with_ctx ( |ctx| ctx. label_ref_to_def ( src . as_ref ( ) ) ) ?;
1323
1316
Some ( Label { parent, label_id } )
1324
1317
}
1325
1318
@@ -1519,7 +1512,7 @@ impl<'db> SemanticsImpl<'db> {
1519
1512
let macro_call = self . find_file ( macro_call. syntax ( ) ) . with_value ( macro_call) ;
1520
1513
self . with_ctx ( |ctx| {
1521
1514
ctx. macro_call_to_macro_call ( macro_call)
1522
- . and_then ( |call| macro_call_to_macro_id ( self , ctx, call) )
1515
+ . and_then ( |call| macro_call_to_macro_id ( ctx, call) )
1523
1516
. map ( Into :: into)
1524
1517
} )
1525
1518
. or_else ( || {
@@ -1561,7 +1554,7 @@ impl<'db> SemanticsImpl<'db> {
1561
1554
let item_in_file = self . wrap_node_infile ( item. clone ( ) ) ;
1562
1555
let id = self . with_ctx ( |ctx| {
1563
1556
let macro_call_id = ctx. item_to_macro_call ( item_in_file. as_ref ( ) ) ?;
1564
- macro_call_to_macro_id ( self , ctx, macro_call_id)
1557
+ macro_call_to_macro_id ( ctx, macro_call_id)
1565
1558
} ) ?;
1566
1559
Some ( Macro { id } )
1567
1560
}
@@ -1725,19 +1718,20 @@ impl<'db> SemanticsImpl<'db> {
1725
1718
}
1726
1719
1727
1720
fn cache ( & self , root_node : SyntaxNode , file_id : HirFileId ) {
1728
- assert ! ( root_node. parent( ) . is_none( ) ) ;
1729
- let mut cache = self . root_to_file_cache . borrow_mut ( ) ;
1730
- let prev = cache. insert ( root_node, file_id) ;
1731
- assert ! ( prev. is_none( ) || prev == Some ( file_id) ) ;
1721
+ SourceToDefCache :: cache (
1722
+ & mut self . s2d_cache . borrow_mut ( ) . root_to_file_cache ,
1723
+ root_node,
1724
+ file_id,
1725
+ ) ;
1732
1726
}
1733
1727
1734
1728
pub fn assert_contains_node ( & self , node : & SyntaxNode ) {
1735
1729
self . find_file ( node) ;
1736
1730
}
1737
1731
1738
1732
fn lookup ( & self , root_node : & SyntaxNode ) -> Option < HirFileId > {
1739
- let cache = self . root_to_file_cache . borrow ( ) ;
1740
- cache. get ( root_node) . copied ( )
1733
+ let cache = self . s2d_cache . borrow ( ) ;
1734
+ cache. root_to_file_cache . get ( root_node) . copied ( )
1741
1735
}
1742
1736
1743
1737
fn wrap_node_infile < N : AstNode > ( & self , node : N ) -> InFile < N > {
@@ -1761,8 +1755,9 @@ impl<'db> SemanticsImpl<'db> {
1761
1755
known nodes: {}\n \n ",
1762
1756
node,
1763
1757
root_node,
1764
- self . root_to_file_cache
1758
+ self . s2d_cache
1765
1759
. borrow( )
1760
+ . root_to_file_cache
1766
1761
. keys( )
1767
1762
. map( |it| format!( "{it:?}" ) )
1768
1763
. collect:: <Vec <_>>( )
@@ -1909,7 +1904,6 @@ impl<'db> SemanticsImpl<'db> {
1909
1904
}
1910
1905
1911
1906
fn macro_call_to_macro_id (
1912
- sema : & SemanticsImpl < ' _ > ,
1913
1907
ctx : & mut SourceToDefCtx < ' _ , ' _ > ,
1914
1908
macro_call_id : MacroCallId ,
1915
1909
) -> Option < MacroId > {
@@ -1925,7 +1919,7 @@ fn macro_call_to_macro_id(
1925
1919
it. to_ptr ( db) . to_node ( & db. parse ( file_id) . syntax_node ( ) )
1926
1920
}
1927
1921
HirFileIdRepr :: MacroFile ( macro_file) => {
1928
- let expansion_info = ctx. cache . get_or_insert_expansion ( sema , macro_file) ;
1922
+ let expansion_info = ctx. cache . get_or_insert_expansion ( ctx . db , macro_file) ;
1929
1923
it. to_ptr ( db) . to_node ( & expansion_info. expanded ( ) . value )
1930
1924
}
1931
1925
} ;
@@ -1937,7 +1931,7 @@ fn macro_call_to_macro_id(
1937
1931
it. to_ptr ( db) . to_node ( & db. parse ( file_id) . syntax_node ( ) )
1938
1932
}
1939
1933
HirFileIdRepr :: MacroFile ( macro_file) => {
1940
- let expansion_info = ctx. cache . get_or_insert_expansion ( sema , macro_file) ;
1934
+ let expansion_info = ctx. cache . get_or_insert_expansion ( ctx . db , macro_file) ;
1941
1935
it. to_ptr ( db) . to_node ( & expansion_info. expanded ( ) . value )
1942
1936
}
1943
1937
} ;
0 commit comments