@@ -37,6 +37,7 @@ use hir::{
3737} ;
3838use rayon:: prelude:: * ;
3939use rustc_hash:: FxHashSet ;
40+ use salsa:: Update ;
4041
4142use crate :: RootDatabase ;
4243
@@ -118,7 +119,7 @@ pub struct LocalRoots {
118119}
119120
120121/// The symbol indices of modules that make up a given crate.
121- pub fn crate_symbols ( db : & dyn HirDatabase , krate : Crate ) -> Box < [ & SymbolIndex ] > {
122+ pub fn crate_symbols ( db : & dyn HirDatabase , krate : Crate ) -> Box < [ & SymbolIndex < ' _ > ] > {
122123 let _p = tracing:: info_span!( "crate_symbols" ) . entered ( ) ;
123124 krate. modules ( db) . into_iter ( ) . map ( |module| SymbolIndex :: module_symbols ( db, module) ) . collect ( )
124125}
@@ -148,7 +149,7 @@ pub fn crate_symbols(db: &dyn HirDatabase, krate: Crate) -> Box<[&SymbolIndex]>
148149// | Editor | Shortcut |
149150// |---------|-----------|
150151// | VS Code | <kbd>Ctrl+T</kbd>
151- pub fn world_symbols ( db : & RootDatabase , query : Query ) -> Vec < FileSymbol > {
152+ pub fn world_symbols ( db : & RootDatabase , query : Query ) -> Vec < FileSymbol < ' _ > > {
152153 let _p = tracing:: info_span!( "world_symbols" , query = ?query. query) . entered ( ) ;
153154
154155 let indices: Vec < _ > = if query. libs {
@@ -170,9 +171,7 @@ pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> {
170171 crates
171172 . par_iter ( )
172173 . for_each_with ( db. clone ( ) , |snap, & krate| _ = crate_symbols ( snap, krate. into ( ) ) ) ;
173- let indices: Vec < _ > =
174- crates. into_iter ( ) . map ( |krate| crate_symbols ( db, krate. into ( ) ) ) . collect ( ) ;
175- indices. iter ( ) . flat_map ( |indices| indices. iter ( ) . cloned ( ) ) . collect ( )
174+ crates. into_iter ( ) . flat_map ( |krate| Vec :: from ( crate_symbols ( db, krate. into ( ) ) ) ) . collect ( )
176175 } ;
177176
178177 let mut res = vec ! [ ] ;
@@ -184,24 +183,27 @@ pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> {
184183}
185184
186185#[ derive( Default ) ]
187- pub struct SymbolIndex {
188- symbols : Box < [ FileSymbol ] > ,
186+ pub struct SymbolIndex < ' db > {
187+ symbols : Box < [ FileSymbol < ' db > ] > ,
189188 map : fst:: Map < Vec < u8 > > ,
190189}
191190
192- impl SymbolIndex {
191+ impl < ' db > SymbolIndex < ' db > {
193192 /// The symbol index for a given source root within library_roots.
194- pub fn library_symbols ( db : & dyn HirDatabase , source_root_id : SourceRootId ) -> & SymbolIndex {
193+ pub fn library_symbols (
194+ db : & ' db dyn HirDatabase ,
195+ source_root_id : SourceRootId ,
196+ ) -> & ' db SymbolIndex < ' db > {
195197 // FIXME:
196198 #[ salsa:: interned]
197199 struct InternedSourceRootId {
198200 id : SourceRootId ,
199201 }
200202 #[ salsa:: tracked( returns( ref) ) ]
201- fn library_symbols (
202- db : & dyn HirDatabase ,
203- source_root_id : InternedSourceRootId < ' _ > ,
204- ) -> SymbolIndex {
203+ fn library_symbols < ' db > (
204+ db : & ' db dyn HirDatabase ,
205+ source_root_id : InternedSourceRootId < ' db > ,
206+ ) -> SymbolIndex < ' db > {
205207 let _p = tracing:: info_span!( "library_symbols" ) . entered ( ) ;
206208
207209 // We call this without attaching because this runs in parallel, so we need to attach here.
@@ -224,15 +226,18 @@ impl SymbolIndex {
224226
225227 /// The symbol index for a given module. These modules should only be in source roots that
226228 /// are inside local_roots.
227- pub fn module_symbols ( db : & dyn HirDatabase , module : Module ) -> & SymbolIndex {
229+ pub fn module_symbols ( db : & dyn HirDatabase , module : Module ) -> & SymbolIndex < ' _ > {
228230 // FIXME:
229231 #[ salsa:: interned]
230232 struct InternedModuleId {
231233 id : hir:: ModuleId ,
232234 }
233235
234236 #[ salsa:: tracked( returns( ref) ) ]
235- fn module_symbols ( db : & dyn HirDatabase , module : InternedModuleId < ' _ > ) -> SymbolIndex {
237+ fn module_symbols < ' db > (
238+ db : & ' db dyn HirDatabase ,
239+ module : InternedModuleId < ' db > ,
240+ ) -> SymbolIndex < ' db > {
236241 let _p = tracing:: info_span!( "module_symbols" ) . entered ( ) ;
237242
238243 // We call this without attaching because this runs in parallel, so we need to attach here.
@@ -250,29 +255,41 @@ impl SymbolIndex {
250255 }
251256}
252257
253- impl fmt:: Debug for SymbolIndex {
258+ impl fmt:: Debug for SymbolIndex < ' _ > {
254259 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
255260 f. debug_struct ( "SymbolIndex" ) . field ( "n_symbols" , & self . symbols . len ( ) ) . finish ( )
256261 }
257262}
258263
259- impl PartialEq for SymbolIndex {
260- fn eq ( & self , other : & SymbolIndex ) -> bool {
264+ impl PartialEq for SymbolIndex < ' _ > {
265+ fn eq ( & self , other : & SymbolIndex < ' _ > ) -> bool {
261266 self . symbols == other. symbols
262267 }
263268}
264269
265- impl Eq for SymbolIndex { }
270+ impl Eq for SymbolIndex < ' _ > { }
266271
267- impl Hash for SymbolIndex {
272+ impl Hash for SymbolIndex < ' _ > {
268273 fn hash < H : Hasher > ( & self , hasher : & mut H ) {
269274 self . symbols . hash ( hasher)
270275 }
271276}
272277
273- impl SymbolIndex {
274- fn new ( mut symbols : Box < [ FileSymbol ] > ) -> SymbolIndex {
275- fn cmp ( lhs : & FileSymbol , rhs : & FileSymbol ) -> Ordering {
278+ unsafe impl Update for SymbolIndex < ' _ > {
279+ unsafe fn maybe_update ( old_pointer : * mut Self , new_value : Self ) -> bool {
280+ let this = unsafe { & mut * old_pointer } ;
281+ if * this == new_value {
282+ false
283+ } else {
284+ * this = new_value;
285+ true
286+ }
287+ }
288+ }
289+
290+ impl < ' db > SymbolIndex < ' db > {
291+ fn new ( mut symbols : Box < [ FileSymbol < ' db > ] > ) -> SymbolIndex < ' db > {
292+ fn cmp ( lhs : & FileSymbol < ' _ > , rhs : & FileSymbol < ' _ > ) -> Ordering {
276293 let lhs_chars = lhs. name . as_str ( ) . chars ( ) . map ( |c| c. to_ascii_lowercase ( ) ) ;
277294 let rhs_chars = rhs. name . as_str ( ) . chars ( ) . map ( |c| c. to_ascii_lowercase ( ) ) ;
278295 lhs_chars. cmp ( rhs_chars)
@@ -318,7 +335,7 @@ impl SymbolIndex {
318335 }
319336
320337 pub fn memory_size ( & self ) -> usize {
321- self . map . as_fst ( ) . size ( ) + self . symbols . len ( ) * size_of :: < FileSymbol > ( )
338+ self . map . as_fst ( ) . size ( ) + self . symbols . len ( ) * size_of :: < FileSymbol < ' _ > > ( )
322339 }
323340
324341 fn range_to_map_value ( start : usize , end : usize ) -> u64 {
@@ -336,10 +353,10 @@ impl SymbolIndex {
336353}
337354
338355impl Query {
339- pub ( crate ) fn search < ' sym , T > (
356+ pub ( crate ) fn search < ' db , T > (
340357 self ,
341- indices : & ' sym [ & SymbolIndex ] ,
342- cb : impl FnMut ( & ' sym FileSymbol ) -> ControlFlow < T > ,
358+ indices : & [ & ' db SymbolIndex < ' db > ] ,
359+ cb : impl FnMut ( & ' db FileSymbol < ' db > ) -> ControlFlow < T > ,
343360 ) -> Option < T > {
344361 let _p = tracing:: info_span!( "symbol_index::Query::search" ) . entered ( ) ;
345362 let mut op = fst:: map:: OpBuilder :: new ( ) ;
@@ -371,11 +388,11 @@ impl Query {
371388 }
372389 }
373390
374- fn search_maps < ' sym , T > (
391+ fn search_maps < ' db , T > (
375392 & self ,
376- indices : & ' sym [ & SymbolIndex ] ,
393+ indices : & [ & ' db SymbolIndex < ' db > ] ,
377394 mut stream : fst:: map:: Union < ' _ > ,
378- mut cb : impl FnMut ( & ' sym FileSymbol ) -> ControlFlow < T > ,
395+ mut cb : impl FnMut ( & ' db FileSymbol < ' db > ) -> ControlFlow < T > ,
379396 ) -> Option < T > {
380397 let ignore_underscore_prefixed = !self . query . starts_with ( "__" ) ;
381398 while let Some ( ( _, indexed_values) ) = stream. next ( ) {
0 commit comments